Search in sources :

Example 1 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AstBuilder method visitLeft.

@Override
public Node visitLeft(SqlBaseParser.LeftContext context) {
    Expression strOrColName = (Expression) visit(context.strOrColName);
    Expression len = (Expression) visit(context.len);
    return new FunctionCall(QualifiedName.of("left"), List.of(strOrColName, len));
}
Also used : 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) FunctionCall(io.crate.sql.tree.FunctionCall)

Example 2 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AstBuilder method visitAtTimezone.

@Override
public Node visitAtTimezone(SqlBaseParser.AtTimezoneContext context) {
    Expression zone = (Expression) visit(context.zone);
    Expression timestamp = (Expression) visit(context.timestamp);
    return new FunctionCall(QualifiedName.of("timezone"), List.of(zone, timestamp));
}
Also used : 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) FunctionCall(io.crate.sql.tree.FunctionCall)

Example 3 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AtTimezoneSyntaxFunctionTest method test_at_time_zone_is_parsed_as_timezone_function_call.

@Test
public void test_at_time_zone_is_parsed_as_timezone_function_call() {
    FunctionCall func = (FunctionCall) SqlParser.createExpression("'1978-02-28T10:00:00+01:00' AT TIME ZONE 'Europe/Madrid'");
    assertEquals(func.getName(), QualifiedName.of("timezone"));
    assertEquals(func.getArguments().size(), 2);
    assertEquals(func.getArguments().get(0), StringLiteral.fromObject("Europe/Madrid"));
    assertEquals(func.getArguments().get(1), StringLiteral.fromObject("1978-02-28T10:00:00+01:00"));
}
Also used : FunctionCall(io.crate.sql.tree.FunctionCall) Test(org.junit.Test)

Example 4 with FunctionCall

use of io.crate.sql.tree.FunctionCall 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)

Example 5 with FunctionCall

use of io.crate.sql.tree.FunctionCall in project crate by crate.

the class AstBuilder method visitTableFunction.

@Override
public Node visitTableFunction(SqlBaseParser.TableFunctionContext ctx) {
    QualifiedName qualifiedName = getQualifiedName(ctx.qname());
    List<Expression> arguments = visitCollection(ctx.valueExpression(), Expression.class);
    return new TableFunction(new FunctionCall(qualifiedName, arguments));
}
Also used : 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) QualifiedName(io.crate.sql.tree.QualifiedName) TableFunction(io.crate.sql.tree.TableFunction) FunctionCall(io.crate.sql.tree.FunctionCall)

Aggregations

FunctionCall (io.crate.sql.tree.FunctionCall)8 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)7 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)7 Expression (io.crate.sql.tree.Expression)7 NegativeExpression (io.crate.sql.tree.NegativeExpression)7 ParameterExpression (io.crate.sql.tree.ParameterExpression)7 SubqueryExpression (io.crate.sql.tree.SubqueryExpression)7 SubscriptExpression (io.crate.sql.tree.SubscriptExpression)7 ArithmeticExpression (io.crate.sql.tree.ArithmeticExpression)6 ArraySliceExpression (io.crate.sql.tree.ArraySliceExpression)6 ArraySubQueryExpression (io.crate.sql.tree.ArraySubQueryExpression)6 IfExpression (io.crate.sql.tree.IfExpression)6 InListExpression (io.crate.sql.tree.InListExpression)6 LogicalBinaryExpression (io.crate.sql.tree.LogicalBinaryExpression)6 NotExpression (io.crate.sql.tree.NotExpression)6 SearchedCaseExpression (io.crate.sql.tree.SearchedCaseExpression)6 SimpleCaseExpression (io.crate.sql.tree.SimpleCaseExpression)6 EscapedCharStringLiteral (io.crate.sql.tree.EscapedCharStringLiteral)3 QualifiedName (io.crate.sql.tree.QualifiedName)3 StringLiteral (io.crate.sql.tree.StringLiteral)3