* Validates the densify spec and gets the `partitionByFieldExpr` * `sortByExpr` and `densifyFunctionOid` to use while building query * tree */
| 860 | * tree |
| 861 | */ |
| 862 | static void |
| 863 | GetDensifyQueryExprs(DensifyArguments *arguments, |
| 864 | AggregationPipelineBuildContext *context, |
| 865 | Expr *docExpr, bool isDataTable, Expr **partitionByFieldsExpr, |
| 866 | SortBy **sortByExpr, Oid *densifyFunctionOid) |
| 867 | { |
| 868 | if (arguments->densifyType == DENSIFY_TYPE_RANGE) |
| 869 | { |
| 870 | *densifyFunctionOid = BsonDensifyRangeWindowFunctionOid(); |
| 871 | } |
| 872 | else if (arguments->densifyType == DENSIFY_TYPE_PARTITION) |
| 873 | { |
| 874 | *densifyFunctionOid = BsonDensifyPartitionWindowFunctionOid(); |
| 875 | } |
| 876 | else if (arguments->densifyType == DENSIFY_TYPE_FULL) |
| 877 | { |
| 878 | *densifyFunctionOid = BsonDensifyFullWindowFunctionOid(); |
| 879 | } |
| 880 | |
| 881 | if (arguments->densifyType != DENSIFY_TYPE_FULL && arguments->partitionByFields != |
| 882 | NULL) |
| 883 | { |
| 884 | /* |
| 885 | * For `full` mode there is no partition created and every row is processed |
| 886 | * in a single partition in the ascending order of `field`. The partitioning |
| 887 | * metadata is stored in `bson_densify_full` function to generate right set |
| 888 | * of documents |
| 889 | */ |
| 890 | |
| 891 | if (isDataTable && IsPartitionByFieldsOnShardKey(arguments->partitionByFields, |
| 892 | context->mongoCollection)) |
| 893 | { |
| 894 | *partitionByFieldsExpr = (Expr *) makeVar(((Var *) docExpr)->varno, |
| 895 | DOCUMENT_DATA_TABLE_SHARD_KEY_VALUE_VAR_ATTR_NUMBER, |
| 896 | INT8OID, -1, |
| 897 | InvalidOid, 0); |
| 898 | } |
| 899 | else |
| 900 | { |
| 901 | Const *partitionConst = MakeBsonConst(arguments->partitionByFields); |
| 902 | *partitionByFieldsExpr = (Expr *) makeFuncExpr( |
| 903 | BsonExpressionPartitionByFieldsGetFunctionOid(), |
| 904 | BsonTypeId(), list_make2( |
| 905 | docExpr, partitionConst), |
| 906 | InvalidOid, InvalidOid, |
| 907 | COERCE_EXPLICIT_CALL); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | pgbson_writer sortSpecWriter; |
| 912 | PgbsonWriterInit(&sortSpecWriter); |
| 913 | PgbsonWriterAppendInt64(&sortSpecWriter, arguments->field.string, |
| 914 | arguments->field.length, 1); |
| 915 | pgbson *sortSpec = PgbsonWriterGetPgbson(&sortSpecWriter); |
| 916 | |
| 917 | Expr *expr = (Expr *) makeFuncExpr(BsonOrderByFunctionOid(), BsonTypeId(), |
| 918 | list_make2(docExpr, MakeBsonConst(sortSpec)), |
| 919 | InvalidOid, InvalidOid, |
no test coverage detected