Commit Graph
181 Commits
Author SHA1 Message Date
Vinod Sridharan df093213ad Merged PR 1511148: [Upsert] On Update with Upsert, convert the final insert to INSERT ON CONFLICT UPDATE
### 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
On Update with Upsert, convert the final insert to INSERT ON CONFLICT UPDATE
This is to handle a race condition where two threads do SELECT for update -> don't find the doc -> one does the insert, and the other will get a unique conflict when it should just succeed.

----
#### AI description  (iteration 1)
#### PR Classification
New feature

#### PR Summary
This pull request introduces a new feature to handle upserts by converting the final insert to `INSERT ON CONFLICT UPDATE`.
- `oss/pg_helio_api/src/commands/insert.c`: Added `InsertOrUpdateDocument` function to handle upserts.
- `oss/pg_helio_api/src/commands/update.c`: Updated functions to use `InsertOrUpdateDocument` for upsert operations.
- `oss/pg_helio_api/include/commands/insert.h`: Declared the new `InsertOrUpdateDocument` function.
- `oss/internal/pg_helio_distributed/src/test/regress/expected/commands_update.out` and `pgmongo/src/test/helio_compat/expected/commands_update.out`: Added tests for the new upsert behavior.
- `oss/internal/pg_helio_distributed/src/test/regress/sql/commands_update.sql`: Added SQL tests for upsert functionality.
2024-11-19 17:25:36 +08:00
Santiago Fernandez Madero b1e4bcb8f2 Merged PR 1509895: Fix oss index with public RUM after adding hooks to load custom handlers
### 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

Fix oss index with public RUM after adding hooks to load custom handlers

After the hook change, the missingOk argument to load the function was set to false always, but we need to consider scenarios where we're using the public RUM (OSS), so the custom multiandgetbimap function would not be available.

![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1509895/attachments/image.png)

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
Fixes the issue with the OSS index when using public RUM by adding hooks to load custom handlers.
- `api_hooks.c`: Modified `GetMultiAndBitmapIndexFunc` to accept a `missingOk` parameter.
- `rum_custom_join_scan.c`: Updated `RegisterRumJoinScanNodes` to pass `missingOk` to `GetMultiAndBitmapIndexFunc`.
- `api_hooks.h`: Updated function declaration of `GetMultiAndBitmapIndexFunc` to include `missingOk` parameter.
2024-11-12 18:48:09 +08:00
Jia Hu 648d2fc575 Merged PR 1509422: Fix wiki formatting issue and debugging error with inline function
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
format
### 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))
No
### Description
fix document format and debug error with inline function

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a wiki formatting issue and a debugging error with an inline function.
- `schema_validation.h`: Changed the `CheckSchemaValidationEnabled` function from `inline` to `static inline`.
- `reference.md`: Fixed formatting issues by removing and adding backticks.
2024-11-12 18:48:09 +08:00
Zinan Ren 🐾 1e9746818f Merged PR 1487172: [Vector Search][Embedding Gen Part 1] Refactor update operators and search spec to support non-oss
### Does this PR have any customer impact?
Yes

### 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?
pgmongo.enableEmbeddingGeneration, default is false(feature disabled)

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
The goal of this feature is enable an inline embedding generation in vCore based on [azure_ai extension]
(https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/generative-ai-azure-openai)

