[teiid-commits] teiid SVN: r642 - in trunk/engine/src: main/java/com/metamatrix/query/processor/relational and 5 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Wed Mar 25 08:20:12 EDT 2009


Author: shawkins
Date: 2009-03-25 08:20:12 -0400 (Wed, 25 Mar 2009)
New Revision: 642

Modified:
   trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
   trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java
Log:
TEIID-438 TEIID-119 fixing procedure relational physical dependent projection of input parameters and select node empty batch handling

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/TupleSource.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -26,6 +26,7 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 
 /**
  * <p>A cursored source of tuples.  The implementation will likely be closely
@@ -38,7 +39,7 @@
      * Returns the List of ElementSymbol describing the Tuple Source
      * @return the List of elements describing the Tuple Source
      */
-	List getSchema();
+	List<SingleElementSymbol> getSchema();
 	
     /**
      * Returns the next tuple
@@ -48,7 +49,7 @@
      * exception such as a communication exception, or other such
      * nondeterministic exception
      */
-	List nextTuple()
+	List<?> nextTuple()
 		throws MetaMatrixComponentException, MetaMatrixProcessingException;
 	
     /**

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -47,7 +47,6 @@
 
     // Processing state
 	private TupleSource tupleSource;
-	private boolean needProcessing = true;
 	private boolean isUpdate = false;
     private boolean returnedRows = false;
     
@@ -58,7 +57,6 @@
     public void reset() {
         super.reset();
         tupleSource = null;
-		needProcessing = true;
 		isUpdate = false;
         returnedRows = false;
     }
@@ -88,7 +86,7 @@
 
         // Copy command and resolve references if necessary
         Command atomicCommand = command;
-        needProcessing = true;
+        boolean needProcessing = true;
         if(shouldEvaluate) {
             atomicCommand = (Command) command.clone();
             needProcessing = prepareNextCommand(atomicCommand);
@@ -123,54 +121,51 @@
 	public TupleBatch nextBatchDirect()
 		throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
         
-        boolean batchDone = false;
-
-        while (!batchDone) {
-            while (!needProcessing && hasNextCommand()) {
-                Command atomicCommand = (Command)command.clone();
-                needProcessing = prepareNextCommand(atomicCommand);
-                if (needProcessing) {
-                	closeSources();
-                    tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), atomicCommand, modelName, null, getID());
-                }
-            }
-            
-    		if(!needProcessing && !hasNextCommand()) {
-                if(isUpdate && !returnedRows) {
-        			List tuple = new ArrayList(1);
-        			tuple.add(new Integer(0));
-                    // Add tuple to current batch
-                    addBatchRow(tuple);
-                }
-                terminateBatches();
-                return pullBatch();
-    		}
+        while (tupleSource != null || hasNextCommand()) {
+        	//drain the tuple source
+        	while (tupleSource != null) {
+                List<?> tuple = tupleSource.nextTuple();
     
-            //needProcessing must be true after this point
-            
-            // Pull a batch worth of tuples
-            while(!batchDone) {
-        		// Read a tuple
-                List tuple = tupleSource.nextTuple();
-    
-                // Check for termination tuple
                 if(tuple == null) {
                     closeSources();
-                    needProcessing = false;
                     break;
                 } 
                 
                 returnedRows = true;
                 
-                // Add tuple to current batch
                 addBatchRow(tuple);
-                // Check for full batch
-                batchDone = isBatchFull();
-            }
+                
+                if (isBatchFull()) {
+                	return pullBatch();
+                }
+        	}
+        	
+        	//execute another command
+            while (hasNextCommand()) {
+            	if (processCommandsIndividually() && hasPendingRows()) {
+            		return pullBatch();
+            	}
+                Command atomicCommand = (Command)command.clone();
+                if (prepareNextCommand(atomicCommand)) {
+                    tupleSource = getDataManager().registerRequest(this.getContext().getProcessorID(), atomicCommand, modelName, null, getID());
+                    break;
+                }
+            }            
         }
-
+        
+        if(isUpdate && !returnedRows) {
+			List tuple = new ArrayList(1);
+			tuple.add(new Integer(0));
+            // Add tuple to current batch
+            addBatchRow(tuple);
+        }
+        terminateBatches();
         return pullBatch();
 	}
+	
+	protected boolean processCommandsIndividually() {
+		return false;
+	}
     
     protected boolean hasNextCommand() {
         return false;

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -99,6 +99,11 @@
         
         return criteriaProcessor.prepareNextCommand();
     }
+    
+    @Override
+    protected boolean processCommandsIndividually() {
+    	return true;
+    }
 
     /**
      * @see com.metamatrix.query.processor.relational.PlanExecutionNode#hasNextCommand()

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -187,8 +187,12 @@
     }
 
     protected boolean isBatchFull() {
-        return (this.batchRows != null) && (this.batchRows.size() == this.batchSize);
+        return (this.batchRows != null) && (this.batchRows.size() >= this.batchSize);
     }
+    
+    protected boolean hasPendingRows() {
+    	return this.batchRows != null;
+    }
 
     protected TupleBatch pullBatch() {
         TupleBatch batch = null;

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -91,10 +91,6 @@
             batch = this.getChildren()[0].nextBatch();
         }
                 
-        if(batch.getRowCount() == 0) {
-            return batch;    
-            
-        }   
         boolean doPrepareToProcessTuple = !blockedOnCriteria;             
         int row = blockedRow;
         if(! blockedOnCriteria && ! blockedOnPrepare) {

Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -523,7 +523,7 @@
                     StoredProcedureInfo storedProcedureInfo = metadata.getStoredProcedureInfoForProcedure(fullName);
 
                     StoredProcedure storedProcedureCommand = new StoredProcedure();
-                    
+                    storedProcedureCommand.setProcedureRelational(true);
                     storedProcedureCommand.setProcedureName(fullName);
                     
                     List metadataParams = storedProcedureInfo.getParameters();

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -74,6 +74,8 @@
     
     private boolean isCallableStatement;
     
+    private boolean isProcedureRelational;
+    
     /**
      * Constructs a default instance of this class.
      */
