Search in sources :

Example 1 with Collect

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());
    }
}
Also used : Collect(io.crate.planner.operators.Collect) Count(io.crate.planner.operators.Count)

Example 2 with Collect

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;
}
Also used : Collect(io.crate.planner.operators.Collect) LogicalPlan(io.crate.planner.operators.LogicalPlan) OptimizeCollectWhereClauseAccess(io.crate.planner.optimizer.rule.OptimizeCollectWhereClauseAccess)

Example 3 with 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());
}
Also used : Collect(io.crate.planner.operators.Collect) Stats(io.crate.statistics.Stats) TableStats(io.crate.statistics.TableStats) WhereClause(io.crate.analyze.WhereClause)

Example 4 with Collect

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;
    }
}
Also used : EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) DocKeys(io.crate.analyze.where.DocKeys) Collect(io.crate.planner.operators.Collect) Get(io.crate.planner.operators.Get) WhereClause(io.crate.analyze.WhereClause) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Example 5 with Collect

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());
    }
}
Also used : Collect(io.crate.planner.operators.Collect) Count(io.crate.planner.operators.Count) Rename(io.crate.planner.operators.Rename)

Aggregations

Collect (io.crate.planner.operators.Collect)7 WhereClause (io.crate.analyze.WhereClause)3 Count (io.crate.planner.operators.Count)2 TableStats (io.crate.statistics.TableStats)2 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 DocKeys (io.crate.analyze.where.DocKeys)1 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)1 ProjectionBuilder (io.crate.execution.dsl.projection.builder.ProjectionBuilder)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 SelectSymbol (io.crate.expression.symbol.SelectSymbol)1 Filter (io.crate.planner.operators.Filter)1 Get (io.crate.planner.operators.Get)1 LogicalPlan (io.crate.planner.operators.LogicalPlan)1 Rename (io.crate.planner.operators.Rename)1 SubQueryResults (io.crate.planner.operators.SubQueryResults)1 OptimizeCollectWhereClauseAccess (io.crate.planner.optimizer.rule.OptimizeCollectWhereClauseAccess)1 Stats (io.crate.statistics.Stats)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 Test (org.junit.Test)1