[teiid-commits] teiid SVN: r927 - in trunk/engine/src: main/java/com/metamatrix/query/sql/lang and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed May 13 00:28:32 EDT 2009


Author: shawkins
Date: 2009-05-13 00:28:31 -0400 (Wed, 13 May 2009)
New Revision: 927

Modified:
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
   trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStore.java
   trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
   trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
   trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java
Log:
TEIID-585 fixes for temp table issue with prepared statements and query cloning

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -25,7 +25,6 @@
 package com.metamatrix.query.processor.relational;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -40,7 +39,6 @@
 import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
 
 public class ProjectIntoNode extends RelationalNode {
 
@@ -115,7 +113,7 @@
                 currentBatch = getChildren()[0].nextBatch(); // can throw BlockedException
                 this.batchRow = currentBatch.getBeginRow();
                 
-                if(currentBatch.getRowCount() == 0) {
+                if(currentBatch.getRowCount() == 0 && !this.intoGroup.isImplicitTempGroupSymbol()) {
                     continue;
                 }
             } else if (currentBatch.getTerminationFlag() && this.batchRow > currentBatch.getEndRow()) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -34,6 +34,7 @@
 import com.metamatrix.query.metadata.QueryMetadataInterface;
 import com.metamatrix.query.sql.LanguageVisitor;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.symbol.SelectSymbol;
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 /**
@@ -366,6 +367,10 @@
             }
         }
         
+        if (into != null) {
+        	copy.into = (Into)into.clone();
+        }
+        
         copyMetadataState(copy);
         
 		return copy;

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -89,7 +89,7 @@
     }
 
     public Class<?> getType() {
-    	if (this.isPositional()) {
+    	if (this.isPositional() && this.expression == null) {
     		return type;
     	}
     	return expression.getType();

Modified: trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStore.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStore.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -25,7 +25,7 @@
 import java.util.Set;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.TupleSource;
 import com.metamatrix.common.buffer.TupleSourceID;
 import com.metamatrix.query.metadata.TempMetadataStore;
@@ -36,15 +36,13 @@
  */
 public interface TempTableStore {
     
-    void addTempTable(Command command, boolean removeExistingTable) throws MetaMatrixComponentException;
-    
     void removeTempTable(Command command) throws MetaMatrixComponentException;
 
     void removeTempTables() throws MetaMatrixComponentException;
   
     TempMetadataStore getMetadataStore();
 
-    public TupleSource registerRequest(Command command)  throws MetaMatrixComponentException, ExpressionEvaluationException;
+    public TupleSource registerRequest(Command command)  throws MetaMatrixComponentException, MetaMatrixProcessingException;
     
     public boolean hasTempTable(Command command);
     

Modified: trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -33,6 +33,7 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryProcessingException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.TupleBatch;
@@ -74,47 +75,13 @@
         this.sessionID = sessionID;
         this.parentTempTableStore = parentTempTableStore;
     }
-    
-    public void addTempTable(Command command, boolean removeExistingTable) throws MetaMatrixComponentException{
-        String tempTableName = null;
-        List columns = null;
 
-        switch (command.getType()) {
-            case Command.TYPE_CREATE:
-                tempTableName = ((Create)command).getTable().getName().toUpperCase();
-                columns = ((Create)command).getColumns();
-                break;
-            case Command.TYPE_QUERY:
-                Query query = (Query)command;
-                if(query.getInto() != null) {
-                    tempTableName = query.getInto().getGroup().getName().toUpperCase();
-                    columns = query.getSelect().getSymbols();
-                    break;
-                }else if(((GroupSymbol)query.getFrom().getGroups().get(0)).isTempGroupSymbol()) {
-                    tempTableName = ((GroupSymbol)query.getFrom().getGroups().get(0)).getNonCorrelationName().toUpperCase();
-                    columns = query.getSelect().getSymbols();
-                    break;
-                }
-                return;
-            case Command.TYPE_INSERT:
-                Insert insert = (Insert)command;
-                GroupSymbol group = insert.getGroup();
-                if(group.isTempGroupSymbol()) {
-                    tempTableName = group.getNonCorrelationName().toUpperCase();
-                    columns = insert.getVariables();
-                    break; 
-                }
-                return;
-            default:
-                return;
-        }
-        
+    public void addTempTable(String tempTableName, List columns, boolean removeExistingTable) throws MetaMatrixComponentException, QueryProcessingException{        
         if(tempMetadataStore.getTempGroupID(tempTableName) != null) {
-            if(removeExistingTable) {
-                removeTempTableByName(tempTableName);
-            }else {
-                throw new MetaMatrixComponentException(QueryExecPlugin.Util.getString("TempTableStore.table_exist_error", tempTableName));//$NON-NLS-1$
+            if(!removeExistingTable) {
+                throw new QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_exist_error", tempTableName));//$NON-NLS-1$
             }
+            removeTempTableByName(tempTableName);
         }
         
         //add metadata
@@ -151,7 +118,7 @@
         return tempMetadataStore;
     }
         
-    public TupleSource registerRequest(Command command) throws MetaMatrixComponentException, ExpressionEvaluationException{
+    public TupleSource registerRequest(Command command) throws MetaMatrixComponentException, ExpressionEvaluationException, QueryProcessingException{
         if(!hasTempTable(command)) {
             return null;
         }
@@ -165,11 +132,16 @@
             {
                 Query query = (Query)command;
                 GroupSymbol group = (GroupSymbol)query.getFrom().getGroups().get(0);
-                return connectTupleSource(group.getNonCorrelationName(), command);
+                TupleSourceID tsId = getTupleSourceID(group.getNonCorrelationName().toUpperCase(), command);
+                try {
+                    return buffer.getTupleSource(tsId);
+                }catch(TupleSourceNotFoundException e) {
+                    throw new MetaMatrixComponentException(e);
+                }
             }
             case Command.TYPE_CREATE:
             {
-                addTempTable(command, false);
+                addTempTable(((Create)command).getTable().getName().toUpperCase(), ((Create)command).getColumns(), false);
                 return new UpdateCountTupleSource(0);
             }
             case Command.TYPE_DROP:
@@ -190,18 +162,9 @@
         }
     }
     
-    private TupleSource connectTupleSource(String tableName, Command command) throws MetaMatrixComponentException{
-        TupleSourceID tsId = getTupleSourceID(tableName, command);
-        try {
-            return buffer.getTupleSource(tsId);
-        }catch(TupleSourceNotFoundException e) {
-            throw new MetaMatrixComponentException(e);
-        }
-    }
-    
-    private TupleSourceID getTupleSourceID(String tempTableID, Command command) throws MetaMatrixComponentException{
+    private TupleSourceID getTupleSourceID(String tempTableID, Command command) throws MetaMatrixComponentException, QueryProcessingException{
        
-        TupleSourceID tsID = (TupleSourceID)groupToTupleSourceID.get(tempTableID.toUpperCase());
+        TupleSourceID tsID = (TupleSourceID)groupToTupleSourceID.get(tempTableID);
         if(tsID != null) {
             return tsID;
         }
@@ -211,14 +174,33 @@
     	        return tsID;
     	    }
         }
-        addTempTable(command, true);       
-        return (TupleSourceID)groupToTupleSourceID.get(tempTableID.toUpperCase());
+        //allow implicit temp group definition
+        List columns = null;
+        switch (command.getType()) {
+        case Command.TYPE_QUERY:
+            Query query = (Query)command;
+            if(query.getInto() != null && query.getInto().getGroup().isImplicitTempGroupSymbol()) {
+                columns = query.getSelect().getSymbols();
+            }
+            break;
+        case Command.TYPE_INSERT:
+            Insert insert = (Insert)command;
+            GroupSymbol group = insert.getGroup();
+            if(group.isImplicitTempGroupSymbol()) {
+                columns = insert.getVariables();
+            }
+            break;
+        }
+        if (columns == null) {
+        	throw new QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_doesnt_exist_error", tempTableID)); //$NON-NLS-1$
+        }
+        addTempTable(tempTableID, columns, true);       
+        return (TupleSourceID)groupToTupleSourceID.get(tempTableID);
     }
     
-    
-    private TupleSource addTuple(Insert insert) throws MetaMatrixComponentException, ExpressionEvaluationException {
+    private TupleSource addTuple(Insert insert) throws MetaMatrixComponentException, ExpressionEvaluationException, QueryProcessingException {
         GroupSymbol group = insert.getGroup();
-        TupleSourceID tsId = getTupleSourceID(group.getNonCorrelationName(), insert);
+        TupleSourceID tsId = getTupleSourceID(group.getNonCorrelationName().toUpperCase(), insert);
         int tuplesAdded = 0;
         try {
             int rowCount = buffer.getRowCount(tsId);

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-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -216,10 +216,7 @@
         metadata = metadataService.lookupMetadata(vdbName, vdbVersion);            
 
         if (metadata == null) {
-            Object[] params = new Object[] { this.vdbName, this.vdbVersion };
-            String msg = DQPPlugin.Util.getString("DQPCore.Unable_to_load_metadata_for_VDB_name__{0},_version__{1}", params); //$NON-NLS-1$
-            MetaMatrixComponentException e = new MetaMatrixComponentException(msg);
-            throw e;
+            throw new MetaMatrixComponentException(DQPPlugin.Util.getString("DQPCore.Unable_to_load_metadata_for_VDB_name__{0},_version__{1}", this.vdbName, this.vdbVersion)); //$NON-NLS-1$
         }
         
         this.metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());

Modified: trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/main/resources/com/metamatrix/query/execution/i18n.properties	2009-05-13 04:28:31 UTC (rev 927)
@@ -184,6 +184,7 @@
 
 RulePlanJoins.cantSatisfy=Join region with unsatisfied access patterns cannot be satisfied by the join criteria, Access patterns: {0} 
 TempTableStore.table_exist_error=Temporary table "{0}" already exists.
+TempTableStore.table_doesnt_exist_error=Temporary table "{0}" does not exist.
 
 XMLQueryPlanner.cannot_plan=Cannot create a query for MappingClass with user criteria {0}
 XMLQueryPlanner.staging_table_has_input_set=Staging table ''{0}'' is not allowed to have an input set.

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-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -2009,7 +2009,7 @@
         procedure.append("select e1 into t1 from pm1.g1;\n"); //$NON-NLS-1$
         procedure.append("drop table t1;\n"); //$NON-NLS-1$
         procedure.append("drop table t1;\n"); //$NON-NLS-1$
-        procedure.append("SELECT e1 from t1;\n"); //$NON-NLS-1$
+        procedure.append("SELECT 1;\n"); //$NON-NLS-1$
         procedure.append("END"); //$NON-NLS-1$
         
         QueryNode sq2n1 = new QueryNode("pm1.sq1", procedure.toString()); //$NON-NLS-1$ 
@@ -2024,7 +2024,7 @@
 
         ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
         
-        helpTestProcess(plan, new List[] {}, dataMgr); 
+        helpTestProcess(plan, new List[] {Arrays.asList(1)}, dataMgr); 
     }
     
     /**

Modified: trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java	2009-05-13 04:18:28 UTC (rev 926)
+++ trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java	2009-05-13 04:28:31 UTC (rev 927)
@@ -155,4 +155,11 @@
         UnitTestUtil.helpTestEquivalence(equals, q, qclone);
         assertEquals(projectedSymbols, qclone.getProjectedSymbols());
     }  
+    
+    public void testClone3() {
+    	Query q = sample2();
+        q.setInto(new Into(new GroupSymbol("#foo"))); //$NON-NLS-1$
+        Query qclone = (Query)q.clone();
+        assertNotNull(qclone.getInto());
+    }
 }




More information about the teiid-commits mailing list