Skip to content

Commit

Permalink
TEIID-2253 addressing one more case where empty rows from one branch may
Browse files Browse the repository at this point in the history
produce an inaccurate result
  • Loading branch information
shawkins committed Nov 28, 2012
1 parent 309adb6 commit 11b3b84
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void addUnionGroupBy(
view.addAsParent(projectPlanNode);

if (!viewOnly) {
addGroupBy(view, groupingColumns, aggregates, metadata, projectPlanNode.getParent(), capFinder, true, groupingColumns.isEmpty());
addGroupBy(view, groupingColumns, aggregates, metadata, projectPlanNode.getParent(), capFinder, true, groupingColumns.isEmpty() || containsNullDependent(aggregates));
}
}

Expand All @@ -560,12 +560,24 @@ private boolean canPushGroupByToUnionChild(QueryMetadataInterface metadata,
if (!result) {
return false;
}
if (groupingExpressions.isEmpty() && !canFilterEmpty(metadata, capFinder, aggregates, planNode)) {
if ((!groupingExpressions.isEmpty() || containsNullDependent(aggregates)) && !canFilterEmpty(metadata, capFinder, aggregates, planNode)) {
return false;
}
return true;
}

private boolean containsNullDependent(Set<AggregateSymbol> aggregates) {
for (AggregateSymbol aggregateSymbol : aggregates) {
if (aggregateSymbol.getAggregateFunction() == Type.COUNT) {
return true;
}
if (aggregateSymbol.getFunctionDescriptor() != null && aggregateSymbol.getFunctionDescriptor().isNullDependent()) {
return true;
}
}
return false;
}

private boolean canFilterEmpty(QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, Set<AggregateSymbol> aggregates,
PlanNode planNode) throws QueryMetadataException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,5 +1211,31 @@ null, new DefaultCapabilitiesFinder(bsc),
0 // UnionAll
});
}

@Test public void testPushDownOverUnionGroupingWithCount() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = getAggregateCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$

ProcessorPlan plan = TestOptimizer.helpPlan("select count(*) from (select e1, e2, 1 as part from pm1.g1 union all select e1, e2, 2 as part from pm1.g2) z group by e1", RealMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
new String[]{"SELECT g_0.e1, COUNT(*) FROM pm1.g1 AS g_0 GROUP BY g_0.e1 HAVING COUNT(*) > 0", "SELECT g_0.e1, COUNT(*) FROM pm1.g2 AS g_0 GROUP BY g_0.e1 HAVING COUNT(*) > 0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
0, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
1, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
1, // Project
0, // Select
0, // Sort
1 // UnionAll
});
}

}

0 comments on commit 11b3b84

Please sign in to comment.