Search in sources :

Example 1 with TableFunction

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

the class AstBuilder method visitInsert.

@Override
public Node visitInsert(SqlBaseParser.InsertContext context) {
    List<String> columns = identsToStrings(context.ident());
    Table table;
    try {
        table = (Table) visit(context.table());
    } catch (ClassCastException e) {
        TableFunction tf = (TableFunction) visit(context.table());
        for (Expression ex : tf.functionCall().getArguments()) {
            if (!(ex instanceof QualifiedNameReference)) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH, "invalid table column reference %s", ex.toString()));
            }
        }
        throw e;
    }
    return new Insert<>(table, (Query) visit(context.insertSource().query()), columns, getReturningItems(context.returning()), createDuplicateKeyContext(context));
}
Also used : DropBlobTable(io.crate.sql.tree.DropBlobTable) ShowCreateTable(io.crate.sql.tree.ShowCreateTable) SwapTable(io.crate.sql.tree.SwapTable) CreateBlobTable(io.crate.sql.tree.CreateBlobTable) Table(io.crate.sql.tree.Table) AlterTable(io.crate.sql.tree.AlterTable) AlterBlobTable(io.crate.sql.tree.AlterBlobTable) CreateTable(io.crate.sql.tree.CreateTable) DropTable(io.crate.sql.tree.DropTable) 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) TableFunction(io.crate.sql.tree.TableFunction) BitString(io.crate.sql.tree.BitString) Insert(io.crate.sql.tree.Insert) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference)

Example 2 with TableFunction

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

the class RelationAnalyzer method visitTableFunction.

@Override
public AnalyzedRelation visitTableFunction(TableFunction node, StatementAnalysisContext statementContext) {
    RelationAnalysisContext context = statementContext.currentRelationContext();
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(statementContext.transactionContext(), nodeCtx, statementContext.paramTyeHints(), FieldProvider.UNSUPPORTED, null);
    ExpressionAnalysisContext expressionContext = context.expressionAnalysisContext();
    // we support `FROM scalar()` but not `FROM 'literal'` -> we turn off eager normalization
    // so we can distinguish between Function and Literal.
    final boolean allowEagerNormalizeOriginalValue = expressionContext.isEagerNormalizationAllowed();
    expressionContext.allowEagerNormalize(false);
    Symbol symbol = expressionAnalyzer.convert(node.functionCall(), expressionContext);
    expressionContext.allowEagerNormalize(allowEagerNormalizeOriginalValue);
    if (!(symbol instanceof Function)) {
        throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "Symbol '%s' is not supported in FROM clause", node.name()));
    }
    Function function = (Function) symbol;
    FunctionImplementation functionImplementation = nodeCtx.functions().getQualified(function, statementContext.sessionContext().searchPath());
    assert functionImplementation != null : "Function implementation not found using full qualified lookup";
    TableFunctionImplementation<?> tableFunction = TableFunctionFactory.from(functionImplementation);
    TableFunctionRelation tableRelation = new TableFunctionRelation(tableFunction, function);
    context.addSourceRelation(tableRelation);
    return tableRelation;
}
Also used : ValuesFunction(io.crate.expression.tablefunctions.ValuesFunction) TableFunction(io.crate.sql.tree.TableFunction) ArrayFunction(io.crate.expression.scalar.arithmetic.ArrayFunction) Function(io.crate.expression.symbol.Function) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.expression.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) FunctionImplementation(io.crate.metadata.FunctionImplementation) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation)

Example 3 with TableFunction

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

TableFunction (io.crate.sql.tree.TableFunction)3 ArithmeticExpression (io.crate.sql.tree.ArithmeticExpression)2 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)2 ArraySliceExpression (io.crate.sql.tree.ArraySliceExpression)2 ArraySubQueryExpression (io.crate.sql.tree.ArraySubQueryExpression)2 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)2 Expression (io.crate.sql.tree.Expression)2 IfExpression (io.crate.sql.tree.IfExpression)2 InListExpression (io.crate.sql.tree.InListExpression)2 LogicalBinaryExpression (io.crate.sql.tree.LogicalBinaryExpression)2 NegativeExpression (io.crate.sql.tree.NegativeExpression)2 NotExpression (io.crate.sql.tree.NotExpression)2 ParameterExpression (io.crate.sql.tree.ParameterExpression)2 SearchedCaseExpression (io.crate.sql.tree.SearchedCaseExpression)2 SimpleCaseExpression (io.crate.sql.tree.SimpleCaseExpression)2 SubqueryExpression (io.crate.sql.tree.SubqueryExpression)2 SubscriptExpression (io.crate.sql.tree.SubscriptExpression)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 ArrayFunction (io.crate.expression.scalar.arithmetic.ArrayFunction)1