/** * Parses an n-ary relational expression from the given json object */ public static NaryFieldRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.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 NaryFieldRelationalExpression(field, op, new Path(x.asText())); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
/** * Parses an n-ary relational expression from the given json object */ public static NaryFieldRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.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 NaryFieldRelationalExpression(field, op, new Path(x.asText())); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected QueryExpression itrNaryFieldRelationalExpression(NaryFieldRelationalExpression q, Path context) { return new NaryFieldRelationalExpression(toRelative(q.getField(), context), q.getOp(), toRelative(q.getRfield(), context)); }
@Override protected QueryExpression itrNaryFieldRelationalExpression(NaryFieldRelationalExpression q, Path context) { return new NaryFieldRelationalExpression(toRelative(q.getField(), context), q.getOp(), toRelative(q.getRfield(), context)); }
@Override protected QueryExpression itrNaryFieldRelationalExpression(NaryFieldRelationalExpression q, Path context) { Path r = map(applyContext(context, q.getRfield())); Path l = map(applyContext(context, q.getField())); if (r != null || l != null) { return new NaryFieldRelationalExpression(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 itrNaryFieldRelationalExpression(NaryFieldRelationalExpression q, Path context) { Path r = map(applyContext(context, q.getRfield())); Path l = map(applyContext(context, q.getField())); if (r != null || l != null) { return new NaryFieldRelationalExpression(l == null ? q.getField() : removeContext(context, l, q.getField()), q.getOp(), r == null ? q.getRfield() : removeContext(context, r, q.getRfield())); } else { return q; } }
return q; } else { return new NaryFieldRelationalExpression(removeContext(lfi.getFieldEntity(),addPrefix(q.getField())), q.getOp(), removeContext(rfi.getFieldEntity(),addPrefix(q.getRfield())));
return q; } else { return new NaryFieldRelationalExpression(removeContext(lfi.getFieldEntity(),addPrefix(q.getField())), q.getOp(), removeContext(rfi.getFieldEntity(),addPrefix(q.getRfield())));
@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; } }