[teiid-commits] teiid SVN: r4128 - in branches/7.4.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon May 21 10:56:11 EDT 2012


Author: jolee
Date: 2012-05-21 10:56:10 -0400 (Mon, 21 May 2012)
New Revision: 4128

Modified:
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
   branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
Log:
TEIID-2045 fix for insert with query expression

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java	2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java	2012-05-21 14:56:10 UTC (rev 4128)
@@ -22,16 +22,7 @@
 
 package org.teiid.query.optimizer.relational.rules;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.api.exception.query.QueryPlannerException;
@@ -501,7 +492,7 @@
         if(sourceNode.getType() != NodeConstants.Types.SOURCE) {
             sourceNode = sourceNode.getFirstChild();
         } 
-        if(sourceNode != null && sourceNode.getType() == NodeConstants.Types.SOURCE) {
+        if(sourceNode != null && sourceNode.getType() == NodeConstants.Types.SOURCE && sourceNode.getChildCount() == 0) {
             Command command = (Command) sourceNode.getProperty(NodeConstants.Info.VIRTUAL_COMMAND);
             if(! (command instanceof QueryCommand)) {
                 return command;

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java	2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java	2012-05-21 14:56:10 UTC (rev 4128)
@@ -112,7 +112,11 @@
             	addDistinct(metadata, capFinder, accessNode, queryCommand);
                 command = queryCommand;
                 if (intoGroup != null) {
-                	Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
+                	Insert insertCommand = (Insert)commandRoot.getParent().getProperty(NodeConstants.Info.VIRTUAL_COMMAND);
+                	if (insertCommand == null) {
+                		//TODO: this is probably no longer needed as we rewrite select into
+                		insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
+                	}
                 	insertCommand.setQueryExpression(queryCommand);
                 	command = insertCommand;
                 }

Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java	2012-05-21 14:05:09 UTC (rev 4127)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java	2012-05-21 14:56:10 UTC (rev 4128)
@@ -15,6 +15,7 @@
 import org.teiid.query.metadata.QueryMetadataInterface;
 import org.teiid.query.optimizer.TestOptimizer;
 import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
 import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
 import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
 import org.teiid.query.sql.lang.BatchedUpdateCommand;
@@ -367,7 +368,7 @@
         // if not doBulkInsert and is doBatching,
         //    check the command hist to ensure it contains the expected commands
         if ( !doBulkInsert && doBatching ) {
-            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(2);
+            BatchedUpdateCommand bu = (BatchedUpdateCommand)dataManager.getCommandHistory().get(2);
             assertEquals(2, bu.getUpdateCommands().size());
             assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
             assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
@@ -390,5 +391,41 @@
         // Run query
         helpProcess(plan, dataManager, expected);
     }
+    
+    @Test public void testInsertQueryExpression() throws Exception {
+        String sql = "insert into pm1.g1 select * from pm1.g2"; //$NON-NLS-1$
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+        caps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true);
+        DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps); 
+        
+        QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+        
+        Command command = helpParse(sql); 
 
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
+        List<?>[] expected = new List<?>[] {Arrays.asList(1)};
+		dataManager.addData("INSERT INTO g1 (e1, e2, e3, e4) SELECT g2.e1, g2.e2, g2.e3, g2.e4 FROM g2", expected);
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testInsertQueryExpression1() throws Exception {
+        String sql = "insert into pm1.g1 (e1) select e1 from pm1.g2"; //$NON-NLS-1$
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+        caps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION, true);
+        DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps); 
+        
+        QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
+        
+        Command command = helpParse(sql); 
+
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
+        List<?>[] expected = new List<?>[] {Arrays.asList(1)};
+		dataManager.addData("INSERT INTO g1 (e1) SELECT g2.e1 FROM g2", expected);
+        helpProcess(plan, dataManager, expected);
+    }
+
 }



More information about the teiid-commits mailing list