### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
support for $out aggregation stage in aggregation pipeline
what we not support :
1. On Mult coordinator setup source and target can not be same
----
#### AI description (iteration 1)
#### PR Classification
New feature
#### PR Summary
This pull request introduces the `$out` aggregation stage to the aggregation pipeline.
- `oss/pg_helio_api/src/aggregation/bson_aggregation_output_pipeline.c`: Added `HandleOut` function to handle the `$out` stage, including parsing, validation, and query mutation for outputting results to a specified collection.
Related work items: #1798580
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
1. Introduces a backend process level collator cache so that we open a collator for a specific collation string once per backend process
2. Uses collation-based sort key generation for string for supporting $in which uses Hashmap for membership check. We wanted the keys of the HashMap to be collation-aware for UTF8 keys.
----
#### AI description (iteration 1)
#### PR Classification
Code enhancement to improve collation handling in string comparison.
#### PR Summary
This pull request refines the string comparison logic using ICU collation in the `bson_compare.c` file.
- `bson_compare.c`: Replaced custom ICU collator creation with `ucol_open` and added error handling for unsupported collations. Closed the collator after use to prevent resource leaks.
- `bson_compare.c`: Added a reference to the ICU documentation for better clarity.
Related work items: #3412412, #3431062, #3456172
### Does this PR have any customer impact?
It fix a bug when using $setWindowFields with range window for shard collection.
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Fix a bug that range window is not processed correctly when using $setWindowFields.
#### How to reproduce
See this case to reproduce it:
```
SELECT mongo_api_v1.insert_one('db', 'collShard', '{ "_id":1, "y": 1, "v": 1}', NULL);
SELECT mongo_api_v1.insert_one('db', 'collShard', '{ "_id":2, "y": 3, "v": 1}', NULL);
SELECT mongo_api_v1.shard_collection('db', 'collShard', '{ "_id": "hashed" }', false);
SELECT document FROM mongo_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collShard", "pipeline": [ { "$setWindowFields": {"sortBy": { "y": 1 }, "output": { "count": { "$count": {}, "window": { "range": [ -1, 0 ] } } } } }, { "$unset": "_id" } ]}');
```
Result:
```
postgres=# SELECT document FROM mongo_catalog.bson_aggregation_pipeline('db', '{ "aggregate": "collShard", "pipeline": [ { "$setWindowFields": {"sortBy": { "y": 1 }, "output": { "count": { "$count": {}, "window": { "range": [ -1, 0 ] } } } } }, { "$unset": "_id" } ]}');
document
--------------------------------------------------------------------------------------------------
{ "y" : { "$numberInt" : "1" }, "v" : { "$numberInt" : "1" }, "count" : { "$numberInt" : "0" } }
{ "y" : { "$numberInt" : "3" }, "v" : { "$numberInt" : "1" }, "count" : { "$numberInt" : "0" } }
(2 rows)
```
#### How to fix
In above case, the result for $count is not correct. It is becuase the WindowClause's parameter `isRangeAsc` is `false` by default.
In unshard collection, the `isRangeAsc` will be set during `transformWindowDefinitions()`. But for shard collection, it does not.
And on the other hand, for $setWindowFields, if a range window is applied, only ASC order is allowed. Thus, we can set `windowClasue->isRangeAsc` to `true` when processing range window cases.
#### After fix

