[teiid-commits] teiid SVN: r801 - in trunk/engine/src: main/java/com/metamatrix/common/buffer/impl and 17 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Apr 20 10:57:26 EDT 2009


Author: shawkins
Date: 2009-04-20 10:57:25 -0400 (Mon, 20 Apr 2009)
New Revision: 801

Added:
   trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/TupleSourceImpl.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ContextReference.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java
Removed:
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSourceState.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/IndexedTupleSourceIterator.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceIterator.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorProvider.java
Modified:
   trunk/engine/src/main/java/com/metamatrix/common/buffer/IndexedTupleSource.java
   trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
   trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
   trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
   trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceValueIterator.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/AbstractSetCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/DependentSetCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ExistsCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubqueryCompareCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubquerySetCriteria.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorSource.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
   trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
   trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java
   trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDependentSetCriteria.java
Log:
TEIID-508 TEIID-507 fixed the handling of dependent criteria and changed dependentsets and subqueries to not require direct setting of value iterators.  this allows for process plans to avoid language object cloning for anything other than pushdown.

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/IndexedTupleSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/IndexedTupleSource.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/IndexedTupleSource.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -23,23 +23,37 @@
 package com.metamatrix.common.buffer;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
 
+public interface IndexedTupleSource extends TupleSource {
 
-/** 
- * @since 4.2
- */
-public interface IndexedTupleSource extends
-                                   TupleSource {
+	/**
+	 * @return true if there are more tuples
+	 * @throws MetaMatrixComponentException
+	 * @throws MetaMatrixProcessingException
+	 */
+	boolean hasNext() throws MetaMatrixComponentException, MetaMatrixProcessingException;
 
-    
-    /**
-     * Returns the index of the current tuple in the tuple source.
-     */
-    int getCurrentTupleIndex();
-    
-    /**
-     * Set the current index of the tuple source.  Allows the user of the tuple source to
-     * set the row that is retrieved.
-     */
-    void setCurrentTupleIndex(int index) throws MetaMatrixComponentException;
+	/**
+	 * Save the current position that can be restored with a call to {@link #reset()}
+	 */
+	void mark();
+
+	/**
+	 * Restore the previous mark and set the mark back to the first position.
+	 */
+	void reset();
+
+	/**
+	 * Set the tuple source position
+	 * @param position
+	 */
+	void setPosition(int position);
+	
+	/**
+	 * Get the current position.  The position is 1 based and reports the position of the
+	 * tuple that will be retrieved with a call to {@link TupleSource#nextTuple()}
+	 * @return
+	 */
+	int getCurrentIndex();
 }

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.common.buffer.impl;
 
-import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -37,10 +36,7 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BlockedOnMemoryException;
 import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.IndexedTupleSource;
 import com.metamatrix.common.buffer.LobTupleBatch;
@@ -395,7 +391,7 @@
 
 		TupleSourceInfo info = getTupleSourceInfo(tupleSourceID, true);
         int batchSize = this.config.getProcessorBatchSize();
-        return new TupleSourceImpl(tupleSourceID, info.getTupleSchema(), batchSize);
+        return new TupleSourceImpl(this, tupleSourceID, info.getTupleSchema(), batchSize);
     }
 
     /**
@@ -893,110 +889,6 @@
         return info;
     }
 
-    private class TupleSourceImpl implements IndexedTupleSource {
-        private TupleSourceID tupleSourceID;
-        private List schema;
-        private int batchSize;
-        private WeakReference currentBatch;
-        private int currentRow = 1;
-
-        TupleSourceImpl(TupleSourceID tupleSourceID, List schema, int batchSize){
-            this.tupleSourceID = tupleSourceID;
-            this.schema = schema;
-            this.batchSize = batchSize;
-        }
-
-        public List getSchema(){
-            return this.schema;
-        }
-
-        public List nextTuple()
-        throws MetaMatrixComponentException{
-            TupleBatch batch = getBatch();
-            if(batch.getRowCount() == 0) {
-                // Check if last
-                try {
-                    TupleSourceStatus status = getStatus(this.tupleSourceID);
-                    if(status == TupleSourceStatus.FULL) {
-                        unpinCurrentBatch();
-                        return null;
-                    } 
-                    throw BlockedException.INSTANCE;
-                } catch(TupleSourceNotFoundException e) {
-                    throw new ComponentNotFoundException(e, e.getMessage());
-                }
-            }
-
-            return batch.getTuple(currentRow++);
-        }
-
-        public void closeSource()
-        throws MetaMatrixComponentException{
-            // Reset to same state as newly-instantiated TupleSourceImpl
-            unpinCurrentBatch();
-            this.currentRow = 1;
-            //TODO: this is not quite correct wrt the javadoc, close does
-            //not need to ensure that we are back at the beginning
-        }
-        
-        public int getCurrentTupleIndex() {
-            return currentRow;
-        }
-        
-        public void setCurrentTupleIndex(int index) {
-            currentRow = index;
-        }
-        
-        private TupleBatch getCurrentBatch() {
-            if (currentBatch != null) {
-                return (TupleBatch)currentBatch.get();
-            }
-            return null;
-        }
-
-        private void unpinCurrentBatch()
-        throws MetaMatrixComponentException {
-            TupleBatch batch = getCurrentBatch();
-            if(batch != null ) {
-                try {
-                    unpinTupleBatch(this.tupleSourceID, batch.getBeginRow(), batch.getEndRow());
-                } catch (TupleSourceNotFoundException e) {
-					throw new MetaMatrixComponentException(e);
-				} finally {
-                    currentBatch = null;
-                }
-            }
-        }
-        
-        // Retrieves the necessary batch based on the currentRow
-        private TupleBatch getBatch()
-        throws MetaMatrixComponentException{
-            TupleBatch batch = getCurrentBatch();
-            if (batch != null) {
-                if (currentRow < batch.getEndRow() && currentRow > batch.getBeginRow()) {
-                    return batch;
-                }
-                unpinCurrentBatch();
-            } 
-            
-            try{
-                batch = pinTupleBatch(this.tupleSourceID, currentRow, (currentRow + batchSize -1));
-                currentBatch = new WeakReference(batch);
-            } catch (MemoryNotAvailableException e) {
-                /* Defect 18499 - ProcessWorker doesn't know how to handle MemoryNotAvailableException properly,
-                 * and this should always be converted to a BlockedOnMemoryException during processing so that
-                 * the work can be requeued.
-                 */
-                throw BlockedOnMemoryException.INSTANCE;
-            } catch(MetaMatrixComponentException e) {
-                throw e;
-            } catch(TupleSourceNotFoundException e){
-                throw new MetaMatrixComponentException(e);
-            }
-            return batch;
-        }
-    }
-
     /** 
      * @see com.metamatrix.common.buffer.BufferManager#stop()
      */

Added: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/TupleSourceImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/TupleSourceImpl.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/TupleSourceImpl.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.common.buffer.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.List;
+
+import com.metamatrix.api.exception.ComponentNotFoundException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BlockedOnMemoryException;
+import com.metamatrix.common.buffer.IndexedTupleSource;
+import com.metamatrix.common.buffer.MemoryNotAvailableException;
+import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
+import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
+
+class TupleSourceImpl implements IndexedTupleSource {
+	private final BufferManagerImpl bufferManagerImpl;
+	private TupleSourceID tupleSourceID;
+    private List<?> schema;
+    private int batchSize;
+    private WeakReference<TupleBatch> currentBatch;
+    private int currentRow = 1;
+    private int mark = 1;
+	private List<?> currentTuple;
+
+    TupleSourceImpl(BufferManagerImpl bufferManagerImpl, TupleSourceID tupleSourceID, List schema, int batchSize){
+        this.bufferManagerImpl = bufferManagerImpl;
+		this.tupleSourceID = tupleSourceID;
+        this.schema = schema;
+        this.batchSize = batchSize;
+    }
+    
+    @Override
+    public int getCurrentIndex() {
+    	return this.currentRow;
+    }
+
+    @Override
+    public List getSchema(){
+        return this.schema;
+    }
+
+    @Override
+    public List<?> nextTuple()
+    throws MetaMatrixComponentException{
+    	List<?> result = null;
+    	if (currentTuple != null){
+			result = currentTuple;
+			currentTuple = null;
+    	} else {
+    		result = getCurrentTuple();
+    	} 
+    	if (result != null) {
+    		currentRow++;
+    	}
+        return result;
+    }
+
+	private List getCurrentTuple() throws MetaMatrixComponentException,
+			BlockedException, ComponentNotFoundException {
+		TupleBatch batch = getBatch();
+        if(batch.getRowCount() == 0) {
+            // Check if last
+            try {
+                TupleSourceStatus status = this.bufferManagerImpl.getStatus(this.tupleSourceID);
+                if(status == TupleSourceStatus.FULL) {
+                    unpinCurrentBatch();
+                    return null;
+                } 
+                throw BlockedException.INSTANCE;
+            } catch(TupleSourceNotFoundException e) {
+                throw new ComponentNotFoundException(e, e.getMessage());
+            }
+        }
+
+        return batch.getTuple(currentRow);
+	}
+
+    @Override
+    public void closeSource()
+    throws MetaMatrixComponentException{
+        // Reset to same state as newly-instantiated TupleSourceImpl
+        unpinCurrentBatch();
+        mark = 1;
+        reset();
+        //TODO: this is not quite correct wrt the javadoc, close does
+        //not need to ensure that we are back at the beginning
+    }
+    
+    private TupleBatch getCurrentBatch() {
+        if (currentBatch != null) {
+            return currentBatch.get();
+        }
+        return null;
+    }
+
+    private void unpinCurrentBatch()
+    throws MetaMatrixComponentException {
+        TupleBatch batch = getCurrentBatch();
+        if(batch != null ) {
+            try {
+                this.bufferManagerImpl.unpinTupleBatch(this.tupleSourceID, batch.getBeginRow(), batch.getEndRow());
+            } catch (TupleSourceNotFoundException e) {
+				throw new MetaMatrixComponentException(e);
+			} finally {
+                currentBatch = null;
+            }
+        }
+    }
+    
+    // Retrieves the necessary batch based on the currentRow
+    private TupleBatch getBatch()
+    throws MetaMatrixComponentException{
+        TupleBatch batch = getCurrentBatch();
+        if (batch != null) {
+            if (currentRow < batch.getEndRow() && currentRow > batch.getBeginRow()) {
+                return batch;
+            }
+            unpinCurrentBatch();
+        } 
+        
+        try{
+            batch = this.bufferManagerImpl.pinTupleBatch(this.tupleSourceID, currentRow, (currentRow + batchSize -1));
+            currentBatch = new WeakReference<TupleBatch>(batch);
+        } catch (MemoryNotAvailableException e) {
+            /* Defect 18499 - ProcessWorker doesn't know how to handle MemoryNotAvailableException properly,
+             * and this should always be converted to a BlockedOnMemoryException during processing so that
+             * the work can be requeued.
+             */
+            throw BlockedOnMemoryException.INSTANCE;
+        } catch(MetaMatrixComponentException e) {
+            throw e;
+        } catch(TupleSourceNotFoundException e){
+            throw new MetaMatrixComponentException(e);
+        }
+        return batch;
+    }
+    
+    @Override
+	public boolean hasNext() throws MetaMatrixComponentException {
+        if (this.currentTuple != null) {
+            return true;
+        }
+        
+        this.currentTuple = getCurrentTuple();
+		return this.currentTuple != null;
+	}
+
+	@Override
+	public void reset() {
+		this.setPosition(mark);
+		this.mark = 1;
+	}
+
+    @Override
+    public void mark() {
+        this.mark = currentRow;
+    }
+
+    @Override
+    public void setPosition(int position) {
+        if (this.currentRow != position) {
+	        this.currentRow = position;
+	        this.currentTuple = null;
+        }
+    }
+}
\ No newline at end of file


Property changes on: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/TupleSourceImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -45,7 +45,9 @@
 import com.metamatrix.query.function.FunctionLibrary;
 import com.metamatrix.query.function.FunctionLibraryManager;
 import com.metamatrix.query.function.metadata.FunctionMethod;
+import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.lang.AbstractSetCriteria;
+import com.metamatrix.query.sql.lang.CollectionValueIterator;
 import com.metamatrix.query.sql.lang.CompareCriteria;
 import com.metamatrix.query.sql.lang.CompoundCriteria;
 import com.metamatrix.query.sql.lang.Criteria;
@@ -53,11 +55,12 @@
 import com.metamatrix.query.sql.lang.IsNullCriteria;
 import com.metamatrix.query.sql.lang.MatchCriteria;
 import com.metamatrix.query.sql.lang.NotCriteria;
+import com.metamatrix.query.sql.lang.SetCriteria;
 import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
 import com.metamatrix.query.sql.symbol.AggregateSymbol;
 import com.metamatrix.query.sql.symbol.CaseExpression;
 import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 import com.metamatrix.query.sql.symbol.Function;
@@ -308,7 +311,14 @@
             return null;
         }
         Boolean result = Boolean.FALSE;
-		ValueIterator valueIter = criteria.getValueIterator();
+
+        ValueIterator valueIter = null;
+        if (criteria instanceof SetCriteria) {
+        	valueIter = new CollectionValueIterator(((SetCriteria)criteria).getValues());
+        } else {
+        	ContextReference ref = (ContextReference)criteria;
+        	valueIter = getContext(criteria).getValueIterator(ref);
+        }
         while(valueIter.hasNext()) {
             Object possibleValue = valueIter.next();
             Object value = null;
@@ -378,7 +388,7 @@
             result = Boolean.TRUE;
         }
 
-        ValueIterator valueIter = criteria.getValueIterator();
+        ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
         while(valueIter.hasNext()) {
             Object value = valueIter.next();
 
@@ -461,7 +471,7 @@
     public boolean evaluate(ExistsCriteria criteria, List tuple)
         throws BlockedException, MetaMatrixComponentException {
 
-        ValueIterator valueIter = criteria.getValueIterator();
+        ValueIterator valueIter = getContext(criteria).getValueIterator(criteria);
         if(valueIter.hasNext()) {
             return true;
         }
@@ -497,12 +507,7 @@
 	           return internalEvaluate(expr, tuple);
 	       } 
 	       
-	       if (expression instanceof ElementSymbol && this.context != null && this.context.getVariableContext() != null 
-	    		   && this.context.getVariableContext().containsVariable((ElementSymbol)expression)) {
-    		   return this.context.getVariableContext().getValue((ElementSymbol)expression);
-	       }
-	       // instead of assuming null, throw an exception.  a problem in planning has occurred
-	       throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
+	       return getContext(expression).getFromContext(expression);
 	   } 
 	   if(expression instanceof Constant) {
 	       return ((Constant) expression).getValue();
@@ -514,6 +519,9 @@
 	       return evaluate((SearchedCaseExpression) expression, tuple);
 	   } else if(expression instanceof Reference) {
 		   Reference ref = (Reference)expression;
+		   if (ref.isPositional() && ref.getExpression() == null) {
+			   return getContext(ref).getVariableContext().getGlobalValue(ref.getContextSymbol());
+		   }
 		   return internalEvaluate(ref.getExpression(), tuple);
 	   } else if(expression instanceof ScalarSubquery) {
 	       return evaluate((ScalarSubquery) expression, tuple);
@@ -607,9 +615,9 @@
 	
 	private Object evaluate(ScalarSubquery scalarSubquery, List tuple)
 	    throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
-	
+		
 	    Object result = null;
-	    ValueIterator valueIter = scalarSubquery.getValueIterator();
+        ValueIterator valueIter = getContext(scalarSubquery).getValueIterator(scalarSubquery);
 	    if(valueIter.hasNext()) {
 	        result = valueIter.next();
 	        if(valueIter.hasNext()) {
@@ -619,6 +627,13 @@
 	        }
 	    }
 	    return result;
-	}        
-    
+	}
+
+	private CommandContext getContext(LanguageObject expression) throws MetaMatrixComponentException {
+		if (context == null) {
+			throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
+		}
+		return context;
+	}       
+	    
 }

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,6 +22,7 @@
 
 package com.metamatrix.query.optimizer.relational;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -51,7 +52,6 @@
 import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
 import com.metamatrix.query.processor.relational.DependentProjectNode;
 import com.metamatrix.query.processor.relational.DependentSelectNode;
