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

PHPLIB-1254 Create Yaml for all operators and stages #1180

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6fe9809
Create Yaml files from Google Sheet
GromNaN Oct 4, 2023
204e88f
Import all operators and stages
GromNaN Oct 4, 2023
b3c6279
Add @no-named-argument to list variadic
GromNaN Oct 5, 2023
59f360c
Improve typing for variadics
GromNaN Oct 5, 2023
64ee28e
Add link and description to classes and factory
GromNaN Oct 5, 2023
05c5ee5
Temporary disable benchmarks and old PHP version from CI
GromNaN Oct 5, 2023
83aa77a
Fix & encoding
GromNaN Oct 5, 2023
9a36d17
Fix schema
GromNaN Oct 5, 2023
c0de34d
Introduce MongoDB\object() function
GromNaN Oct 5, 2023
70f8671
Fix single encoding + optional value in array
GromNaN Oct 5, 2023
38c7750
Fix psalm + accumulator
GromNaN Oct 5, 2023
5733833
Case insensitive sort of methods
GromNaN Oct 6, 2023
6faa7f8
Fix $sum accumulator test
GromNaN Oct 6, 2023
27c9f21
Ignore psalm issues
GromNaN Oct 6, 2023
502ed6b
Improve doc for object function
GromNaN Oct 6, 2023
3f175e7
Fix methods order
GromNaN Oct 6, 2023
d89d024
Remove tests on PHP 8.0
GromNaN Oct 6, 2023
2129f88
Rename mixed to any and remove incorrect generic type from list
GromNaN Oct 6, 2023
06c5294
Improve operator classification and add all BSON types
GromNaN Oct 9, 2023
a5840c0
Rename Expression Operators and write architecture document
GromNaN Oct 10, 2023
99e2266
Implement Regex factory
GromNaN Oct 10, 2023
636aa4a
Remove generated warning on non-generated files
GromNaN Oct 10, 2023
5bc3cd8
Add use function for generated code
GromNaN Oct 10, 2023
bdfbcc5
Refinement of query type with a new filter type
GromNaN Oct 11, 2023
c7bc14c
Move Projection operators to a dedicated namespace
GromNaN Oct 11, 2023
35dbd63
Move Optional & Encode enum to the Type namespace
GromNaN Oct 11, 2023
00b3cd3
Move Accumulator and Window operators in a dedicated namespace
GromNaN Oct 11, 2023
dd28e4a
Remove category from Yaml files and remove scrape command
GromNaN Oct 11, 2023
58fd4d0
Add some errors for incorrect types
GromNaN Oct 11, 2023
13d29a8
Rename filter to fieldQuery
GromNaN Oct 11, 2023
e51b16f
exclude accumulator from QA
GromNaN Oct 11, 2023
c0790e0
Make FieldPath implement ResolveToAny
GromNaN Oct 11, 2023
960eaa4
Remove unused packages
GromNaN Oct 11, 2023
120f530
Make operator classes read-only
GromNaN Oct 12, 2023
57555b9
Add tests on Pipeline class
GromNaN Oct 12, 2023
fee0df6
Rename PhpObject enum
GromNaN Oct 12, 2023
ad48be4
Use BSON\Type and BSON\Javascript classes, remove duplicate resolveToInt
GromNaN Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- "v*.*"
- "master"
- "feature/*"
#- "feature/*"
jmikola marked this conversation as resolved.
Show resolved Hide resolved
paths-ignore:
- "docs/**"
push:
Expand All @@ -15,6 +15,7 @@ on:
- "feature/*"
paths-ignore:
- "docs/**"
- "generator/**"

env:
PHP_VERSION: "8.2"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
os:
- "ubuntu-20.04"
php-version:
- "7.4"
- "8.0"
#- "7.4"
#- "8.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be reverted by PHPLIB-1268

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you come to a solution to still run PHPLIB against 7.4+ but limit the aggregation builder code to 8.1+?

