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

Function array_subscript_transform

src/backend/utils/adt/arraysubs.c:54–164  ·  view source on GitHub ↗

* Finish parse analysis of a SubscriptingRef expression for an array. * * Transform the subscript expressions, coerce them to integers, * and determine the result type of the SubscriptingRef node. */

Source from the content-addressed store, hash-verified

52 * and determine the result type of the SubscriptingRef node.
53 */
54static void
55array_subscript_transform(SubscriptingRef *sbsref,
56 List *indirection,
57 ParseState *pstate,
58 bool isSlice,
59 bool isAssignment)
60{
61 List *upperIndexpr = NIL;
62 List *lowerIndexpr = NIL;
63 ListCell *idx;
64
65 /*
66 * Transform the subscript expressions, and separate upper and lower
67 * bounds into two lists.
68 *
69 * If we have a container slice expression, we convert any non-slice
70 * indirection items to slices by treating the single subscript as the
71 * upper bound and supplying an assumed lower bound of 1.
72 */
73 foreach(idx, indirection)
74 {
75 A_Indices *ai = lfirst_node(A_Indices, idx);
76 Node *subexpr;
77
78 if (isSlice)
79 {
80 if (ai->lidx)
81 {
82 subexpr = transformExpr(pstate, ai->lidx, pstate->p_expr_kind);
83 /* If it's not int4 already, try to coerce */
84 subexpr = coerce_to_target_type(pstate,
85 subexpr, exprType(subexpr),
86 INT4OID, -1,
87 COERCION_ASSIGNMENT,
88 COERCE_IMPLICIT_CAST,
89 -1);
90 if (subexpr == NULL)
91 ereport(ERROR,
92 (errcode(ERRCODE_DATATYPE_MISMATCH),
93 errmsg("array subscript must have type integer"),
94 parser_errposition(pstate, exprLocation(ai->lidx))));
95 }
96 else if (!ai->is_slice)
97 {
98 /* Make a constant 1 */
99 subexpr = (Node *) makeConst(INT4OID,
100 -1,
101 InvalidOid,
102 sizeof(int32),
103 Int32GetDatum(1),
104 false,
105 true); /* pass by value */
106 }
107 else
108 {
109 /* Slice with omitted lower bound, put NULL into the list */
110 subexpr = NULL;
111 }

Callers

nothing calls this directly

Calls 12

transformExprFunction · 0.85
coerce_to_target_typeFunction · 0.85
exprTypeFunction · 0.85
parser_errpositionFunction · 0.85
exprLocationFunction · 0.85
makeConstFunction · 0.85
Int32GetDatumFunction · 0.85
lappendFunction · 0.85
list_lengthFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected