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

Function TryProcessOrIntoDollarIn

pg_documentdb/src/query/query_operator.c:4725–4844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4723
4724
4725static Expr *
4726TryProcessOrIntoDollarIn(BsonQueryOperatorContext *context,
4727 List *orQuals)
4728{
4729 const MongoQueryOperator *op = GetMongoQueryOperatorByQueryOperatorType(
4730 QUERY_OPERATOR_EQ, context->inputType);
4731
4732 /* First pass - validate all paths are the same and the $eq operator */
4733 StringView singlePath = { .length = 0, .string = "" };
4734 Expr *firstArg = NULL;
4735 ListCell *cell;
4736 pgbson_writer inValueWriter;
4737 PgbsonWriterInit(&inValueWriter);
4738
4739 pgbson_element_writer elementWriter;
4740 PgbsonInitObjectElementWriter(&inValueWriter, &elementWriter, "", 0);
4741
4742 pgbson_array_writer arrayWriter;
4743 PgbsonElementWriterStartArray(&elementWriter, &arrayWriter);
4744 foreach(cell, orQuals)
4745 {
4746 Expr *currentExpr = lfirst(cell);
4747 if (IsA(currentExpr, BoolExpr))
4748 {
4749 BoolExpr *boolExpr = (BoolExpr *) currentExpr;
4750 if (boolExpr->boolop == AND_EXPR &&
4751 list_length(boolExpr->args) == 1)
4752 {
4753 /* Flatten single $and */
4754 currentExpr = linitial(boolExpr->args);
4755 }
4756 }
4757
4758 Oid funcId;
4759 List *args;
4760 if (IsA(currentExpr, FuncExpr))
4761 {
4762 FuncExpr *expr = (FuncExpr *) currentExpr;
4763 funcId = expr->funcid;
4764 args = expr->args;
4765 }
4766 else if (IsA(currentExpr, OpExpr))
4767 {
4768 OpExpr *opExpr = (OpExpr *) currentExpr;
4769 funcId = opExpr->opfuncid;
4770 args = opExpr->args;
4771 }
4772 else
4773 {
4774 return NULL;
4775 }
4776
4777 /* Not a $eq - cannot convert to $in */
4778 if (funcId != op->postgresRuntimeFunctionOidLookup())
4779 {
4780 return NULL;
4781 }
4782

Callers 1

Calls 11

PgbsonWriterInitFunction · 0.85
StringViewEqualsFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected