@Override protected QueryExpression itrArrayContainsExpression(ArrayContainsExpression q, Path context) { return new ArrayContainsExpression(toRelative(q.getArray(), context), q.getOp(), q.getValues()); }
private DBObject translateArrayContains(FieldTreeNode context, ArrayContainsExpression expr) { DBObject ret = null; FieldTreeNode arrayNode = resolve(context, expr.getArray()); if (arrayNode instanceof ArrayField) { Type t = ((ArrayField) arrayNode).getElement().getType(); switch (expr.getOp()) { case _all: ret = translateArrayContainsAll(t, expr.getArray(), expr.getValues()); break; case _any: ret = translateArrayContainsAny(t, expr.getArray(), expr.getValues()); break; case _none: ret = translateArrayContainsNone(t, expr.getArray(), expr.getValues()); break; } } else { throw Error.get(ERR_INVALID_FIELD, expr.toString()); } return ret; }
@Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; }
@Override protected QueryExpression itrArrayContainsExpression(ArrayContainsExpression q, Path context) { fieldInfo.add(resolveField(q.getArray(), context, q, true)); return q; }
/** * Parses an ArrayContainsExpression from a JSON object node. */ public static ArrayContainsExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("contains"); if (x != null) { ContainsOperator op = ContainsOperator.fromString(x.asText()); if (op != null) { x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new ArrayContainsExpression(field, op, values); } } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected T itrArrayContainsExpression(ArrayContainsExpression q, Path context) { if(q.getOp()==ContainsOperator._any) { return processAnyExpression(q); } else return null; }
@Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; }
private static boolean isFieldQueried(Path field, ArrayContainsExpression q, Path context) { LOGGER.debug("Checking if field {} is queried by array expression {}", field, q); return isFieldQueried(field, q.getArray(), context); }
/** * Parses an ArrayContainsExpression from a JSON object node. */ public static ArrayContainsExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("contains"); if (x != null) { ContainsOperator op = ContainsOperator.fromString(x.asText()); if (op != null) { x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new ArrayContainsExpression(field, op, values); } } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected T itrArrayContainsExpression(ArrayContainsExpression q, Path context) { if(q.getOp()==ContainsOperator._any) { return processAnyExpression(q); } else return null; }
@Override protected QueryExpression itrArrayContainsExpression(ArrayContainsExpression q, Path context) { return new ArrayContainsExpression(toRelative(q.getArray(), context), q.getOp(), q.getValues()); }
@Override public boolean evaluate(QueryEvaluationContext ctx) { boolean ret = false; JsonNode node = ctx.getNode(expr.getArray()); if (node instanceof ArrayNode) { ArrayNode array = (ArrayNode) node; List<Value> values = expr.getValues(); ContainsOperator op = expr.getOp(); Type t = elem.getType(); int numElementsContained = 0; for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { JsonNode valueNode = itr.next(); for (Value value : values) { Object v = value.getValue(); if (isValueInNode(valueNode, v, t)) { numElementsContained++; break; } } } ret = evaluateContainsOperator(op, numElementsContained, values); } ctx.setResult(ret); return ret; }
private DBObject translateArrayContains(FieldTreeNode context, EntityMetadata md, ArrayContainsExpression expr,MutablePath fullPath) { DBObject ret = null; FieldInfo finfo=resolveFieldForQuery(context,fullPath.immutableCopy(),expr.getArray()); if (finfo.fieldMd instanceof ArrayField) { Type t = ((ArrayField) finfo.fieldMd).getElement().getType(); switch (expr.getOp()) { case _all: ret = translateArrayContainsAll(t, finfo.field, expr.getValues()); break; case _any: ret = translateArrayContainsAny(t, finfo.field, expr.getValues()); break; case _none: ret = translateArrayContainsNone(t, finfo.field, expr.getValues()); break; } } else { throw Error.get(ERR_INVALID_FIELD, expr.toString()); } return ret; }
@Override protected QueryExpression itrArrayContainsExpression(ArrayContainsExpression q, Path context) { fieldInfo.add(resolveField(q.getArray(), context, q, true)); return q; }
BinaryComparisonOperator._eq, new Value(entity)), new ArrayContainsExpression(P_VERSIONS, ContainsOperator._any, versionList));
@Override protected QueryExpression itrArrayContainsExpression(ArrayContainsExpression q, Path context) { Path p = rewrite(context, q.getArray()); if (!p.equals(q.getArray())) { return new ArrayContainsExpression(p, q.getOp(), q.getValues()); } else { return q; } }
FieldTreeNode fieldMd=ctx.contextNode.resolve(query.getArray()); String valueArr=declareValueArray(ctx,((ArrayField)fieldMd).getElement(),query.getValues()); Block arrayContainsBlock=new Block(ctx.topLevel.newGlobal(ctx,query.getOp()==ContainsOperator._any?"false":"true")); arrayContainsBlock.add(arrayLoop); Name arrayName=ctx.varName(new Name(query.getArray())); SimpleStatement.S_BREAK)); switch(query.getOp()) { case _any: arrayLoop.add(new IfStatement(new SimpleExpression(arrayLoop.resultVar),
private static boolean isFieldQueried(Path field, ArrayContainsExpression q, Path context) { LOGGER.debug("Checking if field {} is queried by array expression {}", field, q); return isFieldQueried(field, q.getArray(), context); }