Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions benchmarks/src/Pipeline/OrdersSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Flow\ETL\Schema;

use function Flow\ETL\DSL\date_schema;
use function Flow\ETL\DSL\datetime_schema;
use function Flow\ETL\DSL\float_schema;
use function Flow\ETL\DSL\json_schema;
Expand Down Expand Up @@ -49,6 +50,7 @@ public static function of(Source $source): Schema
json_schema('address', true),
json_schema('notes', true),
json_schema('items', true),
date_schema('ordered_on', true),
),
Source::json, Source::json_lines => schema(
string_schema('order_id', true),
Expand Down Expand Up @@ -79,6 +81,7 @@ public static function of(Source $source): Schema
])),
true,
),
string_schema('ordered_on', true),
),
Source::array, Source::floe, Source::memory, Source::parquet => schema(
uuid_schema('order_id', true),
Expand Down Expand Up @@ -109,6 +112,7 @@ public static function of(Source $source): Schema
])),
true,
),
date_schema('ordered_on', true),
),
};
}
Expand All @@ -132,6 +136,7 @@ public static function ofService(ServiceSource $source): Schema
json_schema('address', true),
json_schema('notes', true),
json_schema('items', true),
date_schema('ordered_on', true),
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function test_every_row_is_keyed_by_column_name(): void
'address',
'notes',
'items',
'ordered_on',
],
array_keys(InMemoryOrders::of(self::ROWS)[0]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ final class OrdersSchemaTest extends TestCase
public function test_every_service_source_declares_eleven_columns(): void
{
foreach (ServiceSource::cases() as $source) {
static::assertCount(11, OrdersSchema::ofService($source)->definitions(), $source->value);
static::assertCount(12, OrdersSchema::ofService($source)->definitions(), $source->value);
}
}

public function test_every_source_declares_eleven_columns(): void
{
foreach (Source::cases() as $source) {
static::assertCount(11, OrdersSchema::of($source)->definitions(), $source->value);
static::assertCount(12, OrdersSchema::of($source)->definitions(), $source->value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\ETL\Schema\Inference\SchemaInference;
Expand Down Expand Up @@ -124,6 +123,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

$schema = $fileColumns->declare($base);
$body = $fileColumns->withoutTail($schema);
$tail = $fileColumns->tail();
$expected = $base->references()->names();

Expand Down Expand Up @@ -154,13 +154,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}
}

$batch = [];

foreach ($rawBatch as $values) {
$batch[] = new RawRowValues($constants->fill($values->values));
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($rawBatch, $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\ETL\Schema\Inference\SchemaInference;
Expand Down Expand Up @@ -170,6 +169,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

$schema = $fileColumns->declare($base);
$body = $fileColumns->withoutTail($schema);
$tail = $fileColumns->tail();
$expected = $base->references()->names();

Expand Down Expand Up @@ -199,13 +199,13 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
$batch = [];

foreach ($sheet->rows() as $rowValues) {
$batch[] = new RawRowValues($constants->fill($rowValues->values));
$batch[] = $rowValues;

if (count($batch) < $batchSize) {
continue;
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($batch, $body), $schema);
$batch = [];

$yielded += $hydrated->count();
Expand All @@ -225,7 +225,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
continue;
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($batch, $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\ETL\Schema\Inference\SchemaInference;
Expand Down Expand Up @@ -126,19 +125,14 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

$schema = $fileColumns->declare($base);
$body = $fileColumns->withoutTail($schema);

foreach ($sources as $source) {
// forFile() reads the PARTITION definitions, which only declare() creates - $base is the body
$constants = $fileColumns->forFile($source, $schema);

foreach ($reader->batches($source, $batchSize) as $rawBatch) {
$batch = [];

foreach ($rawBatch as $values) {
$batch[] = new RawRowValues($constants->fill($values->values));
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($rawBatch, $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\ETL\Schema\Inference\SchemaInference;
Expand Down Expand Up @@ -126,19 +125,14 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

$schema = $fileColumns->declare($base);
$body = $fileColumns->withoutTail($schema);

foreach ($sources as $source) {
// forFile() reads the PARTITION definitions, which only declare() creates - $base is the body
$constants = $fileColumns->forFile($source, $schema);

foreach ($reader->batches($source, $batchSize) as $rawBatch) {
$batch = [];

foreach ($rawBatch as $values) {
$batch[] = new RawRowValues($constants->fill($values->values));
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($rawBatch, $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
// R6: over the FILE's schema, never over schema()'s output
$fileSchema = $fileColumns->declare($this->schema ?? $file->schema());
$constants = $fileColumns->forFile($file->source(), $fileSchema);
$rowsSchema = $promisedSchema ?? $fileSchema;
$body = $fileColumns->withoutTail($rowsSchema);
$matchTo = $promisedSchema === null && !$fileSchema->isSame($target) ? $target : null;

$encoder = new ParquetEncoder($file->file->schema());
Expand All @@ -151,10 +153,13 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
$limit === null ? null : $limit - $yielded,
$fileOffset,
) as $row) {
$rawBatch[] = $constants->fill($row);
$rawBatch[] = $row;

if (count($rawBatch) >= $batchSize) {
$hydrated = $hydrator->hydrate($encoder->decode($rawBatch), $promisedSchema ?? $fileSchema);
$hydrated = $constants->fillRows(
$hydrator->hydrate($encoder->decode($rawBatch), $body),
$rowsSchema,
);

if ($matchTo !== null) {
$hydrated = $hydrated->matchTo($matchTo);
Expand All @@ -177,7 +182,10 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

if ($rawBatch !== []) {
$hydrated = $hydrator->hydrate($encoder->decode($rawBatch), $promisedSchema ?? $fileSchema);
$hydrated = $constants->fillRows(
$hydrator->hydrate($encoder->decode($rawBatch), $body),
$rowsSchema,
);

if ($matchTo !== null) {
$hydrated = $hydrated->matchTo($matchTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\Filesystem\Filesystem;
Expand Down Expand Up @@ -83,6 +82,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi

$fileColumns = $this->fileColumns($this->filesystem, $this->path);
$schema = $fileColumns->declare($baseSchema);
$body = $fileColumns->withoutTail($schema);

foreach ($this->sourceFiles($this->filesystem, $this->path, $pathFilter) as $source) {
$stream = $this->filesystem->readFrom($source->path);
Expand All @@ -96,16 +96,13 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
$rawLines[] = $line;

if (count($rawLines) >= $batchSize) {
$batch = [];

foreach ($encoder->decode($rawLines) as $rowValues) {
$batch[] = new RawRowValues($constants->fill($rowValues->values));
}
$hydrated = $constants->fillRows(
$hydrator->hydrate($encoder->decode($rawLines), $body),
$schema,
);

$rawLines = [];

$hydrated = $hydrator->hydrate($batch, $schema);

$yielded += $hydrated->count();

$signal = yield $hydrated;
Expand All @@ -121,13 +118,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

if ($rawLines !== []) {
$batch = [];

foreach ($encoder->decode($rawLines) as $rowValues) {
$batch[] = new RawRowValues($constants->fill($rowValues->values));
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($encoder->decode($rawLines), $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi

$fileColumns = $this->fileColumns($this->filesystem, $this->path);
$schema = $fileColumns->declare($baseSchema);
$body = $fileColumns->withoutTail($schema);

foreach ($this->sourceFiles($this->filesystem, $this->path, $pathFilter) as $source) {
$stream = $this->filesystem->readFrom($source->path);
Expand All @@ -115,10 +116,10 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
$batch = [];

foreach ($nodes->of($stream, $this->bufferSize) as $node) {
$batch[] = new RawRowValues($constants->fill(['node' => $node]));
$batch[] = new RawRowValues(['node' => $node]);

if (count($batch) >= $batchSize) {
$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($batch, $body), $schema);

$batch = [];

Expand All @@ -137,7 +138,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

if ($batch !== []) {
$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($batch, $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\Extractor\Statistics;
use Flow\ETL\FlowContext;
use Flow\ETL\Row\RawRowValues;
use Flow\ETL\Rows;
use Flow\ETL\Schema;
use Flow\Filesystem\Filesystem;
Expand Down Expand Up @@ -112,6 +111,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi

$fileColumns = $this->fileColumns($this->filesystem, $this->path);
$schema = $fileColumns->declare($baseSchema);
$body = $fileColumns->withoutTail($schema);

foreach ($this->sourceFiles($this->filesystem, $this->path, $pathFilter) as $source) {
$constants = $fileColumns->forFile($source, $schema);
Expand Down Expand Up @@ -152,16 +152,13 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
$rawNodes[] = $node === false ? '' : (string) $dom->saveXML($node);

if (count($rawNodes) >= $batchSize) {
$batch = [];

foreach ($encoder->decode($rawNodes) as $rowValues) {
$batch[] = new RawRowValues($constants->fill($rowValues->values));
}
$hydrated = $constants->fillRows(
$hydrator->hydrate($encoder->decode($rawNodes), $body),
$schema,
);

$rawNodes = [];

$hydrated = $hydrator->hydrate($batch, $schema);

$yielded += $hydrated->count();

$signal = yield $hydrated;
Expand All @@ -181,13 +178,7 @@ public function extract(FlowContext $context, ?int $limit = null, Filter $pathFi
}

if ($rawNodes !== []) {
$batch = [];

foreach ($encoder->decode($rawNodes) as $rowValues) {
$batch[] = new RawRowValues($constants->fill($rowValues->values));
}

$hydrated = $hydrator->hydrate($batch, $schema);
$hydrated = $constants->fillRows($hydrator->hydrate($encoder->decode($rawNodes), $body), $schema);

$yielded += $hydrated->count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function array_map;
use function count;
use function Flow\ETL\DSL\array_to_rows;
use function Flow\ETL\DSL\date_schema;
use function Flow\ETL\DSL\datetime_schema;
use function Flow\ETL\DSL\float_schema;
use function Flow\ETL\DSL\list_schema;
Expand Down Expand Up @@ -69,6 +70,7 @@ public function schema(): Schema
'price' => type_float(),
])),
),
date_schema('ordered_on'),
);
}

Expand Down Expand Up @@ -147,6 +149,7 @@ public function rawData(): Generator
],
range(1, $faker->numberBetween(1, 4)),
),
'ordered_on' => $createdAt->setTime(0, 0),
];

if ($signal === Signal::STOP) {
Expand Down
Loading
Loading