- "8.1"
- "8.2"
mongodb-version:
Expand Down
27 changes: 27 additions & 0 deletions .idea/jsonSchemas.xml

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

8 changes: 6 additions & 2 deletions examples/aggregation-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use MongoDB\Builder\Stage;
use MongoDB\Client;

use function array_is_list;
use function assert;
use function getenv;
use function is_array;
use function is_object;
use function MongoDB\BSON\fromPHP;
use function MongoDB\BSON\toRelaxedExtendedJSON;
Expand Down Expand Up @@ -48,15 +50,15 @@ function toJSON(object $document): string
totalCount: Aggregation::sum(1),
evenCount: Aggregation::sum(
Aggregation::mod(
Expression::fieldPath('randomValue'),
Expression::numberFieldPath('randomValue'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is numberFieldPath required over fieldPath since the code would expect ResolvesToNumber here? Do users still have the choice of passing an arbitrary field path as a string?

Looking at this now, I can see how these might be annoying if users must use type in the query builder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a request from @alcaeus in the Technical Design doc.

To complete the type experience, there are also typed fieldPath helpers (e.g. stringFieldPath) which communicate to the type system that the field path resolves to the given type. This can again be used by an ORM to verify that the field will actually resolve to the given type (if known).

2,
),
),
oddCount: Aggregation::sum(
Aggregation::subtract(
1,
Aggregation::mod(
Expression::fieldPath('randomValue'),
Expression::numberFieldPath('randomValue'),
2,
),
),
Expand All @@ -74,6 +76,8 @@ function toJSON(object $document): string
$encoder = new BuilderEncoder();
$pipeline = $encoder->encode($pipeline);

assert(is_array($pipeline) && array_is_list($pipeline));

$cursor = $collection->aggregate($pipeline);

foreach ($cursor as $document) {
Expand Down
3 changes: 3 additions & 0 deletions generator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"mongodb/mongodb": "@dev",
"nette/php-generator": "^4",
"symfony/console": "^6.3",
"symfony/css-selector": "^6.3",
"symfony/dom-crawler": "^6.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove when the scrape command is removed.

"symfony/finder": "^6.3",
"symfony/yaml": "^6.3"
},
"license": "Apache-2.0",
Expand Down
15 changes: 15 additions & 0 deletions generator/config/aggregation-operators/abs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# $schema: ../schema.json
name: $abs
category:
- 'Arithmetic Expression'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/'
type:
- resolvesToNumber
encode: single
description: |
Returns the absolute value of a number.
arguments:
-
name: value
type:
- resolvesToNumber
57 changes: 57 additions & 0 deletions generator/config/aggregation-operators/accumulator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# $schema: ../schema.json
name: $accumulator
category:
- Accumulators
- 'Custom Aggregation Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/'
type:
- Accumulator
encode: object
description: |
Defines a custom accumulator function.
New in version 4.4.
arguments:
-
name: init
type:
- string
description: |
Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String.
-
name: initArgs
type:
- resolvesToArray
optional: true
description: |
Arguments passed to the init function.
-
name: accumulate
type:
- string
description: |
Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String.
-
name: accumulateArgs
type:
- resolvesToArray
description: |
Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function.
-
name: merge
type:
- string
description: |
Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge.
-
name: finalize
type:
- string
optional: true
description: |
Function used to update the result of the accumulation.
-
name: lang
type:
- string
description: |
The language used in the $accumulator code.
20 changes: 20 additions & 0 deletions generator/config/aggregation-operators/acos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: ../schema.json
name: $acos
category:
- 'Trigonometry Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/'
type:
- resolvesToDouble
- resolvesToDecimal
encode: single
description: |
Returns the inverse cosine (arc cosine) of a value in radians.
arguments:
-
name: expression
type:
- resolvesToNumber
description: |
$acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1.
$acos returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $acos returns values as a double. $acos can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
20 changes: 20 additions & 0 deletions generator/config/aggregation-operators/acosh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: ../schema.json
name: $acosh
category:
- 'Trigonometry Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/'
type:
- resolvesToDouble
- resolvesToDecimal
encode: single
description: |
Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians.
arguments:
-
name: expression
type:
- resolvesToNumber
description: |
$acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity.
$acosh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $acosh returns values as a double. $acosh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
21 changes: 21 additions & 0 deletions generator/config/aggregation-operators/add.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# $schema: ../schema.json
name: $add
category:
- 'Arithmetic Expression Operator'
- 'Date Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/'
type:
- resolvesToNumber
- resolvesToDate
encode: array
description: |
Adds numbers to return the sum, or adds numbers and a date to return a new date. If adding numbers and a date, treats the numbers as milliseconds. Accepts any number of argument expressions, but at most, one expression can resolve to a date.
arguments:
-
name: expression
type:
- resolvesToNumber
- resolvesToDate
variadic: array
description: |
The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date.
18 changes: 18 additions & 0 deletions generator/config/aggregation-operators/addToSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# $schema: ../schema.json
name: $addToSet
category:
- Accumulators
- 'Window Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/'
type:
- Accumulator
encode: single
description: |
Returns an array of unique expression values for each group. Order of the array elements is undefined.
Changed in version 5.0: Available in the $setWindowFields stage.
arguments:
-
name: expression
type:
- expression
- fieldPath
16 changes: 16 additions & 0 deletions generator/config/aggregation-operators/allElementsTrue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# $schema: ../schema.json
name: $allElementsTrue
category:
- 'Set Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/'
type:
- resolvesToBool
encode: array
description: |
Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression.
arguments:
-
name: expression
type:
- resolvesToArray
variadic: array
20 changes: 20 additions & 0 deletions generator/config/aggregation-operators/and.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: ../schema.json
name: $and
category:
- 'Boolean Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/'
type:
- resolvesToBool
encode: single
description: |
Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions.
arguments:
-
name: expression
type:
- expression
- resolvesToBool
- resolvesToNumber
- resolvesToString
- resolvesToNull
variadic: array
15 changes: 15 additions & 0 deletions generator/config/aggregation-operators/anyElementTrue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# $schema: ../schema.json
name: $anyElementTrue
category:
- 'Set Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/'
type:
- resolvesToBool
encode: array
description: |
Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression.
arguments:
-
name: expression
type:
- resolvesToArray
19 changes: 19 additions & 0 deletions generator/config/aggregation-operators/arrayElemAt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# $schema: ../schema.json
name: $arrayElemAt
category:
- 'Array Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/'
type:
- resolvesToAnything
encode: array
description: |
Returns the element at the specified array index.
arguments:
-
name: array
type:
- resolvesToArray
-
name: idx
type:
- resolvesToInt
15 changes: 15 additions & 0 deletions generator/config/aggregation-operators/arrayToObject.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# $schema: ../schema.json
name: $arrayToObject
category:
- 'Array Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/'
type:
- resolvesToObject
encode: array
description: |
Converts an array of key value pairs to a document.
arguments:
-
name: array
type:
- resolvesToArray
20 changes: 20 additions & 0 deletions generator/config/aggregation-operators/asin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: ../schema.json
name: $asin
category:
- 'Trigonometry Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/'
type:
- resolvesToDouble
- resolvesToDecimal
encode: single
description: |
Returns the inverse sin (arc sine) of a value in radians.
arguments:
-
name: expression
type:
- resolvesToNumber
description: |
$asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1.
$asin returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $asin returns values as a double. $asin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
20 changes: 20 additions & 0 deletions generator/config/aggregation-operators/asinh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: ../schema.json
name: $asinh
category:
- 'Trigonometry Expression Operator'
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/'
type:
- resolvesToDouble
- resolvesToDecimal
encode: single
description: |
Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians.
arguments:
-
name: expression
type:
- resolvesToNumber
description: |
$asinh takes any valid expression that resolves to a number.
$asinh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees.
By default $asinh returns values as a double. $asinh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value.
Loading
Loading