----
#### AI description (iteration 1)
#### PR Classification
Bug fix to correct the range window for shard collection.
#### PR Summary
This pull request fixes a bug where the range window was not correctly set for shard collections.
- `oss/pg_helio_api/src/aggregation/bson_aggregation_window_operators.c`: Ensured range-based bounds require an ascending `sortBy` by setting `inRangeAsc` and `inRangeNullsFirst` to true.
- `pgmongo/src/test/regress/sql/bson_ag...
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Other
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
NA
### Description
Add Number divide API.
----
#### AI description (iteration 1)
#### PR Classification
New feature
#### PR Summary
Introduces a new API for dividing BSON values, handling both decimal and double types, and ensuring division by zero is properly managed.
- Added `DivideBsonValueNumbers` function in `oss/pg_helio_core/src/io/pgbson_utils.c` to perform division on BSON values.
- Updated `oss/pg_helio_core/include/io/bsonvalue_utils.h` to declare the new `DivideBsonValueNumbers` function.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Enable $setWindowFields stage by default
----
#### AI description (iteration 1)
#### PR Classification
Enable `$setWindowFields` stage by default for version 1.22.
#### PR Summary
This pull request enables the `$setWindowFields` stage by default in the configuration for version 1.22.
- Modified `scripts/utils.sh` to remove the manual enabling of `helio_api.enableStageSetWindowFields`.
- Updated `oss/internal/pg_helio_distributed/src/test/regress/postgresql.conf` and `pgmongo/src/test/regress/postgresql.conf` to remove redundant enabling of `helio_api.enableStageSetWindowFields`.
- Changed `oss/pg_helio_api/src/helio_api_init.c` to set `DEFAULT_ENABLE_STAGE_SET_WINDOW_FIELDS` to `true` by default.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
- Port more error codes to OSS
- Disallow new backend tests in pgmongo
----
#### AI description (iteration 1)
#### PR Classification
Porting additional error codes to the open-source version.
#### PR Summary
This pull request ports more error codes to the open-source version and updates related test cases and error handling.
- Added multiple SQL test files in `/pgmongo/src/test/regress/pgmongo_test_baseline`.
- Updated error codes in `commands_create_index_geospatial.out` and `and3.out` test files.
- Modified error handling in `oss/pg_helio_api/src/collation/collation.c` to use new error codes.
- Adjusted error logging in `oss/pg_helio_api/src/commands/insert.c` to include SQL state.
### Does this PR have any customer impact?
No.
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing/Bugfix.
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No.
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No.
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Adding tests for index truncation on missing bson types.
Bugfixes:
1- Off by one error when truncating nested documents.
2- Missing bson type code truncation logic for nested entries.
----
#### AI description (iteration 1)
#### PR Classification
New feature: Added tests for BSON index truncation.
#### PR Summary
This pull request introduces new tests to verify BSON index truncation behavior for various BSON data types.
- Added `bson_index_truncation_binary_tests.sql` to test binary BSON data.
- Added `bson_index_truncation_code_tests.sql` to test code BSON data.
- Added `bson_index_truncation_symbol_tests.sql` to test symbol BSON data.
- Modified `gin_index_term.c` to adjust term truncation logic.
- Updated `bson_schedule` to include new test files.
Related work items: #3412472
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Port more errors to helio for more folders.
----
#### AI description (iteration 1)
#### PR Classification
Code cleanup to port error codes to Helio-specific error codes.
#### PR Summary
This pull request updates various error codes from Mongo-specific to Helio-specific error codes across multiple files.
- `vector_index_kind_impl.c`: Replaced `MongoBadValue` and `MongoFailedToParse` with `ERRCODE_HELIO_BADVALUE` and `ERRCODE_HELIO_FAILEDTOPARSE`.
- `shard_colocation.c`: Updated error codes from `MongoCommandNotSupported`, `MongoBadValue`, and `MongoFailedToParse` to Helio-specific equivalents.
- `bson_update_operators.c`: Changed error codes like `MongoTypeMismatch` and `MongoBadValue` to `ERRCODE_HELIO_TYPEMISMATCH` and `ERRCODE_HELIO_BADVALUE`.
- `parse_error.h`: Replaced `MongoTypeMismatch` with `ERRCODE_HELIO_TYPEMISMATCH`.
- `collection.c`: Updated error codes from `MongoBadValue` and `MongoInvalidNamespace` to Helio-specific equivalents.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Move to helio error codes in pg-helio-core
Enforce hygiene in helio core
Move to helio errors
----
#### AI description (iteration 1)
#### PR Classification
Code cleanup
#### PR Summary
This pull request refactors error handling by replacing Mongo-specific error codes with Helio-specific error codes and updates error messages accordingly.
- Added `CheckNoMongoErrorCodes` function in `/scripts/validate_helio_extension_state.sh` to ensure no Mongo-specific error codes are used.
- Updated error codes and messages in `oss/pg_helio_core/src/query/bson_compare.c` to use Helio-specific codes.
- Modified error handling in `oss/pg_helio_core/src/types/pcre_regex.c` to replace Mongo error codes with Helio error codes.
- Replaced Mongo error codes with Helio error codes in `oss/pg_helio_core/src/io/pgbsonsequence.c`.
- Updated error codes in `oss/pg_helio_core/src/types/decimal128.c` to use Helio-specific codes.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
This pr is forked from $rank and $denseRank pr.
----
#### AI description (iteration 1)
#### PR Classification
New feature: Adding support for `$documentNumber` in BSON aggregation.
#### PR Summary
This pull request introduces support for the `$documentNumber` window aggregation operator in BSON, along with `$rank` and `$denseRank` operators.
- `bson_aggregation_window_operators.c`: Added handlers for `$rank`, `$denseRank`, and `$documentNumber` window operators.
- `metadata_cache.c`: Added OID retrieval functions for the new BSON window functions.
- `bson_aggregation_window_functions.c`: Implemented the window functions for `$rank`, `$denseRank`, and `$documentNumber`.
- `window_aggregate_support--1.21-0.sql`: Created SQL functions for the new BSON window operators.
- `bson_aggregation_pipeline_stage_setWindowFields.sql`: Added test cases for the new window operators.
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
[schema validation] support validation in insertion
Details about evaluation part is here:https://msdata.visualstudio.com/DefaultCollection/CosmosDB/_git/pgmongo/pullRequest/1429339#1724674832
----
#### AI description (iteration 1)
#### PR Classification
New feature: Adds support for schema validation during document insertion.
#### PR Summary
This pull request introduces schema validation for document insertions, ensuring that documents adhere to specified schemas before being inserted into collections.
- `schema_validation.c`: Implements functions for preparing and validating documents against schema validators.
- `insert.c`: Integrates schema validation into the document insertion process.
- `bson_expr_eval.c`: Adds functions to evaluate expressions against documents for validation purposes.
- `schema_validation_insert.sql` and `schema_validation_insert.out`: Adds regression tests for schema validation during insertions.
- `SchemaValidationMetadataTests.cs`: Adds integration tests for schema validation during document insertion.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Fix typo in header guard macro definition that causes build warnings and multiple inclusions of the header file.
WKBBUfferITERATOR_H was replaced by WKBBufferITERATOR_H
----
#### AI description (iteration 1)
#### PR Classification
Bug fix
#### PR Summary
This pull request fixes a typo in the header guard macro definition.
- `include/geospatial/bson_geospatial_wkb_iterator.h`: Corrected the macro definition from `WKBBUfferITERATOR_H` to `WKBBufferITERATOR_H`.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
New feature implementation.
#### PR Summary
This pull request introduces the `$expMovingAvg` aggregation operator to calculate the exponential moving average of numeric values.
- Added new aggregate functions in `oss/pg_helio_api/sql/udfs/aggregation/group_aggregates--1.19-0.sql` for BSON data types.
- Implemented supporting functions in `oss/pg_helio_api/sql/udfs/aggregation/group_aggregates_support--1.19-0.sql`.
- Documented the `$expMovingAvg` operator in `docs/pgmongo/design_docs/data_plane/aggregation_operators/expMovingAvg.md`.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Add more tests from Pgmongo -> pg_helio_distributed.
Move the dollar Ops tests to pg_helio_distributed.
----
#### AI description (iteration 1)
#### PR Classification
Test migration
#### PR Summary
This pull request migrates additional tests to the `pg_helio_distributed` module.
- Added extensive BSON dollar operations and JSON schema query tests in `pg_helio_distributed/src/test/regress/expected/bson_dollar_ops_json_schema_query_tests.out`.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Input validation for user RBAC methods
----
#### AI description (iteration 1)
#### PR Classification
Input validation for user RBAC methods.
#### PR Summary
This pull request adds input validation to ensure that user specifications are provided for various user RBAC methods.
- `src/commands/users.c`: Added checks to ensure user specifications are not null for `create_user`, `drop_user`, `update_user`, and `get_users` methods.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactoring
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Move writer util to write int32 or double
----
#### AI description (iteration 1)
#### PR Classification
Code cleanup
#### PR Summary
Refactored code to move the utility for writing int32 or double values into a common function.
- Removed `WriteStatsAsIntOrDouble` function from `src/commands/coll_stats.c` and replaced its usage with `PgbsonWriterAppendInt32OrDouble`.
- Added `PgbsonWriterAppendInt32OrDouble` function to `src/io/pgbson.c`.
- Updated `pgbson_writer.h` to include the declaration of `PgbsonWriterAppendInt32OrDouble`.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No(ish)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Start using the new Helio error codes. These are of the format M0000->M0ZZZ
Convert helio_core to use M0001 for BadValue
With the new error syntax, the errmsg is the user facing error message.
Any PII Safe messages intended for the server will now be placed under errdetail_log (rather than errhint).
----
#### AI description (iteration 1)
#### PR Classification
New feature: Introduces a new error format and usage.
#### PR Summary
This pull request implements a new error format and updates the usage of error handling across multiple components.
- `logger_hooks.c`: Adds logic to transform client log data and ensure error details are properly set.
- `PostgresMongoResultExtensions.cs`: Refactors error handling to include sanitized error hints and details.
- `error.rs` and `pg.rs`: Adds support for known PostgreSQL error codes and refines error handling.
- `PostgresError.cs` and `PostgresClient.cs`: Updates error properties to include error hints and details.
- Multiple files in `pg_helio_core`: Replaces `ERRCODE_INVALID_TEXT_REPRESENTATION` with `ERRCODE_HELIO_BADVALUE` for better error categorization.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Version update in preparation for 1.21 release
----
#### AI description (iteration 1)
#### PR Classification
Version update in preparation for 1.21 release.
#### PR Summary
This pull request updates the version numbers and prepares the project for the 1.21 release.
- Added release notes template in `/docs/release_notes/pgmongo_1.22.md`.
- Updated version numbers in control files: `/oss/internal/pg_helio_distributed/pg_helio_distributed.control`, `/oss/pg_helio_api/pg_helio_api.control`, `/oss/pg_helio_core/pg_helio_core.control`, and `/pgmongo/pgmongo.control`.
- Added SQL migration scripts for version updates in `/oss/internal/pg_helio_distributed/sql/pg_helio_distributed--1.21-0--1.22-0.sql`, `/oss/pg_helio_api/sql/pg_helio_api--1.21-0--1.22-0.sql`, `/oss/pg_helio_core/sql/pg_helio_core--1.21-0--1.22-0.sql`, and `/pgmongo/sql/pgmongo--1.21-0--1.22-0.sql`.
- Updated SHA1 checksums for SQL scripts in `/pgmongo/sql/sha1/`.
No
Bugfix
No
No
Turned off cost output in one test that has different
output in PG16 vs PG15
added citus installation step to Dockerfile to make
pg_helio_distributed test to pass
----
Bug fix for SQL tests in `pg_helio_api` and `pg_helio_distributed`.
This pull request addresses issues with SQL tests by updating configurations and expected outputs.
- `/oss/.devcontainer/devcontainer.json`: Added Docker build arguments for PostgreSQL and Citus versions, and configured port forwarding.
- `/oss/pg_helio_api/src/test/regress/expected/bson_aggregation_pipeline_tests_geonear.out`: Updated expected output for `bson_aggregation_pipeline` tests to include verbose EXPLAIN output.
- `/oss/.devcontainer/Dockerfile`: Parameterized PostgreSQL and Citus versions, added locale settings, and updated package installations.
- `/oss/pg_helio_api/src/test/regress/sql/bson_aggregation_pipeline_tests_geonear.sql`: Modified SQL test to include verbose EXPLAIN output.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Adding feature counters
----
#### AI description (iteration 1)
#### PR Classification
New feature
#### PR Summary
This pull request adds feature usage counters for user-related operations.
- `feature_counter.c`: Added new feature mappings for user CRUD operations.
- `feature_counter.h`: Defined new feature types for user CRUD operations and updated the maximum feature count.
- `users.c`: Integrated feature usage reporting for user create, drop, update, and get operations.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
Performance improvement for aggregation operations.
#### PR Summary
This pull request optimizes the handling of set aggregation operations by refactoring and adding new parsing and evaluation functions.
- `src/operators/bson_expression_set_operators.c`: Added and refactored functions for parsing and evaluating `$setEquals`, `$setDifference`, `$setIsSubset`, `$anyElementTrue`, `$allElementsTrue`, `$setUnion`, and `$setIntersection` expressions.
- Introduced helper functions for parsing and evaluating set operators with variable and dual operands.
Related work items: #3444465
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Migrate conditional operators (`$ifNull`, `$cond`, `$switch`) to new aggregation framework and ensure correct behavior.
----
#### AI description (iteration 1)
#### PR Classification
Performance improvement for conditional aggregation operations.
#### PR Summary
This pull request refactors and optimizes the handling of arithmetic and boolean aggregation operators to improve performance.
- `bson_expression_arithmetic_operators.c`: Refactored functions to handle pre-parsed arithmetic operations, added helper functions for single, dual, and variable operand parsing and evaluation.
- `bson_expression_boolean_operators.c`: Refactored functions to handle pre-parsed boolean operations, added helper functions for variable operand parsing and evaluation, and a unified boolean operator processing function.
Related work items: #3430332
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
One time upgrade to allow existing flex clusters to create roles
----
#### AI description (iteration 1)
#### PR Classification
New feature to enable existing flex clusters to create roles.
#### PR Summary
This pull request introduces a one-time upgrade to allow existing flex clusters to create roles, specifically targeting the `azure_pg_admin` role.
- `cluster_operations.c`: Added logic to grant roles to `azure_pg_admin` during setup if certain conditions are met.
- `helio_api_init.c`: Introduced a new configuration variable `ClusterAdminRole` with a default value and updated initialization logic.
- `complete_pgmongo_upgrade--1.21-0.sql`: Created a new SQL function to complete the extension upgrade.
- `pgmongo_postgres_flex_userconfig.conf`: Added a new configuration entry for `clusterAdminRole`.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Use new error codes and move to source generators for errors for the C# GW
----
#### AI description (iteration 1)
#### PR Classification
Code cleanup and new feature.
#### PR Summary
This pull request ports CodeGen and new error definitions to the managed Gateway.
- Added comprehensive error definitions in `include/utils/helio_errors.h`.
- Removed `EtwEventWriterGenerator` class and related code from `Cosmos.Core.Trace.EtwEventWriterGenerator/EtwEventWriterGenerator.cs`.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactoring
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Generate error codes that are PG compatible
- Code-gen header file for Mongo Errors
- Generate a text file that can be used for other languages.
- In subsequent changes the existing codebase will be updated to consume these errors.
----
#### AI description (iteration 1)
#### PR Classification
New feature: Generate error codes that are PostgreSQL (PG) compatible.
#### PR Summary
This pull request introduces a new feature to generate error codes that are compatible with PostgreSQL.
- Added `helio_errors.h` with definitions for various Helio error codes and their corresponding MongoDB error codes.
- Created `mongoerrors.csv` to map error names to MongoDB error codes and their ordinal positions.
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Adding support for $rank and $denseRank setWindowFields operator
----
#### AI description (iteration 1)
#### PR Classification
New feature: Implementation of `$rank` and `$denseRank` functions in pgmongo.
#### PR Summary
This pull request introduces the `$rank` window function to the pgmongo implementation, enabling rank-based aggregation operations.
- Added `BsonRankFunctionOid` and `HandleDollarRankWindowOperator` in `metadata_cache.c` and `bson_aggregation_window_operators.c` respectively.
- Implemented `bson_rank` function and `RankContext` struct in `bson_aggregates.c`.
- Updated SQL scripts `window_aggregate_support--1.20-0.sql` and `window_aggregate_support--latest.sql` to include the new `bson_rank` function.
- Declared `BsonRankFunctionOid` in `metadata_cache.h`.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Our Collstats response is not line with the native mongo response.
Native mongo behaviour :
1) When we run collstats the response size and all fields are expected to be Int32
2) If they overflow the range for int32 in response the output is of type double
With this pr we change the PgbsonWriter to reflect the same functionality while sending final response
----
#### AI description (iteration 1)
#### PR Classification
Bug fix for failing `coll_stats` JavaScript test.
#### PR Summary
This pull request addresses a bug in the `coll_stats` function by ensuring the correct data type is used for various statistics. It modifies the test output and the core implementation to handle integer and double values appropriately.
- `/pgmongo/src/test/regress/expected/commands_coll_stats.out`: Updated expected output to reflect correct data types (`$numberInt` and `$numberLong`).
- `/oss/pg_helio_api/src/commands/coll_stats.c`: Introduced `WriteStatsAsIntorDouble` helper function to decide whether to write stats as `int32` or `double`. Updated `WriteCoreStorageStats` and `BuildEmptyResponseMessage` to use this helper function.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
NA
### Description
Ignore apiVersion in command requests
----
#### AI description (iteration 1)
#### PR Classification
Bug fix to ignore the `apiVersion` field in command requests if present.
#### PR Summary
This pull request ensures that the `apiVersion` field is ignored in various command requests, adding it to the list of common spec fields to be ignored.
- Added `apiVersion` to `IgnoredCommonSpecFields` in `commands_common.c`.
- Created new test cases in `commands_crud_ignore_common_spec_fields.sql` and `commands_crud_ignore_common_spec_fields.out` to verify the changes.
- Updated existing test cases in `commands_crud_ignore_common_spec_fields.sql` and `commands_crud_ignore_common_spec_fields.out` to include `apiVersion`.
- Modified `basic_schedule` to include the new test suite.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
BugFix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
This PR has following fix :
1. $bitwise query operator fixes: Validate If document is double it must should be under INT_64 Range.
2. corrected double to INT_64 conversion underflow case to Match with Native mongo behavior, Before change underflow was `-9223372036854775295` but after change underflow `-9223372036854776832`.
with the fix the all operators has improved correctness: $skip, $convert, $toDate, $toLong and all 4 bitwise query operator .
Related work items: #3100851, #3100975
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Test
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Making more compat tests pass
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Fix handling of skip in count command/aggregate
----
#### AI description (iteration 1)
#### PR Classification
Bug fix for handling invalid values in the `$skip` stage of BSON aggregation.
#### PR Summary
This pull request addresses the handling of invalid values in the `$skip` stage of BSON aggregation by improving error messages and type checks.
- `src/aggregation/bson_aggregation_pipeline.c`: Improved error messages for invalid `$skip` values and refined type checks to ensure values are numbers and non-negative.
- `Tests.Integration.Shell.Postgres/custom_js_tests.csv`: Added a new test case for FerretDB issue 401.
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Add aggregation operator: $sampleRate
### Description
Implementation for $sampleRate operator
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
UDF
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Implemented covariancePop & covarianceSamp for setWindowFields
----
#### AI description (iteration 1)
#### PR Classification
Documentation
#### PR Summary
This pull request adds design documentation for the `$covariancePop` and `$covarianceSamp` aggregation operators.
- Added `covariancePop.md` detailing the specification, behavior, examples, implementation plan, and test plan for the `$covariancePop` operator.
- Added `covarianceSamp.md` detailing the specification, behavior, examples, implementation plan, and test plan for the `$covarianceSamp` operator.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactoring
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
rename pgmongo.next_collection_id to helio_api.next_collection_id globally
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Update complete_upgrade to work even if cluster is readonly for full disk
If the control plane sets the cluster into readonly, we prohibit write operations at the planner level. However complete_upgrade should be successful to be able to move the clusters forward when they're on that state.
----
#### AI description (iteration 1)
#### PR Classification
Bug fix to ensure the `complete_upgrade` function works even if the cluster is in a read-only state due to full disk.
#### PR Summary
This pull request updates the `complete_upgrade` function to handle scenarios where the cluster is read-only due to a full disk, ensuring the upgrade process can still proceed.
- `cluster_operations.c`: Modified `command_complete_upgrade` to temporarily disable the read-only setting during the upgrade.
- `extension_upgrade_diskfull_readonly.sql` and `extension_upgrade_diskfull_readonly.out`: Added new regression tests to verify the upgrade process in read-only mode.
- `upgrade_schedule`: Included the new test case for disk full read-only upgrade scenario.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Run helio_compat tests in pgmongo
----
#### AI description (iteration 1)
#### PR Classification
Failing test setup for `helio_compat` tests in `pgmongo`.
#### PR Summary
This pull request sets up a baseline for running `helio_compat` tests in the `pgmongo` project, although the tests are still failing.
- Added expected output for various BSON expression evaluations in `pgmongo/src/test/helio_compat/expected/bson_expr_eval_tests.out`.
### Does this PR have any customer impact?
No.
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix.
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No.
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No.
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
This PR fixes a bad input error when an empty document expression was handled by an addToSet transition.
```
[direct: mongos] test> db.coll1.aggregate([ { $group: { _id: "$_id", items: { $addToSet: { $getField: { field: "a", input: { b: 1 } } } } } } ])
MongoServerError: [ActivityId=03940874-08ea-4df5-ad67-9e1f87499861] Bad input format for addToSet transition.
```
The new implementation will ignore the empty document and continue the aggregation execution.
----
#### AI description (iteration 1)
#### PR Classification
Bug fix to handle empty documents in the `addToSet` transition.
#### PR Summary
This pull request fixes the handling of empty documents in the `addToSet` transition within the BSON aggregation pipeline.
- `oss/pg_helio_api/src/aggregation/bson_aggregates.c`: Added a check to ensure `addToSet` transition skips empty documents.
- `oss/pg_helio_api/src/test/regress/sql/bson_aggregation_pipeline_tests_add_to_set_group.sql` and `oss/pg_helio_api/src/test/regress/expected/bson_aggregation_pipeline_tests_add_to_set_group.out`: Added new test cases to verify the correct handling of empty documents in the `addToSet` transition.
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
Yes (helio_api.enableCollation). Yes.
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Done
### Description
Runtime implementation of collation support in Mongo Find query.
We parse the Mongo collation spec and covert it to an ICU standard collation string. An example string is "und-u-ks-level1-kc-true This string uniquely identify collation-based string comparison logic by Postgres. See: https://www.postgresql.org/docs/current/collation.html
This document tracks the current support matrix for query operators
| Operator | Runtime | Index Pushdown | Comments
| --------- | ---- | ----- | ----
| $eq | Yes | No |
| $gt | Yes | No |
| $gte | Yes | No |
| $lt | Yes | No |
| $lte | Yes | No |
| $ne | Yes | No |
| $in | No* | No | See below
| $nin | No* | No | Do
| $and | Yes | No |
| $not | Yes | No |
| $nor | Yes | No |
| $or | Yes | No |
| $all | Yes | No |
| $elemMatch | Yes | No |
| $positional | N/A | N/A | positional query operators are only used in projections.
| $regex | N/A | N/A | $regex ignores collations in Native Mongo
| $exists | N/A | N/A |
| $size | N/A | N/A |
| $type | N/A | N/A |
| $bitsAllClear | N/A | N/A | Not relevant for Utf8
| $bitsAnyClear | N/A | N/A | Do
| $bitsAllSet | N/A | N/A | Do
| $bitsAnySet | N/A | N/A | Do
| $mod | N/A | N/A | Do
| $range | N/A | N/A | Only applies to Number
| $text | N/A | N/A | Seprate Index, has its own collation spec
| $geowithin | N/A | N/A | Not relevant for Utf8
| $geointersects | N/A | N/A | Do
* $in/$nin is implemented with HashMap that does not support collation friendly Hashkeys
* $regex : collations are ignored with
* $text: $text spec has collation specific parameters
* $rage: For numbers only
This document tracks the current support matrix for update operators/commands
| Operator | Runtime | Index Pushdown |
| --------- | ---- | ----- |
| find_and_modify | No | No |
| updateOne | No | No |
| updateMany | No | No |
| createIndex | No | No |
Tests:
1. All Gated Tests pass when Collation is enabled by default
TODO:
1. Index support [already implemented - but breaking down for easy review]
2. Persist collation info while collection created [already implemented - but breaking down for easy review]
3. $cond, $let
Related work items: #3412359
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Seg fault fix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
- Fix geospatial segmentation fault for $geonear, $near, $nearSpher when no valid geometry found in runtime
### Description
Fix geospatial segmentation fault for $geonear, $near, $nearSpher when no valid geometry found in runtime
----
#### AI description (iteration 1)
#### PR Classification
Bug fix for segmentation fault in `ST_Distance` function when calculating distance for null geometry.
#### PR Summary
This pull request addresses a core dump issue caused by a null pointer reference in the `ST_Distance` function during `$near` queries.
- `oss/pg_helio_api/src/geospatial/bson_geospatial_geonear.c`: Added checks to handle empty geo values and prevent null pointer dereference.
- `pgmongo/src/test/regress/sql/bson_aggregation_pipeline_tests_geonear.sql` and `pgmongo/src/test/regress/expected/bson_aggregation_pipeline_tests_geonear.out`: Added test cases to validate the fix and ensure proper error handling for invalid geo values.
Related work items: #3380924
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
DevOps
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Updated libbson build to remove libicu as a dependency.
----
#### AI description (iteration 1)
#### PR Classification
Build configuration update to remove `libicu` as a dependency.
#### PR Summary
This pull request updates the build configuration for the `libbson` library to remove `libicu` as a dependency.
- `oss/scripts/install_setup_libbson.sh`: Updated build script to disable ICU support by adding `-DMONGOC_ENABLE_ICU=OFF -DENABLE_ICU=OFF` flags.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Port bson basic compare tests to the OSS distributed extension
----
#### AI description (iteration 1)
#### PR Classification
Porting tests to the open-source distributed extension.
#### PR Summary
This pull request ports the BSON basic compare tests to the open-source distributed extension.
- Removed test cases from `pgmongo/src/test/regress/expected/bson_dollar_ops_basic_compare_tests_explain_index_no_bitmap.out`.
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
New feature: Adds support for `$addToSet` in window aggregation stages.
#### PR Summary
This pull request introduces the `$addToSet` operator for window aggregation stages, enhancing the aggregation capabilities.
- `bson_aggregates.c`: Added logic to handle `$addToSet` for both regular and window aggregations, including state management and result finalization.
- `bson_aggregation_window_operators.c`: Implemented the `HandleDollarAddToSetWindowOperator` function to support the new operator in window contexts.
- Updated the `WindowOperatorDefinitions` to include the `$addToSet` operator.
Related work items: #2151565
### Does this PR have any customer impact?
Cx can use $merge stage
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature Enable
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Enabling Merge GUC to True By Default
----
#### AI description (iteration 1)
#### PR Classification
Configuration change to enable a feature by default.
#### PR Summary
This pull request enables the `$merge` stage in the pipeline by default and updates the error message for unsupported target collection creation.
- Modified `oss/pg_helio_api/src/helio_api_init.c` to set `DEFAULT_ENABLE_MERGE_STAGE` to `true`.
- Updated error and hint messages in `pgmongo/src/test/regress/expected/bson_aggregation_stage_merge_tests.out` to reflect the new behavior for `$merge` target collection creation.