Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/core/etl/src/Flow/ETL/Constraint/SortedByConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class SortedByConstraint implements Constraint

private readonly References $references;

public function __construct(Reference $column, Reference ...$columns)
public function __construct(Reference ...$columns)
{
$this->references = new References($column, ...$columns);
$this->references = new References(...$columns);
}

public function isSatisfiedBy(Row $row) : bool
Expand Down
4 changes: 2 additions & 2 deletions src/core/etl/src/Flow/ETL/Constraint/UniqueConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ final class UniqueConstraint implements Constraint

private Storage $storage;

public function __construct(string|Reference $column, string|Reference ...$columns)
public function __construct(string|Reference ...$columns)
{
$this->reference = refs($column, ...$columns);
$this->reference = refs(...$columns);
$this->storage = new InMemoryStorage();
}

Expand Down
15 changes: 7 additions & 8 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2399,15 +2399,14 @@ function type_is(Type $type, string $typeClass) : bool
* @template T
*
* @param Type<T> $type
* @param class-string<Type<T>> $typeClass
* @param class-string<Type<T>> ...$typeClasses
*
* @deprecated please use \Flow\Types\DSL\type_is_any($type, $typeClass, ...$typeClasses): bool instead
* @deprecated please use \Flow\Types\DSL\type_is_any($type, ...$typeClasses): bool instead
*/
#[DocumentationDSL(module: Module::DEPRECATED, type: DSLType::DEPRECATED)]
function type_is_any(Type $type, string $typeClass, string ...$typeClasses) : bool
function type_is_any(Type $type, string ...$typeClasses) : bool
{
return type_is_any_new($type, $typeClass, ...$typeClasses);
return type_is_any_new($type, ...$typeClasses);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
Expand Down Expand Up @@ -2497,17 +2496,17 @@ function with_entry(string $name, ScalarFunction $function) : WithEntry
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
function constraint_unique(string $reference, string ...$references) : UniqueConstraint
function constraint_unique(string ...$references) : UniqueConstraint
{
return new UniqueConstraint($reference, ...$references);
return new UniqueConstraint(...$references);
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
function constraint_sorted_by(string|Reference $column, string|Reference ...$columns) : SortedByConstraint
function constraint_sorted_by(string|Reference ...$columns) : SortedByConstraint
{
$references = \array_map(
static fn (string|Reference $ref) => EntryReference::init($ref),
[$column, ...$columns]
$columns,
);

return new SortedByConstraint(...$references);
Expand Down
8 changes: 2 additions & 6 deletions src/core/etl/src/Flow/ETL/DataFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ public function collectRefs(References $references) : self
return $this;
}

public function constrain(Constraint $constraint, Constraint ...$constraints) : self
public function constrain(Constraint ...$constraints) : self
{
$constraints = \array_merge([$constraint], $constraints);

$this->pipeline->add(new ConstrainedProcessor($constraints));

return $this;
Expand Down Expand Up @@ -665,10 +663,8 @@ public function onError(ErrorHandler $handler) : self
/**
* @lazy
*/
public function partitionBy(string|Reference $entry, string|Reference ...$entries) : self
public function partitionBy(string|Reference ...$entries) : self
{
\array_unshift($entries, $entry);

$this->pipeline->add(new PartitioningProcessor(References::init(...$entries)->all()));

return $this;
Expand Down
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/References.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ final class References implements \ArrayAccess, \Countable, \IteratorAggregate

public function __construct(string|Reference ...$references)
{
if ([] === $references) {
throw new InvalidArgumentException('References cannot be empty.');
}

foreach ($references as $ref) {
$ref = EntryReference::init($ref);

Expand Down
5 changes: 2 additions & 3 deletions src/core/etl/src/Flow/ETL/Rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,16 +583,15 @@ public function offsetUnset(mixed $offset) : void
}

/**
* @param Reference|string $reference
* @param Reference|string ...$references
*
* @throws InvalidArgumentException
*
* @return array<Rows>
*/
public function partitionBy(string|Reference $reference, string|Reference ...$references) : array
public function partitionBy(string|Reference ...$references) : array
{
$refs = References::init($reference, ...$references);
$refs = References::init(...$references);

/** @var array<string, array<mixed>> $partitions */
$partitions = [];
Expand Down
11 changes: 10 additions & 1 deletion src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
namespace Flow\ETL\Tests\Unit\Row;

use function Flow\ETL\DSL\{ref, refs};
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row\References;
use Flow\ETL\Tests\FlowTestCase;

final class ReferencesTest extends FlowTestCase
{
public function test_empty() : void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('References cannot be empty.');

refs();
}

public function test_lazy_without() : void
{
$refs = refs()->without('id')->add('id')->add('name');
$refs = refs('id')->without('id')->add('id')->add('name');

self::assertEquals(
refs('name')->all(),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/filesystem/src/Flow/Filesystem/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static function realpath(string $path, array|Options $options = []) : sel
);
}

public function addPartitions(Partition $partition, Partition ...$partitions) : self
public function addPartitions(Partition ...$partitions) : self
{
return new self($this->implementation->addPartitions($partition, ...$partitions));
return new self($this->implementation->addPartitions(...$partitions));
}

public function basename() : string
Expand Down
7 changes: 3 additions & 4 deletions src/lib/filesystem/src/Flow/Filesystem/Path/UnixPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static function realpath(string $path, array|Options $options = []) : sel
return new self('/' . \implode('/', $absoluteParts), $options);
}

public function addPartitions(Partition $partition, Partition ...$partitions) : self
public function addPartitions(Partition ...$partitions) : self
{
if ($this->isPattern()) {
throw new InvalidArgumentException("Can't add partitions to path pattern.");
Expand All @@ -104,11 +104,10 @@ public function addPartitions(Partition $partition, Partition ...$partitions) :
$pathInfo = \pathinfo($this->path);
$dirname = $pathInfo['dirname'] ?? '';
$basename = $pathInfo['basename'] ?? '';
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, [$partition, ...$partitions]));
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, $partitions));

return match ($dirname) {
'', '.' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
'/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
'', '.', '/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
default => new self($this->protocol->scheme() . $dirname . '/' . $partitionsString . '/' . $basename, $this->options),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/filesystem/src/Flow/Filesystem/Path/WindowsPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function realpath(string $path, array|Options $options = []) : sel
return new self($drive . '/' . \implode('/', $absoluteParts), $options);
}

public function addPartitions(Partition $partition, Partition ...$partitions) : self
public function addPartitions(Partition ...$partitions) : self
{
if ($this->isPattern()) {
throw new InvalidArgumentException("Can't add partitions to path pattern.");
Expand All @@ -100,7 +100,7 @@ public function addPartitions(Partition $partition, Partition ...$partitions) :
$pathInfo = \pathinfo($this->path);
$dirname = $pathInfo['dirname'] ?? '';
$basename = $pathInfo['basename'] ?? '';
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, [$partition, ...$partitions]));
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, $partitions));

return match ($dirname) {
'', '.', '/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
Expand Down
5 changes: 2 additions & 3 deletions src/lib/types/src/Flow/Types/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,12 @@ function type_is(Type $type, string $typeClass) : bool
* @template T
*
* @param Type<T> $type
* @param class-string<Type<mixed>> $typeClass
* @param class-string<Type<mixed>> ...$typeClasses
*/
#[DocumentationDSL(module: Module::TYPES, type: DSLType::HELPER)]
function type_is_any(Type $type, string $typeClass, string ...$typeClasses) : bool
function type_is_any(Type $type, string ...$typeClasses) : bool
{
return (new Comparator())->isAny($type, $typeClass, ...$typeClasses);
return (new Comparator())->isAny($type, ...$typeClasses);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/lib/types/src/Flow/Types/Type/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,11 @@ public function is(Type $type, string $typeClass) : bool
* @template T
*
* @param Type<T> $type
* @param class-string<Type<mixed>> $typeClass
* @param class-string<Type<mixed>> ...$typeClasses
*/
public function isAny(Type $type, string $typeClass, string ...$typeClasses) : bool
public function isAny(Type $type, string ...$typeClasses) : bool
{
$classes = [$typeClass, ...$typeClasses];

foreach ($classes as $class) {
foreach ($typeClasses as $class) {
if ($this->is($type, $class)) {
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions web/landing/assets/codemirror/completions/dataframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ const dataframeMethods = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">constrain</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraint</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraints</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
<span class=\"fn-name\">constrain</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraints</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
</div>
`
return div
},
apply: snippet("constrain(" + "$" + "{" + "1:constraint" + "}" + ", " + "$" + "{" + "2:constraints" + "}" + ")"),
apply: snippet("constrain(" + "$" + "{" + "1:constraints" + "}" + ")"),
boost: 10
}, {
label: "count",
Expand Down Expand Up @@ -625,15 +625,15 @@ const dataframeMethods = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">partitionBy</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entry</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entries</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
<span class=\"fn-name\">partitionBy</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entries</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
</div>
<div style="color: #8b949e; font-size: 13px;">
@lazy
</div>
`
return div
},
apply: snippet("partitionBy(" + "$" + "{" + "1:entry" + "}" + ", " + "$" + "{" + "2:entries" + "}" + ")"),
apply: snippet("partitionBy(" + "$" + "{" + "1:entries" + "}" + ")"),
boost: 10
}, {
label: "pivot",
Expand Down
14 changes: 7 additions & 7 deletions web/landing/assets/codemirror/completions/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2068,12 +2068,12 @@ const dslFunctions = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">constraint_sorted_by</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$column</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$columns</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">SortedByConstraint</span>
<span class=\"fn-name\">constraint_sorted_by</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$columns</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">SortedByConstraint</span>
</div>
`
return div
},
apply: snippet("\\Flow\\ETL\\DSL\\constraint_sorted_by(" + "$" + "{" + "1:column" + "}" + ", " + "$" + "{" + "2:columns" + "}" + ")"),
apply: snippet("\\Flow\\ETL\\DSL\\constraint_sorted_by(" + "$" + "{" + "1:columns" + "}" + ")"),
boost: 10
}, {
label: "constraint_unique",
Expand All @@ -2083,12 +2083,12 @@ const dslFunctions = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">constraint_unique</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">string</span> <span class=\"fn-param\">$reference</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">string</span> <span class=\"fn-param\">$references</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">UniqueConstraint</span>
<span class=\"fn-name\">constraint_unique</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">string</span> <span class=\"fn-param\">$references</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">UniqueConstraint</span>
</div>
`
return div
},
apply: snippet("\\Flow\\ETL\\DSL\\constraint_unique(" + "$" + "{" + "1:reference" + "}" + ", " + "$" + "{" + "2:references" + "}" + ")"),
apply: snippet("\\Flow\\ETL\\DSL\\constraint_unique(" + "$" + "{" + "1:references" + "}" + ")"),
boost: 10
}, {
label: "context",
Expand Down Expand Up @@ -11092,15 +11092,15 @@ const dslFunctions = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">type_is_any</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Type</span> <span class=\"fn-param\">$type</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">string</span> <span class=\"fn-param\">$typeClass</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">string</span> <span class=\"fn-param\">$typeClasses</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">bool</span>
<span class=\"fn-name\">type_is_any</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Type</span> <span class=\"fn-param\">$type</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">string</span> <span class=\"fn-param\">$typeClasses</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">bool</span>
</div>
<div style="color: #8b949e; font-size: 13px;">
@template T<br>@param Type<T> $type<br>@param class-string<Type<mixed>> $typeClass<br>@param class-string<Type<mixed>> ...$typeClasses
@template T<br>@param Type<T> $type<br>@param class-string<Type<mixed>> ...$typeClasses
</div>
`
return div
},
apply: snippet("\\Flow\\Types\\DSL\\type_is_any(" + "$" + "{" + "1:type" + "}" + ", " + "$" + "{" + "2:typeClass" + "}" + ", " + "$" + "{" + "3:typeClasses" + "}" + ")"),
apply: snippet("\\Flow\\Types\\DSL\\type_is_any(" + "$" + "{" + "1:type" + "}" + ", " + "$" + "{" + "2:typeClasses" + "}" + ")"),
boost: 10
}, {
label: "type_is_nullable",
Expand Down
2 changes: 1 addition & 1 deletion web/landing/resources/api.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/landing/resources/dsl.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ const dataframeMethods = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">constrain</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraint</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraints</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
<span class=\"fn-name\">constrain</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Constraint</span> <span class=\"fn-param\">$constraints</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
</div>
`
return div
},
apply: snippet("constrain(" + "$" + "{" + "1:constraint" + "}" + ", " + "$" + "{" + "2:constraints" + "}" + ")"),
apply: snippet("constrain(" + "$" + "{" + "1:constraints" + "}" + ")"),
boost: 10
}, {
label: "count",
Expand Down Expand Up @@ -625,15 +625,15 @@ const dataframeMethods = [
const div = document.createElement("div")
div.innerHTML = `
<div style="font-family: 'Fira Code', 'JetBrains Mono', monospace; margin-bottom: 8px;">
<span class=\"fn-name\">partitionBy</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entry</span><span class=\"fn-operator\">,</span> <span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entries</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
<span class=\"fn-name\">partitionBy</span><span class=\"fn-operator\">(</span><span class=\"fn-type\">Reference|string</span> <span class=\"fn-param\">$entries</span><span class=\"fn-operator\">)</span> <span class=\"fn-operator\">:</span> <span class=\"fn-return\">self</span>
</div>
<div style="color: #8b949e; font-size: 13px;">
@lazy
</div>
`
return div
},
apply: snippet("partitionBy(" + "$" + "{" + "1:entry" + "}" + ", " + "$" + "{" + "2:entries" + "}" + ")"),
apply: snippet("partitionBy(" + "$" + "{" + "1:entries" + "}" + ")"),
boost: 10
}, {
label: "pivot",
Expand Down
Loading
Loading