Skip to content

[Test] test change #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: users/yangqiao/AddTriggeringPipeline
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
99c07ce
Avoid including internal libintelmath header. (#99)
mbanck-cd Mar 12, 2025
23e6751
Merged PR 1588069: Set analyze statistics to 0 for unique index uuid …
visridha Feb 26, 2025
6e39f12
Merged PR 1591206: [engine][collation] Collation Support for Query Ma…
CorneliusOsei2 Feb 27, 2025
f200c96
Merged PR 1542893: PostBatchResume token implementation for change st…
rajeshkt78 Feb 27, 2025
746cd8c
Merged PR 1588377: [engine][collation][1/n] Collation Support for Agg…
CorneliusOsei2 Feb 28, 2025
07f6bec
Merged PR 1523428: [schema validation] apply to stage $merge/$out
jiahu2 Feb 28, 2025
dfc690c
Merged PR 1587905: Enabling large unique index keys by default
lucasbfernandes Mar 1, 2025
9849d49
Merged PR 1592153: [engine][collation] Support for Array Aggregation …
CorneliusOsei2 Mar 4, 2025
07871fa
Merged PR 1593971: Add new GUC to support custom index handler op cla…
safern Mar 4, 2025
e679d4f
Merged PR 1588576: [engine][let] Support for Query Match
CorneliusOsei2 Mar 5, 2025
8bf9489
Merged PR 1592819: [engine][collation] Support for redact
CorneliusOsei2 Mar 5, 2025
90c92c4
Merged PR 1591616: [engine][collation] Support for project
CorneliusOsei2 Mar 5, 2025
1341b55
Merged PR 1599232: [engine][collation] Support for Set Operators
CorneliusOsei2 Mar 7, 2025
d1b0992
Merged PR 1591622: [engine][collation] Support for addFields & set
CorneliusOsei2 Mar 10, 2025
b2ef1f3
Merged PR 1585449: [json schema] enable $jsonSchema in query command
jiahu2 Mar 12, 2025
58e9029
Merged PR 1590489: top level let support with $geoNear stage
diipak-bisht Mar 12, 2025
b7606c8
Merged PR 1605600: Fix densify for PG17
diipak-bisht Mar 12, 2025
48326a6
Merged PR 1606155: [Cleanup] Delete old code - Delete default Feature…
visridha Mar 13, 2025
7d31ca1
Merged PR 1605959: [Index Changes] A few fixes for background indexin…
visridha Mar 14, 2025
70887c4
Merged PR 1601128: [engine][collation] Support for replaceRoot
CorneliusOsei2 Mar 16, 2025
dec0c84
Merged PR 1610308: Make range index optimizations only run for RUM in…
safern Mar 17, 2025
bc9a5f7
Merged PR 1610202: [Livesite Fixes] add logging and fix continuation …
visridha Mar 17, 2025
98a5603
Merged PR 1594069: [engine][collation] Support for find
CorneliusOsei2 Mar 18, 2025
b405e3d
Merged PR 1610601: [Cleanup] Code Cleanups on Versions and DocumentDB
visridha Mar 18, 2025
38af796
Merged PR 1612052: [Infra] Delete Helio test files, Reduce index buil…
visridha Mar 19, 2025
9fa289e
DocumentDB sync sha=282647cb8
shuaitian-git Mar 19, 2025
546a2e4
Add dockerfile for pre-build image (#105)
fatmelon Mar 19, 2025
3a369bf
Fix handling of explicit `maxTimeMS` zero values (#41) (#111)
AlekSi Mar 25, 2025
399e01d
Merged PR 1539417: [Operator] $toUUID in Mongo 8.0
xingfan-msft Mar 19, 2025
86ce366
Merged PR 1556142: DateFromString part-2: Add more functionalities to…
Mar 20, 2025
5a8db34
Merged PR 1614043: [Operator] Support extended $getfield for 8.0
xingfan-msft Mar 21, 2025
0c77472
Merged PR 1614124: [Infra] adding support for documentdb_distributed …
LordParag Mar 21, 2025
80df5a1
Merged PR 1604750: [perf][creation_time] Alter creation time : part 1
LordParag Mar 24, 2025
f31e0b6
Merged PR 1615832: Support for pushdown of in to PFE indexes
visridha Mar 24, 2025
580a0a8
Merged PR 1615448: Version update for 102 release
gaurm Mar 24, 2025
b8bb5f3
DocumentDB sync sha=de048377f
shuaitian-git Mar 26, 2025
3f6d186
first commit (#114)
fatmelon Mar 26, 2025
632baa0
update (#115)
fatmelon Mar 26, 2025
06cd6b0
Update CHANGELOG.md for v0.102-0 released (#120)
AvijitkGupta Mar 26, 2025
916e359
test change
Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merged PR 1594069: [engine][collation] Support for find
### 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? No

### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description
Support collation with `find` queries.

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

#### PR Summary
This pull request adds support for the `project find` functionality with collation in the engine.
- Added new SQL functions in `sql/udfs/projection/bson_projection--0.102-0.sql` for handling BSON projection with collation.
- Updated `metadata_cache.c` to include OID caching for the new `bson_dollar_project_find` function with collation.
- Modified `bson_project.c` to handle additional arguments for collation in the `bson_dollar_project_find` function.
- Updated `bson_projection--latest.sql` to include the new function definition.
- Added function declaration in `metadata_cache.h` for the new `bson_dollar_project_find` function with collation.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #3924476
  • Loading branch information
CorneliusOsei2 authored and safern committed Mar 19, 2025
commit 98a5603d6475e109df8081a8250c1e64aa3c1d36
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
* Support collation with `$in` array operator *[Feature]*
* Support unique index truncation by default with new operator class *[Feature]*
* Support collation in aggregation `$redact` stage *[Feature]*
* Support collation in aggregation `find` *[Feature]*
* Support collation in aggregation `$set` stage *[Feature]*
* Support collation in aggregation `$addFields` stage *[Feature]*
* Support collation with `$setEquals`, `$setUnion`, `$setIntersection`, `$setDifference`, `$setIsSubet` in the aggregation pipeline *[Feature]*
Original file line number Diff line number Diff line change
@@ -2263,6 +2263,57 @@ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_p
{ "a" : "bat", "newField" : false }
(6 rows)

-- find
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }');
document
---------------------------------------------------------------------
{ "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true }
{ "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : false }
{ "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true }
{ "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : false }
{ "_id" : "bat", "a" : "bat", "newField" : false }
(5 rows)

SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2} }');
document
---------------------------------------------------------------------
{ "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false }
{ "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true }
{ "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false }
{ "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true }
{ "_id" : "bat", "a" : "bat", "newField" : true }
(5 rows)

SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }');
document
---------------------------------------------------------------------
{ "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true }
{ "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true }
{ "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true }
{ "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true }
{ "_id" : "bat", "a" : "bat", "newField" : true }
(5 rows)

SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }');
document
---------------------------------------------------------------------
{ "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : true }
{ "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true }
{ "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : true }
{ "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true }
{ "_id" : "bat", "a" : "bat", "newField" : false }
(5 rows)

SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }');
document
---------------------------------------------------------------------
{ "_id" : { "$numberInt" : "1" }, "a" : "cat", "newField" : false }
{ "_id" : { "$numberInt" : "2" }, "a" : "dog", "newField" : true }
{ "_id" : { "$numberInt" : "3" }, "a" : "cAt", "newField" : false }
{ "_id" : { "$numberInt" : "4" }, "a" : "dOg", "newField" : true }
{ "_id" : "bat", "a" : "bat", "newField" : false }
(5 rows)

-- redact
SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL);
NOTICE: creating collection
Original file line number Diff line number Diff line change
@@ -522,6 +522,13 @@ SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_p
SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$lte": ["$a", "DoG"] } } } } ], "cursor": {}, "collation": { "locale": "fr", "strength" : 1} }');
SELECT document FROM bson_aggregation_pipeline('db', '{ "aggregate": "coll_agg_proj", "pipeline": [ { "$replaceRoot": { "newRoot": { "a": "$a", "newField": { "$gte": ["$a", "doG"] } } } } ], "cursor": {}, "collation": { "locale": "en", "strength" : 3} }');

-- find
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$eq": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }');
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 2} }');
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$ne": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }');
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 1} }');
SELECT document FROM bson_aggregation_find('db', '{ "find": "coll_agg_proj", "projection": { "a": 1, "newField": { "$gte": ["$a", "CAT"] } }, "sort": { "_id": 1 }, "skip": 0, "limit": 5, "collation": { "locale": "en", "strength" : 3} }');

-- redact
SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 1, "level": "public", "content": "content 1", "details": { "level": "public", "value": "content 1.1", "moreDetails": { "level": "restricted", "info": "content 1.1.1" } } }', NULL);
SELECT documentdb_api.insert_one('db','coll_redact','{ "_id": 2, "level": "restricted", "content": "content 2", "details": { "level": "public", "value": "content 2.1", "moreDetails": { "level": "restricted", "info": "content 2.1.1" } } }', NULL);
1 change: 1 addition & 0 deletions pg_documentdb/include/metadata/metadata_cache.h
Original file line number Diff line number Diff line change
@@ -299,6 +299,7 @@ Oid BsonDollarMergeExtractFilterFunctionOid(void);
Oid BsonDollarMergeJoinFunctionOid(void);
Oid BsonDollarProjectFindFunctionOid(void);
Oid BsonDollarProjectFindWithLetFunctionOid(void);
Oid BsonDollarProjectFindWithLetAndCollationFunctionOid(void);
Oid BsonDollarUnwindFunctionOid(void);
Oid BsonDollarUnwindWithOptionsFunctionOid(void);
Oid BsonDollarReplaceRootFunctionOid(void);
Original file line number Diff line number Diff line change
@@ -29,6 +29,12 @@ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(d
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT
AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$;

CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text)
RETURNS __CORE_SCHEMA_V2__.bson
LANGUAGE c
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT
AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$;

CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
RETURNS __CORE_SCHEMA__.bson
LANGUAGE c
Original file line number Diff line number Diff line change
@@ -29,6 +29,12 @@ CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(d
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT
AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$;

CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project_find(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, querySpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson, collationString text)
RETURNS __CORE_SCHEMA_V2__.bson
LANGUAGE c
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT
AS 'MODULE_PATHNAME', $function$bson_dollar_project_find$function$;

CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_add_fields(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
RETURNS __CORE_SCHEMA__.bson
LANGUAGE c
15 changes: 13 additions & 2 deletions pg_documentdb/src/aggregation/bson_aggregation_pipeline.c
Original file line number Diff line number Diff line change
@@ -3109,7 +3109,19 @@ HandleProjectFind(const bson_value_t *existingValue, const bson_value_t *queryVa

List *args;
Oid funcOid = BsonDollarProjectFindFunctionOid();
if (context->variableSpec != NULL)
if (IsCollationApplicable(context->collationString) && IsClusterVersionAtleast(
DocDB_V0, 102, 0))
{
pgbson *queryDoc = queryValue->value_type == BSON_TYPE_EOD ? PgbsonInitEmpty() :
PgbsonInitFromDocumentBsonValue(queryValue);
Const *collationStringConst = MakeTextConst(context->collationString,
strlen(context->collationString));

args = list_make5(currentProjection, projectProcessed, MakeBsonConst(queryDoc),
context->variableSpec, collationStringConst);
funcOid = BsonDollarProjectFindWithLetAndCollationFunctionOid();
}
else if (context->variableSpec != NULL)
{
pgbson *queryDoc = queryValue->value_type == BSON_TYPE_EOD ? PgbsonInitEmpty() :
PgbsonInitFromDocumentBsonValue(queryValue);
@@ -3128,7 +3140,6 @@ HandleProjectFind(const bson_value_t *existingValue, const bson_value_t *queryVa
args = list_make3(currentProjection, projectProcessed, queryDocProcessed);
}


FuncExpr *resultExpr = makeFuncExpr(funcOid, BsonTypeId(), args, InvalidOid,
InvalidOid, COERCE_EXPLICIT_CALL);

14 changes: 12 additions & 2 deletions pg_documentdb/src/aggregation/bson_project.c
Original file line number Diff line number Diff line change
@@ -405,6 +405,7 @@ bson_dollar_project_find(PG_FUNCTION_ARGS)
pgbson *pathSpec = PG_GETARG_PGBSON(1);
pgbson *querySpec = NULL;
pgbson *variableSpec = NULL;
char *collationString = NULL;

if (PG_NARGS() > 2)
{
@@ -424,7 +425,7 @@ bson_dollar_project_find(PG_FUNCTION_ARGS)

const BsonProjectionQueryState *state;

int argPosition[2] = { 1, 0 };
int argPosition[3] = { 1, 0, 0 };
int numArgs = 1;

if (PG_NARGS() > 3)
@@ -435,6 +436,14 @@ bson_dollar_project_find(PG_FUNCTION_ARGS)
numArgs = 2;
}

if (EnableCollation && PG_NARGS() > 4)
{
collationString = PG_ARGISNULL(4) ? NULL : text_to_cstring(PG_GETARG_TEXT_P(4));

argPosition[2] = 4;
numArgs = 3;
}

bson_iter_t pathSpecIter;
PgbsonInitIterator(pathSpec, &pathSpecIter);

@@ -443,7 +452,8 @@ bson_dollar_project_find(PG_FUNCTION_ARGS)
.allowInclusionExclusion = false,
.pathSpecIter = &pathSpecIter,
.querySpec = querySpec,
.variableSpec = variableSpec
.variableSpec = variableSpec,
.collationString = collationString
};

SetCachedFunctionStateMultiArgs(
17 changes: 17 additions & 0 deletions pg_documentdb/src/metadata/metadata_cache.c
Original file line number Diff line number Diff line change
@@ -687,6 +687,9 @@ typedef struct DocumentDBApiOidCacheData
/* OID of the bson_dollar_project_find with let args function */
Oid ApiCatalogBsonDollarProjectFindWithLetFunctionOid;

/* OID of the bson_dollar_project_find with let and collation function */
Oid ApiCatalogBsonDollarProjectFindWithLetAndCollationFunctionOid;

/* OID of the bson_dollar_unwind(bson, text) function */
Oid ApiCatalogBsonDollarUnwindFunctionOid;

@@ -3300,6 +3303,20 @@ BsonDollarProjectFindWithLetFunctionOid(void)
}


Oid
BsonDollarProjectFindWithLetAndCollationFunctionOid(void)
{
return GetOperatorFunctionIdFiveArgs(
&Cache.ApiCatalogBsonDollarProjectFindWithLetAndCollationFunctionOid,
DocumentDBApiInternalSchemaName,
"bson_dollar_project_find",
DocumentDBCoreBsonTypeId(), DocumentDBCoreBsonTypeId(),
DocumentDBCoreBsonTypeId(),
DocumentDBCoreBsonTypeId(),
TEXTOID);
}


Oid
BsonDollarMergeHandleWhenMatchedFunctionOid(void)
{
Original file line number Diff line number Diff line change
@@ -225,6 +225,7 @@
documentdb_api_internal | bson_dollar_project | documentdb_core.bson | document documentdb_core.bson, pathspec documentdb_core.bson, variablespec documentdb_core.bson | func
documentdb_api_internal | bson_dollar_project | documentdb_core.bson | document documentdb_core.bson, pathspec documentdb_core.bson, variablespec documentdb_core.bson, collationstring text | func
documentdb_api_internal | bson_dollar_project_find | documentdb_core.bson | document documentdb_core.bson, pathspec documentdb_core.bson, queryspec documentdb_core.bson, letvariablespec documentdb_core.bson | func
documentdb_api_internal | bson_dollar_project_find | documentdb_core.bson | document documentdb_core.bson, pathspec documentdb_core.bson, queryspec documentdb_core.bson, letvariablespec documentdb_core.bson, collationstring text | func
documentdb_api_internal | bson_dollar_range | boolean | documentdb_core.bson, documentdb_core.bson | func
documentdb_api_internal | bson_dollar_redact | documentdb_core.bson | documentdb_core.bson, documentdb_core.bson, text, documentdb_core.bson | func
documentdb_api_internal | bson_dollar_redact | documentdb_core.bson | document documentdb_core.bson, redactspec documentdb_core.bson, redactspectext text, variablespec documentdb_core.bson, collationstring text | func
@@ -381,7 +382,7 @@
documentdb_api_internal | update_one | record | p_collection_id bigint, p_shard_key_value bigint, p_query documentdb_core.bson, p_update documentdb_core.bson, p_shard_key documentdb_core.bson, p_is_upsert boolean, p_sort documentdb_core.bson, p_return_old_or_new boolean, p_return_fields documentdb_core.bson, p_array_filters documentdb_core.bson, p_transaction_id text, OUT o_is_row_updated boolean, OUT o_update_skipped boolean, OUT o_is_retry boolean, OUT o_reinsert_document documentdb_core.bson, OUT o_upserted_object_id bytea, OUT o_result_document documentdb_core.bson | func
documentdb_api_internal | update_worker | documentdb_core.bson | p_collection_id bigint, p_shard_key_value bigint, p_shard_oid regclass, p_update_internal_spec documentdb_core.bson, p_update_internal_docs documentdb_core.bsonsequence, p_transaction_id text | func
documentdb_api_internal | validate_dbname | void | dbname text | func
(206 rows)
(207 rows)

\df documentdb_data.*
List of functions