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

Function bson_distinct_unwind

pg_documentdb/src/aggregation/bson_unwind.c:163–193  ·  view source on GitHub ↗

* Implements the unwind function for Distinct. Walks the document for the given * dotted path, and for every element that matches the path, adds it to the tuple store * for instance, given the document { "a": [ { "b": [ 1, 2, 3, 4] }, { "b": [ 2, 4 ] }, { "b": 1 }]} for the path * "a.b", will produce a tuple store with the elements [ 1, 2, 3, 4, 2, 4, 1 ]. * This will then be passed through DI

Source from the content-addressed store, hash-verified

161 * This will then be passed through DISTINCT to reduce the array set.
162 */
163Datum
164bson_distinct_unwind(PG_FUNCTION_ARGS)
165{
166 TupleDesc descriptor;
167 Tuplestorestate *tupleStore = SetupBsonTuplestore(fcinfo, &descriptor);
168 pgbson *document = PG_GETARG_PGBSON(0);
169 char *path = text_to_cstring(PG_GETARG_TEXT_P(1));
170
171 bson_iter_t documentIterator;
172 PgbsonInitIterator(document, &documentIterator);
173 TraverseBsonExecutionFuncs distinctExecutionFuncs =
174 {
175 .ContinueProcessIntermediateArray = DistinctContinueProcessIntermediateArray,
176 .SetTraverseResult = DistinctSetTraverseResult,
177 .VisitArrayField = DistinctVisitArrayField,
178 .VisitTopLevelField = DistinctVisitTopLevelField,
179 .SetIntermediateArrayIndex = NULL,
180 .HandleIntermediateArrayPathNotFound = NULL,
181 .SetIntermediateArrayStartEnd = NULL,
182 };
183
184 DistinctTraverseState traverseState =
185 {
186 .tupleDescriptor = descriptor,
187 .tupleStore = tupleStore
188 };
189
190 TraverseBson(&documentIterator, path, &traverseState, &distinctExecutionFuncs);
191
192 PG_RETURN_VOID();
193}
194
195
196/*

Callers

nothing calls this directly

Calls 3

SetupBsonTuplestoreFunction · 0.85
PgbsonInitIteratorFunction · 0.85
TraverseBsonFunction · 0.85

Tested by

no test coverage detected