Author: shawkins
Date: 2010-11-23 11:49:01 -0500 (Tue, 23 Nov 2010)
New Revision: 2737
Modified:
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
Log:
TEIID-1370 a fix for inline view correlation names in the order by clause
Modified:
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-11-23
16:47:16 UTC (rev 2736)
+++
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-11-23
16:49:01 UTC (rev 2737)
@@ -26,6 +26,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.cdk.CommandBuilder;
import org.teiid.cdk.api.TranslationUtility;
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.Command;
@@ -168,5 +169,14 @@
command = tu.parseCommand("select * from (select max(x) as max from bar)
x"); //$NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(cast(bar.x
as char(36))) AS max FROM bar) x", trans, command); //$NON-NLS-1$
}
+
+ @Test public void testRowLimitWithInlineViewOrderBy() throws Exception {
+ String input = "select intkey from (select intkey from bqt1.smalla) as x
order by intkey limit 100"; //$NON-NLS-1$
+ String output = "SELECT TOP 100 v_0.c_0 FROM (SELECT g_0.IntKey AS c_0 FROM
SmallA g_0) v_0 ORDER BY v_0.c_0"; //$NON-NLS-1$
+
+ CommandBuilder commandBuilder = new
CommandBuilder(FakeMetadataFactory.exampleBQTCached());
+ Command obj = commandBuilder.getCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(output, trans, obj);
+ }
}
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-11-23
16:47:16 UTC (rev 2736)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-11-23
16:49:01 UTC (rev 2737)
@@ -362,14 +362,11 @@
element = new AliasSymbol(element.getShortName(),
(SingleElementSymbol)expr);
} else if (expr instanceof ElementSymbol) {
element = (ElementSymbol)expr;
+ visitNode(element);
}
item.setSymbol(element);
element.setOutputName(name);
}
-
- if (!(element instanceof ElementSymbol)) {
- visitNode(element);
- }
}
}
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
===================================================================
---
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java 2010-11-23
16:47:16 UTC (rev 2736)
+++
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java 2010-11-23
16:49:01 UTC (rev 2737)
@@ -36,7 +36,6 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.unittest.FakeMetadataFactory;
@SuppressWarnings("nls")
@@ -75,7 +74,7 @@
String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY
c_0"; //$NON-NLS-1$
Query command = (Query)helpTest(sql, expected, true, false,
FakeMetadataFactory.example1Cached());
assertEquals(command.getOrderBy().getSortKeys().get(0).getName(),
"e1"); //$NON-NLS-1$
-
assertEquals(((SingleElementSymbol)command.getProjectedSymbols().get(0)).getShortName(),
"e1"); //$NON-NLS-1$
+ assertEquals(command.getProjectedSymbols().get(0).getShortName(),
"e1"); //$NON-NLS-1$
}
@Test public void testInlineViewWithSubQuery() throws Exception {
@@ -87,7 +86,10 @@
@Test public void testInlineViewOrderBy() throws Exception {
String sql = "select intnum from (select intnum from bqt1.smallb) b order by
b.intnum"; //$NON-NLS-1$
String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM
bqt1.smallb AS g_0) AS v_0 ORDER BY c_0"; //$NON-NLS-1$
- helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
+ Command command = helpTest(sql, expected, true, false,
FakeMetadataFactory.exampleBQTCached());
+ LanguageBridgeFactory lbf = new
LanguageBridgeFactory(FakeMetadataFactory.exampleBQTCached());
+ org.teiid.language.Command c = lbf.translate(command);
+ assertEquals("SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM SmallB AS
g_0) AS v_0 ORDER BY v_0.c_0", c.toString());
}
@Test public void testNestedInlineViewOrderBy() throws Exception {
Show replies by date