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; }
public Set<String> getAllAliases() { return items.stream().map(i -> i.getProjectionAliasAsString()).collect(Collectors.toSet()); }
/** * INTERNAL USE ONLY this has to be invoked ONLY if the item is aggregate!!! * * @param aggregateSplit */ public OProjectionItem splitForAggregation(AggregateProjectionSplit aggregateSplit, OCommandContext ctx) { if (isAggregate()) { OProjectionItem result = new OProjectionItem(-1); result.alias = getProjectionAlias(); result.expression = expression.splitForAggregation(aggregateSplit, ctx); result.nestedProjection = nestedProjection; return result; } else { return this; } }
private static OProjectionItem projectionFromAlias(OIdentifier oIdentifier) { OProjectionItem result = new OProjectionItem(-1); result.setExpression(new OExpression(oIdentifier)); return result; }
public void deserialize(OResult fromResult) { distinct = fromResult.getProperty("distinct"); if (fromResult.getProperty("items") != null) { items = new ArrayList<>(); List<OResult> ser = fromResult.getProperty("items"); for (OResult x : ser) { OProjectionItem item = new OProjectionItem(-1); item.deserialize(x); items.add(item); } } }
/** * 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; }
if (items.size() == 0 || (items.size() == 1 && items.get(0).isAll()) && items.get(0).nestedProjection == null) { return iRecord; if (item.isAll()) { for (String alias : iRecord.getPropertyNames()) { Object val = item.convert(iRecord.getProperty(alias)); if (item.nestedProjection != null) { val = item.nestedProjection.apply(item.expression, val, iContext); result.setProperty(item.getProjectionAliasAsString(), item.execute(iRecord, iContext));
if (isAggregate(item)) { isSplitted = true; OProjectionItem post = item.splitForAggregation(result, ctx); OIdentifier postAlias = item.getProjectionAlias(); postAlias = new OIdentifier(postAlias, true); post.setAlias(postAlias); postAggregate.getItems().add(post); aggregate.getItems().addAll(result.getAggregate()); preAggregate.getItems().add(item); OProjectionItem aggItem = new OProjectionItem(-1); aggItem.setExpression(new OExpression(item.getProjectionAlias())); aggregate.getItems().add(aggItem); postAggregate.getItems().add(aggItem);
String alias = proj.getProjectionAlias().getStringValue(); if (proj.isAggregate()) { AggregationContext aggrCtx = preAggr.getProperty(alias); if (aggrCtx == null) { aggrCtx = proj.getAggregationContext(ctx); preAggr.setProperty(alias, aggrCtx); preAggr.setProperty(alias, proj.execute(next, ctx));
private void addReturnStep(OSelectExecutionPlan result, OCommandContext context, boolean profilingEnabled) { if (returnElements) { result.chain(new ReturnMatchElementsStep(context, profilingEnabled)); } else if (returnPaths) { result.chain(new ReturnMatchPathsStep(context, profilingEnabled)); } else if (returnPatterns) { result.chain(new ReturnMatchPatternsStep(context, profilingEnabled)); } else if (returnPathElements) { result.chain(new ReturnMatchPathElementsStep(context, profilingEnabled)); } else { OProjection projection = new OProjection(-1); projection.setItems(new ArrayList<>()); for (int i = 0; i < returnAliases.size(); i++) { OProjectionItem item = new OProjectionItem(-1); item.setExpression(returnItems.get(i)); item.setAlias(returnAliases.get(i)); item.setNestedProjection(returnNestedProjections.get(i)); projection.getItems().add(item); } result.chain(new ProjectionCalculationStep(projection, context, profilingEnabled)); } }
boolean isMappable = select.getProjection().getItems().stream().peek(i -> fields.add(i.getProjectionAliasAsString())) .allMatch(i -> i.getExpression().isBaseIdentifier()); if (!isMappable) fields.clear();
OProjectionItem newItem = new OProjectionItem(-1); newItem.setExpression(exp); OIdentifier groupByAlias = new OIdentifier("_$$$GROUP_BY_ALIAS$$$_" + (i++)); newItem.setAlias(groupByAlias); if (info.preAggregateProjection == null) { info.preAggregateProjection = new OProjection(-1);
final public OProjectionItem ProjectionItem() throws ParseException { OProjectionItem jjtn000 = new OProjectionItem(JJTPROJECTIONITEM); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { jjtn000.expression = Expression(); jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
if (info.orderApplied || info.expand || info.unwind != null || info.orderBy == null || info.orderBy.getItems().size() == 0 || info.projection == null || info.projection.getItems() == null || (info.projection.getItems().size() == 1 && info.projection.getItems().get(0).isAll())) { return; if (info.preAggregateProjection != null) { 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);
public OProjectionItem copy() { OProjectionItem result = new OProjectionItem(-1); result.all = all; result.alias = alias == null ? null : alias.copy(); result.expression = expression == null ? null : expression.copy(); result.nestedProjection = nestedProjection == null ? null : nestedProjection.copy(); result.aggregate = aggregate; return result; }
public Object execute(OIdentifiable iCurrentRecord, OCommandContext ctx) { Object result; if (all) { result = iCurrentRecord; } else { result = expression.execute(iCurrentRecord, ctx); } if (nestedProjection != null) { result = nestedProjection.apply(expression, result, ctx); } return convert(result); }
@Override public OExecutionStep copy(OCommandContext ctx) { return new GuaranteeEmptyCountStep(item.copy(), ctx, profilingEnabled); }
public void extractSubQueries(SubQueryCollector collector) { if (items != null) { for (OProjectionItem item : items) { item.extractSubQueries(collector); } } }
for (OOrderByItem item : orderBy.getItems()) { if (!allAliases.contains(item.getAlias())) { OProjectionItem newProj = new OProjectionItem(-1); if (item.getAlias() != null) { newProj.setExpression(new OExpression(new OIdentifier(item.getAlias()), item.getModifier())); } else if (item.getRecordAttr() != null) { ORecordAttribute attr = new ORecordAttribute(-1); attr.setName(item.getRecordAttr()); newProj.setExpression(new OExpression(attr, item.getModifier())); } else if (item.getRid() != null) { OExpression exp = new OExpression(-1); exp.setRid(item.getRid().copy()); newProj.setExpression(exp); newProj.setAlias(newAlias); item.setAlias(newAlias.getStringValue()); item.setModifier(null);
public OProjectionItem getExpandContent() { OProjectionItem result = new OProjectionItem(-1); result.setExpression(expression.getExpandContent()); return result; }