Search in sources :

Example 11 with RowExpressionDeterminismEvaluator

use of com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator in project presto by prestodb.

the class SortExpressionExtractor method extractSortExpression.

public static Optional<SortExpressionContext> extractSortExpression(Set<VariableReferenceExpression> buildVariables, RowExpression filter, FunctionAndTypeManager functionAndTypeManager) {
    List<RowExpression> filterConjuncts = LogicalRowExpressions.extractConjuncts(filter);
    SortExpressionVisitor visitor = new SortExpressionVisitor(buildVariables, functionAndTypeManager);
    DeterminismEvaluator determinismEvaluator = new RowExpressionDeterminismEvaluator(functionAndTypeManager);
    List<SortExpressionContext> sortExpressionCandidates = filterConjuncts.stream().filter(determinismEvaluator::isDeterministic).map(conjunct -> conjunct.accept(visitor, null)).filter(Optional::isPresent).map(Optional::get).collect(toMap(SortExpressionContext::getSortExpression, identity(), SortExpressionExtractor::merge)).values().stream().collect(toImmutableList());
    // TODO: make it cost based decision based on symbol statistics
    return sortExpressionCandidates.stream().sorted(comparing(context -> -1 * context.getSearchExpressions().size())).findFirst();
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) Optional(java.util.Optional) DeterminismEvaluator(com.facebook.presto.spi.relation.DeterminismEvaluator) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Aggregations

RowExpressionDeterminismEvaluator (com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator)11 FunctionResolution (com.facebook.presto.sql.relational.FunctionResolution)6 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)4 TableHandle (com.facebook.presto.spi.TableHandle)4 BeforeClass (org.testng.annotations.BeforeClass)4 Session (com.facebook.presto.Session)3 ConnectorId (com.facebook.presto.spi.ConnectorId)3 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)3 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)3 RowExpression (com.facebook.presto.spi.relation.RowExpression)3 Optional (java.util.Optional)3 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)2 MemoryManagerConfig (com.facebook.presto.memory.MemoryManagerConfig)2 Metadata (com.facebook.presto.metadata.Metadata)2 Split (com.facebook.presto.metadata.Split)2 LookupJoinOperators (com.facebook.presto.operator.LookupJoinOperators)2 NoOpFragmentResultCacheManager (com.facebook.presto.operator.NoOpFragmentResultCacheManager)2 PagesIndex (com.facebook.presto.operator.PagesIndex)2 StageExecutionDescriptor (com.facebook.presto.operator.StageExecutionDescriptor)2 TableCommitContext (com.facebook.presto.operator.TableCommitContext)2