@Test public void elem_match_returns_false_when_no_values_in_array_match() throws Exception { QueryExpression expr = EvalTestContext.queryExpressionFromJson("{'array':'field7','elemMatch':{'field':'elemf3','op':'>','rvalue':10}}"); QueryEvaluator eval = QueryEvaluator.getInstance(expr, md); QueryEvaluationContext context = eval.evaluate(jsonDoc); Assert.assertFalse(context.getResult()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while(cursor.hasNext()&&!ret) { cursor.next(); JsonNode node=cursor.getCurrentValue(); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; int index = 0; QueryEvaluationContext nestedCtx = null; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode arrayElem = itr.next(); if (index == 0) { nestedCtx = ctx.firstElementNestedContext(arrayElem, field); } else { nestedCtx.elementNestedContext(arrayElem, index); } if (ev.evaluate(nestedCtx)) { ret = true; } index++; } } } ctx.setResult(ret); return ret; }
ArrayMatchEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while(cursor.hasNext()&&!ret) { cursor.next(); JsonNode node=cursor.getCurrentValue(); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; int index = 0; QueryEvaluationContext nestedCtx = null; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode arrayElem = itr.next(); if (index == 0) { nestedCtx = ctx.firstElementNestedContext(arrayElem, field); } else { nestedCtx.elementNestedContext(arrayElem, index); } if (ev.evaluate(nestedCtx)) { ret = true; } index++; } } } ctx.setResult(ret); return ret; } }
ArrayMatchEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while(cursor.hasNext()&&!ret) { cursor.next(); JsonNode node=cursor.getCurrentValue(); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; int index = 0; QueryEvaluationContext nestedCtx = null; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode arrayElem = itr.next(); if (index == 0) { nestedCtx = ctx.firstElementNestedContext(arrayElem, field); } else { nestedCtx.elementNestedContext(arrayElem, index); } if (ev.evaluate(nestedCtx)) { ret = true; } index++; } } } ctx.setResult(ret); return ret; } ArrayMatchEvaluator(ArrayMatchExpression expr,
                               FieldTreeNode context); }
ArrayMatchEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while(cursor.hasNext()&&!ret) { cursor.next(); JsonNode node=cursor.getCurrentValue(); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; int index = 0; QueryEvaluationContext nestedCtx = null; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode arrayElem = itr.next(); if (index == 0) { nestedCtx = ctx.firstElementNestedContext(arrayElem, field); } else { nestedCtx.elementNestedContext(arrayElem, index); } if (ev.evaluate(nestedCtx)) { ret = true; } index++; } } } ctx.setResult(ret); return ret; } ArrayMatchEvaluator(ArrayMatchExpression expr,
                               FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx); }
ArrayMatchEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while(cursor.hasNext()&&!ret) { cursor.next(); JsonNode node=cursor.getCurrentValue(); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; int index = 0; QueryEvaluationContext nestedCtx = null; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode arrayElem = itr.next(); if (index == 0) { nestedCtx = ctx.firstElementNestedContext(arrayElem, field); } else { nestedCtx.elementNestedContext(arrayElem, index); } if (ev.evaluate(nestedCtx)) { ret = true; } index++; } } } ctx.setResult(ret); return ret; } ArrayMatchEvaluator(ArrayMatchExpression expr,
                               FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }