[teiid-commits] teiid SVN: r1689 - in trunk/engine/src/test/java/com/metamatrix/query: processor and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Dec 21 15:01:48 EST 2009


Author: loleary
Date: 2009-12-21 15:01:48 -0500 (Mon, 21 Dec 2009)
New Revision: 1689

Modified:
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
Log:
TEIID-912: Add unit test methods from JBEDSP-1137: StackOverflowError when top level query uses the same symbol name and group alias that is in a second level query or sub-query
Tests migrated from JBEDSP-1137 (R050503)
Reviewed by shawkins

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java	2009-12-21 19:43:33 UTC (rev 1688)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java	2009-12-21 20:01:48 UTC (rev 1689)
@@ -6736,6 +6736,108 @@
     			TestOptimizer.SHOULD_SUCCEED);
     }
 
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query.
+     * <p>
+     * No source table is being used.  For example, <code>SELECT A.e2 FROM 
+     * (SELECT e2 FROM (SELECT 1 AS e2) AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasInSubQueryNoSource() {
+        // Create query
+    	String sql = "SELECT A.e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"	SELECT e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"		SELECT 5 AS e2" + //$NON-NLS-1$
+    	"	) AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+        helpPlan(sql, FakeMetadataFactory.example1(), new String[] {});
+    }
+         
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query
+     * and uses columns belonging to the alias as a parameter to a function.
+     * <p>
+     * No source table is being used.  For example, <code>SELECT CONVERT(A.e2, 
+     * biginteger) AS e2 FROM (SELECT CONVERT(e2, long) AS e2 FROM (SELECT 1 AS 
+     * e2) AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasFunctionInSubQueryNoSource() {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"	SELECT CONVERT(e2, long) AS e2 FROM (" + //$NON-NLS-1$
+    	"		SELECT 5 AS e2" + //$NON-NLS-1$
+    	"	) AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+    	helpPlan(sql, FakeMetadataFactory.example1(), new String[] {});
+    }
+
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query.
+     * <p>
+     * For example, <code>SELECT A.e2 FROM (SELECT e12FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasInSubQuerySource() {
+        // Create query
+    	String sql = "SELECT A.e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT e2 AS e2 FROM pm1.g1 AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+        helpPlan(sql, FakeMetadataFactory.example1(), new String[] {"SELECT e2 FROM pm1.g1 AS A"}); //$NON-NLS-1$
+    }
+         
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query
+     * and uses columns belonging to the alias as a parameter to a function.
+     * <p>
+     * For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT 
+     * CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasFunctionInSubQuerySource() {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+        helpPlan(sql, FakeMetadataFactory.example1(), new String[] {"SELECT e2 FROM pm1.g1 AS A"}); //$NON-NLS-1$
+
+        // Add convert capability to pm1 and try it again
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+
+        helpPlan(sql, metadata, null, capFinder,
+            new String[] {"SELECT CONVERT(CONVERT(e2, long), biginteger) FROM pm1.g1 AS A"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    }
+
 	public static final boolean DEBUG = false;
 
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-12-21 19:43:33 UTC (rev 1688)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-12-21 20:01:48 UTC (rev 1689)
@@ -7510,6 +7510,40 @@
         
         helpProcess(plan, dataManager, expected);
     }
-    
+
+    /**
+     * Test a query that uses ambiguous alias names in the top level query and 
+     * its sub-query and uses columns belonging to the alias as a parameter to a 
+     * function.
+     * <p>
+     * For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT 
+     * CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAliasReuseInFunctionInSubQuery() throws Exception {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A WHERE e1 = 'a'" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new BigInteger("3") }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$ 
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+
     private static final boolean DEBUG = false;
 }



More information about the teiid-commits mailing list