Author: shawkins
Date: 2011-05-04 14:22:15 -0400 (Wed, 04 May 2011)
New Revision: 3152
Modified:
branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-1578 fix for properly nesting the last set op branch
Modified:
branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
---
branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-05-04
18:21:08 UTC (rev 3151)
+++
branches/7.4.x/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-05-04
18:22:15 UTC (rev 3152)
@@ -869,9 +869,9 @@
protected void appendSetQuery(SetQuery parent, QueryExpression obj, boolean right) {
if((!(obj instanceof SetQuery) && useParensForSetQueries())
- || (right && obj instanceof SetQuery
+ || (right && ((obj instanceof SetQuery
&& ((parent.isAll() && !((SetQuery)obj).isAll())
- || parent.getOperation() != ((SetQuery)obj).getOperation()))) {
+ || parent.getOperation() != ((SetQuery)obj).getOperation())) ||
obj.getLimit() != null || obj.getOrderBy() != null))) {
buffer.append(Tokens.LPAREN);
append(obj);
buffer.append(Tokens.RPAREN);
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-05-04
18:21:08 UTC (rev 3151)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-05-04
18:22:15 UTC (rev 3152)
@@ -930,8 +930,8 @@
protected void appendSetQuery( SetQuery parent,
QueryCommand obj,
boolean right ) {
- if (right && obj instanceof SetQuery
- && ((parent.isAll() && !((SetQuery)obj).isAll()) ||
parent.getOperation() != ((SetQuery)obj).getOperation())) {
+ if (right && ((obj instanceof SetQuery
+ && ((parent.isAll() && !((SetQuery)obj).isAll()) ||
parent.getOperation() != ((SetQuery)obj).getOperation())) || obj.getLimit() != null ||
obj.getOrderBy() != null)) {
append(Tokens.LPAREN);
visitNode(obj);
append(Tokens.RPAREN);
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-05-04
18:21:08 UTC (rev 3151)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2011-05-04
18:22:15 UTC (rev 3152)
@@ -1875,6 +1875,12 @@
helpTest(command, "SELECT pm1.g1.e1 FROM pm1.g1 UNION SELECT e2 FROM pm1.g2
ORDER BY e1"); //$NON-NLS-1$
}
+ public void testUnionBranchOrderBy() throws Exception {
+ Command command = QueryParser.getQueryParser().parseCommand("select
pm1.g1.e1 from pm1.g1 union (select e2 from pm1.g2 order by e1)"); //$NON-NLS-1$
+ QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
+ helpTest(command, "SELECT pm1.g1.e1 FROM pm1.g1 UNION (SELECT e2 FROM pm1.g2
ORDER BY e1)"); //$NON-NLS-1$
+ }
+
public void testAliasedOrderBy() throws Exception {
Command command = QueryParser.getQueryParser().parseCommand("select
pm1.g1.e1 as a from pm1.g1 order by a"); //$NON-NLS-1$
QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
Modified:
branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
---
branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2011-05-04
18:21:08 UTC (rev 3151)
+++
branches/7.4.x/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2011-05-04
18:22:15 UTC (rev 3152)
@@ -352,7 +352,7 @@
}
@Test public void testVisitIUnion1() throws Exception {
- String expected = "SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS
myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4
HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC UNION
SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >=
200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 <
600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC ORDER BY e1, e2 DESC, e3, e4
DESC";//$NON-NLS-1$
+ String expected = "SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS
myAlias, g3, g4 WHERE 100 >= 200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4
HAVING 100 >= 200 AND 500 < 600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC UNION
(SELECT DISTINCT g1.e1, g1.e2, g1.e3, g1.e4 FROM g1, g2 AS myAlias, g3, g4 WHERE 100 >=
200 AND 500 < 600 GROUP BY g1.e1, g1.e2, g1.e3, g1.e4 HAVING 100 >= 200 AND 500 <
600 ORDER BY g1.e1, g1.e2 DESC, g1.e3, g1.e4 DESC) ORDER BY e1, e2 DESC, e3, e4
DESC";//$NON-NLS-1$
assertEquals(expected, getString(TestSetQueryImpl.example()));
}