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

Function addTargetToSortList

src/backend/parser/parse_clause.c:3574–3697  ·  view source on GitHub ↗

* addTargetToSortList * If the given targetlist entry isn't already in the SortGroupClause * list, add it to the end of the list, using the given sort ordering * info. * * Returns the updated SortGroupClause list. */

Source from the content-addressed store, hash-verified

3572 * Returns the updated SortGroupClause list.
3573 */
3574List *
3575addTargetToSortList(ParseState *pstate, TargetEntry *tle,
3576 List *sortlist, List *targetlist, SortBy *sortby)
3577{
3578 Oid restype = exprType((Node *) tle->expr);
3579 Oid sortop;
3580 Oid eqop;
3581 bool hashable;
3582 bool reverse;
3583 int location;
3584 ParseCallbackState pcbstate;
3585
3586 /* if tlist item is an UNKNOWN literal, change it to TEXT */
3587 if (restype == UNKNOWNOID)
3588 {
3589 tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
3590 restype, TEXTOID, -1,
3591 COERCION_IMPLICIT,
3592 COERCE_IMPLICIT_CAST,
3593 exprLocation((Node *) tle->expr));
3594 restype = TEXTOID;
3595 }
3596
3597 /*
3598 * Rather than clutter the API of get_sort_group_operators and the other
3599 * functions we're about to use, make use of error context callback to
3600 * mark any error reports with a parse position. We point to the operator
3601 * location if present, else to the expression being sorted. (NB: use the
3602 * original untransformed expression here; the TLE entry might well point
3603 * at a duplicate expression in the regular SELECT list.)
3604 */
3605 location = sortby->location;
3606 if (location < 0)
3607 location = exprLocation(sortby->node);
3608 setup_parser_errposition_callback(&pcbstate, pstate, location);
3609
3610 /* determine the sortop, eqop, and directionality */
3611 switch (sortby->sortby_dir)
3612 {
3613 case SORTBY_DEFAULT:
3614 case SORTBY_ASC:
3615 get_sort_group_operators(restype,
3616 true, true, false,
3617 &sortop, &eqop, NULL,
3618 &hashable);
3619 reverse = false;
3620 break;
3621 case SORTBY_DESC:
3622 get_sort_group_operators(restype,
3623 false, true, true,
3624 NULL, &eqop, &sortop,
3625 &hashable);
3626 reverse = true;
3627 break;
3628 case SORTBY_USING:
3629 Assert(sortby->useOp != NIL);
3630 sortop = compatible_oper_opid(sortby->useOp,
3631 restype,

Callers 2

transformAggregateCallFunction · 0.85
transformSortClauseFunction · 0.85

Calls 15

exprTypeFunction · 0.85
coerce_typeFunction · 0.85
exprLocationFunction · 0.85
get_sort_group_operatorsFunction · 0.85
compatible_oper_opidFunction · 0.85
op_hashjoinableFunction · 0.85
targetIsInSortListFunction · 0.85
assignSortGroupRefFunction · 0.85
lappendFunction · 0.85

Tested by

no test coverage detected