use of org.hibernate.query.sqm.tree.expression.SqmStar in project hibernate-orm by hibernate.
the class AbstractCteMutationHandler method createCountStar.
private Expression createCountStar(SessionFactoryImplementor factory, MultiTableSqmMutationConverter sqmConverter) {
final SqmExpression<?> arg = new SqmStar(factory.getNodeBuilder());
final TypeConfiguration typeConfiguration = factory.getJpaMetamodel().getTypeConfiguration();
return factory.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor("count").generateSqmExpression(arg, null, factory.getQueryEngine(), typeConfiguration).convertToSqlAst(sqmConverter);
}
use of org.hibernate.query.sqm.tree.expression.SqmStar in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitGenericFunction.
@Override
public Object visitGenericFunction(HqlParser.GenericFunctionContext ctx) {
final String originalFunctionName = visitGenericFunctionName(ctx.genericFunctionName());
final String functionName = originalFunctionName.toLowerCase();
if (creationOptions.useStrictJpaCompliance() && !JPA_STANDARD_FUNCTIONS.contains(functionName)) {
throw new StrictJpaComplianceViolation("Encountered non-compliant non-standard function call [" + originalFunctionName + "], but strict JPA " + "compliance was requested; use JPA's FUNCTION(functionName[,...]) " + "syntax name instead", StrictJpaComplianceViolation.Type.FUNCTION_CALL);
}
final ParseTree argumentChild = ctx.getChild(2);
final List<SqmTypedNode<?>> functionArguments;
if (argumentChild instanceof HqlParser.GenericFunctionArgumentsContext) {
functionArguments = (List<SqmTypedNode<?>>) argumentChild.accept(this);
} else if ("*".equals(argumentChild.getText())) {
functionArguments = Collections.singletonList(new SqmStar(getCreationContext().getNodeBuilder()));
} else {
functionArguments = emptyList();
}
final Boolean fromFirst = getFromFirst(ctx);
final Boolean respectNulls = getRespectNullsClause(ctx);
final SqmOrderByClause withinGroup = getWithinGroup(ctx);
final SqmPredicate filterExpression = getFilterExpression(ctx);
final boolean hasOverClause = ctx.getChild(ctx.getChildCount() - 1) instanceof HqlParser.OverClauseContext;
SqmFunctionDescriptor functionTemplate = getFunctionDescriptor(functionName);
if (functionTemplate == null) {
FunctionKind functionKind = FunctionKind.NORMAL;
if (withinGroup != null) {
functionKind = FunctionKind.ORDERED_SET_AGGREGATE;
} else if (hasOverClause) {
functionKind = FunctionKind.WINDOW;
} else if (filterExpression != null) {
functionKind = FunctionKind.AGGREGATE;
}
functionTemplate = new NamedSqmFunctionDescriptor(functionName, true, null, StandardFunctionReturnTypeResolvers.invariant(resolveExpressibleTypeBasic(Object.class)), null, functionName, functionKind, null, SqlAstNodeRenderingMode.DEFAULT);
} else {
if (hasOverClause && functionTemplate.getFunctionKind() == FunctionKind.NORMAL) {
throw new SemanticException("OVER clause is illegal for normal function: " + functionName);
} else if (!hasOverClause && functionTemplate.getFunctionKind() == FunctionKind.WINDOW) {
throw new SemanticException("OVER clause is mandatory for window-only function: " + functionName);
}
if (respectNulls != null) {
switch(functionName) {
case "lag":
case "lead":
case "first_value":
case "last_value":
case "nth_value":
break;
default:
throw new SemanticException("RESPECT/IGNORE NULLS is illegal for function: " + functionName);
}
}
if (fromFirst != null && !"nth_value".equals(functionName)) {
throw new SemanticException("FROM FIRST/LAST is illegal for function: " + functionName);
}
}
final SqmFunction<?> function;
switch(functionTemplate.getFunctionKind()) {
case ORDERED_SET_AGGREGATE:
function = functionTemplate.generateOrderedSetAggregateSqmExpression(functionArguments, filterExpression, withinGroup, null, creationContext.getQueryEngine(), creationContext.getJpaMetamodel().getTypeConfiguration());
break;
case AGGREGATE:
function = functionTemplate.generateAggregateSqmExpression(functionArguments, filterExpression, null, creationContext.getQueryEngine(), creationContext.getJpaMetamodel().getTypeConfiguration());
break;
case WINDOW:
function = functionTemplate.generateWindowSqmExpression(functionArguments, filterExpression, null, null, null, creationContext.getQueryEngine(), creationContext.getJpaMetamodel().getTypeConfiguration());
break;
default:
if (filterExpression != null) {
throw new ParsingException("Illegal use of a FILTER clause for non-aggregate function: " + originalFunctionName);
}
function = functionTemplate.generateSqmExpression(functionArguments, null, creationContext.getQueryEngine(), creationContext.getJpaMetamodel().getTypeConfiguration());
break;
}
return applyOverClause(ctx, function);
}
use of org.hibernate.query.sqm.tree.expression.SqmStar in project hibernate-orm by hibernate.
the class CteInsertHandler method createCountStar.
private Expression createCountStar(SessionFactoryImplementor factory, MultiTableSqmMutationConverter sqmConverter) {
final SqmExpression<?> arg = new SqmStar(factory.getNodeBuilder());
final TypeConfiguration typeConfiguration = factory.getJpaMetamodel().getTypeConfiguration();
return factory.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor("count").generateSqmExpression(arg, null, factory.getQueryEngine(), typeConfiguration).convertToSqlAst(sqmConverter);
}
Aggregations