Search in sources :

Example 11 with Symbols

use of io.crate.expression.symbol.Symbols in project crate by crate.

the class CreateTableAsAnalyzer method analyze.

public AnalyzedCreateTableAs analyze(CreateTableAs createTableAs, ParamTypeHints paramTypeHints, CoordinatorTxnCtx txnCtx) {
    RelationName relationName = RelationName.of(createTableAs.name().getName(), txnCtx.sessionContext().searchPath().currentSchema());
    relationName.ensureValidForRelationCreation();
    AnalyzedRelation analyzedSourceQuery = relationAnalyzer.analyze(createTableAs.query(), new StatementAnalysisContext(paramTypeHints, Operation.READ, txnCtx));
    List<TableElement<Expression>> tableElements = Lists2.map(analyzedSourceQuery.outputs(), Symbols::toColumnDefinition);
    CreateTable<Expression> createTable = new CreateTable<Expression>(createTableAs.name(), tableElements, Optional.empty(), Optional.empty(), GenericProperties.empty(), false);
    // This is only a preliminary analysis to to have the source available for privilege checks.
    // It will be analyzed again with the target columns from the target table once
    // the table has been created.
    AnalyzedRelation sourceRelation = relationAnalyzer.analyze(createTableAs.query(), new StatementAnalysisContext(paramTypeHints, Operation.READ, txnCtx));
    // postponing the analysis of the insert statement, since the table has not been created yet.
    Supplier<AnalyzedInsertStatement> postponedInsertAnalysis = () -> {
        Insert<Expression> insert = new Insert<Expression>(createTableAs.name(), createTableAs.query(), Collections.emptyList(), Collections.emptyList(), Insert.DuplicateKeyContext.none());
        return insertAnalyzer.analyze(insert, paramTypeHints, txnCtx);
    };
    return new AnalyzedCreateTableAs(createTableStatementAnalyzer.analyze(createTable, paramTypeHints, txnCtx), sourceRelation, postponedInsertAnalysis);
}
Also used : CreateTable(io.crate.sql.tree.CreateTable) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) Insert(io.crate.sql.tree.Insert) TableElement(io.crate.sql.tree.TableElement) StatementAnalysisContext(io.crate.analyze.relations.StatementAnalysisContext) Expression(io.crate.sql.tree.Expression) Symbols(io.crate.expression.symbol.Symbols) RelationName(io.crate.metadata.RelationName)

Aggregations

Symbols (io.crate.expression.symbol.Symbols)11 SQLExecutor (io.crate.testing.SQLExecutor)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)6 Test (org.junit.Test)6 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 Symbol (io.crate.expression.symbol.Symbol)3 RelationName (io.crate.metadata.RelationName)2 OrderBy (io.crate.analyze.OrderBy)1 StatementAnalysisContext (io.crate.analyze.relations.StatementAnalysisContext)1 Lists2 (io.crate.common.collections.Lists2)1 Paging (io.crate.data.Paging)1 Projection (io.crate.execution.dsl.projection.Projection)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)1 SelectSymbol (io.crate.expression.symbol.SelectSymbol)1 SymbolVisitors (io.crate.expression.symbol.SymbolVisitors)1 Routing (io.crate.metadata.Routing)1 RowGranularity (io.crate.metadata.RowGranularity)1 TransactionContext (io.crate.metadata.TransactionContext)1 DistributionInfo (io.crate.planner.distribution.DistributionInfo)1