/** * for backward compatibility, translate "distinct(foo)" to "DISTINCT foo". This method modifies the projection itself. * * @param projection the projection */ protected static OProjection translateDistinct(OProjection projection) { if (projection != null && projection.getItems().size() == 1) { if (isDistinct(projection.getItems().get(0))) { projection = projection.copy(); OProjectionItem item = projection.getItems().get(0); OFunctionCall function = ((OBaseExpression) item.getExpression().getMathExpression()).getIdentifier().getLevelZero() .getFunctionCall(); OExpression exp = function.getParams().get(0); OProjectionItem resultItem = new OProjectionItem(-1); resultItem.setAlias(item.getAlias()); resultItem.setExpression(exp.copy()); OProjection result = new OProjection(-1); result.setItems(new ArrayList<>()); result.setDistinct(true); result.getItems().add(resultItem); return result; } } return projection; }
private OResult calculateProjections(OCommandContext ctx, OResult next) { long begin = profilingEnabled ? System.nanoTime() : 0; try { return this.projection.calculateSingle(ctx, next); } 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; OCreateVertexStatement that = (OCreateVertexStatement) o; if (targetClass != null ? !targetClass.equals(that.targetClass) : that.targetClass != null) return false; if (targetClusterName != null ? !targetClusterName.equals(that.targetClusterName) : that.targetClusterName != null) return false; if (targetCluster != null ? !targetCluster.equals(that.targetCluster) : that.targetCluster != null) return false; if (returnStatement != null ? !returnStatement.equals(that.returnStatement) : that.returnStatement != null) return false; if (insertBody != null ? !insertBody.equals(that.insertBody) : that.insertBody != null) return false; return true; }
public OProjection getExpandContent() { OProjection result = new OProjection(-1); result.setItems(new ArrayList<>()); result.getItems().add(this.getItems().get(0).getExpandContent()); return result; }
|| info.projection == null || info.projection.getItems() == null || (info.projection.getItems().size() == 1 && info.projection.getItems().get(0).isAll())) { return; List<OProjectionItem> additionalOrderByProjections = calculateAdditionalOrderByProjections(info.projection.getAllAliases(), newOrderBy); if (additionalOrderByProjections.size() > 0) { info.projectionAfterOrderBy = new OProjection(-1); info.projectionAfterOrderBy.setItems(new ArrayList<>()); for (String alias : info.projection.getAllAliases()) { info.projectionAfterOrderBy.getItems().add(projectionFromAlias(new OIdentifier(alias))); info.preAggregateProjection.getItems().add(item); info.aggregateProjection.getItems().add(projectionFromAlias(item.getAlias())); info.projection.getItems().add(projectionFromAlias(item.getAlias())); } else { info.projection.getItems().add(item);
private static boolean isCountStar(QueryPlanningInfo info) { if (info.aggregateProjection == null || info.projection == null || info.aggregateProjection.getItems().size() != 1 || info.projection.getItems().size() != 1) { return false; } OProjectionItem item = info.aggregateProjection.getItems().get(0); if (!item.getExpression().toString().equalsIgnoreCase("count(*)")) { return false; } return true; }
items.add(item); info.projection = new OProjection(items, returnDistinct); info.distinct = info.projection == null ? false : info.projection.isDistinct(); if (info.projection != null) { info.projection.setDistinct(false);
final public OProjection Projection() throws ParseException { OProjection jjtn000 = new OProjection(JJTPROJECTION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));java.util.List<OProjectionItem> items = new java.util.ArrayList<OProjectionItem>(); OProjectionItem lastItem = null; try { jjtn000.jjtSetLastToken(getToken(0)); jjtn000.items = items; {if (true) return jjtn000;} if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
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(); }
@Override public OExecutionStep copy(OCommandContext ctx) { return new ProjectionCalculationStep(projection.copy(), ctx, profilingEnabled); } }
protected static void optimizeQuery(QueryPlanningInfo info, OCommandContext ctx) { splitLet(info, ctx); rewriteIndexChainsAsSubqueries(info, ctx); extractSubQueries(info); if (info.projection != null && info.projection.isExpand()) { info.expand = true; info.projection = info.projection.getExpandContent(); } if (info.whereClause != null) { info.flattenedWhereClause = info.whereClause.flatten(); //this helps index optimization info.flattenedWhereClause = moveFlattededEqualitiesLeft(info.flattenedWhereClause); } splitProjectionsForGroupBy(info, ctx); addOrderByProjections(info); }
projection = new OProjection(-1); projection.deserialize(fromResult.getProperty("projection"));
@Override public int hashCode() { int result = target != null ? target.hashCode() : 0; result = 31 * result + (operations != null ? operations.hashCode() : 0); result = 31 * result + (upsert ? 1 : 0); result = 31 * result + (returnBefore ? 1 : 0); result = 31 * result + (returnAfter ? 1 : 0); result = 31 * result + (returnProjection != null ? returnProjection.hashCode() : 0); result = 31 * result + (whereClause != null ? whereClause.hashCode() : 0); result = 31 * result + (lockRecord != null ? lockRecord.hashCode() : 0); result = 31 * result + (limit != null ? limit.hashCode() : 0); result = 31 * result + (timeout != null ? timeout.hashCode() : 0); return result; }
private boolean handleHardwiredCountOnIndex(OSelectExecutionPlan result, QueryPlanningInfo info, OCommandContext ctx, boolean profilingEnabled) { OIndexIdentifier targetIndex = info.target == null ? null : info.target.getItem().getIndex(); if (targetIndex == null) { return false; } if (info.distinct || info.expand) { return false; } if (info.preAggregateProjection != null) { return false; } if (!isCountStar(info)) { return false; } if (!isMinimalQuery(info)) { return false; } result.chain(new CountFromIndexStep(targetIndex, info.projection.getAllAliases().iterator().next(), ctx, profilingEnabled)); return true; }
public OProjection copy() { OProjection result = new OProjection(-1); if (items != null) { result.items = items.stream().map(x -> x.copy()).collect(Collectors.toList()); } result.distinct = distinct; return result; }
info.projection.extractSubQueries(collector);
for (String alias : info.preAggregateProjection.getAllAliases()) { newItem.setAlias(groupByAlias); if (info.preAggregateProjection == null) { info.preAggregateProjection = new OProjection(-1); if (info.preAggregateProjection.getItems() == null) { info.preAggregateProjection.setItems(new ArrayList<>()); info.preAggregateProjection.getItems().add(newItem); newGroupBy.getItems().add(new OExpression(groupByAlias));
OProjection preAggregate = new OProjection(-1); preAggregate.setItems(new ArrayList<>()); OProjection aggregate = new OProjection(-1); aggregate.setItems(new ArrayList<>()); OProjection postAggregate = new OProjection(-1); postAggregate.setItems(new ArrayList<>()); for (OProjectionItem item : info.projection.getItems()) { result.reset(); if (isAggregate(item)) { postAlias = new OIdentifier(postAlias, true); post.setAlias(postAlias); postAggregate.getItems().add(post); aggregate.getItems().addAll(result.getAggregate()); preAggregate.getItems().addAll(result.getPreAggregate()); } else { preAggregate.getItems().add(item); aggregate.getItems().add(aggItem); postAggregate.getItems().add(aggItem); if (info.preAggregateProjection.getItems() == null || info.preAggregateProjection.getItems().size() == 0) { info.preAggregateProjection = null; if (info.aggregateProjection.getItems() == null || info.aggregateProjection.getItems().size() == 0) { info.aggregateProjection = null;
private static boolean isCountOnly(QueryPlanningInfo info) { if (info.aggregateProjection == null || info.projection == null || info.aggregateProjection.getItems().size() != 1 || info.projection.getItems().size() != 1) { return false; } OProjectionItem item = info.aggregateProjection.getItems().get(0); OExpression exp = item.getExpression(); if (exp.getMathExpression() != null && exp.getMathExpression() instanceof OBaseExpression) { OBaseExpression base = (OBaseExpression) exp.getMathExpression(); return base.isCount() && base.getModifier() == null; } return false; }
@Override public OCreateVertexStatement copy() { OCreateVertexStatement result = null; try { result = getClass().getConstructor(Integer.TYPE).newInstance(-1); } catch (Exception e) { throw new RuntimeException(e); } result.targetClass = targetClass == null ? null : targetClass.copy(); result.targetClusterName = targetClusterName == null ? null : targetClusterName.copy(); result.targetCluster = targetCluster == null ? null : targetCluster.copy(); result.returnStatement = returnStatement == null ? null : returnStatement.copy(); result.insertBody = insertBody == null ? null : insertBody.copy(); return result; }