@Override public OBinaryCondition copy() { OBinaryCondition result = new OBinaryCondition(-1); result.left = left.copy(); result.operator = (OBinaryCompareOperator) operator.copy(); result.right = right.copy(); return result; }
private List<OBinaryCondition> filterIndexedFunctionsWithoutIndex(List<OBinaryCondition> indexedFunctionConditions, OFromClause fromClause, OCommandContext ctx) { if (indexedFunctionConditions == null) { return null; } List<OBinaryCondition> result = new ArrayList<>(); for (OBinaryCondition cond : indexedFunctionConditions) { if (cond.allowsIndexedFunctionExecutionOnTarget(fromClause, ctx)) { result.add(cond); } else if (!cond.canExecuteIndexedFunctionWithoutIndex(fromClause, ctx)) { throw new OCommandExecutionException("Cannot evaluate " + cond + ": no index defined"); } } return result; }
@Override public void reset() { index = null; condition = condition == null ? null : condition.copy(); additionalRangeCondition = additionalRangeCondition == null ? null : additionalRangeCondition.copy(); cost = 0; count = 0; inited = false; cursor = null; customIterator = null; nullKeyIterator = null; nextEntry = null; }
if (!binaryCondition.getLeft().isBaseIdentifier()) { return false; if (!(binaryCondition.getOperator() instanceof OEqualsCompareOperator)) { if (fields.size() == 1 && fields.get(0).equals(binaryCondition.getLeft().getDefaultAlias().getStringValue())) { OBinaryCondition indexCond = new OBinaryCondition(-1); indexCond.setLeft(new OExpression(new OIdentifier("key"))); indexCond.setOperator(new OEqualsCompareOperator(-1)); indexCond.setRight(((OBinaryCondition) condition).getRight().copy()); result.chain(new FetchFromIndexStep(classIndex, indexCond, null, ctx, profilingEnabled)); result.chain(new AggregateProjectionCalculationStep(info.aggregateProjection, info.groupBy, ctx, profilingEnabled));
OBinaryCondition blockCandidateFunction = null; for (OBinaryCondition cond : indexedFunctionConditions) { if (!cond.allowsIndexedFunctionExecutionOnTarget(info.target, ctx)) { if (!cond.canExecuteIndexedFunctionWithoutIndex(info.target, ctx)) { throw new OCommandExecutionException("Cannot execute " + block + " on " + queryTarget); blockCandidateFunction = cond; } else { boolean thisAllowsNoIndex = cond.canExecuteIndexedFunctionWithoutIndex(info.target, ctx); boolean prevAllowsNoIndex = blockCandidateFunction.canExecuteIndexedFunctionWithoutIndex(info.target, ctx); if (!thisAllowsNoIndex && !prevAllowsNoIndex) { } else if (thisAllowsNoIndex && prevAllowsNoIndex) { long thisEstimate = cond.estimateIndexed(info.target, ctx); long lastEstimate = blockCandidateFunction.estimateIndexed(info.target, ctx); if (thisEstimate > -1 && thisEstimate < lastEstimate) { blockCandidateFunction = cond; if (!blockCandidateFunction.executeIndexedFunctionAfterIndexSearch(info.target, ctx)) { block = block.copy(); block.getSubBlocks().remove(blockCandidateFunction);
final public OBooleanExpression BinaryCondition() throws ParseException { OBinaryCondition jjtn000 = new OBinaryCondition(JJTBINARYCONDITION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { jjtn000.left = Expression(); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
@Override public void deserialize(OResult fromResult) { try { OExecutionStepInternal.basicDeserialize(fromResult, this); functionCondition = new OBinaryCondition(-1); functionCondition.deserialize(fromResult.getProperty("functionCondition ")); queryTarget = new OFromClause(-1); queryTarget.deserialize(fromResult.getProperty("functionCondition ")); } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException(""), e); } } }
long estimation = condition.estimateIndexed(((OSelectStatement) this.preParsedStatement).getTarget(), getContext()); if (estimation > -1 && estimation < lastEstimation) { lastEstimation = estimation; .executeIndexedFunction(((OSelectStatement) this.preParsedStatement).getTarget(), getContext()); if (result == null) { return null;
private void init(OCommandContext ctx) { if (fullResult == null) { long begin = profilingEnabled ? System.nanoTime() : 0; try { fullResult = functionCondition.executeIndexedFunction(queryTarget, ctx).iterator(); } finally { if (profilingEnabled) { cost += (System.nanoTime() - begin); } } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IndexCondPair that = (IndexCondPair) o; if (mainCondition != null ? !mainCondition.equals(that.mainCondition) : that.mainCondition != null) return false; if (additionalRange != null ? !additionalRange.equals(that.additionalRange) : that.additionalRange != null) return false; return true; }
@Override public Optional<OUpdateItem> transformToUpdateItem() { if (!checkCanTransformToUpdate()) { return Optional.empty(); } if (operator instanceof OEqualsCompareOperator) { OUpdateItem result = new OUpdateItem(-1); result.operator = OUpdateItem.OPERATOR_EQ; OBaseExpression baseExp = ((OBaseExpression) left.mathExpression); result.left = baseExp.identifier.suffix.identifier.copy(); result.leftModifier = baseExp.modifier == null ? null : baseExp.modifier.copy(); result.right = right.copy(); return Optional.of(result); } return super.transformToUpdateItem(); }
@Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) { if (left.isFunctionAny()) { return evaluateAny(currentRecord, ctx); } Object leftVal = left.execute(currentRecord, ctx); Object rightVal = right.execute(currentRecord, ctx); OCollate collate = left.getCollate(currentRecord, ctx); if (collate == null) { collate = right.getCollate(currentRecord, ctx); } if (collate != null) { leftVal = collate.transform(leftVal); rightVal = collate.transform(rightVal); } return operator.execute(leftVal, rightVal); }
from.item = item; from.item.setIdentifier(new OIdentifier(oClass.getName())); long newCount = cond.estimateIndexed(from, ctx); if (newCount < conditionEstimation) { conditionEstimation = newCount;
OBinaryCondition keyCondition = new OBinaryCondition(-1); OIdentifier key = new OIdentifier("key"); keyCondition.setLeft(new OExpression(key)); boolean allowsRange = allowsRangeQueries(index); boolean found = false; OBooleanExpression singleExp = blockIterator.next(); 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 found = true; indexFieldFound = true; OBinaryCondition condition = new OBinaryCondition(-1); condition.setLeft(left); condition.setOperator(operator); condition.setRight(((OBinaryCondition) singleExp).getRight().copy()); indexKeyValue.getSubBlocks().add(condition); blockIterator.remove(); found = true; indexFieldFound = true; OBinaryCondition condition = new OBinaryCondition(-1); condition.setLeft(left);
@Override public void deserialize(OResult fromResult) { try { OExecutionStepInternal.basicDeserialize(fromResult, this); indexName = fromResult.getProperty("indexName"); if (fromResult.getProperty("condition") != null) { condition = OBooleanExpression.deserializeFromOResult(fromResult.getProperty("condition")); } if (fromResult.getProperty("additionalRangeCondition") != null) { additionalRangeCondition = new OBinaryCondition(-1); additionalRangeCondition.deserialize(fromResult.getProperty("additionalRangeCondition")); } orderAsc = fromResult.getProperty("orderAsc"); } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException(""), e); } }
private OSelectStatement indexChainToStatement(OModifier modifier, OClass clazz, OExpression right, OCommandContext ctx) { OClass queryClass = clazz; OSelectStatement result = new OSelectStatement(-1); result.target = new OFromClause(-1); result.target.setItem(new OFromItem(-1)); result.target.getItem().identifier = new OIdentifier(queryClass.getName()); result.whereClause = new OWhereClause(-1); OBinaryCondition base = new OBinaryCondition(-1); result.whereClause.baseExpression = new ONotBlock(-1); ((ONotBlock) result.whereClause.baseExpression).sub = base; ((ONotBlock) result.whereClause.baseExpression).negate = false; base.left = new OExpression(-1); base.left.mathExpression = new OBaseExpression(-1); ((OBaseExpression) base.left.mathExpression).identifier = new OBaseIdentifier(modifier.suffix.identifier); ((OBaseExpression) base.left.mathExpression).modifier = modifier.next == null ? null : modifier.next.copy(); base.operator = new OEqualsCompareOperator(-1); base.right = right.copy(); return result; } }
@Override public OExecutionStep copy(OCommandContext ctx) { FetchFromIndexStep result = new FetchFromIndexStep(indexName, this.condition == null ? null : this.condition.copy(), this.additionalRangeCondition == null ? null : this.additionalRangeCondition.copy(), this.orderAsc, ctx, this.profilingEnabled); return result; } }