Author: shawkins
Date: 2010-06-22 15:11:30 -0400 (Tue, 22 Jun 2010)
New Revision: 2278
Modified:
branches/7.0.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.0.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
Log:
TEIID-339 modifying the add distinct logic to consider the presence of a group by
Modified:
branches/7.0.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
---
branches/7.0.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-06-22
19:08:30 UTC (rev 2277)
+++
branches/7.0.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-06-22
19:11:30 UTC (rev 2278)
@@ -159,8 +159,10 @@
if (queryCommand instanceof SetQuery) {
((SetQuery)queryCommand).setAll(false);
} else if (!NewCalculateCostUtil.usesKey(accessNode,
queryCommand.getProjectedSymbols(), metadata) &&
CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT,
RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
- //TODO: could check for group by and a select clause containing all group by
expressions
- ((Query)queryCommand).getSelect().setDistinct(true);
+ Query query = (Query)queryCommand;
+ if (!QueryRewriter.isDistinctWithGroupBy(query)) {
+ ((Query)queryCommand).getSelect().setDistinct(true);
+ }
}
}
Modified: branches/7.0.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.0.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-22
19:08:30 UTC (rev 2277)
+++
branches/7.0.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-22
19:11:30 UTC (rev 2278)
@@ -653,6 +653,9 @@
if (query.getGroupBy() == null) {
return query;
}
+ if (isDistinctWithGroupBy(query)) {
+ query.getSelect().setDistinct(false);
+ }
// we check for group by expressions here to create an ANSI SQL plan
boolean hasExpression = false;
for (final Iterator iterator = query.getGroupBy().getSymbols().iterator();
!hasExpression && iterator.hasNext();) {
@@ -723,6 +726,23 @@
rewriteExpressions(innerSelect);
return query;
}
+
+ public static boolean isDistinctWithGroupBy(Query query) {
+ GroupBy groupBy = query.getGroupBy();
+ if (groupBy == null) {
+ return false;
+ }
+ HashSet<Expression> selectExpressions = new HashSet<Expression>();
+ for (SingleElementSymbol selectExpr :
(List<SingleElementSymbol>)query.getSelect().getProjectedSymbols()) {
+ selectExpressions.add(SymbolMap.getExpression(selectExpr));
+ }
+ for (SingleElementSymbol groupByExpr :
(List<SingleElementSymbol>)groupBy.getSymbols()) {
+ if (!selectExpressions.contains(groupByExpr)) {
+ return false;
+ }
+ }
+ return true;
+ }
private void rewriteExpressions(LanguageObject obj) throws TeiidComponentException,
TeiidProcessingException{
if (obj == null) {
Modified:
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
===================================================================
---
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2010-06-22
19:08:30 UTC (rev 2277)
+++
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2010-06-22
19:11:30 UTC (rev 2278)
@@ -204,7 +204,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
metadata,
null, getAggregatesFinder(),
- new String[] {"SELECT DISTINCT g_0.p_productid
AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT
DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, SUM(g_0.o_amount) AS c_2 FROM
m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid)
AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP
BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT DISTINCT g_0.p_productid
AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT
g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, SUM(g_0.o_amount) AS c_2 FROM
m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid)
AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP
BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
TestOptimizer.checkNodeTypes(plan, new int[] {
@@ -234,7 +234,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
metadata,
null, getAggregatesFinder(),
- new String[] {"SELECT DISTINCT g_0.p_productid
AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT
DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, MAX(g_0.o_amount) AS c_2,
SUM(g_0.o_amount) AS c_3 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE
(g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN
(<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"},
//$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT DISTINCT g_0.p_productid
AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT
g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, MAX(g_0.o_amount) AS c_2, SUM(g_0.o_amount)
AS c_3 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid =
g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent
values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$
//$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
TestOptimizer.checkNodeTypes(plan, new int[] {
@@ -569,7 +569,7 @@
metadata,
null, capFinder,
new String[] {"SELECT g_0.\"MONTH\",
g_0.\"YEAR\" FROM msModel.\"TIME\" AS g_0 WHERE g_0.\"YEAR\"
= '1999'", //$NON-NLS-1$
- "SELECT DISTINCT
g_0.\"MONTH\" AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES
AS g_0 WHERE (g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN
(<dependent values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0,
c_1", //$NON-NLS-1$
+ "SELECT g_0.\"MONTH\"
AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE
(g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN (<dependent
values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0, c_1",
//$NON-NLS-1$
"SELECT g_0.CITY, g_0.REGION
FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX',
'POLINESIA')"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
@@ -617,7 +617,7 @@
metadata,
null, capFinder,
new String[] {"SELECT g_0.\"MONTH\",
g_0.\"YEAR\" FROM msModel.\"TIME\" AS g_0 WHERE g_0.\"YEAR\"
= '1999'", //$NON-NLS-1$
- "SELECT DISTINCT g_0.\"MONTH\"
AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE
(g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN (<dependent
values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0, c_1",
//$NON-NLS-1$
+ "SELECT g_0.\"MONTH\" AS c_0,
g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE
(g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN (<dependent
values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0, c_1",
//$NON-NLS-1$
"SELECT g_0.CITY, g_0.REGION FROM
oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX',
'POLINESIA')"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
@@ -664,7 +664,7 @@
ProcessorPlan plan = helpPlan(sql,
metadata,
null, capFinder,
- new String[] {"SELECT DISTINCT
g_0.\"MONTH\" AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM
db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND
(g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.\"MONTH\" IN
(<dependent values>)) GROUP BY g_0.\"MONTH\", g_1.REGION ORDER BY
c_0", //$NON-NLS-1$
+ new String[] {"SELECT g_0.\"MONTH\"
AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0,
db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN
('BORDEAUX', 'POLINESIA')) AND (g_0.\"MONTH\" IN (<dependent
values>)) GROUP BY g_0.\"MONTH\", g_1.REGION ORDER BY c_0",
//$NON-NLS-1$
"SELECT g_0.\"MONTH\"
AS c_0, g_0.\"YEAR\" AS c_1 FROM msModel.\"TIME\" AS g_0 WHERE
g_0.\"YEAR\" = '1999' ORDER BY c_0"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING
);
Modified:
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java
===================================================================
---
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java 2010-06-22
19:08:30 UTC (rev 2277)
+++
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java 2010-06-22
19:11:30 UTC (rev 2278)
@@ -135,7 +135,7 @@
public static InlineViewCase createInlineViewWithDistinctAndOrderBy() throws Exception
{
String userQuery = "select Q1.a from (select distinct count(bqt1.smalla.intkey) as
a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey order by
bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a =
1 and q1.a + q1.intkey = 2"; //$NON-NLS-1$
- String optimizedQuery = "SELECT v_0.c_0 FROM (SELECT DISTINCT
COUNT(g_0.intkey) AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey
HAVING ((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0,
bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey"; //$NON-NLS-1$
+ String optimizedQuery = "SELECT v_0.c_1 FROM (SELECT g_0.intkey AS c_0,
COUNT(g_0.intkey) AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey HAVING
((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0, bqt1.smallb AS
g_1 WHERE v_0.c_0 = g_1.intkey"; //$NON-NLS-1$
List expectedResults = new ArrayList();
List row1 = new ArrayList();
@@ -173,7 +173,7 @@
public static InlineViewCase createInlineViewWithOuterOrderAndGroup() throws Exception
{
String userQuery = "select count(Q1.a) b from (select distinct
count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by
bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on
q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group by Q1.a order by
b"; //$NON-NLS-1$
- String optimizedQuery = "SELECT COUNT(v_0.c_0) AS c_0 FROM (SELECT DISTINCT
COUNT(g_0.intkey) AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey
HAVING ((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0,
bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0 ORDER BY c_0";
//$NON-NLS-1$
+ String optimizedQuery = "SELECT COUNT(v_0.c_1) AS c_0 FROM (SELECT g_0.intkey AS
c_0, COUNT(g_0.intkey) AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey HAVING
((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0, bqt1.smallb AS
g_1 WHERE v_0.c_0 = g_1.intkey GROUP BY v_0.c_1 ORDER BY c_0"; //$NON-NLS-1$
List expectedResults = new ArrayList();
List row1 = new ArrayList();
@@ -193,7 +193,7 @@
public static InlineViewCase crateInlineViewsInUnions() throws Exception {
String userQuery = "select q1.a from (select count(bqt1.smalla.intkey) as a,
bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) q1 left outer join
bqt1.smallb on q1.a = bqt1.smallb.intkey where q1.intkey = 1 union all (select count(Q1.a)
b from (select distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from
bqt1.smalla group by bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join
bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group
by Q1.a order by b)"; //$NON-NLS-1$
- String optimizedQuery = "SELECT v_1.c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM
bqt1.smalla AS g_2 WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN
bqt1.smallb AS g_3 ON v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_0) AS c_0 FROM
(SELECT DISTINCT COUNT(g_0.IntKey) AS c_0, g_0.IntKey AS c_1 FROM bqt1.smalla AS g_0 GROUP
BY g_0.IntKey HAVING ((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1))
AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0";
//$NON-NLS-1$
+ String optimizedQuery = "SELECT v_1.c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM
bqt1.smalla AS g_2 WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN
bqt1.smallb AS g_3 ON v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_1) AS c_0 FROM
(SELECT g_0.IntKey AS c_0, COUNT(g_0.IntKey) AS c_1 FROM bqt1.smalla AS g_0 GROUP BY
g_0.IntKey HAVING ((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1)) AS
v_0, bqt1.smallb AS g_1 WHERE v_0.c_0 = g_1.intkey GROUP BY v_0.c_1"; //$NON-NLS-1$
List expectedResults = new ArrayList();
List row1 = new ArrayList();
@@ -218,7 +218,7 @@
public static InlineViewCase createUnionInInlineView() throws Exception{
String userQuery = "select t1.intkey from (select case when q1.a=1 then 2 else
1 end as a from (select count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from
bqt1.smalla group by bqt1.smalla.intkey) q1 left outer join bqt1.smallb on q1.a =
bqt1.smallb.intkey where q1.intkey = 1 union all (select count(Q1.a) b from (select
distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by
bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on
q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group by Q1.a order by b))
as q3, bqt1.smallb as t1 where q3.a = t1.intkey order by t1.intkey"; //$NON-NLS-1$
- String optimizedQuery = "SELECT g_4.intkey AS c_0 FROM (SELECT CASE WHEN v_1.c_0 =
1 THEN 2 ELSE 1 END AS c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM bqt1.smalla AS g_2
WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN bqt1.smallb AS g_3 ON
v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_0) AS c_0 FROM (SELECT DISTINCT
COUNT(g_0.IntKey) AS c_0, g_0.IntKey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.IntKey
HAVING ((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1)) AS v_0,
bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0) AS v_2, bqt1.smallb AS g_4
WHERE v_2.c_0 = g_4.intkey ORDER BY c_0"; //$NON-NLS-1$
+ String optimizedQuery = "SELECT g_4.intkey AS c_0 FROM (SELECT CASE WHEN v_1.c_0 =
1 THEN 2 ELSE 1 END AS c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM bqt1.smalla AS g_2
WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN bqt1.smallb AS g_3 ON
v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_1) AS c_0 FROM (SELECT g_0.IntKey AS
c_0, COUNT(g_0.IntKey) AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.IntKey HAVING
((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1)) AS v_0, bqt1.smallb AS
g_1 WHERE v_0.c_0 = g_1.intkey GROUP BY v_0.c_1) AS v_2, bqt1.smallb AS g_4 WHERE v_2.c_0
= g_4.intkey ORDER BY c_0"; //$NON-NLS-1$
List expectedResults = new ArrayList();
List row1 = new ArrayList();
@@ -257,7 +257,7 @@
QueryMetadataInterface metadata = createInlineViewMetadata(capFinder);
ProcessorPlan plan = helpPlan("select a, b from (select distinct
count(intNum) a, count(stringKey), bqt1.smalla.intkey as b from bqt1.smalla group by
bqt1.smalla.intkey) q1 order by q1.a", //$NON-NLS-1$
- metadata, null, capFinder, new String[] {"SELECT a, b FROM (SELECT
DISTINCT COUNT(intNum) AS a, COUNT(stringKey) AS count1, bqt1.smalla.intkey AS b FROM
bqt1.smalla GROUP BY bqt1.smalla.intkey) AS q1 ORDER BY a"}, true); //$NON-NLS-1$
+ metadata, null, capFinder, new String[] {"SELECT COUNT(g_0.intNum)
AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey ORDER BY c_0"},
true); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
Modified:
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
===================================================================
---
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2010-06-22
19:08:30 UTC (rev 2277)
+++
branches/7.0.x/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java 2010-06-22
19:11:30 UTC (rev 2278)
@@ -50,10 +50,10 @@
}
@Test public void testSimpleMergeGroupBy1() {
- ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT distinct
e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT distinct
min(e1), max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
FakeMetadataFactory.example1Cached(), null,
TestAggregatePushdown.getAggregatesFinder(),
new String[] {
- "SELECT v_0.c_1 FROM (SELECT DISTINCT
g_0.e1 AS c_0, MAX(g_0.e2) AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e1) AS v_0"},
TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+ "SELECT v_0.c_1 FROM (SELECT DISTINCT
MIN(g_0.e1) AS c_0, MAX(g_0.e2) AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e1) AS v_0"},
TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
@@ -75,10 +75,10 @@
@Test public void testSimpleMergeGroupBy3() {
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM
(SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM
(SELECT min(e1) as e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
metadata, null,
TestAggregatePushdown.getAggregatesFinder(),
new String[] {
- "SELECT DISTINCT MAX(e2) AS x, e1 FROM
pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+ "SELECT DISTINCT MAX(e2) AS x, MIN(e1)
FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
@@ -113,10 +113,10 @@
@Test public void testSimpleMergeGroupBy7() {
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM
(SELECT distinct e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM
(SELECT distinct min(e1) as e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z",
//$NON-NLS-1$
metadata, null,
TestAggregatePushdown.getAggregatesFinder(),
new String[] {
- "SELECT DISTINCT MAX(e2) AS x, e1 FROM
pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+ "SELECT DISTINCT MAX(e2) AS x, MIN(e1)
FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}