private void init() { //copying the content, so that it can be manipulated and optimized info = new QueryPlanningInfo(); info.projection = this.statement.getProjection() == null ? null : this.statement.getProjection().copy(); info.projection = translateDistinct(info.projection); info.distinct = info.projection == null ? false : info.projection.isDistinct(); if (info.projection != null) { info.projection.setDistinct(false); } info.target = this.statement.getTarget(); info.whereClause = this.statement.getWhereClause() == null ? null : this.statement.getWhereClause().copy(); info.whereClause = translateLucene(info.whereClause); info.perRecordLetClause = this.statement.getLetClause() == null ? null : this.statement.getLetClause().copy(); info.groupBy = this.statement.getGroupBy() == null ? null : this.statement.getGroupBy().copy(); info.orderBy = this.statement.getOrderBy() == null ? null : this.statement.getOrderBy().copy(); info.unwind = this.statement.getUnwind() == null ? null : this.statement.getUnwind().copy(); info.skip = this.statement.getSkip(); info.limit = this.statement.getLimit(); info.lockRecord = this.statement.getLockRecord(); }
private void handleTarget(OUpdateExecutionPlan result, OCommandContext ctx, OFromClause target, OWhereClause whereClause, boolean profilingEnabled) { OSelectStatement sourceStatement = new OSelectStatement(-1); sourceStatement.setTarget(target); sourceStatement.setWhereClause(whereClause); OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement); result.chain(new SubQueryStep(planner.createExecutionPlan(ctx, profilingEnabled, false), ctx, ctx, profilingEnabled)); }
@Override public OSelectStatement copy() { return super.copy(); } }
private void handleTarget(OUpdateExecutionPlan result, OCommandContext ctx, OFromClause target, OWhereClause whereClause, OTimeout timeout, boolean profilingEnabled) { OSelectStatement sourceStatement = new OSelectStatement(-1); sourceStatement.setTarget(target); sourceStatement.setWhereClause(whereClause); if (timeout != null) { sourceStatement.setTimeout(this.timeout.copy()); } OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement); result.chain(new SubQueryStep(planner.createExecutionPlan(ctx, profilingEnabled, false), ctx, ctx, profilingEnabled)); } }
private void validateStatement(OSelectStatement statement) { if (statement.getProjection() != null) { if (statement.getProjection().getItems().size() > 1) { throw new OCommandExecutionException("Projections cannot be used in live query " + statement); } else if (statement.getProjection().getItems().get(0).isAll()) { throw new OCommandExecutionException("Projections cannot be used in live query " + statement); } } if (statement.getTarget().getItem().getIdentifier() == null && statement.getTarget().getItem().getRids() == null) { throw new OCommandExecutionException("Live queries can only be executed against a Class or on RIDs" + statement); } if (statement.getOrderBy() != null) { throw new OCommandExecutionException("Live queries do not support ORDER BY " + statement); } if (statement.getGroupBy() != null) { throw new OCommandExecutionException("Live queries do not support GROUP BY " + statement); } if (statement.getSkip() != null || statement.getLimit() != null) { throw new OCommandExecutionException("Live queries do not support SKIP/LIMIT " + statement); } }
ORid rid = this.aliasRids.get(patternNode.alias); OWhereClause where = aliasFilters.get(patternNode.alias); OSelectStatement select = new OSelectStatement(-1); select.setTarget(new OFromClause(-1)); select.getTarget().setItem(new OFromItem(-1)); if (clazz != null) { select.getTarget().getItem().setIdentifier(new OIdentifier(clazz)); } else if (cluster != null) { select.getTarget().getItem().setCluster(new OCluster(cluster)); } else if (rid != null) { select.getTarget().getItem().setRids(Collections.singletonList(rid)); select.setWhereClause(where == null ? null : where.copy()); OBasicCommandContext subContxt = new OBasicCommandContext(); subContxt.setParentWithoutOverridingChild(context); plan.chain( new MatchFirstStep(context, patternNode, select.createExecutionPlan(subContxt, profilingEnabled), profilingEnabled));
final public OSelectStatement SelectStatement() throws ParseException { OSelectStatement jjtn000 = new OSelectStatement(JJTSELECTSTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { jj_consume_token(SELECT); jjtn000.jjtSetLastToken(getToken(0)); jjtn000.validate(); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
private void handleSource(OUpdateExecutionPlan result, OCommandContext ctx, OFromItem source, boolean profilingEnabled) { OSelectStatement sourceStatement = new OSelectStatement(-1); sourceStatement.setTarget(new OFromClause(-1)); sourceStatement.getTarget().setItem(source); OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement); result.chain(new SubQueryStep(planner.createExecutionPlan(ctx, profilingEnabled, false), ctx, ctx, profilingEnabled)); } }
if (select.getProjection() != null) { boolean isMappable = select.getProjection().getItems().stream().peek(i -> fields.add(i.getProjectionAliasAsString())) .allMatch(i -> i.getExpression().isBaseIdentifier()); if (!isMappable)
private void addPrefetchSteps(OSelectExecutionPlan result, Set<String> aliasesToPrefetch, OCommandContext context, boolean profilingEnabled) { for (String alias : aliasesToPrefetch) { String targetClass = aliasClasses.get(alias); String targetCluster = aliasClusters.get(alias); ORid targetRid = aliasRids.get(alias); OWhereClause filter = aliasFilters.get(alias); OSelectStatement prefetchStm = createSelectStatement(targetClass, targetCluster, targetRid, filter); MatchPrefetchStep step = new MatchPrefetchStep(context, prefetchStm.createExecutionPlan(context, profilingEnabled), alias, profilingEnabled); result.chain(step); } }
public OInternalExecutionPlan createExecutionPlan(OCommandContext ctx, boolean enableProfiling, boolean useCache) { ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) ctx.getDatabase(); if (useCache && !enableProfiling && statement.executinPlanCanBeCached()) { OExecutionPlan plan = OExecutionPlanCache.get(statement.getOriginalStatement(), ctx, db); if (plan != null) { return (OInternalExecutionPlan) plan; if (useCache && !enableProfiling && statement.executinPlanCanBeCached() && result.canBeCached() && OExecutionPlanCache.getLastInvalidation(db) < planningStart) { OExecutionPlanCache.put(statement.getOriginalStatement(), result, (ODatabaseDocumentInternal) ctx.getDatabase());
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; OInCondition that = (OInCondition) o; if (left != null ? !left.equals(that.left) : that.left != null) return false; if (operator != null ? !operator.equals(that.operator) : that.operator != null) return false; if (rightStatement != null ? !rightStatement.equals(that.rightStatement) : that.rightStatement != null) return false; if (rightParam != null ? !rightParam.equals(that.rightParam) : that.rightParam != null) return false; if (rightMathExpression != null ? !rightMathExpression.equals(that.rightMathExpression) : that.rightMathExpression != null) return false; if (right != null ? !right.equals(that.right) : that.right != null) return false; if (inputFinalValue != null ? !inputFinalValue.equals(that.inputFinalValue) : that.inputFinalValue != null) return false; return true; }
private OSelectStatement buildSelectStatement(String className, OWhereClause oWhereClause) { OSelectStatement stm = new OSelectStatement(-1); stm.whereClause = oWhereClause; stm.target = new OFromClause(-1); stm.target.item = new OFromItem(-1); stm.target.item.identifier = new OIdentifier(className); return stm; }
@Override public boolean isCacheable() { if (left != null && !left.isCacheable()) { return false; } if (rightStatement != null && !rightStatement.executinPlanCanBeCached()) { return false; } if (rightMathExpression != null && !rightMathExpression.isCacheable()) { return false; } return true; }
protected static Object executeQuery(OSelectStatement rightStatement, OCommandContext ctx) { OBasicCommandContext subCtx = new OBasicCommandContext(); subCtx.setParentWithoutOverridingChild(ctx); OResultSet result = rightStatement.execute(ctx.getDatabase(), ctx.getInputParameters()); return result.stream().collect(Collectors.toSet()); }
@Override public OResultSet execute(ODatabase db, Object[] args, OCommandContext parentCtx) { OBasicCommandContext ctx = new OBasicCommandContext(); if (parentCtx != null) { ctx.setParentWithoutOverridingChild(parentCtx); } ctx.setDatabase(db); Map<Object, Object> params = new HashMap<>(); if (args != null) { for (int i = 0; i < args.length; i++) { params.put(i, args[i]); } } ctx.setInputParameters(params); OInternalExecutionPlan executionPlan = createExecutionPlan(ctx, false); OLocalResultSet result = new OLocalResultSet(executionPlan); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ONotInCondition that = (ONotInCondition) o; if (left != null ? !left.equals(that.left) : that.left != null) return false; if (operator != null ? !operator.equals(that.operator) : that.operator != null) return false; if (rightStatement != null ? !rightStatement.equals(that.rightStatement) : that.rightStatement != null) return false; if (right != null ? !right.equals(that.right) : that.right != null) return false; if (rightParam != null ? !rightParam.equals(that.rightParam) : that.rightParam != null) return false; if (rightMathExpression != null ? !rightMathExpression.equals(that.rightMathExpression) : that.rightMathExpression != null) return false; if (inputFinalValue != null ? !inputFinalValue.equals(that.inputFinalValue) : that.inputFinalValue != null) return false; return true; }
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 boolean isCacheable() { if (left != null && !left.isCacheable()) { return false; } if (rightStatement != null && !rightStatement.executinPlanCanBeCached()) { return false; } if (rightMathExpression != null && !rightMathExpression.isCacheable()) { return false; } return true; }
private void handleTarget(OUpdateExecutionPlan result, OCommandContext ctx, OFromClause target, OWhereClause whereClause, boolean profilingEnabled) { OSelectStatement sourceStatement = new OSelectStatement(-1); sourceStatement.setTarget(target); sourceStatement.setWhereClause(whereClause); OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement); result.chain(new SubQueryStep(planner.createExecutionPlan(ctx, profilingEnabled, false), ctx, ctx, profilingEnabled)); } }