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

Function FormPartitionKeyDatum

src/backend/executor/execPartition.c:1257–1312  ·  view source on GitHub ↗

---------------- * FormPartitionKeyDatum * Construct values[] and isnull[] arrays for the partition key * of a tuple. * * pd Partition dispatch object of the partitioned table * slot Heap tuple from which to extract partition key * estate executor state for evaluating any partition key * expressions (must be non-NULL) * values Array of partition key Datums (output area)

Source from the content-addressed store, hash-verified

1255 * ----------------
1256 */
1257static void
1258FormPartitionKeyDatum(PartitionDispatch pd,
1259 TupleTableSlot *slot,
1260 EState *estate,
1261 Datum *values,
1262 bool *isnull,
1263 AttrMap *attno_map)
1264{
1265 ListCell *partexpr_item;
1266 int i;
1267
1268 if (pd->key->partexprs != NIL && pd->keystate == NIL)
1269 {
1270 /* Check caller has set up context correctly */
1271 Assert(estate != NULL &&
1272 GetPerTupleExprContext(estate)->ecxt_scantuple == slot);
1273
1274 /* First time through, set up expression evaluation state */
1275 pd->keystate = ExecPrepareExprList(pd->key->partexprs, estate);
1276 }
1277
1278 partexpr_item = list_head(pd->keystate);
1279 for (i = 0; i < pd->key->partnatts; i++)
1280 {
1281 AttrNumber keycol = pd->key->partattrs[i];
1282 /* Use passed in map to extract part key, as slot's attrs may not match the Relation's attrs */
1283 if (attno_map) {
1284 Assert(pd->key->partattrs[i] - 1 < attno_map->maplen);
1285 keycol = attno_map->attnums[pd->key->partattrs[i] - 1];
1286 }
1287
1288 Datum datum;
1289 bool isNull;
1290
1291 if (keycol != 0)
1292 {
1293 /* Plain column; get the value directly from the heap tuple */
1294 datum = slot_getattr(slot, keycol, &isNull);
1295 }
1296 else
1297 {
1298 /* Expression; need to evaluate it */
1299 if (partexpr_item == NULL)
1300 elog(ERROR, "wrong number of partition key expressions");
1301 datum = ExecEvalExprSwitchContext((ExprState *) lfirst(partexpr_item),
1302 GetPerTupleExprContext(estate),
1303 &isNull);
1304 partexpr_item = lnext(pd->keystate, partexpr_item);
1305 }
1306 values[i] = datum;
1307 isnull[i] = isNull;
1308 }
1309
1310 if (partexpr_item != NULL)
1311 elog(ERROR, "wrong number of partition key expressions");
1312}
1313
1314/*

Callers 1

ExecFindPartitionFunction · 0.85

Calls 5

ExecPrepareExprListFunction · 0.85
list_headFunction · 0.85
slot_getattrFunction · 0.85
lnextFunction · 0.85

Tested by

no test coverage detected