diff --git a/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVExtractor.php b/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVExtractor.php index a9cab672a..74b65cc46 100644 --- a/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVExtractor.php +++ b/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVExtractor.php @@ -65,6 +65,9 @@ public function extract(FlowContext $context) : \Generator $headers = \array_map(fn (int $e) : string => 'e' . \str_pad((string) $e, 2, '0', STR_PAD_LEFT), \range(0, \count($rowData) - 1)); } + $headers = \array_map(fn (string $header) : string => \trim($header), $headers); + $headers = \array_map(fn (string $header, int $index) : string => $header !== '' ? $header : 'e' . \str_pad((string) $index, 2, '0', STR_PAD_LEFT), $headers, \array_keys($headers)); + while (\is_array($rowData)) { if (\count($headers) > \count($rowData)) { \array_push( diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Fixtures/file_with_empty_headers.csv b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Fixtures/file_with_empty_headers.csv new file mode 100644 index 000000000..91343cfb3 --- /dev/null +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Fixtures/file_with_empty_headers.csv @@ -0,0 +1,3 @@ +,name,active +,,false +1,Norbert \ No newline at end of file diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVExtractorTest.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVExtractorTest.php index 69f766c30..67b2bbf13 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVExtractorTest.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVExtractorTest.php @@ -88,6 +88,28 @@ public function test_extracting_csv_empty_columns_as_null() : void ); } + public function test_extracting_csv_empty_headers() : void + { + $extractor = from_csv( + __DIR__ . '/../Fixtures/file_with_empty_headers.csv' + ); + + $this->assertSame( + [ + [ + ['e00' => null, 'name' => null, 'active' => 'false'], + ], + [ + ['e00' => '1', 'name' => 'Norbert', 'active' => null], + ], + ], + \array_map( + fn (Rows $r) => $r->toArray(), + \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) + ) + ); + } + public function test_extracting_csv_files_from_directory_recursively() : void { $extractor = from_csv( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php index 990f6c5cc..b6adbfff6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php @@ -142,8 +142,10 @@ public function test_pruning_multiple_partitions() : void ->collect() ->fetch(); + $days = $rows->reduceToArray('day'); + \sort($days); $this->assertCount(2, $rows); - $this->assertSame([1, 2], $rows->reduceToArray('day')); + $this->assertSame([1, 2], $days); } public function test_pruning_single_partition() : void