private Map<String, Object> getEqualityOperations(OAndBlock condition, OCommandContext ctx) { Map<String, Object> result = new HashMap<String, Object>(); for (OBooleanExpression expression : condition.subBlocks) { if (expression instanceof OBinaryCondition) { OBinaryCondition b = (OBinaryCondition) expression; if (b.operator instanceof OEqualsCompareOperator) { if (b.left.isBaseIdentifier() && b.right.isEarlyCalculated(ctx)) { result.put(b.left.toString(), b.right.execute((OResult) null, ctx)); } } } } return result; }
public void deserialize(OResult fromResult) { if (fromResult.getProperty("expressions") != null) { expressions = new ArrayList<>(); List<OResult> ser = fromResult.getProperty("expressions"); for (OResult item : ser) { OExpression exp = new OExpression(-1); exp.deserialize(item); expressions.add(exp); } } }
/** * tests if current expression involves an indexed function AND that function can be used on this target * * @param target the query target * @param context the execution context * * @return true if current expression involves an indexed function AND that function can be used on this target, false otherwise */ public boolean allowsIndexedFunctionExecutionOnTarget(OFromClause target, OCommandContext context) { return left.allowsIndexedFunctionExecutionOnTarget(target, context, operator, right.execute((OResult) null, context)); }
/** * tests if current expression involves an indexed funciton AND that function can also be executed without using the index * * @param target the query target * @param context the execution context * * @return true if current expression involves an indexed function AND that function can be used on this target, false otherwise */ public boolean canExecuteIndexedFunctionWithoutIndex(OFromClause target, OCommandContext context) { return left.canExecuteIndexedFunctionWithoutIndex(target, context, operator, right.execute((OResult) null, context)); }
@Override public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) { return expression.execute(currentRecord, ctx) == null; }
OBinaryCondition keyCondition = new OBinaryCondition(-1); OIdentifier key = new OIdentifier("key"); keyCondition.setLeft(new OExpression(key)); boolean allowsRange = allowsRangeQueries(index); boolean found = false; if (singleExp instanceof OBinaryCondition) { OExpression left = ((OBinaryCondition) singleExp).getLeft(); if (left.isBaseIdentifier()) { String fieldName = left.getDefaultAlias().getStringValue(); if (indexField.equals(fieldName)) { OBinaryCompareOperator operator = ((OBinaryCondition) singleExp).getOperator(); if (!((OBinaryCondition) singleExp).getRight().isEarlyCalculated(ctx)) { continue; //this cannot be used because the value depends on single record condition.setLeft(left); condition.setOperator(operator); condition.setRight(((OBinaryCondition) singleExp).getRight().copy()); indexKeyValue.getSubBlocks().add(condition); blockIterator.remove(); condition.setLeft(left); condition.setOperator(operator); condition.setRight(((OBinaryCondition) singleExp).getRight().copy()); indexKeyValue.getSubBlocks().add(condition); blockIterator.remove(); condition.setLeft(left); condition.setOperator(operator);
private void processBinaryCondition() { OIndexDefinition definition = index.getDefinition(); OBinaryCompareOperator operator = ((OBinaryCondition) condition).getOperator(); OExpression left = ((OBinaryCondition) condition).getLeft(); if (!left.toString().equalsIgnoreCase("key")) { throw new OCommandExecutionException("search for index for " + condition + " is not supported yet"); } Object rightValue = ((OBinaryCondition) condition).getRight().execute((OResult) null, ctx); cursor = createCursor(operator, definition, rightValue, ctx); }
int i = 0; for (OExpression exp : info.groupBy.getItems()) { if (exp.isAggregate()) { throw new OCommandExecutionException("Cannot group by an aggregate function"); if (alias.equals(exp.getDefaultAlias().getStringValue()) && exp.isBaseIdentifier()) { found = true; newGroupBy.getItems().add(exp); newGroupBy.getItems().add(new OExpression(groupByAlias));
public OIdentifier getDefaultAlias() { OIdentifier identifier; if (isBaseIdentifier()) { identifier = new OIdentifier(((OBaseExpression) mathExpression).identifier.getSuffix().identifier.getStringValue()); } else { identifier = new OIdentifier(this.toString()); } return identifier; }
public void toString(Map<Object, Object> params, StringBuilder builder) { if (leftIdentifier != null) { builder.append("\""); leftIdentifier.toString(params, builder); builder.append("\""); } if (leftString != null) { builder.append("\""); builder.append(OExpression.encode(leftString)); builder.append("\""); } builder.append(": "); right.toString(params, builder); }
private Object calculateNewValue(OResultInternal doc, OCommandContext ctx, OMathExpression.Operator explicitOperator) { OExpression leftEx = new OExpression(left.copy()); if (leftModifier != null) { ((OBaseExpression) leftEx.mathExpression).modifier = leftModifier.copy(); } OMathExpression mathExp = new OMathExpression(-1); mathExp.getChildExpressions().add(leftEx.getMathExpression()); mathExp.getChildExpressions().add(new OParenthesisExpression(right.copy())); mathExp.getOperators().add(explicitOperator); return mathExp.execute(doc, ctx); }
public void applyUpdate(OResultInternal result, OCommandContext ctx) { if (right != null) { Object leftVal = left.execute(result, ctx); Object rightVal = right.execute(result, ctx); if (OMultiValue.isMultiValue(leftVal)) { OMultiValue.remove(leftVal, rightVal, false); if (OMultiValue.isMultiValue(rightVal)) { Iterator<Object> iter = OMultiValue.getMultiValueIterator(rightVal); while (iter.hasNext()) { Object item = iter.next(); if (item instanceof OResult && ((OResult) item).getIdentity().isPresent()) { OMultiValue.remove(leftVal, ((OResult) item).getIdentity().get(), false); } else { OMultiValue.remove(leftVal, item, false); } } } } } else { left.applyRemove(result, ctx); } } }
private OExpression fieldNamesToStrings(OExpression left) { if (left.isBaseIdentifier()) { OIdentifier identifier = ((OBaseExpression) left.mathExpression).identifier.suffix.identifier; OCollection newColl = new OCollection(-1); newColl.expressions = new ArrayList<>(); newColl.expressions.add(identifierToStringExpr(identifier)); OExpression result = new OExpression(-1); OBaseExpression newBase = new OBaseExpression(-1); result.mathExpression = newBase; if (exp.isBaseIdentifier()) { OIdentifier identifier = ((OBaseExpression) exp.mathExpression).identifier.suffix.identifier; OExpression val = identifierToStringExpr(identifier); OExpression result = new OExpression(-1); OBaseExpression newBase = new OBaseExpression(-1); result.mathExpression = newBase;
public void extractSubQueries(SubQueryCollector collector) { if (expression != null) { expression.extractSubQueries(collector); } else if (statement != null) { OIdentifier alias = collector.addStatement(statement); statement = null; expression = new OExpression(alias); } }
private static OProjectionItem projectionFromAlias(OIdentifier oIdentifier) { OProjectionItem result = new OProjectionItem(-1); result.setExpression(new OExpression(oIdentifier)); return result; }
if (select.getProjection() != null) { boolean isMappable = select.getProjection().getItems().stream().peek(i -> fields.add(i.getProjectionAliasAsString())) .allMatch(i -> i.getExpression().isBaseIdentifier()); if (!isMappable) fields.clear();
public void toString(Map<Object, Object> params, StringBuilder builder) { Object finalValue = bindFromInputParams(params); if (finalValue == this) { builder.append(":" + paramName); } else if (finalValue instanceof String) { builder.append("\""); builder.append(OExpression.encode(finalValue.toString())); builder.append("\""); } else if (finalValue instanceof SimpleNode) { ((SimpleNode) finalValue).toString(params, builder); } else { builder.append(finalValue); } }
@Override public void applyRemove(OResultInternal result, OCommandContext ctx) { if (expression != null) { expression.applyRemove(result, ctx); } else { throw new OCommandExecutionException("Cannot apply REMOVE " + toString()); } }