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();
}
Aggregations