Related design doc [Inline embedding generation in vCore ](https://microsoftapc-my.sharepoint.com/:w:/g/personal/zhli2_microsoft_com/Ea2uDc0c0FBNr-fpoMdHIPUBJiA5yXZ-xRRNWGYEBqZ38Q?e=dQdU7i&ovuser=72f988bf-86f1-41af-91ab-2d7cd011db47%2Crongwa%40microsoft.com&clickparams=eyJBcHBOYW1lIjoiVGVhbXMtRGVza3RvcCIsIkFwcFZlcnNpb24iOiI0OS8yNDAzMTQxNDcxMiIsIkhhc0ZlZGVyYXRlZFVzZXIiOmZhbHNlfQ%3D%3D)
![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1339487/attachments/image.png)

- Feature Flag
**pgmongo.enableEmbeddingGeneration**

- Feature counter
**update_operator_vector_gen_embeddings**
**search_vector_gen_embeddings**

- Onboard AOAI resource([Part 3 PR](https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1478366))
```
SELECT create_distributed_table('azure_ai.settings','key');

SELECT azure_ai.set_setting('azure_openai.endpoint','https://localhost.openai.azure.com');
SELECT azure_ai.set_setting('azure_openai.subscription_key','<api-key-placeholder>');

ALTER SYSTEM SET pgmongo.azureOpenAIEmbeddingDeploymentName = 'text-embedding-ada-002';
SELECT pg_reload_conf();
SELECT run_command_on_workers('ALTER SYSTEM SET pgmongo.azureOpenAIEmbeddingDeploymentName = ''text-embedding-ada-002''');
SELECT run_command_on_workers('SELECT pg_reload_conf()');

```

- Update command
```
SELECT mongo_api_v1.update('db',
    '{"update":"generate_embedding_pipeline",
      "updates":[
             {"q":{},"u":{"**$generateEmbeddings**":{"a":"embeddings"}}, "multi":true}
      ]}'
);
```

- Vector search
```
SELECT document FROM bson_aggregation_pipeline('db',
     '{ "aggregate": "generate_embedding_pipeline",
        "pipeline": [
               { "$search": {
                         "cosmosSearch": { "query": "some sentence", "k": 4, "path": "embeddings", "efSearch": 2 }  }
                  } ,
               { "$count": "_id" }
        ],
        "cursor": {}
      }'
);
```

----
#### AI description  (iteration 1)
#### PR Classification
Refactor to support non-OSS embedding generation and vector search.

#### PR Summary
This pull request refactors update operations and search specifications to support embedding generation in non-OSS environments.
- Added `vector_g...
2024-11-12 18:48:09 +08:00
Zinan Ren 🐾 4742ecce61 Merged PR 1487201: [Vector Search][Embedding Gen Part 2] Integrate azure_ai extension and add local tests
### 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

- Create azure_ai extension if it is available( in flex cluster)
- Add mock aoai server
- Add local only tests which will never be run in CI pipeline

----
#### AI description  (iteration 1)
#### PR Classification
New feature

#### PR Summary
This pull request integrates the `azure_ai` extension and adds local tests for embedding generation using a mock AOAI server.
- Added `scripts/mock_aoai/aoai_mock_server.py` to mock AOAI API server for local testing.
- Added `pgmongo/src/test/regress/sql/bson_aggregation_pipeline_tests_vector_gen_embedding.sql` and `pgmongo/src/test/regress/expected/bson_aggregation_pipeline_tests_vector_gen_embedding.out` for embedding generation tests.
- Updated `pgmongo/src/infrastructure/process_utility_hook.c` to check and create the `azure_ai` extension if available.
- Added `scripts/mock_aoai/setup_and_start_mock_server.sh` to set up and start the mock AOAI server.
- Modified `pgmongo/src/test/regress/Makefile` to include embedding generation tests with the mock server.
2024-11-12 18:48:09 +08:00
Jia Hu 778bc161e3 Merged PR 1452968: [schema validation] apply on general update
### 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)
yes
### 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
apply schema validation on general update

####Comments to follow:https://msdata.visualstudio.com/DefaultCollection/CosmosDB/_git/pgmongo/pullRequest/1452968#1729531108

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Schema validation applied on general update operations.

#### PR Summary
This pull request introduces schema validation for update operations, ensuring documents comply with defined schemas during updates.
- Added `command_schema_validation_against_update` function and `ValidateSchemaOnDocumentUpdate` in `schema_validation.c` to handle schema validation during updates.
- Updated `bson_expr_eval.h` to include `ExprEvalState` struct definition.
- Modified `update.c` to integrate schema validation logic into batch and single document update processes.
- Enhanced `schema_validation_insert.sql` with tests for update operations involving schema validation.
2024-11-12 18:48:09 +08:00
Santiago Fernandez Madero 48aefab508 Merged PR 1504921: Add hooks to load specific index handler and multiandbitmap function
### 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 adds 2 hooks.
1. To override the default index am routine for the index handler.
2. To override the multiandbitmap function.

Also, adds some explain improvements and pushes limit down to the multiandbitmap.
2024-11-12 18:48:09 +08:00
Ujjwal Agrawal 5e68dee1bc Merged PR 1467812: [BugFix] $setOnInsert no-op instead of error with upsert: false
### 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

make setOnInsert no-op instead of error

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a bug where the `$setOnInsert` operator would cause an error instead of being a no-op when `upsert` is set to `false`.

For example,
mongos> coll.find()
{ "_id" : "double", "v" : 42.13 }
{ "_id" : "array", "v" : [ 42 ] }
mongos> db.runCommand({update: 'test', updates: [{q: {_id: 'double'}, u: {$setOnInsert: {'v.foo': NumberInt(1)}}}]})
{
        "n" : 0,
        "nModified" : 0,
        "writeErrors" : [
                {
                        "index" : 0,
                        "code" : 28,
                        "errmsg" : "Cannot create field 'v' in element {v : 42.13}"
                }
        ],
        "ok" : 1
}

mongo returns { "n" : 1, "nModified" : 0, "ok" : 1 }

Related work items: #3463180
2024-11-04 17:14:58 +08:00
Cornelius Boateng ee9c5de90c Merged PR 1453287: [Perf] Type Aggregation Ops
### Does this PR have any customer impact? No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf

### 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)) No

### Description
Migrate `$isNumber`, `$type`, `$toBool`, `$toObjectId`, `$toInt`, `$toLong`, `$toString`, `$toDate`, `$toDouble`, `$toDecimal`, and `$convert` to the new aggregation framework.

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement for type aggregation operations.

#### PR Summary
This pull request optimizes the handling of type aggregation operations, specifically focusing on the `$convert` and `$makeArray` expressions.
- `src/operators/bson_expression_type_operators.c`: Refactored the `$convert` expression to pre-parse and handle arguments more efficiently, reducing redundant evaluations and improving error handling.
- Added new functions to handle pre-parsed `$convert` and `$makeArray` expressions, ensuring better performance and cleaner code structure.

Related work items: #3458660
2024-11-04 17:14:58 +08:00
Shuai Tian f8c366966d Revert "HelioDB Push 2024-10-31" (#76)
Reverts microsoft/heliodb#75, redo the merge instead of squash merge
which discarded the commit history
2024-11-04 14:38:52 +08:00
69edcc3556 HelioDB Push 2024-10-31 (#75)
Co-authored-by: Deepak Pemmaraju <deepakpe@microsoft.com>
Co-authored-by: Cornelius Boateng <cboateng@microsoft.com>
Co-authored-by: Ujjwal Agrawal <uagrawal@microsoft.com>
Co-authored-by: Jia Hu 👻 <jiahu2@microsoft.com>
Co-authored-by: Jayanta Mondal <jmondal@microsoft.com>
Co-authored-by: Vinod Sridharan <visridha@microsoft.com>
2024-10-31 16:09:00 +08:00
Cornelius Boateng 894e98f0db Merged PR 1461699: [Perf] Array Aggregation Operators
### 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

more

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement for array aggregation operators.

#### PR Summary
This pull request optimizes the handling of array aggregation operators by refactoring and consolidating code.
- `src/operators/bson_expression_array_operators.c`: Refactored the `$filter` operator parsing and processing, including error handling and validation.
- Consolidated and optimized the `$slice`, `$isArray`, `$in`, `$size`, `$arrayElemAt`, `$first`, `$last`, `$objectToArray`, `$arrayToObject`, and `$concatArrays` operators.
- Improved error messages and validation checks for various array operations.

Related work items: #3458685
2024-10-25 09:11:39 +03:00
Deepak Bisht 1225b7ea85 Merged PR 1490664: [InternalError] [Fix] Too many args
### 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
For `$group` and `$setWindowFields` we tend to create `bson_repath_and_build` function expression with the path and values as arguments to the function, if this argument list goes beyond 100 its an internal error.

So with this PR huge number of aggregates are broken down using functions expression of `bson_dollar_merge` and `bson_repath_and_build`.
e.g If there are 110 groupby operators then the projector will be of this form.

```
bson_dollar_merge_documents(
    bson_repath_and_build(<50 operators>),
    bson_dollar_merge_documents(
        bson_repath_and_build(<50 operators>),
        bson_repath_and_build(<10 operators>)
    )
)
```

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses an issue with handling too many arguments in aggregation functions by introducing a new method to manage large numbers of arguments.
- `bson_aggregation_pipeline.c`: Added `GenerateMultiExpressionRepathExpression` function to handle cases where the number of arguments exceeds `FUNC_MAX_ARGS`.
- `bson_aggregation_pipeline.c`: Updated `HandleGroup` to use the new function for generating repath expressions.
- `setwindowfields_and_group_compliance.sql`: Added tests to verify the handling of multiple arguments in aggregation functions.
- `bson_aggregation_window_operators.c`: Modified `HandleSetWindowFieldsCore` to use the new function for repath expressions.
- `bson_aggregation_pipeline_private.h`: Declared the new function for generating multi-expression repath expressions.
2024-10-25 09:11:39 +03:00
Deepak Bisht cb8964171d Merged PR 1487560: [Oss] Test migrations part 14 [9 tests]
### 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))
Test migration

### Description
Move miscellaneous tests from pgmongo to helio_distributed

----
#### AI description  (iteration 1)
#### PR Classification
Test migration

#### PR Summary
This pull request adds a new test file to validate collection management functionalities.
- Added `oss/internal/pg_helio_distributed/src/test/regress/expected/collection_management.out` to test various collection operations such as creation, insertion, querying, renaming, and dropping collections.
2024-10-25 09:11:39 +03:00
Parag Jain d3db854dae Merged PR 1485054: [Perf] [Update] Query Positional Update 10x faster for 1 Lakh Elements
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf

### 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
query :
`
db.test.updateOne(
    { _id: ObjectId("670e3a9f9b192eb7f2f1cce7"), "items.id": 99999},
    { $set: { "items.$.status": "asdasasasddd" } }
)`

num elements in array items: `100000`

Time taken before: `120265 Ms'
Time taken after improvement: `250 Ms'
**Perf Gain: 10 x**.

**Changes Description:**
Previously, for each element in the array of the source document (O(n)), we were attempting to match it against positional qualifiers, which was also O(n), resulting in a total complexity of O(n²).

However, now we evaluate and find the index only the first time we encounter a positional node, and then reuse that index for all subsequent elements in the source document, reducing the complexity to O(n).

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement

#### PR Summary
This pull request optimizes the query positional update process, making it 10x faster for handling 1 lakh elements.
- `bson_update_operators_workflow.c`: Added `indexOfPositionalTypeQueryFilter` parameter to various functions to avoid redundant evaluations and improve performance.
2024-10-25 09:11:39 +03:00
Vinod Sridharan 27496ae4d2 Merged PR 1487161: Support $comment 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)
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 parsing and ignoring the $comment query operator.

----
#### AI description  (iteration 1)
#### PR Classification
New feature

#### PR Summary
This pull request adds support for the `$comment` operator in MongoDB queries.
- Added `$comment` operator to `QueryOperators` in `mongo_query_operator.c`.
- Updated `query_operator.c` to handle and ignore `$comment` during query processing.
- Added tests for `$comment` operator in `bson_aggregation_pipeline_tests.sql` and `bson_aggregation_pipeline_tests.out`.
- Defined `QUERY_OPERATOR_COMMENT` in `mongo_query_operator.h`.
2024-10-25 09:11:39 +03:00
Vinod Sridharan 0489b4dce6 Merged PR 1486731: [Perf] Improve update performance by preparing the update candidate
### 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.

#### PR Summary
This pull request aims to enhance the performance of the update operation by preparing the update candidate more efficiently.
- `src/commands/update.c`: Added logic to use precompiled query plans for update operations, reducing execution time.
- `include/infrastructure/helio_plan_cache.h`: Defined new query plan IDs for selecting update candidates.
2024-10-17 11:43:08 +03:00
Zinan Ren 🐾 1222508d23 Merged PR 1485084: [Vector Search][DiskANN] Re-order search results after filtering
### 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
The results of vector search + filtering on the DiskANN index might become unordered after iterative searches. It's necessary to re-order the results.

Adds a wrapper select query to the join query and re-order by the orderVar.
To force the planner to re-order the query,

`SELECT document FROM (JOIN c1 ON c1.ctid = c2.ctid limit k) ORDER BY c1.orderVal + 0`

----
#### AI description  (iteration 1)
#### PR Classification
Enhancement to re-order search results after filtering in vector search using DiskANN.

#### PR Summary
This pull request introduces a mechanism to re-order search results after applying filters in vector search using DiskANN.
- `src/aggregation/bson_aggregation_vector_search.c`: Added a new function `ReorderQueryResults` to wrap the join query and re-order results by a specified variable.
- `src/test/regress/expected/bson_aggregation_pipeline_tests_vector_diskann.out`: Updated expected output to reflect the new query structure and re-ordering logic.
2024-10-17 11:43:08 +03:00
Deepak Bisht d325973fd0 Merged PR 1424623: $text and $geoNear index support enhancement for mandatory index usage
### 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))
- $geoNear, $near and $nearSphere queries will require suitable geospatial indexes to be present in the collection.

### Description
Make $geoNear require index and fail if no suitable index is found.
Also move $text to same infrastructure to mandate index usage

Steps:
- Check if the index paths are created for Geonear and Text queries in the planner.
- If not update the query tree to only have quals needed to generate the index path and again try to create index path using
`create_index_paths`.
- If the index paths are created then revert back to original query but retain the index path created and allow the query.
- else return error that the indexes were not found for the query
- Clean customsetup.js to not pass key if key is missing is JStest that is handled on the backend now

----
#### AI description  (iteration 1)
#### PR Classification
Enhancement for mandatory index usage in `$text` and `$geoNear` queries.

#### PR Summary
This pull request enhances the support for mandatory index usage in `$text` and `$geoNear` queries by ensuring the appropriate index paths are enforced.
- `planner.c`: Added functions `ProcessQueryOperatorsWithSortClauses` and `ForceIndexForQueryOperators` to handle index path enforcement for special query operators.
- `metadata_cache.c`: Introduced functions `BsonGistGeographyOperatorFamily` and `BsonGistGeometryOperatorFamily` to fetch OIDs for BSON GIST spherical geometries.
- `helio_bson_text_gin.h`: Added `ForceIndexQueryOperatorData` struct to manage index enforcement for special query operators.
- `index_support.c`: Updated `ProcessRestrictionInfoAndRewriteFuncExpr` to set `QUERY_OPERATOR_TEXT` type and handle text index enforcement.
- Removed legacy test cases for `$nearSphere` with coordinate pairs from `bson_query_operator_near_nearsphere.out`.
2024-10-17 11:43:08 +03:00
Cornelius Boateng caf2c7834d Merged PR 1448751: [let 3/n] Let Support for $groupBy on Sharded Collections
### 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

let support for group by on sharded collections
For now, we wrap the `bson_expression_get` with a `helio_core_bson_to_bson` function

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Support for `$groupBy` on sharded collections.

#### PR Summary
This pull request introduces support for the `$groupBy` aggregation operation on sharded collections, along with various enhancements and tests for aggregation pipeline operations.
- Added new test cases in `/pgmongo/src/test/regress/sql/bson_aggregation_pipeline_tests_let.sql` to validate `$groupBy` and other aggregation operations on sharded collections.
- Introduced `helio_core_bson_to_bson` function in `/oss/pg_helio_api/src/aggregation/bson_aggregation_pipeline.c` for BSON type conversion.
- Updated metadata cache in `/oss/pg_helio_api/src/metadata/metadata_cache.c` to include OID for the new BSON conversion function.
- Created SQL scripts for BSON coercion compatibility in `/oss/pg_helio_api/sql/udfs/aggregation/bson_coercion_compat--1.22-0.sql` and `/oss/pg_helio_api/sql/udfs/aggregation/bson_coercion_compat--latest.sql`.
- Updated control files to new versions in `/oss/pg_helio_api/pg_helio_api.control`, `/oss/pg_helio_core/pg_helio_core.control`, and `/pgmongo/pgmongo.control`.
2024-10-17 11:43:08 +03:00
Vinod Sridharan dd58525877 Merged PR 1482107: [Perf] Fix local shard pushdown not working in all cases
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf

### 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
When looking at the local shard, if the collection was cached when the table was created then the local shard was never registered and those backends saw degraded perf - this fixes it.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to address local shard pushdown not working in all cases.

#### PR Summary
This pull request fixes issues with local shard pushdown by ensuring proper handling of shard names and remote shard status.
- `src/metadata/collection.c`: Added `TrySetCollectionShard` function to handle shard name setting and remote status.
- `src/distribution/distributed_hooks.c`: Updated `TryGetShardNameForUnshardedCollectionCore` to return empty string instead of NULL in specific cases and added logging.
- `include/metadata/collection.h`: Added `isShardRemote` field to `MongoCollection` struct.
- `include/api_hooks.h`: Updated documentation for `TryGetShardNameForUnshardedCollection` to reflect new return values.
- `src/commands/aggregation_commands.c`: Minor change to use `DatumGetTextPP` instead of `DatumGetTextP`.
2024-10-17 11:43:08 +03:00
Parag Jain 45b6958171 Merged PR 1479514: [Cleanup] : "helio_api_internal" to HelioApiInternalSchemaName
### 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
[Cleanup] : "helio_api_internal" to ApiMainInternalSchemaName

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup

#### PR Summary
This pull request refactors the code by introducing a new variable `ApiMainInternalSchemaName` to replace hardcoded instances of "helio_api_internal".
- `metadata_cache.c`: Added `ApiMainInternalSchemaName` and replaced hardcoded "helio_api_internal" with the new variable.
- `delete.c`, `insert.c`, `update.c`: Updated SQL queries to use `ApiMainInternalSchemaName` instead of hardcoded schema name.
- `current_op.c`, `mongo_query_operator.c`: Replaced hardcoded "helio_api_internal" with `ApiMainInternalSchemaName`.
- `metadata_cache.h`: Declared the new variable `ApiMainInternalSchemaName`.
2024-10-10 11:17:14 +03:00
Zinan Ren 🐾 5a91bdffbc Merged PR 1438545: [Vector Search][DiskANN Part 4 - Backend] Add diskann index to pgmongo
### 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: Add DiskANN index support to pgmongo for vector search.

#### PR Summary
This pull request introduces DiskANN index support to the pgmongo backend, enabling efficient vector search capabilities.
- Added extensive SQL tests for DiskANN index creation, parameter validation, and search operations in `bson_aggregation_pipeline_tests_vector_diskann.sql`.
- Implemented new test cases in `SearchTests.cs` to validate DiskANN index functionality, including index creation, search operations, and error handling.
- Updated expected output in `bson_aggregation_pipeline_tests_vector_prefilter.out` to reflect new DiskANN index tests and results.
2024-10-10 11:17:14 +03:00
Vinod Sridharan d3b352e197 Merged PR 1478219: [Perf] Improve perf in the cursor generation
### Does this PR have any customer impact?
no

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf

### 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
Only generate cursorId if the query has a continuation. (seen to take ~2% backend CPU of a ycsb read workload).

Also remove some functions that are long deprecated.

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement

#### PR Summary
This pull request aims to improve performance in cursor generation by removing deprecated functions and related tests.
- Removed deprecated cursor-related functions from `oss/pg_helio_api/src/commands/cursors.c`.
- Deleted test files `pgmongo/src/test/regress/expected/pgmongo_get_cursor_page_tests.out` and `pgmongo/src/test/regress/sql/pgmongo_get_cursor_page_tests.sql`.
- Updated `pgmongo/src/test/regress/expected/bson_aggregation_stage_merge_tests.out` to reflect changes in cursor ID handling.
- Added deprecation error messages for cursor-related functions in `pgmongo/src/function_stubs.c`.
2024-10-10 11:17:14 +03:00
Cornelius Boateng 80077a901c Merged PR 1459965: [Perf] String Aggregation Ops
### 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 string aggregation operations.

#### PR Summary
This pull request refactors and optimizes string aggregation operations, focusing on performance improvements.
- Removed redundant functions and added new parsing and handling functions for `$regexFind`, `$regexMatch`, and `$regexFindAll` in `bson_expression_string_operators.c`.
- Refactored existing string operations like `$concat`, `$toUpper`, `$toLower`, `$strLenBytes`, `$strLenCP`, `$split`, `$trim`, `$ltrim`, and `$rtrim` to use a more efficient parsing and handling framework in `bson_expression_string_operators.c`.
- Introduced helper functions for parsing and evaluating string operators with one, two, and three operands in `bson_expression_string_operators.c`.

Related work items: #3458666
2024-10-03 10:48:48 +03:00
Vinod Sridharan cdc00f176d Merged PR 1472614: [AddNode] Fix up add node for distribution
### 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?
Yes

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

Fix up add node to work - after add node create table fails - fix this up - This is because the reference tables for collections aren't replicated to the new node so we can't replicate the table + create shards on that node in the same command.

Check on create table if all shards have reference tables - if not call replicate_reference_tables on create.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses an issue with node addition in a distributed system by ensuring metadata tables are properly replicated.
- `distributed_hooks.c`: Added `EnsureMetadataTableReplicatedCore` function to ensure metadata tables are replicated across nodes.
- `helio_distributed_init.c` (new file): Introduced initialization for distributed configurations, including a new GUC `EnableMetadataReferenceTableSync`.
- `pgmongo.c`: Moved read concern level definitions and configurations from `pg_helio_api` to `pgmongo`.
- `api_hooks.c`: Added `EnsureMetadataTableReplicated` function to check and replicate metadata tables.
- `create_collection_core.c` and `sharding.c`: Integrated `EnsureMetadataTableReplicated` to ensure metadata tables are handled during collection creation and sharding.
2024-10-03 10:48:48 +03:00
Parag Jain 07a4125ae5 Merged PR 1469364: [Perf] Delete directly from shard in delete one if available
### 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
Delete directly from shard in delete one if available

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup and deprecation.

#### PR Summary
This pull request deprecates the `command_delete_one` function and refactors the deletion logic to directly delete from shards if available.
- `oss/pg_helio_api/src/commands/delete.c`: Deprecated `command_delete_one` function and refactored deletion logic to use shard-specific tables.
- `oss/pg_helio_api/src/test/regress/expected/commands_delete.out` and `oss/pg_helio_api/src/test/regress/sql/commands_delete.sql`: Removed tests for the deprecated function and updated tests to use `find_and_modify` with the remove option.
- Deleted `pgmongo/src/test/regress/expected/commands_delete.out` and `pgmongo/src/test/regress/sql/commands_delete.sql` as they are no longer needed.
2024-10-03 10:48:48 +03:00
Cornelius Boateng d5954f7381 Merged PR 1470292: [Perf] Date Aggregation Ops
### Does this PR have any customer impact? No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf

### 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

Migrate date aggregation operators to new aggregation framework.

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement

#### PR Summary
This pull request migrates date aggregation operators to a new framework to enhance performance.
- `src/operators/bson_expression_date_operators.c`: Refactored functions to separate parsing and execution of date part operators, added new helper functions for handling pre-parsed expressions.
- Updated function names to reflect the new parsing and execution separation.
- Improved handling of timezone application and constant expression evaluation.

Related work items: #3458680
2024-10-03 10:48:48 +03:00
Vinod Sridharan 472d3182a5 Merged PR 1469479: [OSS] Bugfixes from OSS and Incidents
### 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)
Yes

### 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
- Invalidate Collection cache trigger was missing in OSS
- Explain should show IXScan if the index had object_id
- ErrCode 16020 should be Location16020 and not EXPRESSIONTAKESEXACTLYNARGS
- row_get_bson should be prefixed with schema.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses several bugs identified from OSS and incidents, including updates to SQL functions, error codes, and triggers.
- Added new SQL functions and triggers in `collection_metadata_functions--1.23-0.sql` and updated `collection_metadata_functions--latest.sql`.
- Modified `PostgresExplainHelper.cs` to refine the condition for reporting `COLLSCAN`.
- Updated error codes in `helio_errors.h`, `mongoerrors.csv`, and `helio_codes.txt`.
- Adjusted SQL queries in `users.c` and `create_indexes_background.c` to use `CoreSchemaName`.
- Added a new trigger in `collection_metadata--1.23-0.sql` and included it in `pg_helio_api--1.22-0--1.23-0.sql` and `pgmongo--1.22-0--1.23-0.sql`.
2024-10-03 10:48:48 +03:00
Cornelius Boateng 3e68960e3c Merged PR 1461259: [Perf] Objects Aggregation Operators
### 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

$mergeObjects

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement for object aggregation operators.

#### PR Summary
Refactors and optimizes the handling of `$mergeObjects` aggregation operator to improve performance.
- `src/operators/bson_expression_object_operators.c`: Refactored `HandleDollarMergeObjects` to `ParseDollarMergeObjects` and `HandlePreParsedDollarMergeObjects`, optimizing argument parsing and result processing.
- `include/operators/bson_expression_operators.h`: Updated function declarations to reflect the new parsing and handling methods.
- `src/operators/bson_expression.c`: Updated the operator expressions array to use the new parsing and handling functions for `$mergeObjects`.
2024-09-26 17:53:12 +03:00
Deepak Bisht 3eb64de267 Merged PR 1467661: [Cleanup][backend] Remove legacy errors and all referrences completely
### 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))
NA

### Description
remove legacy errors completely

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup

#### PR Summary
This pull request removes legacy MongoDB error handling code and all related references.
- Deleted `mongo_errors.h`.
- Removed `CheckNoMongoErrorCodeHeader` function and related calls from `scripts/validate_helio_extension_state.sh`.
- Updated `error_utils.c` to remove legacy MongoDB error handling logic.
- Deleted deprecated functions from `helio_distributed_test_helpers.sql` and `pgmongo_test_helpers.sql`.
- Updated expected test outputs in `helio_distributed_test_helpers.out` and `pgmongo_test_helpers.out` to reflect the removal of deprecated functions.
2024-09-26 17:53:12 +03:00
Ujjwal Agrawal dc157bd631 Merged PR 1446886: $first(N) & $last(N) implementation for $setWindowFields stage
### 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)
Yes
### 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

----
#### AI description  (iteration 1)
#### PR Classification
New feature implementation for the `$setWindowFields` stage.

#### PR Summary
This pull request implements the `$first(N)` and `$last(N)` aggregation functions for the `$setWindowFields` stage.
- Added new aggregate functions in `oss/pg_helio_api/sql/udfs/aggregation/group_aggregates--1.21-0.sql` for `BSONFIRST`, `BSONLAST`, `BSONFIRSTN`, `BSONLASTN`, and their sorted variants.

Related work items: #2151585, #2151587
2024-09-19 20:36:13 +03:00
Jinrui Zhang 55b25d9c55 Merged PR 1423500: Implementation of $fill stage
This PR includes two parts:

1. The design doc of $fill
2. The implementation of $fill using `rewrite` way. Refer design doc [here](https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1423500?_a=files&path=/docs/pgmongo/design_docs/data_plane/aggregation_stages/fill.md).

3. Extract bson_expression_partition_by_fields_get() as a common method. So that, some related changes are:

     a. densify's parse stage is changed
     b. densify's unit tests is changed due to method name change
     c. densify's original method for partitionByFields is removed

**Noticed:**
This implementation is based on the impl of `$linearFill` and `$locf`.
2024-09-19 20:36:13 +03:00
Deepak Bisht 91e5f2226f Merged PR 1458099: [Final] [Port Errors] - Move all errors to helio_errors, remove all referrences to mongo_errors.h
### 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)
yes

### 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
1. Move all legacy errors to new helio errors
2. Remove all refs to mongo_errors.h excluding error_utils.c , there is function which needs backword compatibility
3. Update `scripts/validate_helio_extension_state.sh` to enforce all validations on oss/pg_helio_api parent directory instead of individual sub directories

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup and deprecation.

#### PR Summary
This pull request moves all error handling to `helio_errors` and removes references to `mongo_errors.h`, deprecating certain functions.
- `error_utils.c`: Deprecated `command_throw_mongo_error` and `command_convert_mongo_error_to_postgres` functions.
- `mongo_errors.h`: Removed Mongo error handling code and redefined error code checks.
- `validate_helio_extension_state.sh`: Updated validation script to remove checks for `mongo_errors.h`.
- Added new SQL functions for database commands in `kill_op--1.22-0.sql`, `get_shard_key_value--1.22-0.sql`, and `reindex--1.22-0.sql`.
- Updated test files to reflect deprecation changes in error handling functions.
2024-09-19 20:36:13 +03:00
Amit Prabhudesai 8fdb33dc6a Merged PR 1454239: [OSS] Port more errors to oss (M of N)
### 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
[OSS] Port more errors to oss (M of N)

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup and error handling improvement.

#### PR Summary
This pull request ports more error codes to the OSS (Open Source Software) version, replacing existing error codes with `ERRCODE_HELIO_*` equivalents and improving error detail logging.
- `bson_aggregation_output_pipeline.c`: Replaced various `Mongo*` error codes with `ERRCODE_HELIO_*` equivalents and updated error messages to use `errdetail_log`.
- `bson_aggregation_pipeline.c`: Updated error handling to use `ERRCODE_HELIO_*` equivalents and improved error detail logging.
- `bson_aggregation_nested_pipeline.c`: Replaced `Mongo*` error codes with `ERRCODE_HELIO_*` equivalents and enhanced error detail logging.
- `bson_project_operator.c`: Updated positional projection error handling to use `ERRCODE_HELIO_*` equivalents.
- `commands_update.out`: Updated expected error codes in test outputs to match new `ERRCODE_HELIO_*` values.
2024-09-12 13:51:02 +03:00
Duan Pei✨ 7fd8660ac4 Merged PR 1363174: [Feature] $maxN/$minN Aggregation Accumulator
### 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

We cannot reuse the logic of firstN in the sort stag because the sort by key of the sort stage is a field, and the input and N of maxN are both expressions. maxN needs to sort the entire input expression.

for example :
input can be a expression:
![image (10).png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1363174/attachments/image%20%2810%29.png)

N also can be a expression:
![image (11).png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1363174/attachments/image%20%2811%29.png)

before the transition function, we need to evaluate input and n.

In the new implementation, we maintain a binaryHeap, the top of heap is maximum/minimum value.

For maxN:
**In transition funciton** :we need to maintain a small root heap and compare the current value with the top of the heap (minimum value). If the current value is greater than the top of the heap (minimum value), then we will pop the top of the heap and insert the current value.

**In the combine function,** each value of the left heap needs to be compared with the top of the right heap. If the conditions are met, the top of the right heap is popped out and the value is inserted. Each time, it is popped out from the left heap until the left heap is empty.
2024-09-12 13:51:02 +03:00
Cornelius Boateng 1181330b3b Merged PR 1450898: [Perf] Miscellaneous Aggregation Ops
### Does this PR have any customer impact?

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf

### 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
Migrate `$rand` and `$meta` to the new aggregation framework.
$rand does not need to exploit caching random constant values

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement for miscellaneous aggregation operations.

#### PR Summary
This pull request optimizes and refactors various aggregation operations to enhance performance.
- Added and reordered function declarations in `include/operators/bson_expression_operators.h` for better organization.
- Implemented `ParseDollarRand` and `HandlePreParsedDollarRand` functions in `src/operators/bson_expression_miscellaneous_operators.c` to handle `$rand` expressions.
- Added `ParseDollarMeta` and `HandlePreParsedDollarMeta` functions in `src/operators/bson_expression_miscellaneous_operators.c` to handle `$meta` expressions.
- Updated `src/operators/bson_expression.c` to integrate new parsing and handling functions for `$rand` and `$meta` expressions.

Related work items: #3458675
2024-09-12 13:51:02 +03:00
Deepak Bisht ccc656e5f0 Merged PR 1454152: Port errors for geospatial, command, index_am folders
### 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))
NA

### Description

Port errors for geospatial, command, index_am folders

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup

#### PR Summary
This pull request updates error codes and messages in the geospatial, command, and index_am folders to use the new `ERRCODE_HELIO` format.
- `src/geospatial/bson_geospatial_geonear.c`: Replaced `MongoTypeMismatch` and `MongoBadValue` with `ERRCODE_HELIO_TYPEMISMATCH` and `ERRCODE_HELIO_BADVALUE`.
- `src/commands/create_indexes.c`: Updated various error codes to `ERRCODE_HELIO_*` equivalents.
- `src/commands/find_and_modify.c`: Changed error codes to `ERRCODE_HELIO_FAILEDTOPARSE`.
- `src/commands/create_collection_view.c`: Replaced `MongoInvalidNamespace` and `MongoInvalidOptions` with `ERRCODE_HELIO_*` equivalents.
- `include/geospatial/bson_geospatial_private.h`: Updated include from `utils/mongo_errors.h` to `utils/helio_errors.h`.
2024-09-12 13:51:02 +03:00
Lusen Dong a45694828a Merged PR 1416932: [Feature] window operator $integral and $derivative
### 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)
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
add a window operator, $integral

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Adds a new window operator `$integral` for aggregation.

#### PR Summary
This pull request introduces the `$integral` window operator to compute integrals using the trapezoidal rule in BSON aggregation.
- Added `BsonIntegralAggState` structure and related functions in `bson_aggregates.c` to handle integral calculations.
- Implemented `HandleDollarIntegralWindowOperator` in `bson_aggregation_window_operators.c` to process the new `$integral` operator.
- Updated SQL UDFs in `group_aggregates_support--latest.sql` and `group_aggregates--latest.sql` to include the new `bson_integral_transition` and `bson_integral_final` functions.
- Added `BsonIntegralAggregateFunctionOid` in `metadata_cache.c` and `metadata_cache.h` for function OID retrieval.
- Exposed `GetDecimal128FromInt64` in `decimal128.c` and `decimal128.h` for converting integers to BSON decimal128 format.

Related work items: #3343290
2024-09-12 13:51:02 +03:00
Deepak Bisht 68f0438c85 Merged PR 1436133: $densify aggregation stage
### 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)
Yes

### Are you introducing any new config? If yes, do you have tests with and without them being set?
Yes

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
$densify stage is implemented with all 3 modes
- range
- partition
- full

All 7 functional tests are passing, few tests which are explain specific will be pass in next PR with the changes

![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1436133/attachments/image.png)

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Adds a new `$densify` aggregation stage.

#### PR Summary
Introduces the `$densify` aggregation stage to create new documents where certain field values are missing.
- Added detailed documentation for `$densify` in `docs/pgmongo/design_docs/data_plane/aggregation_stages/densify.md`.
- Implemented core aggregation logic in `oss/pg_helio_api/src/aggregation/bson_densify.c`.
- Created SQL functions and aggregates for densify operations in `oss/pg_helio_api/sql/udfs/aggregation/bson_densify_aggregates--1.21-0.sql` and `oss/pg_helio_api/sql/udfs/aggregation/bson_densify_aggregates--latest.sql`.
- Updated versioning and inclusion of new SQL files in `oss/pg_helio_api/sql/pg_helio_api--1.20-0--1.21-0.sql` and `pgmongo/sql/pgmongo--1.20-0--1.21-0.sql`.

Related work items: #3436236
2024-09-12 13:51:02 +03:00
Ujjwal Agrawal 213287f350 Merged PR 1408344: $top(N)/$bottom(N) accumulator operators implementation
### 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)
Yes

### 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

$top, $topN, $bottom, $bottomN implementation for $group and $setWindowFields
----
#### AI description  (iteration 1)
#### PR Classification
New feature: Added support for `$topN` and `$bottomN` group expression operators.

#### PR Summary
This pull request introduces the `$topN` and `$bottomN` group expression operators to the aggregation pipeline.
- `bson_aggregation_pipeline.c`: Added `ParseInputDocumentForTopAndBottom` function to parse input documents for `$topN` and `$bottomN` operators, and integrated it into the existing aggregation handling logic.
- `mongo_errors.h`: Defined new error codes for handling errors related to the new operators.

Related work items: #2151574, #2151576, #2151596, #2151597, #2988406, #2988407, #2988413, #2988415
2024-09-12 13:51:02 +03:00
Ujjwal Agrawal 6d86e18151 Merged PR 1434207: $shift operator for $setWindowFields
### 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: Added support for `$shift` operator in `$setWindowFields`.

#### PR Summary
This pull request introduces the `$shift` operator for window functions in BSON aggregation, along with additional rank-based window functions.
- Added `HandleDollarShiftWindowOperator` and related functions in `bson_aggregation_window_operators.c` to handle the `$shift` operator.
- Implemented `bson_rank`, `bson_dense_rank`, and `bson_shift` functions in `bson_aggregation_window_functions.c`.
- Added integration tests for rank-based window functions in `custom_rank.js`.
- Updated `bson_aggregation_pipeline_stage_setWindowFields.sql` with tests for `$rank` and `$denseRank` accumulators.
- Added OID lookup functions for new BSON window functions in `metadata_cache.c`.
2024-09-12 13:51:02 +03:00
Duan Pei✨ e0cd9853fc Merged PR 1405758: [Feature] $toHashedIndexkey operator implementation
### 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

https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/
2024-09-12 13:51:02 +03:00
Parag Jain 7740a1f014 Merged PR 1439695: [Feature] $out aggregation stage
### 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
2024-09-12 13:51:02 +03:00
Jayanta Mondal a511a8c252 Merged PR 1443760: [engine] collator cache, and support for $in with collation , $lookup with collation
### 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
2024-09-12 13:51:02 +03:00
Vinod Sridharan c1e2dcba6c Merged PR 1450846: Port more errors to helio errors
### 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.
2024-09-12 13:51:02 +03:00
Vinod Sridharan 3d3298c4b2 Merged PR 1448867: Move to helio errors in helio core
### 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.
2024-09-12 13:51:02 +03:00
Ayush Saluja 5bec50ce04 Merged PR 1434519: Adding support for $document Number
### 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.
2024-09-12 13:51:02 +03:00
Jinrui Zhang ffe78264e1 Merged PR 1412059: implementation of $LinearFill and $locf for $setWindowFields
This PR is used for implementation of `$linearFill` and `$locf` for `$setWindowFields`. It includes:

1) The design doc for $linearFill and $locf
2) The implementation of $linearFill and $locf for verification purpose.

The detailed design and implementation could be refered in the design docs:

[$linearFill](https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1412059?_a=files&path=/docs/pgmongo/design_docs/data_plane/aggregation_operators/linearfill.md),

[$locf](https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1412059?_a=files&path=/docs/pgmongo/design_docs/data_plane/aggregation_operators/locf.md)
2024-09-05 18:18:23 +03:00
Jia Hu 👻 b36e62a18b Merged PR 1429339: [schema validation] support schema validation in insertion
### 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.
2024-09-05 18:18:23 +03:00