| 5792 | |
| 5793 | |
| 5794 | static Expr * |
| 5795 | ProcessElemMatchOperator(bytea *options, Datum queryValue, const |
| 5796 | MongoIndexOperatorInfo *operator, List *args) |
| 5797 | { |
| 5798 | pgbson *queryBson = DatumGetPgBson(queryValue); |
| 5799 | pgbsonelement argElement = { 0 }; |
| 5800 | PgbsonToSinglePgbsonElement(queryBson, &argElement); |
| 5801 | |
| 5802 | |
| 5803 | BsonQueryOperatorContext context = { 0 }; |
| 5804 | BsonQueryOperatorContextCommonBuilder(&context); |
| 5805 | context.documentExpr = linitial(args); |
| 5806 | |
| 5807 | /* Convert the pgbson query into a query AST that processes bson */ |
| 5808 | Expr *expr = CreateQualForBsonExpression(&argElement.bsonValue, |
| 5809 | argElement.path, &context); |
| 5810 | |
| 5811 | /* Get the underlying list of expressions that are AND-ed */ |
| 5812 | List *clauses = make_ands_implicit(expr); |
| 5813 | |
| 5814 | IndexElemmatchState elemMatchState = { 0 }; |
| 5815 | |
| 5816 | WalkExprAndAddSupportedElemMatchExprs(clauses, options, &elemMatchState, |
| 5817 | argElement.path); |
| 5818 | |
| 5819 | if (elemMatchState.pathStates == NIL) |
| 5820 | { |
| 5821 | return NULL; |
| 5822 | } |
| 5823 | |
| 5824 | ListCell *cell; |
| 5825 | |
| 5826 | List *overallQuals = NIL; |
| 5827 | foreach(cell, elemMatchState.pathStates) |
| 5828 | { |
| 5829 | IndexElemMatchPathState *pathState = lfirst(cell); |
| 5830 | ListCell *innerCell; |
| 5831 | |
| 5832 | pgbson_writer writer; |
| 5833 | PgbsonWriterInit(&writer); |
| 5834 | pgbson_array_writer arrayWriter; |
| 5835 | PgbsonWriterStartArray(&writer, "", 0, &arrayWriter); |
| 5836 | |
| 5837 | foreach(innerCell, pathState->singleOps) |
| 5838 | { |
| 5839 | IndexElemMatchSingleOp *singleOp = lfirst(innerCell); |
| 5840 | |
| 5841 | pgbson_writer qualWriter; |
| 5842 | PgbsonArrayWriterStartDocument(&arrayWriter, &qualWriter); |
| 5843 | PgbsonWriterAppendInt32(&qualWriter, "op", 2, singleOp->op); |
| 5844 | PgbsonWriterAppendValue(&qualWriter, "value", 5, &singleOp->value); |
| 5845 | PgbsonWriterAppendBool(&qualWriter, "isTopLevel", 10, pathState->isTopLevel); |
| 5846 | PgbsonArrayWriterEndDocument(&arrayWriter, &qualWriter); |
| 5847 | } |
| 5848 | |
| 5849 | pgbsonelement queryElement; |
| 5850 | queryElement.path = pathState->indexPath; |
| 5851 | queryElement.pathLength = pathState->indexPathLength; |
no test coverage detected