diff --git a/src/core/etl/src/Flow/ETL/Loader/StreamLoader.php b/src/core/etl/src/Flow/ETL/Loader/StreamLoader.php index b9b38a7d4..62dc9ce84 100644 --- a/src/core/etl/src/Flow/ETL/Loader/StreamLoader.php +++ b/src/core/etl/src/Flow/ETL/Loader/StreamLoader.php @@ -63,6 +63,9 @@ public function load(Rows $rows, FlowContext $context) : void \fwrite( $stream, match ($this->output) { + Output::rows_count => 'Rows: ' . $rows->count() . "\n", + Output::column_count => 'Columns: ' . $rows->schema()->count() . "\n", + Output::rows_and_column_count => 'Rows: ' . $rows->count() . ', Columns: ' . $rows->schema()->count() . "\n", Output::rows => $this->formatter->format($rows, $this->truncate), Output::schema => $this->schemaFormatter->format($rows->schema()), Output::rows_and_schema => $this->formatter->format($rows, $this->truncate) . "\n" . $this->schemaFormatter->format($rows->schema()), diff --git a/src/core/etl/src/Flow/ETL/Loader/StreamLoader/Output.php b/src/core/etl/src/Flow/ETL/Loader/StreamLoader/Output.php index 885e2bfe1..b41fc2477 100644 --- a/src/core/etl/src/Flow/ETL/Loader/StreamLoader/Output.php +++ b/src/core/etl/src/Flow/ETL/Loader/StreamLoader/Output.php @@ -6,7 +6,10 @@ enum Output { + case column_count; case rows; + case rows_and_column_count; case rows_and_schema; + case rows_count; case schema; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/StreamLoaderTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/StreamLoaderTest.php index 879b3490f..8c19a5eae 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/StreamLoaderTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/StreamLoaderTest.php @@ -13,6 +13,32 @@ final class StreamLoaderTest extends TestCase { + public function test_columns_count_to_php_output_stream() : void + { + $loader = to_output(false, StreamLoader\Output::column_count); + + \ob_start(); + + $loader->load( + rows( + row(int_entry('id', 1), str_entry('name', 'id_1')), + row(int_entry('id', 2), str_entry('name', 'id_2')), + row(int_entry('id', 3), str_entry('name', 'id_3')) + ), + new FlowContext(Config::default()) + ); + $output = \ob_get_contents(); + \ob_end_clean(); + + self::assertSame( + <<<'ASCII' +Columns: 2 + +ASCII, + $output + ); + } + public function test_loading_data_into_invalid_stream() : void { $this->expectExceptionMessage("Can't open stream for url: php://qweqweqw in mode: w"); @@ -30,7 +56,7 @@ public function test_loading_data_into_invalid_stream() : void ); } - public function test_loading_partitioned_rows_into_php_memory_stream() : void + public function test_loading_partitioned_rows_into_php_output_stream() : void { $loader = new StreamLoader('php://output', Mode::WRITE, 0); @@ -64,7 +90,7 @@ public function test_loading_partitioned_rows_into_php_memory_stream() : void ); } - public function test_loading_rows_and_schema_into_php_memory_stream() : void + public function test_loading_rows_and_schema_into_output_stream() : void { $loader = to_output(false, StreamLoader\Output::rows_and_schema); @@ -101,7 +127,7 @@ public function test_loading_rows_and_schema_into_php_memory_stream() : void ); } - public function test_loading_rows_into_php_memory_stream() : void + public function test_loading_rows_into_php_output_stream() : void { $loader = new StreamLoader('php://output', Mode::WRITE, 0); @@ -133,7 +159,7 @@ public function test_loading_rows_into_php_memory_stream() : void ); } - public function test_loading_schema_into_php_memory_stream() : void + public function test_loading_schema_into_php_output_stream() : void { $loader = new StreamLoader('php://output', Mode::WRITE, 0, StreamLoader\Output::schema); @@ -156,6 +182,58 @@ public function test_loading_schema_into_php_memory_stream() : void |-- id: integer |-- name: string +ASCII, + $output + ); + } + + public function test_rows_and_columns_count_to_php_output_stream() : void + { + $loader = to_output(false, StreamLoader\Output::rows_and_column_count); + + \ob_start(); + + $loader->load( + rows( + row(int_entry('id', 1), str_entry('name', 'id_1')), + row(int_entry('id', 2), str_entry('name', 'id_2')), + row(int_entry('id', 3), str_entry('name', 'id_3')) + ), + new FlowContext(Config::default()) + ); + $output = \ob_get_contents(); + \ob_end_clean(); + + self::assertSame( + <<<'ASCII' +Rows: 3, Columns: 2 + +ASCII, + $output + ); + } + + public function test_rows_count_to_php_output_stream() : void + { + $loader = to_output(false, StreamLoader\Output::rows_count); + + \ob_start(); + + $loader->load( + rows( + row(int_entry('id', 1), str_entry('name', 'id_1')), + row(int_entry('id', 2), str_entry('name', 'id_2')), + row(int_entry('id', 3), str_entry('name', 'id_3')) + ), + new FlowContext(Config::default()) + ); + $output = \ob_get_contents(); + \ob_end_clean(); + + self::assertSame( + <<<'ASCII' +Rows: 3 + ASCII, $output );