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
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"build": [
"@test:docs",
"@test:monorepo",
"@test:examples",
"@static:analyze",
"@test",
"@test:benchmark",
Expand All @@ -222,6 +223,12 @@
"@test:benchmark:loader",
"@test:benchmark:transformer"
],
"test:website": [
"composer test --working-dir=./web/landing"
],
"test:examples": [
"./examples/run.php"
],
"test:benchmark:building_blocks": [
"tools/phpbench/vendor/bin/phpbench run --report=flow-report --group=building_blocks"
],
Expand Down
85 changes: 42 additions & 43 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions examples/topics/schema/apply/code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{bool_schema, data_frame, from_array, int_schema, schema, str_schema, to_stream};
use Flow\ETL\Loader\StreamLoader\Output;
use Flow\ETL\Row\Schema\Metadata;

require __DIR__ . '/../../../autoload.php';

$schema = schema(
int_schema('id', $nullable = false),
str_schema('name', $nullable = true),
bool_schema('active', $nullable = false, Metadata::empty()->add('key', 'value')),
);

data_frame()
->read(
from_array([
['id' => 1, 'name' => 'Product 1', 'active' => true],
['id' => 2, 'name' => 'Product 2', 'active' => false],
['id' => 3, 'name' => 'Product 3', 'active' => true],
])->withSchema($schema)
)
->collect()
->write(to_stream(__DIR__ . '/output.txt', truncate: false, output: Output::schema))
->run();
8 changes: 8 additions & 0 deletions examples/topics/schema/apply/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
While iterating through dataset that comes from a source which does not
support strict schema, like CSV/XML/JSON, you can tell the extractor
what schema to apply to each read column.

Otherwise, DataFrame will try to guess the schema based on the data in the column.
It might be problematic if the first rows would be empty or null.
If the first row is a null, entry factory (mechanism responsible for creating entries)
will assume that the column is of type `string`.
4 changes: 4 additions & 0 deletions examples/topics/schema/apply/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
schema
|-- id: integer
|-- name: string
|-- active: boolean
1 change: 1 addition & 0 deletions examples/topics/schema/apply/priority.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
13 changes: 3 additions & 10 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
ArrayUnpack,
Average,
Between,
CallMethod,
Capitalize,
Cast,
Coalesce,
Expand Down Expand Up @@ -944,15 +943,6 @@ function upper(ScalarFunction|string $value) : ToUpper
return new ToUpper($value);
}

/**
* @param array<mixed> $params
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::SCALAR_FUNCTION)]
function call_method(object $object, ScalarFunction|string $method, array $params = []) : CallMethod
{
return new CallMethod($object, $method, $params);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::SCALAR_FUNCTION)]
function all(ScalarFunction ...$functions) : All
{
Expand Down Expand Up @@ -1557,6 +1547,7 @@ function dom_element_to_string(\DOMElement $element, bool $format_output = false
return $doc->saveXML($doc->documentElement);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
function date_interval_to_milliseconds(\DateInterval $interval) : int
{
if ($interval->y !== 0 || $interval->m !== 0) {
Expand All @@ -1573,6 +1564,7 @@ function date_interval_to_milliseconds(\DateInterval $interval) : int
: (int) ($absoluteSeconds * 1000 + $interval->f * 1000);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
function date_interval_to_seconds(\DateInterval $interval) : int
{
if ($interval->y !== 0 || $interval->m !== 0) {
Expand All @@ -1589,6 +1581,7 @@ function date_interval_to_seconds(\DateInterval $interval) : int
: (int) ceil($absoluteSeconds + $interval->f);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
function date_interval_to_microseconds(\DateInterval $interval) : int
{
if ($interval->y !== 0 || $interval->m !== 0) {
Expand Down
37 changes: 0 additions & 37 deletions src/core/etl/src/Flow/ETL/Function/CallMethod.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,6 @@ public function lower() : self
return new ToLower($this);
}

/**
* @param ScalarFunction|string $method
* @param array<mixed> $params
*/
public function method(ScalarFunction|string $method, array $params) : self
{
return new CallMethod($this, $method, $params);
}

public function minus(ScalarFunction|int|float $ref) : self
{
return new Minus($this, $ref);
Expand Down
Loading
Loading