Skip to content

Commit

Permalink
Allow expressions as partition in $fill stage
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Mar 23, 2023
1 parent e517015 commit 77d5827
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public function getExpression(): array
$params = (object) [];

if ($this->partitionBy) {
$params->partitionBy = $this->partitionBy;
$params->partitionBy = $this->partitionBy instanceof Expr
? $this->partitionBy->getExpression()
: $this->partitionBy;
}

if ($this->partitionByFields) {
Expand Down
24 changes: 24 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ public function testStage(): void
);
}

public function testStageWithExpressionAsPartition(): void
{
$builder = $this->getTestAggregationBuilder();
$fillStage = new Fill($builder);
$fillStage
->partitionBy($builder->expr()->year('$field'))
->sortBy('field1', 1)
->output()
->field('foo')->locf();

self::assertEquals(
[
'$fill' => (object) [
'partitionBy' => ['$year' => '$field'],
'sortBy' => (object) ['field1' => 1],
'output' => (object) [
'foo' => ['method' => 'locf'],
],
],
],
$fillStage->getExpression(),
);
}

public function testStageWithComplexSort(): void
{
$fillStage = new Fill($this->getTestAggregationBuilder());
Expand Down

0 comments on commit 77d5827

Please sign in to comment.