/** * Appends objectType:X to the query */ public static QueryExpression appendObjectType(QueryExpression q,String entityName) { QueryExpression ot=new ValueComparisonExpression(DocTranslator.OBJECT_TYPE,BinaryComparisonOperator._eq,new Value(entityName)); if(q==null) { return ot; } if(q instanceof NaryLogicalExpression && ((NaryLogicalExpression)q).getOp()==NaryLogicalOperator._and) { List<QueryExpression> l=new ArrayList<>(((NaryLogicalExpression)q).getQueries()); l.add(ot); return new NaryLogicalExpression(NaryLogicalOperator._and,l); } else { return new NaryLogicalExpression(NaryLogicalOperator._and,q,ot); } }
/** * Returns a json representation of this query */ @Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (QueryExpression x : queries) { arr.add(x.toJson()); } return getFactory().objectNode().set(op.toString(), arr); }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
public static QueryExpression combine(NaryLogicalOperator op, List<QueryExpression> list) { List<QueryExpression> l = list.stream().filter(q -> q != null).collect(Collectors.toList()); if (l.size() == 0) { return null; } else if (l.size() == 1) { return l.get(0); } else { return new NaryLogicalExpression(op, l); } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le=dyncast(NaryLogicalExpression.class,q); if(le!=null) if(le.getQueries().size()==1) return le.getQueries().get(0); return q; } }
/** * Parses a query expression from the given json node */ public static QueryExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { ObjectNode onode = (ObjectNode) node; // If there is only one field, then that field must be a // logical operator String firstField = onode.fieldNames().next(); if (UnaryLogicalOperator.fromString(firstField) != null) { return UnaryLogicalExpression.fromJson(onode); } else if (NaryLogicalOperator.fromString(firstField) != null) { return NaryLogicalExpression.fromJson(onode); } else { return ComparisonExpression.fromJson(onode); } } else { throw Error.get(QueryConstants.ERR_INVALID_QUERY, node.toString()); } }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
public static QueryExpression combine(NaryLogicalOperator op, List<QueryExpression> list) { List<QueryExpression> l = list.stream().filter(q -> q != null).collect(Collectors.toList()); if (l.size() == 0) { return null; } else if (l.size() == 1) { return l.get(0); } else { return new NaryLogicalExpression(op, l); } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getQueries().size() == 1) { return le.getQueries().get(0); } } return q; } }
/** * Parses a query expression from the given json node */ public static QueryExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { ObjectNode onode = (ObjectNode) node; // If there is only one field, then that field must be a // logical operator String firstField = onode.fieldNames().next(); if (UnaryLogicalOperator.fromString(firstField) != null) { return UnaryLogicalExpression.fromJson(onode); } else if (NaryLogicalOperator.fromString(firstField) != null) { return NaryLogicalExpression.fromJson(onode); } else { return ComparisonExpression.fromJson(onode); } } else { throw Error.get(QueryConstants.ERR_INVALID_QUERY, node.toString()); } }
@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; } }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
public void setQueries(List<Conjunct> conjuncts) { this.conjuncts = conjuncts; List<QueryExpression> l = new ArrayList<>(conjuncts.size()); for (Conjunct c : conjuncts) { l.add(c.getClause()); } if (l.isEmpty()) { query = null; } else if (l.size() == 1) { query = l.get(0); } else { query = new NaryLogicalExpression(NaryLogicalOperator._and, l); } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getQueries().size() == 1) { return le.getQueries().get(0); } } return q; } }
/** * Returns a json representation of this query */ @Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (QueryExpression x : queries) { arr.add(x.toJson()); } return getFactory().objectNode().set(op.toString(), arr); }
@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; } }
private DBObject translateNaryLogicalExpression(FieldTreeNode context, EntityMetadata md, NaryLogicalExpression expr, EntityMetadata emd, MutablePath fullPath) { List<QueryExpression> queries = expr.getQueries(); List<DBObject> list = new ArrayList<>(queries.size()); for (QueryExpression query : queries) { list.add(translate(context, query, emd, fullPath)); } return new BasicDBObject(NARY_LOGICAL_OPERATOR_MAP.get(expr.getOp()), list); }
public void setQueries(List<Conjunct> conjuncts) { this.conjuncts = conjuncts; List<QueryExpression> l = new ArrayList<>(conjuncts.size()); for (Conjunct c : conjuncts) { l.add(c.getClause()); } if (l.isEmpty()) { query = null; } else if (l.size() == 1) { query = l.get(0); } else { query = new NaryLogicalExpression(NaryLogicalOperator._and, l); } }
private static boolean isFieldQueried(Path field, NaryLogicalExpression q, Path context) { for (QueryExpression x : q.getQueries()) { if (x.isRequired(field, context)) { return true; } } return false; }
@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; } }