/** * 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()); } }
/** * 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()); } }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { return new FieldComparisonExpression(toRelative(q.getField(), context), q.getOp(), toRelative(q.getRfield(), context)); }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { return new FieldComparisonExpression(toRelative(q.getField(), context), q.getOp(), toRelative(q.getRfield(), context)); }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { Path left = rewrite(context, q.getField()); Path right = rewrite(context, q.getRfield()); if (!left.equals(q.getField()) || !right.equals(q.getRfield())) { return new FieldComparisonExpression(left, q.getOp(), right); } else { return q; } }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { Path left = rewrite(context, q.getField()); Path right = rewrite(context, q.getRfield()); if (!left.equals(q.getField()) || !right.equals(q.getRfield())) { return new FieldComparisonExpression(left, q.getOp(), right); } else { return q; } }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { Path left = rewrite(context, q.getField()); Path right = rewrite(context, q.getRfield()); if (!left.equals(q.getField()) || !right.equals(q.getRfield())) { return new FieldComparisonExpression(left, q.getOp(), right); } else { return q; } }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { Path r = map(applyContext(context, q.getRfield())); Path l = map(applyContext(context, q.getField())); if (r != null || l != null) { return new FieldComparisonExpression(l == null ? q.getField() : removeContext(context, l, q.getField()), q.getOp(), r == null ? q.getRfield() : removeContext(context, r, q.getRfield())); } else { return q; } }
@Override protected QueryExpression itrFieldComparisonExpression(FieldComparisonExpression q, Path context) { Path r = map(applyContext(context, q.getRfield())); Path l = map(applyContext(context, q.getField())); if (r != null || l != null) { return new FieldComparisonExpression(l == null ? q.getField() : removeContext(context, l, q.getField()), q.getOp(), r == null ? q.getRfield() : removeContext(context, r, q.getRfield())); } else { return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { ArrayMatchExpression ae = dyncast(ArrayMatchExpression.class, q); QueryExpression newq = q; if (ae != null) { QueryExpression nestedq = ae.getElemMatch(); ValueComparisonExpression vce; FieldComparisonExpression fce; NaryValueRelationalExpression nvre; NaryFieldRelationalExpression nfre; if ((vce = dyncast(ValueComparisonExpression.class, nestedq)) != null) { newq = new ValueComparisonExpression(normalize(ae, vce.getField()), vce.getOp(), vce.getRvalue()); } else if ((fce = dyncast(FieldComparisonExpression.class, nestedq)) != null) { newq = new FieldComparisonExpression(normalize(ae, fce.getField()), fce.getOp(), normalize(ae, fce.getRfield())); } } return newq; }
@Override public QueryExpression rewrite(QueryExpression q) { ArrayMatchExpression ae = dyncast(ArrayMatchExpression.class, q); QueryExpression newq = q; if (ae != null) { QueryExpression nestedq = ae.getElemMatch(); ValueComparisonExpression vce; FieldComparisonExpression fce; NaryValueRelationalExpression nvre; NaryFieldRelationalExpression nfre; if ((vce = dyncast(ValueComparisonExpression.class, nestedq)) != null) { newq = new ValueComparisonExpression(normalize(ae, vce.getField()), vce.getOp(), vce.getRvalue()); } else if ((fce = dyncast(FieldComparisonExpression.class, nestedq)) != null) { newq = new FieldComparisonExpression(normalize(ae, fce.getField()), fce.getOp(), normalize(ae, fce.getRfield())); } } return newq; }
@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; } }
@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; } }
@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 q; } else { return new FieldComparisonExpression(addPrefix(q.getField()), q.getOp(), addPrefix(q.getRfield()));
return q; } else { return new FieldComparisonExpression(addPrefix(q.getField()), q.getOp(), addPrefix(q.getRfield()));