-import com.metamatrix.query.processor.relational.DependentValueSource;
 import com.metamatrix.query.processor.relational.DupRemoveNode;
 import com.metamatrix.query.processor.relational.GroupingNode;
 import com.metamatrix.query.processor.relational.JoinNode;
@@ -66,6 +66,7 @@
 import com.metamatrix.query.processor.relational.RelationalPlan;
 import com.metamatrix.query.processor.relational.SelectNode;
 import com.metamatrix.query.processor.relational.SortNode;
+import com.metamatrix.query.processor.relational.SubqueryProcessorUtility;
 import com.metamatrix.query.processor.relational.UnionAllNode;
 import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
 import com.metamatrix.query.resolver.util.ResolverUtil;
@@ -75,7 +76,9 @@
 import com.metamatrix.query.sql.lang.JoinType;
 import com.metamatrix.query.sql.lang.Query;
 import com.metamatrix.query.sql.lang.StoredProcedure;
+import com.metamatrix.query.sql.lang.SubqueryContainer;
 import com.metamatrix.query.sql.lang.SetQuery.Operation;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.GroupSymbol;
 import com.metamatrix.query.sql.util.SymbolMap;
@@ -188,17 +191,15 @@
                 } else {
                     List symbols = (List) node.getProperty(NodeConstants.Info.PROJECT_COLS);
                     
-                    // This project node has one or more subqueries
-                    List subqueries = node.getSubqueryContainers();
-                    if (subqueries.isEmpty()){
-                		ProjectNode pnode = new ProjectNode(getID());
-                		processNode = pnode;
+                    SubqueryProcessorUtility spu = createSubqueryProcessor(node);
+                    if (spu == null) {
+	                    ProjectNode pnode = new ProjectNode(getID());
+	            		processNode = pnode;
                     } else {
-                        SymbolMap correlatedReferences = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
-                        DependentProjectNode pnode = new DependentProjectNode(getID(), correlatedReferences);
-
+                        DependentProjectNode pnode = new DependentProjectNode(getID(), spu);
                         processNode = pnode;
                     }
+
                     ((ProjectNode)processNode).setSelectSymbols(symbols);
                 }
                 break;
@@ -229,7 +230,7 @@
                                
                 processNode = jnode;
                 
-                DependentValueSource depValueSource = (DependentValueSource) node.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE);
+                String depValueSource = (String) node.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE);
                 jnode.setDependentValueSource(depValueSource);
                 
 				break;
@@ -322,20 +323,16 @@
 			case NodeConstants.Types.SELECT:
 
 				Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
-				List subCrits = node.getSubqueryContainers();
-                if (subCrits.isEmpty()){
+                SubqueryProcessorUtility spu = createSubqueryProcessor(node);
+
+                if (spu == null){
 					// This is a normal select node
 					SelectNode selnode = new SelectNode(getID());
 					selnode.setCriteria(crit);
-
 					processNode = selnode;
 				} else {
-                    // This select node has one or more subqueries
-                    SymbolMap correlatedReferences = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
-
-                    DependentSelectNode selnode = new DependentSelectNode(getID(), correlatedReferences);
+                    DependentSelectNode selnode = new DependentSelectNode(getID(), spu);
 					selnode.setCriteria(crit);
-
 					processNode = selnode;
 				}
                 possiblyDependentObject = crit;
@@ -423,6 +420,21 @@
 		return processNode;
 	}
 
+	private SubqueryProcessorUtility createSubqueryProcessor(PlanNode node) {
+		List<SubqueryContainer> subqueries = node.getSubqueryContainers();
+		if (subqueries.isEmpty()){
+			return null;
+		}
+	    SymbolMap correlatedReferences = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
+	    List<ProcessorPlan> plans = new ArrayList<ProcessorPlan>(subqueries.size());
+	    List<String> contextReferences = new ArrayList<String>(subqueries.size());
+	    for (SubqueryContainer subqueryContainer : subqueries) {
+			plans.add(subqueryContainer.getCommand().getProcessorPlan());
+			contextReferences.add(((ContextReference)subqueryContainer).getContextSymbol());
+		}
+	    return new SubqueryProcessorUtility(plans, contextReferences, correlatedReferences);
+	}
+
     private RelationalNode correctProjectionForTempTable(PlanNode node,
                                                                 AccessNode aNode,
                                                                 LanguageObject possiblyDependentObject) throws QueryMetadataException,

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -85,7 +85,7 @@
         JOIN_STRATEGY,      // JoinStrategyType
         LEFT_EXPRESSIONS,   // List <SingleElementSymbol> 
         RIGHT_EXPRESSIONS,  // List <SingleElementSymbol> 
-        DEPENDENT_VALUE_SOURCE, // DependentValueSource for supplying multiple value iterators to remote nodes
+        DEPENDENT_VALUE_SOURCE, // String
         NON_EQUI_JOIN_CRITERIA,      // List <CompareCriteria>
         SORT_LEFT,  // Boolean
         SORT_RIGHT,     // Boolean

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseDependent.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -27,6 +27,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.QueryMetadataException;
@@ -42,14 +43,12 @@
 import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
 import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
 import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.processor.relational.DependentValueSource;
 import com.metamatrix.query.sql.lang.CompareCriteria;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.DependentSetCriteria;
 import com.metamatrix.query.sql.lang.JoinType;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.util.ValueIteratorSource;
 import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
 import com.metamatrix.query.util.CommandContext;
 import com.metamatrix.query.util.LogConstants;
@@ -58,6 +57,8 @@
  * Finds nodes that can be turned into dependent joins 
  */
 public final class RuleChooseDependent implements OptimizerRule {
+	
+	private static AtomicInteger ID = new AtomicInteger();
 
     private static class CandidateJoin {
         PlanNode joinNode;
@@ -305,11 +306,11 @@
             return false;
         }
 
+        String id = "$dsc/id" + ID.getAndIncrement(); //$NON-NLS-1$
         // Create DependentValueSource and set on the independent side as this will feed the values
-        DependentValueSource valueIterSrc = new DependentValueSource();            
-        joinNode.setProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE, valueIterSrc);
+        joinNode.setProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE, id);
 
-        List crits = getDependentCriteriaNodes(valueIterSrc, independentExpressions, dependentExpressions);
+        List crits = getDependentCriteriaNodes(id, independentExpressions, dependentExpressions);
         
         PlanNode newRoot = sourceNode;
         
@@ -331,8 +332,7 @@
      * @return
      * @since 4.3
      */
