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) 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)) ### Description Porting udfs into documentdb ---- #### AI description (iteration 1) #### PR Classification Code cleanup and feature enhancement. #### PR Summary This pull request continues the porting of UDFs into DocumentDB, updating and including various SQL files for better functionality and organization. - Updated `documentdb--0.24-0.sql` to include new UDFs and operators, replacing old function references. - Added new UDFs for query, projection, geospatial, aggregation, metadata, schema management, index management, CRUD commands, user management, schema validation, telemetry, TTL, vector search, extension version, diagnostic, and RBAC metadata. - Removed outdated function definitions and replaced them with updated SQL includes.
95 lines
3.8 KiB
SQL
95 lines
3.8 KiB
SQL
/*
|
|
Description: This function is use in $merge stage aggregation pipeline to perform action in case of a match.
|
|
Arguments:
|
|
- @bson: source document
|
|
- @bson: target document
|
|
- @int_parameter: action to perform in case of match e.g, replace, keepExisting, merge, fail, pipeline
|
|
|
|
Returns:
|
|
@bson: The final output to writing into target collection.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_handle_when_matched(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, int4)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_handle_when_matched$function$;
|
|
|
|
/*
|
|
Description: support function for index pushdown in merge join used by __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support(internal)
|
|
RETURNS internal
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $$bson_dollar_merge_filter_support$$;
|
|
|
|
|
|
/*
|
|
Description: * The runtime implementation of this is identical to $eq. so we just make a direct function call to the function.
|
|
We just have a tail end argument of the index path so that we can do index pushdown for $merge scenarios.
|
|
Arguments:
|
|
- @bson: target document
|
|
- @bson: filter document
|
|
- @text: index path
|
|
|
|
Returns:
|
|
@bool : True if target document matches the filter document.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_join(__CORE_SCHEMA__.bson,__CORE_SCHEMA__.bson, text)
|
|
RETURNS BOOLEAN
|
|
LANGUAGE c
|
|
SUPPORT __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_filter_support
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_join_filter$function$;
|
|
|
|
/*
|
|
Description: This function adds object ID in a bson document if it not present.
|
|
Arguments:
|
|
- @bson: input document
|
|
- @bson: object id to add
|
|
Returns:
|
|
@bson: output bson with object id.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_add_object_id(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_add_object_id$function$;
|
|
|
|
/*
|
|
Description: This function is use in $merge stage aggregation to fail in case of user wants to fail in `whenNotMatced`.
|
|
This function accepts dummy arguments and has return type to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_fail_when_not_matched(__CORE_SCHEMA__.bson,text)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_fail_when_not_matched$function$;
|
|
|
|
/*
|
|
Description: This function generates object ID.
|
|
Arguments:
|
|
- @bson: this is a dummy input as Non Immutable function are not supported in citus MERGE command.
|
|
passing dummy input to prevent PostgreSQL from treating it as a constant function and evaluating it prematurely.
|
|
Returns:
|
|
@bson: output bson with object id.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_merge_generate_object_id(__CORE_SCHEMA__.bson)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_merge_generate_object_id$function$;
|
|
|
|
/*
|
|
Description: This function extracts merge filter from source document to match against target document.
|
|
Arguments:
|
|
- @bson: source document
|
|
- @text: path to extract filter from source document
|
|
Returns:
|
|
@bson: extracted filter document.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION __API_SCHEMA_INTERNAL_V2__.bson_dollar_extract_merge_filter(__CORE_SCHEMA__.bson, text)
|
|
RETURNS __CORE_SCHEMA__.bson
|
|
LANGUAGE c
|
|
IMMUTABLE PARALLEL SAFE STRICT
|
|
AS 'MODULE_PATHNAME', $function$bson_dollar_extract_merge_filter$function$; |