MCPcopy Create free account
hub / github.com/documentdb/documentdb / bson_densify_full

Function bson_densify_full

pg_documentdb/src/aggregation/bson_densify.c:368–461  ·  view source on GitHub ↗

bson_densify_full * Fills the documents for a range that is minimum and maximum across * all the partitions. * * document => The document that needs to be densified * densifySpec => $densify spec of this form: * { * 'partitionByFields': [ ], * field: , * range: { * bounds: "full", * steps: , *

Source from the content-addressed store, hash-verified

366 * The documents are processed in an ORDER BY for the `field` value
367 */
368Datum
369bson_densify_full(PG_FUNCTION_ARGS)
370{
371 WindowObject winObject = PG_WINDOW_OBJECT();
372
373 bool isNull = false;
374 pgbson *document = DatumGetPgBson(WinGetFuncArgCurrent(winObject, 0, &isNull));
375 pgbson *spec = DatumGetPgBson(WinGetFuncArgCurrent(winObject, 1, &isNull));
376
377 DensifyWindowState *densifyState = NULL;
378 int argPosition = 1;
379 SetCachedFunctionState(
380 densifyState,
381 DensifyWindowState,
382 argPosition,
383 InitializeDensifyWindowState,
384 spec,
385 DENSIFY_TYPE_FULL);
386
387 if (densifyState == NULL)
388 {
389 densifyState = palloc0(sizeof(DensifyWindowState));
390 InitializeDensifyWindowState(densifyState, spec, DENSIFY_TYPE_FULL);
391 }
392
393 PartitionAwareState *partitionState = GetValidPartitionAwareState(densifyState,
394 document);
395
396 /* Find the group entry in hash, if this a new group create the entry for this group */
397 HTAB *partitionGroupTable = partitionState->partitionInfo;
398 bool found;
399 DensifyFullEntry searchPartitionKey = { 0 };
400 bool moveToExecutorContext = false;
401 searchPartitionKey.evaluatedPartitionBy = GetPartitionByFieldsPgbson(document,
402 densifyState,
403 moveToExecutorContext);
404 DensifyFullEntry *foundEntry = hash_search(partitionGroupTable, &searchPartitionKey,
405 HASH_ENTER, &found);
406 if (!found)
407 {
408 /* When a new group is seen, copy the group by value in executor context so that
409 * it doesn't vanish in the hash table, and set the lastMinValueInGroup to the first
410 * row's value so that densification starts from global minimum value
411 */
412 if (searchPartitionKey.evaluatedPartitionBy != NULL)
413 {
414 foundEntry->evaluatedPartitionBy =
415 CopyPgbsonIntoMemoryContext(searchPartitionKey.evaluatedPartitionBy,
416 densifyState->executorContext);
417 }
418
419 /*
420 * Note: arguments.lowerBound is not available in case of `full` but we use it to store
421 * the minimum value which is the first row's value and because there is no default partitioning done
422 * for `full` it is also the minimum across all partitions that we will create inside this function
423 * using hash
424 */
425 foundEntry->lastMinValueInGroup = densifyState->arguments.lowerBound;

Callers

nothing calls this directly

Calls 7

DensifyDocsFromStateFunction · 0.85
PgbsonFreeIfNotNullFunction · 0.85

Tested by

no test coverage detected