Search in sources :

Example 1 with NameFieldProvider

use of io.crate.analyze.relations.NameFieldProvider in project crate by crate.

the class InsertFromValuesAnalyzer method analyze.

public AnalyzedStatement analyze(InsertFromValues node, Analysis analysis) {
    DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.of(node.table(), analysis.sessionContext().defaultSchema()));
    Operation.blockedRaiseException(tableInfo, Operation.INSERT);
    DocTableRelation tableRelation = new DocTableRelation(tableInfo);
    FieldProvider fieldProvider = new NameFieldProvider(tableRelation);
    Function<ParameterExpression, Symbol> convertParamFunction = analysis.parameterContext();
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), convertParamFunction, fieldProvider, null);
    ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
    expressionAnalyzer.setResolveFieldsOperation(Operation.INSERT);
    ValuesResolver valuesResolver = new ValuesResolver(tableRelation);
    ExpressionAnalyzer valuesAwareExpressionAnalyzer = new ValuesAwareExpressionAnalyzer(functions, analysis.sessionContext(), convertParamFunction, fieldProvider, valuesResolver);
    InsertFromValuesAnalyzedStatement statement = new InsertFromValuesAnalyzedStatement(tableInfo, analysis.parameterContext().numBulkParams());
    handleInsertColumns(node, node.maxValuesLength(), statement);
    Set<Reference> allReferencedReferences = new HashSet<>();
    for (GeneratedReference reference : tableInfo.generatedColumns()) {
        allReferencedReferences.addAll(reference.referencedReferences());
    }
    ReferenceToLiteralConverter.Context referenceToLiteralContext = new ReferenceToLiteralConverter.Context(statement.columns(), allReferencedReferences);
    ValueNormalizer valuesNormalizer = new ValueNormalizer(schemas);
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.COPY, null, tableRelation);
    analyzeColumns(statement.tableInfo(), statement.columns());
    for (ValuesList valuesList : node.valuesLists()) {
        analyzeValues(tableRelation, valuesNormalizer, normalizer, expressionAnalyzer, expressionAnalysisContext, analysis.transactionContext(), valuesResolver, valuesAwareExpressionAnalyzer, valuesList, node.onDuplicateKeyAssignments(), statement, analysis.parameterContext(), referenceToLiteralContext);
    }
    return statement;
}
Also used : ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) DocTableInfo(io.crate.metadata.doc.DocTableInfo) ValueNormalizer(io.crate.analyze.expressions.ValueNormalizer) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) FieldProvider(io.crate.analyze.relations.FieldProvider) NameFieldProvider(io.crate.analyze.relations.NameFieldProvider) NameFieldProvider(io.crate.analyze.relations.NameFieldProvider) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Aggregations

ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 ValueNormalizer (io.crate.analyze.expressions.ValueNormalizer)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 FieldProvider (io.crate.analyze.relations.FieldProvider)1 NameFieldProvider (io.crate.analyze.relations.NameFieldProvider)1 Symbol (io.crate.analyze.symbol.Symbol)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1