use of io.crate.analyze.WhereClause in project crate by crate.
the class CountPhase method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
executionPhaseId = in.readVInt();
routing = Routing.fromStream(in);
whereClause = new WhereClause(in);
distributionInfo = DistributionInfo.fromStream(in);
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class RoutedCollectPhase method normalize.
/**
* normalizes the symbols of this node with the given normalizer
*
* @return a normalized node, if no changes occurred returns this
*/
public RoutedCollectPhase normalize(EvaluatingNormalizer normalizer, TransactionContext transactionContext) {
assert whereClause() != null : "whereClause must not be null";
RoutedCollectPhase result = this;
List<Symbol> newToCollect = normalizer.normalize(toCollect(), transactionContext);
boolean changed = newToCollect != toCollect();
WhereClause newWhereClause = whereClause().normalize(normalizer, transactionContext);
OrderBy orderBy = this.orderBy;
if (orderBy != null) {
List<Symbol> orderBySymbols = orderBy.orderBySymbols();
List<Symbol> normalizedOrderBy = normalizer.normalize(orderBySymbols, transactionContext);
changed = changed || orderBySymbols != normalizedOrderBy;
orderBy = new OrderBy(normalizedOrderBy, this.orderBy.reverseFlags(), this.orderBy.nullsFirst());
}
changed = changed || newWhereClause != whereClause();
if (changed) {
result = new RoutedCollectPhase(jobId(), phaseId(), name(), routing, maxRowGranularity, newToCollect, projections, newWhereClause, distributionInfo);
result.orderBy(orderBy);
}
return result;
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class RoutedCollectPhase method forQueriedTable.
public static RoutedCollectPhase forQueriedTable(Planner.Context plannerContext, QueriedTableRelation table, List<Symbol> toCollect, List<Projection> projections) {
TableInfo tableInfo = table.tableRelation().tableInfo();
WhereClause where = table.querySpec().where();
if (table.tableRelation() instanceof TableFunctionRelation) {
TableFunctionRelation tableFunctionRelation = (TableFunctionRelation) table.tableRelation();
plannerContext.normalizer().normalizeInplace(tableFunctionRelation.function().arguments(), plannerContext.transactionContext());
return new TableFunctionCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), plannerContext.allocateRouting(tableInfo, where, null), tableFunctionRelation, projections, toCollect, where);
}
return new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", plannerContext.allocateRouting(tableInfo, where, null), tableInfo.rowGranularity(), toCollect, projections, where, DistributionInfo.DEFAULT_BROADCAST);
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class RoutedCollectPhase method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
distributionInfo = DistributionInfo.fromStream(in);
toCollect = Symbols.listFromStream(in);
maxRowGranularity = RowGranularity.fromStream(in);
if (in.readBoolean()) {
routing = Routing.fromStream(in);
}
whereClause = new WhereClause(in);
if (in.readBoolean()) {
nodePageSizeHint = in.readVInt();
}
if (in.readBoolean()) {
orderBy = OrderBy.fromStream(in);
}
isPartitioned = in.readBoolean();
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzer method tieBreakPartitionQueries.
private static WhereClause tieBreakPartitionQueries(EvaluatingNormalizer normalizer, Map<Symbol, List<Literal>> queryPartitionMap, WhereClause whereClause, TransactionContext transactionContext) throws UnsupportedOperationException {
/*
* Got multiple normalized queries which all could match.
* This might be the case if one partition resolved to null
*
* e.g.
*
* p = 1 and x = 2
*
* might lead to
*
* null and x = 2
* true and x = 2
*
* At this point it is unknown if they really match.
* In order to figure out if they could potentially match all conditions involving references are now set to true
*
* null and true -> can't match
* true and true -> can match, can use this query + partition
*
* If there is still more than 1 query that can match it's not possible to execute the query :(
*/
List<Tuple<Symbol, List<Literal>>> canMatch = new ArrayList<>();
SymbolToTrueVisitor symbolToTrueVisitor = new SymbolToTrueVisitor();
for (Map.Entry<Symbol, List<Literal>> entry : queryPartitionMap.entrySet()) {
Symbol query = entry.getKey();
List<Literal> partitions = entry.getValue();
Symbol symbol = symbolToTrueVisitor.process(query, null);
Symbol normalized = normalizer.normalize(symbol, transactionContext);
assert normalized instanceof Literal : "after normalization and replacing all reference occurrences with true there must only be a literal left";
Object value = ((Literal) normalized).value();
if (value != null && (Boolean) value) {
canMatch.add(new Tuple<>(query, partitions));
}
}
if (canMatch.size() == 1) {
Tuple<Symbol, List<Literal>> symbolListTuple = canMatch.get(0);
WhereClause where = new WhereClause(symbolListTuple.v1(), whereClause.docKeys().orElse(null), new ArrayList<String>(symbolListTuple.v2().size()));
where.partitions(symbolListTuple.v2());
return where;
}
throw new UnsupportedOperationException("logical conjunction of the conditions in the WHERE clause which " + "involve partitioned columns led to a query that can't be executed.");
}
Aggregations