Search in sources :

Example 1 with ArgumentsValidator

use of org.hibernate.query.sqm.produce.function.ArgumentsValidator in project hibernate-orm by hibernate.

the class InverseDistributionWindowEmulation method generateSqmOrderedSetAggregateFunctionExpression.

@Override
public <T> SelfRenderingSqmOrderedSetAggregateFunction<T> generateSqmOrderedSetAggregateFunctionExpression(List<? extends SqmTypedNode<?>> arguments, SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
    return new SelfRenderingInverseDistributionFunction<>(arguments, filter, withinGroupClause, impliedResultType, queryEngine) {

        @Override
        public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
            final Clause currentClause = walker.getCurrentClauseStack().getCurrent();
            if (currentClause == Clause.OVER) {
                return super.convertToSqlAst(walker);
            } else if (currentClause != Clause.SELECT) {
                throw new IllegalArgumentException("Can't emulate [" + getName() + "] in clause " + currentClause + ". Only the SELECT clause is supported!");
            }
            final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
            List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
            ArgumentsValidator argumentsValidator = getArgumentsValidator();
            if (argumentsValidator != null) {
                argumentsValidator.validateSqlTypes(arguments, getFunctionName());
            }
            List<SortSpecification> withinGroup;
            if (this.getWithinGroup() == null) {
                withinGroup = Collections.emptyList();
            } else {
                walker.getCurrentClauseStack().push(Clause.ORDER);
                try {
                    final List<SqmSortSpecification> sortSpecifications = this.getWithinGroup().getSortSpecifications();
                    withinGroup = new ArrayList<>(sortSpecifications.size());
                    for (SqmSortSpecification sortSpecification : sortSpecifications) {
                        final SortSpecification specification = (SortSpecification) walker.visitSortSpecification(sortSpecification);
                        if (specification != null) {
                            withinGroup.add(specification);
                        }
                    }
                } finally {
                    walker.getCurrentClauseStack().pop();
                }
            }
            final SelfRenderingFunctionSqlAstExpression function = new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), arguments, getFilter() == null ? null : (Predicate) getFilter().accept(walker), withinGroup, resultType, getMappingModelExpressible(walker, resultType));
            final Over<Object> windowFunction = new Over<>(function, new ArrayList<>(), Collections.emptyList());
            walker.registerQueryTransformer(new AggregateWindowEmulationQueryTransformer(windowFunction, withinGroup, null));
            return windowFunction;
        }
    };
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) SqmToSqlAstConverter(org.hibernate.query.sqm.sql.SqmToSqlAstConverter) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Over(org.hibernate.sql.ast.tree.expression.Over) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingOrderedSetAggregateFunctionSqlAstExpression) Clause(org.hibernate.sql.ast.Clause) SqmOrderByClause(org.hibernate.query.sqm.tree.select.SqmOrderByClause) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator)

Example 2 with ArgumentsValidator

use of org.hibernate.query.sqm.produce.function.ArgumentsValidator in project hibernate-orm by hibernate.

the class HypotheticalSetWindowEmulation method generateSqmOrderedSetAggregateFunctionExpression.

@Override
public <T> SelfRenderingSqmOrderedSetAggregateFunction<T> generateSqmOrderedSetAggregateFunctionExpression(List<? extends SqmTypedNode<?>> arguments, SqmPredicate filter, SqmOrderByClause withinGroupClause, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
    return new SelfRenderingSqmOrderedSetAggregateFunction<>(this, this, arguments, filter, withinGroupClause, impliedResultType, getArgumentsValidator(), getReturnTypeResolver(), queryEngine.getCriteriaBuilder(), getName()) {

        @Override
        public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
            final Clause currentClause = walker.getCurrentClauseStack().getCurrent();
            if (currentClause == Clause.OVER) {
                return super.convertToSqlAst(walker);
            } else if (currentClause != Clause.SELECT) {
                throw new IllegalArgumentException("Can't emulate [" + getName() + "] in clause " + currentClause + ". Only the SELECT clause is supported!");
            }
            final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
            List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
            ArgumentsValidator argumentsValidator = getArgumentsValidator();
            if (argumentsValidator != null) {
                argumentsValidator.validateSqlTypes(arguments, getFunctionName());
            }
            List<SortSpecification> withinGroup;
            if (this.getWithinGroup() == null) {
                withinGroup = Collections.emptyList();
            } else {
                walker.getCurrentClauseStack().push(Clause.ORDER);
                try {
                    final List<SqmSortSpecification> sortSpecifications = this.getWithinGroup().getSortSpecifications();
                    withinGroup = new ArrayList<>(sortSpecifications.size());
                    for (SqmSortSpecification sortSpecification : sortSpecifications) {
                        final SortSpecification specification = (SortSpecification) walker.visitSortSpecification(sortSpecification);
                        if (specification != null) {
                            withinGroup.add(specification);
                        }
                    }
                } finally {
                    walker.getCurrentClauseStack().pop();
                }
            }
            final SelfRenderingFunctionSqlAstExpression function = new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), Collections.emptyList(), getFilter() == null ? null : (Predicate) getFilter().accept(walker), Collections.emptyList(), resultType, getMappingModelExpressible(walker, resultType));
            final Over<Object> windowFunction = new Over<>(function, new ArrayList<>(), withinGroup);
            walker.registerQueryTransformer(new AggregateWindowEmulationQueryTransformer(windowFunction, withinGroup, arguments));
            return windowFunction;
        }
    };
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) SqmToSqlAstConverter(org.hibernate.query.sqm.sql.SqmToSqlAstConverter) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Over(org.hibernate.sql.ast.tree.expression.Over) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingOrderedSetAggregateFunctionSqlAstExpression) Clause(org.hibernate.sql.ast.Clause) SqmOrderByClause(org.hibernate.query.sqm.tree.select.SqmOrderByClause) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator) SelfRenderingSqmOrderedSetAggregateFunction(org.hibernate.query.sqm.function.SelfRenderingSqmOrderedSetAggregateFunction)

