use of io.crate.planner.operators.Collect in project crate by crate.
the class MergeAggregateAndCollectToCount method apply.
@Override
public Count apply(HashAggregate aggregate, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Collect collect = captures.get(collectCapture);
var countAggregate = Lists2.getOnlyElement(aggregate.aggregates());
if (countAggregate.filter() != null) {
return new Count(countAggregate, collect.relation(), collect.where().add(countAggregate.filter()));
} else {
return new Count(countAggregate, collect.relation(), collect.where());
}
}
use of io.crate.planner.operators.Collect in project crate by crate.
the class CopyToPlan method optimizeCollect.
private static LogicalPlan optimizeCollect(PlannerContext context, TableStats tableStats, LogicalPlan collect) {
OptimizeCollectWhereClauseAccess rewriteCollectToGet = new OptimizeCollectWhereClauseAccess();
Match<Collect> match = rewriteCollectToGet.pattern().accept(collect, Captures.empty());
if (match.isPresent()) {
LogicalPlan plan = rewriteCollectToGet.apply(match.value(), match.captures(), tableStats, context.transactionContext(), context.nodeContext());
return plan == null ? collect : plan;
}
return collect;
}
use of io.crate.planner.operators.Collect in project crate by crate.
the class MergeFilterAndCollect method apply.
@Override
public LogicalPlan apply(Filter filter, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Collect collect = captures.get(collectCapture);
Stats stats = tableStats.getStats(collect.relation().tableInfo().ident());
WhereClause newWhere = collect.where().add(filter.query());
return new Collect(collect.relation(), collect.outputs(), newWhere, SelectivityFunctions.estimateNumRows(stats, newWhere.queryOrFallback(), null), stats.averageSizePerRowInBytes());
}
use of io.crate.planner.operators.Collect in project crate by crate.
the class OptimizeCollectWhereClauseAccess method apply.
@Override
public LogicalPlan apply(Collect collect, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
var relation = (DocTableRelation) collect.relation();
var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, relation);
WhereClause where = collect.where();
var detailedQuery = WhereClauseOptimizer.optimize(normalizer, where.queryOrFallback(), relation.tableInfo(), txnCtx, nodeCtx);
Optional<DocKeys> docKeys = detailedQuery.docKeys();
// noinspection OptionalIsPresent no capturing lambda allocation
if (docKeys.isPresent()) {
return new Get(relation, docKeys.get(), detailedQuery.query(), collect.outputs(), tableStats.estimatedSizePerRow(relation.relationName()));
} else if (!detailedQuery.clusteredBy().isEmpty() && collect.detailedQuery() == null) {
return new Collect(collect, detailedQuery);
} else {
return null;
}
}
use of io.crate.planner.operators.Collect in project crate by crate.
the class MergeAggregateRenameAndCollectToCount method apply.
@Override
public LogicalPlan apply(HashAggregate aggregate, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Collect collect = captures.get(collectCapture);
Rename rename = captures.get(renameCapture);
var countAggregate = Lists2.getOnlyElement(aggregate.aggregates());
var filter = countAggregate.filter();
if (filter != null) {
var mappedFilter = FieldReplacer.replaceFields(filter, rename::resolveField);
return new Count(countAggregate, collect.relation(), collect.where().add(mappedFilter));
} else {
return new Count(countAggregate, collect.relation(), collect.where());
}
}
Aggregations