Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added join expressions to dsl #1039

Merged
merged 1 commit into from
Apr 5, 2024
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
73 changes: 72 additions & 1 deletion src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,28 @@
use Flow\ETL\Row\Schema\Formatter\ASCIISchemaFormatter;
use Flow\ETL\Row\Schema\{Definition, Matcher\EvolvingSchemaMatcher, Matcher\StrictSchemaMatcher, SchemaFormatter};
use Flow\ETL\Row\{EntryFactory, EntryReference, Reference, References, Schema};
use Flow\ETL\{Config, ConfigBuilder, DataFrame, Extractor, Flow, FlowContext, Formatter, Loader, Partition, Pipeline, Row, Rows, Transformer, Window};
use Flow\ETL\{Config,
ConfigBuilder,
DataFrame,
Extractor,
Flow,
FlowContext,
Formatter,
Join\Comparison,
Join\Comparison\Equal,
Join\Comparison\GreaterThan,
Join\Comparison\GreaterThanEqual,
Join\Comparison\Identical,
Join\Comparison\LessThan,
Join\Comparison\LessThanEqual,
Join\Expression,
Loader,
Partition,
Pipeline,
Row,
Rows,
Transformer,
Window};

/**
* Alias for data_frame() : Flow.
Expand Down Expand Up @@ -1121,3 +1142,53 @@ function print_rows(Rows $rows, int|bool $truncate = false, ?Formatter $formatte
{
return ($formatter ?? new Formatter\AsciiTableFormatter())->format($rows, $truncate);
}

function identical(Reference|string $left, Reference|string $right) : Identical
{
return new Identical($left, $right);
}

function equal(Reference|string $left, Reference|string $right) : Equal
{
return new Equal($left, $right);
}

function compare_all(Comparison ...$comparisons) : Comparison\All
{
return new Comparison\All(...$comparisons);
}

function compare_any(Comparison ...$comparisons) : Comparison\Any
{
return new Comparison\Any(...$comparisons);
}

function greater_than(Reference|string $left, Reference|string $right) : GreaterThan
{
return new GreaterThan($left, $right);
}

function greater_than_equal(Reference|string $left, Reference|string $right) : GreaterThanEqual
{
return new GreaterThanEqual($left, $right);
}

function less_than(Reference|string $left, Reference|string $right) : LessThan
{
return new LessThan($left, $right);
}

function less_than_equal(Reference|string $left, Reference|string $right) : LessThanEqual
{
return new LessThanEqual($left, $right);
}

function negation(Comparison $comparison) : Comparison\Not
{
return new Comparison\Not($comparison);
}

function join_on(array|Comparison $comparisons, string $joinPrefix = '') : Expression
{
return Expression::on($comparisons, $joinPrefix);
}
8 changes: 7 additions & 1 deletion src/core/etl/src/Flow/ETL/Join/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
}

/**
* @param array<string, string>|Comparison $comparison
* @param array<Comparison>|array<string, string>|Comparison $comparison
*/
public static function on(array|Comparison $comparison, string $joinPrefix = '') : self
{
Expand All @@ -27,6 +27,12 @@ public static function on(array|Comparison $comparison, string $joinPrefix = '')
$comparisons = [];

foreach ($comparison as $left => $right) {
if ($right instanceof Comparison) {
$comparisons[] = $right;

continue;
}

if (!\is_string($left)) {
throw new RuntimeException('Expected left entry name to be string, got ' . \gettype($left) . ". Example: ['id' => 'id']");
}
Expand Down
Loading