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

Function transformRangeFunction

src/backend/parser/parse_clause.c:611–894  ·  view source on GitHub ↗

* transformRangeFunction --- transform a function call appearing in FROM */

Source from the content-addressed store, hash-verified

609 * transformRangeFunction --- transform a function call appearing in FROM
610 */
611static ParseNamespaceItem *
612transformRangeFunction(ParseState *pstate, RangeFunction *r)
613{
614 List *funcexprs = NIL;
615 List *funcnames = NIL;
616 List *coldeflists = NIL;
617 bool is_lateral;
618 ListCell *lc;
619
620 if (!r->is_rowsfrom && list_length(r->functions) == 1)
621 {
622 List *pair = (List *) linitial(r->functions);
623 Node *fexpr;
624 List *coldeflist;
625
626 /* Disassemble the function-call/column-def-list pairs */
627 Assert(list_length(pair) == 2);
628 fexpr = (Node *) linitial(pair);
629 coldeflist = (List *) lsecond(pair);
630
631 /* If we see a gp_dist_random('name') call with no special decoration, it actually
632 * refers to a table.
633 */
634 if (IsA(fexpr, FuncCall))
635 {
636 FuncCall *fc = (FuncCall *) fexpr;
637
638 if (list_length(fc->funcname) == 1 &&
639 pg_strcasecmp(strVal(linitial(fc->funcname)), GP_DIST_RANDOM_NAME) == 0 &&
640 fc->agg_order == NIL &&
641 fc->agg_filter == NULL &&
642 !fc->agg_star &&
643 !fc->agg_distinct &&
644 !fc->func_variadic &&
645 fc->over == NULL &&
646 coldeflist == NIL)
647 {
648 /* OK, now we need to check the arguments and generate a RTE */
649
650 if (list_length(fc->args) != 1)
651 elog(ERROR, "Invalid %s syntax.", GP_DIST_RANDOM_NAME);
652
653 if (IsA(linitial(fc->args), A_Const))
654 {
655 A_Const *arg_val;
656 List *qualified_name_list;
657 RangeVar *rel;
658 ParseNamespaceItem *rte;
659
660 arg_val = linitial(fc->args);
661 if (!IsA(&arg_val->val, String))
662 {
663 elog(ERROR, "%s: invalid argument type, non-string in value", GP_DIST_RANDOM_NAME);
664 }
665
666 /* Build the RTE for the table. */
667 qualified_name_list = stringToQualifiedNameList(strVal(&arg_val->val));
668 rel = makeRangeVarFromNameList(qualified_name_list);

Callers 1

transformFromClauseItemFunction · 0.85

Calls 15

list_lengthFunction · 0.85
pg_strcasecmpFunction · 0.85
makeRangeVarFromNameListFunction · 0.85
addRangeTableEntryFunction · 0.85
makeFuncCallFunction · 0.85
transformExprFunction · 0.85
parser_errpositionFunction · 0.85
exprLocationFunction · 0.85
lappendFunction · 0.85
FigureColnameFunction · 0.85
assign_list_collationsFunction · 0.85

Tested by

no test coverage detected