From 591529abe541256dd031555dfaf5519e1326a8c1 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz <1921950+norberttech@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:33:50 -0600 Subject: [PATCH] DSL refactoring (#852) * Deprecated From/To/Transform/Handler DSL classes in favor of functions.php * Deprecated all DSL static classes from adapters * Added ScalarFunctionFilter implementation of Partition Filter in order to deprecate Partitions dsl and simplify filtering partitions * Covered list/map/struct in DSL * Renamed read to df() * Extract adapter specific dsl functions to adapters * Fixed invalid autoload paths * Fixed wrong import statements * CS Fixes * Fixed incorrect import --- UPGRADE.md | 23 ++ composer.json | 11 + examples/data/orders_flow.php | 20 +- examples/setup/php_to_csv.php | 4 +- .../topics/aggregations/daily_revenue.php | 11 +- examples/topics/aggregations/power_plant.php | 17 +- .../aggregations/power_plant_bar_chart.php | 20 +- examples/topics/dataframe/get.php | 19 +- examples/topics/db/db_source.php | 4 +- examples/topics/db/db_to_db_sync.php | 7 +- .../topics/fs/remote/json_remote_stream.php | 7 +- .../fs/remote/json_remote_stream_glob.php | 7 +- examples/topics/http/psr_http_dynamic.php | 4 +- .../topics/join/left_anti/left_anti_join.php | 15 +- .../join/left_anti/left_anti_join_each.php | 19 +- examples/topics/transformations/aggregate.php | 36 +- .../topics/transformations/array_expand.php | 31 +- .../topics/transformations/array_unpack.php | 29 +- .../topics/transformations/filter_divide.php | 26 +- .../topics/transformations/filter_mod.php | 26 +- examples/topics/transformations/group_by.php | 32 +- examples/topics/transformations/literals.php | 24 +- examples/topics/transformations/math.php | 26 +- examples/topics/transformations/size.php | 25 +- examples/topics/transformations/sort.php | 8 +- examples/topics/transformations/when_null.php | 29 +- examples/topics/transformations/when_odd.php | 8 +- examples/topics/types/csv/csv_read.php | 4 +- .../topics/types/csv/csv_read_partitioned.php | 8 +- .../types/csv/csv_read_partitioned_filter.php | 12 +- examples/topics/types/csv/csv_to_avro.php | 8 +- examples/topics/types/csv/csv_to_json.php | 14 +- .../topics/types/csv/csv_to_parquet_100k.php | 8 +- .../topics/types/csv/csv_to_parquet_10k.php | 8 +- examples/topics/types/csv/csv_to_text.php | 4 +- .../topics/types/csv/php_to_csv_partition.php | 4 +- examples/topics/types/xml/reading.php | 8 +- examples/topics/types/xml/salaries.php | 8 +- phpunit.xml | 1 + src/adapter/etl-adapter-avro/composer.json | 5 +- .../src/Flow/ETL/Adapter/Avro/functions.php | 40 ++ .../src/Flow/ETL/DSL/Avro.php | 2 + .../Tests/Benchmark/AvroExtractorBench.php | 4 +- .../Avro/Tests/Benchmark/AvroLoaderBench.php | 7 +- .../Avro/Tests/Integration/AvroTest.php | 283 ++++++------- .../Avro/Tests/SchemaConverterTest.php | 8 +- src/adapter/etl-adapter-chartjs/composer.json | 5 +- .../Flow/ETL/Adapter/ChartJS/functions.php | 48 +++ .../src/Flow/ETL/DSL/ChartJS.php | 3 + .../Tests/Integration/ChartJSLoaderTest.php | 42 +- .../ChartJS/Tests/Unit/Chart/BarChartTest.php | 8 +- src/adapter/etl-adapter-csv/composer.json | 5 +- .../src/Flow/ETL/Adapter/CSV/functions.php | 69 ++++ .../etl-adapter-csv/src/Flow/ETL/DSL/CSV.php | 3 + .../CSV/Tests/Benchmark/CSVExtractorBench.php | 4 +- .../CSV/Tests/Benchmark/CSVLoaderBench.php | 7 +- .../Tests/Integration/CSVExtractorTest.php | 37 +- .../CSV/Tests/Integration/CSVLoaderTest.php | 56 +-- .../etl-adapter-doctrine/composer.json | 5 +- .../Adapter/Doctrine/DbalDataFrameFactory.php | 11 +- .../Flow/ETL/Adapter/Doctrine/functions.php | 172 ++++++++ .../src/Flow/ETL/DSL/Dbal.php | 3 + .../Integration/DbalDataFrameFactoryTest.php | 14 +- .../DbalLimitOffsetExtractorTest.php | 58 ++- .../Tests/Integration/DbalLoaderTest.php | 49 +-- .../Integration/DbalQueryExtractorTest.php | 13 +- .../etl-adapter-elasticsearch/composer.json | 5 +- .../ETL/Adapter/Elasticsearch/functions.php | 114 ++++++ .../src/Flow/ETL/DSL/Elasticsearch.php | 3 + .../Tests/Context/Elasticsearch7Context.php | 4 +- .../Tests/Context/Elasticsearch8Context.php | 4 +- .../ElasticsearchExtractorTest.php | 29 +- .../ElasticsearchLoaderTest.php | 17 +- .../ElasticsearchPHP/IntegrationTest.php | 10 +- .../Tests/Integration/ElasticsearchTest.php | 8 +- .../Unit/EntryIdFactory/HashIdFactoryTest.php | 6 +- .../ETL/Adapter/Filesystem/FlysystemFS.php | 1 - .../Tests/Integration/FlysystemFSTest.php | 20 +- .../etl-adapter-google-sheet/composer.json | 5 +- .../ETL/Adapter/GoogleSheet/functions.php | 83 ++++ .../src/Flow/ETL/DSL/GoogleSheet.php | 3 + .../Tests/Unit/GoogleSheetExtractorTest.php | 14 +- .../Http/PsrHttpClientDynamicExtractor.php | 9 +- .../Http/PsrHttpClientStaticExtractor.php | 9 +- src/adapter/etl-adapter-json/composer.json | 5 +- .../src/Flow/ETL/Adapter/JSON/functions.php | 52 +++ .../src/Flow/ETL/DSL/Json.php | 3 + .../Tests/Benchmark/JsonExtractorBench.php | 4 +- .../JSON/Tests/Benchmark/JsonLoaderBench.php | 7 +- .../JSONMachine/JsonExtractorTest.php | 19 +- .../JSON/Tests/Integration/JsonLoaderTest.php | 52 +-- .../etl-adapter-meilisearch/composer.json | 5 +- .../ETL/Adapter/Meilisearch/functions.php | 47 +++ .../src/Flow/ETL/DSL/Meilisearch.php | 3 + .../Tests/Context/MeilisearchContext.php | 4 +- .../MeilisearchPHP/MailiSearchTest.php | 16 +- .../MeilisearchExtractorTest.php | 18 +- .../MeilisearchPHP/MeilisearchLoaderTest.php | 15 +- src/adapter/etl-adapter-parquet/composer.json | 5 +- .../ETL/Adapter/Parquet/SchemaConverter.php | 21 +- .../Flow/ETL/Adapter/Parquet/functions.php | 73 ++++ .../src/Flow/ETL/DSL/Parquet.php | 2 + .../Tests/Benchmark/ParquetExtractorBench.php | 4 +- .../Tests/Benchmark/ParquetLoaderBench.php | 11 +- .../Integration/ParquetExtractorTest.php | 12 +- .../Parquet/Tests/Integration/ParquetTest.php | 79 ++-- .../Tests/Unit/SchemaConverterTest.php | 10 +- src/adapter/etl-adapter-text/composer.json | 5 +- .../src/Flow/ETL/Adapter/Text/functions.php | 50 +++ .../src/Flow/ETL/DSL/Text.php | 3 + .../Tests/Benchmark/TextExtractorBench.php | 4 +- .../Text/Tests/Benchmark/TextLoaderBench.php | 7 +- .../Tests/Integration/TextExtractorTest.php | 17 +- .../Text/Tests/Integration/TextLoaderTest.php | 10 +- src/adapter/etl-adapter-xml/composer.json | 5 +- .../ETL/Adapter/XML/XMLReaderExtractor.php | 9 +- .../src/Flow/ETL/Adapter/XML/functions.php | 39 ++ .../etl-adapter-xml/src/Flow/ETL/DSL/XML.php | 3 + .../XML/Tests/Benchmark/XmlExtractorBench.php | 4 +- .../Integration/XMLReaderExtractorTest.php | 36 +- src/core/etl/src/Flow/ETL/DSL/Entry.php | 2 + src/core/etl/src/Flow/ETL/DSL/From.php | 2 + src/core/etl/src/Flow/ETL/DSL/Handler.php | 2 + src/core/etl/src/Flow/ETL/DSL/Partitions.php | 15 + src/core/etl/src/Flow/ETL/DSL/To.php | 2 + src/core/etl/src/Flow/ETL/DSL/Transform.php | 2 + src/core/etl/src/Flow/ETL/DSL/functions.php | 372 ++++++++++++++++++ src/core/etl/src/Flow/ETL/DataFrame.php | 35 +- src/core/etl/src/Flow/ETL/Flow.php | 5 + .../etl/src/Flow/ETL/Function/Average.php | 6 +- .../etl/src/Flow/ETL/Function/Collect.php | 3 +- .../src/Flow/ETL/Function/CollectUnique.php | 3 +- src/core/etl/src/Flow/ETL/Function/Count.php | 3 +- src/core/etl/src/Flow/ETL/Function/Max.php | 9 +- src/core/etl/src/Flow/ETL/Function/Min.php | 9 +- src/core/etl/src/Flow/ETL/Function/Sum.php | 6 +- .../ETL/PHP/Type/ArrayContentDetector.php | 6 +- .../ETL/PHP/Type/Logical/List/ListElement.php | 19 +- .../Flow/ETL/PHP/Type/Logical/Map/MapKey.php | 8 +- .../ETL/PHP/Type/Logical/Map/MapValue.php | 19 +- .../Flow/ETL/PHP/Type/Native/ArrayType.php | 16 +- .../Flow/ETL/PHP/Type/Native/ObjectType.php | 13 - .../src/Flow/ETL/PHP/Type/TypeDetector.php | 24 +- .../src/Flow/ETL/Partition/CallableFilter.php | 2 + .../ETL/Partition/ScalarFunctionFilter.php | 50 +++ .../Flow/ETL/Pipeline/BatchingPipeline.php | 7 +- .../Flow/ETL/Pipeline/CollectingPipeline.php | 4 +- .../ETL/Pipeline/ParallelizingPipeline.php | 7 +- .../Flow/ETL/Pipeline/SynchronousPipeline.php | 4 +- .../etl/src/Flow/ETL/Row/Entry/ArrayEntry.php | 3 +- .../src/Flow/ETL/Row/Entry/BooleanEntry.php | 3 +- .../src/Flow/ETL/Row/Entry/DateTimeEntry.php | 3 +- .../etl/src/Flow/ETL/Row/Entry/FloatEntry.php | 3 +- .../src/Flow/ETL/Row/Entry/IntegerEntry.php | 3 +- .../etl/src/Flow/ETL/Row/Entry/JsonEntry.php | 3 +- .../etl/src/Flow/ETL/Row/Entry/NullEntry.php | 4 +- .../src/Flow/ETL/Row/Entry/ObjectEntry.php | 3 +- .../src/Flow/ETL/Row/Entry/StringEntry.php | 3 +- .../etl/src/Flow/ETL/Row/Entry/UuidEntry.php | 3 +- .../etl/src/Flow/ETL/Row/Entry/XMLEntry.php | 3 +- .../src/Flow/ETL/Row/Entry/XMLNodeEntry.php | 3 +- .../ETL/Row/Factory/NativeEntryFactory.php | 87 ++-- .../Schema/Formatter/ASCIISchemaFormatter.php | 29 +- src/core/etl/src/Flow/ETL/Rows.php | 6 +- .../Transformer/KeepEntriesTransformer.php | 4 +- .../Tests/Double/AllRowTypesFakeExtractor.php | 56 +-- .../ETL/Tests/Fixtures/with-dataframe.php | 8 +- .../Integration/Cache/PSRSimpleCacheTest.php | 8 +- .../Tests/Integration/DataFrame/CacheTest.php | 16 +- .../Integration/DataFrame/DisplayTest.php | 138 +++---- .../Integration/DataFrame/GroupByTest.php | 248 ++++++------ .../Tests/Integration/DataFrame/JoinTest.php | 134 ++++--- .../Tests/Integration/DataFrame/LimitTest.php | 67 ++-- .../DataFrame/PartitioningTest.php | 84 ++-- .../Integration/DataFrame/RenameTest.php | 80 ++-- .../Tests/Integration/DataFrame/SortTest.php | 26 +- .../Filesystem/FilesystemStreamsTest.php | 33 +- .../Filesystem/LocalFilesystemTest.php | 20 +- .../Function/AddDynamicEntriesTest.php | 8 +- .../Integration/Function/AddJsonTest.php | 20 +- .../Tests/Integration/Function/AllTest.php | 8 +- .../Tests/Integration/Function/AnyTest.php | 8 +- .../Integration/Function/ArrayExistsTest.php | 8 +- .../Integration/Function/ArrayExpandTest.php | 16 +- .../Function/ArrayGetCollectionTest.php | 8 +- .../Integration/Function/ArrayGetTest.php | 8 +- .../Function/ArrayKeyRenameTest.php | 8 +- .../Function/ArrayKeysStyleConvertTest.php | 8 +- .../Function/ArrayMergeCollectionTest.php | 8 +- .../Integration/Function/ArrayMergeTest.php | 8 +- .../Integration/Function/ArrayReverseTest.php | 8 +- .../Integration/Function/ArraySortTest.php | 8 +- .../Integration/Function/ArrayUnpackTest.php | 8 +- .../Function/BinaryComparisonsTest.php | 8 +- .../Integration/Function/CapitalizeTest.php | 8 +- .../Tests/Integration/Function/CastTest.php | 33 ++ .../Integration/Function/CombineTest.php | 8 +- .../Tests/Integration/Function/ConcatTest.php | 12 +- .../Integration/Function/ContainsTest.php | 16 +- .../Tests/Integration/Function/CountTest.php | 16 +- .../Integration/Function/EndsWithTest.php | 16 +- .../Tests/Integration/Function/HashTest.php | 12 +- .../Integration/Function/JsonDecodeTest.php | 8 +- .../Integration/Function/JsonEncodeTest.php | 12 +- .../Tests/Integration/Function/NotTest.php | 8 +- .../Integration/Function/PregMatchAllTest.php | 20 +- .../Integration/Function/PregMatchTest.php | 16 +- .../Integration/Function/PregReplaceTest.php | 16 +- .../Integration/Function/SanitizeTest.php | 16 +- .../Tests/Integration/Function/SizeTest.php | 16 +- .../Tests/Integration/Function/SplitTest.php | 16 +- .../Integration/Function/SprintfTest.php | 16 +- .../Integration/Function/StartsWithTest.php | 16 +- .../Tests/Integration/Function/StrPadTest.php | 12 +- .../Integration/Function/StrReplaceTest.php | 12 +- .../Integration/Function/ToLowerTest.php | 12 +- .../Integration/Function/ToUpperTest.php | 12 +- .../Tests/Integration/Function/TrimTest.php | 24 +- .../Tests/Integration/Function/WhenTest.php | 12 +- .../Pipeline/BatchingPipelineTest.php | 25 +- .../Pipeline/CollectingPipelineTest.php | 11 +- .../Pipeline/ParallelizingPipelineTest.php | 6 +- .../Pipeline/SynchronousPipelineTest.php | 14 +- .../Window/WindowFunctionsTest.php | 15 +- .../Tests/Unit/Cache/IneMemoryCacheTest.php | 6 +- .../Flow/ETL/Tests/Unit/DataFrameTest.php | 242 ++++++------ .../ETL/Tests/Unit/ETLErrorHandlingTest.php | 10 +- .../Unit/ExternalSort/BufferCacheTest.php | 16 +- .../Unit/Extractor/CacheExtractorTest.php | 37 +- .../Unit/Extractor/ChainExtractorTest.php | 22 +- .../Unit/Extractor/DataFrameExtractorTest.php | 46 +-- .../Unit/Extractor/MemoryExtractorTest.php | 34 +- .../Unit/Extractor/PipelineExtractorTest.php | 8 +- .../Unit/Extractor/ProcessExtractorTest.php | 17 +- .../Unit/Extractor/SequenceExtractorTest.php | 65 +-- .../Unit/Formatter/ASCII/ASCIIBodyTest.php | 7 +- .../Unit/Formatter/ASCII/ASCIIHeadersTest.php | 7 +- .../Unit/Formatter/ASCII/ASCIIValueTest.php | 6 +- .../Tests/Unit/Formatter/ASCIITableTest.php | 49 +-- .../Flow/ETL/Tests/Unit/Function/AllTest.php | 4 +- .../Flow/ETL/Tests/Unit/Function/AnyTest.php | 4 +- .../Tests/Unit/Function/ArrayExpandTest.php | 11 +- .../Unit/Function/ArrayGetCollectionTest.php | 13 +- .../ETL/Tests/Unit/Function/ArrayGetTest.php | 13 +- .../Unit/Function/ArrayKeyRenameTest.php | 13 +- .../Function/ArrayKeysStyleConverterTest.php | 7 +- .../Function/ArrayMergeCollectionTest.php | 9 +- .../Tests/Unit/Function/ArrayMergeTest.php | 15 +- .../Tests/Unit/Function/ArrayReverseTest.php | 7 +- .../ETL/Tests/Unit/Function/ArraySortTest.php | 13 +- .../Tests/Unit/Function/ArrayUnpackTest.php | 7 +- .../ETL/Tests/Unit/Function/AverageTest.php | 48 +-- .../Unit/Function/BinaryComparisonsTest.php | 60 +-- .../Tests/Unit/Function/CallMethodTest.php | 26 +- .../Tests/Unit/Function/CapitalizeTest.php | 4 +- .../ETL/Tests/Unit/Function/CollectTest.php | 10 +- .../Tests/Unit/Function/CollectUniqueTest.php | 10 +- .../ETL/Tests/Unit/Function/ConcatTest.php | 4 +- .../ETL/Tests/Unit/Function/CountTest.php | 43 +- .../Unit/Function/DateTimeFormatTest.php | 9 +- .../ETL/Tests/Unit/Function/DensRankTest.php | 32 +- .../ETL/Tests/Unit/Function/ExistsTest.php | 7 +- .../ETL/Tests/Unit/Function/FirstTest.php | 13 +- .../Flow/ETL/Tests/Unit/Function/HashTest.php | 15 +- .../Tests/Unit/Function/JsonDecodeTest.php | 9 +- .../Tests/Unit/Function/JsonEncodeTest.php | 13 +- .../Flow/ETL/Tests/Unit/Function/LastTest.php | 18 +- .../Flow/ETL/Tests/Unit/Function/MathTest.php | 19 +- .../Flow/ETL/Tests/Unit/Function/MaxTest.php | 39 +- .../Flow/ETL/Tests/Unit/Function/MinTest.php | 39 +- .../Flow/ETL/Tests/Unit/Function/NotTest.php | 5 +- .../Tests/Unit/Function/NumberFormatTest.php | 38 +- .../Flow/ETL/Tests/Unit/Function/RankTest.php | 32 +- .../ETL/Tests/Unit/Function/RowNumberTest.php | 12 +- .../ETL/Tests/Unit/Function/SanitizeTest.php | 13 +- .../Unit/Function/ScalarFunctionsTest.php | 11 +- .../ETL/Tests/Unit/Function/StrPadTest.php | 7 +- .../Tests/Unit/Function/StrReplaceTest.php | 9 +- .../Flow/ETL/Tests/Unit/Function/SumTest.php | 41 +- .../ETL/Tests/Unit/Function/ToDateTest.php | 10 +- .../Tests/Unit/Function/ToDateTimeTest.php | 10 +- .../ETL/Tests/Unit/Function/ToMoneyTest.php | 16 +- .../Tests/Unit/Function/ToTimeZoneTest.php | 4 +- .../Flow/ETL/Tests/Unit/Function/TrimTest.php | 11 +- .../Flow/ETL/Tests/Unit/Function/WhenTest.php | 8 +- .../tests/Flow/ETL/Tests/Unit/GroupByTest.php | 73 ++-- .../Tests/Unit/Join/Comparison/AllTest.php | 10 +- .../Tests/Unit/Join/Comparison/AnyTest.php | 10 +- .../Tests/Unit/Join/Comparison/EqualTest.php | 10 +- .../Unit/Join/Comparison/GreaterTest.php | 14 +- .../Join/Comparison/GreaterThanEqualTest.php | 14 +- .../Unit/Join/Comparison/IdenticalTest.php | 10 +- .../Tests/Unit/Join/Comparison/LessTest.php | 14 +- .../Join/Comparison/LessThanEqualTest.php | 14 +- .../Tests/Unit/Join/Comparison/NotTest.php | 10 +- .../ETL/Tests/Unit/Join/ExpressionTest.php | 6 +- .../Tests/Unit/Loader/CallbackLoaderTest.php | 17 +- .../Tests/Unit/Loader/MemoryLoaderTest.php | 11 +- .../Loader/SchemaValidationLoaderTest.php | 7 +- .../Tests/Unit/Loader/StreamLoaderTest.php | 34 +- .../Unit/Loader/TransformerLoaderTest.php | 6 +- .../PHP/Type/ArrayContentDetectorTest.php | 91 ++--- .../PHP/Type/Logical/StructureTypeTest.php | 29 +- .../Unit/PHP/Type/Native/ArrayTypeTest.php | 27 +- .../Unit/PHP/Type/Native/CallableTypeTest.php | 24 +- .../Unit/PHP/Type/Native/NullTypeTest.php | 20 +- .../Unit/PHP/Type/Native/ResourceTypeTest.php | 24 +- .../Unit/PHP/Type/Native/ScalarTypeTest.php | 33 +- .../Partition/ScalarFunctionFilterTest.php | 68 ++++ .../Unit/Pipeline/NestedPipelineTest.php | 11 +- .../ETL/Tests/Unit/Pipeline/PipesTest.php | 19 +- .../Flow/ETL/Tests/Unit/Row/EntriesTest.php | 30 +- .../Tests/Unit/Row/Entry/ListEntryTest.php | 41 +- .../Unit/Row/Entry/StructureEntryTest.php | 92 ++--- .../ETL/Tests/Unit/Row/Entry/XMLEntryTest.php | 6 +- .../ETL/Tests/Unit/Row/EntryReferenceTest.php | 14 +- .../Row/Factory/NativeEntryFactoryTest.php | 123 +++--- .../Row/Schema/Constraint/NotEmptyTest.php | 62 +-- .../Tests/Unit/Row/Schema/DefinitionTest.php | 60 +-- .../Formatter/ASCIISchemaFormatterTest.php | 13 +- .../Tests/Unit/Row/Schema/MetadataTest.php | 7 +- .../Row/Schema/SelectiveValidatorTest.php | 14 +- .../Unit/Row/Schema/StrictValidatorTest.php | 16 +- .../etl/tests/Flow/ETL/Tests/Unit/RowTest.php | 95 +++-- .../Flow/ETL/Tests/Unit/RowsJoinTest.php | 263 +++++++------ .../tests/Flow/ETL/Tests/Unit/RowsTest.php | 84 ++-- .../CallbackRowTransformerTest.php | 6 +- .../DropDuplicatesTransformerTest.php | 55 +-- ...EntryNameStyleConverterTransformerTest.php | 13 +- .../GroupToArrayTransformerTest.php | 4 +- .../JoinEachRowsTransformerTest.php | 56 +-- .../Transformer/JoinRowsTransformerTest.php | 56 +-- .../ScalarFunctionFilterTransformerTest.php | 36 +- .../ScalarFunctionTransformerTest.php | 19 +- .../Tests/Unit/CompressingSerializerTest.php | 41 +- .../Tests/Unit/NativePHPSerializerTest.php | 38 +- .../ParquetViewer/Command/ReadDataCommand.php | 12 +- 337 files changed, 4910 insertions(+), 3144 deletions(-) create mode 100644 src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/functions.php create mode 100644 src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/functions.php create mode 100644 src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/functions.php create mode 100644 src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php create mode 100644 src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/Adapter/Elasticsearch/functions.php create mode 100644 src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/functions.php create mode 100644 src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/functions.php create mode 100644 src/adapter/etl-adapter-meilisearch/src/Flow/ETL/Adapter/Meilisearch/functions.php create mode 100644 src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php create mode 100644 src/adapter/etl-adapter-text/src/Flow/ETL/Adapter/Text/functions.php create mode 100644 src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/functions.php create mode 100644 src/core/etl/src/Flow/ETL/Partition/ScalarFunctionFilter.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CastTest.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Partition/ScalarFunctionFilterTest.php diff --git a/UPGRADE.md b/UPGRADE.md index 8719bdb70..5b74d20a0 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -111,6 +111,29 @@ Class `Sha1IdFactory` was removed, use `HashIdFactory` class: (new HashIdFactory('entry_name'))->withAlgorithm('sha1'); ``` +### 15) Deprecate DSL Static classes + +DSL static classes were deprecated in favor of using functions defined in `src/core/etl/src/Flow/ETL/DSL/functions.php` file. + +Deprecated classes: + +- `src/core/etl/src/Flow/ETL/DSL/From.php` +- `src/core/etl/src/Flow/ETL/DSL/Handler.php` +- `src/core/etl/src/Flow/ETL/DSL/To.php` +- `src/core/etl/src/Flow/ETL/DSL/Transform.php` +- `src/core/etl/src/Flow/ETL/DSL/Partitions.php` +- `src/adapter/etl-adapter-avro/src/Flow/ETL/DSL/Avro.php` +- `src/adapter/etl-adapter-chartjs/src/Flow/ETL/DSL/ChartJS.php` +- `src/adapter/etl-adapter-csv/src/Flow/ETL/DSL/CSV.php` +- `src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php` +- `src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/DSL/Elasticsearch.php` +- `src/adapter/etl-adapter-google-sheet/src/Flow/ETL/DSL/GoogleSheet.php` +- `src/adapter/etl-adapter-json/src/Flow/ETL/DSL/Json.php` +- `src/adapter/etl-adapter-meilisearch/src/Flow/ETL/DSL/Meilisearch.php` +- `src/adapter/etl-adapter-parquet/src/Flow/ETL/DSL/Parquet.php` +- `src/adapter/etl-adapter-text/src/Flow/ETL/DSL/Text.php` +- `src/adapter/etl-adapter-xml/src/Flow/ETL/DSL/XML.php` + --- ## Upgrading from 0.3.x to 0.4.x diff --git a/composer.json b/composer.json index 34128310b..4cb61d7b4 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,17 @@ }, "autoload": { "files": [ + "src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/functions.php", + "src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/functions.php", + "src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/functions.php", + "src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php", + "src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/Adapter/Elasticsearch/functions.php", + "src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/functions.php", + "src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/functions.php", + "src/adapter/etl-adapter-meilisearch/src/Flow/ETL/Adapter/Meilisearch/functions.php", + "src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php", + "src/adapter/etl-adapter-text/src/Flow/ETL/Adapter/Text/functions.php", + "src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/functions.php", "src/core/etl/src/Flow/ETL/DSL/functions.php", "src/lib/array-dot/src/Flow/ArrayDot/array_dot.php", "src/lib/parquet/src/Flow/Parquet/functions.php", diff --git a/examples/data/orders_flow.php b/examples/data/orders_flow.php index e9fbf59d7..3ab59e171 100644 --- a/examples/data/orders_flow.php +++ b/examples/data/orders_flow.php @@ -1,11 +1,11 @@ read(From::array($orders)) + ->read(from_array($orders)) ->mode(SaveMode::Overwrite) - ->write(Parquet::to(__DIR__ . '/orders_flow.parquet')) - ->write(Json::to(__DIR__ . '/orders_flow.json')) - ->write(Avro::to(__DIR__ . '/orders_flow.avro')) + ->write(to_parquet(__DIR__ . '/orders_flow.parquet')) + ->write(to_json(__DIR__ . '/orders_flow.json')) + ->write(to_avro(__DIR__ . '/orders_flow.avro')) ->withEntry('order_id', ref('order_id')->cast('string')) ->withEntry('customer', ref('customer')->cast('string')) ->withEntry('address', ref('customer')->cast('string')) ->withEntry('notes', ref('customer')->cast('string')) - ->write(CSV::to(__DIR__ . '/orders_flow.csv')) + ->write(to_csv(__DIR__ . '/orders_flow.csv')) ->run(); diff --git a/examples/setup/php_to_csv.php b/examples/setup/php_to_csv.php index ee623b175..4249035c9 100644 --- a/examples/setup/php_to_csv.php +++ b/examples/setup/php_to_csv.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\to_csv; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; use Flow\ETL\Flow; use Flow\ETL\Monitoring\Memory\Consumption; @@ -17,7 +17,7 @@ $flow = (new Flow()) ->read($extractor) - ->write(CSV::to(__FLOW_OUTPUT__ . '/dataset.csv')); + ->write(to_csv(__FLOW_OUTPUT__ . '/dataset.csv')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/aggregations/daily_revenue.php b/examples/topics/aggregations/daily_revenue.php index d68b9f535..83d94aec0 100644 --- a/examples/topics/aggregations/daily_revenue.php +++ b/examples/topics/aggregations/daily_revenue.php @@ -2,18 +2,19 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\Parquet\from_parquet; +use function Flow\ETL\Adapter\Parquet\to_parquet; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\sum; -use Flow\ETL\DSL\Parquet; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; require __DIR__ . '/../../bootstrap.php'; $flow = (new Flow()) - ->read(Parquet::from(__FLOW_DATA__ . '/orders_flow.parquet')) + ->read(from_parquet(__FLOW_DATA__ . '/orders_flow.parquet')) ->select('created_at', 'total_price', 'discount') ->withEntry('created_at', ref('created_at')->toDate()->dateFormat('Y/m')) ->withEntry('revenue', ref('total_price')->minus(ref('discount'))) @@ -23,10 +24,10 @@ ->sortBy(ref('created_at')->desc()) ->withEntry('daily_revenue', ref('revenue_sum')->round(lit(2))->numberFormat(lit(2))) ->drop('revenue_sum') - ->write(To::output(truncate: false)) + ->write(to_output(truncate: false)) ->withEntry('created_at', ref('created_at')->toDate('Y/m')) ->mode(SaveMode::Overwrite) - ->write(Parquet::to(__FLOW_OUTPUT__ . '/daily_revenue.parquet')); + ->write(to_parquet(__FLOW_OUTPUT__ . '/daily_revenue.parquet')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/aggregations/power_plant.php b/examples/topics/aggregations/power_plant.php index 1527a9280..6f36186c3 100644 --- a/examples/topics/aggregations/power_plant.php +++ b/examples/topics/aggregations/power_plant.php @@ -2,21 +2,21 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; use function Flow\ETL\DSL\average; use function Flow\ETL\DSL\concat; +use function Flow\ETL\DSL\data_frame; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\max; use function Flow\ETL\DSL\min; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\sum; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read(CSV::from(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';')) +$df = data_frame() + ->read(from_csv(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';')) ->withEntry('production_kwh', ref('Produkcja(kWh)')) ->withEntry('consumption_kwh', ref('Zużycie(kWh)')) ->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m')) @@ -32,7 +32,6 @@ sum(ref('production_kwh')), sum(ref('consumption_kwh')) ) - ->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2))) ->withEntry('consumption_kwh_avg', ref('consumption_kwh_avg')->round(lit(2))) ->withEntry('production_kwh_min', ref('production_kwh_min')->round(lit(2))) @@ -44,10 +43,10 @@ ->withEntry('consumption', ref('consumption_kwh_sum')->divide(ref('production_kwh_sum'))) ->withEntry('consumption', ref('consumption')->multiply(lit(100))->round(lit(2))) ->withEntry('consumption', concat(ref('consumption'), lit('%'))) - ->write(To::output(truncate: false)); + ->write(to_output(truncate: false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/aggregations/power_plant_bar_chart.php b/examples/topics/aggregations/power_plant_bar_chart.php index fc3945f6c..be06a9f1a 100644 --- a/examples/topics/aggregations/power_plant_bar_chart.php +++ b/examples/topics/aggregations/power_plant_bar_chart.php @@ -2,21 +2,23 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\ChartJS\bar_chart; +use function Flow\ETL\Adapter\ChartJS\to_chartjs_file; +use function Flow\ETL\Adapter\CSV\from_csv; use function Flow\ETL\DSL\average; use function Flow\ETL\DSL\concat; +use function Flow\ETL\DSL\df; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\max; use function Flow\ETL\DSL\min; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\refs; use function Flow\ETL\DSL\sum; -use Flow\ETL\DSL\ChartJS; -use Flow\ETL\DSL\CSV; -use Flow\ETL\Flow; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow) - ->read(CSV::from(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';')) +$df = df() + ->read(from_csv(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';')) ->withEntry('production_kwh', ref('Produkcja(kWh)')) ->withEntry('consumption_kwh', ref('Zużycie(kWh)')) ->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m')) @@ -45,15 +47,15 @@ ->withEntry('consumption', ref('consumption')->multiply(lit(100))->round(lit(2))) ->withEntry('consumption', concat(ref('consumption'), lit('%'))) ->write( - ChartJS::to_file( - ChartJS::bar(label: ref('date'), datasets: [ref('production_kwh_avg'), ref('consumption_kwh_avg')]) + to_chartjs_file( + bar_chart(label: ref('date'), datasets: refs(ref('production_kwh_avg'), ref('consumption_kwh_avg'))) ->setOptions(['indexAxis' => 'y']), output: __FLOW_OUTPUT__ . '/power_plant_bar_chart.html' ) ); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/dataframe/get.php b/examples/topics/dataframe/get.php index 9535ddc42..b80184f5d 100644 --- a/examples/topics/dataframe/get.php +++ b/examples/topics/dataframe/get.php @@ -2,8 +2,9 @@ declare(strict_types=1); -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -12,14 +13,14 @@ $etl = (new Flow()) ->read( - From::rows( + from_rows( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ), ) ); diff --git a/examples/topics/db/db_source.php b/examples/topics/db/db_source.php index 530dfdbad..1692e3d4b 100644 --- a/examples/topics/db/db_source.php +++ b/examples/topics/db/db_source.php @@ -7,13 +7,13 @@ exit(1); } +use function Flow\ETL\Adapter\CSV\from_csv; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Flow\ETL\Adapter\Doctrine\DbalLoader; -use Flow\ETL\DSL\CSV; use Flow\ETL\Flow; $dbConnectionString = 'postgresql://postgres:postgres@127.0.0.1:5432/postgres?serverVersion=11%26charset=utf8'; @@ -36,7 +36,7 @@ ); (new Flow()) - ->read(CSV::from($path = __FLOW_OUTPUT__ . '/dataset.csv', 10_000)) + ->read(from_csv($path = __FLOW_OUTPUT__ . '/dataset.csv', 10_000)) ->rename('last name', 'last_name') ->limit(1_000_000) ->load(DbalLoader::fromConnection($dbConnection, 'source_dataset_table', 1000)) diff --git a/examples/topics/db/db_to_db_sync.php b/examples/topics/db/db_to_db_sync.php index 64bb731cd..6ff6f3265 100644 --- a/examples/topics/db/db_to_db_sync.php +++ b/examples/topics/db/db_to_db_sync.php @@ -6,13 +6,14 @@ exit(1); } +use function Flow\ETL\Adapter\Doctrine\from_dbal_limit_offset; +use function Flow\ETL\Adapter\Doctrine\to_dbal_table_insert; use function Flow\ETL\DSL\concat; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; use Aeon\Calendar\Stopwatch; use Flow\ETL\Adapter\Doctrine\Order; use Flow\ETL\Adapter\Doctrine\OrderBy; -use Flow\ETL\DSL\Dbal; use Flow\ETL\Flow; require __DIR__ . '/../../bootstrap.php'; @@ -31,7 +32,7 @@ (new Flow()) ->read( - Dbal::from_limit_offset( + from_dbal_limit_offset( $sourceDbConnection, 'source_dataset_table', new OrderBy('id', Order::DESC) @@ -40,7 +41,7 @@ ->withEntry('id', ref('id')->cast('int')) ->withEntry('name', concat(ref('name'), lit(' '), ref('last name'))) ->drop('last_name') - ->write(Dbal::to_table_insert($dbConnection, 'flow_dataset_table')) + ->write(to_dbal_table_insert($dbConnection, 'flow_dataset_table')) ->run(); $stopwatch->stop(); diff --git a/examples/topics/fs/remote/json_remote_stream.php b/examples/topics/fs/remote/json_remote_stream.php index f78a9804f..7ab269bc9 100644 --- a/examples/topics/fs/remote/json_remote_stream.php +++ b/examples/topics/fs/remote/json_remote_stream.php @@ -6,12 +6,13 @@ exit(1); } +use function Flow\ETL\Adapter\JSON\from_json; +use function Flow\ETL\Adapter\JSON\to_json; use function Flow\ETL\DSL\concat; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\Filesystem\AwsS3Stream; use Flow\ETL\Adapter\Filesystem\AzureBlobStream; -use Flow\ETL\DSL\Json; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; use Symfony\Component\Dotenv\Dotenv; @@ -45,9 +46,9 @@ AzureBlobStream::register(); (new Flow()) - ->read(Json::from(new Path('flow-aws-s3://dataset.json', $s3_client_option))) + ->read(from_json(new Path('flow-aws-s3://dataset.json', $s3_client_option))) ->withEntry('id', ref('id')->cast('integer')) ->withEntry('name', concat(ref('name'), lit(' '), ref('last name'))) ->drop('last name') - ->write(Json::to(new Path('flow-azure-blob://dataset_test.json', $azure_blob_connection_string))) + ->write(to_json(new Path('flow-azure-blob://dataset_test.json', $azure_blob_connection_string))) ->run(); diff --git a/examples/topics/fs/remote/json_remote_stream_glob.php b/examples/topics/fs/remote/json_remote_stream_glob.php index 06c1684de..5ea3faccc 100644 --- a/examples/topics/fs/remote/json_remote_stream_glob.php +++ b/examples/topics/fs/remote/json_remote_stream_glob.php @@ -6,12 +6,13 @@ exit(1); } +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\CSV\to_csv; use function Flow\ETL\DSL\concat; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\Filesystem\AwsS3Stream; use Flow\ETL\Adapter\Filesystem\AzureBlobStream; -use Flow\ETL\DSL\CSV; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; use Symfony\Component\Dotenv\Dotenv; @@ -45,9 +46,9 @@ AzureBlobStream::register(); (new Flow()) - ->read(CSV::from(new Path('flow-aws-s3://nested/**/*.csv', $s3_client_option))) + ->read(from_csv(new Path('flow-aws-s3://nested/**/*.csv', $s3_client_option))) ->withEntry('id', ref('id')->cast('int')) ->withEntry('name', concat(ref('name'), lit(' '), ref('last name'))) ->drop('last name') - ->write(CSV::to(new Path('flow-azure-blob://output.csv', $azure_blob_connection_string))) + ->write(to_csv(new Path('flow-azure-blob://output.csv', $azure_blob_connection_string))) ->run(); diff --git a/examples/topics/http/psr_http_dynamic.php b/examples/topics/http/psr_http_dynamic.php index c73a2d740..bdcf554ee 100644 --- a/examples/topics/http/psr_http_dynamic.php +++ b/examples/topics/http/psr_http_dynamic.php @@ -3,9 +3,9 @@ declare(strict_types=1); use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Adapter\Http\DynamicExtractor\NextRequestFactory; use Flow\ETL\Adapter\Http\PsrHttpClientDynamicExtractor; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; use Http\Client\Curl\Client; use Nyholm\Psr7\Factory\Psr17Factory; @@ -37,7 +37,7 @@ public function create(?Message\ResponseInterface $previousResponse = null) : ?M ->withEntry('unpacked', ref('unpacked')->unpack()) ->renameAll('unpacked.', '') ->select('name', 'html_url', 'blog') - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/join/left_anti/left_anti_join.php b/examples/topics/join/left_anti/left_anti_join.php index b7986c10d..8f806aec3 100644 --- a/examples/topics/join/left_anti/left_anti_join.php +++ b/examples/topics/join/left_anti/left_anti_join.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_output; use Flow\ETL\DSL\Entry; use Flow\ETL\DSL\To; use Flow\ETL\Flow; @@ -14,14 +17,14 @@ require __DIR__ . '/../../../bootstrap.php'; $externalProducts = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('sku', 'PRODUCT01')), - Row::create(Entry::integer('id', 2), Entry::string('sku', 'PRODUCT02')), - Row::create(Entry::integer('id', 3), Entry::string('sku', 'PRODUCT03')) + Row::create(int_entry('id', 1), str_entry('sku', 'PRODUCT01')), + Row::create(int_entry('id', 2), str_entry('sku', 'PRODUCT02')), + Row::create(int_entry('id', 3), str_entry('sku', 'PRODUCT03')) ); $internalProducts = new Rows( - Row::create(Entry::integer('id', 2), Entry::string('sku', 'PRODUCT02')), - Row::create(Entry::integer('id', 3), Entry::string('sku', 'PRODUCT03')) + Row::create(int_entry('id', 2), str_entry('sku', 'PRODUCT02')), + Row::create(int_entry('id', 3), str_entry('sku', 'PRODUCT03')) ); /** @@ -37,7 +40,7 @@ Expression::on(new Equal('id', 'id')), // by using All or Any comparisons, more than one entry can be used to prepare the condition Join::left_anti ) - ->write(To::output()); + ->write(to_output()); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/join/left_anti/left_anti_join_each.php b/examples/topics/join/left_anti/left_anti_join_each.php index 8d94c0153..48ad391d5 100644 --- a/examples/topics/join/left_anti/left_anti_join_each.php +++ b/examples/topics/join/left_anti/left_anti_join_each.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_output; use Flow\ETL\DataFrame; use Flow\ETL\DataFrameFactory; use Flow\ETL\DSL\Entry; @@ -21,15 +24,15 @@ public function extract(FlowContext $context) : Generator { yield new Rows( - Row::create(Entry::integer('id', 1), Entry::string('sku', 'PRODUCT01')), - Row::create(Entry::integer('id', 2), Entry::string('sku', 'PRODUCT02')), - Row::create(Entry::integer('id', 3), Entry::string('sku', 'PRODUCT03')) + Row::create(int_entry('id', 1), str_entry('sku', 'PRODUCT01')), + Row::create(int_entry('id', 2), str_entry('sku', 'PRODUCT02')), + Row::create(int_entry('id', 3), str_entry('sku', 'PRODUCT03')) ); yield new Rows( - Row::create(Entry::integer('id', 10_001), Entry::string('sku', 'PRODUCT10_001')), - Row::create(Entry::integer('id', 10_002), Entry::string('sku', 'PRODUCT10_002')), - Row::create(Entry::integer('id', 10_003), Entry::string('sku', 'PRODUCT10_003')) + Row::create(int_entry('id', 10_001), str_entry('sku', 'PRODUCT10_001')), + Row::create(int_entry('id', 10_002), str_entry('sku', 'PRODUCT10_002')), + Row::create(int_entry('id', 10_003), str_entry('sku', 'PRODUCT10_003')) ); } }; @@ -54,7 +57,7 @@ private function findRowsInDatabase(Rows $rows) : Rows { // Lets pretend there are 10k more entries in the DB $databaseRows = \array_map( - static fn (int $id) : Row => Row::create(Entry::integer('id', $id), Entry::string('sku', 'PRODUCT' . $id)), + static fn (int $id) : Row => Row::create(int_entry('id', $id), str_entry('sku', 'PRODUCT' . $id)), \range(1, 10_000) ); @@ -76,7 +79,7 @@ private function findRowsInDatabase(Rows $rows) : Rows Expression::on(new Equal('id', 'id')), // by using All or Any comparisons, more than one entry can be used to prepare the condition Join::left_anti ) - ->write(To::output()); + ->write(to_output()); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/transformations/aggregate.php b/examples/topics/transformations/aggregate.php index 99e47aba0..e96b1a10d 100644 --- a/examples/topics/transformations/aggregate.php +++ b/examples/topics/transformations/aggregate.php @@ -2,32 +2,30 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\row; +use function Flow\ETL\DSL\rows; use function Flow\ETL\DSL\sum; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; -use Flow\ETL\Row; -use Flow\ETL\Rows; +use function Flow\ETL\DSL\to_output; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('a', 100)), - Row::with(Entry::int('a', 100)), - Row::with(Entry::int('a', 200)), - Row::with(Entry::int('a', 400)), - Row::with(Entry::int('a', 400)) - )) - ) +$df = df() + ->from(from_rows(rows( + row(int_entry('a', 100)), + row(int_entry('a', 100)), + row(int_entry('a', 200)), + row(int_entry('a', 400)), + row(int_entry('a', 400)) + ))) ->aggregate(sum(ref('a'))) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/array_expand.php b/examples/topics/transformations/array_expand.php index c9f2310f4..08c85ae14 100644 --- a/examples/topics/transformations/array_expand.php +++ b/examples/topics/transformations/array_expand.php @@ -2,29 +2,28 @@ declare(strict_types=1); +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_expand; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; -use Flow\ETL\Row; -use Flow\ETL\Rows; +use function Flow\ETL\DSL\row; +use function Flow\ETL\DSL\rows; +use function Flow\ETL\DSL\to_output; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('id', 1), Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3])), - )) - ) - ->write(To::output(false)) +$df = df() + ->read(from_rows(rows( + row(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])), + ))) + ->write(to_output(false)) ->withEntry('expanded', array_expand(ref('array'))) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/array_unpack.php b/examples/topics/transformations/array_unpack.php index a9fcffc41..d27fe7a0d 100644 --- a/examples/topics/transformations/array_unpack.php +++ b/examples/topics/transformations/array_unpack.php @@ -2,29 +2,28 @@ declare(strict_types=1); +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('id', 1), Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3])), - Row::with(Entry::int('id', 2), Entry::array('array', ['d' => 4, 'e' => 5, 'f' => 6])), - )) - ) - ->write(To::output(false)) +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])), + Row::with(int_entry('id', 2), array_entry('array', ['d' => 4, 'e' => 5, 'f' => 6])), + ))) + ->write(to_output(false)) ->withEntry('unpacked', ref('array')->unpack()) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/filter_divide.php b/examples/topics/transformations/filter_divide.php index 96efb7b97..f1d4df353 100644 --- a/examples/topics/transformations/filter_divide.php +++ b/examples/topics/transformations/filter_divide.php @@ -2,30 +2,28 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('a', 100), Entry::int('b', 100)), - Row::with(Entry::int('a', 100), Entry::int('b', 200)) - )) - ) +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('a', 100), int_entry('b', 100)), + Row::with(int_entry('a', 100), int_entry('b', 200)) + ))) ->filter(ref('b')->divide(lit(2))->equals(lit('a'))) ->withEntry('new_b', ref('b')->multiply(lit(2))->multiply(lit(5))) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/filter_mod.php b/examples/topics/transformations/filter_mod.php index fc146121a..d06662717 100644 --- a/examples/topics/transformations/filter_mod.php +++ b/examples/topics/transformations/filter_mod.php @@ -2,29 +2,27 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('a', 4), Entry::int('b', 5)), - Row::with(Entry::int('a', 3), Entry::int('b', 6)) - )) - ) +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('a', 4), int_entry('b', 5)), + Row::with(int_entry('a', 3), int_entry('b', 6)) + ))) ->filter(ref('b')->mod(lit(2))->equals(lit(0))) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/group_by.php b/examples/topics/transformations/group_by.php index 44f56f6dd..74b65b813 100644 --- a/examples/topics/transformations/group_by.php +++ b/examples/topics/transformations/group_by.php @@ -2,31 +2,29 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('a', 100)), - Row::with(Entry::int('a', 100)), - Row::with(Entry::int('a', 200)), - Row::with(Entry::int('a', 400)), - Row::with(Entry::int('a', 400)) - )) - ) +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('a', 100)), + Row::with(int_entry('a', 100)), + Row::with(int_entry('a', 200)), + Row::with(int_entry('a', 400)), + Row::with(int_entry('a', 400)) + ))) ->groupBy(ref('a')) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/literals.php b/examples/topics/transformations/literals.php index ea1c93b3a..ae346f0c1 100644 --- a/examples/topics/transformations/literals.php +++ b/examples/topics/transformations/literals.php @@ -2,27 +2,25 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; use function Flow\ETL\DSL\lit; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::create(Entry::string('name', 'Norbert')) - )) - ) +$df = df() + ->read(from_rows(new Rows( + Row::create(str_entry('name', 'Norbert')) + ))) ->withEntry('number', lit(1)) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/math.php b/examples/topics/transformations/math.php index 7f74354e8..081c78bf3 100644 --- a/examples/topics/transformations/math.php +++ b/examples/topics/transformations/math.php @@ -2,29 +2,27 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::create(Entry::integer('a', 100), Entry::integer('b', 200)) - )) - ) - ->write(To::output(false)) +$df = df() + ->read(from_rows(new Rows( + Row::create(int_entry('a', 100), int_entry('b', 200)) + ))) + ->write(to_output(false)) ->withEntry('c', ref('a')->plus(ref('b'))) ->withEntry('d', ref('b')->minus(ref('a'))) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/size.php b/examples/topics/transformations/size.php index e3d3ab59d..cd6868abf 100644 --- a/examples/topics/transformations/size.php +++ b/examples/topics/transformations/size.php @@ -2,27 +2,26 @@ declare(strict_types=1); +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read( - From::rows(new Rows( - Row::with(Entry::int('id', 1), Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3])), - )) - ) +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])), + ))) ->withEntry('array_size', ref('array')->size()) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/sort.php b/examples/topics/transformations/sort.php index 129f75b48..c7925e338 100644 --- a/examples/topics/transformations/sort.php +++ b/examples/topics/transformations/sort.php @@ -2,17 +2,17 @@ declare(strict_types=1); +use function Flow\ETL\DSL\from_sequence_number; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Flow; require __DIR__ . '/../../bootstrap.php'; $flow = (new Flow()) - ->read(From::sequence_number('id', 0, 10)) + ->read(from_sequence_number('id', 0, 10)) ->sortBy(ref('id')->desc()) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/transformations/when_null.php b/examples/topics/transformations/when_null.php index 23a181d19..8afb639b5 100644 --- a/examples/topics/transformations/when_null.php +++ b/examples/topics/transformations/when_null.php @@ -2,34 +2,35 @@ declare(strict_types=1); +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_output; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; require __DIR__ . '/../../bootstrap.php'; -$flow = (new Flow()) - ->read(From::rows(new Rows( - Row::with(Entry::int('id', 1), Entry::int('value', 1)), - Row::with(Entry::int('id', 2), Entry::int('value', 1)), - Row::with(Entry::int('id', 3), Entry::null('value')), - Row::with(Entry::int('id', 4), Entry::int('value', 1)), - Row::with(Entry::int('id', 5), Entry::null('value')), +$df = df() + ->read(from_rows(new Rows( + Row::with(int_entry('id', 1), int_entry('value', 1)), + Row::with(int_entry('id', 2), int_entry('value', 1)), + Row::with(int_entry('id', 3), null_entry('value')), + Row::with(int_entry('id', 4), int_entry('value', 1)), + Row::with(int_entry('id', 5), null_entry('value')), ))) ->withEntry( 'value', when(ref('value')->isNull(), then: lit(0)) ) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/transformations/when_odd.php b/examples/topics/transformations/when_odd.php index db6078865..e6f869540 100644 --- a/examples/topics/transformations/when_odd.php +++ b/examples/topics/transformations/when_odd.php @@ -2,17 +2,17 @@ declare(strict_types=1); +use function Flow\ETL\DSL\from_sequence_number; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_output; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; require __DIR__ . '/../../bootstrap.php'; $flow = (new Flow()) - ->read(From::sequence_number('number', 1, 100)) + ->read(from_sequence_number('number', 1, 100)) ->collect() ->withEntry( 'type', @@ -22,7 +22,7 @@ else: lit('even') ) ) - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_read.php b/examples/topics/types/csv/csv_read.php index 2ab60eb63..2c98e14fe 100644 --- a/examples/topics/types/csv/csv_read.php +++ b/examples/topics/types/csv/csv_read.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; @@ -13,7 +13,7 @@ } $flow = (new Flow()) - ->read(CSV::from(__FLOW_OUTPUT__ . '/dataset.csv')); + ->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_read_partitioned.php b/examples/topics/types/csv/csv_read_partitioned.php index 31f36d00a..ece9f64e1 100644 --- a/examples/topics/types/csv/csv_read_partitioned.php +++ b/examples/topics/types/csv/csv_read_partitioned.php @@ -2,19 +2,19 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_output; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; $flow = (new Flow()) - ->read(CSV::from(__FLOW_DATA__ . '/partitioned')) + ->read(from_csv(__FLOW_DATA__ . '/partitioned')) ->collect() ->sortBy(ref('id')) - ->write(To::output()); + ->write(to_output()); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_read_partitioned_filter.php b/examples/topics/types/csv/csv_read_partitioned_filter.php index fc8704c07..9db1be0ff 100644 --- a/examples/topics/types/csv/csv_read_partitioned_filter.php +++ b/examples/topics/types/csv/csv_read_partitioned_filter.php @@ -2,21 +2,21 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_output; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\Partitions; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; $flow = (new Flow()) - ->read(CSV::from(__FLOW_DATA__ . '/partitioned')) + ->read(from_csv(__FLOW_DATA__ . '/partitioned')) ->collect() - ->filterPartitions(Partitions::only('t_shirt_color', 'green')) + ->filterPartitions(ref('t_shirt_color')->equals(lit('green'))) ->sortBy(ref('id')) - ->write(To::output()); + ->write(to_output()); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_to_avro.php b/examples/topics/types/csv/csv_to_avro.php index 18b34c541..39fb0de8e 100644 --- a/examples/topics/types/csv/csv_to_avro.php +++ b/examples/topics/types/csv/csv_to_avro.php @@ -2,9 +2,9 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\DSL\Adapter\Avro\to_avro; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\Avro; -use Flow\ETL\DSL\CSV; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; @@ -14,9 +14,9 @@ } $flow = (new Flow()) - ->read(CSV::from(__FLOW_OUTPUT__ . '/dataset.csv')) + ->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv')) ->rename('last name', 'last_name') - ->write(Avro::to(__FLOW_OUTPUT__ . '/dataset.avro')); + ->write(to_avro(__FLOW_OUTPUT__ . '/dataset.avro')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_to_json.php b/examples/topics/types/csv/csv_to_json.php index c0eed73e4..6073420ca 100644 --- a/examples/topics/types/csv/csv_to_json.php +++ b/examples/topics/types/csv/csv_to_json.php @@ -1,8 +1,8 @@ read(CSV::from(__FLOW_OUTPUT__ . '/dataset.csv')) - ->write(Json::to(__FLOW_OUTPUT__ . '/dataset.json')); +$df = df()->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv'))->write(to_json(__FLOW_OUTPUT__ . '/dataset.json')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { - return $flow; + return $df; } -$flow->run(); +$df->run(); diff --git a/examples/topics/types/csv/csv_to_parquet_100k.php b/examples/topics/types/csv/csv_to_parquet_100k.php index 8c01c53dc..bfbc5e3e7 100644 --- a/examples/topics/types/csv/csv_to_parquet_100k.php +++ b/examples/topics/types/csv/csv_to_parquet_100k.php @@ -2,9 +2,9 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\Parquet\to_parquet; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\Parquet; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; @@ -14,8 +14,8 @@ } $flow = (new Flow()) - ->read(CSV::from(__FLOW_OUTPUT__ . '/dataset.csv')) - ->write(Parquet::to(__FLOW_OUTPUT__ . '/dataset_100k.parquet')); + ->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv')) + ->write(to_parquet(__FLOW_OUTPUT__ . '/dataset_100k.parquet')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_to_parquet_10k.php b/examples/topics/types/csv/csv_to_parquet_10k.php index 37098ab4a..34a610e14 100644 --- a/examples/topics/types/csv/csv_to_parquet_10k.php +++ b/examples/topics/types/csv/csv_to_parquet_10k.php @@ -2,9 +2,9 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\Parquet\to_parquet; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\Parquet; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; @@ -14,8 +14,8 @@ } $flow = (new Flow()) - ->read(CSV::from(__FLOW_OUTPUT__ . '/dataset.csv')) - ->write(Parquet::to(__FLOW_OUTPUT__ . '/dataset_10k.parquet')); + ->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv')) + ->write(to_parquet(__FLOW_OUTPUT__ . '/dataset_10k.parquet')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/csv_to_text.php b/examples/topics/types/csv/csv_to_text.php index 5c1c15a48..020056fbe 100644 --- a/examples/topics/types/csv/csv_to_text.php +++ b/examples/topics/types/csv/csv_to_text.php @@ -2,14 +2,14 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\Text\from_text; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\Text; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; $flow = (new Flow()) - ->read(Text::from(__FLOW_DATA__ . '/annual-enterprise-survey-2019-financial-year-provisional.csv')); + ->read(from_text(__FLOW_DATA__ . '/annual-enterprise-survey-2019-financial-year-provisional.csv')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/csv/php_to_csv_partition.php b/examples/topics/types/csv/php_to_csv_partition.php index 49db94159..74d0d0aaa 100644 --- a/examples/topics/types/csv/php_to_csv_partition.php +++ b/examples/topics/types/csv/php_to_csv_partition.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\CSV\to_csv; use Aeon\Calendar\Stopwatch; -use Flow\ETL\DSL\CSV; use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; @@ -15,7 +15,7 @@ ->read($extractor) ->mode(SaveMode::Overwrite) ->partitionBy('country_code', 't_shirt_color') - ->write(CSV::to(__FLOW_OUTPUT__ . '/partitioned')); + ->write(to_csv(__FLOW_OUTPUT__ . '/partitioned')); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/xml/reading.php b/examples/topics/types/xml/reading.php index d59239149..baa2e070c 100644 --- a/examples/topics/types/xml/reading.php +++ b/examples/topics/types/xml/reading.php @@ -2,15 +2,15 @@ declare(strict_types=1); -use Flow\ETL\DSL\To; -use Flow\ETL\DSL\XML; +use function Flow\ETL\Adapter\XML\from_xml; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; $flow = (new Flow()) - ->read(XML::from(__FLOW_DATA__ . '/simple_items.xml', 'root/items/item')) - ->write(To::output(false)); + ->read(from_xml(__FLOW_DATA__ . '/simple_items.xml', 'root/items/item')) + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/examples/topics/types/xml/salaries.php b/examples/topics/types/xml/salaries.php index f98f53440..73f374d10 100644 --- a/examples/topics/types/xml/salaries.php +++ b/examples/topics/types/xml/salaries.php @@ -2,16 +2,16 @@ declare(strict_types=1); +use function Flow\ETL\Adapter\XML\from_xml; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\sum; -use Flow\ETL\DSL\To; -use Flow\ETL\DSL\XML; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Flow; require __DIR__ . '/../../../bootstrap.php'; $flow = (new Flow()) - ->read(XML::from(__FLOW_DATA__ . '/salaries.xml')) + ->read(from_xml(__FLOW_DATA__ . '/salaries.xml')) ->withEntry('months', ref('node')->xpath('/Salaries/Month')) ->withEntry('month', ref('months')->expand()) ->withEntry('month_name', ref('month')->domNodeAttribute('name')) @@ -23,7 +23,7 @@ ->groupBy(ref('month_name')) ->aggregate(sum(ref('department_salary'))) ->rename('department_salary_sum', 'total_monthly_salaries') - ->write(To::output(false)); + ->write(to_output(false)); if ($_ENV['FLOW_PHAR_APP'] ?? false) { return $flow; diff --git a/phpunit.xml b/phpunit.xml index 73b8039dc..4842e6cf9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -49,6 +49,7 @@ src/lib/parquet/src/Flow/Parquet/Thrift + src/core/etl/src/Flow/ETL/DSL/functions.php diff --git a/src/adapter/etl-adapter-avro/composer.json b/src/adapter/etl-adapter-avro/composer.json index 44a754c4f..55f3b4fa2 100644 --- a/src/adapter/etl-adapter-avro/composer.json +++ b/src/adapter/etl-adapter-avro/composer.json @@ -26,7 +26,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Avro/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/functions.php b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/functions.php new file mode 100644 index 000000000..cae8e7907 --- /dev/null +++ b/src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/functions.php @@ -0,0 +1,40 @@ + $extractors */ + $extractors = []; + + foreach ($path as $next_path) { + $extractors[] = new AvroExtractor( + \is_string($next_path) ? Path::realpath($next_path) : $next_path, + ); + } + + return from_all(...$extractors); + } + + return new AvroExtractor( + \is_string($path) ? Path::realpath($path) : $path + ); +} + +function to_avro(Path|string $path, ?Schema $schema = null) : AvroLoader +{ + return new AvroLoader( + \is_string($path) ? Path::realpath($path) : $path, + $schema + ); +} diff --git a/src/adapter/etl-adapter-avro/src/Flow/ETL/DSL/Avro.php b/src/adapter/etl-adapter-avro/src/Flow/ETL/DSL/Avro.php index 99096212a..f683ef895 100644 --- a/src/adapter/etl-adapter-avro/src/Flow/ETL/DSL/Avro.php +++ b/src/adapter/etl-adapter-avro/src/Flow/ETL/DSL/Avro.php @@ -12,6 +12,8 @@ use Flow\ETL\Row\Schema; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class Avro diff --git a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroExtractorBench.php b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroExtractorBench.php index 032e9ff7c..0da7084ef 100644 --- a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroExtractorBench.php +++ b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\Avro\Tests\Benchmark; +use function Flow\ETL\DSL\Adapter\Avro\from_avro; use Flow\ETL\Config; -use Flow\ETL\DSL\Avro; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (Avro::from(__DIR__ . '/../Fixtures/orders_flow.avro')->extract($this->context) as $rows) { + foreach (from_avro(__DIR__ . '/../Fixtures/orders_flow.avro')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroLoaderBench.php b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroLoaderBench.php index 72a0c69bc..8aa14859b 100644 --- a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroLoaderBench.php +++ b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Benchmark/AvroLoaderBench.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Adapter\Avro\Tests\Benchmark; +use function Flow\ETL\DSL\Adapter\Avro\from_avro; +use function Flow\ETL\DSL\Adapter\Avro\to_avro; use Flow\ETL\Config; -use Flow\ETL\DSL\Avro; use Flow\ETL\FlowContext; use Flow\ETL\Rows; use PhpBench\Attributes\Groups; @@ -23,7 +24,7 @@ public function __construct() $this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_avro_loader_bench') . '.avro'; $this->rows = new Rows(); - foreach (Avro::from(__DIR__ . '/../Fixtures/orders_flow.avro')->extract($this->context) as $rows) { + foreach (from_avro(__DIR__ . '/../Fixtures/orders_flow.avro')->extract($this->context) as $rows) { $this->rows = $this->rows->merge($rows); } } @@ -39,6 +40,6 @@ public function __destruct() public function bench_load_10k() : void { - Avro::to($this->outputPath)->load($this->rows, $this->context); + to_avro($this->outputPath)->load($this->rows, $this->context); } } diff --git a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php index fa6195aa1..af2a2d7f9 100644 --- a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php +++ b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php @@ -4,19 +4,34 @@ namespace Flow\ETL\Adapter\Avro\Tests\Integration; +use function Flow\ETL\DSL\Adapter\Avro\from_avro; +use function Flow\ETL\DSL\Adapter\Avro\to_avro; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\json_entry; +use function Flow\ETL\DSL\json_object_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Adapter\Avro\FlixTech\AvroExtractor; use Flow\ETL\Config; -use Flow\ETL\DSL\Avro; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\Path; use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; use Flow\ETL\FlowContext; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -31,8 +46,8 @@ public function test_limit() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Avro::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_avro($path)) ->run(); $extractor = new AvroExtractor(Path::realpath($path)); @@ -50,26 +65,26 @@ public function test_partitioning() : void $this->removeFile($path = \sys_get_temp_dir() . '/file.avro'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))), ); }, \range(1, 100)) ) )) ->partitionBy('integer') - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); } @@ -77,26 +92,26 @@ public function test_safe_writing_and_reading_avro_with_all_supported_types() : { $this->cleanDirectory($path = \sys_get_temp_dir() . '/directory.avro'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) ->appendSafe() - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); $paths = \array_map( @@ -109,7 +124,7 @@ public function test_safe_writing_and_reading_avro_with_all_supported_types() : $this->assertEquals( $rows, (new Flow()) - ->read(Avro::from($paths)) + ->read(from_avro($paths)) ->fetch() ); @@ -124,8 +139,8 @@ public function test_signal_stop() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Avro::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_avro($path)) ->run(); $extractor = new AvroExtractor(Path::realpath($path)); @@ -148,28 +163,28 @@ public function test_using_pattern_path() : void { $this->expectExceptionMessage("AvroLoader path can't be pattern, given: /path/*/pattern.avro"); - Avro::to(new Path('/path/*/pattern.avro')); + to_avro(new Path('/path/*/pattern.avro')); } public function test_writing_and_reading_avro_with_all_supported_types() : void { $this->removeFile($path = \sys_get_temp_dir() . '/file.avro'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - $i % 10 === 0 ? Entry::null('string') : Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]), - Entry::structure( + int_entry('integer', $i), + float_entry('float', 1.5), + $i % 10 === 0 ? null_entry('string') : str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))), + struct_entry( 'address', [ 'street' => 'street_' . $i, @@ -178,16 +193,16 @@ public function test_writing_and_reading_avro_with_all_supported_types() : void 'country' => 'country_' . $i, 'location' => ['lat' => 1.5, 'lon' => 1.5], ], - new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), - new StructureElement('zip', ScalarType::string()), - new StructureElement('country', ScalarType::string()), - new StructureElement( + struct_type( + struct_element('street', type_string()), + struct_element('city', type_string()), + struct_element('zip', type_string()), + struct_element('country', type_string()), + struct_element( 'location', - new StructureType( - new StructureElement('lat', ScalarType::float()), - new StructureElement('lon', ScalarType::float()), + struct_type( + struct_element('lat', type_float()), + struct_element('lon', type_float()), ) ) ), @@ -197,7 +212,7 @@ public function test_writing_and_reading_avro_with_all_supported_types() : void ) )) ->batchSize(10) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); $this->assertFileExists($path); @@ -205,7 +220,7 @@ public function test_writing_and_reading_avro_with_all_supported_types() : void $this->assertEquals( $rows, Flow::setUp(Config::builder()->putInputIntoRows()->build()) - ->read(Avro::from($path)) + ->read(from_avro($path)) ->drop('_input_file_uri') ->fetch() ); @@ -219,46 +234,46 @@ public function test_writing_twice_to_the_same_location() : void $this->expectExceptionMessage('please change path to different or set different SaveMode'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); $this->assertFileExists($path); @@ -266,7 +281,7 @@ public function test_writing_twice_to_the_same_location() : void $this->assertEquals( $rows, (new Flow()) - ->read(Avro::from($path)) + ->read(from_avro($path)) ->fetch() ); @@ -277,47 +292,47 @@ public function test_writing_twice_to_the_same_location_with_ignore_mode() : voi { $this->removeFile($path = \sys_get_temp_dir() . '/file.avro'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) ->mode(SaveMode::Ignore) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); $this->assertFileExists($path); @@ -325,7 +340,7 @@ public function test_writing_twice_to_the_same_location_with_ignore_mode() : voi $this->assertEquals( $rows, (new Flow()) - ->read(Avro::from($path)) + ->read(from_avro($path)) ->fetch() ); @@ -336,47 +351,47 @@ public function test_writing_twice_to_the_same_location_with_overwrite_mode() : { $this->removeFile($path = \sys_get_temp_dir() . '/file.avro'); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); - (new Flow) - ->read(From::rows( + df() + ->read(from_rows( $rows = new Rows( ...\array_map(function (int $i) : Row { return Row::create( - Entry::integer('integer', $i), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $i), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]) + int_entry('integer', $i), + float_entry('float', 1.5), + str_entry('string', 'name_' . $i), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))) ); }, \range(1, 100)) ) )) ->mode(SaveMode::Overwrite) - ->write(Avro::to($path)) + ->write(to_avro($path)) ->run(); $this->assertFileExists($path); @@ -384,7 +399,7 @@ public function test_writing_twice_to_the_same_location_with_overwrite_mode() : $this->assertEquals( $rows, (new Flow()) - ->read(Avro::from($path)) + ->read(from_avro($path)) ->fetch() ); diff --git a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/SchemaConverterTest.php b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/SchemaConverterTest.php index 4918ebf07..7418a0b6f 100644 --- a/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/SchemaConverterTest.php +++ b/src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/SchemaConverterTest.php @@ -4,6 +4,8 @@ namespace Flow\ETL\Adapter\Avro\Tests; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Adapter\Avro\FlixTech\SchemaConverter; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\PHP\Type\Logical\List\ListElement; @@ -13,8 +15,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Schema; use PHPUnit\Framework\TestCase; @@ -92,7 +92,7 @@ public function test_convert_etl_entries_to_avro_json() : void Schema\Definition::dateTime('datetime'), Schema\Definition::json('json'), Schema\Definition::list('list', new ListType(ListElement::string())), - Schema\Definition::structure('structure', new StructureType(new StructureElement('a', ScalarType::string()))), + Schema\Definition::structure('structure', new StructureType(new StructureElement('a', type_string()))), Schema\Definition::map('map', new MapType(MapKey::string(), MapValue::integer())) )) ); @@ -104,7 +104,7 @@ public function test_convert_object_entry_to_avro_array() : void $this->expectExceptionMessage("Flow\ETL\Row\Entry\ObjectEntry is not yet supported."); (new SchemaConverter())->toAvroJsonSchema(new Schema( - Schema\Definition::object('object', new ObjectType(\stdClass::class, false)) + Schema\Definition::object('object', type_object(\stdClass::class, false)) )); } } diff --git a/src/adapter/etl-adapter-chartjs/composer.json b/src/adapter/etl-adapter-chartjs/composer.json index 7f057b66a..cf358c73b 100644 --- a/src/adapter/etl-adapter-chartjs/composer.json +++ b/src/adapter/etl-adapter-chartjs/composer.json @@ -24,7 +24,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/ChartJS/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/functions.php b/src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/functions.php new file mode 100644 index 000000000..ce184472a --- /dev/null +++ b/src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/functions.php @@ -0,0 +1,48 @@ + '2023-02-06', 'Revenue' => 14000.23, 'CM' => 6000.89, 'Ads Spends' => 2800.89, 'Storage Costs' => 1800.89, 'Shipping Costs' => 2300.23, 'Currency' => 'USD'], ]; - (new Flow()) - ->read(From::memory(new ArrayMemory($data))) + df() + ->read(from_memory(new ArrayMemory($data))) ->withEntry('Profit', ref('Revenue')->minus(ref('CM'))->minus(ref('Ads Spends'))->minus(ref('Storage Costs'))->minus(ref('Shipping Costs'))->round(lit(2))) ->write( - ChartJS::to_file( - $chart = ChartJS::bar( + to_chartjs_file( + $chart = bar_chart( ref('Date'), refs( ref('Revenue'), @@ -100,12 +104,12 @@ public function test_loading_data_to_bar_chart_output_variable() : void $output = []; - (new Flow()) - ->read(From::memory(new ArrayMemory($data))) + df() + ->read(from_memory(new ArrayMemory($data))) ->withEntry('Profit', ref('Revenue')->minus(ref('CM'))->minus(ref('Ads Spends'))->minus(ref('Storage Costs'))->minus(ref('Shipping Costs'))->round(lit(2))) ->write( - ChartJS::to_var( - ChartJS::bar( + to_chartjs_var( + bar_chart( ref('Date'), refs( ref('Revenue'), @@ -169,12 +173,12 @@ public function test_loading_data_to_line_chart() : void ['Date' => '2023-02-06', 'Revenue' => 14000.23, 'CM' => 6000.89, 'Ads Spends' => 2800.89, 'Storage Costs' => 1800.89, 'Shipping Costs' => 2300.23, 'Currency' => 'USD'], ]; - (new Flow()) - ->read(From::memory(new ArrayMemory($data))) + df() + ->read(from_memory(new ArrayMemory($data))) ->withEntry('Profit', ref('Revenue')->minus(ref('CM'))->minus(ref('Ads Spends'))->minus(ref('Storage Costs'))->minus(ref('Shipping Costs'))->round(lit(2))) ->write( - ChartJS::to_file( - $chart = ChartJS::line( + to_chartjs_file( + $chart = line_chart( ref('Date'), refs( ref('Revenue'), @@ -239,7 +243,7 @@ public function test_loading_data_to_pie_chart() : void ['Date' => '2023-02-06', 'Revenue' => 14000.23, 'CM' => 6000.89, 'Ads Spends' => 2800.89, 'Storage Costs' => 1800.89, 'Shipping Costs' => 2300.23, 'Currency' => 'USD'], ]; - $chart = ChartJS::pie( + $chart = pie_chart( ref('Date'), refs( ref('Revenue'), @@ -252,8 +256,8 @@ public function test_loading_data_to_pie_chart() : void ) ->setOptions(['label' => 'PnL']); - (new Flow()) - ->read(From::memory(new ArrayMemory($data))) + df() + ->read(from_memory(new ArrayMemory($data))) ->withEntry('Profit', ref('Revenue')->minus(ref('CM'))->minus(ref('Ads Spends'))->minus(ref('Storage Costs'))->minus(ref('Shipping Costs'))->round(lit(2))) ->aggregate( first(ref('Date')->as('Date')), @@ -265,7 +269,7 @@ public function test_loading_data_to_pie_chart() : void sum(ref('Profit')->as('Profit')), ) ->write( - ChartJS::to_file( + to_chartjs_file( $chart, $output = __DIR__ . '/Output/pie_chart.html' ) diff --git a/src/adapter/etl-adapter-chartjs/tests/Flow/ETL/Adapter/ChartJS/Tests/Unit/Chart/BarChartTest.php b/src/adapter/etl-adapter-chartjs/tests/Flow/ETL/Adapter/ChartJS/Tests/Unit/Chart/BarChartTest.php index 6ed14dfc8..091ff28eb 100644 --- a/src/adapter/etl-adapter-chartjs/tests/Flow/ETL/Adapter/ChartJS/Tests/Unit/Chart/BarChartTest.php +++ b/src/adapter/etl-adapter-chartjs/tests/Flow/ETL/Adapter/ChartJS/Tests/Unit/Chart/BarChartTest.php @@ -4,11 +4,11 @@ namespace Flow\ETL\Adapter\ChartJS\Tests\Unit\Chart; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_memory; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\refs; use Flow\ETL\Adapter\ChartJS\Chart\BarChart; -use Flow\ETL\DSL\From; -use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -25,8 +25,8 @@ public function test_collecting_data_from_rows() : void ['Date' => '2023-02-06', 'Revenue' => 14000.23, 'CM' => 6000.89, 'Ads Spends' => 2800.89, 'Storage Costs' => 1800.89, 'Shipping Costs' => 2300.23, 'Currency' => 'USD'], ]; - $rows = (new Flow()) - ->read(From::memory(new ArrayMemory($data))) + $rows = df() + ->read(from_memory(new ArrayMemory($data))) ->fetch(); $chart = new BarChart(ref('Date'), refs(ref('Revenue'), ref('CM'), ref('Ads Spends'), ref('Storage Costs'), ref('Shipping Costs'))); diff --git a/src/adapter/etl-adapter-csv/composer.json b/src/adapter/etl-adapter-csv/composer.json index 06a83eec6..4d75a7e5a 100644 --- a/src/adapter/etl-adapter-csv/composer.json +++ b/src/adapter/etl-adapter-csv/composer.json @@ -24,7 +24,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/CSV/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/functions.php b/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/functions.php new file mode 100644 index 000000000..6693bdc1e --- /dev/null +++ b/src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/functions.php @@ -0,0 +1,69 @@ + $characters_read_in_line + */ +function from_csv( + string|Path|array $path, + bool $with_header = true, + bool $empty_to_null = true, + string $delimiter = ',', + string $enclosure = '"', + string $escape = '\\', + int $characters_read_in_line = 1000 +) : Extractor { + if (\is_array($path)) { + $extractors = []; + + foreach ($path as $file_path) { + $extractors[] = new CSVExtractor( + \is_string($file_path) ? Path::realpath($file_path) : $file_path, + $with_header, + $empty_to_null, + $delimiter, + $enclosure, + $escape, + $characters_read_in_line, + ); + } + + return from_all(...$extractors); + } + + return new CSVExtractor( + \is_string($path) ? Path::realpath($path) : $path, + $with_header, + $empty_to_null, + $delimiter, + $enclosure, + $escape, + $characters_read_in_line, + ); +} + +function to_csv( + string|Path $uri, + bool $with_header = true, + string $separator = ',', + string $enclosure = '"', + string $escape = '\\', + string $new_line_separator = PHP_EOL +) : Loader { + return new CSVLoader( + \is_string($uri) ? Path::realpath($uri) : $uri, + $with_header, + $separator, + $enclosure, + $escape, + $new_line_separator + ); +} diff --git a/src/adapter/etl-adapter-csv/src/Flow/ETL/DSL/CSV.php b/src/adapter/etl-adapter-csv/src/Flow/ETL/DSL/CSV.php index fd6faa2e1..28fdc65e7 100644 --- a/src/adapter/etl-adapter-csv/src/Flow/ETL/DSL/CSV.php +++ b/src/adapter/etl-adapter-csv/src/Flow/ETL/DSL/CSV.php @@ -11,6 +11,9 @@ use Flow\ETL\Filesystem\Path; use Flow\ETL\Loader; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class CSV { /** diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVExtractorBench.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVExtractorBench.php index fc8a10535..19e09e2d4 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVExtractorBench.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\CSV\Tests\Benchmark; +use function Flow\ETL\Adapter\CSV\from_csv; use Flow\ETL\Config; -use Flow\ETL\DSL\CSV; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (CSV::from(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { + foreach (from_csv(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVLoaderBench.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVLoaderBench.php index 7c566448f..693b35e65 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVLoaderBench.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Benchmark/CSVLoaderBench.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Adapter\CSV\Tests\Benchmark; +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\CSV\to_csv; use Flow\ETL\Config; -use Flow\ETL\DSL\CSV; use Flow\ETL\FlowContext; use Flow\ETL\Rows; use PhpBench\Attributes\Groups; @@ -23,7 +24,7 @@ public function __construct() $this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_csv_loader_bench') . '.csv'; $this->rows = new Rows(); - foreach (CSV::from(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { + foreach (from_csv(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { $this->rows = $this->rows->merge($rows); } } @@ -39,6 +40,6 @@ public function __destruct() public function bench_load_10k() : void { - CSV::to($this->outputPath)->load($this->rows, $this->context); + to_csv($this->outputPath)->load($this->rows, $this->context); } } 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 0d1b63d50..78a6ed81a 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 @@ -4,12 +4,13 @@ namespace Flow\ETL\Adapter\CSV\Tests\Integration; +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\CSV\to_csv; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\CSV\CSVExtractor; use Flow\ETL\Config; use Flow\ETL\ConfigBuilder; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\From; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\LocalFilesystem; use Flow\ETL\Filesystem\Path; @@ -23,7 +24,7 @@ final class CSVExtractorTest extends TestCase { public function test_extracting_csv_empty_columns_as_empty_strings() : void { - $extractor = CSV::from( + $extractor = from_csv( $path = Path::realpath(__DIR__ . '/../Fixtures/file_with_empty_columns.csv'), empty_to_null: false, ); @@ -56,7 +57,7 @@ public function test_extracting_csv_empty_columns_as_empty_strings() : void public function test_extracting_csv_empty_columns_as_null() : void { - $extractor = CSV::from( + $extractor = from_csv( __DIR__ . '/../Fixtures/file_with_empty_columns.csv' ); @@ -86,7 +87,7 @@ public function test_extracting_csv_empty_columns_as_null() : void public function test_extracting_csv_files_from_directory_recursively() : void { - $extractor = CSV::from( + $extractor = from_csv( [ Path::realpath(__DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv'), Path::realpath(__DIR__ . '/../Fixtures/nested/annual-enterprise-survey-2019-financial-year-provisional-csv.csv'), @@ -115,7 +116,7 @@ public function test_extracting_csv_files_with_header() : void $path = __DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv'; $rows = (new Flow()) - ->read(CSV::from($path)) + ->read(from_csv($path)) ->fetch(); foreach ($rows as $row) { @@ -142,7 +143,7 @@ public function test_extracting_csv_files_with_header() : void public function test_extracting_csv_files_without_header() : void { - $extractor = CSV::from( + $extractor = from_csv( __DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv', false ); @@ -166,7 +167,7 @@ public function test_extracting_csv_files_without_header() : void public function test_extracting_csv_with_corrupted_row() : void { $rows = (new Flow()) - ->extract(CSV::from(__DIR__ . '/../Fixtures/corrupted_row.csv')) + ->extract(from_csv(__DIR__ . '/../Fixtures/corrupted_row.csv')) ->fetch(); $this->assertSame(3, $rows->count()); @@ -174,7 +175,7 @@ public function test_extracting_csv_with_corrupted_row() : void public function test_extracting_csv_with_more_columns_than_headers() : void { - $extractor = CSV::from( + $extractor = from_csv( __DIR__ . '/../Fixtures/more_columns_than_headers.csv' ); @@ -196,7 +197,7 @@ public function test_extracting_csv_with_more_columns_than_headers() : void public function test_extracting_csv_with_more_headers_than_columns() : void { - $extractor = CSV::from( + $extractor = from_csv( Path::realpath(__DIR__ . '/../Fixtures/more_headers_than_columns.csv') ); @@ -221,7 +222,7 @@ public function test_extracting_csv_with_more_than_1000_characters_per_line_spli $this->assertCount( 2, (new Flow()) - ->read(CSV::from(__DIR__ . '/../Fixtures/more_than_1000_characters_per_line.csv')) + ->read(from_csv(__DIR__ . '/../Fixtures/more_than_1000_characters_per_line.csv')) ->fetch() ->toArray(), 'Long line was broken down into two rows.' @@ -233,7 +234,7 @@ public function test_extracting_csv_with_more_than_1000_characters_per_line_with $this->assertCount( 1, (new Flow()) - ->read(CSV::from(__DIR__ . '/../Fixtures/more_than_1000_characters_per_line.csv', characters_read_in_line: 2000)) + ->read(from_csv(__DIR__ . '/../Fixtures/more_than_1000_characters_per_line.csv', characters_read_in_line: 2000)) ->fetch() ->toArray(), 'Long line was read as one row.' @@ -248,8 +249,8 @@ public function test_limit() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(CSV::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_csv($path)) ->run(); $extractor = new CSVExtractor(Path::realpath($path)); @@ -275,7 +276,7 @@ public function test_loading_data_from_all_partitions() : void ['group' => '2', 'id' => 8, 'value' => 'h'], ], (new Flow()) - ->read(CSV::from(__DIR__ . '/../Fixtures/partitioned/group=*/*.csv')) + ->read(from_csv(__DIR__ . '/../Fixtures/partitioned/group=*/*.csv')) ->withEntry('id', ref('id')->cast('int')) ->sortBy(ref('id')) ->fetch() @@ -297,7 +298,7 @@ public function test_loading_data_from_all_with_local_fs() : void ['group' => '2', 'id' => 8, 'value' => 'h'], ], (new Flow((new ConfigBuilder())->filesystem(new LocalFilesystem()))) - ->read(CSV::from(__DIR__ . '/../Fixtures/partitioned/group=*/*.csv')) + ->read(from_csv(__DIR__ . '/../Fixtures/partitioned/group=*/*.csv')) ->withEntry('id', ref('id')->cast('int')) ->sortBy(ref('id')) ->fetch() @@ -313,8 +314,8 @@ public function test_signal_stop() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(CSV::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_csv($path)) ->run(); $extractor = new CSVExtractor(Path::realpath($path)); diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php index 2e6b58a5b..07d32a218 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVLoaderTest.php @@ -4,8 +4,10 @@ namespace Flow\ETL\Adapter\CSV\Tests\Integration; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\Adapter\CSV\to_csv; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Filesystem\Path; use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; @@ -25,10 +27,10 @@ public function test_loading_array_entry() : void (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::array('data', ['foo' => 'bar'])), + Row::create(int_entry('id', 1), array_entry('data', ['foo' => 'bar'])), ) ) - ->write(CSV::to($path)) + ->write(to_csv($path)) ->run(); if (\file_exists($path)) { @@ -49,7 +51,7 @@ public function test_loading_csv_files_with_append_safe() : void ) ) ->appendSafe() - ->load(CSV::to($path)) + ->load(to_csv($path)) ->run(); $files = \array_values(\array_diff(\scandir($path), ['..', '.'])); @@ -78,12 +80,12 @@ public function test_loading_csv_files_without_thread_safe_and_with_serializatio (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'Norbert')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'Tomek')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'Dawid')), + Row::create(int_entry('id', 1), str_entry('name', 'Norbert')), + Row::create(int_entry('id', 2), str_entry('name', 'Tomek')), + Row::create(int_entry('id', 3), str_entry('name', 'Dawid')), ) ) - ->load($serializer->unserialize($serializer->serialize(CSV::to($path, $withHeader = true)))) + ->load($serializer->unserialize($serializer->serialize(to_csv($path, $withHeader = true)))) ->run(); $this->assertStringContainsString( @@ -108,12 +110,12 @@ public function test_loading_csv_files_without_threadsafe() : void (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'Norbert')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'Tomek')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'Dawid')), + Row::create(int_entry('id', 1), str_entry('name', 'Norbert')), + Row::create(int_entry('id', 2), str_entry('name', 'Tomek')), + Row::create(int_entry('id', 3), str_entry('name', 'Dawid')), ) ) - ->load(CSV::to($path)) + ->load(to_csv($path)) ->run(); $this->assertStringContainsString( @@ -138,13 +140,13 @@ public function test_loading_csv_with_partitioning() : void (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::integer('group', 1)), - Row::create(Entry::integer('id', 2), Entry::integer('group', 1)), - Row::create(Entry::integer('id', 3), Entry::integer('group', 2)), - Row::create(Entry::integer('id', 4), Entry::integer('group', 2)), + Row::create(int_entry('id', 1), int_entry('group', 1)), + Row::create(int_entry('id', 2), int_entry('group', 1)), + Row::create(int_entry('id', 3), int_entry('group', 2)), + Row::create(int_entry('id', 4), int_entry('group', 2)), ) ) - ->load(CSV::to($path)) + ->load(to_csv($path)) ->partitionBy('group') ->run(); @@ -189,24 +191,24 @@ public function test_loading_overwrite_csv() : void (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'Norbert')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'Tomek')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'Dawid')), + Row::create(int_entry('id', 1), str_entry('name', 'Norbert')), + Row::create(int_entry('id', 2), str_entry('name', 'Tomek')), + Row::create(int_entry('id', 3), str_entry('name', 'Dawid')), ) ) - ->load(CSV::to($path)) + ->load(to_csv($path)) ->run(); (new Flow()) ->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'Norbert')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'Tomek')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'Dawid')), + Row::create(int_entry('id', 1), str_entry('name', 'Norbert')), + Row::create(int_entry('id', 2), str_entry('name', 'Tomek')), + Row::create(int_entry('id', 3), str_entry('name', 'Dawid')), ) ) ->mode(SaveMode::Overwrite) - ->load(CSV::to($path)) + ->load(to_csv($path)) ->run(); $this->assertStringContainsString( @@ -228,7 +230,7 @@ public function test_using_pattern_path() : void { $this->expectExceptionMessage("CSVLoader path can't be pattern, given: /path/*/pattern.csv"); - CSV::to(new Path('/path/*/pattern.csv')); + to_csv(new Path('/path/*/pattern.csv')); } /** diff --git a/src/adapter/etl-adapter-doctrine/composer.json b/src/adapter/etl-adapter-doctrine/composer.json index 0af87263d..ae2ae6881 100644 --- a/src/adapter/etl-adapter-doctrine/composer.json +++ b/src/adapter/etl-adapter-doctrine/composer.json @@ -22,7 +22,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Doctrine/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php index 29323c24f..cf73fdb00 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\DriverManager; use Flow\ETL\DataFrame; use Flow\ETL\DataFrameFactory; -use Flow\ETL\DSL\Dbal; use Flow\ETL\Flow; use Flow\ETL\Rows; @@ -79,15 +78,7 @@ public function from(Rows $rows) : DataFrame } } - return (new Flow()) - ->extract( - Dbal::from_query( - $this->connection(), - $this->query, - $parameters, - $types, - ) - ); + return (new Flow())->extract(\Flow\ETL\Adapter\Doctrine\dbal_from_query($this->connection(), $this->query, $parameters, $types)); } private function connection() : Connection diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php new file mode 100644 index 000000000..9782496ea --- /dev/null +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php @@ -0,0 +1,172 @@ +|Connection $connection + * @param string $query + * @param QueryParameter ...$parameters + * + * @return DataFrameFactory + */ +function dbal_dataframe_factory( + array|Connection $connection, + string $query, + QueryParameter ...$parameters +) : DataFrameFactory { + return \is_array($connection) + ? new DbalDataFrameFactory($connection, $query, ...$parameters) + : DbalDataFrameFactory::fromConnection($connection, $query, ...$parameters); +} + +/** + * @param Connection $connection + * @param string|Table $table + * @param array|OrderBy $order_by + * @param int $page_size + * @param null|int $maximum + * + * @throws InvalidArgumentException + * + * @return Extractor + */ +function from_dbal_limit_offset( + Connection $connection, + string|Table $table, + array|OrderBy $order_by, + int $page_size = 1000, + ?int $maximum = null, +) : Extractor { + return DbalLimitOffsetExtractor::table( + $connection, + \is_string($table) ? new Table($table) : $table, + $order_by instanceof OrderBy ? [$order_by] : $order_by, + $page_size, + $maximum, + ); +} + +/** + * @param Connection $connection + * @param int $page_size + * @param null|int $maximum + * + * @return Extractor + */ +function from_dbal_limit_offset_qb( + Connection $connection, + QueryBuilder $queryBuilder, + int $page_size = 1000, + ?int $maximum = null, +) : Extractor { + return new DbalLimitOffsetExtractor( + $connection, + $queryBuilder, + $page_size, + $maximum, + ); +} + +/** + * @param Connection $connection + * @param string $query + * @param null|ParametersSet $parameters_set - each one parameters array will be evaluated as new query + * @param array|array $types + * + * @return Extractor + */ +function dbal_from_queries( + Connection $connection, + string $query, + ?ParametersSet $parameters_set = null, + array $types = [], +) : Extractor { + return new DbalQueryExtractor( + $connection, + $query, + $parameters_set, + $types, + ); +} + +/** + * @param Connection $connection + * @param string $query + * @param array|list $parameters + * @param array|array $types + * + * @return Extractor + */ +function dbal_from_query( + Connection $connection, + string $query, + array $parameters = [], + array $types = [], +) : Extractor { + return DbalQueryExtractor::single( + $connection, + $query, + $parameters, + $types, + ); +} + +/** + * In order to control the size of the single insert, use DataFrame::chunkSize() method just before calling DataFrame::load(). + * + * @param array|Connection $connection + * @param array{ + * skip_conflicts?: boolean, + * constraint?: string, + * conflict_columns?: array, + * update_columns?: array, + * primary_key_columns?: array + * } $options + * + * @throws InvalidArgumentException + */ +function to_dbal_table_insert( + array|Connection $connection, + string $table, + array $options = [], +) : Loader { + return \is_array($connection) + ? new DbalLoader($table, $connection, $options, 'insert') + : DbalLoader::fromConnection($connection, $table, $options, 'insert'); +} + +/** + * In order to control the size of the single request, use DataFrame::chunkSize() method just before calling DataFrame::load(). + * + * @param array|Connection $connection + * @param array{ + * skip_conflicts?: boolean, + * constraint?: string, + * conflict_columns?: array, + * update_columns?: array, + * primary_key_columns?: array + * } $options + * + * @throws InvalidArgumentException + * + * @return Loader + */ +function to_dbal_table_update( + array|Connection $connection, + string $table, + array $options = [], +) : Loader { + return \is_array($connection) + ? new DbalLoader($table, $connection, $options, 'update') + : DbalLoader::fromConnection($connection, $table, $options, 'update'); +} diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php index ba4c305bd..780c8e87f 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php @@ -20,6 +20,9 @@ use Flow\ETL\Extractor; use Flow\ETL\Loader; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class Dbal { /** diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalDataFrameFactoryTest.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalDataFrameFactoryTest.php index f94d77a1a..f0ec96b03 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalDataFrameFactoryTest.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalDataFrameFactoryTest.php @@ -4,16 +4,16 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Integration; +use function Flow\ETL\Adapter\Doctrine\dbal_dataframe_factory; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; -use Flow\ETL\Adapter\Doctrine\DbalDataFrameFactory; use Flow\ETL\Adapter\Doctrine\LiteralParameter; use Flow\ETL\Adapter\Doctrine\Parameter; use Flow\ETL\Adapter\Doctrine\Tests\IntegrationTestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -38,7 +38,7 @@ public function test_create_loader_with_invalid_operation() : void $this->pgsqlDatabaseContext->insert('flow_doctrine_data_factory_test', ['id' => 5, 'name' => 'Name 5', 'description' => 'Some Description 5']); $rows = ( - new DbalDataFrameFactory( + dbal_dataframe_factory( $this->connectionParams(), 'SELECT * FROM flow_doctrine_data_factory_test WHERE id IN (:ids) AND name = :name', Parameter::ints('ids', ref('id')), @@ -46,10 +46,10 @@ public function test_create_loader_with_invalid_operation() : void ) ) ->from(new Rows( - Row::with(Entry::int('id', 1)), - Row::with(Entry::int('id', 2)), - Row::with(Entry::int('id', 3)), - Row::with(Entry::int('id', 55)), + Row::with(int_entry('id', 1)), + Row::with(int_entry('id', 2)), + Row::with(int_entry('id', 3)), + Row::with(int_entry('id', 55)), )) ->select('id') ->fetch(); diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLimitOffsetExtractorTest.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLimitOffsetExtractorTest.php index ff57470b7..5d1bee24a 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLimitOffsetExtractorTest.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLimitOffsetExtractorTest.php @@ -4,6 +4,9 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Integration; +use function Flow\ETL\Adapter\Doctrine\from_dbal_limit_offset; +use function Flow\ETL\Adapter\Doctrine\from_dbal_limit_offset_qb; +use function Flow\ETL\DSL\df; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; @@ -11,7 +14,6 @@ use Flow\ETL\Adapter\Doctrine\Order; use Flow\ETL\Adapter\Doctrine\OrderBy; use Flow\ETL\Adapter\Doctrine\Tests\IntegrationTestCase; -use Flow\ETL\DSL\Dbal; use Flow\ETL\Flow; final class DbalLimitOffsetExtractorTest extends IntegrationTestCase @@ -32,15 +34,13 @@ public function test_extracting_entire_table() : void $this->pgsqlDatabaseContext->insert($table, ['id' => $i, 'name' => 'name_' . $i, 'description' => 'description_' . $i]); } - $data = (new Flow()) - ->extract( - Dbal::from_limit_offset( - $this->pgsqlDatabaseContext->connection(), - $table, - new OrderBy('id', Order::ASC), - 5 - ) - ) + $data = df() + ->read(from_dbal_limit_offset( + $this->pgsqlDatabaseContext->connection(), + $table, + new OrderBy('id', Order::ASC), + 5 + )) ->fetch(); $this->assertSame( @@ -76,7 +76,7 @@ public function test_extracting_entire_table_using_qb() : void $data = (new Flow()) ->extract( - Dbal::from_limit_offset_qb( + from_dbal_limit_offset_qb( $this->pgsqlDatabaseContext->connection(), $this->pgsqlDatabaseContext->connection()->createQueryBuilder() ->from($table) @@ -118,16 +118,14 @@ public function test_extracting_limited_number_of_rows_from_table() : void $this->pgsqlDatabaseContext->insert($table, ['id' => $i, 'name' => 'name_' . $i, 'description' => 'description_' . $i]); } - $data = (new Flow()) - ->extract( - Dbal::from_limit_offset( - $this->pgsqlDatabaseContext->connection(), - $table, - new OrderBy('id', Order::ASC), - 5, - 7 - ) - ) + $data = df() + ->read(from_dbal_limit_offset( + $this->pgsqlDatabaseContext->connection(), + $table, + new OrderBy('id', Order::ASC), + 5, + 7 + )) ->fetch(); $this->assertSame( @@ -160,16 +158,14 @@ public function test_extracting_selected_columns() : void $this->pgsqlDatabaseContext->insert($table, ['id' => $i, 'name' => 'name_' . $i, 'description' => 'description_' . $i]); } - $data = (new Flow()) - ->extract( - Dbal::from_limit_offset( - $this->pgsqlDatabaseContext->connection(), - new \Flow\ETL\Adapter\Doctrine\Table($table, ['name']), - new OrderBy('id', Order::ASC), - 5, - 7 - ) - ) + $data = df() + ->read(from_dbal_limit_offset( + $this->pgsqlDatabaseContext->connection(), + new \Flow\ETL\Adapter\Doctrine\Table($table, ['name']), + new OrderBy('id', Order::ASC), + 5, + 7 + )) ->fetch(); $this->assertSame( diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLoaderTest.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLoaderTest.php index d76500e04..d5e65c114 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLoaderTest.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLoaderTest.php @@ -4,14 +4,15 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Integration; +use function Flow\ETL\Adapter\Doctrine\to_dbal_table_insert; +use function Flow\ETL\Adapter\Doctrine\to_dbal_table_update; +use function Flow\ETL\DSL\from_array; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Flow\ETL\Adapter\Doctrine\DbalLoader; use Flow\ETL\Adapter\Doctrine\Tests\IntegrationTestCase; -use Flow\ETL\DSL\Dbal; -use Flow\ETL\DSL\From; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Flow; use Flow\Serializer\CompressingSerializer; @@ -71,11 +72,11 @@ public function test_inserts_multiple_rows_at_once() : void )) ->setPrimaryKey(['id'])); - $loader = Dbal::to_table_insert($this->connectionParams(), $table); + $loader = to_dbal_table_insert($this->connectionParams(), $table); (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], @@ -102,11 +103,11 @@ public function test_inserts_multiple_rows_at_once_after_serialization_and_deser ); $serializer = new CompressingSerializer(); - $loaderSerialized = $serializer->serialize(Dbal::to_table_insert($this->connectionParams(), $table)); + $loaderSerialized = $serializer->serialize(to_dbal_table_insert($this->connectionParams(), $table)); (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], @@ -132,11 +133,11 @@ public function test_inserts_multiple_rows_at_once_using_existing_connection() : ->setPrimaryKey(['id']) ); - $loader = Dbal::to_table_insert($this->pgsqlDatabaseContext->connection(), $table); + $loader = to_dbal_table_insert($this->pgsqlDatabaseContext->connection(), $table); (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], @@ -163,13 +164,13 @@ public function test_inserts_multiple_rows_in_two_insert_queries() : void (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], ]) ) - ->load(Dbal::to_table_insert($this->connectionParams(), $table)) + ->load(to_dbal_table_insert($this->connectionParams(), $table)) ->run(); $this->assertEquals(3, $this->pgsqlDatabaseContext->tableCount($table)); @@ -188,24 +189,24 @@ public function test_inserts_new_rows_and_skip_already_existed() : void ->setPrimaryKey(['id'])); (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], ]) ) - ->load(Dbal::to_table_insert($this->connectionParams(), $table)) + ->load(to_dbal_table_insert($this->connectionParams(), $table)) ->run(); (new Flow()) ->read( - From::array([ + from_array([ ['id' => 2, 'name' => 'New Name Two', 'description' => 'New Description Two'], ['id' => 3, 'name' => 'New Name Three', 'description' => 'New Description Three'], ['id' => 4, 'name' => 'New Name Four', 'description' => 'New Description Three'], ]) ) - ->load(Dbal::to_table_insert($this->connectionParams(), $table, ['skip_conflicts' => true])) + ->load(to_dbal_table_insert($this->connectionParams(), $table, ['skip_conflicts' => true])) ->run(); $this->assertEquals(4, $this->pgsqlDatabaseContext->tableCount($table)); @@ -236,23 +237,23 @@ public function test_inserts_new_rows_or_updates_already_existed_based_on_primar (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], ]) ) - ->load(Dbal::to_table_insert($this->connectionParams(), $table)) + ->load(to_dbal_table_insert($this->connectionParams(), $table)) ->run(); (new Flow())->extract( - From::array([ + from_array([ ['id' => 2, 'name' => 'New Name Two', 'description' => 'New Description Two'], ['id' => 3, 'name' => 'New Name Three', 'description' => 'New Description Three'], ['id' => 4, 'name' => 'New Name Four', 'description' => 'New Description Three'], ]) ) - ->load(Dbal::to_table_insert($this->connectionParams(), $table, ['constraint' => 'flow_doctrine_bulk_test_pkey'])) + ->load(to_dbal_table_insert($this->connectionParams(), $table, ['constraint' => 'flow_doctrine_bulk_test_pkey'])) ->run(); $this->assertEquals(4, $this->pgsqlDatabaseContext->tableCount($table)); @@ -279,7 +280,7 @@ public function test_that_operation_is_lower_cased() : void )) ->setPrimaryKey(['id'])); - $loader = Dbal::to_table_insert($this->connectionParams(), $table); + $loader = to_dbal_table_insert($this->connectionParams(), $table); $this->assertSame($loader->__serialize()['operation'], 'insert'); } @@ -296,7 +297,7 @@ public function test_that_operation_is_lower_cased_from_connection_method() : vo )) ->setPrimaryKey(['id'])); - $loader = Dbal::to_table_insert( + $loader = to_dbal_table_insert( $this->pgsqlDatabaseContext->connection(), $table, $this->connectionParams() @@ -317,11 +318,11 @@ public function test_update_multiple_rows_at_once() : void )) ->setPrimaryKey(['id'])); - $insertLoader = Dbal::to_table_insert($this->connectionParams(), $table); - $updateLoader = Dbal::to_table_update($this->connectionParams(), $table, ['primary_key_columns' => ['id'], ['update_columns' => ['name']]]); + $insertLoader = to_dbal_table_insert($this->connectionParams(), $table); + $updateLoader = to_dbal_table_update($this->connectionParams(), $table, ['primary_key_columns' => ['id'], ['update_columns' => ['name']]]); (new Flow())->extract( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], @@ -332,7 +333,7 @@ public function test_update_multiple_rows_at_once() : void (new Flow()) ->read( - From::array([ + from_array([ ['id' => 1, 'name' => 'Changed Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Changed Name Three', 'description' => 'Description Three'], diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalQueryExtractorTest.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalQueryExtractorTest.php index 32e2fdf5a..cd97df4da 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalQueryExtractorTest.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalQueryExtractorTest.php @@ -4,6 +4,9 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Integration; +use function Flow\ETL\Adapter\Doctrine\dbal_from_queries; +use function Flow\ETL\Adapter\Doctrine\dbal_from_query; +use function Flow\ETL\DSL\from_array; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; @@ -11,8 +14,6 @@ use Flow\ETL\Adapter\Doctrine\DbalLoader; use Flow\ETL\Adapter\Doctrine\ParametersSet; use Flow\ETL\Adapter\Doctrine\Tests\IntegrationTestCase; -use Flow\ETL\DSL\Dbal; -use Flow\ETL\DSL\From; use Flow\ETL\Flow; final class DbalQueryExtractorTest extends IntegrationTestCase @@ -30,7 +31,7 @@ public function test_extracting_multiple_rows_at_once() : void ->setPrimaryKey(['id'])); (new Flow())->extract( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name One', 'description' => 'Description One'], ['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'], ['id' => 3, 'name' => 'Name Three', 'description' => 'Description Three'], @@ -40,7 +41,7 @@ public function test_extracting_multiple_rows_at_once() : void )->run(); $rows = (new Flow())->extract( - Dbal::from_query( + dbal_from_query( $this->pgsqlDatabaseContext->connection(), "SELECT * FROM {$table} ORDER BY id" ) @@ -70,7 +71,7 @@ public function test_extracting_multiple_rows_multiple_times() : void (new Flow()) ->extract( - From::array([ + from_array([ ['id' => 1, 'name' => 'Name', 'description' => 'Description'], ['id' => 2, 'name' => 'Name', 'description' => 'Description'], ['id' => 3, 'name' => 'Name', 'description' => 'Description'], @@ -87,7 +88,7 @@ public function test_extracting_multiple_rows_multiple_times() : void ->run(); $rows = (new Flow())->extract( - Dbal::from_queries( + dbal_from_queries( $this->pgsqlDatabaseContext->connection(), "SELECT * FROM {$table} ORDER BY id LIMIT :limit OFFSET :offset", new ParametersSet( diff --git a/src/adapter/etl-adapter-elasticsearch/composer.json b/src/adapter/etl-adapter-elasticsearch/composer.json index 5c7c58b8e..3f354f2e5 100644 --- a/src/adapter/etl-adapter-elasticsearch/composer.json +++ b/src/adapter/etl-adapter-elasticsearch/composer.json @@ -27,7 +27,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Elasticsearch/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/Adapter/Elasticsearch/functions.php b/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/Adapter/Elasticsearch/functions.php new file mode 100644 index 000000000..639dfc8cc --- /dev/null +++ b/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/Adapter/Elasticsearch/functions.php @@ -0,0 +1,114 @@ +, + * connectionParams?: array, + * retries?: int, + * sniffOnStart?: boolean, + * sslCert?: array, + * sslKey?: array, + * sslVerification?: boolean|string, + * elasticMetaHeader?: boolean, + * includePortInHostHeader?: boolean + * } $config + * @param string $index + * @param IdFactory $id_factory + * @param array $parameters - https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html + * + * @return ElasticsearchLoader + */ +function to_es_bulk_index( + array $config, + string $index, + IdFactory $id_factory, + array $parameters = [] +) : ElasticsearchLoader { + return new ElasticsearchLoader($config, $index, $id_factory, $parameters); +} + +/** + * https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html. + * + * In order to control the size of the single request, use DataFrame::chunkSize() method just before calling DataFrame::load(). + * + * @param array{ + * hosts?: array, + * connectionParams?: array, + * retries?: int, + * sniffOnStart?: boolean, + * sslCert?: array, + * sslKey?: array, + * sslVerification?: boolean|string, + * elasticMetaHeader?: boolean, + * includePortInHostHeader?: boolean + * } $config + * @param string $index + * @param IdFactory $id_factory + * @param array $parameters - https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html + * + * @return Loader + */ +function to_es_bulk_update( + array $config, + string $index, + IdFactory $id_factory, + array $parameters = [] +) : Loader { + return ElasticsearchLoader::update($config, $index, $id_factory, $parameters); +} + +/** + * Transforms elasticsearch results into clear Flow Rows using ['hits']['hits'][x]['_source']. + * + * @return HitsIntoRowsTransformer + */ +function es_hits_to_rows(DocumentDataSource $source = DocumentDataSource::source) : HitsIntoRowsTransformer +{ + return new HitsIntoRowsTransformer($source); +} + +/** + * Extractor will automatically try to iterate over whole index using one of the two iteration methods:. + * + * - from/size + * - search_after + * + * Search after is selected when you provide define sort parameters in query, otherwise it will fallback to from/size. + * + * @param array{ + * hosts?: array, + * connectionParams?: array, + * retries?: int, + * sniffOnStart?: boolean, + * sslCert?: array, + * sslKey?: array, + * sslVerification?: boolean|string, + * elasticMetaHeader?: boolean, + * includePortInHostHeader?: boolean + * } $config + * @param array $params - https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html + * @param ?array $pit_params - when used extractor will create point in time to stabilize search results. Point in time is automatically closed when last element is extracted. https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + */ +function from_es(array $config, array $params, ?array $pit_params = null) : ElasticsearchExtractor +{ + return new ElasticsearchExtractor( + $config, + $params, + $pit_params, + ); +} diff --git a/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/DSL/Elasticsearch.php b/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/DSL/Elasticsearch.php index ddf83644e..5bb4690d6 100644 --- a/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/DSL/Elasticsearch.php +++ b/src/adapter/etl-adapter-elasticsearch/src/Flow/ETL/DSL/Elasticsearch.php @@ -13,6 +13,9 @@ use Flow\ETL\Loader; use Flow\ETL\Transformer; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class Elasticsearch { /** diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch7Context.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch7Context.php index c2a7d5637..be99ab378 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch7Context.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch7Context.php @@ -4,13 +4,13 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Context; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; use Elasticsearch\Client; use Elasticsearch\ClientBuilder; use Elasticsearch\Common\Exceptions\BadRequest400Exception; use Elasticsearch\Common\Exceptions\Missing404Exception; use Flow\ETL\Adapter\Elasticsearch\IdFactory; use Flow\ETL\Config; -use Flow\ETL\DSL\Elasticsearch; use Flow\ETL\FlowContext; use Flow\ETL\Rows; @@ -69,7 +69,7 @@ public function deleteIndex(string $name) : void public function loadRows(Rows $rows, string $index, IdFactory $idFactory) : void { - Elasticsearch::bulk_index( + to_es_bulk_index( $this->clientConfig(), $index, $idFactory, diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch8Context.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch8Context.php index 0a892a2e3..4c3bb19f1 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch8Context.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Context/Elasticsearch8Context.php @@ -4,12 +4,12 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Context; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; use Elastic\Elasticsearch\Client; use Elastic\Elasticsearch\ClientBuilder; use Elastic\Elasticsearch\Exception\ClientResponseException; use Flow\ETL\Adapter\Elasticsearch\IdFactory; use Flow\ETL\Config; -use Flow\ETL\DSL\Elasticsearch; use Flow\ETL\FlowContext; use Flow\ETL\Rows; @@ -68,7 +68,7 @@ public function deleteIndex(string $name) : void public function loadRows(Rows $rows, string $index, IdFactory $idFactory) : void { - Elasticsearch::bulk_index( + to_es_bulk_index( $this->clientConfig(), $index, $idFactory, diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php index 9893f2698..0bbc1af5b 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php @@ -4,11 +4,14 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration\ElasticsearchPHP; +use function Flow\ETL\Adapter\Elasticsearch\es_hits_to_rows; +use function Flow\ETL\Adapter\Elasticsearch\from_es; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; +use function Flow\ETL\DSL\df; use Flow\ETL\Adapter\Elasticsearch\ElasticsearchPHP\DocumentDataSource; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\EntryIdFactory; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; use Flow\ETL\Config; -use Flow\ETL\DSL\Elasticsearch; use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -35,7 +38,7 @@ protected function tearDown() : void public function test_empty_extraction() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( ...\array_map( @@ -66,8 +69,8 @@ public function test_empty_extraction() : void 'keep_alive' => '5m', ]; - $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params, $pitParams)) + $results = df() + ->read(from_es($this->elasticsearchContext->clientConfig(), $params, $pitParams)) ->fetch(); $this->assertCount(0, $results); @@ -75,7 +78,7 @@ public function test_empty_extraction() : void public function test_extraction_index_with_from_and_size() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( ...\array_map( @@ -105,8 +108,8 @@ public function test_extraction_index_with_from_and_size() : void ]; $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params)) - ->transform(Elasticsearch::hits_to_rows(DocumentDataSource::fields)) + ->extract(from_es($this->elasticsearchContext->clientConfig(), $params)) + ->transform(es_hits_to_rows(DocumentDataSource::fields)) ->fetch(); $this->assertCount(2000, $results); @@ -118,7 +121,7 @@ public function test_extraction_index_with_from_and_size() : void public function test_extraction_index_with_search_after() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( ...\array_map( @@ -146,7 +149,7 @@ public function test_extraction_index_with_search_after() : void ]; $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params)) + ->extract(from_es($this->elasticsearchContext->clientConfig(), $params)) ->fetch(); $this->assertCount(3, $results); @@ -154,7 +157,7 @@ public function test_extraction_index_with_search_after() : void public function test_extraction_index_with_search_after_with_point_in_time() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( ...\array_map( @@ -187,7 +190,7 @@ public function test_extraction_index_with_search_after_with_point_in_time() : v ]; $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params, $pitParams)) + ->extract(from_es($this->elasticsearchContext->clientConfig(), $params, $pitParams)) ->fetch(); $this->assertCount(3, $results); @@ -195,7 +198,7 @@ public function test_extraction_index_with_search_after_with_point_in_time() : v public function test_extraction_whole_index_with_point_in_time() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( ...\array_map( @@ -228,7 +231,7 @@ public function test_extraction_whole_index_with_point_in_time() : void ]; $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params, $pitParams)) + ->extract(from_es($this->elasticsearchContext->clientConfig(), $params, $pitParams)) ->fetch(); $this->assertCount(3, $results); diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php index f6a074a9c..a85be5c46 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php @@ -4,11 +4,12 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration\ElasticsearchPHP; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_update; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\EntryIdFactory; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\HashIdFactory; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; use Flow\ETL\Config; -use Flow\ETL\DSL\Elasticsearch; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -34,7 +35,7 @@ protected function tearDown() : void public function test_empty_rows() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows(), new FlowContext(Config::default())); @@ -54,7 +55,7 @@ public function test_empty_rows() : void public function test_integration_with_entry_factory() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new EntryIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( Row::create( @@ -96,7 +97,7 @@ public function test_integration_with_entry_factory() : void public function test_integration_with_json_entry() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( Row::create( @@ -125,7 +126,7 @@ public function test_integration_with_json_entry() : void public function test_integration_with_partial_update_id_factory() : void { - $insertLoader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); + $insertLoader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); $insertLoader->load(new Rows( Row::create( @@ -136,7 +137,7 @@ public function test_integration_with_partial_update_id_factory() : void ), ), new FlowContext(Config::default())); - $updateLoader = Elasticsearch::bulk_update($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); + $updateLoader = to_es_bulk_update($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); $updateLoader->load(new Rows( Row::create( @@ -182,7 +183,7 @@ public function test_integration_with_serialization() : void $serializer = new CompressingSerializer(); $loaderSerialized = $serializer->serialize( - Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]) + to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]) ); $serializer->unserialize($loaderSerialized)->load(new Rows( @@ -212,7 +213,7 @@ public function test_integration_with_serialization() : void public function test_integration_with_sha1_id_factory() : void { - $loader = Elasticsearch::bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); + $loader = to_es_bulk_index($this->elasticsearchContext->clientConfig(), self::INDEX_NAME, new HashIdFactory('id'), ['refresh' => true]); $loader->load(new Rows( Row::create( diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/IntegrationTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/IntegrationTest.php index 8f796e424..4924f9b13 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/IntegrationTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/IntegrationTest.php @@ -4,9 +4,11 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration\ElasticsearchPHP; +use function Flow\ETL\Adapter\Elasticsearch\es_hits_to_rows; +use function Flow\ETL\Adapter\Elasticsearch\from_es; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\EntryIdFactory; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Elasticsearch; use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -67,11 +69,11 @@ public function test_loading_and_extraction_with_limit_and_transformation() : vo ]; $results = (new Flow()) - ->extract(Elasticsearch::search($this->elasticsearchContext->clientConfig(), $params)) - ->rows(Elasticsearch::hits_to_rows()) + ->extract(from_es($this->elasticsearchContext->clientConfig(), $params)) + ->rows(es_hits_to_rows()) ->limit($limit = 20) ->load( - Elasticsearch::bulk_index( + to_es_bulk_index( $this->elasticsearchContext->clientConfig(), index: self::DESTINATION_INDEX, id_factory: new EntryIdFactory('id') diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchTest.php index 1178821a3..bf119277e 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchTest.php @@ -2,10 +2,10 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration; +use function Flow\ETL\Adapter\Elasticsearch\to_es_bulk_index; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\EntryIdFactory; use Flow\ETL\Adapter\Elasticsearch\Tests\Doubles\Spy\HttpClientSpy; -use Flow\ETL\DSL\Elasticsearch; -use Flow\ETL\DSL\From; use Flow\ETL\Flow; final class ElasticsearchTest extends TestCase @@ -17,7 +17,7 @@ public function test_batch_size_when_its_not_explicitly_set() : void } (new Flow()) - ->read(From::array([ + ->read(from_array([ ['id' => 1, 'text' => 'lorem ipsum'], ['id' => 2, 'text' => 'lorem ipsum'], ['id' => 3, 'text' => 'lorem ipsum'], @@ -26,7 +26,7 @@ public function test_batch_size_when_its_not_explicitly_set() : void ['id' => 6, 'text' => 'lorem ipsum'], ])) ->write( - Elasticsearch::bulk_index( + to_es_bulk_index( \array_merge( $this->elasticsearchContext->clientConfig(), ['httpClient' => $httpClient = new HttpClientSpy()] diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Unit/EntryIdFactory/HashIdFactoryTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Unit/EntryIdFactory/HashIdFactoryTest.php index 3112ae9d2..c7b29e5b2 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Unit/EntryIdFactory/HashIdFactoryTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Unit/EntryIdFactory/HashIdFactoryTest.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Unit; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\HashIdFactory; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function test_create_row() : void \hash('xxh128', 'John:Doe') ), $factory->create( - Row::create(Entry::string('first_name', 'John'), Entry::string('last_name', 'Doe')) + Row::create(str_entry('first_name', 'John'), str_entry('last_name', 'Doe')) ) ); } @@ -35,7 +35,7 @@ public function test_create_row_with_different_hash() : void \sha1('John:Doe') ), $factory->create( - Row::create(Entry::string('first_name', 'John'), Entry::string('last_name', 'Doe')) + Row::create(str_entry('first_name', 'John'), str_entry('last_name', 'Doe')) ) ); } diff --git a/src/adapter/etl-adapter-filesystem/src/Flow/ETL/Adapter/Filesystem/FlysystemFS.php b/src/adapter/etl-adapter-filesystem/src/Flow/ETL/Adapter/Filesystem/FlysystemFS.php index cbc25e441..48fe15e84 100644 --- a/src/adapter/etl-adapter-filesystem/src/Flow/ETL/Adapter/Filesystem/FlysystemFS.php +++ b/src/adapter/etl-adapter-filesystem/src/Flow/ETL/Adapter/Filesystem/FlysystemFS.php @@ -179,7 +179,6 @@ public function scan(Path $path, PartitionFilter $partitionFilter) : \Generator } $filter = function (FileAttributes|DirectoryAttributes $file) use ($path, $partitionFilter) : bool { - // var_dump($file->path()); if ($file instanceof DirectoryAttributes) { return false; } diff --git a/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php b/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php index 9f757baa3..ea0ed2118 100644 --- a/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php +++ b/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php @@ -4,11 +4,15 @@ namespace Flow\ETL\Adapter\Filesystem\Tests\Integration; +use function Flow\ETL\DSL\all; +use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\Filesystem\FlysystemFS; -use Flow\ETL\DSL\Partitions; use Flow\ETL\Filesystem\Path; use Flow\ETL\Filesystem\Stream\Mode; use Flow\ETL\Partition\NoopFilter; +use Flow\ETL\Partition\ScalarFunctionFilter; +use Flow\ETL\Row\Factory\NativeEntryFactory; use PHPUnit\Framework\TestCase; final class FlysystemFSTest extends TestCase @@ -81,9 +85,15 @@ public function test_reading_multi_partitioned_path() : void (new FlysystemFS()) ->scan( new Path(__DIR__ . '/Fixtures/multi_partitions'), - Partitions::chain( - Partitions::only('country', 'pl'), - Partitions::date_between('date', new \DateTimeImmutable('2022-01-02'), new \DateTimeImmutable('2022-01-04')) + new ScalarFunctionFilter( + all( + ref('country')->equals(lit('pl')), + all( + ref('date')->cast('date')->greaterThanEqual(lit(new \DateTimeImmutable('2022-01-02 00:00:00'))), + ref('date')->cast('date')->lessThan(lit(new \DateTimeImmutable('2022-01-04 00:00:00'))) + ) + ), + new NativeEntryFactory() ) ) ); @@ -122,7 +132,7 @@ public function test_reading_partitioned_folder_with_partitions_filtering() : vo (new FlysystemFS()) ->scan( new Path(__DIR__ . '/Fixtures/partitioned'), - Partitions::only('partition_01', 'b') + new ScalarFunctionFilter(ref('partition_01')->equals(lit('b')), new NativeEntryFactory()) ) ) ); diff --git a/src/adapter/etl-adapter-google-sheet/composer.json b/src/adapter/etl-adapter-google-sheet/composer.json index e0b84559a..8194aaf4c 100644 --- a/src/adapter/etl-adapter-google-sheet/composer.json +++ b/src/adapter/etl-adapter-google-sheet/composer.json @@ -26,7 +26,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/GoogleSheet/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/functions.php b/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/functions.php new file mode 100644 index 000000000..722ca8548 --- /dev/null +++ b/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/Adapter/GoogleSheet/functions.php @@ -0,0 +1,83 @@ +setScopes(Sheets::SPREADSHEETS_READONLY); + $client->setAuthConfig($auth_config); + $sheets = new Sheets($client); + } + + return new GoogleSheetExtractor( + $sheets, + $spreadsheet_id, + new Columns($sheet_name, 'A', 'Z'), + $with_header, + $rows_per_page, + $options, + ); +} + +/** + * @param array{type: string, project_id: string, private_key_id: string, private_key: string, client_email: string, client_id: string, auth_uri: string, token_uri: string, auth_provider_x509_cert_url: string, client_x509_cert_url: string}|Sheets $auth_config + * @param string $spreadsheet_id + * @param string $sheet_name + * @param string $start_range_column + * @param string $end_range_column + * @param bool $with_header + * @param int $rows_per_page - how many rows per page to fetch from Google Sheets API + * @param array{dateTimeRenderOption?: string, majorDimension?: string, valueRenderOption?: string} $options + */ +function from_google_sheet_columns( + array|Sheets $auth_config, + string $spreadsheet_id, + string $sheet_name, + string $start_range_column, + string $end_range_column, + bool $with_header = true, + int $rows_per_page = 1000, + array $options = [], +) : Extractor { + if ($auth_config instanceof Sheets) { + $sheets = $auth_config; + } else { + $client = new Client(); + $client->setScopes(Sheets::SPREADSHEETS_READONLY); + $client->setAuthConfig($auth_config); + $sheets = new Sheets($client); + } + + return new GoogleSheetExtractor( + $sheets, + $spreadsheet_id, + new Columns($sheet_name, $start_range_column, $end_range_column), + $with_header, + $rows_per_page, + $options, + ); +} diff --git a/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/DSL/GoogleSheet.php b/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/DSL/GoogleSheet.php index e6d9776a1..a94541128 100644 --- a/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/DSL/GoogleSheet.php +++ b/src/adapter/etl-adapter-google-sheet/src/Flow/ETL/DSL/GoogleSheet.php @@ -10,6 +10,9 @@ use Google\Client; use Google\Service\Sheets; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class GoogleSheet { /** diff --git a/src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/GoogleSheetExtractorTest.php b/src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/GoogleSheetExtractorTest.php index 906d0c79a..e19c975df 100644 --- a/src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/GoogleSheetExtractorTest.php +++ b/src/adapter/etl-adapter-google-sheet/tests/Flow/ETL/Adapter/GoogleSheet/Tests/Unit/GoogleSheetExtractorTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Adapter\GoogleSheet\Tests\Unit; +use function Flow\ETL\Adapter\GoogleSheet\from_google_sheet_columns; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\ConfigBuilder; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\GoogleSheet; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -20,7 +20,7 @@ final class GoogleSheetExtractorTest extends TestCase { public function test_its_stop_fetching_data_if_processed_row_count_is_less_then_last_range_end_row() : void { - $extractor = GoogleSheet::from_columns( + $extractor = from_google_sheet_columns( $service = $this->createMock(Sheets::class), $spreadSheetId = 'spread-id', $sheetName = 'sheet', @@ -50,9 +50,9 @@ public function test_its_stop_fetching_data_if_processed_row_count_is_less_then_ $rowsArray = \iterator_to_array($extractor->extract(new FlowContext((new ConfigBuilder())->putInputIntoRows()->build()))); $this->assertCount(2, $rowsArray); $this->assertSame(1, $rowsArray[0]->count()); - $this->assertEquals(Row::create($sheetNameEntry, $spreadSheetIdEntry, Entry::string('header', 'row1')), $rowsArray[0]->first()); + $this->assertEquals(Row::create($sheetNameEntry, $spreadSheetIdEntry, str_entry('header', 'row1')), $rowsArray[0]->first()); $this->assertSame(1, $rowsArray[1]->count()); - $this->assertEquals(Row::create($sheetNameEntry, $spreadSheetIdEntry, Entry::string('header', 'row2')), $rowsArray[1]->first()); + $this->assertEquals(Row::create($sheetNameEntry, $spreadSheetIdEntry, str_entry('header', 'row2')), $rowsArray[1]->first()); } public function test_rows_in_batch_must_be_positive_integer() : void @@ -60,7 +60,7 @@ public function test_rows_in_batch_must_be_positive_integer() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Rows per page must be greater than 0'); - GoogleSheet::from_columns( + from_google_sheet_columns( $this->createMock(Sheets::class), 'spread-id', 'sheet', @@ -73,7 +73,7 @@ public function test_rows_in_batch_must_be_positive_integer() : void public function test_works_for_no_data() : void { - $extractor = GoogleSheet::from_columns( + $extractor = from_google_sheet_columns( $service = $this->createMock(Sheets::class), 'spread-id', 'sheet', diff --git a/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientDynamicExtractor.php b/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientDynamicExtractor.php index e2c5bb341..5bd6f1086 100644 --- a/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientDynamicExtractor.php +++ b/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientDynamicExtractor.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Adapter\Http; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Adapter\Http\DynamicExtractor\NextRequestFactory; -use Flow\ETL\DSL\Entry; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -67,9 +68,9 @@ public function extract(FlowContext $context) : \Generator $responseFactory->create($response)->all(), $requestFactory->create($nextRequest)->all(), [ - Entry::string('request_uri', (string) $nextRequest->getUri()), - Entry::string('request_method', $nextRequest->getMethod()), - Entry::array('request_headers', $nextRequest->getHeaders()), + str_entry('request_uri', (string) $nextRequest->getUri()), + str_entry('request_method', $nextRequest->getMethod()), + array_entry('request_headers', $nextRequest->getHeaders()), ] ) ) diff --git a/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientStaticExtractor.php b/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientStaticExtractor.php index 351621d78..0f612800c 100644 --- a/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientStaticExtractor.php +++ b/src/adapter/etl-adapter-http/src/Flow/ETL/Adapter/Http/PsrHttpClientStaticExtractor.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Adapter\Http; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -61,9 +62,9 @@ public function extract(FlowContext $context) : \Generator $responseFactory->create($response)->all(), $requestFactory->create($request)->all(), [ - Entry::string('request_uri', (string) $request->getUri()), - Entry::string('request_method', $request->getMethod()), - Entry::array('request_headers', $request->getHeaders()), + str_entry('request_uri', (string) $request->getUri()), + str_entry('request_method', $request->getMethod()), + array_entry('request_headers', $request->getHeaders()), ] ) ) diff --git a/src/adapter/etl-adapter-json/composer.json b/src/adapter/etl-adapter-json/composer.json index b3cc26162..719185b8a 100644 --- a/src/adapter/etl-adapter-json/composer.json +++ b/src/adapter/etl-adapter-json/composer.json @@ -26,7 +26,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/JSON/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/functions.php b/src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/functions.php new file mode 100644 index 000000000..97a421ddc --- /dev/null +++ b/src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/functions.php @@ -0,0 +1,52 @@ +|Path|string $path - string is internally turned into LocalFile stream + * @param ?string $pointer - if you want to iterate only results of a subtree, use a pointer, read more at https://github.com/halaxa/json-machine#parsing-a-subtree + * + * @return Extractor + */ +function from_json( + string|Path|array $path, + ?string $pointer = null, +) : Extractor { + if (\is_array($path)) { + $extractors = []; + + foreach ($path as $file) { + $extractors[] = new JsonExtractor( + \is_string($file) ? Path::realpath($file) : $file, + $pointer, + ); + } + + return from_all(...$extractors); + } + + return new JsonExtractor( + \is_string($path) ? Path::realpath($path) : $path, + $pointer, + ); +} + +/** + * @param Path|string $path + * + * @return Loader + */ +function to_json(string|Path $path) : Loader +{ + return new JsonLoader( + \is_string($path) ? Path::realpath($path) : $path, + ); +} diff --git a/src/adapter/etl-adapter-json/src/Flow/ETL/DSL/Json.php b/src/adapter/etl-adapter-json/src/Flow/ETL/DSL/Json.php index 71a23f60b..0fb03ea19 100644 --- a/src/adapter/etl-adapter-json/src/Flow/ETL/DSL/Json.php +++ b/src/adapter/etl-adapter-json/src/Flow/ETL/DSL/Json.php @@ -10,6 +10,9 @@ use Flow\ETL\Filesystem\Path; use Flow\ETL\Loader; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class Json { /** diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonExtractorBench.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonExtractorBench.php index b54c544a4..88ce67355 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonExtractorBench.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\JSON\Tests\Benchmark; +use function Flow\ETL\Adapter\JSON\from_json; use Flow\ETL\Config; -use Flow\ETL\DSL\Json; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (Json::from(__DIR__ . '/../Fixtures/orders_flow.json')->extract($this->context) as $rows) { + foreach (from_json(__DIR__ . '/../Fixtures/orders_flow.json')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonLoaderBench.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonLoaderBench.php index f9f6724ab..f2ca84b87 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonLoaderBench.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Benchmark/JsonLoaderBench.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Adapter\JSON\Tests\Benchmark; +use function Flow\ETL\Adapter\JSON\from_json; +use function Flow\ETL\Adapter\JSON\to_json; use Flow\ETL\Config; -use Flow\ETL\DSL\Json; use Flow\ETL\FlowContext; use Flow\ETL\Rows; use PhpBench\Attributes\Groups; @@ -23,7 +24,7 @@ public function __construct() $this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_json_loader_bench') . '.json'; $this->rows = new Rows(); - foreach (Json::from(__DIR__ . '/../Fixtures/orders_flow.json')->extract($this->context) as $rows) { + foreach (from_json(__DIR__ . '/../Fixtures/orders_flow.json')->extract($this->context) as $rows) { $this->rows = $this->rows->merge($rows); } } @@ -39,6 +40,6 @@ public function __destruct() public function bench_load_10k() : void { - Json::to($this->outputPath)->load($this->rows, $this->context); + to_json($this->outputPath)->load($this->rows, $this->context); } } diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JSONMachine/JsonExtractorTest.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JSONMachine/JsonExtractorTest.php index 1de0f2307..ebb20e533 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JSONMachine/JsonExtractorTest.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JSONMachine/JsonExtractorTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Adapter\JSON\Tests\Integration\JSONMachine; +use function Flow\ETL\Adapter\JSON\from_json; +use function Flow\ETL\Adapter\JSON\to_json; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Adapter\JSON\JSONMachine\JsonExtractor; use Flow\ETL\Config; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Json; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; @@ -21,7 +22,7 @@ final class JsonExtractorTest extends TestCase public function test_extracting_json_from_local_file_stream() : void { $rows = (new Flow(Config::builder()->putInputIntoRows())) - ->read(Json::from(__DIR__ . '/../../Fixtures/timezones.json')) + ->read(from_json(__DIR__ . '/../../Fixtures/timezones.json')) ->fetch(); foreach ($rows as $row) { @@ -44,7 +45,7 @@ public function test_extracting_json_from_local_file_stream() : void public function test_extracting_json_from_local_file_stream_using_pointer() : void { $rows = (new Flow()) - ->read(Json::from(__DIR__ . '/../../Fixtures/nested_timezones.json', pointer: '/timezones')) + ->read(from_json(__DIR__ . '/../../Fixtures/nested_timezones.json', pointer: '/timezones')) ->fetch(); foreach ($rows as $row) { @@ -99,8 +100,8 @@ public function test_limit() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Json::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_json($path)) ->run(); $extractor = new JsonExtractor(Path::realpath($path)); @@ -120,8 +121,8 @@ public function test_signal_stop() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Json::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_json($path)) ->run(); $extractor = new JsonExtractor(Path::realpath($path)); @@ -144,6 +145,6 @@ public function test_using_pattern_path() : void { $this->expectExceptionMessage("JsonLoader path can't be pattern, given: /path/*/pattern.json"); - Json::to(new Path('/path/*/pattern.json')); + to_json(new Path('/path/*/pattern.json')); } } diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php index eac4f1483..47f49aaee 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonLoaderTest.php @@ -4,11 +4,13 @@ namespace Flow\ETL\Adapter\JSON\Tests\Integration; +use function Flow\ETL\Adapter\Json\from_json; +use function Flow\ETL\Adapter\Json\to_json; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; use Flow\ETL\Adapter\JSON\JsonLoader; use Flow\ETL\Config; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Json; use Flow\ETL\Filesystem\Path; use Flow\ETL\Filesystem\SaveMode; use Flow\ETL\Flow; @@ -35,7 +37,7 @@ public function test_json_loader() : void ) ) ) - ->write(Json::to($stream)) + ->write(to_json($stream)) ->run(); $this->assertJsonStringEqualsJsonString( @@ -153,8 +155,8 @@ public function test_save_mode_ignore_on_partitioned_rows() : void \unlink($path); } - (new Flow) - ->read(From::array([ + df() + ->read(from_array([ ['id' => 1, 'partition' => 'a'], ['id' => 2, 'partition' => 'a'], ['id' => 3, 'partition' => 'a'], @@ -163,17 +165,17 @@ public function test_save_mode_ignore_on_partitioned_rows() : void ])) ->partitionBy(ref('partition')) ->mode(SaveMode::Overwrite) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); - (new Flow) - ->read(From::array([ + df() + ->read(from_array([ ['id' => 8, 'partition' => 'b'], ['id' => 10, 'partition' => 'b'], ])) ->partitionBy(ref('partition')) ->mode(SaveMode::Ignore) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); $this->assertSame( @@ -184,8 +186,8 @@ public function test_save_mode_ignore_on_partitioned_rows() : void ['id' => 4, 'partition' => 'b'], ['id' => 5, 'partition' => 'b'], ], - (new Flow()) - ->read(Json::from($path)) + df() + ->read(from_json($path)) ->fetch() ->toArray() ); @@ -200,7 +202,7 @@ public function test_save_mode_overwrite_on_partitioned_rows() : void } (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 1, 'partition' => 'a'], ['id' => 2, 'partition' => 'a'], ['id' => 3, 'partition' => 'a'], @@ -209,17 +211,17 @@ public function test_save_mode_overwrite_on_partitioned_rows() : void ])) ->partitionBy(ref('partition')) ->mode(SaveMode::Overwrite) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 8, 'partition' => 'b'], ['id' => 10, 'partition' => 'b'], ])) ->partitionBy(ref('partition')) ->mode(SaveMode::Overwrite) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); $this->assertSame( @@ -231,7 +233,7 @@ public function test_save_mode_overwrite_on_partitioned_rows() : void ['id' => 10, 'partition' => 'b'], ], (new Flow()) - ->read(Json::from($path)) + ->read(from_json($path)) ->fetch() ->toArray() ); @@ -246,7 +248,7 @@ public function test_save_mode_throw_exception_on_partitioned_rows() : void } (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 1, 'partition' => 'a'], ['id' => 2, 'partition' => 'a'], ['id' => 3, 'partition' => 'a'], @@ -255,19 +257,19 @@ public function test_save_mode_throw_exception_on_partitioned_rows() : void ])) ->partitionBy(ref('partition')) ->mode(SaveMode::ExceptionIfExists) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); $this->expectExceptionMessage('Destination path "file:/' . $path . '/partition=b" already exists, please change path to different or set different SaveMode'); (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 8, 'partition' => 'b'], ['id' => 10, 'partition' => 'b'], ])) ->partitionBy(ref('partition')) ->mode(SaveMode::ExceptionIfExists) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); } @@ -281,23 +283,23 @@ public function test_save_with_ignore_mode() : void } (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], ])) ->mode(SaveMode::Ignore) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); (new Flow) - ->read(From::array([ + ->read(from_array([ ['id' => 4], ['id' => 5], ['id' => 6], ])) ->mode(SaveMode::Ignore) - ->write(Json::to($path)) + ->write(to_json($path)) ->run(); $this->assertSame( @@ -307,7 +309,7 @@ public function test_save_with_ignore_mode() : void ['id' => 3], ], (new Flow) - ->read(Json::from($path)) + ->read(from_json($path)) ->fetch() ->toArray() ); diff --git a/src/adapter/etl-adapter-meilisearch/composer.json b/src/adapter/etl-adapter-meilisearch/composer.json index 43dfbc67c..d4ba0ca20 100644 --- a/src/adapter/etl-adapter-meilisearch/composer.json +++ b/src/adapter/etl-adapter-meilisearch/composer.json @@ -27,7 +27,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Meilisearch/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/Adapter/Meilisearch/functions.php b/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/Adapter/Meilisearch/functions.php new file mode 100644 index 000000000..03d377907 --- /dev/null +++ b/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/Adapter/Meilisearch/functions.php @@ -0,0 +1,47 @@ +, sort: ?array} $params + */ +function from_meilisearch(array $config, array $params, string $index) : MeilisearchExtractor +{ + return new MeilisearchExtractor($config, $params, $index); +} diff --git a/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/DSL/Meilisearch.php b/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/DSL/Meilisearch.php index 86a485b0f..529a3d01b 100644 --- a/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/DSL/Meilisearch.php +++ b/src/adapter/etl-adapter-meilisearch/src/Flow/ETL/DSL/Meilisearch.php @@ -12,6 +12,9 @@ use Flow\ETL\Transformer; use Psr\Http\Client\ClientInterface; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class Meilisearch { /** diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Context/MeilisearchContext.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Context/MeilisearchContext.php index 47be0c7e4..f4fd6a9f0 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Context/MeilisearchContext.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Context/MeilisearchContext.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Adapter\Meilisearch\Tests\Context; +use function Flow\ETL\Adapter\Meilisearch\to_meilisearch_bulk_index; use Flow\ETL\Config; -use Flow\ETL\DSL\Meilisearch; use Flow\ETL\FlowContext; use Flow\ETL\Rows; use Meilisearch\Client; @@ -62,7 +62,7 @@ public function deleteIndex(string $name) : void public function loadRows(Rows $rows, string $index) : void { - Meilisearch::bulk_index( + to_meilisearch_bulk_index( $this->clientConfig(), $index ) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MailiSearchTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MailiSearchTest.php index 0ff0d0d55..0ab4a62e1 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MailiSearchTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MailiSearchTest.php @@ -4,10 +4,12 @@ namespace Flow\ETL\Adapter\Meilisearch\Tests\Integration\MeilisearchPHP; +use function Flow\ETL\Adapter\Meilisearch\from_meilisearch; +use function Flow\ETL\Adapter\Meilisearch\meilisearch_hits_to_rows; +use function Flow\ETL\Adapter\Meilisearch\to_meilisearch_bulk_index; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Adapter\Meilisearch\Tests\Context\MeilisearchContext; use Flow\ETL\Adapter\Meilisearch\Tests\Double\Spy\HttpClientSpy; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Meilisearch; use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -41,7 +43,7 @@ protected function tearDown() : void public function test_batch_size_when_its_not_explicitly_set() : void { (new Flow()) - ->read(From::array([ + ->read(from_array([ ['id' => 1, 'text' => 'lorem ipsum'], ['id' => 2, 'text' => 'lorem ipsum'], ['id' => 3, 'text' => 'lorem ipsum'], @@ -50,7 +52,7 @@ public function test_batch_size_when_its_not_explicitly_set() : void ['id' => 6, 'text' => 'lorem ipsum'], ])) ->write( - Meilisearch::bulk_index( + to_meilisearch_bulk_index( \array_merge( $this->meilisearchContext->clientConfig(), ['httpClient' => $httpClient = new HttpClientSpy()] @@ -89,11 +91,11 @@ public function test_loading_and_extraction_with_limit_and_transformation() : vo ]; $results = (new Flow()) - ->extract(Meilisearch::search($this->meilisearchContext->clientConfig(), $params, self::SOURCE_INDEX)) - ->rows(Meilisearch::hits_to_rows()) + ->extract(from_meilisearch($this->meilisearchContext->clientConfig(), $params, self::SOURCE_INDEX)) + ->rows(meilisearch_hits_to_rows()) ->limit($limit) ->load( - Meilisearch::bulk_index( + to_meilisearch_bulk_index( $this->meilisearchContext->clientConfig(), self::DESTINATION_INDEX ) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php index e51740893..ca802b84a 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php @@ -4,9 +4,11 @@ namespace Flow\ETL\Adapter\Meilisearch\Tests\Integration\MeilisearchPHP; +use function Flow\ETL\Adapter\Meilisearch\from_meilisearch; +use function Flow\ETL\Adapter\Meilisearch\meilisearch_hits_to_rows; +use function Flow\ETL\Adapter\Meilisearch\to_meilisearch_bulk_index; use Flow\ETL\Adapter\Meilisearch\Tests\Context\MeilisearchContext; use Flow\ETL\Config; -use Flow\ETL\DSL\Meilisearch; use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -34,7 +36,7 @@ protected function tearDown() : void public function test_empty_extraction() : void { - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( ...\array_map( static fn (int $i) : Row => Row::create( @@ -52,7 +54,7 @@ public function test_empty_extraction() : void ]; $results = (new Flow()) - ->extract(Meilisearch::search($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) + ->extract(from_meilisearch($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) ->fetch(); $this->assertCount(0, $results); @@ -60,7 +62,7 @@ public function test_empty_extraction() : void public function test_extraction_index_with_from_and_size() : void { - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( ...\array_map( static fn (int $i) : Row => Row::create( @@ -84,8 +86,8 @@ public function test_extraction_index_with_from_and_size() : void ]; $results = (new Flow()) - ->extract(Meilisearch::search($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) - ->transform(Meilisearch::hits_to_rows()) + ->extract(from_meilisearch($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) + ->transform(meilisearch_hits_to_rows()) ->fetch(); $this->assertCount(999, $results); @@ -99,7 +101,7 @@ public function test_extraction_index_with_sort() : void { $this->meilisearchContext->client()->index(self::INDEX_NAME)->updateSettings(['sortableAttributes' => ['position']]); - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( ...\array_map( static fn (int $i) : Row => Row::create( @@ -119,7 +121,7 @@ public function test_extraction_index_with_sort() : void ]; $results = (new Flow()) - ->extract(Meilisearch::search($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) + ->extract(from_meilisearch($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME)) ->fetch(); $this->assertCount(999, $results); diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php index a0fa829a3..888d9e857 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Adapter\Meilisearch\Tests\Integration\MeilisearchPHP; +use function Flow\ETL\Adapter\Meilisearch\to_meilisearch_bulk_index; +use function Flow\ETL\Adapter\Meilisearch\to_meilisearch_bulk_update; use Flow\ETL\Adapter\Meilisearch\Tests\Context\MeilisearchContext; use Flow\ETL\Config; -use Flow\ETL\DSL\Meilisearch; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -34,7 +35,7 @@ protected function tearDown() : void public function test_empty_rows() : void { - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows(), new FlowContext(Config::default())); $response = $this->meilisearchContext->client()->index(self::INDEX_NAME)->search('', ['page' => 1]); @@ -44,7 +45,7 @@ public function test_empty_rows() : void public function test_integration_with_entry_factory() : void { - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( Row::create( new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), @@ -76,7 +77,7 @@ public function test_integration_with_entry_factory() : void public function test_integration_with_json_entry() : void { - $loader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( Row::create( new Row\Entry\IntegerEntry('id', 1), @@ -95,7 +96,7 @@ public function test_integration_with_json_entry() : void public function test_integration_with_partial_update_id_factory() : void { - $insertLoader = Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $insertLoader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $insertLoader->load(new Rows( Row::create( new Row\Entry\IntegerEntry('id', 1), @@ -105,7 +106,7 @@ public function test_integration_with_partial_update_id_factory() : void ), ), new FlowContext(Config::default())); - $updateLoader = Meilisearch::bulk_update($this->meilisearchContext->clientConfig(), self::INDEX_NAME); + $updateLoader = to_meilisearch_bulk_update($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $updateLoader->load(new Rows( Row::create( new Row\Entry\IntegerEntry('id', 1), @@ -141,7 +142,7 @@ public function test_integration_with_serialization() : void $serializer = new CompressingSerializer(); $loaderSerialized = $serializer->serialize( - Meilisearch::bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME) + to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME) ); $serializer->unserialize($loaderSerialized)->load(new Rows( diff --git a/src/adapter/etl-adapter-parquet/composer.json b/src/adapter/etl-adapter-parquet/composer.json index 06e1dea69..d8c94fb16 100644 --- a/src/adapter/etl-adapter-parquet/composer.json +++ b/src/adapter/etl-adapter-parquet/composer.json @@ -26,7 +26,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Parquet/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php index d1af91c04..1e5b055fe 100644 --- a/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php +++ b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/SchemaConverter.php @@ -2,13 +2,18 @@ namespace Flow\ETL\Adapter\Parquet; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_null; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\NullType; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; @@ -266,21 +271,21 @@ private function typeFromDefinition(Definition $definition) : Type switch ($type) { case Entry\IntegerEntry::class: - return ScalarType::integer($definition->isNullable()); + return type_int($definition->isNullable()); case Entry\BooleanEntry::class: - return ScalarType::boolean($definition->isNullable()); + return type_boolean($definition->isNullable()); case Entry\FloatEntry::class: - return ScalarType::float($definition->isNullable()); + return type_float($definition->isNullable()); case Entry\EnumEntry::class: case Entry\JsonEntry::class: case Entry\StringEntry::class: - return ScalarType::string($definition->isNullable()); + return type_string($definition->isNullable()); case Entry\NullEntry::class: - return new NullType(); + return type_null(); case Entry\DateTimeEntry::class: - return new ObjectType(\DateTimeInterface::class, $definition->isNullable()); + return type_object(\DateTimeInterface::class, $definition->isNullable()); case Entry\UuidEntry::class: - return new ObjectType(Entry\Type\Uuid::class, $definition->isNullable()); + return type_object(Entry\Type\Uuid::class, $definition->isNullable()); } throw new RuntimeException($type . ' is not supported.'); diff --git a/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php new file mode 100644 index 000000000..ff6305cea --- /dev/null +++ b/src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/functions.php @@ -0,0 +1,73 @@ +|Path|string $uri + * @param array $columns + * + * @return Extractor + */ +function from_parquet( + string|Path|array $uri, + array $columns = [], + Options $options = new Options(), + ByteOrder $byte_order = ByteOrder::LITTLE_ENDIAN, +) : Extractor { + if (\is_array($uri)) { + $extractors = []; + + foreach ($uri as $filePath) { + $extractors[] = new ParquetExtractor( + $filePath, + $options, + $byte_order, + $columns + ); + } + + return from_all(...$extractors); + } + + return new ParquetExtractor( + \is_string($uri) ? Path::realpath($uri) : $uri, + $options, + $byte_order, + $columns + ); +} + +/** + * @param Path|string $path + * @param null|Schema $schema + * + * @return Loader + */ +function to_parquet( + string|Path $path, + ?Options $options = null, + Compressions $compressions = Compressions::SNAPPY, + ?Schema $schema = null, +) : Loader { + if ($options === null) { + $options = Options::default(); + } + + return new ParquetLoader( + \is_string($path) ? Path::realpath($path) : $path, + $options, + $compressions, + $schema, + ); +} diff --git a/src/adapter/etl-adapter-parquet/src/Flow/ETL/DSL/Parquet.php b/src/adapter/etl-adapter-parquet/src/Flow/ETL/DSL/Parquet.php index 28aa16fc2..d82b627d0 100644 --- a/src/adapter/etl-adapter-parquet/src/Flow/ETL/DSL/Parquet.php +++ b/src/adapter/etl-adapter-parquet/src/Flow/ETL/DSL/Parquet.php @@ -15,6 +15,8 @@ use Flow\Parquet\ParquetFile\Compressions; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class Parquet diff --git a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetExtractorBench.php b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetExtractorBench.php index 34b22029b..b96419f3b 100644 --- a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetExtractorBench.php +++ b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\Parquet\Tests\Benchmark; +use function Flow\ETL\Adapter\Parquet\from_parquet; use Flow\ETL\Config; -use Flow\ETL\DSL\Parquet; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (Parquet::from(__DIR__ . '/../Fixtures/orders_flow.parquet')->extract($this->context) as $rows) { + foreach (from_parquet(__DIR__ . '/../Fixtures/orders_flow.parquet')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetLoaderBench.php b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetLoaderBench.php index 9def2be19..b863c8b28 100644 --- a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetLoaderBench.php +++ b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Benchmark/ParquetLoaderBench.php @@ -2,9 +2,10 @@ namespace Flow\ETL\Adapter\Parquet\Tests\Benchmark; +use function Flow\ETL\Adapter\Parquet\from_parquet; +use function Flow\ETL\Adapter\Parquet\to_parquet; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\Parquet; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -25,9 +26,9 @@ public function __construct() $this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_parquet_loader_bench') . '.parquet'; $this->rows = new Rows(); - foreach (Parquet::from(__DIR__ . '/../Fixtures/orders_flow.parquet')->extract($this->context) as $rows) { + foreach (from_parquet(__DIR__ . '/../Fixtures/orders_flow.parquet')->extract($this->context) as $rows) { $rows = $rows->map(static function (Row $row) : Row { - return $row->set(Entry::str('order_id', $row->valueOf('order_id')->toString())); + return $row->set(str_entry('order_id', $row->valueOf('order_id')->toString())); }); $this->rows = $this->rows->merge($rows); @@ -45,6 +46,6 @@ public function __destruct() public function bench_load_10k() : void { - Parquet::to($this->outputPath)->load($this->rows, $this->context); + to_parquet($this->outputPath)->load($this->rows, $this->context); } } diff --git a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetExtractorTest.php b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetExtractorTest.php index 1bce4694a..6f8ea591e 100644 --- a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetExtractorTest.php +++ b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetExtractorTest.php @@ -2,10 +2,10 @@ namespace Flow\ETL\Adapter\Parquet\Tests\Integration; +use function Flow\ETL\Adapter\Parquet\to_parquet; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Adapter\Parquet\ParquetExtractor; use Flow\ETL\Config; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Parquet; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; @@ -23,8 +23,8 @@ public function test_limit() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Parquet::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_parquet($path)) ->run(); $extractor = new ParquetExtractor(Path::realpath($path), Options::default()); @@ -44,8 +44,8 @@ public function test_signal_stop() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Parquet::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_parquet($path)) ->run(); $extractor = new ParquetExtractor(Path::realpath($path), Options::default()); diff --git a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetTest.php b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetTest.php index 555c88e52..a4fef36f9 100644 --- a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetTest.php +++ b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Integration/ParquetTest.php @@ -2,14 +2,27 @@ namespace Flow\ETL\Adapter\Parquet\Tests\Integration; +use function Flow\ETL\Adapter\Parquet\from_parquet; +use function Flow\ETL\Adapter\Parquet\to_parquet; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\json_entry; +use function Flow\ETL\DSL\json_object_entry; +use function Flow\ETL\DSL\list_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Parquet; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Flow; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\Parquet\ParquetFile\Compressions; @@ -23,15 +36,15 @@ public function test_writing_to_file() : void $path = \sys_get_temp_dir() . '/file.snappy.parquet'; $this->removeFile($path); - (new Flow()) - ->read(From::rows($rows = $this->createRows(10))) - ->write(Parquet::to($path)) + df() + ->read(from_rows($rows = $this->createRows(10))) + ->write(to_parquet($path)) ->run(); $this->assertEquals( $rows, (new Flow()) - ->read(Parquet::from($path)) + ->read(from_parquet($path)) ->fetch() ); @@ -51,8 +64,8 @@ public function test_writing_with_partitioning() : void $path = \sys_get_temp_dir() . '/partitioned'; $this->cleanDirectory($path); - (new Flow()) - ->read(From::rows($rows = new Rows( + df() + ->read(from_rows($rows = new Rows( $this->createRow(1, new \DateTimeImmutable('2020-01-01 00:01:00')), $this->createRow(1, new \DateTimeImmutable('2020-01-01 00:02:00')), $this->createRow(1, new \DateTimeImmutable('2020-01-02 00:01:00')), @@ -61,13 +74,13 @@ public function test_writing_with_partitioning() : void ))) ->withEntry('date', ref('datetime')->toDate()->dateFormat()) ->partitionBy(ref('date')) - ->write(Parquet::to($path)) + ->write(to_parquet($path)) ->run(); $this->assertEquals( $rows, (new Flow()) - ->read(Parquet::from($path)) + ->read(from_parquet($path)) ->drop('date') ->sortBy(ref('datetime')->asc()) ->fetch() @@ -104,16 +117,16 @@ private function cleanDirectory(string $path) : void private function createRow(int $index, ?\DateTimeImmutable $dateTime = null) : Row { return Row::create( - Entry::integer('integer', $index), - Entry::float('float', 1.5), - Entry::string('string', 'name_' . $index), - Entry::boolean('boolean', true), - Entry::datetime('datetime', $dateTime ?: new \DateTimeImmutable()), - Entry::json_object('json_object', ['id' => 1, 'name' => 'test']), - Entry::json('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), - Entry::list_of_string('list_of_strings', ['a', 'b', 'c']), - Entry::list_of_datetime('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()]), - Entry::structure( + int_entry('integer', $index), + float_entry('float', 1.5), + str_entry('string', 'name_' . $index), + bool_entry('boolean', true), + datetime_entry('datetime', $dateTime ?: new \DateTimeImmutable()), + json_object_entry('json_object', ['id' => 1, 'name' => 'test']), + json_entry('json', [['id' => 1, 'name' => 'test'], ['id' => 2, 'name' => 'test']]), + list_entry('list_of_strings', ['a', 'b', 'c'], type_list(type_string())), + list_entry('list_of_datetimes', [new \DateTimeImmutable(), new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))), + struct_entry( 'address', [ 'street' => 'street_' . $index, @@ -122,16 +135,16 @@ private function createRow(int $index, ?\DateTimeImmutable $dateTime = null) : R 'country' => 'country_' . $index, 'location' => ['lat' => 1.5, 'lon' => 1.5], ], - new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), - new StructureElement('zip', ScalarType::string()), - new StructureElement('country', ScalarType::string()), - new StructureElement( + struct_type( + struct_element('street', type_string()), + struct_element('city', type_string()), + struct_element('zip', type_string()), + struct_element('country', type_string()), + struct_element( 'location', - new StructureType( - new StructureElement('lat', ScalarType::float()), - new StructureElement('lon', ScalarType::float()), + struct_type( + struct_element('lat', type_float()), + struct_element('lon', type_float()), ) ) ), diff --git a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Unit/SchemaConverterTest.php b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Unit/SchemaConverterTest.php index f22d91b61..4854812e6 100644 --- a/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Unit/SchemaConverterTest.php +++ b/src/adapter/etl-adapter-parquet/tests/Flow/ETL/Adapter/Parquet/Tests/Unit/SchemaConverterTest.php @@ -4,6 +4,8 @@ namespace Flow\ETL\Adapter\Parquet\Tests\Unit; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Adapter\Parquet\SchemaConverter; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\PHP\Type\Logical\List\ListElement; @@ -13,8 +15,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Schema; use Flow\Parquet\ParquetFile\Schema as ParquetSchema; use Flow\Parquet\ParquetFile\Schema\FlatColumn; @@ -56,9 +56,9 @@ public function test_convert_etl_entries_to_parquet_fields() : void Schema\Definition::dateTime('datetime'), Schema\Definition::json('json'), Schema\Definition::list('list', new ListType(ListElement::string())), - Schema\Definition::structure('structure', new StructureType(new StructureElement('a', ScalarType::string()))), + Schema\Definition::structure('structure', new StructureType(new StructureElement('a', type_string()))), Schema\Definition::map('map', new MapType(MapKey::string(), MapValue::integer())), - Schema\Definition::object('time', new ObjectType(\DateInterval::class, false)) + Schema\Definition::object('time', type_object(\DateInterval::class, false)) )) ); } @@ -69,7 +69,7 @@ public function test_convert_object_entry_to_parquet_array() : void $this->expectExceptionMessage("stdClass can't be converted to any parquet columns."); (new SchemaConverter())->toParquet(new Schema( - Schema\Definition::object('object', new ObjectType(\stdClass::class, false)) + Schema\Definition::object('object', type_object(\stdClass::class, false)) )); } } diff --git a/src/adapter/etl-adapter-text/composer.json b/src/adapter/etl-adapter-text/composer.json index 55e7c9f8f..2eb364f33 100644 --- a/src/adapter/etl-adapter-text/composer.json +++ b/src/adapter/etl-adapter-text/composer.json @@ -24,7 +24,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/Text/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-text/src/Flow/ETL/Adapter/Text/functions.php b/src/adapter/etl-adapter-text/src/Flow/ETL/Adapter/Text/functions.php new file mode 100644 index 000000000..8eb7c1dda --- /dev/null +++ b/src/adapter/etl-adapter-text/src/Flow/ETL/Adapter/Text/functions.php @@ -0,0 +1,50 @@ +|Path|string $path + * + * @return Extractor + */ +function from_text( + string|Path|array $path, +) : Extractor { + if (\is_array($path)) { + $extractors = []; + + foreach ($path as $file_path) { + $extractors[] = new TextExtractor( + \is_string($file_path) ? Path::realpath($file_path) : $file_path, + ); + } + + return new Extractor\ChainExtractor(...$extractors); + } + + return new TextExtractor( + \is_string($path) ? Path::realpath($path) : $path, + ); +} + +/** + * @param Path|string $path + * @param string $new_line_separator + * + * @return Loader + */ +function to_text( + string|Path $path, + string $new_line_separator = PHP_EOL +) : Loader { + return new TextLoader( + \is_string($path) ? Path::realpath($path) : $path, + $new_line_separator + ); +} diff --git a/src/adapter/etl-adapter-text/src/Flow/ETL/DSL/Text.php b/src/adapter/etl-adapter-text/src/Flow/ETL/DSL/Text.php index 73d8a53c5..803e2b29d 100644 --- a/src/adapter/etl-adapter-text/src/Flow/ETL/DSL/Text.php +++ b/src/adapter/etl-adapter-text/src/Flow/ETL/DSL/Text.php @@ -10,6 +10,9 @@ use Flow\ETL\Filesystem\Path; use Flow\ETL\Loader; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class Text { /** diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextExtractorBench.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextExtractorBench.php index d6fce86d7..2d71b2df4 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextExtractorBench.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\Text\Tests\Benchmark; +use function Flow\ETL\Adapter\Text\from_text; use Flow\ETL\Config; -use Flow\ETL\DSL\Text; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (Text::from(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { + foreach (from_text(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextLoaderBench.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextLoaderBench.php index 24a0aa1e8..5f6dec61e 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextLoaderBench.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Benchmark/TextLoaderBench.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Adapter\Text\Tests\Benchmark; +use function Flow\ETL\Adapter\Text\from_text; +use function Flow\ETL\Adapter\Text\to_text; use Flow\ETL\Config; -use Flow\ETL\DSL\Text; use Flow\ETL\FlowContext; use Flow\ETL\Rows; use PhpBench\Attributes\Groups; @@ -23,7 +24,7 @@ public function __construct() $this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_txt_loader_bench') . '.txt'; $this->rows = new Rows(); - foreach (Text::from(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { + foreach (from_text(__DIR__ . '/../Fixtures/orders_flow.csv')->extract($this->context) as $rows) { $this->rows = $this->rows->merge($rows); } } @@ -39,6 +40,6 @@ public function __destruct() public function bench_load_10k() : void { - Text::to($this->outputPath)->load($this->rows, $this->context); + to_text($this->outputPath)->load($this->rows, $this->context); } } diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextExtractorTest.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextExtractorTest.php index 45f006600..67dd6ae66 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextExtractorTest.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextExtractorTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Adapter\Text\Tests\Integration; +use function Flow\ETL\Adapter\Text\from_text; +use function Flow\ETL\Adapter\Text\to_text; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Adapter\Text\TextExtractor; use Flow\ETL\Config; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\Text; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; @@ -23,7 +24,7 @@ public function test_extracting_text_file() : void $path = __DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv'; $rows = (new Flow()) - ->read(Text::from($path)) + ->read(from_text($path)) ->fetch(); foreach ($rows as $row) { @@ -35,7 +36,7 @@ public function test_extracting_text_file() : void public function test_extracting_text_files_from_directory() : void { - $extractor = Text::from( + $extractor = from_text( [ __DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv', __DIR__ . '/../Fixtures/nested/annual-enterprise-survey-2019-financial-year-provisional-csv.csv', @@ -63,8 +64,8 @@ public function test_limit() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Text::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_text($path)) ->run(); $extractor = new TextExtractor(Path::realpath($path)); $extractor->changeLimit(2); @@ -83,8 +84,8 @@ public function test_signal_stop() : void \unlink($path); } - (new Flow())->read(From::array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) - ->write(Text::to($path)) + (new Flow())->read(from_array([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]])) + ->write(to_text($path)) ->run(); $extractor = new TextExtractor(Path::realpath($path)); diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextLoaderTest.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextLoaderTest.php index fef36421c..0f7915725 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextLoaderTest.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextLoaderTest.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Adapter\Text\Tests\Integration; -use Flow\ETL\DSL\Text; +use function Flow\ETL\Adapter\Text\to_text; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; use Flow\ETL\Row; @@ -26,7 +26,7 @@ public function test_loading_text_files_with_append_safe() : void Row::create(new Row\Entry\StringEntry('name', 'Dawid')), ) ) - ->load(Text::to($path)) + ->write(to_text($path)) ->appendSafe() ->run(); @@ -58,7 +58,7 @@ public function test_loading_text_files_without_safe_mode() : void Row::create(new Row\Entry\StringEntry('name', 'Dawid')), ) ) - ->load(Text::to($path)) + ->write(to_text($path)) ->run(); $this->assertStringContainsString( @@ -89,7 +89,7 @@ public function test_loading_text_files_without_safe_mode_and_with_serialization Row::create(new Row\Entry\StringEntry('name', 'Dawid')), ) ) - ->load($serializer->unserialize($serializer->serialize(Text::to($path)))) + ->write($serializer->unserialize($serializer->serialize(to_text($path)))) ->run(); $this->assertStringContainsString( @@ -110,6 +110,6 @@ public function test_using_pattern_path() : void { $this->expectExceptionMessage("TextLoader path can't be pattern, given: /path/*/pattern.csv"); - Text::to(new Path('/path/*/pattern.csv')); + to_text(new Path('/path/*/pattern.csv')); } } diff --git a/src/adapter/etl-adapter-xml/composer.json b/src/adapter/etl-adapter-xml/composer.json index bcd5e2283..d1b9d177b 100644 --- a/src/adapter/etl-adapter-xml/composer.json +++ b/src/adapter/etl-adapter-xml/composer.json @@ -26,7 +26,10 @@ "Flow\\": [ "src/Flow" ] - } + }, + "files": [ + "src/Flow/ETL/Adapter/XML/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/XMLReaderExtractor.php b/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/XMLReaderExtractor.php index cd5beb0bf..01b5506ab 100644 --- a/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/XMLReaderExtractor.php +++ b/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/XMLReaderExtractor.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Adapter\XML; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\xml_entry; use Flow\ETL\Extractor; use Flow\ETL\Extractor\FileExtractor; use Flow\ETL\Extractor\Limitable; @@ -78,11 +79,11 @@ public function extract(FlowContext $context) : \Generator if ($shouldPutInputIntoRows) { $row = Row::create( - Entry::xml('node', $node), - Entry::string('_input_file_uri', $filePath->uri()) + xml_entry('node', $node), + str_entry('_input_file_uri', $filePath->uri()) ); } else { - $row = Row::create(Entry::xml('node', $node)); + $row = Row::create(xml_entry('node', $node)); } $signal = yield \count($partitions) diff --git a/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/functions.php b/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/functions.php new file mode 100644 index 000000000..914d5784f --- /dev/null +++ b/src/adapter/etl-adapter-xml/src/Flow/ETL/Adapter/XML/functions.php @@ -0,0 +1,39 @@ +|Path|string $path + * @param string $xml_node_path + * + * @return Extractor + */ +function from_xml( + string|Path|array $path, + string $xml_node_path = '' +) : Extractor { + if (\is_array($path)) { + /** @var array $extractors */ + $extractors = []; + + foreach ($path as $next_path) { + $extractors[] = new XMLReaderExtractor( + \is_string($next_path) ? Path::realpath($next_path) : $next_path, + $xml_node_path + ); + } + + return from_all(...$extractors); + } + + return new XMLReaderExtractor( + \is_string($path) ? Path::realpath($path) : $path, + $xml_node_path + ); +} diff --git a/src/adapter/etl-adapter-xml/src/Flow/ETL/DSL/XML.php b/src/adapter/etl-adapter-xml/src/Flow/ETL/DSL/XML.php index 557368a95..30f6fd747 100644 --- a/src/adapter/etl-adapter-xml/src/Flow/ETL/DSL/XML.php +++ b/src/adapter/etl-adapter-xml/src/Flow/ETL/DSL/XML.php @@ -8,6 +8,9 @@ use Flow\ETL\Extractor; use Flow\ETL\Filesystem\Path; +/** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + */ class XML { /** diff --git a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Benchmark/XmlExtractorBench.php b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Benchmark/XmlExtractorBench.php index e692bb91b..786305ae6 100644 --- a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Benchmark/XmlExtractorBench.php +++ b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Benchmark/XmlExtractorBench.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Adapter\XML\Tests\Benchmark; +use function Flow\ETL\Adapter\XML\from_xml; use Flow\ETL\Config; -use Flow\ETL\DSL\XML; use Flow\ETL\FlowContext; use PhpBench\Attributes\Groups; @@ -19,7 +19,7 @@ public function __construct() public function bench_extract_10k() : void { - foreach (XML::from(__DIR__ . '/../Fixtures/flow_orders.xml', xml_node_path: 'root/row')->extract($this->context) as $rows) { + foreach (from_xml(__DIR__ . '/../Fixtures/flow_orders.xml', xml_node_path: 'root/row')->extract($this->context) as $rows) { } } } diff --git a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Integration/XMLReaderExtractorTest.php b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Integration/XMLReaderExtractorTest.php index fd374d36d..6900657d5 100644 --- a/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Integration/XMLReaderExtractorTest.php +++ b/src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Integration/XMLReaderExtractorTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Adapter\XML\Tests\Integration; +use function Flow\ETL\Adapter\XML\from_xml; +use function Flow\ETL\DSL\xml_entry; use Flow\ETL\Adapter\XML\XMLReaderExtractor; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\XML; use Flow\ETL\Extractor\Signal; use Flow\ETL\Filesystem\Path; use Flow\ETL\Flow; @@ -61,29 +61,29 @@ public function test_reading_deep_xml() : void { $this->assertEquals( new Rows( - Row::create(Entry::xml( + Row::create(xml_entry( 'node', '1' )), - Row::create(Entry::xml( + Row::create(xml_entry( 'node', '2' )), - Row::create(Entry::xml( + Row::create(xml_entry( 'node', '3' )), - Row::create(Entry::xml( + Row::create(xml_entry( 'node', '4' )), - Row::create(Entry::xml( + Row::create(xml_entry( 'node', '5' )), ), (new Flow()) - ->read(XML::from(__DIR__ . '/../Fixtures/deepest_items_flat.xml', 'root/items/item/deep')) + ->read(from_xml(__DIR__ . '/../Fixtures/deepest_items_flat.xml', 'root/items/item/deep')) ->fetch() ); } @@ -94,9 +94,9 @@ public function test_reading_xml() : void $xml->load(__DIR__ . '/../Fixtures/simple_items.xml'); $this->assertEquals( - (new Rows(Row::create(Entry::xml('node', $xml)))), + (new Rows(Row::create(xml_entry('node', $xml)))), (new Flow()) - ->read(XML::from(__DIR__ . '/../Fixtures/simple_items.xml')) + ->read(from_xml(__DIR__ . '/../Fixtures/simple_items.xml')) ->fetch() ); } @@ -105,14 +105,14 @@ public function test_reading_xml_each_collection_item() : void { $this->assertEquals( new Rows( - Row::create(Entry::xml('node', '1')), - Row::create(Entry::xml('node', '2')), - Row::create(Entry::xml('node', '3')), - Row::create(Entry::xml('node', '4')), - Row::create(Entry::xml('node', '5')), + Row::create(xml_entry('node', '1')), + Row::create(xml_entry('node', '2')), + Row::create(xml_entry('node', '3')), + Row::create(xml_entry('node', '4')), + Row::create(xml_entry('node', '5')), ), (new Flow()) - ->read(XML::from(__DIR__ . '/../Fixtures/simple_items_flat.xml', 'root/items/item')) + ->read(from_xml(__DIR__ . '/../Fixtures/simple_items_flat.xml', 'root/items/item')) ->fetch() ); } @@ -142,9 +142,9 @@ public function test_reading_xml_from_path() : void XML); $this->assertEquals( - new Rows(Row::create(Entry::xml('node', $xml))), + new Rows(Row::create(xml_entry('node', $xml))), (new Flow()) - ->read(XML::from(__DIR__ . '/../Fixtures/simple_items.xml', 'root/items')) + ->read(from_xml(__DIR__ . '/../Fixtures/simple_items.xml', 'root/items')) ->fetch() ); } diff --git a/src/core/etl/src/Flow/ETL/DSL/Entry.php b/src/core/etl/src/Flow/ETL/DSL/Entry.php index 969e59b82..9754251c5 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Entry.php +++ b/src/core/etl/src/Flow/ETL/DSL/Entry.php @@ -14,6 +14,8 @@ use Flow\ETL\Row\Entry\Type\Uuid; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class Entry diff --git a/src/core/etl/src/Flow/ETL/DSL/From.php b/src/core/etl/src/Flow/ETL/DSL/From.php index 3c8e01714..b55e22dde 100644 --- a/src/core/etl/src/Flow/ETL/DSL/From.php +++ b/src/core/etl/src/Flow/ETL/DSL/From.php @@ -14,6 +14,8 @@ use Flow\ETL\Rows; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class From diff --git a/src/core/etl/src/Flow/ETL/DSL/Handler.php b/src/core/etl/src/Flow/ETL/DSL/Handler.php index b96c6e982..f69ad34f4 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Handler.php +++ b/src/core/etl/src/Flow/ETL/DSL/Handler.php @@ -7,6 +7,8 @@ use Flow\ETL\ErrorHandler; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class Handler diff --git a/src/core/etl/src/Flow/ETL/DSL/Partitions.php b/src/core/etl/src/Flow/ETL/DSL/Partitions.php index 339aa6f47..a8ed1246a 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Partitions.php +++ b/src/core/etl/src/Flow/ETL/DSL/Partitions.php @@ -9,12 +9,15 @@ use Flow\ETL\Partition\PartitionFilter; /** + * @deprecated please pass ScalarFunctions directly to DataFrame::partitionFilter() method + * * @infection-ignore-all */ class Partitions { public static function chain(PartitionFilter ...$filters) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($filters) : bool { foreach ($filters as $filter) { if (!$filter->keep(...$partitions)) { @@ -28,6 +31,7 @@ public static function chain(PartitionFilter ...$filters) : PartitionFilter public static function date_after(string $partition, \DateTimeInterface $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { if ($p->name === $partition && new \DateTimeImmutable($p->value) > $value) { @@ -41,6 +45,7 @@ public static function date_after(string $partition, \DateTimeInterface $value) public static function date_after_or_equal(string $partition, \DateTimeInterface $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { if ($p->name === $partition && new \DateTimeImmutable($p->value) >= $value) { @@ -54,6 +59,7 @@ public static function date_after_or_equal(string $partition, \DateTimeInterface public static function date_before(string $partition, \DateTimeInterface $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { if ($p->name === $partition && new \DateTimeImmutable($p->value) < $value) { @@ -67,6 +73,7 @@ public static function date_before(string $partition, \DateTimeInterface $value) public static function date_before_or_equal(string $partition, \DateTimeInterface $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { if ($p->name === $partition && new \DateTimeImmutable($p->value) <= $value) { @@ -80,6 +87,7 @@ public static function date_before_or_equal(string $partition, \DateTimeInterfac public static function date_between(string $partition, \DateTimeInterface $start, \DateTimeInterface $end) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $start, $end) : bool { foreach ($partitions as $p) { if ($p->name === $partition && new \DateTimeImmutable($p->value) >= $start && new \DateTimeImmutable($p->value) < $end) { @@ -93,6 +101,7 @@ public static function date_between(string $partition, \DateTimeInterface $start public static function greater(string $partition, int|float $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { $castedValue = \is_int($value) ? (int) $p->value : (float) $p->value; @@ -108,6 +117,7 @@ public static function greater(string $partition, int|float $value) : PartitionF public static function greater_or_equal(string $partition, int|float $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { $castedValue = \is_int($value) ? (int) $p->value : (float) $p->value; @@ -123,6 +133,7 @@ public static function greater_or_equal(string $partition, int|float $value) : P public static function lower(string $partition, int|float $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { $castedValue = \is_int($value) ? (int) $p->value : (float) $p->value; @@ -138,6 +149,7 @@ public static function lower(string $partition, int|float $value) : PartitionFil public static function lower_or_equal(string $partition, int|float $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { $castedValue = \is_int($value) ? (int) $p->value : (float) $p->value; @@ -153,6 +165,7 @@ public static function lower_or_equal(string $partition, int|float $value) : Par public static function not(PartitionFilter $filter) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static fn (FlowPartition ...$partitions) : bool => !$filter->keep(...$partitions)); } @@ -164,6 +177,7 @@ public static function not(PartitionFilter $filter) : PartitionFilter */ public static function one_of(string $partition, array $values) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter( static function (FlowPartition ...$partitions) use ($partition, $values) : bool { foreach ($partitions as $p) { @@ -179,6 +193,7 @@ static function (FlowPartition ...$partitions) use ($partition, $values) : bool public static function only(string $partition, string $value) : PartitionFilter { + /** @psalm-suppress DeprecatedClass */ return new CallableFilter(static function (FlowPartition ...$partitions) use ($partition, $value) : bool { foreach ($partitions as $p) { if ($p->name === $partition && $p->value === $value) { diff --git a/src/core/etl/src/Flow/ETL/DSL/To.php b/src/core/etl/src/Flow/ETL/DSL/To.php index d9128297d..00a8122ff 100644 --- a/src/core/etl/src/Flow/ETL/DSL/To.php +++ b/src/core/etl/src/Flow/ETL/DSL/To.php @@ -14,6 +14,8 @@ use Flow\ETL\Transformer; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class To diff --git a/src/core/etl/src/Flow/ETL/DSL/Transform.php b/src/core/etl/src/Flow/ETL/DSL/Transform.php index b3eceaef8..86d7e3dc7 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Transform.php +++ b/src/core/etl/src/Flow/ETL/DSL/Transform.php @@ -13,6 +13,8 @@ use Flow\ETL\Transformer\StyleConverter\StringStyles; /** + * @deprecated please use functions defined in Flow\ETL\DSL\functions.php + * * @infection-ignore-all */ class Transform diff --git a/src/core/etl/src/Flow/ETL/DSL/functions.php b/src/core/etl/src/Flow/ETL/DSL/functions.php index d990a0f69..68858f2af 100644 --- a/src/core/etl/src/Flow/ETL/DSL/functions.php +++ b/src/core/etl/src/Flow/ETL/DSL/functions.php @@ -4,6 +4,16 @@ namespace Flow\ETL\DSL; +use Flow\ETL\Config; +use Flow\ETL\ConfigBuilder; +use Flow\ETL\DataFrame; +use Flow\ETL\ErrorHandler\IgnoreError; +use Flow\ETL\ErrorHandler\SkipRows; +use Flow\ETL\ErrorHandler\ThrowError; +use Flow\ETL\Extractor; +use Flow\ETL\Filesystem\Stream\Mode; +use Flow\ETL\Flow; +use Flow\ETL\Formatter; use Flow\ETL\Function\All; use Flow\ETL\Function\Any; use Flow\ETL\Function\ArrayExists; @@ -62,16 +72,363 @@ use Flow\ETL\Function\Ulid; use Flow\ETL\Function\Uuid; use Flow\ETL\Function\When; +use Flow\ETL\Loader; +use Flow\ETL\Loader\CallbackLoader; +use Flow\ETL\Loader\MemoryLoader; +use Flow\ETL\Loader\StreamLoader; +use Flow\ETL\Loader\StreamLoader\Output; +use Flow\ETL\Loader\TransformerLoader; +use Flow\ETL\Memory\ArrayMemory; +use Flow\ETL\Memory\Memory; use Flow\ETL\Partition; +use Flow\ETL\PHP\Type\Logical\List\ListElement; +use Flow\ETL\PHP\Type\Logical\ListType; +use Flow\ETL\PHP\Type\Logical\Map\MapKey; +use Flow\ETL\PHP\Type\Logical\Map\MapValue; +use Flow\ETL\PHP\Type\Logical\MapType; +use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; +use Flow\ETL\PHP\Type\Logical\StructureType; +use Flow\ETL\PHP\Type\Native\ArrayType; +use Flow\ETL\PHP\Type\Native\CallableType; +use Flow\ETL\PHP\Type\Native\EnumType; +use Flow\ETL\PHP\Type\Native\NullType; +use Flow\ETL\PHP\Type\Native\ObjectType; +use Flow\ETL\PHP\Type\Native\ResourceType; +use Flow\ETL\PHP\Type\Native\ScalarType; +use Flow\ETL\PHP\Type\Type; +use Flow\ETL\Pipeline; use Flow\ETL\Row; use Flow\ETL\Row\EntryFactory; use Flow\ETL\Row\EntryReference; use Flow\ETL\Row\Factory\NativeEntryFactory; use Flow\ETL\Row\Reference; use Flow\ETL\Row\References; +use Flow\ETL\Row\Schema\Formatter\ASCIISchemaFormatter; +use Flow\ETL\Row\Schema\SchemaFormatter; use Flow\ETL\Rows; +use Flow\ETL\Transformer; use Flow\ETL\Window; +/** + * Alias for data_frame() : Flow. + */ +function df(Config|ConfigBuilder|null $config = null) : Flow +{ + return data_frame($config); +} + +function data_frame(Config|ConfigBuilder|null $config = null) : Flow +{ + return new Flow($config); +} + +function from_rows(Rows ...$rows) : Extractor\ProcessExtractor +{ + return new Extractor\ProcessExtractor(...$rows); +} + +function from_array(array $array) : Extractor\MemoryExtractor +{ + return new Extractor\MemoryExtractor(new ArrayMemory($array)); +} + +function from_cache(string $id, ?Extractor $fallback_extractor = null, bool $clear = false) : Extractor\CacheExtractor +{ + return new Extractor\CacheExtractor($id, $fallback_extractor, $clear); +} + +function from_all(Extractor ...$extractors) : Extractor\ChainExtractor +{ + return new Extractor\ChainExtractor(...$extractors); +} + +function from_memory(Memory $memory) : Extractor\MemoryExtractor +{ + return new Extractor\MemoryExtractor($memory); +} + +/** + * @param int<1, max> $chunk_size + */ +function chunks_from(Extractor $extractor, int $chunk_size) : Extractor\ChunkExtractor +{ + return new Extractor\ChunkExtractor($extractor, $chunk_size); +} + +function from_pipeline(Pipeline $pipeline) : Extractor\PipelineExtractor +{ + return new Extractor\PipelineExtractor($pipeline); +} + +function from_data_frame(DataFrame $data_frame) : Extractor\DataFrameExtractor +{ + return new Extractor\DataFrameExtractor($data_frame); +} + +function from_sequence_date_period(string $entry_name, \DateTimeInterface $start, \DateInterval $interval, \DateTimeInterface $end, int $options = 0) : Extractor\SequenceExtractor +{ + /** @psalm-suppress ArgumentTypeCoercion */ + return new Extractor\SequenceExtractor( + new Extractor\SequenceGenerator\DatePeriodSequenceGenerator(new \DatePeriod($start, $interval, $end, $options)), + $entry_name + ); +} + +function from_sequence_date_period_recurrences(string $entry_name, \DateTimeInterface $start, \DateInterval $interval, int $recurrences, int $options = 0) : Extractor\SequenceExtractor +{ + /** @psalm-suppress ArgumentTypeCoercion */ + return new Extractor\SequenceExtractor( + new Extractor\SequenceGenerator\DatePeriodSequenceGenerator(new \DatePeriod($start, $interval, $recurrences, $options)), + $entry_name + ); +} + +function from_sequence_number(string $entry_name, string|int|float $start, string|int|float $end, int|float $step = 1) : Extractor\SequenceExtractor +{ + return new Extractor\SequenceExtractor( + new Extractor\SequenceGenerator\NumberSequenceGenerator($start, $end, $step), + $entry_name + ); +} + +function to_callable(callable $callable) : CallbackLoader +{ + return new CallbackLoader($callable); +} + +function to_memory(Memory $memory) : MemoryLoader +{ + return new MemoryLoader($memory); +} + +function to_output(int|bool $truncate = 20, Output $output = Output::rows, Formatter $formatter = new Formatter\AsciiTableFormatter(), SchemaFormatter $schemaFormatter = new ASCIISchemaFormatter()) : StreamLoader +{ + return StreamLoader::output($truncate, $output, $formatter, $schemaFormatter); +} + +function to_stderr(int|bool $truncate = 20, Output $output = Output::rows, Formatter $formatter = new Formatter\AsciiTableFormatter(), SchemaFormatter $schemaFormatter = new ASCIISchemaFormatter()) : StreamLoader +{ + return StreamLoader::stderr($truncate, $output, $formatter, $schemaFormatter); +} + +function to_stdout(int|bool $truncate = 20, Output $output = Output::rows, Formatter $formatter = new Formatter\AsciiTableFormatter(), SchemaFormatter $schemaFormatter = new ASCIISchemaFormatter()) : StreamLoader +{ + return StreamLoader::stdout($truncate, $output, $formatter, $schemaFormatter); +} + +function to_stream(string $uri, int|bool $truncate = 20, Output $output = Output::rows, string $mode = 'w', Formatter $formatter = new Formatter\AsciiTableFormatter(), SchemaFormatter $schemaFormatter = new ASCIISchemaFormatter()) : StreamLoader +{ + return new StreamLoader($uri, Mode::from($mode), $truncate, $output, $formatter, $schemaFormatter); +} + +function to_transformation(Transformer $transformer, Loader $loader) : TransformerLoader +{ + return new TransformerLoader($transformer, $loader); +} + +/** + * @param array $data + */ +function array_entry(string $array, array $data) : Row\Entry\ArrayEntry +{ + return new Row\Entry\ArrayEntry($array, $data); +} + +function bool_entry(string $name, bool $value) : Row\Entry\BooleanEntry +{ + return new Row\Entry\BooleanEntry($name, $value); +} + +function boolean_entry(string $name, bool $value) : Row\Entry\BooleanEntry +{ + return bool_entry($name, $value); +} + +function datetime_entry(string $name, \DateTimeInterface|string $value) : Row\Entry\DateTimeEntry +{ + return new Row\Entry\DateTimeEntry($name, $value); +} + +function int_entry(string $name, int $value) : Row\Entry\IntegerEntry +{ + return new Row\Entry\IntegerEntry($name, $value); +} + +function integer_entry(string $name, int $value) : Row\Entry\IntegerEntry +{ + return int_entry($name, $value); +} + +function enum_entry(string $name, \UnitEnum $enum) : Row\Entry\EnumEntry +{ + return new Row\Entry\EnumEntry($name, $enum); +} + +function float_entry(string $name, float $value) : Row\Entry\FloatEntry +{ + return new Row\Entry\FloatEntry($name, $value); +} + +function json_entry(string $name, array|string $data) : Row\Entry\JsonEntry +{ + return new Row\Entry\JsonEntry($name, $data); +} + +function json_object_entry(string $name, array|string $data) : Row\Entry\JsonEntry +{ + if (\is_string($data)) { + return new Row\Entry\JsonEntry($name, $data); + } + + return Row\Entry\JsonEntry::object($name, $data); +} + +function null_entry(string $name) : Row\Entry\NullEntry +{ + return new Row\Entry\NullEntry($name); +} + +function object_entry(string $name, object $data) : Row\Entry\ObjectEntry +{ + return new Row\Entry\ObjectEntry($name, $data); +} + +function obj_entry(string $name, object $data) : Row\Entry\ObjectEntry +{ + return object_entry($name, $data); +} + +function str_entry(string $name, string $value) : Row\Entry\StringEntry +{ + return new Row\Entry\StringEntry($name, $value); +} + +function string_entry(string $name, string $value) : Row\Entry\StringEntry +{ + return str_entry($name, $value); +} + +function uuid_entry(string $name, Row\Entry\Type\Uuid|string $value) : Row\Entry\UuidEntry +{ + return new Row\Entry\UuidEntry($name, $value); +} + +function xml_entry(string $name, \DOMDocument|string $value) : Row\Entry\XMLEntry +{ + return new Row\Entry\XMLEntry($name, $value); +} + +function xml_node_entry(string $name, \DOMNode $value) : Row\Entry\XMLNodeEntry +{ + return new Row\Entry\XMLNodeEntry($name, $value); +} + +function entries(Row\Entry ...$entries) : Row\Entries +{ + return new Row\Entries(...$entries); +} + +function struct_entry(string $name, array $value, StructureType $type) : Row\Entry\StructureEntry +{ + return new Row\Entry\StructureEntry($name, $value, $type); +} + +function struct_type(StructureElement ...$element) : StructureType +{ + return new StructureType(...$element); +} + +function struct_element(string $name, Type $type) : StructureElement +{ + return new StructureElement($name, $type); +} + +function list_entry(string $name, array $value, ListType $type) : Row\Entry\ListEntry +{ + return new Row\Entry\ListEntry($name, $value, $type); +} + +function type_list(Type $element) : ListType +{ + return new ListType(new ListElement($element)); +} + +function type_map(ScalarType $key_type, Type $value_type) : MapType +{ + return new MapType(new MapKey($key_type), new MapValue($value_type)); +} + +function map_entry(string $name, array $value, MapType $mapType) : Row\Entry\MapEntry +{ + return new Row\Entry\MapEntry($name, $value, $mapType); +} + +function type_int(bool $nullable = false) : ScalarType +{ + return ScalarType::integer($nullable); +} + +function type_string(bool $nullable = false) : ScalarType +{ + return ScalarType::string($nullable); +} + +function type_float(bool $nullable = false) : ScalarType +{ + return ScalarType::float($nullable); +} + +function type_boolean(bool $nullable = false) : ScalarType +{ + return ScalarType::boolean($nullable); +} + +/** + * @param class-string $class + */ +function type_object(string $class, bool $nullable = false) : ObjectType +{ + return new ObjectType($class, $nullable); +} + +function type_resource(bool $nullable = true) : ResourceType +{ + return new ResourceType($nullable); +} + +function type_array(bool $empty = false, bool $nullable = false) : ArrayType +{ + return new ArrayType($empty, $nullable); +} + +function type_callable(bool $nullable = true) : CallableType +{ + return new CallableType($nullable); +} + +function type_null() : NullType +{ + return new NullType(); +} + +/** + * @param class-string<\UnitEnum> $class + */ +function type_enum(string $class, bool $nullable = false) : EnumType +{ + return new EnumType($class, $nullable); +} + +function row(Row\Entry ...$entry) : Row +{ + return Row::create(...$entry); +} + +function rows(Row ...$row) : Rows +{ + return new Rows(...$row); +} + function col(string $entry) : EntryReference { return new EntryReference($entry); @@ -324,6 +681,21 @@ function to_timezone(ScalarFunction $function, ScalarFunction $timeZone) : Scala return new ToTimeZone($function, $timeZone); } +function ignore_error_handler() : IgnoreError +{ + return new IgnoreError(); +} + +function skip_rows_handler() : SkipRows +{ + return new SkipRows(); +} + +function throw_error_handler() : ThrowError +{ + return new ThrowError(); +} + function to_money(ScalarFunction $amount, ScalarFunction $currency, ?\Money\MoneyParser $moneyParser = null) : ScalarFunction { if (null !== $moneyParser) { diff --git a/src/core/etl/src/Flow/ETL/DataFrame.php b/src/core/etl/src/Flow/ETL/DataFrame.php index 47398c1d2..92b85428b 100644 --- a/src/core/etl/src/Flow/ETL/DataFrame.php +++ b/src/core/etl/src/Flow/ETL/DataFrame.php @@ -4,8 +4,7 @@ namespace Flow\ETL; -use Flow\ETL\DSL\To; -use Flow\ETL\DSL\Transform; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Filesystem\SaveMode; @@ -17,6 +16,7 @@ use Flow\ETL\Join\Join; use Flow\ETL\Loader\SchemaValidationLoader; use Flow\ETL\Loader\StreamLoader\Output; +use Flow\ETL\Partition\ScalarFunctionFilter; use Flow\ETL\Pipeline\BatchingPipeline; use Flow\ETL\Pipeline\CachingPipeline; use Flow\ETL\Pipeline\CollectingPipeline; @@ -30,11 +30,15 @@ use Flow\ETL\Transformer\CallbackRowTransformer; use Flow\ETL\Transformer\CrossJoinRowsTransformer; use Flow\ETL\Transformer\DropDuplicatesTransformer; +use Flow\ETL\Transformer\EntryNameStyleConverterTransformer; use Flow\ETL\Transformer\JoinEachRowsTransformer; use Flow\ETL\Transformer\JoinRowsTransformer; use Flow\ETL\Transformer\KeepEntriesTransformer; use Flow\ETL\Transformer\LimitTransformer; use Flow\ETL\Transformer\RemoveEntriesTransformer; +use Flow\ETL\Transformer\RenameAllCaseTransformer; +use Flow\ETL\Transformer\RenameEntryTransformer; +use Flow\ETL\Transformer\RenameStrReplaceAllEntriesTransformer; use Flow\ETL\Transformer\ScalarFunctionFilterTransformer; use Flow\ETL\Transformer\ScalarFunctionTransformer; use Flow\ETL\Transformer\StyleConverter\StringStyles; @@ -280,9 +284,14 @@ public function filter(ScalarFunction $function) : self /** * @lazy */ - public function filterPartitions(Partition\PartitionFilter $filter) : self + public function filterPartitions(Partition\PartitionFilter|ScalarFunction $filter) : self { - $this->context->filterPartitions($filter); + if ($filter instanceof Partition\PartitionFilter) { + $this->context->filterPartitions($filter); + + return $this; + } + $this->context->filterPartitions(new ScalarFunctionFilter($filter, $this->context->entryFactory())); return $this; } @@ -539,7 +548,7 @@ public function printRows(int|null $limit = 20, int|bool $truncate = 20, Formatt $clone->limit($limit); } - $clone->load(To::output($truncate, Output::rows, $formatter)); + $clone->load(to_output($truncate, Output::rows, $formatter)); $clone->run(); } @@ -554,7 +563,7 @@ public function printSchema(int|null $limit = 20, Schema\SchemaFormatter $format if ($limit !== null) { $clone->limit($limit); } - $clone->load(To::output(false, Output::schema, schemaFormatter: $formatter)); + $clone->load(to_output(false, Output::schema, schemaFormatter: $formatter)); $clone->run(); } @@ -564,7 +573,7 @@ public function printSchema(int|null $limit = 20, Schema\SchemaFormatter $format */ public function rename(string $from, string $to) : self { - $this->pipeline->add(Transform::rename($from, $to)); + $this->pipeline->add(new RenameEntryTransformer($from, $to)); return $this; } @@ -575,7 +584,7 @@ public function rename(string $from, string $to) : self */ public function renameAll(string $search, string $replace) : self { - $this->pipeline->add(Transform::rename_str_replace_all($search, $replace)); + $this->pipeline->add(new RenameStrReplaceAllEntriesTransformer($search, $replace)); return $this; } @@ -585,7 +594,7 @@ public function renameAll(string $search, string $replace) : self */ public function renameAllLowerCase() : self { - $this->pipeline->add(Transform::rename_all_case(lower: true)); + $this->pipeline->add(new RenameAllCaseTransformer(lower: true)); return $this; } @@ -597,7 +606,7 @@ public function renameAllLowerCase() : self */ public function renameAllStyle(StringStyles|string $style) : self { - $this->pipeline->add(Transform::convert_name($style)); + $this->pipeline->add(new EntryNameStyleConverterTransformer(\is_string($style) ? StringStyles::fromString($style) : $style)); return $this; } @@ -607,7 +616,7 @@ public function renameAllStyle(StringStyles|string $style) : self */ public function renameAllUpperCase() : self { - $this->pipeline->add(Transform::rename_all_case(upper: true)); + $this->pipeline->add(new RenameAllCaseTransformer(upper: true)); return $this; } @@ -617,7 +626,7 @@ public function renameAllUpperCase() : self */ public function renameAllUpperCaseFirst() : self { - $this->pipeline->add(Transform::rename_all_case(ucfirst: true)); + $this->pipeline->add(new RenameAllCaseTransformer(ucfirst: true)); return $this; } @@ -627,7 +636,7 @@ public function renameAllUpperCaseFirst() : self */ public function renameAllUpperCaseWord() : self { - $this->pipeline->add(Transform::rename_all_case(ucwords: true)); + $this->pipeline->add(new RenameAllCaseTransformer(ucwords: true)); return $this; } diff --git a/src/core/etl/src/Flow/ETL/Flow.php b/src/core/etl/src/Flow/ETL/Flow.php index 69bef6dd1..fd47ceadd 100644 --- a/src/core/etl/src/Flow/ETL/Flow.php +++ b/src/core/etl/src/Flow/ETL/Flow.php @@ -33,6 +33,11 @@ public function extract(Extractor $extractor) : DataFrame ); } + public function from(Extractor $extractor) : DataFrame + { + return $this->read($extractor); + } + public function process(Rows ...$rows) : DataFrame { return new DataFrame( diff --git a/src/core/etl/src/Flow/ETL/Function/Average.php b/src/core/etl/src/Flow/ETL/Function/Average.php index 4508218af..269e37d5e 100644 --- a/src/core/etl/src/Flow/ETL/Function/Average.php +++ b/src/core/etl/src/Flow/ETL/Function/Average.php @@ -2,6 +2,8 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\integer_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Row; @@ -80,10 +82,10 @@ public function result() : Entry } if ($result - $resultInt === 0.0) { - return \Flow\ETL\DSL\Entry::integer($this->ref->name(), (int) $result); + return integer_entry($this->ref->name(), (int) $result); } - return \Flow\ETL\DSL\Entry::float($this->ref->name(), $result); + return float_entry($this->ref->name(), $result); } public function toString() : string diff --git a/src/core/etl/src/Flow/ETL/Function/Collect.php b/src/core/etl/src/Flow/ETL/Function/Collect.php index c78112004..b1a683008 100644 --- a/src/core/etl/src/Flow/ETL/Function/Collect.php +++ b/src/core/etl/src/Flow/ETL/Function/Collect.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\array_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use Flow\ETL\Row\Entry; @@ -41,6 +42,6 @@ public function result() : Entry $this->ref->as($this->ref->name() . '_collection'); } - return \Flow\ETL\DSL\Entry::array($this->ref->name(), $this->collection); + return array_entry($this->ref->name(), $this->collection); } } diff --git a/src/core/etl/src/Flow/ETL/Function/CollectUnique.php b/src/core/etl/src/Flow/ETL/Function/CollectUnique.php index 0f608015b..10ac47860 100644 --- a/src/core/etl/src/Flow/ETL/Function/CollectUnique.php +++ b/src/core/etl/src/Flow/ETL/Function/CollectUnique.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\array_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use Flow\ETL\Row\Entry; @@ -46,6 +47,6 @@ public function result() : Entry $this->ref->as($this->ref->name() . '_collection_unique'); } - return \Flow\ETL\DSL\Entry::array($this->ref->name(), $this->collection); + return array_entry($this->ref->name(), $this->collection); } } diff --git a/src/core/etl/src/Flow/ETL/Function/Count.php b/src/core/etl/src/Flow/ETL/Function/Count.php index 4f640973b..5757f53b6 100644 --- a/src/core/etl/src/Flow/ETL/Function/Count.php +++ b/src/core/etl/src/Flow/ETL/Function/Count.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Row; @@ -62,7 +63,7 @@ public function result() : Entry $this->ref->as($this->ref->to() . '_count'); } - return \Flow\ETL\DSL\Entry::integer($this->ref->name(), $this->count); + return int_entry($this->ref->name(), $this->count); } public function toString() : string diff --git a/src/core/etl/src/Flow/ETL/Function/Max.php b/src/core/etl/src/Flow/ETL/Function/Max.php index 8a6d9912f..bce0a8bb1 100644 --- a/src/core/etl/src/Flow/ETL/Function/Max.php +++ b/src/core/etl/src/Flow/ETL/Function/Max.php @@ -4,6 +4,9 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use Flow\ETL\Row\Entry; @@ -45,15 +48,15 @@ public function result() : Entry } if ($this->max === null) { - return \Flow\ETL\DSL\Entry::null($this->ref->name()); + return null_entry($this->ref->name()); } $resultInt = (int) $this->max; if ($this->max - $resultInt === 0.0) { - return \Flow\ETL\DSL\Entry::integer($this->ref->name(), (int) $this->max); + return int_entry($this->ref->name(), (int) $this->max); } - return \Flow\ETL\DSL\Entry::float($this->ref->name(), $this->max); + return float_entry($this->ref->name(), $this->max); } } diff --git a/src/core/etl/src/Flow/ETL/Function/Min.php b/src/core/etl/src/Flow/ETL/Function/Min.php index afb2b9410..c1e288b3e 100644 --- a/src/core/etl/src/Flow/ETL/Function/Min.php +++ b/src/core/etl/src/Flow/ETL/Function/Min.php @@ -4,6 +4,9 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use Flow\ETL\Row\Entry; @@ -47,13 +50,13 @@ public function result() : Entry $resultInt = (int) $this->min; if ($this->min === null) { - return \Flow\ETL\DSL\Entry::null($this->ref->name()); + return null_entry($this->ref->name()); } if ($this->min - $resultInt === 0.0) { - return \Flow\ETL\DSL\Entry::integer($this->ref->name(), (int) $this->min); + return int_entry($this->ref->name(), (int) $this->min); } - return \Flow\ETL\DSL\Entry::float($this->ref->name(), $this->min); + return float_entry($this->ref->name(), $this->min); } } diff --git a/src/core/etl/src/Flow/ETL/Function/Sum.php b/src/core/etl/src/Flow/ETL/Function/Sum.php index 537e30b13..27deec572 100644 --- a/src/core/etl/src/Flow/ETL/Function/Sum.php +++ b/src/core/etl/src/Flow/ETL/Function/Sum.php @@ -2,6 +2,8 @@ namespace Flow\ETL\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Row; @@ -68,10 +70,10 @@ public function result() : Entry $resultInt = (int) $this->sum; if ($this->sum - $resultInt === 0.0) { - return \Flow\ETL\DSL\Entry::integer($this->ref->name(), (int) $this->sum); + return int_entry($this->ref->name(), (int) $this->sum); } - return \Flow\ETL\DSL\Entry::float($this->ref->name(), $this->sum); + return float_entry($this->ref->name(), $this->sum); } public function toString() : string diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php b/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php index 5dcd03d5c..1debc23db 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/ArrayContentDetector.php @@ -4,9 +4,9 @@ namespace Flow\ETL\PHP\Type; +use function Flow\ETL\DSL\type_array; +use function Flow\ETL\DSL\type_null; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\Native\ArrayType; -use Flow\ETL\PHP\Type\Native\NullType; use Flow\ETL\PHP\Type\Native\ScalarType; final class ArrayContentDetector @@ -24,7 +24,7 @@ public function __construct(Types $uniqueKeysType, Types $uniqueValuesType) $this->firstKeyType = $uniqueKeysType->first(); $this->firstValueType = $uniqueValuesType->first(); $this->uniqueKeysCount = $uniqueKeysType->count(); - $this->uniqueValuesCount = $uniqueValuesType->without(ArrayType::empty(), new NullType())->count(); + $this->uniqueValuesCount = $uniqueValuesType->without(type_array(true), type_null())->count(); } public function firstKeyType() : ?ScalarType diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php index 1fc4dab74..31caa32e5 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/List/ListElement.php @@ -2,26 +2,29 @@ namespace Flow\ETL\PHP\Type\Logical\List; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; final class ListElement { - private function __construct(private readonly Type $value) + public function __construct(private readonly Type $value) { } public static function boolean() : self { - return new self(ScalarType::boolean()); + return new self(type_boolean(false)); } public static function float() : self { - return new self(ScalarType::float()); + return new self(type_float(false)); } public static function fromType(Type $type) : self @@ -31,7 +34,7 @@ public static function fromType(Type $type) : self public static function integer() : self { - return new self(ScalarType::integer()); + return new self(type_int(false)); } public static function list(ListType $type) : self @@ -49,12 +52,12 @@ public static function map(MapType $type) : self */ public static function object(string $class, bool $nullable = false) : self { - return new self(ObjectType::of($class, $nullable)); + return new self(type_object($class, $nullable)); } public static function string() : self { - return new self(ScalarType::string()); + return new self(type_string(false)); } public function isEqual(mixed $value) : bool diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapKey.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapKey.php index f5acb6856..ec11a236c 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapKey.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapKey.php @@ -2,11 +2,13 @@ namespace Flow\ETL\PHP\Type\Logical\Map; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Native\ScalarType; final class MapKey { - private function __construct(private readonly ScalarType $value) + public function __construct(private readonly ScalarType $value) { } @@ -17,12 +19,12 @@ public static function fromType(ScalarType $type) : self public static function integer() : self { - return new self(ScalarType::integer()); + return new self(type_int(false)); } public static function string() : self { - return new self(ScalarType::string()); + return new self(type_string(false)); } public function isEqual(mixed $value) : bool diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapValue.php b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapValue.php index 38ca57a3f..41d6d0e54 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapValue.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Logical/Map/MapValue.php @@ -2,26 +2,29 @@ namespace Flow\ETL\PHP\Type\Logical\Map; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; final class MapValue { - private function __construct(private readonly Type $value) + public function __construct(private readonly Type $value) { } public static function boolean() : self { - return new self(ScalarType::boolean()); + return new self(type_boolean()); } public static function float() : self { - return new self(ScalarType::float()); + return new self(type_float()); } public static function fromType(Type $type) : self @@ -31,7 +34,7 @@ public static function fromType(Type $type) : self public static function integer() : self { - return new self(ScalarType::integer()); + return new self(type_int()); } public static function list(ListType $type) : self @@ -49,12 +52,12 @@ public static function map(MapType $type) : self */ public static function object(string $class, bool $optional = false) : self { - return new self(ObjectType::of($class, $optional)); + return new self(type_object($class, $optional)); } public static function string() : self { - return new self(ScalarType::string()); + return new self(type_string()); } public function isEqual(mixed $value) : bool diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Native/ArrayType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ArrayType.php index 28983e6c3..9a8a6d867 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Native/ArrayType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ArrayType.php @@ -6,11 +6,11 @@ use Flow\ETL\PHP\Type\Type; /** - * @implements NativeType + * @implements NativeType */ final class ArrayType implements NativeType { - public function __construct(private readonly bool $empty = false) + public function __construct(private readonly bool $empty = false, private readonly bool $nullable = false) { } @@ -21,12 +21,16 @@ public static function empty() : self public function __serialize() : array { - return ['empty' => $this->empty]; + return [ + 'empty' => $this->empty, + 'nullable' => $this->nullable, + ]; } public function __unserialize(array $data) : void { $this->empty = $data['empty']; + $this->nullable = $data['nullable']; } public function isEqual(Type $type) : bool @@ -41,15 +45,15 @@ public function isValid(mixed $value) : bool public function nullable() : bool { - return false; + return $this->nullable; } public function toString() : string { if ($this->empty) { - return 'array'; + return ($this->nullable ? '?' : '') . 'array'; } - return 'array'; + return ($this->nullable ? '?' : '') . 'array'; } } diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php index d30d4374b..a1d66c178 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/Native/ObjectType.php @@ -22,19 +22,6 @@ public function __construct(public readonly string $class, private readonly bool } } - public static function fromObject(object $object, bool $nullable = false) : self - { - return new self($object::class, $nullable); - } - - /** - * @param class-string $class - */ - public static function of(string $class, bool $nullable = false) : self - { - return new self($class, $nullable); - } - public function __serialize() : array { return ['class' => $this->class, 'nullable' => $this->nullable]; diff --git a/src/core/etl/src/Flow/ETL/PHP/Type/TypeDetector.php b/src/core/etl/src/Flow/ETL/PHP/Type/TypeDetector.php index 85b8bb929..f47fe60a9 100644 --- a/src/core/etl/src/Flow/ETL/PHP/Type/TypeDetector.php +++ b/src/core/etl/src/Flow/ETL/PHP/Type/TypeDetector.php @@ -4,6 +4,13 @@ namespace Flow\ETL\PHP\Type; +use function Flow\ETL\DSL\type_array; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_null; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; @@ -11,32 +18,29 @@ use Flow\ETL\PHP\Type\Logical\StructureType; use Flow\ETL\PHP\Type\Native\ArrayType; use Flow\ETL\PHP\Type\Native\EnumType; -use Flow\ETL\PHP\Type\Native\NullType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; final class TypeDetector { public function detectType(mixed $value) : Type { if (null === $value) { - return new NullType(); + return type_null(); } if (\is_string($value)) { - return ScalarType::string(); + return type_string(); } if (\is_int($value)) { - return ScalarType::integer(); + return type_int(); } if (\is_bool($value)) { - return ScalarType::boolean(); + return type_boolean(); } if (\is_float($value)) { - return ScalarType::float(); + return type_float(); } if (\is_array($value)) { @@ -65,7 +69,7 @@ public function detectType(mixed $value) : Type return new StructureType(...$elements); } - return new ArrayType([] === \array_filter($value, fn ($value) : bool => null !== $value)); + return type_array([] === \array_filter($value, fn ($value) : bool => null !== $value)); } if ($value instanceof \UnitEnum) { @@ -73,7 +77,7 @@ public function detectType(mixed $value) : Type } if (\is_object($value)) { - return ObjectType::fromObject($value); + return type_object($value::class); } throw InvalidArgumentException::because('Unsupported type given: ' . \gettype($value)); diff --git a/src/core/etl/src/Flow/ETL/Partition/CallableFilter.php b/src/core/etl/src/Flow/ETL/Partition/CallableFilter.php index d2b2fe377..1345dc2c7 100644 --- a/src/core/etl/src/Flow/ETL/Partition/CallableFilter.php +++ b/src/core/etl/src/Flow/ETL/Partition/CallableFilter.php @@ -10,6 +10,8 @@ use Laravel\SerializableClosure\SerializableClosure; /** + * @deprecated please use ScalarFunctionFilter instead + * * @implements PartitionFilter */ final class CallableFilter implements PartitionFilter diff --git a/src/core/etl/src/Flow/ETL/Partition/ScalarFunctionFilter.php b/src/core/etl/src/Flow/ETL/Partition/ScalarFunctionFilter.php new file mode 100644 index 000000000..95ebeb171 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/Partition/ScalarFunctionFilter.php @@ -0,0 +1,50 @@ + + */ +final class ScalarFunctionFilter implements PartitionFilter +{ + public function __construct( + private readonly ScalarFunction $function, + private readonly EntryFactory $entryFactory + ) { + } + + public function __serialize() : array + { + return [ + 'function' => $this->function, + 'entry_factory' => $this->entryFactory, + ]; + } + + public function __unserialize(array $data) : void + { + $this->function = $data['function']; + $this->entryFactory = $data['entry_factory']; + } + + public function keep(Partition ...$partitions) : bool + { + try { + return (bool) $this->function->eval( + row( + ...\array_map( + fn (Partition $partition) => $this->entryFactory->create($partition->name, $partition->value), + $partitions + ) + ) + ); + } catch (\Exception $e) { + return false; + } + } +} diff --git a/src/core/etl/src/Flow/ETL/Pipeline/BatchingPipeline.php b/src/core/etl/src/Flow/ETL/Pipeline/BatchingPipeline.php index 73799fd32..8cfc1007d 100644 --- a/src/core/etl/src/Flow/ETL/Pipeline/BatchingPipeline.php +++ b/src/core/etl/src/Flow/ETL/Pipeline/BatchingPipeline.php @@ -2,7 +2,8 @@ namespace Flow\ETL\Pipeline; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\chunks_from; +use function Flow\ETL\DSL\from_pipeline; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; @@ -80,8 +81,8 @@ public function pipes() : Pipes public function process(FlowContext $context) : \Generator { $this->nextPipeline->setSource( - From::chunks_from( - From::pipeline($this->pipeline), + chunks_from( + from_pipeline($this->pipeline), $this->size ) ); diff --git a/src/core/etl/src/Flow/ETL/Pipeline/CollectingPipeline.php b/src/core/etl/src/Flow/ETL/Pipeline/CollectingPipeline.php index bd7584f3b..be16c49ea 100644 --- a/src/core/etl/src/Flow/ETL/Pipeline/CollectingPipeline.php +++ b/src/core/etl/src/Flow/ETL/Pipeline/CollectingPipeline.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Pipeline; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\from_rows; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; @@ -74,7 +74,7 @@ public function pipes() : Pipes public function process(FlowContext $context) : \Generator { - $this->nextPipeline->setSource(From::rows( + $this->nextPipeline->setSource(from_rows( (new Rows())->merge(...\iterator_to_array($this->pipeline->process($context))) )); diff --git a/src/core/etl/src/Flow/ETL/Pipeline/ParallelizingPipeline.php b/src/core/etl/src/Flow/ETL/Pipeline/ParallelizingPipeline.php index cbe42cd08..2b2bf4c30 100644 --- a/src/core/etl/src/Flow/ETL/Pipeline/ParallelizingPipeline.php +++ b/src/core/etl/src/Flow/ETL/Pipeline/ParallelizingPipeline.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Pipeline; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\chunks_from; +use function Flow\ETL\DSL\from_pipeline; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; use Flow\ETL\Loader; @@ -75,8 +76,8 @@ public function pipes() : Pipes public function process(FlowContext $context) : \Generator { $this->nextPipeline->setSource( - From::chunks_from( - From::pipeline($this->pipeline), + chunks_from( + from_pipeline($this->pipeline), $this->parallel ) ); diff --git a/src/core/etl/src/Flow/ETL/Pipeline/SynchronousPipeline.php b/src/core/etl/src/Flow/ETL/Pipeline/SynchronousPipeline.php index bb831b60d..429e9651e 100644 --- a/src/core/etl/src/Flow/ETL/Pipeline/SynchronousPipeline.php +++ b/src/core/etl/src/Flow/ETL/Pipeline/SynchronousPipeline.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Pipeline; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\from_rows; use Flow\ETL\Exception\LimitReachedException; use Flow\ETL\Extractor; use Flow\ETL\Extractor\Signal; @@ -24,7 +24,7 @@ final class SynchronousPipeline implements Pipeline public function __construct() { $this->pipes = Pipes::empty(); - $this->extractor = From::rows(new Rows()); + $this->extractor = from_rows(new Rows()); } public function add(Loader|Transformer $pipe) : self diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/ArrayEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/ArrayEntry.php index bbe538afb..52e1f8392 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/ArrayEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/ArrayEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_array; use Flow\ArrayComparison\ArrayComparison; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ArrayType; @@ -34,7 +35,7 @@ public function __construct( throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = new ArrayType([] === $this->value); + $this->type = type_array([] === $this->value); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php index 846e17d16..0c5f7b229 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_boolean; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; @@ -29,7 +30,7 @@ public function __construct(private readonly string $name, private readonly bool throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = ScalarType::boolean(); + $this->type = type_boolean(); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php index 3d8f9f59f..187acf2a1 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_object; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Type; @@ -43,7 +44,7 @@ public function __construct(private readonly string $name, \DateTimeInterface|st $this->value = $value; } - $this->type = ObjectType::fromObject($this->value); + $this->type = type_object($this->value::class); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php index 036298d3d..6c6f90df4 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_float; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; @@ -29,7 +30,7 @@ public function __construct(private readonly string $name, private readonly floa throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = ScalarType::float(); + $this->type = type_float(); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php index e82b0a6f7..be260625a 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_int; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; @@ -29,7 +30,7 @@ public function __construct(private readonly string $name, private readonly int throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = ScalarType::integer(); + $this->type = type_int(); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/JsonEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/JsonEntry.php index 823702495..0cdc070bd 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/JsonEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/JsonEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_string; use Flow\ArrayComparison\ArrayComparison; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ScalarType; @@ -46,7 +47,7 @@ public function __construct(private readonly string $name, array|string $value) $this->value = $value; } - $this->type = ScalarType::string(); + $this->type = type_string(); } /** diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/NullEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/NullEntry.php index 25cc5ac0b..6235bfea4 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/NullEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/NullEntry.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_null; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\Native\NullType; use Flow\ETL\PHP\Type\Type; use Flow\ETL\Row\Entry; use Flow\ETL\Row\Reference; @@ -87,7 +87,7 @@ public function toString() : string public function type() : Type { - return new NullType(); + return type_null(); } public function value() diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/ObjectEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/ObjectEntry.php index 113076a9a..630340651 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/ObjectEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/ObjectEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_object; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Type; @@ -29,7 +30,7 @@ public function __construct(private readonly string $name, private readonly obje throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = ObjectType::fromObject($value); + $this->type = type_object($value::class); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php index f16883019..eeffaefbe 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; @@ -29,7 +30,7 @@ public function __construct(private readonly string $name, private string $value throw InvalidArgumentException::because('Entry name cannot be empty'); } - $this->type = ScalarType::string(); + $this->type = type_string(); } /** diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/UuidEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/UuidEntry.php index 44a0f96f7..ab2d1e860 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/UuidEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/UuidEntry.php @@ -4,6 +4,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_object; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Type; @@ -37,7 +38,7 @@ public function __construct(private readonly string $name, Entry\Type\Uuid|strin $this->value = $value; } - $this->type = ObjectType::fromObject($this->value); + $this->type = type_object($this->value::class); } public static function from(string $name, string $value) : self diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/XMLEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/XMLEntry.php index 607761e71..d67576912 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/XMLEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/XMLEntry.php @@ -2,6 +2,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_object; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Type; @@ -34,7 +35,7 @@ public function __construct(private readonly string $name, \DOMDocument|string $ $this->value = $value; } - $this->type = ObjectType::fromObject($this->value); + $this->type = type_object($this->value::class); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Entry/XMLNodeEntry.php b/src/core/etl/src/Flow/ETL/Row/Entry/XMLNodeEntry.php index 8f04a6d42..600b26f69 100644 --- a/src/core/etl/src/Flow/ETL/Row/Entry/XMLNodeEntry.php +++ b/src/core/etl/src/Flow/ETL/Row/Entry/XMLNodeEntry.php @@ -2,6 +2,7 @@ namespace Flow\ETL\Row\Entry; +use function Flow\ETL\DSL\type_object; use Flow\ETL\PHP\Type\Native\ObjectType; use Flow\ETL\PHP\Type\Type; use Flow\ETL\Row\Entry; @@ -19,7 +20,7 @@ final class XMLNodeEntry implements \Stringable, Entry public function __construct(private readonly string $name, private readonly \DOMNode $value) { - $this->type = ObjectType::fromObject($this->value); + $this->type = type_object($this->value::class); } public function __serialize() : array diff --git a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php index 0abae5b73..9174e49ad 100644 --- a/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php +++ b/src/core/etl/src/Flow/ETL/Row/Factory/NativeEntryFactory.php @@ -4,7 +4,24 @@ namespace Flow\ETL\Row\Factory; -use Flow\ETL\DSL\Entry as EntryDSL; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\enum_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\json_entry; +use function Flow\ETL\DSL\json_object_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\map_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\obj_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\string_entry; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\uuid_entry; +use function Flow\ETL\DSL\xml_entry; +use function Flow\ETL\DSL\xml_node_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\PHP\Type\Logical\ListType; @@ -19,6 +36,8 @@ use Flow\ETL\Row\Entry; use Flow\ETL\Row\EntryFactory; use Flow\ETL\Row\Schema; +use Ramsey\Uuid\UuidInterface; +use Symfony\Component\Uid\Uuid; /** * @implements EntryFactory @@ -56,64 +75,64 @@ public function create(string $entryName, mixed $value, ?Schema $schema = null) if ('' !== $trimmedValue) { if ($this->isJson($trimmedValue)) { - return new Row\Entry\JsonEntry($entryName, $value); + return json_entry($entryName, $value); } if ($this->isUuid($trimmedValue)) { - return new Row\Entry\UuidEntry($entryName, Entry\Type\Uuid::fromString($value)); + return uuid_entry($entryName, Entry\Type\Uuid::fromString($value)); } if ($this->isXML($trimmedValue)) { - return new Entry\XMLEntry($entryName, $value); + return xml_entry($entryName, $value); } } - return new Row\Entry\StringEntry($entryName, $value); + return string_entry($entryName, $value); } if ($valueType->isFloat()) { - return new Row\Entry\FloatEntry($entryName, $value); + return float_entry($entryName, $value); } if ($valueType->isInteger()) { - return new Row\Entry\IntegerEntry($entryName, $value); + return int_entry($entryName, $value); } if ($valueType->isBoolean()) { - return new Row\Entry\BooleanEntry($entryName, $value); + return bool_entry($entryName, $value); } } if ($valueType instanceof ObjectType) { if ($valueType->class === \DOMDocument::class) { - return new Row\Entry\XMLEntry($entryName, $value); + return xml_entry($entryName, $value); } if (\in_array($valueType->class, [\DOMElement::class, \DOMNode::class], true)) { - return new Row\Entry\XMLNodeEntry($entryName, $value); + return xml_node_entry($entryName, $value); } if (\in_array($valueType->class, [\DateTimeImmutable::class, \DateTimeInterface::class, \DateTime::class], true)) { - return new Row\Entry\DateTimeEntry($entryName, $value); + return datetime_entry($entryName, $value); } - if (\in_array($valueType->class, [Entry\Type\Uuid::class, \Ramsey\Uuid\UuidInterface::class, \Symfony\Component\Uid\Uuid::class], true)) { - if (\in_array($valueType->class, [\Ramsey\Uuid\UuidInterface::class, \Symfony\Component\Uid\Uuid::class], true)) { - return new Row\Entry\UuidEntry($entryName, new Entry\Type\Uuid($value)); + if (\in_array($valueType->class, [Entry\Type\Uuid::class, UuidInterface::class, Uuid::class], true)) { + if (\in_array($valueType->class, [UuidInterface::class, Uuid::class], true)) { + return uuid_entry($entryName, new Entry\Type\Uuid($value)); } - return new Row\Entry\UuidEntry($entryName, $value); + return uuid_entry($entryName, $value); } - return new Row\Entry\ObjectEntry($entryName, $value); + return object_entry($entryName, $value); } if ($valueType instanceof EnumType) { - return new Row\Entry\EnumEntry($entryName, $value); + return enum_entry($entryName, $value); } if ($valueType instanceof ArrayType) { - return new Row\Entry\ArrayEntry($entryName, $value); + return array_entry($entryName, $value); } if ($valueType instanceof ListType) { @@ -134,41 +153,41 @@ public function create(string $entryName, mixed $value, ?Schema $schema = null) private function fromDefinition(Schema\Definition $definition, mixed $value) : Entry { if ($definition->isNullable() && null === $value) { - return EntryDSL::null($definition->entry()->name()); + return null_entry($definition->entry()->name()); } try { foreach ($definition->types() as $type) { if ($type === Entry\StringEntry::class) { - return EntryDSL::string($definition->entry()->name(), $value); + return string_entry($definition->entry()->name(), $value); } if ($type === Entry\IntegerEntry::class) { - return EntryDSL::integer($definition->entry()->name(), $value); + return int_entry($definition->entry()->name(), $value); } if ($type === Entry\FloatEntry::class) { - return EntryDSL::float($definition->entry()->name(), $value); + return float_entry($definition->entry()->name(), $value); } if ($type === Entry\BooleanEntry::class) { - return EntryDSL::boolean($definition->entry()->name(), $value); + return bool_entry($definition->entry()->name(), $value); } if ($type === Entry\XMLEntry::class) { - return EntryDSL::xml($definition->entry()->name(), $value); + return xml_entry($definition->entry()->name(), $value); } if ($type === Entry\UuidEntry::class) { - return EntryDSL::uuid($definition->entry()->name(), $value); + return uuid_entry($definition->entry()->name(), $value); } if ($type === Entry\ObjectEntry::class) { - return EntryDSL::object($definition->entry()->name(), $value); + return obj_entry($definition->entry()->name(), $value); } if ($type === Entry\DateTimeEntry::class) { - return EntryDSL::datetime($definition->entry()->name(), $value); + return datetime_entry($definition->entry()->name(), $value); } if ($type === Entry\EnumEntry::class) { @@ -179,7 +198,7 @@ private function fromDefinition(Schema\Definition $definition, mixed $value) : E foreach ($cases as $case) { if ($case->name === $value) { - return EntryDSL::enum($definition->entry()->name(), $case); + return enum_entry($definition->entry()->name(), $case); } } @@ -188,28 +207,28 @@ private function fromDefinition(Schema\Definition $definition, mixed $value) : E if ($type === Entry\JsonEntry::class) { try { - return EntryDSL::json_object($definition->entry()->name(), $value); + return json_object_entry($definition->entry()->name(), $value); } catch (InvalidArgumentException) { - return EntryDSL::json($definition->entry()->name(), $value); + return json_entry($definition->entry()->name(), $value); } } if ($type === Entry\ArrayEntry::class) { - return EntryDSL::array($definition->entry()->name(), $value); + return array_entry($definition->entry()->name(), $value); } if ($type === Entry\MapEntry::class) { /** @var MapType $entryType */ $entryType = $definition->metadata()->get(Schema\FlowMetadata::METADATA_MAP_ENTRY_TYPE); - return EntryDSL::map($definition->entry()->name(), $value, $entryType); + return map_entry($definition->entry()->name(), $value, $entryType); } if ($type === Entry\StructureEntry::class) { /** @var StructureType $entryType */ $entryType = $definition->metadata()->get(Schema\FlowMetadata::METADATA_STRUCTURE_ENTRY_TYPE); - return EntryDSL::structure($definition->entry()->name(), $value, $entryType); + return struct_entry($definition->entry()->name(), $value, $entryType); } if ($type === Entry\ListEntry::class) { @@ -223,7 +242,7 @@ private function fromDefinition(Schema\Definition $definition, mixed $value) : E $firstValue = \current($value); if (\is_a($elementType->type()->class, \DateTimeInterface::class, true) && \is_string($firstValue)) { - return new Entry\ListEntry( + return list_entry( $definition->entry()->name(), \array_map(static fn (string $datetime) : \DateTimeImmutable => new \DateTimeImmutable($datetime), $value), $entryType, diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Formatter/ASCIISchemaFormatter.php b/src/core/etl/src/Flow/ETL/Row/Schema/Formatter/ASCIISchemaFormatter.php index 8deb24025..869b53759 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Formatter/ASCIISchemaFormatter.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema/Formatter/ASCIISchemaFormatter.php @@ -4,13 +4,16 @@ namespace Flow\ETL\Row\Schema\Formatter; +use function Flow\ETL\DSL\type_array; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ArrayType; use Flow\ETL\PHP\Type\Native\EnumType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Type; use Flow\ETL\Row\Entry\ArrayEntry; use Flow\ETL\Row\Entry\BooleanEntry; @@ -64,21 +67,21 @@ private function definitionTypesFromEntry(array $types, bool $nullable, Schema\M foreach ($types as $type) { /** @var Type $definitionType */ $definitionType = match ($type) { - ArrayEntry::class => new ArrayType($nullable), - BooleanEntry::class => ScalarType::boolean($nullable), - DateTimeEntry::class => ObjectType::of(\DateTimeImmutable::class, $nullable), + ArrayEntry::class => type_array($nullable), + BooleanEntry::class => type_boolean($nullable), + DateTimeEntry::class => type_object(\DateTimeImmutable::class, $nullable), EnumEntry::class => EnumType::of(\UnitEnum::class, $nullable), - FloatEntry::class => ScalarType::float($nullable), - IntegerEntry::class => ScalarType::integer($nullable), - StringEntry::class, JsonEntry::class => ScalarType::string($nullable), + FloatEntry::class => type_float($nullable), + IntegerEntry::class => type_int($nullable), + StringEntry::class, JsonEntry::class => type_string($nullable), ListEntry::class => $metadata->get(FlowMetadata::METADATA_LIST_ENTRY_TYPE), MapEntry::class => $metadata->get(FlowMetadata::METADATA_MAP_ENTRY_TYPE), ObjectEntry::class => $metadata->get(FlowMetadata::METADATA_OBJECT_ENTRY_TYPE), - UuidEntry::class => ObjectType::of(Uuid::class, $nullable), - XMLEntry::class => ObjectType::of(\DOMDocument::class, $nullable), - XMLNodeEntry::class => ObjectType::of(\DOMElement::class, $nullable), + UuidEntry::class => type_object(Uuid::class, $nullable), + XMLEntry::class => type_object(\DOMDocument::class, $nullable), + XMLNodeEntry::class => type_object(\DOMElement::class, $nullable), // Fallback - StructureEntry::class => new ArrayType(false), + StructureEntry::class => type_array(false), default => throw new InvalidArgumentException('Unknown entry type given: ' . $type) }; diff --git a/src/core/etl/src/Flow/ETL/Rows.php b/src/core/etl/src/Flow/ETL/Rows.php index 826da9355..16d09f7df 100644 --- a/src/core/etl/src/Flow/ETL/Rows.php +++ b/src/core/etl/src/Flow/ETL/Rows.php @@ -5,7 +5,7 @@ namespace Flow\ETL; use function Flow\ETL\DSL\array_to_rows; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\null_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Join\Expression; @@ -369,7 +369,7 @@ public function joinLeft(self $right, Expression $expression) : self $joined[] = $joinedRow ?: $leftRow->merge( Row::create( ...\array_map( - static fn (string $e) : NullEntry => Entry::null($e), + static fn (string $e) : NullEntry => null_entry($e), \array_map( static fn (Reference $r) : string => $r->name(), $rightSchema->entries() @@ -446,7 +446,7 @@ public function joinRight(self $right, Expression $expression) : self if ($joinedRow === null) { $joined[] = $rightRow->merge( Row::create( - ...\array_map(static fn (Reference $e) : NullEntry => Entry::null($e->name()), $leftSchema->entries()) + ...\array_map(static fn (Reference $e) : NullEntry => null_entry($e->name()), $leftSchema->entries()) ), $expression->prefix() ); diff --git a/src/core/etl/src/Flow/ETL/Transformer/KeepEntriesTransformer.php b/src/core/etl/src/Flow/ETL/Transformer/KeepEntriesTransformer.php index 7ff776430..c328f05ac 100644 --- a/src/core/etl/src/Flow/ETL/Transformer/KeepEntriesTransformer.php +++ b/src/core/etl/src/Flow/ETL/Transformer/KeepEntriesTransformer.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Transformer; -use Flow\ETL\DSL\Entry as EntryDSL; +use function Flow\ETL\DSL\null_entry; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Row\Entry; @@ -50,7 +50,7 @@ public function transform(Rows $rows, FlowContext $context) : Rows foreach ($this->refs as $keepEntryName) { if (!$newEntries->entries()->has($keepEntryName)) { - $newEntries = $newEntries->add(EntryDSL::null($keepEntryName->name())); + $newEntries = $newEntries->add(null_entry($keepEntryName->name())); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Double/AllRowTypesFakeExtractor.php b/src/core/etl/tests/Flow/ETL/Tests/Double/AllRowTypesFakeExtractor.php index 449ed7198..c0f2737a2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Double/AllRowTypesFakeExtractor.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Double/AllRowTypesFakeExtractor.php @@ -4,15 +4,25 @@ namespace Flow\ETL\Tests\Double; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\enum_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\map_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_map; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; -use Flow\ETL\PHP\Type\Logical\Map\MapKey; -use Flow\ETL\PHP\Type\Logical\Map\MapValue; -use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\ETL\Tests\Fixtures\Enum\BackedStringEnum; @@ -37,35 +47,35 @@ public function extract(FlowContext $context) : \Generator for ($r = 0; $r < $this->rowsSize; $r++) { $rows[] = Row::create( - Entry::integer('id', $id + $r), - Entry::float('price', \random_int(100, 100000) / 100), - Entry::boolean('deleted', false), - Entry::datetime('created-at', new \DateTimeImmutable('now')), - Entry::null('phase'), - Entry::integer('status', 0), - Entry::array( + int_entry('id', $id + $r), + float_entry('price', \random_int(100, 100000) / 100), + bool_entry('deleted', false), + datetime_entry('created-at', new \DateTimeImmutable('now')), + null_entry('phase'), + int_entry('status', 0), + array_entry( 'array', [ ['id' => 1, 'status' => 'NEW'], ['id' => 2, 'status' => 'PENDING'], ] ), - Entry::list_of_int('list', [1, 2, 3]), - Entry::map( + list_entry('list', [1, 2, 3], type_list(type_int())), + map_entry( 'map', ['NEW', 'PENDING'], - new MapType(MapKey::integer(), MapValue::string()) + type_map(type_int(), type_string()) ), - Entry::structure( + struct_entry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType( - new StructureElement('item-id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + struct_type( + struct_element('item-id', type_int()), + struct_element('name', type_string()) ) ), - Entry::object('object', new \ArrayIterator([1, 2, 3])), - Entry::enum('enum', BackedStringEnum::three) + object_entry('object', new \ArrayIterator([1, 2, 3])), + enum_entry('enum', BackedStringEnum::three) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Fixtures/with-dataframe.php b/src/core/etl/tests/Flow/ETL/Tests/Fixtures/with-dataframe.php index 27c86b949..7d7f73768 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Fixtures/with-dataframe.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Fixtures/with-dataframe.php @@ -2,15 +2,15 @@ declare(strict_types=1); -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Flow; use Flow\ETL\Row; use Flow\ETL\Rows; return (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php index 8743521f9..1065084d7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Integration\Cache; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Cache\PSRSimpleCache; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\ETL\Tests\Integration\IntegrationTestCase; @@ -24,9 +24,9 @@ public function test_saving_to_psr_simple_cache_implementation() : void $this->assertFalse($cache->has('test')); - $cache->add('test', new Rows(Row::create(Entry::int('id', 1)))); - $cache->add('test', new Rows(Row::create(Entry::int('id', 2)))); - $cache->add('test', new Rows(Row::create(Entry::int('id', 3)))); + $cache->add('test', new Rows(Row::create(int_entry('id', 1)))); + $cache->add('test', new Rows(Row::create(int_entry('id', 2)))); + $cache->add('test', new Rows(Row::create(int_entry('id', 3)))); $this->assertCount( 3, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/CacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/CacheTest.php index 5a9cf189e..94282b3b1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/CacheTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/CacheTest.php @@ -2,10 +2,10 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_cache; use Flow\ETL\Cache\PSRSimpleCache; use Flow\ETL\Config; -use Flow\ETL\DSL\From; -use Flow\ETL\Flow; use Flow\ETL\Tests\Double\AllRowTypesFakeExtractor; use Flow\ETL\Tests\Integration\IntegrationTestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -15,7 +15,8 @@ final class CacheTest extends IntegrationTestCase { public function test_cache() : void { - (new Flow())->extract(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) + df() + ->read(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) ->cache('test_etl_cache') ->run(); @@ -26,15 +27,12 @@ public function test_cache() : void public function test_psr_cache() : void { - Flow::setUp( - Config::builder()->cache($cache = new PSRSimpleCache(new Psr16Cache(new ArrayAdapter())))->build() - )->extract(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) + df(Config::builder()->cache($cache = new PSRSimpleCache(new Psr16Cache(new ArrayAdapter())))->build()) + ->read(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) ->cache('test_etl_cache') ->run(); - $cachedRows = Flow::setUp(Config::builder()->cache($cache)->build()) - ->read(From::cache('test_etl_cache')) - ->fetch(); + $cachedRows = df(Config::builder()->cache($cache)->build())->from(from_cache('test_etl_cache'))->fetch(); $this->assertCount($rowsets * $rows, $cachedRows); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/DisplayTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/DisplayTest.php index c4f9e070e..e3c688ff6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/DisplayTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/DisplayTest.php @@ -2,10 +2,14 @@ namespace Flow\ETL\Tests\Integration\DataFrame; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Extractor; -use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; @@ -14,7 +18,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row; use Flow\ETL\Row\Entry\ArrayEntry; use Flow\ETL\Row\Entry\BooleanEntry; @@ -33,8 +36,8 @@ final class DisplayTest extends IntegrationTestCase { public function test_display() : void { - $etl = (new Flow())->extract( - new class implements Extractor { + $etl = df() + ->read(new class implements Extractor { /** * @return \Generator */ @@ -70,8 +73,8 @@ public function extract(FlowContext $context) : \Generator 'items', ['item-id' => '1', 'name' => 'one'], new StructureType( - new StructureElement('item-id', ScalarType::string()), - new StructureElement('name', ScalarType::string()), + new StructureElement('item-id', type_string()), + new StructureElement('name', type_string()), ) ), new Row\Entry\ObjectEntry('object', new \ArrayIterator([1, 2, 3])), @@ -81,8 +84,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ); + }); $this->assertSame( <<<'ASCIITABLE' @@ -122,47 +124,45 @@ public function extract(FlowContext $context) : \Generator public function test_display_with_very_long_entry_name() : void { - $etl = (new Flow()) - ->read( - From::array([ - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + $etl = df() + ->read(from_array([ + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + ], + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + ], + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + ], + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + ], + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - [ - 'this is very long entry name that should be longer than items' => [ - ['id' => 1, 'status' => 'NEW'], - ['id' => 2, 'status' => 'PENDING'], - ], + ], + [ + 'this is very long entry name that should be longer than items' => [ + ['id' => 1, 'status' => 'NEW'], + ['id' => 2, 'status' => 'PENDING'], ], - ]) - ); + ], + ])); $this->assertStringContainsString( <<<'ASCIITABLE' @@ -200,17 +200,19 @@ public function test_display_with_very_long_entry_name() : void public function test_print_rows() : void { \ob_start(); - (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - ), - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::integer('salary', 5000)), - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::null('salary')), - ) - )->printRows(); + df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + ), + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), int_entry('salary', 5000)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), null_entry('salary')), + ) + )) + ->printRows(); $output = \ob_get_clean(); $this->assertStringContainsString( @@ -238,17 +240,19 @@ public function test_print_rows() : void public function test_print_schema() : void { \ob_start(); - (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - ), - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::integer('salary', 5000)), - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::null('salary')), - ) - )->printSchema(); + df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + ), + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), int_entry('salary', 5000)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), null_entry('salary')), + ) + )) + ->printSchema(); $output = \ob_get_clean(); $this->assertStringContainsString( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php index 9f5e121da..ccd6e9698 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/GroupByTest.php @@ -4,16 +4,22 @@ use function Flow\ETL\DSL\average; use function Flow\ETL\DSL\count; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\from_memory; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\max; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\rank; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\sum; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\DSL\Transform; -use Flow\ETL\Flow; use Flow\ETL\Loader; use Flow\ETL\Memory\ArrayMemory; use Flow\ETL\Row; @@ -28,18 +34,19 @@ public function test_group_by_multiple_columns_and_batch_size() : void $loader->expects($this->exactly(4)) ->method('load'); - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50), Entry::string('gender', 'male')), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25), str_entry('gender', 'male')), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30), str_entry('gender', 'female')), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'female')), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'male')), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45), str_entry('gender', 'female')), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50), str_entry('gender', 'male')), + ) + )) ->groupBy('country', 'gender') ->batchSize(1) ->write($loader) @@ -47,10 +54,10 @@ public function test_group_by_multiple_columns_and_batch_size() : void $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'male')), - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'female')), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'female')), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'male')), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'male')), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'female')), + Row::create(str_entry('country', 'US'), str_entry('gender', 'female')), + Row::create(str_entry('country', 'US'), str_entry('gender', 'male')), ), $rows ); @@ -58,28 +65,29 @@ public function test_group_by_multiple_columns_and_batch_size() : void public function test_group_by_multiples_columns_with_avg_aggregation() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50), Entry::string('gender', 'male')), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25), str_entry('gender', 'male')), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30), str_entry('gender', 'female')), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'female')), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'male')), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45), str_entry('gender', 'female')), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50), str_entry('gender', 'male')), + ) + )) ->groupBy('country', 'gender') ->aggregate(average(ref('age'))) ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'male'), Entry::float('age_avg', 21.666666666666668)), - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'female'), Entry::integer('age_avg', 30)), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'female'), Entry::float('age_avg', 42.5)), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'male'), Entry::integer('age_avg', 45)), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'male'), float_entry('age_avg', 21.666666666666668)), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'female'), int_entry('age_avg', 30)), + Row::create(str_entry('country', 'US'), str_entry('gender', 'female'), float_entry('age_avg', 42.5)), + Row::create(str_entry('country', 'US'), str_entry('gender', 'male'), int_entry('age_avg', 45)), ), $rows ); @@ -87,29 +95,30 @@ public function test_group_by_multiples_columns_with_avg_aggregation() : void public function test_group_by_multiples_columns_with_avg_aggregation_with_null() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45), Entry::null('gender')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50), Entry::string('gender', 'male')), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25), str_entry('gender', 'male')), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30), str_entry('gender', 'female')), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'female')), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'male')), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45), null_entry('gender')), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50), str_entry('gender', 'male')), + ) + )) ->groupBy('country', 'gender') ->aggregate(average(ref('age'))) ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'male'), Entry::float('age_avg', 21.666666666666668)), - Row::create(Entry::string('country', 'PL'), Entry::string('gender', 'female'), Entry::integer('age_avg', 30)), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'female'), Entry::integer('age_avg', 40)), - Row::create(Entry::string('country', 'US'), Entry::string('gender', 'male'), Entry::integer('age_avg', 45)), - Row::create(Entry::string('country', 'US'), Entry::null('gender'), Entry::integer('age_avg', 45)), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'male'), float_entry('age_avg', 21.666666666666668)), + Row::create(str_entry('country', 'PL'), str_entry('gender', 'female'), int_entry('age_avg', 30)), + Row::create(str_entry('country', 'US'), str_entry('gender', 'female'), int_entry('age_avg', 40)), + Row::create(str_entry('country', 'US'), str_entry('gender', 'male'), int_entry('age_avg', 45)), + Row::create(str_entry('country', 'US'), null_entry('gender'), int_entry('age_avg', 45)), ), $rows ); @@ -117,25 +126,26 @@ public function test_group_by_multiples_columns_with_avg_aggregation_with_null() public function test_group_by_single_column() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->groupBy('country') ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'PL')), - Row::create(Entry::string('country', 'US')), + Row::create(str_entry('country', 'PL')), + Row::create(str_entry('country', 'US')), ), $rows ); @@ -143,26 +153,27 @@ public function test_group_by_single_column() : void public function test_group_by_single_column_with_avg_aggregation() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->groupBy('country') ->aggregate(average(ref('age'))) ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'PL'), Entry::float('age_avg', 23.75)), - Row::create(Entry::string('country', 'US'), Entry::float('age_avg', 43.75)), + Row::create(str_entry('country', 'PL'), float_entry('age_avg', 23.75)), + Row::create(str_entry('country', 'US'), float_entry('age_avg', 43.75)), ), $rows ); @@ -185,8 +196,8 @@ public function test_group_by_twice() : void ['date' => '2023-01-03', 'user' => 'user_04'], ]; - $rows = (new Flow()) - ->read(From::array($dataset)) + $rows = df() + ->read(from_array($dataset)) ->groupBy(ref('date'), ref('user')) ->aggregate(count(ref('user'))) ->rename('user_count', 'contributions') @@ -224,13 +235,8 @@ public function test_pivot() : void ['date' => '2023-11-05', 'user' => 'stloyd', 'contributions' => 11], ]; - $rows = (new Flow()) - ->read( - From::chain( - From::array($dataset1), - From::array($dataset2), - ) - ) + $rows = df() + ->read(from_all(from_array($dataset1), from_array($dataset2))) ->groupBy(ref('date')) ->pivot(ref('user')) ->aggregate(sum(ref('contributions'))) @@ -270,25 +276,26 @@ public function test_pivot() : void public function test_standalone_avg_aggregation() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->aggregate(average(ref('age'))) ->rows(Transform::rename('age_avg', 'average_age')) ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::float('average_age', 33.75)), + Row::create(float_entry('average_age', 33.75)), ), $rows ); @@ -296,25 +303,26 @@ public function test_standalone_avg_aggregation() : void public function test_standalone_avg_and_max_aggregation() : void { - (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->aggregate(average(ref('age')), max(ref('age'))) ->run(function (Rows $rows) : void { $this->assertEquals( new Rows( Row::create( - Entry::float('age_avg', 33.75), - Entry::integer('age_max', 50) + float_entry('age_avg', 33.75), + int_entry('age_max', 50) ) ), $rows @@ -348,8 +356,8 @@ public function test_window_avg_function() : void ['department' => 'Marketing', 'avg_salary' => 2940.0], ['department' => 'Finance', 'avg_salary' => 3550.0], ], - (new Flow) - ->read(From::chain(From::memory($memoryPage1), From::memory($memoryPage2))) + df() + ->from(from_all(from_memory($memoryPage1), from_memory($memoryPage2))) ->withEntry('avg_salary', average(ref('salary'))->over(window()->partitionBy(ref('department')))) ->select('department', 'avg_salary') ->dropDuplicates(ref('department'), ref('avg_salary')) @@ -394,8 +402,8 @@ public function test_window_rank_function() : void ['employee_name' => 'Sophia', 'department' => 'Finance', 'salary' => 4200, 'rank' => 1], ['employee_name' => 'Noah', 'department' => 'Marketing', 'salary' => 3400, 'rank' => 1], ], - (new Flow) - ->read(From::all(From::memory($memoryPage1), From::memory($memoryPage2))) + df() + ->from(from_all(from_memory($memoryPage1), from_memory($memoryPage2))) ->dropDuplicates(ref('employee_name'), ref('department')) ->withEntry('rank', rank()->over(window()->partitionBy(ref('department'))->orderBy(ref('salary')->desc()))) ->filter(ref('rank')->equals(lit(1))) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/JoinTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/JoinTest.php index 7d4c63368..a6214ad66 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/JoinTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/JoinTest.php @@ -2,9 +2,14 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\string_entry; use Flow\ETL\DataFrame; use Flow\ETL\DataFrameFactory; -use Flow\ETL\DSL\Entry; use Flow\ETL\Flow; use Flow\ETL\Join\Expression; use Flow\ETL\Loader; @@ -20,20 +25,21 @@ public function test_cross_join() : void $loader->expects($this->exactly(2)) ->method('load'); - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL')), - ) - ) + $rows = df() + ->from(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'PL')), + Row::create(int_entry('id', 4), str_entry('country', 'PL')), + ) + )) ->batchSize(2) ->crossJoin( (new Flow())->process( new Rows( - Row::create(Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('num', 2), Entry::boolean('active', false)), + Row::create(int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('num', 2), bool_entry('active', false)), ) ), ) @@ -42,14 +48,14 @@ public function test_cross_join() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), ), $rows ); @@ -61,24 +67,25 @@ public function test_join() : void $loader->expects($this->exactly(2)) ->method('load'); - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US')), - ) - ) + $rows = df() + ->from(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'PL')), + Row::create(int_entry('id', 4), str_entry('country', 'PL')), + Row::create(int_entry('id', 5), str_entry('country', 'US')), + Row::create(int_entry('id', 6), str_entry('country', 'US')), + Row::create(int_entry('id', 7), str_entry('country', 'US')), + Row::create(int_entry('id', 9), str_entry('country', 'US')), + ) + )) ->batchSize(4) ->join( (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), ) ), Expression::on(['country' => 'code']), @@ -88,14 +95,14 @@ public function test_join() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::string('name', 'United States')), + Row::create(int_entry('id', 1), string_entry('country', 'PL'), string_entry('name', 'Poland')), + Row::create(int_entry('id', 2), string_entry('country', 'PL'), string_entry('name', 'Poland')), + Row::create(int_entry('id', 3), string_entry('country', 'PL'), string_entry('name', 'Poland')), + Row::create(int_entry('id', 4), string_entry('country', 'PL'), string_entry('name', 'Poland')), + Row::create(int_entry('id', 5), string_entry('country', 'US'), string_entry('name', 'United States')), + Row::create(int_entry('id', 6), string_entry('country', 'US'), string_entry('name', 'United States')), + Row::create(int_entry('id', 7), string_entry('country', 'US'), string_entry('name', 'United States')), + Row::create(int_entry('id', 9), string_entry('country', 'US'), string_entry('name', 'United States')), ), $rows ); @@ -107,18 +114,19 @@ public function test_join_each() : void $loader->expects($this->exactly(2)) ->method('load'); - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US')), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'PL')), + Row::create(int_entry('id', 4), str_entry('country', 'PL')), + Row::create(int_entry('id', 5), str_entry('country', 'US')), + Row::create(int_entry('id', 6), str_entry('country', 'US')), + Row::create(int_entry('id', 7), str_entry('country', 'US')), + Row::create(int_entry('id', 9), str_entry('country', 'US')), + ) + )) ->batchSize(4) ->joinEach( new class implements DataFrameFactory { @@ -126,8 +134,8 @@ public function from(Rows $rows) : DataFrame { return (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), ) ); } @@ -148,14 +156,14 @@ public function __unserialize(array $data) : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::string('name', 'United States')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 5), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 6), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 7), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 9), str_entry('country', 'US'), str_entry('name', 'United States')), ), $rows ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php index e771ec017..700b27a4c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php @@ -2,11 +2,12 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\from_rows; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Extractor; -use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Row\Entry\ArrayEntry; @@ -18,13 +19,13 @@ final class LimitTest extends IntegrationTestCase { public function test_exceeding_the_limit_in_one_rows_set() : void { - $rows = (new Flow()) - ->read( - From::array(\array_map( + $rows = df() + ->read(from_array( + \array_map( fn (int $id) : array => ['id' => $id], \range(1, 1000) - )) - ) + ) + )) ->limit(9) ->fetch(); @@ -33,8 +34,8 @@ public function test_exceeding_the_limit_in_one_rows_set() : void public function test_fetch_with_limit() : void { - $rows = (new Flow()) - ->read(From::array([ + $rows = df() + ->from(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], @@ -56,14 +57,13 @@ public function test_fetch_with_limit_below_0() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Limit can't be lower or equal zero, given: -1"); - (new Flow())->process(new Rows()) - ->fetch(-1); + df()->read(from_rows(new Rows()))->fetch(-1); } public function test_fetch_without_limit() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -77,8 +77,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->fetch(); $this->assertCount(20, $rows); @@ -86,8 +85,8 @@ public function extract(FlowContext $context) : \Generator public function test_limit() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -102,8 +101,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->limit(10) ->fetch(); @@ -115,14 +113,13 @@ public function test_limit_below_0() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Limit can't be lower or equal zero, given: -1"); - (new Flow())->process(new Rows()) - ->limit(-1); + df()->read(from_rows(new Rows()))->limit(-1); } public function test_limit_when_transformation_is_expanding_rows_extracted_from_extractor() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -140,8 +137,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->withEntries([ 'expanded' => ref('ids')->expand(), 'element' => ref('expanded')->unpack(), @@ -157,8 +153,8 @@ public function extract(FlowContext $context) : \Generator public function test_limit_with_batch_size() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -173,8 +169,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->batchSize(50) ->limit(10) ->fetch(); @@ -184,8 +179,8 @@ public function extract(FlowContext $context) : \Generator public function test_limit_with_collecting() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -200,8 +195,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->limit(10) ->collect() ->fetch(); @@ -211,8 +205,8 @@ public function extract(FlowContext $context) : \Generator public function test_with_total_rows_below_the_limit() : void { - $rows = (new Flow())->extract( - new class implements Extractor { + $rows = df() + ->read(new class implements Extractor { /** * @param FlowContext $context * @@ -226,8 +220,7 @@ public function extract(FlowContext $context) : \Generator ); } } - } - ) + }) ->limit(10) ->fetch(); 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 7f9a39bf4..7943a7904 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 @@ -2,10 +2,12 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\Partitions; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\ETL\Tests\Integration\IntegrationTestCase; @@ -14,28 +16,29 @@ final class PartitioningTest extends IntegrationTestCase { public function test_filter_partitions() : void { - $partitionedRows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + $partitionedRows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->partitionBy('country') - ->filterPartitions(Partitions::chain(Partitions::only('country', 'US'))) + ->filterPartitions(ref('country')->equals(lit('US'))) ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), ), $partitionedRows ); @@ -43,18 +46,19 @@ public function test_filter_partitions() : void public function test_partition_by() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), + ) + )) ->partitionBy(ref('country')) ->batchSize(2) // split each partition into two ->get(); @@ -62,20 +66,20 @@ public function test_partition_by() : void $this->assertEquals( [ new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)) + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)) ), new Rows( - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), ), new Rows( - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)) + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)) ), new Rows( - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), ), ], \iterator_to_array($rows) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/RenameTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/RenameTest.php index 9925a48a0..7b34d1afa 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/RenameTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/RenameTest.php @@ -2,10 +2,14 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\Flow; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\ETL\Tests\Integration\IntegrationTestCase; @@ -15,21 +19,22 @@ final class RenameTest extends IntegrationTestCase { public function test_rename() : void { - $rows = (new Flow())->process( - new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), - ) - ) + $rows = df() + ->read(from_rows( + new Rows( + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), + ) + )) ->rename('name', 'new_name') ->fetch(); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('new_name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('new_name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('new_name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('new_name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('new_name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('new_name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -38,12 +43,12 @@ public function test_rename() : void public function test_rename_all() : void { $rows = new Rows( - Row::create(Entry::array('array', ['id' => 1, 'name' => 'name', 'active' => true])), - Row::create(Entry::array('array', ['id' => 2, 'name' => 'name', 'active' => false])) + Row::create(array_entry('array', ['id' => 1, 'name' => 'name', 'active' => true])), + Row::create(array_entry('array', ['id' => 2, 'name' => 'name', 'active' => false])) ); - $ds = (new Flow()) - ->read(From::rows($rows)) + $ds = df() + ->read(from_rows($rows)) ->withEntry('row', ref('array')->unpack()) ->renameAll('row.', '') ->drop('array') @@ -61,14 +66,11 @@ public function test_rename_all() : void public function test_rename_all_lower_case() : void { $rows = new Rows( - Row::create(Entry::int('ID', 1), Entry::str('NAME', 'name'), Entry::bool('ACTIVE', true)), - Row::create(Entry::int('ID', 2), Entry::str('NAME', 'name'), Entry::bool('ACTIVE', false)), + Row::create(int_entry('ID', 1), str_entry('NAME', 'name'), bool_entry('ACTIVE', true)), + Row::create(int_entry('ID', 2), str_entry('NAME', 'name'), bool_entry('ACTIVE', false)), ); - $ds = (new Flow()) - ->read(From::rows($rows)) - ->renameAllLowerCase() - ->getEachAsArray(); + $ds = df()->read(from_rows($rows))->renameAllLowerCase()->getEachAsArray(); $this->assertEquals( [ @@ -82,12 +84,12 @@ public function test_rename_all_lower_case() : void public function test_rename_all_to_snake_case() : void { $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('UserName', 'name'), Entry::bool('isActive', true)), - Row::create(Entry::int('id', 2), Entry::str('UserName', 'name'), Entry::bool('isActive', false)), + Row::create(int_entry('id', 1), str_entry('UserName', 'name'), bool_entry('isActive', true)), + Row::create(int_entry('id', 2), str_entry('UserName', 'name'), bool_entry('isActive', false)), ); - $ds = (new Flow()) - ->read(From::rows($rows)) + $ds = df() + ->read(from_rows($rows)) ->renameAllStyle(StringStyles::SNAKE) ->renameAllLowerCase() ->getEachAsArray(); @@ -104,12 +106,12 @@ public function test_rename_all_to_snake_case() : void public function test_rename_all_upper_case() : void { $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name'), Entry::bool('active', true)), - Row::create(Entry::int('id', 2), Entry::str('name', 'name'), Entry::bool('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'name'), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('name', 'name'), bool_entry('active', false)), ); - $ds = (new Flow()) - ->read(From::rows($rows)) + $ds = df() + ->read(from_rows($rows)) ->renameAllUpperCase() ->getEachAsArray(); @@ -125,12 +127,12 @@ public function test_rename_all_upper_case() : void public function test_rename_all_upper_case_first() : void { $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name'), Entry::bool('active', true)), - Row::create(Entry::int('id', 2), Entry::str('name', 'name'), Entry::bool('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'name'), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('name', 'name'), bool_entry('active', false)), ); - $ds = (new Flow()) - ->read(From::rows($rows)) + $ds = df() + ->read(from_rows($rows)) ->renameAllUpperCaseFirst() ->getEachAsArray(); @@ -146,12 +148,12 @@ public function test_rename_all_upper_case_first() : void public function test_rename_all_upper_case_word() : void { $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name'), Entry::bool('active', true)), - Row::create(Entry::int('id', 2), Entry::str('name', 'name'), Entry::bool('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'name'), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('name', 'name'), bool_entry('active', false)), ); - $ds = (new Flow()) - ->read(From::rows($rows)) + $ds = df() + ->read(from_rows($rows)) ->renameAllUpperCaseWord() ->getEachAsArray(); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SortTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SortTest.php index db25e7867..702642109 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SortTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SortTest.php @@ -2,10 +2,10 @@ namespace Flow\ETL\Tests\Integration\DataFrame; +use function Flow\ETL\DSL\df; use function Flow\ETL\DSL\ref; use Flow\ETL\Config; use Flow\ETL\ExternalSort\MemorySort; -use Flow\ETL\Flow; use Flow\ETL\Monitoring\Memory\Unit; use Flow\ETL\Tests\Double\AllRowTypesFakeExtractor; use Flow\ETL\Tests\Double\CacheSpy; @@ -17,12 +17,13 @@ public function test_etl_sort_at_disk_in_memory() : void { \ini_set('memory_limit', '500M'); - Flow::setUp( - Config::builder() - ->id($id = 'test_etl_sort_by_in_memory') - ->cache($cacheSpy = new CacheSpy(Config::default()->cache())) - ->externalSort(new MemorySort($id, $cacheSpy, Unit::fromKb(10))) - )->extract(new AllRowTypesFakeExtractor($rowsets = 50, $rows = 50)) + $config = Config::builder() + ->id($id = 'test_etl_sort_by_in_memory') + ->cache($cacheSpy = new CacheSpy(Config::default()->cache())) + ->externalSort(new MemorySort($id, $cacheSpy, Unit::fromKb(10))); + + df($config) + ->read(new AllRowTypesFakeExtractor($rowsets = 50, $rows = 50)) ->sortBy(ref('id')) ->run(); @@ -44,11 +45,12 @@ public function test_etl_sort_by_in_memory() : void { \ini_set('memory_limit', '-1'); - $rows = Flow::setUp( - Config::builder() - ->id($id = 'test_etl_sort_by_in_memory') - ->cache($cacheSpy = new CacheSpy(Config::default()->cache())) - )->extract(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) + $config = Config::builder() + ->id($id = 'test_etl_sort_by_in_memory') + ->cache($cacheSpy = new CacheSpy(Config::default()->cache())); + + $rows = df($config) + ->read(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) ->sortBy(ref('id')) ->fetch(); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/FilesystemStreamsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/FilesystemStreamsTest.php index 91232fa65..c59a5b164 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/FilesystemStreamsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/FilesystemStreamsTest.php @@ -2,7 +2,8 @@ namespace Flow\ETL\Tests\Integration\Filesystem; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Filesystem\FilesystemStreams; use Flow\ETL\Filesystem\LocalFilesystem; use Flow\ETL\Filesystem\Path; @@ -41,11 +42,11 @@ public function test_closing_stream_with_non_append_safe_base_path() : void public function test_open_partitioned_rows() : void { $rows = (new Rows(...[ - Row::create(Entry::integer('id', 1), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 2), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 3), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 4), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 5), Entry::string('group', 'b')), + Row::create(int_entry('id', 1), str_entry('group', 'a')), + Row::create(int_entry('id', 2), str_entry('group', 'a')), + Row::create(int_entry('id', 3), str_entry('group', 'b')), + Row::create(int_entry('id', 4), str_entry('group', 'b')), + Row::create(int_entry('id', 5), str_entry('group', 'b')), ]))->partitionBy('group')[0]; $stream = (new FilesystemStreams(new LocalFilesystem())) @@ -69,11 +70,11 @@ public function test_open_partitioned_rows() : void public function test_open_rows() : void { (new Rows(...[ - Row::create(Entry::integer('id', 1), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 2), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 3), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 4), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 5), Entry::string('group', 'b')), + Row::create(int_entry('id', 1), str_entry('group', 'a')), + Row::create(int_entry('id', 2), str_entry('group', 'a')), + Row::create(int_entry('id', 3), str_entry('group', 'b')), + Row::create(int_entry('id', 4), str_entry('group', 'b')), + Row::create(int_entry('id', 5), str_entry('group', 'b')), ])); $stream = (new FilesystemStreams(new LocalFilesystem())) @@ -224,11 +225,11 @@ public function test_opening_multiple_partitions_in_overwrite_mode() : void public function test_overwrite_mode_on_processed_partitions() : void { $partitionedRows = (new Rows(...[ - Row::create(Entry::integer('id', 1), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 2), Entry::string('group', 'a')), - Row::create(Entry::integer('id', 3), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 4), Entry::string('group', 'b')), - Row::create(Entry::integer('id', 5), Entry::string('group', 'b')), + Row::create(int_entry('id', 1), str_entry('group', 'a')), + Row::create(int_entry('id', 2), str_entry('group', 'a')), + Row::create(int_entry('id', 3), str_entry('group', 'b')), + Row::create(int_entry('id', 4), str_entry('group', 'b')), + Row::create(int_entry('id', 5), str_entry('group', 'b')), ]))->partitionBy('group'); $streams = new FilesystemStreams(new LocalFilesystem()); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php index b0e16fa18..e67b4d0e6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php @@ -4,11 +4,15 @@ namespace Flow\ETL\Tests\Integration\Filesystem; -use Flow\ETL\DSL\Partitions; +use function Flow\ETL\DSL\all; +use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\ref; use Flow\ETL\Filesystem\LocalFilesystem; use Flow\ETL\Filesystem\Path; use Flow\ETL\Filesystem\Stream\Mode; use Flow\ETL\Partition\NoopFilter; +use Flow\ETL\Partition\ScalarFunctionFilter; +use Flow\ETL\Row\Factory\NativeEntryFactory; use PHPUnit\Framework\TestCase; final class LocalFilesystemTest extends TestCase @@ -81,9 +85,15 @@ public function test_reading_multi_partitioned_path() : void (new LocalFilesystem()) ->scan( new Path(__DIR__ . '/Fixtures/multi_partitions'), - Partitions::chain( - Partitions::only('country', 'pl'), - Partitions::date_between('date', new \DateTimeImmutable('2022-01-02'), new \DateTimeImmutable('2022-01-04')) + new ScalarFunctionFilter( + all( + ref('country')->equals(lit('pl')), + all( + ref('date')->cast('date')->greaterThanEqual(lit(new \DateTimeImmutable('2022-01-02'))), + ref('date')->cast('date')->lessThan(lit(new \DateTimeImmutable('2022-01-04'))) + ) + ), + new NativeEntryFactory() ) ) ); @@ -122,7 +132,7 @@ public function test_reading_partitioned_folder_with_partitions_filtering() : vo (new LocalFilesystem()) ->scan( new Path(__DIR__ . '/Fixtures/partitioned'), - Partitions::only('partition_01', 'b') + new ScalarFunctionFilter(ref('partition_01')->equals(lit('b')), new NativeEntryFactory()) ) ) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddDynamicEntriesTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddDynamicEntriesTest.php index b4d24dff8..b07c65733 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddDynamicEntriesTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddDynamicEntriesTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,7 +17,7 @@ public function test_adding_new_entries() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ['id' => 2], @@ -25,7 +25,7 @@ public function test_adding_new_entries() : void ) ) ->withEntry('updated_at', lit(new \DateTimeImmutable('2020-01-01 00:00:00 UTC'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertEquals( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddJsonTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddJsonTest.php index 52403c3a9..96c98b880 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddJsonTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AddJsonTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,12 +18,12 @@ public function test_add_json_into_existing_reference() : void { (new Flow()) ->read( - From::array( + from_array( [['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]], ) ) ->withEntry('array', ref('array')->arrayMerge(lit(['d' => 4]))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -38,14 +38,14 @@ public function test_add_json_string_into_existing_reference() : void { (new Flow()) ->read( - From::array( + from_array( [['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]], ) ) ->withEntry('json', lit('{"d": 4}')) ->withEntry('array', ref('array')->arrayMerge(ref('json')->jsonDecode())) ->drop('json') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -60,11 +60,11 @@ public function test_adding_json_as_object_from_string_entry() : void { (new Flow()) ->read( - From::array([['id' => 1]]) + from_array([['id' => 1]]) ) ->withEntry('json', lit(['id' => 1, 'name' => 'test'])) ->withEntry('json', ref('json')->jsonEncode(\JSON_FORCE_OBJECT)) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -82,10 +82,10 @@ public function test_adding_json_from_string_entry() : void { (new Flow()) ->read( - From::array([['id' => 1]]) + from_array([['id' => 1]]) ) ->withEntry('json', lit('[{"id":1},{"id":2}]')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AllTest.php index 03d66b4bd..524ac3cc9 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AllTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AllTest.php @@ -5,11 +5,11 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\all; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_memory; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function test_all_cases_found() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -38,7 +38,7 @@ public function test_all_cases_found() : void ) ) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AnyTest.php index 3c1647ea3..d8aaae088 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AnyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/AnyTest.php @@ -5,11 +5,11 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\any; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_memory; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function test_any_case_found() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -38,7 +38,7 @@ public function test_any_case_found() : void ) ) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExistsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExistsTest.php index fb3cb2d13..7afa84648 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExistsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExistsTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_exists; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,7 +18,7 @@ public function test_array_exists() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -27,7 +27,7 @@ public function test_array_exists() : void ) ->withEntry('has_array', array_exists(ref('array'), 'a')) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExpandTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExpandTest.php index 90205c16d..b26774312 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExpandTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayExpandTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_expand; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Function\ArrayExpand\ArrayExpand; use Flow\ETL\Memory\ArrayMemory; @@ -19,7 +19,7 @@ public function test_expand_both() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ] @@ -27,7 +27,7 @@ public function test_expand_both() : void ) ->withEntry('expanded', array_expand(ref('array'), ArrayExpand::BOTH)) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -44,7 +44,7 @@ public function test_expand_keys() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ] @@ -52,7 +52,7 @@ public function test_expand_keys() : void ) ->withEntry('expanded', array_expand(ref('array'), ArrayExpand::KEYS)) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -69,7 +69,7 @@ public function test_expand_values() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ] @@ -77,7 +77,7 @@ public function test_expand_values() : void ) ->withEntry('expanded', array_expand(ref('array'))) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetCollectionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetCollectionTest.php index 10fd88a9e..6b65a6fe7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetCollectionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetCollectionTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_get_collection; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,7 +18,7 @@ public function test_array_get_collection() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => [ ['a' => 1, 'b' => 2, 'c' => 3], @@ -31,7 +31,7 @@ public function test_array_get_collection() : void ) ->withEntry('result', array_get_collection(ref('array'), 'a', 'c')) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetTest.php index c9131d10c..1eca08a37 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayGetTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_get; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,7 +18,7 @@ public function test_array_get() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -27,7 +27,7 @@ public function test_array_get() : void ) ->withEntry('result', array_get(ref('array'), 'b')) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeyRenameTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeyRenameTest.php index bb55b7cb3..1ad84f508 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeyRenameTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeyRenameTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_key_rename; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ public function test_array_key_rename() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -27,7 +27,7 @@ public function test_array_key_rename() : void ) ) ->withEntry('array', optional(array_key_rename(ref('array'), 'a', 'd'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeysStyleConvertTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeysStyleConvertTest.php index d4c83cf23..d98dee0ae 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeysStyleConvertTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayKeysStyleConvertTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_keys_style_convert; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_array_keys_style_convert() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['camelCased' => 1, 'snake_cased' => 2, 'space word' => 3]], ] ) ) ->withEntry('array', array_keys_style_convert(ref('array'), 'kebab')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeCollectionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeCollectionTest.php index 5aa0e390a..9faa61edc 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeCollectionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeCollectionTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_merge_collection; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ public function test_array_merge_collection() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => [ ['a' => 1], @@ -32,7 +32,7 @@ public function test_array_merge_collection() : void ) ->withEntry('result', optional(array_merge_collection(ref('array')))) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeTest.php index eb5cd58e0..adaefa7c3 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayMergeTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_merge; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ public function test_array_merge() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'first' => ['a' => 1, 'b' => 2], 'second' => ['c' => 3]], ['id' => 2], @@ -28,7 +28,7 @@ public function test_array_merge() : void ) ->withEntry('array', optional(array_merge(ref('first'), ref('second')))) ->drop('first', 'second') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayReverseTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayReverseTest.php index a02e99ec2..2ea33b576 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayReverseTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayReverseTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,7 +18,7 @@ public function test_array_reverse() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -26,7 +26,7 @@ public function test_array_reverse() : void ) ) ->withEntry('array', optional(ref('array'))->arrayReverse()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArraySortTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArraySortTest.php index e124b46c5..2a0183d91 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArraySortTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArraySortTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\array_sort; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ public function test_array_sort() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'c' => 3, 'b' => 2]], ['id' => 2], @@ -28,7 +28,7 @@ public function test_array_sort() : void ) ->withEntry('array', optional(array_sort(ref('array'), 'ksort'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayUnpackTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayUnpackTest.php index fe94fb2f4..eb237e0b7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayUnpackTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ArrayUnpackTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,7 +17,7 @@ public function test_array_unpack() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2, 'array' => []], @@ -27,7 +27,7 @@ public function test_array_unpack() : void ->withEntry('array', ref('array')->unpack()) ->renameAll('array.', '') ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/BinaryComparisonsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/BinaryComparisonsTest.php index 9e3b57d5e..ca88af8e1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/BinaryComparisonsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/BinaryComparisonsTest.php @@ -4,11 +4,11 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_memory; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use Flow\ETL\Row\Entry\StringEntry; @@ -20,7 +20,7 @@ public function test_all_comparisons() : void { (new Flow()) ->read( - From::array( + from_array( [ ['a' => 100, 'b' => 100, 'c' => 10, 'd' => 'value', 'array' => ['a' => 10, 'b' => 20, 'c' => 30]], ] @@ -83,7 +83,7 @@ public function test_all_comparisons() : void when(ref('a')->isType(StringEntry::class), lit(true), lit(false)) ) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CapitalizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CapitalizeTest.php index a54bcd351..d542c6c41 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CapitalizeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CapitalizeTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_to_lower() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'this is title'], ] ) ) ->withEntry('capitalized', ref('key')->capitalize()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CastTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CastTest.php new file mode 100644 index 000000000..f3538b3ae --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CastTest.php @@ -0,0 +1,33 @@ +read(from_array( + [ + ['date' => new \DateTimeImmutable('2023-01-01')], + ] + )) + ->withEntry('date', ref('date')->cast('string')) + ->write(to_memory($memory = new ArrayMemory())) + ->run(); + + $this->assertEquals( + [ + ['date' => '2023-01-01T00:00:00+00:00'], + ], + $memory->data + ); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CombineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CombineTest.php index deae0e617..e4a375f57 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CombineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CombineTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Integration\Function; use function Flow\ETL\DSL\combine; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\optional; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -19,7 +19,7 @@ public function test_combine() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'first' => ['a', 'b', 'c'], 'second' => [1, 2, 3]], ['id' => 2], @@ -28,7 +28,7 @@ public function test_combine() : void ) ->withEntry('array', optional(combine(ref('first'), ref('second')))) ->drop('first', 'second') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ConcatTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ConcatTest.php index a6ef7c48a..ddfb320c1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ConcatTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ConcatTest.php @@ -6,10 +6,10 @@ use function Flow\ETL\DSL\array_get; use function Flow\ETL\DSL\concat; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function test_concat_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ['id' => 2], @@ -28,7 +28,7 @@ public function test_concat_on_non_string_value() : void ) ) ->withEntry('concat', concat(ref('id'), lit(null))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -44,7 +44,7 @@ public function test_concat_on_stringable_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['field' => 'value']], ['id' => 2], @@ -53,7 +53,7 @@ public function test_concat_on_stringable_value() : void ) ->withEntry('concat', concat(ref('id'), lit('-'), array_get(ref('array'), 'field'))) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ContainsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ContainsTest.php index f9cf0ec69..dd9ec3df3 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ContainsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ContainsTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_contains() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('contains', ref('key')->contains(lit('a'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_contains_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('contains', ref('id')->contains(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_contains_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('contains', ref('id')->contains(lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CountTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CountTest.php index 3608f5934..6a4fc73e2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CountTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/CountTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_count_on_array() : void { (new Flow()) ->read( - From::array( + from_array( [ ['array' => [1, 2, 3]], ] ) ) ->withEntry('count', ref('array')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_count_on_non_countable() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 1], ] ) ) ->withEntry('count', ref('key')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -63,14 +63,14 @@ public function test_count_on_object() : void (new Flow()) ->read( - From::array( + from_array( [ ['key' => $iterator], ] ) ) ->withEntry('count', ref('key')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertEquals( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/EndsWithTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/EndsWithTest.php index e5461d030..67e0e988d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/EndsWithTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/EndsWithTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_ends_with() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('ends_with', ref('key')->endsWith(lit('e'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_ends_with_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('ends_with', ref('id')->endsWith(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_ends_with_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('ends_with', ref('id')->endsWith(lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/HashTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/HashTest.php index 46402bdff..28fc9ddb5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/HashTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/HashTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -27,14 +27,14 @@ public function test_hash_on_given_value(mixed $value, string $expected) : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => $value], ] ) ) ->withEntry('hash', ref('key')->hash()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -49,14 +49,14 @@ public function test_hash_with_different_algorithm() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('hash', ref('key')->hash('sha512')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonDecodeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonDecodeTest.php index 39cbe179d..6d0cd40d8 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonDecodeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonDecodeTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_add_json_string_into_existing_reference() : void { (new Flow()) ->read( - From::array( + from_array( [['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]], ) ) ->withEntry('json', lit('{"d": 4}')) ->withEntry('array', ref('array')->arrayMerge(ref('json')->jsonDecode())) ->drop('json') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonEncodeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonEncodeTest.php index 84a38ec5a..f8c397b7d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonEncodeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/JsonEncodeTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,11 +18,11 @@ public function test_adding_json_as_object_from_string_entry() : void { (new Flow()) ->read( - From::array([['id' => 1]]) + from_array([['id' => 1]]) ) ->withEntry('json', lit(['id' => 1, 'name' => 'test'])) ->withEntry('json', ref('json')->jsonEncode(\JSON_FORCE_OBJECT)) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,11 +40,11 @@ public function test_adding_json_from_string_entry() : void { (new Flow()) ->read( - From::array([['id' => 1]]) + from_array([['id' => 1]]) ) ->withEntry('json', lit([1, 2, 3])) ->withEntry('json', ref('json')->jsonEncode()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/NotTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/NotTest.php index 2e8864bba..5ddfa3e0a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/NotTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/NotTest.php @@ -4,12 +4,12 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\not; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_memory; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -20,7 +20,7 @@ public function test_not() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]], ['id' => 2], @@ -38,7 +38,7 @@ public function test_not() : void ) ) ->drop('array') - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchAllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchAllTest.php index 720984bbb..af7bb9c95 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchAllTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchAllTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_preg_match_all() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('preg_match', ref('key')->regexMatchAll(lit('/a/'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_preg_match_all_on_non_integer_flags() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('preg_match', ref('key')->regexMatchAll(lit('1'), lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_preg_match_all_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('preg_match', ref('id')->regexMatchAll(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -84,14 +84,14 @@ public function test_preg_match_all_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('preg_match', ref('id')->regexMatchAll(lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchTest.php index 94c3f5228..7f78d626a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregMatchTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_preg_match() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('preg_match', ref('key')->regexMatch(lit('/a/'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_preg_match_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('preg_match', ref('id')->regexMatch(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_preg_match_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('preg_match', ref('id')->regexMatch(lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregReplaceTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregReplaceTest.php index af5407a01..a5e6a564a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregReplaceTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/PregReplaceTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_preg_replace() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('preg_replace', ref('key')->regexReplace(lit('/e/'), lit('es'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_preg_replace_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('preg_replace', ref('id')->regexReplace(lit('1'), lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_preg_replace_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('preg_replace', ref('id')->regexReplace(lit(1), lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SanitizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SanitizeTest.php index e8cc10a01..50505b528 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SanitizeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SanitizeTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_sanitize_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('sanitize', ref('id')->sanitize(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_sanitize_with_skip_characters() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('sanitize', ref('key')->sanitize(lit('*'), lit(2))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_sanitize_without_skip_characters() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('sanitize', ref('key')->sanitize(lit('*'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SizeTest.php index 4ad049631..9315bf88b 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SizeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SizeTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_size_on_array() : void { (new Flow()) ->read( - From::array( + from_array( [ ['array' => [1, 2, 3]], ] ) ) ->withEntry('size', ref('array')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_size_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('size', ref('id')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -61,14 +61,14 @@ public function test_size_on_string() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('size', ref('key')->size()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SplitTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SplitTest.php index 6f749bb90..e6b24d8cc 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SplitTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SplitTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\split; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_split() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => '1-2'], ] ) ) ->withEntry('split', split(ref('key'), '-')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_split_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 1], ] ) ) ->withEntry('split', split(ref('key'), '-')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_split_with_missing_separator() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => '1'], ] ) ) ->withEntry('split', split(ref('key'), '-')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SprintfTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SprintfTest.php index 2f13c3cd6..f65ec7bdd 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SprintfTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/SprintfTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_sprintf() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'test %s'], ] ) ) ->withEntry('sprintf', ref('key')->sprintf(lit('value'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_sprintf_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('sprintf', ref('id')->sprintf(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_sprintf_on_null_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('sprintf', ref('id')->sprintf(lit(null))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StartsWithTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StartsWithTest.php index 921a73c46..b10c339d0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StartsWithTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StartsWithTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -18,14 +18,14 @@ public function test_starts_with() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('starts_with', ref('key')->startsWith(lit('v'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_starts_with_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('starts_with', ref('id')->startsWith(lit('1'))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_starts_with_on_non_string_value() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => '1'], ] ) ) ->withEntry('starts_with', ref('id')->startsWith(lit(1))) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrPadTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrPadTest.php index 95c27cf38..4fcec90db 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrPadTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrPadTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_strpad() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('strpad', ref('key')->strPad(10, '*')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_strpad_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('strpad', ref('id')->strPad(10)) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrReplaceTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrReplaceTest.php index 88813472a..7275ffc6a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrReplaceTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/StrReplaceTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_str_replace() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('str_replace', ref('key')->strReplace('e', 'es')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_str_replace_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('str_replace', ref('id')->strReplace('', '')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToLowerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToLowerTest.php index 21e7e4644..b03b3888a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToLowerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToLowerTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_to_lower() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'VALUE'], ] ) ) ->withEntry('to_lower', ref('key')->lower()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_to_lower_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('to_lower', ref('id')->lower()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToUpperTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToUpperTest.php index d24066983..1b7f736b7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToUpperTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/ToUpperTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,14 +17,14 @@ public function test_to_upper() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => 'value'], ] ) ) ->withEntry('to_upper', ref('key')->upper()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -39,14 +39,14 @@ public function test_to_upper_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('to_upper', ref('id')->upper()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/TrimTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/TrimTest.php index a0352ae5b..ecd8b62f5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/TrimTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/TrimTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Flow; use Flow\ETL\Function\Trim\Type; use Flow\ETL\Memory\ArrayMemory; @@ -18,14 +18,14 @@ public function test_trim_both() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => ' value '], ] ) ) ->withEntry('trim', ref('key')->trim()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -40,14 +40,14 @@ public function test_trim_custom_characters() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => '-value '], ] ) ) ->withEntry('trim', ref('key')->trim(characters: '-')) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -62,14 +62,14 @@ public function test_trim_left() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => ' value '], ] ) ) ->withEntry('trim', ref('key')->trim(Type::LEFT)) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -84,14 +84,14 @@ public function test_trim_on_non_string_key() : void { (new Flow()) ->read( - From::array( + from_array( [ ['id' => 1], ] ) ) ->withEntry('trim', ref('id')->trim()) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( @@ -106,14 +106,14 @@ public function test_trim_right() : void { (new Flow()) ->read( - From::array( + from_array( [ ['key' => ' value '], ] ) ) ->withEntry('trim', ref('key')->trim(Type::RIGHT)) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/WhenTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/WhenTest.php index 0ff0af6f0..6040ec073 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/WhenTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Function/WhenTest.php @@ -4,12 +4,12 @@ namespace Flow\ETL\Tests\Integration\Function; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_sequence_number; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\to_memory; use function Flow\ETL\DSL\when; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; -use Flow\ETL\Flow; use Flow\ETL\Memory\ArrayMemory; use PHPUnit\Framework\TestCase; @@ -17,8 +17,8 @@ final class WhenTest extends TestCase { public function test_when_odd_even() : void { - (new Flow()) - ->read(From::sequence_number('id', 1, 10)) + df() + ->read(from_sequence_number('id', 1, 10)) ->collect() ->withEntry( 'type', @@ -28,7 +28,7 @@ public function test_when_odd_even() : void lit('even') ) ) - ->write(To::memory($memory = new ArrayMemory())) + ->write(to_memory($memory = new ArrayMemory())) ->run(); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/BatchingPipelineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/BatchingPipelineTest.php index 8bb143e69..a5d0dc07d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/BatchingPipelineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/BatchingPipelineTest.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Tests\Integration\Pipeline; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Config; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Pipeline\BatchingPipeline; use Flow\ETL\Pipeline\SynchronousPipeline; @@ -15,15 +16,15 @@ final class BatchingPipelineTest extends TestCase public function test_batching_rows() : void { $pipeline = new BatchingPipeline(new SynchronousPipeline(), size: 10); - $pipeline->setSource(From::chain( - From::array([ + $pipeline->setSource(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5], ]), - From::array([ + from_array([ ['id' => 6], ['id' => 7], ['id' => 8], @@ -40,9 +41,9 @@ public function test_batching_rows() : void public function test_that_rows_are_not_lost() : void { - $pipeline = new BatchingPipeline(new SynchronousPipeline(), $batchSize = 7); - $pipeline->setSource(From::chain( - From::array([ + $pipeline = new BatchingPipeline(new SynchronousPipeline(), size: 7); + $pipeline->setSource(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], @@ -83,15 +84,15 @@ public function test_that_rows_are_not_lost() : void public function test_using_bigger_batch_size_than_total_number_of_rows() : void { $pipeline = new BatchingPipeline(new SynchronousPipeline(), size: 11); - $pipeline->setSource(From::chain( - From::array([ + $pipeline->setSource(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5], ]), - From::array([ + from_array([ ['id' => 6], ['id' => 7], ['id' => 8], @@ -109,8 +110,8 @@ public function test_using_bigger_batch_size_than_total_number_of_rows() : void public function test_using_smaller_batch_size_than_total_number_of_rows() : void { $pipeline = new BatchingPipeline(new SynchronousPipeline(), size: 5); - $pipeline->setSource(From::chain( - From::array([ + $pipeline->setSource(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/CollectingPipelineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/CollectingPipelineTest.php index 8dc5564ce..658782394 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/CollectingPipelineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/CollectingPipelineTest.php @@ -2,8 +2,9 @@ namespace Flow\ETL\Tests\Integration\Pipeline; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Config; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Pipeline\CollectingPipeline; use Flow\ETL\Pipeline\SynchronousPipeline; @@ -14,22 +15,22 @@ final class CollectingPipelineTest extends TestCase public function test_collecting() : void { $pipeline = new CollectingPipeline(new SynchronousPipeline()); - $pipeline->setSource(From::chain( - From::array([ + $pipeline->setSource(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5], ]), - From::array([ + from_array([ ['id' => 6], ['id' => 7], ['id' => 8], ['id' => 9], ['id' => 10], ]), - From::array([ + from_array([ ['id' => 11], ['id' => 12], ['id' => 13], diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/ParallelizingPipelineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/ParallelizingPipelineTest.php index f7dae21b0..c66e5f115 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/ParallelizingPipelineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/ParallelizingPipelineTest.php @@ -2,8 +2,8 @@ namespace Flow\ETL\Tests\Integration\Pipeline; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Config; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Pipeline\ParallelizingPipeline; use Flow\ETL\Pipeline\SynchronousPipeline; @@ -17,7 +17,7 @@ public function test_parallelizing_pipeline() : void new SynchronousPipeline(), 5 ); - $pipeline->setSource(From::array([ + $pipeline->setSource(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], @@ -42,7 +42,7 @@ public function test_parallelizing_pipeline_with_batch_size_greater_than_total_n new SynchronousPipeline(), 15 ); - $pipeline->setSource(From::array([ + $pipeline->setSource(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/SynchronousPipelineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/SynchronousPipelineTest.php index 44c8f345e..15009920e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/SynchronousPipelineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Pipeline/SynchronousPipelineTest.php @@ -2,11 +2,11 @@ namespace Flow\ETL\Tests\Integration\Pipeline; -use Flow\ETL\DSL\CSV; -use Flow\ETL\DSL\From; +use function Flow\ETL\Adapter\CSV\from_csv; +use function Flow\ETL\Adapter\CSV\to_csv; +use function Flow\ETL\DSL\from_array; use Flow\ETL\Flow; use Flow\ETL\Tests\Integration\IntegrationTestCase; -use Flow\ETL\Transformer\LimitTransformer; final class SynchronousPipelineTest extends IntegrationTestCase { @@ -19,7 +19,7 @@ public function test_limit() : void } (new Flow()) - ->read(From::array([ + ->read(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], @@ -27,14 +27,14 @@ public function test_limit() : void ['id' => 5], ['id' => 6], ])) - ->write(CSV::to($path)) + ->write(to_csv($path)) ->run(); $this->assertSame( 3, (new Flow()) - ->read(CSV::from($path)) - ->transform(new LimitTransformer(3)) + ->read(from_csv($path)) + ->limit(3) ->count() ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Window/WindowFunctionsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Window/WindowFunctionsTest.php index 21921f98a..30ddb7ffe 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Window/WindowFunctionsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Window/WindowFunctionsTest.php @@ -3,10 +3,11 @@ namespace Flow\ETL\Tests\Integration\Window; use function Flow\ETL\DSL\dens_rank; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\from_array; use function Flow\ETL\DSL\rank; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\From; use Flow\ETL\Flow; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -17,13 +18,13 @@ public function test_rank_on_partitioned_window() : void { $rows = (new Flow()) ->read( - From::chain( - From::array([ + from_all( + from_array([ ['id' => 1, 'name' => 'Greg', 'department' => 'IT', 'salary' => 6000], ['id' => 2, 'name' => 'Michal', 'department' => 'IT', 'salary' => 5000], ['id' => 3, 'name' => 'Tomas', 'department' => 'Finances', 'salary' => 11_000], ]), - From::array([ + from_array([ ['id' => 4, 'name' => 'John', 'department' => 'Finances', 'salary' => 9000], ['id' => 5, 'name' => 'Jane', 'department' => 'Finances', 'salary' => 14_000], ['id' => 6, 'name' => 'Janet', 'department' => 'Finances', 'salary' => 4000], @@ -58,13 +59,13 @@ public function test_rank_without_partitioning() : void { $rows = (new Flow()) ->read( - From::chain( - From::array([ + from_all( + from_array([ ['id' => 1, 'name' => 'Greg', 'department' => 'IT', 'salary' => 6000], ['id' => 2, 'name' => 'Michal', 'department' => 'IT', 'salary' => 5000], ['id' => 3, 'name' => 'Tomas', 'department' => 'Finances', 'salary' => 11_000], ]), - From::array([ + from_array([ ['id' => 4, 'name' => 'John', 'department' => 'Finances', 'salary' => 9000], ['id' => 5, 'name' => 'Jane', 'department' => 'Finances', 'salary' => 14_000], ['id' => 6, 'name' => 'Janet', 'department' => 'Finances', 'salary' => 4000], diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Cache/IneMemoryCacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Cache/IneMemoryCacheTest.php index 5860b34cb..107320f45 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Cache/IneMemoryCacheTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Cache/IneMemoryCacheTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Cache; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Cache\InMemoryCache; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -19,8 +19,8 @@ public function test_cache() : void $this->assertFalse($cache->has('id-1')); $this->assertFalse($cache->has('id-2')); - $cache->add('id-1', $rows1 = new Rows(Row::create(Entry::integer('id', 1)))); - $cache->add('id-2', $rows2 = new Rows(Row::create(Entry::integer('id', 1)))); + $cache->add('id-1', $rows1 = new Rows(Row::create(int_entry('id', 1)))); + $cache->add('id-2', $rows2 = new Rows(Row::create(int_entry('id', 1)))); $this->assertEquals([$rows1], \iterator_to_array($cache->read('id-1'))); $this->assertEquals([$rows2], \iterator_to_array($cache->read('id-2'))); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/DataFrameTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/DataFrameTest.php index f3dd604ad..24bcf2c65 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/DataFrameTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/DataFrameTest.php @@ -4,14 +4,22 @@ namespace Flow\ETL\Tests\Unit; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\average; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\from_array; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\refs; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_callable; use Flow\ETL\DataFrame; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\DSL\Transform; use Flow\ETL\ErrorHandler\IgnoreError; use Flow\ETL\Extractor; @@ -36,8 +44,8 @@ final class DataFrameTest extends TestCase { public function test_batch_size() : void { - (new Flow()) - ->read(From::array([ + df() + ->read(from_array([ ['id' => '01', 'elements' => [['sub_id' => '01_01'], ['sub_id' => '01_02']]], ['id' => '02', 'elements' => [['sub_id' => '02_01'], ['sub_id' => '02_02']]], ['id' => '03', 'elements' => [['sub_id' => '03_01'], ['sub_id' => '03_02']]], @@ -45,7 +53,7 @@ public function test_batch_size() : void ['id' => '05', 'elements' => [['sub_id' => '05_01'], ['sub_id' => '05_02'], ['sub_id' => '05_03']]], ])) ->batchSize(1) - ->load(To::callback(function (Rows $rows) : void { + ->load(to_callable(function (Rows $rows) : void { $this->assertCount(1, $rows); })) ->withEntry('element', ref('elements')->expand()) @@ -68,10 +76,10 @@ public function test_collect_references() : void ['id' => 1, 'name' => 'test', 'active' => false, 'group' => 'A'], ]; - (new Flow()) - ->read(From::chain( - From::array($dataset1), - From::array($dataset2), + df() + ->read(from_all( + from_array($dataset1), + from_array($dataset2), )) ->collectRefs($refs = refs()) ->run(); @@ -84,8 +92,8 @@ public function test_collect_references() : void public function test_count() : void { - $count = (new Flow()) - ->read(From::array([ + $count = df() + ->read(from_array([ ['id' => 1], ['id' => 2], ['id' => 3], @@ -99,11 +107,11 @@ public function test_count() : void public function test_drop() : void { - $rows = (new Flow())->process( + $rows = df()->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) ) ->drop('id') @@ -111,9 +119,9 @@ public function test_drop() : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(null_entry('name'), bool_entry('active', false)), + Row::create(str_entry('name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -121,11 +129,11 @@ public function test_drop() : void public function test_drop_duplicates() : void { - $rows = (new Flow())->process( + $rows = df()->process( new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'foo'), Entry::bool('active', true)), - Row::create(Entry::int('id', 2), Entry::str('name', 'bar'), Entry::bool('active', false)), - Row::create(Entry::int('id', 2), Entry::str('name', 'bar'), Entry::bool('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) ) ->dropDuplicates(ref('id')) @@ -133,8 +141,8 @@ public function test_drop_duplicates() : void $this->assertEquals( new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'foo'), Entry::bool('active', true)), - Row::create(Entry::int('id', 2), Entry::str('name', 'bar'), Entry::bool('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -142,16 +150,16 @@ public function test_drop_duplicates() : void public function test_encapsulate_transformations() : void { - $rows = (new Flow())->process( + $rows = df()->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40), Entry::string('gender', 'male')), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45), Entry::string('gender', 'female')), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50), Entry::string('gender', 'male')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20), str_entry('gender', 'male')), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25), str_entry('gender', 'male')), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30), str_entry('gender', 'female')), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'female')), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40), str_entry('gender', 'male')), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45), str_entry('gender', 'female')), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50), str_entry('gender', 'male')), ) ) ->rows(new class implements Transformation { @@ -174,14 +182,14 @@ public function transform(DataFrame $dataFrame) : DataFrame $this->assertEquals( new Rows( - Row::create(Entry::string('country', 'pl'), Entry::integer('age', 2)), - Row::create(Entry::string('country', 'pl'), Entry::integer('age', 2)), - Row::create(Entry::string('country', 'pl'), Entry::float('age', 2.5)), - Row::create(Entry::string('country', 'pl'), Entry::integer('age', 3)), - Row::create(Entry::string('country', 'us'), Entry::integer('age', 4)), - Row::create(Entry::string('country', 'us'), Entry::integer('age', 4)), - Row::create(Entry::string('country', 'us'), Entry::float('age', 4.5)), - Row::create(Entry::string('country', 'us'), Entry::integer('age', 5)), + Row::create(str_entry('country', 'pl'), int_entry('age', 2)), + Row::create(str_entry('country', 'pl'), int_entry('age', 2)), + Row::create(str_entry('country', 'pl'), float_entry('age', 2.5)), + Row::create(str_entry('country', 'pl'), int_entry('age', 3)), + Row::create(str_entry('country', 'us'), int_entry('age', 4)), + Row::create(str_entry('country', 'us'), int_entry('age', 4)), + Row::create(str_entry('country', 'us'), float_entry('age', 4.5)), + Row::create(str_entry('country', 'us'), int_entry('age', 5)), ), $rows ); @@ -189,7 +197,7 @@ public function transform(DataFrame $dataFrame) : DataFrame public function test_filter() : void { - $rows = (new Flow())->extract( + $rows = df()->extract( new class implements Extractor { /** * @param FlowContext $context @@ -218,19 +226,19 @@ public function extract(FlowContext $context) : \Generator public function test_foreach() : void { - (new Flow())->process( + df()->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) ) ->foreach(function (Rows $rows) : void { $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -239,15 +247,15 @@ public function test_foreach() : void public function test_get() : void { - $rows = (new Flow()) - ->extract(From::rows( + $rows = df() + ->read(from_rows( $extractedRows = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ) )) ->get(); @@ -257,15 +265,15 @@ public function test_get() : void public function test_get_as_array() : void { - $rows = (new Flow()) - ->extract(From::rows( + $rows = df() + ->read(from_rows( $extractedRows = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ) )) ->getAsArray(); @@ -277,40 +285,40 @@ public function test_get_as_array() : void public function test_get_each() : void { - $rows = (new Flow()) - ->extract(From::rows( + $rows = df() + ->read(from_rows( $extractedRows = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ) )) ->getEach(); $this->assertEquals([ - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ], \iterator_to_array($rows)); } public function test_get_each_as_array() : void { - $rows = (new Flow()) - ->extract(From::rows( + $rows = df() + ->read(from_rows( $extractedRows = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'baz')), - Row::create(Entry::integer('id', 4), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 5), Entry::string('name', 'bar')), - Row::create(Entry::integer('id', 6), Entry::string('name', 'baz')), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 2), str_entry('name', 'bar')), + Row::create(int_entry('id', 3), str_entry('name', 'baz')), + Row::create(int_entry('id', 4), str_entry('name', 'foo')), + Row::create(int_entry('id', 5), str_entry('name', 'bar')), + Row::create(int_entry('id', 6), str_entry('name', 'baz')), ) )) ->getEachAsArray(); @@ -500,9 +508,9 @@ public function test_select() : void { $rows = (new Flow())->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) ) ->select('name', 'id') @@ -510,9 +518,9 @@ public function test_select() : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'foo'), Entry::integer('id', 1)), - Row::create(Entry::null('name'), Entry::integer('id', 2)), - Row::create(Entry::string('name', 'bar'), Entry::integer('id', 2)), + Row::create(str_entry('name', 'foo'), int_entry('id', 1)), + Row::create(null_entry('name'), int_entry('id', 2)), + Row::create(str_entry('name', 'bar'), int_entry('id', 2)), ), $rows ); @@ -522,9 +530,9 @@ public function test_selective_validation_against_schema() : void { $rows = (new Flow())->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::array('tags', ['foo', 'bar'])), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), array_entry('tags', ['foo', 'bar'])), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) )->validate( new Schema(Schema\Definition::integer('id', $nullable = false)), @@ -533,9 +541,9 @@ public function test_selective_validation_against_schema() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::array('tags', ['foo', 'bar'])), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), array_entry('tags', ['foo', 'bar'])), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -545,9 +553,9 @@ public function test_strict_validation_against_schema() : void { $rows = (new Flow())->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ) )->validate( new Schema( @@ -559,9 +567,9 @@ public function test_strict_validation_against_schema() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::null('name'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('name', 'bar'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('name', 'foo'), bool_entry('active', true)), + Row::create(int_entry('id', 2), null_entry('name'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('name', 'bar'), bool_entry('active', false)), ), $rows ); @@ -570,15 +578,15 @@ public function test_strict_validation_against_schema() : void public function test_until() : void { $rows = (new Flow()) - ->read(From::chain( - From::array([ + ->read(from_all( + from_array([ ['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5], ]), - From::array([ + from_array([ ['id' => 6], ['id' => 7], ['id' => 8], @@ -604,14 +612,14 @@ public function test_void() : void { $rows = (new Flow())->process( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('age', 20)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'PL'), Entry::integer('age', 25)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'PL'), Entry::integer('age', 30)), - Row::create(Entry::integer('id', 5), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 6), Entry::string('country', 'US'), Entry::integer('age', 40)), - Row::create(Entry::integer('id', 7), Entry::string('country', 'US'), Entry::integer('age', 45)), - Row::create(Entry::integer('id', 9), Entry::string('country', 'US'), Entry::integer('age', 50)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('age', 20)), + Row::create(int_entry('id', 3), str_entry('country', 'PL'), int_entry('age', 25)), + Row::create(int_entry('id', 4), str_entry('country', 'PL'), int_entry('age', 30)), + Row::create(int_entry('id', 5), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 6), str_entry('country', 'US'), int_entry('age', 40)), + Row::create(int_entry('id', 7), str_entry('country', 'US'), int_entry('age', 45)), + Row::create(int_entry('id', 9), str_entry('country', 'US'), int_entry('age', 50)), ) ) ->rename('country', 'country_code') diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/ETLErrorHandlingTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/ETLErrorHandlingTest.php index 095e9bcbd..6f8d5b1e9 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/ETLErrorHandlingTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/ETLErrorHandlingTest.php @@ -4,7 +4,9 @@ namespace Flow\ETL\Tests\Unit; -use Flow\ETL\DSL\Handler; +use function Flow\ETL\DSL\ignore_error_handler; +use function Flow\ETL\DSL\skip_rows_handler; +use function Flow\ETL\DSL\throw_error_handler; use Flow\ETL\Extractor; use Flow\ETL\Flow; use Flow\ETL\FlowContext; @@ -89,7 +91,7 @@ public function __unserialize(array $data) : void (new Flow()) ->extract($extractor) - ->onError(Handler::throw_error()) + ->onError(throw_error_handler()) ->transform($brokenTransformer) ->load($loader) ->run(); @@ -162,7 +164,7 @@ public function __unserialize(array $data) : void (new Flow()) ->extract($extractor) - ->onError(Handler::ignore_error()) + ->onError(ignore_error_handler()) ->transform($brokenTransformer) ->load($loader) ->run(); @@ -256,7 +258,7 @@ public function __unserialize(array $data) : void (new Flow()) ->extract($extractor) - ->onError(Handler::skip_rows()) + ->onError(skip_rows_handler()) ->transform($brokenTransformer) ->load($loader) ->run(); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/ExternalSort/BufferCacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/ExternalSort/BufferCacheTest.php index bcce53562..350242f76 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/ExternalSort/BufferCacheTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/ExternalSort/BufferCacheTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\ExternalSort; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Cache; -use Flow\ETL\DSL\Entry; use Flow\ETL\ExternalSort\BufferCache; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -25,8 +25,8 @@ public function test_buffer_cache_close() : void ->method('add') ->with('id', new Callback(fn (Rows $rows) => $rows->count() === 2)); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 1)))); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 2)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 1)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 2)))); $bufferCache->close(); } @@ -42,8 +42,8 @@ public function test_buffer_cache_overflow() : void ->method('add') ->with('id', new Callback(fn (Rows $rows) => $rows->count() === 2)); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 1)))); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 2)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 1)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 2)))); } public function test_buffer_cache_overflow_and_close() : void @@ -56,9 +56,9 @@ public function test_buffer_cache_overflow_and_close() : void $cacheMock->expects($this->exactly(2)) ->method('add'); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 1)))); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 2)))); - $bufferCache->add('id', new Rows(Row::create(Entry::integer('id', 3)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 1)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 2)))); + $bufferCache->add('id', new Rows(Row::create(int_entry('id', 3)))); $bufferCache->close(); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/CacheExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/CacheExtractorTest.php index 3cb4c4d7c..2ad435a9a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/CacheExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/CacheExtractorTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\from_cache; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Cache; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -20,9 +21,9 @@ public function test_extracting_from_cache() : void $cache = $this->createMock(Cache::class); $generator = function () : \Generator { - yield new Rows(Row::create(Entry::integer('id', 1))); - yield new Rows(Row::create(Entry::integer('id', 2))); - yield new Rows(Row::create(Entry::integer('id', 3))); + yield new Rows(Row::create(int_entry('id', 1))); + yield new Rows(Row::create(int_entry('id', 2))); + yield new Rows(Row::create(int_entry('id', 3))); }; $cache->expects($this->any()) @@ -39,13 +40,13 @@ public function test_extracting_from_cache() : void ->method('clear') ->with('id'); - $extractor = From::cache('id'); + $extractor = from_cache('id'); $this->assertEquals( [ - new Rows(Row::create(Entry::integer('id', 1))), - new Rows(Row::create(Entry::integer('id', 2))), - new Rows(Row::create(Entry::integer('id', 3))), + new Rows(Row::create(int_entry('id', 1))), + new Rows(Row::create(int_entry('id', 2))), + new Rows(Row::create(int_entry('id', 3))), ], \iterator_to_array($extractor->extract(new FlowContext(Config::builder()->cache($cache)->build()))) ); @@ -56,9 +57,9 @@ public function test_extracting_from_cache_and_clear() : void $cache = $this->createMock(Cache::class); $generator = function () : \Generator { - yield new Rows(Row::create(Entry::integer('id', 1))); - yield new Rows(Row::create(Entry::integer('id', 2))); - yield new Rows(Row::create(Entry::integer('id', 3))); + yield new Rows(Row::create(int_entry('id', 1))); + yield new Rows(Row::create(int_entry('id', 2))); + yield new Rows(Row::create(int_entry('id', 3))); }; $cache->expects($this->any()) @@ -75,7 +76,7 @@ public function test_extracting_from_cache_and_clear() : void ->method('clear') ->with('id'); - \iterator_to_array((From::cache('id', clear: true))->extract(new FlowContext(Config::builder()->cache($cache)->build()))); + \iterator_to_array((from_cache('id', clear: true))->extract(new FlowContext(Config::builder()->cache($cache)->build()))); } public function test_extracting_from_fallback_extractor_when_cache_is_empty() : void @@ -93,10 +94,10 @@ public function test_extracting_from_fallback_extractor_when_cache_is_empty() : ->method('read') ->with('id') ->willReturn( - From::rows($rowsToCache = new Rows( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), - Row::create(Entry::integer('id', 3)), + from_rows($rowsToCache = new Rows( + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), + Row::create(int_entry('id', 3)), ))->extract(new FlowContext($config)) ); @@ -104,7 +105,7 @@ public function test_extracting_from_fallback_extractor_when_cache_is_empty() : ->method('clear') ->with('id'); - $extractor = From::cache('id', From::rows($rowsToCache)); + $extractor = from_cache('id', from_rows($rowsToCache)); \iterator_to_array($extractor->extract(new FlowContext($config))); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ChainExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ChainExtractorTest.php index e256210a6..eb5367e03 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ChainExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ChainExtractorTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\from_all; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -17,29 +17,29 @@ final class ChainExtractorTest extends TestCase { public function test_chain_extractor() : void { - $extractor = From::chain( + $extractor = from_all( new class implements Extractor { public function extract(FlowContext $context) : \Generator { - yield new Rows(Row::create(Entry::integer('id', 1))); - yield new Rows(Row::create(Entry::integer('id', 2))); + yield new Rows(Row::create(int_entry('id', 1))); + yield new Rows(Row::create(int_entry('id', 2))); } }, new class implements Extractor { public function extract(FlowContext $context) : \Generator { - yield new Rows(Row::create(Entry::integer('id', 3))); - yield new Rows(Row::create(Entry::integer('id', 4))); + yield new Rows(Row::create(int_entry('id', 3))); + yield new Rows(Row::create(int_entry('id', 4))); } }, ); $this->assertEquals( [ - new Rows(Row::create(Entry::integer('id', 1))), - new Rows(Row::create(Entry::integer('id', 2))), - new Rows(Row::create(Entry::integer('id', 3))), - new Rows(Row::create(Entry::integer('id', 4))), + new Rows(Row::create(int_entry('id', 1))), + new Rows(Row::create(int_entry('id', 2))), + new Rows(Row::create(int_entry('id', 3))), + new Rows(Row::create(int_entry('id', 4))), ], \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/DataFrameExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/DataFrameExtractorTest.php index 8a9706a38..6ef7e4f8c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/DataFrameExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/DataFrameExtractorTest.php @@ -4,13 +4,14 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\from_data_frame; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\row; +use function Flow\ETL\DSL\rows; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\Flow; use Flow\ETL\FlowContext; -use Flow\ETL\Row; -use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; final class DataFrameExtractorTest extends TestCase @@ -19,28 +20,27 @@ public function test_extracting_from_another_data_frame() : void { $this->assertEquals( [ - new Rows( - Row::create(Entry::str('value', 'test')), - Row::create(Entry::str('value', 'test')), + rows( + row(str_entry('value', 'test')), + row(str_entry('value', 'test')), ), - new Rows( - Row::create(Entry::str('value', 'test')), - Row::create(Entry::str('value', 'test')), + rows( + row(str_entry('value', 'test')), + row(str_entry('value', 'test')), ), ], \iterator_to_array( - From::data_frame( - (new Flow()) - ->extract(From::rows( - new Rows( - Row::create(Entry::str('value', 'test')), - Row::create(Entry::str('value', 'test')), - ), - new Rows( - Row::create(Entry::str('value', 'test')), - Row::create(Entry::str('value', 'test')), - ) - )), + from_data_frame( + df()->read(from_rows( + rows( + row(str_entry('value', 'test')), + row(str_entry('value', 'test')), + ), + rows( + row(str_entry('value', 'test')), + row(str_entry('value', 'test')), + ) + )), )->extract(new FlowContext(Config::default())) ), ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/MemoryExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/MemoryExtractorTest.php index e6f492274..278b1dfd1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/MemoryExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/MemoryExtractorTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\from_memory; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; -use Flow\ETL\DSL\To; use Flow\ETL\FlowContext; use Flow\ETL\Memory\ArrayMemory; use Flow\ETL\Row; @@ -16,32 +17,21 @@ final class MemoryExtractorTest extends TestCase { - public static function chunk_sizes() : \Generator - { - yield [1]; - yield [2]; - yield [3]; - yield [4]; - } - - /** - * @dataProvider chunk_sizes - */ - public function test_memory_extractor(int $chunkSize) : void + public function test_memory_extractor() : void { $rows = new Rows( - Row::create(Entry::integer('number', 1), Entry::string('name', 'one')), - Row::create(Entry::integer('number', 2), Entry::string('name', 'two')), - Row::create(Entry::integer('number', 3), Entry::string('name', 'tree')), - Row::create(Entry::integer('number', 4), Entry::string('name', 'four')), - Row::create(Entry::integer('number', 5), Entry::string('name', 'five')), + Row::create(int_entry('number', 1), str_entry('name', 'one')), + Row::create(int_entry('number', 2), str_entry('name', 'two')), + Row::create(int_entry('number', 3), str_entry('name', 'tree')), + Row::create(int_entry('number', 4), str_entry('name', 'four')), + Row::create(int_entry('number', 5), str_entry('name', 'five')), ); $memory = new ArrayMemory(); - (To::memory($memory))->load($rows, new FlowContext(Config::default())); + (to_memory($memory))->load($rows, new FlowContext(Config::default())); - $extractor = From::memory($memory, $chunkSize); + $extractor = from_memory($memory); $data = []; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/PipelineExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/PipelineExtractorTest.php index a15457043..c930ebcbd 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/PipelineExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/PipelineExtractorTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Extractor\PipelineExtractor; use Flow\ETL\Extractor\ProcessExtractor; use Flow\ETL\FlowContext; @@ -20,9 +20,9 @@ public function test_pipeline_extractor() : void { $pipeline = new SynchronousPipeline(); $pipeline->setSource(new ProcessExtractor( - new Rows(Row::create(Entry::integer('id', 1)), Row::create(Entry::integer('id', 2))), - new Rows(Row::create(Entry::integer('id', 3)), Row::create(Entry::integer('id', 4))), - new Rows(Row::create(Entry::integer('id', 5)), Row::create(Entry::integer('id', 6))), + new Rows(Row::create(int_entry('id', 1)), Row::create(int_entry('id', 2))), + new Rows(Row::create(int_entry('id', 3)), Row::create(int_entry('id', 4))), + new Rows(Row::create(int_entry('id', 5)), Row::create(int_entry('id', 6))), )); $extractor = new PipelineExtractor($pipeline, Config::default()); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ProcessExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ProcessExtractorTest.php index 21cee3e57..9023f8838 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ProcessExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/ProcessExtractorTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\from_rows; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -17,14 +18,14 @@ final class ProcessExtractorTest extends TestCase public function test_process_extractor() : void { $rows = new Rows( - Row::create(Entry::integer('number', 1), Entry::string('name', 'one')), - Row::create(Entry::integer('number', 2), Entry::string('name', 'two')), - Row::create(Entry::integer('number', 3), Entry::string('name', 'tree')), - Row::create(Entry::integer('number', 4), Entry::string('name', 'four')), - Row::create(Entry::integer('number', 5), Entry::string('name', 'five')), + Row::create(int_entry('number', 1), str_entry('name', 'one')), + Row::create(int_entry('number', 2), str_entry('name', 'two')), + Row::create(int_entry('number', 3), str_entry('name', 'tree')), + Row::create(int_entry('number', 4), str_entry('name', 'four')), + Row::create(int_entry('number', 5), str_entry('name', 'five')), ); - $extractor = From::rows($rows); + $extractor = from_rows($rows); $data = []; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/SequenceExtractorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/SequenceExtractorTest.php index 140c2c43a..80a61026d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/SequenceExtractorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Extractor/SequenceExtractorTest.php @@ -4,9 +4,12 @@ namespace Flow\ETL\Tests\Unit\Extractor; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\from_sequence_date_period; +use function Flow\ETL\DSL\from_sequence_date_period_recurrences; +use function Flow\ETL\DSL\from_sequence_number; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\From; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -16,19 +19,19 @@ final class SequenceExtractorTest extends TestCase { public function test_extracting_from_date_period() : void { - $extractor = From::sequence_date_period('day', new \DateTimeImmutable('2023-01-01'), new \DateInterval('P1D'), new \DateTimeImmutable('2023-01-11'), \DatePeriod::EXCLUDE_START_DATE); + $extractor = from_sequence_date_period('day', new \DateTimeImmutable('2023-01-01'), new \DateInterval('P1D'), new \DateTimeImmutable('2023-01-11'), \DatePeriod::EXCLUDE_START_DATE); $this->assertEquals( [ - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-02')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-03')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-04')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-05')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-06')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-07')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-08')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-09')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-10')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-02')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-03')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-04')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-05')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-06')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-07')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-08')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-09')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-10')))), ], \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) ); @@ -36,20 +39,20 @@ public function test_extracting_from_date_period() : void public function test_extracting_from_date_period_recurrences() : void { - $extractor = From::sequence_date_period_recurrences('day', new \DateTimeImmutable('2023-01-01'), new \DateInterval('P1D'), 10, \DatePeriod::EXCLUDE_START_DATE); + $extractor = from_sequence_date_period_recurrences('day', new \DateTimeImmutable('2023-01-01'), new \DateInterval('P1D'), 10, \DatePeriod::EXCLUDE_START_DATE); $this->assertEquals( [ - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-02')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-03')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-04')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-05')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-06')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-07')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-08')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-09')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-10')))), - new Rows(Row::create(Entry::datetime('day', new \DateTimeImmutable('2023-01-11')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-02')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-03')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-04')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-05')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-06')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-07')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-08')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-09')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-10')))), + new Rows(Row::create(datetime_entry('day', new \DateTimeImmutable('2023-01-11')))), ], \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) ); @@ -57,17 +60,17 @@ public function test_extracting_from_date_period_recurrences() : void public function test_extracting_from_numbers_range() : void { - $extractor = From::sequence_number('num', 0, 10, 1.5); + $extractor = from_sequence_number('num', 0, 10, 1.5); $this->assertEquals( [ - new Rows(Row::create(Entry::float('num', 0))), - new Rows(Row::create(Entry::float('num', 1.5))), - new Rows(Row::create(Entry::float('num', 3))), - new Rows(Row::create(Entry::float('num', 4.5))), - new Rows(Row::create(Entry::float('num', 6))), - new Rows(Row::create(Entry::float('num', 7.5))), - new Rows(Row::create(Entry::float('num', 9))), + new Rows(Row::create(float_entry('num', 0))), + new Rows(Row::create(float_entry('num', 1.5))), + new Rows(Row::create(float_entry('num', 3))), + new Rows(Row::create(float_entry('num', 4.5))), + new Rows(Row::create(float_entry('num', 6))), + new Rows(Row::create(float_entry('num', 7.5))), + new Rows(Row::create(float_entry('num', 9))), ], \iterator_to_array($extractor->extract(new FlowContext(Config::default()))) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIBodyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIBodyTest.php index 1bf7eb7df..a66b49430 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIBodyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIBodyTest.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Tests\Unit\Formatter\ASCII; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Formatter\ASCII\ASCIIBody; use Flow\ETL\Formatter\ASCII\Body; use Flow\ETL\Formatter\ASCII\Headers; @@ -17,8 +18,8 @@ final class ASCIIBodyTest extends TestCase public function test_printing_ascii_body() : void { $rows = new Rows( - Row::create(Entry::integer('id', 1), Entry::float('value', 1.4)), - Row::create(Entry::integer('id', 2), Entry::float('value', 3.4)) + Row::create(int_entry('id', 1), float_entry('value', 1.4)), + Row::create(int_entry('id', 2), float_entry('value', 3.4)) ); $headers = new ASCIIBody( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIHeadersTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIHeadersTest.php index aa99273b3..1cf2348fc 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIHeadersTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIHeadersTest.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Tests\Unit\Formatter\ASCII; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Formatter\ASCII\ASCIIHeaders; use Flow\ETL\Formatter\ASCII\Body; use Flow\ETL\Formatter\ASCII\Headers; @@ -17,8 +18,8 @@ final class ASCIIHeadersTest extends TestCase public function test_printing_ascii_headers() : void { $rows = new Rows( - Row::create(Entry::integer('id', 1), Entry::float('value', 1.4)), - Row::create(Entry::integer('id', 2), Entry::float('value', 3.4)) + Row::create(int_entry('id', 1), float_entry('value', 1.4)), + Row::create(int_entry('id', 2), float_entry('value', 3.4)) ); $headers = new ASCIIHeaders( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIValueTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIValueTest.php index a701d912a..5a2de1480 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIValueTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCII/ASCIIValueTest.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Tests\Unit\Formatter\ASCII; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\datetime_entry; use Flow\ETL\Formatter\ASCII\ASCIIValue; use PHPUnit\Framework\TestCase; @@ -15,7 +15,7 @@ public static function values_with_truncating() : \Generator yield ['string', 'str']; yield [false, 'fal']; yield [true, 'tru']; - yield [Entry::datetime('test', new \DateTimeImmutable('2023-01-01 00:00:00 UTC')), '202']; + yield [datetime_entry('test', new \DateTimeImmutable('2023-01-01 00:00:00 UTC')), '202']; yield [['a' => 1, 'b' => 2, 'c' => ['test']], '{"a']; } @@ -25,7 +25,7 @@ public static function values_without_truncating() : \Generator yield [1, '1']; yield [false, 'false']; yield [true, 'true']; - yield [Entry::datetime('test', new \DateTimeImmutable('2023-01-01 00:00:00 UTC')), '2023-01-01T00:00:00+00:00']; + yield [datetime_entry('test', new \DateTimeImmutable('2023-01-01 00:00:00 UTC')), '2023-01-01T00:00:00+00:00']; yield [['a' => 1, 'b' => 2, 'c' => ['test']], '{"a":1,"b":2,"c":["test"]}']; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCIITableTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCIITableTest.php index 0f8de9fe9..d3a335055 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCIITableTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Formatter/ASCIITableTest.php @@ -4,7 +4,8 @@ namespace Flow\ETL\Tests\Unit\Formatter; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Formatter\ASCII\ASCIITable; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -15,13 +16,13 @@ final class ASCIITableTest extends TestCase public function test_ascii_table_with_mb_strings() : void { $rows = new Rows( - Row::create(Entry::string('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), - Row::create(Entry::string('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), - Row::create(Entry::string('row', '[572][647]WŁADCA PIERŚCIENI')), - Row::create(Entry::string('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), - Row::create(Entry::string('row', '[742][762]/Trzy zostały dane elfom...')), - Row::create(Entry::string('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), - Row::create(Entry::string('row', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), + Row::create(str_entry('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), + Row::create(str_entry('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), + Row::create(str_entry('row', '[572][647]WŁADCA PIERŚCIENI')), + Row::create(str_entry('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), + Row::create(str_entry('row', '[742][762]/Trzy zostały dane elfom...')), + Row::create(str_entry('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), + Row::create(str_entry('row', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), ); $this->assertStringContainsString( @@ -45,13 +46,13 @@ public function test_ascii_table_with_mb_strings() : void public function test_ascii_table_with_mb_strings_truncate() : void { $rows = new Rows( - Row::create(Entry::string('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), - Row::create(Entry::string('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), - Row::create(Entry::string('row', '[572][647]WŁADCA PIERŚCIENI')), - Row::create(Entry::string('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), - Row::create(Entry::string('row', '[742][762]/Trzy zostały dane elfom...')), - Row::create(Entry::string('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), - Row::create(Entry::string('row', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), + Row::create(str_entry('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), + Row::create(str_entry('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), + Row::create(str_entry('row', '[572][647]WŁADCA PIERŚCIENI')), + Row::create(str_entry('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), + Row::create(str_entry('row', '[742][762]/Trzy zostały dane elfom...')), + Row::create(str_entry('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), + Row::create(str_entry('row', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), ); $this->assertStringContainsString( @@ -75,13 +76,13 @@ public function test_ascii_table_with_mb_strings_truncate() : void public function test_ascii_table_with_non_symmetric_entries() : void { $rows = new Rows( - Row::create(Entry::string('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), - Row::create(Entry::string('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), - Row::create(Entry::string('row', '[572][647]WŁADCA PIERŚCIENI')), - Row::create(Entry::string('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), - Row::create(Entry::string('row', '[742][762]/Trzy zostały dane elfom...')), - Row::create(Entry::string('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), - Row::create(Entry::string('test', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), + Row::create(str_entry('row', '[498][534]/Wiele z tego,|/co niegdyś było, przepadło.')), + Row::create(str_entry('row', '[540][572]/A nie żyje już nikt z tych,|/którzy by o tym pamiętali.')), + Row::create(str_entry('row', '[572][647]WŁADCA PIERŚCIENI')), + Row::create(str_entry('row', '[701][741]/Wszystko zaczęło się|/od wykucia Pierścieni Władzy.')), + Row::create(str_entry('row', '[742][762]/Trzy zostały dane elfom...')), + Row::create(str_entry('row', '[763][805]/nieśmiertelnym, najmędrszym|/i najbliższym magii spośród wszystkich ras.')), + Row::create(str_entry('test', '[816][853]/Siedem - władcom krasnoludów,|/wspaniałym górnikom')), ); $this->assertStringContainsString( @@ -118,8 +119,8 @@ public function test_ascii_table_with_single_row() : void +----+------+ TABLE, (new ASCIITable(new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'EN')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'PL')), + Row::create(int_entry('id', 1), str_entry('name', 'EN')), + Row::create(int_entry('id', 2), str_entry('name', 'PL')), )))->print(false) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AllTest.php index a29751126..1dce31a9c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AllTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AllTest.php @@ -6,8 +6,8 @@ use function Flow\ETL\DSL\all; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ final class AllTest extends TestCase public function test_all_expression_on_is_null_expression() : void { $this->assertTrue( - all(ref('value')->isNull())->eval(Row::create(Entry::null('value'))) + all(ref('value')->isNull())->eval(Row::create(null_entry('value'))) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AnyTest.php index 79c2797bd..9169e620f 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AnyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AnyTest.php @@ -6,8 +6,8 @@ use function Flow\ETL\DSL\any; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -30,7 +30,7 @@ public function test_any_expression_on_boolean_true_value() : void public function test_any_expression_on_is_null_expression() : void { $this->assertTrue( - any(ref('value')->isNull())->eval(Row::create(Entry::null('value'))) + any(ref('value')->isNull())->eval(Row::create(null_entry('value'))) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayExpandTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayExpandTest.php index b633f67c7..39346cf22 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayExpandTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayExpandTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_expand; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Function\ArrayExpand\ArrayExpand; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ final class ArrayExpandTest extends TestCase public function test_expand_both() : void { $row = Row::create( - Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3]), + array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3]), ); $this->assertSame( @@ -32,7 +33,7 @@ public function test_expand_both() : void public function test_expand_keys() : void { $row = Row::create( - Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3]), + array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3]), ); $this->assertSame( @@ -44,7 +45,7 @@ public function test_expand_keys() : void public function test_expand_values() : void { $row = Row::create( - Entry::array('array', ['a' => 1, 'b' => 2, 'c' => 3]), + array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3]), ); $this->assertSame( @@ -56,7 +57,7 @@ public function test_expand_values() : void public function test_for_not_array_entry() : void { $this->assertNull( - array_expand(ref('integer_entry'))->eval(Row::create(Entry::int('integer_entry', 1))) + array_expand(ref('integer_entry'))->eval(Row::create(int_entry('integer_entry', 1))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetCollectionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetCollectionTest.php index 4eccb4083..e4a8cf93e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetCollectionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetCollectionTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_get_collection; use function Flow\ETL\DSL\array_get_collection_first; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ final class ArrayGetCollectionTest extends TestCase public function test_for_not_array_entry() : void { $row = Row::create( - Entry::integer('invalid_entry', 1), + int_entry('invalid_entry', 1), ); $this->assertNull(array_get_collection(ref('invalid_entry'), 'id')->eval($row)); @@ -25,7 +26,7 @@ public function test_for_not_array_entry() : void public function test_getting_keys_from_simple_array() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ 'id' => 1, @@ -42,7 +43,7 @@ public function test_getting_keys_from_simple_array() : void public function test_getting_specific_keys_from_collection_of_array() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ [ @@ -73,7 +74,7 @@ public function test_getting_specific_keys_from_collection_of_array() : void public function test_getting_specific_keys_from_first_element_in_collection_of_array() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ [ @@ -105,7 +106,7 @@ public function test_getting_specific_keys_from_first_element_in_collection_of_a public function test_getting_specific_keys_from_first_element_in_collection_of_array_when_first_index_does_not_exists() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ 2 => [ diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetTest.php index 750b6324d..70bd2af53 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayGetTest.php @@ -4,11 +4,12 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_exists; use function Flow\ETL\DSL\array_get; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; use Flow\ArrayDot\Exception\InvalidPathException; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,14 +17,14 @@ final class ArrayGetTest extends TestCase { public function test_array_access_for_not_array_entry() : void { - $this->assertNull(array_get(ref('integer_entry'), 'invalid_path')->eval(Row::create(Entry::int('integer_entry', 1)))); - $this->assertFalse(array_exists(ref('integer_entry'), 'invalid_path')->eval(Row::create(Entry::int('integer_entry', 1)))); + $this->assertNull(array_get(ref('integer_entry'), 'invalid_path')->eval(Row::create(int_entry('integer_entry', 1)))); + $this->assertFalse(array_exists(ref('integer_entry'), 'invalid_path')->eval(Row::create(int_entry('integer_entry', 1)))); } public function test_array_accessor_transformer() : void { $row = Row::create( - Entry::array('array_entry', [ + array_entry('array_entry', [ 'id' => 1, 'status' => 'PENDING', 'enabled' => true, @@ -37,7 +38,7 @@ public function test_array_accessor_transformer() : void public function test_array_accessor_transformer_with_invalid_and_without_strict_path() : void { $row = Row::create( - Entry::array('array_entry', [ + array_entry('array_entry', [ 'id' => 1, 'status' => 'PENDING', 'enabled' => true, @@ -57,7 +58,7 @@ public function test_array_accessor_transformer_with_invalid_but_strict_path() : array_get(ref('array_entry'), 'invalid_path')->eval( Row::create( - Entry::array('array_entry', [ + array_entry('array_entry', [ 'id' => 1, 'status' => 'PENDING', 'enabled' => true, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeyRenameTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeyRenameTest.php index 969a09a64..940db5df2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeyRenameTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeyRenameTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_key_rename; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; use Flow\ArrayDot\Exception\InvalidPathException; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ final class ArrayKeyRenameTest extends TestCase public function test_for_not_array_entry() : void { $row = Row::create( - Entry::integer('integer_entry', 1), + int_entry('integer_entry', 1), ); $this->assertNull(array_key_rename(ref('integer_entry'), 'invalid_path', 'new_name')->eval($row)); @@ -25,11 +26,11 @@ public function test_for_not_array_entry() : void public function test_renames_array_entry_keys_in_multiple_array_entry() : void { $row = Row::create( - Entry::array('customer', [ + array_entry('customer', [ 'first' => 'John', 'last' => 'Snow', ]), - Entry::array('shipping', [ + array_entry('shipping', [ 'address' => [ 'line' => '3644 Clement Street', 'city' => 'Atalanta', @@ -62,7 +63,7 @@ public function test_renames_array_entry_keys_in_multiple_array_entry() : void public function test_renames_array_entry_keys_in_single_array_entry() : void { $row = Row::create( - Entry::array('array_entry', [ + array_entry('array_entry', [ 'id' => 1, 'status' => 'PENDING', 'enabled' => true, @@ -84,7 +85,7 @@ public function test_renames_array_entry_keys_in_single_array_entry() : void public function test_throws_exception_for_invalid_path() : void { $row = Row::create( - Entry::array('array_entry', [ + array_entry('array_entry', [ 'id' => 1, 'status' => 'PENDING', 'enabled' => true, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeysStyleConverterTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeysStyleConverterTest.php index b5014c664..96dd65604 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeysStyleConverterTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayKeysStyleConverterTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_keys_style_convert; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -19,7 +20,7 @@ public function test_for_invalid_style() : void $this->expectExceptionMessage('Unrecognized style invalid, please use one of following:'); $row = Row::create( - Entry::array('invalid_entry', []), + array_entry('invalid_entry', []), ); array_keys_style_convert(ref('invalid_entry'), 'invalid')->eval($row); @@ -28,7 +29,7 @@ public function test_for_invalid_style() : void public function test_for_not_array_entry() : void { $row = Row::create( - Entry::integer('invalid_entry', 1), + int_entry('invalid_entry', 1), ); $this->assertNull(array_keys_style_convert(ref('invalid_entry'), 'snake')->eval($row)); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeCollectionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeCollectionTest.php index ae0c90e83..87286de39 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeCollectionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeCollectionTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\array_merge_collection; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,7 +16,7 @@ final class ArrayMergeCollectionTest extends TestCase public function test_attempt_of_merging_collection_where_not_every_element_is_array() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ ['foo' => 'bar'], @@ -30,7 +31,7 @@ public function test_attempt_of_merging_collection_where_not_every_element_is_ar public function test_for_not_array_entry() : void { $row = Row::create( - Entry::integer('invalid_entry', 1), + int_entry('invalid_entry', 1), ); $this->assertNull(array_merge_collection(ref('invalid_entry'))->eval($row)); @@ -39,7 +40,7 @@ public function test_for_not_array_entry() : void public function test_merging_collection_of_arrays() : void { $row = Row::create( - Entry::array( + array_entry( 'array_entry', [ [ diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeTest.php index 984a8a67a..20eaf6a30 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayMergeTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Function\ArrayMerge; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -20,8 +21,8 @@ public function test_array_merge_two_array_row_entries() : void ref('a')->arrayMerge(ref('b')) ->eval( Row::create( - Entry::array('a', ['a' => 1]), - Entry::array('b', ['b' => 2]), + array_entry('a', ['a' => 1]), + array_entry('b', ['b' => 2]), ), ) ); @@ -43,8 +44,8 @@ public function test_array_merge_when_left_side_is_not_an_array() : void ref('a')->arrayMerge(ref('b')) ->eval( Row::create( - Entry::int('a', 1), - Entry::array('b', ['b' => 2]), + int_entry('a', 1), + array_entry('b', ['b' => 2]), ), ) ); @@ -56,8 +57,8 @@ public function test_array_merge_when_right_side_is_not_an_array() : void ref('a')->arrayMerge(ref('b')) ->eval( Row::create( - Entry::array('a', ['a' => 1]), - Entry::int('b', 2), + array_entry('a', ['a' => 1]), + int_entry('b', 2), ), ) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayReverseTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayReverseTest.php index ba5e22aa6..410cedb66 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayReverseTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayReverseTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -18,7 +19,7 @@ public function test_array_reverse_array_entry() : void ref('a')->arrayReverse() ->eval( Row::create( - Entry::array('a', [4, 10, 3, 5]), + array_entry('a', [4, 10, 3, 5]), ), ) ); @@ -30,7 +31,7 @@ public function test_array_reverse_non_array_entry() : void ref('a')->arrayReverse() ->eval( Row::create( - Entry::int('a', 123), + int_entry('a', 123), ), ) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArraySortTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArraySortTest.php index 78e8c19dc..49cd881f6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArraySortTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArraySortTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -14,8 +15,8 @@ final class ArraySortTest extends TestCase public function test_sorting_big_arrays() : void { $this->assertSame( - ref('array')->arraySort('sort')->eval(Row::create(Entry::array('array', \json_decode($this->jsonDifferentOrder(), true, 512, JSON_THROW_ON_ERROR)))), - ref('array')->arraySort('sort')->eval(Row::create(Entry::array('array', \json_decode($this->json(), true, 512, JSON_THROW_ON_ERROR)))) + ref('array')->arraySort('sort')->eval(Row::create(array_entry('array', \json_decode($this->jsonDifferentOrder(), true, 512, JSON_THROW_ON_ERROR)))), + ref('array')->arraySort('sort')->eval(Row::create(array_entry('array', \json_decode($this->json(), true, 512, JSON_THROW_ON_ERROR)))) ); } @@ -32,7 +33,7 @@ public function test_sorting_nested_array_using_asort_algo() : void ], ], ref('array')->arraySort('asort')->eval(Row::create( - Entry::array( + array_entry( 'array', [ 'a' => [ @@ -61,7 +62,7 @@ public function test_sorting_nested_associative_array() : void ], ], ref('array')->arraySort('ksort')->eval(Row::create( - Entry::array( + array_entry( 'array', [ 'a' => [ @@ -81,7 +82,7 @@ public function test_sorting_nested_associative_array() : void public function test_sorting_non_array_value() : void { $this->assertNull( - ref('array')->arraySort()->eval(Row::create(Entry::str('array', 'string'))) + ref('array')->arraySort()->eval(Row::create(str_entry('array', 'string'))) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayUnpackTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayUnpackTest.php index aa161f30f..51a8766f7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayUnpackTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ArrayUnpackTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Function\ArrayUnpack; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,8 +16,8 @@ final class ArrayUnpackTest extends TestCase public function test_array_unpack() : void { $row = Row::create( - Entry::int('id', 1), - Entry::array('array_entry', [ + int_entry('id', 1), + array_entry('array_entry', [ 'status' => 'PENDING', 'enabled' => true, 'array' => ['foo' => 'bar'], diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AverageTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AverageTest.php index 608599439..1cb678a18 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AverageTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/AverageTest.php @@ -5,9 +5,11 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\average; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -18,11 +20,11 @@ public function test_aggregation_average_from_numeric_values() : void { $aggregator = average(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '30'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '30'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( 21.25, @@ -34,10 +36,10 @@ public function test_aggregation_average_including_null_value() : void { $aggregator = average(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::null('int'))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(null_entry('int'))); $this->assertSame( 20, @@ -49,10 +51,10 @@ public function test_aggregation_average_with_float_result() : void { $aggregator = average(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::integer('int', 25))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(int_entry('int', 25))); $this->assertSame( 21.25, @@ -64,10 +66,10 @@ public function test_aggregation_average_with_integer_result() : void { $aggregator = average(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::integer('int', 40))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(int_entry('int', 40))); $this->assertSame( 25, @@ -88,11 +90,11 @@ public function test_aggregation_average_with_zero_result() : void public function test_window_function_average_on_partitioned_rows() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1)), - Row::create(Entry::int('id', 2), Entry::int('value', 100)), - Row::create(Entry::int('id', 3), Entry::int('value', 25)), - Row::create(Entry::int('id', 4), Entry::int('value', 64)), - Row::create(Entry::int('id', 5), Entry::int('value', 23)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1)), + Row::create(int_entry('id', 2), int_entry('value', 100)), + Row::create(int_entry('id', 3), int_entry('value', 25)), + Row::create(int_entry('id', 4), int_entry('value', 64)), + Row::create(int_entry('id', 5), int_entry('value', 23)), ); $avg = average(ref('value'))->over(window()->orderBy(ref('value'))); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/BinaryComparisonsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/BinaryComparisonsTest.php index 027ce66f6..6b9d617ad 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/BinaryComparisonsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/BinaryComparisonsTest.php @@ -4,9 +4,13 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\Contains; use Flow\ETL\Function\EndsWith; use Flow\ETL\Function\Equals; @@ -33,7 +37,7 @@ final class BinaryComparisonsTest extends TestCase { public function test_equals() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100), Entry::integer('c', 10), Entry::datetime('d', '2023-01-01 00:00:00 UTC'), Entry::datetime('e', '2023-01-01 00:00:00 UTC')); + $row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10), datetime_entry('d', '2023-01-01 00:00:00 UTC'), datetime_entry('e', '2023-01-01 00:00:00 UTC')); $this->assertTrue( (new Equals(ref('a'), ref('b')))->eval($row) @@ -49,11 +53,11 @@ public function test_equals() : void public function test_greater_than() : void { $row = Row::create( - Entry::integer('a', 100), - Entry::integer('b', 100), - Entry::integer('c', 10), - Entry::datetime('d', '2023-01-01 00:00:00 UTC'), - Entry::datetime('e', '2023-01-02 00:00:00 UTC'), + int_entry('a', 100), + int_entry('b', 100), + int_entry('c', 10), + datetime_entry('d', '2023-01-01 00:00:00 UTC'), + datetime_entry('e', '2023-01-02 00:00:00 UTC'), ); $this->assertTrue((new GreaterThan(ref('a'), ref('c')))->eval($row)); @@ -68,11 +72,11 @@ public function test_greater_than() : void public function test_is_in() : void { $row = Row::with( - Entry::array('a', [1, 2, 3, 4, 5]), - Entry::array('b', ['a', 'b', 'c']), - Entry::str('c', 'another'), - Entry::int('d', 4), - Entry::str('e', 'b'), + array_entry('a', [1, 2, 3, 4, 5]), + array_entry('b', ['a', 'b', 'c']), + str_entry('c', 'another'), + int_entry('d', 4), + str_entry('e', 'b'), ); $this->assertTrue((new IsIn(ref('a'), lit(1)))->eval($row)); @@ -84,8 +88,8 @@ public function test_is_in() : void public function test_is_numeric() : void { $row = Row::create( - Entry::integer('a', 100), - Entry::null('b'), + int_entry('a', 100), + null_entry('b'), ); $this->assertTrue((new IsNumeric(ref('a')))->eval($row)); $this->assertFalse((new IsNumeric(ref('b')))->eval($row)); @@ -98,8 +102,8 @@ public function test_is_numeric() : void public function test_is_type() : void { $row = Row::create( - Entry::integer('a', 100), - Entry::null('b'), + int_entry('a', 100), + null_entry('b'), ); $this->assertTrue((new IsType(ref('a'), IntegerEntry::class, StringEntry::class))->eval($row)); @@ -111,8 +115,8 @@ public function test_is_type_with_non_existing_type_class() : void $this->expectExceptionMessage('"aaa" is not valid Entry Type class'); $row = Row::create( - Entry::integer('a', 100), - Entry::null('b'), + int_entry('a', 100), + null_entry('b'), ); $this->assertFalse((new IsType(ref('a'), 'aaa'))->eval($row)); @@ -120,7 +124,7 @@ public function test_is_type_with_non_existing_type_class() : void public function test_less_than() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100), Entry::integer('c', 10)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10)); $this->assertFalse( (new LessThan(ref('a'), ref('c')))->eval($row) @@ -138,7 +142,7 @@ public function test_less_than() : void public function test_not_equals() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100), Entry::integer('c', 10)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10)); $this->assertFalse( (new NotEquals(ref('a'), ref('b')))->eval($row) @@ -150,7 +154,7 @@ public function test_not_equals() : void public function test_not_same() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100), Entry::integer('c', 10)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10)); $this->assertTrue( (new NotSame(ref('a'), ref('c')))->eval($row) @@ -163,8 +167,8 @@ public function test_not_same() : void public function test_null() : void { $row = Row::create( - Entry::integer('a', 100), - Entry::null('b'), + int_entry('a', 100), + null_entry('b'), ); $this->assertFalse((new IsNull(ref('a')))->eval($row)); @@ -177,7 +181,7 @@ public function test_null() : void public function test_same() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100), Entry::integer('c', 10), Entry::datetime('d', '2023-01-01 00:00:00 UTC'), Entry::datetime('e', '2023-01-01 00:00:00 UTC')); + $row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10), datetime_entry('d', '2023-01-01 00:00:00 UTC'), datetime_entry('e', '2023-01-01 00:00:00 UTC')); $this->assertTrue( (new Same(ref('a'), ref('b')))->eval($row) @@ -193,10 +197,10 @@ public function test_same() : void public function test_starts_ends_with() : void { $row = Row::with( - Entry::str('a', 'some not too long string'), - Entry::str('b', 'another not too long text'), - Entry::str('c', 'another'), - Entry::str('d', 'text') + str_entry('a', 'some not too long string'), + str_entry('b', 'another not too long text'), + str_entry('c', 'another'), + str_entry('d', 'text') ); $this->assertTrue((new StartsWith(ref('a'), lit('some not')))->eval($row)); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CallMethodTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CallMethodTest.php index 612daae61..33a8854da 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CallMethodTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CallMethodTest.php @@ -3,8 +3,10 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\call_method; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -13,9 +15,9 @@ final class CallMethodTest extends TestCase public function test_call_method() : void { $row = Row::create( - Entry::datetime('object', '2023-01-01 00:00:00 UTC'), - Entry::str('method', 'format'), - Entry::str('method_param', 'H:i:s Y-m-d'), + datetime_entry('object', '2023-01-01 00:00:00 UTC'), + str_entry('method', 'format'), + str_entry('method_param', 'H:i:s Y-m-d'), ); $this->assertEquals( @@ -31,8 +33,8 @@ public function test_call_method() : void public function test_method_not_string() : void { $row = Row::create( - Entry::datetime('object', '2023-01-01 00:00:00 UTC'), - Entry::datetime('method', '2023-01-01 00:00:00 UTC'), + datetime_entry('object', '2023-01-01 00:00:00 UTC'), + datetime_entry('method', '2023-01-01 00:00:00 UTC'), ); $this->assertNull( @@ -46,8 +48,8 @@ public function test_method_not_string() : void public function test_not_existing_method() : void { $row = Row::create( - Entry::datetime('object', '2023-01-01 00:00:00 UTC'), - Entry::str('method', 'method_that_not_exists'), + datetime_entry('object', '2023-01-01 00:00:00 UTC'), + str_entry('method', 'method_that_not_exists'), ); $this->assertNull( @@ -61,8 +63,8 @@ public function test_not_existing_method() : void public function test_null_method() : void { $row = Row::create( - Entry::datetime('object', '2023-01-01 00:00:00 UTC'), - Entry::null('method'), + datetime_entry('object', '2023-01-01 00:00:00 UTC'), + null_entry('method'), ); $this->assertNull( @@ -76,8 +78,8 @@ public function test_null_method() : void public function test_null_object() : void { $row = Row::create( - Entry::null('object'), - Entry::str('method', 'getTimestamp'), + null_entry('object'), + str_entry('method', 'getTimestamp'), ); $this->assertNull( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CapitalizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CapitalizeTest.php index 6481b6674..4477f8c7d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CapitalizeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CapitalizeTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,7 +15,7 @@ public function test_capitalize_valid_string() : void { $this->assertSame( 'This Is A Value', - ref('string')->capitalize()->eval(Row::create(Entry::str('string', 'this is a value'))) + ref('string')->capitalize()->eval(Row::create(str_entry('string', 'this is a value'))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectTest.php index a4e5394f1..7ed1b363f 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectTest.php @@ -6,7 +6,7 @@ use function Flow\ETL\DSL\collect; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,10 +16,10 @@ public function test_aggregation_collect_entry_values() : void { $aggregator = collect(ref('data')); - $aggregator->aggregate(Row::create(Entry::string('data', 'a'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'b'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'b'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'c'))); + $aggregator->aggregate(Row::create(str_entry('data', 'a'))); + $aggregator->aggregate(Row::create(str_entry('data', 'b'))); + $aggregator->aggregate(Row::create(str_entry('data', 'b'))); + $aggregator->aggregate(Row::create(str_entry('data', 'c'))); $this->assertSame( [ diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectUniqueTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectUniqueTest.php index f7bcac8fd..4c6f44a07 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectUniqueTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CollectUniqueTest.php @@ -6,7 +6,7 @@ use function Flow\ETL\DSL\collect_unique; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,10 +16,10 @@ public function test_aggregation_collect_unique_values() : void { $aggregator = collect_unique(ref('data')); - $aggregator->aggregate(Row::create(Entry::string('data', 'a'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'b'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'b'))); - $aggregator->aggregate(Row::create(Entry::string('data', 'c'))); + $aggregator->aggregate(Row::create(str_entry('data', 'a'))); + $aggregator->aggregate(Row::create(str_entry('data', 'b'))); + $aggregator->aggregate(Row::create(str_entry('data', 'b'))); + $aggregator->aggregate(Row::create(str_entry('data', 'c'))); $this->assertSame( [ diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ConcatTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ConcatTest.php index 36413d56d..f042c9a2a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ConcatTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ConcatTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\concat; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -17,7 +17,7 @@ public function test_concat_arrays() : void { $this->assertSame( '["a"]["b","c"]', - concat(ref('array_1'), ref('array_2'))->eval(Row::create(Entry::array('array_1', ['a']), Entry::array('array_2', ['b', 'c']))), + concat(ref('array_1'), ref('array_2'))->eval(Row::create(array_entry('array_1', ['a']), array_entry('array_2', ['b', 'c']))), ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CountTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CountTest.php index d100311d3..3ee7df8a6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CountTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/CountTest.php @@ -5,9 +5,12 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\count; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -18,11 +21,11 @@ public function test_aggregation_count_from_numeric_values() : void { $aggregator = count(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( 4, @@ -34,10 +37,10 @@ public function test_aggregation_count_with_float_result() : void { $aggregator = count(ref('int')); - $aggregator->aggregate(Row::create(Entry::float('int', 10.25))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 305))); - $aggregator->aggregate(Row::create(Entry::integer('int', 25))); + $aggregator->aggregate(Row::create(float_entry('int', 10.25))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 305))); + $aggregator->aggregate(Row::create(int_entry('int', 25))); $this->assertSame( 4, @@ -49,11 +52,11 @@ public function test_aggregation_when_row_does_not_have_entry() : void { $aggregator = count(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::null('int'))); - $aggregator->aggregate(Row::create(Entry::null('test'))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(null_entry('int'))); + $aggregator->aggregate(Row::create(null_entry('test'))); $this->assertSame( 4, @@ -64,11 +67,11 @@ public function test_aggregation_when_row_does_not_have_entry() : void public function test_window_function_count_on_partitioned_rows() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1)), - $row2 = Row::create(Entry::int('id', 2), Entry::int('value', 1)), - Row::create(Entry::int('id', 3), Entry::int('value', 1)), - Row::create(Entry::int('id', 4), Entry::int('value', 1)), - Row::create(Entry::int('id', 1), Entry::int('value', 1)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1)), + $row2 = Row::create(int_entry('id', 2), int_entry('value', 1)), + Row::create(int_entry('id', 3), int_entry('value', 1)), + Row::create(int_entry('id', 4), int_entry('value', 1)), + Row::create(int_entry('id', 1), int_entry('value', 1)), ); $count = count(ref('id'))->over(window()->orderBy(ref('id')->desc())); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DateTimeFormatTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DateTimeFormatTest.php index 2c967d3f5..9cfc62d51 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DateTimeFormatTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DateTimeFormatTest.php @@ -5,9 +5,10 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\date_time_format; +use function Flow\ETL\DSL\datetime_entry; use function Flow\ETL\DSL\now; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -17,7 +18,7 @@ public function test_date_time_format() : void { $this->assertEquals( '2020-01-01 00:00:00', - date_time_format(ref('date_time'), 'Y-m-d H:i:s')->eval(Row::create(Entry::datetime('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) + date_time_format(ref('date_time'), 'Y-m-d H:i:s')->eval(Row::create(datetime_entry('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) ); } @@ -25,14 +26,14 @@ public function test_formatting_now() : void { $this->assertInstanceOf( \DateTimeImmutable::class, - now()->eval(Row::create(Entry::datetime('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) + now()->eval(Row::create(datetime_entry('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) ); } public function test_invalid_date_time_format() : void { $this->assertNull( - date_time_format(ref('date_time'), 'Y-m-d H:i:s')->eval(Row::create(Entry::string('date_time', '2020-01-01 00:00:00'))) + date_time_format(ref('date_time'), 'Y-m-d H:i:s')->eval(Row::create(str_entry('date_time', '2020-01-01 00:00:00'))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DensRankTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DensRankTest.php index 0a11db649..44afeab87 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DensRankTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/DensRankTest.php @@ -5,9 +5,9 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\dens_rank; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -17,11 +17,11 @@ final class DensRankTest extends TestCase public function test_rank_function_on_collection_of_rows_sorted_by_id_descending() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - $row2 = Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - $row3 = Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - $row4 = Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - $row5 = Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + $row2 = Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + $row3 = Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + $row4 = Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + $row5 = Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); $densRank = dens_rank()->over(window()->orderBy(ref('salary')->desc())); @@ -38,11 +38,11 @@ public function test_rank_function_without_more_than_one_order_by_entries() : vo $this->expectExceptionMessage('Dens Rank window function supports only one order by column'); $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); $densRank = dens_rank()->over(window()->orderBy(ref('salary'), ref('id'))); @@ -54,11 +54,11 @@ public function test_rank_function_without_order_by() : void { $this->expectExceptionMessage('Window function "dens_rank()" requires an OVER clause.'); $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); dens_rank()->apply($row1, $rows); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ExistsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ExistsTest.php index 09f7e7f9f..72636c9a1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ExistsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ExistsTest.php @@ -5,8 +5,9 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\Exists; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ final class ExistsTest extends TestCase public function test_if_reference_exists() : void { $this->assertTrue( - ref('value')->exists()->eval(Row::create(Entry::str('value', 'test'))) + ref('value')->exists()->eval(Row::create(str_entry('value', 'test'))) ); } @@ -30,7 +31,7 @@ public function test_that_lit_function_exists() : void public function test_that_null_reference_to_null_entry_exists() : void { $this->assertTrue( - ref('value')->exists()->eval(Row::create(Entry::null('value'))) + ref('value')->exists()->eval(Row::create(null_entry('value'))) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/FirstTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/FirstTest.php index ca36e6adc..5002fff0e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/FirstTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/FirstTest.php @@ -5,8 +5,9 @@ namespace Flow\ETL\Tests\Unit\Function; use function Flow\ETL\DSL\first; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,11 +17,11 @@ public function test_aggregation_firs_value() : void { $aggregator = first(ref('int')); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); $this->assertSame( '10', diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/HashTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/HashTest.php index 9386910dd..b4335b980 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/HashTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/HashTest.php @@ -4,11 +4,14 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; use function Flow\ETL\DSL\concat; +use function Flow\ETL\DSL\datetime_entry; use function Flow\ETL\DSL\hash; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -18,7 +21,7 @@ public function test_hashing_array_value() : void { $this->assertSame( '4450cf82dc53848e2bbe9798b70b0a6a', - ref('value')->hash()->eval(Row::create(Entry::array('value', ['test']))), + ref('value')->hash()->eval(Row::create(array_entry('value', ['test']))), ); } @@ -26,7 +29,7 @@ public function test_hashing_concat() : void { $this->assertSame( \hash('xxh128', 'test_test'), - hash(concat(ref('value'), lit('_'), ref('value')))->eval(Row::create(Entry::str('value', 'test'))) + hash(concat(ref('value'), lit('_'), ref('value')))->eval(Row::create(str_entry('value', 'test'))) ); } @@ -34,14 +37,14 @@ public function test_hashing_datetime() : void { $this->assertSame( '5347d10de38eb5570c044eb710a5120a', - ref('value')->hash()->eval(Row::create(Entry::datetime('value', new \DateTimeImmutable('2021-01-01')))), + ref('value')->hash()->eval(Row::create(datetime_entry('value', new \DateTimeImmutable('2021-01-01')))), ); } public function test_hashing_null_value() : void { $this->assertNull( - ref('value')->hash()->eval(Row::create(Entry::null('value'))), + ref('value')->hash()->eval(Row::create(null_entry('value'))), ); } @@ -49,7 +52,7 @@ public function test_hashing_string_value() : void { $this->assertSame( '6c78e0e3bd51d358d01e758642b85fb8', - ref('value')->hash()->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->hash()->eval(Row::create(str_entry('value', 'test'))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonDecodeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonDecodeTest.php index 09cc32f7d..2e58cb640 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonDecodeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonDecodeTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,21 +16,21 @@ public function test_json_decode_expression() : void { $this->assertSame( ['value' => 1], - ref('value')->jsonDecode()->eval(Row::create(Entry::str('value', '{"value": 1}'))), + ref('value')->jsonDecode()->eval(Row::create(str_entry('value', '{"value": 1}'))), ); } public function test_json_decode_expression_with_invalid_json() : void { $this->assertNull( - ref('value')->jsonDecode()->eval(Row::create(Entry::str('value', '{"value": 1'))), + ref('value')->jsonDecode()->eval(Row::create(str_entry('value', '{"value": 1'))), ); } public function test_json_decode_on_non_json_value() : void { $this->assertNull( - ref('value')->jsonDecode()->eval(Row::create(Entry::int('value', 125))), + ref('value')->jsonDecode()->eval(Row::create(int_entry('value', 125))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonEncodeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonEncodeTest.php index f8ac80bd0..7af060ed7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonEncodeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/JsonEncodeTest.php @@ -4,8 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,7 +18,7 @@ public function test_json_encode_on_datetime() : void { $this->assertSame( '{"date":"2021-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}', - ref('value')->jsonEncode()->eval(Row::create(Entry::datetime('value', new \DateTimeImmutable('2021-01-01')))), + ref('value')->jsonEncode()->eval(Row::create(datetime_entry('value', new \DateTimeImmutable('2021-01-01')))), ); } @@ -23,7 +26,7 @@ public function test_json_encode_on_integer() : void { $this->assertSame( '125', - ref('value')->jsonEncode()->eval(Row::create(Entry::int('value', 125))), + ref('value')->jsonEncode()->eval(Row::create(int_entry('value', 125))), ); } @@ -31,7 +34,7 @@ public function test_json_encode_on_string() : void { $this->assertSame( '"test"', - ref('value')->jsonEncode()->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->jsonEncode()->eval(Row::create(str_entry('value', 'test'))), ); } @@ -39,7 +42,7 @@ public function test_json_encode_on_valid_associative_array() : void { $this->assertSame( '{"value":1}', - ref('value')->jsonEncode()->eval(Row::create(Entry::array('value', ['value' => 1]))), + ref('value')->jsonEncode()->eval(Row::create(array_entry('value', ['value' => 1]))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/LastTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/LastTest.php index 21152d764..aa8044c12 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/LastTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/LastTest.php @@ -4,8 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\last; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -13,13 +15,13 @@ final class LastTest extends TestCase { public function test_aggregation_last_value() : void { - $aggregator = \Flow\ETL\DSL\last(ref('int')); + $aggregator = last(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( '25', @@ -29,7 +31,7 @@ public function test_aggregation_last_value() : void public function test_aggregation_last_value_when_nothing_aggregated() : void { - $aggregator = \Flow\ETL\DSL\last(ref('int')); + $aggregator = last(ref('int')); $this->assertEquals( new Row\Entry\NullEntry('int'), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MathTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MathTest.php index 58064e76e..0d3bb3fc5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MathTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MathTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Function\Divide; use Flow\ETL\Function\Minus; use Flow\ETL\Function\Mod; @@ -21,7 +22,7 @@ final class MathTest extends TestCase { public function test_divide() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 10)); + $row = Row::create(int_entry('a', 100), int_entry('b', 10)); $this->assertSame( 10, @@ -31,7 +32,7 @@ public function test_divide() : void public function test_minus() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100)); $this->assertSame( 0, @@ -41,7 +42,7 @@ public function test_minus() : void public function test_modulo() : void { - $row = Row::create(Entry::integer('a', 110), Entry::integer('b', 100)); + $row = Row::create(int_entry('a', 110), int_entry('b', 100)); $this->assertSame( 10, @@ -53,13 +54,13 @@ public function test_multiple_operations() : void { $this->assertSame( 200, - ref('a')->plus(lit(100))->plus(lit(100))->minus(ref('b'))->eval(Row::create(Entry::int('a', 100), Entry::int('b', 100))) + ref('a')->plus(lit(100))->plus(lit(100))->minus(ref('b'))->eval(Row::create(int_entry('a', 100), int_entry('b', 100))) ); } public function test_multiply() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100)); $this->assertSame( 10_000, @@ -69,7 +70,7 @@ public function test_multiply() : void public function test_plus() : void { - $row = Row::create(Entry::integer('a', 100), Entry::integer('b', 100)); + $row = Row::create(int_entry('a', 100), int_entry('b', 100)); $this->assertSame( 200, @@ -79,7 +80,7 @@ public function test_plus() : void public function test_power() : void { - $row = Row::create(Entry::integer('a', 1), Entry::integer('b', 2)); + $row = Row::create(int_entry('a', 1), int_entry('b', 2)); $this->assertSame( 1, @@ -89,7 +90,7 @@ public function test_power() : void public function test_round() : void { - $row = Row::create(Entry::float('a', 1.009), Entry::integer('b', 2)); + $row = Row::create(float_entry('a', 1.009), int_entry('b', 2)); $this->assertSame( 1.01, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MaxTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MaxTest.php index 523ae905b..f990d01d2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MaxTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MaxTest.php @@ -4,8 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,11 +18,11 @@ public function test_aggregation_max_from_numeric_values() : void { $aggregator = \Flow\ETL\DSL\max(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( 55, @@ -31,10 +34,10 @@ public function test_aggregation_max_including_null_value() : void { $aggregator = \Flow\ETL\DSL\max(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::null('int'))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(null_entry('int'))); $this->assertSame( 30, @@ -46,10 +49,10 @@ public function test_aggregation_max_with_float_result() : void { $aggregator = \Flow\ETL\DSL\max(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::float('int', 30.5))); - $aggregator->aggregate(Row::create(Entry::integer('int', 25))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(float_entry('int', 30.5))); + $aggregator->aggregate(Row::create(int_entry('int', 25))); $this->assertSame( 30.5, @@ -61,10 +64,10 @@ public function test_aggregation_max_with_integer_result() : void { $aggregator = \Flow\ETL\DSL\max(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::integer('int', 40))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(int_entry('int', 40))); $this->assertSame( 40, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MinTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MinTest.php index d00b5b9b8..fcbaaeabd 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MinTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/MinTest.php @@ -4,9 +4,12 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\min; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,11 +19,11 @@ public function test_aggregation_min_from_numeric_values() : void { $aggregator = min(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( 10, @@ -32,10 +35,10 @@ public function test_aggregation_min_including_null_value() : void { $aggregator = min(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::null('int'))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(null_entry('int'))); $this->assertSame( 10, @@ -47,10 +50,10 @@ public function test_aggregation_min_with_float_result() : void { $aggregator = min(ref('int')); - $aggregator->aggregate(Row::create(Entry::float('int', 10.25))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 305))); - $aggregator->aggregate(Row::create(Entry::integer('int', 25))); + $aggregator->aggregate(Row::create(float_entry('int', 10.25))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 305))); + $aggregator->aggregate(Row::create(int_entry('int', 25))); $this->assertSame( 10.25, @@ -62,10 +65,10 @@ public function test_aggregation_min_with_integer_result() : void { $aggregator = min(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::integer('int', 40))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(int_entry('int', 40))); $this->assertSame( 10, diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NotTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NotTest.php index db4997133..54818e8a0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NotTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NotTest.php @@ -4,10 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\not; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -30,7 +31,7 @@ public function test_not_expression_on_boolean_true_value() : void public function test_not_expression_on_is_in_expression() : void { $this->assertTrue( - not(ref('value')->isIn(ref('array')))->eval(Row::create(Entry::array('array', [1, 2, 3]), Entry::int('value', 10))) + not(ref('value')->isIn(ref('array')))->eval(Row::create(array_entry('array', [1, 2, 3]), int_entry('value', 10))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NumberFormatTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NumberFormatTest.php index e7a41c164..fc25268dc 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NumberFormatTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/NumberFormatTest.php @@ -2,9 +2,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\NumberFormat; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -24,10 +26,10 @@ public function test_number_format() : void '1,234.57', $expression->eval( Row::create( - Entry::float('value', 1234.5678), - Entry::int('decimals', 2), - Entry::string('decimal_separator', '.'), - Entry::string('thousands_separator', ',') + float_entry('value', 1234.5678), + int_entry('decimals', 2), + str_entry('decimal_separator', '.'), + str_entry('thousands_separator', ',') ) ) ); @@ -46,7 +48,7 @@ public function test_number_format_dsl() : void '1,234.57', $expression->eval( Row::create( - Entry::float('value', 1234.5678), + float_entry('value', 1234.5678), ) ) ); @@ -64,10 +66,10 @@ public function test_number_format_on_decimals_that_are_not_integer() : void $this->assertNull( $expression->eval( Row::create( - Entry::float('value', 1234.5678), - Entry::float('decimals', 2.5), - Entry::string('decimal_separator', '.'), - Entry::string('thousands_separator', ',') + float_entry('value', 1234.5678), + float_entry('decimals', 2.5), + str_entry('decimal_separator', '.'), + str_entry('thousands_separator', ',') ) ) ); @@ -85,10 +87,10 @@ public function test_number_format_on_non_int_entry() : void $this->assertNull( $expression->eval( Row::create( - Entry::string('value', 'test'), - Entry::int('decimals', 2), - Entry::string('decimal_separator', '.'), - Entry::string('thousands_separator', ',') + str_entry('value', 'test'), + int_entry('decimals', 2), + str_entry('decimal_separator', '.'), + str_entry('thousands_separator', ',') ) ) ); @@ -107,10 +109,10 @@ public function test_number_format_on_numeric_entry() : void '1,234.57', $expression->eval( Row::create( - Entry::string('value', '1234.5678'), - Entry::int('decimals', 2), - Entry::string('decimal_separator', '.'), - Entry::string('thousands_separator', ',') + str_entry('value', '1234.5678'), + int_entry('decimals', 2), + str_entry('decimal_separator', '.'), + str_entry('thousands_separator', ',') ) ) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RankTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RankTest.php index 15b6f0bf2..815804e78 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RankTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RankTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\rank; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -17,11 +17,11 @@ final class RankTest extends TestCase public function test_rank_function_on_collection_of_rows_sorted_by_id_descending() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - $row2 = Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - $row3 = Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - $row4 = Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - $row5 = Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + $row2 = Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + $row3 = Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + $row4 = Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + $row5 = Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); $rank = rank()->over(window()->orderBy(ref('salary')->desc())); @@ -38,11 +38,11 @@ public function test_rank_function_without_more_than_one_order_by_entries() : vo $this->expectExceptionMessage('Rank window function supports only one order by column'); $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); $rank = rank()->over(window()->partitionBy(ref('value'))->orderBy(ref('salary'), ref('id'))); @@ -54,11 +54,11 @@ public function test_rank_function_without_order_by() : void { $this->expectExceptionMessage('Window function "rank()" requires an OVER clause.'); $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 2), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 3), Entry::int('value', 1), Entry::int('salary', 6000)), - Row::create(Entry::int('id', 4), Entry::int('value', 1), Entry::int('salary', 2000)), - Row::create(Entry::int('id', 5), Entry::int('value', 1), Entry::int('salary', 4000)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 2), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 3), int_entry('value', 1), int_entry('salary', 6000)), + Row::create(int_entry('id', 4), int_entry('value', 1), int_entry('salary', 2000)), + Row::create(int_entry('id', 5), int_entry('value', 1), int_entry('salary', 4000)), ); $rank = rank(); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RowNumberTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RowNumberTest.php index 2dc67036d..28d389134 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RowNumberTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/RowNumberTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; use function Flow\ETL\DSL\row_number; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -17,11 +17,11 @@ final class RowNumberTest extends TestCase public function test_row_number_function_on_collection_of_rows_sorted_by_id_descending() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1)), - Row::create(Entry::int('id', 2), Entry::int('value', 1)), - Row::create(Entry::int('id', 3), Entry::int('value', 1)), - Row::create(Entry::int('id', 4), Entry::int('value', 1)), - Row::create(Entry::int('id', 5), Entry::int('value', 1)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1)), + Row::create(int_entry('id', 2), int_entry('value', 1)), + Row::create(int_entry('id', 3), int_entry('value', 1)), + Row::create(int_entry('id', 4), int_entry('value', 1)), + Row::create(int_entry('id', 5), int_entry('value', 1)), ); $rowNumber = row_number()->over(window()->partitionBy(ref('value'))->orderBy(ref('id')->desc())); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SanitizeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SanitizeTest.php index 935577226..ffc5c9efd 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SanitizeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SanitizeTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -15,7 +16,7 @@ final class SanitizeTest extends TestCase public function test_sanitize_on_non_string_value() : void { $this->assertNull( - ref('value')->sanitize()->eval(Row::create(Entry::int('value', 1000))), + ref('value')->sanitize()->eval(Row::create(int_entry('value', 1000))), ); } @@ -23,7 +24,7 @@ public function test_sanitize_on_valid_string() : void { $this->assertSame( '****', - ref('value')->sanitize()->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->sanitize()->eval(Row::create(str_entry('value', 'test'))), ); } @@ -31,7 +32,7 @@ public function test_sanitize_on_valid_string_with_left_characters() : void { $this->assertSame( 'te**', - ref('value')->sanitize(skipCharacters: lit(2))->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->sanitize(skipCharacters: lit(2))->eval(Row::create(str_entry('value', 'test'))), ); } @@ -39,7 +40,7 @@ public function test_sanitize_on_valid_string_with_left_characters_longer_than_s { $this->assertSame( '****', - ref('value')->sanitize(skipCharacters: lit(5))->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->sanitize(skipCharacters: lit(5))->eval(Row::create(str_entry('value', 'test'))), ); } @@ -47,7 +48,7 @@ public function test_sanitize_on_valid_string_with_placeholder() : void { $this->assertSame( '----', - ref('value')->sanitize(lit('-'))->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->sanitize(lit('-'))->eval(Row::create(str_entry('value', 'test'))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ScalarFunctionsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ScalarFunctionsTest.php index 8194e3a75..26a0d32c6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ScalarFunctionsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ScalarFunctionsTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\Cast; use Flow\ETL\Function\Equals; use Flow\ETL\Function\ScalarFunctions; @@ -23,7 +24,7 @@ public function test_evaluating_multiple_entry_references() : void new Cast(ref('entry'), 'string'), new Equals(ref('entry'), lit(1)) ))->eval(Row::create( - Entry::int('entry', 1), + int_entry('entry', 1), )) ); } @@ -44,14 +45,14 @@ public function test_evaluation_cast_expression() : void { $this->assertSame( 1, - (new ScalarFunctions(new Cast(ref('entry'), 'int')))->eval(Row::create(Entry::string('entry', '1'))) + (new ScalarFunctions(new Cast(ref('entry'), 'int')))->eval(Row::create(str_entry('entry', '1'))) ); } public function test_evaluation_empty_expression() : void { $this->assertNull( - (new ScalarFunctions())->eval(Row::create(Entry::string('entry', 'value'))) + (new ScalarFunctions())->eval(Row::create(str_entry('entry', 'value'))) ); } @@ -59,7 +60,7 @@ public function test_evaluation_equals_expression() : void { $this->assertTrue( (new ScalarFunctions(ref('entry')->equals(lit('1')))) - ->eval(Row::create(Entry::string('entry', '1'))) + ->eval(Row::create(str_entry('entry', '1'))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrPadTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrPadTest.php index db0fe244a..a40872588 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrPadTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrPadTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -14,7 +15,7 @@ final class StrPadTest extends TestCase public function test_str_pad_on_non_string_value() : void { $this->assertNull( - ref('value')->strPad(5, '-', \STR_PAD_LEFT)->eval(Row::create(Entry::int('value', 1000))), + ref('value')->strPad(5, '-', \STR_PAD_LEFT)->eval(Row::create(int_entry('value', 1000))), ); } @@ -22,7 +23,7 @@ public function test_str_pad_on_valid_string() : void { $this->assertSame( '----N', - ref('value')->strPad(5, '-', \STR_PAD_LEFT)->eval(Row::create(Entry::str('value', 'N'))), + ref('value')->strPad(5, '-', \STR_PAD_LEFT)->eval(Row::create(str_entry('value', 'N'))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrReplaceTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrReplaceTest.php index f2a910896..e38a4d567 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrReplaceTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StrReplaceTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -14,7 +15,7 @@ final class StrReplaceTest extends TestCase public function test_str_replace_on_non_string_value() : void { $this->assertNull( - ref('value')->strReplace('test', '1')->eval(Row::create(Entry::int('value', 1000))), + ref('value')->strReplace('test', '1')->eval(Row::create(int_entry('value', 1000))), ); } @@ -22,7 +23,7 @@ public function test_str_replace_on_valid_string() : void { $this->assertSame( '1', - ref('value')->strReplace('test', '1')->eval(Row::create(Entry::str('value', 'test'))), + ref('value')->strReplace('test', '1')->eval(Row::create(str_entry('value', 'test'))), ); } @@ -30,7 +31,7 @@ public function test_str_replace_on_valid_string_with_array_of_replacements() : { $this->assertSame( 'test was successful', - ref('value')->strReplace(['is', 'broken'], ['was', 'successful'])->eval(Row::create(Entry::str('value', 'test is broken'))), + ref('value')->strReplace(['is', 'broken'], ['was', 'successful'])->eval(Row::create(str_entry('value', 'test is broken'))), ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SumTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SumTest.php index 391f0825c..038198065 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SumTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/SumTest.php @@ -4,10 +4,13 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\sum; use function Flow\ETL\DSL\window; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use Flow\ETL\Rows; use PHPUnit\Framework\TestCase; @@ -18,11 +21,11 @@ public function test_aggregation_sum_from_numeric_values() : void { $aggregator = sum(ref('int')); - $aggregator->aggregate(Row::create(Entry::string('int', '10'))); - $aggregator->aggregate(Row::create(Entry::string('int', '20'))); - $aggregator->aggregate(Row::create(Entry::string('int', '55'))); - $aggregator->aggregate(Row::create(Entry::string('int', '25'))); - $aggregator->aggregate(Row::create(Entry::null('not_int'))); + $aggregator->aggregate(Row::create(str_entry('int', '10'))); + $aggregator->aggregate(Row::create(str_entry('int', '20'))); + $aggregator->aggregate(Row::create(str_entry('int', '55'))); + $aggregator->aggregate(Row::create(str_entry('int', '25'))); + $aggregator->aggregate(Row::create(null_entry('not_int'))); $this->assertSame( 110, @@ -34,10 +37,10 @@ public function test_aggregation_sum_including_null_value() : void { $aggregator = sum(ref('int')); - $aggregator->aggregate(Row::create(Entry::integer('int', 10))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 30))); - $aggregator->aggregate(Row::create(Entry::null('int'))); + $aggregator->aggregate(Row::create(int_entry('int', 10))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 30))); + $aggregator->aggregate(Row::create(null_entry('int'))); $this->assertSame( 60, @@ -49,10 +52,10 @@ public function test_aggregation_sum_with_float_result() : void { $aggregator = sum(ref('int')); - $aggregator->aggregate(Row::create(Entry::float('int', 10.25))); - $aggregator->aggregate(Row::create(Entry::integer('int', 20))); - $aggregator->aggregate(Row::create(Entry::integer('int', 305))); - $aggregator->aggregate(Row::create(Entry::integer('int', 25))); + $aggregator->aggregate(Row::create(float_entry('int', 10.25))); + $aggregator->aggregate(Row::create(int_entry('int', 20))); + $aggregator->aggregate(Row::create(int_entry('int', 305))); + $aggregator->aggregate(Row::create(int_entry('int', 25))); $this->assertSame( 360.25, @@ -63,11 +66,11 @@ public function test_aggregation_sum_with_float_result() : void public function test_window_function_sum_on_partitioned_rows() : void { $rows = new Rows( - $row1 = Row::create(Entry::int('id', 1), Entry::int('value', 1)), - Row::create(Entry::int('id', 2), Entry::int('value', 1)), - Row::create(Entry::int('id', 3), Entry::int('value', 1)), - Row::create(Entry::int('id', 4), Entry::int('value', 1)), - Row::create(Entry::int('id', 5), Entry::int('value', 1)), + $row1 = Row::create(int_entry('id', 1), int_entry('value', 1)), + Row::create(int_entry('id', 2), int_entry('value', 1)), + Row::create(int_entry('id', 3), int_entry('value', 1)), + Row::create(int_entry('id', 4), int_entry('value', 1)), + Row::create(int_entry('id', 5), int_entry('value', 1)), ); $sum = sum(ref('id'))->over(window()->orderBy(ref('id')->desc())); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTest.php index ea8784df0..c445e7931 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTest.php @@ -4,9 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\to_date; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +18,7 @@ public function test_date_time_to_date() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date(ref('date_time'))->eval(Row::create(Entry::datetime('date_time', new \DateTimeImmutable('2020-01-01 12:43:23', new \DateTimeZone('UTC'))))) + to_date(ref('date_time'))->eval(Row::create(datetime_entry('date_time', new \DateTimeImmutable('2020-01-01 12:43:23', new \DateTimeZone('UTC'))))) ); } @@ -24,7 +26,7 @@ public function test_int_to_date_time() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date(ref('int'))->eval(Row::create(Entry::int('int', (int) (new \DateTimeImmutable('2020-01-01 10:11:11', new \DateTimeZone('UTC')))->format('U')))) + to_date(ref('int'))->eval(Row::create(int_entry('int', (int) (new \DateTimeImmutable('2020-01-01 10:11:11', new \DateTimeZone('UTC')))->format('U')))) ); } @@ -32,7 +34,7 @@ public function test_string_to_date_time() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date(ref('string'), 'Y-m-d H:i:s')->eval(Row::create(Entry::str('string', '2020-01-01 10:08:00'))) + to_date(ref('string'), 'Y-m-d H:i:s')->eval(Row::create(str_entry('string', '2020-01-01 10:08:00'))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTimeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTimeTest.php index e5117c09d..925653c59 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTimeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToDateTimeTest.php @@ -4,9 +4,11 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\to_date_time; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +18,7 @@ public function test_date_time_to_date_time() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date_time(ref('date_time'))->eval(Row::create(Entry::datetime('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) + to_date_time(ref('date_time'))->eval(Row::create(datetime_entry('date_time', new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC'))))) ); } @@ -24,7 +26,7 @@ public function test_int_to_date_time() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date_time(ref('int'))->eval(Row::create(Entry::int('int', (int) (new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')))->format('U')))) + to_date_time(ref('int'))->eval(Row::create(int_entry('int', (int) (new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')))->format('U')))) ); } @@ -32,7 +34,7 @@ public function test_string_to_date_time() : void { $this->assertEquals( new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('UTC')), - to_date_time(ref('string'), 'Y-m-d H:i:s')->eval(Row::create(Entry::str('string', '2020-01-01 00:00:00'))) + to_date_time(ref('string'), 'Y-m-d H:i:s')->eval(Row::create(str_entry('string', '2020-01-01 00:00:00'))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToMoneyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToMoneyTest.php index ba2d6411e..f0fdbaa17 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToMoneyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToMoneyTest.php @@ -2,8 +2,12 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\ToMoney; use Flow\ETL\Row; use Money\Currency; @@ -14,7 +18,7 @@ final class ToMoneyTest extends TestCase { public function test_money_amount() : void { - $row = Row::create(Entry::str('a', '19.90'), Entry::str('b', 'USD')); + $row = Row::create(str_entry('a', '19.90'), str_entry('b', 'USD')); $this->assertEquals( new Money('1990', new Currency('USD')), @@ -24,7 +28,7 @@ public function test_money_amount() : void public function test_money_amount_float() : void { - $row = Row::create(Entry::float('a', 19.90), Entry::str('b', 'USD')); + $row = Row::create(float_entry('a', 19.90), str_entry('b', 'USD')); $this->assertEquals( new Money('1990', new Currency('USD')), @@ -34,7 +38,7 @@ public function test_money_amount_float() : void public function test_money_amount_integer() : void { - $row = Row::create(Entry::integer('a', 19), Entry::str('b', 'USD')); + $row = Row::create(int_entry('a', 19), str_entry('b', 'USD')); $this->assertEquals( new Money('1900', new Currency('USD')), @@ -44,7 +48,7 @@ public function test_money_amount_integer() : void public function test_non_numeric_money_amount() : void { - $row = Row::create(Entry::bool('a', false), Entry::null('b')); + $row = Row::create(bool_entry('a', false), null_entry('b')); $this->assertNull( (new ToMoney(ref('a'), ref('b')))->eval($row) @@ -53,7 +57,7 @@ public function test_non_numeric_money_amount() : void public function test_null_currency() : void { - $row = Row::create(Entry::str('a', '19.90'), Entry::null('b')); + $row = Row::create(str_entry('a', '19.90'), null_entry('b')); $this->assertNull( (new ToMoney(ref('a'), ref('b')))->eval($row) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToTimeZoneTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToTimeZoneTest.php index 7d2d44b29..26b0b5ff9 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToTimeZoneTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/ToTimeZoneTest.php @@ -6,8 +6,8 @@ use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\to_timezone; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -31,7 +31,7 @@ public function test_casting_date_time_pst_to_utc_time_zone_from_entry_ref() : v to_timezone( lit(new \DateTimeImmutable('2020-01-01 00:00:00', new \DateTimeZone('PST'))), ref('tz') - )->eval(Row::create(Entry::str('tz', 'UTC')))->format('Y-m-d H:i:s.u') + )->eval(Row::create(str_entry('tz', 'UTC')))->format('Y-m-d H:i:s.u') ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/TrimTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/TrimTest.php index ca3bbd343..382bcfb5e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/TrimTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/TrimTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Function\Trim\Type; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,14 +17,14 @@ public function test_trim_both_valid_string() : void { $this->assertSame( 'value', - ref('string')->trim()->eval(Row::create(Entry::str('string', ' value'))) + ref('string')->trim()->eval(Row::create(str_entry('string', ' value'))) ); } public function test_trim_integer() : void { $this->assertNull( - ref('integer')->trim()->eval(Row::create(Entry::integer('integer', 1))) + ref('integer')->trim()->eval(Row::create(int_entry('integer', 1))) ); } @@ -31,7 +32,7 @@ public function test_trim_left_valid_string() : void { $this->assertSame( 'value ', - ref('string')->trim(Type::LEFT)->eval(Row::create(Entry::str('string', ' value '))) + ref('string')->trim(Type::LEFT)->eval(Row::create(str_entry('string', ' value '))) ); } @@ -39,7 +40,7 @@ public function test_trim_right_valid_string() : void { $this->assertSame( ' value', - ref('string')->trim(Type::RIGHT)->eval(Row::create(Entry::str('string', ' value '))) + ref('string')->trim(Type::RIGHT)->eval(Row::create(str_entry('string', ' value '))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/WhenTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/WhenTest.php index 2740c846f..5d636b45e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/WhenTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/WhenTest.php @@ -4,9 +4,9 @@ namespace Flow\ETL\Tests\Unit\Function; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Function\Literal; use Flow\ETL\Function\When; use Flow\ETL\Row; @@ -22,7 +22,7 @@ public function test_condition_not_satisfied_without_else() : void ref('id')->equals(lit(2)), new Literal('then'), ref('id') - ))->eval(Row::with(Entry::int('id', 1))) + ))->eval(Row::with(int_entry('id', 1))) ); } @@ -34,7 +34,7 @@ public function test_else() : void new Literal(false), new Literal('then'), new Literal('else'), - ))->eval(Row::with(Entry::int('id', 1))) + ))->eval(Row::with(int_entry('id', 1))) ); } @@ -45,7 +45,7 @@ public function test_when() : void (new When( new Literal(true), new Literal('then') - ))->eval(Row::with(Entry::int('id', 1))) + ))->eval(Row::with(int_entry('id', 1))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/GroupByTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/GroupByTest.php index 3658bdbf7..a800b0700 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/GroupByTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/GroupByTest.php @@ -4,10 +4,13 @@ namespace Flow\ETL\Tests\Unit; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; use function Flow\ETL\DSL\sum; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\FlowContext; @@ -26,9 +29,9 @@ public function test_group_by_array_entry() : void $groupBy = new GroupBy('array'); $groupBy->group(new Rows( - Row::create(Entry::array('array', [1, 2, 3])), - Row::create(Entry::array('array', [1, 2, 3])), - Row::create(Entry::array('array', [4, 5, 6])) + Row::create(array_entry('array', [1, 2, 3])), + Row::create(array_entry('array', [1, 2, 3])), + Row::create(array_entry('array', [4, 5, 6])) )); } @@ -37,16 +40,16 @@ public function test_group_by_missing_entry() : void $groupBy = new GroupBy('type'); $groupBy->group(new Rows( - Row::create(Entry::string('type', 'a')), - Row::create(Entry::string('not-type', 'b')), - Row::create(Entry::string('type', 'c')) + Row::create(str_entry('type', 'a')), + Row::create(str_entry('not-type', 'b')), + Row::create(str_entry('type', 'c')) )); $this->assertEquals( new Rows( - Row::create(Entry::string('type', 'a')), - Row::create(Entry::null('type')), - Row::create(Entry::string('type', 'c')) + Row::create(str_entry('type', 'a')), + Row::create(null_entry('type')), + Row::create(str_entry('type', 'c')) ), $groupBy->result(new FlowContext(Config::default())) ); @@ -58,19 +61,19 @@ public function test_group_by_with_aggregation() : void $group->aggregate(sum(ref('id'))); $group->group(new Rows( - Row::create(Entry::int('id', 1), Entry::string('type', 'a')), - Row::create(Entry::int('id', 2), Entry::string('type', 'b')), - Row::create(Entry::int('id', 3), Entry::string('type', 'c')), - Row::create(Entry::int('id', 4), Entry::string('type', 'a')), - Row::create(Entry::int('id', 5), Entry::string('type', 'd')) + Row::create(int_entry('id', 1), str_entry('type', 'a')), + Row::create(int_entry('id', 2), str_entry('type', 'b')), + Row::create(int_entry('id', 3), str_entry('type', 'c')), + Row::create(int_entry('id', 4), str_entry('type', 'a')), + Row::create(int_entry('id', 5), str_entry('type', 'd')) )); $this->assertEquals( new Rows( - Row::create(Entry::int('id_sum', 5), Entry::string('type', 'a')), - Row::create(Entry::int('id_sum', 2), Entry::string('type', 'b')), - Row::create(Entry::int('id_sum', 3), Entry::string('type', 'c')), - Row::create(Entry::int('id_sum', 5), Entry::string('type', 'd')), + Row::create(int_entry('id_sum', 5), str_entry('type', 'a')), + Row::create(int_entry('id_sum', 2), str_entry('type', 'b')), + Row::create(int_entry('id_sum', 3), str_entry('type', 'c')), + Row::create(int_entry('id_sum', 5), str_entry('type', 'd')), ), $group->result(new FlowContext(Config::default())) ); @@ -87,18 +90,18 @@ public function test_group_by_with_empty_aggregations() : void public function test_group_by_with_pivoting() : void { $rows = new Rows( - Row::create(Entry::string('product', 'Banana'), Entry::int('amount', 1000), Entry::string('country', 'USA')), - Row::create(Entry::string('product', 'Carrots'), Entry::int('amount', 1500), Entry::string('country', 'USA')), - Row::create(Entry::string('product', 'Beans'), Entry::int('amount', 1600), Entry::string('country', 'USA')), - Row::create(Entry::string('product', 'Orange'), Entry::int('amount', 2000), Entry::string('country', 'USA')), - Row::create(Entry::string('product', 'Orange'), Entry::int('amount', 2000), Entry::string('country', 'USA')), - Row::create(Entry::string('product', 'Banana'), Entry::int('amount', 400), Entry::string('country', 'China')), - Row::create(Entry::string('product', 'Carrots'), Entry::int('amount', 1200), Entry::string('country', 'China')), - Row::create(Entry::string('product', 'Beans'), Entry::int('amount', 1500), Entry::string('country', 'China')), - Row::create(Entry::string('product', 'Orange'), Entry::int('amount', 4000), Entry::string('country', 'China')), - Row::create(Entry::string('product', 'Banana'), Entry::int('amount', 2000), Entry::string('country', 'Canada')), - Row::create(Entry::string('product', 'Carrots'), Entry::int('amount', 2000), Entry::string('country', 'Canada')), - Row::create(Entry::string('product', 'Beans'), Entry::int('amount', 2000), Entry::string('country', 'Mexico')), + Row::create(str_entry('product', 'Banana'), int_entry('amount', 1000), str_entry('country', 'USA')), + Row::create(str_entry('product', 'Carrots'), int_entry('amount', 1500), str_entry('country', 'USA')), + Row::create(str_entry('product', 'Beans'), int_entry('amount', 1600), str_entry('country', 'USA')), + Row::create(str_entry('product', 'Orange'), int_entry('amount', 2000), str_entry('country', 'USA')), + Row::create(str_entry('product', 'Orange'), int_entry('amount', 2000), str_entry('country', 'USA')), + Row::create(str_entry('product', 'Banana'), int_entry('amount', 400), str_entry('country', 'China')), + Row::create(str_entry('product', 'Carrots'), int_entry('amount', 1200), str_entry('country', 'China')), + Row::create(str_entry('product', 'Beans'), int_entry('amount', 1500), str_entry('country', 'China')), + Row::create(str_entry('product', 'Orange'), int_entry('amount', 4000), str_entry('country', 'China')), + Row::create(str_entry('product', 'Banana'), int_entry('amount', 2000), str_entry('country', 'Canada')), + Row::create(str_entry('product', 'Carrots'), int_entry('amount', 2000), str_entry('country', 'Canada')), + Row::create(str_entry('product', 'Beans'), int_entry('amount', 2000), str_entry('country', 'Mexico')), ); $group = new GroupBy(ref('product')); @@ -109,10 +112,10 @@ public function test_group_by_with_pivoting() : void $this->assertEquals( new Rows( - Row::create(Entry::string('product', 'Banana'), Entry::int('Canada', 2000), Entry::int('China', 400), Entry::null('Mexico'), Entry::int('USA', 1000)), - Row::create(Entry::string('product', 'Beans'), Entry::null('Canada'), Entry::int('China', 1500), Entry::int('Mexico', 2000), Entry::int('USA', 1600)), - Row::create(Entry::string('product', 'Carrots'), Entry::int('Canada', 2000), Entry::int('China', 1200), Entry::null('Mexico'), Entry::int('USA', 1500)), - Row::create(Entry::string('product', 'Orange'), Entry::null('Canada'), Entry::int('China', 4000), Entry::null('Mexico'), Entry::int('USA', 4000)), + Row::create(str_entry('product', 'Banana'), int_entry('Canada', 2000), int_entry('China', 400), null_entry('Mexico'), int_entry('USA', 1000)), + Row::create(str_entry('product', 'Beans'), null_entry('Canada'), int_entry('China', 1500), int_entry('Mexico', 2000), int_entry('USA', 1600)), + Row::create(str_entry('product', 'Carrots'), int_entry('Canada', 2000), int_entry('China', 1200), null_entry('Mexico'), int_entry('USA', 1500)), + Row::create(str_entry('product', 'Orange'), null_entry('Canada'), int_entry('China', 4000), null_entry('Mexico'), int_entry('USA', 4000)), ), $group->result(new FlowContext(Config::default()))->sortBy(ref('product')) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AllTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AllTest.php index ca88063c3..3578d8cf6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AllTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AllTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison; use Flow\ETL\Join\Comparison\All; use Flow\ETL\Row; @@ -27,8 +27,8 @@ public function test_failure() : void $this->assertFalse( (new All($comparison1, $comparison2)) ->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } @@ -48,8 +48,8 @@ public function test_success() : void $this->assertTrue( (new All($comparison1, $comparison2)) ->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AnyTest.php index 9000182e6..07d2924ae 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AnyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/AnyTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison; use Flow\ETL\Join\Comparison\Any; use Flow\ETL\Row; @@ -27,8 +27,8 @@ public function test_failure() : void $this->assertFalse( (new Any($comparison1, $comparison2)) ->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } @@ -48,8 +48,8 @@ public function test_success() : void $this->assertTrue( (new Any($comparison1, $comparison2)) ->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/EqualTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/EqualTest.php index 12bd444ed..58c32ec44 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/EqualTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/EqualTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\datetime_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\Equal; use Flow\ETL\Row; @@ -15,8 +15,8 @@ public function test_failure() : void { $this->assertFalse( (new Equal('datetime', 'datetime'))->compare( - Row::create(Entry::datetime('datetime', new \DateTimeImmutable('2022-10-01 00:00:00'))), - Row::create(Entry::datetime('datetime', new \DateTimeImmutable('2022-10-01 01:00:00'))), + Row::create(datetime_entry('datetime', new \DateTimeImmutable('2022-10-01 00:00:00'))), + Row::create(datetime_entry('datetime', new \DateTimeImmutable('2022-10-01 01:00:00'))), ) ); } @@ -25,8 +25,8 @@ public function test_success() : void { $this->assertTrue( (new Equal('datetime', 'datetime'))->compare( - Row::create(Entry::datetime('datetime', $datetime = new \DateTimeImmutable('2022-10-01 00:00:00'))), - Row::create(Entry::datetime('datetime', $datetime)), + Row::create(datetime_entry('datetime', $datetime = new \DateTimeImmutable('2022-10-01 00:00:00'))), + Row::create(datetime_entry('datetime', $datetime)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterTest.php index ca75c0990..5e15d1be2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\GreaterThan; use Flow\ETL\Row; @@ -15,14 +15,14 @@ public function test_failure() : void { $this->assertFalse( (new GreaterThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); $this->assertFalse( (new GreaterThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), ) ); } @@ -31,8 +31,8 @@ public function test_success() : void { $this->assertTrue( (new GreaterThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 5)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 5)), + Row::create(int_entry('id', 1)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterThanEqualTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterThanEqualTest.php index 3586829ec..cfeecca46 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterThanEqualTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/GreaterThanEqualTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\GreaterThanEqual; use Flow\ETL\Row; @@ -15,8 +15,8 @@ public function test_failure() : void { $this->assertFalse( (new GreaterThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } @@ -25,15 +25,15 @@ public function test_success() : void { $this->assertTrue( (new GreaterThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 5)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 5)), + Row::create(int_entry('id', 1)), ) ); $this->assertTrue( (new GreaterThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/IdenticalTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/IdenticalTest.php index e45d43737..853540b32 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/IdenticalTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/IdenticalTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\Identical; use Flow\ETL\Row; @@ -15,8 +15,8 @@ public function test_failure() : void { $this->assertFalse( (new Identical('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)), ) ); } @@ -25,8 +25,8 @@ public function test_success() : void { $this->assertTrue( (new Identical('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessTest.php index f87866cc0..872c89ad9 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\LessThan; use Flow\ETL\Row; @@ -15,14 +15,14 @@ public function test_failure() : void { $this->assertFalse( (new LessThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 2)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 2)), + Row::create(int_entry('id', 1)), ) ); $this->assertFalse( (new LessThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), ) ); } @@ -31,8 +31,8 @@ public function test_success() : void { $this->assertTrue( (new LessThan('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 5)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 5)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessThanEqualTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessThanEqualTest.php index 82f4c5afd..de65be270 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessThanEqualTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/LessThanEqualTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\LessThanEqual; use Flow\ETL\Row; @@ -15,8 +15,8 @@ public function test_failure() : void { $this->assertFalse( (new LessThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 2)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 2)), + Row::create(int_entry('id', 1)), ) ); } @@ -25,15 +25,15 @@ public function test_success() : void { $this->assertTrue( (new LessThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 5)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 5)), ) ); $this->assertTrue( (new LessThanEqual('id', 'id'))->compare( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/NotTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/NotTest.php index fb437e160..1a74dab67 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/NotTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/Comparison/NotTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Join\Comparison; +use function Flow\ETL\DSL\datetime_entry; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\Entry; use Flow\ETL\Join\Comparison\Equal; use Flow\ETL\Join\Comparison\Not; use Flow\ETL\Row; @@ -16,8 +16,8 @@ public function test_failure() : void { $this->assertFalse( (new Not(new Equal('datetime', 'datetime')))->compare( - Row::create(Entry::datetime('datetime', $datetime = new \DateTimeImmutable('2022-10-01 00:00:00'))), - Row::create(Entry::datetime('datetime', $datetime)), + Row::create(datetime_entry('datetime', $datetime = new \DateTimeImmutable('2022-10-01 00:00:00'))), + Row::create(datetime_entry('datetime', $datetime)), ) ); } @@ -26,8 +26,8 @@ public function test_success() : void { $this->assertTrue( (new Not(new Equal('datetime', 'datetime')))->compare( - Row::create(Entry::datetime('datetime', new \DateTimeImmutable('2022-10-01 00:00:00'))), - Row::create(Entry::datetime('datetime', new \DateTimeImmutable('2022-10-01 01:00:00'))), + Row::create(datetime_entry('datetime', new \DateTimeImmutable('2022-10-01 00:00:00'))), + Row::create(datetime_entry('datetime', new \DateTimeImmutable('2022-10-01 01:00:00'))), ) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/ExpressionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/ExpressionTest.php index ce77d70c3..b783b20eb 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/ExpressionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Join/ExpressionTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Tests\Unit\Join; use function Flow\ETL\DSL\col; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\int_entry; use Flow\ETL\Join\Comparison\Equal; use Flow\ETL\Join\Expression; use Flow\ETL\Row; @@ -27,8 +27,8 @@ public function test_expression_comparison() : void $expression = Expression::on(new Equal('id', 'id'), '_'); $this->assertTrue($expression->meet( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 1)), + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 1)), )); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/CallbackLoaderTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/CallbackLoaderTest.php index be971e8be..0ef5dc514 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/CallbackLoaderTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/CallbackLoaderTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Loader; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_callable; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\To; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -18,13 +19,13 @@ final class CallbackLoaderTest extends TestCase public function test_callback_loader() : void { $rows = new Rows( - Row::create(Entry::integer('number', 1), Entry::string('name', 'one')), - Row::create(Entry::integer('number', 2), Entry::string('name', 'two')), + Row::create(int_entry('number', 1), str_entry('name', 'one')), + Row::create(int_entry('number', 2), str_entry('name', 'two')), ); $data = []; - To::callback(function (Rows $rows) use (&$data) : void { + to_callable(function (Rows $rows) use (&$data) : void { $data = $rows->toArray(); })->load($rows, new FlowContext(Config::default())); @@ -34,13 +35,13 @@ public function test_callback_loader() : void public function test_callback_loader_serialization() : void { $rows = new Rows( - Row::create(Entry::integer('number', 1), Entry::string('name', 'one')), - Row::create(Entry::integer('number', 2), Entry::string('name', 'two')), + Row::create(int_entry('number', 1), str_entry('name', 'one')), + Row::create(int_entry('number', 2), str_entry('name', 'two')), ); $path = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . \uniqid('flow_callback_loader') . '.txt'; - $loader = To::callback(function (Rows $rows) use ($path) : void { + $loader = to_callable(function (Rows $rows) use ($path) : void { $data = $rows->toArray(); \file_put_contents($path, \print_r($data, true)); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/MemoryLoaderTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/MemoryLoaderTest.php index e1e1d24a7..3e1639ae4 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/MemoryLoaderTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/MemoryLoaderTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Loader; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_memory; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\To; use Flow\ETL\FlowContext; use Flow\ETL\Memory\ArrayMemory; use Flow\ETL\Row; @@ -18,13 +19,13 @@ final class MemoryLoaderTest extends TestCase public function test_loads_rows_data_into_memory() : void { $rows = new Rows( - Row::create(Entry::integer('number', 1), Entry::string('name', 'one')), - Row::create(Entry::integer('number', 2), Entry::string('name', 'two')), + Row::create(int_entry('number', 1), str_entry('name', 'one')), + Row::create(int_entry('number', 2), str_entry('name', 'two')), ); $memory = new ArrayMemory(); - To::memory($memory)->load($rows, new FlowContext(Config::default())); + to_memory($memory)->load($rows, new FlowContext(Config::default())); $this->assertEquals($rows->toArray(), $memory->dump()); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/SchemaValidationLoaderTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/SchemaValidationLoaderTest.php index 4a0e83216..3aab38e40 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/SchemaValidationLoaderTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/SchemaValidationLoaderTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Loader; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\SchemaValidationException; use Flow\ETL\FlowContext; use Flow\ETL\Loader\SchemaValidationLoader; @@ -40,7 +41,7 @@ public function test_schema_validation_failed() : void ); $loader->load(new Rows( - Row::create(Entry::string('id', '1')) + Row::create(str_entry('id', '1')) ), new FlowContext(Config::default())); } @@ -54,7 +55,7 @@ public function test_schema_validation_succeed() : void ); $loader->load(new Rows( - Row::create(Entry::integer('id', 1)) + Row::create(int_entry('id', 1)) ), new FlowContext(Config::default())); // validate that error wasn't thrown 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 8cf3eb9cb..7a7d93d64 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 @@ -4,9 +4,11 @@ namespace Flow\ETL\Tests\Unit\Loader; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\to_output; +use function Flow\ETL\DSL\to_stream; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; -use Flow\ETL\DSL\To; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Filesystem\Stream\Mode; use Flow\ETL\FlowContext; @@ -22,13 +24,13 @@ public function test_loading_data_int_invalid_stream() : void $this->expectExceptionMessage("Can't open stream for url: php://qweqweqw in mode: w"); $this->expectException(RuntimeException::class); - $loader = To::stream('php://qweqweqw', 0); + $loader = to_stream('php://qweqweqw', 0); $loader->load( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'id_1')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'id_2')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'id_3')) + Row::create(int_entry('id', 1), str_entry('name', 'id_1')), + Row::create(int_entry('id', 2), str_entry('name', 'id_2')), + Row::create(int_entry('id', 3), str_entry('name', 'id_3')) ), new FlowContext(Config::default()) ); @@ -36,15 +38,15 @@ public function test_loading_data_int_invalid_stream() : void public function test_loading_rows_and_schema_into_php_memory_stream() : void { - $loader = To::output(false, StreamLoader\Output::rows_and_schema); + $loader = to_output(false, StreamLoader\Output::rows_and_schema); \ob_start(); $loader->load( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'id_1')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'id_2')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'id_3')) + Row::create(int_entry('id', 1), str_entry('name', 'id_1')), + Row::create(int_entry('id', 2), str_entry('name', 'id_2')), + Row::create(int_entry('id', 3), str_entry('name', 'id_3')) ), new FlowContext(Config::default()) ); @@ -79,9 +81,9 @@ public function test_loading_rows_into_php_memory_stream() : void $loader->load( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'id_1')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'id_2')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'id_3')) + Row::create(int_entry('id', 1), str_entry('name', 'id_1')), + Row::create(int_entry('id', 2), str_entry('name', 'id_2')), + Row::create(int_entry('id', 3), str_entry('name', 'id_3')) ), new FlowContext(Config::default()) ); @@ -111,9 +113,9 @@ public function test_loading_schema_into_php_memory_stream() : void $loader->load( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'id_1')), - Row::create(Entry::integer('id', 2), Entry::string('name', 'id_2')), - Row::create(Entry::integer('id', 3), Entry::string('name', 'id_3')) + Row::create(int_entry('id', 1), str_entry('name', 'id_1')), + Row::create(int_entry('id', 2), str_entry('name', 'id_2')), + Row::create(int_entry('id', 3), str_entry('name', 'id_3')) ), new FlowContext(Config::default()) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/TransformerLoaderTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/TransformerLoaderTest.php index bd012b1b5..b297e4057 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/TransformerLoaderTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Loader/TransformerLoaderTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Loader; +use function Flow\ETL\DSL\to_transformation; use Flow\ETL\Config; -use Flow\ETL\DSL\To; use Flow\ETL\FlowContext; use Flow\ETL\Loader; use Flow\ETL\Rows; @@ -26,7 +26,7 @@ public function test_transformer_loader() : void $loaderMock->expects($this->once()) ->method('load'); - $transformer = To::transform_to( + $transformer = to_transformation( $transformerMock, $loaderMock ); @@ -40,7 +40,7 @@ public function test_transformer_loader_with_serialization() : void $loaderMock = $this->createMock(Loader::class); - $transformer = To::transform_to( + $transformer = to_transformation( $transformerMock, $loaderMock ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/ArrayContentDetectorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/ArrayContentDetectorTest.php index 603a26416..d0b55f7d3 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/ArrayContentDetectorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/ArrayContentDetectorTest.php @@ -2,6 +2,9 @@ namespace Flow\ETL\Tests\Unit\PHP\Type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_null; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\ArrayContentDetector; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; @@ -11,8 +14,6 @@ use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; use Flow\ETL\PHP\Type\Native\ArrayType; -use Flow\ETL\PHP\Type\Native\NullType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\PHP\Type\Types; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -23,30 +24,30 @@ public static function provide_list_data() : \Generator { yield 'simple list' => [ [ - ScalarType::integer(), + type_int(), ], [ - ScalarType::string(), + type_string(), ], true, ]; yield 'simple map' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), ], false, ]; yield 'simple structure' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), new MapType(MapKey::string(), MapValue::string()), new ListType(ListElement::integer()), ], @@ -55,12 +56,12 @@ public static function provide_list_data() : \Generator yield 'list of unique same structures' => [ [ - ScalarType::integer(), + type_int(), ], [ new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + new StructureElement('id', type_int()), + new StructureElement('name', type_string()) ), ], true, @@ -68,7 +69,7 @@ public static function provide_list_data() : \Generator yield 'map with string key, of maps string with string' => [ [ - ScalarType::string(), + type_string(), ], [ new MapType( @@ -83,12 +84,12 @@ public static function provide_list_data() : \Generator yield 'array of nulls' => [ [ - ScalarType::string(), + type_string(), ], [ - new NullType(), - new NullType(), - new NullType(), + type_null(), + type_null(), + type_null(), ], false, ]; @@ -98,30 +99,30 @@ public static function provide_map_data() : \Generator { yield 'simple list' => [ [ - ScalarType::integer(), + type_int(), ], [ - ScalarType::string(), + type_string(), ], false, ]; yield 'simple map' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), ], true, ]; yield 'simple structure' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), new MapType(MapKey::string(), MapValue::string()), new ListType(ListElement::integer()), ], @@ -130,12 +131,12 @@ public static function provide_map_data() : \Generator yield 'list of unique same structures' => [ [ - ScalarType::integer(), + type_int(), ], [ new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + new StructureElement('id', type_int()), + new StructureElement('name', type_string()) ), ], false, @@ -143,7 +144,7 @@ public static function provide_map_data() : \Generator yield 'map with string key, of maps string with string' => [ [ - ScalarType::string(), + type_string(), ], [ new MapType( @@ -158,12 +159,12 @@ public static function provide_map_data() : \Generator yield 'array of nulls' => [ [ - ScalarType::string(), + type_string(), ], [ - new NullType(), - new NullType(), - new NullType(), + type_null(), + type_null(), + type_null(), ], false, ]; @@ -173,30 +174,30 @@ public static function provide_structure_data() : \Generator { yield 'simple list' => [ [ - ScalarType::integer(), + type_int(), ], [ - ScalarType::string(), + type_string(), ], false, ]; yield 'simple map' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), ], false, ]; yield 'simple structure' => [ [ - ScalarType::string(), + type_string(), ], [ - ScalarType::string(), + type_string(), new MapType(MapKey::string(), MapValue::string()), new ListType(ListElement::integer()), ], @@ -205,12 +206,12 @@ public static function provide_structure_data() : \Generator yield 'list of unique same structures' => [ [ - ScalarType::integer(), + type_int(), ], [ new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + new StructureElement('id', type_int()), + new StructureElement('name', type_string()) ), ], false, @@ -218,7 +219,7 @@ public static function provide_structure_data() : \Generator yield 'map with string key, of maps string with string' => [ [ - ScalarType::string(), + type_string(), ], [ new MapType( @@ -233,19 +234,19 @@ public static function provide_structure_data() : \Generator yield 'array of nulls' => [ [ - ScalarType::string(), + type_string(), ], [ - new NullType(), - new NullType(), - new NullType(), + type_null(), + type_null(), + type_null(), ], false, ]; yield 'array of empty arrays' => [ [ - ScalarType::string(), + type_string(), ], [ ArrayType::empty(), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/StructureTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/StructureTypeTest.php index c4fe06a55..bda36f256 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/StructureTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Logical/StructureTypeTest.php @@ -2,6 +2,10 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Logical; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; @@ -10,7 +14,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class StructureTypeTest extends TestCase @@ -30,12 +33,12 @@ public function test_equals() : void ->isEqual(new StructureType(new StructureElement('map', new MapType(MapKey::string(), MapValue::float())))) ); $this->assertFalse( - (new StructureType(new StructureElement('string', ScalarType::string()), new StructureElement('bool', ScalarType::boolean()))) + (new StructureType(new StructureElement('string', type_string()), new StructureElement('bool', type_boolean()))) ->isEqual(new ListType(ListElement::integer())) ); $this->assertFalse( - (new StructureType(new StructureElement('string', ScalarType::string()), new StructureElement('bool', ScalarType::boolean()))) - ->isEqual(new StructureType(new StructureElement('bool', ScalarType::boolean()), new StructureElement('integer', ScalarType::string()))) + (new StructureType(new StructureElement('string', type_string()), new StructureElement('bool', type_boolean()))) + ->isEqual(new StructureType(new StructureElement('bool', type_boolean()), new StructureElement('integer', type_string()))) ); } @@ -44,7 +47,7 @@ public function test_structure_element_name_cannot_be_empty() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Structure element name cannot be empty'); - new StructureElement('', ScalarType::string()); + new StructureElement('', type_string()); } public function test_structure_elements_must_have_unique_names() : void @@ -53,16 +56,16 @@ public function test_structure_elements_must_have_unique_names() : void $this->expectExceptionMessage('All structure element names must be unique'); (new StructureType( - new StructureElement('test', ScalarType::string()), - new StructureElement('test', ScalarType::string()) + new StructureElement('test', type_string()), + new StructureElement('test', type_string()) )); } public function test_to_string() : void { $struct = new StructureType( - new StructureElement('string', ScalarType::string()), - new StructureElement('float', ScalarType::float()), + new StructureElement('string', type_string()), + new StructureElement('float', type_float()), new StructureElement('map', new MapType(MapKey::string(), MapValue::list(new ListType(ListElement::object(\DateTimeInterface::class))))) ); @@ -75,7 +78,7 @@ public function test_to_string() : void public function test_valid() : void { $this->assertTrue( - (new StructureType(new StructureElement('string', ScalarType::string())))->isValid(['one' => 'two']) + (new StructureType(new StructureElement('string', type_string())))->isValid(['one' => 'two']) ); $this->assertTrue( ( @@ -87,13 +90,13 @@ public function test_valid() : void MapValue::map(new MapType(MapKey::string(), MapValue::list(new ListType(ListElement::integer())))) ) ), - new StructureElement('string', ScalarType::string()), - new StructureElement('float', ScalarType::float()) + new StructureElement('string', type_string()), + new StructureElement('float', type_float()) ) )->isValid(['a' => [0 => ['one' => [1, 2]], 1 => ['two' => [3, 4]]], 'b' => 'c', 'd' => 1.5]) ); $this->assertFalse( - (new StructureType(new StructureElement('int', ScalarType::integer())))->isValid([1, 2]) + (new StructureType(new StructureElement('int', type_int())))->isValid([1, 2]) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ArrayTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ArrayTypeTest.php index 14764d73c..b72411e1b 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ArrayTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ArrayTypeTest.php @@ -2,11 +2,12 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Native; +use function Flow\ETL\DSL\type_array; +use function Flow\ETL\DSL\type_float; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Native\ArrayType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class ArrayTypeTest extends TestCase @@ -14,19 +15,19 @@ final class ArrayTypeTest extends TestCase public function test_equals() : void { $this->assertTrue( - (new ArrayType())->isEqual(new ArrayType) + (type_array())->isEqual(new ArrayType) ); $this->assertTrue( ArrayType::empty()->isEqual(ArrayType::empty()) ); $this->assertFalse( - (new ArrayType())->isEqual(new MapType(MapKey::string(), MapValue::float())) + (type_array())->isEqual(new MapType(MapKey::string(), MapValue::float())) ); $this->assertFalse( - (new ArrayType())->isEqual(ScalarType::float()) + (type_array())->isEqual(type_float()) ); $this->assertFalse( - ArrayType::empty()->isEqual(new ArrayType) + ArrayType::empty()->isEqual(type_array()) ); } @@ -34,7 +35,7 @@ public function test_to_string() : void { $this->assertSame( 'array', - (new ArrayType())->toString() + type_array()->toString() ); $this->assertSame( 'array', @@ -45,25 +46,25 @@ public function test_to_string() : void public function test_valid() : void { $this->assertTrue( - (new ArrayType())->isValid([]) + type_array()->isValid([]) ); $this->assertTrue( - (new ArrayType())->isValid(['one']) + type_array()->isValid(['one']) ); $this->assertTrue( - (new ArrayType())->isValid([1]) + type_array()->isValid([1]) ); $this->assertFalse( - (new ArrayType())->isValid(null) + type_array()->isValid(null) ); $this->assertFalse( - (new ArrayType())->isValid('one') + type_array()->isValid('one') ); $this->assertFalse( - (new ArrayType())->isValid(true) + type_array()->isValid(true) ); $this->assertFalse( - (new ArrayType())->isValid(123) + type_array()->isValid(123) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/CallableTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/CallableTypeTest.php index c3723bfc1..37d73612a 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/CallableTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/CallableTypeTest.php @@ -2,11 +2,11 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Native; +use function Flow\ETL\DSL\type_callable; +use function Flow\ETL\DSL\type_float; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\CallableType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class CallableTypeTest extends TestCase @@ -14,16 +14,16 @@ final class CallableTypeTest extends TestCase public function test_equals() : void { $this->assertTrue( - (new CallableType(false))->isEqual(new CallableType(false)) + type_callable(false)->isEqual(type_callable(false)) ); $this->assertFalse( - (new CallableType(false))->isEqual(new MapType(MapKey::string(), MapValue::float())) + type_callable(false)->isEqual(new MapType(MapKey::string(), MapValue::float())) ); $this->assertFalse( - (new CallableType(false))->isEqual(ScalarType::float()) + type_callable(false)->isEqual(type_float()) ); $this->assertFalse( - (new CallableType(false))->isEqual(new CallableType(true)) + type_callable(false)->isEqual(type_callable(true)) ); } @@ -31,27 +31,27 @@ public function test_to_string() : void { $this->assertSame( 'callable', - (new CallableType(false))->toString() + type_callable(false)->toString() ); $this->assertSame( '?callable', - (new CallableType(true))->toString() + type_callable(true)->toString() ); } public function test_valid() : void { $this->assertTrue( - (new CallableType(false))->isValid('printf') + type_callable(false)->isValid('printf') ); $this->assertFalse( - (new CallableType(false))->isValid('one') + type_callable(false)->isValid('one') ); $this->assertFalse( - (new CallableType(false))->isValid([1, 2]) + type_callable(false)->isValid([1, 2]) ); $this->assertFalse( - (new CallableType(false))->isValid(123) + type_callable(false)->isValid(123) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/NullTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/NullTypeTest.php index 5c62ec921..9688b955d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/NullTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/NullTypeTest.php @@ -2,11 +2,11 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Native; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_null; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\NullType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class NullTypeTest extends TestCase @@ -14,13 +14,13 @@ final class NullTypeTest extends TestCase public function test_equals() : void { $this->assertTrue( - (new NullType)->isEqual(new NullType) + type_null()->isEqual(type_null()) ); $this->assertFalse( - (new NullType)->isEqual(new MapType(MapKey::string(), MapValue::float())) + type_null()->isEqual(new MapType(MapKey::string(), MapValue::float())) ); $this->assertFalse( - (new NullType)->isEqual(ScalarType::float()) + type_null()->isEqual(type_float()) ); } @@ -28,23 +28,23 @@ public function test_to_string() : void { $this->assertSame( 'null', - (new NullType)->toString() + type_null()->toString() ); } public function test_valid() : void { $this->assertTrue( - (new NullType)->isValid(null) + type_null()->isValid(null) ); $this->assertFalse( - (new NullType)->isValid('one') + type_null()->isValid('one') ); $this->assertFalse( - (new NullType)->isValid([1, 2]) + type_null()->isValid([1, 2]) ); $this->assertFalse( - (new NullType)->isValid(123) + type_null()->isValid(123) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ResourceTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ResourceTypeTest.php index f84ea3614..dbd4d6489 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ResourceTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ResourceTypeTest.php @@ -2,11 +2,11 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Native; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_resource; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\ResourceType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class ResourceTypeTest extends TestCase @@ -14,16 +14,16 @@ final class ResourceTypeTest extends TestCase public function test_equals() : void { $this->assertTrue( - (new ResourceType(false))->isEqual(new ResourceType(false)) + (type_resource(false))->isEqual(type_resource(false)) ); $this->assertFalse( - (new ResourceType(false))->isEqual(new MapType(MapKey::string(), MapValue::float())) + (type_resource(false))->isEqual(new MapType(MapKey::string(), MapValue::float())) ); $this->assertFalse( - (new ResourceType(false))->isEqual(ScalarType::float()) + (type_resource(false))->isEqual(type_float()) ); $this->assertFalse( - (new ResourceType(false))->isEqual(new ResourceType(true)) + (type_resource(false))->isEqual(type_resource()) ); } @@ -31,11 +31,11 @@ public function test_to_string() : void { $this->assertSame( 'resource', - (new ResourceType(false))->toString() + (type_resource(false))->toString() ); $this->assertSame( '?resource', - (new ResourceType(true))->toString() + (type_resource())->toString() ); } @@ -43,17 +43,17 @@ public function test_valid() : void { $handle = \fopen('php://temp/max', 'r+b'); $this->assertTrue( - (new ResourceType(false))->isValid($handle) + (type_resource(false))->isValid($handle) ); \fclose($handle); $this->assertFalse( - (new ResourceType(false))->isValid('one') + (type_resource(false))->isValid('one') ); $this->assertFalse( - (new ResourceType(false))->isValid([1, 2]) + (type_resource(false))->isValid([1, 2]) ); $this->assertFalse( - (new ResourceType(false))->isValid(123) + (type_resource(false))->isValid(123) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ScalarTypeTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ScalarTypeTest.php index 015b61d65..37e2f0282 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ScalarTypeTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/Native/ScalarTypeTest.php @@ -2,10 +2,13 @@ namespace Flow\ETL\Tests\Unit\PHP\Type\Native; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Native\ScalarType; use PHPUnit\Framework\TestCase; final class ScalarTypeTest extends TestCase @@ -13,23 +16,23 @@ final class ScalarTypeTest extends TestCase public function test_equals() : void { $this->assertTrue( - ScalarType::integer()->isEqual(ScalarType::integer()) + type_int()->isEqual(type_int()) ); $this->assertFalse( - ScalarType::integer()->isEqual(new MapType(MapKey::string(), MapValue::float())) + type_int()->isEqual(new MapType(MapKey::string(), MapValue::float())) ); $this->assertFalse( - ScalarType::integer()->isEqual(ScalarType::float()) + type_int()->isEqual(type_float()) ); } public function test_nullable() : void { $this->assertFalse( - ScalarType::string()->nullable() + type_string(false)->nullable() ); $this->assertTrue( - ScalarType::boolean(true)->nullable() + type_boolean(true)->nullable() ); } @@ -37,36 +40,36 @@ public function test_to_string() : void { $this->assertSame( 'boolean', - ScalarType::boolean()->toString() + type_boolean()->toString() ); $this->assertSame( '?string', - ScalarType::string(true)->toString() + type_string(true)->toString() ); } public function test_valid() : void { $this->assertTrue( - ScalarType::boolean()->isValid(true) + type_boolean()->isValid(true) ); $this->assertTrue( - ScalarType::string()->isValid('one') + type_string()->isValid('one') ); $this->assertTrue( - ScalarType::integer()->isValid(1) + type_int()->isValid(1) ); $this->assertTrue( - ScalarType::integer(true)->isValid(null) + type_int(true)->isValid(null) ); $this->assertFalse( - ScalarType::integer()->isValid('one') + type_int()->isValid('one') ); $this->assertFalse( - ScalarType::string()->isValid([1, 2]) + type_string()->isValid([1, 2]) ); $this->assertFalse( - ScalarType::boolean()->isValid(123) + type_boolean()->isValid(123) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Partition/ScalarFunctionFilterTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Partition/ScalarFunctionFilterTest.php new file mode 100644 index 000000000..bc8e3dd7b --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Partition/ScalarFunctionFilterTest.php @@ -0,0 +1,68 @@ +greaterThan(lit(10)), + new NativeEntryFactory() + ); + + $this->assertTrue($filter->keep(new Partition('foo', '100'))); + $this->assertFalse($filter->keep(new Partition('foo', '5'))); + } + + public function test_filtering_when_partition_is_not_covered_by_any_filter() : void + { + $filter = new ScalarFunctionFilter( + ref('foo')->greaterThan(lit(10)), + new NativeEntryFactory() + ); + + $this->assertFalse($filter->keep(new Partition('bar', '100'))); + } + + public function test_filtering_with_multiple_partitions_and_condition() : void + { + $filter = new ScalarFunctionFilter( + all( + ref('foo')->greaterThanEqual(lit(100)), + ref('bar')->greaterThanEqual(lit(100)) + ), + new NativeEntryFactory() + ); + + $this->assertTrue($filter->keep(new Partition('foo', '100'), new Partition('bar', '100'))); + $this->assertFalse($filter->keep(new Partition('foo', '100'), new Partition('bar', '5'))); + $this->assertFalse($filter->keep(new Partition('foo', '5'), new Partition('bar', '100'))); + $this->assertFalse($filter->keep(new Partition('foo', '5'), new Partition('bar', '5'))); + } + + public function test_filtering_with_multiple_partitions_or_condition() : void + { + $filter = new ScalarFunctionFilter( + any( + ref('foo')->greaterThanEqual(lit(100)), + ref('bar')->greaterThanEqual(lit(100)) + ), + new NativeEntryFactory() + ); + + $this->assertTrue($filter->keep(new Partition('foo', '100'), new Partition('bar', '100'))); + $this->assertTrue($filter->keep(new Partition('foo', '100'), new Partition('bar', '5'))); + $this->assertTrue($filter->keep(new Partition('foo', '5'), new Partition('bar', '100'))); + $this->assertFalse($filter->keep(new Partition('foo', '5'), new Partition('bar', '5'))); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/NestedPipelineTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/NestedPipelineTest.php index 543ab9902..639197530 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/NestedPipelineTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/NestedPipelineTest.php @@ -4,9 +4,10 @@ namespace Flow\ETL\Tests\Unit\Pipeline; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Extractor\ProcessExtractor; use Flow\ETL\FlowContext; use Flow\ETL\Pipeline\NestedPipeline; @@ -28,18 +29,18 @@ public function test_nested_pipelines() : void $pipeline->setSource(new ProcessExtractor( new Rows( - Row::create(Entry::integer('id', 1)), - Row::create(Entry::integer('id', 2)) + Row::create(int_entry('id', 1)), + Row::create(int_entry('id', 2)) ) )); $this->assertEquals( [ new Rows( - Row::create(Entry::integer('id', 1), Entry::boolean('active', true)), + Row::create(int_entry('id', 1), bool_entry('active', true)), ), new Rows( - Row::create(Entry::integer('id', 2), Entry::boolean('active', true)) + Row::create(int_entry('id', 2), bool_entry('active', true)) ), ], \iterator_to_array($pipeline->process(new FlowContext(Config::default()))) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/PipesTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/PipesTest.php index 2dcafbcfe..704bcbbfe 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/PipesTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Pipeline/PipesTest.php @@ -5,8 +5,9 @@ namespace Flow\ETL\Tests\Unit\Pipeline; use function Flow\ETL\DSL\lit; +use function Flow\ETL\DSL\to_memory; +use function Flow\ETL\DSL\to_output; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; -use Flow\ETL\DSL\To; use Flow\ETL\Memory\ArrayMemory; use Flow\ETL\Pipeline\Pipes; use Flow\ETL\Transformer\DropDuplicatesTransformer; @@ -18,8 +19,8 @@ public function test_getting_only_loaders_from_pipes() : void { $pipes = new Pipes([ new ScalarFunctionTransformer('string', lit('test')), - $outputLoader = To::output(), - $memoryLoader = To::memory(new ArrayMemory()), + $outputLoader = to_output(), + $memoryLoader = to_memory(new ArrayMemory()), ]); $this->assertEquals( @@ -32,8 +33,8 @@ public function test_has_transformer() : void { $pipes = new Pipes([ new ScalarFunctionTransformer('string', lit('test')), - $outputLoader = To::output(), - $memoryLoader = To::memory(new ArrayMemory()), + $outputLoader = to_output(), + $memoryLoader = to_memory(new ArrayMemory()), ]); $this->assertTrue($pipes->has(ScalarFunctionTransformer::class)); @@ -44,8 +45,8 @@ public function test_has_transformer_when_passed_class_does_not_exists() : void { $pipes = new Pipes([ new ScalarFunctionTransformer('string', lit('test')), - $outputLoader = To::output(), - $memoryLoader = To::memory(new ArrayMemory()), + $outputLoader = to_output(), + $memoryLoader = to_memory(new ArrayMemory()), ]); $this->assertFalse($pipes->has('SomeClassThatDoesNotExist')); @@ -55,8 +56,8 @@ public function test_has_transformer_when_passed_class_is_not_a_transformer_clas { $pipes = new Pipes([ new ScalarFunctionTransformer('string', lit('test')), - $outputLoader = To::output(), - $memoryLoader = To::memory(new ArrayMemory()), + $outputLoader = to_output(), + $memoryLoader = to_memory(new ArrayMemory()), ]); $this->assertFalse($pipes->has(Pipes::class)); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntriesTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntriesTest.php index 288cb9fe1..0156996e6 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntriesTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntriesTest.php @@ -4,12 +4,14 @@ namespace Flow\ETL\Tests\Unit\Row; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entries; use Flow\ETL\Row\Entry\BooleanEntry; use Flow\ETL\Row\Entry\DateTimeEntry; @@ -148,8 +150,8 @@ public function test_create_from_non_unique_entries() : void public function test_get_all_entries() : void { $entries = new Entries( - Entry::integer('id', 1), - Entry::integer('name', 1), + int_entry('id', 1), + int_entry('name', 1), ); $this->assertCount( @@ -162,8 +164,8 @@ public function test_get_all_entries_when_at_least_one_is_missing() : void { $this->expectException(InvalidArgumentException::class); $entries = new Entries( - Entry::integer('id', 1), - Entry::integer('name', 1), + int_entry('id', 1), + int_entry('name', 1), ); $entries->getAll('id', 'name', 'status'); @@ -172,8 +174,8 @@ public function test_get_all_entries_when_at_least_one_is_missing() : void public function test_has_when_at_least_one_is_missing() : void { $entries = new Entries( - Entry::integer('id', 1), - Entry::integer('name', 1), + int_entry('id', 1), + int_entry('name', 1), ); $this->assertFalse($entries->has('id', 'name', 'status')); @@ -182,9 +184,9 @@ public function test_has_when_at_least_one_is_missing() : void public function test_has_when_none_of_many_is_missing() : void { $entries = new Entries( - Entry::integer('id', 1), - Entry::integer('name', 1), - Entry::boolean('active', true) + int_entry('id', 1), + int_entry('name', 1), + bool_entry('active', true) ); $this->assertTrue($entries->has('id', 'name')); @@ -373,7 +375,7 @@ public function test_sorts_entries_by_name() : void $items = new StructureEntry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + new StructureType(new StructureElement('id', type_int()), new StructureElement('name', type_string())) ) ); @@ -387,7 +389,7 @@ public function test_sorts_entries_by_name() : void $items = new StructureEntry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + new StructureType(new StructureElement('id', type_int()), new StructureElement('name', type_string())) ), $phase = new NullEntry('phase') ), @@ -405,7 +407,7 @@ public function test_transforms_collection_to_array() : void new StructureEntry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + new StructureType(new StructureElement('id', type_int()), new StructureElement('name', type_string())) ), new EnumEntry('enum', BasicEnum::three) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php index e7edcf65d..6fc8b1f3b 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/ListEntryTest.php @@ -4,7 +4,12 @@ namespace Flow\ETL\Tests\Unit\Row\Entry; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\type_boolean; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; @@ -19,7 +24,7 @@ public function test_create_with_empty_name() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Entry name cannot be empty'); - Entry::list_of_string('', ['one', 'two', 'three']); + list_entry('', ['one', 'two', 'three'], type_list(type_string())); } public function test_creating_boolean_list_from_wrong_value_types() : void @@ -27,7 +32,7 @@ public function test_creating_boolean_list_from_wrong_value_types() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected list got different types: array'); - new ListEntry('list', ['string', false], new ListType(ListElement::boolean())); + list_entry('list', ['string', false], type_list(type_boolean())); } public function test_creating_datetime_list_from_wrong_value_types() : void @@ -74,39 +79,39 @@ public function test_definition() : void { $this->assertEquals( Definition::list('strings', new ListType(ListElement::string())), - Entry::list_of_string('strings', ['one', 'two', 'three'])->definition() + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->definition() ); } public function test_is_equal() : void { $this->assertTrue( - Entry::list_of_string('strings', ['one', 'two', 'three']) - ->isEqual(Entry::list_of_string('strings', ['one', 'two', 'three'])) + list_entry('strings', ['one', 'two', 'three'], type_list(type_string())) + ->isEqual(list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))) ); $this->assertFalse( - Entry::list_of_string('strings', ['one', 'two', 'three']) - ->isEqual(Entry::list_of_int('strings', [1, 2, 3])) + list_entry('strings', ['one', 'two', 'three'], type_list(type_string())) + ->isEqual(list_entry('strings', [1, 2, 3], type_list(type_int()))) ); $this->assertTrue( - Entry::list_of_string('strings', ['two', 'one', 'three']) - ->isEqual(Entry::list_of_string('strings', ['one', 'two', 'three'])) + list_entry('strings', ['two', 'one', 'three'], type_list(type_string())) + ->isEqual(list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))) ); } public function test_map() : void { $this->assertEquals( - Entry::list_of_string('strings', ['one, two, three']), - Entry::list_of_string('strings', ['one', 'two', 'three'])->map(fn (array $value) => [\implode(', ', $value)]) + list_entry('strings', ['one, two, three'], type_list(type_string())), + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->map(fn (array $value) => [\implode(', ', $value)]) ); } public function test_rename() : void { $this->assertEquals( - Entry::list_of_string('new_name', ['one', 'two', 'three']), - Entry::list_of_string('strings', ['one', 'two', 'three'])->rename('new_name') + list_entry('new_name', ['one', 'two', 'three'], type_list(type_string())), + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->rename('new_name') ); } @@ -114,7 +119,7 @@ public function test_to_string() : void { $this->assertEquals( '["one","two","three"]', - Entry::list_of_string('strings', ['one', 'two', 'three'])->toString() + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->toString() ); } @@ -122,7 +127,7 @@ public function test_to_string_date_time() : void { $this->assertEquals( '[{"date":"2021-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}]', - Entry::list_of_datetime('strings', [new \DateTimeImmutable('2021-01-01 00:00:00')])->toString() + list_entry('strings', [new \DateTimeImmutable('2021-01-01 00:00:00')], type_list(type_object(\DateTimeImmutable::class)))->toString() ); } @@ -130,7 +135,7 @@ public function test_type() : void { $this->assertEquals( new ListType(ListElement::string()), - Entry::list_of_string('strings', ['one', 'two', 'three'])->type() + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->type() ); } @@ -138,7 +143,7 @@ public function test_value() : void { $this->assertEquals( ['one', 'two', 'three'], - Entry::list_of_string('strings', ['one', 'two', 'three'])->value() + list_entry('strings', ['one', 'two', 'three'], type_list(type_string()))->value() ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/StructureEntryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/StructureEntryTest.php index 1b73ed2d1..ac25fc7cb 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/StructureEntryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/StructureEntryTest.php @@ -4,15 +4,16 @@ namespace Flow\ETL\Tests\Unit\Row\Entry; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_array; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\Map\MapKey; use Flow\ETL\PHP\Type\Logical\Map\MapValue; use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ArrayType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry\StructureEntry; use Flow\ETL\Row\Schema\Definition; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['1' => 1, '2' => 2, '3' => 3], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::integer()), new StructureElement('3', ScalarType::integer())) + struct_type(struct_element('1', type_int()), struct_element('2', type_int()), struct_element('3', type_int())) ), new StructureEntry( 'name', ['1' => 1, '2' => 2, '3' => 3], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::integer()), new StructureElement('3', ScalarType::integer())) + struct_type(struct_element('1', type_int()), struct_element('2', type_int()), struct_element('3', type_int())) ), ]; yield 'equal names and equal simple same integer entries with different number of entries' => [ @@ -39,12 +40,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['1' => 1, '2' => 2, '3' => 3], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::string()), new StructureElement('3', ScalarType::string())) + struct_type(struct_element('1', type_int()), struct_element('2', type_string()), struct_element('3', type_string())) ), new StructureEntry( 'name', ['1' => 1, '2' => 2], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::string())) + struct_type(struct_element('1', type_int()), struct_element('2', type_string())) ), ]; yield 'equal names and equal simple same integer entries with different number of entries reversed' => [ @@ -52,12 +53,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['1' => 1, '2' => 2], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::string())) + struct_type(struct_element('1', type_int()), struct_element('2', type_string())) ), new StructureEntry( 'name', ['1' => 1, '2' => 2, '3' => 3], - new StructureType(new StructureElement('1', ScalarType::integer()), new StructureElement('2', ScalarType::string()), new StructureElement('3', ScalarType::string())) + struct_type(struct_element('1', type_int()), struct_element('2', type_string()), struct_element('3', type_string())) ), ]; yield 'equal names and equal simple same array entries' => [ @@ -65,12 +66,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['json' => ['foo' => ['bar' => 'baz']]], - new StructureType(new StructureElement('json', new MapType(MapKey::string(), MapValue::map(new MapType(MapKey::string(), MapValue::string()))))) + struct_type(struct_element('json', new MapType(MapKey::string(), MapValue::map(new MapType(MapKey::string(), MapValue::string()))))) ), new StructureEntry( 'name', ['json' => ['foo' => ['bar' => 'baz']]], - new StructureType(new StructureElement('json', new MapType(MapKey::string(), MapValue::map(new MapType(MapKey::string(), MapValue::string()))))) + struct_type(struct_element('json', new MapType(MapKey::string(), MapValue::map(new MapType(MapKey::string(), MapValue::string()))))) ), ]; yield 'equal names and equal simple same collection entries' => [ @@ -78,12 +79,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['json' => ['1' => 1, '2' => 2, '3' => 3]], - new StructureType(new StructureElement('json', new ArrayType())) + struct_type(struct_element('json', type_array())) ), new StructureEntry( 'name', ['json' => ['1' => 1, '2' => 2, '3' => 3]], - new StructureType(new StructureElement('json', new ArrayType())) + struct_type(struct_element('json', type_array())) ), ]; yield 'equal names and equal simple different collection entries' => [ @@ -91,25 +92,12 @@ public static function is_equal_data_provider() : \Generator new StructureEntry( 'name', ['json' => ['5' => 5, '2' => 2, '1' => 1]], - new StructureType(new StructureElement('json', new ArrayType())) + struct_type(struct_element('json', type_array())) ), new StructureEntry( 'name', ['json' => ['1' => 1, '2' => 2, '3' => 3]], - new StructureType(new StructureElement('json', new ArrayType())) - ), - ]; - yield 'equal names and nullable entries' => [ - false, - new StructureEntry( - 'name', - ['a' => 'a', 'b' => 'b', 'c' => 'c'], - new StructureType(new StructureElement('a', ScalarType::string()), new StructureElement('b', ScalarType::string(true)), new StructureElement('c', ScalarType::string())) - ), - new StructureEntry( - 'name', - ['a' => 'a', 'b' => null, 'c' => 'c'], - new StructureType(new StructureElement('a', ScalarType::string()), new StructureElement('b', ScalarType::string(true)), new StructureElement('c', ScalarType::string())) + struct_type(struct_element('json', type_array())) ), ]; } @@ -122,13 +110,13 @@ public function test_creating_string_structure_from_wrong_value_types() : void new StructureEntry( 'test', [1, 2, 3], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + struct_type(struct_element('id', type_int()), struct_element('name', type_string())) ); } public function test_definition() : void { - $entry = Entry::structure( + $entry = struct_entry( 'items', [ 'id' => 1, @@ -138,14 +126,14 @@ public function test_definition() : void 'city' => 'bar', ], ], - new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()), - new StructureElement( + struct_type( + struct_element('id', type_int()), + struct_element('name', type_string()), + struct_element( 'address', - new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), + struct_type( + struct_element('street', type_string()), + struct_element('city', type_string()), ) ), ), @@ -154,14 +142,14 @@ public function test_definition() : void $this->assertEquals( Definition::structure( 'items', - new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()), - new StructureElement( + struct_type( + struct_element('id', type_int()), + struct_element('name', type_string()), + struct_element( 'address', - new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), + struct_type( + struct_element('street', type_string()), + struct_element('city', type_string()), ) ) ), @@ -178,7 +166,7 @@ public function test_entry_name_can_be_zero() : void new StructureEntry( '0', ['id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + struct_type(struct_element('id', type_int()), struct_element('name', type_string())) ) )->name() ); @@ -197,7 +185,7 @@ public function test_map() : void $entry = new StructureEntry( 'entry-name', ['id' => 1234], - new StructureType(new StructureElement('id', ScalarType::integer())) + struct_type(struct_element('id', type_int())) ); $this->assertEquals( @@ -214,7 +202,7 @@ public function test_prevents_from_creating_entry_with_empty_entry_name() : void new StructureEntry( '', ['id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + struct_type(struct_element('id', type_int()), struct_element('name', type_string())) ); } @@ -223,7 +211,7 @@ public function test_renames_entry() : void $entry = new StructureEntry( 'entry-name', ['id' => 1234], - new StructureType(new StructureElement('id', ScalarType::integer())) + struct_type(struct_element('id', type_int())) ); $newEntry = $entry->rename('new-entry-name'); @@ -236,7 +224,7 @@ public function test_returns_array_as_value() : void $entry = new StructureEntry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + struct_type(struct_element('id', type_int()), struct_element('name', type_string())) ); $this->assertEquals( @@ -253,7 +241,7 @@ public function test_serialization() : void $string = new StructureEntry( 'name', ['json' => ['5' => 5, '2' => 2, '3' => 3]], - new StructureType(new StructureElement('json', new ArrayType())) + struct_type(struct_element('json', type_array())) ); $serialized = \serialize($string); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/XMLEntryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/XMLEntryTest.php index fe1cb3885..2cf93c49e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/XMLEntryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/XMLEntryTest.php @@ -4,7 +4,7 @@ namespace Flow\ETL\Tests\Unit\Row\Entry; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\xml_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row\Entry\XMLEntry; use PHPUnit\Framework\TestCase; @@ -95,8 +95,8 @@ public function test_canonicalization() : void XML); $this->assertNotEquals( - Entry::xml('row', $doc), - Entry::xml('row', $doc2), + xml_entry('row', $doc), + xml_entry('row', $doc2), ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntryReferenceTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntryReferenceTest.php index 7b442d830..d857ff10e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntryReferenceTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntryReferenceTest.php @@ -4,8 +4,8 @@ namespace Flow\ETL\Tests\Unit\Row; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; use Flow\ETL\Row; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ public function test_executing_equals_expression() : void $ref = ref('a')->equals(ref('b')); $this->assertTrue( - $ref->eval(Row::create(Entry::integer('a', 1), Entry::integer('b', 1))) + $ref->eval(Row::create(int_entry('a', 1), int_entry('b', 1))) ); } @@ -26,7 +26,7 @@ public function test_executing_expression() : void $this->assertSame( 100, - $ref->eval(Row::create(Entry::integer('a', 1))) + $ref->eval(Row::create(int_entry('a', 1))) ); } @@ -35,11 +35,11 @@ public function test_is_even() : void $ref = ref('a')->isEven(); $this->assertFalse( - $ref->eval(Row::create(Entry::integer('a', 1))) + $ref->eval(Row::create(int_entry('a', 1))) ); $this->assertTrue( - $ref->eval(Row::create(Entry::integer('a', 2))) + $ref->eval(Row::create(int_entry('a', 2))) ); } @@ -48,11 +48,11 @@ public function test_is_odd() : void $ref = ref('a')->isOdd(); $this->assertTrue( - $ref->eval(Row::create(Entry::integer('a', 1))) + $ref->eval(Row::create(int_entry('a', 1))) ); $this->assertFalse( - $ref->eval(Row::create(Entry::integer('a', 2))) + $ref->eval(Row::create(int_entry('a', 2))) ); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php index 145cbe43e..859ea48c0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Factory/NativeEntryFactoryTest.php @@ -4,20 +4,37 @@ namespace Flow\ETL\Tests\Unit\Row\Factory; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\enum_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\json_entry; +use function Flow\ETL\DSL\json_object_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; +use function Flow\ETL\DSL\uuid_entry; +use function Flow\ETL\DSL\xml_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry\StructureEntry; use Flow\ETL\Row\Factory\NativeEntryFactory; use Flow\ETL\Row\Schema; use Flow\ETL\Tests\Fixtures\Enum\BackedIntEnum; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use Ramsey\Uuid\Uuid; final class NativeEntryFactoryTest extends TestCase { @@ -54,7 +71,7 @@ public function test_array_structure() : void new StructureEntry( 'e', ['a' => 1, 'b' => '2'], - new StructureType(new StructureElement('a', ScalarType::integer()), new StructureElement('b', ScalarType::string())) + new StructureType(new StructureElement('a', type_int()), new StructureElement('b', type_string())) ), (new NativeEntryFactory())->create('e', ['a' => 1, 'b' => '2']) ); @@ -63,7 +80,7 @@ public function test_array_structure() : void public function test_array_with_schema() : void { $this->assertEquals( - Entry::array('e', [1, 2, 3]), + array_entry('e', [1, 2, 3]), (new NativeEntryFactory()) ->create('e', [1, 2, 3], new Schema(Schema\Definition::array('e'))) ); @@ -72,7 +89,7 @@ public function test_array_with_schema() : void public function test_bool() : void { $this->assertEquals( - Entry::boolean('e', false), + bool_entry('e', false), (new NativeEntryFactory())->create('e', false) ); } @@ -80,7 +97,7 @@ public function test_bool() : void public function test_boolean_with_schema() : void { $this->assertEquals( - Entry::boolean('e', false), + bool_entry('e', false), (new NativeEntryFactory())->create('e', false, new Schema(Schema\Definition::boolean('e'))) ); } @@ -88,7 +105,7 @@ public function test_boolean_with_schema() : void public function test_conversion_to_different_type_with_schema() : void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("Field \"e\" conversion exception. Flow\ETL\DSL\Entry::string(): Argument #2 (\$value) must be of type string, int given"); + $this->expectExceptionMessage("Field \"e\" conversion exception. Flow\ETL\DSL\string_entry(): Argument #2 (\$value) must be of type string, int given, called in"); (new NativeEntryFactory()) ->create('e', 1, new Schema(Schema\Definition::string('e'))); @@ -97,7 +114,7 @@ public function test_conversion_to_different_type_with_schema() : void public function test_datetime() : void { $this->assertEquals( - Entry::datetime('e', $now = new \DateTimeImmutable()), + datetime_entry('e', $now = new \DateTimeImmutable()), (new NativeEntryFactory())->create('e', $now) ); } @@ -105,7 +122,7 @@ public function test_datetime() : void public function test_datetime_string_with_schema() : void { $this->assertEquals( - Entry::datetime('e', '2022-01-01 00:00:00 UTC'), + datetime_entry('e', '2022-01-01 00:00:00 UTC'), (new NativeEntryFactory()) ->create('e', '2022-01-01 00:00:00 UTC', new Schema(Schema\Definition::dateTime('e'))) ); @@ -114,7 +131,7 @@ public function test_datetime_string_with_schema() : void public function test_datetime_with_schema() : void { $this->assertEquals( - Entry::datetime('e', $datetime = new \DateTimeImmutable('now')), + datetime_entry('e', $datetime = new \DateTimeImmutable('now')), (new NativeEntryFactory()) ->create('e', $datetime, new Schema(Schema\Definition::dateTime('e'))) ); @@ -123,7 +140,7 @@ public function test_datetime_with_schema() : void public function test_enum() : void { $this->assertEquals( - Entry::enum('e', $enum = BackedIntEnum::one), + enum_entry('e', $enum = BackedIntEnum::one), (new NativeEntryFactory()) ->create('e', $enum) ); @@ -132,7 +149,7 @@ public function test_enum() : void public function test_enum_from_string_with_schema() : void { $this->assertEquals( - Entry::enum('e', BackedIntEnum::one), + enum_entry('e', BackedIntEnum::one), (new NativeEntryFactory()) ->create('e', 'one', new Schema(Schema\Definition::enum('e', BackedIntEnum::class))) ); @@ -150,7 +167,7 @@ public function test_enum_invalid_value_with_schema() : void public function test_float() : void { $this->assertEquals( - Entry::float('e', 1.1), + float_entry('e', 1.1), (new NativeEntryFactory())->create('e', 1.1) ); } @@ -158,7 +175,7 @@ public function test_float() : void public function test_float_with_schema() : void { $this->assertEquals( - Entry::float('e', 1.1), + float_entry('e', 1.1), (new NativeEntryFactory())->create('e', 1.1, new Schema(Schema\Definition::float('e'))) ); } @@ -166,7 +183,7 @@ public function test_float_with_schema() : void public function test_from_empty_string() : void { $this->assertEquals( - Entry::string('e', ''), + str_entry('e', ''), (new NativeEntryFactory())->create('e', '') ); } @@ -174,7 +191,7 @@ public function test_from_empty_string() : void public function test_int() : void { $this->assertEquals( - Entry::integer('e', 1), + int_entry('e', 1), (new NativeEntryFactory())->create('e', 1) ); } @@ -182,7 +199,7 @@ public function test_int() : void public function test_integer_with_schema() : void { $this->assertEquals( - Entry::integer('e', 1), + int_entry('e', 1), (new NativeEntryFactory())->create('e', 1, new Schema(Schema\Definition::integer('e'))) ); } @@ -190,7 +207,7 @@ public function test_integer_with_schema() : void public function test_json() : void { $this->assertEquals( - Entry::json_object('e', ['id' => 1]), + json_object_entry('e', ['id' => 1]), (new NativeEntryFactory())->create('e', '{"id":1}') ); } @@ -198,7 +215,7 @@ public function test_json() : void public function test_json_object_array_with_schema() : void { $this->assertEquals( - Entry::json_object('e', ['id' => 1]), + json_object_entry('e', ['id' => 1]), (new NativeEntryFactory())->create('e', ['id' => 1], new Schema(Schema\Definition::json('e'))) ); } @@ -206,7 +223,7 @@ public function test_json_object_array_with_schema() : void public function test_json_string() : void { $this->assertEquals( - Entry::json('e', '{"id": 1}'), + json_entry('e', '{"id": 1}'), (new NativeEntryFactory())->create('e', '{"id": 1}') ); } @@ -214,7 +231,7 @@ public function test_json_string() : void public function test_json_string_with_schema() : void { $this->assertEquals( - Entry::json('e', '{"id": 1}'), + json_entry('e', '{"id": 1}'), (new NativeEntryFactory())->create('e', '{"id": 1}', new Schema(Schema\Definition::json('e'))) ); } @@ -222,7 +239,7 @@ public function test_json_string_with_schema() : void public function test_json_with_schema() : void { $this->assertEquals( - Entry::json('e', [['id' => 1]]), + json_entry('e', [['id' => 1]]), (new NativeEntryFactory())->create('e', [['id' => 1]], new Schema(Schema\Definition::json('e'))) ); } @@ -230,7 +247,7 @@ public function test_json_with_schema() : void public function test_list_int_with_schema() : void { $this->assertEquals( - Entry::list_of_int('e', [1, 2, 3]), + list_entry('e', [1, 2, 3], type_list(type_int())), (new NativeEntryFactory())->create('e', [1, 2, 3], new Schema(Schema\Definition::list('e', new ListType(ListElement::integer())))) ); } @@ -246,7 +263,7 @@ public function test_list_int_with_schema_but_string_list() : void public function test_list_of_datetime_with_schema() : void { $this->assertEquals( - Entry::list_of_datetime('e', $list = [new \DateTimeImmutable('now'), new \DateTimeImmutable('tomorrow')]), + list_entry('e', $list = [new \DateTimeImmutable('now'), new \DateTimeImmutable('tomorrow')], type_list(type_object(\DateTimeImmutable::class))), (new NativeEntryFactory()) ->create('e', $list, new Schema(Schema\Definition::list('e', new ListType(ListElement::object(\DateTimeImmutable::class))))) ); @@ -255,7 +272,7 @@ public function test_list_of_datetime_with_schema() : void public function test_list_of_datetimes() : void { $this->assertEquals( - Entry::list_of_objects('e', \DateTimeImmutable::class, $list = [new \DateTimeImmutable(), new \DateTimeImmutable()]), + list_entry('e', $list = [new \DateTimeImmutable(), new \DateTimeImmutable()], type_list(type_object(\DateTimeImmutable::class))), (new NativeEntryFactory())->create('e', $list) ); } @@ -263,7 +280,7 @@ public function test_list_of_datetimes() : void public function test_list_of_scalars() : void { $this->assertEquals( - Entry::list_of_int('e', [1, 2]), + list_entry('e', [1, 2], type_list(type_int())), (new NativeEntryFactory())->create('e', [1, 2]) ); } @@ -271,7 +288,7 @@ public function test_list_of_scalars() : void public function test_list_of_string_datetime_with_schema() : void { $this->assertEquals( - Entry::list_of_datetime('e', [new \DateTimeImmutable('2022-01-01 00:00:00 UTC'), new \DateTimeImmutable('2022-01-01 00:00:00 UTC')]), + list_entry('e', [new \DateTimeImmutable('2022-01-01 00:00:00 UTC'), new \DateTimeImmutable('2022-01-01 00:00:00 UTC')], type_list(type_object(\DateTimeImmutable::class))), (new NativeEntryFactory()) ->create( 'e', @@ -296,16 +313,16 @@ public function test_nested_structure() : void 'zip' => '31-021', ], new StructureType( - new StructureElement('city', ScalarType::string()), + new StructureElement('city', type_string()), new StructureElement( 'geo', new StructureType( - new StructureElement('lat', ScalarType::float()), - new StructureElement('lon', ScalarType::float()) + new StructureElement('lat', type_float()), + new StructureElement('lon', type_float()) ), ), - new StructureElement('street', ScalarType::string()), - new StructureElement('zip', ScalarType::string()), + new StructureElement('street', type_string()), + new StructureElement('zip', type_string()), ), ), (new NativeEntryFactory())->create('address', [ @@ -323,7 +340,7 @@ public function test_nested_structure() : void public function test_null() : void { $this->assertEquals( - Entry::null('e'), + null_entry('e'), (new NativeEntryFactory())->create('e', null) ); } @@ -331,12 +348,12 @@ public function test_null() : void public function test_null_with_schema() : void { $this->assertEquals( - Entry::null('e'), + null_entry('e'), (new NativeEntryFactory())->create('e', null, new Schema(Schema\Definition::null('e'))) ); $this->assertEquals( - Entry::null('e'), + null_entry('e'), (new NativeEntryFactory())->create('e', null, new Schema(Schema\Definition::string('e', true))) ); } @@ -344,7 +361,7 @@ public function test_null_with_schema() : void public function test_object() : void { $this->assertEquals( - Entry::object('e', $object = new \ArrayIterator([1, 2])), + object_entry('e', $object = new \ArrayIterator([1, 2])), (new NativeEntryFactory())->create('e', $object) ); } @@ -352,16 +369,16 @@ public function test_object() : void public function test_object_with_schema() : void { $this->assertEquals( - Entry::object('e', $object = new \ArrayObject([1, 2, 3])), + object_entry('e', $object = new \ArrayObject([1, 2, 3])), (new NativeEntryFactory()) - ->create('e', $object, new Schema(Schema\Definition::object('e', ObjectType::fromObject($object)))) + ->create('e', $object, new Schema(Schema\Definition::object('e', type_object($object::class)))) ); } public function test_string() : void { $this->assertEquals( - Entry::string('e', 'test'), + str_entry('e', 'test'), (new NativeEntryFactory())->create('e', 'test') ); } @@ -369,7 +386,7 @@ public function test_string() : void public function test_string_with_schema() : void { $this->assertEquals( - Entry::string('e', 'string'), + str_entry('e', 'string'), (new NativeEntryFactory())->create('e', 'string', new Schema(Schema\Definition::string('e'))) ); } @@ -381,10 +398,10 @@ public function test_structure() : void 'address', ['id' => 1, 'city' => 'Krakow', 'street' => 'Floriańska', 'zip' => '31-021'], new StructureType( - new StructureElement('id', ScalarType::integer()), - new StructureElement('city', ScalarType::string()), - new StructureElement('street', ScalarType::string()), - new StructureElement('zip', ScalarType::string()) + new StructureElement('id', type_int()), + new StructureElement('city', type_string()), + new StructureElement('street', type_string()), + new StructureElement('zip', type_string()) ) ), (new NativeEntryFactory())->create('address', ['id' => 1, 'city' => 'Krakow', 'street' => 'Floriańska', 'zip' => '31-021']) @@ -395,19 +412,19 @@ public function test_structure() : void public function test_unrecognized_data_set_same_as_provided(string $input) : void { $this->assertEquals( - Entry::string('e', $input), + str_entry('e', $input), (new NativeEntryFactory())->create('e', $input) ); } public function test_uuid_from_ramsey_uuid_library() : void { - if (!\class_exists(\Ramsey\Uuid\Uuid::class)) { + if (!\class_exists(Uuid::class)) { $this->markTestSkipped("Package 'ramsey/uuid' is required for this test."); } $this->assertEquals( - Entry::uuid('e', $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString()), + uuid_entry('e', $uuid = Uuid::uuid4()->toString()), (new NativeEntryFactory())->create('e', $uuid) ); } @@ -415,7 +432,7 @@ public function test_uuid_from_ramsey_uuid_library() : void public function test_uuid_from_string() : void { $this->assertEquals( - Entry::uuid('e', $uuid = '00000000-0000-0000-0000-000000000000'), + uuid_entry('e', $uuid = '00000000-0000-0000-0000-000000000000'), (new NativeEntryFactory())->create('e', $uuid) ); } @@ -423,7 +440,7 @@ public function test_uuid_from_string() : void public function test_uuid_string_with_uuid_definition_provided() : void { $this->assertEquals( - Entry::uuid('e', $uuid = '00000000-0000-0000-0000-000000000000'), + uuid_entry('e', $uuid = '00000000-0000-0000-0000-000000000000'), (new NativeEntryFactory())->create('e', $uuid, new Schema(Schema\Definition::uuid('e'))) ); } @@ -451,7 +468,7 @@ public function test_xml_from_dom_document() : void $doc = new \DOMDocument(); $doc->loadXML($xml = '123'); $this->assertEquals( - Entry::xml('e', $xml), + xml_entry('e', $xml), (new NativeEntryFactory())->create('e', $doc) ); } @@ -459,7 +476,7 @@ public function test_xml_from_dom_document() : void public function test_xml_from_string() : void { $this->assertEquals( - Entry::xml('e', $xml = '123'), + xml_entry('e', $xml = '123'), (new NativeEntryFactory())->create('e', $xml) ); } @@ -467,7 +484,7 @@ public function test_xml_from_string() : void public function test_xml_string_with_xml_definition_provided() : void { $this->assertEquals( - Entry::xml('e', $xml = '123'), + xml_entry('e', $xml = '123'), (new NativeEntryFactory())->create('e', $xml, new Schema(Schema\Definition::xml('e'))) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php index 1022a3376..aa14f5e9b 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php @@ -4,13 +4,25 @@ namespace Flow\ETL\Tests\Unit\Row\Schema\Constraint; -use Flow\ETL\DSL\Entry; -use Flow\ETL\PHP\Type\Logical\Map\MapKey; -use Flow\ETL\PHP\Type\Logical\Map\MapValue; -use Flow\ETL\PHP\Type\Logical\MapType; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\json_entry; +use function Flow\ETL\DSL\json_object_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\map_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_map; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Row\Schema\Constraint\NotEmpty; use PHPUnit\Framework\TestCase; @@ -20,29 +32,29 @@ public function test_not_empty_is_not_satisfied() : void { $constraint = new NotEmpty(); - $this->assertFalse($constraint->isSatisfiedBy(Entry::array('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(Entry::json('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(Entry::json_object('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(Entry::list_of_int('e', []))); + $this->assertFalse($constraint->isSatisfiedBy(array_entry('e', []))); + $this->assertFalse($constraint->isSatisfiedBy(json_entry('e', []))); + $this->assertFalse($constraint->isSatisfiedBy(json_object_entry('e', []))); + $this->assertFalse($constraint->isSatisfiedBy(list_entry('e', [], type_list(type_int())))); } public function test_not_empty_is_satisfied() : void { $constraint = new NotEmpty(); - $this->assertTrue($constraint->isSatisfiedBy(Entry::array('e', [1]))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::boolean('e', false))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::datetime('e', new \DateTimeImmutable()))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::object('e', ScalarType::integer()))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::float('e', 1.1))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::integer('e', 1))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::json('e', [1, 2]))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::list_of_int('e', [1, 2]))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::null('e'))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::object('e', new \SplFixedArray(2)))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::string('e', 'e'))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::list_of_int('list', [1, 2, 3]))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::map('map', ['NEW', 'PENDING'], new MapType(MapKey::integer(), MapValue::string())))); - $this->assertTrue($constraint->isSatisfiedBy(Entry::structure('e', ['id' => 1], new StructureType(new StructureElement('id', ScalarType::integer()))))); + $this->assertTrue($constraint->isSatisfiedBy(array_entry('e', [1]))); + $this->assertTrue($constraint->isSatisfiedBy(bool_entry('e', false))); + $this->assertTrue($constraint->isSatisfiedBy(datetime_entry('e', new \DateTimeImmutable()))); + $this->assertTrue($constraint->isSatisfiedBy(object_entry('e', type_int()))); + $this->assertTrue($constraint->isSatisfiedBy(float_entry('e', 1.1))); + $this->assertTrue($constraint->isSatisfiedBy(int_entry('e', 1))); + $this->assertTrue($constraint->isSatisfiedBy(json_entry('e', [1, 2]))); + $this->assertTrue($constraint->isSatisfiedBy(list_entry('e', [1, 2], type_list(type_int())))); + $this->assertTrue($constraint->isSatisfiedBy(null_entry('e'))); + $this->assertTrue($constraint->isSatisfiedBy(object_entry('e', new \SplFixedArray(2)))); + $this->assertTrue($constraint->isSatisfiedBy(str_entry('e', 'e'))); + $this->assertTrue($constraint->isSatisfiedBy(list_entry('list', [1, 2, 3], type_list(type_int())))); + $this->assertTrue($constraint->isSatisfiedBy(map_entry('map', ['NEW', 'PENDING'], type_map(type_int(), type_string())))); + $this->assertTrue($constraint->isSatisfiedBy(struct_entry('e', ['id' => 1], struct_type(struct_element('id', type_int()))))); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php index 3320b49a1..32a828f89 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php @@ -4,13 +4,19 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_float; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry\IntegerEntry; use Flow\ETL\Row\Entry\ListEntry; use Flow\ETL\Row\Entry\NullEntry; @@ -85,21 +91,21 @@ public function test_matches_when_constraint_satisfied_and_everything_else_match $def = Definition::integer('test', false, $constraint); - $this->assertTrue($def->matches(Entry::integer('test', 1))); + $this->assertTrue($def->matches(int_entry('test', 1))); } public function test_matches_when_nullable_and_name_matches() : void { $def = Definition::integer('test', $nullable = true); - $this->assertTrue($def->matches(Entry::null('test'))); + $this->assertTrue($def->matches(null_entry('test'))); } public function test_matches_when_type_and_name_match() : void { $def = Definition::integer('test'); - $this->assertTrue($def->matches(Entry::integer('test', 1))); + $this->assertTrue($def->matches(int_entry('test', 1))); } public function test_merge_definitions_with_both_side_constraints() : void @@ -178,28 +184,28 @@ public function test_not_matches_when_constraint_not_satisfied() : void $def = Definition::integer('test', false, $constraint); - $this->assertFalse($def->matches(Entry::integer('test', 1))); + $this->assertFalse($def->matches(int_entry('test', 1))); } public function test_not_matches_when_not_nullable_name_matches_but_null_given() : void { $def = Definition::integer('test', $nullable = false); - $this->assertFalse($def->matches(Entry::null('test'))); + $this->assertFalse($def->matches(null_entry('test'))); } public function test_not_matches_when_type_does_not_match() : void { $def = Definition::integer('test'); - $this->assertFalse($def->matches(Entry::string('test', 'test'))); + $this->assertFalse($def->matches(str_entry('test', 'test'))); } public function test_not_matches_when_type_name_not_match() : void { $def = Definition::integer('test'); - $this->assertFalse($def->matches(Entry::integer('not-test', 1))); + $this->assertFalse($def->matches(int_entry('not-test', 1))); } public function test_nullable_is_not_union() : void @@ -209,21 +215,21 @@ public function test_nullable_is_not_union() : void public function test_structure_definition_metadata() : void { - $address = Entry::structure( + $address = struct_entry( 'address', [ 'street' => 'street', 'city' => 'city', 'location' => ['lat' => 1.0, 'lng' => 1.0], ], - new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), - new StructureElement( + struct_type( + struct_element('street', type_string()), + struct_element('city', type_string()), + struct_element( 'location', - new StructureType( - new StructureElement('lat', ScalarType::float()), - new StructureElement('lng', ScalarType::float()), + struct_type( + struct_element('lat', type_float()), + struct_element('lng', type_float()), ) ) ), @@ -231,13 +237,13 @@ public function test_structure_definition_metadata() : void $this->assertEquals( new StructureType( - new StructureElement('street', ScalarType::string()), - new StructureElement('city', ScalarType::string()), - new StructureElement( + struct_element('street', type_string()), + struct_element('city', type_string()), + struct_element( 'location', new StructureType( - new StructureElement('lat', ScalarType::float()), - new StructureElement('lng', ScalarType::float()), + struct_element('lat', type_float()), + struct_element('lng', type_float()), ) ) ), @@ -249,10 +255,10 @@ public function test_union_type_definition() : void { $def = Definition::union('test', [IntegerEntry::class, StringEntry::class]); - $this->assertFalse($def->matches(Entry::integer('not-test', 1))); - $this->assertTrue($def->matches(Entry::integer('test', 1))); - $this->assertTrue($def->matches(Entry::string('test', 'test'))); - $this->assertFalse($def->matches(Entry::boolean('test', false))); + $this->assertFalse($def->matches(int_entry('not-test', 1))); + $this->assertTrue($def->matches(int_entry('test', 1))); + $this->assertTrue($def->matches(str_entry('test', 'test'))); + $this->assertFalse($def->matches(bool_entry('test', false))); } public function test_union_type_from_non_unique_types() : void diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Formatter/ASCIISchemaFormatterTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Formatter/ASCIISchemaFormatterTest.php index feb7913f9..6d300eff0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Formatter/ASCIISchemaFormatterTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Formatter/ASCIISchemaFormatterTest.php @@ -4,6 +4,8 @@ namespace Flow\ETL\Tests\Unit\Row\Schema\Formatter; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\Map\MapKey; @@ -11,7 +13,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Entry\FloatEntry; use Flow\ETL\Row\Entry\IntegerEntry; use Flow\ETL\Row\Schema; @@ -27,14 +28,14 @@ public function test_format_nested_schema() : void Schema\Definition::structure( 'user', new StructureType( - new StructureElement('name', ScalarType::string(true)), - new StructureElement('age', ScalarType::integer()), + new StructureElement('name', type_string(true)), + new StructureElement('age', type_int()), new StructureElement( 'address', new StructureType( - new StructureElement('street', ScalarType::string(true)), - new StructureElement('city', ScalarType::string(true)), - new StructureElement('country', ScalarType::string(true)), + new StructureElement('street', type_string(true)), + new StructureElement('city', type_string(true)), + new StructureElement('country', type_string(true)), ) ) ), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php index a0e8568b4..4624ad005 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row\Schema\Metadata; use PHPUnit\Framework\TestCase; @@ -44,8 +45,8 @@ public function test_merge_metadata_with_the_same_keys() : void public function test_merge_object_metadata() : void { $this->assertEquals( - Metadata::empty()->add('type', ScalarType::integer()), - Metadata::empty()->add('type', ScalarType::string())->merge(Metadata::empty()->add('type', ScalarType::integer())) + Metadata::empty()->add('type', type_int()), + Metadata::empty()->add('type', type_string())->merge(Metadata::empty()->add('type', type_int())) ); } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/SelectiveValidatorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/SelectiveValidatorTest.php index 70c135cc0..2634f34a0 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/SelectiveValidatorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/SelectiveValidatorTest.php @@ -4,7 +4,9 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use Flow\ETL\Row\Schema; use Flow\ETL\Row\Schema\SelectiveValidator; @@ -22,7 +24,7 @@ public function test_rows_with_a_missing_entry() : void $this->assertFalse( (new SelectiveValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), bool_entry('active', true))), $schema ) ); @@ -37,7 +39,7 @@ public function test_rows_with_an_extra_entry() : void $this->assertTrue( (new SelectiveValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -53,7 +55,7 @@ public function test_rows_with_single_invalid_entry() : void $this->assertFalse( (new SelectiveValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -69,8 +71,8 @@ public function test_rows_with_single_invalid_row() : void $this->assertFalse( (new SelectiveValidator())->isValid( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 1), Entry::boolean('active', true)) + Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true)), + Row::create(int_entry('id', 1), bool_entry('active', true)) ), $schema ) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/StrictValidatorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/StrictValidatorTest.php index fd57f4875..803f7eaeb 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/StrictValidatorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/StrictValidatorTest.php @@ -4,7 +4,9 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Row; use Flow\ETL\Row\Schema; use Flow\ETL\Row\Schema\StrictValidator; @@ -22,7 +24,7 @@ public function test_rows_with_a_missing_entry() : void $this->assertFalse( (new StrictValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -38,7 +40,7 @@ public function test_rows_with_all_entries_valid() : void $this->assertTrue( (new StrictValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -55,7 +57,7 @@ public function test_rows_with_an_extra_entry() : void $this->assertFalse( (new StrictValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -71,7 +73,7 @@ public function test_rows_with_single_invalid_entry() : void $this->assertFalse( (new StrictValidator())->isValid( - new Rows(Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true))), + new Rows(Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true))), $schema ) ); @@ -88,8 +90,8 @@ public function test_rows_with_single_invalid_row() : void $this->assertFalse( (new StrictValidator())->isValid( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'test'), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 1), Entry::boolean('active', true)) + Row::create(int_entry('id', 1), str_entry('name', 'test'), bool_entry('active', true)), + Row::create(int_entry('id', 1), bool_entry('active', true)) ), $schema ) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php index 5a4bcbb7f..41338a750 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php @@ -4,7 +4,24 @@ namespace Flow\ETL\Tests\Unit; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\map_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_map; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\type_string; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\Map\MapKey; @@ -12,8 +29,6 @@ use Flow\ETL\PHP\Type\Logical\MapType; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ObjectType; -use Flow\ETL\PHP\Type\Native\ScalarType; use Flow\ETL\Row; use Flow\ETL\Row\Entries; use Flow\ETL\Row\Entry\ArrayEntry; @@ -96,33 +111,33 @@ public static function is_equal_data_provider() : \Generator public function test_getting_schema_from_row() : void { $row = Row::create( - Entry::integer('id', \random_int(100, 100000)), - Entry::float('price', \random_int(100, 100000) / 100), - Entry::boolean('deleted', false), - Entry::datetime('created-at', new \DateTimeImmutable('now')), - Entry::null('phase'), - Entry::array( + int_entry('id', \random_int(100, 100000)), + float_entry('price', \random_int(100, 100000) / 100), + bool_entry('deleted', false), + datetime_entry('created-at', new \DateTimeImmutable('now')), + null_entry('phase'), + array_entry( 'array', [ ['id' => 1, 'status' => 'NEW'], ['id' => 2, 'status' => 'PENDING'], ] ), - Entry::structure( + struct_entry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType( - new StructureElement('item-id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + struct_type( + struct_element('item-id', type_int()), + struct_element('name', type_string()) ) ), - Entry::list_of_int('list', [1, 2, 3]), - Entry::map( + list_entry('list', [1, 2, 3], type_list(type_int())), + map_entry( 'statuses', ['NEW', 'PENDING'], - new MapType(MapKey::integer(), MapValue::string()) + type_map(type_int(), type_string()) ), - Entry::object('object', new \ArrayIterator([1, 2, 3])) + object_entry('object', new \ArrayIterator([1, 2, 3])) ); $this->assertEquals( @@ -136,8 +151,8 @@ public function test_getting_schema_from_row() : void Row\Schema\Definition::structure( 'items', new StructureType( - new StructureElement('item-id', ScalarType::integer()), - new StructureElement('name', ScalarType::string()) + new StructureElement('item-id', type_int()), + new StructureElement('name', type_string()) ) ), Row\Schema\Definition::map( @@ -145,7 +160,7 @@ public function test_getting_schema_from_row() : void new MapType(MapKey::integer(), MapValue::string()) ), Row\Schema\Definition::list('list', new ListType(ListElement::integer())), - Row\Schema\Definition::object('object', ObjectType::of(\ArrayIterator::class)), + Row\Schema\Definition::object('object', type_object(\ArrayIterator::class)), ), $row->schema() ); @@ -162,15 +177,15 @@ public function test_is_equal(bool $equals, Row $row, Row $nextRow) : void public function test_keep() : void { $row = new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test'), - Entry::boolean('active', true) + int_entry('id', 1), + str_entry('name', 'test'), + bool_entry('active', true) )); $this->assertEquals( new Row(new Entries( - Entry::int('id', 1), - Entry::boolean('active', true) + int_entry('id', 1), + bool_entry('active', true) )), $row->keep('id', 'active') ); @@ -181,9 +196,9 @@ public function test_keep_non_existing_entry() : void $this->expectExceptionMessage('Entry "something" does not exist.'); $row = new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test'), - Entry::boolean('active', true) + int_entry('id', 1), + str_entry('name', 'test'), + bool_entry('active', true) )); $this->assertEquals( @@ -195,15 +210,15 @@ public function test_keep_non_existing_entry() : void public function test_remove() : void { $row = new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test'), - Entry::boolean('active', true) + int_entry('id', 1), + str_entry('name', 'test'), + bool_entry('active', true) )); $this->assertEquals( new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test') + int_entry('id', 1), + str_entry('name', 'test') )), $row->remove('active') ); @@ -212,16 +227,16 @@ public function test_remove() : void public function test_remove_non_existing_entry() : void { $row = new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test'), - Entry::boolean('active', true) + int_entry('id', 1), + str_entry('name', 'test'), + bool_entry('active', true) )); $this->assertEquals( new Row(new Entries( - Entry::int('id', 1), - Entry::string('name', 'test'), - Entry::boolean('active', true) + int_entry('id', 1), + str_entry('name', 'test'), + bool_entry('active', true) )), $row->remove('something') ); @@ -254,7 +269,7 @@ public function test_transforms_row_to_array() : void new StructureEntry( 'items', ['item-id' => 1, 'name' => 'one'], - new StructureType(new StructureElement('id', ScalarType::integer()), new StructureElement('name', ScalarType::string())) + new StructureType(new StructureElement('id', type_int()), new StructureElement('name', type_string())) ), new Row\Entry\MapEntry( 'statuses', diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsJoinTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsJoinTest.php index dc084ed29..b8c23d0c7 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsJoinTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsJoinTest.php @@ -4,7 +4,10 @@ namespace Flow\ETL\Tests\Unit; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Join\Expression; use Flow\ETL\Row; @@ -16,29 +19,29 @@ final class RowsJoinTest extends TestCase public function test_cross_join() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinCross( new Rows( - Row::create(Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('num', 2), Entry::boolean('active', false)), + Row::create(int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('num', 2), bool_entry('active', false)), ), ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::integer('num', 2), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR'), Entry::integer('num', 1), Entry::boolean('active', true)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR'), Entry::integer('num', 2), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 3), str_entry('country', 'US'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 3), str_entry('country', 'US'), int_entry('num', 2), bool_entry('active', false)), + Row::create(int_entry('id', 4), str_entry('country', 'FR'), int_entry('num', 1), bool_entry('active', true)), + Row::create(int_entry('id', 4), str_entry('country', 'FR'), int_entry('num', 2), bool_entry('active', false)), ), $joined, ); @@ -47,10 +50,10 @@ public function test_cross_join() : void public function test_cross_join_empty() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinCross( @@ -59,10 +62,10 @@ public function test_cross_join_empty() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ), $joined ); @@ -74,19 +77,19 @@ public function test_cross_join_left_empty() : void $joined = $left->joinCross( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ), ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ), $joined ); @@ -97,15 +100,15 @@ public function test_cross_join_left_with_name_conflict() : void $this->expectExceptionMessage('Merged entries names must be unique, given: [id, country, active] + [active]. Please consider using join prefix option'); $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), bool_entry('active', false)), + Row::create(int_entry('id', 3), str_entry('country', 'US'), bool_entry('active', false)), + Row::create(int_entry('id', 4), str_entry('country', 'FR'), bool_entry('active', false)), ); $joined = $left->joinCross( new Rows( - Row::create(Entry::boolean('active', true)) + Row::create(bool_entry('active', true)) ), ); } @@ -113,25 +116,25 @@ public function test_cross_join_left_with_name_conflict() : void public function test_cross_join_left_with_name_conflict_with_prefix() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::boolean('active', false)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR'), Entry::boolean('active', false)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), bool_entry('active', false)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), bool_entry('active', false)), + Row::create(int_entry('id', 3), str_entry('country', 'US'), bool_entry('active', false)), + Row::create(int_entry('id', 4), str_entry('country', 'FR'), bool_entry('active', false)), ); $joined = $left->joinCross( new Rows( - Row::create(Entry::boolean('active', true)) + Row::create(bool_entry('active', true)) ), '_' ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::boolean('active', false), Entry::boolean('_active', true)), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::boolean('active', false), Entry::boolean('_active', true)), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::boolean('active', false), Entry::boolean('_active', true)), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR'), Entry::boolean('active', false), Entry::boolean('_active', true)), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), bool_entry('active', false), bool_entry('_active', true)), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), bool_entry('active', false), bool_entry('_active', true)), + Row::create(int_entry('id', 3), str_entry('country', 'US'), bool_entry('active', false), bool_entry('_active', true)), + Row::create(int_entry('id', 4), str_entry('country', 'FR'), bool_entry('active', false), bool_entry('_active', true)), ), $joined ); @@ -140,10 +143,10 @@ public function test_cross_join_left_with_name_conflict_with_prefix() : void public function test_inner_empty() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinInner( @@ -160,26 +163,26 @@ public function test_inner_empty() : void public function test_inner_join() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinInner( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US'), Entry::string('name', 'United States')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 2), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 3), str_entry('country', 'US'), str_entry('name', 'United States')), ), $joined ); @@ -191,9 +194,9 @@ public function test_inner_join_into_empty() : void $joined = $left->joinInner( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); @@ -210,17 +213,17 @@ public function test_inner_join_with_duplicated_entries() : void $this->expectExceptionMessage('Merged entries names must be unique, given: [id, country] + [id, code, name]. Please consider using Condition, join prefix option'); $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $left->joinInner( new Rows( - Row::create(Entry::integer('id', 101), Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 102), Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 103), Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(int_entry('id', 101), str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 102), str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 103), str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); @@ -229,22 +232,22 @@ public function test_inner_join_with_duplicated_entries() : void public function test_left_anti_join() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $joined = $left->joinLeftAnti( new Rows( - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'FR'), Entry::string('name', 'France')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'FR'), str_entry('name', 'France')), ), Expression::on(['country' => 'code']) ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), ), $joined ); @@ -253,9 +256,9 @@ public function test_left_anti_join() : void public function test_left_anti_join_on_empty() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $joined = $left->joinLeftAnti( @@ -272,25 +275,25 @@ public function test_left_anti_join_on_empty() : void public function test_left_join() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $joined = $left->joinLeft( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR'), Entry::null('name')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 2), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 3), str_entry('country', 'FR'), null_entry('name')), ), $joined ); @@ -299,9 +302,9 @@ public function test_left_join() : void public function test_left_join_empty() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $joined = $left->joinLeft( @@ -311,9 +314,9 @@ public function test_left_join_empty() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ), $joined ); @@ -325,9 +328,9 @@ public function test_left_join_to_empty() : void $joined = $left->joinLeft( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); @@ -344,16 +347,16 @@ public function test_left_join_with_the_duplicated_columns() : void $this->expectExceptionMessage('Merged entries names must be unique, given: [id, country] + [id, code, name]. Please consider using Condition, join prefix option'); $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $left->joinLeft( new Rows( - Row::create(Entry::integer('id', 100), Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 101), Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 102), Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(int_entry('id', 100), str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 101), str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 102), str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); @@ -362,27 +365,27 @@ public function test_left_join_with_the_duplicated_columns() : void public function test_right_join() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinRight( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); $this->assertEquals( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland'), Entry::integer('id', 1)), - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland'), Entry::integer('id', 2)), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States'), Entry::integer('id', 3)), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain'), Entry::null('id')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland'), int_entry('id', 1)), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland'), int_entry('id', 2)), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States'), int_entry('id', 3)), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain'), null_entry('id')), ), $joined ); @@ -391,10 +394,10 @@ public function test_right_join() : void public function test_right_join_empty() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $joined = $left->joinRight( @@ -414,18 +417,18 @@ public function test_right_join_to_empty() : void $joined = $left->joinRight( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); $this->assertEquals( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), $joined ); @@ -437,17 +440,17 @@ public function test_right_join_with_duplicated_entry_names() : void $this->expectExceptionMessage('Merged entries names must be unique, given: [id, code, name] + [id, country]. Please consider using Condition, join prefix option'); $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 4), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'PL')), + Row::create(int_entry('id', 3), str_entry('country', 'US')), + Row::create(int_entry('id', 4), str_entry('country', 'FR')), ); $left->joinRight( new Rows( - Row::create(Entry::integer('id', 101), Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 102), Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 103), Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(int_entry('id', 101), str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 102), str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 103), str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ), Expression::on(['country' => 'code']) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php index 02acef4b1..171ce4a21 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowsTest.php @@ -4,8 +4,16 @@ namespace Flow\ETL\Tests\Unit; +use function Flow\ETL\DSL\array_entry; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\list_entry; +use function Flow\ETL\DSL\null_entry; use function Flow\ETL\DSL\ref; -use Flow\ETL\DSL\Entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Exception\RuntimeException; use Flow\ETL\Partition; @@ -175,14 +183,14 @@ public function test_building_rows_from_array() : void $this->assertEquals( new Rows( Row::create( - Entry::integer('id', 1234), - Entry::bool('deleted', false), - Entry::null('phase'), + int_entry('id', 1234), + bool_entry('deleted', false), + null_entry('phase'), ), Row::create( - Entry::integer('id', 4321), - Entry::bool('deleted', true), - Entry::string('phase', 'launch'), + int_entry('id', 4321), + bool_entry('deleted', true), + str_entry('phase', 'launch'), ) ), $rows @@ -327,7 +335,7 @@ public function test_drop_right_more_than_exists() : void public function test_empty_rows() : void { $this->assertTrue((new Rows())->empty()); - $this->assertFalse((new Rows(Row::create(Entry::integer('id', 1))))->empty()); + $this->assertFalse((new Rows(Row::create(int_entry('id', 1))))->empty()); } public function test_filters_out_rows() : void @@ -512,8 +520,8 @@ public function test_partition_rows_by_multiple_duplicated_entries() : void [ Rows::partitioned( [ - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), ], [ new Partition('num', '1'), @@ -521,21 +529,21 @@ public function test_partition_rows_by_multiple_duplicated_entries() : void ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 1), Entry::string('cat', 'b'))], + [Row::create(int_entry('num', 1), str_entry('cat', 'b'))], [ new Partition('num', '1'), new Partition('cat', 'b'), ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 3), Entry::string('cat', 'a'))], + [Row::create(int_entry('num', 3), str_entry('cat', 'a'))], [ new Partition('num', '3'), new Partition('cat', 'a'), ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 2), Entry::string('cat', 'b'))], + [Row::create(int_entry('num', 2), str_entry('cat', 'b'))], [ new Partition('num', '2'), new Partition('cat', 'b'), @@ -543,11 +551,11 @@ public function test_partition_rows_by_multiple_duplicated_entries() : void ), ], (new Rows( - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 3), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'b')), - Row::create(Entry::integer('num', 2), Entry::string('cat', 'b')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), + Row::create(int_entry('num', 3), str_entry('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'b')), + Row::create(int_entry('num', 2), str_entry('cat', 'b')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), ))->partitionBy('num', 'num', 'cat') ); } @@ -558,8 +566,8 @@ public function test_partition_rows_by_multiple_entries() : void [ Rows::partitioned( [ - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), ], [ new Partition('num', '1'), @@ -567,21 +575,21 @@ public function test_partition_rows_by_multiple_entries() : void ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 1), Entry::string('cat', 'b'))], + [Row::create(int_entry('num', 1), str_entry('cat', 'b'))], [ new Partition('num', '1'), new Partition('cat', 'b'), ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 3), Entry::string('cat', 'a'))], + [Row::create(int_entry('num', 3), str_entry('cat', 'a'))], [ new Partition('num', '3'), new Partition('cat', 'a'), ] ), Rows::partitioned( - [Row::create(Entry::integer('num', 2), Entry::string('cat', 'b'))], + [Row::create(int_entry('num', 2), str_entry('cat', 'b'))], [ new Partition('num', '2'), new Partition('cat', 'b'), @@ -589,11 +597,11 @@ public function test_partition_rows_by_multiple_entries() : void ), ], (new Rows( - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 3), Entry::string('cat', 'a')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'b')), - Row::create(Entry::integer('num', 2), Entry::string('cat', 'b')), - Row::create(Entry::integer('num', 1), Entry::string('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), + Row::create(int_entry('num', 3), str_entry('cat', 'a')), + Row::create(int_entry('num', 1), str_entry('cat', 'b')), + Row::create(int_entry('num', 2), str_entry('cat', 'b')), + Row::create(int_entry('num', 1), str_entry('cat', 'a')), ))->partitionBy('num', 'cat') ); } @@ -637,10 +645,10 @@ public function test_partition_rows_by_single_entry() : void public function test_partitions() : void { $rows = (new Rows( - Row::create(Entry::integer('number', 1), Entry::string('group', 'a')), - Row::create(Entry::integer('number', 2), Entry::string('group', 'a')), - Row::create(Entry::integer('number', 3), Entry::string('group', 'a')), - Row::create(Entry::integer('number', 4), Entry::string('group', 'a')), + Row::create(int_entry('number', 1), str_entry('group', 'a')), + Row::create(int_entry('number', 2), str_entry('group', 'a')), + Row::create(int_entry('number', 3), str_entry('group', 'a')), + Row::create(int_entry('number', 4), str_entry('group', 'a')), ))->partitionBy('group'); $this->assertEquals( @@ -717,10 +725,10 @@ public function test_rows_diff_right(Rows $expected, Rows $left, Rows $right) : public function test_rows_schema() : void { $rows = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('name', 'foo')), - Row::create(Entry::integer('id', 1), Entry::null('name'), Entry::list_of_int('list', [1, 2])), - Row::create(Entry::integer('id', 1), Entry::string('name', 'bar'), Entry::array('tags', ['a', 'b'])), - Row::create(Entry::integer('id', 1), Entry::integer('name', 25)), + Row::create(int_entry('id', 1), str_entry('name', 'foo')), + Row::create(int_entry('id', 1), null_entry('name'), list_entry('list', [1, 2], type_list(type_int()))), + Row::create(int_entry('id', 1), str_entry('name', 'bar'), array_entry('tags', ['a', 'b'])), + Row::create(int_entry('id', 1), int_entry('name', 25)), ); $this->assertEquals( @@ -737,8 +745,8 @@ public function test_rows_schema() : void public function test_rows_schema_when_rows_have_different_list_types() : void { $rows = new Rows( - Row::create(Entry::list_of_string('list', ['one', 'two'])), - Row::create(Entry::list_of_int('list', [1, 2])), + Row::create(list_entry('list', ['one', 'two'], type_list(type_string()))), + Row::create(list_entry('list', [1, 2], type_list(type_int()))), ); $this->assertEquals( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/CallbackRowTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/CallbackRowTransformerTest.php index 711d3eba9..6610eda63 100755 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/CallbackRowTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/CallbackRowTransformerTest.php @@ -5,11 +5,11 @@ namespace Flow\ETL\Tests\Unit\Transformer; use Flow\ETL\Config; -use Flow\ETL\DSL\Transform; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Row\Entry; use Flow\ETL\Rows; +use Flow\ETL\Transformer\CallbackRowTransformer; use Flow\Serializer\NativePHPSerializer; use PHPUnit\Framework\TestCase; @@ -17,7 +17,7 @@ class CallbackRowTransformerTest extends TestCase { public function test_replacing_dashes_in_entry_name_with_str_replace_callback() : void { - $callbackTransformer = Transform::callback_row( + $callbackTransformer = new CallbackRowTransformer( fn (Row $row) : Row => $row->remove('old-int') ); @@ -40,7 +40,7 @@ public function test_replacing_dashes_in_entry_name_with_str_replace_callback() public function test_replacing_dashes_in_entry_name_with_str_replace_callback_with_serialization() : void { - $callbackTransformer = Transform::callback_row( + $callbackTransformer = new CallbackRowTransformer( fn (Row $row) : Row => $row->remove('old-int') ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/DropDuplicatesTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/DropDuplicatesTransformerTest.php index 31d1b83a8..cdf1c27f5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/DropDuplicatesTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/DropDuplicatesTransformerTest.php @@ -4,8 +4,9 @@ namespace Flow\ETL\Tests\Unit\Transformer; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -28,18 +29,18 @@ public function test_dropping_duplicated_entries_from_rows() : void $transformer = new DropDuplicatesTransformer('id'); $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 3), Entry::str('name', 'name3')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 3), str_entry('name', 'name3')), ); $this->assertEquals( new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 3), Entry::string('name', 'name3')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 3), str_entry('name', 'name3')), ), $transformer->transform($rows, new FlowContext(Config::default())) ); @@ -50,20 +51,20 @@ public function test_dropping_duplicates_when_not_all_rows_has_expected_entry() $transformer = new DropDuplicatesTransformer('id'); $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::str('name', 'name3')), - Row::create(Entry::int('id', 4), Entry::str('name', 'name4')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(str_entry('name', 'name3')), + Row::create(int_entry('id', 4), str_entry('name', 'name4')), ); $this->assertEquals( new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::str('name', 'name3')), - Row::create(Entry::int('id', 4), Entry::str('name', 'name4')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(str_entry('name', 'name3')), + Row::create(int_entry('id', 4), str_entry('name', 'name4')), ), $transformer->transform($rows, new FlowContext(Config::default())) ); @@ -74,18 +75,18 @@ public function test_dropping_duplications_based_on_two_entries() : void $transformer = new DropDuplicatesTransformer('id', 'name'); $rows = new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 3), Entry::str('name', 'name3')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 3), str_entry('name', 'name3')), ); $this->assertEquals( new Rows( - Row::create(Entry::int('id', 1), Entry::str('name', 'name1')), - Row::create(Entry::int('id', 2), Entry::str('name', 'name2')), - Row::create(Entry::int('id', 3), Entry::str('name', 'name3')), + Row::create(int_entry('id', 1), str_entry('name', 'name1')), + Row::create(int_entry('id', 2), str_entry('name', 'name2')), + Row::create(int_entry('id', 3), str_entry('name', 'name3')), ), $transformer->transform($rows, new FlowContext(Config::default())) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/EntryNameStyleConverterTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/EntryNameStyleConverterTransformerTest.php index 81637ab03..c1b123c0f 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/EntryNameStyleConverterTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/EntryNameStyleConverterTransformerTest.php @@ -5,11 +5,10 @@ namespace Flow\ETL\Tests\Unit\Transformer; use Flow\ETL\Config; -use Flow\ETL\DSL\Transform; -use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; +use Flow\ETL\Transformer\EntryNameStyleConverterTransformer; use Flow\ETL\Transformer\StyleConverter\StringStyles; use PHPUnit\Framework\TestCase; @@ -17,7 +16,7 @@ final class EntryNameStyleConverterTransformerTest extends TestCase { public function test_conversion_of_entry_names_style() : void { - $transformer = Transform::convert_name(StringStyles::SNAKE); + $transformer = new EntryNameStyleConverterTransformer(StringStyles::SNAKE); $rows = $transformer->transform(new Rows( Row::create( @@ -36,12 +35,4 @@ public function test_conversion_of_entry_names_style() : void $rows->toArray() ); } - - public function test_using_invalid_style() : void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unrecognized style wrong style, please use one of following:'); - - Transform::convert_name('wrong style'); - } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php index 080c0114a..dc541991d 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php @@ -5,10 +5,10 @@ namespace Flow\ETL\Tests\Unit\Transformer; use Flow\ETL\Config; -use Flow\ETL\DSL\Transform; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; +use Flow\ETL\Transformer\GroupToArrayTransformer; use PHPUnit\Framework\TestCase; final class GroupToArrayTransformerTest extends TestCase @@ -39,7 +39,7 @@ public function test_grouping_entries_to_array() : void ) ); - $transformer = Transform::group_to_array('order_id', 'order_line_items'); + $transformer = new GroupToArrayTransformer('order_id', 'order_line_items'); $this->assertSame( [ diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinEachRowsTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinEachRowsTransformerTest.php index 39af54804..955525159 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinEachRowsTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinEachRowsTransformerTest.php @@ -4,10 +4,12 @@ namespace Flow\ETL\Tests\Unit\Transformer; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; use Flow\ETL\DataFrame; use Flow\ETL\DataFrameFactory; -use Flow\ETL\DSL\Entry; use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\Join\Expression; @@ -21,9 +23,9 @@ final class JoinEachRowsTransformerTest extends TestCase public function test_inner_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = new class implements DataFrameFactory { @@ -31,9 +33,9 @@ public function from(Rows $rows) : DataFrame { return (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); } @@ -52,8 +54,8 @@ public function __unserialize(array $data) : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'Poland'), Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::string('name', 'United States'), Entry::integer('id', 2), Entry::string('country', 'US')), + Row::create(str_entry('name', 'Poland'), int_entry('id', 1), str_entry('country', 'PL')), + Row::create(str_entry('name', 'United States'), int_entry('id', 2), str_entry('country', 'US')), ), $transformer->transform($left, new FlowContext(Config::default())) ); @@ -62,18 +64,18 @@ public function __unserialize(array $data) : void public function test_left_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = new class implements DataFrameFactory { public function from(Rows $rows) : DataFrame { return (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); } @@ -92,9 +94,9 @@ public function __unserialize(array $data) : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR'), Entry::null('name')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 2), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 3), str_entry('country', 'FR'), null_entry('name')), ), $transformer->transform($left, new FlowContext(Config::default())) ); @@ -103,18 +105,18 @@ public function __unserialize(array $data) : void public function test_right_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = new class implements DataFrameFactory { public function from(Rows $rows) : DataFrame { return (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); } @@ -133,9 +135,9 @@ public function __unserialize(array $data) : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'Poland'), Entry::string('code', 'PL'), Entry::integer('id', 1)), - Row::create(Entry::string('name', 'United States'), Entry::string('code', 'US'), Entry::integer('id', 2)), - Row::create(Entry::string('name', 'Great Britain'), Entry::string('code', 'GB'), Entry::null('id')), + Row::create(str_entry('name', 'Poland'), str_entry('code', 'PL'), int_entry('id', 1)), + Row::create(str_entry('name', 'United States'), str_entry('code', 'US'), int_entry('id', 2)), + Row::create(str_entry('name', 'Great Britain'), str_entry('code', 'GB'), null_entry('id')), ), $transformer->transform($left, new FlowContext(Config::default())) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinRowsTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinRowsTransformerTest.php index 6fcc23d73..53d102704 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinRowsTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/JoinRowsTransformerTest.php @@ -4,8 +4,10 @@ namespace Flow\ETL\Tests\Unit\Transformer; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\str_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Flow; use Flow\ETL\FlowContext; use Flow\ETL\Join\Expression; @@ -19,15 +21,15 @@ final class JoinRowsTransformerTest extends TestCase public function test_inner_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); @@ -35,8 +37,8 @@ public function test_inner_join_rows() : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'Poland'), Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::string('name', 'United States'), Entry::integer('id', 2), Entry::string('country', 'US')), + Row::create(str_entry('name', 'Poland'), int_entry('id', 1), str_entry('country', 'PL')), + Row::create(str_entry('name', 'United States'), int_entry('id', 2), str_entry('country', 'US')), ), $transformer->transform($left, new FlowContext(Config::default())) ); @@ -45,15 +47,15 @@ public function test_inner_join_rows() : void public function test_left_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); @@ -61,9 +63,9 @@ public function test_left_join_rows() : void $this->assertEquals( new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR'), Entry::null('name')), + Row::create(int_entry('id', 1), str_entry('country', 'PL'), str_entry('name', 'Poland')), + Row::create(int_entry('id', 2), str_entry('country', 'US'), str_entry('name', 'United States')), + Row::create(int_entry('id', 3), str_entry('country', 'FR'), null_entry('name')), ), $transformer->transform($left, new FlowContext(Config::default())) ); @@ -72,15 +74,15 @@ public function test_left_join_rows() : void public function test_right_join_rows() : void { $left = new Rows( - Row::create(Entry::integer('id', 1), Entry::string('country', 'PL')), - Row::create(Entry::integer('id', 2), Entry::string('country', 'US')), - Row::create(Entry::integer('id', 3), Entry::string('country', 'FR')), + Row::create(int_entry('id', 1), str_entry('country', 'PL')), + Row::create(int_entry('id', 2), str_entry('country', 'US')), + Row::create(int_entry('id', 3), str_entry('country', 'FR')), ); $right = (new Flow())->process( new Rows( - Row::create(Entry::string('code', 'PL'), Entry::string('name', 'Poland')), - Row::create(Entry::string('code', 'US'), Entry::string('name', 'United States')), - Row::create(Entry::string('code', 'GB'), Entry::string('name', 'Great Britain')), + Row::create(str_entry('code', 'PL'), str_entry('name', 'Poland')), + Row::create(str_entry('code', 'US'), str_entry('name', 'United States')), + Row::create(str_entry('code', 'GB'), str_entry('name', 'Great Britain')), ) ); @@ -88,9 +90,9 @@ public function test_right_join_rows() : void $this->assertEquals( new Rows( - Row::create(Entry::string('name', 'Poland'), Entry::string('code', 'PL'), Entry::integer('id', 1)), - Row::create(Entry::string('name', 'United States'), Entry::string('code', 'US'), Entry::integer('id', 2)), - Row::create(Entry::string('name', 'Great Britain'), Entry::string('code', 'GB'), Entry::null('id')), + Row::create(str_entry('name', 'Poland'), str_entry('code', 'PL'), int_entry('id', 1)), + Row::create(str_entry('name', 'United States'), str_entry('code', 'US'), int_entry('id', 2)), + Row::create(str_entry('name', 'Great Britain'), str_entry('code', 'GB'), null_entry('id')), ), $transformer->transform($left, new FlowContext(Config::default())) ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionFilterTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionFilterTransformerTest.php index 622bbc889..d5922a831 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionFilterTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionFilterTransformerTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Unit\Transformer; +use function Flow\ETL\DSL\int_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\FlowContext; use Flow\ETL\Row; use Flow\ETL\Rows; @@ -19,8 +19,8 @@ final class ScalarFunctionFilterTransformerTest extends TestCase public function test_equal() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -36,8 +36,8 @@ public function test_equal() : void public function test_equal_on_literal() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -51,7 +51,7 @@ public function test_equal_on_literal() : void public function test_greater_than() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -65,8 +65,8 @@ public function test_greater_than() : void public function test_greater_than_or_equal() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -81,8 +81,8 @@ public function test_greater_than_or_equal() : void public function test_less_than() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -96,8 +96,8 @@ public function test_less_than() : void public function test_less_than_equal() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -112,8 +112,8 @@ public function test_less_than_equal() : void public function test_not_equal() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -127,8 +127,8 @@ public function test_not_equal() : void public function test_not_same() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( @@ -142,8 +142,8 @@ public function test_not_same() : void public function test_same() : void { $rows = new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 1)), - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 1)), + Row::create(int_entry('a', 1), int_entry('b', 2)) ); $this->assertSame( diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionTransformerTest.php index 742b5177c..2d8e72830 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ScalarFunctionTransformerTest.php @@ -4,10 +4,15 @@ namespace Flow\ETL\Tests\Unit\Transformer; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\list_entry; use function Flow\ETL\DSL\lit; use function Flow\ETL\DSL\ref; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\type_list; +use function Flow\ETL\DSL\type_object; +use function Flow\ETL\DSL\xml_entry; use Flow\ETL\Config; -use Flow\ETL\DSL\Entry; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\FlowContext; use Flow\ETL\Row; @@ -36,7 +41,7 @@ public function test_lit_expression_on_non_empty_rows() : void ], (new ScalarFunctionTransformer('number', lit(1))) ->transform( - new Rows(Row::create(Entry::string('name', 'Norbert'))), + new Rows(Row::create(str_entry('name', 'Norbert'))), new FlowContext(Config::default()) ) ->toArray() @@ -62,7 +67,7 @@ public function test_plus_expression_on_non_empty_rows() : void ], (new ScalarFunctionTransformer('c', ref('a')->plus(ref('b')))) ->transform(new Rows( - Row::create(Entry::integer('a', 1), Entry::integer('b', 2)) + Row::create(int_entry('a', 1), int_entry('b', 2)) ), new FlowContext(Config::default())) ->toArray() ); @@ -79,7 +84,7 @@ public function test_plus_expression_on_non_existing_rows() : void ], (new ScalarFunctionTransformer('number', ref('num')->plus(ref('num1')))) ->transform( - new Rows(Row::create(Entry::integer('a', 1))), + new Rows(Row::create(int_entry('a', 1))), new FlowContext(Config::default()) ) ->toArray() @@ -94,13 +99,13 @@ public function test_xml_xpath_expression_when_there_is_more_than_one_node_under $xpath = new \DOMXPath($document); $this->assertEquals( - Entry::list_of_objects('xpath', \DOMElement::class, [ + list_entry('xpath', [ $xpath->query('/root/foo')->item(0), $xpath->query('/root/foo')->item(1), - ]), + ], type_list(type_object(\DOMElement::class))), (new ScalarFunctionTransformer('xpath', ref('xml')->xpath('/root/foo'))) ->transform( - new Rows(Row::create(Entry::xml('xml', $xml))), + new Rows(Row::create(xml_entry('xml', $xml))), new FlowContext(Config::default()) ) ->first() diff --git a/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php b/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php index 226806261..9cf6d6ec4 100644 --- a/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php +++ b/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php @@ -4,14 +4,21 @@ namespace Flow\Serializer\Tests\Unit; -use Flow\ETL\DSL\Entry; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\Serializer\CompressingSerializer; -use Flow\Serializer\NativePHPSerializer; use PHPUnit\Framework\TestCase; final class CompressingSerializerTest extends TestCase @@ -28,19 +35,19 @@ public function test_serializing_rows() : void $rows = new Rows( ...\array_map( fn () : Row => Row::create( - Entry::integer('integer', 1), - Entry::string('string', 'string'), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable('2022-01-01 00:00:00')), - Entry::null('null'), - Entry::float('float', 0.12), - Entry::object('object', new \ArrayIterator([1, 2, 3])), - Entry::structure( + int_entry('integer', 1), + str_entry('string', 'string'), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable('2022-01-01 00:00:00')), + null_entry('null'), + float_entry('float', 0.12), + object_entry('object', new \ArrayIterator([1, 2, 3])), + struct_entry( 'struct', ['integer' => 1, 'string' => 'string'], - new StructureType( - new StructureElement('integer', ScalarType::integer()), - new StructureElement('string', ScalarType::string()) + struct_type( + struct_element('integer', type_int()), + struct_element('string', type_string()) ) ) ), @@ -48,7 +55,7 @@ public function test_serializing_rows() : void ) ); - $serializer = new CompressingSerializer(new NativePHPSerializer()); + $serializer = new CompressingSerializer(); $serialized = $serializer->serialize($rows); diff --git a/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php b/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php index 1f63bb65a..d0276bc2b 100644 --- a/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php +++ b/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php @@ -4,10 +4,18 @@ namespace Flow\Serializer\Tests\Unit; -use Flow\ETL\DSL\Entry; -use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; -use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\PHP\Type\Native\ScalarType; +use function Flow\ETL\DSL\bool_entry; +use function Flow\ETL\DSL\datetime_entry; +use function Flow\ETL\DSL\float_entry; +use function Flow\ETL\DSL\int_entry; +use function Flow\ETL\DSL\null_entry; +use function Flow\ETL\DSL\object_entry; +use function Flow\ETL\DSL\str_entry; +use function Flow\ETL\DSL\struct_element; +use function Flow\ETL\DSL\struct_entry; +use function Flow\ETL\DSL\struct_type; +use function Flow\ETL\DSL\type_int; +use function Flow\ETL\DSL\type_string; use Flow\ETL\Row; use Flow\ETL\Rows; use Flow\Serializer\NativePHPSerializer; @@ -20,19 +28,19 @@ public function test_serializing_rows() : void $rows = new Rows( ...\array_map( fn () : Row => Row::create( - Entry::integer('integer', 1), - Entry::string('string', 'string'), - Entry::boolean('boolean', true), - Entry::datetime('datetime', new \DateTimeImmutable('2022-01-01 00:00:00')), - Entry::null('null'), - Entry::float('float', 0.12), - Entry::object('object', new \ArrayIterator([1, 2, 3])), - Entry::structure( + int_entry('integer', 1), + str_entry('string', 'string'), + bool_entry('boolean', true), + datetime_entry('datetime', new \DateTimeImmutable('2022-01-01 00:00:00')), + null_entry('null'), + float_entry('float', 0.12), + object_entry('object', new \ArrayIterator([1, 2, 3])), + struct_entry( 'struct', ['integer' => 1, 'string' => 'string'], - new StructureType( - new StructureElement('integer', ScalarType::integer()), - new StructureElement('string', ScalarType::string()) + struct_type( + struct_element('integer', type_int()), + struct_element('string', type_string()) ) ) ), diff --git a/src/lib/parquet-viewer/src/Flow/ParquetViewer/Command/ReadDataCommand.php b/src/lib/parquet-viewer/src/Flow/ParquetViewer/Command/ReadDataCommand.php index beaf58f80..8e16bcf04 100644 --- a/src/lib/parquet-viewer/src/Flow/ParquetViewer/Command/ReadDataCommand.php +++ b/src/lib/parquet-viewer/src/Flow/ParquetViewer/Command/ReadDataCommand.php @@ -1,9 +1,11 @@ -read(Parquet::from($filePath, $columns)) + ->read(from_parquet($filePath, $columns)) ->limit($limit) ->batchSize($batchSize) - ->write(To::output($truncate)) + ->write(to_output($truncate)) ->run(); $output->write(\ob_get_clean() ?: '');