Example 3 with ArgumentsValidator

use of org.hibernate.query.sqm.produce.function.ArgumentsValidator in project hibernate-orm by hibernate.

the class SelfRenderingSqmAggregateFunction method convertToSqlAst.

@Override
public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
    final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
    List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
    ArgumentsValidator argumentsValidator = getArgumentsValidator();
    if (argumentsValidator != null) {
        argumentsValidator.validateSqlTypes(arguments, getFunctionName());
    }
    return new SelfRenderingAggregateFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), arguments, filter == null ? null : walker.visitNestedTopLevelPredicate(filter), resultType, getMappingModelExpressible(walker, resultType));
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator)

Example 4 with ArgumentsValidator

use of org.hibernate.query.sqm.produce.function.ArgumentsValidator in project hibernate-orm by hibernate.

the class SelfRenderingSqmOrderedSetAggregateFunction method convertToSqlAst.

@Override
public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
    final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
    List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
    ArgumentsValidator argumentsValidator = getArgumentsValidator();
    if (argumentsValidator != null) {
        argumentsValidator.validateSqlTypes(arguments, getFunctionName());
    }
    List<SortSpecification> withinGroup;
    if (this.withinGroup == null) {
        withinGroup = Collections.emptyList();
    } else {
        walker.getCurrentClauseStack().push(Clause.WITHIN_GROUP);
        try {
            final List<SqmSortSpecification> sortSpecifications = this.withinGroup.getSortSpecifications();
            withinGroup = new ArrayList<>(sortSpecifications.size());
            for (SqmSortSpecification sortSpecification : sortSpecifications) {
                final SortSpecification specification = (SortSpecification) walker.visitSortSpecification(sortSpecification);
                if (specification != null) {
                    withinGroup.add(specification);
                }
            }
        } finally {
            walker.getCurrentClauseStack().pop();
        }
    }
    return new SelfRenderingOrderedSetAggregateFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), arguments, getFilter() == null ? null : walker.visitNestedTopLevelPredicate(getFilter()), withinGroup, resultType, getMappingModelExpressible(walker, resultType));
}
Also used : SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification)

Example 5 with ArgumentsValidator

use of org.hibernate.query.sqm.produce.function.ArgumentsValidator in project hibernate-orm by hibernate.

the class SelfRenderingSqmWindowFunction method convertToSqlAst.

@Override
public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
    final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
    List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
    ArgumentsValidator argumentsValidator = getArgumentsValidator();
    if (argumentsValidator != null) {
        argumentsValidator.validateSqlTypes(arguments, getFunctionName());
    }
    return new SelfRenderingWindowFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), arguments, filter == null ? null : walker.visitNestedTopLevelPredicate(filter), respectNulls, fromFirst, resultType, getMappingModelExpressible(walker, resultType));
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator)

Aggregations

ArgumentsValidator (org.hibernate.query.sqm.produce.function.ArgumentsValidator)5 SqlAstNode (org.hibernate.sql.ast.tree.SqlAstNode)5 SqmSortSpecification (org.hibernate.query.sqm.tree.select.SqmSortSpecification)3 SortSpecification (org.hibernate.sql.ast.tree.select.SortSpecification)3 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)2 SelfRenderingOrderedSetAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingOrderedSetAggregateFunctionSqlAstExpression)2 SqmToSqlAstConverter (org.hibernate.query.sqm.sql.SqmToSqlAstConverter)2 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)2 SqmOrderByClause (org.hibernate.query.sqm.tree.select.SqmOrderByClause)2 Clause (org.hibernate.sql.ast.Clause)2 Over (org.hibernate.sql.ast.tree.expression.Over)2 Predicate (org.hibernate.sql.ast.tree.predicate.Predicate)2 SelfRenderingSqmOrderedSetAggregateFunction (org.hibernate.query.sqm.function.SelfRenderingSqmOrderedSetAggregateFunction)1