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

Function FormPartitionKeyDatumFromExpr

src/backend/commands/tablecmds_gp.c:62–126  ·  view source on GitHub ↗

* Build a datum according to tables partition key based on parse expr. Would * have been nice if FormPartitionKeyDatum() was generic and could have been * used instead. */

Source from the content-addressed store, hash-verified

60 * used instead.
61 */
62static void
63FormPartitionKeyDatumFromExpr(Relation rel, Node *expr, Datum *values, bool *isnull)
64{
65 PartitionKey partkey;
66 int num_expr;
67 ListCell *lc;
68 int i;
69
70 Assert(rel);
71 partkey = RelationGetPartitionKey(rel);
72 Assert(partkey != NULL);
73
74 Assert(IsA(expr, List));
75 num_expr = list_length((List *) expr);
76
77 if (num_expr > RelationGetDescr(rel)->natts)
78 ereport(ERROR,
79 (errcode(ERRCODE_DATATYPE_MISMATCH),
80 errmsg("too many columns in boundary specification (%d > %d)",
81 num_expr, RelationGetDescr(rel)->natts)));
82
83 if (num_expr > partkey->partnatts)
84 ereport(ERROR,
85 (errcode(ERRCODE_DATATYPE_MISMATCH),
86 errmsg("too many columns in boundary specification (%d > %d)",
87 num_expr, partkey->partnatts)));
88
89 i = 0;
90 foreach(lc, (List *) expr)
91 {
92 Const *result;
93 char *colname;
94 Oid coltype;
95 int32 coltypmod;
96 Oid partcollation;
97 Node *n1 = (Node *) lfirst(lc);
98
99 /* Get column's name in case we need to output an error */
100 if (partkey->partattrs[i] != 0)
101 colname = get_attname(RelationGetRelid(rel),
102 partkey->partattrs[i], false);
103 else
104 colname = deparse_expression((Node *) linitial(partkey->partexprs),
105 deparse_context_for(RelationGetRelationName(rel),
106 RelationGetRelid(rel)),
107 false, false);
108
109 coltype = get_partition_col_typid(partkey, i);
110 coltypmod = get_partition_col_typmod(partkey, i);
111 partcollation = get_partition_col_collation(partkey, i);
112 result = transformPartitionBoundValue(make_parsestate(NULL), n1,
113 colname, coltype, coltypmod,
114 partcollation);
115
116 values[i] = result->constvalue;
117 isnull[i] = result->constisnull;
118 i++;
119 }

Callers 1

GpFindTargetPartitionFunction · 0.85

Calls 13

RelationGetPartitionKeyFunction · 0.85
list_lengthFunction · 0.85
get_attnameFunction · 0.85
deparse_expressionFunction · 0.85
deparse_context_forFunction · 0.85
get_partition_col_typidFunction · 0.85
get_partition_col_typmodFunction · 0.85
make_parsestateFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected