@Test public void one_$parent_value_comparison_returns_false_when_field_value_does_not_match_expression() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field6.nf7.$parent.$parent.field4','op':'<','rvalue':3.5}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); Assert.assertFalse(ctx.getResult()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { ctx.setResult(false); Object value = rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); boolean fieldValueExists = false; while (cursor.hasNext()) { fieldValueExists = true; cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); int result; if (value == null) { boolean docValueNull = valueNode == null || valueNode instanceof NullNode; if (docValueNull) { result = 0; } else { result = -1; } } else { Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" fieldvalue={} value={} type={}", docValue, value, fieldMd.getType().getName()); result = fieldMd.getType().compare(docValue, value); } LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } if (value == null && !fieldValueExists && operator == BinaryComparisonOperator._eq) { ctx.setResult(true); } return ctx.getResult(); }
ValueComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { ctx.setResult(false); Object value = rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); boolean fieldValueExists = false; while (cursor.hasNext()) { fieldValueExists = true; cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); int result; if (value == null) { boolean docValueNull = valueNode == null || valueNode instanceof NullNode; if (docValueNull) { result = 0; } else { result = -1; } } else { Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" fieldvalue={} value={} type={}", docValue, value, fieldMd.getType().getName()); result = fieldMd.getType().compare(docValue, value); } LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } if (value == null && !fieldValueExists && operator == BinaryComparisonOperator._eq) { ctx.setResult(true); } return ctx.getResult(); } }
ValueComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { ctx.setResult(false); Object value = rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); boolean fieldValueExists = false; while (cursor.hasNext()) { fieldValueExists = true; cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); int result; if (value == null) { boolean docValueNull = valueNode == null || valueNode instanceof NullNode; if (docValueNull) { result = 0; } else { result = -1; } } else { Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" fieldvalue={} value={} type={}", docValue, value, fieldMd.getType().getName()); result = fieldMd.getType().compare(docValue, value); } LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } if (value == null && !fieldValueExists && operator == BinaryComparisonOperator._eq) { ctx.setResult(true); } return ctx.getResult(); } ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context); }
ValueComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { ctx.setResult(false); Object value = rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); boolean fieldValueExists = false; while (cursor.hasNext()) { fieldValueExists = true; cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); int result; if (value == null) { boolean docValueNull = valueNode == null || valueNode instanceof NullNode; if (docValueNull) { result = 0; } else { result = -1; } } else { Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" fieldvalue={} value={} type={}", docValue, value, fieldMd.getType().getName()); result = fieldMd.getType().compare(docValue, value); } LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } if (value == null && !fieldValueExists && operator == BinaryComparisonOperator._eq) { ctx.setResult(true); } return ctx.getResult(); } ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx); }
ValueComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { ctx.setResult(false); Object value = rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); boolean fieldValueExists = false; while (cursor.hasNext()) { fieldValueExists = true; cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); int result; if (value == null) { boolean docValueNull = valueNode == null || valueNode instanceof NullNode; if (docValueNull) { result = 0; } else { result = -1; } } else { Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" fieldvalue={} value={} type={}", docValue, value, fieldMd.getType().getName()); result = fieldMd.getType().compare(docValue, value); } LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } if (value == null && !fieldValueExists && operator == BinaryComparisonOperator._eq) { ctx.setResult(true); } return ctx.getResult(); } ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }