Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

PHPLIB-1359 Add tests on Accumulators ($group, $bucket, $bucketAuto, $setWindowFields) #29

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 16, 2024

Fix PHPLIB-1359

https://www.mongodb.com/docs/manual/reference/operator/aggregation/#accumulators---group---bucket---bucketauto---setwindowfields-

For the operators that have accumulator and expression examples on the same page, I added the examples on both.

  • $accumulator already done
  • $addToSet already done
  • $avg accumulator + expression
  • $bottom
  • $bottomN
  • $count the empty object required modifications in Yaml parsing
  • $first already done
  • $firstN accumulator + expression
  • $last already done
  • $lastN
  • $max accumulator + expression
  • $maxN
  • $median accumulator + expression
  • $mergeObjects
  • $min accumulator + expression
  • $percentile accumulator + expression
  • $push
  • $stdDevPop accumulator + expression
  • $stdDevSamp accumulator + expression
  • $sum accumulator + expression
  • $top
  • $topN

@GromNaN GromNaN marked this pull request as ready for review January 17, 2024 14:50
@GromNaN GromNaN requested a review from alcaeus January 17, 2024 14:50
$operator = Yaml::parseFile($file->getPathname());
assert(is_array($operator));
$definitions[] = new OperatorDefinition(...$operator);
$operator = Yaml::parseFile($file->getPathname(), Yaml::PARSE_OBJECT | Yaml::PARSE_OBJECT_FOR_MAP);
Copy link
Member Author

Choose a reason for hiding this comment

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

The option PARSE_OBJECT_FOR_MAP is required to ensure the $count empty object {} from the Yaml is not converted to an empty array. []

@@ -63,6 +63,6 @@ public function __construct(

$this->arguments = array_merge($requiredArgs, $optionalArgs);

$this->tests = array_map(static fn (array $test): TestDefinition => new TestDefinition(...$test), array_values($tests));
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests));
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this line of code is "expert" level.

Copy link
Member

Choose a reason for hiding this comment

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

Splitting this line across multiple lines may just make it a little less "expert" and help tell the closure apart from the arg:

Suggested change
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests));
$this->tests = array_map(
static fn (object $test): TestDefinition => new TestDefinition(...(array) $test),
array_values($tests),
);

sortBy: object(
orderDate: 1,
),
output: object(
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm always using the same way to write the pipelines (using object and not array map), so I don't really cover all the feature.

Expression::numberFieldPath('test03'),
],
p: [0.5, 0.95],
method: 'approximate',
Copy link
Member Author

Choose a reason for hiding this comment

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

This should be an enum.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Have one comment for legibility, but LGTM.

As for the topic of enums, I believe there are a couple of other places where we can consider using an enum (e.g. the unbounded and current identifiers for windows). These have the advantage of making possible values easier to discover.

@@ -63,6 +63,6 @@ public function __construct(

$this->arguments = array_merge($requiredArgs, $optionalArgs);

$this->tests = array_map(static fn (array $test): TestDefinition => new TestDefinition(...$test), array_values($tests));
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests));
Copy link
Member

Choose a reason for hiding this comment

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

Splitting this line across multiple lines may just make it a little less "expert" and help tell the closure apart from the arg:

Suggested change
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests));
$this->tests = array_map(
static fn (object $test): TestDefinition => new TestDefinition(...(array) $test),
array_values($tests),
);

@GromNaN
Copy link
Member Author

GromNaN commented Jan 18, 2024

As for the topic of enums, I believe there are a couple of other places where we can consider using an enum (e.g. the unbounded and current identifiers for windows). These have the advantage of making possible values easier to discover.

Since both values are often used together (at least in examples), we may also make an enum that return both.

@GromNaN GromNaN merged commit 2660e6d into mongodb:0.1 Jan 18, 2024
@GromNaN GromNaN deleted the PHPLIB-1359 branch January 18, 2024 10:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants