Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types accepted by $round builder #1401

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
20 changes: 15 additions & 5 deletions generator/config/expression/round.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ type:
- resolvesToLong
encode: array
description: |
Rounds a number to to a whole integer or to a specified decimal place.
Rounds a number to a whole integer or to a specified decimal place.
arguments:
-
name: number
type:
- resolvesToInt
- resolvesToDouble
- resolvesToDecimal
- resolvesToLong
- resolvesToNumber
description: |
Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.
$round returns an error if the expression resolves to a non-numeric data type.
Expand All @@ -38,3 +35,16 @@ tests:
$round:
- '$value'
- 1
-
name: 'Round Average Rating'
pipeline:
-
$project:
roundedAverageRating:
$avg:
-
$round:
-
$avg:
- '$averageRating'
- 2
6 changes: 3 additions & 3 deletions src/Builder/Expression/FactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Builder/Expression/RoundOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/Builder/Expression/Pipelines.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/Builder/Expression/RoundOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ public function testExample(): void

$this->assertSamePipeline(Pipelines::RoundExample, $pipeline);
}

public function testRoundAverageRating(): void
{
$pipeline = new Pipeline(
Stage::project(
roundedAverageRating: Expression::avg(
Expression::round(
Expression::avg(
Expression::doubleFieldPath('averageRating'),
),
2,
),
),
),
);

$this->assertSamePipeline(Pipelines::RoundRoundAverageRating, $pipeline);
}
}