-    private List getDependentCriteriaNodes( ValueIteratorSource iterSrc,
-                                           List independentExpressions,
+    private List getDependentCriteriaNodes(String id, List independentExpressions,
                                            List dependentExpressions) {
         
         List result = new LinkedList();
@@ -343,9 +343,8 @@
         while(depIter.hasNext()) {
             Expression depExpr = (Expression) depIter.next();
             Expression indepExpr = (Expression) indepIter.next();
-            DependentSetCriteria crit = new DependentSetCriteria(SymbolMap.getExpression(depExpr));
+            DependentSetCriteria crit = new DependentSetCriteria(SymbolMap.getExpression(depExpr), id);
             crit.setValueExpression(indepExpr);
-            crit.setValueIteratorSource(iterSrc);
             
             PlanNode selectNode = GenerateCanonical.createSelectNode(crit, false);
             

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePlanProcedures.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -44,15 +44,12 @@
 import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.LanguageVisitor;
 import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.DependentSetCriteria;
 import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.NotCriteria;
 import com.metamatrix.query.sql.lang.SPParameter;
 import com.metamatrix.query.sql.lang.SetCriteria;
 import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.navigator.PreOrderNavigator;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.Reference;
@@ -162,40 +159,25 @@
             
             LanguageVisitor visitor = new LanguageVisitor() {      
                 public void visit(CompareCriteria compCrit){
-                    if(compCrit.getOperator() != CompareCriteria.EQ){
-                        return;
-                    }
-                    if (checkForInput(compCrit.getLeftExpression()) && !checkForAnyInput(compCrit.getRightExpression())) {
+                    if (compCrit.getOperator() == CompareCriteria.EQ && checkForInput(compCrit.getLeftExpression()) && !checkForAnyInput(compCrit.getRightExpression())) {
                         addInputNode((Reference)compCrit.getLeftExpression());
                     }
                 }
                 
-                public void visit(NotCriteria obj) {
-                    setAbort(true);
-                }
-                
-                public void visit(CompoundCriteria obj) {
-                    setAbort(true);
-                }
-
                 private void addInputNode(Reference param) {
                     params.add(param.getExpression());
                     conjuncts.add(crit);
                     NodeEditor.removeChildNode(currentNode.getParent(), currentNode);
-                    setAbort(true);
                 }
                 
                 public void visit(IsNullCriteria isNull){
-                    if (isNull.isNegated()) {
-                        return;
-                    }
-                    if (checkForInput(isNull.getExpression())) {
+                    if (!isNull.isNegated() && checkForInput(isNull.getExpression())) {
                         addInputNode((Reference)isNull.getExpression());
                     }
                 }
                 
                 public void visit(SetCriteria obj) {
-                    if (checkForInput(obj.getExpression()) && !checkForAnyInput(obj.getValues())) {
+                    if (!obj.isNegated() && checkForInput(obj.getExpression()) && !checkForAnyInput(obj.getValues())) {
                         addInputNode((Reference)obj.getExpression());
                     }
                 }
@@ -234,8 +216,7 @@
                 }
                 
             };
-
-            PreOrderNavigator.doVisit(crit, visitor);
+            crit.acceptVisitor(visitor);
         }
     }
     

Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushSelectCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -260,12 +260,10 @@
                     
                     satisfyAccessPatterns(critNode, currentNode);
                     
-                    if (critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET) 
-                                    && CapabilitiesUtil.getMaxInCriteriaSize(RuleRaiseAccess.getModelIDFromAccess(currentNode, metadata), metadata, capFinder) > 0) {
+                    if (critNode.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)) {
                         //once a dependent crit node is pushed, don't bother pushing it further into the command
                         //dependent access node will use this as an assumption for where dependent sets can appear in the command
                         critNode.setProperty(NodeConstants.Info.IS_PUSHED, Boolean.TRUE);
-                        
                         currentNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
                         return currentNode.getFirstChild();
                     } 

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/AbstractAssignmentInstruction.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -103,10 +103,8 @@
     
     
     protected void cloneState(AbstractAssignmentInstruction clone) {
-        clone.setVariable((ElementSymbol)getVariable().clone());
-        if (expression != null) {
-            clone.setExpression((Expression)getExpression().clone());
-        }
+        clone.setVariable(this.variable);
+        clone.setExpression(this.expression);
         if (processPlan != null) {
             clone.setProcessPlan((ProcessorPlan)getProcessPlan().clone());
         }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ExecSqlInstruction.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -97,12 +97,7 @@
      * Returns a deep clone
      */
     public Object clone(){
-        GroupSymbol clonedIntoGroup = null;
-        if(this.intoGroup != null){
-            clonedIntoGroup = (GroupSymbol)intoGroup.clone();
-        }
-        
-        ExecSqlInstruction clone = new ExecSqlInstruction((ProcessorPlan)commandPlan.clone(), clonedIntoGroup);
+        ExecSqlInstruction clone = new ExecSqlInstruction((ProcessorPlan)commandPlan.clone(), intoGroup);
         return clone;
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/IfInstruction.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -123,13 +123,12 @@
      * Returns a deep clone
      */
     public Object clone(){
-    	Criteria cloneCriteria = (Criteria) this.condition.clone();
     	Program cloneIf = (Program) this.ifProgram.clone();
     	Program cloneElse = null;
     	if(elseProgram != null) {
     		cloneElse = (Program) this.elseProgram.clone();
     	}
-        IfInstruction clone = new IfInstruction(cloneCriteria, cloneIf, cloneElse);
+        IfInstruction clone = new IfInstruction(this.condition, cloneIf, cloneElse);
         return clone;
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/proc/WhileInstruction.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -61,7 +61,7 @@
      * Returns a deep clone
      */
     public Object clone(){
-        return new WhileInstruction((Program)this.whileProgram.clone(), (Criteria)this.condition.clone());
+        return new WhileInstruction((Program)this.whileProgram.clone(), this.condition);
     }
 
     public String toString() {

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/AccessNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -211,7 +211,7 @@
 		target.modelName = source.modelName;
 		target.connectorBindingId = source.connectorBindingId;
 		target.shouldEvaluate = source.shouldEvaluate;
-		target.command = (Command)source.command.clone();
+		target.command = source.command;
 	}
 
     /*

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchIterator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -27,10 +27,12 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.buffer.IndexedTupleSource;
 import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 
 final class BatchIterator implements
-                                 TupleSourceIterator {
+                                 IndexedTupleSource {
 
     private final RelationalNode source;
 
@@ -65,9 +67,20 @@
         }
         return true;
     }
-
-    public List next() throws MetaMatrixComponentException,
-                      MetaMatrixProcessingException {
+    
+    @Override
+    public void closeSource() throws MetaMatrixComponentException {
+    	
+    }
+    
+    @Override
+    public List<SingleElementSymbol> getSchema() {
+    	return source.getElements();
+    }
+    
+    @Override
+    public List<?> nextTuple() throws MetaMatrixComponentException,
+    		MetaMatrixProcessingException {
         if (currentTuple == null && !hasNext()) {
             throw new NoSuchElementException();
         }
@@ -84,6 +97,7 @@
         //does nothing
     }
 
+    @Override
     public int getCurrentIndex() {
         return currentRow;
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/BatchedUpdateNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -182,11 +182,7 @@
      * @since 4.2
      */
     public Object clone() {
-        List clonedCommands = new ArrayList(updateCommands.size());
-        for (int i = 0; i < updateCommands.size(); i++) {
-            clonedCommands.add(((Command)updateCommands.get(i)).clone());
-        }
-        BatchedUpdateNode clonedNode = new BatchedUpdateNode(getID(), clonedCommands, contexts, shouldEvaluate, modelName);
+        BatchedUpdateNode clonedNode = new BatchedUpdateNode(getID(), updateCommands, contexts, shouldEvaluate, modelName);
         super.copy(this, clonedNode);
         return clonedNode;
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentCriteriaProcessor.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -23,201 +23,209 @@
 package com.metamatrix.query.processor.relational;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.TupleSourceID;
 import com.metamatrix.common.buffer.TupleSourceNotFoundException;
-import com.metamatrix.query.processor.relational.DependentSourceState.SetState;
+import com.metamatrix.query.eval.Evaluator;
+import com.metamatrix.query.rewriter.QueryRewriter;
 import com.metamatrix.query.sql.lang.AbstractSetCriteria;
 import com.metamatrix.query.sql.lang.CollectionValueIterator;
+import com.metamatrix.query.sql.lang.CompareCriteria;
+import com.metamatrix.query.sql.lang.CompoundCriteria;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.DependentSetCriteria;
 import com.metamatrix.query.sql.lang.OrderBy;
 import com.metamatrix.query.sql.lang.SetCriteria;
+import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorSource;
 
 public class DependentCriteriaProcessor {
+	
+    public static class SetState {
 
-    class TupleState implements DependentSourceState {
+        Collection<Object> replacement = new LinkedHashSet<Object>();
 
-        private SortUtility sortUtility;
-        private TupleSourceID outputID;
-        private List dependentSetStates;
-        private DependentValueSource valueSource = new DependentValueSource();
+        Expression valueExpression;
 
-        public TupleState(List sortSymbols,
-                                    TupleSource ts,
-                                    TupleSourceID tsID) throws MetaMatrixComponentException {
+        ValueIterator valueIterator;
 
-            List sortDirection = new ArrayList(sortSymbols.size());
+        Object nextValue;
 
-            for (int i = 0; i < sortSymbols.size(); i++) {
-                sortDirection.add(Boolean.valueOf(OrderBy.ASC));
-            }
+        boolean isNull;
+    }
 
-            this.sortUtility = new SortUtility(tsID, ts.getSchema(), sortSymbols, sortDirection, true, dependentNode.getBufferManager(),
-                                               dependentNode.getConnectionID());
+    class TupleState {
+
+        private SortUtility sortUtility;
+        private DependentValueSource dvs;
+        private List<SetState> dependentSetStates = new LinkedList<SetState>();
+        private String valueSource;
+
+        public TupleState(String source) {
+        	this.valueSource = source;
         }
 
         public void sort() throws BlockedException,
                    MetaMatrixComponentException {
-            if (outputID == null) {
-                outputID = sortUtility.sort();
+            if (dvs == null) {
+            	if (sortUtility == null) {
+            		List<Expression> sortSymbols = new ArrayList<Expression>(dependentSetStates.size());
+	                List<Boolean> sortDirection = new ArrayList<Boolean>(sortSymbols.size());
+	                for (int i = 0; i < dependentSetStates.size(); i++) {
+	                    sortDirection.add(Boolean.valueOf(OrderBy.ASC));
+	                    sortSymbols.add(dependentSetStates.get(i).valueExpression);
+	                }
+	                DependentValueSource originalVs = (DependentValueSource)dependentNode.getContext().getVariableContext().getGlobalValue(valueSource);
+	                TupleSource ts;
+					try {
+						ts = dependentNode.getBufferManager().getTupleSource(originalVs.getTupleSourceID());
+					} catch (TupleSourceNotFoundException e) {
+						throw new MetaMatrixComponentException(e);
+					}
+	                this.sortUtility = new SortUtility(originalVs.getTupleSourceID(), ts.getSchema(), sortSymbols, sortDirection, true, dependentNode.getBufferManager(),
+	                                                   dependentNode.getConnectionID());
+            	}
+            	dvs = new DependentValueSource(sortUtility.sort(), dependentNode.getBufferManager());
+            	for (SetState setState : dependentSetStates) {
+                    setState.valueIterator = dvs.getValueIterator(setState.valueExpression);
+    			}
             }
         }
         
         public void close() throws MetaMatrixComponentException {
-            if (outputID != null) {
+            if (dvs != null) {
+            	sortUtility = null;
                 try {
-                    dependentNode.getBufferManager().removeTupleSource(outputID);
+                    dependentNode.getBufferManager().removeTupleSource(dvs.getTupleSourceID());
                 } catch (TupleSourceNotFoundException e) {
-                    throw new MetaMatrixComponentException(e, e.getMessage());
                 }
-                outputID = null;
+                dvs = null;
             }
         }
-        
-        public ValueIterator getValueIterator(SetState setState) {
-            return valueSource.getValueIterator(setState.valueExpression);
-        }
-        
-        public void connectValueSource() throws MetaMatrixComponentException {
-            try {
-                valueSource.setTupleSource(dependentNode.getBufferManager().getTupleSource(outputID), outputID);
-            } catch (TupleSourceNotFoundException err) {
-                throw new MetaMatrixComponentException(err);
-            }
-        }
-
-        public List getDepedentSetStates() {
+                
+        public List<SetState> getDepedentSetStates() {
             return dependentSetStates;
         }
-
-        public void setDependentSetStates(List states) {
-            this.dependentSetStates = states;
-        }
-    }
-    
-    private final static class FixedState implements DependentSourceState {
         
-        private List dependentSetStates;
-        private Collection values;
-        
-        public FixedState(SetCriteria crit) {
-            this.values = new ArrayList(crit.getValues());
-        }
-
-        public void sort() throws BlockedException,
-                          MetaMatrixComponentException {
-            //do nothing, it should already be sorted
-        }
-
-        public void close() throws MetaMatrixComponentException {
-            //do nothing
-        }
-
-        public ValueIterator getValueIterator(SetState setState) {
-            return new CollectionValueIterator(values);
-        }
-
-        public void connectValueSource() throws MetaMatrixComponentException {
-            //do nothing
-        }
-
-        public List getDepedentSetStates() {
-            return dependentSetStates;
-        }
-
-        public void setDependentSetStates(List states) {
-            this.dependentSetStates = states;
-        }
     }
-
-    private final static class SimpleValueIteratorSource implements
-                                                        ValueIteratorSource {
-
-        private Collection values;
-
-        public SimpleValueIteratorSource(Collection values) {
-            this.values = values;
-        }
-
-        public ValueIterator getValueIterator(Expression valueExpression) {
-            return new CollectionValueIterator(values);
-        }
-
-        public boolean isReady() {
-            return true;
-        }
-    }
-
-    private static final int INITIAL = 1;
+    
     private static final int SORT = 2;
     private static final int SET_PROCESSING = 3;
 
+    //constructor state
     private int maxSetSize;
-
-    // processing state
     private RelationalNode dependentNode;
     private Criteria dependentCrit;
-    private int phase = INITIAL;
-    private List sources;
-    private LinkedHashMap dependentState;
-    private LinkedList restartIndexes;
-    private int currentIterator;
+
+    //initialization state
+    private List<Criteria> queryCriteria;
+    private Map<Integer, SetState> setStates = new HashMap<Integer, SetState>();
+    private LinkedHashMap<String, TupleState> dependentState = new LinkedHashMap<String, TupleState>();
+    private List<List<SetState>> sources = new ArrayList<List<SetState>>();
+
+    // processing state
+    private int phase = SORT;
+    private LinkedList<Integer> restartIndexes = new LinkedList<Integer>();
+    private int currentIndex;
     private boolean hasNextCommand;
+    
 
-    public DependentCriteriaProcessor(int maxSetSize, RelationalNode dependentNode, Criteria dependentCriteria) {
+    public DependentCriteriaProcessor(int maxSetSize, RelationalNode dependentNode, Criteria dependentCriteria) throws ExpressionEvaluationException, MetaMatrixComponentException {
         this.maxSetSize = maxSetSize;
         this.dependentNode = dependentNode;
         this.dependentCrit = dependentCriteria;
+        queryCriteria = Criteria.separateCriteriaByAnd(dependentCrit);
+        
+        for (int i = 0; i < queryCriteria.size(); i++) {
+        	Criteria criteria = queryCriteria.get(i);
+            if (!(criteria instanceof AbstractSetCriteria)) {
+                continue;
+            }
+            
+            if (criteria instanceof SetCriteria) {
+                SetCriteria setCriteria = (SetCriteria)criteria;
+                if (setCriteria.isNegated() || setCriteria.getNumberOfValues() <= maxSetSize) {
+                    continue;
+                }
+                SetState state = new SetState();
+                setStates.put(i, state);
+            	Evaluator evaluator = new Evaluator(Collections.emptyMap(), dependentNode.getDataManager(), dependentNode.getContext());
+                LinkedHashSet<Object> values = new LinkedHashSet<Object>();
+                for (Expression expr : (Collection<Expression>)setCriteria.getValues()) {
+					values.add(evaluator.evaluate(expr, null));
+				}
+                state.valueIterator = new CollectionValueIterator(values);
+                sources.add(Arrays.asList(state));
+            } else if (criteria instanceof DependentSetCriteria) {
+            	DependentSetCriteria dsc = (DependentSetCriteria)criteria;
+                String source = dsc.getContextSymbol();
+                
+                SetState state = new SetState();
+                setStates.put(i, state);
+                state.valueExpression = dsc.getValueExpression();
+                TupleState ts = dependentState.get(source);
+                if (ts == null) {
+                	ts = new TupleState(source);
+                	dependentState.put(source, ts);
+                    sources.add(ts.getDepedentSetStates());
+                }
+                ts.getDepedentSetStates().add(state);
+            } 
+        }        
     }
 
     public void close() throws MetaMatrixComponentException {
         if (dependentState != null) {
-            for (int i = 0; i < sources.size(); i++) {
-                DependentSourceState dss = (DependentSourceState)dependentState.get(sources.get(i));
-                dss.close();
-            }
+            for (TupleState state : dependentState.values()) {
+				state.close();
+			}
         }
     }
 
-    public void reset() {
-        dependentState = null;
-        phase = INITIAL;
-    }
-
     public Criteria prepareCriteria() throws MetaMatrixComponentException {
 
-        if (phase == INITIAL) {
-            initializeDependentState();
-
-            phase = SORT;
-        }
-
         if (phase == SORT) {
-            sortDependentSources();
+        	for (TupleState state : dependentState.values()) {
+                state.sort();
+            }
 
             phase = SET_PROCESSING;
         }
 
-        if (!dependentState.isEmpty()) {
-            replaceDependentValueIterators();
+        replaceDependentValueIterators();
+        
+        LinkedList<Criteria> crits = new LinkedList<Criteria>();
+        
+        for (int i = 0; i < queryCriteria.size(); i++) {
+        	SetState state = this.setStates.get(i);
+        	if (state == null) {
+        		crits.add((Criteria)queryCriteria.get(i).clone());
+        	} else {
+        		Criteria crit = replaceDependentCriteria((AbstractSetCriteria)queryCriteria.get(i), state);
+        		if (crit == QueryRewriter.FALSE_CRITERIA) {
+        			return QueryRewriter.FALSE_CRITERIA;
+        		}
+        		crits.add(crit);
+        	}
         }
         
-        Criteria result = (Criteria)dependentCrit.clone();
-
-        return result;
+        if (crits.size() == 1) {
+        	return crits.get(0);
+        }
+        return new CompoundCriteria(CompoundCriteria.AND, crits);
     }
     
     public void consumedCriteria() {
@@ -227,139 +235,20 @@
             return;
         }
         
-        int restartIndex = ((Integer)restartIndexes.removeLast()).intValue();
+        int restartIndex = restartIndexes.removeLast().intValue();
         
         for (int i = restartIndex; i < sources.size(); i++) {
 
-            DependentSourceState dss = (DependentSourceState)dependentState.get(sources.get(i));
+            List<SetState> source = sources.get(i);
 
-            for (int j = 0; j < dss.getDepedentSetStates().size(); j++) {
-
-                SetState state = (SetState)dss.getDepedentSetStates().get(j);
-
-                state.replacement.clear();
+            for (SetState setState : source) {
+            	setState.replacement.clear();
             }
         }
 
-        currentIterator = restartIndex;
+        currentIndex = restartIndex;
     }
 
-    private void initializeDependentState() throws MetaMatrixComponentException {
-        hasNextCommand = false;
-        dependentState = new LinkedHashMap();
-        currentIterator = 0;
-        restartIndexes = new LinkedList();
-
-        List queryCriteria = Criteria.separateCriteriaByAnd(dependentCrit);
-
-        for (Iterator i = queryCriteria.iterator(); i.hasNext();) {
-            Criteria criteria = (Criteria)i.next();
-
-            if (!(criteria instanceof AbstractSetCriteria)) {
-                continue;
-            }
-            
-            Object source = null;
-            
-            if (criteria instanceof SetCriteria) {
-                SetCriteria setCriteria = (SetCriteria)criteria;
-                if (setCriteria.getNumberOfValues() <= maxSetSize) {
-                    continue;
-                }
-                source = new Object(); //we just need a consistent hash key
-
-            // jh Case 6435a                
-            } else if (criteria instanceof DependentSetCriteria) {
-                source = ((DependentSetCriteria)criteria).getValueIteratorSource();                
-            } else {
-                continue;
-            }
-            List sets = (List)dependentState.get(source);
-
-            if (sets == null) {
-                sets = new LinkedList();
-                dependentState.put(source, sets);
-            }
-
-            sets.add(criteria);
-        }
-
-        sources = new ArrayList(dependentState.keySet());
-
-        for (Iterator i = dependentState.entrySet().iterator(); i.hasNext();) {
-
-            Map.Entry entry = (Map.Entry)i.next();
-            
-            if (entry.getKey() instanceof DependentValueSource) {
-
-                DependentValueSource dvs = (DependentValueSource)entry.getKey();
-    
-                List sets = (List)entry.getValue();
-    
-                List symbols = new ArrayList(sets.size());
-    
-                for (int j = 0; j < sets.size(); j++) {
-    
-                    DependentSetCriteria crit = (DependentSetCriteria)sets.get(j);
-    
-                    SetState state = new SetState();
-                    state.valueExpression = crit.getValueExpression();
-                    symbols.add(state.valueExpression);
-    
-                    sets.set(j, state);
-    
-                    crit.setValueIteratorSource(new SimpleValueIteratorSource(state.replacement));
-                }
-    
-                DependentSourceState dss = new TupleState(symbols, dvs.getTupleSource(), dvs.getTupleSourceID());
-    
-                entry.setValue(dss);
-    
-                dss.setDependentSetStates(sets);
-            } else {
-                
-                List sets = (List)entry.getValue();
-                
-                SetCriteria crit = (SetCriteria)sets.get(0);
-                
-                DependentSourceState dss = new FixedState(crit);
-                
-                SetState state = new SetState();
-                state.valueExpression = crit.getExpression();
-
-                sets.set(0, state);
-
-                crit.setValues(state.replacement);
-                
-                entry.setValue(dss);
-    
-                dss.setDependentSetStates(sets);
-            }
-        }
-    }
-
-    private void sortDependentSources() throws BlockedException,
-                                       MetaMatrixComponentException {
-        for (int i = 0; i < sources.size(); i++) {
-            DependentSourceState dss = (DependentSourceState)dependentState.get(sources.get(i));
-
-            dss.sort();
-        }
-
-        // all have been sorted, now create the tuple source iterators
-        for (int i = 0; i < sources.size(); i++) {
-            DependentSourceState dss = (DependentSourceState)dependentState.get(sources.get(i));
-
-            dss.connectValueSource();
-
-            for (int j = 0; j < dss.getDepedentSetStates().size(); j++) {
-                SetState setState = (SetState)dss.getDepedentSetStates().get(j);
-
-                setState.valueIterator = dss.getValueIterator(setState);
-            }
-        }
-    }
-
     /**
      * Replace the dependentSet value iterators with the next set of values from the independent tuple source
      * 
@@ -369,9 +258,9 @@
      */
     private void replaceDependentValueIterators() throws MetaMatrixComponentException {
 
-        for (; currentIterator < sources.size(); currentIterator++) {
+        for (; currentIndex < sources.size(); currentIndex++) {
 
-            DependentSourceState dss = (DependentSourceState)dependentState.get(sources.get(currentIterator));
+            List<SetState> source = sources.get(currentIndex);
 
             boolean done = false;
 
@@ -380,9 +269,7 @@
                 boolean isNull = false;
                 boolean lessThanMax = true;
 
-                for (int i = 0; i < dss.getDepedentSetStates().size(); i++) {
-                    SetState state = (SetState)dss.getDepedentSetStates().get(i);
-
+                for (SetState state : source) {
                     if (state.nextValue == null && !state.isNull) {
                         if (state.valueIterator.hasNext()) {
                             state.nextValue = state.valueIterator.next();
@@ -399,16 +286,14 @@
                 }
 
                 if (done) {
-                    if (!restartIndexes.isEmpty() && ((Integer)restartIndexes.getLast()).intValue() == currentIterator) {
+                    if (!restartIndexes.isEmpty() && restartIndexes.getLast().intValue() == currentIndex) {
                         restartIndexes.removeLast();
                     }
                     break;
                 }
 
                 if (lessThanMax || isNull) {
-                    for (int i = 0; i < dss.getDepedentSetStates().size(); i++) {
-                        SetState state = (SetState)dss.getDepedentSetStates().get(i);
-
+                	for (SetState state : source) {
                         if (!isNull) {
                             state.replacement.add(state.nextValue);
                         }
@@ -416,7 +301,7 @@
                         state.isNull = false;
                     }
                 } else {
-                    restartIndexes.add(new Integer(currentIterator));
+                    restartIndexes.add(currentIndex);
                     done = true;
                 }
             }
@@ -428,5 +313,24 @@
     protected boolean hasNextCommand() {
         return hasNextCommand;
     }
+    
+    public Criteria replaceDependentCriteria(AbstractSetCriteria crit, SetState state) {
+    	if (state.replacement.isEmpty()) {
+            // No values - return criteria that is always false
+            return QueryRewriter.FALSE_CRITERIA;
+    	}
+    	if (state.replacement.size() == 1) {
+    		return new CompareCriteria(crit.getExpression(), CompareCriteria.EQ, new Constant(state.replacement.iterator().next()));
+    	}
+        List vals = new ArrayList(state.replacement.size());
+        for (Object val : state.replacement) {
+            vals.add(new Constant(val));
+        }
+        
+        SetCriteria sc = new SetCriteria();
+        sc.setExpression(crit.getExpression());
+        sc.setValues(vals);
+        return sc;
+    }
 
 }

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureAccessNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,7 +22,6 @@
 
 package com.metamatrix.query.processor.relational;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -67,9 +66,9 @@
      * @see com.metamatrix.query.processor.relational.PlanExecutionNode#clone()
      */
     public Object clone() {
-        DependentProcedureAccessNode copy = new DependentProcedureAccessNode(getID(), (Criteria)inputCriteria.clone(),
-                                                                                   new ArrayList(inputReferences),
-                                                                                   new ArrayList(inputDefaults));
+        DependentProcedureAccessNode copy = new DependentProcedureAccessNode(getID(), inputCriteria,
+                                                                                   inputReferences,
+                                                                                   inputDefaults);
         copy(this, copy);
         return copy;
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProcedureCriteriaProcessor.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -27,18 +27,18 @@
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.buffer.TupleSourceNotFoundException;
 import com.metamatrix.core.util.Assertion;
 import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.sql.lang.AbstractSetCriteria;
+import com.metamatrix.query.rewriter.QueryRewriter;
 import com.metamatrix.query.sql.lang.CompareCriteria;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.IsNullCriteria;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.util.ValueIterator;
 import com.metamatrix.query.sql.util.VariableContext;
 
 public class DependentProcedureCriteriaProcessor extends DependentCriteriaProcessor {
@@ -52,18 +52,13 @@
                                                Criteria dependentCriteria,
                                                List references,
                                                List defaults,
-                                               Evaluator eval) {
+                                               Evaluator eval) throws ExpressionEvaluationException, MetaMatrixComponentException {
         super(1, dependentNode, dependentCriteria);
         this.eval = eval;
         this.inputDefaults = defaults;
         this.inputReferences = references;
     }
     
-    public void reset() {
-        super.reset();
-        critInProgress = null;
-    }
-    
     /**
      * @throws TupleSourceNotFoundException
      * @see com.metamatrix.query.processor.relational.PlanExecutionNode#prepareNextCommand()
@@ -81,6 +76,12 @@
 
             context.remove(ref.getExpression());
         }
+        
+    	if (critInProgress == QueryRewriter.FALSE_CRITERIA) {
+    		critInProgress = null;
+    		consumedCriteria();
+    		return false;
+    	}
 
         boolean validRow = true;
 
@@ -91,14 +92,7 @@
             boolean nullAllowed = false;
             Reference parameter = null;
 
-            if (crit instanceof AbstractSetCriteria) {
-                AbstractSetCriteria asc = (AbstractSetCriteria)crit;
-                ValueIterator iter = asc.getValueIterator();
-                if (iter.hasNext()) {
-                    value = asc.getValueIterator().next();
-                }
-                parameter = (Reference)asc.getExpression();
-            } else if (crit instanceof IsNullCriteria) {
+            if (crit instanceof IsNullCriteria) {
                 parameter = (Reference)((IsNullCriteria)crit).getExpression();
                 nullAllowed = true;
             } else if (crit instanceof CompareCriteria) {
@@ -150,5 +144,5 @@
 
         return true;
     }
-
+    
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentProjectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -28,8 +28,6 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
 
 /**
  * A project node containing one or more scalar subqueries.
@@ -40,14 +38,13 @@
 public class DependentProjectNode extends ProjectNode {
 
     private SubqueryProcessorUtility subqueryProcessor;
-    private SymbolMap correlatedReferences;
 
     /**
      * @param nodeID
      */
-    public DependentProjectNode(int nodeID, SymbolMap correlatedReferences) {
+    public DependentProjectNode(int nodeID, SubqueryProcessorUtility spu) {
         super(nodeID);
-        this.correlatedReferences = correlatedReferences;
+        this.subqueryProcessor = spu;
     }
 
     public void reset() {
@@ -65,13 +62,6 @@
         this.subqueryProcessor.open(this);
     }
     
-    @Override
-    public void setSelectSymbols(List symbols) {
-    	super.setSelectSymbols(symbols);
-		List valueList = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(this.getSelectSymbols());
-		this.subqueryProcessor = new SubqueryProcessorUtility(valueList, this.correlatedReferences);
-    }
-
     /**
      * Closes the subquery processor (which removes the temporary tuple 
      * sources of the subquery results)
@@ -107,9 +97,8 @@
      * @see java.lang.Object#clone()
      */
     public Object clone(){
-        DependentProjectNode clonedNode = new DependentProjectNode(super.getID(), this.correlatedReferences);
+        DependentProjectNode clonedNode = new DependentProjectNode(super.getID(), this.subqueryProcessor.clone());
         super.copy(this, clonedNode);
-        
         return clonedNode;
     }   
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSelectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -28,9 +28,6 @@
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
 
 /**
  * This node represents a Select node for the case where the criteria
@@ -43,15 +40,14 @@
 public class DependentSelectNode extends SelectNode {
 
     private SubqueryProcessorUtility subqueryProcessor;
-    private SymbolMap correlatedReferences;
 
 	/**
 	 * Constructor for DependentSelectNode.
 	 * @param nodeID
 	 */
-	public DependentSelectNode(int nodeID, SymbolMap correlatedReferences) {
+	public DependentSelectNode(int nodeID, SubqueryProcessorUtility subqueryProcessorUtility) {
 		super(nodeID);
-		this.correlatedReferences = correlatedReferences;
+		this.subqueryProcessor = subqueryProcessorUtility;
 	}
 
     /** for unit testing */
@@ -74,13 +70,6 @@
         this.subqueryProcessor.open(this);
 	}
 	
-	@Override
-	public void setCriteria(Criteria criteria) {
-		super.setCriteria(criteria);
-		List valueList = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(this.getCriteria());
-		this.subqueryProcessor = new SubqueryProcessorUtility(valueList, this.correlatedReferences);
-	}
-
 	/**
 	 * Closes the subquery processor (which removes the temporary tuple 
      * sources of the subquery results)
@@ -116,7 +105,7 @@
 	 * @see java.lang.Object#clone()
 	 */
 	public Object clone(){
-		DependentSelectNode clonedNode = new DependentSelectNode(super.getID(), this.correlatedReferences);
+		DependentSelectNode clonedNode = new DependentSelectNode(super.getID(), subqueryProcessor.clone());
 		super.copy(this, clonedNode);
 		return clonedNode;
 	}	

Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSourceState.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSourceState.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentSourceState.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.ValueIterator;
-
-interface DependentSourceState {
-    
-    public static class SetState {
-
-        Collection replacement = new LinkedHashSet();
-
-        Expression valueExpression;
-
-        ValueIterator valueIterator;
-
-        Object nextValue;
-
-        boolean isNull;
-    }
-
-    public void sort() throws BlockedException,
-                      MetaMatrixComponentException;
-
-    public void close() throws MetaMatrixComponentException;
-
-    public ValueIterator getValueIterator(SetState setState);
-
-    public void connectValueSource() throws MetaMatrixComponentException;
-    
-    public List getDepedentSetStates();
-    
-    public void setDependentSetStates(List states);
-
-}
\ No newline at end of file

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/DependentValueSource.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,10 +22,11 @@
 
 package com.metamatrix.query.processor.relational;
 
-import java.util.List;
-
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.buffer.BufferManager;
 import com.metamatrix.common.buffer.IndexedTupleSource;
 import com.metamatrix.common.buffer.TupleSourceID;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.util.ValueIterator;
 import com.metamatrix.query.sql.util.ValueIteratorSource;
@@ -36,47 +37,35 @@
 public class DependentValueSource implements
                                  ValueIteratorSource {
 
-    // Runtime
-    private IndexedTupleSource tupleSource;
     private TupleSourceID tupleSourceID;
+    private BufferManager bm;
     
-    public DependentValueSource() {
-        super();
-    }
-
-    public void setTupleSource(IndexedTupleSource tupleSource, TupleSourceID tupleSourceID) {
-        this.tupleSource = tupleSource;
+    public DependentValueSource(TupleSourceID tupleSourceID, BufferManager bm) {
         this.tupleSourceID = tupleSourceID;
+        this.bm = bm;
     }
     
     public TupleSourceID getTupleSourceID() {
-        return tupleSourceID;
-    }
+		return tupleSourceID;
+	}
     
-    public IndexedTupleSource getTupleSource() {
-        return tupleSource;
-    }
-    
-    public boolean isReady() {
-        return this.tupleSource != null;
-    }
-    
     /** 
+     * @throws MetaMatrixComponentException 
+     * @throws TupleSourceNotFoundException 
      * @see com.metamatrix.query.sql.util.ValueIteratorSource#getValueIterator(com.metamatrix.query.sql.symbol.Expression)
      */
-    public ValueIterator getValueIterator(Expression valueExpression) {
-        TupleSourceValueIterator iter = null;
-        if(this.tupleSource != null) {
-            List schema = tupleSource.getSchema();
-            int columnIndex = schema.indexOf(valueExpression);
-            iter = new TupleSourceValueIterator(this.tupleSource, columnIndex);
-        }
-        return iter;
+    public ValueIterator getValueIterator(Expression valueExpression) throws  MetaMatrixComponentException {
+    	IndexedTupleSource its;
+		try {
+			its = bm.getTupleSource(tupleSourceID);
+		} catch (TupleSourceNotFoundException e) {
+			throw new MetaMatrixComponentException(e);
+		}
+    	int index = 0;
+    	if (valueExpression != null) {
+    		index = its.getSchema().indexOf(valueExpression);
+    	}
+        return new TupleSourceValueIterator(its, index);
     }
            
-    public void reset() {
-        // Reset runtime state
-        this.tupleSource = null;
-    }
-
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -443,12 +443,8 @@
 	public Object clone(){
 		GroupingNode clonedNode = new GroupingNode(super.getID());
 		super.copy(this, clonedNode);
-		if(sortElements != null){
-			clonedNode.sortElements = new ArrayList(sortElements);
-		}
-		if(sortTypes != null){
-			clonedNode.sortTypes = new ArrayList(sortTypes);
-		}
+		clonedNode.sortElements = sortElements;
+		clonedNode.sortTypes = sortTypes;
 		return clonedNode;
 	}
 

Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/IndexedTupleSourceIterator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/IndexedTupleSourceIterator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/IndexedTupleSourceIterator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -1,105 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-import java.util.NoSuchElementException;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.IndexedTupleSource;
-
-/**
- * A ValueIterator implementation that iterates over the TupleSource
- */
-class IndexedTupleSourceIterator implements TupleSourceIterator {
-
-    private IndexedTupleSource tupleSource;
-    private int currentRow = 1;
-    private int mark = 1;
-	private List currentTuple;
-    
-    IndexedTupleSourceIterator(IndexedTupleSource tupleSource){
-        this.tupleSource = tupleSource;
-	}
-    
-	/** 
-     * @throws MetaMatrixProcessingException 
-	 * @see com.metamatrix.query.processor.relational.TupleSourceIterator#hasNext()
-     */
-	public boolean hasNext() throws MetaMatrixComponentException, MetaMatrixProcessingException{
-        if (this.currentTuple != null) {
-            return true;
-        }
-        
-	    this.tupleSource.setCurrentTupleIndex(currentRow);
-        
-        this.currentTuple = this.tupleSource.nextTuple();
-        
-		return this.currentTuple != null;
-	}
-
-	/** 
-     * @throws MetaMatrixProcessingException 
-	 * @see com.metamatrix.query.processor.relational.TupleSourceIterator#next()
-     */
-	public List next() throws MetaMatrixComponentException, MetaMatrixProcessingException{
-        if (currentTuple == null && !hasNext()){
-			throw new NoSuchElementException();
-		}
-        this.currentRow++;
-		List result = currentTuple;
-		currentTuple = null;
-		return result;
-	}
-    
-	/** 
-     * @see com.metamatrix.query.processor.relational.TupleSourceIterator#reset()
-     */
-	public void reset() {
-		this.currentRow = mark;
-		this.mark = 1;
-	}
-
-    /** 
-     * @see com.metamatrix.query.processor.relational.TupleSourceIterator#getCurrentIndex()
-     */
-    public int getCurrentIndex() {
-        return currentRow;
-    }
-
-    /** 
-     * @see com.metamatrix.query.processor.relational.TupleSourceIterator#mark()
-     */
-    public void mark() {
-        this.mark = currentRow;
-    }
-
-    /** 
-     * @see com.metamatrix.query.processor.relational.TupleSourceIterator#setPosition(int)
-     */
-    public void setPosition(int position) {
-        this.currentRow = position;
-    }
-	
-}

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/JoinNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -36,7 +36,6 @@
 import com.metamatrix.query.eval.Evaluator;
 import com.metamatrix.query.sql.lang.Criteria;
 import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.symbol.Expression;
 
 /** 
  * @since 4.2
@@ -51,7 +50,7 @@
     
     private JoinStrategy joinStrategy;
     private JoinType joinType;
-    private DependentValueSource dependentValueSource;
+    private String dependentValueSource;
    
     // Set up state - need to be cloned but not reset
     private List leftExpressions;
@@ -133,21 +132,9 @@
         
         clonedNode.joinCriteria = this.joinCriteria;
         
-        if (leftExpressions != null) {
-            List leftCopy = new ArrayList(leftExpressions.size());
-            for(int i=0; i<leftExpressions.size(); i++) {
-                leftCopy.add(((Expression)leftExpressions.get(i)).clone());
-            }
-            clonedNode.leftExpressions = leftCopy;
-        }
+        clonedNode.leftExpressions = leftExpressions;
         
-        if (rightExpressions != null) {
-            List rightCopy = new ArrayList(rightExpressions.size());
-            for(int i=0; i<rightExpressions.size(); i++) {
-                rightCopy.add(((Expression)rightExpressions.get(i)).clone());
-            }
-            clonedNode.rightExpressions = rightCopy;
-        }
+        clonedNode.rightExpressions = rightExpressions;
         clonedNode.dependentValueSource = this.dependentValueSource;
         
         return clonedNode;
@@ -168,7 +155,7 @@
         if (state == State.LOAD_RIGHT) {
             if (isDependent() && !this.rightOpened) { 
                 TupleSourceID tsID = this.joinStrategy.leftSource.getTupleSourceID();
-                this.dependentValueSource.setTupleSource(this.getBufferManager().getTupleSource(tsID), tsID);
+                this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, new DependentValueSource(tsID, this.getBufferManager()));
                 //open the right side now that the tuples have been collected
                 this.getChildren()[1].open();
                 this.rightOpened = true;
@@ -259,7 +246,7 @@
     /** 
      * @param isDependent The isDependent to set.
      */
-    public void setDependentValueSource(DependentValueSource dependentValueSource) {
+    public void setDependentValueSource(String dependentValueSource) {
         this.dependentValueSource = dependentValueSource;
     }
     

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/LimitNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -150,15 +150,8 @@
     }
     
     public Object clone() {
-        Expression clonedLimit = null;
-        if (limitExpr != null) {
-        	clonedLimit = (Expression)limitExpr.clone();
-        }
-        Expression clonedOffset = null;
-        if (offsetExpr != null) {
-            clonedOffset = (Expression)offsetExpr.clone();
-        }
-        LimitNode node = new LimitNode(getID(), clonedLimit, clonedOffset);
+        
+        LimitNode node = new LimitNode(getID(), limitExpr, offsetExpr);
         copy(this, node);
         node.rowCounter = this.rowCounter;
         return node;

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectIntoNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -203,8 +203,8 @@
         ProjectIntoNode clonedNode = new ProjectIntoNode(super.getID());
         super.copy(this, clonedNode);
 
-        clonedNode.intoGroup = (GroupSymbol) intoGroup.clone();
-        clonedNode.intoElements = new ArrayList(intoElements);
+        clonedNode.intoGroup = intoGroup;
+        clonedNode.intoElements = intoElements;
         clonedNode.modelName = this.modelName;
         clonedNode.doBatching = this.doBatching;
         clonedNode.doBulkInsert = this.doBulkInsert;

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -36,7 +36,6 @@
 import com.metamatrix.core.util.Assertion;
 import com.metamatrix.query.eval.Evaluator;
 import com.metamatrix.query.execution.QueryExecPlugin;
-import com.metamatrix.query.sql.LanguageObject;
 import com.metamatrix.query.sql.symbol.AggregateSymbol;
 import com.metamatrix.query.sql.symbol.AliasSymbol;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -288,13 +287,7 @@
 
     protected void copy(ProjectNode source, ProjectNode target){
         super.copy(source, target);
-        if(selectSymbols != null){
-        	List clonedSymbols = new ArrayList(source.selectSymbols.size());
-        	for (LanguageObject obj : (List<LanguageObject>)this.selectSymbols) {
-        		clonedSymbols.add(obj.clone());
-        	}
-            target.setSelectSymbols(clonedSymbols);
-        }
+        target.selectSymbols = this.selectSymbols;
     }
 
     /*

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SelectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -170,12 +170,8 @@
 	
 	protected void copy(SelectNode source, SelectNode target){
 		super.copy(source, target);
-		if(criteria != null){
-			target.setCriteria((Criteria)source.criteria.clone());
-		}
-		if(elementMap != null){
-			target.elementMap = new HashMap(source.elementMap);
-		}
+		target.criteria = criteria;
+		target.elementMap = source.elementMap;
 	}
     
     /* 

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SourceState.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -38,8 +38,7 @@
     private IndexedTupleSource tupleSource;
     private TupleSourceID tsID;
     private List<Object> outerVals;
-    private TupleSourceIterator iterator;
-    private List expressions;
+    private IndexedTupleSource iterator;
     private int[] expressionIndexes;
     private List currentTuple;
     private int maxProbeMatch = 1;
@@ -65,7 +64,7 @@
     }
     
     public List saveNext() throws MetaMatrixComponentException, MetaMatrixProcessingException {
-        this.currentTuple = this.getIterator().next();
+        this.currentTuple = this.getIterator().nextTuple();
         return currentTuple;
     }
     
@@ -112,10 +111,10 @@
         }
     }
     
-    TupleSourceIterator getIterator() {
+    IndexedTupleSource getIterator() {
         if (this.iterator == null) {
             if (this.tupleSource != null) {
-                iterator = new IndexedTupleSourceIterator(this.tupleSource);
+                iterator = this.tupleSource;
             } else {
                 // return a TupleBatch tuplesource iterator
                 iterator = new BatchIterator(this.source);

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/SubqueryProcessorUtility.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -30,62 +30,30 @@
 import com.metamatrix.api.exception.MetaMatrixProcessingException;
 import com.metamatrix.common.buffer.BlockedException;
 import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.IndexedTupleSource;
 import com.metamatrix.common.buffer.TupleSourceID;
 import com.metamatrix.common.buffer.TupleSourceNotFoundException;
 import com.metamatrix.core.MetaMatrixCoreException;
 import com.metamatrix.query.eval.Evaluator;
 import com.metamatrix.query.processor.ProcessorPlan;
 import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.sql.lang.SubqueryContainer;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorProvider;
 import com.metamatrix.query.sql.util.VariableContext;
 import com.metamatrix.query.util.CommandContext;
 
 /**
  * <p>This utility handles the work of processing a subquery; certain types
  * of processor nodes will use an instance of this class to do that work.
- * All the corresponding "child" or "sub" ProcessorPlans
- * (one for each ValueIteratorProvider) must be processed before the
- * client processor node can do it's work.</p>
- *
- * <p>For example, a DependentSelectNode is basically a select node where
- * part of the criteria is a subquery.  The criteria cannot be evaluated
- * until the values of the subquery result are available.  A
- * DependentProjectNode is a project node where one of the projected
- * symbols is a scalar subquery.  That project cannot be performed until
- * the scalar subquery is executed and it's value is available so that the
- * subquery can be evaluated as an expression.</p>
- *
- * <p>The ValueIteratorProvider interface abstracts a language object that
- * needs to have it's subquery processed and the resulting values given to
- * it.  This utility class does the processing of the subquery ProcessorPlan,
- * and provides the ValueIteratorProvider instance with a ValueIterator
- * instance, which iterates over the subquery results.</p>
  */
 public class SubqueryProcessorUtility {
 	
-	/**
-     * List of ProcessorPlans for each subquery.  Contents match
-     * 1-for-1 with the contents of {@link #valueIteratorProviders} List
-     * see {@link #setPlansAndValueProviders}
-     */
-	private List<ProcessorPlan> processorPlans = new ArrayList<ProcessorPlan>();
-	private List<QueryProcessor> processors = new ArrayList<QueryProcessor>();
+	private List<? extends ProcessorPlan> processorPlans;
+	private List<String> contextReferences;
+	private SymbolMap correlatedReferences;
 
-	/**
-     * List of ValueIteratorProvider for each subquery.  Contents match
-     * 1-for-1 with the contents of {@link #processorPlans} List
-     * see {@link #setPlansAndValueProviders}
-     */
-	private List<ValueIteratorProvider> valueIteratorProviders;
-
-    private SymbolMap correlatedReferences;
-
+	private List<QueryProcessor> processors = new ArrayList<QueryProcessor>();
+    
 	// "Placeholder" state, for resuming processing after
 	// a BlockedException - not cloned
 	private int currentIndex = 0;
@@ -97,25 +65,26 @@
 	
 	private VariableContext currentContext;
 
-	public SubqueryProcessorUtility(List<ValueIteratorProvider> valList, SymbolMap references) {
-		for (ValueIteratorProvider val : valList) {
-			SubqueryContainer sc = (SubqueryContainer)val;
-			this.processorPlans.add((ProcessorPlan)sc.getCommand().getProcessorPlan().clone());
-		}
-		this.valueIteratorProviders = valList;
+	public SubqueryProcessorUtility(List<? extends ProcessorPlan> valList, List<String> contextReferences, SymbolMap references) {
+		this.processorPlans = valList;
+		this.contextReferences = contextReferences;
 		if (references != null && !references.asMap().isEmpty()) {
 			this.correlatedReferences = references;
 		}
 	}
+	
+	public SubqueryProcessorUtility clone() {
+		List<ProcessorPlan> plans = new ArrayList<ProcessorPlan>(processorPlans.size());
+		for (ProcessorPlan processorPlan : processorPlans) {
+			plans.add((ProcessorPlan)processorPlan.clone());
+		}
+		return new SubqueryProcessorUtility(plans, contextReferences, correlatedReferences);
+	}
 
-	List<ProcessorPlan> getSubqueryPlans(){
+	List<? extends ProcessorPlan> getSubqueryPlans(){
 		return this.processorPlans;
 	}
 
-	List getValueIteratorProviders(){
-		return this.valueIteratorProviders;
-	}
-
 	void reset() {
 		this.currentIndex = 0;
 		currentProcessor = null;
@@ -212,10 +181,8 @@
 			}
 
 			// Process the results
-			IndexedTupleSource subqueryResults = null;
 			try {
 				this.currentProcessor.process(Integer.MAX_VALUE);
-				subqueryResults = parent.getBufferManager().getTupleSource(this.currentProcessor.getResultsID());
 				this.currentProcessor.getProcessorPlan().reset();
 			} catch (MetaMatrixProcessingException e) {
 				throw e;
@@ -226,9 +193,7 @@
 			}
 
 			// Set the results on the ValueIteratorProviders
-            ValueIteratorProvider vip = this.valueIteratorProviders.get(this.currentIndex);
-            ValueIterator iterator = new TupleSourceValueIterator(subqueryResults, 0);
-			vip.setValueIterator(iterator);
+			parent.getContext().getVariableContext().setGlobalValue(this.contextReferences.get(this.currentIndex), new DependentValueSource(this.currentProcessor.getResultsID(), parent.getBufferManager()));
 
             this.currentProcessor = null;
 			this.currentIndex++;

Deleted: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceIterator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceIterator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceIterator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.processor.relational;
-
-import java.util.List;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-
-/** 
- * @since 4.3
- */
-interface TupleSourceIterator {
-
-    /**
-     * @see java.util.Iterator#hasNext()
-     */
-    boolean hasNext() throws MetaMatrixComponentException, MetaMatrixProcessingException;
-
-    /**
-     * Returns constant Object values, not Expressions.
-     * @see java.util.Iterator#next()
-     */
-    List next() throws MetaMatrixComponentException, MetaMatrixProcessingException;
-
-    /**
-     * Flags a reset as being needed
-     * @see com.metamatrix.query.sql.util.ValueIterator#reset()
-     */
-    void reset();
-    
-    void mark();
-    
-    int getCurrentIndex();
-    
-    void setPosition(int position);
-    
-    //int available();
-
-}
\ No newline at end of file

Modified: trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceValueIterator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceValueIterator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/processor/relational/TupleSourceValueIterator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -37,11 +37,11 @@
  */
 class TupleSourceValueIterator implements ValueIterator{
 
-    private TupleSourceIterator tupleSourceIterator;
+    private IndexedTupleSource tupleSourceIterator;
     private int columnIndex;
     
     TupleSourceValueIterator(IndexedTupleSource tupleSource, int columnIndex){
-        this.tupleSourceIterator = new IndexedTupleSourceIterator(tupleSource);
+        this.tupleSourceIterator = tupleSource;
         this.columnIndex = columnIndex;
 	}
     
@@ -62,7 +62,7 @@
 	 */
 	public Object next() throws MetaMatrixComponentException{
 	    try {
-            return tupleSourceIterator.next().get(columnIndex);
+            return tupleSourceIterator.nextTuple().get(columnIndex);
         } catch (MetaMatrixProcessingException err) {
             throw new MetaMatrixComponentException(err, err.getMessage());
         }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/AbstractSetCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/AbstractSetCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/AbstractSetCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -23,15 +23,13 @@
 package com.metamatrix.query.sql.lang;
 
 import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.ValueIteratorProvider;
 
 /**
  * This is an abstract class to define some common functionality in the two varieties of 
  * IN criteria:  {@link SetCriteria} (where values are specified) and {@link SubquerySetCriteria}
  * (where a subquery is defined and will supply the values for the IN set).  
  */
-public abstract class AbstractSetCriteria extends PredicateCriteria 
-implements ValueIteratorProvider{
+public abstract class AbstractSetCriteria extends PredicateCriteria {
 
     /** The left expression */
     private Expression expression;

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/DependentSetCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/DependentSetCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/DependentSetCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,15 +22,11 @@
 
 package com.metamatrix.query.sql.lang;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
 import com.metamatrix.core.util.EquivalenceUtil;
 import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorSource;
-import com.metamatrix.query.util.ErrorMessageKeys;
 
 
 /** 
@@ -39,45 +35,28 @@
  * by a separate processing node.
  * @since 5.0.1
  */
-public class DependentSetCriteria extends AbstractSetCriteria {
-
+public class DependentSetCriteria extends AbstractSetCriteria implements ContextReference {
+	
     /**
-     * Specifies who will provide the value iterator later during execution.  The
-     * ValueIterator is typically not ready yet, so we can't hold it directly.
-     */
-    private ValueIteratorSource valueIteratorSource;
-    
-    /**
      * Specifies the expression whose values we want to return in the iterator
      */
     private Expression valueExpression;
+    private String id;
     
     /** 
      * Construct with the left expression 
      */
-    public DependentSetCriteria(Expression expr) {
+    public DependentSetCriteria(Expression expr, String id) {
         setExpression(expr);
+        this.id = id;
     }    
-
-    /** 
- 	 * Get the valute iterator source, which will provide the iterator
-     * when it is ready during processing.   
-     * @return Returns the valueIteratorSource.
-     */
-    public ValueIteratorSource getValueIteratorSource() {
-        return this.valueIteratorSource;
+        
+    @Override
+    public String getContextSymbol() {
+    	return id;
     }
 
-    
     /** 
-     * Set the value iterator source, which will provide value iterators during processing.
-     * @param valueIteratorSource The valueIteratorSource to set.
-     */
-    public void setValueIteratorSource(ValueIteratorSource valueIteratorSource) {
-        this.valueIteratorSource = valueIteratorSource;
-    }    
-    
-    /** 
      * Get the independent value expression
      * @return Returns the valueExpression.
      */
@@ -94,25 +73,6 @@
         this.valueExpression = valueExpression;
     }
     
-    /**
-     * Returns a ValueIterator to obtain the values in this IN criteria's value set.
-     * This method can only be safely called if the ValueIteratorSource is ready.
-     * @return this object's ValueIterator instance 
-     * @throws MetaMatrixRuntimeException if the subquery for this set criteria
-     * has not yet been processed and no value iterator is available
-     * @see com.metamatrix.query.sql.lang.AbstractSetCriteria#getValueIterator()
-     */
-    public ValueIterator getValueIterator() {
-        ValueIterator valueIterator = this.valueIteratorSource.getValueIterator(this.valueExpression);
-        
-        if(valueIterator == null) {
-            throw new MetaMatrixRuntimeException(ErrorMessageKeys.SQL_0012, QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0012));
-        }
-        
-        valueIterator.reset();
-        return valueIterator;
-    }
-
     public void acceptVisitor(LanguageVisitor visitor) {
         visitor.visit(this);
     }
@@ -165,21 +125,11 @@
             copy = (Expression) getExpression().clone();
         }
 
-        DependentSetCriteria criteriaCopy = new DependentSetCriteria(copy);
+        DependentSetCriteria criteriaCopy = new DependentSetCriteria(copy, id);
         criteriaCopy.setNegated(isNegated());
-        criteriaCopy.setValueIteratorSource(getValueIteratorSource());
         criteriaCopy.setValueExpression((Expression) getValueExpression().clone());
+        criteriaCopy.id = this.id;
         return criteriaCopy;
     }
     
-    /** 
-     * This method is not supported for DependentSetCriteria as it will obtain it's 
-     * value iterators for the ValueIteratorSource.
-     * @see com.metamatrix.query.sql.lang.AbstractSetCriteria#setValueIterator(com.metamatrix.query.sql.util.ValueIterator)
-     * @throws UnsupportedOperationException Always
-     */
-    public void setValueIterator(ValueIterator valueIterator) {
-        throw new UnsupportedOperationException("DependentSetCriteria.setValueIterator() should never be called as the value iterator is produced dynamically."); //$NON-NLS-1$
-    }
-    
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ExistsCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ExistsCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/ExistsCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,14 +22,13 @@
 
 package com.metamatrix.query.sql.lang;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import com.metamatrix.core.util.EquivalenceUtil;
 import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorProvider;
-import com.metamatrix.query.util.ErrorMessageKeys;
+import com.metamatrix.query.sql.symbol.ContextReference;
+import com.metamatrix.query.sql.symbol.Expression;
 
 /**
  * This predicate criteria implements the "exists" predicate, which has
@@ -37,10 +36,12 @@
  * "EXISTS (Select EmployeeID FROM Employees WHERE EmployeeName = 'Smith')".
  */
 public class ExistsCriteria extends PredicateCriteria
-implements SubqueryContainer, ValueIteratorProvider {
+implements SubqueryContainer, ContextReference {
+	
+	private static AtomicInteger ID = new AtomicInteger();
 
     private Command command;
-    private ValueIterator valueIterator;
+    private String id = "$ec/id" + ID.getAndIncrement(); //$NON-NLS-1$
 
     /**
      * Default constructor
@@ -52,6 +53,16 @@
     public ExistsCriteria(Command subqueryCommand){
         this.command = subqueryCommand;
     }
+    
+    @Override
+    public String getContextSymbol() {
+    	return id;
+    }
+    
+    @Override
+    public Expression getValueExpression() {
+    	return null;
+    }
 
     /**
      * @see com.metamatrix.query.sql.lang.SubqueryCriteria#getCommand()
@@ -64,35 +75,6 @@
         this.command = subqueryCommand;
     }
 
-    /**
-     * Returns always the same instance of a ValueIterator, but
-     * {@link ValueIterator#reset resets} it each time this method is called
-     * @return this object's ValueIterator instance (always the same instance)
-     * @throws MetaMatrixRuntimeException if the subquery for this set criteria
-     * has not yet been processed and no value iterator is available
-     * @see com.metamatrix.query.sql.lang.AbstractSetCriteria#getValueIterator()
-     */
-    public ValueIterator getValueIterator() {
-        if (this.valueIterator == null){
-            throw new MetaMatrixRuntimeException(ErrorMessageKeys.SQL_0034, QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0034));
-        }
-        this.valueIterator.reset();
-        return this.valueIterator;
-    }
-
-    /**
-     * Set the ValueIterator on this object (the ValueIterator will encapsulate
-     * the single-column results of the subquery processor plan).  This
-     * ValueIterator must be set before processing (before the Criteria can be
-     * evaluated).  Also, this ValueIterator should be considered transient -
-     * only available during processing - and it will not be cloned should
-     * this Criteria object be cloned.
-     * @param valueIterator encapsulating the results of the sub query
-     */
-    public void setValueIterator(ValueIterator valueIterator) {
-        this.valueIterator = valueIterator;
-    }
-
     public void acceptVisitor(LanguageVisitor visitor) {
         visitor.visit(this);
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SetCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,13 +22,17 @@
 
 package com.metamatrix.query.sql.lang;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 
+import com.metamatrix.core.util.EquivalenceUtil;
 import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.sql.*;
+import com.metamatrix.query.sql.LanguageVisitor;
 import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.core.util.EquivalenceUtil;
-import com.metamatrix.query.sql.util.ValueIterator;
 
 /**
  * A criteria which is true is the expression's value is a member in a list 
@@ -78,25 +82,7 @@
         this.values = values;
     }
     
-	/**
-	 * Returns a new instance of a ValueIterator
-	 * @return new ValueIterator instance
-	 * @see com.metamatrix.query.sql.lang.AbstractSetCriteria#getValueIterator()
-	 */
-	public ValueIterator getValueIterator() {
-		return new CollectionValueIterator(this.values);
-	}    
-
     /**
-     * This method is purposely not implemented.  The values are
-     * set through the constructor or the {@link #setValues} method.
-     * @see com.metamatrix.query.sql.util.ValueIteratorProvider#setValueIterator(com.metamatrix.query.sql.util.ValueIterator)
-     */
-    public void setValueIterator(ValueIterator valueIterator) {
-        //Do nothing
-    }
-
-    /**
      * Sets the membership expression and the set of value expressions
      * @param expression The membership expression
      * @param values   The set of value expressions

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubqueryCompareCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubqueryCompareCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubqueryCompareCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,16 +22,14 @@
 
 package com.metamatrix.query.sql.lang;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import com.metamatrix.core.util.EquivalenceUtil;
 import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorProvider;
-import com.metamatrix.query.util.ErrorMessageKeys;
 
 /**
  * <p>This class implements a quantified comparison predicate.  This is
@@ -57,8 +55,10 @@
  * </UL>
  */
 public class SubqueryCompareCriteria extends AbstractCompareCriteria
-implements SubqueryContainer, ValueIteratorProvider{
+implements SubqueryContainer, ContextReference {
 
+	private static AtomicInteger ID = new AtomicInteger();
+
     /** "All" predicate quantifier */
     public static final int NO_QUANTIFIER = 1;
 
@@ -74,9 +74,8 @@
     private int predicateQuantifier = NO_QUANTIFIER;
 
     private Command command;
+    private String id = "$scc/id" + ID.getAndIncrement(); //$NON-NLS-1$
 
-    private ValueIterator valueIterator;
-
     public SubqueryCompareCriteria(){
         super();
     }
@@ -87,6 +86,16 @@
         setOperator(operator);
         setPredicateQuantifier(predicateQuantifier);
     }
+    
+    @Override
+    public String getContextSymbol() {
+    	return id;
+    }
+    
+    @Override
+    public Expression getValueExpression() {
+    	return null;
+    }
 
     /**
      * Get the predicate quantifier - returns one of the following:
@@ -128,35 +137,6 @@
     }
 
     /**
-     * Returns always the same instance of a ValueIterator, but
-     * {@link ValueIterator#reset resets} it each time this method is called
-     * @return this object's ValueIterator instance (always the same instance)
-     * @throws MetaMatrixRuntimeException if the subquery for this set criteria
-     * has not yet been processed and no value iterator is available
-     * @see com.metamatrix.query.sql.lang.SubqueryCriteria#getValueIterator()
-     */
-    public ValueIterator getValueIterator() {
-        if (this.valueIterator == null){
-            throw new MetaMatrixRuntimeException(ErrorMessageKeys.SQL_0034, QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0034));
-        }
-        this.valueIterator.reset();
-        return this.valueIterator;
-    }
-
-    /**
-     * Set the ValueIterator on this object (the ValueIterator will encapsulate
-     * the single-column results of the subquery processor plan).  This
-     * ValueIterator must be set before processing (before the Criteria can be
-     * evaluated).  Also, this ValueIterator should be considered transient -
-     * only available during processing - and it will not be cloned should
-     * this Criteria object be cloned.
-     * @param valueIterator encapsulating the results of the sub query
-     */
-    public void setValueIterator(ValueIterator valueIterator) {
-        this.valueIterator = valueIterator;
-    }
-
-    /**
      * Returns the predicate quantifier as a string.
      * @return String version of predicate quantifier
      */

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubquerySetCriteria.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubquerySetCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/SubquerySetCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,24 +22,25 @@
 
 package com.metamatrix.query.sql.lang;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import com.metamatrix.core.util.EquivalenceUtil;
 import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.util.ErrorMessageKeys;
 
 /**
  * A criteria which is true is the expression's value is a member in a list
  * of values returned from a subquery.  This criteria can be represented as
  * "<expression> IN (SELECT ...)".
  */
-public class SubquerySetCriteria extends AbstractSetCriteria implements SubqueryContainer {
+public class SubquerySetCriteria extends AbstractSetCriteria implements SubqueryContainer, ContextReference {
 
+	private static AtomicInteger ID = new AtomicInteger();
+
     private Command command;
-	private ValueIterator valueIterator;
+    private String id = "$ssc/id" + ID.getAndIncrement(); //$NON-NLS-1$
 
     /**
      * Constructor for SubquerySetCriteria.
@@ -52,6 +53,16 @@
         setExpression(expression);
         setCommand(subCommand);
     }
+    
+    @Override
+    public String getContextSymbol() {
+    	return id;
+    }
+    
+    @Override
+    public Expression getValueExpression() {
+    	return null;
+    }
 
     /**
      * Set the subquery command (either a SELECT or a procedure execution).
@@ -69,35 +80,6 @@
         return this.command;
     }
 
-	/**
-	 * Returns always the same instance of a ValueIterator, but
-	 * {@link ValueIterator#reset resets} it each time this method is called
-	 * @return this object's ValueIterator instance (always the same instance)
-     * @throws MetaMatrixRuntimeException if the subquery for this set criteria
-     * has not yet been processed and no value iterator is available
-	 * @see com.metamatrix.query.sql.lang.AbstractSetCriteria#getValueIterator()
-	 */
-	public ValueIterator getValueIterator() {
-        if (this.valueIterator == null){
-            throw new MetaMatrixRuntimeException(ErrorMessageKeys.SQL_0012, QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0012));
-        }
-        this.valueIterator.reset();
-		return this.valueIterator;
-	}
-
-	/**
-	 * Set the ValueIterator on this object (the ValueIterator will encapsulate
-	 * the single-column results of the subquery processor plan).  This
-	 * ValueIterator must be set before processing (before the Criteria can be
-	 * evaluated).  Also, this ValueIterator should be considered transient -
-	 * only available during processing - and it will not be cloned should
-	 * this Criteria object be cloned.
-	 * @param valueIterator encapsulating the results of the sub query
-	 */
-	public void setValueIterator(ValueIterator valueIterator) {
-		this.valueIterator = valueIterator;
-	}
-
     public void acceptVisitor(LanguageVisitor visitor) {
         visitor.visit(this);
     }

Added: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ContextReference.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ContextReference.java	                        (rev 0)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ContextReference.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.sql.symbol;
+
+public interface ContextReference {
+
+	public String getContextSymbol();
+	
+	public Expression getValueExpression();
+	
+}


Property changes on: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ContextReference.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/Reference.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -32,7 +32,7 @@
  * to an element from another scope).  This reference may resolve to many different values
  * during evaluation.  For any particular bound value, it is treated as a constant.
  */
-public class Reference implements Expression {
+public class Reference implements Expression, ContextReference {
 
     private boolean positional;
 
@@ -73,11 +73,18 @@
     public int getIndex() {
         return this.refIndex;
     }
+    
+    @Override
+    public String getContextSymbol() {
+    	return "$param/pos" + this.refIndex; //$NON-NLS-1$
+    }
+    
+    @Override
+    public Expression getValueExpression() {
+    	return this.expression;
+    }
 
     public ElementSymbol getExpression() {
-    	if (this.isPositional() && this.expression == null) {
-    		return new ElementSymbol("$param/pos" + this.refIndex); //$NON-NLS-1$
-    	}
         return this.expression;    
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,15 +22,12 @@
 
 package com.metamatrix.query.sql.symbol;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.query.QueryPlugin;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import com.metamatrix.query.sql.LanguageVisitor;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.SubqueryContainer;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorProvider;
 import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-import com.metamatrix.query.util.ErrorMessageKeys;
 
 /**
  * This is an Expression implementation that can be used in a SELECT clause.
@@ -40,16 +37,15 @@
  * of this could be used wherever an Expression is legal, but it is
  * specifically needed for the SELECT clause.
  */
-public class ScalarSubquery implements Expression, SubqueryContainer, ValueIteratorProvider {
+public class ScalarSubquery implements Expression, SubqueryContainer, ContextReference {
 
+	private static AtomicInteger ID = new AtomicInteger();
+	
     private Command command;
     private Class type;
     private int hashCode;
+    private String id = "$sc/id" + ID.getAndIncrement(); //$NON-NLS-1$
 
-    // This is "transient" state, available only during query
-    // processing.  It is not cloned, if present.
-    private ValueIterator valueIterator;
-
     /**
      * Default constructor
      */
@@ -60,34 +56,15 @@
     public ScalarSubquery(Command subqueryCommand){
         this.setCommand(subqueryCommand);
     }
-
-    /**
-     * Returns always the same instance of a ValueIterator, but
-     * {@link ValueIterator#reset resets} it each time this method is called
-     * @return this object's ValueIterator instance (always the same instance)
-     * @throws MetaMatrixRuntimeException if the subquery for this set criteria
-     * has not yet been processed and no value iterator is available
-     * @see com.metamatrix.query.sql.lang.SubqueryLanguageObject#getValueIterator()
-     */
-    public ValueIterator getValueIterator() {
-        if (this.valueIterator == null){
-            throw new MetaMatrixRuntimeException(ErrorMessageKeys.SQL_0034, QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0034));
-        }
-        this.valueIterator.reset();
-        return this.valueIterator;
+    
+    @Override
+    public String getContextSymbol() {
+    	return id;
     }
-
-    /**
-     * Set the ValueIterator on this object (the ValueIterator will encapsulate
-     * the single-column results of the subquery processor plan).  This
-     * ValueIterator must be set before processing (before the Criteria can be
-     * evaluated).  Also, this ValueIterator should be considered transient -
-     * only available during processing - and it will not be cloned should
-     * this Criteria object be cloned.
-     * @param valueIterator encapsulating the results of the sub query
-     */
-    public void setValueIterator(ValueIterator valueIterator) {
-        this.valueIterator = valueIterator;
+    
+    @Override
+    public Expression getValueExpression() {
+    	return null;
     }
 
     /**

Deleted: trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorProvider.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorProvider.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorProvider.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.sql.util;
-
-import com.metamatrix.query.sql.LanguageObject;
-
-/**
- * <p>Language Object Implementors of this interface will provide a 
- * {@link ValueIterator} over one or potentially more values
- * that they have.</p>  
- * 
- * <p>Also, in some cases implementors may need to
- * have their value iterators given to them by some external
- * entity, so there is a setter method in this interface.</p>  
- */
-public interface ValueIteratorProvider extends LanguageObject {
-
-    /**
-     * Get the {@link ValueIterator} from this ValueIterator provider
-     * @return ValueIterator over the values of this instance
-     */
-    ValueIterator getValueIterator();
-
-    /**
-     * Set the {@link ValueIterator} instance on this ValueIterator
-     * provider.  Note that the implementor may choose to not
-     * implement this method, and the method call would have no 
-     * effect.
-     * @param valueIterator an instance of ValueIterator to be set
-     * on this ValueIterator provider (as in the case of subquery
-     * containers whose results are provided externally).
-     */
-    void setValueIterator(ValueIterator valueIterator);
-
-}

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorSource.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/ValueIteratorSource.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,6 +22,8 @@
 
 package com.metamatrix.query.sql.util;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.buffer.TupleSourceNotFoundException;
 import com.metamatrix.query.sql.symbol.Expression;
 
 
@@ -39,14 +41,10 @@
      * not ready yet, return null to indicate that.
      * @param valueExpression The expression we are retrieving an iterator for  
      * @return ValueIterator if ready, null otherwise
+     * @throws MetaMatrixComponentException 
+     * @throws TupleSourceNotFoundException 
      * @since 5.0.1
      */
-    ValueIterator getValueIterator(Expression valueExpression);
+    ValueIterator getValueIterator(Expression valueExpression) throws MetaMatrixComponentException;
     
-    /**
-     * Check whether the source is ready to provide valid iterators
-     * @return True if iterator is ready
-     */
-    boolean isReady();
-    
 }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/util/VariableContext.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -25,7 +25,10 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.util.ErrorMessageKeys;
 
 public class VariableContext {
 
@@ -48,8 +51,27 @@
     	this.variableMap = new HashMap();
     }
 
+    public void setGlobalValue(String variable, Object value) {
+    	if (this.parentContext != null) {
+    		this.parentContext.setGlobalValue(variable, value);
+    	} else {
+    		variableMap.put(variable, value);
+    	}
+    }
+    
+    public Object getGlobalValue(String variable) throws MetaMatrixComponentException {
+    	if (this.parentContext != null) {
+    		return this.parentContext.getGlobalValue(variable);
+    	} 
+    	Object value = variableMap.get(variable);
+    	if (value == null && !variableMap.containsKey(variable)) {
+    		throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, variable, "No value was available")); //$NON-NLS-1$
+    	}
+    	return value;
+    }
+    
     /**
-     * Set the value for the given, if the variable aready exits replaces its value
+     * Set the value for the given, if the variable already exits replaces its value
      * with the given value else adds a new variable to the map.
      * @param variable The <code>ElementSymbol</code> to be added as a variable.
      * @param value The value to be set for the given variable.
@@ -135,6 +157,7 @@
             if(this.parentContext != null) {
                 return this.parentContext.isEmpty();
             }
+            return true;
         }
         return false;
     }

Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluateExpressionVisitor.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,33 +22,21 @@
 
 package com.metamatrix.query.sql.visitor;
 
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.MetaMatrixException;
 import com.metamatrix.api.exception.query.ExpressionEvaluationException;
 import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.eval.Evaluator;
 import com.metamatrix.query.eval.LookupEvaluator;
 import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.DependentSetCriteria;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SetCriteria;
 import com.metamatrix.query.sql.navigator.DeepPostOrderNavigator;
 import com.metamatrix.query.sql.navigator.PostOrderNavigator;
 import com.metamatrix.query.sql.symbol.Constant;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.util.ValueIterator;
+import com.metamatrix.query.sql.symbol.ScalarSubquery;
 import com.metamatrix.query.util.CommandContext;
 
 /**
@@ -64,80 +52,14 @@
     private CommandContext context;
     private LookupEvaluator dataMgr;
         
-    public EvaluateExpressionVisitor() {
+    EvaluateExpressionVisitor() {
         super(null);
     }
 
     public void setContext(CommandContext context) {
         this.context = context;
     }
-                                
-    // ######### Visit methods that are replacing DependentSetCriteria with resolved SetCriteria ########
-    
-    public void visit(CompoundCriteria obj) {
-        List crit = obj.getCriteria();
-        List newCrit = new ArrayList(crit.size());
-        Iterator iter = crit.iterator();
-        while(iter.hasNext()) {
-            newCrit.add(checkDependentCriteria((Criteria) iter.next()));
-        }
-        obj.setCriteria(newCrit);
-    }
 
-    public void visit(JoinPredicate obj) {
-        List joinCrit = obj.getJoinCriteria();
-        List newCrit = new ArrayList(joinCrit.size());
-        Iterator iter = joinCrit.iterator();
-        while(iter.hasNext()) {
-            newCrit.add(checkDependentCriteria((Criteria) iter.next()));
-        }
-        obj.setJoinCriteria(newCrit);
-    }
-
-    public void visit(Query obj) {
-        obj.setCriteria(checkDependentCriteria(obj.getCriteria()));
-        obj.setHaving(checkDependentCriteria(obj.getHaving()));
-    }
-
-    private Criteria checkDependentCriteria(Criteria crit) {
-        if (!(crit instanceof DependentSetCriteria)) {
-            return crit;
-        }
-        return replaceDependentCriteria((DependentSetCriteria)crit);            
-    }
-
-    public Criteria replaceDependentCriteria(DependentSetCriteria crit) {
-        ValueIterator iter = crit.getValueIterator();
-        if(iter == null) {
-            // Something has gone horribly wrong!  This should never happen
-            Assertion.failed(QueryPlugin.Util.getString("EvaluateExpressionVisitor.Cant_get_iterator", crit.getValueExpression().toString())); //$NON-NLS-1$
-        }
-            
-        try {
-            List vals = new ArrayList();
-            while(iter.hasNext()) {
-                Object val = iter.next();
-                if(val != null) {
-                    vals.add(new Constant(val));
-                }
-            }
-            
-            if(vals.size() > 0) {                    
-                SetCriteria sc = new SetCriteria();
-                sc.setExpression(crit.getExpression());
-                sc.setValues(vals);
-                return sc;
-            }
-            
-            // No values - return criteria that is always false
-            return new CompareCriteria(new Constant(new Integer(0)), CompareCriteria.EQ, new Constant(new Integer(1)));
-            
-        } catch(MetaMatrixComponentException e) {
-            throw new MetaMatrixRuntimeException(e);
-        }
-    }
-    
-
     /**
      * Evaluate the expression.  This method takes into account whether the 
      * Expression CAN be evaluated or not.  
@@ -151,12 +73,8 @@
      * @return
      */
     public Expression replaceExpression(Expression expr) {
-        if(!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr).isEmpty()) {
-            return expr;
-        }
-               
         //if the expression is a constant or is not evaluatable, just return
-        if (expr instanceof Constant || (!(expr instanceof Reference) && !EvaluatableVisitor.isEvaluatable(expr, false, true, false, false))) {
+        if (expr instanceof Constant || expr instanceof ScalarSubquery || (!(expr instanceof Reference) && !EvaluatableVisitor.isEvaluatable(expr, false, true, false, false))) {
             return expr;
         }
 

Modified: trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/com/metamatrix/query/util/CommandContext.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -28,13 +28,20 @@
 import java.util.Stack;
 import java.util.TimeZone;
 
+import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.api.exception.query.QueryProcessingException;
 import com.metamatrix.common.util.PropertiesUtils;
 import com.metamatrix.core.util.ArgCheck;
+import com.metamatrix.query.QueryPlugin;
 import com.metamatrix.query.eval.SecurityFunctionEvaluator;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.optimizer.relational.PlanToProcessConverter;
 import com.metamatrix.query.processor.QueryProcessor;
+import com.metamatrix.query.sql.symbol.ContextReference;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.util.ValueIterator;
+import com.metamatrix.query.sql.util.ValueIteratorSource;
 import com.metamatrix.query.sql.util.VariableContext;
 
 /** 
@@ -89,7 +96,7 @@
     
     private QueryProcessor.ProcessorFactory queryProcessorFactory;
     
-    private VariableContext variableContext;
+    private VariableContext variableContext = new VariableContext();
     
     /**
      * Construct a new context.
@@ -403,4 +410,25 @@
 		toPush.setParentContext(this.variableContext);
 		this.variableContext = toPush;
 	}
+	
+	public Object getFromContext(Expression expression) throws MetaMatrixComponentException {
+		if (variableContext == null || !(expression instanceof ElementSymbol)) {
+			throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
+		}
+		Object value = variableContext.getValue((ElementSymbol)expression);
+		if (value == null && !variableContext.containsVariable((ElementSymbol)expression)) {
+			throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
+		}
+		return value;
+	}
+	
+	public ValueIterator getValueIterator(ContextReference ref)
+			throws MetaMatrixComponentException {
+		if (variableContext == null) {
+			throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, ref.getContextSymbol(), "No value was available")); //$NON-NLS-1$
+		}
+		ValueIteratorSource dvs = (ValueIteratorSource) this.variableContext.getGlobalValue(ref.getContextSymbol());
+		return dvs.getValueIterator(ref.getValueExpression());
+	}
+
 }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -228,7 +228,7 @@
 		}
 		
 		if (paramValues.size() > 1) {
-			this.context.setVariableContext(null);
+			this.context.setVariableContext(new VariableContext());
 		} 
 		
 		if (supportPreparedBatchUpdate || paramValues.size() == 1) {
@@ -287,7 +287,7 @@
 	        }
 	        	        
 	        //bind variable
-	        result.setValue(param.getExpression(), value);
+	        result.setGlobalValue(param.getContextSymbol(), value);
 	    }
 	    
 	    context.setVariableContext(result);

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/multisource/MultiSourcePlanToProcessConverter.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -99,7 +99,7 @@
             instanceNode.setConnectorBindingId(bindingUUID);
             
             // Modify the command to pull the instance column and evaluate the criteria
-            Command command = instanceNode.getCommand();
+            Command command = (Command)instanceNode.getCommand().clone();
             
             // Replace all multi-source elements with the source name
             DeepPreOrderNavigator.doVisit(command, new MultiSourceElementReplacementVisitor(bindingName));

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -167,7 +167,7 @@
     }
     
     @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$
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1 in (1,2,3) and param2 in ('a', 'b') order by param1, param2"; //$NON-NLS-1$
 
         // Create expected results
         List[] expected = new List[] { 

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -5479,7 +5479,7 @@
         // Collect reference, set value
         Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
         VariableContext vc = new VariableContext();
-        vc.setValue(ref.getExpression()	, "a    "); //$NON-NLS-1$
+        vc.setGlobalValue(ref.getContextSymbol(),  "a    "); //$NON-NLS-1$
         CommandContext context = createCommandContext();
         context.setVariableContext(vc);
         // Run query
@@ -5521,7 +5521,7 @@
         // Collect reference, set value
         Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
         VariableContext vc = new VariableContext();
-        vc.setValue(ref.getExpression()	, "a"); //$NON-NLS-1$
+        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
         CommandContext context = createCommandContext();
         context.setVariableContext(vc);
         
@@ -7870,7 +7870,7 @@
         
         Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
         VariableContext vc = new VariableContext();
-        vc.setValue(ref.getExpression(), "a"); //$NON-NLS-1$
+        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
         CommandContext context = createCommandContext();
         context.setVariableContext(vc);
         

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -45,7 +45,10 @@
 import com.metamatrix.query.sql.lang.SetCriteria;
 import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
 import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.util.ValueIterator;
+import com.metamatrix.query.util.CommandContext;
 
 public class TestCriteriaEvaluator extends TestCase {
 
@@ -91,15 +94,21 @@
         assertEquals("Result did not match expected value", expectedMatch, result); //$NON-NLS-1$
     }
         
-    private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException{
+    private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult, final Collection values) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException{
         
         Map elementMap = new HashMap();
         ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$
         elementMap.put(e1, new Integer(0));
         
         List tuple = Arrays.asList(new String[]{"a"}); //$NON-NLS-1$
-        
-        assertEquals(expectedResult, new Evaluator(elementMap, null, null).evaluate(crit, tuple));
+        CommandContext cc = new CommandContext() {
+        	@Override
+        	public ValueIterator getValueIterator(ContextReference ref)
+        			throws MetaMatrixComponentException {
+        		return new CollectionValueIterator(values);
+        	}
+        };
+        assertEquals(expectedResult, new Evaluator(elementMap, null, cc).evaluate(crit, tuple));
     }
 
     private SubqueryCompareCriteria helpGetCompareSubqueryCriteria(int operator, int predicateQuantifier){
@@ -381,18 +390,12 @@
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        
-        assertTrue( Evaluator.evaluate(crit) );
+        helpTestCompareSubqueryCriteria(crit, true, values);
     }
 
     public void testExistsCriteria2() throws Exception {
         ExistsCriteria crit = new ExistsCriteria(new Query());
-        CollectionValueIterator valueIter = new CollectionValueIterator(Collections.EMPTY_LIST);
-        crit.setValueIterator(valueIter);
-        
-        assertFalse( Evaluator.evaluate(crit) );
+        helpTestCompareSubqueryCriteria(crit, false, Collections.emptyList());
     }
 
     /**
@@ -405,10 +408,7 @@
         values.add(null);
         values.add(null);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        
-        assertTrue( Evaluator.evaluate(crit) );
+        helpTestCompareSubqueryCriteria(crit, true, values);
     }
 
     /**
@@ -417,9 +417,7 @@
      */
     public void testCompareSubqueryCriteriaNoRows() throws Exception {
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ALL);
-        CollectionValueIterator valueIter = new CollectionValueIterator(Collections.EMPTY_LIST);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, Collections.emptyList()); 
     }
 
     /**
@@ -428,9 +426,7 @@
      */
     public void testCompareSubqueryCriteriaNoRows2() throws Exception {
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.SOME);
-        CollectionValueIterator valueIter = new CollectionValueIterator(Collections.EMPTY_LIST);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, Collections.emptyList()); 
     }
 
     /**
@@ -439,9 +435,7 @@
      */
     public void testCompareSubqueryCriteriaNoRows3() throws Exception {
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
-        CollectionValueIterator valueIter = new CollectionValueIterator(Collections.EMPTY_LIST);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, Collections.emptyList()); 
     }
 
     public void testCompareSubqueryCriteria2() throws Exception {
@@ -450,9 +444,7 @@
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     public void testCompareSubqueryCriteria3() throws Exception {
@@ -461,9 +453,7 @@
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, values); 
     }
     
     public void testCompareSubqueryCriteria4() throws Exception {
@@ -471,9 +461,7 @@
         ArrayList values = new ArrayList();
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     public void testCompareSubqueryCriteria5() throws Exception {
@@ -482,27 +470,21 @@
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, values); 
     }
 
     public void testCompareSubqueryCriteria6() throws Exception {
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
         ArrayList values = new ArrayList();
         values.add("a"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, values); 
     }
 
     public void testCompareSubqueryCriteria7() throws Exception {
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
         ArrayList values = new ArrayList();
         values.add("b"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
 
@@ -517,10 +499,8 @@
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
         values.add("c"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
         try {
-        	helpTestCompareSubqueryCriteria(crit, false);
+        	helpTestCompareSubqueryCriteria(crit, false, values);
         } catch (CriteriaEvaluationException e) {
         	assertEquals("The subquery of this compare criteria has to be scalar, but returned more than one value: e1 = (<undefined>)", e.getMessage()); //$NON-NLS-1$
         }
@@ -530,9 +510,7 @@
         SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
         ArrayList values = new ArrayList();
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     public void testCompareSubqueryCriteriaNulls3() throws Exception {
@@ -540,9 +518,7 @@
         ArrayList values = new ArrayList();
         values.add(null);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     public void testCompareSubqueryCriteriaNulls4() throws Exception {
@@ -550,9 +526,7 @@
         ArrayList values = new ArrayList();
         values.add(null);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     public void testCompareSubqueryCriteriaNulls5() throws Exception {
@@ -561,9 +535,7 @@
         values.add(null);
         values.add("a"); //$NON-NLS-1$
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, values); 
     }
 
     public void testCompareSubqueryCriteriaNulls6() throws Exception {
@@ -572,9 +544,7 @@
         values.add("a"); //$NON-NLS-1$
         values.add(null);
         values.add("a"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, true); 
+        helpTestCompareSubqueryCriteria(crit, true, values); 
     }
 
     /**
@@ -585,9 +555,7 @@
         ArrayList values = new ArrayList();
         values.add(null);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 
     /**
@@ -598,8 +566,6 @@
         ArrayList values = new ArrayList();
         values.add(null);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        crit.setValueIterator(valueIter);
-        helpTestCompareSubqueryCriteria(crit, false); 
+        helpTestCompareSubqueryCriteria(crit, false, values); 
     }
 }

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -47,6 +47,7 @@
 import com.metamatrix.query.sql.symbol.AggregateSymbol;
 import com.metamatrix.query.sql.symbol.CaseExpression;
 import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.ContextReference;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
 import com.metamatrix.query.sql.symbol.Expression;
 import com.metamatrix.query.sql.symbol.Function;
@@ -55,6 +56,7 @@
 import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 import com.metamatrix.query.sql.symbol.TestCaseExpression;
 import com.metamatrix.query.sql.symbol.TestSearchedCaseExpression;
+import com.metamatrix.query.sql.util.ValueIterator;
 import com.metamatrix.query.sql.visitor.EvaluateExpressionVisitor;
 import com.metamatrix.query.util.CommandContext;
 
@@ -264,28 +266,35 @@
         ScalarSubquery expr = new ScalarSubquery(new Query());
         ArrayList values = new ArrayList(1);
         values.add("a"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        expr.setValueIterator(valueIter);
-        
-        assertEquals("a", Evaluator.evaluate(expr) ); //$NON-NLS-1$
+        Object expected = "a"; //$NON-NLS-1$
+        helpTestWithValueIterator(expr, values, expected);
     }
 
+	private void helpTestWithValueIterator(ScalarSubquery expr,
+			List<?> values, Object expected)
+			throws BlockedException,
+			MetaMatrixComponentException, ExpressionEvaluationException {
+		final CollectionValueIterator valueIter = new CollectionValueIterator(values);
+        CommandContext cc = new CommandContext() {
+        	@Override
+        	public ValueIterator getValueIterator(ContextReference ref)
+        			throws MetaMatrixComponentException {
+        		return valueIter;
+        	}
+        };
+        assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc).evaluate(expr, null) );
+	}
+
     public void testScalarSubquery2() throws Exception{
         ScalarSubquery expr = new ScalarSubquery(new Query());
         ArrayList values = new ArrayList(1);
         values.add(null);
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        expr.setValueIterator(valueIter);
-        
-        assertEquals(null, Evaluator.evaluate(expr) );
+        helpTestWithValueIterator(expr, values, null);
     }
 
     public void testScalarSubquery3() throws Exception{
         ScalarSubquery expr = new ScalarSubquery(new Query());
-        CollectionValueIterator valueIter = new CollectionValueIterator(Collections.EMPTY_LIST);
-        expr.setValueIterator(valueIter);
-        
-        assertEquals(null, Evaluator.evaluate(expr) );
+        helpTestWithValueIterator(expr, Collections.emptyList(), null);
     }
 
     public void testScalarSubqueryFails() throws Exception{
@@ -293,11 +302,9 @@
         ArrayList values = new ArrayList(2);
         values.add("a"); //$NON-NLS-1$
         values.add("b"); //$NON-NLS-1$
-        CollectionValueIterator valueIter = new CollectionValueIterator(values);
-        expr.setValueIterator(valueIter);
         
         try {
-        	Evaluator.evaluate(expr);
+        	helpTestWithValueIterator(expr, values, null);
             fail("Expected ExpressionEvaluationException but got none"); //$NON-NLS-1$
         } catch (ExpressionEvaluationException e) {
             assertEquals("Unable to evaluate (<undefined>): The command of this scalar subquery returned more than one value: <undefined>", e.getMessage()); //$NON-NLS-1$

Added: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java	                        (rev 0)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.query.processor.relational;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+import com.metamatrix.query.processor.relational.DependentAccessNode;
+import com.metamatrix.query.processor.relational.DependentCriteriaProcessor;
+import com.metamatrix.query.sql.lang.CompareCriteria;
+import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.SetCriteria;
+import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
+import com.metamatrix.query.util.CommandContext;
+
+public class TestDependentCriteriaProcessor {
+
+	@Test public void testNegatedSetCriteria() throws Exception {
+		DependentAccessNode dan = new DependentAccessNode(0);
+		SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2))); //$NON-NLS-1$
+		DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, dan, sc);
+		Criteria result = dcp.prepareCriteria();
+		assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$ 
+		assertTrue(dcp.hasNextCommand());
+	}
+	
+	@Test public void testEvaluatedSetCriteria() throws Exception {
+		DependentAccessNode dan = new DependentAccessNode(0);
+		CommandContext cc = new CommandContext();
+		dan.setContext(cc);
+		List<Reference> references = Arrays.asList(new Reference(1), new Reference(2));
+		for (Reference reference : references) {
+			cc.getVariableContext().setGlobalValue(reference.getContextSymbol(), 1);
+		}
+		SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), references); //$NON-NLS-1$
+		DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, dan, sc);
+		Criteria result = dcp.prepareCriteria();
+		assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$ 
+		assertFalse(dcp.hasNextCommand());
+	}
+	
+}


Property changes on: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentSelectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,16 +22,35 @@
 
 package com.metamatrix.query.processor.relational;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
-import junit.framework.*;
+import junit.framework.TestCase;
 
 import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.*;
-import com.metamatrix.query.processor.*;
-import com.metamatrix.query.sql.lang.*;
-import com.metamatrix.query.sql.symbol.*;
-import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
+import com.metamatrix.common.buffer.BlockedException;
+import com.metamatrix.common.buffer.BufferManager;
+import com.metamatrix.common.buffer.TupleBatch;
+import com.metamatrix.common.buffer.TupleSource;
+import com.metamatrix.query.processor.ProcessorDataManager;
+import com.metamatrix.query.processor.ProcessorPlan;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.CompoundCriteria;
+import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.ExistsCriteria;
+import com.metamatrix.query.sql.lang.From;
+import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.Select;
+import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubquerySetCriteria;
+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.util.CommandContext;
 
 /**
@@ -128,10 +147,7 @@
 		Command subCommand2 = helpMakeCommand2();
 		subCommand2.setProcessorPlan(new DoNothingProcessorPlan());
 		Criteria subCrit2 = new SubquerySetCriteria(new ElementSymbol("f"), subCommand2); //$NON-NLS-1$
-		List crits = new ArrayList(2);
-		crits.add(subCrit);
-		crits.add(subCrit2);
-		DependentSelectNode node = new DependentSelectNode(id, null);
+		DependentSelectNode node = new DependentSelectNode(id, new SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new DoNothingProcessorPlan()), null, null));
 		//Set up criteria
 		CompoundCriteria crit = new CompoundCriteria();
 		crit.addCriteria(subCrit);
@@ -144,25 +160,16 @@
 		//Test clone
 		DependentSelectNode cloned = (DependentSelectNode)node.clone();
 		
-		List<ProcessorPlan> originalProcessorPlans = node.getSubqueryProcessorUtility().getSubqueryPlans();
+		List<? extends ProcessorPlan> originalProcessorPlans = node.getSubqueryProcessorUtility().getSubqueryPlans();
 		List clonedProcessorPlans = cloned.getSubqueryProcessorUtility().getSubqueryPlans();
-		List clonedCrits = cloned.getSubqueryProcessorUtility().getValueIteratorProviders();
-		List checkClonedCrits = new ArrayList(clonedCrits.size());
-        ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(cloned.getCriteria(), checkClonedCrits);
         assertTrue(clonedProcessorPlans.size() == 2);
 		assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
-		assertEquals(clonedCrits.size(), checkClonedCrits.size());
-		assertEquals(clonedCrits.size(), clonedProcessorPlans.size());
 		for (int i=0; i<originalProcessorPlans.size(); i++){
 			//Check ProcessorPlans
 			ProcessorPlan originalPlan = originalProcessorPlans.get(i);
 			DoNothingProcessorPlan clonedPlan = (DoNothingProcessorPlan)clonedProcessorPlans.get(i);
 			assertNotNull(clonedPlan.original);
-			assertSame(((DoNothingProcessorPlan)originalPlan).original, clonedPlan.original);
-			
-			//Check SubquerySetCriteria
-			assertNotNull(clonedCrits.get(i));
-			assertSame(clonedCrits.get(i), checkClonedCrits.get(i));			
+			assertSame(originalPlan, clonedPlan.original);
 		}
 		
 	}
@@ -185,7 +192,7 @@
         crits.add(subCrit);
         crits.add(subCrit2);
 
-        DependentSelectNode node = new DependentSelectNode(id, null);
+		DependentSelectNode node = new DependentSelectNode(id, new SubqueryProcessorUtility(Arrays.asList(new DoNothingProcessorPlan(), new DoNothingProcessorPlan()), null, null));
 
         //Set up criteria
         CompoundCriteria crit = new CompoundCriteria();
@@ -201,23 +208,14 @@
         
         List originalProcessorPlans = node.getSubqueryProcessorUtility().getSubqueryPlans();
         List clonedProcessorPlans = cloned.getSubqueryProcessorUtility().getSubqueryPlans();
-        List clonedCrits = cloned.getSubqueryProcessorUtility().getValueIteratorProviders();
-        List checkClonedCrits = new ArrayList(clonedCrits.size());
-        ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(cloned.getCriteria(), checkClonedCrits);
         assertTrue(clonedProcessorPlans.size() == 2);
         assertEquals(originalProcessorPlans.size(), clonedProcessorPlans.size());
-        assertEquals(clonedCrits.size(), checkClonedCrits.size());
-        assertEquals(clonedCrits.size(), clonedProcessorPlans.size());
         for (int i=0; i<originalProcessorPlans.size(); i++){
             //Check ProcessorPlans
             Object originalPlan = originalProcessorPlans.get(i);
             DoNothingProcessorPlan clonedPlan = (DoNothingProcessorPlan)clonedProcessorPlans.get(i);
             assertNotNull(clonedPlan.original);
-            assertSame(((DoNothingProcessorPlan)originalPlan).original, clonedPlan.original);
-            
-            //Check SubquerySetCriteria
-            assertNotNull(clonedCrits.get(i));
-            assertSame(clonedCrits.get(i), checkClonedCrits.get(i));            
+            assertSame(originalPlan, clonedPlan.original);
         }
     }
     

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-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -85,7 +85,7 @@
         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$
+	        		assertEquals("Rows don't match at " + i, expected[i], iterator.nextTuple()); //$NON-NLS-1$
 	        		break;
 	        	} catch (BlockedException e) {
 	        		continue;

Modified: trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDependentSetCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDependentSetCriteria.java	2009-04-20 14:15:14 UTC (rev 800)
+++ trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDependentSetCriteria.java	2009-04-20 14:57:25 UTC (rev 801)
@@ -22,17 +22,10 @@
 
 package com.metamatrix.query.sql.lang;
 
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
 import junit.framework.TestCase;
 
 import com.metamatrix.core.util.UnitTestUtil;
 import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.sql.util.ValueIteratorSource;
 
 
 /** 
@@ -53,72 +46,30 @@
         super(name);
     }
 
-    private DependentSetCriteria example(Object[] vals) {
+    private DependentSetCriteria example() {
         ElementSymbol e1 = new ElementSymbol("pm1.g1.e1"); //$NON-NLS-1$
-        DependentSetCriteria dsc = new DependentSetCriteria(e1);
+        DependentSetCriteria dsc = new DependentSetCriteria(e1, ""); //$NON-NLS-1$
         
         final ElementSymbol e2 = new ElementSymbol("pm2.g1.e2"); //$NON-NLS-1$
         dsc.setValueExpression(e2);
         
-        FakeValueIteratorSource vis = new FakeValueIteratorSource();        
-        vis.addData(e2, vals);
-        vis.ready();
-        dsc.setValueIteratorSource(vis);
-        
         return dsc;
     }
     
-    public void testGetValueIterator() throws Exception {
-        Object[] vals = new Object[] { "a", "b", "c"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        DependentSetCriteria dsc = example(vals);
-        ValueIterator iter = dsc.getValueIterator();
-        for(int i=0; iter.hasNext(); i++) {
-            assertEquals(vals[i], iter.next());
-        }
-        assertEquals(false, iter.hasNext());
-    }
-    
     public void testEquivalence() {
-        Object[] vals = new Object[] { "a", "b", "c"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        DependentSetCriteria dsc = example(vals);
+        DependentSetCriteria dsc = example();
         
         UnitTestUtil.helpTestEquivalence(0, dsc, dsc);            
         UnitTestUtil.helpTestEquivalence(0, dsc, dsc.clone());            
     }
     
     public void testEquivalence1() {
-        Object[] vals = new Object[] { "a", "b", "c"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        DependentSetCriteria dsc = example(vals);
-        DependentSetCriteria dsc1 = example(vals);
+        DependentSetCriteria dsc = example();
+        DependentSetCriteria dsc1 = example();
         
         dsc1.setValueExpression(new ElementSymbol("foo")); //$NON-NLS-1$
         
         assertNotSame(dsc, dsc1);
     }
     
-    static class FakeValueIteratorSource implements ValueIteratorSource {
-
-        private Map data = new HashMap();
-        private boolean ready = false;
-        
-        
-        public void addData(Expression valueExpression, Object[] values) {
-            data.put(valueExpression, values);            
-        }
-        
-        public void ready() {
-            this.ready = true;
-        }
-        
-        public ValueIterator getValueIterator(Expression valueExpression) {
-            Object[] vals = (Object[])data.get(valueExpression);
-            return new CollectionValueIterator(Arrays.asList(vals));
-        }
-        
-        public boolean isReady() {
-            return ready;
-        }
-
-    }
-
 }




More information about the teiid-commits mailing list