Skip to content

Commit

Permalink
Added join expressions to dsl (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech authored Apr 5, 2024
1 parent 0ea3dfc commit c1992f3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
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

0 comments on commit c1992f3

Please sign in to comment.