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; }
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; }
if (select.getProjection() != null) { boolean isMappable = select.getProjection().getItems().stream().peek(i -> fields.add(i.getProjectionAliasAsString())) .allMatch(i -> i.getExpression().isBaseIdentifier()); if (!isMappable) fields.clear();
if (item.getExpression() == null) { return false; if (item.getExpression().getMathExpression() == null) { return false; if (!(item.getExpression().getMathExpression() instanceof OBaseExpression)) { return false; OBaseExpression base = (OBaseExpression) item.getExpression().getMathExpression(); if (base.getIdentifier() == null) { return false;
/** * 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; }