@Test public void nf3_less_than_nf9() throws Exception { QueryEvaluationContext ctx = QueryEvaluator. getInstance(EvalTestContext.queryExpressionFromJson("{'field':'field6.nf3','op':'<','rfield':'field6.nf9'}"), md). evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {} {}", relativePath, operator, rfieldRelativePath); KeyValueCursor<Path, JsonNode> lcursor = ctx.getNodes(relativePath); ctx.setResult(false); if (lcursor != null) { while (lcursor.hasNext() && !ctx.getResult()) { lcursor.next(); JsonNode lvalueNode = lcursor.getCurrentValue(); Object ldocValue = null; List<Object> ldocList = null; if (lvalueNode != null) { if (fieldMd.getType() instanceof ArrayType) { ldocList = makeList(((ArrayField) fieldMd).getElement().getType(), lvalueNode); } else { ldocValue = fieldMd.getType().fromJson(lvalueNode); } } KeyValueCursor<Path, JsonNode> rcursor = ctx.getNodes(rfieldRelativePath); if (rcursor != null) { while (rcursor.hasNext() && !ctx.getResult()) { rcursor.next(); JsonNode rvalueNode = rcursor.getCurrentValue(); Object rdocValue = null; List<Object> rdocList = null; if (rvalueNode != null) { if (rfieldMd.getType() instanceof ArrayType) { rdocList = makeList(((ArrayField) rfieldMd).getElement().getType(), rvalueNode); } else { rdocValue = rfieldMd.getType().fromJson(rvalueNode); } } LOGGER.debug(" lvalue={} rvalue={}", lvalueNode, rvalueNode); boolean leftIsValue = ldocValue != null || ldocList == null; boolean rightIsValue = rdocValue != null || rdocList == null; if (leftIsValue && rightIsValue) { int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); } } else if (!leftIsValue && !rightIsValue) { Type type = ((ArrayField) fieldMd).getElement().getType(); int ln = ldocList.size(); int rn = rdocList.size(); int cmp = 0; if (ln == rn) { for (int i = 0; i < ln; i++) { cmp = apply(cmp, type.compare(ldocList.get(i), rdocList.get(i))); } } else { cmp = 0x07; } LOGGER.debug("Comparing arrays {} {} {}={}", ldocList, operator, rdocList, cmp); if (cmpOp(CMP_LOOKUP[cmp], operator)) { ctx.setResult(true); } } else if (!leftIsValue) { BinaryComparisonOperator resultOp = lvCompare(rdocValue, ldocList, ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } else { BinaryComparisonOperator resultOp = lvCompare(ldocValue, rdocList, fieldMd.getType()); LOGGER.debug("Comparing field with array {} {} {}={}", ldocValue, operator, rdocList, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } } } } } return ctx.getResult(); }
FieldComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {} {}", relativePath, operator, rfieldRelativePath); KeyValueCursor<Path, JsonNode> lcursor = ctx.getNodes(relativePath); ctx.setResult(false); if (lcursor != null) { while (lcursor.hasNext() && !ctx.getResult()) { lcursor.next(); JsonNode lvalueNode = lcursor.getCurrentValue(); Object ldocValue = null; List<Object> ldocList = null; if (lvalueNode != null) { if (fieldMd.getType() instanceof ArrayType) { ldocList = makeList(((ArrayField) fieldMd).getElement().getType(), lvalueNode); } else { ldocValue = fieldMd.getType().fromJson(lvalueNode); } } KeyValueCursor<Path, JsonNode> rcursor = ctx.getNodes(rfieldRelativePath); if (rcursor != null) { while (rcursor.hasNext() && !ctx.getResult()) { rcursor.next(); JsonNode rvalueNode = rcursor.getCurrentValue(); Object rdocValue = null; List<Object> rdocList = null; if (rvalueNode != null) { if (rfieldMd.getType() instanceof ArrayType) { rdocList = makeList(((ArrayField) rfieldMd).getElement().getType(), rvalueNode); } else { rdocValue = rfieldMd.getType().fromJson(rvalueNode); } } LOGGER.debug(" lvalue={} rvalue={}", lvalueNode, rvalueNode); boolean leftIsValue = ldocValue != null || ldocList == null; boolean rightIsValue = rdocValue != null || rdocList == null; if (leftIsValue && rightIsValue) { int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); } } else if (!leftIsValue && !rightIsValue) { Type type = ((ArrayField) fieldMd).getElement().getType(); int ln = ldocList.size(); int rn = rdocList.size(); int cmp = 0; if (ln == rn) { for (int i = 0; i < ln; i++) { cmp = apply(cmp, type.compare(ldocList.get(i), rdocList.get(i))); } } else { cmp = 0x07; } LOGGER.debug("Comparing arrays {} {} {}={}", ldocList, operator, rdocList, cmp); if (cmpOp(CMP_LOOKUP[cmp], operator)) { ctx.setResult(true); } } else if (!leftIsValue) { BinaryComparisonOperator resultOp = lvCompare(rdocValue, ldocList, ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } else { BinaryComparisonOperator resultOp = lvCompare(ldocValue, rdocList, fieldMd.getType()); LOGGER.debug("Comparing field with array {} {} {}={}", ldocValue, operator, rdocList, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } } } } } return ctx.getResult(); } }
FieldComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {} {}", relativePath, operator, rfieldRelativePath); KeyValueCursor<Path, JsonNode> lcursor = ctx.getNodes(relativePath); ctx.setResult(false); if (lcursor != null) { while (lcursor.hasNext() && !ctx.getResult()) { lcursor.next(); JsonNode lvalueNode = lcursor.getCurrentValue(); Object ldocValue = null; List<Object> ldocList = null; if (lvalueNode != null) { if (fieldMd.getType() instanceof ArrayType) { ldocList = makeList(((ArrayField) fieldMd).getElement().getType(), lvalueNode); } else { ldocValue = fieldMd.getType().fromJson(lvalueNode); } } KeyValueCursor<Path, JsonNode> rcursor = ctx.getNodes(rfieldRelativePath); if (rcursor != null) { while (rcursor.hasNext() && !ctx.getResult()) { rcursor.next(); JsonNode rvalueNode = rcursor.getCurrentValue(); Object rdocValue = null; List<Object> rdocList = null; if (rvalueNode != null) { if (rfieldMd.getType() instanceof ArrayType) { rdocList = makeList(((ArrayField) rfieldMd).getElement().getType(), rvalueNode); } else { rdocValue = rfieldMd.getType().fromJson(rvalueNode); } } LOGGER.debug(" lvalue={} rvalue={}", lvalueNode, rvalueNode); boolean leftIsValue = ldocValue != null || ldocList == null; boolean rightIsValue = rdocValue != null || rdocList == null; if (leftIsValue && rightIsValue) { int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); } } else if (!leftIsValue && !rightIsValue) { Type type = ((ArrayField) fieldMd).getElement().getType(); int ln = ldocList.size(); int rn = rdocList.size(); int cmp = 0; if (ln == rn) { for (int i = 0; i < ln; i++) { cmp = apply(cmp, type.compare(ldocList.get(i), rdocList.get(i))); } } else { cmp = 0x07; } LOGGER.debug("Comparing arrays {} {} {}={}", ldocList, operator, rdocList, cmp); if (cmpOp(CMP_LOOKUP[cmp], operator)) { ctx.setResult(true); } } else if (!leftIsValue) { BinaryComparisonOperator resultOp = lvCompare(rdocValue, ldocList, ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } else { BinaryComparisonOperator resultOp = lvCompare(ldocValue, rdocList, fieldMd.getType()); LOGGER.debug("Comparing field with array {} {} {}={}", ldocValue, operator, rdocList, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } } } } } return ctx.getResult(); } FieldComparisonEvaluator(FieldComparisonExpression expr, FieldTreeNode context); }
FieldComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {} {}", relativePath, operator, rfieldRelativePath); KeyValueCursor<Path, JsonNode> lcursor = ctx.getNodes(relativePath); ctx.setResult(false); if (lcursor != null) { while (lcursor.hasNext() && !ctx.getResult()) { lcursor.next(); JsonNode lvalueNode = lcursor.getCurrentValue(); Object ldocValue = null; List<Object> ldocList = null; if (lvalueNode != null) { if (fieldMd.getType() instanceof ArrayType) { ldocList = makeList(((ArrayField) fieldMd).getElement().getType(), lvalueNode); } else { ldocValue = fieldMd.getType().fromJson(lvalueNode); } } KeyValueCursor<Path, JsonNode> rcursor = ctx.getNodes(rfieldRelativePath); if (rcursor != null) { while (rcursor.hasNext() && !ctx.getResult()) { rcursor.next(); JsonNode rvalueNode = rcursor.getCurrentValue(); Object rdocValue = null; List<Object> rdocList = null; if (rvalueNode != null) { if (rfieldMd.getType() instanceof ArrayType) { rdocList = makeList(((ArrayField) rfieldMd).getElement().getType(), rvalueNode); } else { rdocValue = rfieldMd.getType().fromJson(rvalueNode); } } LOGGER.debug(" lvalue={} rvalue={}", lvalueNode, rvalueNode); boolean leftIsValue = ldocValue != null || ldocList == null; boolean rightIsValue = rdocValue != null || rdocList == null; if (leftIsValue && rightIsValue) { int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); } } else if (!leftIsValue && !rightIsValue) { Type type = ((ArrayField) fieldMd).getElement().getType(); int ln = ldocList.size(); int rn = rdocList.size(); int cmp = 0; if (ln == rn) { for (int i = 0; i < ln; i++) { cmp = apply(cmp, type.compare(ldocList.get(i), rdocList.get(i))); } } else { cmp = 0x07; } LOGGER.debug("Comparing arrays {} {} {}={}", ldocList, operator, rdocList, cmp); if (cmpOp(CMP_LOOKUP[cmp], operator)) { ctx.setResult(true); } } else if (!leftIsValue) { BinaryComparisonOperator resultOp = lvCompare(rdocValue, ldocList, ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } else { BinaryComparisonOperator resultOp = lvCompare(ldocValue, rdocList, fieldMd.getType()); LOGGER.debug("Comparing field with array {} {} {}={}", ldocValue, operator, rdocList, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } } } } } return ctx.getResult(); } FieldComparisonEvaluator(FieldComparisonExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx); }
FieldComparisonEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {} {}", relativePath, operator, rfieldRelativePath); KeyValueCursor<Path, JsonNode> lcursor = ctx.getNodes(relativePath); ctx.setResult(false); if (lcursor != null) { while (lcursor.hasNext() && !ctx.getResult()) { lcursor.next(); JsonNode lvalueNode = lcursor.getCurrentValue(); Object ldocValue = null; List<Object> ldocList = null; if (lvalueNode != null) { if (fieldMd.getType() instanceof ArrayType) { ldocList = makeList(((ArrayField) fieldMd).getElement().getType(), lvalueNode); } else { ldocValue = fieldMd.getType().fromJson(lvalueNode); } } KeyValueCursor<Path, JsonNode> rcursor = ctx.getNodes(rfieldRelativePath); if (rcursor != null) { while (rcursor.hasNext() && !ctx.getResult()) { rcursor.next(); JsonNode rvalueNode = rcursor.getCurrentValue(); Object rdocValue = null; List<Object> rdocList = null; if (rvalueNode != null) { if (rfieldMd.getType() instanceof ArrayType) { rdocList = makeList(((ArrayField) rfieldMd).getElement().getType(), rvalueNode); } else { rdocValue = rfieldMd.getType().fromJson(rvalueNode); } } LOGGER.debug(" lvalue={} rvalue={}", lvalueNode, rvalueNode); boolean leftIsValue = ldocValue != null || ldocList == null; boolean rightIsValue = rdocValue != null || rdocList == null; if (leftIsValue && rightIsValue) { int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); } } else if (!leftIsValue && !rightIsValue) { Type type = ((ArrayField) fieldMd).getElement().getType(); int ln = ldocList.size(); int rn = rdocList.size(); int cmp = 0; if (ln == rn) { for (int i = 0; i < ln; i++) { cmp = apply(cmp, type.compare(ldocList.get(i), rdocList.get(i))); } } else { cmp = 0x07; } LOGGER.debug("Comparing arrays {} {} {}={}", ldocList, operator, rdocList, cmp); if (cmpOp(CMP_LOOKUP[cmp], operator)) { ctx.setResult(true); } } else if (!leftIsValue) { BinaryComparisonOperator resultOp = lvCompare(rdocValue, ldocList, ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } else { BinaryComparisonOperator resultOp = lvCompare(ldocValue, rdocList, fieldMd.getType()); LOGGER.debug("Comparing field with array {} {} {}={}", ldocValue, operator, rdocList, resultOp); if (cmpOp(resultOp, operator)) { ctx.setResult(true); } } } } } } return ctx.getResult(); } FieldComparisonEvaluator(FieldComparisonExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }