[teiid-commits] teiid SVN: r1466 - in trunk/engine/src: main/java/com/metamatrix/query/optimizer/relational and 17 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Sep 23 14:22:51 EDT 2009


Author: shawkins
Date: 2009-09-23 14:22:50 -0400 (Wed, 23 Sep 2009)
New Revision: 1466

Modified:
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/QueryOptimizer.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/MergeTreeNodeProcessor.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLQueryPlanner.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
   trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
   trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
   trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
   trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/SimpleQueryProcessorFactory.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
   trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
   trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
Log:
TEIID-848 TEIID-788 TEIID-853 making insert with a query expression the dominant processing abstraction, adding validation of select into in a union, changing dynamic sql projection to positional, fixing insert with query expression

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/QueryOptimizer.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/QueryOptimizer.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/QueryOptimizer.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -167,9 +167,7 @@
             analysisRecord.println("\nCANONICAL PLAN: \n" + node.getCanonicalPlan()); //$NON-NLS-1$
 		}   
 				
-		Iterator commands = command.getSubCommands().iterator();
-		while (commands.hasNext()) {
-			Command subcommand = (Command) commands.next();
+		for (Command subcommand : command.getSubCommands()) {
 			CommandTreeNode child = new CommandTreeNode();
 			node.addLastChild(child);
             child.setParent(node);
@@ -193,11 +191,7 @@
 		AnalysisRecord analysisRecord,
         CommandContext context) 
 	throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
-
-				
-		Iterator commands = node.getChildren().iterator();
-		while (commands.hasNext()) {
-			CommandTreeNode child = (CommandTreeNode) commands.next();
+		for (CommandTreeNode child : node.getChildren()) {
 			recursiveOptimize(child, idGenerator, metadata, capFinder, analysisRecord, context);
 		}
         

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -27,6 +27,7 @@
 import java.util.List;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
@@ -40,11 +41,13 @@
 import com.metamatrix.query.sql.lang.From;
 import com.metamatrix.query.sql.lang.FromClause;
 import com.metamatrix.query.sql.lang.GroupBy;
+import com.metamatrix.query.sql.lang.Insert;
 import com.metamatrix.query.sql.lang.JoinPredicate;
 import com.metamatrix.query.sql.lang.JoinType;
 import com.metamatrix.query.sql.lang.Limit;
 import com.metamatrix.query.sql.lang.Option;
 import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.ProcedureContainer;
 import com.metamatrix.query.sql.lang.Query;
 import com.metamatrix.query.sql.lang.QueryCommand;
 import com.metamatrix.query.sql.lang.Select;
@@ -53,6 +56,7 @@
 import com.metamatrix.query.sql.lang.SubqueryFromClause;
 import com.metamatrix.query.sql.lang.UnaryFromClause;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
 import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
 import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
@@ -84,7 +88,7 @@
 			// update PlanHints to note that it is an update
 			hints.isUpdate = true;
 
-			return GenerateCanonical.createUpdatePlan(command, hints);
+			return GenerateCanonical.createUpdatePlan(command, hints, metadata);
 
 		} else if( command.getType() == Command.TYPE_STORED_PROCEDURE) {
 
@@ -97,30 +101,43 @@
 
 	private GenerateCanonical() { }
 
-	static PlanNode createUpdatePlan(Command command, PlanHints hints) {
+	static PlanNode createUpdatePlan(Command command, PlanHints hints, QueryMetadataInterface metadata) throws QueryPlannerException, MetaMatrixComponentException {
 
         // Create top project node - define output columns for stored query / procedure
         PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
 
-        Collection groups = GroupCollectorVisitor.getGroups(command, false);
+        Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(command, false);
         projectNode.addGroups(groups);
 
         // Set output columns
-        List cols = command.getProjectedSymbols();
+        List<SingleElementSymbol> cols = command.getProjectedSymbols();
         projectNode.setProperty(NodeConstants.Info.PROJECT_COLS, cols);
 
         // Define source of data for stored query / procedure
         PlanNode sourceNode = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
         sourceNode.setProperty(NodeConstants.Info.ATOMIC_REQUEST, command);
         sourceNode.setProperty(NodeConstants.Info.VIRTUAL_COMMAND, command);
-        List subCommands = command.getSubCommands();
-        if (subCommands.size() == 1) {
-            sourceNode.setProperty(NodeConstants.Info.NESTED_COMMAND, subCommands.iterator().next());
+        if (command instanceof ProcedureContainer) {
+        	ProcedureContainer container = (ProcedureContainer)command;
+	        if (container.getSubCommand() != null) {
+	            sourceNode.setProperty(NodeConstants.Info.NESTED_COMMAND, container.getSubCommand());
+	        }
         }
         sourceNode.addGroups(groups);
 
         GenerateCanonical.attachLast(projectNode, sourceNode);
 
+        //for INTO query, attach source and project nodes
+        if(command instanceof Insert){
+        	Insert insert = (Insert)command;
+        	if (insert.getQueryExpression() != null) {
+	            PlanNode plan = createQueryPlan(insert.getQueryExpression(), hints, metadata);
+	            GenerateCanonical.attachLast(sourceNode, plan);
+	            MergeTreeNodeProcessor.mergeTempMetadata(insert.getQueryExpression(), insert);
+	            projectNode.setProperty(NodeConstants.Info.INTO_GROUP, insert.getGroup());
+        	}
+        }
+        
         return projectNode;
 	}
 
@@ -203,7 +220,7 @@
     }
 
     private static PlanNode createQueryPlan(Query query, PlanHints hints, QueryMetadataInterface metadata)
-		throws QueryPlannerException, MetaMatrixComponentException {
+		throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
 
         PlanNode plan = null;
 
@@ -212,7 +229,7 @@
             
             PlanNode dummyRoot = new PlanNode();
             
-    		hints.hasOptionalJoin |= buildTree(fromClause, dummyRoot);
+    		hints.hasOptionalJoin |= buildTree(fromClause, dummyRoot, metadata, hints);
             
             plan = dummyRoot.getFirstChild();
             
@@ -255,33 +272,6 @@
             plan = attachTupleLimit(plan, query.getLimit(), hints);
         }
 
-        //for SELECT INTO, attach source and project nodes
-        if(query.getInto() != null){
-            // For defect 10976 - find project in current plan and
-            // set top columns
-            List groups = null;
-            PlanNode sourceNode = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
-                
-            GenerateCanonical.attachLast(sourceNode, plan);
-            plan = sourceNode;
-
-            if (query.getFrom() != null){
-                groups = query.getFrom().getGroups();
-                sourceNode.addGroups(groups);
-            }
-
-            PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
-            List selectCols = query.getProjectedSymbols();
-            projectNode.setProperty(NodeConstants.Info.PROJECT_COLS, selectCols);
-            projectNode.setProperty(NodeConstants.Info.INTO_GROUP, query.getInto().getGroup());
-
-            if (groups != null){
-                projectNode.addGroups(groups);
-            }
-            GenerateCanonical.attachLast(projectNode, plan);
-            plan = projectNode;
-        }
-
 		return plan;
 	}
 
@@ -310,9 +300,11 @@
      * @param markJoinsInternal Flag saying whether joins built in this method should be marked
      * as internal
      * @return true if there are optional join nodes
+     * @throws MetaMatrixComponentException 
+     * @throws QueryMetadataException 
      */
-    static boolean buildTree(FromClause clause, PlanNode parent)
-        throws QueryPlannerException {
+    static boolean buildTree(FromClause clause, PlanNode parent, QueryMetadataInterface metadata, PlanHints hints)
+        throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
         
         boolean result = false;
         
@@ -322,6 +314,9 @@
             // No join required
             UnaryFromClause ufc = (UnaryFromClause)clause;
             GroupSymbol group = ufc.getGroup();
+            if (metadata.isVirtualGroup(group.getMetadataID())) {
+            	hints.hasVirtualGroups = true;
+            }
             Command nestedCommand = ufc.getExpandedCommand();
             node = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
             node.addGroup(group);
@@ -347,7 +342,7 @@
             // Handle each child
             FromClause[] clauses = new FromClause[] {jp.getLeftClause(), jp.getRightClause()};
             for(int i=0; i<2; i++) {
-                result |= buildTree(clauses[i], node);
+                result |= buildTree(clauses[i], node, metadata, hints);
 
                 // Add groups to joinNode
                 for (PlanNode child : node.getChildren()) {
@@ -361,7 +356,7 @@
             node = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
             node.addGroup(group);
             node.setProperty(NodeConstants.Info.NESTED_COMMAND, nestedCommand);
-            
+            hints.hasVirtualGroups = true;
             parent.addLastChild(node);
         }
         

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/MergeTreeNodeProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/MergeTreeNodeProcessor.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/MergeTreeNodeProcessor.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -103,9 +103,7 @@
 			Command childCommand = child.getCommand();
 			Command parentCommand = parent.getCommand();
 			
-			Iterator i = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(parentCommand).iterator();
-			while (i.hasNext()) {
-                SubqueryContainer crit = (SubqueryContainer) i.next();
+			for (SubqueryContainer crit : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(parentCommand)) {
 				if (crit.getCommand() == childCommand){
 					//Don't merge these two nodes
 					return;
@@ -124,7 +122,7 @@
      * @param childCommand 
      * @param parentCommand
      */
-    private static void mergeTempMetadata(
+    static void mergeTempMetadata(
         Command childCommand,
         Command parentCommand) {
         Map childTempMetadata = childCommand.getTemporaryMetadata();
@@ -155,9 +153,7 @@
 	throws QueryMetadataException, MetaMatrixComponentException {
 			
 		PlanNode parentPlan = (PlanNode)parent.getCanonicalPlan();
-		Iterator sourceNodes = NodeEditor.findAllNodes(parentPlan, NodeConstants.Types.SOURCE).iterator();
-		while (sourceNodes.hasNext()){
-			PlanNode sourceNode = (PlanNode)sourceNodes.next();
+		for (PlanNode sourceNode : NodeEditor.findAllNodes(parentPlan, NodeConstants.Types.SOURCE)) {
             if(sourceNode.getChildCount()>0) {
                 continue;
             }

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.query.optimizer.relational;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -30,8 +29,6 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
 import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
 import com.metamatrix.core.id.IDGenerator;
 import com.metamatrix.core.id.IntegerID;
 import com.metamatrix.core.id.IntegerIDFactory;
@@ -40,12 +37,12 @@
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.optimizer.QueryOptimizer;
 import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
 import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
 import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
 import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
 import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
+import com.metamatrix.query.optimizer.relational.plantree.NodeConstants.Info;
 import com.metamatrix.query.optimizer.relational.rules.CapabilitiesUtil;
 import com.metamatrix.query.processor.ProcessorPlan;
 import com.metamatrix.query.processor.relational.AccessNode;
@@ -71,9 +68,7 @@
 import com.metamatrix.query.processor.relational.JoinNode.JoinStrategyType;
 import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
 import com.metamatrix.query.processor.relational.SortUtility.Mode;
-import com.metamatrix.query.resolver.QueryResolver;
 import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.rewriter.QueryRewriter;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.Insert;
@@ -84,7 +79,6 @@
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
 import com.metamatrix.query.sql.util.SymbolMap;
 import com.metamatrix.query.sql.visitor.EvaluatableVisitor;
 import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
@@ -169,28 +163,16 @@
                 GroupSymbol intoGroup = (GroupSymbol) node.getProperty(NodeConstants.Info.INTO_GROUP);
                 if(intoGroup != null) {
                     try {
-                        // Figure out what elements should be inserted based on what is being projected 
-                        // from child node
-                        List<ElementSymbol> allIntoElements = ResolverUtil.resolveElementsInGroup(intoGroup, metadata);
+                    	Insert insert = (Insert)node.getFirstChild().getProperty(Info.VIRTUAL_COMMAND);
+                        List<ElementSymbol> allIntoElements = insert.getVariables();
                         
-                        
                         Object groupID = intoGroup.getMetadataID();
                         Object modelID = metadata.getModelID(groupID);
                         String modelName = metadata.getFullName(modelID);
                         if (metadata.isVirtualGroup(groupID)) {
-                        	List<Reference> references = new ArrayList<Reference>(allIntoElements.size());
-                        	for (int i = 0; i < allIntoElements.size(); i++) {
-                        		Reference ref = new Reference(i);
-                        		ref.setType(allIntoElements.get(i).getType());
-								references.add(ref);
-							}
-                        	Insert insert = new Insert(intoGroup, allIntoElements, references);
-                        	QueryResolver.resolveCommand(insert, metadata, analysisRecord);
-                        	QueryRewriter.rewrite(insert, null, metadata, context);
-                        	ProcessorPlan plan = QueryOptimizer.optimizePlan(insert, metadata, idGenerator, capFinder, analysisRecord, context);
                         	InsertPlanExecutionNode ipen = new InsertPlanExecutionNode(getID());
-                        	ipen.setProcessorPlan(plan);
-                        	ipen.setReferences(references);
+                        	ipen.setProcessorPlan((ProcessorPlan)node.getFirstChild().getProperty(Info.PROCESSOR_PLAN));
+                        	ipen.setReferences(insert.getValues());
                         	processNode = ipen;
                         } else {
 	                        ProjectIntoNode pinode = new ProjectIntoNode(getID());
@@ -208,10 +190,6 @@
                         }
                     } catch(QueryMetadataException e) {
                         throw new MetaMatrixComponentException(e);
-                    } catch(QueryResolverException e) {
-                        throw new MetaMatrixComponentException(e);
-                    } catch(QueryValidatorException e) {
-                        throw new MetaMatrixComponentException(e);
                     }
 
                 } else {

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -111,7 +111,6 @@
         // Check whether command has virtual groups
         Command command = node.getCommand();
         PlanHints hints = (PlanHints)node.getProperty(RelationalPlanner.HINTS);
-        RelationalPlanner.checkForVirtualGroups(command, hints, metadata);
 
         // Distribute make dependent hints as necessary
         if(hints.makeDepGroups != null) {
@@ -211,27 +210,6 @@
     }
 
     /**
-     * Look for any virtual groups in the user's command.  If some exist, then
-     * set the hint for virtual groups to true.  Otherwise, leave the hint at it's
-     * default value which is false.  This allows the buildRules() method later to
-     * leave out a bunch of rules relating to virtual groups if none were used.
-     * @param command Command to check
-     * @param hints Hints to update if virtual groups are used in plan
-     */
-    private static void checkForVirtualGroups(Command command, PlanHints hints, QueryMetadataInterface metadata)
-    throws QueryMetadataException, MetaMatrixComponentException {
-        Collection groups = GroupCollectorVisitor.getGroups(command, true);
-        Iterator groupIter = groups.iterator();
-        while (groupIter.hasNext()) {
-            GroupSymbol group = (GroupSymbol) groupIter.next();
-            if( metadata.isVirtualGroup(group.getMetadataID()) ) {
-                hints.hasVirtualGroups = true;
-                break;
-            }
-        }
-    }
-
-    /**
      * Distribute and "make (not) dependent" hints specified in the query into the
      * fully resolved query plan.  This is done after virtual group resolution so
      * that all groups in the plan are known.  The hint is attached to all SOURCE

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/QueryUtil.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -126,10 +126,10 @@
      * @throws QueryPlannerException
      * @since 4.3
      */
-    static void rewriteQuery(Command query, QueryMetadataInterface metadata, CommandContext context) 
+    static Command rewriteQuery(Command query, QueryMetadataInterface metadata, CommandContext context) 
         throws QueryPlannerException {
         try {
-            QueryRewriter.rewrite(query, null, metadata, context);
+            return QueryRewriter.rewrite(query, null, metadata, context);
         } catch(QueryValidatorException e) {
             throw new QueryPlannerException(e, e.getMessage());
         }

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLQueryPlanner.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/xml/XMLQueryPlanner.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -433,7 +433,7 @@
 	        }
         }
         
-        QueryUtil.rewriteQuery(query, planEnv.getGlobalMetadata(), planEnv.context);
+        Command cmd = QueryUtil.rewriteQuery(query, planEnv.getGlobalMetadata(), planEnv.context);
                 
         ProcessorPlan plan = null;
         
@@ -445,7 +445,7 @@
         
         try {
             // register with env
-            plan = optimizePlan(query, planEnv);
+            plan = optimizePlan(cmd, planEnv);
         } catch (QueryPlannerException e) {
             if (implicit) {
                 if (debug) {
@@ -488,7 +488,7 @@
         }
         
         ResultSetInfo rsInfo = planEnv.getStagingTableResultsInfo(stageGroupName);
-        rsInfo.setCommand(query);
+        rsInfo.setCommand(cmd);
         rsInfo.setPlan(plan);
         
         //set the carinality on the temp group.
@@ -504,7 +504,7 @@
         ResultSetInfo rsUnloadInfo = planEnv.getStagingTableResultsInfo(unloadName);
         Command command = wrapStagingTableUnloadQuery(intoGroupSymbol);
         QueryUtil.resolveQuery(command, planEnv.getGlobalMetadata());
-        QueryUtil.rewriteQuery(command, planEnv.getGlobalMetadata(), planEnv.context);
+        command = QueryUtil.rewriteQuery(command, planEnv.getGlobalMetadata(), planEnv.context);
         
         plan = optimizePlan(command, planEnv);
         rsUnloadInfo.setCommand(command);

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -33,7 +33,6 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.api.exception.query.QueryProcessingException;
-import com.metamatrix.api.exception.query.QueryResolverException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.log.LogManager;
 import com.metamatrix.common.types.DataTypeManager;
@@ -42,7 +41,6 @@
 import com.metamatrix.query.analysis.AnalysisRecord;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
 import com.metamatrix.query.metadata.TempMetadataStore;
 import com.metamatrix.query.optimizer.QueryOptimizer;
 import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
@@ -52,28 +50,19 @@
 import com.metamatrix.query.processor.program.ProgramInstruction;
 import com.metamatrix.query.resolver.QueryResolver;
 import com.metamatrix.query.resolver.util.ResolveVirtualGroupCriteriaVisitor;
-import com.metamatrix.query.resolver.util.ResolverUtil;
 import com.metamatrix.query.rewriter.QueryRewriter;
 import com.metamatrix.query.sql.ProcedureReservedWords;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.DynamicCommand;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Into;
+import com.metamatrix.query.sql.lang.Insert;
 import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
 import com.metamatrix.query.sql.lang.SetClause;
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
 import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
 import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
 import com.metamatrix.query.util.CommandContext;
 
 /**
@@ -189,13 +178,18 @@
             nameValueMap.putAll(QueryResolver.getVariableValues(parentProcCommand.getUserCommand(), metadata));
             // validation visitor?
 
-			QueryRewriter.rewrite(command, parentProcCommand, metadata,
-					procEnv.getContext(), nameValueMap, parentProcCommand.getUserCommand().getType());
-
-			if (dynamicCommand.getAsColumns() != null
+            if (dynamicCommand.getAsColumns() != null
 					&& !dynamicCommand.getAsColumns().isEmpty()) {
-				command = wrapCommand(command);
+        		command = QueryRewriter.createInlineViewQuery(new GroupSymbol("X"), command, metadata, dynamicCommand.getAsColumns()); //$NON-NLS-1$
+				if (dynamicCommand.getIntoGroup() != null) {
+					Insert insert = new Insert(dynamicCommand.getIntoGroup(), dynamicCommand.getAsColumns(), Collections.emptyList());
+					insert.setQueryExpression((Query)command);
+					command = insert;
+				}
 			}
+            
+			command = QueryRewriter.rewrite(command, parentProcCommand, metadata,
+					procEnv.getContext(), nameValueMap, parentProcCommand.getUserCommand().getType());
 
             ProcessorPlan commandPlan = QueryOptimizer.optimizePlan(command, metadata,
 					idGenerator, capFinder, AnalysisRecord
@@ -247,92 +241,6 @@
 	}
     
 	/**
-	 * @param command
-	 * @return
-	 * @throws QueryResolverException
-	 * @throws MetaMatrixComponentException
-	 */
-	private Query wrapCommand(Command command) throws QueryResolverException,
-			MetaMatrixComponentException {
-		Collection groups = GroupCollectorVisitor.getGroups(command, true);
-		int i = 0;
-		String subquery_group_name = "X"; //$NON-NLS-1$
-		GroupSymbol groupSymbol = new GroupSymbol(subquery_group_name);
-		while (groups.contains(groupSymbol)) {
-			subquery_group_name = "X" + i; //$NON-NLS-1$
-			i++;
-			groupSymbol = new GroupSymbol(subquery_group_name);
-		}
-
-		Select select = new Select();
-		
-		Map shortNameMap = createShortNameMap(command.getProjectedSymbols());
-
-		Iterator columns = dynamicCommand.getAsColumns().iterator();
-		while (columns.hasNext()) {
-			Class projectedSymbolType = null;
-			ElementSymbol expectedSymbol = (ElementSymbol) columns.next();
-			String expectedName = expectedSymbol.getShortCanonicalName();
-			String actualName = expectedName;
-			boolean shouldAlias = false;
-
-			if (dynamicCommand.getAsColumns().size() == 1) {
-				SingleElementSymbol projectedSymbol = (SingleElementSymbol) command
-						.getProjectedSymbols().get(0);
-				actualName = projectedSymbol.getShortCanonicalName();
-				projectedSymbolType = projectedSymbol.getType();
-				shouldAlias = !actualName.equals(expectedName);
-			} else {
-				projectedSymbolType = (Class)shortNameMap.get(expectedName); 
-			}
-			SingleElementSymbol wrappedSymbol = new ElementSymbol(groupSymbol
-					.getCanonicalName()
-					+ SingleElementSymbol.SEPARATOR
-					+ actualName);
-
-            Expression result = ResolverUtil.convertExpression(wrappedSymbol, DataTypeManager.getDataTypeName(projectedSymbolType), DataTypeManager.getDataTypeName(expectedSymbol.getType()));
-            
-			if (!(result instanceof SingleElementSymbol)) {
-				wrappedSymbol = new ExpressionSymbol(expectedName, result);
-				shouldAlias = true;
-			}
-			if (shouldAlias) {
-				wrappedSymbol = new AliasSymbol(expectedName, wrappedSymbol);
-			}
-			
-			select.addSymbol(wrappedSymbol);
-		}
-		Query query = new Query();
-		query.setSelect(select);
-		From from = new From();
-        
-        GroupSymbol inlineGroup = new GroupSymbol(subquery_group_name);
-        
-        from.addClause(new UnaryFromClause(inlineGroup)); 
-        TempMetadataStore store = new TempMetadataStore();
-        TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
-        
-        store.addTempGroup(inlineGroup.getName(), command.getProjectedSymbols());
-        inlineGroup.setMetadataID(store.getTempGroupID(inlineGroup.getName()));
-        query.setFrom(from); 
-        QueryResolver.resolveCommand(query, tma);
-        query.setOption(command.getOption());
-                
-        from.getClauses().clear();
-        SubqueryFromClause sqfc = new SubqueryFromClause(inlineGroup.getName());
-        sqfc.setCommand(command);
-        sqfc.getGroupSymbol().setMetadataID(inlineGroup.getMetadataID());
-        from.addClause(sqfc);
-        //copy the metadata onto the new query so that temp metadata adapters will be used in later calls
-        query.getTemporaryMetadata().putAll(store.getData()); 
-
-		if (dynamicCommand.getIntoGroup() != null) {
-			query.setInto(new Into(dynamicCommand.getIntoGroup()));
-		}
-		return query;
-	}
-
-	/**
 	 * @param localContext
 	 * @return
 	 */
@@ -361,53 +269,32 @@
 			QueryProcessingException {
 		// validate project symbols
 		List dynamicExpectedColumns = dynamicCommand.getAsColumns();
-		List sourceProjectedSymbolList = command.getProjectedSymbols();
+		List<SingleElementSymbol> sourceProjectedSymbolList = command.getProjectedSymbols();
 
 		if (dynamicExpectedColumns != null && !dynamicExpectedColumns.isEmpty()) {
-			if (dynamicExpectedColumns.size() != sourceProjectedSymbolList
-					.size()) {
+			if (dynamicExpectedColumns.size() != sourceProjectedSymbolList.size()) {
 				throw new QueryProcessingException(QueryExecPlugin.Util
 						.getString("ExecDynamicSqlInstruction.4")); //$NON-NLS-1$
 			}
 			// If there is only one project symbol, we won't validate the name.
 
 			Iterator dynamicIter = dynamicExpectedColumns.iterator();
-			Map sourceMap = createShortNameMap(sourceProjectedSymbolList);
-
+			Iterator<SingleElementSymbol> sourceIter = sourceProjectedSymbolList.iterator();
 			// Check for proper element name and datatype definition in the
 			// dynamic SQL
 			// If the projected symbol list equal to 1, we won't bother checking
 			// the name.
 			while (dynamicIter.hasNext()) {
-				SingleElementSymbol dynamicSymbol = (SingleElementSymbol) dynamicIter
-						.next();
-				Object sourceSymbolDatatype = null;
-				// If the project list is greater than one, use the dynamic
-				// symbol
-				// to get the source project. Otherwise just get the one and
-				// only.
-				if (dynamicExpectedColumns.size() > 1) {
-					sourceSymbolDatatype = sourceMap.get(dynamicSymbol
-							.getShortCanonicalName());
+				SingleElementSymbol dynamicSymbol = (SingleElementSymbol) dynamicIter.next();
+				Class<?> sourceSymbolDatatype = sourceIter.next().getType();
 
-					if (sourceSymbolDatatype == null) {
-						Object[] params = new Object[] { dynamicSymbol
-								.getShortCanonicalName() };
-						throw new QueryProcessingException(QueryExecPlugin.Util
-								.getString(
-										"ExecDynamicSqlInstruction.5", params)); //$NON-NLS-1$
-					}
-				} else {
-					sourceSymbolDatatype = sourceMap.values().iterator().next();
-				}
-
 				// Check if the the dynamic sql element types are equal or
 				// implicitly convertible to the source types
-				Class dynamicType = dynamicSymbol.getType();
+				Class<?> dynamicType = dynamicSymbol.getType();
 				String dynamicTypeName = DataTypeManager
 						.getDataTypeName(dynamicType);
 				String sourceTypeName = DataTypeManager
-						.getDataTypeName((Class) sourceSymbolDatatype);
+						.getDataTypeName(sourceSymbolDatatype);
 				if (!dynamicTypeName.equals(sourceTypeName)
 						&& // If the types aren't the same, and...
 						!DataTypeManager.isImplicitConversion(sourceTypeName,
@@ -444,23 +331,6 @@
 	}
 
 	/**
-	 * @param sourceProjectedSymbolList
-	 * @return
-	 */
-	private Map createShortNameMap(List sourceProjectedSymbolList) {
-		Iterator sourceIter = sourceProjectedSymbolList.iterator();
-		Map sourceMap = new HashMap();
-
-		// Load source project symbol map
-		while (sourceIter.hasNext()) {
-			SingleElementSymbol symbol = (SingleElementSymbol) sourceIter
-					.next();
-			sourceMap.put(symbol.getShortCanonicalName(), symbol.getType());
-		}
-		return sourceMap;
-	}
-
-	/**
 	 * Returns a deep clone
 	 */
 	public Object clone() {

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -473,7 +473,7 @@
         tempTables.addAll(current);
         
         for (Iterator i = tempTables.iterator(); i.hasNext();) {
-            removeResults((String)i.next());
+            this.tempTableStore.removeTempTableByName((String)i.next());
         }
         
         this.tempContext.removeLast();
@@ -565,7 +565,6 @@
                 throw new MetaMatrixComponentException(e, ErrorMessageKeys.PROCESSOR_0022, QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0022, (String) null));
     		}
             LogManager.logTrace(LogConstants.CTX_DQP, new Object[]{"removed tuple source", state.tsID, "for result set"}); //$NON-NLS-1$ //$NON-NLS-2$
-            this.tempTableStore.removeTempTableByName(rsKey);
         }
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -55,6 +55,7 @@
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
 import com.metamatrix.query.util.ErrorMessageKeys;
 
 /**
@@ -75,7 +76,7 @@
         
         //variables and values must be resolved separately to account for implicitly defined temp groups
         resolveList(insert.getValues(), metadata, insert.getExternalGroupContexts(), null);
-
+        
         //resolve subquery if there
         if(insert.getQueryExpression() != null) {
         	QueryResolver.setChildMetadata(insert.getQueryExpression(), command);
@@ -83,7 +84,7 @@
             QueryResolver.resolveCommand(insert.getQueryExpression(), Collections.EMPTY_MAP, useMetadataCommands, metadata.getMetadata(), analysis, false);
         }
 
-        Set groups = new HashSet();
+        Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
         groups.add(insert.getGroup());
         
         if (insert.getVariables().isEmpty()) {
@@ -114,11 +115,21 @@
             //ensure that the types match
             resolveTypes(insert);
         }
+        
+        if (insert.getQueryExpression() != null && metadata.isVirtualGroup(insert.getGroup().getMetadataID())) {
+        	List<Reference> references = new ArrayList<Reference>(insert.getVariables().size());
+        	for (int i = 0; i < insert.getVariables().size(); i++) {
+        		Reference ref = new Reference(i);
+        		ref.setType(((ElementSymbol)insert.getVariables().get(i)).getType());
+				references.add(ref);
+			}
+        	insert.setValues(references);
+        }
     }
 
     private void resolveVariables(TempMetadataAdapter metadata,
                                   Insert insert,
-                                  Set groups) throws MetaMatrixComponentException,
+                                  Set<GroupSymbol> groups) throws MetaMatrixComponentException,
                                              QueryResolverException {
         try {
             resolveList(insert.getVariables(), metadata, null, groups);
@@ -128,7 +139,7 @@
     }
 
     private void resolveList(Collection elements, TempMetadataAdapter metadata,
-                                  GroupContext externalGroups, Set groups) throws MetaMatrixComponentException,
+                                  GroupContext externalGroups, Set<GroupSymbol> groups) throws MetaMatrixComponentException,
                                              QueryResolverException {
         for (Iterator i = elements.iterator(); i.hasNext();) {
             Expression expr = (Expression)i.next();

Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -700,7 +700,7 @@
 		return translatedCriteria;
 	}
 
-	private Query rewriteQuery(Query query)
+	private Command rewriteQuery(Query query)
              throws QueryValidatorException {
         
         // Rewrite from clause
@@ -778,7 +778,7 @@
                 } catch (QueryResolverException err) {
                     throw new QueryValidatorException(err, err.getMessage());
                 } catch (MetaMatrixComponentException err) {
-                    throw new QueryValidatorException(err, err.getMessage());
+                    throw new MetaMatrixRuntimeException(err);
                 }
                 Iterator iter = outerQuery.getSelect().getProjectedSymbols().iterator();
                 HashMap<Expression, SingleElementSymbol> expressionMap = new HashMap<Expression, SingleElementSymbol>();
@@ -818,7 +818,7 @@
         }
         
         if (query.getInto() != null) {
-            query = rewriteSelectInto(query);
+            return rewriteSelectInto(query);
         }
         
         return query;
@@ -911,37 +911,43 @@
      * @param query
      * @throws QueryValidatorException
      */
-    private Query rewriteSelectInto(Query query) throws QueryValidatorException {
+    private Insert rewriteSelectInto(Query query) throws QueryValidatorException {
         Into into = query.getInto();
-        
         try {
-            List allIntoElements = ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata);
-            boolean needsView = false;
-            
-            for (int i = 0; !needsView && i < allIntoElements.size(); i++) {
-                SingleElementSymbol ses = (SingleElementSymbol)allIntoElements.get(i);
-                if (ses.getType() != ((SingleElementSymbol)query.getSelect().getProjectedSymbols().get(i)).getType()) {
-                    needsView = true;
-                }
-            }
-            
-            if (needsView) {
-                query.setInto(null);
-                query = createInlineViewQuery(into.getGroup(), query);
-                query.setInto(into);
-                return query;
-            }
-            return query;
+            List<ElementSymbol> allIntoElements = deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
+            Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList());
+            query.setInto(null);
+            insert.setQueryExpression(query);
+            return correctDatatypes(insert);
         } catch (QueryMetadataException err) {
             throw new QueryValidatorException(err, err.getMessage());
-        } catch (QueryResolverException err) {
-            throw new QueryValidatorException(err, err.getMessage());
         } catch (MetaMatrixComponentException err) {
             throw new QueryValidatorException(err, err.getMessage());
-        }
-        
+		}
     }
 
+	private Insert correctDatatypes(Insert insert) throws QueryValidatorException {
+		boolean needsView = false;
+		for (int i = 0; !needsView && i < insert.getVariables().size(); i++) {
+		    SingleElementSymbol ses = (SingleElementSymbol)insert.getVariables().get(i);
+		    if (ses.getType() != insert.getQueryExpression().getProjectedSymbols().get(i).getType()) {
+		        needsView = true;
+		    }
+		}
+		if (needsView) {
+		    try {
+				insert.setQueryExpression(createInlineViewQuery(insert.getGroup(), insert.getQueryExpression(), metadata, insert.getVariables()));
+			} catch (QueryResolverException e) {
+				throw new QueryValidatorException(e, e.getMessage());
+			} catch (QueryMetadataException e) {
+				throw new QueryValidatorException(e, e.getMessage());
+			} catch (MetaMatrixComponentException e) {
+				throw new MetaMatrixRuntimeException(e);
+			}
+		}
+		return insert;
+	}
+
     private void correctProjectedTypes(List actualSymbolTypes, Query query) {
         
         List symbols = query.getSelect().getProjectedSymbols();
@@ -1177,7 +1183,7 @@
             } catch(CriteriaEvaluationException e) {
                 throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0001, QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0001, crit));
             } catch(MetaMatrixComponentException e) {
-                throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0001, QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0001, crit));
+                throw new MetaMatrixRuntimeException(e);
             }
         }
         
@@ -2113,7 +2119,7 @@
                 }
                 throw new QueryValidatorException(e, e.getMessage());
 			} catch(MetaMatrixComponentException e) {
-                throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0005, QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0005, function));
+                throw new MetaMatrixRuntimeException(e);
 			}
 		} 
         return function;
@@ -2288,30 +2294,12 @@
         return storedProcedure;
     }
 
-	private Command rewriteInsert(Insert insert) throws QueryValidatorException {
+	private Insert rewriteInsert(Insert insert) throws QueryValidatorException {
         
         if ( insert.getQueryExpression() != null ) {
-            Query query = null;
-            QueryCommand nested = insert.getQueryExpression();
-            rewriteCommand(nested, true);
-            if(nested instanceof SetQuery) {
-                try {
-                    query = createInlineViewQuery(insert.getGroup(), nested);
-                } catch (QueryMetadataException err) {
-                    throw new QueryValidatorException(err, err.getMessage());
-                } catch (QueryResolverException err) {
-                    throw new QueryValidatorException(err, err.getMessage());
-                } catch (MetaMatrixComponentException err) {
-                    throw new QueryValidatorException(err, err.getMessage());
-                }
-            } else {
-                query = (Query)nested;  
-                query.setOption(insert.getOption());
-            }
-            query.setInto( new Into( insert.getGroup() ) );  
-            return query;
+        	insert.setQueryExpression((QueryCommand)rewriteCommand(insert.getQueryExpression(), true));
+        	return correctDatatypes(insert);
         }
-
         // Evaluate any function / constant trees in the insert values
         List expressions = insert.getValues();
         List evalExpressions = new ArrayList(expressions.size());
@@ -2322,23 +2310,13 @@
         }
 
         insert.setValues(evalExpressions);        
-
 		return insert;
 	}
 
-	/**
-	 * Creates an inline view around the target query.
-	 */
-    private Query createInlineViewQuery(GroupSymbol group,
-                                          QueryCommand nested) throws QueryMetadataException, QueryResolverException, MetaMatrixComponentException {
-        List actualSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
-        return createInlineViewQuery(group, nested, metadata, actualSymbols);
-    }
-
-    private static Query createInlineViewQuery(GroupSymbol group,
-                                               QueryCommand nested,
+    public static Query createInlineViewQuery(GroupSymbol group,
+                                               Command nested,
                                                QueryMetadataInterface metadata,
-                                               List actualSymbols) throws QueryMetadataException,
+                                               List<SingleElementSymbol> actualSymbols) throws QueryMetadataException,
                                                                   QueryResolverException,
                                                                   MetaMatrixComponentException {
         Query query = new Query();
@@ -2349,20 +2327,31 @@
         from.addClause(new UnaryFromClause(inlineGroup)); 
         TempMetadataStore store = new TempMetadataStore();
         TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
-        Query firstProject = nested.getProjectedQuery(); 
-        makeSelectUnique(firstProject.getSelect(), false);
-        
+        if (nested instanceof QueryCommand) {
+	        Query firstProject = ((QueryCommand)nested).getProjectedQuery(); 
+	        makeSelectUnique(firstProject.getSelect(), false);
+        }
         store.addTempGroup(inlineGroup.getName(), nested.getProjectedSymbols());
         inlineGroup.setMetadataID(store.getTempGroupID(inlineGroup.getName()));
         
-        List actualTypes = new ArrayList(nested.getProjectedSymbols().size());
-        
-        for (Iterator i = actualSymbols.iterator(); i.hasNext();) {
-            SingleElementSymbol ses = (SingleElementSymbol)i.next();
+        List<Class<?>> actualTypes = new ArrayList<Class<?>>(nested.getProjectedSymbols().size());
+        for (SingleElementSymbol ses : actualSymbols) {
             actualTypes.add(ses.getType());
         }
-        List selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.resolveElementsInGroup(inlineGroup, tma), actualTypes);
-        select.addSymbols(deepClone(selectSymbols, SingleElementSymbol.class));
+        List<SingleElementSymbol> selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.resolveElementsInGroup(inlineGroup, tma), actualTypes);
+        Iterator<SingleElementSymbol> iter = actualSymbols.iterator();
+        for (SingleElementSymbol ses : selectSymbols) {
+        	ses = (SingleElementSymbol)ses.clone();
+        	SingleElementSymbol actual = iter.next();
+        	if (!ses.getShortCanonicalName().equals(actual.getShortCanonicalName())) {
+	        	if (ses instanceof AliasSymbol) {
+	        		((AliasSymbol)ses).setName(actual.getShortName());
+	        	} else {
+	        		ses = new AliasSymbol(actual.getShortName(), ses);
+	        	}
+        	}
+			select.addSymbol(ses);
+		}
         query.setFrom(from); 
         QueryResolver.resolveCommand(query, tma);
         query.setOption(nested.getOption());

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -152,7 +152,7 @@
      * is not safe to manipulate (see @link#CommandContainer insead) 
      * @return
      */
-    public List getSubCommands() {
+    public List<Command> getSubCommands() {
         return CommandCollectorVisitor.getCommands(this);
     }
     

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/CommandCollectorVisitor.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -32,6 +32,7 @@
 import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.ExistsCriteria;
+import com.metamatrix.query.sql.lang.Insert;
 import com.metamatrix.query.sql.lang.ProcedureContainer;
 import com.metamatrix.query.sql.lang.SetQuery;
 import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
@@ -201,7 +202,7 @@
     		modes.add(Mode.NON_EMBEDDED);
     	}
         CommandCollectorVisitor visitor = new CommandCollectorVisitor(modes);
-        final boolean visitCommands = command instanceof SetQuery;
+        final boolean visitCommands = command instanceof SetQuery || command instanceof Insert;
         PreOrderNavigator navigator = new PreOrderNavigator(visitor) {
 
         	@Override

Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -663,6 +663,9 @@
             if(isXMLCommand(subQuery)) {
                 handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0034), query);
             }
+            if (subQuery instanceof Query && ((Query)subQuery).getInto() != null) {
+            	handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.union_insert"), query); //$NON-NLS-1$
+            }
         }
         
         if (!query.isAll() || query.getOperation() == Operation.EXCEPT || query.getOperation() == Operation.INTERSECT) {

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -614,7 +614,7 @@
         	copy.pushCall(recursionGroup);
         }
         
-        QueryRewriter.rewrite(newCommand, null, metadata, copy);
+        newCommand = QueryRewriter.rewrite(newCommand, null, metadata, copy);
         ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, capabilitiesFinder, analysisRecord, copy);
         return new QueryProcessor(plan, copy, bufferManager, processorDataManager);
 	}

Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties	2009-09-23 18:22:50 UTC (rev 1466)
@@ -282,6 +282,7 @@
 ValidationVisitor.limit_not_valid_for_xml=The limit clause cannot be used on an XML document query.
 ValidationVisitor.translated_or=Translated user criteria must not contain OR criteria
 ValidateCriteriaVistitor.element_not_comparable = The following data elements are not supported in comparison criteria: {0}.
+ValidationVisitor.union_insert = Select into is not allowed under a set operation: {0}.
 ERR.015.012.0028 = The following data elements are not supported in match criteria: {0}.
 ERR.015.012.0029 = INSERT, UPDATE, and DELETE not allowed on XML documents
 ERR.015.012.0030 = Commands used in stored procedure language not allowed on XML documents

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -71,7 +71,7 @@
                                                                  QueryMetadataException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 
-        QueryParser parser = new QueryParser();
+        QueryParser parser = QueryParser.getQueryParser();
         Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
         QueryResolver.resolveCommand(userCommand, metadata);
 		ValidatorReport report = Validator.validate(userCommand, metadata);
@@ -80,7 +80,7 @@
             ValidatorFailure firstFailure = (ValidatorFailure) report.getItems().iterator().next();
             throw new QueryValidatorException(firstFailure.getMessage());
         }
-        QueryRewriter.rewrite(userCommand, null, metadata, null);
+        userCommand = QueryRewriter.rewrite(userCommand, null, metadata, null);
         
         AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
         

Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -45,7 +45,7 @@
                           boolean aliasGroups,
                           QueryMetadataInterface metadata) throws QueryValidatorException {
         Command command = TestResolver.helpResolve(sql, metadata, null);
-        QueryRewriter.rewrite(command, null, metadata, null);
+        command = QueryRewriter.rewrite(command, null, metadata, null);
         command.acceptVisitor(new AliasGenerator(aliasGroups));
         assertEquals(expected, command.toString());
         return command;

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -142,58 +142,39 @@
     
     static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) {
 		if(DEBUG) System.out.println("\n####################################\n" + command); //$NON-NLS-1$
-
-		// resolve
+		AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
 		try {
 			QueryResolver.resolveCommand(command, metadata);
-		} catch(Throwable e) {
-            throw new MetaMatrixRuntimeException(e);
-		}
         
-        ValidatorReport repo = null;
-        try {
-            repo = Validator.validate(command, metadata);
-        } catch (MetaMatrixComponentException e) {
-            throw new MetaMatrixRuntimeException(e);
-        }
-        Collection failures = new ArrayList();
-        repo.collectInvalidObjects(failures);
-        if (failures.size() > 0){
-            fail("Exception during validation (" + repo); //$NON-NLS-1$
-        }        
-
-		// rewrite
-		try {
+			ValidatorReport repo  = Validator.validate(command, metadata);
+	        Collection failures = new ArrayList();
+	        repo.collectInvalidObjects(failures);
+	        if (failures.size() > 0){
+	            fail("Exception during validation (" + repo); //$NON-NLS-1$
+	        }        
 			command = QueryRewriter.rewrite(command, null, metadata, createCommandContext());
-		} catch(Throwable e) {
-            throw new MetaMatrixRuntimeException(e);
-		}
+	        ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
+			if(DEBUG) System.out.println("\n" + process); //$NON-NLS-1$
+	        //per defect 10022, clone this plan before processing, just to make sure
+	        //a cloned plan with correlated subquery references (or any cloned plan) can be processed
+	        ProcessorPlan cloned = (ProcessorPlan)process.clone();
+	        process = cloned;
+	        
+	        assertNotNull("Output elements of process plan are null", process.getOutputElements()); //$NON-NLS-1$
 
-//		// plan
-		ProcessorPlan process = null;
-        AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
-		try {
-			process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
-		} catch(Throwable e) {
-            throw new MetaMatrixRuntimeException(e);
+	        // verify we can get child plans for any plan with no problem
+	        process.getChildPlans();
+	        
+			return process;
+        } catch (MetaMatrixComponentException e) {
+            throw new RuntimeException(e);
+		} catch (MetaMatrixProcessingException e) {
+			throw new RuntimeException(e);
 		} finally {
             if(DEBUG) {
                 System.out.println(analysisRecord.getDebugLog());
             }
         }
-		if(DEBUG) System.out.println("\n" + process); //$NON-NLS-1$
-
-        //per defect 10022, clone this plan before processing, just to make sure
-        //a cloned plan with correlated subquery references (or any cloned plan) can be processed
-        ProcessorPlan cloned = (ProcessorPlan)process.clone();
-        process = cloned;
-        
-        assertNotNull("Output elements of process plan are null", process.getOutputElements()); //$NON-NLS-1$
-
-        // verify we can get child plans for any plan with no problem
-        process.getChildPlans();
-        
-		return process;
 	}
 
     public static void helpProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults) {    

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -26,7 +26,6 @@
 import java.util.List;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -52,11 +51,10 @@
 		dataManager = new TempTableDataManager(fdm, tempStore);
 	}
 
-	@Ignore("need to correct select into query formation")
 	@Test public void testInsertWithQueryExpression() throws Exception {
 		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
 		execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
 	}
 	
 	@Test public void testOutofOrderInsert() throws Exception {

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/SimpleQueryProcessorFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/SimpleQueryProcessorFactory.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/SimpleQueryProcessorFactory.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -63,7 +63,7 @@
 			throws MetaMatrixProcessingException, MetaMatrixComponentException {
 		Command command = QueryParser.getQueryParser().parseCommand(sql);
 		QueryResolver.resolveCommand(command, metadata);
-		QueryRewriter.rewrite(command, null, metadata, commandContext);
+		command = QueryRewriter.rewrite(command, null, metadata, commandContext);
 		ProcessorPlan plan = QueryOptimizer.optimizePlan(command, metadata,
 				idGenerator, finder, AnalysisRecord.createNonRecordingRecord(),
 				commandContext);

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -1603,7 +1603,7 @@
         helpTestProcessFailure(false, plan, dataMgr, "Couldn't execute the dynamic SQL command \"EXECUTE STRING 'EXEC pm1.sq1(''First'')' AS e1 string, e2 integer\" with the SQL statement \"'EXEC pm1.sq1(''First'')'\" due to: The dynamic sql string contains an incorrect number of elements."); //$NON-NLS-1$
      }
     
-    @Test public void testDynamicCommandIncorrectProjectSymbolNames() throws Exception {
+    @Test public void testDynamicCommandPositional() throws Exception {
     	//Tests dynamic query with incorrect number of elements   
         FakeMetadataFacade metadata = FakeMetadataFactory.example1();
         
@@ -1625,7 +1625,9 @@
 
         ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
     	
-        helpTestProcessFailure(false, plan, dataMgr, "Couldn't execute the dynamic SQL command \"EXECUTE STRING 'select e1 as x, e2 from pm1.g1'\" with the SQL statement \"'select e1 as x, e2 from pm1.g1'\" due to: No match found for expected symbol 'E1' in the dynamic SQL."); //$NON-NLS-1$
+        helpTestProcess(plan, new List[] {Arrays.asList("First", "5"), //$NON-NLS-1$ //$NON-NLS-2$
+        		Arrays.asList("Second", "15"), //$NON-NLS-1$ //$NON-NLS-2$
+        		Arrays.asList("Third", "51")}, dataMgr); //$NON-NLS-1$ //$NON-NLS-2$
      }
     
     @Test public void testDynamicCommandIncorrectProjectSymbolDatatypes() throws Exception {

Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -55,9 +55,7 @@
         
         QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
         
-        QueryRewriter.rewrite(command, null, FakeMetadataFactory.example1Cached(), null);
-        
-        return command;
+        return QueryRewriter.rewrite(command, null, FakeMetadataFactory.example1Cached(), null);
     }
 
     private void helpCheckElements(OrderBy langObj,

Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -1945,7 +1945,7 @@
     
     @Test public void testRewriteSelectInto() {
         String sql = "select distinct pm1.g1.e1 into #temp from pm1.g1"; //$NON-NLS-1$
-        String expected = "SELECT DISTINCT pm1.g1.e1 INTO #temp FROM pm1.g1"; //$NON-NLS-1$
+        String expected = "INSERT INTO #temp (#TEMP.E1) SELECT DISTINCT pm1.g1.e1 FROM pm1.g1"; //$NON-NLS-1$
                 
         helpTestRewriteCommand(sql, expected);        
     }
@@ -1955,7 +1955,7 @@
      */
     @Test public void testRewriteSelectInto1() {
         String sql = "select distinct e2, e2, e3, e4 into pm1.g1 from pm1.g2"; //$NON-NLS-1$
-        String expected = "SELECT PM1_G1_1.E2 AS E2, PM1_G1_1.E2_0, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT DISTINCT e2, e2 AS E2_0, e3, e4 FROM pm1.g2) AS pm1_g1_1"; //$NON-NLS-1$
+        String expected = "INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4) SELECT PM1_G1_1.E2 AS e1, PM1_G1_1.E2_0 AS e2, PM1_G1_1.E3, PM1_G1_1.E4 FROM (SELECT DISTINCT e2, e2 AS E2_0, e3, e4 FROM pm1.g2) AS pm1_g1_1"; //$NON-NLS-1$
                 
         helpTestRewriteCommand(sql, expected);        
     }
@@ -2020,16 +2020,9 @@
         procedure += "Select x from temp;\n"; //$NON-NLS-1$
         procedure += "END\n"; //$NON-NLS-1$
         
-        helpTestRewriteCommand(procedure, "CREATE VIRTUAL PROCEDURE\nBEGIN\nCREATE LOCAL TEMPORARY TABLE temp (x string, y integer, z integer);\nSELECT TEMP_1.E2 AS E2, TEMP_1.X, TEMP_1.X_0 INTO temp FROM (SELECT pm1.g1.e2, 1 AS x, 2 AS X_0 FROM pm1.g1 ORDER BY pm1.g1.e2 LIMIT 1) AS temp_1;\nSELECT x FROM temp;\nEND"); //$NON-NLS-1$
+        helpTestRewriteCommand(procedure, "CREATE VIRTUAL PROCEDURE\nBEGIN\nCREATE LOCAL TEMPORARY TABLE temp (x string, y integer, z integer);\nINSERT INTO temp (TEMP.X, TEMP.Y, TEMP.Z) SELECT TEMP_1.E2 AS X, TEMP_1.X AS Y, TEMP_1.X_0 AS Z FROM (SELECT pm1.g1.e2, 1 AS x, 2 AS X_0 FROM pm1.g1 ORDER BY pm1.g1.e2 LIMIT 1) AS temp_1;\nSELECT x FROM temp;\nEND"); //$NON-NLS-1$
     }
     
-    
-    @Test public void testInsertWithQuery() throws Exception {
-        String sql = "insert into pm1.g1 select e1, e2, e3, e4 from pm1.g2 union select e1, e2, e3, e4 from pm1.g2"; //$NON-NLS-1$
-        
-        helpTestRewriteCommand(sql, "SELECT PM1_G1_1.E1, PM1_G1_1.E2, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT e1, e2, e3, e4 FROM pm1.g2 UNION SELECT e1, e2, e3, e4 FROM pm1.g2) AS pm1_g1_1"); //$NON-NLS-1$
-    }
-    
     @Test public void testRewriteNot() {
         helpTestRewriteCriteria("not(not(pm1.g1.e1 = 1 + 1))", "pm1.g1.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
     }

Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -48,8 +48,6 @@
 import com.metamatrix.query.mapping.xml.MappingElement;
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.metadata.StoredProcedureInfo;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
-import com.metamatrix.query.metadata.TempMetadataStore;
 import com.metamatrix.query.parser.QueryParser;
 import com.metamatrix.query.resolver.QueryResolver;
 import com.metamatrix.query.sql.LanguageObject;
@@ -583,6 +581,10 @@
         helpValidate("SELECT e3 FROM pm1.g1 intersect all SELECT e3 FROM pm1.g1", new String[] {"SELECT e3 FROM pm1.g1 INTERSECT ALL SELECT e3 FROM pm1.g1"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
+    public void testValidateSetSelectInto() {
+        helpValidate("SELECT e3 into #temp FROM pm1.g1 intersect all SELECT e3 FROM pm1.g1", new String[] {"SELECT e3 INTO #temp FROM pm1.g1 INTERSECT ALL SELECT e3 FROM pm1.g1"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
     public void testInsert1() {
         helpValidate("INSERT INTO test.group (e0) VALUES (null)", new String[] {"e0"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
     }    

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2009-09-23 15:39:01 UTC (rev 1465)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2009-09-23 18:22:50 UTC (rev 1466)
@@ -112,7 +112,7 @@
         Command command = TestResolver.helpResolve(userSql, wrapper, analysis);               
                 
         // Plan
-        QueryRewriter.rewrite(command, null, wrapper, null);
+        command = QueryRewriter.rewrite(command, null, wrapper, null);
         FakeCapabilitiesFinder fakeFinder = new FakeCapabilitiesFinder();
         fakeFinder.addCapabilities(multiModel, TestOptimizer.getTypicalCapabilities()); 
 



More information about the teiid-commits mailing list