private String writeComparisonJS(String field1,boolean field1IsArray, String field2,boolean field2IsArray, BinaryComparisonOperator op) { if(field1IsArray) { if(field2IsArray) { return writeArrayArrayComparisonJS(field1,field2,op); } else { return writeArrayFieldComparisonJS(field2,field1,BINARY_COMPARISON_OPERATOR_JS_MAP.get(op.invert())); } } else if(field2IsArray) { return writeArrayFieldComparisonJS(field1,field2,BINARY_COMPARISON_OPERATOR_JS_MAP.get(op)); } else { return String.format("if(this.%s %s this.%s) { return true;}",field1,BINARY_COMPARISON_OPERATOR_JS_MAP.get(op),field2); } }
/** * Parses a relational expression using the given object node */ public static RelationalExpression fromJson(ObjectNode node) { JsonNode x = node.get("regex"); if (x != null) { return RegexMatchExpression.fromJson(node); } else { x = node.get("op"); if (x != null) { String op = x.asText(); if (BinaryComparisonOperator.fromString(op) != null) { return BinaryRelationalExpression.fromJson(node); } else if (NaryRelationalOperator.fromString(op) != null) { return NaryRelationalExpression.fromJson(node); } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
/** * Returns the json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). set("rvalue", rvalue.toJson()); } }
int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) {
@Override public boolean evaluate(QueryEvaluationContext ctx) { Object value=rvalue.getValue(); LOGGER.debug("evaluate {} {} {}", field, operator, value); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(field); while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); int result = fieldMd.getType().compare(docValue, value); LOGGER.debug(" result={}", result); ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break; } } return ctx.getResult(); } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le=dyncast(UnaryLogicalExpression.class,q); if(le!=null&&le.getOp()==UnaryLogicalOperator._not) { ValueComparisonExpression vce=dyncast(ValueComparisonExpression.class,le.getQuery()); if(vce!=null) { return new ValueComparisonExpression(vce.getField(),vce.getOp().negate(),vce.getRvalue()); } else { FieldComparisonExpression fce=dyncast(FieldComparisonExpression.class,le.getQuery()); if(fce!=null) { return new FieldComparisonExpression(fce.getField(),fce.getOp().negate(),fce.getRfield()); } else { NaryRelationalExpression nre=dyncast(NaryRelationalExpression.class,le.getQuery()); if(nre!=null) { return new NaryRelationalExpression(nre.getField(),nre.getOp().negate(),nre.getValues()); } } } } return q; } }
int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); if (operator.apply(result)) { ctx.setResult(true); ((ArrayField) fieldMd).getElement().getType()).invert(); LOGGER.debug("Comparing array with field {} {} {}={}", ldocList, operator, rdocValue, resultOp); if (cmpOp(resultOp, operator)) {
ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break;
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { ValueComparisonExpression vce = dyncast(ValueComparisonExpression.class, le.getQuery()); if (vce != null) { return new ValueComparisonExpression(vce.getField(), vce.getOp().negate(), vce.getRvalue()); } else { FieldComparisonExpression fce = dyncast(FieldComparisonExpression.class, le.getQuery()); if (fce != null) { return new FieldComparisonExpression(fce.getField(), fce.getOp().negate(), fce.getRfield()); } else { NaryValueRelationalExpression nre = dyncast(NaryValueRelationalExpression.class, le.getQuery()); if (nre != null) { return new NaryValueRelationalExpression(nre.getField(), nre.getOp().negate(), nre.getValues()); } else { NaryFieldRelationalExpression nfe = dyncast(NaryFieldRelationalExpression.class, le.getQuery()); if (nfe != null) { return new NaryFieldRelationalExpression(nfe.getField(), nfe.getOp().negate(), nfe.getRfield()); } } } } } return q; } }
return new ValueComparisonExpression(removeContext(rfi.getFieldEntity(),addPrefix(rfi.getEntityRelativeFieldName())), q.getOp().invert(), value); } else { return new TruePH();
int result = fieldMd.getType().compare(ldocValue, rdocValue); LOGGER.debug(" result={}", result); boolean ret = operator.apply(result); if (ret) { ctx.setResult(ret);
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { ValueComparisonExpression vce = dyncast(ValueComparisonExpression.class, le.getQuery()); if (vce != null) { return new ValueComparisonExpression(vce.getField(), vce.getOp().negate(), vce.getRvalue()); } else { FieldComparisonExpression fce = dyncast(FieldComparisonExpression.class, le.getQuery()); if (fce != null) { return new FieldComparisonExpression(fce.getField(), fce.getOp().negate(), fce.getRfield()); } else { NaryValueRelationalExpression nre = dyncast(NaryValueRelationalExpression.class, le.getQuery()); if (nre != null) { return new NaryValueRelationalExpression(nre.getField(), nre.getOp().negate(), nre.getValues()); } else { NaryFieldRelationalExpression nfe = dyncast(NaryFieldRelationalExpression.class, le.getQuery()); if (nfe != null) { return new NaryFieldRelationalExpression(nfe.getField(), nfe.getOp().negate(), nfe.getRfield()); } } } } } return q; } }
/** * Returns json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). put("rfield", rfield.toString()); } }
/** * Parses a relational expression using the given object node */ public static RelationalExpression fromJson(ObjectNode node) { JsonNode x = node.get("regex"); if (x != null) { return RegexMatchExpression.fromJson(node); } else { x = node.get("op"); if (x != null) { String op = x.asText(); if (BinaryComparisonOperator.fromString(op) != null) { return BinaryRelationalExpression.fromJson(node); } else if (NaryRelationalOperator.fromString(op) != null) { return NaryRelationalExpression.fromJson(node); } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
return new ValueComparisonExpression(removeContext(rfi.getFieldEntity(),addPrefix(rfi.getEntityRelativeFieldName())), q.getOp().invert(), value); } else { return new TruePH();
ctx.setResult(operator.apply(result)); if (ctx.getResult()) { break;
/** * Returns json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). put("rfield", rfield.toString()); } }
/** * Parses a field comparison or value comparison expression from the given * json object */ public static BinaryRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { BinaryComparisonOperator op = BinaryComparisonOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("rfield"); if (x != null) { return new FieldComparisonExpression(field, op, new Path(x.asText())); } else { x = node.get("rvalue"); if (x != null) { return new ValueComparisonExpression(field, op, Value.fromJson(x)); } } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
arrayFieldName=rfieldName; simpleFieldName=lfieldName; op=query.getOp().invert(); isDate=((ArrayField)rFieldMd).getElement().getType() instanceof DateType && lFieldMd.getType() instanceof DateType; } else {
/** * Returns the json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). set("rvalue", rvalue.toJson()); } }