MCPcopy Create free account
hub / github.com/apache/cloudberry / build_aggregate_transfn_expr

Function build_aggregate_transfn_expr

src/backend/parser/parse_agg.c:2050–2105  ·  view source on GitHub ↗

* Create an expression tree for the transition function of an aggregate. * This is needed so that polymorphic functions can be used within an * aggregate --- without the expression tree, such functions would not know * the datatypes they are supposed to use. (The trees will never actually * be executed, however, so we can skimp a bit on correctness.) * * agg_input_types and agg_state_type i

Source from the content-addressed store, hash-verified

2048 * invtransfnexpr.
2049 */
2050void
2051build_aggregate_transfn_expr(Oid *agg_input_types,
2052 int agg_num_inputs,
2053 int agg_num_direct_inputs,
2054 bool agg_variadic,
2055 Oid agg_state_type,
2056 Oid agg_input_collation,
2057 Oid transfn_oid,
2058 Oid invtransfn_oid,
2059 Expr **transfnexpr,
2060 Expr **invtransfnexpr)
2061{
2062 List *args;
2063 FuncExpr *fexpr;
2064 int i;
2065
2066 /*
2067 * Build arg list to use in the transfn FuncExpr node.
2068 */
2069 args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2070
2071 for (i = agg_num_direct_inputs; i < agg_num_inputs; i++)
2072 {
2073 args = lappend(args,
2074 make_agg_arg(agg_input_types[i], agg_input_collation));
2075 }
2076
2077 fexpr = makeFuncExpr(transfn_oid,
2078 agg_state_type,
2079 args,
2080 InvalidOid,
2081 agg_input_collation,
2082 COERCE_EXPLICIT_CALL);
2083 fexpr->funcvariadic = agg_variadic;
2084 *transfnexpr = (Expr *) fexpr;
2085
2086 /*
2087 * Build invtransfn expression if requested, with same args as transfn
2088 */
2089 if (invtransfnexpr != NULL)
2090 {
2091 if (OidIsValid(invtransfn_oid))
2092 {
2093 fexpr = makeFuncExpr(invtransfn_oid,
2094 agg_state_type,
2095 args,
2096 InvalidOid,
2097 agg_input_collation,
2098 COERCE_EXPLICIT_CALL);
2099 fexpr->funcvariadic = agg_variadic;
2100 *invtransfnexpr = (Expr *) fexpr;
2101 }
2102 else
2103 *invtransfnexpr = NULL;
2104 }
2105}
2106
2107/*

Callers 2

initialize_peraggFunction · 0.85

Calls 3

make_agg_argFunction · 0.85
lappendFunction · 0.85
makeFuncExprFunction · 0.85

Tested by

no test coverage detected