Search in sources :

Example 11 with WindowDefinition

use of io.crate.analyze.WindowDefinition in project crate by crate.

the class ExpressionAnalyzer method convertFunctionCall.

private Symbol convertFunctionCall(FunctionCall node, ExpressionAnalysisContext context) {
    List<Symbol> arguments = new ArrayList<>(node.getArguments().size());
    for (Expression expression : node.getArguments()) {
        Symbol argSymbol = expression.accept(innerAnalyzer, context);
        arguments.add(argSymbol);
    }
    List<String> parts = node.getName().getParts();
    // We don't set a default schema here because no supplied schema
    // means that we first try to lookup builtin functions, followed
    // by a lookup in the default schema for UDFs.
    String schema = null;
    String name;
    if (parts.size() == 1) {
        name = parts.get(0);
    } else {
        schema = parts.get(0);
        name = parts.get(1);
    }
    Symbol filter = node.filter().map(expression -> convert(expression, context)).orElse(null);
    WindowDefinition windowDefinition = getWindowDefinition(node.getWindow(), context);
    if (node.isDistinct()) {
        if (arguments.size() > 1) {
            throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "%s(DISTINCT x) does not accept more than one argument", node.getName()));
        }
        Symbol collectSetFunction = allocateFunction(CollectSetAggregation.NAME, arguments, filter, context, coordinatorTxnCtx, nodeCtx);
        // define the outer function which contains the inner function as argument.
        String nodeName = "collection_" + name;
        List<Symbol> outerArguments = List.of(collectSetFunction);
        try {
            return allocateBuiltinOrUdfFunction(schema, nodeName, outerArguments, null, node.ignoreNulls(), windowDefinition, context);
        } catch (UnsupportedOperationException ex) {
            throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "unknown function %s(DISTINCT %s)", name, arguments.get(0).valueType()), ex);
        }
    } else {
        return allocateBuiltinOrUdfFunction(schema, name, arguments, filter, node.ignoreNulls(), windowDefinition, context);
    }
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) NullLiteral(io.crate.sql.tree.NullLiteral) ArrayLikePredicate(io.crate.sql.tree.ArrayLikePredicate) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) LikeOperators(io.crate.expression.operator.LikeOperators) IntervalParser(io.crate.interval.IntervalParser) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) NegateFunctions(io.crate.expression.scalar.arithmetic.NegateFunctions) ExpressionFormatter(io.crate.sql.ExpressionFormatter) BetweenPredicate(io.crate.sql.tree.BetweenPredicate) Map(java.util.Map) ArrayLiteral(io.crate.sql.tree.ArrayLiteral) IntervalLiteral(io.crate.sql.tree.IntervalLiteral) AstVisitor(io.crate.sql.tree.AstVisitor) NotPredicate(io.crate.expression.predicate.NotPredicate) EscapedCharStringLiteral(io.crate.sql.tree.EscapedCharStringLiteral) CastMode(io.crate.expression.scalar.cast.CastMode) UndefinedType(io.crate.types.UndefinedType) TryCast(io.crate.sql.tree.TryCast) CurrentDateFunction(io.crate.expression.scalar.CurrentDateFunction) IfExpression(io.crate.sql.tree.IfExpression) NotExpression(io.crate.sql.tree.NotExpression) ObjectLiteral(io.crate.sql.tree.ObjectLiteral) HOUR(io.crate.sql.tree.IntervalLiteral.IntervalField.HOUR) MINUTE(io.crate.sql.tree.IntervalLiteral.IntervalField.MINUTE) SemanticSortValidator(io.crate.analyze.validator.SemanticSortValidator) FunctionCall(io.crate.sql.tree.FunctionCall) OrderyByAnalyzer(io.crate.analyze.relations.OrderyByAnalyzer) Extract(io.crate.sql.tree.Extract) SearchedCaseExpression(io.crate.sql.tree.SearchedCaseExpression) Operation(io.crate.metadata.table.Operation) InPredicate(io.crate.sql.tree.InPredicate) Operator(io.crate.expression.operator.Operator) ArrayList(java.util.ArrayList) CurrentTime(io.crate.sql.tree.CurrentTime) AndOperator(io.crate.expression.operator.AndOperator) BooleanLiteral(io.crate.sql.tree.BooleanLiteral) WindowFrameDefinition(io.crate.analyze.WindowFrameDefinition) QualifiedName(io.crate.sql.tree.QualifiedName) Nullable(javax.annotation.Nullable) MatchPredicate(io.crate.sql.tree.MatchPredicate) LogicalBinaryExpression(io.crate.sql.tree.LogicalBinaryExpression) CollectSetAggregation(io.crate.execution.engine.aggregation.impl.CollectSetAggregation) IsNullPredicate(io.crate.sql.tree.IsNullPredicate) ArraySliceExpression(io.crate.sql.tree.ArraySliceExpression) SubscriptFunctions(io.crate.expression.scalar.SubscriptFunctions) Reference(io.crate.metadata.Reference) IntegerLiteral(io.crate.sql.tree.IntegerLiteral) RecordSubscript(io.crate.sql.tree.RecordSubscript) Literal(io.crate.expression.symbol.Literal) BitStringType(io.crate.types.BitStringType) RegexpMatchCaseInsensitiveOperator(io.crate.expression.operator.RegexpMatchCaseInsensitiveOperator) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ConversionException(io.crate.exceptions.ConversionException) ArraySubQueryExpression(io.crate.sql.tree.ArraySubQueryExpression) DoubleLiteral(io.crate.sql.tree.DoubleLiteral) SimpleCaseExpression(io.crate.sql.tree.SimpleCaseExpression) SubscriptContext(io.crate.analyze.SubscriptContext) MapFunction(io.crate.expression.scalar.arithmetic.MapFunction) ExtractFunctions(io.crate.expression.scalar.ExtractFunctions) AllOperator(io.crate.expression.operator.AllOperator) RelationName(io.crate.metadata.RelationName) FieldProvider(io.crate.analyze.relations.FieldProvider) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) IsNotNullPredicate(io.crate.sql.tree.IsNotNullPredicate) Node(io.crate.sql.tree.Node) CurrentTimestampFunction(io.crate.expression.scalar.timestamp.CurrentTimestampFunction) ArrayType(io.crate.types.ArrayType) OrOperator(io.crate.expression.operator.OrOperator) NegateLiterals(io.crate.analyze.NegateLiterals) Locale(java.util.Locale) SelectSymbol(io.crate.expression.symbol.SelectSymbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) InListExpression(io.crate.sql.tree.InListExpression) SECOND(io.crate.sql.tree.IntervalLiteral.IntervalField.SECOND) YEAR(io.crate.sql.tree.IntervalLiteral.IntervalField.YEAR) Window(io.crate.sql.tree.Window) ArrayComparison(io.crate.sql.tree.ArrayComparison) NodeContext(io.crate.metadata.NodeContext) ParameterExpression(io.crate.sql.tree.ParameterExpression) Collection(java.util.Collection) EqOperator(io.crate.expression.operator.EqOperator) Signature(io.crate.metadata.functions.Signature) Lists2(io.crate.common.collections.Lists2) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) BitString(io.crate.sql.tree.BitString) AnyOperator(io.crate.expression.operator.any.AnyOperator) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) DataTypes(io.crate.types.DataTypes) WindowFunction(io.crate.expression.symbol.WindowFunction) Optional(java.util.Optional) Expression(io.crate.sql.tree.Expression) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) StringLiteral(io.crate.sql.tree.StringLiteral) WindowFrame(io.crate.sql.tree.WindowFrame) LongLiteral(io.crate.sql.tree.LongLiteral) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) HashMap(java.util.HashMap) RegexpMatchOperator(io.crate.expression.operator.RegexpMatchOperator) FrameBoundDefinition(io.crate.analyze.FrameBoundDefinition) MatchPredicateColumnIdent(io.crate.sql.tree.MatchPredicateColumnIdent) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) HashSet(java.util.HashSet) SubscriptValidator(io.crate.analyze.SubscriptValidator) ArithmeticExpression(io.crate.sql.tree.ArithmeticExpression) Cast(io.crate.sql.tree.Cast) DAY(io.crate.sql.tree.IntervalLiteral.IntervalField.DAY) MONTH(io.crate.sql.tree.IntervalLiteral.IntervalField.MONTH) Symbols(io.crate.expression.symbol.Symbols) SqlParser(io.crate.sql.parser.SqlParser) Nonnull(javax.annotation.Nonnull) NegativeExpression(io.crate.sql.tree.NegativeExpression) WhenClause(io.crate.sql.tree.WhenClause) ArrayFunction(io.crate.expression.scalar.arithmetic.ArrayFunction) CurrentTimeFunction(io.crate.expression.scalar.timestamp.CurrentTimeFunction) LikePredicate(io.crate.sql.tree.LikePredicate) Period(org.joda.time.Period) IfFunction(io.crate.expression.scalar.conditional.IfFunction) ArraySliceFunction(io.crate.expression.scalar.ArraySliceFunction) DataType(io.crate.types.DataType) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) Collectors.toList(java.util.stream.Collectors.toList) WindowDefinition(io.crate.analyze.WindowDefinition) FunctionType(io.crate.metadata.FunctionType) DataTypeAnalyzer(io.crate.analyze.DataTypeAnalyzer) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) FrameBound(io.crate.sql.tree.FrameBound) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) IfExpression(io.crate.sql.tree.IfExpression) NotExpression(io.crate.sql.tree.NotExpression) SearchedCaseExpression(io.crate.sql.tree.SearchedCaseExpression) LogicalBinaryExpression(io.crate.sql.tree.LogicalBinaryExpression) ArraySliceExpression(io.crate.sql.tree.ArraySliceExpression) ArraySubQueryExpression(io.crate.sql.tree.ArraySubQueryExpression) SimpleCaseExpression(io.crate.sql.tree.SimpleCaseExpression) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) InListExpression(io.crate.sql.tree.InListExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) ArithmeticExpression(io.crate.sql.tree.ArithmeticExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) SelectSymbol(io.crate.expression.symbol.SelectSymbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) BitString(io.crate.sql.tree.BitString) WindowDefinition(io.crate.analyze.WindowDefinition)

Aggregations

WindowDefinition (io.crate.analyze.WindowDefinition)11 Symbol (io.crate.expression.symbol.Symbol)9 OrderBy (io.crate.analyze.OrderBy)8 FunctionImplementation (io.crate.metadata.FunctionImplementation)8 ArrayList (java.util.ArrayList)8 NodeContext (io.crate.metadata.NodeContext)7 List (java.util.List)7 Literal (io.crate.expression.symbol.Literal)6 Symbols (io.crate.expression.symbol.Symbols)6 WindowFunction (io.crate.expression.symbol.WindowFunction)6 WindowFrame (io.crate.sql.tree.WindowFrame)6 DataType (io.crate.types.DataType)6 Nullable (javax.annotation.Nullable)6 TransactionContext (io.crate.metadata.TransactionContext)5 SymbolEvaluator.evaluateWithoutParams (io.crate.analyze.SymbolEvaluator.evaluateWithoutParams)4 RamAccounting (io.crate.breaker.RamAccounting)4 RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)4 Input (io.crate.data.Input)4 Projector (io.crate.data.Projector)4 Row (io.crate.data.Row)4