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 all 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
  •  
  •  
  •  
8 changes: 2 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ psalm-baseline.xml export-ignore

# Keep generated files from displaying in diffs by default
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
/src/Builder/Aggregation.php linguist-generated=true
/src/Builder/Aggregation/*.php linguist-generated=true
/src/Builder/Expression.php linguist-generated=true
/src/Builder/Accumulator/*.php linguist-generated=true
/src/Builder/Expression/*.php linguist-generated=true
/src/Builder/Query.php linguist-generated=true
/src/Builder/Query/*.php linguist-generated=true
/src/Builder/Stage.php linguist-generated=true
/src/Builder/Projection/*.php linguist-generated=true
/src/Builder/Stage/*.php linguist-generated=true
/src/Builder/Stage/Stage.php linguist-generated=false
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- "v*.*"
- "master"
- "feature/*"
paths-ignore:
- "docs/**"
push:
Expand All @@ -15,6 +14,7 @@ on:
- "feature/*"
paths-ignore:
- "docs/**"
- "generator/**"

env:
PHP_VERSION: "8.2"
Expand Down
14 changes: 7 additions & 7 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 All @@ -39,27 +39,27 @@ jobs:
- "server"
include:
- os: "ubuntu-20.04"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "6.0"
driver-version: "mongodb/mongo-php-driver@master"
topology: "replica_set"
- os: "ubuntu-20.04"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "6.0"
driver-version: "mongodb/mongo-php-driver@master"
topology: "sharded_cluster"
- os: "ubuntu-20.04"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "5.0"
driver-version: "mongodb/mongo-php-driver@master"
topology: "server"
- os: "ubuntu-20.04"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "4.4"
driver-version: "mongodb/mongo-php-driver@master"
topology: "replica_set"
- os: "ubuntu-20.04"
php-version: "8.0"
php-version: "8.1"
mongodb-version: "4.4"
driver-version: "mongodb/mongo-php-driver@master"
topology: "sharded_cluster"
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.

32 changes: 13 additions & 19 deletions examples/aggregation-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

namespace MongoDB\Examples\AggregationBuilder;

use MongoDB\Builder\Aggregation;
use MongoDB\Builder\Accumulator;
use MongoDB\Builder\BuilderEncoder;
use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
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 @@ -45,35 +47,27 @@ function toJSON(object $document): string
$pipeline = new Pipeline(
Stage::group(
_id: null,
totalCount: Aggregation::sum(1),
evenCount: Aggregation::sum(
Aggregation::mod(
Expression::fieldPath('randomValue'),
2,
),
totalCount: Accumulator::sum(1),
evenCount: Accumulator::sum(
Expression::mod(Expression::numberFieldPath('randomValue'), 2),
),
oddCount: Aggregation::sum(
Aggregation::subtract(
oddCount: Accumulator::sum(
Expression::subtract(
1,
Aggregation::mod(
Expression::fieldPath('randomValue'),
2,
),
Expression::mod(Expression::numberFieldPath('randomValue'), 2),
),
),
maxValue: Aggregation::max(
Expression::fieldPath('randomValue'),
),
minValue: Aggregation::min(
Expression::fieldPath('randomValue'),
),
maxValue: Accumulator::max(Expression::numberFieldPath('randomValue')),
minValue: Accumulator::min(Expression::numberfieldPath('randomValue')),
),
);

// @todo Accept a Pipeline instance in Collection::aggregate() and automatically encode it
$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
1 change: 1 addition & 0 deletions generator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mongodb/mongodb": "@dev",
"nette/php-generator": "^4",
"symfony/console": "^6.3",
"symfony/finder": "^6.3",
"symfony/yaml": "^6.3"
},
"license": "Apache-2.0",
Expand Down
55 changes: 55 additions & 0 deletions generator/config/accumulator/accumulator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# $schema: ../schema.json
name: $accumulator

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.
16 changes: 16 additions & 0 deletions generator/config/accumulator/addToSet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# $schema: ../schema.json
name: $addToSet

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/'
type:
- accumulator
- window
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
16 changes: 16 additions & 0 deletions generator/config/accumulator/avg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# $schema: ../schema.json
name: $avg

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/'
type:
- accumulator
- window
encode: single
description: |
Returns an average of numerical values. Ignores non-numeric values.
Changed in version 5.0: Available in the $setWindowFields stage.
arguments:
-
name: expression
type:
- resolvesToNumber
24 changes: 24 additions & 0 deletions generator/config/accumulator/bottom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# $schema: ../schema.json
name: $bottom

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/'
type:
- accumulator
- window
encode: object
description: |
Returns the bottom element within a group according to the specified sort order.
New in version 5.2: Available in the $group and $setWindowFields stages.
arguments:
-
name: sortBy
type:
- object # SortSpec
description: |
Specifies the order of results, with syntax similar to $sort.
-
name: output
type:
- expression
description: |
Represents the output for each element in the group and can be any expression.
31 changes: 31 additions & 0 deletions generator/config/accumulator/bottomN.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# $schema: ../schema.json
name: $bottomN

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/'
type:
- accumulator
- window
encode: object
description: |
Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group.
New in version 5.2.
Available in the $group and $setWindowFields stages.
arguments:
-
name: 'n'
type:
- resolvesToInt
description: |
Limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group.
-
name: sortBy
type:
- object # SortSpec
description: |
Specifies the order of results, with syntax similar to $sort.
-
name: output
type:
- expression
description: |
Represents the output for each element in the group and can be any expression.
12 changes: 12 additions & 0 deletions generator/config/accumulator/count.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# $schema: ../schema.json
name: $count

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/'
type:
- accumulator
- window
encode: object
description: |
Returns the number of documents in the group or window.
Distinct from the $count pipeline stage.
New in version 5.0.
19 changes: 19 additions & 0 deletions generator/config/accumulator/covariancePop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# $schema: ../schema.json
name: $covariancePop

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/'
type:
- window
encode: array
description: |
Returns the population covariance of two numeric expressions.
New in version 5.0.
arguments:
-
name: expression1
type:
- resolvesToNumber
-
name: expression2
type:
- resolvesToNumber
19 changes: 19 additions & 0 deletions generator/config/accumulator/covarianceSamp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# $schema: ../schema.json
name: $covarianceSamp

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/'
type:
- window
encode: array
description: |
Returns the sample covariance of two numeric expressions.
New in version 5.0.
arguments:
-
name: expression1
type:
- resolvesToNumber
-
name: expression2
type:
- resolvesToNumber
10 changes: 10 additions & 0 deletions generator/config/accumulator/denseRank.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# $schema: ../schema.json
name: $denseRank

link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/'
type:
- window
encode: object
description: |
Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. There are no gaps in the ranks. Ties receive the same rank.
New in version 5.0.
Loading
Loading