use of io.crate.analyze.where.WhereClauseAnalyzer in project crate by crate.
the class DeleteAnalyzer method analyze.
public AnalyzedStatement analyze(Delete node, Analysis analysis) {
int numNested = 1;
Function<ParameterExpression, Symbol> convertParamFunction = analysis.parameterContext();
StatementAnalysisContext statementAnalysisContext = new StatementAnalysisContext(analysis.sessionContext(), convertParamFunction, Operation.DELETE, analysis.transactionContext());
RelationAnalysisContext relationAnalysisContext = statementAnalysisContext.startRelation();
AnalyzedRelation analyzedRelation = relationAnalyzer.analyze(node.getRelation(), statementAnalysisContext);
assert analyzedRelation instanceof DocTableRelation : "analyzedRelation must be DocTableRelation";
DocTableRelation docTableRelation = (DocTableRelation) analyzedRelation;
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, docTableRelation);
DeleteAnalyzedStatement deleteAnalyzedStatement = new DeleteAnalyzedStatement(docTableRelation);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), convertParamFunction, new FullQualifedNameFieldProvider(relationAnalysisContext.sources()), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, deleteAnalyzedStatement.analyzedRelation());
if (analysis.parameterContext().hasBulkParams()) {
numNested = analysis.parameterContext().numBulkParams();
}
TransactionContext transactionContext = analysis.transactionContext();
for (int i = 0; i < numNested; i++) {
analysis.parameterContext().setBulkIdx(i);
Symbol query = expressionAnalyzer.generateQuerySymbol(node.getWhere(), expressionAnalysisContext);
WhereClause whereClause = new WhereClause(normalizer.normalize(query, transactionContext));
whereClause = validate(whereClauseAnalyzer.analyze(whereClause, transactionContext));
deleteAnalyzedStatement.whereClauses.add(whereClause);
}
statementAnalysisContext.endRelation();
return deleteAnalyzedStatement;
}
use of io.crate.analyze.where.WhereClauseAnalyzer in project crate by crate.
the class UpdateAnalyzer method analyze.
public AnalyzedStatement analyze(Update node, Analysis analysis) {
StatementAnalysisContext statementAnalysisContext = new StatementAnalysisContext(analysis.sessionContext(), analysis.parameterContext(), Operation.UPDATE, analysis.transactionContext());
RelationAnalysisContext currentRelationContext = statementAnalysisContext.startRelation();
AnalyzedRelation analyzedRelation = relationAnalyzer.analyze(node.relation(), statementAnalysisContext);
FieldResolver fieldResolver = (FieldResolver) analyzedRelation;
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, fieldResolver);
FieldProvider columnFieldProvider = new NameFieldProvider(analyzedRelation);
ExpressionAnalyzer columnExpressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), analysis.parameterContext(), columnFieldProvider, null);
columnExpressionAnalyzer.setResolveFieldsOperation(Operation.UPDATE);
assert Iterables.getOnlyElement(currentRelationContext.sources().values()) == analyzedRelation : "currentRelationContext.sources().values() must have one element and equal to analyzedRelation";
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), analysis.parameterContext(), new FullQualifedNameFieldProvider(currentRelationContext.sources()), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
int numNested = 1;
if (analysis.parameterContext().numBulkParams() > 0) {
numNested = analysis.parameterContext().numBulkParams();
}
WhereClauseAnalyzer whereClauseAnalyzer = null;
if (analyzedRelation instanceof DocTableRelation) {
whereClauseAnalyzer = new WhereClauseAnalyzer(functions, ((DocTableRelation) analyzedRelation));
}
TableInfo tableInfo = ((AbstractTableRelation) analyzedRelation).tableInfo();
List<UpdateAnalyzedStatement.NestedAnalyzedStatement> nestedAnalyzedStatements = new ArrayList<>(numNested);
for (int i = 0; i < numNested; i++) {
analysis.parameterContext().setBulkIdx(i);
Symbol querySymbol = expressionAnalyzer.generateQuerySymbol(node.whereClause(), expressionAnalysisContext);
WhereClause whereClause = new WhereClause(normalizer.normalize(querySymbol, analysis.transactionContext()));
if (whereClauseAnalyzer != null) {
whereClause = whereClauseAnalyzer.analyze(whereClause, analysis.transactionContext());
}
if (!whereClause.docKeys().isPresent() && Symbols.containsColumn(whereClause.query(), DocSysColumns.VERSION)) {
throw VERSION_SEARCH_EX;
}
UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalyzedStatement = new UpdateAnalyzedStatement.NestedAnalyzedStatement(whereClause);
for (Assignment assignment : node.assignements()) {
analyzeAssignment(assignment, nestedAnalyzedStatement, tableInfo, normalizer, expressionAnalyzer, columnExpressionAnalyzer, expressionAnalysisContext, analysis.transactionContext());
}
nestedAnalyzedStatements.add(nestedAnalyzedStatement);
}
statementAnalysisContext.endRelation();
return new UpdateAnalyzedStatement(analyzedRelation, nestedAnalyzedStatements);
}
use of io.crate.analyze.where.WhereClauseAnalyzer in project crate by crate.
the class QueriedDocTable method analyzeWhereClause.
void analyzeWhereClause(Functions functions, TransactionContext transactionContext) {
WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, tableRelation());
querySpec().where(whereClauseAnalyzer.analyze(querySpec().where(), transactionContext));
}
use of io.crate.analyze.where.WhereClauseAnalyzer in project crate by crate.
the class CopyAnalyzer method createWhereClause.
private WhereClause createWhereClause(Optional<Expression> where, DocTableRelation tableRelation, List<String> partitions, EvaluatingNormalizer normalizer, ExpressionAnalyzer expressionAnalyzer, ExpressionAnalysisContext expressionAnalysisContext, TransactionContext transactionContext) {
WhereClause whereClause = null;
if (where.isPresent()) {
WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, tableRelation);
Symbol query = expressionAnalyzer.convert(where.get(), expressionAnalysisContext);
whereClause = new WhereClause(normalizer.normalize(query, transactionContext));
whereClause = whereClauseAnalyzer.analyze(whereClause, transactionContext);
}
if (whereClause == null) {
return new WhereClause(null, null, partitions);
} else if (whereClause.noMatch()) {
return whereClause;
} else {
if (!whereClause.partitions().isEmpty() && !partitions.isEmpty() && !whereClause.partitions().equals(partitions)) {
throw new IllegalArgumentException("Given partition ident does not match partition evaluated from where clause");
}
return new WhereClause(whereClause.query(), whereClause.docKeys().orElse(null), partitions.isEmpty() ? whereClause.partitions() : partitions);
}
}
Aggregations