/** * 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; }
info.distinct = info.projection == null ? false : info.projection.isDistinct(); if (info.projection != null) { info.projection.setDistinct(false);
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(); }