public static Set<WindowFunction> getWindowFunctions( List<Expression> projectCols) { LinkedHashSet<WindowFunction> windowFunctions = new LinkedHashSet<WindowFunction>(); for (Expression singleElementSymbol : projectCols) { AggregateSymbolCollectorVisitor.getAggregates(singleElementSymbol, null, null, null, windowFunctions, null); } return windowFunctions; }
public static Set<WindowFunction> getWindowFunctions( List<Expression> projectCols) { LinkedHashSet<WindowFunction> windowFunctions = new LinkedHashSet<WindowFunction>(); for (Expression singleElementSymbol : projectCols) { AggregateSymbolCollectorVisitor.getAggregates(singleElementSymbol, null, null, null, windowFunctions, null); } return windowFunctions; }
public static Set<WindowFunction> getWindowFunctions( List<Expression> projectCols) { LinkedHashSet<WindowFunction> windowFunctions = new LinkedHashSet<WindowFunction>(); for (Expression singleElementSymbol : projectCols) { AggregateSymbolCollectorVisitor.getAggregates(singleElementSymbol, null, null, null, windowFunctions, null); } return windowFunctions; }
private void validateNoAggsInClause(LanguageObject clause) { if (clause == null) { return; } LinkedHashSet<Expression> aggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(clause, aggs, null, null, aggs, null); if (!aggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level", aggs), aggs); //$NON-NLS-1$ } }
private void validateNoNestedAggs(LanguageObject aggExp, boolean windowOnly) { // Check for any nested aggregates (which are not allowed) if(aggExp != null) { HashSet<Expression> nestedAggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(aggExp, windowOnly?null:nestedAggs, null, null, nestedAggs, null); if(!nestedAggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0039", nestedAggs), nestedAggs); //$NON-NLS-1$ } } }
private void validateNoNestedAggs(LanguageObject aggExp, boolean windowOnly) { // Check for any nested aggregates (which are not allowed) if(aggExp != null) { HashSet<Expression> nestedAggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(aggExp, windowOnly?null:nestedAggs, null, null, nestedAggs, null); if(!nestedAggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0039", nestedAggs), nestedAggs); //$NON-NLS-1$ } } }
private void validateNoAggsInClause(LanguageObject clause) { if (clause == null) { return; } LinkedHashSet<Expression> aggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(clause, aggs, null, null, aggs, null); if (!aggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level", aggs), aggs); //$NON-NLS-1$ } }
private void validateNoNestedAggs(LanguageObject aggExp, boolean windowOnly) { // Check for any nested aggregates (which are not allowed) if(aggExp != null) { HashSet<Expression> nestedAggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(aggExp, windowOnly?null:nestedAggs, null, null, nestedAggs, null); if(!nestedAggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0039", nestedAggs), nestedAggs); //$NON-NLS-1$ } } }
private void validateNoAggsInClause(LanguageObject clause) { if (clause == null) { return; } LinkedHashSet<Expression> aggs = new LinkedHashSet<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(clause, aggs, null, null, aggs, null); if (!aggs.isEmpty()) { handleValidationError(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level", aggs), aggs); //$NON-NLS-1$ } }
private boolean canAddGrouping(LanguageObject lo) { for (AggregateSymbol as : AggregateSymbolCollectorVisitor.getAggregates(lo, false)) { if (as.isCount() || as.getAggregateFunction() == Type.TEXTAGG) { //these can be non-null for no rows. //TODO: could include udaf as well return false; } } return true; }
private boolean canAddGrouping(LanguageObject lo) { for (AggregateSymbol as : AggregateSymbolCollectorVisitor.getAggregates(lo, false)) { if (as.isCount() || as.getAggregateFunction() == Type.TEXTAGG) { //these can be non-null for no rows. //TODO: could include udaf as well return false; } } return true; }
public boolean hasAggregates() { return getGroupBy() != null || getHaving() != null || !AggregateSymbolCollectorVisitor.getAggregates(getSelect(), false).isEmpty(); }
public boolean hasAggregates() { return getGroupBy() != null || getHaving() != null || !AggregateSymbolCollectorVisitor.getAggregates(getSelect(), false).isEmpty(); }
public boolean hasAggregates() { return getGroupBy() != null || getHaving() != null || !AggregateSymbolCollectorVisitor.getAggregates(getSelect(), false).isEmpty(); }
private boolean requiresDistinctRows(Query query) { Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>(); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getSelect(), false)); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getHaving(), false)); if (!aggs.isEmpty() || query.getGroupBy() != null) { if (!AggregateSymbol.areAggregatesCardinalityDependent(aggs)) { return false; } } else if (query.getSelect().isDistinct()) { for (Expression projectSymbol : query.getSelect().getProjectedSymbols()) { Expression ex = SymbolMap.getExpression(projectSymbol); if (FunctionCollectorVisitor.isNonDeterministic(ex)) { return true; } if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex).isEmpty()) { return true; } } return false; } return true; }
/** * Return true if the result from the subquery may be different * if non-distinct rows are used as input * @param query * @return */ public static boolean requiresDistinctRows(Query query) { Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>(); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getSelect(), false)); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getHaving(), false)); if (!aggs.isEmpty() || query.getGroupBy() != null) { if (!AggregateSymbol.areAggregatesCardinalityDependent(aggs)) { return false; } } else if (query.getSelect().isDistinct()) { for (Expression projectSymbol : query.getSelect().getProjectedSymbols()) { Expression ex = SymbolMap.getExpression(projectSymbol); if (FunctionCollectorVisitor.isNonDeterministic(ex)) { return true; } if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex).isEmpty()) { return true; } } return false; } return true; }
/** * Return true if the result from the subquery may be different * if non-distinct rows are used as input * @param query * @return */ public static boolean requiresDistinctRows(Query query) { Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>(); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getSelect(), false)); aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(query.getHaving(), false)); if (!aggs.isEmpty() || query.getGroupBy() != null) { if (!AggregateSymbol.areAggregatesCardinalityDependent(aggs)) { return false; } } else if (query.getSelect().isDistinct()) { for (Expression projectSymbol : query.getSelect().getProjectedSymbols()) { Expression ex = SymbolMap.getExpression(projectSymbol); if (FunctionCollectorVisitor.isNonDeterministic(ex)) { return true; } if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex).isEmpty()) { return true; } } return false; } return true; }
private void processCriteria(Collection<GroupSymbol> leftGroups, PlannedResult plannedResult, List<GroupSymbol> rightGroups, Set<Expression> requiredExpressions, final SymbolMap refs, Criteria joinCriteria, GroupBy groupBy, boolean where) { if (joinCriteria == null) { return; } List<Criteria> crits = Criteria.separateCriteriaByAnd((Criteria)joinCriteria.clone()); for (Iterator<Criteria> critIter = crits.iterator(); critIter.hasNext();) { Criteria conjunct = critIter.next(); List<Expression> additionalRequired = new LinkedList<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(conjunct, additionalRequired, additionalRequired, additionalRequired, null, groupBy!=null?groupBy.getSymbols():null); ReferenceReplacementVisitor emv = new ReferenceReplacementVisitor(refs); DeepPostOrderNavigator.doVisit(conjunct, emv); if (!emv.replacedAny) { //if not correlated, then leave it on the query critIter.remove(); if (where) { plannedResult.query.setCriteria(Criteria.combineCriteria(plannedResult.query.getCriteria(), conjunct)); } else { plannedResult.query.setHaving(Criteria.combineCriteria(plannedResult.query.getHaving(), conjunct)); } } else { requiredExpressions.addAll(additionalRequired); } } RuleChooseJoinStrategy.separateCriteria(leftGroups, rightGroups, plannedResult.leftExpressions, plannedResult.rightExpressions, crits, plannedResult.nonEquiJoinCriteria); }
private void processCriteria(Collection<GroupSymbol> leftGroups, PlannedResult plannedResult, List<GroupSymbol> rightGroups, Set<Expression> requiredExpressions, final SymbolMap refs, Criteria joinCriteria, GroupBy groupBy, boolean where) { if (joinCriteria == null) { return; } List<Criteria> crits = Criteria.separateCriteriaByAnd((Criteria)joinCriteria.clone()); for (Iterator<Criteria> critIter = crits.iterator(); critIter.hasNext();) { Criteria conjunct = critIter.next(); List<Expression> additionalRequired = new LinkedList<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(conjunct, additionalRequired, additionalRequired, additionalRequired, null, groupBy!=null?groupBy.getSymbols():null); ReferenceReplacementVisitor emv = new ReferenceReplacementVisitor(refs); DeepPostOrderNavigator.doVisit(conjunct, emv); if (!emv.replacedAny) { //if not correlated, then leave it on the query critIter.remove(); if (where) { plannedResult.query.setCriteria(Criteria.combineCriteria(plannedResult.query.getCriteria(), conjunct)); } else { plannedResult.query.setHaving(Criteria.combineCriteria(plannedResult.query.getHaving(), conjunct)); } } else { requiredExpressions.addAll(additionalRequired); } } RuleChooseJoinStrategy.separateCriteria(leftGroups, rightGroups, plannedResult.leftExpressions, plannedResult.rightExpressions, crits, plannedResult.nonEquiJoinCriteria); }
public void helpTestCollectAggregates(String sql, String[] aggs, String[] elems) throws QueryParserException { // Parse command Command command = QueryParser.getQueryParser().parseCommand(sql); // Find aggregates List<Expression> foundAggs = new ArrayList<Expression>(); List<Expression> foundElements = new ArrayList<Expression>(); AggregateSymbolCollectorVisitor.getAggregates(command, foundAggs, foundElements, null, null, null); // Compare assertEquals("Incorrect number of aggregates: " + foundAggs, aggs.length, foundAggs.size()); //$NON-NLS-1$ for(int i=0; i<aggs.length; i++) { assertEquals("Incorrect agg match at " + i, aggs[i], foundAggs.get(i).toString()); //$NON-NLS-1$ } assertEquals("Incorrect number of elements: " + foundElements, elems.length, foundElements.size()); //$NON-NLS-1$ for(int i=0; i<elems.length; i++) { assertEquals("Incorrect agg match at " + i, elems[i], foundElements.get(i).toString()); //$NON-NLS-1$ } }