use of org.hibernate.query.sqm.tree.expression.SqmTuple in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitGenericFunctionArguments.
@Override
public List<SqmTypedNode<?>> visitGenericFunctionArguments(HqlParser.GenericFunctionArgumentsContext ctx) {
final int size = ctx.getChildCount();
final int lastIndex = size - 1;
// Shift 1 bit instead of division by 2
final int estimateArgumentCount = size >> 1;
final List<SqmTypedNode<?>> arguments = new ArrayList<>(estimateArgumentCount);
int i = 0;
boolean distinct = false;
final ParseTree firstChild = ctx.getChild(0);
if (firstChild instanceof HqlParser.DatetimeFieldContext) {
arguments.add(toDurationUnit((SqmExtractUnit<?>) firstChild.accept(this)));
i += 2;
} else if (firstChild instanceof TerminalNode) {
distinct = true;
i++;
}
for (; i < size; i += 2) {
// we handle the final argument differently...
if (i == lastIndex) {
arguments.add(visitFinalFunctionArgument(ctx.getChild(i)));
} else {
arguments.add((SqmTypedNode<?>) ctx.getChild(i).accept(this));
}
}
if (distinct) {
final NodeBuilder nodeBuilder = getCreationContext().getNodeBuilder();
if (arguments.size() == 1) {
arguments.set(0, new SqmDistinct<>((SqmExpression<?>) arguments.get(0), nodeBuilder));
} else {
final List<SqmTypedNode<?>> newArguments = new ArrayList<>(1);
// noinspection unchecked
newArguments.add(new SqmDistinct<>(new SqmTuple<>((List<SqmExpression<?>>) (List<?>) arguments, nodeBuilder), nodeBuilder));
return newArguments;
}
}
return arguments;
}
Aggregations