diff --git a/pg_helio_api/include/metadata/metadata_cache.h b/pg_helio_api/include/metadata/metadata_cache.h index 72fb2ec0..b16bf2b0 100644 --- a/pg_helio_api/include/metadata/metadata_cache.h +++ b/pg_helio_api/include/metadata/metadata_cache.h @@ -327,6 +327,9 @@ Oid ApiCollStatsAggregationFunctionOid(void); Oid ApiIndexStatsAggregationFunctionOid(void); Oid BsonCurrentOpAggregationFunctionId(void); +/* Window functions*/ +Oid BsonLinearFillFunctionOid(void); +Oid BsonLocfFillFunctionOid(void); /* Catalog */ Oid ApiDataNamespaceOid(void); diff --git a/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--1.22-0.sql b/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--1.22-0.sql index 25af9ee3..01738409 100644 --- a/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--1.22-0.sql +++ b/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--1.22-0.sql @@ -59,4 +59,18 @@ CREATE OR REPLACE FUNCTION helio_api_internal.bson_exp_moving_avg(__CORE_SCHEMA_ LANGUAGE c STABLE WINDOW -AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; \ No newline at end of file +AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; + +CREATE OR REPLACE FUNCTION helio_api_internal.bson_linear_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) + RETURNS __CORE_SCHEMA__.bson + LANGUAGE c + STABLE + WINDOW +AS 'MODULE_PATHNAME', $function$bson_linear_fill$function$; + +CREATE OR REPLACE FUNCTION helio_api_internal.bson_locf_fill(__CORE_SCHEMA__.bson) + RETURNS __CORE_SCHEMA__.bson + LANGUAGE c + STABLE + WINDOW +AS 'MODULE_PATHNAME', $function$bson_locf_fill$function$; \ No newline at end of file diff --git a/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--latest.sql b/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--latest.sql index 25af9ee3..01738409 100644 --- a/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--latest.sql +++ b/pg_helio_api/sql/udfs/aggregation/window_aggregate_support--latest.sql @@ -59,4 +59,18 @@ CREATE OR REPLACE FUNCTION helio_api_internal.bson_exp_moving_avg(__CORE_SCHEMA_ LANGUAGE c STABLE WINDOW -AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; \ No newline at end of file +AS 'MODULE_PATHNAME', $function$bson_exp_moving_avg$function$; + +CREATE OR REPLACE FUNCTION helio_api_internal.bson_linear_fill(__CORE_SCHEMA__.bson, __CORE_SCHEMA__.bson) + RETURNS __CORE_SCHEMA__.bson + LANGUAGE c + STABLE + WINDOW +AS 'MODULE_PATHNAME', $function$bson_linear_fill$function$; + +CREATE OR REPLACE FUNCTION helio_api_internal.bson_locf_fill(__CORE_SCHEMA__.bson) + RETURNS __CORE_SCHEMA__.bson + LANGUAGE c + STABLE + WINDOW +AS 'MODULE_PATHNAME', $function$bson_locf_fill$function$; \ No newline at end of file diff --git a/pg_helio_api/src/aggregation/bson_aggregation_window_functions.c b/pg_helio_api/src/aggregation/bson_aggregation_window_functions.c index a20461ad..796935de 100644 --- a/pg_helio_api/src/aggregation/bson_aggregation_window_functions.c +++ b/pg_helio_api/src/aggregation/bson_aggregation_window_functions.c @@ -13,8 +13,40 @@ #include #include "io/helio_bson_core.h" +#include "types/decimal128.h" +#include "utils/mongo_errors.h" #include "windowapi.h" +typedef struct BsonLocfFillState +{ + bool init; + bool hasPre; + pgbson *preValue; +} BsonLocfFillState; + +typedef struct BsonLinearFillState +{ + bool init; + + bool hasPre; + bson_value_t preValue; /* previous non-null value for filled field */ + bson_value_t preSortKeyValue; /* the value of sortKey of previous non-null value */ + + bool hasNext; + bson_value_t nextValue; /* next non-null value for filled field */ + bson_value_t nextSortKeyValue; /* the value of sortKey of next non-null value */ + int64 nextPos; /* the position of next non-null value */ + + bool sortKeyIsNumeric; /* if sort key is numeric */ + bool sortKeyIsDate; /* if sort key is date */ + bool isOut; /* if all rows in current partition has been scanned */ +} BsonLinearFillState; + +/* --------------------------------------------------------- */ +/* Forward declaration */ +/* --------------------------------------------------------- */ +static void CheckDecimal128Result(Decimal128Result result); +static void CheckSortKeyBsonValue(bool isnull, pgbsonelement *sortKeyElement); /* --------------------------------------------------------- */ /* Top level exports */ @@ -22,7 +54,8 @@ PG_FUNCTION_INFO_V1(bson_rank); PG_FUNCTION_INFO_V1(bson_dense_rank); - +PG_FUNCTION_INFO_V1(bson_linear_fill); +PG_FUNCTION_INFO_V1(bson_locf_fill); Datum bson_rank(PG_FUNCTION_ARGS) @@ -42,3 +75,338 @@ bson_dense_rank(PG_FUNCTION_ARGS) finalValue.value.v_int32 = DatumGetInt64(rank); PG_RETURN_POINTER(BsonValueToDocumentPgbson(&finalValue)); } + + +Datum +bson_linear_fill(PG_FUNCTION_ARGS) +{ + WindowObject winobj = PG_WINDOW_OBJECT(); + BsonLinearFillState *stateData; + + stateData = (BsonLinearFillState *) + WinGetPartitionLocalMemory(winobj, sizeof(BsonLinearFillState)); + + if (!stateData->init) + { + /* first call */ + stateData->init = true; + stateData->hasPre = false; + stateData->hasNext = false; + stateData->sortKeyIsDate = false; + stateData->sortKeyIsNumeric = false; + stateData->isOut = false; + } + + Datum nextDatum; + Datum nextSortKeyDatum; + pgbsonelement nextValueElement; + pgbsonelement nextSortKeyElement; + bool isnull = true; + bool isout = false; + bool isValueNull = true; + bool isSortKeyNull = true; + + int64 current_pos = WinGetCurrentPosition(winobj); + + /** + * We need to verify the sortBy value when using linearFill. The restrictions are: + * 1) Value of the sortBy field must be numeric or a date + * 2) No repeated values in the sortBy field in a single partition + */ + pgbson *sortByValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 1, &isnull)); + pgbsonelement sortByValueElement; + PgbsonToSinglePgbsonElement(sortByValue, &sortByValueElement); + CheckSortKeyBsonValue(isnull, &sortByValueElement); + + if (sortByValueElement.bsonValue.value_type == BSON_TYPE_DATE_TIME) + { + stateData->sortKeyIsDate = true; + } + else + { + stateData->sortKeyIsNumeric = true; + } + if (stateData->sortKeyIsDate && stateData->sortKeyIsNumeric) + { + ereport(ERROR, (errcode(MongoTypeMismatch), + errmsg( + "The sortBy field must be either numeric or a date, but not both"), + errhint( + "The sortBy field must be either numeric or a date, but not both"))); + } + + /* Check if there are repeated values in the sortBy field in a single partition */ + if (current_pos != 0 && WinRowsArePeers(winobj, current_pos - 1, current_pos)) + { + ereport(ERROR, (errcode(MongoLocation6050106), + errmsg("There can be no repeated values in the sort field"), + errhint("There can be no repeated values in the sort field"))); + } + + /* Move forward winobj's mark position to release unnecessary tuples in TupleStore */ + WinSetMarkPosition(winobj, current_pos - 1); + + pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isnull)); + pgbsonelement currentValueElement; + PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); + if (!isnull && currentValueElement.bsonValue.value_type != BSON_TYPE_NULL) + { + /* As Mongo does, the filled value should be numeric or nullish. */ + if (!BsonValueIsNumber(¤tValueElement.bsonValue)) + { + ereport(ERROR, (errcode(MongoTypeMismatch), + errmsg(" Value to be filled must be numeric or nullish"), + errhint("Value to be filled must be numeric or nullish"))); + } + stateData->hasPre = true; + + /* In linearFill, only numeric type is allowed, so we can directly use `=` to copy the value to state. */ + stateData->preValue = currentValueElement.bsonValue; + stateData->preSortKeyValue = sortByValueElement.bsonValue; + PG_RETURN_POINTER(currentValue); + } + + pgbsonelement finalValue; + finalValue.path = ""; + finalValue.pathLength = 0; + + /* return null if no pre non-null value or no next non-null value in current partition*/ + if (!stateData->hasPre || stateData->isOut) + { + finalValue.bsonValue.value_type = BSON_TYPE_NULL; + PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); + } + + /* In this case, cur is null and hasPre is true. get next non-null value */ + if (!stateData->hasNext || (current_pos >= stateData->nextPos)) + { + int64 start_offset = 0; + isout = false; + isnull = true; + isValueNull = true; + isSortKeyNull = true; + + while (!isout && (isnull || isValueNull)) + { + start_offset++; + nextDatum = WinGetFuncArgInPartition(winobj, 0, start_offset, + WINDOW_SEEK_CURRENT, false, &isnull, + &isout); + if (isnull || isout) + { + continue; + } + PgbsonToSinglePgbsonElement(DatumGetPgBson(nextDatum), &nextValueElement); + isValueNull = nextValueElement.bsonValue.value_type == BSON_TYPE_NULL; + + /* As we didn't change the offset, we can reuse the `isout` and its value should be same as previous call */ + nextSortKeyDatum = WinGetFuncArgInPartition(winobj, 1, start_offset, + WINDOW_SEEK_CURRENT, false, + &isSortKeyNull, &isout); + PgbsonToSinglePgbsonElement(DatumGetPgBson(nextSortKeyDatum), + &nextSortKeyElement); + CheckSortKeyBsonValue(isSortKeyNull, &nextSortKeyElement); + } + if (!isnull && !isValueNull) + { + stateData->hasNext = true; + stateData->nextValue = nextValueElement.bsonValue; + stateData->nextSortKeyValue = nextSortKeyElement.bsonValue; + stateData->nextPos = current_pos + start_offset; + } + else + { + /* if this branch hit, current partiton reaches the end and has no more non-null value */ + stateData->hasNext = false; + stateData->isOut = true; + } + } + if (!stateData->hasNext) + { + finalValue.bsonValue.value_type = BSON_TYPE_NULL; + PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); + } + + /** + * As Mongo does, the filled value should be numeric or nullish. + */ + if (!BsonValueIsNumber(&stateData->nextValue)) + { + ereport(ERROR, (errcode(MongoTypeMismatch), + errmsg(" Value to be filled must be numeric or nullish"), + errhint("Value to be filled must be numeric or nullish"))); + } + + /** + * As Mongo does, if both values are not Deciaml128, double will be returned; otherwise, Decimal128 will be returned. + */ + if (stateData->preValue.value_type != BSON_TYPE_DECIMAL128 && + stateData->nextValue.value_type != BSON_TYPE_DECIMAL128) + { + double preValue = BsonValueAsDouble(&stateData->preValue); + double nextValue = BsonValueAsDouble(&stateData->nextValue); + double currentSortKeyValue = BsonValueAsDouble(&sortByValueElement.bsonValue); + double preSortKeyValue = BsonValueAsDouble(&stateData->preSortKeyValue); + double nextSortKeyValue = BsonValueAsDouble(&stateData->nextSortKeyValue); + + double filledValue = preValue + (nextValue - preValue) * (currentSortKeyValue - + preSortKeyValue) / + (nextSortKeyValue - preSortKeyValue); + + finalValue.bsonValue.value_type = BSON_TYPE_DOUBLE; + finalValue.bsonValue.value.v_double = filledValue; + PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); + } + else + { + bson_value_t preValue; + preValue.value_type = BSON_TYPE_DECIMAL128; + preValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( + &stateData->preValue); + + bson_value_t nextValue; + nextValue.value_type = BSON_TYPE_DECIMAL128; + nextValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( + &stateData->nextValue); + + bson_value_t filledValue; + + bson_value_t preSortKeyValue; + preSortKeyValue.value_type = BSON_TYPE_DECIMAL128; + preSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( + &stateData->preSortKeyValue); + + bson_value_t nextSortKeyValue; + nextSortKeyValue.value_type = BSON_TYPE_DECIMAL128; + nextSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( + &stateData->nextSortKeyValue); + + bson_value_t currentSortKeyValue; + currentSortKeyValue.value_type = BSON_TYPE_DECIMAL128; + currentSortKeyValue.value.v_decimal128 = GetBsonValueAsDecimal128Quantized( + &sortByValueElement.bsonValue); + + CheckDecimal128Result(SubtractDecimal128Numbers(&nextSortKeyValue, + &preSortKeyValue, + &nextSortKeyValue)); + CheckDecimal128Result(SubtractDecimal128Numbers(¤tSortKeyValue, + &preSortKeyValue, + ¤tSortKeyValue)); + + CheckDecimal128Result(SubtractDecimal128Numbers(&nextValue, &preValue, + &filledValue)); + CheckDecimal128Result(MultiplyDecimal128Numbers(&filledValue, + ¤tSortKeyValue, + &filledValue)); + CheckDecimal128Result(DivideDecimal128Numbers(&filledValue, &nextSortKeyValue, + &filledValue)); + CheckDecimal128Result(AddDecimal128Numbers(&preValue, &filledValue, + &filledValue)); + + finalValue.bsonValue.value_type = BSON_TYPE_DECIMAL128; + finalValue.bsonValue.value.v_decimal128 = filledValue.value.v_decimal128; + PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); + } +} + + +Datum +bson_locf_fill(PG_FUNCTION_ARGS) +{ + WindowObject winobj = PG_WINDOW_OBJECT(); + BsonLocfFillState *stateData; + + stateData = (BsonLocfFillState *) + WinGetPartitionLocalMemory(winobj, sizeof(BsonLocfFillState)); + + if (!stateData->init) + { + /* first call */ + stateData->init = true; + stateData->hasPre = false; + stateData->preValue = NULL; + } + + bool isnull = true; + + /* bool isout = true; */ + + int64 current_pos = WinGetCurrentPosition(winobj); + pgbson *currentValue = DatumGetPgBson(WinGetFuncArgCurrent(winobj, 0, &isnull)); + pgbsonelement currentValueElement; + PgbsonToSinglePgbsonElement(currentValue, ¤tValueElement); + + /* switch to partition level memory context */ + if (!isnull && currentValueElement.bsonValue.value_type != BSON_TYPE_NULL) + { + /* release memory of pre value because we will replaced it with current value by new memory allocation */ + if (stateData->preValue != NULL) + { + pfree(stateData->preValue); + } + stateData->hasPre = true; + stateData->preValue = CopyPgbsonIntoMemoryContext(currentValue, + fcinfo->flinfo->fn_mcxt); + + /** + * Once we get current value, the values before current value won't be used in locf fill. + * Thus we can move the winobj's mark position forward to `current_pos - 1` to reduce the memory usage of TupleStore in NodeWindowAgg. + */ + WinSetMarkPosition(winobj, current_pos - 1); + PG_RETURN_POINTER(currentValue); + } + + /* return null if cur is null and no pre non-null value*/ + if (!stateData->hasPre) + { + pgbsonelement finalValue; + finalValue.path = ""; + finalValue.pathLength = 0; + finalValue.bsonValue.value_type = BSON_TYPE_NULL; + PG_RETURN_POINTER(PgbsonElementToPgbson(&finalValue)); + } + else + { + PG_RETURN_POINTER(stateData->preValue); + } +} + + +static void +CheckSortKeyBsonValue(bool isnull, pgbsonelement *sortKeyElement) +{ + if (isnull || sortKeyElement->bsonValue.value_type == BSON_TYPE_NULL) + { + ereport(ERROR, (errcode(MongoTypeMismatch), + errmsg("sortBy value must be numeric or a date, but found null"), + errhint( + "sortBy value must be numeric or a date, but found null"))); + } + if (!BsonValueIsNumber(&sortKeyElement->bsonValue) && + sortKeyElement->bsonValue.value_type != BSON_TYPE_DATE_TIME) + { + ereport(ERROR, (errcode(MongoTypeMismatch), + errmsg("sortBy value must be numeric or a date, but found %s", + BsonTypeName(sortKeyElement->bsonValue.value_type)), + errhint("sortBy value must be numeric or a date, but found %s", + BsonTypeName(sortKeyElement->bsonValue.value_type)))); + } +} + + +/** + * Check the result of Decimal128 operation. If the result is Decimal128Result_Unknown, throw an error. + * $linearFill will return Infinity, -Infinity or NaN if the result is overflow, underflow or NaN. + */ +static void +CheckDecimal128Result(Decimal128Result result) +{ + if (result == Decimal128Result_Unknown) + { + ereport(ERROR, (errcode(MongoInternalError), + errmsg( + " Unknown error when processing Decimal128 numbers in $linearFill"), + errhint( + " Unknown error when processing Decimal128 numbers in $linearFill"))); + } +} diff --git a/pg_helio_api/src/aggregation/bson_aggregation_window_operators.c b/pg_helio_api/src/aggregation/bson_aggregation_window_operators.c index 98bf6f6f..2f9c138c 100644 --- a/pg_helio_api/src/aggregation/bson_aggregation_window_operators.c +++ b/pg_helio_api/src/aggregation/bson_aggregation_window_operators.c @@ -168,6 +168,10 @@ static WindowFunc * HandleDollarSumWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); static WindowFunc * HandleDollarExpMovingAvgWindowOperator(const bson_value_t *opValue, WindowOperatorContext *context); +static WindowFunc * HandleDollarLinearFillWindowOperator(const bson_value_t *opValue, + WindowOperatorContext *context); +static WindowFunc * HandleDollarLocfFillWindowOperator(const bson_value_t *opValue, + WindowOperatorContext *context); /* GUC to enable SetWindowFields stage */ @@ -246,11 +250,11 @@ static const WindowOperatorDefinition WindowOperatorDefinitions[] = }, { .operatorName = "$linearFill", - .windowOperatorFunc = NULL + .windowOperatorFunc = &HandleDollarLinearFillWindowOperator }, { .operatorName = "$locf", - .windowOperatorFunc = NULL + .windowOperatorFunc = &HandleDollarLocfFillWindowOperator }, { .operatorName = "$max", @@ -1748,3 +1752,123 @@ HandleDollarExpMovingAvgWindowOperator(const bson_value_t *opValue, windowFunc->args = list_make3(accumFunc, weightConstValue, isAlphaConst); return windowFunc; } + + +/* + * Handle for $linearFill window aggregation operator. + */ +static WindowFunc * +HandleDollarLinearFillWindowOperator(const bson_value_t *opValue, + WindowOperatorContext *context) +{ + if (!(IsClusterVersionAtleastThis(1, 22, 0))) + { + ereport(ERROR, (errcode(MongoLocation605001), + errmsg( + " $linearFill is only supported on vCore 1.21.0 and above"))); + } + if (list_length(context->sortOptions) != 1) + { + ereport(ERROR, (errcode(MongoLocation605001), + errmsg( + " $linearFill must be specified with a top level sortBy expression with exactly one element"))); + } + if (context->isWindowPresent) + { + ereport(ERROR, (errcode(MongoFailedToParse), + errmsg( + " 'window' field is not allowed in $linearFill"))); + } + + WindowFunc *windowFunc = makeNode(WindowFunc); + windowFunc->winfnoid = BsonLinearFillFunctionOid(); + windowFunc->wintype = BsonTypeId(); + windowFunc->winref = context->winRef; + windowFunc->winstar = false; + windowFunc->winagg = false; + + Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(opValue)); \ + Const *trueConst = (Const *) MakeBoolValueConst(true); + List *args; + Oid functionOid; + + if (context->variableContext != NULL) + { + functionOid = BsonExpressionGetWithLetFunctionOid(); + args = list_make4(context->docExpr, constValue, trueConst, + context->variableContext); + } + else + { + functionOid = BsonExpressionGetFunctionOid(); + args = list_make3(context->docExpr, constValue, trueConst); + } + + FuncExpr *accumFunc = makeFuncExpr( + functionOid, BsonTypeId(), args, InvalidOid, + InvalidOid, COERCE_EXPLICIT_CALL); + + SetWindowFieldSortOption *sortOption = (SetWindowFieldSortOption *) linitial( + context->sortOptions); + List *sortExprArgs = list_make2(context->docExpr, sortOption->sortSpecConst); + + FuncExpr *sortExpr = makeFuncExpr( + BsonOrderByFunctionOid(), BsonTypeId(), sortExprArgs, InvalidOid, + InvalidOid, COERCE_EXPLICIT_CALL); + + windowFunc->args = list_make2(accumFunc, sortExpr); + return windowFunc; +} + + +/* + * Handle for $locf window aggregation operator. + */ +static WindowFunc * +HandleDollarLocfFillWindowOperator(const bson_value_t *opValue, + WindowOperatorContext *context) +{ + if (!(IsClusterVersionAtleastThis(1, 22, 0))) + { + ereport(ERROR, (errcode(MongoLocation605001), + errmsg( + " $locf is only supported on vCore 1.21.0 and above"))); + } + if (context->isWindowPresent) + { + ereport(ERROR, (errcode(MongoFailedToParse), + errmsg( + " 'window' field is not allowed in $locf"))); + } + + WindowFunc *windowFunc = makeNode(WindowFunc); + windowFunc->winfnoid = BsonLocfFillFunctionOid(); + windowFunc->wintype = BsonTypeId(); + windowFunc->winref = context->winRef; + windowFunc->winstar = false; + windowFunc->winagg = false; + + Expr *constValue = (Expr *) MakeBsonConst(BsonValueToDocumentPgbson(opValue)); + + Const *trueConst = (Const *) MakeBoolValueConst(true); + List *args; + Oid functionOid; + + if (context->variableContext != NULL) + { + functionOid = BsonExpressionGetWithLetFunctionOid(); + args = list_make4(context->docExpr, constValue, trueConst, + context->variableContext); + } + else + { + functionOid = BsonExpressionGetFunctionOid(); + args = list_make3(context->docExpr, constValue, trueConst); + } + + FuncExpr *accumFunc = makeFuncExpr( + functionOid, BsonTypeId(), args, InvalidOid, + InvalidOid, COERCE_EXPLICIT_CALL); + windowFunc->args = list_make1(accumFunc); + return windowFunc; +} diff --git a/pg_helio_api/src/metadata/metadata_cache.c b/pg_helio_api/src/metadata/metadata_cache.c index 80109a29..dee02af1 100644 --- a/pg_helio_api/src/metadata/metadata_cache.c +++ b/pg_helio_api/src/metadata/metadata_cache.c @@ -648,6 +648,12 @@ typedef struct HelioApiOidCacheData /* OID of the BSONSUM aggregate function */ Oid ApiCatalogBsonSumAggregateFunctionOid; + /* OID of the bson_linear_fill window function */ + Oid ApiCatalogBsonLinearFillFunctionOid; + + /* OID of the bson_locf_fill window function */ + Oid ApiCatalogBsonLocfFillFunctionOid; + /* OID of the BSONAVERAGE aggregate function */ Oid ApiCatalogBsonAverageAggregateFunctionOid; @@ -3247,6 +3253,46 @@ BsonSumAggregateFunctionOid(void) } +Oid +BsonLinearFillFunctionOid(void) +{ + InitializeHelioApiExtensionCache(); + + if (Cache.ApiCatalogBsonLinearFillFunctionOid == InvalidOid) + { + List *functionNameList = list_make2(makeString("helio_api_internal"), + makeString("bson_linear_fill")); + Oid paramOids[2] = { BsonTypeId(), BsonTypeId() }; + bool missingOK = false; + + Cache.ApiCatalogBsonLinearFillFunctionOid = + LookupFuncName(functionNameList, 2, paramOids, missingOK); + } + + return Cache.ApiCatalogBsonLinearFillFunctionOid; +} + + +Oid +BsonLocfFillFunctionOid(void) +{ + InitializeHelioApiExtensionCache(); + + if (Cache.ApiCatalogBsonLocfFillFunctionOid == InvalidOid) + { + List *functionNameList = list_make2(makeString("helio_api_internal"), + makeString("bson_locf_fill")); + Oid paramOids[1] = { BsonTypeId() }; + bool missingOK = false; + + Cache.ApiCatalogBsonLocfFillFunctionOid = + LookupFuncName(functionNameList, 1, paramOids, missingOK); + } + + return Cache.ApiCatalogBsonLocfFillFunctionOid; +} + + Oid BsonAvgAggregateFunctionOid(void) { diff --git a/pg_helio_core/include/utils/mongo_errors.h b/pg_helio_core/include/utils/mongo_errors.h index 234e56d7..4fae5366 100644 --- a/pg_helio_core/include/utils/mongo_errors.h +++ b/pg_helio_core/include/utils/mongo_errors.h @@ -444,6 +444,7 @@ _DEFINE_MONGO_ERROR(Location51750, 51750); _DEFINE_MONGO_ERROR(Location51751, 51751); _DEFINE_MONGO_ERROR(Location327391, 327391); _DEFINE_MONGO_ERROR(Location327392, 327392); +_DEFINE_MONGO_ERROR(Location605001, 605001); _DEFINE_MONGO_ERROR(DollarIfNullRequiresAtLeastTwoArgs, 1257300); _DEFINE_MONGO_ERROR(DollarRandNonEmptyArgument, 3040501); _DEFINE_MONGO_ERROR(IntermediateResultTooLarge, 4031700); @@ -526,6 +527,7 @@ _DEFINE_MONGO_ERROR(Location5788200, 5788200); _DEFINE_MONGO_ERROR(Location5858203, 5858203); _DEFINE_MONGO_ERROR(Location5976500, 5976500); _DEFINE_MONGO_ERROR(Location6045000, 6045000); +_DEFINE_MONGO_ERROR(Location6050106, 6050106); /* do not expose helper macro unnecessarily */ #undef _DEFINE_MONGO_ERROR