use of io.crate.expression.eval.EvaluatingNormalizer 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;
}
use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.
the class CopyAnalyzer method analyzeCopyTo.
AnalyzedCopyTo analyzeCopyTo(CopyTo<Expression> node, ParamTypeHints paramTypeHints, CoordinatorTxnCtx txnCtx) {
if (!node.directoryUri()) {
throw new UnsupportedOperationException("Using COPY TO without specifying a DIRECTORY is not supported");
}
TableInfo tableInfo = schemas.resolveTableInfo(node.table().getName(), Operation.COPY_TO, txnCtx.sessionContext().sessionUser(), txnCtx.sessionContext().searchPath());
Operation.blockedRaiseException(tableInfo, Operation.READ);
DocTableRelation tableRelation = new DocTableRelation((DocTableInfo) tableInfo);
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, tableRelation);
var exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
var expressionAnalyzer = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, new NameFieldProvider(tableRelation), null);
var exprAnalyzerWithFieldsAsString = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, FieldProvider.FIELDS_AS_LITERAL, null);
var uri = expressionAnalyzer.convert(node.targetUri(), exprCtx);
var table = node.table().map(x -> exprAnalyzerWithFieldsAsString.convert(x, exprCtx));
var properties = node.properties().map(x -> expressionAnalyzer.convert(x, exprCtx));
var columns = Lists2.map(node.columns(), c -> normalizer.normalize(expressionAnalyzer.convert(c, exprCtx), txnCtx));
var whereClause = node.whereClause().map(w -> normalizer.normalize(expressionAnalyzer.convert(w, exprCtx), txnCtx)).orElse(null);
return new AnalyzedCopyTo(tableInfo, table, normalizer.normalize(uri, txnCtx), properties, columns, whereClause);
}
use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.
the class UpdatePlanner method plan.
private static Plan plan(DocTableRelation docTable, Map<Reference, Symbol> assignmentByTargetCol, Symbol query, PlannerContext plannerCtx, @Nullable List<Symbol> returnValues) {
EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(plannerCtx.nodeContext());
DocTableInfo tableInfo = docTable.tableInfo();
WhereClauseOptimizer.DetailedQuery detailedQuery = WhereClauseOptimizer.optimize(normalizer, query, tableInfo, plannerCtx.transactionContext(), plannerCtx.nodeContext());
if (detailedQuery.docKeys().isPresent()) {
return new UpdateById(tableInfo, assignmentByTargetCol, detailedQuery.docKeys().get(), returnValues, plannerCtx.nodeContext());
}
return new Update((plannerContext, params, subQueryValues) -> updateByQuery(plannerContext, docTable, assignmentByTargetCol, detailedQuery, params, subQueryValues, returnValues));
}
use of io.crate.expression.eval.EvaluatingNormalizer in project crate by crate.
the class WhereClauseAnalyzerTest method analyzeSelectWhere.
private WhereClause analyzeSelectWhere(String stmt) {
AnalyzedRelation rel = e.analyze(stmt);
if (rel instanceof QueriedSelectRelation) {
QueriedSelectRelation queriedRelation = ((QueriedSelectRelation) rel);
if (queriedRelation.from().get(0) instanceof DocTableRelation) {
DocTableRelation docTableRelation = (DocTableRelation) queriedRelation.from().get(0);
WhereClauseOptimizer.DetailedQuery detailedQuery = WhereClauseOptimizer.optimize(new EvaluatingNormalizer(e.nodeCtx, RowGranularity.CLUSTER, null, docTableRelation), queriedRelation.where(), docTableRelation.tableInfo(), coordinatorTxnCtx, e.nodeCtx);
return detailedQuery.toBoundWhereClause(docTableRelation.tableInfo(), Row.EMPTY, SubQueryResults.EMPTY, coordinatorTxnCtx, e.nodeCtx);
}
return new WhereClause(queriedRelation.where());
} else {
return WhereClause.MATCH_ALL;
}
}
Aggregations