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

Function current_op

pg_documentdb/src/commands/current_op.c:190–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189
190Datum
191current_op(pgbson *commandSpec)
192{
193 ReportFeatureUsage(FEATURE_COMMAND_CURRENTOP);
194
195 pgbson *filterSpec = NULL;
196 pgbson *aggregateSpec = BuildAggregateSpecFromCommandSpec(commandSpec, &filterSpec);
197
198 /* Now write the response */
199 pgbson_writer writer;
200 PgbsonWriterInit(&writer);
201
202 StringInfo str = makeStringInfo();
203 appendStringInfo(str,
204 "WITH currentOpQuery AS (SELECT %s.current_op_aggregation($1) AS document), "
205 "currentOpResponse AS (SELECT COALESCE(array_agg(document), '{}') AS \"inprog\", "
206 " 1::float AS \"ok\" FROM currentOpQuery WHERE $2 IS NULL OR document OPERATOR(%s.@@) $2) "
207 " SELECT %s.row_get_bson(currentOpResponse) FROM currentOpResponse",
208 ApiInternalSchemaNameV2, ApiCatalogSchemaName, CoreSchemaName);
209
210 Oid argTypes[2] = { BsonTypeId(), BsonTypeId() };
211 Datum argValues[2] = { PointerGetDatum(aggregateSpec), PointerGetDatum(filterSpec) };
212 char argNulls[2] = { ' ', ' ' };
213 if (filterSpec == NULL)
214 {
215 argNulls[1] = 'n';
216 }
217
218 bool readOnly = true;
219 bool isNull = false;
220 Datum result = ExtensionExecuteQueryWithArgsViaSPI(str->data, 2, argTypes, argValues,
221 argNulls, readOnly, SPI_OK_SELECT,
222 &isNull);
223 if (isNull)
224 {
225 ereport(ERROR, (errmsg(
226 "Unexpected - currentOp internal query returned a null response")));
227 }
228
229 PG_RETURN_DATUM(result);
230}
231
232
233/*

Callers 1

command_current_opFunction · 0.85

Calls 5

ReportFeatureUsageFunction · 0.85
PgbsonWriterInitFunction · 0.85
BsonTypeIdFunction · 0.85

Tested by

no test coverage detected