Skip to content

Commit

Permalink
Improve FragmentFinder implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 13, 2024
1 parent 950f862 commit ecef445
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/FragmentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,28 @@ private function find(array $parsedExpression, TabularDataReader $tabularDataRea
(null === $selection['end'] || $offset <= $selection['end'])
);

return [$tabularDataReader->filter($rowFilter)];
return [Statement::create()->where($rowFilter)->process($tabularDataReader)];
}

if (self::TYPE_COLUMN === $type) {
$columns = array_reduce($selections, fn (array $columns, array $selection) => [...$columns, ...$selection['columns']], []);
$columns = array_reduce(
$selections,
fn (array $columns, array $selection) => [...$columns, ...$selection['columns']],
[]
);

return [match ([]) {
$columns => ResultSet::createFromRecords(),
default => $tabularDataReader->select(...$columns),
default => Statement::create()->select(...$columns)->process($tabularDataReader),
}];
}

return array_map(
fn (array $selection) => $tabularDataReader
->slice($selection['start'], $selection['length'])
->select(...$selection['columns']),
fn (array $selection) => Statement::create()
->select(...$selection['columns'])
->offset($selection['start'])
->limit($selection['length'])
->process($tabularDataReader),
$selections
);
}
Expand Down

0 comments on commit ecef445

Please sign in to comment.