Search in sources :

Example 1 with ExcludedFieldProvider

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

the class InsertAnalyzer method getUpdateAssignments.

private static Map<Reference, Symbol> getUpdateAssignments(DocTableRelation targetTable, List<Reference> targetCols, ExpressionAnalyzer exprAnalyzer, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, ParamTypeHints paramTypeHints, Insert.DuplicateKeyContext<Expression> duplicateKeyContext) {
    if (duplicateKeyContext.getAssignments().isEmpty()) {
        return Collections.emptyMap();
    }
    ExpressionAnalysisContext exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
    ValuesResolver valuesResolver = new ValuesResolver(targetCols);
    final FieldProvider<?> fieldProvider;
    if (duplicateKeyContext.getType() == Insert.DuplicateKeyContext.Type.ON_CONFLICT_DO_UPDATE_SET) {
        fieldProvider = new ExcludedFieldProvider(new NameFieldProvider(targetTable), valuesResolver);
    } else {
        fieldProvider = new NameFieldProvider(targetTable);
    }
    var expressionAnalyzer = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, fieldProvider, null);
    var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, targetTable);
    Map<Reference, Symbol> updateAssignments = new HashMap<>(duplicateKeyContext.getAssignments().size());
    for (Assignment<Expression> assignment : duplicateKeyContext.getAssignments()) {
        Reference targetCol = (Reference) exprAnalyzer.convert(assignment.columnName(), exprCtx);
        Symbol valueSymbol = ValueNormalizer.normalizeInputForReference(normalizer.normalize(expressionAnalyzer.convert(assignment.expression(), exprCtx), txnCtx), targetCol, targetTable.tableInfo(), s -> normalizer.normalize(s, txnCtx));
        updateAssignments.put(targetCol, valueSymbol);
    }
    return updateAssignments;
}
Also used : ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) HashMap(java.util.HashMap) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) DynamicReference(io.crate.expression.symbol.DynamicReference) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) FullQualifiedNameFieldProvider(io.crate.analyze.relations.FullQualifiedNameFieldProvider) NameFieldProvider(io.crate.analyze.relations.NameFieldProvider) Expression(io.crate.sql.tree.Expression) ExcludedFieldProvider(io.crate.analyze.relations.ExcludedFieldProvider)

Aggregations

ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 ExcludedFieldProvider (io.crate.analyze.relations.ExcludedFieldProvider)1 FullQualifiedNameFieldProvider (io.crate.analyze.relations.FullQualifiedNameFieldProvider)1 NameFieldProvider (io.crate.analyze.relations.NameFieldProvider)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 DynamicReference (io.crate.expression.symbol.DynamicReference)1 Symbol (io.crate.expression.symbol.Symbol)1 GeneratedReference (io.crate.metadata.GeneratedReference)1 Reference (io.crate.metadata.Reference)1 Expression (io.crate.sql.tree.Expression)1 QualifiedNameReference (io.crate.sql.tree.QualifiedNameReference)1 HashMap (java.util.HashMap)1