@@ -163,13 +165,13 @@
     * Returns a List of SPParameter objects for this stored procedure
     *
     */
-    public List getParameters(){
-        List listOfParameters = new ArrayList(mapOfParameters.values());
+    public List<SPParameter> getParameters(){
+        List<SPParameter> listOfParameters = new ArrayList<SPParameter>(mapOfParameters.values());
         return listOfParameters;
     }
 
     public SPParameter getParameter(int index){
-        return (SPParameter)mapOfParameters.get(new Integer(index));
+        return mapOfParameters.get(new Integer(index));
     }
 
     public int getNumberOfColumns(){
@@ -232,6 +234,7 @@
         
         copy.displayNamedParameters = displayNamedParameters;
         copy.isCallableStatement = isCallableStatement;
+        copy.isProcedureRelational = isProcedureRelational;
         return copy;
     }
 
@@ -373,11 +376,11 @@
         return paramName;
     }
     
-    public List getInputParameters() {
-    	List parameters = getParameters();
-    	Iterator params = parameters.iterator();
+    public List<SPParameter> getInputParameters() {
+    	List<SPParameter> parameters = getParameters();
+    	Iterator<SPParameter> params = parameters.iterator();
     	while (params.hasNext()) {
-    		SPParameter param = (SPParameter)params.next();
+    		SPParameter param = params.next();
     		if(param.getParameterType() != ParameterInfo.IN && param.getParameterType() != ParameterInfo.INOUT) {
     			params.remove();
     		}
@@ -386,26 +389,12 @@
     }
     
     public boolean isProcedureRelational() {
-        List inputs = getInputParameters();
-        if (inputs.size() == 0) {
-            return false;
-        }
-        
-        for (Iterator params = inputs.iterator(); params.hasNext();) {
-            SPParameter param = (SPParameter)params.next();
-            ElementSymbol symbol = param.getParameterSymbol();
-            Expression input = param.getExpression();
-            if (!(input instanceof Reference)) {
-                return false;
-            }
-            Reference reference = (Reference)input;
-            if (!symbol.equals(reference.getExpression())) {
-                return false;
-            }
-        }
-        
-        return true;
-    }
+		return isProcedureRelational;
+	}
+    
+    public void setProcedureRelational(boolean isProcedureRelational) {
+		this.isProcedureRelational = isProcedureRelational;
+	}
 
 	public boolean isCallableStatement() {
 		return isCallableStatement;

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -25,9 +25,12 @@
 import java.util.Arrays;
 import java.util.List;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.QueryValidatorException;
+import com.metamatrix.common.buffer.TupleSource;
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.dqp.message.ParameterInfo;
 import com.metamatrix.query.mapping.relational.QueryNode;
@@ -36,14 +39,17 @@
 import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
 import com.metamatrix.query.processor.relational.RelationalNode;
 import com.metamatrix.query.processor.relational.RelationalPlan;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.SPParameter;
+import com.metamatrix.query.sql.lang.StoredProcedure;
 import com.metamatrix.query.unittest.FakeMetadataFacade;
 import com.metamatrix.query.unittest.FakeMetadataFactory;
 import com.metamatrix.query.unittest.FakeMetadataObject;
 import com.metamatrix.query.unittest.FakeMetadataStore;
 
-public class TestProcedureRelational extends TestCase {
+public class TestProcedureRelational {
 
-    public void testProcInExistsSubquery() throws Exception {
+    @Test public void testProcInExistsSubquery() throws Exception {
         String sql = "select pm1.g1.e1 from pm1.g1 where exists (select * from (EXEC pm1.vsp9(pm1.g1.e2 + 1)) x where x.e1 = pm1.g1.e1)"; //$NON-NLS-1$
 
         List[] expected = new List[] { 
@@ -59,7 +65,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected);
     }
     
-    public void testProcInSelectScalarSubquery() throws Exception {
+    @Test public void testProcInSelectScalarSubquery() throws Exception {
         String sql = "select (EXEC pm1.vsp36(pm1.g1.e2)) from pm1.g1 where pm1.g1.e1 = 'a'"; //$NON-NLS-1$
 
         List[] expected = new List[] { 
@@ -76,7 +82,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected);
     }
     
-    public void testProcAsTable(){
+    @Test public void testProcAsTable(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -93,7 +99,7 @@
     }
     
     //virtual group with procedure in transformation
-    public void testAliasedProcAsTable(){
+    @Test public void testAliasedProcAsTable(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 as x where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -109,7 +115,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
 
-    public void testAliasedJoin(){
+    @Test public void testAliasedJoin(){
         String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = 2 and y.param2 = 'b'"; //$NON-NLS-1$
 
         // Create expected results
@@ -126,7 +132,7 @@
     }
 
     
-    public void testAliasedJoin1(){
+    @Test public void testAliasedJoin1(){
         String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = x.param1 and y.param2 = x.param2"; //$NON-NLS-1$
 
         // Create expected results
@@ -145,7 +151,7 @@
     /**
      * Will fail due to access pattern validation (missing param2 assignment) 
      */
-    public void testProcAsTable1(){
+    @Test public void testProcAsTable1(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1"; //$NON-NLS-1$
 
         TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
@@ -154,13 +160,13 @@
     /**
      * Will fail since less than does not constitue an input 
      */
-    public void testProcAsTable2(){
+    @Test public void testProcAsTable2(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1<1 and param2='a'"; //$NON-NLS-1$
 
         TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false); 
     }
     
-    public void testProcAsTable3(){
+    @Test public void testProcAsTable3(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1 in (1,2,3) and param2 in ('a', 'b')"; //$NON-NLS-1$
 
         // Create expected results
@@ -183,13 +189,13 @@
     /**
      * Will fail missing param2 assignment 
      */
-    public void testProcAsTable4(){
+    @Test public void testProcAsTable4(){
         String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and not(param2 = 'a')"; //$NON-NLS-1$
 
         TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
     }
     
-    public void testProcAsTableInJoin(){
+    @Test public void testProcAsTableInJoin(){
         String sql = "select param1, param2, pm1.vsp26.e2 from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
 
         // Create expected results
@@ -213,7 +219,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsTableInSubquery(){
+    @Test public void testProcAsTableInSubquery(){
         String sql = "select param1, param2, pm1.vsp26.e2, (select count(e1) from pm1.vsp26 where param1 = 1 and param2 = 'a') x from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
 
         // Create expected results
@@ -269,7 +275,7 @@
     }
     
     //virtual group with procedure in transaformation
-    public void testProcInVirtualGroup1() {
+    @Test public void testProcInVirtualGroup1() {
         
         String userQuery = "select e1 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
         String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
@@ -279,7 +285,7 @@
     }
 
     //virtual group with procedure in transformation
-    public void testCase3403() {        
+    @Test public void testCase3403() {        
         String userQuery = "select e1 from pm1.vsp26 where param1=2 and param2='a' and 'x'='x'"; //$NON-NLS-1$
         String inputCriteria = "(pm1.vsp26.param1 = 2) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
         String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
@@ -287,7 +293,7 @@
         helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
     }
     
-    public void testCase3448() {
+    @Test public void testCase3448() {
         String userQuery = "select e1 from pm1.vsp26 where (param1=1 and e2=2) and param2='a'"; //$NON-NLS-1$
         String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
         String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
@@ -295,7 +301,7 @@
         helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
     }
     
-    public void testProcAsVirtualGroup2(){
+    @Test public void testProcAsVirtualGroup2(){
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -311,7 +317,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup3(){
+    @Test public void testProcAsVirtualGroup3(){
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -327,7 +333,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup4(){
+    @Test public void testProcAsVirtualGroup4(){
         String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, pm1.g2 where P.e1=g2.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -345,7 +351,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup5(){
+    @Test public void testProcAsVirtualGroup5(){
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a' and e1='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -361,7 +367,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup6(){
+    @Test public void testProcAsVirtualGroup6(){
         String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -379,7 +385,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup7(){
+    @Test public void testProcAsVirtualGroup7(){
         String sql = "SELECT e1 FROM (SELECT p.e1, param1, param2 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1) x where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -397,7 +403,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected); 
     }
     
-    public void testProcAsVirtualGroup10_Defect20164(){
+    @Test public void testProcAsVirtualGroup10_Defect20164(){
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where (param1=1 and param2='a') and e1='c'"; //$NON-NLS-1$
 
         // Create expected results
@@ -411,7 +417,7 @@
         TestProcessor.helpProcess(plan, dataManager, expected);
     }
 
-    public void testProcAsVirtualGroup8(){
+    @Test public void testProcAsVirtualGroup8(){
         String sql = "SELECT P.e1 as ve3, P.e2 as ve4 FROM pm1.vsp26 as P where param1=1 and param2='a' and e2=3"; //$NON-NLS-1$
 
         // Create expected results
@@ -428,7 +434,7 @@
     }
 
     //virtual group with procedure in transformation
-    public void testProcAsVirtualGroup9(){
+    @Test public void testProcAsVirtualGroup9(){
         String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a'"; //$NON-NLS-1$
 
         // Create expected results
@@ -489,7 +495,7 @@
     /**
      *  test for defect 22376
      */
-    public void testParameterPassing() throws Exception {
+    @Test public void testParameterPassing() throws Exception {
         FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
         
         FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.rs1", v1, new String[] {"e1"}, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$ 
@@ -526,7 +532,7 @@
     }
 
     //virtual group with procedure in transformation
-    public void testCase6395ProcAsVirtualGroup9(){
+    @Test public void testCase6395ProcAsVirtualGroup9(){
         String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a' OPTION DEBUG"; //$NON-NLS-1$
 
         // Create expected results
@@ -546,7 +552,7 @@
      *  Case 6395 - This test case will now raise a QueryPlannerException.  param2 is required
      *  and not nullable.  This case is expected to fail because of 'param2 is null' 
      */
-    public void testProcAsVirtualGroup2WithNull() throws Exception {
+    @Test public void testProcAsVirtualGroup2WithNull() throws Exception {
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 is null"; //$NON-NLS-1$
 
         // Create expected results
@@ -570,7 +576,7 @@
      *  Case 6395 - This case is expected to succeed.  param1 and param2 are both required, but nulls 
      *  are acceptable for both.
      */
-    public void testProcAsVirtualGroup2WithNull2() throws Exception {
+    @Test public void testProcAsVirtualGroup2WithNull2() throws Exception {
         String sql = "select * from pm1.vsp47 where param1 is null and param2 is null"; //$NON-NLS-1$
 
         // Create expected results
@@ -589,7 +595,7 @@
     /**
      *  Case 6395 - This will not throw an exception and the proc will not be invoked.
      */
-    public void testProcAsVirtualGroup2WithNull3() throws Exception {
+    @Test public void testProcAsVirtualGroup2WithNull3() throws Exception {
         String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 = commandpayload()"; //$NON-NLS-1$
 
         // Create expected results
@@ -609,52 +615,118 @@
      * procedure input criteria is valid.  This can be addressed later more generally when we do up front validation of
      * access patterns and access patterns have a wider range of semantics.
      * 
-    public void testProcInVirtualGroupDefect14609_1() throws Exception{
+    @Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
         helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
     }
    
-    public void testProcInVirtualGroupDefect14609_2() throws Exception{
+    @Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
         helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
-    public void testProcInVirtualGroupDefect14609_3() throws Exception{
+    @Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
         helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
-    public void testProcInVirtualGroupDefect14609_4() throws Exception{
+    @Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
         helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
     }    
 
-    public void testDefect15861() throws Exception{
+    @Test public void testDefect15861() throws Exception{
         helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
 
-    public void testProcInVirtualGroup1_Defect20164() {
+    @Test public void testProcInVirtualGroup1_Defect20164() {
         helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup2_Defect20164() {
+    @Test public void testProcInVirtualGroup2_Defect20164() {
         helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup3_Defect20164() {
+    @Test public void testProcInVirtualGroup3_Defect20164() {
         helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup4_Defect20164() {
+    @Test public void testProcInVirtualGroup4_Defect20164() {
         helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup5_Defect20164() {
+    @Test public void testProcInVirtualGroup5_Defect20164() {
         helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup6_Defect20164() {
+    @Test public void testProcInVirtualGroup6_Defect20164() {
         helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }
 
-    public void testProcInVirtualGroup7_Defect20164() {
+    @Test public void testProcInVirtualGroup7_Defect20164() {
         helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
     }*/
     
+    /**
+     * Ensures that dependent procedures are processed 1 at a time so that projected input values
+     * are set correctly.
+     */
+    @Test public void testIssue119() throws Exception {
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        
+        FakeMetadataObject in = FakeMetadataFactory.createParameter("v1.vp1.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
+        FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.vp1.rs1", v1, new String[] {"e1", "e2", "e3", "e4", "e5"}, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ 
+        FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);  //$NON-NLS-1$
+
+        QueryNode n1 = new QueryNode("v1.vp1", "CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualProcedure("v1.vp1", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1, in }), n1); //$NON-NLS-1$
+        
+        FakeMetadataObject in1 = FakeMetadataFactory.createParameter("pm1.sp119.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
+		FakeMetadataObject rs3 = FakeMetadataFactory.createResultSet("pm1.sp119.rs1", pm1, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ 
+        FakeMetadataObject rs3p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs3);  //$NON-NLS-1$
+		FakeMetadataObject sp1 = FakeMetadataFactory.createStoredProcedure("pm1.sp119", pm1, Arrays.asList(new FakeMetadataObject[] { rs3p1, in1 }), "pm1.sp119");  //$NON-NLS-1$ //$NON-NLS-2$
+
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(v1);
+        store.addObject(rs1);
+        store.addObject(vt1);
+        store.addObject(sp1);
+        
+        String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5"; //$NON-NLS-1$
+        
+        List<?>[] expected = new List[] {
+        	Arrays.asList(1, 1, 3, 3, 5),	
+        	Arrays.asList(1, 1, 3, 3, 8),
+        	Arrays.asList(1, 1, 6, 6, 8),
+        	Arrays.asList(1, 1, 6, 6, 11),
+        };
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        // Construct data manager with data 
+        // Plan query 
+        ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);        
+        // Run query 
+        HardcodedDataManager dataManager = new HardcodedDataManager() {
+        	@Override
+        	public TupleSource registerRequest(Object processorID,
+        			Command command, String modelName,
+        			String connectorBindingId, int nodeID)
+        			throws MetaMatrixComponentException {
+        		if (command instanceof StoredProcedure) {
+        			StoredProcedure proc = (StoredProcedure)command;
+        			List<SPParameter> params = proc.getInputParameters();
+        			assertEquals(1, params.size());
+        			int value = (Integer)params.get(0).getValue();
+        			return new FakeTupleSource(command.getProjectedSymbols(), new List[] {
+        				Arrays.asList(value+2), Arrays.asList(value+5)
+        			});
+        		}
+        		return super.registerRequest(processorID, command, modelName,
+        				connectorBindingId, nodeID);
+        	}
+        };
+        
+        TestProcedureProcessor.helpTestProcess(plan, expected, dataManager);  
+               
+    }
+    
 }

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-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -57,6 +57,7 @@
 import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
 import com.metamatrix.query.parser.QueryParser;
 import com.metamatrix.query.processor.FakeDataManager;
+import com.metamatrix.query.processor.ProcessorDataManager;
 import com.metamatrix.query.processor.ProcessorPlan;
 import com.metamatrix.query.processor.QueryProcessor;
 import com.metamatrix.query.processor.TestProcessor;
@@ -111,7 +112,7 @@
     }
     
     static void helpTestProcess(boolean optimistic, ProcessorPlan procPlan, int rowsUpdated, List[] expectedResults, boolean shouldFail, 
-    				FakeDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
+    		ProcessorDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
         // Process twice, testing reset and clone method of Processor plan
         for (int i=1; i<=2; i++) {
 	        BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
@@ -190,7 +191,7 @@
         }
     }
     
-    public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, FakeDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
+    public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, ProcessorDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
         helpTestProcess(false, procPlan, expectedResults, dataMgr, false);
     }
     
@@ -199,7 +200,7 @@
     }
     
     static void helpTestProcess(boolean optimistic, ProcessorPlan procPlan, List[] expectedResults, 
-                    FakeDataManager dataMgr, boolean shouldFail) throws SQLException, MetaMatrixCoreException {
+    		ProcessorDataManager dataMgr, boolean shouldFail) throws SQLException, MetaMatrixCoreException {
         helpTestProcess(optimistic, procPlan, 0, expectedResults, shouldFail, dataMgr);
     }
 

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java	2009-03-24 19:15:41 UTC (rev 641)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java	2009-03-25 12:20:12 UTC (rev 642)
@@ -62,42 +62,78 @@
     }
     
     public void helpTestSelect(List elements, Criteria criteria, List[] data, List childElements, ProcessorDataManager dataMgr, List[] expected) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    	helpTestSelect(elements, criteria, childElements, dataMgr, expected, new FakeRelationalNode(2, data));
+    }
+    
+    public void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child) throws MetaMatrixComponentException, MetaMatrixProcessingException {
         BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
         CommandContext context = new CommandContext("pid", "test", null, 100, null, null, null, null);               //$NON-NLS-1$ //$NON-NLS-2$
         
-        FakeRelationalNode dataNode = new FakeRelationalNode(2, data);
-        dataNode.setElements(childElements);
-        dataNode.initialize(context, mgr, dataMgr);    
+        child.setElements(childElements);
+        child.initialize(context, mgr, dataMgr);    
         
         SelectNode selectNode = new SelectNode(1);
         selectNode.setCriteria(criteria);
         selectNode.setElements(elements);
-        selectNode.addChild(dataNode);
+        selectNode.addChild(child);
         selectNode.initialize(context, mgr, dataMgr);
         
         selectNode.open();
         
-        int currentRow = 1;
-        while(true) {
-            try {
-                TupleBatch batch = selectNode.nextBatch();
-                if(batch.getRowCount() > 0) {
-                    for(int row = currentRow; row <= batch.getEndRow(); row++) {
-                        //System.out.println(batch.getTuple(row));
-                        assertEquals("Rows don't match at " + row, expected[row-1], batch.getTuple(row)); //$NON-NLS-1$
-                    }
-                }
-                
-                if(batch.getTerminationFlag()) {
-                    break;
-                }
-                currentRow += batch.getRowCount();    
-            } catch(BlockedException e) {
-                // ignore and retry
-            }
-        }
+        BatchIterator iterator = new BatchIterator(selectNode);
+        
+        for (int i = 0; i < expected.length; i++) {
+        	while (true) {
+	        	try {
+	        		assertEquals("Rows don't match at " + i, expected[i], iterator.next()); //$NON-NLS-1$
+	        		break;
+	        	} catch (BlockedException e) {
+	        		continue;
+	        	}
+        	}
+		}  
+        assertFalse(iterator.hasNext());
     }
     
+    /**
+     * Ensures that a final empty batch is reindexed so that the batch iterator works correctly
+     */
+    public void testEmptyBatchIndexing() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    	ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
+        es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+
+        List elements = new ArrayList();
+        elements.add(es1);
+        
+        CompareCriteria crit = new CompareCriteria(new Constant(0), CompareCriteria.EQ, new Constant(new Integer(1)));
+        
+        List childElements = new ArrayList();
+        childElements.add(es1);
+        
+    	RelationalNode child = new RelationalNode(0) {
+    		int i = 0;
+    		
+			@Override
+			public Object clone() {
+				return null;
+			}
+
+			@Override
+			protected TupleBatch nextBatchDirect() throws BlockedException,
+					MetaMatrixComponentException, MetaMatrixProcessingException {
+				if (i++ == 0) {
+					return new TupleBatch(1, new List[] {Arrays.asList(1), Arrays.asList(1)});
+				}
+				TupleBatch batch = new TupleBatch(3, new List[0] );
+				batch.setTerminationFlag(true);
+				return batch;
+			}
+    		
+    	};
+    	
+    	helpTestSelect(elements, crit, childElements, null, new List[0], child);
+    }
+    
     public void testNoRows() throws MetaMatrixComponentException, MetaMatrixProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);




More information about the teiid-commits mailing list