/** * Parses a unary logical expression using the given object node */ public static UnaryLogicalExpression fromJson(ObjectNode node) { if (node.size() != 1) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } String fieldName = node.fieldNames().next(); UnaryLogicalOperator op = UnaryLogicalOperator.fromString(fieldName); if (op == null) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } QueryExpression q = QueryExpression.fromJson(node.get(fieldName)); return new UnaryLogicalExpression(op, q); } }
/** * Parses a unary logical expression using the given object node */ public static UnaryLogicalExpression fromJson(ObjectNode node) { if (node.size() != 1) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } String fieldName = node.fieldNames().next(); UnaryLogicalOperator op = UnaryLogicalOperator.fromString(fieldName); if (op == null) { throw Error.get(QueryConstants.ERR_INVALID_LOGICAL_EXPRESSION, node.toString()); } QueryExpression q = QueryExpression.fromJson(node.get(fieldName)); return new UnaryLogicalExpression(op, q); } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le=dyncast(UnaryLogicalExpression.class,q); if(le!=null&&le.getOp()==UnaryLogicalOperator._not) { NaryLogicalExpression oreq=dyncast(NaryLogicalExpression.class,le.getQuery()); if(oreq!=null&&oreq.getOp()==NaryLogicalOperator._or) { List<QueryExpression> newList=new ArrayList<>(oreq.getQueries().size()); for(QueryExpression x:oreq.getQueries()) newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not,x)); return new NaryLogicalExpression(NaryLogicalOperator._and,newList); } } return q; } }
/** * Default behavior is to recursively iterate the nested query. If nested * processing returns an object different from the original nested query, * this method creates a new unary logical expression using the new query * expression, and returns that. */ protected QueryExpression itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { QueryExpression newq = iterate(q.getQuery(), context); if (newq != q.getQuery()) { return new UnaryLogicalExpression(q.getOp(), newq); } else { return q; } }
/** * Default behavior is to recursively iterate the nested query. If nested * processing returns an object different from the original nested query, * this method creates a new unary logical expression using the new query * expression, and returns that. */ protected QueryExpression itrUnaryLogicalExpression(UnaryLogicalExpression q, Path context) { QueryExpression newq = iterate(q.getQuery(), context); if (newq != q.getQuery()) { return new UnaryLogicalExpression(q.getOp(), newq); } else { return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { NaryLogicalExpression oreq = dyncast(NaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == NaryLogicalOperator._or) { List<QueryExpression> newList = new ArrayList<>(oreq.getQueries().size()); for (QueryExpression x : oreq.getQueries()) { newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not, x)); } return new NaryLogicalExpression(NaryLogicalOperator._and, newList); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { NaryLogicalExpression oreq = dyncast(NaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == NaryLogicalOperator._or) { List<QueryExpression> newList = new ArrayList<>(oreq.getQueries().size()); for (QueryExpression x : oreq.getQueries()) { newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not, x)); } return new NaryLogicalExpression(NaryLogicalOperator._and, newList); } } return q; } }
LOGGER.debug("Rewritten nested query={}",newNestedq); if(newNestedq!=nestedq) newq=new UnaryLogicalExpression( ((UnaryLogicalExpression)q).getOp(), newNestedq); } else if (q instanceof NaryLogicalExpression) { LOGGER.debug("q is a n-ary logical expression, rewriting nested terms");
LOGGER.debug("Rewritten nested query={}", newNestedq); if (newNestedq != nestedq) { newq = new UnaryLogicalExpression(((UnaryLogicalExpression) q).getOp(), newNestedq);
LOGGER.debug("Rewritten nested query={}", newNestedq); if (newNestedq != nestedq) { newq = new UnaryLogicalExpression(((UnaryLogicalExpression) q).getOp(), newNestedq);