use of com.blazebit.persistence.parser.expression.VisitorAdapter in project blaze-persistence by Blazebit.
the class GroupByExpressionGatheringVisitor method extractGroupByExpressions.
public Set<Expression> extractGroupByExpressions(Expression expression, ClauseType clauseType) {
// Also, grouping by just a parameter does not make sense as the value is constant
if (expression instanceof LiteralExpression || expression instanceof ParameterExpression) {
return Collections.emptySet();
}
clear();
try {
// When having a predicate at the top level, we have to collect
collect = expression instanceof Predicate;
boolean expressionWasSplit = expression.accept(this);
// In the HAVING clause we additionally add the path expressions to the expression set for DBMS like MySQL that's don't support partial expression structure matching
if (clauseType == ClauseType.HAVING && !dbmsDialect.supportsGroupByExpressionInHavingMatching()) {
expression.accept(new VisitorAdapter() {
@Override
public void visit(FunctionExpression expression) {
// Skip aggregate expressions
if (expression instanceof AggregateExpression || (treatSizeAsAggregate && com.blazebit.persistence.parser.util.ExpressionUtils.isSizeFunction(expression))) {
return;
}
super.visit(expression);
}
@Override
public void visit(SubqueryExpression expression) {
GroupByExpressionGatheringVisitor.this.visit(expression);
}
@Override
public void visit(PathExpression expression) {
if (expression.getBaseNode() == null) {
((SelectInfo) aliasManager.getAliasInfo(expression.toString())).getExpression().accept(this);
} else {
expressions.add(expression);
}
}
@Override
public void visit(TreatExpression expression) {
expressions.add(expression);
}
@Override
public void visit(PropertyExpression expression) {
expressions.add(expression);
}
@Override
public void visit(ListIndexExpression expression) {
expressions.add(expression);
}
@Override
public void visit(MapEntryExpression expression) {
expressions.add(expression);
}
@Override
public void visit(MapKeyExpression expression) {
expressions.add(expression);
}
@Override
public void visit(MapValueExpression expression) {
expressions.add(expression);
}
});
return expressions;
}
if (expressionWasSplit) {
return expressions;
}
} catch (IllegalParameterException ex) {
throw new IllegalArgumentException("Can't use the expression '" + expression + "' as an implicit group by clause, because the parameter '" + ex.parameterExpression + "' with the value '" + ex.value + "' can't be rendered as literal which is required!", ex);
}
return Collections.singleton(expression);
}
Aggregations