mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
### 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? No ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description Because of N-1 tests we can't update the sql UDF and start using it in documentdb at the same release. This 1 of 2 PRs to add the schema changes in release 0.101 and next PR will start using these UDF in documentdb in 0.102 Bug description: `bson_dollar_merge_documents` UDF today doesn't override nested arrays for projection with conflicting path and add the new projection entities inside each element of array which is not required in few places e.g. $lookup, $graphlookup etc ---- #### AI description (iteration 1) #### PR Classification New feature #### PR Summary This pull request introduces a new function to handle mutating nested arrays in BSON documents. - Added `bson_dollar_merge_documents` function with an override flag in `bson_projection--0.101-0.sql`. - Implemented `MergeDocumentWithArrayOverride` function in `bson_project.c` to support the new feature. - Updated test cases in `bson_aggregation_stage_lookup_tests.sql` and corresponding expected output files. - Included the new SQL file in `documentdb--0.100-0--0.101-0.sql` and `pgmongo--1.24-0--1.101-0.sql`. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
93 lines
4.5 KiB
SQL
93 lines
4.5 KiB
SQL
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_project(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson)
|
|
RETURNS __CORE_SCHEMA_V2__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_project$function$;
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_project_find(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, querySpec __CORE_SCHEMA__.bson DEFAULT NULL)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
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)
|
|
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
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_add_fields(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, letVariableSpec __CORE_SCHEMA_V2__.bson)
|
|
RETURNS __CORE_SCHEMA_V2__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_add_fields$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_set(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_set$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_unset(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_unset$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_replace_root(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$;
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_replace_root(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson)
|
|
RETURNS __CORE_SCHEMA_V2__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_replace_root$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_CATALOG_SCHEMA__.bson_dollar_facet_project(__CORE_SCHEMA__.bson, bool)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_facet_project$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents(document __CORE_SCHEMA__.bson, pathSpec __CORE_SCHEMA__.bson, overrideArray bool)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_documents_at_path(leftDocument __CORE_SCHEMA__.bson, rightDocument __CORE_SCHEMA__.bson, fieldPath text)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_documents_at_path$function$;
|
|
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_lookup_expression_eval_merge(document __CORE_SCHEMA_V2__.bson, pathSpec __CORE_SCHEMA_V2__.bson, variableSpec __CORE_SCHEMA_V2__.bson)
|
|
RETURNS __CORE_SCHEMA_V2__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_lookup_expression_eval_merge$function$;
|