private static boolean isDistinctOperator(AggregationNode node) { return node.getAggregations().isEmpty(); } }
private static boolean hasMixedDistinctAndNonDistincts(AggregationNode aggregation) { long distincts = aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .filter(FunctionCall::isDistinct) .count(); return distincts > 0 && distincts < aggregation.getAggregations().size(); }
private static boolean hasMixedDistinctAndNonDistincts(AggregationNode aggregation) { long distincts = aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .filter(FunctionCall::isDistinct) .count(); return distincts > 0 && distincts < aggregation.getAggregations().size(); }
private static boolean allDistinctAggregates(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .allMatch(FunctionCall::isDistinct); }
private static Stream<Set<Expression>> extractArgumentSets(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .filter(FunctionCall::isDistinct) .map(FunctionCall::getArguments) .<Set<Expression>>map(HashSet::new) .distinct(); }
private static Stream<Set<Expression>> extractArgumentSets(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .filter(FunctionCall::isDistinct) .map(FunctionCall::getArguments) .<Set<Expression>>map(HashSet::new) .distinct(); }
private static boolean noMasks(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getMask().isPresent()); }
private static boolean noFilters(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .map(Aggregation::getCall) .noneMatch(call -> call.getFilter().isPresent()); }
private static boolean hasMultipleDistincts(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .filter(e -> e.getCall().isDistinct()) .map(Aggregation::getCall) .map(FunctionCall::getArguments) .map(HashSet::new) .distinct() .count() > 1; }
private static boolean hasMultipleDistincts(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .filter(e -> e.getCall().isDistinct()) .map(Aggregation::getCall) .map(FunctionCall::getArguments) .map(HashSet::new) .distinct() .count() > 1; }
@Override public Void visitAggregation(AggregationNode node, ImmutableList.Builder<Expression> context) { node.getAggregations().values() .forEach(aggregation -> context.add(aggregation.getCall())); return super.visitAggregation(node, context); }
@Override public Void visitAggregation(AggregationNode node, ImmutableList.Builder<Expression> context) { node.getAggregations().values() .forEach(aggregation -> context.add(aggregation.getCall())); return super.visitAggregation(node, context); }
private static boolean hasSpatialPartitioningAggregation(AggregationNode aggregation) { return aggregation.getAggregations().values().stream() .map(Aggregation::getCall) .anyMatch(call -> call.getName().toString().equals(NAME) && call.getArguments().size() == 1); }
private static boolean hasSpatialPartitioningAggregation(AggregationNode aggregation) { return aggregation.getAggregations().values().stream() .map(Aggregation::getCall) .anyMatch(call -> call.getName().toString().equals(NAME) && call.getArguments().size() == 1); }
private static boolean hasFilters(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .anyMatch(e -> e.getCall().getFilter().isPresent() && !e.getMask().isPresent()); // can't handle filtered aggregations with DISTINCT (conservatively, if they have a mask) }
private static boolean hasFilters(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .anyMatch(e -> e.getCall().getFilter().isPresent() && !e.getMask().isPresent()); // can't handle filtered aggregations with DISTINCT (conservatively, if they have a mask) }
/** * Whether this node corresponds to a DISTINCT operation in SQL */ private static boolean isDistinct(AggregationNode node) { return node.getAggregations().isEmpty() && node.getOutputSymbols().size() == node.getGroupingKeys().size() && node.getOutputSymbols().containsAll(node.getGroupingKeys()); }
private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregation) { return aggregation.getAggregations() .values().stream() .noneMatch(e -> e.getCall().isDistinct() && (e.getCall().getFilter().isPresent() || e.getMask().isPresent())); }
private FilterNode addFilterForIntersect(AggregationNode aggregation) { ImmutableList<Expression> predicates = aggregation.getAggregations().keySet().stream() .map(column -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, column.toSymbolReference(), new GenericLiteral("BIGINT", "1"))) .collect(toImmutableList()); return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicates)); }
private FilterNode addFilterForIntersect(AggregationNode aggregation) { ImmutableList<Expression> predicates = aggregation.getAggregations().keySet().stream() .map(column -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, column.toSymbolReference(), new GenericLiteral("BIGINT", "1"))) .collect(toImmutableList()); return new FilterNode(idAllocator.getNextId(), aggregation, ExpressionUtils.and(predicates)); }