Skip to content

Commit

Permalink
Added DataFrame::fromArray method
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Feb 11, 2024
1 parent 5f04b07 commit 1580877
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function extract(FlowContext $context) : \Generator
if (\method_exists($countQuery, 'resetOrderBy')) {
$countQuery->resetOrderBy();
} else {
/**
* @psalm-suppress UndefinedMethod
*
* @phpstan-ignore-next-line
*/
$countQuery->resetQueryPart('orderBy');
}

Expand Down
25 changes: 16 additions & 9 deletions src/core/etl/src/Flow/ETL/DataFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ public function __construct(private Pipeline $pipeline, Config $configuration)
}

/**
* @throws \JsonException
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public static function fromJson(string $json) : self
public static function fromArray(array $definition) : self
{
$namespaces = [
DSLNamespace::global(new DenyAll()),
Expand All @@ -103,12 +102,7 @@ public static function fromJson(string $json) : self
)
);

try {
$results = (new Executor())
->execute($builder->parse(\json_decode($json, true, 512, JSON_THROW_ON_ERROR)));
} catch (\JsonException $exception) {
throw new InvalidFileFormatException('json', 'unknown');
}
$results = (new Executor())->execute($builder->parse($definition));

if (\count($results) !== 1) {
throw new InvalidArgumentException('Invalid JSON, please make sure that there is only one data_frame function');
Expand All @@ -124,6 +118,19 @@ public static function fromJson(string $json) : self
}
}

/**
* @throws \JsonException
* @throws InvalidArgumentException
*/
public static function fromJson(string $json) : self
{
try {
return self::fromArray(\json_decode($json, true, 512, JSON_THROW_ON_ERROR));
} catch (\JsonException $exception) {
throw new InvalidFileFormatException('json', 'unknown');
}
}

/**
* @lazy
*
Expand Down

0 comments on commit 1580877

Please sign in to comment.