[teiid-commits] teiid SVN: r2118 - in trunk: engine/src/test/java/com/metamatrix/query/processor and 97 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue May 11 18:15:49 EDT 2010


Author: shawkins
Date: 2010-05-11 18:15:35 -0400 (Tue, 11 May 2010)
New Revision: 2118

Added:
   trunk/engine/src/test/java/org/teiid/cache/
   trunk/engine/src/test/java/org/teiid/cdk/
   trunk/engine/src/test/java/org/teiid/common/
   trunk/engine/src/test/java/org/teiid/common/buffer/
   trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java
   trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBatch.java
   trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
   trunk/engine/src/test/java/org/teiid/common/buffer/impl/
   trunk/engine/src/test/java/org/teiid/common/log/
   trunk/engine/src/test/java/org/teiid/common/queue/
   trunk/engine/src/test/java/org/teiid/dqp/message/
   trunk/engine/src/test/java/org/teiid/dqp/service/
   trunk/engine/src/test/java/org/teiid/internal/
   trunk/engine/src/test/java/org/teiid/internal/core/
   trunk/engine/src/test/java/org/teiid/internal/core/xml/
   trunk/engine/src/test/java/org/teiid/query/
   trunk/engine/src/test/java/org/teiid/query/analysis/
   trunk/engine/src/test/java/org/teiid/query/function/
   trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
   trunk/engine/src/test/java/org/teiid/query/function/TestFunctionDescriptorImpl.java
   trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
   trunk/engine/src/test/java/org/teiid/query/function/TestFunctionMetadataReader.java
   trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java
   trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java
   trunk/engine/src/test/java/org/teiid/query/function/metadata/
   trunk/engine/src/test/java/org/teiid/query/function/source/
   trunk/engine/src/test/java/org/teiid/query/mapping/
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/
   trunk/engine/src/test/java/org/teiid/query/optimizer/
   trunk/engine/src/test/java/org/teiid/query/optimizer/FakeFunctionMetadataSource.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/InlineViewCase.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestComparableMetadataPushdown.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinWithFunction.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/batch/
   trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/
   trunk/engine/src/test/java/org/teiid/query/optimizer/proc/
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestRuleStack.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/plantree/
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/
   trunk/engine/src/test/java/org/teiid/query/parser/
   trunk/engine/src/test/java/org/teiid/query/processor/
   trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java
   trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java
   trunk/engine/src/test/java/org/teiid/query/processor/FakeProcessorPlan.java
   trunk/engine/src/test/java/org/teiid/query/processor/FakeTupleSource.java
   trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestBaseProcessorPlan.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestCollectionTupleSource.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestQueryProcessor.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
   trunk/engine/src/test/java/org/teiid/query/processor/batch/
   trunk/engine/src/test/java/org/teiid/query/processor/dynamic/
   trunk/engine/src/test/java/org/teiid/query/processor/eval/
   trunk/engine/src/test/java/org/teiid/query/processor/proc/
   trunk/engine/src/test/java/org/teiid/query/processor/relational/
   trunk/engine/src/test/java/org/teiid/query/processor/xml/
   trunk/engine/src/test/java/org/teiid/query/processor/xquery/
   trunk/engine/src/test/java/org/teiid/query/resolver/
   trunk/engine/src/test/java/org/teiid/query/rewriter/
   trunk/engine/src/test/java/org/teiid/query/sql/
   trunk/engine/src/test/java/org/teiid/query/sql/lang/
   trunk/engine/src/test/java/org/teiid/query/sql/proc/
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/
   trunk/engine/src/test/java/org/teiid/query/sql/util/
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/
   trunk/engine/src/test/java/org/teiid/query/unittest/
   trunk/engine/src/test/java/org/teiid/query/util/
   trunk/engine/src/test/java/org/teiid/query/validator/
   trunk/engine/src/test/java/org/teiid/query/xquery/
   trunk/engine/src/test/java/org/teiid/vdb/
   trunk/engine/src/test/java/org/teiid/vdb/runtime/
   trunk/engine/src/test/resources/org/
   trunk/engine/src/test/resources/org/teiid/
Removed:
   trunk/engine/src/test/java/com/metamatrix/query/parser/
   trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataStore.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/FakeProcessorPlan.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestAggregateProcessing.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestBaseProcessorPlan.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestBatchIterator.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestCollectionTupleSource.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestInsertProcessing.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestJoinWithFunction.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestOptionalJoins.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/TestQueryProcessor.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestSecurityFunctions.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
   trunk/engine/src/test/java/com/metamatrix/query/processor/batch/
   trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/
   trunk/engine/src/test/java/com/metamatrix/query/processor/eval/
   trunk/engine/src/test/java/com/metamatrix/query/processor/proc/
   trunk/engine/src/test/java/com/metamatrix/query/processor/relational/
   trunk/engine/src/test/java/com/metamatrix/query/processor/xml/
   trunk/engine/src/test/java/com/metamatrix/query/processor/xquery/
   trunk/engine/src/test/java/com/metamatrix/query/resolver/
   trunk/engine/src/test/java/com/metamatrix/query/rewriter/
   trunk/engine/src/test/java/com/metamatrix/query/sql/lang/
   trunk/engine/src/test/java/com/metamatrix/query/sql/proc/
   trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/
   trunk/engine/src/test/java/com/metamatrix/query/sql/util/
   trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/
   trunk/engine/src/test/java/com/metamatrix/query/unittest/
   trunk/engine/src/test/java/com/metamatrix/query/util/
   trunk/engine/src/test/java/com/metamatrix/query/validator/
   trunk/engine/src/test/java/com/metamatrix/query/xquery/
   trunk/engine/src/test/java/com/metamatrix/vdb/runtime/
   trunk/engine/src/test/resources/com/
   trunk/engine/src/test/resources/org/metamatrix/
   trunk/engine/src/test/resources/org/teiid/query/mapping/xml/testExample.xml
Modified:
   trunk/engine/src/test/java/org/teiid/cache/FakeCache.java
   trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java
   trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
   trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkItem.java
   trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkManager.java
   trunk/engine/src/test/java/org/teiid/common/queue/TestStatsCapturingWorkManager.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeTransactionService.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorManager.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorWorkItem.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestExecutionContextImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestBatchedUpdatesImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompareCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompoundCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestDeleteImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestElementImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestExistsCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestFunctionImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupByImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInlineViewImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInsertImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestIsNullCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestJoinImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLikeCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLiteralImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestNotCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestOrderByImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestProcedureImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestQueryImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestScalarSubqueryImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSearchedCaseExpressionImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSelectSymbolImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSetQueryImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryCompareCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryInCriteriaImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestUpdateImpl.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TstLanguageBridgeFactory.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/metadata/TestMetadataFactory.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestByteLobChunkStream.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCallableStatement.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestConnectorCapabilitiesFinder.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceCapabilitiesFinder.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceElementReplacementVisitor.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceMetadataWrapper.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/validator/TestAuthorizationValidationVisitor.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/transaction/TestTransactionServer.java
   trunk/engine/src/test/java/org/teiid/dqp/message/TestAtomicRequestMessage.java
   trunk/engine/src/test/java/org/teiid/dqp/message/TestRequestID.java
   trunk/engine/src/test/java/org/teiid/dqp/message/TestResultsMessage.java
   trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
   trunk/engine/src/test/java/org/teiid/dqp/service/FakeBufferService.java
   trunk/engine/src/test/java/org/teiid/internal/core/xml/TestJdomHelper.java
   trunk/engine/src/test/java/org/teiid/metadata/TestTransformationMetadata.java
   trunk/engine/src/test/java/org/teiid/query/analysis/TestAnalysisRecord.java
   trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java
   trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMethod.java
   trunk/engine/src/test/java/org/teiid/query/function/metadata/TestSystemSource.java
   trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingAttribute.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingChoiceNode.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingDocument.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingElement.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingLoader.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingOutputter.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingRecursiveElement.java
   trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestNamespace.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/batch/TestBatchedUpdatePlanner.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/FakeCapabilitiesFinder.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestBasicSourceCapabilities.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestDefaultCapabilitiesFinder.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/plantree/TestNodeEditor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCriteriaCapabilityValidatorVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestFrameUtil.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestJoinRegion.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAccessPatternValidation.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAssignOutputElements.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePushSelectCriteria.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleValidateWhereAll.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/FakeXMLMetadata.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestContextReplacerVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestHandleNillableNode.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestRemoveExcludedVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLNodeMappingVisitor.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLPlanner.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestCallableStatementParsing.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
   trunk/engine/src/test/java/org/teiid/query/processor/batch/TestBatchedUpdatePlan.java
   trunk/engine/src/test/java/org/teiid/query/processor/dynamic/SimpleQueryProcessorFactory.java
   trunk/engine/src/test/java/org/teiid/query/processor/dynamic/TestSqlEval.java
   trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
   trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
   trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/BlockingFakeRelationalNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/FakeRelationalNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/NodeTestUtil.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestBatchedUpdateNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDependentCriteriaProcessor.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDuplicateFilter.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestGroupingNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestLimitNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalPlan.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSelectNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/relational/TestUnionAllNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/FakeXMLProcessorEnvironment.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/NoOpInstruction.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestAddNodeInstruction.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestElement.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestInstructions.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSAXDocumentInProgress.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSourceNodeGenaratorVisitor.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLContext.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java
   trunk/engine/src/test/java/org/teiid/query/processor/xml/XMLProgramUtil.java
   trunk/engine/src/test/java/org/teiid/query/processor/xquery/TestXQueryProcessor.java
   trunk/engine/src/test/java/org/teiid/query/resolver/CheckNoTempMetadataIDsVisitor.java
   trunk/engine/src/test/java/org/teiid/query/resolver/CheckSymbolsAreResolvedVisitor.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestAccessPattern.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
   trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
   trunk/engine/src/test/java/org/teiid/query/rewriter/TestOrderByRewrite.java
   trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestAliasSymbol.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestBetweenCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCompoundCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCreate.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDependentSetCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDrop.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDynamicCommand.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestExpressionSymbol.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestIsNullCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJDBCExecutionHelper.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJoinPredicate.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestLimit.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestMatchCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestOption.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestQuery.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetQuery.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubqueryFromClause.java
   trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubquerySetCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBlock.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBreakStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCommandStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestContinueStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestDeclareStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestLoopStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestCaseExpression.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestConstant.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestFunction.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestGroupSymbol.java
   trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestSearchedCaseExpression.java
   trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
   trunk/engine/src/test/java/org/teiid/query/sql/util/TestUpdateProcedureGenerator.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestDeepGroupCollectorVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestEvaluatableVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestGroupCollectorVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
   trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java
   trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
   trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataObject.java
   trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataStore.java
   trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
   trunk/engine/src/test/java/org/teiid/query/util/TestPermutation.java
   trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
   trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java
   trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java
   trunk/engine/src/test/java/org/teiid/vdb/runtime/TestVDBKey.java
   trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java
   trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
   trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java
   trunk/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java
   trunk/metadata/src/main/java/org/teiid/internal/core/index/VirtualRandomAccessFile.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/MetadataConstants.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/RuntimeMetadataPlugin.java
   trunk/metadata/src/main/java/org/teiid/metadata/index/SimpleIndexUtil.java
   trunk/metadata/src/test/java/com/metamatrix/cdk/api/TranslationUtility.java
   trunk/metadata/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java
   trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
   trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
   trunk/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
   trunk/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java
   trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/TranslatorDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/UDFMetaData.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBStructure.java
   trunk/runtime/src/main/java/org/teiid/deployers/VirtualDatabaseException.java
   trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
   trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
   trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
   trunk/runtime/src/main/java/org/teiid/transport/ClientInstance.java
   trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java
   trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java
   trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
   trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
   trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java
   trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java
   trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
   trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java
   trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java
   trunk/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
   trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java
   trunk/runtime/src/main/java/org/teiid/transport/SocketListener.java
   trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java
   trunk/runtime/src/test/java/org/teiid/deployers/TestObjectSerializer.java
   trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
   trunk/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java
   trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java
   trunk/test-integration/common/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestElement.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestGroup.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestMetadataObject.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestParams.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestProcedure.java
   trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
   trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java
   trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java
   trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/AbstractMMQueryTestCase.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestQueryPlans.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java
   trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java
   trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestPartsDatabaseMetadata.java
   trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestResultSetMetadata.java
   trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
   trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/ListNestedSortComparator.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
   trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/exception/QueryTestFailedException.java
   trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java
   trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
   trunk/test-integration/db/src/test/java/org/teiid/dynamicvdb/TestVDBLessExecution.java
Log:
TEIID-918 changing package to org.teiid and removing metamatrix from class names

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,402 +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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.teiid.logging.LogManager;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.CriteriaEvaluationException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Delete;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.TranslatableProcedureContainer;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
-import com.metamatrix.query.util.CommandContext;
-
-public class FakeDataManager implements ProcessorDataManager {
-	private Map tuples = new HashMap();
-    private static final String LOG_CONTEXT = "FAKE_DATA_MANAGER"; //$NON-NLS-1$
-    
-    //used to test blocked exception. If true,
-    //the first time nextTuple is called on FakeTupleSource,
-    //it will throws BlockedExceptiom
-    private boolean blockOnce;
-
-    // ---- Cached code table stuff ---- 
-    	
-    // upper table name + upper key col name + upper ret col name -> map of values
-    private Map codeTableValues = new HashMap();
-    
-    // throw Blocked on first request
-    private boolean throwBlocked = false;
-    
-    // upper table name + upper key col name + upper ret col name -> flag of whether this table has blocked yet
-    private Map blockedState = new HashMap();
-
-    // Track history to verify it later
-    private List<String> queries = new ArrayList<String>();
-    private boolean recordingCommands = true;
-    
-    /**
-     * Return string form of all queries run against this FDM 
-     * @return List<String> recorded commands
-     */
-    public List<String> getQueries() {
-        return this.queries;
-    }
-	        
-    /**
-     * Clears the list of recorded commands and returns a copy
-     * @return a copy of the recorded commands prior to clearing the list
-     */
-    public List<String> clearQueries() {
-    	List<String> rc = new ArrayList<String>(this.getQueries());
-    	this.queries.clear();
-    	return rc;
-    }
-	        
-	public void registerTuples(Object groupID, List elements, List[] data) {
-		tuples.put(groupID, new Object[] { elements, data });
-	}
-	
-	public void closeRequest(Object requestID) {
-		// does nothing?
-    } 
-	
-	public TupleSource registerRequest(Object processorID, Command command, String modelName, String connectorBindingId, int nodeID)
-		throws MetaMatrixComponentException {
-        
-        LogManager.logTrace(LOG_CONTEXT, new Object[]{"Register Request:", command, ",processorID:", processorID, ",model name:", modelName,",TupleSourceID nodeID:",new Integer(nodeID)}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
-        if (this.recordingCommands) {
-            if (! (command instanceof BatchedUpdateCommand) ) {
-            	this.queries.add(command.toString());
-            }
-        }
-
-        if (ReferenceCollectorVisitor.getReferences(command).size() > 0) {
-            throw new IllegalArgumentException("Found references in the command registered with the DataManager."); //$NON-NLS-1$
-        }
-		// Get group ID from atomic command
-		GroupSymbol group = null;
-		if(command instanceof Query){
-			group = getQueryGroup((Query)command);    
-        }else if(command instanceof SetQuery) {
-            SetQuery union = (SetQuery) command;            
-            group = getQueryGroup(union.getProjectedQuery());
-		} else if (command instanceof ProcedureContainer) {
-			group = ((ProcedureContainer) command).getGroup();
-		} else if ( command instanceof BatchedUpdateCommand ) {
-    		if ( command.getSubCommands().get(0) instanceof Update ) {
-    			group = ((Update)command.getSubCommands().get(0)).getGroup();
-    		}
-    		if (this.recordingCommands) {
-            	for ( Iterator<Command> it = ((BatchedUpdateCommand) command).getUpdateCommands().iterator(); it.hasNext(); ) {
-            		this.queries.add(it.next().toString());
-            	}
-    		}
-		}
-		
-		Object groupID = group.getMetadataID();
-		
-		Object[] tupleInfo = (Object[]) tuples.get(groupID);
-		List elements = (List) tupleInfo[0];
-		List[] tuples = (List[]) tupleInfo[1];
-		
-		List projectedSymbols = command.getProjectedSymbols();
-		int[] columnMap = getColumnMap(elements, projectedSymbols);
-		
-		/* 
-		*  updateCommands is used to hold a list of commands that 
-		*  either came from a BatchedUpdateCommand or a signle 
-		*  command from an Update command.
-		*/
-		List<Command> updateCommands = new ArrayList<Command>();
-		
-		// Apply query criteria to tuples
-		if(command instanceof Query){
-			Query query = (Query)command;
-			if(query.getCriteria() != null) {
-			    // Build lookupMap from BOTH all the elements and the projected symbols - both may be needed here
-	            Map lookupMap = new HashMap();
-	            for(int i=0; i<elements.size(); i++) { 
-	                Object element = elements.get(i);
-                    mapElementToIndex(lookupMap, element, new Integer(i), group);        
-	            }
-	            for(int i=0; i<projectedSymbols.size(); i++) { 
-	            	Object element = projectedSymbols.get(i);
-                    mapElementToIndex(lookupMap, element, new Integer(columnMap[i]), group);
-	            }
-			    
-			    List filteredTuples = new ArrayList();
-			    for(int i=0; i<tuples.length; i++) {
-	                try {
-	    				if(new Evaluator(lookupMap, null, null).evaluate(query.getCriteria(), tuples[i])) {
-	                        filteredTuples.add(tuples[i]);
-	                    }
-	                } catch(CriteriaEvaluationException e) {
-	                    throw new MetaMatrixComponentException(e, e.getMessage());
-	                }
-			    }
-			    
-			    tuples = new List[filteredTuples.size()];
-			    filteredTuples.toArray(tuples);
-			}
-		} else if ( command instanceof Insert || command instanceof Update || command instanceof Delete) {
-			// add single update command to a list to be executed
-			updateCommands.add(command);
-		} else if ( command instanceof BatchedUpdateCommand ) {
-			// add all update commands to a list to be executed
-    		updateCommands.addAll(((BatchedUpdateCommand) command).getUpdateCommands());
-		}
-		
-		// if we had update commands added to the list, execute them now
-		if ( updateCommands.size() > 0 ) {
-		    List<List<Integer>> filteredTuples = new ArrayList<List<Integer>>();
-			for ( int c = 0; c < updateCommands.size(); c++ ) {
-				Command cmd = updateCommands.get(c);
-				if (cmd instanceof TranslatableProcedureContainer) {
-					TranslatableProcedureContainer update = (TranslatableProcedureContainer)cmd;
-					if ( update.getCriteria() != null ) {
-					    // Build lookupMap from BOTH all the elements and the projected symbols - both may be needed here
-			            Map<Object, Integer> lookupMap = new HashMap<Object, Integer>();
-			            for(int i=0; i<elements.size(); i++) { 
-			                Object element = elements.get(i);
-		                    mapElementToIndex(lookupMap, element, new Integer(i), group);        
-			            }
-			            for(int i=0; i<projectedSymbols.size(); i++) { 
-			            	Object element = projectedSymbols.get(i);
-		                    mapElementToIndex(lookupMap, element, new Integer(columnMap[i]), group);
-			            }
-					    
-					    int updated = 0;
-					    for(int i=0; i<tuples.length; i++) {
-			                try {
-			    				if(new Evaluator(lookupMap, null, null).evaluate(update.getCriteria(), tuples[i])) {
-			                        updated++;
-			                    }
-			                } catch(CriteriaEvaluationException e) {
-			                    throw new MetaMatrixComponentException(e, e.getMessage());
-			                }
-					    }
-				    	List<Integer> updateTuple = new ArrayList<Integer>(1);
-				    	updateTuple.add( new Integer(updated) );
-	                    filteredTuples.add(updateTuple);
-					}
-				} else {
-					filteredTuples.add(Arrays.asList(1)); //TODO: check for bulk
-				}
-			}
-		    tuples = new List[filteredTuples.size()];
-		    filteredTuples.toArray(tuples);
-		    elements = new ArrayList<Object>(projectedSymbols);
-		    columnMap[0] = 0;
-		}		
-				
-        FakeTupleSource ts= new FakeTupleSource(elements, tuples, projectedSymbols, columnMap);
-		if(this.blockOnce){
-            ts.setBlockOnce();
-		}
-        return ts;
-	}
-    
-    private GroupSymbol getQueryGroup(Query query) throws MetaMatrixComponentException {
-        GroupSymbol group;
-        From from = query.getFrom();
-        List groups = from.getGroups();
-        if(groups.size() != 1) { 
-        	throw new MetaMatrixComponentException("Cannot build fake tuple source for command: " + query);	 //$NON-NLS-1$
-        }
-        group = (GroupSymbol) groups.get(0);
-        Iterator projSymbols = query.getSelect().getProjectedSymbols().iterator();
-        while (projSymbols.hasNext()) {
-            Object symbol = projSymbols.next();
-            if (symbol instanceof ElementSymbol){
-                ElementSymbol elementSymbol = (ElementSymbol)symbol;
-                GroupSymbol g = elementSymbol.getGroupSymbol();
-                if (!g.equals(group)){
-                    throw new MetaMatrixComponentException("Illegal symbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                if (elementSymbol.getMetadataID() == null){
-                    throw new MetaMatrixComponentException("Illegal null metadata ID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
-                } else if (elementSymbol.getMetadataID() instanceof TempMetadataID){
-                    throw new MetaMatrixComponentException("Illegal TempMetadataID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
-                }
-            }
-        }
-        return group;
-    }
-
-    /**
-     * @param lookupMap
-     * @param element
-     * @param integer
-     * @param group
-     */
-    private void mapElementToIndex(Map lookupMap, Object element, Integer index, GroupSymbol group) {
-        if (group.getDefinition() != null){
-            String groupAlias = group.getCanonicalName();
-            ElementSymbol elementSymbol = (ElementSymbol)SymbolMap.getExpression((SingleElementSymbol)element);
-            String newName = groupAlias + "." + elementSymbol.getShortName(); //$NON-NLS-1$
-            ElementSymbol aliasedElement = new ElementSymbol(newName, elementSymbol.getDisplayFullyQualified());
-            aliasedElement.setGroupSymbol(elementSymbol.getGroupSymbol());
-            aliasedElement.setMetadataID(elementSymbol.getMetadataID());
-            aliasedElement.setType(elementSymbol.getType());
-            lookupMap.put(aliasedElement, index);
-        } else {
-            lookupMap.put(element, index);
-        }
-    }    
-	
-	//   columnMap[expectedElementIndex] = allElementIndex
-	private int[] getColumnMap(List allElements, List expectedElements) {
-		int[] map = new int[expectedElements.size()];
-		
-		for(int i=0; i<expectedElements.size(); i++) { 
-		    SingleElementSymbol symbol = (SingleElementSymbol) expectedElements.get(i);
-		    
-		    if (symbol instanceof AliasSymbol) {
-		        symbol = ((AliasSymbol)symbol).getSymbol();
-		    }
-		    
-		    String shortName = symbol.getShortName();
-		    
-		    // Find matching short name in all elements
-		    boolean foundMatch = false;
-		    for(int j=0; j<allElements.size(); j++) { 
-				SingleElementSymbol tupleSymbol = (SingleElementSymbol) allElements.get(j);
-				if(tupleSymbol.getShortName().equalsIgnoreCase(shortName)) {
-				    map[i] = j;
-				    foundMatch = true;
-				    break;
-				}
-		    }
-		    
-		    if(! foundMatch) { 
-                map[i] = -1;
-		    }
-		}
-		
-		return map;
-	}
-
-
-    public void setThrowBlocked(boolean throwBlocked) {
-        this.throwBlocked = throwBlocked;
-    }
-
-    public void defineCodeTable(String tableName, String keyCol, String retCol, Map values) {
-        String key = tableName.toUpperCase() + keyCol.toUpperCase() + retCol.toUpperCase();
-        this.codeTableValues.put(key, values);
-        this.blockedState.put(key, Boolean.FALSE);                      
-    }
-	
-    public Object lookupCodeValue(
-        CommandContext context,
-        String codeTableName,
-        String returnElementName,
-        String keyElementName,
-        Object keyValue)
-        throws BlockedException, MetaMatrixComponentException {
-            
-            String tableKey = codeTableName.toUpperCase() + keyElementName.toUpperCase() + returnElementName.toUpperCase();
-            if(! codeTableValues.containsKey(tableKey)) {
-                throw new MetaMatrixComponentException("Unknown code table: " + codeTableName); //$NON-NLS-1$
-            }
-        
-            if(throwBlocked) {
-                if(blockedState.get(tableKey).equals(Boolean.FALSE)) { 
-                    blockedState.put(tableKey, Boolean.TRUE);
-                    throw BlockedException.INSTANCE;
-                }
-            }
-        
-            Map values = (Map) codeTableValues.get(tableKey);
-            return values.get(keyValue);
-    }
-
-    public void setBlockOnce() {
-        blockOnce = true;
-    }
-    
-    @Override
-    public void clearCodeTables() {/* does nothing */}
-
-    /**
-     * Are commands/queries that are registered with the data manager being 
-     * recorded?
-     * <p>
-     * Recorded commands can be retrieved by {@link #getQueries()}
-     * 
-	 * @return whether or not commands should be recorded
-	 */
-	public boolean isRecordingCommands() {
-		return recordingCommands;
-	}
-
-	/**
-	 * Indicate whether or not commands/queries registered with the data 
-	 * manager are to be recorded in {@link #queries}.
-	 * <p>
-	 * Recorded commands can be retrieved by {@link #getQueries()}
-     * 
-	 * @param shouldRecord should commands be recorded?
-	 */
-	public void setRecordingCommands(boolean shouldRecord) {
-		this.recordingCommands = shouldRecord;
-	}
-
-	public void registerTuples(QueryMetadataInterface metadata, String groupName, List[] tuples) throws QueryResolverException, MetaMatrixComponentException {
-	    GroupSymbol group = new GroupSymbol(groupName);
-	    ResolverUtil.resolveGroup(group, metadata);
-	    List<ElementSymbol> elementSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
-		this.registerTuples(group.getMetadataID(), elementSymbols, tuples);
-	}
-
-
-}
\ No newline at end of file

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataStore.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataStore.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataStore.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,321 +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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.client.metadata.ParameterInfo;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.metadata.StoredProcedureInfo;
-import com.metamatrix.query.metadata.TempMetadataStore;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-
-
-/** 
- * This is sample data go along with FakeMetaDataFactory and FakeDataManager
- */
-public class FakeDataStore {
-    
-    // Helper to create a list of elements - used in creating sample data
-    public static List createElements(List elementIDs) { 
-        List elements = new ArrayList();
-        for(int i=0; i<elementIDs.size(); i++) {
-            FakeMetadataObject elementID = (FakeMetadataObject) elementIDs.get(i);            
-            ElementSymbol element = new ElementSymbol(elementID.getName());
-            elements.add(element);
-        }        
-        
-        return elements;
-    }     
-    
-    private static List getProcResultSetSymbols(List params){
-        List result = new ArrayList();
-        Iterator iter = params.iterator();
-        while(iter.hasNext()){
-            SPParameter param = (SPParameter)iter.next();
-            if(param.getResultSetColumns() != null){
-                result.addAll(param.getResultSetColumns());
-            }
-        }
-        iter = params.iterator();
-        while(iter.hasNext()){
-            SPParameter param = (SPParameter)iter.next();
-            if(param.getParameterType() == ParameterInfo.INOUT || param.getParameterType() == ParameterInfo.RETURN_VALUE) {
-                result.add(param.getParameterSymbol());
-            }
-        }
-        return result;
-    }
-    
-    public static void sampleData1(FakeDataManager dataMgr) throws QueryMetadataException, MetaMatrixComponentException {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        // Group pm1.g1
-        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-        List elementIDs = metadata.getElementIDsInGroupID(groupID);
-        List elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-
-        // Group pm1.g2
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-
-        // Group pm1.g3
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g3"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-            
-        // Group pm2.g1
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-                
-        // Group pm2.g2
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g2"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-
-        // Group pm2.g3
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g3"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-
-        // Group tm1.g1
-        groupID = (FakeMetadataObject) metadata.getGroupID("tm1.g1"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-                } );    
-
-        //stored procedure pm1.sp1
-        TempMetadataStore tempStore = new TempMetadataStore();          
-        StoredProcedureInfo procInfo = metadata.getStoredProcedureInfoForProcedure("pm1.sp1"); //$NON-NLS-1$
-        elementSymbols = getProcResultSetSymbols(procInfo.getParameters());
-        tempStore.addTempGroup("pm1.sp1", elementSymbols); //$NON-NLS-1$
-        Object procID = tempStore.getTempGroupID("pm1.sp1"); //$NON-NLS-1$
-        dataMgr.registerTuples(
-            procID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { null,  new Integer(1)}),
-                Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(1)}), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(2)}), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
-                } );    
-    }
-
-    public static void sampleData2(FakeDataManager dataMgr) throws QueryMetadataException, MetaMatrixComponentException {
-		FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-
-		// Group pm1.g1
-		FakeMetadataObject groupID = (FakeMetadataObject) metadata
-				.getGroupID("pm1.g1"); //$NON-NLS-1$
-		List elementIDs = metadata.getElementIDsInGroupID(groupID);
-		List elementSymbols = createElements(elementIDs);
-
-		dataMgr.registerTuples(groupID, elementSymbols,
-
-		new List[] {
-				Arrays.asList(new Object[] {
-						"a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
-		});
-
-		// Group pm1.g2
-		groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
-		elementIDs = metadata.getElementIDsInGroupID(groupID);
-		elementSymbols = createElements(elementIDs);
-
-		dataMgr.registerTuples(groupID, elementSymbols,
-
-		new List[] {
-				Arrays.asList(new Object[] {
-						"a", new Integer(1), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(0), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(5), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(2), Boolean.FALSE, null }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"d", new Integer(2), Boolean.FALSE, new Double(1.0) }), //$NON-NLS-1$
-		});
-
-		// Group pm2.g1
-		groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
-		elementIDs = metadata.getElementIDsInGroupID(groupID);
-		elementSymbols = createElements(elementIDs);
-
-		dataMgr.registerTuples(groupID, elementSymbols,
-
-		new List[] {
-				Arrays.asList(new Object[] {
-						"b", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"d", new Integer(3), Boolean.TRUE, new Double(7.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"e", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
-		});
-
-		// Group pm2.g2
-		groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g2"); //$NON-NLS-1$
-		elementIDs = metadata.getElementIDsInGroupID(groupID);
-		elementSymbols = createElements(elementIDs);
-
-		dataMgr.registerTuples(groupID, elementSymbols,
-
-		new List[] {
-				Arrays.asList(new Object[] {
-						"a", new Integer(1), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(0), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(5), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(2), Boolean.FALSE, null }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"d", new Integer(2), Boolean.FALSE, new Double(1.0) }), //$NON-NLS-1$
-		});
-
-		// Group pm1.table1
-		groupID = (FakeMetadataObject) metadata.getGroupID("pm1.table1"); //$NON-NLS-1$
-		elementIDs = metadata.getElementIDsInGroupID(groupID);
-		elementSymbols = createElements(elementIDs);
-
-		dataMgr.registerTuples(groupID, elementSymbols,
-
-		new List[] {
-				Arrays.asList(new Object[] {
-						"a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
-				Arrays.asList(new Object[] {
-						"c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
-		});
-	}                  
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeProcessorPlan.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/FakeProcessorPlan.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/FakeProcessorPlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,142 +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;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- */
-public class FakeProcessorPlan extends ProcessorPlan {
-
-    private List outputElements;
-    private List batches;
-    int batchIndex = 0;
-    private int nextBatchRow = 1;
-    private boolean opened = false;
-    
-    /**
-     * Constructor for FakeProcessorPlan.
-     * @param batches List of things to return in response to nextBatch() - typically 
-     * this is TupleBatch, but it can also be BlockedException or a 
-     * MetaMatrixComponentException.  
-     */
-    public FakeProcessorPlan(List outputElements, List batches) {
-        this.outputElements = outputElements;
-        this.batches = batches;
-    }
-    
-    public FakeProcessorPlan(int counts) {
-    	List[] rows = new List[counts];
-    	for (int i = 0; i < counts; i++) {
-            rows[i] = Arrays.asList(new Object[] {new Integer(1)});
-        }
-        TupleBatch batch = new TupleBatch(1, rows);
-        batch.setTerminationFlag(true);
-        this.batches = Arrays.asList(batch);
-        this.outputElements = Command.getUpdateCommandSymbol();
-    }
-    
-    public boolean isOpened() {
-		return opened;
-	}
-
-    /**
-     * @see java.lang.Object#clone()
-     */
-    public FakeProcessorPlan clone() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#initialize(com.metamatrix.query.processor.ProcessorDataManager, java.lang.Object, com.metamatrix.common.buffer.BufferManager, java.lang.String, int)
-     */
-    public void initialize(
-        CommandContext context,
-        ProcessorDataManager dataMgr,
-        BufferManager bufferMgr) {
-            
-        // nothing
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#getOutputElements()
-     */
-    public List getOutputElements() {
-        return this.outputElements;
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#open()
-     */
-    public void open() throws MetaMatrixComponentException {
-    	assertFalse("ProcessorPlan.open() should not be called more than once", opened); //$NON-NLS-1$
-        opened = true;
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#nextBatch()
-     */
-    public TupleBatch nextBatch() throws BlockedException, MetaMatrixComponentException {
-        if(this.batches == null || this.batches.size() == 0 || batchIndex >= this.batches.size()) {
-            // Return empty terminator batch
-            TupleBatch batch = new TupleBatch(nextBatchRow, Collections.EMPTY_LIST);  
-            batch.setTerminationFlag(true);
-            return batch;  
-        }
-        Object nextReturn = this.batches.get(batchIndex);
-        batchIndex++;
-
-        if(nextReturn instanceof TupleBatch) { 
-            TupleBatch batch = (TupleBatch) nextReturn;
-            nextBatchRow = nextBatchRow + batch.getRowCount();
-            return batch;
-        }
-        throw (MetaMatrixComponentException) nextReturn;
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#close()
-     */
-    public void close() throws MetaMatrixComponentException {
-        // nothing
-    }
-
-    /**
-     * @see com.metamatrix.query.processor.ProcessorPlan#getSchema()
-     */
-    public List getSchema() {
-        return this.outputElements;
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,124 +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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.*;
-
-public class FakeTupleSource implements TupleSource {
-    
-    public static class FakeComponentException extends MetaMatrixComponentException {
-        
-    }
-
-	private List elements;
-	private List[] tuples;
-	private int index = 0;
-	private List expectedSymbols;
-	private int[] columnMap;
-    
-    //used to test blocked exception. If true,
-    //the first time nextTuple is called, it will throws BlockedExceptiom
-    private boolean blockOnce;
-    
-    private boolean exceptionOnClose;
-	
-	public FakeTupleSource(List elements, List[] tuples) {
-		this.elements = elements;
-		this.tuples = tuples; 
-	}
-
-	public FakeTupleSource(List elements, List[] tuples, List expectedSymbols, int[] columnMap) {
-		this.elements = elements;
-		this.tuples = tuples; 
-		this.expectedSymbols = expectedSymbols;
-		this.columnMap = columnMap;
-	}
-
-	public List getSchema() { 
-        List theElements = null;        
-	    if(expectedSymbols != null) {
-			theElements = expectedSymbols;
-	    } else {
-	    	theElements = elements;    
-	    }
-        
-        return theElements;
-	}
-	
-	public void openSource()
-		throws MetaMatrixComponentException {				
-		
-		index = 0;
-	}
-
-	public List nextTuple()
-		throws MetaMatrixComponentException {
-	
-        if(this.blockOnce){
-            this.blockOnce = false;
-            throw BlockedException.INSTANCE;            
-        }
-        
-		if(index < tuples.length) { 
-		    // Get full data tuple, with elements
-		    List tuple = tuples[index++];
-		    
-		    if(expectedSymbols == null) { 
-		        return tuple;
-		    }
-		    // Build mapped data tuple, with expectedSymbols
-		    List mappedTuple = new ArrayList(expectedSymbols.size());
-		    for(int i=0; i<columnMap.length; i++) { 
-		    	int colIndex = columnMap[i];
-                if(colIndex >= 0) {
-                    mappedTuple.add( tuple.get(colIndex) );
-                } else {
-                    mappedTuple.add( null );
-                }
-		    }		    
-			return mappedTuple;
-		}
-		return null;
-	}
-
-	public void closeSource() {
-	}
-    
-    public void setBlockOnce(){
-        this.blockOnce = true;
-    }
-
-    public void setExceptionOnClose(boolean exceptionOnClose) {
-        this.exceptionOnClose = exceptionOnClose;
-    }
-    
-    @Override
-    public int available() {
-    	return 0;
-    }
-    
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,155 +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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.util.CommandContext;
-
-
-/** 
- * @since 4.2
- */
-public class HardcodedDataManager implements
-                                 ProcessorDataManager {
-
-    // sql string to data
-    private Map data = new HashMap();
-    
-    // valid models - if null, any is assumed valid
-    private Set validModels;
-    
-    private boolean mustRegisterCommands = true;
-    
-    private boolean blockOnce;
-    
-    // Collect all commands run against this class
-    private Collection commandHistory = new ArrayList(); // Commands
-    
-    public HardcodedDataManager() {
-    	this(true);
-    }
-    
-    public HardcodedDataManager(boolean mustRegisterCommands) {
-    	this.mustRegisterCommands = mustRegisterCommands;
-    }
-    
-    public void addData(String sql, List[] rows) {
-        data.put(sql, rows);
-    }
-    
-    public void clearData() {
-    	this.data.clear();
-    	this.commandHistory.clear();
-    }
-    
-    public void setBlockOnce(boolean blockOnce) {
-		this.blockOnce = blockOnce;
-	}
-    
-    /**
-     * Set of model names that are valid.  Invalid ones will throw an error. 
-     * @param models
-     * @since 4.2
-     */
-    public void setValidModels(Set models) {
-        this.validModels = models;
-    }
-    
-    /**
-     * Return collection of Command that has occurred on this data manager 
-     * @return
-     * @since 4.2
-     */
-    public Collection getCommandHistory() {
-        return this.commandHistory;
-    }
-    
-    /** 
-     * @see com.metamatrix.query.processor.ProcessorDataManager#lookupCodeValue(com.metamatrix.query.util.CommandContext, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
-     * @since 4.2
-     */
-    public Object lookupCodeValue(CommandContext context,
-                                  String codeTableName,
-                                  String returnElementName,
-                                  String keyElementName,
-                                  Object keyValue) throws BlockedException,
-                                                  MetaMatrixComponentException {
-        return null;
-    }
-    
-    /** 
-     * @see com.metamatrix.query.processor.ProcessorDataManager#registerRequest(java.lang.Object, com.metamatrix.query.sql.lang.Command, java.lang.String, String, int)
-     * @since 4.2
-     */
-    public TupleSource registerRequest(Object processorID,
-                                Command command,
-                                String modelName,
-                                String connectorBindingId, int nodeID) throws MetaMatrixComponentException {
-        
-        if(modelName != null && validModels != null && ! validModels.contains(modelName)) {
-            throw new MetaMatrixComponentException("Detected query against invalid model: " + modelName + ": " + command);  //$NON-NLS-1$//$NON-NLS-2$
-        } 
-        this.commandHistory.add(command);
-        
-        List projectedSymbols = command.getProjectedSymbols();
-
-        List[] rows = (List[]) data.get(command.toString());
-        if(rows == null) {
-            if (mustRegisterCommands) {
-                throw new MetaMatrixComponentException("Unknown command: " + command.toString());  //$NON-NLS-1$
-            }
-            // Create one row of nulls
-            rows = new List[1];
-            rows[0] = new ArrayList();
-            
-            for(int i=0; i<projectedSymbols.size(); i++) {
-                rows[0].add(null);
-            }
-        }
-        
-        FakeTupleSource source = new FakeTupleSource(projectedSymbols, rows);
-        if (blockOnce) {
-        	source.setBlockOnce();
-        }
-        return source;
-    }
-
-    public void setMustRegisterCommands(boolean mustRegisterCommands) {
-        this.mustRegisterCommands = mustRegisterCommands;
-    }
-
-	public void clearCodeTables() {
-		
-	}
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestAggregateProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestAggregateProcessing.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestAggregateProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,285 +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;
-
-import static com.metamatrix.query.processor.TestProcessor.*;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestAggregatePushdown;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
-public class TestAggregateProcessing {
-
-	static void sampleDataBQT3(FakeDataManager dataMgr) throws Exception {
-		QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-
-		// Group bqt1.smalla
-
-		List[] tuples = new List[20];
-		for (int i = 0; i < tuples.length; i++) {
-			tuples[i] = new ArrayList(17);
-			tuples[i].add(new Integer(i));
-			tuples[i].add("" + i); //$NON-NLS-1$
-			tuples[i].add(new Integer(i + 1));
-			for (int j = 0; j < 14; j++) {
-				tuples[i].add(null);
-			}
-		}
-
-		dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
-
-		tuples = new List[20];
-		for (int i = 0; i < tuples.length; i++) {
-			tuples[i] = new ArrayList(17);
-			tuples[i].add(new Integer(i));
-			for (int j = 0; j < 16; j++) {
-				tuples[i].add(null);
-			}
-		}
-
-		dataMgr.registerTuples(metadata, "bqt2.mediumb", tuples); //$NON-NLS-1$
-	}
-
-	private void sampleDataBQT_defect9842(FakeDataManager dataMgr) throws Exception {
-		QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-
-		List[] tuples = new List[5];
-		for (int i = 0; i < tuples.length; i++) {
-			int k = i + 10;
-			tuples[i] = new ArrayList(17);
-			if (i < 2) {
-				tuples[i].add(new Integer(1)); // need duplicate values
-			} else {
-				tuples[i].add(new Integer(2)); // need duplicate values
-			}
-			tuples[i].add("" + k); //$NON-NLS-1$
-			tuples[i].add(new Integer(k + 1));
-			tuples[i].add("" + (k + 1)); //$NON-NLS-1$
-			tuples[i].add(new Float(0.5));
-			for (int j = 0; j < 8; j++) {
-				tuples[i].add(null);
-			}
-			tuples[i].add(new Short((short) k));
-			tuples[i].add(null);
-			tuples[i].add(new BigDecimal("" + k)); //$NON-NLS-1$
-			tuples[i].add(null);
-		}
-
-		dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
-	}
-
-	@Test public void testAggregateOnBQT() throws Exception {
-		// Create query
-		String sql = "SELECT IntKey, SUM(IntNum) FROM BQT1.SmallA GROUP BY IntKey, IntNum HAVING IntNum > 10 ORDER BY IntKey"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-				Arrays.asList(new Object[] { new Integer(10), new Long(11) }),
-				Arrays.asList(new Object[] { new Integer(11), new Long(12) }),
-				Arrays.asList(new Object[] { new Integer(12), new Long(13) }),
-				Arrays.asList(new Object[] { new Integer(13), new Long(14) }),
-				Arrays.asList(new Object[] { new Integer(14), new Long(15) }),
-				Arrays.asList(new Object[] { new Integer(15), new Long(16) }),
-				Arrays.asList(new Object[] { new Integer(16), new Long(17) }),
-				Arrays.asList(new Object[] { new Integer(17), new Long(18) }),
-				Arrays.asList(new Object[] { new Integer(18), new Long(19) }),
-				Arrays.asList(new Object[] { new Integer(19), new Long(20) }) };
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleDataBQT3(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
-				.exampleBQTCached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void testAggregateOnBQT2() throws Exception {
-		// Create query
-		String sql = "SELECT IntNum, IsNotNull FROM (SELECT IntNum, LongNum, COUNT(IntNum) AS IsNotNull FROM BQT1.SmallA GROUP BY IntNum, LongNum HAVING LongNum IS NULL ) AS x ORDER BY IntNum, IsNotNull"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-				Arrays.asList(new Object[] { new Integer(1), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(2), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(3), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(4), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(5), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(6), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(7), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(8), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(9), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(10), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(11), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(12), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(13), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(14), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(15), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(16), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(17), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(18), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(19), new Integer(1) }),
-				Arrays.asList(new Object[] { new Integer(20), new Integer(1) }) };
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleDataBQT3(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
-				.exampleBQTCached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void testAggregateOnBQT_defect9842() throws Exception {
-		// Create query
-		String sql = "SELECT IntKey, SUM((BigDecimalValue)*(ShortValue)-(BigDecimalValue)*(ShortValue)*(FloatNum)) " + //$NON-NLS-1$
-				"AS MySum FROM BQT1.SmallA GROUP BY IntKey ORDER BY IntKey"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-				Arrays.asList(new Object[] { new Integer(1),
-						new BigDecimal("110.5") }), //$NON-NLS-1$
-				Arrays.asList(new Object[] { new Integer(2),
-						new BigDecimal("254.5") }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleDataBQT_defect9842(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
-				.exampleBQTCached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-	
-    @Test public void testCase186260() {
-        /*
-         * This case revealed that an expression like "COUNT( DISTINCT e1 )", where the type of e1 is 
-         * anything but integer, was not handled properly.  We tried to use "integer" (the type of the
-         * COUNT expression) to work with the e1 tuples.
-         */
-        // Create query 
-        String sql = "SELECT COUNT(DISTINCT pm1.g2.e1), COUNT(DISTINCT pm1.g3.e1) FROM pm1.g2, pm1.g3"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(3), new Integer(3) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @SuppressWarnings("unchecked")
-	@Test public void testAggregatePushdown() {
-    	Command command = helpParse("select e1, count(e2), max(e2) from (select e1, e2, e3 from pm1.g1 union all select e1, e2, e3 from pm1.g2 union all select e1, e2, e3 from pm2.g1) z group by e1"); //$NON-NLS-1$
-    	
-    	FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-    	capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities()); //$NON-NLS-1$
-    	capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
-    	HardcodedDataManager dataManager = new HardcodedDataManager();
-    	
-    	dataManager.addData("SELECT v_0.c_0, COUNT(v_0.c_1), MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0", //$NON-NLS-1$ 
-    			new List[] {
-    				Arrays.asList("a", Integer.valueOf(2), Integer.valueOf(1)), //$NON-NLS-1$
-    			});
-    	dataManager.addData("SELECT v_0.c_0, COUNT(v_0.c_1), MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g2 AS g_0) AS v_0 GROUP BY v_0.c_0", //$NON-NLS-1$ 
-    			new List[] {
-    				Arrays.asList("a", Integer.valueOf(3), Integer.valueOf(2)), //$NON-NLS-1$
-    			});
-    	dataManager.addData("SELECT g_0.e1, g_0.e2 FROM pm2.g1 AS g_0", //$NON-NLS-1$ 
-    			new List[] {
-    				Arrays.asList("a", Integer.valueOf(3)), //$NON-NLS-1$
-    				Arrays.asList("xyz", Integer.valueOf(4)), //$NON-NLS-1$
-    				Arrays.asList(null, Integer.valueOf(5)),
-    			});
-    	
-    	ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-    	
-    	List[] expected = new List[] { 
-                Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(5)),
-                Arrays.asList("a", Integer.valueOf(6), Integer.valueOf(3)), //$NON-NLS-1$
-                Arrays.asList("xyz", Integer.valueOf(1), Integer.valueOf(4)) //$NON-NLS-1$
-            };    
-    	
-    	helpProcess(plan, dataManager, expected);
-    }
-    
-	@Test public void testUnionAggregatePushdown() {
-    	Command command = helpParse("select count(*), max(e3) from (select e1, e2, e3 from pm1.g1 union all (select convert(e2, string) as a, e2, e3 from pm2.g2 order by a limit 10)) x group by e1, e2"); //$NON-NLS-1$
-    	
-    	FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-    	capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities()); //$NON-NLS-1$
-    	BasicSourceCapabilities bac = TestAggregatePushdown.getAggregateCapabilities();
-    	bac.setFunctionSupport("convert", true); //$NON-NLS-1$
-    	capFinder.addCapabilities("pm2", bac); //$NON-NLS-1$
-    	HardcodedDataManager dataManager = new HardcodedDataManager();
-    	
-    	dataManager.addData("SELECT v_0.c_1, v_0.c_0, COUNT(*), MAX(v_0.c_2) FROM (SELECT g_0.e2 AS c_0, g_0.e1 AS c_1, g_0.e3 AS c_2 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0, v_0.c_1", //$NON-NLS-1$ 
-    			new List[] {
-    				Arrays.asList("2", Integer.valueOf(2), Integer.valueOf(2), Boolean.FALSE), //$NON-NLS-1$
-    				Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(3), Boolean.TRUE), //$NON-NLS-1$
-    			});
-    	dataManager.addData("SELECT v_0.c_1, v_0.c_0, COUNT(*), MAX(v_0.c_2) FROM (SELECT g_0.e2 AS c_0, convert(g_0.e2, string) AS c_1, g_0.e3 AS c_2 FROM pm2.g2 AS g_0 ORDER BY c_1 LIMIT 10) AS v_0 GROUP BY v_0.c_0, v_0.c_1", //$NON-NLS-1$ 
-    			new List[] {
-    				Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(4), Boolean.FALSE), //$NON-NLS-1$
-    			});
-    	
-    	ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-    	
-    	List[] expected = new List[] { 
-                Arrays.asList(Integer.valueOf(7), Boolean.TRUE),
-                Arrays.asList(Integer.valueOf(2), Boolean.FALSE),
-            };    
-    	
-    	helpProcess(plan, dataManager, expected);
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestBaseProcessorPlan.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestBaseProcessorPlan.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestBaseProcessorPlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,48 +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;
-
-import java.util.Collections;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixException;
-
-public class TestBaseProcessorPlan extends TestCase {
-
-    public TestBaseProcessorPlan(String name) {
-        super(name);
-    }
-
-    public void testGetAndClearWarnings() {        
-        FakeProcessorPlan plan = new FakeProcessorPlan(Collections.emptyList(), Collections.emptyList());
-        MetaMatrixException warning = new MetaMatrixException("test"); //$NON-NLS-1$
-        plan.addWarning(warning);
-        
-        List warnings = plan.getAndClearWarnings();
-        assertEquals("Did not get expected number of warnings", 1, warnings.size()); //$NON-NLS-1$
-        assertEquals("Did not get expected warning", warning, warnings.get(0)); //$NON-NLS-1$
-        assertNull("Did not clear warnings from plan", plan.getAndClearWarnings());         //$NON-NLS-1$
-    }
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestBatchIterator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestBatchIterator.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestBatchIterator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,54 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
-import com.metamatrix.query.processor.relational.FakeRelationalNode;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-
- at SuppressWarnings("nls")
-public class TestBatchIterator {
-
-	@Test public void testReset() throws Exception {
-		BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
-			Arrays.asList(1),
-			Arrays.asList(1),
-			Arrays.asList(1)
-		}, 1));
-		BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
-		bi.setBuffer(bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR), true);  //$NON-NLS-1$
-		bi.mark();
-		bi.nextTuple();
-		bi.nextTuple();
-		bi.reset();
-		bi.nextTuple();
-	}
-	
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestCollectionTupleSource.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestCollectionTupleSource.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestCollectionTupleSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,70 +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;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-/**
- */
-public class TestCollectionTupleSource {
-
-    @Test public void testNullSource() {
-        List<SingleElementSymbol> elements = new ArrayList<SingleElementSymbol>();
-        elements.add(new ElementSymbol("x")); //$NON-NLS-1$
-        elements.add(new ElementSymbol("y")); //$NON-NLS-1$
-        CollectionTupleSource nts = CollectionTupleSource.createNullTupleSource(elements);   
-        
-        // Check schema
-        assertEquals("Didn't get expected schema", elements, nts.getSchema()); //$NON-NLS-1$
-        
-        // Walk it and get no data
-        List tuple = nts.nextTuple();
-        nts.closeSource();
-
-        assertEquals("Didn't get termination tuple for first tuple", null, tuple);             //$NON-NLS-1$
-    }
-    
-    @Test public void testUpdateCountSource() {
-        CollectionTupleSource nts = CollectionTupleSource.createUpdateCountTupleSource(5);   
-        
-        // Check schema
-        assertEquals("Didn't get expected schema", Command.getUpdateCommandSymbol(), nts.getSchema()); //$NON-NLS-1$
-        
-        // Walk it and get no data
-        List tuple = nts.nextTuple();
-        nts.closeSource();
-
-        assertEquals("Didn't get termination tuple for first tuple", Arrays.asList(5), tuple);             //$NON-NLS-1$
-    }
-
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,783 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.processor.relational.JoinNode;
-import com.metamatrix.query.processor.relational.RelationalNode;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-
-
-public class TestDependentJoins extends TestCase {
-    
-    /** 
-     * @param sql
-     * @return
-     */
-    static ProcessorPlan helpGetPlan(String sql) {
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(2));
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false); //fake data manager doesn't support order by
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(TestProcessor.helpParse(sql),
-                                                       FakeMetadataFactory.example1Cached(),
-                                                       capFinder);
-        return plan;
-    }
-    
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin1() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin2() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       ProcessorPlan plan = helpGetPlan(sql);
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin3() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin4() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND concat(pm1.g1.e1, 'a') = concat(pm2.g1.e1, 'a') AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin5() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, 'a') = concat(pm2.g1.e1, 'a') AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    public void testMultiCritDepJoin5a() { 
-        // Create query 
-        String sql = "SELECT X.e1 FROM pm1.g1 as X, pm2.g1 WHERE concat(X.e1, 'a') = concat(pm2.g1.e1, 'a') AND X.e2=pm2.g1.e2 order by x.e1"; //$NON-NLS-1$
-       
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };    
-       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-   public void testMultiCritDepJoin5b() { 
-       //Create query 
-       String sql = "SELECT X.e1, X.e2 FROM pm1.g1 as X, pm2.g1 WHERE concat(X.e1, convert(X.e4, string)) = concat(pm2.g1.e1, convert(pm2.g1.e4, string)) AND X.e2=pm2.g1.e2 order by x.e1 option makedep x"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b", new Integer(2) }), //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = concat(pm2.g1.e1, '') AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin6() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = concat(pm2.g1.e1, '') AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, '') = pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
-    public void testMultiCritDepJoin7() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, '') = pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = pm2.g1.e1 AND pm1.g1.e2 <> pm2.g1.e2 */
-    public void testMultiCritDepJoin8() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = pm2.g1.e1 AND pm1.g1.e2 <> pm2.g1.e2 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql);
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 <> pm2.g1.e2 */
-    public void testMultiCritDepJoin9() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 <> pm2.g1.e2 option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { null }),
-           Arrays.asList(new Object[] { null }),
-           Arrays.asList(new Object[] { null }),
-           Arrays.asList(new Object[] { null }),
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }     
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e3=pm2.g1.e3 AND pm1.g1.e2=pm2.g1.e2 AND pm2.g1.e1 = 'a' */
-    public void testMultiCritDepJoin10() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e3=pm2.g1.e3 AND pm1.g1.e2=pm2.g1.e2 AND pm2.g1.e1 = 'a' option makedep pm1.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }       
-
-    public void testLargeSetInDepJoinWAccessPatternCausingSortNodeInsertCanHandleAlias() {
-        helpTestDepAccessCausingSortNodeInsert(true);
-    }
-    
-    public void testLargeSetInDepJoinWAccessPatternCausingSortNodeInsertCannotHandleAlias() {
-        helpTestDepAccessCausingSortNodeInsert(false);
-    }
-    
-    public void helpTestDepAccessCausingSortNodeInsert(boolean accessNodeHandlesAliases) {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e2=b.e2 AND a.e1 = b.e1 OPTION MAKEDEP a"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-              Arrays.asList(new Object[] { "aa ", "aa ", new Integer(0)}), //$NON-NLS-1$ //$NON-NLS-2$
-             Arrays.asList(new Object[] { "bb   ", "bb   ", new Integer(1)}), //$NON-NLS-1$ //$NON-NLS-2$
-             Arrays.asList(new Object[] { "cc  ", "cc  ", new Integer(2)}) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData2b(dataManager);
-
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
-        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        if(accessNodeHandlesAliases) {
-            depcaps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        }
-        
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        
-        capFinder.addCapabilities("pm4", depcaps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        // Slightly modify metadata to set max set size to just a few rows - this
-        // will allow us to test the dependent overflow case
-        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
-        
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
-        
-        //Verify a dependent join (not merge join) was used
-        assertTrue(plan instanceof RelationalPlan);
-        RelationalPlan relationalPlan = (RelationalPlan)plan;
-        RelationalNode project = relationalPlan.getRootNode();
-        RelationalNode join = project.getChildren()[0];
-        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);          
-    }
-    
-    public void testCase5130() {
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        String sql = "select a.intkey from bqt1.smalla a, bqt1.smallb b where concat(a.stringkey, 't') = b.stringkey option makedep a"; //$NON-NLS-1$ 
-         
-        // Plan query 
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, new String[] {"SELECT a.stringkey, a.intkey FROM bqt1.smalla AS a", "SELECT b.stringkey FROM bqt1.smallb AS b"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] { 
-            2,      // Access 
-            0,      // DependentAccess 
-            0,      // DependentSelect 
-            0,      // DependentProject 
-            0,      // DupRemove 
-            0,      // Grouping 
-            0,      // Join 
-            1,      // MergeJoin 
-            0,      // Null 
-            0,      // PlanExecution 
-            2,      // Project 
-            1,      // Select 
-            0,      // Sort 
-            0       // UnionAll 
-        });
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("SELECT g_0.stringkey FROM bqt1.smallb AS g_0",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1t" }), //$NON-NLS-1$
-                                         Arrays.asList(new Object[] { "2" })}); //$NON-NLS-1$
-        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1) })}); //$NON-NLS-1$
-        
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(1) }), 
-        };
-        
-        TestProcessor.helpProcess(plan, dataManager, expected);
-        
-        assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey, a.intkey FROM bqt1.smalla AS a WHERE concat(a.stringkey, 't') IN ('1', '2')")); //$NON-NLS-1$
-    }
-    
-    public void testCase5130a() throws Exception {
-        HardcodedDataManager dataManager = helpTestDependentJoin(false);
-        
-        assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey, a.intkey FROM bqt2.smalla AS a WHERE (concat(a.stringkey, 't') IN ('1t', '2')) AND (a.intkey IN (1))")); //$NON-NLS-1$
-    }
-    
-    public void testUnlimitedIn() throws Exception {
-    	helpTestDependentJoin(true);
-    }
-
-	private HardcodedDataManager helpTestDependentJoin(boolean unlimitIn)
-			throws MetaMatrixComponentException, MetaMatrixProcessingException {
-		FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
-        if (unlimitIn) {
-        	caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, -1);
-        }
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        
-        String sql = "select a.intkey from bqt1.smalla a, bqt2.smallb b where concat(a.stringkey, 't') = b.stringkey and a.intkey = b.intkey option makedep a"; //$NON-NLS-1$ 
-         
-        // Plan query 
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
-                                                    new String[] {"SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0 WHERE g_0.intkey IN (<dependent values>)", "SELECT g_0.stringkey, g_0.intkey FROM bqt2.smallb AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] { 
-            unlimitIn?2:1,      // Access 
-            unlimitIn?0:1,      // DependentAccess 
-            0,      // DependentSelect 
-            0,      // DependentProject 
-            0,      // DupRemove 
-            0,      // Grouping 
-            0,      // Join 
-            1,      // MergeJoin 
-            0,      // Null 
-            0,      // PlanExecution 
-            2,      // Project 
-            1,      // Select 
-            0,      // Sort 
-            0       // UnionAll 
-        });
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt2.smallb AS g_0",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1t", new Integer(1) }), //$NON-NLS-1$
-                                         Arrays.asList(new Object[] { "2t", new Integer(2) })}); //$NON-NLS-1$
-        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0 WHERE g_0.intkey IN (1, 2)",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1) })}); //$NON-NLS-1$
-        
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(1) }), 
-        };
-        
-        TestProcessor.helpProcess(plan, dataManager, expected);
-		return dataManager;
-	}
-    
-    static void sampleData4(FakeDataManager dataMgr) throws Exception {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        // Group pm1.g1
-        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-        List elementIDs = metadata.getElementIDsInGroupID(groupID);
-        List elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                } );       
-            
-        // Group pm6.g1
-        groupID = (FakeMetadataObject) metadata.getGroupID("pm6.g1"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { "b",   new Integer(0) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "d",   new Integer(3) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { "e",   new Integer(1) }), //$NON-NLS-1$
-                } );      
-    }
-
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1 */
-    public void testLargeSetInDepAccess() throws Exception {
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1"; //$NON-NLS-1$
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData4(dataManager);
-
-        // Slightly modify metadata to set max set size to just a few rows - this
-        // will allow us to test the dependent overflow case
-        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
-
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
-        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm6", depcaps); //$NON-NLS-1$
-
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] {
-                new String("b")})}; //$NON-NLS-1$
-
-        Command command = TestProcessor.helpParse(sql);
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-
-    public void testLargeSetInDepAccessMultiJoinCriteria() {
-        //     Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by e1 OPTION MAKEDEP pm2.g1"; //$NON-NLS-1$
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-
-        // Slightly modify metadata to set max set size to just a few rows - this
-        // will allow us to test the dependent overflow case
-        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
-
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
-        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", depcaps); //$NON-NLS-1$
-
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] {
-                new String("a")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("a")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("a")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("a")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("a")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("b")}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {
-                new String("c")})}; //$NON-NLS-1$
-
-        Command command = TestProcessor.helpParse(sql);
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-
-    }
-
-    public void testLargeSetInDepAccessWithAccessPattern() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e1=b.e1 AND a.e2 = b.e2"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] {
-                "aa ", "aa ", new Integer(0)}), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] {
-                "bb   ", "bb   ", new Integer(1)}), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] {
-                "cc  ", "cc  ", new Integer(2)}) //$NON-NLS-1$ //$NON-NLS-2$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData2b(dataManager);
-
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
-        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-
-        capFinder.addCapabilities("pm4", depcaps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
-
-        Command command = TestProcessor.helpParse(sql);
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
-
-        //Verify a dependent join (not merge join) was used
-        assertTrue(plan instanceof RelationalPlan);
-        RelationalPlan relationalPlan = (RelationalPlan)plan;
-        RelationalNode project = relationalPlan.getRootNode();
-        RelationalNode join = project.getChildren()[0];
-        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    /** SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g1.e2 = -100 OPTION MAKEDEP pm1.g2 */
-    public void testDependentNoRows() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g1.e2 = -100 OPTION MAKEDEP pm1.g2"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-       };    
-        
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-
-    /** SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE (pm1.g1.e2+1)=pm2.g1.e2 OPTION MAKEDEP pm1.g2 */
-    public void testExpressionInDepJoin() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE (pm1.g1.e2+1)=pm2.g1.e2 OPTION MAKEDEP pm2.g1"; //$NON-NLS-1$
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
-           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
-           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
-           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(2), new Integer(3) })
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       TestProcessor.sampleData1(dataManager);
-       
-       // Plan query
-
-       FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-       BasicSourceCapabilities caps = new BasicSourceCapabilities();
-       caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-       caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
-       capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-       capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-       
-       Command command = TestProcessor.helpParse(sql);   
-       ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-       // Run query
-       TestProcessor.helpProcess(plan, dataManager, expected);
-   }    
-    
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestInsertProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestInsertProcessing.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestInsertProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,406 +0,0 @@
-package com.metamatrix.query.processor;
-
-import static com.metamatrix.query.processor.TestProcessor.*;
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-
-public class TestInsertProcessing {
-	
-    @Test public void testSelectIntoWithTypeConversion() {
-        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
-        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
-        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true); 
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
-                                    new String[] { "e1", "e2", "e3" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataTypes.FLOAT});
-                                
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(pm1);
-        store.addObject(pm1g1);     
-        store.addObjects(pm1g1e);
-        
-        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("BatchedUpdate{I}",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
-        
-        String sql = "SELECT 1, convert(1, float), convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(1) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-        
-        BatchedUpdateCommand buc = (BatchedUpdateCommand)dataManager.getCommandHistory().iterator().next();
-        Insert insert = (Insert)buc.getUpdateCommands().get(0);
-                
-        Constant value0 = (Constant)insert.getValues().get(0);
-        Constant value1 = (Constant)insert.getValues().get(1);
-        
-        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
-        assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
-    }
-    
-    
-    @Test public void testSelectInto_Case5569a_BATCH_NO_BULK_NO() {
-        boolean doBatching  = false;
-        boolean doBulkInsert = false;
-        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
-    }    
-    
-    @Test public void testSelectInto_Case5569b_BATCH_YES_BULK_NO() {
-        boolean doBatching  = true;
-        boolean doBulkInsert = false;
-        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
-    }
-    
-    @Test public void testSelectInto_Case5569c_BATCH_NO_BULK_YES() {
-        boolean doBatching  = false;
-        boolean doBulkInsert = true;
-        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
-    }
-
-    public void helpSelectInto_Case5569Processor( boolean doBatching, boolean doBulkInsert ) {
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
- 
-        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching); 
-        caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert); 
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-
-        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
-                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
-        
-        if (doBulkInsert) {
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
-        } 
-        else 
-        if (doBatching) {
-            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
-        } else {
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
-        }
-
-        String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 INTO pm1.g2 from pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(2) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-        
-        // if not doBulkInsert and is doBatching,
-        //    check the command hist to ensure it contains the expected commands
-        if ( !doBulkInsert && doBatching ) {
-            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(1);
-            assertEquals(2, bu.getUpdateCommands().size());
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
-        }        
-    }
-    
-
-    @Test public void testSelectInto_Case5412a() {
-        
-        // test setting BULK_INSERT capability to true
-        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
-        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
- 
-        caps.setCapabilitySupport(Capability.BULK_UPDATE, true); 
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
-                                    new String[] { "e1", "e2" }, //$NON-NLS-1$ //$NON-NLS-2$ 
-                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT});
-                                
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(pm1);
-        store.addObject(pm1g1);     
-        store.addObjects(pm1g1e);
-        
-        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES (?, ?)",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
-        
-        String sql = "SELECT 1, convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(1) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-    }
-
-    
-    @Test public void testSelectInto_Case5412b() {
-        
-        // test setting BULK_INSERT capability to false
-        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
-        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
- 
-        caps.setCapabilitySupport(Capability.BULK_UPDATE, false); 
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
-                                    new String[] { "e1", "e2" }, //$NON-NLS-1$ //$NON-NLS-2$ 
-                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT});
-                                
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(pm1);
-        store.addObject(pm1g1);     
-        store.addObjects(pm1g1e);
-        
-        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES (1, 1.0)",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
-        
-        String sql = "SELECT 1, convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(1) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-        
-        Insert insert = (Insert)dataManager.getCommandHistory().iterator().next();
-        
-        Constant value0 = (Constant)insert.getValues().get(0);
-        Constant value1 = (Constant)insert.getValues().get(1);
-        
-        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
-        assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
-    }
-    
-    @Test public void testInsertIntoWithSubquery_None() {
-        helpInsertIntoWithSubquery( null );
-    }    
-    
-    @Test public void testInsertIntoWithSubquery_Batch() {
-        helpInsertIntoWithSubquery( Capability.BATCHED_UPDATES );
-    }
-    
-    @Test public void testInsertIntoWithSubquery_Bulk() {
-        helpInsertIntoWithSubquery( Capability.BULK_UPDATE );
-    }
-    
-    @Test public void testInsertIntoWithSubquery_Pushdown() {
-        helpInsertIntoWithSubquery( Capability.INSERT_WITH_QUERYEXPRESSION );
-    }
-
-    public void helpInsertIntoWithSubquery( Capability cap ) {
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
- 
-        caps.setCapabilitySupport(cap, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-
-        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
-                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
-        
-        if (cap != null) {
-        	switch (cap) {
-	        case BULK_UPDATE:
-	            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
-	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
-	            break;
-	        case BATCHED_UPDATES:
-	            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
-	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
-	            break;
-	        case INSERT_WITH_QUERYEXPRESSION:
-	        	dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
-	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
-	        	break;
-	        }
-        } else {
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
-        }
-
-        String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(2) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-        
-        // if not doBulkInsert and is doBatching,
-        //    check the command hist to ensure it contains the expected commands
-        if ( cap == Capability.BATCHED_UPDATES ) {
-            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(1);
-            assertEquals(2, bu.getUpdateCommands().size());
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
-        }        
-    }
-    
-    @Test public void testInsertIntoWithSubquery2_BATCH_NO_BULK_NO() {
-        boolean doBatching  = false;
-        boolean doBulkInsert = false;
-        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
-    }    
-    
-    @Test public void testInsertIntoWithSubquery2_BATCH_YES_BULK_NO() {
-        boolean doBatching  = true;
-        boolean doBulkInsert = false;
-        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
-    }
-    
-    @Test public void testInsertIntoWithSubquery2_BATCH_NO_BULK_YES() {
-        boolean doBatching  = false;
-        boolean doBulkInsert = true;
-        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
-    }
-
-    public void helpInsertIntoWithSubquery2( boolean doBatching, boolean doBulkInsert ) {
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
- 
-        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching); 
-        caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert); 
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-
-        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
-                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
-        
-        if (doBulkInsert) {
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
-        } 
-        else 
-        if (doBatching) {
-            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
-        } else {
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
-            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
-                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
-        }
-
-        String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1 UNION ALL SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1"; //$NON-NLS-1$
-//        String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 INTO pm1.g2 from pm1.g1"; //$NON-NLS-1$
-        
-        Command command = helpParse(sql); 
-
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
-        
-        List[] expected = new List[] {   
-            Arrays.asList(new Object[] { new Integer(4) }), 
-        }; 
-        
-        helpProcess(plan, dataManager, expected);
-        
-        // if not doBulkInsert and is doBatching,
-        //    check the command hist to ensure it contains the expected commands
-        if ( !doBulkInsert && doBatching ) {
-            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(2);
-            assertEquals(2, bu.getUpdateCommands().size());
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
-            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
-        }        
-    }
-    
-    @Test public void testInsertIntoVirtualWithQueryExpression() { 
-        String sql = "insert into vm1.g1 (e1, e2, e3, e4) select * from pm1.g1"; //$NON-NLS-1$
-        
-        List[] expected = new List[] { 
-            Arrays.asList(6),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestJoinWithFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestJoinWithFunction.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestJoinWithFunction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,437 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright (C) 2009 Red Hat, Inc.
- * Licensed to Red Hat, Inc. under one or more contributor 
- * license agreements.  See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- * 
- * 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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
-/**
- * <p><code>TestCase</code> to cover processing of JOINs which use a scalar 
- * function as a symbol or as part of the JOIN criteria.</p>
- * 
- * <p>All tests should verify and validate that the scalar function's result 
- * is being used appropriately from the pre-JOIN and post-JOIN aspect.  Most 
- * specifically, the results returned from the JOIN should match the expected 
- * results defined in each test method.</p>
- * @since 6.0
- */
-public class TestJoinWithFunction extends TestCase {
-
-	/**
-	 * <p>Test the use of a non-deterministic function on a user command that
-	 * performs a JOIN of two sources.</p>
-	 * 
-	 * <p>The function should be executed on the result returned from the JOIN and
-	 * is expected to be executed for each row of the final result set.</p>
-	 * @throws MetaMatrixComponentException 
-	 * @throws QueryMetadataException 
-	 */
-	public void testNonDeterministicPostJoin() throws QueryMetadataException, MetaMatrixComponentException {
-		// source query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// source query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. RandomTop is the use of RAND() on
-		 * the user command and should result in unique random numbers for each 
-		 * row in the JOINed output.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, RAND() AS RandomTop " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"("	+ rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-
-		/*
-		 * Populate a List with our expected results. We can predict the return value
-		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
-		 * number generator. 
-		 */
-		List<?>[] expected = new List[] {
-				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(0.24053641567148587) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(0.0), new Double(0.6374174253501083) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(0.5504370051176339) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-						new Boolean(false), null, new Double(0.5975452777972018) }), };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * <p>Test the use of a non-deterministic function on a source command of a JOIN
-	 * defined by a user command that performs a JOIN of two sources.</p>
-	 * 
-	 * <p>The function should be executed on the result that will be used for one side
-	 * of the JOIN.  The function should only be executed for each row of the the result
-	 * set returned from the left-side of the JOIN which should result in the same return 
-	 * value for multiple rows of the final result set after the JOIN is completed.  For 
-	 * example, if the left-side query is expected to return one row and the right-side 
-	 * query will return three rows which match the JOIN criteria for the one row on the 
-	 * left-side then the expected result should be that the function be executed once to 
-	 * represent the one row from the left-side and the function's return value will be 
-	 * repeated for each of the three post-JOINed results.</p>
-	 * @throws MetaMatrixComponentException 
-	 * @throws QueryMetadataException 
-	 */
-	public void testNonDeterministicPreJoin() throws QueryMetadataException, MetaMatrixComponentException {
-		// source query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// source query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. TopRandom is the use of RAND() on
-		 * the user command while RandomLeft is the use of RAND() within a
-		 * source node.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-
-		/*
-		 * Populate a List with our expected results. We can predict the return value
-		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
-		 * number generator. 
-		 */
-		List<?>[] expected = new List[] {
-				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(0.24053641567148587) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(0.0), new Double(0.6374174253501083) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(0.6374174253501083) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-						new Boolean(false), null, new Double(0.6374174253501083) }), 
-		};
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * <p>Test the use of a non-deterministic function on the sub-command of a user
-	 * command and the user command itself, which performs a JOIN of two sources.</p>
-	 * 
-	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
-	 * @see #testNonDeterministicPostJoin
-	 * @see #testNonDeterministicPreJoin
-	 * @throws MetaMatrixComponentException 
-	 * @throws QueryMetadataException 
-	 */
-	public void testNonDeterministicPrePostJoin() throws MetaMatrixComponentException, QueryMetadataException {
-		// source query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// source query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. TopRandom is the use of RAND() on
-		 * the user command while RandomLeft is the use of RAND() within a
-		 * source node.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft, RAND() AS RandomTop " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-		
-		/*
-		 * Populate a List with our expected results. We can predict the return value
-		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
-		 * number generator. 
-		 */
-		List<?>[] expected = new List[] {
-			Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-					new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-					new Boolean(true), new Double(2.0), new Double(0.24053641567148587), new Double(0.5975452777972018) }),
-			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-					new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-					new Boolean(false), new Double(0.0), new Double(0.6374174253501083), new Double(0.3332183994766498) }),
-			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-					new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-					new Boolean(true), new Double(2.0), new Double(0.6374174253501083), new Double(0.3851891847407185) }),
-			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-					new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-					new Boolean(false), null, new Double(0.6374174253501083), new Double(0.984841540199809) })
-		};
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * <p>Test the use of a deterministic function on the user command which
-	 * performs a JOIN of two sources.</p>
-	 * 
-	 * <p>The function should be executed prior to the JOIN being executed and should 
-	 * result in the projected symbol becoming a constant.</p>
-	 * @throws MetaMatrixComponentException
-	 * @throws QueryMetadataException
-	 */
-	public void testDeterministicPostJoin() throws MetaMatrixComponentException, QueryMetadataException {
-		// source query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// source query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
-		 * the user command and should result in 10 for each row in the JOINed 
-		 * output.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-
-		/*
-		 * Populate a List with our expected results.  
-		 */
-		List<?>[] expected = new List[] {
-				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(0.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-						new Boolean(false), null, new Double(10) }), 
-		};
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * <p>The function should be executed prior to the JOIN being executed and should 
-	 * result in the projected symbol becoming a constant.</p>
-
-	 * <p>Test the use of a deterministic function on the source command of a JOIN
-	 * defined by a user command which performs a JOIN of two sources.</p>
-	 * 
-	 * <p>The function should be executed prior to the commands from either side of the
-	 * JOIN being executed and merged into user command prior to the JOIN actually being 
-	 * executed.</p>
-	 * @throws MetaMatrixComponentException 
-	 * @throws QueryMetadataException 
-	 */
-	public void testDeterministicPreJoin() throws QueryMetadataException, MetaMatrixComponentException {
-		// source query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// source query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. SqrtLeft is the use of SQRT() 
-		 * within a source node.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-
-		/*
-		 * Populate a List with our expected results. 
-		 */
-		List<?>[] expected = new List[] {
-				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(0.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-						new Boolean(false), null, new Double(10) }), 
-		};
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * <p>Test the use of a deterministic function on the sub-command of a user
-	 * command and the user command itself, which performs a JOIN of two sources.</p>
-	 * 
-	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
-	 * @throws MetaMatrixComponentException 
-	 * @throws QueryMetadataException 
-	 * @see #testDeterministicPostJoin
-	 * @see #testDeterministicPreJoin
-	 */
-	public void testDeterministicPrePostJoin() throws QueryMetadataException, MetaMatrixComponentException {
-		// sub-query for one side of a JOIN
-		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
-				+ "FROM pm1.g1"; //$NON-NLS-1$
-		// sub-query for other side of a JOIN
-		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
-				+ "FROM pm2.g2"; //$NON-NLS-1$
-
-		// User Command
-		/*
-		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
-		 * the user command while SqrtLeft is the use of SQRT() within a
-		 * source node.
-		 */
-		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
-				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
-				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
-				"WHERE l.ID = r.ID"; //$NON-NLS-1$
-
-		/*
-		 * Populate a List with our expected results. 
-		 */
-		List<?>[] expected = new List[] {
-				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10.0), new Double(10.0) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
-						new Boolean(false), new Double(0.0), new Double(10.0), new Double(10.0) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
-						new Boolean(true), new Double(2.0), new Double(10.0), new Double(10.0) }),
-				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
-						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
-						new Boolean(false), null, new Double(10.0), new Double(10.0) }), 
-		};
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        FakeDataStore.sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-	}
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestOptionalJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestOptionalJoins.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestOptionalJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,491 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
-public class TestOptionalJoins {
-    
-    @Test public void testOptionalJoinNode1() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2 where pm1.g1.e1 = 'a'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode2() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2, pm1.g3 where pm1.g1.e1 = 'a' and pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode3() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode4() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode5() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$       
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode6() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode7() { 
-        // Create query 
-        String sql = "SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode8() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ (select * from pm1.g2) as X on pm1.g1.e1 = x.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode9() { 
-        // Create query 
-        String sql = "SELECT pm1.g2.e1 FROM pm1.g2, /* optional */ vm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode10() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM /* optional */ vm1.g1, pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode11() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ vm1.g2 on pm1.g1.e1 = vm1.g2.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode12() { 
-        // Create query 
-        String sql = "SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN vm1.g1 on pm1.g1.e1 = vm1.g1.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode13() { 
-        // Create query 
-        String sql = "SELECT count(pm1.g1.e1) FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(5) }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode15() { 
-        // Create query 
-        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode16() { 
-        // Create query 
-        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x order by x.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode17() { 
-        // Create query 
-        String sql = "SELECT length(z) FROM /* optional */ pm1.g1, (select distinct e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY y, z) AS x"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(5) }),
-            Arrays.asList(new Object[] { new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(5) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode18() { 
-        // Create query 
-        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }), 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOptionalJoinNode19() { 
-        // Create query 
-        String sql = "SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(6) }), 
-            Arrays.asList(new Object[] { new Integer(6) }), 
-            Arrays.asList(new Object[] { new Integer(5) }), 
-            Arrays.asList(new Object[] { new Integer(5) }), 
-            Arrays.asList(new Object[] { new Integer(6) }), 
-            Arrays.asList(new Object[] { new Integer(6) }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }    
-
-    
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,763 +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;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-import org.teiid.client.metadata.ParameterInfo;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.processor.proc.CreateCursorResultSetInstruction;
-import com.metamatrix.query.processor.proc.ProcedurePlan;
-import com.metamatrix.query.processor.proc.TestProcedureProcessor;
-import com.metamatrix.query.processor.relational.DependentProcedureExecutionNode;
-import com.metamatrix.query.processor.relational.RelationalNode;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-
-public class TestProcedureRelational {
-
-    @Test public void testProcInExistsSubquery() throws Exception {
-        String sql = "select pm1.g1.e1 from pm1.g1 where exists (select * from (EXEC pm1.vsp9(pm1.g1.e2 + 1)) x where x.e1 = pm1.g1.e1)"; //$NON-NLS-1$
-
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-        };    
-
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testProcInSelectScalarSubquery() throws Exception {
-        String sql = "select (EXEC pm1.vsp36(pm1.g1.e2)) from pm1.g1 where pm1.g1.e1 = 'a'"; //$NON-NLS-1$
-
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) }), 
-            Arrays.asList(new Object[] { new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(0) }), 
-        };    
-
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testProcAsTable(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    //virtual group with procedure in transformation
-    @Test public void testAliasedProcAsTable(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 as x where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-
-    @Test public void testAliasedJoin(){
-        String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = 2 and y.param2 = 'b'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "a", new Integer(2), "b", "a"}), //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-
-    
-    @Test public void testAliasedJoin1(){
-        String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = x.param1 and y.param2 = x.param2"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "a", new Integer(1), "a", "a"}), //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    /**
-     * Will fail due to access pattern validation (missing param2 assignment) 
-     */
-    @Test public void testProcAsTable1(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1"; //$NON-NLS-1$
-
-        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
-    }
-
-    /**
-     * Will fail since less than does not constitue an input 
-     */
-    @Test public void testProcAsTable2(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1<1 and param2='a'"; //$NON-NLS-1$
-
-        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false); 
-    }
-    
-    @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') order by param1, param2"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { new Integer(1), "b", "b", new Integer(2)}), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { new Integer(2), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { new Integer(2), "b", "b", new Integer(2)}), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { new Integer(3), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    /**
-     * Will fail missing param2 assignment 
-     */
-    @Test public void testProcAsTable4(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and not(param2 = 'a')"; //$NON-NLS-1$
-
-        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
-    }
-    
-    /**
-     * Will fail missing param2 assignment 
-     */
-    @Test public void testProcAsTable5(){
-        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=e2 and param2 = 'a'"; //$NON-NLS-1$
-
-        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
-    }
-    
-    @Test public void testProcAsTableInJoin(){
-        String sql = "select param1, param2, pm1.vsp26.e2 from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(1), "c", new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(2), "b", new Integer(2)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(3), "a", new Integer(3)}), //$NON-NLS-1$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsTableInSubquery(){
-        String sql = "select param1, param2, pm1.vsp26.e2, (select count(e1) from pm1.vsp26 where param1 = 1 and param2 = 'a') x from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(1), "c", new Integer(1), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(2), "b", new Integer(2), new Integer(1)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(3), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    private void helpTestProcRelational(String userQuery,
-                                        String inputCriteria,
-                                        String atomicQuery) {
-        ProcessorPlan plan = TestOptimizer.helpPlan(userQuery, FakeMetadataFactory.example1Cached(), 
-            new String[] {} ); 
-        
-        RelationalPlan rplan = (RelationalPlan)plan;
-
-        RelationalNode root = rplan.getRootNode();
-        
-        while (root.getChildren() != null) {
-            root = root.getChildren()[0];
-            
-            if (root instanceof DependentProcedureExecutionNode) {
-                break;
-            }
-        }
-        
-        DependentProcedureExecutionNode dep = (DependentProcedureExecutionNode)root;
-        
-        assertEquals(inputCriteria, dep.getInputCriteria().toString()); 
-        
-        ProcedurePlan pp = (ProcedurePlan)dep.getProcessorPlan();
-        
-        CreateCursorResultSetInstruction ccrsi = (CreateCursorResultSetInstruction)pp.getOriginalProgram().getInstructionAt(0);
-        
-        plan = ccrsi.getCommand();
-        
-        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
-        
-        TestOptimizer.checkAtomicQueries(new String[] {atomicQuery}, plan);
-    }
-    
-    //virtual group with procedure in transaformation
-    @Test public void testProcInVirtualGroup1() {
-        
-        String userQuery = "select e1 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
-        String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
-        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
-        
-        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
-    }
-
-    //virtual group with procedure in transformation
-    @Test public void testCase3403() {        
-        String userQuery = "select e1 from pm1.vsp26 where param1=2 and param2='a' and 'x'='x'"; //$NON-NLS-1$
-        String inputCriteria = "(pm1.vsp26.param1 = 2) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
-        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
-        
-        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
-    }
-    
-    @Test public void testCase3448() {
-        String userQuery = "select e1 from pm1.vsp26 where (param1=1 and e2=2) and param2='a'"; //$NON-NLS-1$
-        String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
-        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
-        
-        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
-    }
-    
-    @Test public void testProcAsVirtualGroup2(){
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup3(){
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup4(){
-        String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, pm1.g2 where P.e1=g2.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup5(){
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a' and e1='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup6(){
-        String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup7(){
-        String sql = "SELECT e1 FROM (SELECT p.e1, param1, param2 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1) x where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testProcAsVirtualGroup10_Defect20164(){
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where (param1=1 and param2='a') and e1='c'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testProcAsVirtualGroup8(){
-        String sql = "SELECT P.e1 as ve3, P.e2 as ve4 FROM pm1.vsp26 as P where param1=1 and param2='a' and e2=3"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", new Integer(3)}), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-
-    //virtual group with procedure in transformation
-    @Test public void testProcAsVirtualGroup9(){
-        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "FOO" }), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }    
-    
-    /**
-     * Relies upon a default value of null for param1 
-     * 
-     * This is marked as defered since it is not desirable to support this behavior for a single default value
-     */
-    public void defer_testProcAsVirtualGroup9a(){
-        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(2112), "a" }), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }    
-    
-    /**
-     * Relies upon a default value of null for both parameters 
-     * 
-     * This is marked as defered since it is not desirable to support this behavior for a single default value
-     */
-    public void defer_testProcAsVirtualGroup9b(){
-        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(2112), null }) 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-
-    /**
-     *  test for defect 22376
-     */
-    @Test public void testParameterPassing() throws Exception {
-        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
-        
-        FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.rs1", v1, new String[] {"e1"}, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$ 
-        FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);  //$NON-NLS-1$
-
-        QueryNode n1 = new QueryNode("v1.vp1", "CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; SELECT e1 FROM v1.vp2 where v1.vp2.in = VARIABLES.x; END"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualProcedure("v1.vp1", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1 }), n1); //$NON-NLS-1$
-        
-        FakeMetadataObject p1 = FakeMetadataFactory.createParameter("v1.vp2.in", 2, ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING, null);  //$NON-NLS-1$
-        QueryNode n2 = new QueryNode("v1.vp2", "CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x; declare string VARIABLES.y; VARIABLES.x = '2'; VARIABLES.y = v1.vp2.in; select VARIABLES.y; end"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vt2 = FakeMetadataFactory.createVirtualProcedure("v1.vp2", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1, p1 }), n2); //$NON-NLS-1$
-                
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(v1);
-        store.addObject(rs1);
-        store.addObject(vt1);
-        store.addObject(vt2);
-        store.addObject(vt2);
-        
-        String sql = "select * from (exec v1.vp1()) foo"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {  
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$ 
-        };        
-        
-        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
-        
-        // Construct data manager with data 
-        // Plan query 
-        ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);        
-        // Run query 
-        TestProcedureProcessor.helpTestProcess(plan, expected, new FakeDataManager());  
-               
-    }
-
-    //virtual group with procedure in transformation
-    @Test public void testCase6395ProcAsVirtualGroup9(){
-        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), "FOO" }), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }    
-        
-    /**
-     *  Case 6395 - This test case will now raise a QueryPlannerException.  param2 is required
-     *  and not nullable.  This case is expected to fail because of 'param2 is null' 
-     */
-    @Test public void testProcAsVirtualGroup2WithNull() throws Exception {
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 is null"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        try {
-        	ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
-            // Run query
-            TestProcessor.doProcess(plan, dataManager, expected, TestProcessor.createCommandContext()); 
-            fail("QueryPlannerException was expected.");  //$NON-NLS-1$
-        } catch (QueryValidatorException e) {
-        	assertEquals("The procedure parameter is not nullable, but is set to null: pm1.vsp26.param2",e.getMessage());  //$NON-NLS-1$
-        }
-    }
-    
-    /**
-     *  Case 6395 - This case is expected to succeed.  param1 and param2 are both required, but nulls 
-     *  are acceptable for both.
-     */
-    @Test public void testProcAsVirtualGroup2WithNull2() throws Exception {
-        String sql = "select * from pm1.vsp47 where param1 is null and param2 is null"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-                Arrays.asList(new Object[] { null, new Integer(2112), null, null }) 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-    
-    /**
-     *  Case 6395 - This will not throw an exception and the proc will not be invoked.
-     */
-    @Test public void testProcAsVirtualGroup2WithNull3() throws Exception {
-        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 = commandpayload()"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected); 
-    }
-       
-    /*
-     * The following are tests that were removed from the validator.  We are no longer trying to validate a priori whether 
-     * procedure input criteria is valid.  This can be addressed later more generally when we do up front validation of
-     * access patterns and access patterns have a wider range of semantics.
-     * 
-    @Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
-        helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-   
-    @Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
-        helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-    
-    @Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
-        helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
-    }
-    
-    @Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
-        helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
-    }    
-
-    @Test public void testDefect15861() throws Exception{
-        helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    }
-
-    @Test public void testProcInVirtualGroup1_Defect20164() {
-        helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup2_Defect20164() {
-        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup3_Defect20164() {
-        helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup4_Defect20164() {
-        helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup5_Defect20164() {
-        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup6_Defect20164() {
-        helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }
-
-    @Test public void testProcInVirtualGroup7_Defect20164() {
-        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-    }*/
-    
-    /**
-     * Ensures that dependent procedures are processed 1 at a time so that projected input values
-     * are set correctly.
-     */
-    @Test public void testIssue119() throws Exception {
-        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
-        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
-        
-        FakeMetadataObject in = FakeMetadataFactory.createParameter("v1.vp1.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
-        FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.vp1.rs1", v1, new String[] {"e1", "e2", "e3", "e4", "e5"}, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ 
-        FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);  //$NON-NLS-1$
-
-        QueryNode n1 = new QueryNode("v1.vp1", "CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualProcedure("v1.vp1", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1, in }), n1); //$NON-NLS-1$
-        
-        FakeMetadataObject in1 = FakeMetadataFactory.createParameter("pm1.sp119.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
-		FakeMetadataObject rs3 = FakeMetadataFactory.createResultSet("pm1.sp119.rs1", pm1, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ 
-        FakeMetadataObject rs3p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs3);  //$NON-NLS-1$
-		FakeMetadataObject sp1 = FakeMetadataFactory.createStoredProcedure("pm1.sp119", pm1, Arrays.asList(new FakeMetadataObject[] { rs3p1, in1 }), "pm1.sp119");  //$NON-NLS-1$ //$NON-NLS-2$
-
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(pm1);
-        store.addObject(v1);
-        store.addObject(rs1);
-        store.addObject(vt1);
-        store.addObject(sp1);
-        
-        String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5"; //$NON-NLS-1$
-        
-        List<?>[] expected = new List[] {
-        	Arrays.asList(1, 1, 3, 3, 5),	
-        	Arrays.asList(1, 1, 3, 3, 8),
-        	Arrays.asList(1, 1, 6, 6, 8),
-        	Arrays.asList(1, 1, 6, 6, 11),
-        };
-        
-        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
-        
-        // Construct data manager with data 
-        // Plan query 
-        ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);        
-        // Run query 
-        HardcodedDataManager dataManager = new HardcodedDataManager() {
-        	@Override
-        	public TupleSource registerRequest(Object processorID,
-        			Command command, String modelName,
-        			String connectorBindingId, int nodeID)
-        			throws MetaMatrixComponentException {
-        		if (command instanceof StoredProcedure) {
-        			StoredProcedure proc = (StoredProcedure)command;
-        			List<SPParameter> params = proc.getInputParameters();
-        			assertEquals(1, params.size());
-        			int value = (Integer)((Constant)params.get(0).getExpression()).getValue();
-        			return new FakeTupleSource(command.getProjectedSymbols(), new List[] {
-        				Arrays.asList(value+2), Arrays.asList(value+5)
-        			});
-        		}
-        		return super.registerRequest(processorID, command, modelName,
-        				connectorBindingId, nodeID);
-        	}
-        };
-        
-        TestProcedureProcessor.helpTestProcess(plan, expected, dataManager);  
-               
-    }
-    
-    @Test public void testProcRelationalWithNoInputs() {
-    	String sql = "select e1 from pm1.vsp2 order by e1 desc limit 1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-        		Arrays.asList("c") //$NON-NLS-1$
-        };        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        TestProcessor.sampleData1(dataManager);       
-        // Plan query
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,7487 +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;
-
-import static org.junit.Assert.*;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.junit.Test;
-import org.teiid.client.metadata.ParameterInfo;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.function.FunctionTree;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.function.UDFSource;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.FakeFunctionMetadataSource;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.TestRuleRaiseNull;
-import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.relational.JoinNode;
-import com.metamatrix.query.processor.relational.RelationalNode;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.resolver.util.BindVariableVisitor;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.util.VariableContext;
-import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.unittest.TimestampUtil;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.validator.Validator;
-import com.metamatrix.query.validator.ValidatorReport;
-
-public class TestProcessor {
-
-	// ################################## TEST HELPERS ################################
-
-    static Command helpParse(String sql) { 
-        // parse
-        try { 
-            return QueryParser.getQueryParser().parseCommand(sql);
-        } catch(MetaMatrixException e) { 
-            throw new MetaMatrixRuntimeException(e);
-        }
-    }
-
-	public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata) { 
-        return helpGetPlan(sql, metadata, null);
-    }
-    
-    public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata, String[] bindings) { 
-        if(DEBUG) System.out.println("\n####################################\n" + sql);  //$NON-NLS-1$
-
-        Command command = helpParse(sql);   
-        
-        // attach bindings
-        if(bindings != null) { 
-            try { 
-                BindVariableVisitor.bindReferences(command, Arrays.asList(bindings), metadata);
-            } catch(Throwable e) {
-                throw new MetaMatrixRuntimeException(e);
-            }
-        }
-        
-    	ProcessorPlan process = helpGetPlan(command, metadata);
-        
-        return process;
-    }
-
-    static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata) {
-        return helpGetPlan(command, metadata, new DefaultCapabilitiesFinder());
-    }
-    
-	static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) {
-        CommandContext context = new CommandContext();
-        context.setProcessorBatchSize(2000);
-        context.setConnectorBatchSize(2000);
-	    return helpGetPlan(command, metadata, capFinder, context);
-    }
-	
-    static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) {
-		if(DEBUG) System.out.println("\n####################################\n" + command); //$NON-NLS-1$
-		AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
-		try {
-			QueryResolver.resolveCommand(command, metadata);
-        
-			ValidatorReport repo  = Validator.validate(command, metadata);
-	        Collection failures = new ArrayList();
-	        repo.collectInvalidObjects(failures);
-	        if (failures.size() > 0){
-	            fail("Exception during validation (" + repo); //$NON-NLS-1$
-	        }        
-			command = QueryRewriter.rewrite(command, metadata, createCommandContext());
-	        ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
-			if(DEBUG) System.out.println("\n" + process); //$NON-NLS-1$
-	        //per defect 10022, clone this plan before processing, just to make sure
-	        //a cloned plan with correlated subquery references (or any cloned plan) can be processed
-	        process = process.clone();
-	        
-	        assertNotNull("Output elements of process plan are null", process.getOutputElements()); //$NON-NLS-1$
-
-			return process;
-        } catch (MetaMatrixComponentException e) {
-            throw new RuntimeException(e);
-		} catch (MetaMatrixProcessingException e) {
-			throw new RuntimeException(e);
-		} finally {
-            if(DEBUG) {
-                System.out.println(analysisRecord.getDebugLog());
-            }
-        }
-	}
-
-    public static void helpProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults) {    
-        CommandContext context = createCommandContext();
-        helpProcess(plan, context, dataManager, expectedResults);
-    }
-    
-    public static void helpProcess(ProcessorPlan plan, CommandContext context, ProcessorDataManager dataManager, List[] expectedResults) {
-        try {
-            ProcessorPlan clonePlan = plan.clone();
-            
-            // Process twice to test reset and clone
-            doProcess(plan, dataManager, expectedResults, context);
-            plan.reset();
-            doProcess(plan, dataManager, expectedResults, context);
-
-            // Execute cloned of original plan
-            doProcess(clonePlan, dataManager, expectedResults, context);
-        } catch (Exception ex) {
-            throw new RuntimeException(ex);
-        }
-    }
-
-    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager) {
-        helpProcessException(plan, dataManager, null);
-    }
-    
-    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
-    	TupleBuffer tsId = null;
-    	BufferManager bufferMgr = null;
-        try {   
-            bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
-            CommandContext context = new CommandContext("0", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
-            QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
-            processor.setNonBlocking(true);
-            BatchCollector collector = processor.createBatchCollector();
-            tsId = collector.collectTuples();
-            fail("Expected error during processing, but got none."); //$NON-NLS-1$
-        } catch(MetaMatrixCoreException e) {
-            // ignore - this is expected
-            if(expectedErrorMessage != null) {
-                assertEquals(expectedErrorMessage, e.getMessage());
-            }
-        } finally {
-        	if (tsId != null) {
-        		tsId.remove();
-        	}
-        }
-    }
-        
-    public static void doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
-        BufferManagerImpl bufferMgr = (BufferManagerImpl)BufferManagerFactory.getStandaloneBufferManager();
-        bufferMgr.setProcessorBatchSize(context.getProcessorBatchSize());
-        bufferMgr.setConnectorBatchSize(context.getProcessorBatchSize());
-        context.getNextRand(0);
-        TupleBuffer id = null;
-        try {
-            QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
-            processor.setNonBlocking(true);
-            BatchCollector collector = processor.createBatchCollector();
-            id = collector.collectTuples();
-            if ( expectedResults != null ) {
-            	examineResults(expectedResults, bufferMgr, id);
-            }
-        } finally {
-        	if (id != null) {
-        		id.remove();
-        	}
-        }
-    }
-
-    /** 
-     * @param expectedResults
-     * @param bufferMgr
-     * @param tsID
-     * @throws MetaMatrixComponentException
-     * @throws MetaMatrixProcessingException 
-     * @since 4.3
-     */
-    static void examineResults(List[] expectedResults,BufferManager bufferMgr,TupleBuffer tsID) 
-        throws MetaMatrixComponentException,SQLException, MetaMatrixProcessingException {
-        
-        // Create QueryResults from TupleSource
-        TupleSource ts = tsID.createIndexedTupleSource();
-        int count = tsID.getRowCount();   
-
-		if(DEBUG) {
-            System.out.println("\nResults:\n" + tsID.getSchema()); //$NON-NLS-1$
-            TupleSource ts2 = tsID.createIndexedTupleSource();
-            for(int j=0; j<count; j++) {
-                System.out.println("" + j + ": " + ts2.nextTuple());	 //$NON-NLS-1$ //$NON-NLS-2$
-            }    
-            ts2.closeSource();
-        }
-        
-        // Compare actual to expected row count
-        assertEquals("Did not get expected row count: ", expectedResults.length, count); //$NON-NLS-1$
-     
-        // Walk results and compare
-        for(int i=0; i<count; i++) { 
-            List record = ts.nextTuple();
-            
-            //handle xml
-            if(record.size() == 1){
-            	Object cellValue = record.get(0);
-            	if(cellValue instanceof XMLType){
-                    XMLType id =  (XMLType)cellValue; 
-                    String actualDoc = id.getString(); 
-                    record = new ArrayList(record);
-                    record.set(0, actualDoc);
-            	}
-            	if (expectedResults[i].size() == 1) {
-                    assertEquals("Row " + i + " does not match expected: ", expectedResults[i].get(0), record.get(0));                 //$NON-NLS-1$ //$NON-NLS-2$
-                    continue;
-            	}
-            }
-            
-            assertEquals("Row " + i + " does not match expected: ", expectedResults[i], record);                 //$NON-NLS-1$ //$NON-NLS-2$
-        }
-        ts.closeSource();
-    }
-
-	public static CommandContext createCommandContext() {
-		Properties props = new Properties();
-		props.setProperty("soap_host", "my.host.com"); //$NON-NLS-1$ //$NON-NLS-2$
-		props.setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
-		CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-        context.setProcessorBatchSize(2000);
-        context.setConnectorBatchSize(2000);
-        context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
-		return context;
-	}   
-    	
-    public static void sampleData1(FakeDataManager dataMgr) {
-        try { 
-        	FakeDataStore.sampleData1(dataMgr);
-        } catch(Throwable e) { 
-        	throw new RuntimeException(e);
-        }
-    }                    
-    
-    private void sampleData2(FakeDataManager dataMgr) {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-            List elementIDs = metadata.getElementIDsInGroupID(groupID);
-            List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );       
-
-            // Group pm1.g2
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "a",   new Integer(1),     Boolean.TRUE,   new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(5),     Boolean.TRUE,   new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "d",   new Integer(2),     Boolean.FALSE,  new Double(1.0) }), //$NON-NLS-1$
-                    } ); 
-                
-            // Group pm2.g1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    } );      
-                                     
-            // Group pm1.table1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm1.table1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );                                     
-                                     
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }                  
-
-    private void sampleData2a(FakeDataManager dataMgr) {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-            List elementIDs = metadata.getElementIDsInGroupID(groupID);
-            List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );       
-                
-            // Group pm2.g1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(7),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    } );      
-
-            // Group pm4.g1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm4.g1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "aa",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "bb",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "cc",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );              
-            
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }    
-    
-    public static void sampleData2b(FakeDataManager dataMgr) {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-            List elementIDs = metadata.getElementIDsInGroupID(groupID);
-            List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "aa ",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "bb   ",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "cc  ",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );       
-                
-            // Group pm2.g1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    } );      
-
-            // Group pm4.g1
-            groupID = (FakeMetadataObject) metadata.getGroupID("pm4.g1"); //$NON-NLS-1$
-            elementIDs = metadata.getElementIDsInGroupID(groupID);
-            elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { "aa ",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "bb   ",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "cc  ",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );       
-            
-            
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }    
-    
-    private void sampleData3(FakeDataManager dataMgr) {
-    	FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-            List elementSymbols = new ArrayList(1);
-            ElementSymbol count = new ElementSymbol("Count"); //$NON-NLS-1$
-            count.setType(Integer.class);
-            elementSymbols.add(count);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { new Integer(1) }),                    
-                    } );    
-        }catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }
-
-    private void sampleDataStringTimestamps(FakeDataManager dataMgr) {
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
-            List elementIDs = metadata.getElementIDsInGroupID(groupID);
-            List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                new List[] { 
-                    Arrays.asList(new Object[] { "Jan 01 2004 12:00:00",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "Dec 31 2004 12:00:00",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "Aug 01 2004 12:00:00",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-                    } );       
-
-                                     
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }     
-    
-    private void sampleDataBQT1(FakeDataManager dataMgr) {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        try { 
-            // Group bqt1.smalla
-        
-            List[] tuples = new List[20];
-            for(int i=0; i<tuples.length; i++) {
-                tuples[i] = new ArrayList(17);
-                tuples[i].add(new Integer(i));
-                for(int j=0; j<16; j++) {
-                    tuples[i].add(null);    
-                }    
-            }
-        
-            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
-
-            // Group bqt2.mediumb
-            tuples = new List[20];
-            for(int i=0; i<tuples.length; i++) {
-                tuples[i] = new ArrayList(17);
-                tuples[i].add(new Integer(i));
-                for(int j=0; j<16; j++) {
-                    tuples[i].add(null);    
-                }    
-            }
-        
-            dataMgr.registerTuples(metadata, "bqt2.mediumb", tuples); //$NON-NLS-1$
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }
-
-	private void sampleDataBQT2(FakeDataManager dataMgr) {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        String[] groups = new String[] {"bqt1.smalla", "bqt2.smalla", "bqt3.smalla" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    
-        try { 
-            for(int i=0; i<groups.length; i++) {
-                String groupName = groups[i];
-    
-                List[] tuples = new List[30];
-                for(int row=0; row<tuples.length; row++) {
-                    tuples[row] = new ArrayList(17);
-                    tuples[row].add(new Integer(row));
-                    for(int col=0; col<16; col++) {
-                        tuples[row].add(null);    
-                    }    
-                }
-        
-                dataMgr.registerTuples(metadata, groupName, tuples);
-            }
-
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }
-    
-    /**
-     * Just want to register two rows of all the integral types to test AVG 
-     * @param dataMgr
-     * @since 4.2
-     */
-    private void sampleDataBQT_defect11682(FakeDataManager dataMgr) {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        try { 
-            List[] tuples = new List[2];
-            for(int i=1; i<=tuples.length; i++) {
-                int index=i-1;
-                tuples[index] = new ArrayList(17);
-                tuples[index].add(new Integer(i)); //IntKey
-                tuples[index].add(null);
-                tuples[index].add(new Integer(i));
-                tuples[index].add(null);
-                tuples[index].add(new Float(i));
-                tuples[index].add(new Long(i));
-                tuples[index].add(new Double(i));
-                tuples[index].add(new Byte((byte)i));
-                tuples[index].add(null);
-                tuples[index].add(null);
-                tuples[index].add(null);
-                tuples[index].add(null);
-                tuples[index].add(null);
-                tuples[index].add(new Short((short)i));
-                tuples[index].add(new BigInteger(i+"")); //$NON-NLS-1$
-                tuples[index].add(new BigDecimal(i+".0")); //$NON-NLS-1$
-                tuples[index].add(null);
-            }
-            
-            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$ 
-            
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }    
-
-    private void sampleDataBQTSmall(FakeDataManager dataMgr) {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        try { 
-            List[] tuples = new List[1];
-            for(int i=0; i<tuples.length; i++) {
-                tuples[i] = new ArrayList(17);
-                tuples[i].add(new Integer(i));
-                for(int j=0; j<16; j++) {
-                    tuples[i].add(null);    
-                }    
-            }
-        
-            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$ 
-
-        } catch(MetaMatrixException e) { 
-        	throw new RuntimeException(e);
-        }
-    }
-
-    private List createRowWithTimestamp(String tsStr) {
-        Timestamp ts = Timestamp.valueOf(tsStr);
-        return Arrays.asList(new Object[] {
-            new Integer(0), "a", new Integer(1), "a",  //$NON-NLS-1$ //$NON-NLS-2$
-            null, null, null, null, null, null, ts, null, null, null, null, null, null   
-        });
-    }
-            
-    private void sampleDataBQT_case1566(FakeDataManager dataMgr) throws Exception {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        dataMgr.registerTuples(metadata, "bqt1.smalla", new List[] { //$NON-NLS-1$ 
-                createRowWithTimestamp("2002-01-01 10:00:00"), //$NON-NLS-1$
-                createRowWithTimestamp("2002-01-01 14:00:00"), //$NON-NLS-1$
-                createRowWithTimestamp("2002-01-02 10:00:00"), //$NON-NLS-1$
-                createRowWithTimestamp("2002-01-02 14:00:00"), //$NON-NLS-1$
-                createRowWithTimestamp("2002-01-02 19:00:00.01"), //$NON-NLS-1$
-                } );       
-    }                
-                
-    static List getProcResultSetSymbols(List params){
-    	List result = new ArrayList();
-    	Iterator iter = params.iterator();
-    	while(iter.hasNext()){
-    		SPParameter param = (SPParameter)iter.next();
-    		if(param.getResultSetColumns() != null){
-    			result.addAll(param.getResultSetColumns());
-    		}
-    	}
-    	iter = params.iterator();
-    	while(iter.hasNext()){
-    		SPParameter param = (SPParameter)iter.next();
-            if(param.getParameterType() == ParameterInfo.INOUT || param.getParameterType() == ParameterInfo.RETURN_VALUE) {
-                result.add(param.getParameterSymbol());
-            }
-    	}
-    	return result;
-    }      
-    
-    @Test public void test1() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void test2() { 
-        // Create query 
-        String sql = "SELECT COUNT(*) FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(6) })
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void test3() { 
-        // Create query 
-        String sql = "SELECT COUNT(*), COUNT(e1), COUNT(distinct e1), COUNT(distinct e2), COUNT(distinct e3), COUNT(distinct e4) FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(6), new Integer(5), new Integer(3), new Integer(4), new Integer(2), new Integer(4) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
- 
-	/** see also integer average defect 11682 */
-    @Test public void test4() { 
-        // Create query 
-        String sql = "SELECT MIN(e2), MAX(e2), SUM(e2), AVG(e2), SUM(distinct e2), AVG(distinct e2) FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), new Integer(3), new Long(7), new Double(1.1666666666666667), new Long(6), new Double(1.5) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-    
-	@Test public void test5() { 
-        // Create query 
-        String sql = "SELECT MIN(e4), MAX(e4), SUM(e4), AVG(e4), SUM(distinct e4), AVG(distinct e4) FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Double(0.0), new Double(7.0), new Double(12.0), new Double(2.4), new Double(10.0), new Double(2.5) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void test7() { 
-        // Create query 
-        String sql = "SELECT * FROM vm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void test8() { 
-        // Create query 
-        String sql = "SELECT * FROM vm1.g2 order by 1, 2, 3"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,  null }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-    
-	@Test public void test9() { 
-        // Create query 
-        String sql = "SELECT * FROM vm1.g4 order by e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-    
-	@Test public void test10() { 
-        // Create query 
-        String sql = "SELECT e1 FROM vm1.g4 where e1 = 'a'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-    @Test public void testBooleanComparisonGT() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 > {b'false'}"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { Boolean.TRUE }), 
-            Arrays.asList(new Object[] { Boolean.TRUE }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testBooleanComparisonGE() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 >= {b'false'}"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.TRUE }), 
-            Arrays.asList(new Object[] { Boolean.TRUE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testBooleanComparisonLT() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 < {b'true'}"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testBooleanComparisonLE() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 <= {b'true'}"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.TRUE }), 
-            Arrays.asList(new Object[] { Boolean.TRUE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }), 
-            Arrays.asList(new Object[] { Boolean.FALSE }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
- 
-    @Test public void testConcatOperator() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1 || e2 AS x FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "a3" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a0" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
- 	/** Duplicates defect #4841: SELECT e1 a, e1 b FROM pm1.g1 order by a */
- 	@Test public void testDefect4841_1() { 
-        // Create query 
-        String sql = "SELECT e1 a, e1 b FROM pm1.g1 order by a"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null,  null }),
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-		};    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-	}
-
-    /** Duplicates defect #4841: SELECT e1 a, e1 b FROM pm1.g1 order by a, b desc */
-    @Test public void testDefect4841_2() { 
-        // Create query 
-        String sql = "SELECT e1 a, e1 b FROM pm1.g1 order by a"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null,  null }),
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** Duplicates defect #5292: SELECT DISTINCT e1, e1 a FROM pm1.g1 */
-    @Test public void testDefect5292_1() { 
-        // Create query 
-        String sql = "SELECT DISTINCT e1, e1 a FROM pm1.g1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null,  null }),
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** Duplicates defect #5292: SELECT DISTINCT e1, e1 a FROM pm1.g1 ORDER BY a */
-    @Test public void testDefect5292_2() { 
-        // Create query 
-        String sql = "SELECT DISTINCT e1, e1 a FROM pm1.g1 ORDER BY a"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null,  null }),
-            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** Duplicates defect #5004: SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx' */
-    @Test public void testDefect5004() { 
-        // Create query 
-        String sql = "SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) })
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * Test to ensure that multiple empty batches are handled by the grouping node as well
-     */
-    @Test public void testDefect5004a() { 
-        // Create query 
-        String sql = "SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) })
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        CommandContext context = createCommandContext();
-        context.setProcessorBatchSize(2);
-        context.setConnectorBatchSize(2);
-        context.setMetadata(FakeMetadataFactory.example1Cached());
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
-
-        // Run query
-        helpProcess(plan, context, dataManager, expected);
-    }
-
-    /** SELECT COUNT(e2), MIN(e2), MAX(e2), SUM(e2), AVG(e2) FROM pm1.g1 WHERE e2=-999999 */
-    @Test public void test13() { 
-        // Create query 
-        String sql = "SELECT COUNT(e2), MIN(e2), MAX(e2), SUM(e2), AVG(e2) FROM pm1.g1 WHERE e2=-999999"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] {new Integer(0), null, null, null, null})
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * This test uncovered a bug in the FakeDataManager; the element
-     * symbol in the atomic query criteria has a canonical name 
-     * of "Y.e4", but the FakeDataManager sends a Map of ElementSymbols
-     * having the unaliased names.  The first symbol cannot be found
-     * in the Map due to the implementation of Symbol.equals() being
-     * based entirely on the canonical name, which causes a NPE.
-     * (Alex says this wasn't previously a problem because aliased groups
-     * did not previously get pushed down to the source.)
-     */
-    @Test public void testCriteriaAliasedGroup() {
-        String sql = "select e1, e2 FROM pm2.g1 Y WHERE 2.0 = e4"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** SELECT e1 FROM pm1.g1 WHERE 'abc' = 'xyz' */
-    @Test public void testCriteriaComparesUnequalConstants() { 
-        // Create query 
-        String sql = "SELECT e1 FROM pm1.g1 WHERE 'abc' = 'xyz'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-     /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
-     @Test public void testRightOuterJoin1() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { null, "d" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null, "e" }) //$NON-NLS-1$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-     /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 LEFT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
-     @Test public void testLeftOuterJoin1() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 LEFT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
-    @Test public void testFullOuterJoin1() throws Exception { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null, "d" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null, "e" }) //$NON-NLS-1$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-    
-    @Test public void testFullOuterJoin2() throws Exception { 
-        // Create query 
-        String sql = "SELECT a.e4 c0, b.e4 c1 FROM pm1.g1 a FULL OUTER JOIN pm1.g1 b ON a.e4=b.e4 order by c0"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }),
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { new Double(0), new Double(0) }),
-            Arrays.asList(new Object[] { new Double(2), new Double(2) }), 
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-    
-    @Test public void testFullOuterJoin3() throws Exception { 
-        // Create query 
-        String sql = "SELECT a.e4 c0, b.e4 c1 FROM pm1.g1 b FULL OUTER JOIN (select e4, 1 x from pm1.g1 union all select e4, 2 from pm1.g1) a ON a.e4=b.e4 and a.x = 2 order by c0"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }),
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { null, null }),
-            Arrays.asList(new Object[] { new Double(0), new Double(0) }),
-            Arrays.asList(new Object[] { new Double(0), null }),
-            Arrays.asList(new Object[] { new Double(2), new Double(2) }), 
-            Arrays.asList(new Object[] { new Double(2), null }),
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-     /** SELECT x.e1, pm2.g1.e1 FROM (SELECT e1 FROM pm1.g1) AS x LEFT OUTER JOIN pm2.g1 ON x.e1=pm2.g1.e1 */
-     @Test public void testLeftOuterJoinWithInlineView() { 
-        // Create query 
-        String sql = "SELECT x.e1, pm2.g1.e1 FROM (SELECT e1 FROM pm1.g1) AS x LEFT OUTER JOIN pm2.g1 ON x.e1=pm2.g1.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-    
-    /** SELECT * FROM vm1.g5 ORDER BY expr */
-    @Test public void testDefect5273_1() {
-        // Create query 
-        String sql = "SELECT expr FROM vm1.g5 ORDER BY expr"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    /** SELECT expr AS e FROM vm1.g5 ORDER BY e */
-    @Test public void testDefect5273_2() {
-        // Create query 
-        String sql = "SELECT expr AS e FROM vm1.g5 ORDER BY e"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    /** SELECT e2 AS e FROM vm1.g5 ORDER BY e */
-    @Test public void testDefect5273_3() {
-        // Create query 
-        String sql = "SELECT e2 AS e FROM vm1.g5 ORDER BY e"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(3) })
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    /** SELECT e AS f FROM vm1.g6 ORDER BY f */
-    @Test public void testDefect5273_4() {
-        // Create query 
-        String sql = "SELECT e AS f FROM vm1.g6 ORDER BY f"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }        
-
-    /** SELECT e AS f FROM vm1.g7 ORDER BY f */
-    @Test public void testDefect5273_5() {
-        // Create query 
-        String sql = "SELECT e AS f FROM vm1.g7 ORDER BY f"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a3" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c1" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }        
-
-    /** SELECT e AS f FROM vm1.g7 ORDER BY f */
-    @Test public void testDefect5273_6() {
-        // Create query 
-        String sql = "SELECT e AS f FROM vm1.g8 ORDER BY f"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }        
-
-    @Test public void testFalseCriteria1() { 
-        // Create query 
-        String sql = "SELECT 5 FROM pm1.g1 WHERE 0=1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testFalseCriteria2() { 
-        // Create query 
-        String sql = "SELECT count(*) FROM pm1.g1 WHERE 0=1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) }),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testTempGroup() { 
-        // Create query 
-        String sql = "SELECT e1 FROM tm1.g1 WHERE e1 = 'a'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testSubquery1() {
-   		// Create query
-   		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"; //$NON-NLS-1$
-   		
-   		// Create expected results
-   		List[] expected = new List[] {
-   			Arrays.asList(new Object[] { "a" }),	 //$NON-NLS-1$
-   			Arrays.asList(new Object[] { null }),
-   			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-   			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-   			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-   			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-   		}; 	
-   		
-   		// Construct data manager with data
-   		FakeDataManager dataManager = new FakeDataManager();
-   		sampleData1(dataManager);
-   		
-    	// Plan query
-    	ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-   		// Run query
-   		helpProcess(plan, dataManager, expected);
-    }
-
-	@Test public void testSubquerySimple() {
-		// Create query
-		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { null }),
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-	
-	@Test public void testCritInSubquery() {
-		// Create query
-		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1 WHERE e1 = 'a') AS x"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-	
-	@Test public void testCritAboveSubquery() {
-		// Create query
-		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x WHERE e1 = 'a'"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}    
-
-	@Test public void testSubqueryInJoinPredicate() {
-		// Create query
-		String sql = "SELECT x.e1 FROM (SELECT e1 FROM pm1.g1) AS x JOIN (SELECT e1 FROM pm1.g1) y ON x.e1=y.e1"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-	@Test public void testSubqueryWithRenaming() {
-		// Create query
-		String sql = "SELECT x.a FROM (SELECT e1 AS a FROM pm1.g1) AS x"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { null }),
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-    @Test public void testNestedSubquery() {
-        // Create query
-        String sql = "SELECT x.a FROM (SELECT e1 AS a FROM (SELECT e1 FROM pm1.g1) AS y) AS x"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null }),
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-	/**
-	 * Tests a single Subquery IN clause criteria
-	 */
-	@Test public void testSubqueryINClause() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * Tests a single Subquery IN clause criteria with nulls
-	 * in sample data
-	 */
-	@Test public void testSubqueryINClauseWithNulls() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e4 IN (SELECT e4 FROM pm2.g1)"; //$NON-NLS-1$
-
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-	
-	/**
-	 * Tests a single Subquery IN clause criteria with nulls
-	 * in sample data
-	 */
-	@Test public void testSubqueryINClauseWithNulls2() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e4 FROM pm2.g1)"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}	
-
-	/**
-	 * Tests a compound criteria of two subqueries in IN clauses
-	 */
-	@Test public void testSubqueryINClauses() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND e1 IN (SELECT e1 FROM pm2.g1)"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-    /**
-     * Tests a compound criteria of a subquery in IN clause and another type of
-     * criteria
-     */
-    @Test public void testSubqueryINClauseMixedCriteria() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND e1 IN ('b')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-	/**
-	 * Tests a compound criteria of a subquery in IN clause and another type of
-	 * criteria
-	 */
-	@Test public void testSubqueryINClauseMixedCriteria2() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND NOT (e1 = 'a')"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-	/**
-	 * Tests nesting of Subquery IN clause criteria
-	 */
-	@Test public void testNestedSubqueryINClauses() {
-		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1 WHERE e1 IN (SELECT e1 FROM pm1.g1))"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] {
-			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-		};
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}	
-
-	@Test public void testSubqueryXML() {
-		// Create query
-		String sql = "SELECT * FROM (SELECT * FROM xmltest.doc1) AS x"; //$NON-NLS-1$
-
-		// Create expected results
-		List[] expected = new List[] { 
-			Arrays.asList(new Object[] { 
-                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
-                    "<root><node1><node2><node3/></node2></node1></root>"             //$NON-NLS-1$
-            })
-		};    
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData1(dataManager);
-
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-		// Run query
-		helpProcess(plan, dataManager, expected);
-	}
-
-    /**
-     * Tests a single Subquery EXISTS predicate criteria
-     */
-    @Test public void testSubqueryExistsPredicate() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Tests a single Subquery EXISTS predicate criteria 
-     * where the subquery returns no rows
-     */
-    @Test public void testSubqueryExistsPredicate2() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1 WHERE e1 = 'ZZTop')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = ANY (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate2() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = SOME (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate3() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = ALL (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate4() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 <= ALL (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate5() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < SOME (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicate5a() {
-        String sql = "SELECT e1 FROM pm2.g1 WHERE e2 < SOME (SELECT e2 FROM pm1.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "e" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     * without predicate quantifier
-     */
-    @Test public void testSubqueryComparePredicate6() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < (SELECT e2 FROM pm2.g1 WHERE e1 = 'e')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Tests a single Subquery in compare predicate criteria
-     */
-    @Test public void testSubqueryComparePredicateNested() {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < SOME (SELECT e2 FROM pm2.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1))"; //$NON-NLS-1$
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List[] { Arrays.asList(new Object[] { new Integer(0), "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-                                                                      Arrays.asList(new Object[] { new Integer(1), "b" }), //$NON-NLS-1$
-                                                                      Arrays.asList(new Object[] { new Integer(2), "c" }), //$NON-NLS-1$
-                                                                      });
-        
-        dataManager.addData("SELECT pm2.g1.e2 FROM pm2.g1", new List[] {  //$NON-NLS-1$
-                                                                 Arrays.asList(new Object[] { new Integer(0) }),
-                                                                 Arrays.asList(new Object[] { new Integer(3) }),
-                                                                 Arrays.asList(new Object[] { new Integer(1) }),                    
-                                                                  });              
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
-        };
-
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * Tests a scalar subquery in the SELECT clause
-     */
-    @Test public void testSubqueryScalar() {
-        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1 WHERE e1 = 'b') FROM pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Tests a scalar subquery which returns no rows in the SELECT clause
-     */
-    @Test public void testSubqueryScalar2() {
-        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1 WHERE e1 = 'a') FROM pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Tests a scalar subquery which returns more than one rows
-     * causes the expected Exception
-     */
-    @Test public void testSubqueryScalarException() throws Exception {
-        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1) FROM pm1.g1"; //$NON-NLS-1$
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcessException(plan, dataManager);
-    }
-    
-    @Test public void testSubqueryScalarInTransformation() {
-        String sql = "select * from vm1.g25"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  new Double(0.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testSubqueryScalarInTransformation2() {
-        String sql = "select * from vm1.g25 where e5 = 0.0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  new Double(0.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    @Test public void testCorrelatedSubquery_CASE2022() {
-        String sql = "select * from BQT2_V WHERE BQT2_V.IntKey < 50"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT1(dataManager);
-        sampleDataBQT2(dataManager);
-
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.exampleBQTCached(), capFinder);
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-    @Test public void testCorrelatedSubquery1() {
-        String sql = "Select e1, e2, e4 from pm1.g1 where e2 in (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0), new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-
-    }
-    
-    /**
-     * There is a bug when the second query in a UNION ALL has a correlated subquery, and both
-     * the outer and inner query are selecting from the same virtual group, and aliasing them
-     * differently to distinguish between them.  The generated atomic query has screwed up
-     * aliasing. 
-     */
-    @Test public void testCorrelatedSubqueryCase3667() {
-
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-
-        // Plan query
-        String sql = "Select e1, e2, e4 from pm2.g1 where 1=2 " + //$NON-NLS-1$
-           "UNION ALL Select e1, e2, e4 from vm1.g1 outg1 where outg1.e2 in (select ing1.e2 FROM vm1.g1 ing1 WHERE outg1.e4 = ing1.e4)";//$NON-NLS-1$
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-        
-        // Run query
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "aString", new Integer(22), new Double(22.0) }), //$NON-NLS-1$
-        };
-
-        dataManager.addData("SELECT g_0.e1, g_0.e2, g_0.e4 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM pm1.g1 AS g_1 WHERE g_1.e4 = g_0.e4)",  //$NON-NLS-1$
-                            expected);
-        
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    /** control query, this test passes */
-    @Test public void testCorrelatedSubqueryCase3667a() {
-
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        // Plan query
-        String sql = "Select e1, e2, e4 from vm1.g1 outg1 where outg1.e2 in (select ing1.e2 FROM vm1.g1 ing1 WHERE outg1.e4 = ing1.e4)";//$NON-NLS-1$
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-        
-        // Run query
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "aString", new Integer(22), new Double(22.0) }), //$NON-NLS-1$
-        };
-        
-        dataManager.addData("SELECT g_0.e1, g_0.e2, g_0.e4 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM pm1.g1 AS g_1 WHERE g_1.e4 = g_0.e4)",  //$NON-NLS-1$
-                            expected);
-        
-        helpProcess(plan, dataManager, expected);
-    }     
-
-    @Test public void testCorrelatedSubquery2() {
-        String sql = "Select e1, e2 from pm1.g1 where e2 in (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-
-    }
-
-    @Test public void testCorrelatedSubquery3() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4) from pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testCorrelatedSubquery3a() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 WHERE X.e4 = e4) from pm1.g1 X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    @Test public void testCorrelatedSubquery3b() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = e4) from pm1.g1 X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubquery3c() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from pm1.g1 X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testCorrelatedSubquery4() {
-        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select e2 FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    @Test public void testCorrelatedSubquery4a() {
-        String sql = "Select e1, e2 from pm1.g1 X where e2 = some (select e2 FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-    @Test public void testCorrelatedSubquery_defect9968() {
-        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select max(X.e2) FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-
-    @Test public void testCorrelatedSubquery_defect9968a() {
-        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select ((X.e2)/2) as e FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-
-    @Test public void testCorrelatedSubquery_defect9968b() {
-        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select (select e2 as e FROM pm2.g1 WHERE X.e4 = pm2.g1.e4) as e FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-
-    @Test public void testCorrelatedSubquery_defect10021() {
-        String sql = "Select e1, e2 from table1 X where e4 in (select max(Y.e4) FROM table1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", new Integer(2) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-    
-    /** 
-     * Note the subquery has a multi-column result - conceptually this is
-     * legal for the EXISTS predicate
-     */
-    @Test public void testCorrelatedSubquery5() {
-        String sql = "Select * from pm1.g1 where exists (select * FROM pm2.g1 WHERE pm1.g1.e1 = e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }       
-
-    /** 
-     * Count the # of parent rows for which no child rows exist
-     */
-    @Test public void testCorrelatedSubquery6() {
-        String sql = "Select count(*) from pm1.g1 where not (exists (select * FROM pm2.g1 WHERE pm1.g1.e1 = e1))"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { new Integer(2) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /** 
-     * Select e2, e4, and the avg of e4 for each group of e1
-     */
-    @Test public void testCorrelatedSubquery7() {
-        String sql = "select e2, e4, (select avg(e4) FROM pm1.g1 Y WHERE X.e1 = e1) from pm1.g1 X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) }),
-            Arrays.asList(new Object[] { new Integer(1), new Double(1.0), null }),
-            Arrays.asList(new Object[] { new Integer(3), new Double(7.0), new Double(3.6666666666666665) }),
-            Arrays.asList(new Object[] { new Integer(1), null ,           null }),
-            Arrays.asList(new Object[] { new Integer(2), new Double(0.0), new Double(0.0) }),
-            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    /** 
-     * Select e2, e4, and the avg of e4 for each group of e1
-     */
-    @Test public void testCorrelatedSubquery8() {
-        String sql = "select X.e2, X.e4, (select avg(Y.e4) FROM pm1.g1 Y WHERE X.e1 = Y.e1) from pm1.g1 X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) }),
-            Arrays.asList(new Object[] { new Integer(1), new Double(1.0), null }),
-            Arrays.asList(new Object[] { new Integer(3), new Double(7.0), new Double(3.6666666666666665) }),
-            Arrays.asList(new Object[] { new Integer(1), null ,           null }),
-            Arrays.asList(new Object[] { new Integer(2), new Double(0.0), new Double(0.0) }),
-            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-    @Test public void testCorrelatedSubqueryVirtualLayer1() {
-        String sql = "Select e1, e2 from vm1.g1 X where e2 in (select e2 FROM vm1.g1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer2() {
-        String sql = "Select e1, e2 from vm1.g2 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g2.e4 = vm1.g1.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer3() {
-        String sql = "Select e2 from vm1.g6 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g6.e = e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer4() {
-        String sql = "Select e2 from vm1.g7 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g7.e = e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer5() {
-        String sql = "Select e1 from vm1.g4 where not (e1 in (select e1 FROM vm1.g1 WHERE vm1.g4.e1 = e1)) order by e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
-        };
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer6() {
-        String sql = "Select e2 from vm1.g1 X where e2 in (select X.e2 FROM vm1.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(3) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(0) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer6a() {
-        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g5)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(3) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(0) })
-        };
-
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer6b() {
-        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g2)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(3) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(0) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer6c() {
-        String sql = "Select e2 from vm1.g7 where e2 in (select vm1.g7.e FROM vm1.g1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer6e() {
-        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g2a)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(0) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(3) }),
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(0) })
-        };
-
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryVirtualLayer7() {
-        String sql = "Select e2 from vm1.g7 where e2 in (select vm1.g7.e FROM vm1.g1 WHERE vm1.g7.e = e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[0];
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryInTransformation() {
-        String sql = "Select * from vm1.g21"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-    
-    @Test public void testCorrelatedSubqueryInTransformation2() {
-        String sql = "Select * from vm1.g20"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    @Test public void testCorrelatedSubqueryInTransformation3() {
-        String sql = "Select * from vm1.g19 order by e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * User correlated subquery, and one of the virtual group transformations
-     * also has a correlated subquery
-     */
-    @Test public void testCorrelatedSubqueryInTransformation4() {
-        String sql = "Select * from vm1.g20 where exists (Select * from vm1.g19 where convert(vm1.g20.e2, string) = vm1.g19.e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }     
-
-    /**
-     * User correlated subquery, and one of the virtual group transformations
-     * also has a correlated subquery
-     */
-    @Test public void testCorrelatedSubqueryInTransformation5() {
-        String sql = "Select * from vm1.g19 where exists (Select e2 from vm1.g20 where convert(e2, string) = vm1.g19.e1) order by e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-    @Test public void testCorrelatedSubqueryInTransformation6() {
-        String sql = "Select * from vm1.g21 where e2 = some (Select e2 from pm1.g1 where e1 = vm1.g21.e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-    @Test public void testCorrelatedSubqueryInTransformation7() {
-        String sql = "Select * from vm1.g21 where exists (Select e2 from pm1.g2 where e4 = convert(vm1.g21.e2, double))"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testCorrelatedSubqueryInTransformation8() {
-        String sql = "Select * from vm1.g21 where exists (Select e2 from pm1.g1 where e4 = convert(vm1.g21.e2, double))"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation9() {
-        String sql = "Select * from vm1.g22"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),  //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation10() {
-        String sql = "Select * from vm1.g23"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),  //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation11() {
-        String sql = "Select * from vm1.g24"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }),
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation12() {
-        String sql = "Select * from vm1.g24 X where exists (Select * from vm1.g24 Y where X.e2 = Y.e2)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }),
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation13() {
-        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g25 where pm1.g1.e4 = e5 and e4=0.0) as e5 from pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    } 
-    
-    @Test public void testCorrelatedSubqueryInTransformation14() {
-        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g26 where pm1.g1.e4 = e5 and e4=0.0) as e5 from pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }     
-
-    @Test public void testCorrelatedSubqueryInTransformation15() {
-        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a'"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
-    @Test public void testCorrelatedSubqueryInTransformation15a() {
-        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select * from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueryInTransformation15b() {
-        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a' and exists (select * from vm1.g23 where vm1.g22.e3 = e3)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
-    @Test public void testCorrelatedSubqueryInTransformation15c() {
-        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select e1, e2, e3, e4, e5 as e from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }   
-
-    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
-    @Test public void testCorrelatedSubqueryInTransformation15d() {
-        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select e1, e2, e3, e4, ((e4 + e5)/(e4 + 1)) as e from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-// Here is select * from vm1.g26
-//  Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }),
-//  Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
-//  Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }),
-//  Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),
-//  Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }),
-//  Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null })
-
-
-    @Test public void testCorrelatedSubqueryInTransformation16() {
-//        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a'"/* and exists (select * from vm1.g23 where vm1.g22.e3 = e3)"*/;
-        String sql = "select * from vm1.g26 where e5 = 0.0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[]{
-//            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }),
-//            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
-//            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }),
-//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),
-            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
-//            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }  
-
-    @Test public void testCorrelatedSubqueriesNested() {
-        String sql = 
-                    "Select e1, e2, e4 from pm1.g1 where e2 < all (" + //$NON-NLS-1$
-                    "select e2 from pm1.g2 where pm1.g1.e1 = e1 and exists("+ //$NON-NLS-1$
-                    "select e2 from pm2.g1 where pm1.g2.e4 = pm2.g1.e4))"; //$NON-NLS-1$
-        Command query = helpParse(sql);
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0), new Double(2.0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", new Integer(1), null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", new Integer(2), new Double(0.0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(query, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** defect 15124 */
-    @Test public void testCorrelatedSubqueryAndInlineView() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select * from pm1.g1) as X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-    
-    /** defect 15124 */
-    @Test public void testCorrelatedSubqueryAndInlineView2() {
-        String sql = "Select e1 from (select * from pm1.g1) as X WHERE e2 IN (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }    
-
-    /** defect 15124 */
-    @Test public void testCorrelatedSubqueryAndInlineView3() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select * from pm1.g1 UNION ALL select * from pm1.g1) as X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }    
-
-    /** defect 15124 */
-    @Test public void testCorrelatedSubqueryAndInlineView4() {
-        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select pm1.g1.e1, (select pm1.g1.e2 from pm1.g1 Z where pm1.g1.e1 = Z.e1), pm1.g1.e3, pm1.g1.e4 from pm1.g1) as X"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }    
-    
-    @Test public void testXMLUnion_defect8373() {
-        // Create query
-        String sql = "SELECT * FROM xmltest.doc5"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] {
-                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
-                "<root><node1><node2>a</node2></node1><node1><node2/></node1><node1><node2>a</node2></node1><node1><node2>c</node2></node1><node1><node2>b</node2></node1><node1><node2>a</node2></node1><node1><node2>a</node2></node1><node1><node2/></node1><node1><node2>a</node2></node1><node1><node2>c</node2></node1><node1><node2>b</node2></node1><node1><node2>a</node2></node1></root>" //$NON-NLS-1$
-            })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testStoredQuery1() {
-        // Create query
-        String sql = "EXEC pm1.sq1()"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null,  new Integer(1) }),
-            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c",   new Integer(1) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b",   new Integer(2) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testStoredQuery2() {
-        // Create query
-        String sql = "EXEC pm1.sq2(\'a\')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0) }),  //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(3) }),    //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a",   new Integer(0) })        //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-        
-    @Test public void testStoredQuery3() {
-        // Create query
-        String sql = "select x.e1 from (EXEC pm1.sq1()) as x"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null}),
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testStoredQuery4() {
-        // Create query
-        String sql = "EXEC pm1.sq5('a')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", new Integer(0)}),             //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(3) }),             //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testStoredQuery5() {
-        // Create query
-        String sql = "EXEC pm1.sp1()"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { null,  new Integer(1)}),
-                    Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "c",   new Integer(1)}), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b",   new Integer(2)}), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testStoredQuery6() {
-        // Create query
-        String sql = "EXEC pm1.sqsp1()"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { null}),
-                    Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "c"}), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testStoredQuery7() {
-        // Create query
-        String sql = "EXEC pm1.sq17()"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { 
-                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
-                    "<root><node1><node2><node3/></node2></node1></root>"             //$NON-NLS-1$
-            })
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-
-    // implict type conversion of parameter
-    @Test public void testStoredQuery8() {
-        // Create query
-        String sql = "EXEC pm1.sq5(5)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    // function for parameter
-    @Test public void testStoredQuery9() {
-        // Create query
-        String sql = "EXEC pm1.sq5(concat('a', ''))"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** named parameters */
-    @Test public void testStoredQuery10() {
-        // Create query
-        String sql = "EXEC pm1.sq3b(\"in\" = 'a', in3 = 'something')"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(0)}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    @Test public void testInsert() {
-        // Create query
-        String sql = "Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values ('MyString', 1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1)})
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData3(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA FULL OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
-     @Test public void testDefect7770_FullOuter() { 
-        // Create query 
-        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA FULL OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
-            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
-            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
-            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
-            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
-            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
-            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
-            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
-            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
-            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA RIGHT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
-     @Test public void testDefect7770_RightOuter() { 
-        // Create query 
-        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA RIGHT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
-            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
-            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
-            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
-            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
-            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
-            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
-            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
-            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
-            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
-     @Test public void testDefect7770_LeftOuter() { 
-        // Create query 
-        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
-            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
-            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
-            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
-            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
-            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
-            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
-            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
-            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
-            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
-            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testReorder1() {
-        // Create query
-        String sql = "SELECT e1 AS x, {b'false'}, e2+e4, e3 FROM pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(2.0), Boolean.FALSE }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { null, Boolean.FALSE, new Double(2.0), Boolean.FALSE }),
-            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(10.0), Boolean.TRUE }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c", Boolean.FALSE, null, Boolean.TRUE }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "b", Boolean.FALSE, new Double(2.0), Boolean.FALSE }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(2.0), Boolean.FALSE }) //$NON-NLS-1$
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testTwoFullOuterJoins1() {
-        // Create query
-        String sql = "SELECT A.IntKey AS A_IntKey, B.IntKey AS B_IntKey, C.IntKey AS C_IntKey " +  //$NON-NLS-1$
-        "FROM (BQT1.SmallA AS A FULL OUTER JOIN BQT2.SmallA AS B ON A.IntKey = B.IntKey) FULL OUTER JOIN BQT3.SmallA AS C ON B.IntKey = C.IntKey " +  //$NON-NLS-1$
-        "WHERE (A.IntKey >= 0) AND (A.IntKey <= 15) " +  //$NON-NLS-1$
-        "AND (B.IntKey >= 5) AND (B.IntKey <= 20) " +  //$NON-NLS-1$
-        "AND (C.IntKey >= 10) AND (C.IntKey <= 30)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(10), new Integer(10), new Integer(10) }),
-            Arrays.asList(new Object[] { new Integer(11), new Integer(11), new Integer(11) }),
-            Arrays.asList(new Object[] { new Integer(12), new Integer(12), new Integer(12) }),
-            Arrays.asList(new Object[] { new Integer(13), new Integer(13), new Integer(13) }),
-            Arrays.asList(new Object[] { new Integer(14), new Integer(14), new Integer(14) }),
-            Arrays.asList(new Object[] { new Integer(15), new Integer(15), new Integer(15) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testSelectDistinctOnBQT() {
-       // Create query
-       String sql = "SELECT DISTINCT IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
-
-       // Create expected results
-       List[] expected = new List[] {
-           Arrays.asList(new Object[] { new Integer(0) }),
-           Arrays.asList(new Object[] { new Integer(1) }),
-           Arrays.asList(new Object[] { new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(3) }),
-           Arrays.asList(new Object[] { new Integer(4) }),
-           Arrays.asList(new Object[] { new Integer(5) }),
-           Arrays.asList(new Object[] { new Integer(6) }),
-           Arrays.asList(new Object[] { new Integer(7) }),
-           Arrays.asList(new Object[] { new Integer(8) }),
-           Arrays.asList(new Object[] { new Integer(9) }),
-           Arrays.asList(new Object[] { new Integer(10) }),
-           Arrays.asList(new Object[] { new Integer(11) }),
-           Arrays.asList(new Object[] { new Integer(12) }),
-           Arrays.asList(new Object[] { new Integer(13) }),
-           Arrays.asList(new Object[] { new Integer(14) }),
-           Arrays.asList(new Object[] { new Integer(15) }),
-           Arrays.asList(new Object[] { new Integer(16) }),
-           Arrays.asList(new Object[] { new Integer(17) }),
-           Arrays.asList(new Object[] { new Integer(18) }),
-           Arrays.asList(new Object[] { new Integer(19) })
-       };
-
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleDataBQT1(dataManager);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-   
-   @Test public void testSelectWithNoFrom() { 
-       // Create query 
-       String sql = "SELECT 5"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(5) })
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-   
-   @Test public void testBetween() { 
-       // Create query 
-       String sql = "SELECT * FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
-           Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }) //$NON-NLS-1$
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   /**
-    * Test <code>QueryProcessor</code>'s ability to process a query containing 
-    * a <code>CASE</code> expression in which a <code>BETWEEN</code> 
-    * comparison is used in the queries <code>SELECT</code> statement.
-    * <p>
-    * For example:
-    * <p>
-    * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
-    */
-   @Test public void testBetweenInCase() { 
-       // Create query 
-       final String sql = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-               Arrays.asList(new Object[] { new Integer(-1) }),
-               Arrays.asList(new Object[] { new Integer(-1) }),
-               Arrays.asList(new Object[] { new Integer(3) }),
-               Arrays.asList(new Object[] { new Integer(-1) }),
-               Arrays.asList(new Object[] { new Integer(-1) }),
-               Arrays.asList(new Object[] { new Integer(-1) }) 
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   /**
-    * Test <code>QueryProcessor</code>'s ability to process a query containing 
-    * an aggregate SUM with a <code>CASE</code> expression in which a 
-    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
-    * statement.
-    * <p>
-    * For example:
-    * <p>
-    * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
-    */
-   @Test public void testBetweenInCaseInSum() { 
-       // Create query 
-       final String sql = "SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Long(-2) })
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   /**
-    * Test <code>QueryProcessor</code>'s ability to process a query containing 
-    * an aggregate SUM with a <code>CASE</code> expression in which a 
-    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
-    * statement and a GROUP BY is specified.
-    * <p>
-    * For example:
-    * <p>
-    * SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) 
-    * FROM pm1.g1 GROUP BY e1 ORDER BY e1
-    */
-   @Test public void testBetweenInCaseInSumWithGroupBy() { 
-       // Create query 
-       final String sql = "SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1 GROUP BY e1 ORDER BY e1"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-    	       Arrays.asList(new Object[] { null,  new Long(-1) }),
-    	       Arrays.asList(new Object[] { "a",   new Long(1) }), //$NON-NLS-1$
-    	       Arrays.asList(new Object[] { "b",   new Long(-1) }), //$NON-NLS-1$
-    	       Arrays.asList(new Object[] { "c",   new Long(-1) }) //$NON-NLS-1$
-       };    
-       
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   /**
-    * Test <code>QueryProcessor</code>'s ability to process a query containing 
-    * an aggregate COUNT with a <code>CASE</code> expression in which a 
-    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
-    * statement.
-    * <p>
-    * For example:
-    * <p>
-    * SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1
-    */
-   @Test public void testBetweenInCaseInCount() { 
-       // Create query 
-       final String sql = "SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1) })
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   @Test public void testCase() { 
-       // Create query 
-       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 ELSE 3 END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(2), new Integer(3) }) 
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-   
-   @Test public void testSelectNoFrom1() { 
-       // Create query 
-       String sql = "SELECT 1"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1) })
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-   
-   @Test public void testSelectNoFrom2() { 
-       // Create query 
-       String sql = "SELECT 1, {b'true'}, 2.0 AS x, {d'2003-11-04'}"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), Boolean.TRUE, new Double(2.0), TimestampUtil.createDate(103, 10, 4)  })
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-
-   @Test public void testCase1566() throws Exception {
-       // Create query
-       String sql = "SELECT x, COUNT(*) FROM (SELECT convert(TimestampValue, date) AS x FROM bqt1.smalla) as y GROUP BY x"; //$NON-NLS-1$
-
-       // Create expected results
-       List[] expected = new List[] {
-               Arrays.asList(new Object[] { java.sql.Date.valueOf("2002-01-01"), new Integer(2) }),
-               Arrays.asList(new Object[] { java.sql.Date.valueOf("2002-01-02"), new Integer(3) }) };
-
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleDataBQT_case1566(dataManager);
-
-       // Create capabilities
-       FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-       BasicSourceCapabilities caps = new BasicSourceCapabilities();
-       caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
-       caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-       capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-       // Parse query
-       Command command = QueryParser.getQueryParser().parseCommand(sql);
-
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder);
-
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }   
-   
-    @Test public void testDefect10976(){
-        String sql = "SELECT * FROM vm1.g28"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { "A", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "B", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "C", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);       
-    }
-         
-    @Test public void testDefect10976_2(){
-        String sql = "SELECT * FROM vm1.g29"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { "A", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "B", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "C", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);       
-    }         
-    
-    @Test public void testDefect10976_3(){
-        String sql = "SELECT * FROM vm1.g30"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);       
-    }
-
-    @Test public void testDefect10976_4(){
-        String sql = "SELECT * FROM vm1.g31 order by x"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);       
-    }
-
-    @Test public void testDefect10976_5(){
-        String sql = "SELECT * FROM vm1.g32"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);       
-    }
-    
-    @Test public void testDefect11236_MergeJoinWithFunctions() { 
-       // Create query 
-       String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1)"; //$NON-NLS-1$
-       boolean pushDown = false;
-       boolean dependent = false;
-       
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-           Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
-           Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
-           Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
-       };    
-        
-       helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
-    }
-    
-    @Test public void testMergeJoinWithFunctionsPushDown() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1)"; //$NON-NLS-1$
-        boolean pushDown = true;
-        boolean dependent = false;
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
-            Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
-        };    
-         
-        helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
-    }
-    
-    @Test public void testMergeJoinWithFunctionsPushDownDependent() { 
-        // Create query 
-        String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1) option makedep pm1.g1"; //$NON-NLS-1$
-        boolean pushDown = true;
-        boolean dependent = true;
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
-            Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
-        };    
-         
-        helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
-    }
-
-
-    /** 
-     * @param sql
-     * @param pushDown
-     * @param expected
-     */
-    private void helpTestMergeJoinWithExpression(String sql,
-                                                 boolean pushDown,
-                                                 boolean dependent,
-                                                 List[] expected) {
-        // Construct data manager with data
-           ProcessorDataManager dataManager = null;
-           if (!pushDown) {
-               FakeDataManager fakeDataManager = new FakeDataManager();
-               sampleData1(fakeDataManager);
-               dataManager = fakeDataManager;
-           } else {
-               HardcodedDataManager hardCoded = new HardcodedDataManager();
-               List[] results = new List[] { 
-                   Arrays.asList(new Object[] {new Integer(0), new Integer(1)}), 
-                   Arrays.asList(new Object[] {new Integer(0), new Integer(1)}), 
-                   Arrays.asList(new Object[] {new Integer(1), new Integer(2)}),
-                   Arrays.asList(new Object[] {new Integer(1), new Integer(2)}), 
-                   Arrays.asList(new Object[] {new Integer(2), new Integer(3)}), 
-                   Arrays.asList(new Object[] {new Integer(3), new Integer(4)}), 
-                   };
-               hardCoded.addData("SELECT g_0.e2 AS c_0, (g_0.e2 + 1) AS c_1 FROM pm2.g1 AS g_0 ORDER BY c_1", results); //$NON-NLS-1$
-               if (!dependent) {
-                   results = new List[] { 
-                       Arrays.asList(new Object[] {new Integer(0),}), 
-                       Arrays.asList(new Object[] {new Integer(0),}), 
-                       Arrays.asList(new Object[] {new Integer(1),}),
-                       Arrays.asList(new Object[] {new Integer(1),}), 
-                       Arrays.asList(new Object[] {new Integer(2),}), 
-                       Arrays.asList(new Object[] {new Integer(3),}), 
-                       };
-                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", results); //$NON-NLS-1$
-               } else {
-                   results = new List[] { 
-                       Arrays.asList(new Object[] {new Integer(1),}),
-                       Arrays.asList(new Object[] {new Integer(2),}),
-                       Arrays.asList(new Object[] {new Integer(1),}), 
-                       };
-                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (1, 2)", results); //$NON-NLS-1$
-                   results = new List[] { 
-                       Arrays.asList(new Object[] {new Integer(3),}), 
-                       };
-                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (3, 4)", results); //$NON-NLS-1$
-               }
-               dataManager = hardCoded;
-           }
-            
-           FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-           FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-           BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-           caps.setCapabilitySupport(Capability.CRITERIA_IN, pushDown);    
-           caps.setCapabilitySupport(Capability.QUERY_ORDERBY, pushDown);
-           caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(2));
-           caps.setFunctionSupport("+", pushDown); //$NON-NLS-1$
-           finder.addCapabilities("pm1", caps); //$NON-NLS-1$
-           finder.addCapabilities("pm2", caps); //$NON-NLS-1$
-
-           // Plan query
-           ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, finder);
-
-           // Run query
-           helpProcess(plan, dataManager, expected);
-    }
-    
-   @Test public void testCase2() { 
-       // Create query 
-       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(2), null }) 
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }
-   
-   @Test public void testCase3() { 
-       // Create query 
-       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 ELSE null END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
-           Arrays.asList(new Object[] { new Integer(2), null }) 
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }   
-
-   /** nested scalar subquery */
-   @Test public void testCase4() { 
-       // Create query 
-       String nestedExpression = "(SELECT e1 FROM pm1.g2 WHERE e2 = 3)"; //$NON-NLS-1$
-       String sql = "SELECT e2, CASE e2 WHEN 1 THEN " + nestedExpression + " ELSE null END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$ //$NON-NLS-2$
-        
-       // Create expected results
-       List[] expected = new List[] { 
-           Arrays.asList(new Object[] { new Integer(1), "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { new Integer(1), "a" }), //$NON-NLS-1$
-           Arrays.asList(new Object[] { new Integer(2), null }) 
-       };    
-    
-       // Construct data manager with data
-       FakeDataManager dataManager = new FakeDataManager();
-       sampleData1(dataManager);
-        
-       // Plan query
-       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-       // Run query
-       helpProcess(plan, dataManager, expected);
-   }  
-
-    /** nested correlated scalar subquery */
-    @Test public void testCase5() { 
-        // Create query 
-        String nestedExpression = "(SELECT e2 FROM pm1.g2 WHERE pm1.g1.e2 = (e4 + 2))"; //$NON-NLS-1$
-        String sql = "SELECT e2, CASE e2 WHEN " + nestedExpression + " THEN 1 ELSE null END FROM pm1.g1"; //$NON-NLS-1$ //$NON-NLS-2$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), null }), 
-            Arrays.asList(new Object[] { new Integer(1), null }), 
-            Arrays.asList(new Object[] { new Integer(3), null }), 
-            Arrays.asList(new Object[] { new Integer(1), null }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
-            Arrays.asList(new Object[] { new Integer(0), null }) 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /** 
-     * NOTE: this test depends on the ProcessorPlan being executed 
-     * twice and reset in between, which currently is done in the 
-     * helpProcess method  
-     */
-    @Test public void testDefect12135(){
-        String sql = "SELECT pm1.g1.e1, pm1.g2.e1 FROM pm1.g1 LEFT OUTER JOIN pm1.g2 ON pm1.g1.e1=pm1.g2.e1"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$ 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);          
-    }
-    
-    @Test public void testDefect12081(){
-        String sql = "SELECT DISTINCT vm1.g1.e1, upper(vm1.g1.e1) as Nuge, pm1.g1.e1, upper(pm1.g1.e1) as Nuge FROM vm1.g1, pm1.g1"; //$NON-NLS-1$
-
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        }; 
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);          
-    }    
-
-    @Test public void testDefect12081_2(){
-        String sql = "SELECT DISTINCT vm1.g1b.e1, vm1.g1b.e1Upper, pm1.g1.e1, upper(pm1.g1.e1) as e1Upper FROM vm1.g1b, pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);          
-    }  
-    
-    @Test public void testDefect12081_3(){
-        String sql = "SELECT DISTINCT vm1.g1b.e1, vm1.g1b.e1Upper, pm1.g1.e1, vm1.g1b.e1Upper FROM vm1.g1b, pm1.g1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "b", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "a", "A", "c", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "a", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "b", "B", "c", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "a", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "b", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);          
-    }
-    
-    /**
-     * Basically the same as above, but with a limit node between the dup removal and the project
-     */
-    @Test public void testDefect12081_4(){
-        String sql = "SELECT DISTINCT e1, e1 FROM pm1.g1 where e1 = 'a' LIMIT 1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "a"}), //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);          
-    }
-    
-    @Test public void testDefect12719(){
-        String sql = "SELECT e1_, e2_, e2 FROM vm1.g34, pm1.g2 WHERE vm1.g34.e1_ = pm1.g2.e1 order by e1_, e2_"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", new Integer(0), new Integer(1) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(0) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(5) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(2) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(0) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(5) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(2) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "d", new Integer(3), new Integer(2) }), //$NON-NLS-1$ 
-        };    
-
-		// Construct data manager with data
-		FakeDataManager dataManager = new FakeDataManager();
-		sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    @Test public void testDefect13034() {
-		String sql = "SELECT CONCAT('http://', CONCAT(CASE WHEN (HOST IS NULL) OR (HOST = '') THEN 'soap_host' ELSE HOST END, CASE WHEN (PORT IS NULL) OR (PORT = '') THEN '/metamatrix-soap/services/DataService' ELSE CONCAT(':', CONCAT(PORT, '/metamatrix-soap/services/DataService')) END)) AS location " + //$NON-NLS-1$
-			"FROM (SELECT env('soap_host') AS HOST, env('soap_port') AS PORT) AS props"; //$NON-NLS-1$
-			
-		// Create expected results
-		List[] expected = new List[] { 
-			Arrays.asList(new Object[] { "http://my.host.com:12345/metamatrix-soap/services/DataService" }), //$NON-NLS-1$ 
-		};    
-           
-		// Plan query
-		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-		// Run query
-		helpProcess(plan, new FakeDataManager(), expected);
-		    	
-    }
-    
-    /** see also integer average defect 11682 */
-    @Test public void testIntAvgDefect11682() { 
-        // Create query 
-        String sql = "SELECT AVG(IntKey), AVG(IntNum), AVG(FloatNum), AVG(LongNum), AVG(DoubleNum), AVG(ByteNum), AVG(ShortValue), AVG(BigIntegerValue), AVG(BigDecimalValue) FROM BQT1.SmallA"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new BigDecimal("1.500000000"), new BigDecimal("1.500000000") }),  //$NON-NLS-1$//$NON-NLS-2$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT_defect11682(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    @Test public void testNonJoinCriteriaInFrom() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-        
-    @Test public void testNonJoinCriteriaInWhere() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 WHERE b.e2 = 0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testNonJoinCriteriaInWhere2() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm1.g2 b ON a.e1=b.e1 WHERE (a.e2 + b.e2 = 1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "a", new Integer(1) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    @Test public void testNonJoinCriteriaInWhere3() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm1.g2 b ON a.e1=b.e1 WHERE (a.e2 = 0) OR (b.e2 = 0)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "a", new Integer(1) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }     
-        
-    @Test public void testNonJoinCriteriaInFromNestedInVirtual() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN (SELECT c.e1, d.e2 FROM pm2.g1 c JOIN pm2.g1 d ON c.e1=d.e1 AND d.e2 >= 0) b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-    
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testNonJoinCriteriaInFromUsingDependentJoin() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
-            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2a(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }          
-    
-    @Test public void testDefect13700() {
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(10) }), 
-        };    
-           
-        // Plan query
-        ProcessorPlan plan = helpGetPlan("EXEC pm1.vsp36(5)", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
-        
-        // Run query
-        helpProcess(plan, new FakeDataManager(), expected);
-        
-    }
-    
-    @Test public void testDefect13920() throws Exception {
-
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, false);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, false);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        
-        Command command = helpParse("SELECT e5, e2, e3, e4 FROM vm1.g1c WHERE e5 >= {ts'2004-08-01 00:00:00.0'}");   //$NON-NLS-1$
-        ProcessorPlan plan = helpGetPlan(command,  
-            FakeMetadataFactory.example1Cached(), capFinder);
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataStringTimestamps(dataManager);
-
-        Calendar cal = Calendar.getInstance();
-        cal.set(2004, Calendar.DECEMBER, 31, 0, 0, 0);
-        cal.set(Calendar.MILLISECOND, 0);
-        Timestamp t1 = new Timestamp(cal.getTime().getTime());
-        cal.clear();
-        cal.set(2004, Calendar.AUGUST, 1, 0, 0, 0);
-        cal.set(Calendar.MILLISECOND, 0);
-        Timestamp t2 = new Timestamp(cal.getTime().getTime());
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { t1,   new Integer(1),     Boolean.TRUE,   null }), 
-            Arrays.asList(new Object[] { t2,   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), 
-        };    
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-        
-    }
-
-    /** RLM Case 2077 */
-    @Test public void testComplexJoinExpressionsUsingDependentJoin() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2b(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
-        caps.setFunctionSupport("||", true); //$NON-NLS-1$
-        caps.setFunctionSupport("rtrim", true); //$NON-NLS-1$
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
-        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
-        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
-        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
-        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
-        
-        Command command = helpParse(sql);   
-        CommandContext context = createCommandContext();
-        context.setMetadata(metadata);
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder,context);
-        
-        //Verify a dependent join (not merge join) was used
-        assertTrue(plan instanceof RelationalPlan);
-        RelationalPlan relationalPlan = (RelationalPlan)plan;
-        RelationalNode project = relationalPlan.getRootNode();
-        RelationalNode join = project.getChildren()[0];
-        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
-
-        // Run query
-        helpProcess(plan, context, dataManager, expected);        
-    }     
-
-    /** RLM Case 2077 */
-    @Test public void testComplexJoinExpressionsUsingDependentJoinWithAccessPattern() {
-        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) //$NON-NLS-1$ //$NON-NLS-2$ 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2b(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-        caps.setFunctionSupport("||", true); //$NON-NLS-1$
-        caps.setFunctionSupport("rtrim", true); //$NON-NLS-1$
-        capFinder.addCapabilities("pm4", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
-        FakeMetadataObject g1 = metadata.getStore().findObject("pm4.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
-        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
-        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
-        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
-        
-        Command command = helpParse(sql);   
-        CommandContext context = createCommandContext();
-        context.setMetadata(metadata);
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
-        
-        //Verify a dependent join (not merge join) was used
-        assertTrue(plan instanceof RelationalPlan);
-        RelationalPlan relationalPlan = (RelationalPlan)plan;
-        RelationalNode project = relationalPlan.getRootNode();
-        RelationalNode join = project.getChildren()[0];
-        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
-
-        // Run query
-        helpProcess(plan, context, dataManager, expected);        
-    }      
-    
-    @Test public void testPushingCriteriaUnderJoinButNotToSource() {
-        // Create query
-        String sql = "SELECT A.IntKey AS A_IntKey, B.IntKey AS B_IntKey, C.IntKey AS C_IntKey " +  //$NON-NLS-1$
-        "FROM (BQT1.SmallA AS A FULL OUTER JOIN BQT2.SmallA AS B ON A.IntKey = B.IntKey) LEFT OUTER JOIN BQT3.SmallA AS C ON B.IntKey = C.IntKey " +  //$NON-NLS-1$
-        "WHERE (sin(A.IntKey) >= 0) " +  //$NON-NLS-1$
-        "AND (C.IntKey >= 10)"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(13), new Integer(13), new Integer(13) }),
-            Arrays.asList(new Object[] { new Integer(14), new Integer(14), new Integer(14) }),
-            Arrays.asList(new Object[] { new Integer(15), new Integer(15), new Integer(15) }),
-            Arrays.asList(new Object[] { new Integer(19), new Integer(19), new Integer(19) }),
-            Arrays.asList(new Object[] { new Integer(20), new Integer(20), new Integer(20) }),
-            Arrays.asList(new Object[] { new Integer(21), new Integer(21), new Integer(21) }),
-            Arrays.asList(new Object[] { new Integer(26), new Integer(26), new Integer(26) }),
-            Arrays.asList(new Object[] { new Integer(27), new Integer(27), new Integer(27) }),
-            Arrays.asList(new Object[] { new Integer(28), new Integer(28), new Integer(28) })
-        };
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2(dataManager);
-
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }    
-    
-    @Test public void testPushdownLiteralInSelectUnderAggregate() {  
-        String sql = "SELECT COUNT(*) FROM (SELECT '' AS y, a.IntKey FROM BQT1.SmallA a union all select '', b.intkey from bqt1.smallb b) AS x"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(30) }) 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testPushdownLiteralInSelectWithOrderBy() {  
-        String sql = "SELECT 1, concat('a', 'b' ) AS X FROM BQT1.SmallA where intkey = 0 " +  //$NON-NLS-1$
-            "UNION ALL " +  //$NON-NLS-1$
-            "select 2, 'Hello2' from BQT1.SmallA where intkey = 1 order by X desc"; //$NON-NLS-1$
-        
-        
-        // Create expected results - would expect these to be:
-        //    1, "ab"
-        //    2, "Hello2"
-        // but our fake tuple source is too dumb to return anything reasonable, so instead get:
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null, null }), 
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQTSmall(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-
-        // Run query
-        helpProcess(plan, dataManager, expected);        
-    }
-    
-    /** defect 15348*/
-    @Test public void testPreparedStatementDefect15348(){
-        String sql = "SELECT e1 from pm1.g1 where myrtrim(?)=e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$  
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2a(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setFunctionSupport("myrtrim", true); //$NON-NLS-1$
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        FunctionLibrary funcLibrary = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(new FakeFunctionMetadataSource().getFunctionMethods())));
-        FakeMetadataFacade metadata = new FakeMetadataFacade(FakeMetadataFactory.example1Cached().getStore(), funcLibrary);
-        
-        
-        Command command = helpParse(sql);   
-        CommandContext context = createCommandContext();
-        context.setMetadata(metadata);        
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
-        
-        // Collect reference, set value
-        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
-        VariableContext vc = new VariableContext();
-        vc.setGlobalValue(ref.getContextSymbol(),  "a    "); //$NON-NLS-1$
-        context.setVariableContext(vc);
-        // Run query
-        helpProcess(plan, context, dataManager, expected);        
-        
-    }    
-
-    /** defect 15348*/
-    @Test public void testPreparedStatementDefect15348b(){
-        String sql = "SELECT e1 from pm4.g1 where myrtrim(concat(?, 'a  '))=e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "aa" }) //$NON-NLS-1$  
-        };    
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2a(dataManager);
-    
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setFunctionSupport("myrtrim", true); //$NON-NLS-1$
-        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
-        capFinder.addCapabilities("pm4", caps); //$NON-NLS-1$
-
-        FunctionLibrary funcLibrary = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(new FakeFunctionMetadataSource().getFunctionMethods())));
-        FakeMetadataFacade metadata = new FakeMetadataFacade(FakeMetadataFactory.example1Cached().getStore(), funcLibrary);
-        
-        
-        Command command = helpParse(sql);   
-        CommandContext context = createCommandContext();
-        context.setMetadata(metadata);        
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
-        
-        // Collect reference, set value
-        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
-        VariableContext vc = new VariableContext();
-        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
-        context.setVariableContext(vc);
-        
-        // Run query
-        helpProcess(plan, context, dataManager, expected);        
-        
-    }      
-
-    @Test public void testSourceDoesntSupportGroupAlias() {  
-        String sql = "SELECT a.IntKey, b.IntKey FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey"; //$NON-NLS-1$
-        
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
-        assertEquals("Expected one query to get pushed down", 1, atomicQueries.size()); //$NON-NLS-1$
-        String atomicSql = atomicQueries.iterator().next().toString();
-        String expectedSql = "SELECT BQT1.SmallA.IntKey, BQT1.SmallB.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5) AND (BQT1.SmallB.IntKey = 5)"; //$NON-NLS-1$
-        assertEquals(expectedSql, atomicSql); 
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(5), new Integer(5)}), 
-                                  };    
-        
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, expected);
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testSourceDoesntSupportGroupAliasOrCriteria() {  
-        String sql = "SELECT a.IntKey, b.IntKey FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.StringKey = '5' AND A.IntKey = b.IntKey"; //$NON-NLS-1$
-        
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
-        assertEquals("Expected 2 queries to get pushed down", 2, atomicQueries.size()); //$NON-NLS-1$
-        
-        String expectedSql = "SELECT BQT1.SmallA.StringKey, BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
-        String expectedSql2 = "SELECT BQT1.SmallB.IntKey FROM BQT1.SmallB"; //$NON-NLS-1$
-        Set expectedQueries = new HashSet();
-        expectedQueries.add(expectedSql);
-        expectedQueries.add(expectedSql2);
-        assertEquals(expectedQueries, atomicQueries); 
-
-        List[] input1 = new List[] { 
-                                    Arrays.asList(new Object[] { "5", new Integer(5)}), //$NON-NLS-1$ 
-                                };    
-        List[] input2 = new List[] {Arrays.asList(new Object[] {new Integer(5)}), 
-        };
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData(expectedSql, input1);
-        dataManager.addData(expectedSql2, input2);
-        
-        List[] expected = new List[] {Arrays.asList(new Object[] {new Integer(5), new Integer(5)}), 
-        };
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    /**
-     * Same as testSourceDoesntSupportGroupAlias, but query is in an inline view and only 
-     * the first column is selected.
-     * 
-     * @since 4.2
-     */
-    @Test public void testSourceDoesntSupportGroupAliasInVirtual() {  
-        String sql = "SELECT x FROM (SELECT a.IntKey as x, b.IntKey as y FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey) AS z, BQT2.SmallA WHERE y = IntKey"; //$NON-NLS-1$
-        
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
-        assertEquals("Expected 2 queries to get pushed down", 2, atomicQueries.size()); //$NON-NLS-1$
-        
-        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5) AND (BQT1.SmallB.IntKey = 5)"; //$NON-NLS-1$
-        String expectedSql2 = "SELECT BQT2.SmallA.IntKey FROM BQT2.SmallA WHERE BQT2.SmallA.IntKey = 5"; //$NON-NLS-1$
-        
-        Set expectedQueries = new HashSet();
-        expectedQueries.add(expectedSql);
-        expectedQueries.add(expectedSql2);
-        assertEquals(expectedQueries, atomicQueries); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(5), new Integer(5)}), 
-                                  };    
-        List[] input2 = new List[] { 
-                                    Arrays.asList(new Object[] { new Integer(5)}), 
-                                };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-        dataManager.addData(expectedSql2, input2);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(5)}), 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testCaseInGroupBy() {  
-        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
-        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
-        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT SUM(X_1.c_1), X_1.c_0 FROM (SELECT CASE WHEN BQT1.SmallA.IntKey >= 5000 THEN '5000 +' ELSE '0-999' END AS c_0, BQT1.SmallA.IntKey AS c_1 FROM BQT1.SmallA) AS v_0 GROUP BY X_1.c_0"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(5), new Integer(10)}), 
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(5), new Integer(10)}), 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testCaseInGroupByAndHavingCantPush() {  
-        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
-        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
-        "HAVING case when IntKey>=5000 then '5000 +' else '0-999' end = '5000 +'"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(2)}),  
-                                      Arrays.asList(new Object[] { new Integer(4)}),  
-                                      Arrays.asList(new Object[] { new Integer(10000)}),  
-                                      Arrays.asList(new Object[] { new Integer(10002)}),  
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Long(20002), "5000 +"}), //$NON-NLS-1$ 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testCaseInGroupByAndHavingCantPush2() {  
-        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end || 'x' " + //$NON-NLS-1$
-        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
-        "HAVING length(case when IntKey>=5000 then '5000 +' else '0-999' end) > 5"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(2)}),  
-                                      Arrays.asList(new Object[] { new Integer(4)}),  
-                                      Arrays.asList(new Object[] { new Integer(10000)}),  
-                                      Arrays.asList(new Object[] { new Integer(10002)}),  
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Long(20002), "5000 +x"}), //$NON-NLS-1$ 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testCaseInGroupByAndHavingCantPush3() {  
-        String sql = "SELECT s, c FROM (" + //$NON-NLS-1$
-            "SELECT sum (IntKey) s, case when IntKey>=5000 then '5000 +' else '0-999' end || 'x' c " + //$NON-NLS-1$
-            "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
-            ") AS x WHERE length(c) > 5 AND s = 20002"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { new Integer(2)}),  
-                                      Arrays.asList(new Object[] { new Integer(4)}),  
-                                      Arrays.asList(new Object[] { new Integer(10000)}),  
-                                      Arrays.asList(new Object[] { new Integer(10002)}),  
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { new Long(20002), "5000 +x"}), //$NON-NLS-1$ 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-
-    @Test public void testFunctionOfAggregateCantPush() {  
-        String sql = "SELECT StringKey || 'x', SUM(length(StringKey || 'x')) + 1 AS x FROM BQT1.SmallA GROUP BY StringKey || 'x' HAVING space(MAX(length((StringKey || 'x') || 'y'))) = '   '"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT BQT1.SmallA.StringKey FROM BQT1.SmallA"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { "0"}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "1"}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "10"}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "11"}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "100"}),   //$NON-NLS-1$
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { "0x", new Long(3)}), //$NON-NLS-1$ 
-                                      Arrays.asList(new Object[] { "1x", new Long(3)}), //$NON-NLS-1$ 
-                                  };    
-        helpProcess(plan, dataManager, expected);        
-    }
-    
-    
-    @Test public void testCase2634() {
-        
-        String sql = "SELECT x, IntKey FROM (SELECT IntKey, 'a' AS x FROM BQT1.SmallA UNION ALL SELECT IntKey, 'b' AS x FROM BQT1.SmallB) as Z"; //$NON-NLS-1$
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
-        String expectedSql = "SELECT 'a' AS c_0, BQT1.SmallA.IntKey AS c_1 FROM BQT1.SmallA UNION ALL SELECT 'b' AS c_0, BQT1.SmallB.IntKey AS c_1 FROM BQT1.SmallB"; //$NON-NLS-1$
-        assertEquals(1, actualQueries.size());        
-        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
-
-        List[] input1 = new List[] { 
-                                      Arrays.asList(new Object[] { "a", new Integer(0)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "a", new Integer(1)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "b", new Integer(0)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "b", new Integer(1)}),   //$NON-NLS-1$
-                                  };    
-        HardcodedDataManager dataManager = new HardcodedDataManager();              
-        dataManager.addData(expectedSql, input1);
-
-        List[] expected = new List[] { 
-                                      Arrays.asList(new Object[] { "a", new Integer(0)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "a", new Integer(1)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "b", new Integer(0)}),   //$NON-NLS-1$
-                                      Arrays.asList(new Object[] { "b", new Integer(1)}),   //$NON-NLS-1$
-                                  };    
-        helpProcess(plan, dataManager, expected);          
-        
-    }
-    
-    @Test public void testQueryWithoutFromWithOrderBy() {
-        
-        String sql = "select 'three' as x ORDER BY x"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "three"} ), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        helpProcess(plan, dataManager, expected);         
-        
-    }
-
-    @Test public void testQueryWithoutFromWithOrderBy2() {
-        
-        String sql = "select concat('three', ' sixteen') as x ORDER BY x"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "three sixteen"} ), //$NON-NLS-1$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        helpProcess(plan, dataManager, expected);         
-        
-    }    
-
-    @Test public void testQueryWithoutFromWithOrderBy3() {
-        
-        String sql = "SELECT CONCAT('yy', 'z') as c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
-                     "CONCAT('21', '12') AS EXPR ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "yyz", "2112"} ), //$NON-NLS-1$ //$NON-NLS-2$ 
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        helpProcess(plan, dataManager, expected);         
-        
-    }     
-    
-    @Test public void testCase2507_3(){
-
-        String sql = "SELECT CONCAT('yy', 'z') AS c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
-                            "CONCAT('21', '12') AS EXPR ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
-
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
-        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
-                                      metadata,
-                                      null, capFinder,
-                                      new String[0] ,
-                                      TestOptimizer.SHOULD_SUCCEED );
-
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-                                        0,      // Access
-                                        0,      // DependentAccess
-                                        0,      // DependentSelect
-                                        0,      // DependentProject
-                                        0,      // DupRemove
-                                        0,      // Grouping
-                                        0,      // Join
-                                        0,      // MergeJoin
-                                        0,      // Null
-                                        0,      // PlanExecution
-                                        1,      // Project
-                                        0,      // Select
-                                        0,      // Sort
-                                        0       // UnionAll
-                                    });        
-        
-        // TEST PROCESSING
-
-        List[] expectedResults = new List[] { 
-              Arrays.asList(new Object[] { "yyz", "2112"}), //$NON-NLS-1$ //$NON-NLS-2$ 
-          };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT1(dataManager);
-
-        // Run query
-        helpProcess(plan, dataManager, expectedResults);        
-        
-    }    
-
-    @Test public void testMultiGroupJoinCriteria() {
-        
-        String sql = "SELECT X.NEWFIELD FROM " + //$NON-NLS-1$
-                       "(SELECT SMALLA.STRINGNUM, " + //$NON-NLS-1$
-                        "CASE WHEN SMALLA.STRINGNUM LIKE '1%' THEN SMALLA.INTKEY " + //$NON-NLS-1$
-                             "WHEN SMALLA.STRINGNUM LIKE '2%' THEN SMALLB.INTNUM " + //$NON-NLS-1$
-                             "WHEN SMALLA.STRINGNUM LIKE '3%' THEN MEDIUMA.INTKEY " + //$NON-NLS-1$
-                       "END AS NEWFIELD " + //$NON-NLS-1$
-                       "FROM BQT1.SMALLA, BQT1.SMALLB, BQT1.MEDIUMA " + //$NON-NLS-1$
-                       "WHERE SMALLA.INTKEY = SMALLB.INTKEY AND SMALLA.INTKEY = MEDIUMA.INTKEY) AS X " + //$NON-NLS-1$
-                     "WHERE X.NEWFIELD = -3"; //$NON-NLS-1$
-        
-        String expectedAtomic1 = "SELECT BQT1.SMALLB.INTKEY, BQT1.SMALLB.INTNUM FROM BQT1.SMALLB"; //$NON-NLS-1$
-        String expectedAtomic2 = "SELECT BQT1.MEDIUMA.INTKEY FROM BQT1.MEDIUMA"; //$NON-NLS-1$
-        String expectedAtomic3 = "SELECT BQT1.SMALLA.INTKEY, BQT1.SMALLA.STRINGNUM FROM BQT1.SMALLA"; //$NON-NLS-1$
-        
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
-                          metadata,
-                          null, capFinder,
-                          new String[] {expectedAtomic1, expectedAtomic2, expectedAtomic3} ,
-                          TestOptimizer.SHOULD_SUCCEED );        
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-                            3,      // Access
-                            0,      // DependentAccess
-                            0,      // DependentSelect
-                            0,      // DependentProject
-                            0,      // DupRemove
-                            0,      // Grouping
-                            0,      // Join
-                            2,      // MergeJoin
-                            0,      // Null
-                            0,      // PlanExecution
-                            1,      // Project
-                            0,      // Select
-                            0,      // Sort
-                            0       // UnionAll
-                        });        
-    
-        // TEST PROCESSING
-        
-        List[] expectedResults = new List[] { 
-        Arrays.asList(new Object[] { new Integer(-3) }), 
-        };    
-        
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager(); 
-        List[] input1 = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(-4)}), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(-3)}), 
-            Arrays.asList(new Object[] { new Integer(3), new Integer(-2)}), 
-        };    
-        dataManager.addData(expectedAtomic1, input1);
-        List[] input2 = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1)}), 
-            Arrays.asList(new Object[] { new Integer(2)}), 
-            Arrays.asList(new Object[] { new Integer(3)}), 
-        };    
-        dataManager.addData(expectedAtomic2, input2);
-        List[] input3 = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), new String("1")}), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { new Integer(2), new String("2")}), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { new Integer(3), new String("3")}), //$NON-NLS-1$ 
-        };    
-        dataManager.addData(expectedAtomic3, input3);
-        
-        // Run query
-        helpProcess(plan, dataManager, expectedResults);        
-        
-    }    
-    
-    /**
-     * Cross-source join with group by on top but no aggregate functions - running some special cases
-     * where there are no "aggregate groups" (the groups of the aggregate expressions) because there
-     * are no aggregate expressions.  In this case, need to switch the aggregate groups to be all the grouping
-     * columns because they are all being "grouped on".    
-     * 
-     * @since 4.3
-     */
-    @Test public void testDefect18360(){
-
-        String sql = "SELECT a.intkey, a.intnum FROM bqt1.smalla a join bqt2.mediumb b on a.stringkey = b.stringkey " + //$NON-NLS-1$
-            "group by a.intkey, a.intnum"; //$NON-NLS-1$
-
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        capFinder.addCapabilities("BQT1", new BasicSourceCapabilities()); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", new BasicSourceCapabilities()); //$NON-NLS-1$
-
-        Command command = helpParse(sql);
-        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder);
-        
-        // Construct data manager with data        
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        List[] data1 = new List[] {
-            Arrays.asList(new Object[] { "1", new Integer(1), new Integer(5) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2", new Integer(2), new Integer(6) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3", new Integer(3), new Integer(7) }), //$NON-NLS-1$
-        };        
-        dataManager.addData("SELECT bqt1.smalla.stringkey, bqt1.smalla.intkey, bqt1.smalla.intnum FROM bqt1.smalla", data1);  //$NON-NLS-1$
-
-        List[] data2 = new List[] {
-            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "3" }), //$NON-NLS-1$
-        };        
-        dataManager.addData("SELECT bqt2.mediumb.stringkey FROM bqt2.mediumb", data2);  //$NON-NLS-1$
-
-        // Run query
-        List[] expectedResults = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), new Integer(5) }), 
-            Arrays.asList(new Object[] { new Integer(2), new Integer(6) }), 
-            Arrays.asList(new Object[] { new Integer(3), new Integer(7) }), 
-        };    
-        helpProcess(plan, dataManager, expectedResults);          
-
-    }    
-    
-    @Test public void testDefect17407(){
-        String sql = "select pm1.g1.e1 from pm1.g1, g7 MAKEDEP WHERE pm1.g1.e2=g7.e2 order by e1"; //$NON-NLS-1$
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { null}),
-            Arrays.asList(new Object[] { null}),
-            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$           
-            Arrays.asList(new Object[] { "b"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "c"}),//$NON-NLS-1$
-            Arrays.asList(new Object[] { "c"}),//$NON-NLS-1$
-        };       
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);   
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
-        // Run query
-        helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testDecodeAsCriteria() { 
-        // Create query 
-        String sql = "SELECT x.foo, e2 FROM (select decodestring(e1, 'a,q,b,w') as foo, e2 from vm1.g1) as x where x.foo = 'w'"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-                Arrays.asList(new Object[] { "w", new Integer(2) }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testInputParamInNestedExecParam() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp48('a')"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testVariableInExecParam() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp49()"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b", new Integer(2) }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testVariableInNestedExecParam() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp50()"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testVariableInNestedExecParamInLoop() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp51()"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "bb" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testVariableInNestedExecParamInAssignment() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp52()"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testInputParamInNestedExecParamInLoop() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp53('b')"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "bb" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    @Test public void testInputParamInNestedExecParamInAssignment() { 
-        // Create query 
-        String sql = "EXEC pm1.vsp54('c')"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testBitwiseAggregateProc() { 
-        // Create query 
-        String sql = "EXEC virt.agg()"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(19) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(1), "b", new Integer(4) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new Integer(2), "c", new Integer(3) }), //$NON-NLS-1$
-        };    
-    
-        // Plan query
-        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBitwise();
-        ProcessorPlan plan = helpGetPlan(sql, metadata);
-
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBitwise(dataManager, metadata);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    private void sampleDataBitwise(FakeDataManager dataMgr, FakeMetadataFacade metadata) {    
-        try { 
-            // Group pm1.g1
-            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("phys.t"); //$NON-NLS-1$
-            List elementIDs = metadata.getElementIDsInGroupID(groupID);
-            List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-            dataMgr.registerTuples(
-                groupID,
-                elementSymbols,
-                
-                new List[] { 
-                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(1) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(16) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { new Integer(1), "b", new Integer(4) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { new Integer(2), "c", new Integer(2) }), //$NON-NLS-1$
-                    Arrays.asList(new Object[] { new Integer(2), "c", new Integer(1) }), //$NON-NLS-1$
-                    } );    
-
-        } catch(Throwable e) { 
-            e.printStackTrace();
-            fail("Exception building test data (" + e.getClass().getName() + "): " + e.getMessage());    //$NON-NLS-1$ //$NON-NLS-2$
-        }
-    }  
-    
-    @Test public void testFunctionGroupByInJoinCriteria() {  
-        // Create query  
-        String sql = "SELECT lower(vm1.g1.e1) from vm1.g1, vm1.g2a where vm1.g1.e1 = vm1.g2a.e1 group by lower(vm1.g1.e1)"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$ 
-                Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$ 
-                };     
-
-        // Construct data manager with data 
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleData1(dataManager); 
-         
-        // Plan query 
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached()); 
- 
-        // Run query 
-        helpProcess(plan, dataManager, expected); 
-    }
-
-    private FakeMetadataFacade createProjectErrorMetadata() {
-        FakeMetadataObject p1 = FakeMetadataFactory.createPhysicalModel("p1"); //$NON-NLS-1$
-        FakeMetadataObject t1 = FakeMetadataFactory.createPhysicalGroup("p1.t", p1); //$NON-NLS-1$
-        List e1 = FakeMetadataFactory.createElements(t1, new String[] {"a", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        
-        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
-        QueryNode n1 = new QueryNode("v1.t1", "SELECT convert(a, integer) as c, b FROM p1.t"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualGroup("v1.t1", v1, n1); //$NON-NLS-1$
-        List vte1 = FakeMetadataFactory.createElements(vt1, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
-        QueryNode n2 = new QueryNode("v1.t2", "SELECT convert(a, integer) as c, b FROM p1.t"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vt2 = FakeMetadataFactory.createVirtualGroup("v1.t2", v1, n2); //$NON-NLS-1$
-        List vte2 = FakeMetadataFactory.createElements(vt2, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
-        QueryNode n3 = new QueryNode("v1.u1", "SELECT c, b FROM v1.t1 UNION ALL SELECT c, b FROM v1.t1"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject vu1 = FakeMetadataFactory.createVirtualGroup("v1.u1", v1, n3); //$NON-NLS-1$
-        List vtu1 = FakeMetadataFactory.createElements(vu1, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(p1);
-        store.addObject(t1);
-        store.addObjects(e1);
-        store.addObject(v1);
-        store.addObject(vt1);
-        store.addObjects(vte1);
-        store.addObject(vt2);
-        store.addObjects(vte2);
-        store.addObject(vu1);
-        store.addObjects(vtu1);
-        return new FakeMetadataFacade(store);
-    }
-    
-    @Test public void testProjectionErrorOverUnionWithConvert() {  
-        // Create query  
-        FakeMetadataFacade metadata = createProjectErrorMetadata();
-        String sql = "SELECT COUNT(*) FROM v1.u1"; //$NON-NLS-1$ 
-         
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        capFinder.addCapabilities("p1", caps); //$NON-NLS-1$
-
-        Command command = helpParse(sql);
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-         
-        // Run query 
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { new Integer(2) }), 
-                };     
-
-        // Construct data manager with data 
-        HardcodedDataManager dataManager = new HardcodedDataManager(); 
-        dataManager.addData("SELECT g_0.a FROM p1.t AS g_0",  //$NON-NLS-1$
-                            new List[] { Arrays.asList(new Object[] { new Integer(1) })});
-        helpProcess(plan, dataManager, expected); 
-    }
-    
-    @Test public void testUpdatesInLoop() { 
-        String sql = "update vm1.g39 set e2=3"; //$NON-NLS-1$ 
- 
-        // Plan query 
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());        
-
-        // Construct data manager with data 
-        HardcodedDataManager dataManager = new HardcodedDataManager(); 
-        dataManager.addData("SELECT pm1.g1.e2 FROM pm1.g1", //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(3) } )});
-        dataManager.addData("UPDATE pm1.g1 SET e2 = 3 WHERE pm1.g1.e2 = 3", //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(1) } )});
-        
-        // Create expected results 
-        List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1)})};        
-        
-        // Run query 
-        helpProcess(plan, dataManager, expected);  
-         
-    }
-    
-    @Test public void testRand() { 
-        // Create query 
-        String sql = "SELECT RAND(E2) FROM pm1.g1 where pm1.g1.e2=3"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] {new Double(0.731057369148862)}),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /*
-     *  Prior to case 3994 testInsertTempTableCreation1 worked, but testInsertTempTableCreation did not.
-     *  Now they should both pass
-     * 
-     */    
-    @Test public void testInsertTempTableCreation() {
-        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
-        QueryNode n1 = new QueryNode("v1.vp", "CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs);  //$NON-NLS-1$
-        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
-        
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(v1);
-        store.addObject(vp);
-        
-        ProcessorPlan plan = helpGetPlan("exec v1.vp()", new FakeMetadataFacade(store)); //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(1) })
-        };
-        helpProcess(plan, new FakeDataManager(), expected);
-    }
-    
-    @Test public void testInsertTempTableCreation1() {
-        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
-        QueryNode n1 = new QueryNode("v1.vp", "CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select 2 as var1 into #temp; select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
-        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs);  //$NON-NLS-1$
-        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
-        
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(v1);
-        store.addObject(vp);
-        
-        ProcessorPlan plan = helpGetPlan("exec v1.vp()", new FakeMetadataFacade(store)); //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(1) }),
-            Arrays.asList(new Object[] { new Integer(2) })
-        };
-        helpProcess(plan, new FakeDataManager(), expected);
-    }    
-        
-    @Test public void testCase4531() { 
-        String sql = "select intkey, intnum from (select intnum as intkey, 1 as intnum from bqt1.smalla union all select intkey, intnum from bqt1.smalla union all select intkey, intnum from bqt2.smalla) x"; //$NON-NLS-1$ 
- 
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true); 
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true); 
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$ 
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$ 
- 
-        Command command = helpParse(sql); 
-        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder); 
- 
-        // Run query  
-        // Create expected results  
-        List[] expected = new List[] {   
-                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
-                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
-                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
-                };      
-         
-        // Construct data manager with data  
-        HardcodedDataManager dataManager = new HardcodedDataManager();  
-        dataManager.addData("SELECT g_0.intkey, g_0.intnum FROM bqt2.smalla AS g_0",  //$NON-NLS-1$ 
-                            new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) })}); 
-        dataManager.addData("SELECT g_1.intnum AS c_0, 1 AS c_1 FROM bqt1.smalla AS g_1 UNION ALL SELECT g_0.IntKey AS c_0, g_0.IntNum AS c_1 FROM bqt1.smalla AS g_0",  //$NON-NLS-1$ 
-                new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
-                                 Arrays.asList(new Object[] { new Integer(1), new Integer(1) })}); 
-        helpProcess(plan, dataManager, expected);  
-    }
-        
-    private void sampleDataBQT2a(FakeDataManager dataMgr) throws Exception {
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-    
-        String[] groups = new String[] {"bqt1.smalla", "bqt2.smalla", "bqt3.smalla" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-    
-        for(int groupIndex=0; groupIndex<groups.length; groupIndex++) {
-            String groupName = groups[groupIndex];
-
-            List[] tuples = new List[3];
-            for(int row=0; row<tuples.length; row++) {
-                tuples[row] = new ArrayList(17);
-                tuples[row].add(new Integer(row)); //IntKey
-                tuples[row].add(String.valueOf(row)); //StringKey
-                tuples[row].add(new Integer(row));  //IntNum
-                tuples[row].add(String.valueOf(row)); //StringNum
-                for(int col=0; col<10; col++) { //FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue
-                    tuples[row].add(null);    
-                }    
-                tuples[row].add(new BigInteger(String.valueOf(row))); //BigIntegerValue
-                tuples[row].add(new BigDecimal(row)); //BigDecimalValue
-                tuples[row].add(null);    //ObjectValue
-            }
-            dataMgr.registerTuples(metadata, groupName, tuples);
-        }
-    }    
-    
-    @Test public void testDefect15355() throws Exception {
-        
-        String sql = "SELECT e1, e1 FROM pm1.g1 "   //$NON-NLS-1$
-        +"UNION ALL "   //$NON-NLS-1$
-        +"SELECT e1, (SELECT e1 FROM pm2.g1 WHERE pm2.g1.e2 = pm1.g2.e2) FROM pm1.g2"; //$NON-NLS-1$
-        
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "c", "c" }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "a", "e" }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$  
-            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$  
-            Arrays.asList(new Object[] { "d", null }), //$NON-NLS-1$  
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testDefect15355b() throws Exception {
-        
-        String sql = "SELECT StringKey, BigIntegerValue FROM BQT1.SmallA "   //$NON-NLS-1$
-        +"UNION ALL "   //$NON-NLS-1$
-        +"SELECT StringKey, (SELECT BigIntegerValue FROM BQT3.SmallA WHERE BQT3.SmallA.BigIntegerValue = BQT2.SmallA.StringNum) FROM BQT2.SmallA"; //$NON-NLS-1$
-        
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "1", new BigInteger("1") }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "2", new BigInteger("2") }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "1", new BigInteger("1") }), //$NON-NLS-1$  //$NON-NLS-2$
-            Arrays.asList(new Object[] { "2", new BigInteger("2") }), //$NON-NLS-1$  //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }    
-
-    @Test public void testDefect15355c() throws Exception {
-        
-        String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }       
-    
-    @Test public void testDefect15355d() throws Exception {
-        
-        String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355a WHERE StringKey = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }     
-
-    @Test public void testDefect15355e() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue, StringKey FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0"), "0" }), //$NON-NLS-1$  //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }    
-
-    @Test public void testDefect15355f() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }     
-
-    @Test public void testDefect15355f2() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE StringKey LIKE '%0' AND StringKey LIKE '0%'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }      
-    
-    @Test public void testDefect15355g() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue AS a, BigIntegerValue AS b FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0"), new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }     
-
-    @Test public void testDefect15355h() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE BigIntegerValue = '0'";  //$NON-NLS-1$
-                      
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }     
-
-    @Test public void testDefect15355i() throws Exception {
-        
-        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355b WHERE BigIntegerValue = '0'";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2a(dataManager);
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
-        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
-        
-        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }  
-    
-    /**
-     * The inner most A.e1 was mistakenly getting transformed into pm1.g3.e1 
-     */
-    @Test public void testInnerCorrelatedReference() throws Exception {
-        
-        String sql = "SELECT DISTINCT A.e1 FROM pm1.g3 AS A WHERE (A.e1 IN (SELECT A.e1 FROM pm1.g3))";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-        };    
-        
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.addData("SELECT DISTINCT g_0.e1 FROM pm1.g3 AS g_0 WHERE g_0.e1 IN (SELECT g_0.e1 FROM pm1.g3 AS g_1)", expected); //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        // Plan query
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        
-        Command command = helpParse(sql);   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);           
-        
-    }
-    
-    @Test public void testCase5413() {
-
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        // Plan query
-        String sql = "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 1) = e1";//$NON-NLS-1$
-        QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
-        Command command = TestProcessor.helpParse(sql);   
-        CommandContext context = createCommandContext();
-        context.setMetadata(metadata);
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
-        
-        // Run query
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
-        };
-        
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        Map valueMap = new HashMap();
-        valueMap.put(1, "b"); //$NON-NLS-1$ //$NON-NLS-2$
-        dataManager.defineCodeTable("pm1.g1", "e2", "e1", valueMap); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        dataManager.setThrowBlocked(true);
-        
-        helpProcess(plan, context, dataManager, expected);
-    } 
-    
-    @Test public void testRaiseNullWithSelectInto() {
-        String sql = "select pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 into pm1.g2 from pm1.g1 where (1=0)"; //$NON-NLS-1$
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder()); 
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-                0,      // Access
-                0,      // DependentAccess
-                0,      // DependentSelect
-                0,      // DependentProject
-                0,      // DupRemove
-                0,      // Grouping
-                0,      // NestedLoopJoinStrategy
-                0,      // MergeJoinStrategy
-                1,      // Null
-                0,      // PlanExecution
-                1,      // Project
-                0,      // Select
-                0,      // Sort
-                0       // UnionAll
-            });
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { new Integer(0)}),
-        };
-
-        helpProcess(plan, new FakeDataManager(), expected);
-        
-    }    
-    
-    /*
-     * Test for Case6219
-     */
-    @Test public void testCase6219() {
-        String sql = "SELECT e1 FROM pm1.g1, (SELECT 'ACT' AS StateCode,'A' AS StateAbbrv UNION ALL SELECT 'NSW' AS StateCode, 'N' AS StateAbbrv) AS StateNames_Abbrvs WHERE (pm1.g1.e1 = StateCode) AND ((StateNames_Abbrvs.StateAbbrv || pm1.g1.e1) = 'VVIC')"; //$NON-NLS-1$
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder()); 
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-                0,      // Access
-                1,      // DependentAccess
-                0,      // DependentSelect
-                0,      // DependentProject
-                0,      // DupRemove
-                0,      // Grouping
-                0,      // NestedLoopJoinStrategy
-                1,      // MergeJoinStrategy
-                0,      // Null
-                0,      // PlanExecution
-                3,      // Project
-                0,      // Select
-                0,      // Sort
-                1       // UnionAll
-            });
-        
-        List[] expected = new List[] {
-        };
-        
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-        
-    }
-    
-    @Test public void testSortWithLimit() {
-        String sql = "select e1 from (select pm1.g1.e1, pm1.g1.e2 from pm1.g1 order by pm1.g1.e1, pm1.g1.e2 limit 1) x"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { null}),
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testSortWithLimit1() {
-        String sql = "select c from (select pm1.g1.e1 a, pm1.g1.e2 b, pm1.g1.e3 c from pm1.g1 order by b limit 1) x"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { Boolean.FALSE}),
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-        //note that the e1 column is not used in the source query
-        assertEquals("SELECT pm1.g1.e3, pm1.g1.e2 FROM pm1.g1", (String)manager.getQueries().iterator().next()); //$NON-NLS-1$
-    }
-    
-    @Test public void testSortWithLimit2() {
-        String sql = "select a from (select max(e2) a from pm1.g1 group by e2 order by a limit 1) x where a = 0"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { new Integer(0) }),
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    /**
-     * A more direct test of 1, where the nested order by is unrelated
-     */
-    @Test public void testSortWithLimit3() {
-        String sql = "select c from (select pm1.g1.e3 c from pm1.g1 order by pm1.g1.e2 limit 1) x"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { Boolean.FALSE }),
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testSortWithLimit4() {
-        String sql = "select c from (select pm1.g1.e1 a, pm1.g1.e2 b, pm1.g1.e3 c from pm1.g1 order by b limit 1) x"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_ORDERBY_UNRELATED, false);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(caps));
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { Boolean.FALSE }),
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-        assertEquals("SELECT g_0.e3 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_1", manager.getQueries().iterator().next()); //$NON-NLS-1$
-    }
-
-    @Test public void testCountWithHaving() {
-        String sql = "select e1, count(*) from pm1.g1 group by e1 having count(*) > 1"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { "a" , new Integer(3)}), //$NON-NLS-1$
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testLimitZero() {
-        String sql = "select e1 from pm1.g1 limit 0"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        TestOptimizer.checkNodeTypes(plan, TestRuleRaiseNull.FULLY_NULL);     
-        
-        List[] expected = new List[] {
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testLimitZero1() {
-        String sql = "select distinct vm1.g1.e1, y.e1 from vm1.g1 left outer join (select 1 x, e1 from vm1.g2 limit 0) y on vm1.g1.e1 = y.e1 where vm1.g1.e1 = 'a'"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            1,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            1,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            0,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            0,      // Select
-            0,      // Sort
-            0       // UnionAll
-       });     
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testLimitZero2() {
-        String sql = "select vm1.g1.e1 from vm1.g1 union select e1 from pm1.g2 limit 0"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testLimitZero3() {
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-        
-        String sql = "select e1 from pm1.g2 limit 0"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, capFinder);
-        
-        List[] expected = new List[] {
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testUnionWithTypeConversion() {
-        String sql = "select pm1.g1.e1, pm1.g1.e2 from pm1.g1 where e1 = 'b' union select e2, e1 from pm1.g2 where e1 = 'b' order by e1, e2"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "2", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList(new Object[] { "b", "2" }), //$NON-NLS-1$ //$NON-NLS-2$
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    /**
-     * Tests non-deterministic evaluation in the select clause.  
-     * 
-     * The evaluation of the rand function is delayed until processing time (which actually has predictable
-     * values since the test initializes the command context with the same seed)
-     * 
-     * If this function were deterministic, it would be evaluated during rewrite to a single value.
-     */
-    @Test public void testNonDeterministicEvaluation() throws Exception {
-        String sql = "select e1, convert(rand()*1000, integer) as x from pm1.g1 where e1 = 'a'"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(240) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(637) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "a", new Integer(550) }), //$NON-NLS-1$ 
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    /**
-     * here the rand function is deterministic and should yield a single value
-     */
-    @Test public void testDeterministicEvaluation() throws Exception {
-        String sql = "select e1, convert(rand(0)*1000, integer) as x from pm1.g1 where e1 = 'a'"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$ 
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testEmptyAggregate() throws Exception {
-        String sql = "select count(e1) from pm1.g1 where 1 = 0"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(0) })
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testNullAggregate() throws Exception {
-        String sql = "select count(*), count(e1), sum(convert(e1, integer)) from pm1.g1 where e1 is null"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new Integer(1), new Integer(0), null })
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    /**
-     * here the presence of a group by causes no rows to be returned 
-     */
-    @Test public void testNullAggregate1() throws Exception {
-        String sql = "select e1 from pm1.g1 where 1 = 0 group by e1"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testReferenceReplacementWithExpression() throws Exception {
-        String sql = "select e1, e2 from (select e1, convert(e2, string) e2 from pm1.g1) x where exists (select e3 from pm1.g2 where x.e2 = e1)"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {};
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-
-    /**
-     * Here a merge join will be used since there is at least one equi join predicate.
-     * TODO: this can be optimized further
-     */
-    @Test public void testCase6193_1() throws Exception { 
-        // Create query 
-        String sql = "select a.INTKEY, b.intkey from bqt1.smalla a LEFT OUTER JOIN bqt2.SMALLA b on a.intkey=b.intkey and a.intkey=5 where a.intkey <10 "; //$NON-NLS-1$
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        capFinder.addCapabilities("BQT2", caps);
-
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), null }),
-            Arrays.asList(new Object[] { new Integer(1), null }),
-            Arrays.asList(new Object[] { new Integer(2), null }),
-            Arrays.asList(new Object[] { new Integer(3), null }),
-            Arrays.asList(new Object[] { new Integer(4), null }),
-            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
-            Arrays.asList(new Object[] { new Integer(6), null }),
-            Arrays.asList(new Object[] { new Integer(7), null }),
-            Arrays.asList(new Object[] { new Integer(8), null }),
-            Arrays.asList(new Object[] { new Integer(9), null })
-        };
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataBQT2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
-                                                    new String[] {"SELECT b.intkey FROM bqt2.SMALLA AS b", "SELECT a.intkey FROM bqt1.smalla AS a"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
-
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            2,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            1,      // Select
-            0,      // Sort
-            0       // UnionAll
-        });
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Here a merge join will be used since there is at least one equi join predicate.
-     */
-    @Test public void testCase6193_2() throws Exception { 
-        // Create query 
-        String sql = "select a.e2, b.e2 from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4 and (a.e2+b.e2)=4 order by a.e2"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0), null }),
-            Arrays.asList(new Object[] { new Integer(0), null }),
-            Arrays.asList(new Object[] { new Integer(1), null }),
-            Arrays.asList(new Object[] { new Integer(1), null }),
-            Arrays.asList(new Object[] { new Integer(2), new Integer(2) }),
-            Arrays.asList(new Object[] { new Integer(3), null }),
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
-                                                    new String[] {"SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            2,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            0,      // Select
-            1,      // Sort
-            0       // UnionAll
-        });
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    /**
-     * Here a merge join will be used since there is at least one equi join predicate.
-     * The inner merge join is also a dependent join
-     */
-    @Test public void testCase6193_3() throws Exception { 
-        // Create query 
-        String sql = "select a.x, b.y from (select 4 x union select 1) a LEFT OUTER JOIN (select (a.e2 + b.e2) y from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4) b on (a.x = b.y)"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(1), null }),
-            Arrays.asList(new Object[] { new Integer(4), new Integer(4) }),
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
-                                                    new String[] {"SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            2,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            2,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            4,      // Project
-            0,      // Select
-            0,      // Sort
-            1       // UnionAll
-        });
-        
-        TestOptimizer.checkDependentJoinCount(plan, 1);
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }           
-    
-    /**
-     * A control test to ensure that y will still exist for sorting
-     */
-    @Test public void testOrderByWithDuplicateExpressions() throws Exception {
-        String sql = "select e1 as x, e1 as y from pm1.g1 order by y ASC"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
-        
-        List[] expected = new List[] { 
-            Arrays.asList(null, null),
-            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList("b", "b"), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList("c", "c"), //$NON-NLS-1$ //$NON-NLS-2$
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    /**
-     * This is a control test.  It should work regardless of whether the reference is aliased
-     * since accessnodes are now fully positional
-     */
-    @Test public void testPushdownNonAliasedSelectLiteral() {
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        Command command = helpParse("select ?, e1 from pm1.g1"); //$NON-NLS-1$   
-        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
-        
-        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
-        VariableContext vc = new VariableContext();
-        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
-        CommandContext context = createCommandContext();
-        context.setVariableContext(vc);
-        
-        List[] expected = new List[] {
-            Arrays.asList("a", "b"), //$NON-NLS-1$ //$NON-NLS-2$
-            Arrays.asList("a", "c") //$NON-NLS-1$ //$NON-NLS-2$
-        };
-
-        HardcodedDataManager manager = new HardcodedDataManager();
-        manager.addData("SELECT 'a', pm1.g1.e1 FROM pm1.g1", expected); //$NON-NLS-1$ 
-        
-        helpProcess(plan, context, manager, expected);
-    }
-    
-    @Test public void testCase6486() { 
-        // Create query 
-        String sql = "select pm2.g1.e1 from pm1.g2, pm2.g1 where pm1.g2.e1=pm2.g1.e1 group by pm2.g1.e1"; //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "d"}) //$NON-NLS-1$
-        };    
-        
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testNonPushedOffset() throws Exception {
-        String sql = "SELECT e1 FROM pm1.g1 LIMIT 1, 5"; //$NON-NLS-1$
-        
-        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
-        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
-
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
-            Arrays.asList(new Object[] { "c"}), //$NON-NLS-1$
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData2(dataManager);
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (5 + 1)"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
-        helpProcess(plan, dataManager, expected);          
-    }
-    
-    @Test public void testNonCorrelatedSubQueryExecution() throws Exception {
-        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
-
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        dataManager.setBlockOnce(true);
-        dataManager.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List[] { //$NON-NLS-1$
-        		Arrays.asList(Integer.valueOf(1), "a"), //$NON-NLS-1$
-        		Arrays.asList(Integer.valueOf(2), "b") //$NON-NLS-1$
-        });
-        dataManager.addData("SELECT pm2.g1.e2 FROM pm2.g1", new List[] { //$NON-NLS-1$
-        		Arrays.asList(Integer.valueOf(2))
-        });
-        
-        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
-
-        List[] expected = new List[] {
-                Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
-            };
-
-        doProcess(plan, dataManager, expected, createCommandContext());
-        
-        //we expect 2 queries, 1 for the outer and 1 for the subquery
-        assertEquals(2, dataManager.getCommandHistory().size());
-    }
-    
-    @Test public void testOrderByOutsideOfSelect() {
-        // Create query 
-        String sql = "SELECT e1 FROM (select e1, e2 || e3 as e2 from pm1.g2) x order by e2"; //$NON-NLS-1$
-        
-        //a, a, null, c, b, a
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList("a"),
-            Arrays.asList("a"),
-            Arrays.asList(new String[] {null}),
-            Arrays.asList("c"),
-            Arrays.asList("b"),
-            Arrays.asList("a"),
-        };    
-    
-        // Construct data manager with data
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        // Plan query
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
-        
-        // Run query
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testOrderByUnrelatedExpression() {
-        String sql = "SELECT e1, e2 + 1 from pm1.g2 order by e3 || e2 limit 1"; //$NON-NLS-1$
-        
-        List[] expected = new List[] { 
-            Arrays.asList("a", 1),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-
-    /**
-     * Test a query that uses ambiguous alias names in the top level query and 
-     * its sub-query and uses columns belonging to the alias as a parameter to a 
-     * function.
-     * <p>
-     * For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT 
-     * CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
-     * <p>
-     * The test is to ensure that A.e2 from the top level is not confused with 
-     * e2 in the second level.
-     * <p>
-     * Related Defects: JBEDSP-1137
-     */
-    @Test public void testAliasReuseInFunctionInSubQuery() throws Exception {
-        // Create query
-    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
-    	"   SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A WHERE e1 = 'a'" + //$NON-NLS-1$
-    	") AS A"; //$NON-NLS-1$
-        
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
-        
-        List[] expected = new List[] {
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$
-            Arrays.asList(new Object[] { new BigInteger("3") }), //$NON-NLS-1$ 
-            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$ 
-        };
-
-        FakeDataManager manager = new FakeDataManager();
-        sampleData1(manager);
-        helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testOrderByDescAll() {
-        String sql = "SELECT distinct e1 from pm1.g2 order by e1 desc limit 1"; //$NON-NLS-1$
-        
-        List[] expected = new List[] { 
-            Arrays.asList("c"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testImplicitAggregateWithInlineView() {
-        String sql = "SELECT * FROM (SELECT b.count, enterprise_id FROM (SELECT COUNT(*), 2 AS enterprise_id FROM (SELECT 'A Name' AS Name, 1 AS enterprise_id) c ) b ) a WHERE enterprise_id = 1"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {};    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-        
-    private static final boolean DEBUG = false;
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestQueryProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestQueryProcessor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestQueryProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,139 +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;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.util.CommandContext;
-
-/**
- */
-public class TestQueryProcessor extends TestCase {
-
-    /**
-     * Constructor for TestQueryProcessor.
-     * @param name
-     */
-    public TestQueryProcessor(String name) {
-        super(name);
-    }
-    
-    public void helpTestProcessor(FakeProcessorPlan plan, long timeslice, List[] expectedResults) throws MetaMatrixCoreException {
-        BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
-        FakeDataManager dataManager = new FakeDataManager();
-
-        CommandContext context = new CommandContext("pid", "group", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
-        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
-        BatchCollector collector = processor.createBatchCollector();
-        TupleBuffer tsID = null;
-        while(true) {
-            try {
-                tsID = collector.collectTuples();         
-                break;
-            } catch(BlockedException e) {
-            }
-        }
-        
-        // Compare # of rows in actual and expected
-        assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount()); //$NON-NLS-1$
-        
-        // Compare actual with expected results
-        TupleSource actual = tsID.createIndexedTupleSource();
-        if(expectedResults.length > 0) {
-            for(int i=0; i<expectedResults.length; i++) {
-                List actRecord = actual.nextTuple();
-                List expRecord = expectedResults[i];                    
-                assertEquals("Did not match row at row index " + i, expRecord, actRecord); //$NON-NLS-1$
-            }
-        }
-        tsID.remove();
-    }
-    
-    public void testNoResults() throws Exception {
-        List elements = new ArrayList();
-        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
-        FakeProcessorPlan plan = new FakeProcessorPlan(elements, null);
-        helpTestProcessor(plan, 1000, new List[0]);    
-    }
-
-    public void testBlockNoResults() throws Exception {
-        List elements = new ArrayList();
-        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
-        
-        List batches = new ArrayList();
-        batches.add(BlockedException.INSTANCE);
-        TupleBatch batch = new TupleBatch(1, new List[0]);
-        batch.setTerminationFlag(true);
-        batches.add(batch);
-        
-        FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
-        helpTestProcessor(plan, 1000, new List[0]);    
-    }
-    
-    public void testProcessWithOccasionalBlocks() throws Exception {
-        List elements = new ArrayList();
-        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
-                
-        HashSet blocked = new HashSet(Arrays.asList(new Integer[] { new Integer(0), new Integer(2), new Integer(7) }));
-        int numBatches = 10;
-        int batchRow = 1;        
-        int rowsPerBatch = 50;
-        List[] expectedResults = new List[rowsPerBatch*(numBatches-blocked.size())];
-        List batches = new ArrayList();
-        for(int b=0; b<numBatches; b++) {
-            if(blocked.contains(new Integer(b))) {
-                batches.add(BlockedException.INSTANCE);
-            } else {    
-                List[] rows = new List[rowsPerBatch];
-                for(int i=0; i<rowsPerBatch; i++) {
-                    rows[i] = new ArrayList();
-                    rows[i].add(new Integer(batchRow));
-                    expectedResults[batchRow-1] = rows[i];
-                    batchRow++;
-                }
-                                                
-                TupleBatch batch = new TupleBatch(batchRow-rows.length, rows);
-                if(b == numBatches-1) {
-                    batch.setTerminationFlag(true);
-                } 
-                batches.add(batch);
-            }
-        }
-        
-        FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
-        helpTestProcessor(plan, 1000, expectedResults);                    
-    }
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,174 +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;
-
-import static com.metamatrix.query.processor.TestProcessor.*;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
- at SuppressWarnings("nls")
-public class TestSQLXMLProcessing {
-	
-	@Test public void testXmlElementTextContent() throws Exception {
-		String sql = "SELECT xmlelement(foo, '<bar>', convert('<bar1/>', xml))"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<foo>&lt;bar&gt;<bar1/></foo>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-	
-	/**
-	 * Repeat of the above test, but with a document declaration.  Because of the way we do event filtering, we end
-	 * up with a slightly different, but equivalent answer.
-	 */
-	@Test public void testXmlElementTextContent1() throws Exception {
-		String sql = "SELECT xmlelement(foo, '<bar>', convert('<?xml version=\"1.0\" encoding=\"UTF-8\"?><bar1/>', xml))"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<foo>&lt;bar&gt;<bar1></bar1></foo>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-	}
-	
-    @Test public void testXmlElement() {
-        String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<e1>1</e1>"),
-        		Arrays.asList("<e1>0</e1>"),
-        		Arrays.asList("<e1>0</e1>"),
-        		Arrays.asList("<e1>3</e1>"),
-        		Arrays.asList("<e1>2</e1>"),
-                Arrays.asList("<e1>1</e1>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithConcat() {
-        String sql = "SELECT xmlelement(e1, e2, xmlconcat(xmlelement(x), xmlelement(y, e3))) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<e1>1<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
-        		Arrays.asList("<e1>3<x></x><y>true</y></e1>"),
-        		Arrays.asList("<e1>2<x></x><y>false</y></e1>"),
-                Arrays.asList("<e1>1<x></x><y>true</y></e1>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithForest() {
-        String sql = "SELECT xmlelement(x, xmlforest(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x><e2>1</e2><val>1</val></x>"), //note e1 is not present, because it's null
-        		Arrays.asList("<x><e1>a</e1><e2>0</e2><val>1</val></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithAttributes() {
-        String sql = "SELECT xmlelement(x, xmlattributes(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x e2=\"1\" val=\"1\"></x>"), //note e1 is not present, because it's null
-        		Arrays.asList("<x e1=\"a\" e2=\"0\" val=\"1\"></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithPi() {
-        String sql = "SELECT xmlelement(x, xmlpi(name e1, '  1'))"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x><?e1 1?></x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-    
-    @Test public void testXmlElementWithNamespaces() {
-        String sql = "SELECT xmlelement(x, xmlnamespaces(no default, 'http://foo' as x, 'http://foo1' as y), xmlattributes(e1), e2) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
-        
-        List[] expected = new List[] {
-        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\">1</x>"), //note e1 is not present, because it's null
-        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\" e1=\"a\">0</x>"),
-        };    
-    
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleData1(dataManager);
-        
-        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
-        
-        helpProcess(plan, dataManager, expected);
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSecurityFunctions.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSecurityFunctions.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSecurityFunctions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,93 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.query.eval.SecurityFunctionEvaluator;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
-
-public class TestSecurityFunctions extends TestCase {
-
-    /**
-     *  hasRole should be true without a service
-     */
-    public void testHasRoleWithoutService() throws Exception {
-        
-        String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { 
-            Arrays.asList(new Object[] { new Integer(0) }),
-        };    
-        
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        
-        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { //$NON-NLS-1$
-            Arrays.asList(new Object[] { "fooRole", new Integer(0) }), //$NON-NLS-1$  
-        }); 
-        
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached());
-        
-        // Run query
-        TestProcessor.helpProcess(plan, dataManager, expected);
-    }
-    
-    public void testHasRoleWithService() throws Exception {
-        
-        String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";  //$NON-NLS-1$
-        
-        // Create expected results
-        List[] expected = new List[] { };    
-        
-        // Construct data manager with data
-        HardcodedDataManager dataManager = new HardcodedDataManager();
-        
-        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { //$NON-NLS-1$
-            Arrays.asList(new Object[] { "fooRole", new Integer(0) }), //$NON-NLS-1$  
-        }); 
-        
-        CommandContext context = new CommandContext();
-        context.setSecurityFunctionEvaluator(new SecurityFunctionEvaluator() {
-            public boolean hasRole(String roleType,
-                                   String roleName) throws MetaMatrixComponentException {
-                return false;
-            }});
-        
-        Command command = TestProcessor.helpParse(sql);   
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
-        
-        // Run query
-        TestProcessor.helpProcess(plan, context, dataManager, expected);
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,86 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
-public class TestSetProcessing {
-    
-    @Test public void testExcept() throws Exception {
-        String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2"; //$NON-NLS-1$
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(), new String[] {"SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g2.e1, pm1.g2.e2 FROM pm1.g2"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  //$NON-NLS-2$
-        
-        List<?>[] expected = new List[] {
-            Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {"a", 3}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {"b", 2}), //$NON-NLS-1$
-            };
-
-        FakeDataManager manager = new FakeDataManager();
-        TestProcessor.sampleData1(manager);
-        TestProcessor.helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testIntersect() throws Exception {
-        String sql = "select e1, e2 from pm1.g2 intersect select e1, 1 from pm1.g2"; //$NON-NLS-1$
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(), new String[] {"SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g2.e1, pm1.g2.e2 FROM pm1.g2"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  //$NON-NLS-2$
-        
-        List<?>[] expected = new List[] {
-            Arrays.asList(new Object[] {null, 1}),
-            Arrays.asList(new Object[] {"c", 1}), //$NON-NLS-1$
-            };
-
-        FakeDataManager manager = new FakeDataManager();
-        TestProcessor.sampleData1(manager);
-        TestProcessor.helpProcess(plan, manager, expected);
-    }
-    
-    @Test public void testIntersectExcept() {
-        String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2 intersect select 'a', e2 from pm1.g2"; //$NON-NLS-1$
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1, 1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT 'a', g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
-        
-        List<?>[] expected = new List[] {
-            Arrays.asList(new Object[] {null, 1}),
-            Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {"a", 3}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {"b", 2}), //$NON-NLS-1$
-            Arrays.asList(new Object[] {"c", 1}), //$NON-NLS-1$
-            };
-
-        FakeDataManager manager = new FakeDataManager();
-        TestProcessor.sampleData1(manager);
-        TestProcessor.helpProcess(plan, manager, expected);
-    }
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,93 +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;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
-import com.metamatrix.query.tempdata.TempTableStoreImpl;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-
-public class TestTempTables {
-	
-	private TempMetadataAdapter metadata;
-	private TempTableDataManager dataManager;
-
-	private void execute(String sql, List[] expectedResults) throws Exception {
-		TestProcessor.doProcess(TestProcessor.helpGetPlan(sql, metadata), dataManager, expectedResults, TestProcessor.createCommandContext());
-	}
-
-	@Before public void setUp() throws MetaMatrixComponentException {
-		TempTableStoreImpl tempStore = new TempTableStoreImpl(BufferManagerFactory.getStandaloneBufferManager(), "1", null); //$NON-NLS-1$
-		metadata = new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), tempStore.getMetadataStore());
-		FakeDataManager fdm = new FakeDataManager();
-	    TestProcessor.sampleData1(fdm);
-		dataManager = new TempTableDataManager(fdm, tempStore);
-	}
-
-	@Test public void testInsertWithQueryExpression() throws Exception {
-		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
-		execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
-	}
-	
-	@Test public void testOutofOrderInsert() throws Exception {
-		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
-		execute("insert into x (e2, e1) values (1, 'one')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
-		execute("select e1, e2 from x", new List[] {Arrays.asList("one", 1)}); //$NON-NLS-1$
-	}
-	
-	@Test public void testUpdate() throws Exception {
-		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
-		execute("insert into x (e2, e1) values (1, 'one')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
-		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
-		execute("select e1 from x where e2 > 0 order by e1", new List[] { //$NON-NLS-1$
-				Arrays.asList((String)null),
-				Arrays.asList("2"), //$NON-NLS-1$
-				Arrays.asList("3"), //$NON-NLS-1$
-				Arrays.asList("c"), //$NON-NLS-1$
-				Arrays.asList("one")}); //$NON-NLS-1$
-	}
-	
-	@Test public void testDelete() throws Exception {
-		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
-		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("delete from x where ascii(e1) > e2", new List[] {Arrays.asList(5)}); //$NON-NLS-1$
-		execute("select e1 from x order by e1", new List[] {Arrays.asList((String)null)}); //$NON-NLS-1$
-	}
-	
-	@Test public void testDelete1() throws Exception {
-		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
-		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("delete from x", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
-		execute("select e1 from x order by e1", new List[] {}); //$NON-NLS-1$
-	}
-
-}

Deleted: trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,771 +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;
-
-import static org.junit.Assert.*;
-
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-
-import org.junit.Test;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.buffer.impl.MemoryStorageManager;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.unittest.TimestampUtil;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.validator.TestValidator;
-
-public class TestVirtualDepJoin {
-    
-    /** 
-     * @param usAcctsElem
-     * @param is
-     * @param is2
-     * @param object
-     * @param object2
-     * @since 4.3
-     */
-    private static void setStats(List elementObjects,
-                                 int[] ndvs,
-                                 int[] nnvs,
-                                 String[] mins,
-                                 String[] maxs) {
-        
-        Iterator iter = elementObjects.iterator();
-        for(int i=0; iter.hasNext(); i++) {
-            FakeMetadataObject obj = (FakeMetadataObject) iter.next();
-            if(ndvs != null) {
-                obj.putProperty(FakeMetadataObject.Props.DISTINCT_VALUES, new Integer(ndvs[i]));
-            }
-            if(nnvs != null) {
-                obj.putProperty(FakeMetadataObject.Props.NULL_VALUES, new Integer(nnvs[i]));
-            }
-            if(mins != null) {
-                obj.putProperty(FakeMetadataObject.Props.MIN_VALUE, mins[i]);
-            }
-            if(maxs != null) {
-                obj.putProperty(FakeMetadataObject.Props.MAX_VALUE, maxs[i]);
-            }
-            
-        }
-    }
-    
-    public static FakeMetadataFacade exampleVirtualDepJoin() {
-        FakeMetadataObject us = FakeMetadataFactory.createPhysicalModel("US"); //$NON-NLS-1$
-        us.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
-        FakeMetadataObject usAccts = FakeMetadataFactory.createPhysicalGroup("US.Accounts", us); //$NON-NLS-1$
-        usAccts.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000000));
-        List usAcctsElem = FakeMetadataFactory.createElements(usAccts, 
-                                    new String[] { "customer", "account", "txn", "txnid", "pennies" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
-        setStats(usAcctsElem,
-                 new int[] { 1000, 1250, 4, 1000000, 800000}, // NDV per column
-                 new int[] { 0, 0, 0, 0, 0}, // NNV per column
-                 new String[] {"0", null, null, null, "-10"}, // min per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
-                 new String[] {"1000", null, null, null, "-5"}  // max per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
-        );
-
-        FakeMetadataObject europe = FakeMetadataFactory.createPhysicalModel("Europe"); //$NON-NLS-1$
-        europe.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
-        FakeMetadataObject euAccts = FakeMetadataFactory.createPhysicalGroup("Europe.CustAccts", europe); //$NON-NLS-1$
-        euAccts.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000000));
-        List euAcctsElem = FakeMetadataFactory.createElements(euAccts, 
-                                    new String[] { "id", "accid", "type", "amount" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.SHORT, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
-        setStats(euAcctsElem,
-                 new int[] { 10000, 1000000, 4, 1000000, 750000}, // NDV per column
-                 new int[] { 0, 0, 0, 0, 0}, // NNV per column
-                 null, // min per column - use defaults
-                 null  // max per column - use defaults
-        );
-
-        FakeMetadataObject cust = FakeMetadataFactory.createPhysicalModel("CustomerMaster"); //$NON-NLS-1$
-        cust.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
-        FakeMetadataObject customers = FakeMetadataFactory.createPhysicalGroup("CustomerMaster.Customers", cust); //$NON-NLS-1$
-        customers.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000));
-        List customersElem = FakeMetadataFactory.createElements(customers, 
-                                    new String[] { "id", "first", "last", "birthday" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.DATE });
-        setStats(customersElem,
-                 new int[] { 1000, 800, 800, 365}, // NDV per column
-                 new int[] { 0, 0, 0, 0}, // NNV per column
-                 null, // min per column - use defaults
-                 null  // max per column - use defaults
-        );
-        FakeMetadataObject locations = FakeMetadataFactory.createPhysicalGroup("CustomerMaster.Locations", cust); //$NON-NLS-1$
-        locations.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1200));
-        List locationsElem = FakeMetadataFactory.createElements(locations, 
-                                    new String[] { "id", "location" }, //$NON-NLS-1$ //$NON-NLS-2$ 
-                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING });
-        setStats(locationsElem,
-                 new int[] { 1000, 2}, // NDV per column
-                 new int[] { 0, 0, 0, 0}, // NNV per column
-                 null, // min per column - use defaults
-                 null  // max per column - use defaults
-        );
-
-        FakeMetadataObject vAccts = FakeMetadataFactory.createVirtualModel("Accounts"); //$NON-NLS-1$
-        QueryNode accountsPlan = new QueryNode("Accounts.Accounts", //$NON-NLS-1$
-                                               "SELECT customer as customer_id, convert(account, long) as account_id, convert(txnid, long) as transaction_id, case txn when 'DEP' then 1 when 'TFR' then 2 when 'WD' then 3 else -1 end as txn_type, (pennies + convert('0.00', bigdecimal)) / 100 as amount, 'US' as source FROM US.Accounts where txn != 'X'" +  //$NON-NLS-1$
-                                               "UNION ALL " +  //$NON-NLS-1$
-                                               "SELECT id, convert(accid / 10000, long), mod(accid, 10000), convert(type, integer), amount, 'EU' from Europe.CustAccts"); //$NON-NLS-1$ 
-        FakeMetadataObject accounts = FakeMetadataFactory.createVirtualGroup("Accounts.Accounts", vAccts, accountsPlan); //$NON-NLS-1$
-        List accountsElem = FakeMetadataFactory.createElements(accounts, 
-                                            new String[] { "customer_id", "account_id", "transaction_id", "txn_type", "amount", "source" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-                                            new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL, DataTypeManager.DefaultDataTypes.STRING });
-        
-        FakeMetadataObject master = FakeMetadataFactory.createVirtualModel("Master"); //$NON-NLS-1$
-        QueryNode masterPlan = new QueryNode("Master.Transactions", //$NON-NLS-1$
-                                               "select id as CustomerID, First, Last, a.account_id as AccountID, transaction_id as TransactionID, txn_type AS TxnCode, Amount from CustomerMaster.Customers c, Accounts.Accounts a where c.id=a.customer_id"); //$NON-NLS-1$ 
-        FakeMetadataObject transactions = FakeMetadataFactory.createVirtualGroup("Master.Transactions", master, masterPlan); //$NON-NLS-1$
-        List transactionsElem = FakeMetadataFactory.createElements(transactions, 
-                                            new String[] { "CustomerID", "First", "Last", "AccountID", "TransactionID", "TxnCode", "Amount" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-                                            new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
-        
-        FakeMetadataStore store = new FakeMetadataStore();
-        store.addObject(us);
-        store.addObject(usAccts);
-        store.addObjects(usAcctsElem);
-
-        store.addObject(europe);
-        store.addObject(euAccts);
-        store.addObjects(euAcctsElem);
-
-        store.addObject(cust);
-        store.addObject(customers);
-        store.addObjects(customersElem);
-        store.addObject(locations);
-        store.addObjects(locationsElem);
-        
-        store.addObject(vAccts);
-        store.addObject(accounts);
-        store.addObjects(accountsElem);
-
-        store.addObject(master);
-        store.addObject(transactions);
-        store.addObjects(transactionsElem);
-
-        return new FakeMetadataFacade(store);
-    }
-
-    @Test public void testVirtualDepJoinNoValues() throws Exception {  
-        // Create query  
-        String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first=-9999 group by c.id, first, last"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
- 
-        TestOptimizer.checkDependentJoinCount(plan, 1);
-        // Run query 
-        TestProcessor.helpProcess(plan, context, dataManager, expected); 
-
-        // Second query *will not be run* as no values were passed and dependent side has always false criteria
-        // So, the list should contain only the first query
-        assertEquals(3, dataManager.getQueries().size());       
-    }  
-    
-    public void helpTestVirtualDepJoinSourceSelection(boolean setPushdown) throws Exception {  
-        // Create query  
-        String sql = "select c.id as CustomerID, First, Last, a.account_id as AccountID, transaction_id as TransactionID, txn_type AS TxnCode, Amount, source from (CustomerMaster.Customers c join CustomerMaster.Locations l on c.id=l.id) join Accounts.Accounts a on c.id=a.customer_id and l.location=a.source where c.first='Miles' option makenotdep c, l"; //$NON-NLS-1$
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20"), "EU" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00"), "EU" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-        
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, setPushdown);    
-        finder.addCapabilities("US", caps); //$NON-NLS-1$
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
-         
-        // Check plan contents
-        int selectCount = !setPushdown ? 2 : 0;
-        int accessCount = setPushdown ? 2 : 4;
-        int depAccessCount = 4 - accessCount;
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            accessCount,      // Access
-            depAccessCount,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            2,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            3,      // Project
-            selectCount,      // Select
-            0,      // Sort
-            1       // UnionAll
-        });   
-                
-        // Run query 
-        TestProcessor.helpProcess(plan, context, dataManager, expected); 
-    }
-    
-    @Test public void testVirtualDepJoinSourceSelectionPushdown() throws Exception {
-        helpTestVirtualDepJoinSourceSelection(true);
-    }
-
-    @Test public void testVirtualDepJoinSourceSelectionNoPushdown() throws Exception {
-        helpTestVirtualDepJoinSourceSelection(false);
-    }
-
-    @Test public void testVirtualDepJoinPartialPushdown() throws Exception {  
-        // Create query  
-        String sql = "SELECT * from Master.Transactions where last = 'Davis'"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
-        BasicSourceCapabilities caps2 = TestOptimizer.getTypicalCapabilities();
-        caps2.setCapabilitySupport(Capability.CRITERIA_IN, false);    
-        finder.addCapabilities("US", caps1); //$NON-NLS-1$
-        finder.addCapabilities("Europe", caps2);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps1);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            2,      // Access
-            1,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            3,      // Project
-            1,      // Select
-            0,      // Sort
-            1       // UnionAll
-        });   
-        
-        TestOptimizer.checkDependentJoinCount(plan, 1);        
-        // Run query 
-        TestProcessor.helpProcess(plan, context, dataManager, expected); 
-    }    
-
-    @Test public void testVirtualDepJoinOverAggregates() throws Exception {  
-        // Create query  
-        String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first='Miles' group by c.id, first, last"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { "Miles", "Davis", new BigDecimal("1007.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            1,      // Access
-            1,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            3,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            0,      // Select
-            0,      // Sort
-            0       // UnionAll
-        });   
-        
-        TestOptimizer.checkDependentJoinCount(plan, 1);        
-        // Run query 
-        TestProcessor.helpProcess(plan, context, dataManager, expected); 
-        
-        List<String> expectedQueries = new ArrayList<String>(6);
-        for (int i = 0; i < 3; i++) {
-        	expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.first AS c_1, g_0.last AS c_2 FROM CustomerMaster.Customers AS g_0 WHERE g_0.first = 'Miles' ORDER BY c_0"); //$NON-NLS-1$
-        	expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.amount AS c_1 FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100 ORDER BY c_0"); //$NON-NLS-1$
-        }
-        
-        assertEquals(expectedQueries, dataManager.getQueries());
-    }    
-    
-    @Test public void testVirtualDepJoinSelects() throws Exception {
-        helpTestVirtualDepJoin(false);
-    }
-    
-    @Test public void testVirtualDepJoinPushdown() throws Exception {
-        helpTestVirtualDepJoin(true);
-    }
-    
-    @Test public void testVirtualDepMultipleDependentBatches() throws Exception {  
-        helpTestMultipleBatches(true);
-    }
-    
-    @Test public void testVirtualDepMultipleDependentBatchesNonUnique() throws Exception {  
-        helpTestMultipleBatches(false);
-    }
-
-    private void helpTestMultipleBatches(boolean unique) throws Exception,
-                                          MetaMatrixComponentException,
-                                          MetaMatrixException,
-                                          SQLException {
-        // Create query  
-        String sql = "SELECT * from Master.Transactions where last = 'Davis' order by CustomerID, TransactionID"; //$NON-NLS-1$ 
-         
-        List expected = new LinkedList();
-        
-        
-        // Create expected results 
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        }            
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        if (!unique) {
-            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        }
-        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(207), new Integer(3), new BigDecimal("12.34") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(299), new Integer(3), new BigDecimal("950.34") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1004), new Integer(3), new BigDecimal("542.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1005), new Integer(1), new BigDecimal("99.99") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1006), new Integer(1), new BigDecimal("10000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1007), new Integer(2), new BigDecimal("0.75") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(630), new Long(1008), new Integer(2), new BigDecimal("62.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager();
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-        overrideVirtualDepJoinData(dataManager, metadata, unique);
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
-        finder.addCapabilities("US", caps); //$NON-NLS-1$
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
- 
-        // Run query 
-        BufferManager bufferMgr = createCustomBufferMgr(2);
-        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
-        processor.setNonBlocking(true);
-        BatchCollector collector = processor.createBatchCollector();
-        TupleBuffer id = collector.collectTuples();
-
-        TestProcessor.examineResults((List[])expected.toArray(new List[expected.size()]), bufferMgr, id);
-    }
-
-    private BufferManager createCustomBufferMgr(int batchSize) throws MetaMatrixComponentException {
-        BufferManagerImpl bufferMgr = new BufferManagerImpl();
-        bufferMgr.setConnectorBatchSize(batchSize);
-        bufferMgr.setProcessorBatchSize(batchSize);
-        bufferMgr.initialize();
-
-        // Add unmanaged memory storage manager
-        bufferMgr.setStorageManager(new MemoryStorageManager());
-
-        return bufferMgr;
-    }
-
-    public void helpTestVirtualDepJoin(boolean pushCriteria) throws Exception {  
-        // Create query  
-        String sql = "SELECT * from Master.Transactions where last = 'Davis'"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.CRITERIA_IN, pushCriteria);    
-        finder.addCapabilities("US", caps); //$NON-NLS-1$
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder); 
- 
-        // Run query 
-        CommandContext context = TestProcessor.createCommandContext();
-        TestProcessor.helpProcess(plan, context, dataManager, expected); 
-    }
-    
-    private void sampleDataVirtualDepJoin(FakeDataManager dataMgr, FakeMetadataFacade metadata) throws Exception {
-        dataMgr.setBlockOnce();
-        // Group US.Accounts
-        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("US.Accounts"); //$NON-NLS-1$
-        List elementIDs = metadata.getElementIDsInGroupID(groupID);
-        List elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "DEP", new Integer(123), new Integer(10000) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "TFR", new Integer(127), new Integer(25000) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "WD", new Integer(128), new Integer(100000) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(100), new Integer(15001), "DEP", new Integer(134), new Integer(1000) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(100), new Integer(15001), "DEP", new Integer(201), new Integer(1000) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "WD", new Integer(207), new Integer(1234) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "WD", new Integer(299), new Integer(95034) }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "X", new Integer(301), new Integer(5000) }), //$NON-NLS-1$
-                } );    
-
-        // Group Europe.CustAccts
-        groupID = (FakeMetadataObject) metadata.getGroupID("Europe.CustAccts"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols,
-            
-            new List[] { 
-                Arrays.asList(new Object[] { new Long(100), new Long(5401002), new Short((short)1), new BigDecimal("7.20") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(100), new Long(5401003), new Short((short)2), new BigDecimal("1000.00") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(200), new Long(5501004), new Short((short)3), new BigDecimal("542.20") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(200), new Long(5501005), new Short((short)1), new BigDecimal("99.99") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(300), new Long(6201006), new Short((short)1), new BigDecimal("10000.00") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(300), new Long(6201007), new Short((short)2), new BigDecimal("0.75") }), //$NON-NLS-1$
-                Arrays.asList(new Object[] { new Long(300), new Long(6301008), new Short((short)2), new BigDecimal("62.00") }), //$NON-NLS-1$
-                } );    
-
-        // Group CustomerMaster.Customers
-        groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Customers"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        TimestampUtil ts = new TimestampUtil();
-        dataMgr.registerTuples(groupID, elementSymbols,                               
-                               new List[] { 
-                                   Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) }), //$NON-NLS-1$ //$NON-NLS-2$
-                                   Arrays.asList(new Object[] { new Long(200), "John", "Coltrane", ts.createDate(1926, 8, 23) }), //$NON-NLS-1$ //$NON-NLS-2$
-                                   Arrays.asList(new Object[] { new Long(300), "Thelonious", "Monk", ts.createDate(1917, 9, 10) }), //$NON-NLS-1$ //$NON-NLS-2$
-                                   } );    
-
-        // Group CustomerMaster.Locations
-        groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Locations"); //$NON-NLS-1$
-        elementIDs = metadata.getElementIDsInGroupID(groupID);
-        elementSymbols = FakeDataStore.createElements(elementIDs);
-    
-        dataMgr.registerTuples(groupID, elementSymbols,                               
-                               new List[] { 
-                                   Arrays.asList(new Object[] { new Long(100), "US" }), //$NON-NLS-1$ 
-                                   Arrays.asList(new Object[] { new Long(100), "EU" }), //$NON-NLS-1$ 
-                                   Arrays.asList(new Object[] { new Long(200), "US" }), //$NON-NLS-1$ 
-                                   Arrays.asList(new Object[] { new Long(200), "EU" }), //$NON-NLS-1$ 
-                                   Arrays.asList(new Object[] { new Long(300), "EU" }), //$NON-NLS-1$ 
-                                   } );        
-    }                    
-
-    private void overrideVirtualDepJoinData(FakeDataManager dataMgr, FakeMetadataFacade metadata, boolean unique) throws Exception {
-        // Group CustomerMaster.Customers
-        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Customers"); //$NON-NLS-1$
-        List elementIDs = metadata.getElementIDsInGroupID(groupID);
-        List elementSymbols = FakeDataStore.createElements(elementIDs);
-        
-        TimestampUtil ts = new TimestampUtil();
-        
-        List data = new LinkedList();
-        
-        data.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) })); //$NON-NLS-1$ //$NON-NLS-2$
-        if (!unique) {
-            data.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) })); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-        data.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", ts.createDate(1926, 4, 26) })); //$NON-NLS-1$ //$NON-NLS-2$
-        data.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", ts.createDate(1926, 4, 27) })); //$NON-NLS-1$ //$NON-NLS-2$
-        data.add(Arrays.asList(new Object[] { new Long(400), "CloneC", "Davis", ts.createDate(1926, 4, 28) })); //$NON-NLS-1$ //$NON-NLS-2$
-        
-        dataMgr.registerTuples(
-            groupID,
-            elementSymbols, (List[])data.toArray(new List[data.size()]));
-    }
-    
-    @Test public void testVirtualAccessVirtualDep() throws Exception {
-        String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
-        
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        finder.addCapabilities("test", caps); //$NON-NLS-1$
-        
-        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, finder, 
-                                                    new String[] {"SELECT g_0.e2 AS c_0 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2') ORDER BY c_0", //$NON-NLS-1$
-        														  "SELECT g_0.e0 AS c_0, g_0.e1 AS c_1, g_0.e0 AS c_2 FROM test.\"group\" AS g_0 WHERE (g_0.e0 IN (<dependent values>)) AND (g_0.e1 IN (<dependent values>)) ORDER BY c_2, c_1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
-        
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            1,      // Access
-            1,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            0,      // Select
-            0,      // Sort
-            0       // UnionAll
-        });
-    }
-    
-    /**
-     * Here the virtual makenotdep hint causes us to throw an exception 
-     *
-     */
-    @Test public void testVirtualAccessVirtualDep2() {
-        String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a makenotdep inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
-        
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        finder.addCapabilities("test", caps); //$NON-NLS-1$
-        
-        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, finder, 
-                                                    new String[] {}, TestOptimizer.SHOULD_FAIL);
-        
-    }
-    
-    /**
-     *  same as testVirtualDepJoinOverAggregate, but the makenotdep hint prevents the
-     *  dependent join from happening
-     */
-    @Test public void testVirtualDepJoinOverAggregates2() throws Exception {  
-        // Create query  
-        String sql = "select first, last, sum(amount) from Europe.CustAccts e makenotdep join CustomerMaster.Customers c on c.id=e.id where c.first='Miles' group by c.id, first, last"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { "Miles", "Davis", new BigDecimal("1007.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        sampleDataVirtualDepJoin(dataManager, metadata); 
-         
-        // Plan query 
-        CommandContext context = TestProcessor.createCommandContext();
-
-        Command command = TestProcessor.helpParse(sql);   
-        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
-        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
-        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
-        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
-        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            2,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            0,      // DupRemove
-            3,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            1,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            0,      // Select
-            0,      // Sort
-            0       // UnionAll
-        });   
-        
-        TestOptimizer.checkDependentJoinCount(plan, 0);        
-        // Run query 
-        TestProcessor.helpProcess(plan, context, dataManager, expected);         
-    }    
-
-    
-    @Test public void testVirtualMakeDepHint() throws Exception {  
-        // Create query  
-        String sql = "select distinct pm1.g1.e1 from (pm1.g1 inner join pm1.g2 on g1.e1 = g2.e1) makedep inner join pm2.g1 on pm2.g1.e1 = pm1.g1.e1 where pm2.g1.e3 = 1"; //$NON-NLS-1$ 
-         
-        // Create expected results 
-        List[] expected = new List[] {  
-                        Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
-                        Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
-                };     
-
-        // Construct data manager with data 
-        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();        
-        FakeDataManager dataManager = new FakeDataManager(); 
-        TestProcessor.sampleData1(dataManager); 
-         
-        // Plan query 
-        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata); 
- 
-        TestOptimizer.checkNodeTypes(plan, new int[] {
-            3,      // Access
-            0,      // DependentAccess
-            0,      // DependentSelect
-            0,      // DependentProject
-            1,      // DupRemove
-            0,      // Grouping
-            0,      // NestedLoopJoinStrategy
-            2,      // MergeJoinStrategy
-            0,      // Null
-            0,      // PlanExecution
-            1,      // Project
-            2,      // Select
-            0,      // Sort
-            0       // UnionAll
-        });   
-        
-        TestOptimizer.checkDependentJoinCount(plan, 1);        
-        // Run query 
-        TestProcessor.helpProcess(plan, new CommandContext(), dataManager, expected);         
-    }    
-
-    
-}

Copied: trunk/engine/src/test/java/org/teiid/cache (from rev 2112, trunk/engine/src/test/java/com/metamatrix/cache)

Modified: trunk/engine/src/test/java/org/teiid/cache/FakeCache.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/cache/FakeCache.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/cache/FakeCache.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.cache;
+package org.teiid.cache;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,6 +29,11 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.teiid.cache.Cache;
+import org.teiid.cache.CacheConfiguration;
+import org.teiid.cache.CacheFactory;
+import org.teiid.cache.CacheListener;
+
 public class FakeCache<K, V> implements Cache<K, V> {
 	
     public static class FakeCacheFactory implements CacheFactory{

Copied: trunk/engine/src/test/java/org/teiid/cdk (from rev 2112, trunk/engine/src/test/java/com/metamatrix/cdk)

Modified: trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/cdk/CommandBuilder.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/cdk/CommandBuilder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,26 +20,26 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.cdk;
+package org.teiid.cdk;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import org.teiid.connector.language.LanguageFactory;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
 import org.teiid.dqp.internal.datamgr.language.LanguageBridgeFactory;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.AliasGenerator;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.symbol.AllSymbol;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.relational.AliasGenerator;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.AllSymbol;
 
 /**
  * Convert a query string into a SQL language parse tree.
@@ -74,8 +74,8 @@
                 command.acceptVisitor(new AliasGenerator(supportsGroupAlias));
             }
             return new LanguageBridgeFactory(metadata).translate(command);
-        } catch (MetaMatrixException e) {
-            throw new MetaMatrixRuntimeException(e);
+        } catch (TeiidException e) {
+            throw new TeiidRuntimeException(e);
 		}
     }
     

Copied: trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/buffer/BufferManagerFactory.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/BufferManagerFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,73 @@
+/*
+ * 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 org.teiid.common.buffer;
+
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.core.TeiidComponentException;
+
+
+/**
+ * <p>Factory for BufferManager instances.  One method will get
+ * a server buffer manager, as it should be instantiated in a running
+ * MetaMatrix server.  That BufferManager is configured mostly by the
+ * passed in properties.</p>
+ *
+ * <p>The other method returns a stand-alone, in-memory buffer manager.  This
+ * is typically used for either in-memory testing or any time the
+ * query processor component is not expected to run out of memory, such as
+ * within the modeler.</p>
+ */
+public class BufferManagerFactory {
+	
+	private static BufferManager INSTANCE;
+	
+    /**
+     * Helper to get a buffer manager all set up for unmanaged standalone use.  This is
+     * typically used for testing or when memory is not an issue.
+     * @return BufferManager ready for use
+     */
+    public static BufferManager getStandaloneBufferManager() {
+    	if (INSTANCE == null) {
+	        BufferManagerImpl bufferMgr = createBufferManager();
+	        INSTANCE = bufferMgr;
+    	}
+
+        return INSTANCE;
+    }
+
+	public static BufferManagerImpl createBufferManager() {
+		BufferManagerImpl bufferMgr = new BufferManagerImpl();
+		try {
+			bufferMgr.initialize();
+		} catch (TeiidComponentException e) {
+			throw new RuntimeException(e);
+		}
+
+		// Add unmanaged memory storage manager
+		bufferMgr.setStorageManager(new MemoryStorageManager());
+		return bufferMgr;
+	}
+
+}

Copied: trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBatch.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBatch.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBatch.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBatch.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,58 @@
+/*
+ * 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 org.teiid.common.buffer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.common.buffer.TupleBatch;
+
+import junit.framework.TestCase;
+
+
+public class TestTupleBatch extends TestCase {
+
+    public TestTupleBatch(String name) {
+        super(name);
+    }
+
+    public TupleBatch exampleBatch(int rowBegin, int numRows, int numColumns) {
+        List rows = new ArrayList();
+        for(int i=0; i<numRows; i++) {
+            List row = new ArrayList();
+            for(int j=0; j<numColumns; j++) { 
+                row.add("data-" + (rowBegin + i) + "-" + j); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            rows.add(row);    
+        }            
+        return new TupleBatch(rowBegin, rows);
+    }
+
+    /*
+     * Test for void TupleBatch(int, List)
+     */
+    public void testTupleBatch() {
+        exampleBatch(0, 10, 2);        
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/buffer/TestTupleBuffer.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,88 @@
+/*
+ * 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 org.teiid.common.buffer;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.common.buffer.BatchManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
+
+public class TestTupleBuffer {
+
+	@Test public void testForwardOnly() throws Exception {
+		ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
+		x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+		List<ElementSymbol> schema = Arrays.asList(x);
+		TupleBuffer tb = new TupleBuffer(new BatchManager() {
+			
+			@Override
+			public void remove() {
+				
+			}
+			
+			@Override
+			public ManagedBatch createManagedBatch(final TupleBatch batch)
+					throws TeiidComponentException {
+				return new ManagedBatch() {
+					
+					@Override
+					public void remove() {
+						
+					}
+					
+					@Override
+					public TupleBatch getBatch(boolean cache, String[] types)
+							throws TeiidComponentException {
+						return batch;
+					}
+				};
+			}
+		}, "x", schema, 32); //$NON-NLS-1$ 
+		tb.setForwardOnly(true);
+		tb.addTuple(Arrays.asList(1));
+		TupleBatch batch = tb.getBatch(1);
+		assertTrue(!batch.getTerminationFlag());
+		assertEquals(1, batch.getBeginRow());
+		try {
+			tb.getBatch(1);
+			fail("expected exception"); //$NON-NLS-1$
+		} catch (AssertionError e) {
+			
+		}
+		tb.addTuple(Arrays.asList(1));
+		tb.close();
+		batch = tb.getBatch(2);
+		assertTrue(batch.getTerminationFlag());
+		assertEquals(2, batch.getBeginRow());
+	}
+	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/common/buffer/TestTupleBuffer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/common/buffer/impl (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/buffer/impl)

Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/buffer/impl/TestFileStorageManager.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.common.buffer.impl;
+package org.teiid.common.buffer.impl;
 
 import static org.junit.Assert.*;
 
@@ -31,15 +31,16 @@
 import java.util.Random;
 
 import org.junit.Test;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.FileStore;
-import com.metamatrix.common.buffer.StorageManager;
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestFileStorageManager {
 		
-	public FileStorageManager getStorageManager(Integer maxFileSize, Integer openFiles, String dir) throws MetaMatrixComponentException {
+	public FileStorageManager getStorageManager(Integer maxFileSize, Integer openFiles, String dir) throws TeiidComponentException {
         FileStorageManager sm = new FileStorageManager();
         sm.setStorageDirectory(UnitTestUtil.getTestScratchPath() + (dir != null ? File.separator + dir : "")); //$NON-NLS-1$
         if (maxFileSize != null) {
@@ -84,7 +85,7 @@
     static Random r = new Random();
     
 	private void writeBytes(FileStore store)
-			throws MetaMatrixComponentException {
+			throws TeiidComponentException {
 		byte[] bytes = new byte[2048];
         r.nextBytes(bytes);
         long start = store.write(bytes, 0, bytes.length);

Copied: trunk/engine/src/test/java/org/teiid/common/log (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/log)

Copied: trunk/engine/src/test/java/org/teiid/common/queue (from rev 2112, trunk/engine/src/test/java/com/metamatrix/common/queue)

Modified: trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkItem.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/queue/FakeWorkItem.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkItem.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.common.queue;
+package org.teiid.common.queue;
 
 import java.sql.Timestamp;
 

Modified: trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/queue/FakeWorkManager.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/common/queue/FakeWorkManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,4 +1,4 @@
-package com.metamatrix.common.queue;
+package org.teiid.common.queue;
 
 import javax.resource.spi.work.ExecutionContext;
 import javax.resource.spi.work.Work;

Modified: trunk/engine/src/test/java/org/teiid/common/queue/TestStatsCapturingWorkManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/queue/TestStatsCapturingWorkManager.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/common/queue/TestStatsCapturingWorkManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.common.queue;
+package org.teiid.common.queue;
 
 import static org.junit.Assert.*;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestDQPContextCache.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,10 +23,10 @@
 
 import junit.framework.TestCase;
 
+import org.teiid.cache.Cache;
+import org.teiid.cache.FakeCache.FakeCacheFactory;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 
-import com.metamatrix.cache.Cache;
-import com.metamatrix.cache.FakeCache.FakeCacheFactory;
 
 
 public class TestDQPContextCache extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeTransactionService.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeTransactionService.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/FakeTransactionService.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,10 +25,10 @@
 import javax.resource.spi.XATerminator;
 import javax.transaction.TransactionManager;
 
+import org.teiid.common.queue.FakeWorkManager;
+import org.teiid.core.util.SimpleMock;
 import org.teiid.dqp.internal.transaction.TransactionServerImpl;
 
-import com.metamatrix.common.queue.FakeWorkManager;
-import com.metamatrix.core.util.SimpleMock;
 
 public class FakeTransactionService extends TransactionServerImpl {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorManager.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,13 +29,13 @@
 import junit.framework.TestCase;
 
 import org.mockito.Mockito;
+import org.teiid.common.buffer.BlockedException;
 import org.teiid.dqp.internal.process.AbstractWorkItem;
+import org.teiid.dqp.message.AtomicRequestID;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.RequestID;
 import org.teiid.resource.cci.ExecutionFactory;
 
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.dqp.message.AtomicRequestID;
-import com.metamatrix.dqp.message.AtomicRequestMessage;
-import com.metamatrix.dqp.message.RequestID;
 
 /**
  * JUnit test for TestConnectorStateManager

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorWorkItem.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorWorkItem.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestConnectorWorkItem.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -38,20 +38,20 @@
 import org.teiid.dqp.internal.datamgr.language.LanguageBridgeFactory;
 import org.teiid.dqp.internal.process.AbstractWorkItem;
 import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.AtomicResultsMessage;
+import org.teiid.dqp.message.RequestID;
+import org.teiid.dqp.service.TransactionContext;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.FakeMetadataFactory;
 import org.teiid.resource.ConnectorException;
 import org.teiid.resource.cci.ProcedureExecution;
 
-import com.metamatrix.dqp.message.AtomicRequestMessage;
-import com.metamatrix.dqp.message.AtomicResultsMessage;
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.dqp.service.TransactionContext;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestConnectorWorkItem {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestExecutionContextImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestExecutionContextImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/impl/TestExecutionContextImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,9 +22,9 @@
 
 package org.teiid.dqp.internal.datamgr.impl;
 
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.dqp.internal.datamgr.impl.ExecutionContextImpl;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,10 +27,10 @@
 import org.teiid.connector.language.AggregateFunction;
 import org.teiid.connector.language.Literal;
 import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.Constant;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
 
 public class TestAggregateImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestBatchedUpdatesImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestBatchedUpdatesImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestBatchedUpdatesImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,10 +29,10 @@
 import org.teiid.connector.language.Delete;
 import org.teiid.connector.language.Insert;
 import org.teiid.connector.language.Update;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompareCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompareCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompareCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,9 +27,9 @@
 import org.teiid.connector.language.Comparison;
 import org.teiid.connector.language.Literal;
 import org.teiid.connector.language.Comparison.Operator;
+import org.teiid.query.sql.lang.AbstractCompareCriteria;
+import org.teiid.query.sql.symbol.Constant;
 
-import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
 
 public class TestCompareCriteriaImpl extends TestCase {
 
@@ -41,10 +41,10 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.CompareCriteria helpExample(int operator, int leftVal, int rightVal) {
+    public static org.teiid.query.sql.lang.CompareCriteria helpExample(int operator, int leftVal, int rightVal) {
         Constant left = new Constant(new Integer(leftVal));
         Constant right = new Constant(new Integer(rightVal));
-        return new com.metamatrix.query.sql.lang.CompareCriteria(left, operator, right);
+        return new org.teiid.query.sql.lang.CompareCriteria(left, operator, right);
     }
     
     public static Comparison example(int operator, int leftVal, int rightVal) throws Exception {

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompoundCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompoundCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestCompoundCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,8 +27,8 @@
 import org.teiid.connector.language.AndOr;
 import org.teiid.connector.language.Comparison;
 import org.teiid.connector.language.AndOr.Operator;
+import org.teiid.query.sql.lang.CompareCriteria;
 
-import com.metamatrix.query.sql.lang.CompareCriteria;
 
 public class TestCompoundCriteriaImpl extends TestCase {
 
@@ -40,10 +40,10 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.CompoundCriteria helpExample(int operator) {
+    public static org.teiid.query.sql.lang.CompoundCriteria helpExample(int operator) {
         CompareCriteria c1 = TestCompareCriteriaImpl.helpExample(CompareCriteria.GE, 100, 200);
         CompareCriteria c2 = TestCompareCriteriaImpl.helpExample(CompareCriteria.LT, 500, 600);
-        return new com.metamatrix.query.sql.lang.CompoundCriteria(operator, c1, c2);
+        return new org.teiid.query.sql.lang.CompoundCriteria(operator, c1, c2);
     }
     
     public static AndOr example(int operator) throws Exception {
@@ -51,12 +51,12 @@
     }
 
     public void testGetOperator() throws Exception {
-        assertEquals(Operator.AND, example(com.metamatrix.query.sql.lang.CompoundCriteria.AND).getOperator());
-        assertEquals(Operator.OR, example(com.metamatrix.query.sql.lang.CompoundCriteria.OR).getOperator());
+        assertEquals(Operator.AND, example(org.teiid.query.sql.lang.CompoundCriteria.AND).getOperator());
+        assertEquals(Operator.OR, example(org.teiid.query.sql.lang.CompoundCriteria.OR).getOperator());
     }
 
     public void testGetCriteria() throws Exception {
-        AndOr cc = example(com.metamatrix.query.sql.lang.CompoundCriteria.AND);
+        AndOr cc = example(org.teiid.query.sql.lang.CompoundCriteria.AND);
         assertTrue(cc.getLeftCondition() instanceof Comparison);
         assertTrue(cc.getRightCondition() instanceof Comparison);
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestDeleteImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestDeleteImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestDeleteImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,8 +26,8 @@
 import junit.framework.TestCase;
 
 import org.teiid.connector.language.Delete;
+import org.teiid.query.sql.lang.CompoundCriteria;
 
-import com.metamatrix.query.sql.lang.CompoundCriteria;
 
 public class TestDeleteImpl extends TestCase {
 
@@ -39,8 +39,8 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.Delete helpExample() {
-        return new com.metamatrix.query.sql.lang.Delete(TestGroupImpl.helpExample("vm1.g1"), //$NON-NLS-1$
+    public static org.teiid.query.sql.lang.Delete helpExample() {
+        return new org.teiid.query.sql.lang.Delete(TestGroupImpl.helpExample("vm1.g1"), //$NON-NLS-1$
                           TestCompoundCriteriaImpl.helpExample(CompoundCriteria.AND));
     }
     

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestElementImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestElementImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestElementImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,9 +26,9 @@
 
 import org.teiid.connector.language.ColumnReference;
 import org.teiid.connector.language.NamedTable;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataObject;
 
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 public class TestElementImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestExistsCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestExistsCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestExistsCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,8 +24,8 @@
 
 
 import org.teiid.connector.language.Exists;
+import org.teiid.query.sql.lang.ExistsCriteria;
 
-import com.metamatrix.query.sql.lang.ExistsCriteria;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestFunctionImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestFunctionImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestFunctionImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 
 import org.teiid.connector.language.Expression;
 import org.teiid.connector.language.Function;
+import org.teiid.query.sql.symbol.Constant;
 
-import com.metamatrix.query.sql.symbol.Constant;
 
 public class TestFunctionImpl extends TestCase {
 
@@ -41,10 +41,10 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.symbol.Function helpExample(String name) {
+    public static org.teiid.query.sql.symbol.Function helpExample(String name) {
         Constant c1 = new Constant(new Integer(100));
         Constant c2 = new Constant(new Integer(200));
-        com.metamatrix.query.sql.symbol.Function f = new com.metamatrix.query.sql.symbol.Function(name, new com.metamatrix.query.sql.symbol.Expression[] {c1, c2});
+        org.teiid.query.sql.symbol.Function f = new org.teiid.query.sql.symbol.Function(name, new org.teiid.query.sql.symbol.Expression[] {c1, c2});
         f.setType(Integer.class);
         return f;
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupByImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupByImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupByImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,10 +30,10 @@
 
 import org.teiid.connector.language.ColumnReference;
 import org.teiid.connector.language.GroupBy;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
 
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
 
 public class TestGroupByImpl extends TestCase {
 
@@ -45,16 +45,16 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.GroupBy helpExample() {
+    public static org.teiid.query.sql.lang.GroupBy helpExample() {
         List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e1")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e2")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e3")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e4")); //$NON-NLS-1$ //$NON-NLS-2$
-        return new com.metamatrix.query.sql.lang.GroupBy(symbols);
+        return new org.teiid.query.sql.lang.GroupBy(symbols);
     }
 
-    public static com.metamatrix.query.sql.lang.GroupBy helpExampleWithFunctions() {
+    public static org.teiid.query.sql.lang.GroupBy helpExampleWithFunctions() {
         List<Expression> symbols = new ArrayList<Expression>();
         
         ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1");//$NON-NLS-1$ //$NON-NLS-2$
@@ -62,7 +62,7 @@
         
         symbols.add(e1); 
         symbols.add(f);
-        return new com.metamatrix.query.sql.lang.GroupBy(symbols);
+        return new org.teiid.query.sql.lang.GroupBy(symbols);
     }
     
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestGroupImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,11 +24,11 @@
 
 
 import org.teiid.connector.language.NamedTable;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataObject;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 public class TestGroupImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,8 +29,8 @@
 import org.teiid.connector.language.Expression;
 import org.teiid.connector.language.Literal;
 import org.teiid.connector.language.In;
+import org.teiid.query.sql.lang.SetCriteria;
 
-import com.metamatrix.query.sql.lang.SetCriteria;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInlineViewImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInlineViewImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInlineViewImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,8 +24,8 @@
 
 
 import org.teiid.connector.language.DerivedTable;
+import org.teiid.query.sql.lang.SubqueryFromClause;
 
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInsertImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInsertImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestInsertImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,10 +31,10 @@
 import org.teiid.connector.language.Expression;
 import org.teiid.connector.language.ExpressionValueSource;
 import org.teiid.connector.language.Insert;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
 
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestInsertImpl extends TestCase {
 
@@ -46,7 +46,7 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.Insert helpExample(String groupName) {
+    public static org.teiid.query.sql.lang.Insert helpExample(String groupName) {
         GroupSymbol group = TestGroupImpl.helpExample(groupName);
         ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
         elements.add(TestElementImpl.helpExample(groupName, "e1")); //$NON-NLS-1$
@@ -60,12 +60,12 @@
         values.add(TestLiteralImpl.helpExample(3));
         values.add(TestLiteralImpl.helpExample(4));
         
-        return new com.metamatrix.query.sql.lang.Insert(group,
+        return new org.teiid.query.sql.lang.Insert(group,
                           elements,
                           values);
     }
     
-    public static com.metamatrix.query.sql.lang.Insert helpExample2(String groupName) {
+    public static org.teiid.query.sql.lang.Insert helpExample2(String groupName) {
         GroupSymbol group = TestGroupImpl.helpExample(groupName);
         ArrayList elements = new ArrayList();
         elements.add(TestElementImpl.helpExample(groupName, "e1")); //$NON-NLS-1$
@@ -73,7 +73,7 @@
         ArrayList values = new ArrayList();
         values.add(TestSearchedCaseExpressionImpl.helpExample());
         
-        return new com.metamatrix.query.sql.lang.Insert(group,
+        return new org.teiid.query.sql.lang.Insert(group,
                           elements,
                           values);
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestIsNullCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestIsNullCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestIsNullCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,8 +24,8 @@
 
 
 import org.teiid.connector.language.IsNull;
+import org.teiid.query.sql.lang.IsNullCriteria;
 
-import com.metamatrix.query.sql.lang.IsNullCriteria;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestJoinImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestJoinImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestJoinImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,12 +28,12 @@
 
 import org.teiid.connector.language.Comparison;
 import org.teiid.connector.language.Join;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 public class TestJoinImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLikeCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLikeCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLikeCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,10 +24,10 @@
 
 import org.teiid.connector.language.Literal;
 import org.teiid.connector.language.Like;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLiteralImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLiteralImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestLiteralImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,8 +24,8 @@
 
 
 import org.teiid.connector.language.Literal;
+import org.teiid.query.sql.symbol.Constant;
 
-import com.metamatrix.query.sql.symbol.Constant;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestNotCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestNotCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestNotCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,9 +24,9 @@
 
 
 import org.teiid.connector.language.Not;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.NotCriteria;
 
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.NotCriteria;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestOrderByImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestOrderByImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestOrderByImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -41,7 +41,7 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.lang.OrderBy helpExample() {
+    public static org.teiid.query.sql.lang.OrderBy helpExample() {
         ArrayList elements = new ArrayList();
         elements.add(TestElementImpl.helpExample("vm1.g1", "e1")); //$NON-NLS-1$ //$NON-NLS-2$
         elements.add(TestElementImpl.helpExample("vm1.g1", "e2")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -53,7 +53,7 @@
         types.add(Boolean.FALSE);
         types.add(Boolean.TRUE);
         types.add(Boolean.FALSE);
-        return new com.metamatrix.query.sql.lang.OrderBy(elements, types);
+        return new org.teiid.query.sql.lang.OrderBy(elements, types);
     }
     
     public static OrderBy example() throws Exception {

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestProcedureImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestProcedureImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestProcedureImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,11 +25,11 @@
 import junit.framework.TestCase;
 
 import org.teiid.connector.language.Call;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.StoredProcedure;
 
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.StoredProcedure;
 
 public class TestProcedureImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestQueryImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestQueryImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestQueryImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,12 +31,12 @@
 
 import org.teiid.connector.language.DerivedColumn;
 import org.teiid.connector.language.Select;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.core.util.EquivalenceUtil;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 public class TestQueryImpl extends TestCase {
 
@@ -48,13 +48,13 @@
         super(name);
     }
     
-    public static com.metamatrix.query.sql.lang.Select helpExampleSelect(boolean distinct) {
+    public static org.teiid.query.sql.lang.Select helpExampleSelect(boolean distinct) {
         ArrayList<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e1")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e2")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e3")); //$NON-NLS-1$ //$NON-NLS-2$
         symbols.add(TestElementImpl.helpExample("vm1.g1", "e4")); //$NON-NLS-1$ //$NON-NLS-2$
-        com.metamatrix.query.sql.lang.Select sel = new com.metamatrix.query.sql.lang.Select(symbols);
+        org.teiid.query.sql.lang.Select sel = new org.teiid.query.sql.lang.Select(symbols);
         sel.setDistinct(distinct);
         return sel;
     }
@@ -109,13 +109,13 @@
         assertTrue(EquivalenceUtil.areEquivalent(expected, types));
     }
 
-	public static com.metamatrix.query.sql.lang.From helpExampleFrom() {
+	public static org.teiid.query.sql.lang.From helpExampleFrom() {
 	    List<UnaryFromClause> clauses = new ArrayList<UnaryFromClause>();
 	    clauses.add(new UnaryFromClause(TestGroupImpl.helpExample("vm1.g1"))); //$NON-NLS-1$
 	    clauses.add(new UnaryFromClause(TestGroupImpl.helpExample("myAlias", "vm1.g2"))); //$NON-NLS-1$ //$NON-NLS-2$
 	    clauses.add(new UnaryFromClause(TestGroupImpl.helpExample("vm1.g3"))); //$NON-NLS-1$
 	    clauses.add(new UnaryFromClause(TestGroupImpl.helpExample("vm1.g4"))); //$NON-NLS-1$
-	    return new com.metamatrix.query.sql.lang.From(clauses);
+	    return new org.teiid.query.sql.lang.From(clauses);
 	}
 	
     public void testGetSelectSymbols() throws Exception {

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestScalarSubqueryImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestScalarSubqueryImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestScalarSubqueryImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,9 +26,9 @@
 
 import org.teiid.connector.language.Select;
 import org.teiid.connector.language.ScalarSubquery;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
 
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 
 /**
  */
@@ -42,9 +42,9 @@
         super(name);
     }
 
-    public static com.metamatrix.query.sql.symbol.ScalarSubquery helpExample() {
+    public static org.teiid.query.sql.symbol.ScalarSubquery helpExample() {
         Query query = TestQueryImpl.helpExample(true);
-        com.metamatrix.query.sql.symbol.ScalarSubquery ss = new com.metamatrix.query.sql.symbol.ScalarSubquery(query);
+        org.teiid.query.sql.symbol.ScalarSubquery ss = new org.teiid.query.sql.symbol.ScalarSubquery(query);
         ss.setType(((SingleElementSymbol)query.getProjectedSymbols().get(0)).getType());
         return ss;
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSearchedCaseExpressionImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSearchedCaseExpressionImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSearchedCaseExpressionImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,13 +26,13 @@
 import java.util.List;
 
 import org.teiid.connector.language.SearchedCase;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.TestCaseExpression;
 
 
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.TestCaseExpression;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSelectSymbolImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSelectSymbolImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSelectSymbolImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,8 +26,8 @@
 
 import org.teiid.connector.language.ColumnReference;
 import org.teiid.connector.language.DerivedColumn;
+import org.teiid.core.types.DataTypeManager;
 
-import com.metamatrix.common.types.DataTypeManager;
 
 public class TestSelectSymbolImpl extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSetQueryImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSetQueryImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSetQueryImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -35,9 +35,9 @@
 import org.teiid.connector.language.SetQuery;
 import org.teiid.connector.language.SortSpecification;
 import org.teiid.connector.language.SortSpecification.Ordering;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.lang.SetQuery.Operation;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
 
 
 /** 
@@ -45,8 +45,8 @@
  */
 public class TestSetQueryImpl extends TestCase {
 
-    public static com.metamatrix.query.sql.lang.SetQuery helpExampleSetQuery() {
-        com.metamatrix.query.sql.lang.SetQuery setQuery = new com.metamatrix.query.sql.lang.SetQuery(Operation.UNION);
+    public static org.teiid.query.sql.lang.SetQuery helpExampleSetQuery() {
+        org.teiid.query.sql.lang.SetQuery setQuery = new org.teiid.query.sql.lang.SetQuery(Operation.UNION);
         setQuery.setAll(false);
         setQuery.setLeftQuery(TestQueryImpl.helpExample(true));
         setQuery.setRightQuery(TestQueryImpl.helpExample(true));
@@ -101,7 +101,7 @@
     }
     
     public void testNestedSetQuery() throws Exception {
-        com.metamatrix.query.sql.lang.SetQuery query = new com.metamatrix.query.sql.lang.SetQuery(com.metamatrix.query.sql.lang.SetQuery.Operation.EXCEPT, true, helpExampleSetQuery(), helpExampleSetQuery());
+        org.teiid.query.sql.lang.SetQuery query = new org.teiid.query.sql.lang.SetQuery(org.teiid.query.sql.lang.SetQuery.Operation.EXCEPT, true, helpExampleSetQuery(), helpExampleSetQuery());
         
         SetQuery setQuery = TstLanguageBridgeFactory.factory.translate(query);
         assertTrue(setQuery.getLeftQuery() instanceof SetQuery);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryCompareCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryCompareCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryCompareCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,11 +27,11 @@
 import org.teiid.connector.language.Comparison;
 import org.teiid.connector.language.SubqueryComparison;
 import org.teiid.connector.language.SubqueryComparison.Quantifier;
+import org.teiid.query.sql.lang.AbstractCompareCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SubqueryCompareCriteria;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryInCriteriaImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryInCriteriaImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestSubqueryInCriteriaImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,12 +24,12 @@
 
 
 import org.teiid.connector.language.SubqueryIn;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestUpdateImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestUpdateImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestUpdateImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,10 +27,10 @@
 import junit.framework.TestCase;
 
 import org.teiid.connector.language.Update;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.GroupSymbol;
 
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestUpdateImpl extends TestCase {
 
@@ -42,9 +42,9 @@
         super(name);
     }
     
-    public static com.metamatrix.query.sql.lang.Update helpExample() {
+    public static org.teiid.query.sql.lang.Update helpExample() {
         GroupSymbol group = TestGroupImpl.helpExample("vm1.g1"); //$NON-NLS-1$
-        com.metamatrix.query.sql.lang.Update result = new com.metamatrix.query.sql.lang.Update();
+        org.teiid.query.sql.lang.Update result = new org.teiid.query.sql.lang.Update();
         result.setGroup(group);
         result.addChange(TestElementImpl.helpExample("vm1.g1", "e1"), new Constant(new Integer(1)));
         result.addChange(TestElementImpl.helpExample("vm1.g1", "e2"), new Constant(new Integer(1)));

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TstLanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TstLanguageBridgeFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TstLanguageBridgeFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,9 +23,9 @@
 package org.teiid.dqp.internal.datamgr.language;
 
 import org.teiid.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TstLanguageBridgeFactory {
     

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/metadata/TestMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/metadata/TestMetadataFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/metadata/TestMetadataFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,13 +26,14 @@
 
 import java.util.List;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
 
 public class TestMetadataFactory  extends TestCase {
     private RuntimeMetadataImpl metadataFactory;

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestByteLobChunkStream.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestByteLobChunkStream.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestByteLobChunkStream.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,10 +26,10 @@
 import java.util.Arrays;
 
 import org.teiid.client.lob.LobChunkInputStream;
+import org.teiid.core.util.ObjectConverterUtil;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.ObjectConverterUtil;
 
 public class TestByteLobChunkStream extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCallableStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCallableStatement.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCallableStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,11 +27,12 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.query.processor.HardcodedDataManager;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestCallableStatement extends TestCase {
 	

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestCodeTableCache.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,15 +25,15 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
 import org.teiid.dqp.internal.process.CodeTableCache;
 import org.teiid.dqp.internal.process.CodeTableCache.CacheKey;
 import org.teiid.dqp.internal.process.CodeTableCache.CacheState;
+import org.teiid.query.util.CommandContext;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  */
@@ -70,7 +70,7 @@
 		
 		try {
 			ctc.loadTable(nodeId, results);
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			throw new RuntimeException(e);
 		}
 		ctc.markCacheDone(nodeId, setDone);
@@ -91,7 +91,7 @@
 		
 		try {
 			ctc.loadTable(nodeId, results);
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			throw new RuntimeException(e);
 		}
 		ctc.markCacheDone(nodeId, true);
@@ -179,7 +179,7 @@
         try {
             ctc.lookupValue("countrycode", "code", "country", "US", TEST_CONTEXT); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
             fail("Expected exception during lookup"); //$NON-NLS-1$
-        } catch(MetaMatrixComponentException e) {
+        } catch(TeiidComponentException e) {
             // expected this
         }
     }
@@ -205,7 +205,7 @@
 		try {
 			ctc.loadTable(nodeId, results);
 			fail("expected exception"); //$NON-NLS-1$
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			assertEquals("Duplicate code table 'table' key 'value' value '1'", e.getMessage()); //$NON-NLS-1$
 		}
     }
@@ -223,7 +223,7 @@
 		try {
 			ctc.loadTable(nodeId, results);
 			fail("expected exception"); //$NON-NLS-1$
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			assertEquals("Error Code:ERR.018.005.0100 Message:Unable to load code table for because result sizes exceeds the allowed parameter - maxCodeTableRecords.", e.getMessage()); //$NON-NLS-1$
 		}
     }
@@ -241,7 +241,7 @@
 		try {
 			ctc.loadTable(nodeId, results);
 			fail("expected exception"); //$NON-NLS-1$
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			assertEquals("Error Code:ERR.018.005.0100 Message:Unable to load code table for because result sizes exceeds the allowed parameter - maxCodeTables.", e.getMessage()); //$NON-NLS-1$
 		}
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestConnectorCapabilitiesFinder.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestConnectorCapabilitiesFinder.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestConnectorCapabilitiesFinder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,9 +31,9 @@
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManager;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
 
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -33,16 +33,16 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.client.RequestMessage;
 import org.teiid.client.ResultsMessage;
+import org.teiid.common.queue.FakeWorkManager;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
+import org.teiid.dqp.service.AutoGenDataService;
+import org.teiid.dqp.service.FakeBufferService;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.queue.FakeWorkManager;
-import com.metamatrix.dqp.service.AutoGenDataService;
-import com.metamatrix.dqp.service.FakeBufferService;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestDQPCore {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,13 +32,13 @@
 import org.teiid.client.RequestMessage;
 import org.teiid.client.SourceWarning;
 import org.teiid.client.security.SessionToken;
+import org.teiid.core.TeiidException;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
 import org.teiid.dqp.internal.process.DQPCore.ClientState;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.RequestID;
+import org.teiid.query.sql.lang.Command;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.dqp.message.AtomicRequestMessage;
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.query.sql.lang.Command;
 
 /**
  */
@@ -107,7 +107,7 @@
     }
     
     private SourceWarning getSourceFailures(String model, String binding, String message) {
-    	return new SourceWarning(model, binding, new MetaMatrixException(message), true);
+    	return new SourceWarning(model, binding, new TeiidException(message), true);
     }
         
     public void testAddRequest() {

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPWorkContext.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,9 +22,10 @@
 
 package org.teiid.dqp.internal.process;
 
+import org.teiid.core.util.UnitTestUtil;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestDQPWorkContext extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,22 +26,22 @@
 
 import org.mockito.Mockito;
 import org.teiid.client.RequestMessage;
+import org.teiid.core.TeiidException;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.RequestID;
+import org.teiid.dqp.service.AutoGenDataService;
+import org.teiid.dqp.service.FakeBufferService;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.dynamic.SimpleQueryProcessorFactory;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.dqp.message.AtomicRequestMessage;
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.dqp.service.AutoGenDataService;
-import com.metamatrix.dqp.service.FakeBufferService;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.dynamic.SimpleQueryProcessorFactory;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 
 public class TestDataTierManager extends TestCase {
@@ -125,7 +125,7 @@
         try {
             dtm.lookupCodeValue(context, "BQT1.SmallA", "IntKey", "StringKey", "49");  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
             fail("processor should have failed"); //$NON-NLS-1$
-        } catch (MetaMatrixException e) {
+        } catch (TeiidException e) {
             assertEquals("Connector Exception", e.getMessage()); //$NON-NLS-1$
         }
     }

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -33,16 +33,16 @@
 import org.teiid.client.RequestMessage;
 import org.teiid.client.metadata.MetadataResult;
 import org.teiid.client.metadata.ResultsMetadataConstants;
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
+import org.teiid.dqp.message.RequestID;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedPlanCache.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,15 +28,15 @@
 
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.parser.ParseInfo;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.relational.ProjectNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.lang.Command;
 
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.parser.ParseInfo;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.relational.ProjectNode;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.sql.lang.Command;
 
 public class TestPreparedPlanCache {
     private static final String EXAMPLE_QUERY = "SELECT * FROM table"; //$NON-NLS-1$

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,31 +31,31 @@
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.api.exception.query.QueryValidatorException;
 import org.teiid.client.RequestMessage;
 import org.teiid.client.RequestMessage.StatementType;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
+import org.teiid.dqp.service.AutoGenDataService;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.dqp.service.AutoGenDataService;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestPreparedStatement {
 	
@@ -207,13 +207,13 @@
     }
     
 	static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values, SessionAwareCache<PreparedPlan> prepPlanCache)
-			throws MetaMatrixComponentException, MetaMatrixProcessingException {    	
+			throws TeiidComponentException, TeiidProcessingException {    	
 		return helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), prepPlanCache, SESSION_ID, false, false, FakeMetadataFactory.example1VDB());
     }
 	
 	static public PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
 			SessionAwareCache<PreparedPlan> prepPlanCache, int conn)
-			throws MetaMatrixComponentException, MetaMatrixProcessingException {
+			throws TeiidComponentException, TeiidProcessingException {
 		return helpGetProcessorPlan(preparedSql, values,
 				new DefaultCapabilitiesFinder(), FakeMetadataFactory
 						.example1Cached(), prepPlanCache, conn, false, false, FakeMetadataFactory.example1VDB());
@@ -221,7 +221,7 @@
 
 	static PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List values,
 			CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, int conn, boolean callableStatement, boolean limitResults, VDBMetaData vdb)
-			throws MetaMatrixComponentException, MetaMatrixProcessingException {
+			throws TeiidComponentException, TeiidProcessingException {
         
         //Create Request
         RequestMessage request = new RequestMessage(preparedSql);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,16 +29,16 @@
 import java.util.List;
 
 import org.junit.Test;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.HardcodedDataManager;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 /**
  * JUnit TestCase to test planning and caching of <code>PreparedStatement</code>

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,21 +30,21 @@
 import org.mockito.Mockito;
 import org.teiid.client.RequestMessage;
 import org.teiid.client.RequestMessage.StatementType;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
+import org.teiid.dqp.service.AutoGenDataService;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.ContextProperties;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.dqp.service.AutoGenDataService;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.ContextProperties;
 
 
 /** 
@@ -125,8 +125,8 @@
         assertEquals("1", request.context.getEnvironmentProperties().get(ContextProperties.SESSION_ID)); //$NON-NLS-1$
     }
 
-    private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws MetaMatrixComponentException,
-                                                           MetaMatrixProcessingException {
+    private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws TeiidComponentException,
+                                                           TeiidProcessingException {
         Request request = null;
         if (cache != null) {
         	request = new PreparedStatementRequest(cache);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceCapabilitiesFinder.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceCapabilitiesFinder.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceCapabilitiesFinder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,13 +26,13 @@
 import java.util.List;
 
 import org.teiid.dqp.internal.process.multisource.MultiSourceCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.AllCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.query.optimizer.capabilities.AllCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceElementReplacementVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceElementReplacementVisitor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceElementReplacementVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,14 +25,15 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.navigator.DeepPostOrderNavigator;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.navigator.DeepPostOrderNavigator;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceMetadataWrapper.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceMetadataWrapper.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourceMetadataWrapper.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,10 +26,11 @@
 import java.util.List;
 import java.util.Properties;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -34,29 +34,29 @@
 import org.junit.Test;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.core.id.IntegerIDFactory;
 import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.resolver.TestResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.core.id.IDGenerator;
-import com.metamatrix.core.id.IntegerIDFactory;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.processor.HardcodedDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.resolver.TestResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 
@@ -73,7 +73,7 @@
             setMustRegisterCommands(false);
         }
 
-        public TupleSource registerRequest(Object processorID, Command command, String modelName, String connectorBindingId, int nodeID) throws com.metamatrix.api.exception.MetaMatrixComponentException {
+        public TupleSource registerRequest(Object processorID, Command command, String modelName, String connectorBindingId, int nodeID) throws org.teiid.core.TeiidComponentException {
         	assertNotNull(connectorBindingId);
         	
         	Collection elements = ElementCollectorVisitor.getElements(command, true, true);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/validator/TestAuthorizationValidationVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/validator/TestAuthorizationValidationVisitor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/validator/TestAuthorizationValidationVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -35,21 +35,21 @@
 import org.teiid.adminapi.impl.DataPolicyMetadata;
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidComponentException;
 import org.teiid.dqp.internal.process.Request;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.Symbol;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorFailure;
+import org.teiid.query.validator.ValidatorReport;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.Symbol;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.validator.Validator;
-import com.metamatrix.query.validator.ValidatorFailure;
-import com.metamatrix.query.validator.ValidatorReport;
 
 public class TestAuthorizationValidationVisitor extends TestCase {
 
@@ -153,7 +153,7 @@
         return svc;
     }
 
-    private void helpTest(DataPolicyMetadata policy, String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+    private void helpTest(DataPolicyMetadata policy, String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb) throws QueryParserException, QueryResolverException, TeiidComponentException {
         QueryParser parser = QueryParser.getQueryParser();
         Command command = parser.parseCommand(sql);
         QueryResolver.resolveCommand(command, metadata);
@@ -279,7 +279,7 @@
         helpTest(exampleAuthSvc1(), "select * from xmltest.doc1", FakeMetadataFactory.example1Cached(), new String[] {"xmltest.doc1"}, FakeMetadataFactory.example1VDB()); //$NON-NLS-1$ //$NON-NLS-2$
     }
     
-	private void helpTestLookupVisibility(boolean visible) throws QueryParserException, QueryValidatorException, MetaMatrixComponentException {
+	private void helpTestLookupVisibility(boolean visible) throws QueryParserException, QueryValidatorException, TeiidComponentException {
 		VDBMetaData vdb = FakeMetadataFactory.example1VDB();
 		vdb.getModel("pm1").setVisible(visible); //$NON-NLS-1$
 		AuthorizationValidationVisitor mvvv = new AuthorizationValidationVisitor(vdb, false, new HashMap<String, DataPolicy>(), "test"); //$NON-NLS-1$

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/transaction/TestTransactionServer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/transaction/TestTransactionServer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/transaction/TestTransactionServer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -34,9 +34,9 @@
 import org.teiid.adminapi.Transaction;
 import org.teiid.client.xa.XATransactionException;
 import org.teiid.client.xa.XidImpl;
+import org.teiid.common.queue.FakeWorkManager;
+import org.teiid.dqp.service.TransactionContext;
 
-import com.metamatrix.common.queue.FakeWorkManager;
-import com.metamatrix.dqp.service.TransactionContext;
 public class TestTransactionServer {
 
     private TransactionServerImpl server;

Copied: trunk/engine/src/test/java/org/teiid/dqp/message (from rev 2112, trunk/engine/src/test/java/com/metamatrix/dqp/message)

Modified: trunk/engine/src/test/java/org/teiid/dqp/message/TestAtomicRequestMessage.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/message/TestAtomicRequestMessage.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/dqp/message/TestAtomicRequestMessage.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,17 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.dqp.message;
+package org.teiid.dqp.message;
 
 import junit.framework.TestCase;
 
 import org.teiid.client.RequestMessage;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.dqp.internal.datamgr.language.TestQueryImpl;
 import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.RequestID;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestAtomicRequestMessage extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/dqp/message/TestRequestID.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestID.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/dqp/message/TestRequestID.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.dqp.message;
+package org.teiid.dqp.message;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.dqp.message.RequestID;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/dqp/message/TestResultsMessage.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/message/TestResultsMessage.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/dqp/message/TestResultsMessage.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.dqp.message;
+package org.teiid.dqp.message;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -31,9 +31,9 @@
 import org.teiid.client.ResultsMessage;
 import org.teiid.client.metadata.ParameterInfo;
 import org.teiid.client.plan.PlanNode;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestResultsMessage extends TestCase {

Copied: trunk/engine/src/test/java/org/teiid/dqp/service (from rev 2112, trunk/engine/src/test/java/com/metamatrix/dqp/service)

Modified: trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/AutoGenDataService.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.dqp.service;
+package org.teiid.dqp.service;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -28,19 +28,19 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManager;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorWork;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorWorkItem;
 import org.teiid.dqp.internal.process.AbstractWorkItem;
+import org.teiid.dqp.message.AtomicRequestMessage;
+import org.teiid.dqp.message.AtomicResultsMessage;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
 import org.teiid.resource.ConnectorException;
 import org.teiid.resource.cci.DataNotAvailableException;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.dqp.message.AtomicRequestMessage;
-import com.metamatrix.dqp.message.AtomicResultsMessage;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 
 /**
  * This data service will automatically generate results when called with a query - basically

Modified: trunk/engine/src/test/java/org/teiid/dqp/service/FakeBufferService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/FakeBufferService.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/dqp/service/FakeBufferService.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.dqp.service;
+package org.teiid.dqp.service;
 
+import org.teiid.cache.CacheFactory;
+import org.teiid.cache.FakeCache.FakeCacheFactory;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
 import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.service.BufferService;
 
-import com.metamatrix.cache.CacheFactory;
-import com.metamatrix.cache.FakeCache.FakeCacheFactory;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
 
 /**
  */

Copied: trunk/engine/src/test/java/org/teiid/internal/core/xml (from rev 2112, trunk/engine/src/test/java/com/metamatrix/internal/core/xml)

Modified: trunk/engine/src/test/java/org/teiid/internal/core/xml/TestJdomHelper.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/internal/core/xml/TestJdomHelper.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/internal/core/xml/TestJdomHelper.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.internal.core.xml;
+package org.teiid.internal.core.xml;
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
@@ -31,8 +31,9 @@
 
 import org.jdom.Document;
 import org.jdom.Element;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.internal.core.xml.JdomHelper;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * This class tests the functionality in the JdomHelper class

Modified: trunk/engine/src/test/java/org/teiid/metadata/TestTransformationMetadata.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/metadata/TestTransformationMetadata.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/engine/src/test/java/org/teiid/metadata/TestTransformationMetadata.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -35,12 +35,12 @@
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.connector.metadata.runtime.Datatype;
 import org.teiid.connector.metadata.runtime.MetadataFactory;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestTransformationMetadata {
 

Copied: trunk/engine/src/test/java/org/teiid/query/analysis (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/analysis)

Modified: trunk/engine/src/test/java/org/teiid/query/analysis/TestAnalysisRecord.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/analysis/TestAnalysisRecord.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/analysis/TestAnalysisRecord.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.analysis;
+package org.teiid.query.analysis;
 
 import java.util.Collection;
 
@@ -28,8 +28,9 @@
 
 import org.teiid.client.plan.Annotation;
 import org.teiid.client.plan.Annotation.Priority;
+import org.teiid.core.util.StringUtil;
+import org.teiid.query.analysis.AnalysisRecord;
 
-import com.metamatrix.core.util.StringUtil;
 
 /**
  */

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,1176 @@
+/*
+ * 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 org.teiid.query.function;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.query.function.FunctionMethods;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
+
+
+public class TestFunction {
+
+    private void helpConcat(String s1, String s2, Object expected) {
+        Object actual = FunctionMethods.concat(s1, s2);
+        assertEquals("concat(" + s1 + ", " + s2 + ") failed.", expected, actual);	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpTrim(String str, boolean left, Object expected) {
+        Object actual = null;
+        if (left) {
+            actual = FunctionMethods.leftTrim(str);
+            assertEquals("ltrim(" + str + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$
+        } else {
+            actual = FunctionMethods.rightTrim(str);
+            assertEquals("rtrim(" + str + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+
+    public static void helpLeft(String str, int count, Object expected) throws FunctionExecutionException {
+        Object actual = FunctionMethods.left(str, new Integer(count));
+        assertEquals("left(" + str + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    public static void helpRight(String str, int count, Object expected) throws FunctionExecutionException {
+        Object actual = FunctionMethods.right(str, new Integer(count));
+        assertEquals("right(" + str + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    public static void helpReplace(String str, String sub, String replace, Object expected) {
+        Object actual = FunctionMethods.replace(str, sub, replace);
+        assertEquals("replace(" + str + "," + sub + "," + replace + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    public static void helpSubstring(String str, Integer start, Integer length, Object expected) {
+        Object actual = FunctionMethods.substring(str, start, length);
+        assertEquals("substring(" + str + "," + start + "," + length + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    public static void helpSubstring(String str, Integer start, Object expected) {
+        Object actual = FunctionMethods.substring(str, start);
+        assertEquals("substring(" + str + "," + start + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpConvert(Object src, String tgtType, Object expected) throws FunctionExecutionException {
+        Object actual = FunctionMethods.convert(src, tgtType);
+        assertEquals("convert(" + src + "," + tgtType + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpConvertFail(Object src, String tgtType) {
+        try {
+            FunctionMethods.convert(src, tgtType);
+            fail("Expected convert(" + src + "," + tgtType + ") to throw FunctionExecutionException, but it did not."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        } catch (FunctionExecutionException e) {
+        } 
+    }
+
+    public static void helpTestInitCap(String input, String expected) {
+        String actual = (String) FunctionMethods.initCap(input);
+        assertEquals("Didn't get expected result from initCap", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestLpad(String input, int length, String expected) throws FunctionExecutionException {
+        String actual = (String) FunctionMethods.lpad(input, new Integer(length));
+        assertEquals("Didn't get expected result from lpad", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestLpad(String input, int length, String pad, String expected) throws FunctionExecutionException {
+        String actual = (String) FunctionMethods.lpad(input, new Integer(length), pad);
+        assertEquals("Didn't get expected result from lpad", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestRpad(String input, int length, String expected) throws FunctionExecutionException {
+        String actual = (String) FunctionMethods.rpad(input, new Integer(length));
+        assertEquals("Didn't get expected result from rpad", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestRpad(String input, int length, String c, String expected) throws FunctionExecutionException {
+        String actual = (String) FunctionMethods.rpad(input, new Integer(length), c);
+        assertEquals("Didn't get expected result from rpad", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestTranslate(String input, String src, String dest, String expected) throws FunctionExecutionException {
+        String actual = (String) FunctionMethods.translate(input, src, dest);
+        assertEquals("Didn't get expected result from translate", expected, actual); //$NON-NLS-1$
+    }
+
+    public static void helpTestLocate(String locateString, String input, int expectedLocation) {
+        Integer location = (Integer) FunctionMethods.locate(locateString, input);
+        int actualLocation = location.intValue();
+        assertEquals("Didn't get expected result from locate", expectedLocation, actualLocation); //$NON-NLS-1$
+    }
+
+    public static void helpTestLocate(String locateString, String input, Integer start, int expectedLocation) {
+        Integer location = (Integer) FunctionMethods.locate(locateString, input, start);
+        int actualLocation = location.intValue();
+        assertEquals("Didn't get expected result from locate", expectedLocation, actualLocation); //$NON-NLS-1$
+    }
+
+    public static void helpTestRound(Integer number, Integer places, Object expected) {
+        Object actual = FunctionMethods.round(number, places);
+        assertEquals("round(" + number + "," + places + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    public static void helpTestRound(Float number, Integer places, Object expected) {
+        Object actual = FunctionMethods.round(number, places);
+        assertEquals("round(" + number + "," + places + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpTestRound(Double number, Integer places, Object expected) {
+        Object actual = FunctionMethods.round(number, places);
+        assertEquals("round(" + number + "," + places + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpTestRound(BigDecimal number, Integer places, Object expected) {
+        Object actual = FunctionMethods.round(number, places);
+        assertEquals("round(" + number + "," + places + ") failed.", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    public static void helpTestHour1(String timeStr, int expected) {
+        Time t = Time.valueOf(timeStr);
+        Object actual = FunctionMethods.hour(t);
+        assertEquals("hour(" + t + ") failed", new Integer(expected), actual); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    public static void helpTestHour2(String timestampStr, int expected) {
+        Timestamp ts = Timestamp.valueOf(timestampStr);
+        Object actual = FunctionMethods.hour(ts);
+        assertEquals("hour(" + ts + ") failed", new Integer(expected), actual); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    public static void helpTestTimestampCreate(java.sql.Date date, Time time, String expected) {
+        Object actual = FunctionMethods.timestampCreate(date, time);
+        assertEquals("timestampCreate(" + date + ", " + time + ") failed", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                     expected, actual.toString()); 
+    }
+
+    public static void helpTestTimestampDiff(String intervalType, Timestamp timeStamp1, Timestamp timeStamp2, Long expected) {
+        Object actual = FunctionMethods.timestampDiff(intervalType, timeStamp1, timeStamp2);
+        assertEquals("timestampDiff(" + intervalType + ", " + timeStamp1 + ", " + timeStamp2 + ") failed", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                     expected, actual); 
+
+        // test reverse - should be 
+        Long expected2 = new Long(0 - expected.longValue());
+        Object actual2 = FunctionMethods.timestampDiff(intervalType, timeStamp2, timeStamp1);
+        assertEquals("timestampDiff(" + intervalType + ", " + timeStamp2 + ", " + timeStamp1 + ") failed", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                     expected2, actual2); 
+    }
+    
+    public static void helpTestParseTimestamp(String tsStr, String format, String expected) throws FunctionExecutionException {
+        Object actual = FunctionMethods.parseTimestamp(tsStr, format);
+        assertEquals("parseTimestamp(" + tsStr + ", " + format + ") failed", expected.toString(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                     new Constant(actual).toString()); 
+    }
+
+    // ################################## ACTUAL TESTS ################################
+
+    // ------------------------------ CONCAT ------------------------------
+
+    @Test public void testConcat1() throws Exception {
+        helpConcat("x", "y", "xy"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testConcat5() throws Exception {
+        helpConcat("", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    // ------------------------------ TRIM ------------------------------
+
+    @Test public void testTrim3() throws Exception {
+        helpTrim("", true, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim4() throws Exception {
+        helpTrim("", false, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim5() throws Exception {
+        helpTrim("x", true, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim6() throws Exception {
+        helpTrim("x", false, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim7() throws Exception {
+        helpTrim("  x", true, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim8() throws Exception {
+        helpTrim(" x ", true, "x "); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim9() throws Exception {
+        helpTrim("x  ", false, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim10() throws Exception {
+        helpTrim(" x x ", false, " x x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim11() throws Exception {
+        helpTrim("  ", true, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testTrim12() throws Exception {
+        helpTrim("  ", false, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    // ------------------------------ LEFT ------------------------------
+
+    @Test public void testLeft1() throws Exception {
+        helpLeft("abcd", 0, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLeft2() throws Exception {
+        helpLeft("abcd", 3, "abc"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLeft4() throws Exception {
+        helpLeft("", 0, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLeft5() throws Exception {
+        helpLeft("", 2, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLeft6() throws Exception {
+        helpLeft("abcd", 5, "abcd"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLeft7() throws Exception {
+        helpLeft("abcd", 4, "abcd"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    // ------------------------------ RIGHT ------------------------------
+
+    @Test public void testRight1() throws Exception {
+        helpRight("abcd", 0, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRight2() throws Exception {
+        helpRight("abcd", 3, "bcd"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRight4() throws Exception {
+        helpRight("", 0, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRight5() throws Exception {
+        helpRight("", 2, ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRight6() throws Exception {
+        helpRight("abcd", 5, "abcd"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRight7() throws Exception {
+        helpRight("abcd", 4, "abcd"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    // ------------------------------ SUBSTRING ------------------------------
+
+    @Test public void testSubstring1() throws Exception {
+        helpSubstring("abc", new Integer(1), new Integer(1), "a"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring2() throws Exception {
+        helpSubstring("abc", new Integer(2), new Integer(2), "bc"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring3() throws Exception {
+        helpSubstring("abc", new Integer(3), new Integer(3), "c"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring4() throws Exception {
+        helpSubstring("abc", new Integer(3), new Integer(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring6() throws Exception {
+        helpSubstring("abc", new Integer(3), "c"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring7() throws Exception {
+        helpSubstring("abc", new Integer(1), "abc"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testSubstring8() throws Exception {
+        helpSubstring("abc", new Integer(-1), "c"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testSubstring9() throws Exception {
+        helpSubstring("abc", new Integer(-3), "abc"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testSubstring10() throws Exception {
+        helpSubstring("abc", new Integer(-4), null); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testSubstring11() throws Exception {
+        helpSubstring("abc", new Integer(-1), new Integer(2), "c"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testSubstring12() throws Exception {
+        helpSubstring("abc", new Integer(-3), new Integer(2), "ab"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testSubstring13() throws Exception {
+        helpSubstring("abc", new Integer(0), new Integer(2), "ab"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    
+    // ------------------------------ REPLACE ------------------------------
+
+    @Test public void testReplace1() throws Exception {
+        helpReplace("", "x", "y", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace2() throws Exception {
+        helpReplace("", "", "z", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace3() throws Exception {
+        helpReplace("x", "x", "y", "y"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace4() throws Exception {
+        helpReplace("xx", "x", "y", "yy"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace5() throws Exception {
+        helpReplace("x x", "x", "y", "y y"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace6() throws Exception {
+        helpReplace("x x", "x", "", " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace7() throws Exception {
+        helpReplace("x x", "x", "yz", "yz yz"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testReplace8() throws Exception {
+        helpReplace("xx xx", "xx", "y", "y y"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    // ------------------------------ CONVERT ------------------------------
+
+    @Test public void testConvertStringBoolean1() throws Exception {
+        helpConvert("true", "boolean", Boolean.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBoolean2() throws Exception {
+        helpConvert("false", "boolean", Boolean.FALSE); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBoolean3() throws Exception {
+        helpConvert("x", "boolean", Boolean.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBoolean4() throws Exception {
+        helpConvert("TrUe", "boolean", Boolean.TRUE); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBoolean5() throws Exception {
+        helpConvert("FAlsE", "boolean", Boolean.FALSE); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringChar1() throws Exception {
+        helpConvert("a", "char", new Character('a')); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringChar2() throws Exception {
+    	helpConvert("xx", "char", new Character('x')); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringByte1() throws Exception {
+        helpConvert("5", "byte", new Byte((byte) 5)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringShort1() throws Exception {
+        helpConvert("5", "short", new Short((short) 5)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringInteger1() throws Exception {
+        helpConvert("5", "integer", new Integer(5)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    // Integer > Integer.MAX_VALUE - should fail
+    @Test public void testConvertStringInteger2() throws Exception {
+        helpConvertFail("" + Integer.MAX_VALUE + "1", "integer"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testConvertStringInteger3() throws Exception {
+        helpConvertFail("5.99", "integer"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringLong1() throws Exception {
+        helpConvert("5", "long", new Long(5)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBigInteger1() throws Exception {
+        helpConvert("5", "biginteger", new BigInteger("5")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testConvertStringBigInteger2() throws Exception {
+        String bigInt = "" + Integer.MAX_VALUE + "111"; //$NON-NLS-1$ //$NON-NLS-2$
+        helpConvert(bigInt, "biginteger", new BigInteger(bigInt)); //$NON-NLS-1$
+    }
+
+    @Test public void testConvertStringFloat1() throws Exception {
+        helpConvert("5.2", "float", new Float(5.2f)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringDouble1() throws Exception {
+        helpConvert("5.2", "double", new Double(5.2d)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertStringBigDecimal1() throws Exception {
+        helpConvert("5.2", "bigdecimal", new BigDecimal("5.2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testConvertDoubleBigInteger() throws Exception {
+        helpConvert(new Double(1.0d), "biginteger", new BigInteger("1")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertFloatBigInteger() throws Exception {
+        helpConvert(new Float(1.0), "biginteger", new BigInteger("1")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertBigDecimalBigInteger() throws Exception {
+        helpConvert(new BigDecimal("1.0"), "biginteger", new BigInteger("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testConvertDoubleLong() throws Exception {
+        helpConvert(new Double(1.0d), "long", new Long("1")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testConvertTimestampString() throws Exception {
+        Timestamp ts = TimestampUtil.createTimestamp(103, 7, 22, 22, 43, 53, 3333333);
+        helpConvert(ts, "string", "2003-08-22 22:43:53.003333333"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testAscii2() throws Exception {
+        Integer code = FunctionMethods.ascii(" "); //$NON-NLS-1$
+        assertEquals("Didn't get expected code", 32, code.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testAscii4() throws Exception {
+    	assertNull(FunctionMethods.ascii("")); //$NON-NLS-1$
+    }
+
+    @Test public void testAscii5() throws Exception {
+        Integer code = FunctionMethods.ascii("abc"); //$NON-NLS-1$
+        assertEquals("Didn't get expected code", 97, code.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testChr1() throws Exception {
+        Character chr = (Character) FunctionMethods.chr(new Integer(32));
+        assertEquals("Didn't get expected character", ' ', chr.charValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testNvl1() throws Exception {
+        String ret = (String) FunctionMethods.ifnull("x", "y"); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("Didn't get expected value", "x", ret); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testNvl2() throws Exception {
+        String ret = (String) FunctionMethods.ifnull(null, "y"); //$NON-NLS-1$
+        assertEquals("Didn't get expected value", "y", ret); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testNvl3() throws Exception {
+        String ret = (String) FunctionMethods.ifnull(null, null);
+        assertEquals("Didn't get expected value", null, ret); //$NON-NLS-1$
+    }
+
+    @Test public void testInitCap2() throws Exception {
+        helpTestInitCap("abc", "Abc"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testInitCap3() throws Exception {
+        helpTestInitCap(" test    some\tweird\rspaces\nhere", " Test    Some\tWeird\rSpaces\nHere"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testInitCap4() throws Exception {
+        helpTestInitCap("x y ", "X Y "); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testInitCap5() throws Exception {
+        helpTestInitCap("cows are FUN", "Cows Are Fun"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLpad1() throws Exception {
+        helpTestLpad("x", 4, "   x");     //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLpad3() throws Exception {
+        helpTestLpad("x", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLpad4() throws Exception {
+        helpTestLpad("xx", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLpad5() throws Exception {
+        helpTestLpad("", 4, "x", "xxxx");     //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testLpad6() throws Exception {
+        helpTestLpad("10", 6, "0", "000010"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testLpad7() throws Exception {
+    	helpTestLpad("x", 4, "yq", "qyqx" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+    }
+
+    @Test public void testRpad1() throws Exception {
+        helpTestRpad("x", 4, "x   "); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRpad3() throws Exception {
+        helpTestRpad("x", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRpad4() throws Exception {
+        helpTestRpad("xx", 1, "x"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRpad5() throws Exception {
+        helpTestRpad("", 4, "x", "xxxx"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testRpad6() throws Exception {
+        helpTestRpad("10", 6, "0", "100000"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testTranslate1() throws Exception {
+        helpTestTranslate("This is my test", "ty", "yt", "This is mt yesy");     //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testTranslate2() throws Exception {
+        helpTestTranslate("", "ty", "yt", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testTranslate3() throws Exception {
+        try {
+            FunctionMethods.translate("test", "x", "yz"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            fail("Did not get expected exception on differing src and dest lengths"); //$NON-NLS-1$
+        } catch (FunctionExecutionException e) {
+        }
+    }
+
+    @Test public void testTranslate4() throws Exception {
+        helpTestTranslate("test", "xy", "ab", "test"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testLocate1() throws Exception {
+        helpTestLocate(",", "Metamatrix, John Quincy", 11); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLocate2() throws Exception {
+        helpTestLocate(" ", "Metamatrix, John Quincy", 12); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLocate3() throws Exception {
+        helpTestLocate("x", "xx", 1); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLocate4() throws Exception {
+        helpTestLocate("y", "xx", 0); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testLocate5() throws Exception {
+        helpTestLocate("b", "abab", 3, 4); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testLocate6() throws Exception {
+        helpTestLocate("z", "abab", 0, 0); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testLocate7() throws Exception {
+        helpTestLocate("z", "abab", null, 0); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testLocate8() throws Exception {
+        helpTestLocate("z", "abab", -1, 0); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testBitand() throws Exception {
+        // Both values are integers
+        Integer result = (Integer) FunctionMethods.bitand(new Integer(0xFFF), new Integer(0x0F0));
+        assertNotNull("Result should not be null", result); //$NON-NLS-1$
+        assertEquals("result should be 0x0F0", 0x0F0, result.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testBitor() throws Exception {
+        // Both values are integers
+        Integer result = (Integer) FunctionMethods.bitor(new Integer(0xFFF), new Integer(0x0F0));
+        assertNotNull("Result should not be null", result); //$NON-NLS-1$
+        assertEquals("result should be 0xFFF", 0xFFF, result.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testBitxor() throws Exception {
+        // Both values are integers
+        Integer result = (Integer) FunctionMethods.bitxor(new Integer(0xFFF), new Integer(0x0F0));
+        assertNotNull("Result should not be null", result); //$NON-NLS-1$
+        assertEquals("result should be 0xF0F", 0xF0F, result.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testBitnot() throws Exception {
+        // Both values are integers
+        Integer result = FunctionMethods.bitnot(0xF0F);
+        assertNotNull("Result should not be null", result); //$NON-NLS-1$
+        assertEquals("result should be 0xFFFFF0F0", 0xFFFFF0F0, result.intValue()); //$NON-NLS-1$
+    }
+
+    @Test public void testRoundInteger1() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(0), new Integer(1928));
+    }
+
+    @Test public void testRoundInteger2() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(-1), new Integer(1930));
+    }
+
+    @Test public void testRoundInteger3() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(-2), new Integer(1900));
+    }
+
+    @Test public void testRoundInteger4() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(-3), new Integer(2000));
+    }
+
+    @Test public void testRoundInteger5() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(-4), new Integer(0));
+    }
+
+    @Test public void testRoundInteger6() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(-5), new Integer(0));
+    }
+
+    @Test public void testRoundInteger7() throws Exception {
+        helpTestRound(new Integer(1928), new Integer(1), new Integer(1928));
+    }
+
+    @Test public void testRoundFloat1() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(4), new Float(123.456F));
+    }
+
+    @Test public void testRoundFloat2() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(3), new Float(123.456F));
+    }
+
+    @Test public void testRoundFloat3() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(2), new Float(123.46F));
+    }
+
+    @Test public void testRoundFloat4() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(1), new Float(123.5F));
+    }
+
+    @Test public void testRoundFloat5() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(0), new Float(123F));
+    }
+
+    @Test public void testRoundFloat6() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(-1), new Float(120F));
+    }
+
+    @Test public void testRoundFloat7() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(-2), new Float(100F));
+    }
+
+    @Test public void testRoundFloat8() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(-3), new Float(0F));
+    }
+
+    @Test public void testRoundFloat9() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(-4), new Float(0F));
+    }
+    
+    @Test public void testRoundFloat10() throws Exception {
+        helpTestRound(new Float(123.456F), new Integer(4000), new Float(123.456F));
+    }
+
+    @Test public void testRoundDouble1() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(4), new Double(123.456));
+    }
+
+    @Test public void testRoundDouble2() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(3), new Double(123.456));
+    }
+
+    @Test public void testRoundDouble3() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(2), new Double(123.46));
+    }
+
+    @Test public void testRoundDouble4() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(1), new Double(123.5));
+    }
+
+    @Test public void testRoundDouble5() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(0), new Double(123));
+    }
+
+    @Test public void testRoundDouble6() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(-1), new Double(120));
+    }
+
+    @Test public void testRoundDouble7() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(-2), new Double(100));
+    }
+
+    @Test public void testRoundDouble8() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(-3), new Double(0));
+    }
+
+    @Test public void testRoundDouble9() throws Exception {
+        helpTestRound(new Double(123.456), new Integer(-4), new Double(0));
+    }
+    
+    @Test public void testRoundDouble10() throws Exception {
+        helpTestRound(new Double(-3.5), new Integer(0), new Double(-4));
+    }
+    
+    @Test public void testRoundBigDecimal1() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(4), new BigDecimal("123.456")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal2() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(3), new BigDecimal("123.456")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal3() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(2), new BigDecimal("123.460")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal4() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(1), new BigDecimal("123.500")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal5() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(0), new BigDecimal("123.000")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal6() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(-1), new BigDecimal("120.000")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal7() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(-2), new BigDecimal("100.000")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal8() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(-3), new BigDecimal("0.000")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testRoundBigDecimal9() throws Exception {
+        helpTestRound(new BigDecimal("123.456"), new Integer(-4), new BigDecimal("0.000")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testHour1() throws Exception {
+        helpTestHour1("00:00:00", 0); //$NON-NLS-1$
+    }
+
+    @Test public void testHour2() throws Exception {
+        helpTestHour1("11:00:00", 11); //$NON-NLS-1$
+    }
+
+    @Test public void testHour3() throws Exception {
+        helpTestHour1("12:00:00", 12); //$NON-NLS-1$
+    }
+
+    @Test public void testHour4() throws Exception {
+        helpTestHour1("13:00:00", 13); //$NON-NLS-1$
+    }
+
+    @Test public void testHour5() throws Exception {
+        helpTestHour1("23:59:59", 23); //$NON-NLS-1$
+    }
+
+    @Test public void testHour6() throws Exception {
+        helpTestHour2("2002-01-01 00:00:00", 0); //$NON-NLS-1$
+    }
+
+    @Test public void testHour7() throws Exception {
+        helpTestHour2("2002-01-01 11:00:00", 11); //$NON-NLS-1$
+    }
+
+    @Test public void testHour8() throws Exception {
+        helpTestHour2("2002-01-01 12:00:00", 12); //$NON-NLS-1$
+    }
+
+    @Test public void testHour9() throws Exception {
+        helpTestHour2("2002-01-01 13:00:00", 13); //$NON-NLS-1$
+    }
+
+    @Test public void testHour10() throws Exception {
+        helpTestHour2("2002-01-01 23:59:59", 23); //$NON-NLS-1$
+    }
+
+    @Test public void testTimestampCreate1() throws Exception {
+        helpTestTimestampCreate(TimestampUtil.createDate(103, 11, 1), TimestampUtil.createTime(23, 59, 59), "2003-12-01 23:59:59.0"); //$NON-NLS-1$
+    }
+
+    @Test public void testTimestampAdd2() throws Exception {
+    	assertEquals(TimestampUtil.createTimestamp(103, 11, 1, 18, 20, 30, 0), FunctionMethods.timestampAdd(SQLReservedWords.SQL_TSI_HOUR, 3, TimestampUtil.createTimestamp(103, 11, 1, 15, 20, 30, 0)));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND, 
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 1),
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 100000000),
+                              new Long(99999999));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_2() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              // 1 day (8.64 x 10^10 nanos) and 1 nano
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 2),
+                              TimestampUtil.createTimestamp((2001-1900), 5, 22, 3, 9, 35, 3),
+                              new Long(86400000000001L));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_3() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              // 1 day (8.64 x 10^10 nanos) less 1 nano
+                              TimestampUtil.createTimestamp((2001-1900), 5, 22, 3, 9, 35, 2),
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 3),
+                              new Long(-86399999999999L));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_4() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 0, 0, 0, 1),
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 0, 0, 0, 3),
+                              new Long(00000002));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_5() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 0, 0, 0, 1),
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 0, 0, 0, 10),
+                              new Long(9));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_6() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              TimestampUtil.createTimestamp((2001-1900), 5, 22, 0, 0, 0, 2),
+                              TimestampUtil.createTimestamp((2001-1900), 5, 22, 0, 0, 0, 3),
+                              new Long(1));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_7() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              // 1 nano diff
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 2),
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 3),
+                              new Long(1));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_FracSec_8() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+                              // 1 nano diff
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 3),
+                              TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 2),
+                              new Long(-1));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Min_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+                              TimestampUtil.createTimestamp(0, 0, 0, 2, 34, 12, 0),
+                              TimestampUtil.createTimestamp(0, 0, 0, 12, 0, 0, 0),
+                              new Long(565));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Min_2() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+                              TimestampUtil.createTimestamp((2001-1900), 0, 0, 2, 0, 0, 0),
+                              TimestampUtil.createTimestamp((2001-1900), 0, 0, 0, 33, 12, 0),
+                              new Long(-86));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Min_3() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+                              TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 07, 58, 65497),
+                              TimestampUtil.createTimestamp((2001-1900), 8, 29, 11, 25, 42, 483219),
+                              new Long(4277));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Min_4() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+                              TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 07, 58, 0),
+                              TimestampUtil.createTimestamp((2001-1900), 8, 29, 11, 25, 42, 0),
+                              new Long(4277));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Min_5() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+                              TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 0, 0, 1),
+                              TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 0, 0, 0),
+                              new Long(0));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Hour_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR,
+                              TimestampUtil.createTimestamp((2004-1900), 8, 26, 12, 0, 0, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 8, 26, 12, 59, 59, 999999999),
+                              new Long(0));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Week_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_WEEK,
+                              TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 100),
+                              TimestampUtil.createTimestamp((2001-1900), 4, 2, 5, 19, 35, 500),
+                              new Long(-7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 4, 19, 0, 0, 0, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 20, 12, 0, 0, 0),
+                              new Long(7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_2() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 5, 1, 0, 0, 0, 1000000),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 1, 12, 0, 0, 1),
+                              new Long(6));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_3() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 4, 19, 0, 0, 0, 1),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 18, 12, 0, 0, 1000000),
+                              new Long(7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_4() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 0, 1000000),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 0, 0),
+                              new Long(7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_5() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 1, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 0, 0),
+                              new Long(7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Month_6() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+                              TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 1, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 2, 0),
+                              new Long(7));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Day_1() throws Exception {
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_DAY,
+                              TimestampUtil.createTimestamp((2004-1900), 2, 1, 0, 0, 0, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 3, 1, 0, 0, 0, 0),
+                              new Long(31));
+    }
+
+    @Test public void testTimestampDiffTimeStamp_Day_2() throws Exception {
+        // Leap year
+        helpTestTimestampDiff(SQLReservedWords.SQL_TSI_DAY,
+                              TimestampUtil.createTimestamp((2004-1900), 1, 1, 0, 0, 0, 0),
+                              TimestampUtil.createTimestamp((2004-1900), 2, 1, 0, 0, 0, 0),
+                              new Long(29));
+    }
+
+	@Test public void testTimestampDiffTime_Hour_1() throws Exception {
+		helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR, new Timestamp(
+				TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(
+				TimestampUtil.createTime(5, 5, 36).getTime()), new Long(2));
+	}
+
+	@Test public void testTimestampDiffTime_Hour_2() throws Exception {
+		helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR, new Timestamp(
+				TimestampUtil.createTime(5, 0, 30).getTime()), new Timestamp(
+				TimestampUtil.createTime(3, 0, 31).getTime()), new Long(-1));
+	}
+
+    @Test public void testParseTimestamp1() throws Exception {
+        helpTestParseTimestamp("1993-04-24 3:59:59 PM", "yyyy-MM-dd hh:mm:ss aa", "{ts'1993-04-24 15:59:59.0'}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+    }
+    
+    public void helpTestModifyTimeZone(String tsStr, String tzStart, String tzEnd, String expectedStr) throws Exception {
+        Timestamp ts = tsStr != null ? Timestamp.valueOf(tsStr) : null;
+        Timestamp actual = null;
+        
+        if(tzStart == null) {
+            actual = (Timestamp) FunctionMethods.modifyTimeZone(new CommandContext(), ts, tzEnd);
+        } else {
+            actual = (Timestamp) FunctionMethods.modifyTimeZone(ts, tzStart, tzEnd);
+        }
+        
+        String actualStr = null;
+        if(actual != null) {
+            actualStr = actual.toString();
+        }
+        assertEquals("Did not get expected output timestamp", expectedStr, actualStr); //$NON-NLS-1$
+    }
+    
+    /*
+     * The following test results may look odd, but it is due to the parsing of the initial date, which is done
+     * against the system default timezone (not the startTz shown below).  The fianl date value is also being read
+     * against the default timezone and not the endTz shown. 
+     */
+    @Test public void testModifyTimeZoneGMT() throws Exception {
+        helpTestModifyTimeZone("2004-10-03 15:19:59.123456789", "GMT+00:00", "GMT-01:00", "2004-10-03 16:19:59.123456789"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testModifyTimeZoneGMTPartialHour() throws Exception {
+        helpTestModifyTimeZone("2004-10-03 15:30:59.123456789", "GMT+00:00", "GMT-01:45", "2004-10-03 17:15:59.123456789"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testModifyTimeZoneNamedTZ() throws Exception {
+        helpTestModifyTimeZone("2004-10-03 15:19:59.123456789", "America/New_York", "America/Chicago", "2004-10-03 16:19:59.123456789"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testModifyTimeZoneNamedTZ2() throws Exception {
+        helpTestModifyTimeZone("2004-10-03 15:19:59.123456789", "America/Chicago", "America/New_York", "2004-10-03 14:19:59.123456789"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testModifyTimeZoneStartLocal() throws Exception {
+        helpTestModifyTimeZone("2004-10-03 15:19:59.123456789", "America/Chicago", "America/Los_Angeles", "2004-10-03 17:19:59.123456789"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+    }
+    
+    // case 2458
+    @Test public void testCurrentDate() throws Exception {
+
+        Date curDate = (Date)FunctionMethods.currentDate();
+     
+        Calendar cal1 = Calendar.getInstance();
+        cal1.setTime(curDate);
+        
+        assertEquals(cal1.get(Calendar.HOUR_OF_DAY), 0);
+        assertEquals(cal1.get(Calendar.MINUTE), 0);
+        assertEquals(cal1.get(Calendar.SECOND), 0);
+        assertEquals(cal1.get(Calendar.MILLISECOND), 0);
+             
+    }
+
+    // case 2458
+    @Test public void testCurrentTime() throws Exception {
+        
+        Time curDate = (Time)FunctionMethods.currentTime();
+
+        Calendar cal1 = Calendar.getInstance();
+        cal1.setTime(curDate);
+        
+        // can not test the current time without making a copy of current "time"
+        // so check the normalization of the date to unix epoch
+        assertEquals(cal1.get(Calendar.YEAR), 1970);
+        assertEquals(cal1.get(Calendar.MONTH), Calendar.JANUARY);
+        assertEquals(cal1.get(Calendar.DATE), 1);
+              
+    }    
+    
+    @Test public void testRand() throws Exception {
+        Double d = (Double)FunctionMethods.rand(new CommandContext(), new Integer(100));
+        assertEquals(new Double(0.7220096548596434), d);
+        
+        try {
+            FunctionMethods.rand(new CommandContext(), new Double(34.5));
+            fail("should have failed to take a double"); //$NON-NLS-1$
+        } catch (FunctionExecutionException e) {            
+        }   
+
+        FunctionMethods.rand(new CommandContext());            
+    }
+    
+    @Test public void testEnv() throws Exception {
+        Properties p = new Properties();
+        String envProperty = "EnvProperty"; //$NON-NLS-1$
+        String systemProperty = "SystemProperty"; //$NON-NLS-1$        
+        p.setProperty(envProperty.toLowerCase(), envProperty);
+
+        // set an environment property
+        CommandContext context = new CommandContext();
+        context.setEnvironmentProperties(p);
+
+        // set the system property
+        System.setProperty(systemProperty, systemProperty);
+        System.setProperty(systemProperty.toLowerCase(), systemProperty+"_lowercase"); //$NON-NLS-1$
+        
+        assertEquals(envProperty, FunctionMethods.env(context, envProperty));
+        assertEquals(systemProperty, FunctionMethods.env(context, systemProperty));
+        assertEquals(systemProperty+"_lowercase", FunctionMethods.env(context, systemProperty.toUpperCase())); //$NON-NLS-1$
+    }
+    
+    @Test(expected=FunctionExecutionException.class) public void testParseIntStrictness() throws Exception {
+    	FunctionMethods.parseInteger("a 1 a", "#"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testParseDateStrictness() throws Exception {
+    	assertEquals(TimestampUtil.createTimestamp(108, 0, 1, 0, 0, 0, 0), FunctionMethods.parseTimestamp(" 2007-13-01", "yyyy-MM")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testParseTimeWhitespace() throws Exception {
+    	assertEquals(TimestampUtil.createTime(15, 0, 0), FunctionMethods.parseTimestamp(" 15:00:00 ", "HH:mm:ss")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testMod() {
+        assertEquals(new BigDecimal("-1.1"), FunctionMethods.mod(new BigDecimal("-3.1"), new BigDecimal("2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod1() {
+        assertEquals(new BigDecimal("-1.1"), FunctionMethods.mod(new BigDecimal("-3.1"), new BigDecimal("-2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod2() {
+        assertEquals(-40, FunctionMethods.mod(-340, 60), 0);
+    }
+    
+    @Test public void testMod3() {
+        assertEquals(-40, FunctionMethods.mod(-340, -60), 0);
+    }
+    
+    @Test public void testMod4() {
+        assertEquals(new BigInteger("-1"), FunctionMethods.mod(new BigInteger("-3"), new BigInteger("2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testMod5() {
+        assertEquals(new BigInteger("-1"), FunctionMethods.mod(new BigInteger("-3"), new BigInteger("-2")));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionDescriptorImpl.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionDescriptorImpl.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionDescriptorImpl.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionDescriptorImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,120 @@
+/*
+ * 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 org.teiid.query.function;
+
+import java.lang.reflect.Method;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.metadata.FunctionMethod;
+
+import junit.framework.TestCase;
+
+
+public class TestFunctionDescriptorImpl extends TestCase {
+
+    /**
+     * Constructor for TestFunctionDescriptorImpl.
+     * @param name
+     */
+    public TestFunctionDescriptorImpl(String name) {
+        super(name);
+    }
+    
+    /**
+     * Find the invocation method for a function.
+     * @param source The function metadata source, which knows how to obtain the invocation class
+     * @param invocationClass The class to invoke for this function
+     * @param invocationMethod The method to invoke for this function
+     * @param numArgs Number of arguments in method
+     * @throws NoSuchMethodException 
+     * @throws SecurityException 
+     */
+    private Method lookupMethod(String invocationClass, String invocationMethod, int numArgs) throws SecurityException, NoSuchMethodException {
+        // Build signature
+        Class[] objectSignature = new Class[numArgs];
+        for(int i=0; i<numArgs; i++) {
+            objectSignature[i] = Integer.TYPE;
+        }
+
+        // Find Method
+        Method method = null;
+        try {
+            Class methodClass = Class.forName(invocationClass);
+            method = methodClass.getMethod(invocationMethod, objectSignature);
+        } catch(ClassNotFoundException e) {
+            // Failed to load class, so can't load method - this will fail at invocation time.
+            // We don't fail here because this situation can occur in the modeler, which does
+            // not have the function jar files.  The modeler never invokes, so this isn't a
+            // problem.
+            return null;
+        } 
+
+        // Validate method
+        if(! FunctionTree.isValidMethod(method)) {
+            return null;
+        }
+        return method;
+    }
+    
+    public void test1() throws Exception {
+        FunctionDescriptor f1 = new FunctionDescriptor("+", FunctionMethod.CAN_PUSHDOWN, //$NON-NLS-1$
+            new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER },
+            DataTypeManager.DefaultDataClasses.INTEGER,
+            lookupMethod("com.metamatrix.query.function.FunctionMethods", "plus", 2) , false, true, FunctionMethod.DETERMINISTIC);    //$NON-NLS-1$ //$NON-NLS-2$
+            
+        UnitTestUtil.helpTestEquivalence(0, f1, f1);             
+    }
+
+    public void test2() throws Exception  {
+        FunctionDescriptor f1 = new FunctionDescriptor("+", FunctionMethod.CAN_PUSHDOWN,//$NON-NLS-1$
+            new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER },
+            DataTypeManager.DefaultDataClasses.INTEGER,
+            lookupMethod("com.metamatrix.query.function.FunctionMethods", "plus", 2), false, true, FunctionMethod.DETERMINISTIC ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        FunctionDescriptor f2 = new FunctionDescriptor("+", FunctionMethod.CAN_PUSHDOWN,//$NON-NLS-1$
+            new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER },
+            DataTypeManager.DefaultDataClasses.INTEGER,
+            lookupMethod("com.metamatrix.query.function.FunctionMethods", "plus", 2), false, true, FunctionMethod.DETERMINISTIC ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        UnitTestUtil.helpTestEquivalence(0, f1, f2);
+    }
+    
+    public void test3() throws Exception  {
+        FunctionDescriptor f1 = new FunctionDescriptor("+", FunctionMethod.CAN_PUSHDOWN,//$NON-NLS-1$
+            new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER },
+            DataTypeManager.DefaultDataClasses.INTEGER,
+            lookupMethod("com.metamatrix.query.function.FunctionMethods", "plus", 2), false, false, FunctionMethod.DETERMINISTIC ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        
+        FunctionDescriptor f2 = new FunctionDescriptor("+", FunctionMethod.CAN_PUSHDOWN,//$NON-NLS-1$
+            new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER },
+            DataTypeManager.DefaultDataClasses.INTEGER,
+            lookupMethod("com.metamatrix.query.function.FunctionMethods", "plus", 2), false, true, FunctionMethod.DETERMINISTIC ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        assertNotSame("objects should not be equal", f1, f2); //$NON-NLS-1$
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,1381 @@
+/*
+ * 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 org.teiid.query.function;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.NullType;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.core.util.TimestampWithTimezone;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.FunctionForm;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionMethods;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
+import org.teiid.resource.cci.SourceSystemFunctions;
+
+
+ at SuppressWarnings("nls")
+public class TestFunctionLibrary {
+
+	// These are just used as shorthand convenience to make unit tests more readable below
+	private static final Class<String> T_STRING = DataTypeManager.DefaultDataClasses.STRING;
+	private static final Class<Integer> T_INTEGER = DataTypeManager.DefaultDataClasses.INTEGER;
+	private static final Class<BigInteger> T_BIG_INTEGER = DataTypeManager.DefaultDataClasses.BIG_INTEGER;
+	private static final Class<BigDecimal> T_BIG_DECIMAL = DataTypeManager.DefaultDataClasses.BIG_DECIMAL;		
+    private static final Class<Long> T_LONG = DataTypeManager.DefaultDataClasses.LONG;
+	private static final Class<Float> T_FLOAT = DataTypeManager.DefaultDataClasses.FLOAT;
+    private static final Class<Double> T_DOUBLE = DataTypeManager.DefaultDataClasses.DOUBLE;
+	private static final Class<NullType> T_NULL = DataTypeManager.DefaultDataClasses.NULL;
+	private static final Class<Time> T_TIME = DataTypeManager.DefaultDataClasses.TIME;
+	private static final Class<Date> T_DATE = DataTypeManager.DefaultDataClasses.DATE;
+	private static final Class<Timestamp> T_TIMESTAMP = DataTypeManager.DefaultDataClasses.TIMESTAMP;
+	
+	private FunctionLibrary library = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(Collections.EMPTY_LIST)));
+
+	@Before public void setUp() { 
+		TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$ 
+	}
+	
+	@After public void tearDown() { 
+		TimestampWithTimezone.resetCalendar(null);
+	}
+	
+	// ################################## TEST HELPERS ################################
+	
+    private FunctionDescriptor helpCreateDescriptor(String name, Class[] types) { 
+        final String fname = name;
+        final Class[] ftypes = types;
+        return new FunctionDescriptor() {
+            public String getName() {
+                return fname;
+            }
+            public int getPushdown() {
+                return FunctionMethod.CAN_PUSHDOWN;
+            }
+            public Class[] getTypes() { 
+                return ftypes;
+            }
+            public Class getReturnType() { 
+                return null;
+            }
+            
+            public String toString() {
+                StringBuffer str = new StringBuffer(fname);
+                str.append("("); //$NON-NLS-1$
+                for(int i=0; i<ftypes.length; i++) {
+                    if(ftypes[i] != null) { 
+                        str.append(ftypes[i].getName());
+                    } else {
+                        str.append("null"); //$NON-NLS-1$
+                    }       
+                    if(i<(ftypes.length-1)) {
+                        str.append(", "); //$NON-NLS-1$
+                    }
+                }
+                return str.toString();
+            }
+            public boolean requiresContext() {
+                return false;
+            }
+            public boolean isNullDependent() {
+                return true;
+            }
+            
+        };
+    }
+    
+	private void helpFindFunction(String fname, Class[] types, FunctionDescriptor expected) {
+		FunctionDescriptor actual =  library.findFunction(fname, types);
+	
+        assertEquals("Function names do not match: ", expected.getName().toLowerCase(), actual.getName().toLowerCase());             //$NON-NLS-1$
+        assertEquals("Arg lengths do not match: ", expected.getTypes().length, actual.getTypes().length); //$NON-NLS-1$
+	}
+
+	private void helpFindFunctionFail(String fname, Class[] types) {
+		FunctionDescriptor actual =  library.findFunction(fname, types);
+		assertNull("Function was found but should not have been: " + actual, actual); //$NON-NLS-1$
+	}
+    
+	private void helpFindConversions(String fname, Class[] types, FunctionDescriptor[] expected) {
+
+		FunctionDescriptor[] actual = library.determineNecessaryConversions(fname, null, types, false);
+		
+		if(expected == null) {
+			if(actual != null) { 
+				fail("Expected to find no conversion for " + fname + Arrays.asList(types) + " but found: " + Arrays.asList(actual)); //$NON-NLS-1$ //$NON-NLS-2$
+			}	
+		} else {
+			if(actual == null) { 
+				fail("Expected to find conversion for " + fname + Arrays.asList(types) + " but found none"); //$NON-NLS-1$ //$NON-NLS-2$
+			} else {
+				// Compare returned descriptors with expected descriptor
+				for(int i=0; i<expected.length; i++) { 
+                    if(expected[i] == null) { 
+                        if(actual[i] != null) { 
+                            fail("Expected no conversion at index " + i + ", but found: " + actual[i]); //$NON-NLS-1$ //$NON-NLS-2$
+                        }
+                    } else {
+                        if(actual[i] == null) { 
+                            fail("Expected conversion at index " + i + ", but found none.");                             //$NON-NLS-1$ //$NON-NLS-2$
+                        } else {
+                            assertEquals("Expected conversion function names do not match: ", expected[i].getName(), actual[i].getName());             //$NON-NLS-1$
+                            assertEquals("Expected conversion arg lengths do not match: ", expected[i].getTypes().length, actual[i].getTypes().length);                         //$NON-NLS-1$
+                        }        
+                    }        
+				}			
+			}			
+		}
+	}	
+	
+	private void helpFindForm(String fname, int numArgs) {
+		FunctionForm form = library.findFunctionForm(fname, numArgs);
+        assertNotNull("Failed to find function '" + fname + "' with " + numArgs + " args", form); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        assertEquals("Function names do not match: ", fname.toUpperCase(), form.getName().toUpperCase());             //$NON-NLS-1$
+        assertEquals("Arg lengths do not match: ", numArgs, form.getArgNames().size()); //$NON-NLS-1$
+	}
+
+	private void helpInvokeMethod(String fname, Object[] inputs, Object expectedOutput) {
+        try {
+            helpInvokeMethod(fname, null, inputs, null, expectedOutput);
+        } catch (Exception err) {
+            throw new RuntimeException(err);
+        } 
+	}
+    
+    private void helpInvokeMethod(String fname, Class[] types, Object[] inputs, CommandContext context, Object expectedOutput) throws FunctionExecutionException {
+    	Object actualOutput = helpInvokeMethod(fname, types, inputs, context);
+        assertEquals("Actual function output not equal to expected: ", expectedOutput, actualOutput); //$NON-NLS-1$
+    }
+
+	private Object helpInvokeMethod(String fname, Class[] types,
+			Object[] inputs, CommandContext context)
+			throws FunctionExecutionException {
+		if (types == null) {
+            // Build type signature
+            types = new Class[inputs.length];
+            for(int i=0; i<inputs.length; i++) { 
+                types[i] = DataTypeManager.determineDataTypeClass(inputs[i]);   
+            }        
+    	}
+    	if (context == null) {
+    		context = new CommandContext();
+    	}
+        Object actualOutput = null;
+        // Find function descriptor
+        FunctionDescriptor descriptor = library.findFunction(fname, types);         
+        if (descriptor.requiresContext()) {
+            // Invoke function with inputs
+            Object[] in = new Object[inputs.length+1];
+            in[0] = context;
+            for (int i = 0; i < inputs.length; i++) {
+                in[i+1] = inputs[i];
+            }
+            actualOutput = descriptor.invokeFunction(in);
+        }
+        else {
+            // Invoke function with inputs
+            actualOutput = descriptor.invokeFunction(inputs);                
+        }
+		return actualOutput;
+	}
+    	    
+	private void helpInvokeMethodFail(String fname, Object[] inputs) {
+		   helpInvokeMethodFail(fname, null, inputs);
+	}	
+    	
+    private void helpInvokeMethodFail(String fname, Class<?> types[], Object[] inputs) {
+    	try {
+            helpInvokeMethod(fname, types, inputs, null);
+            fail("expected exception"); //$NON-NLS-1$
+        } catch (FunctionExecutionException err) {
+        }    
+    }    
+	// ################################## ACTUAL TESTS ################################
+	
+	@Test public void testFindFunction1() { 
+		helpFindFunction("convert", new Class[] { T_INTEGER, T_STRING }, //$NON-NLS-1$
+            helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING }) );
+	}
+	
+	@Test public void testFindFunction2() { 
+		helpFindFunction("cast", new Class[] { T_INTEGER, T_STRING }, //$NON-NLS-1$
+            helpCreateDescriptor(FunctionLibrary.CAST, new Class[] { T_INTEGER, T_STRING }) );
+	}
+	
+    @Test public void testFindFunction3() {
+        helpFindFunction("curdate", new Class[0], //$NON-NLS-1$
+        	helpCreateDescriptor("curdate", new Class[0])); //$NON-NLS-1$
+    }
+   
+    @Test public void testFindFunction4() {
+        helpFindFunctionFail("curdate", new Class[] { T_INTEGER }); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindFunction5() {
+        helpFindFunction("+", new Class[] { T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+        	helpCreateDescriptor("+", new Class[] { T_INTEGER, T_INTEGER }) ); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindFunction6() {
+        helpFindFunctionFail("+", new Class[] {T_INTEGER, T_FLOAT}); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindFunction7() {
+        helpFindFunctionFail("+", new Class[] {T_INTEGER, T_FLOAT, T_INTEGER}); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindFunction8() {
+        helpFindFunctionFail("+", new Class[] {T_INTEGER}); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindFunction9() {        
+		helpFindFunctionFail("+", new Class[] {T_INTEGER, T_NULL });     //$NON-NLS-1$
+    }
+
+    @Test public void testFindFunction10() {
+        helpFindFunction("substring", new Class[] { T_STRING, T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+            helpCreateDescriptor("substring", new Class[] { T_STRING, T_INTEGER, T_INTEGER }) ); //$NON-NLS-1$
+    }
+
+    @Test public void testFindFunction11() {
+        helpFindFunction("substring", new Class[] { T_STRING, T_INTEGER }, //$NON-NLS-1$
+            helpCreateDescriptor("substring", new Class[] { T_STRING, T_INTEGER }) ); //$NON-NLS-1$
+    }
+
+    @Test public void testFindFunction12() {
+        helpFindFunction("context", new Class[] { T_STRING, T_INTEGER }, //$NON-NLS-1$
+            helpCreateDescriptor("context", new Class[] { T_STRING, T_INTEGER }) ); //$NON-NLS-1$
+    }
+
+    @Test public void testFindFunction12a() {
+        helpFindFunction("rowlimit", new Class[] { T_STRING }, //$NON-NLS-1$
+            helpCreateDescriptor("rowlimit", new Class[] { T_STRING }) ); //$NON-NLS-1$
+    }
+
+    @Test public void testFindFunction12b() {
+        helpFindFunction("rowlimitexception", new Class[] { T_STRING }, //$NON-NLS-1$
+            helpCreateDescriptor("rowlimitexception", new Class[] { T_STRING }) ); //$NON-NLS-1$
+    }
+    
+	@Test public void testFind0ArgConversion1() { 	
+		helpFindConversions(
+			"curdate", new Class[] {}, //$NON-NLS-1$
+			new FunctionDescriptor[0] );
+	}
+
+	@Test public void testFind0ArgConversion2() { 	
+		helpFindConversions(
+			"curdate", new Class[] { T_INTEGER }, //$NON-NLS-1$
+			null );
+	}
+
+	@Test public void testFind1ArgConversion1() { 	
+		helpFindConversions(
+			"length", new Class[] { T_STRING }, //$NON-NLS-1$
+			new FunctionDescriptor[1] );
+	}
+
+	@Test public void testFind1ArgConversion2() { 	
+		helpFindConversions(
+			"length", new Class[] { T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+			    helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING })
+			} );
+	}
+
+	@Test public void testFind1ArgConversion3() { 	
+		helpFindConversions(
+			"length", new Class[] { DataTypeManager.DefaultDataClasses.TIMESTAMP }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+			    helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.TIMESTAMP, T_STRING })
+			} );
+	}
+
+	@Test public void testFind2ArgConversion1() { 	
+		helpFindConversions(
+			"+", new Class[] { T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[2] );
+	}
+
+	@Test public void testFind2ArgConversion2() { 	
+		helpFindConversions(
+			"+", new Class[] { T_INTEGER, T_FLOAT }, //$NON-NLS-1$
+			new FunctionDescriptor[] { 
+                helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING }), 
+                helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_FLOAT, T_STRING }) } );
+	}
+
+	@Test public void testFind2ArgConversion3() { 	
+		helpFindConversions(
+			"+", new Class[] { T_FLOAT, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] { 
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_FLOAT, T_STRING }), 
+                helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING }) } );
+	}
+
+	@Test public void testFind2ArgConversion4() { 	
+		helpFindConversions(
+			"+", new Class[] { T_STRING, T_FLOAT }, //$NON-NLS-1$
+			null );
+	}
+
+	@Test public void testFind2ArgConversion5() { 	
+		helpFindConversions(
+			"+", new Class[] { T_NULL, T_NULL }, //$NON-NLS-1$
+			new FunctionDescriptor[] { 
+			    helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }), 
+                helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }) } );
+	}
+
+	@Test public void testFind2ArgConversion6() { 	
+		helpFindConversions(
+			"+", new Class[] { T_NULL, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] { 
+			    helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }), 
+				null } );
+	}
+
+	@Test public void testFind2ArgConversion7() { 	
+		helpFindConversions(
+			"+", new Class[] { T_INTEGER, T_NULL }, //$NON-NLS-1$
+			new FunctionDescriptor[] { 
+			    null, 
+			    helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }) } );
+	}
+
+	@Test public void testFind3ArgConversion1() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_STRING, T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[3] );
+	}
+
+	@Test public void testFind3ArgConversion2() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_INTEGER, T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING }),
+				null,
+				null    
+			} );
+	}
+
+	@Test public void testFind3ArgConversion3() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_INTEGER, T_INTEGER, DataTypeManager.DefaultDataClasses.SHORT }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_INTEGER, T_STRING }),
+				null,
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.SHORT, T_STRING })    
+			} );
+	}
+
+	@Test public void testFind3ArgConversion4() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_STRING, T_INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP }, //$NON-NLS-1$
+			null );
+	}
+
+	@Test public void testFind3ArgConversion5() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_STRING, DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.SHORT }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+			    null,
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.SHORT, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.SHORT, T_STRING })    
+			} );
+	}
+
+	@Test public void testFind3ArgConversion6() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_INTEGER, DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.SHORT }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.SHORT, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { DataTypeManager.DefaultDataClasses.SHORT, T_STRING })    
+			} );
+	}
+
+	@Test public void testFind3ArgConversion7() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_NULL, T_INTEGER, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }),    
+				null,
+				null }
+			);
+	}
+
+	@Test public void testFind3ArgConversion8() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_NULL, T_NULL, T_INTEGER }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }),    
+				null }
+			);
+	}
+
+	@Test public void testFind3ArgConversion9() { 	
+		helpFindConversions(
+			"substring", new Class[] { T_NULL, T_NULL, T_NULL }, //$NON-NLS-1$
+			new FunctionDescriptor[] {
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }),    
+				helpCreateDescriptor(FunctionLibrary.CONVERT, new Class[] { T_NULL, T_STRING }) }
+			);
+	}
+
+    // Walk through all functions by metadata 
+    @Test public void testEnumerateForms() {
+        Collection categories = library.getFunctionCategories();
+        Iterator catIter = categories.iterator();
+        while(catIter.hasNext()) { 
+            String category = (String) catIter.next();
+            //System.out.println("Category: " + category);
+            
+            Collection functions = library.getFunctionForms(category);
+            Iterator functionIter = functions.iterator();
+            while(functionIter.hasNext()) { 
+                FunctionForm form = (FunctionForm) functionIter.next();
+                //System.out.println("\tFunction: " + form.getDisplayString());                
+                
+                // Lookup this form
+                helpFindForm(form.getName(), form.getArgNames().size());
+            }            
+        }        
+    }
+
+	@Test public void testFindForm1() { 
+		helpFindForm("convert", 2); //$NON-NLS-1$
+	}
+ 
+	@Test public void testFindForm2() { 
+		helpFindForm("locate", 2); //$NON-NLS-1$
+	}
+    
+	@Test public void testFindForm3() { 
+		helpFindForm("locate", 3); //$NON-NLS-1$
+	}
+
+    @Test public void testFindForm4() { 
+        helpFindForm("substring", 2); //$NON-NLS-1$
+    }
+    
+    @Test public void testFindForm5() { 
+        helpFindForm("substring", 3); //$NON-NLS-1$
+    }
+ 
+	@Test public void testFindForm6() { 
+		helpFindForm("now", 0); //$NON-NLS-1$
+	}
+    
+    @Test public void testInvokePlus1() { 
+    	helpInvokeMethod("+", new Object[] { new Integer(3), new Integer(2) }, new Integer(5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokePlus2() {
+        helpInvokeMethod("+", new Object[] { new Long(3), new Long(2) }, new Long(5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokePlus3() {
+        helpInvokeMethod("+", new Object[] { new Float(3), new Float(2) }, new Float(5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokePlus4() {
+        helpInvokeMethod("+", new Object[] { new Double(3), new Double(2) }, new Double(5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokePlus5() {
+        helpInvokeMethod("+", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("5")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokePlus6() {
+        helpInvokeMethod("+", new Object[] { new BigDecimal("3"), new BigDecimal("2") }, new BigDecimal("5")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeMinus1() {
+        helpInvokeMethod("-", new Object[] { new Integer(3), new Integer(2) }, new Integer(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMinus2() {
+        helpInvokeMethod("-", new Object[] { new Long(3), new Long(2) }, new Long(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMinus3() {
+        helpInvokeMethod("-", new Object[] { new Float(3), new Float(2) }, new Float(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMinus4() {
+        helpInvokeMethod("-", new Object[] { new Double(3), new Double(2) }, new Double(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMinus5() {
+        helpInvokeMethod("-", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeMinus6() {
+        helpInvokeMethod("-", new Object[] { new BigDecimal("3"), new BigDecimal("2") }, new BigDecimal("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeMultiply1() {
+        helpInvokeMethod("*", new Object[] { new Integer(3), new Integer(2) }, new Integer(6)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMultiply2() {
+        helpInvokeMethod("*", new Object[] { new Long(3), new Long(2) }, new Long(6)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMultiply3() {
+        helpInvokeMethod("*", new Object[] { new Float(3), new Float(2) }, new Float(6)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMultiply4() {
+        helpInvokeMethod("*", new Object[] { new Double(3), new Double(2) }, new Double(6)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeMultiply5() {
+        helpInvokeMethod("*", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("6")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeMultiply6() {
+        helpInvokeMethod("*", new Object[] { new BigDecimal("3"), new BigDecimal("2") }, new BigDecimal("6")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeDivide1() {
+        helpInvokeMethod("/", new Object[] { new Integer(3), new Integer(2) }, new Integer(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeDivide2() {
+        helpInvokeMethod("/", new Object[] { new Long(3), new Long(2) }, new Long(1)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeDivide3() {
+        helpInvokeMethod("/", new Object[] { new Float(3), new Float(2) }, new Float(1.5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeDivide4() {
+        helpInvokeMethod("/", new Object[] { new Double(3), new Double(2) }, new Double(1.5)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeDivide5() {
+        helpInvokeMethod("/", new Object[] { new BigInteger("3"), new BigInteger("2") }, new BigInteger("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    // one digit precision
+    @Test public void testInvokeDivide6() {
+        helpInvokeMethod("/", new Object[] { new BigDecimal("3"), new BigDecimal("2") }, new BigDecimal("2"));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testInvokeDivide7() throws Exception {
+        helpInvokeMethodFail("/", new Object[] { new Float("3"), new Float("0") });   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testInvokeDivideMod() {
+        helpInvokeMethod("mod", new Object[] { new BigDecimal("3.1"), new BigDecimal("2") }, new BigDecimal("1.1"));   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeAbs1() {
+        helpInvokeMethod("abs", new Object[] { new Integer(-3) }, new Integer(3)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeAbs2() {
+        helpInvokeMethod("abs", new Object[] { new Long(-3) }, new Long(3)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeAbs3() {
+        helpInvokeMethod("abs", new Object[] { new Float(-3) }, new Float(3)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeAbs4() {
+        helpInvokeMethod("abs", new Object[] { new Double(-3) }, new Double(3)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeAbs5() {
+        helpInvokeMethod("abs", new Object[] { new BigInteger("-3") }, new BigInteger("3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testInvokeAbs6() {
+        helpInvokeMethod("abs", new Object[] { new BigDecimal("-3") }, new BigDecimal("3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+	@Test public void testInvokeAcos() {
+		helpInvokeMethod("acos", new Object[] { new Double(0.05) }, new Double(1.5207754699891267)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeAsin() {
+		helpInvokeMethod("asin", new Object[] { new Double(0.05) }, new Double(0.050020856805770016)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeAtan() {
+		helpInvokeMethod("atan", new Object[] { new Double(0.05) }, new Double(0.049958395721942765)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeAtan2() {
+		helpInvokeMethod("atan2", new Object[] { new Double(0.05), new Double(0.07) }, new Double(0.6202494859828215)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeAtanBigDecimal() {
+		helpInvokeMethod("atan", new Object[] { new BigDecimal(0.05) }, new Double(0.049958395721942765)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeAtan2BigDecimal() {
+		helpInvokeMethod("atan2", new Object[] { new BigDecimal(0.05), new BigDecimal(0.07) }, new Double(0.6202494859828215)); //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeCos() {
+		helpInvokeMethod("cos", new Object[] { new Double(1.57) }, new Double(7.963267107332633E-4)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeCot() {
+		helpInvokeMethod("cot", new Object[] { new Double(1.57) }, new Double(7.963269632231926E-4)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeDegrees() {
+		helpInvokeMethod("degrees", new Object[] { new Double(1.57) }, new Double(89.95437383553926)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokePI() {
+		helpInvokeMethod("pi", new Object[] { }, new Double(3.141592653589793)); //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeRadians() {
+		helpInvokeMethod("radians", new Object[] { new Double(89.95437383553926) }, new Double(1.57)); //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeSin() {
+		helpInvokeMethod("sin", new Object[] { new Double(1.57) }, new Double(0.9999996829318346)); //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeTan() {
+		helpInvokeMethod("tan", new Object[] { new Double(0.785) }, new Double(0.9992039901050427)); //$NON-NLS-1$
+	}
+							
+    @Test public void testInvokeAscii() {
+        helpInvokeMethod("ascii", new Object[] { " " }, new Integer(32)); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testInvokeChr() {
+        helpInvokeMethod("chr", new Object[] { new Integer(32) }, new Character(' ')); //$NON-NLS-1$
+    }
+    
+    @Test public void testInvokeNvl() {
+        helpInvokeMethod("nvl", new Object[] { new Integer(5), new Integer(10) }, new Integer(5) ); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeConcatOperator() {
+        helpInvokeMethod("||", new Object[] { "a", "b" }, "ab" );         //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+
+    @Test public void testInvokeInitcap() {
+        helpInvokeMethod("initcap", new Object[] { "my test\ndata" }, "My Test\nData" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testInvokeLpad1() {
+        helpInvokeMethod("lpad", new Object[] { "x", new Integer(3) }, "  x" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testInvokeLpad2() {
+        helpInvokeMethod("lpad", new Object[] { "x", new Integer(3), "y" }, "yyx" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testInvokeRpad1() {
+        helpInvokeMethod("rpad", new Object[] { "x", new Integer(3) }, "x  " ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testInvokeRpad2() {
+        helpInvokeMethod("rpad", new Object[] { "x", new Integer(3), "y" }, "xyy" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+    }
+
+    @Test public void testInvokeTranslate() {
+        helpInvokeMethod("translate", new Object[] { "ababcd", "ad", "da" }, "dbdbca" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+    }
+    
+	@Test public void testFindFunction13() { 
+		helpFindFunction("formatTime", new Class[] { T_TIME, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatTime", new Class[] { T_TIME, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFunction14() { 
+		helpFindFunction("formatDate", new Class[] { T_DATE, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatDate", new Class[] { T_DATE, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFunction15() { 
+		helpFindFunction("formatTimestamp", new Class[] { T_TIMESTAMP, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatTimestamp", new Class[] { T_TIMESTAMP, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFunction16() { 
+		helpFindFunction("parseTime", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseTime", new Class[] { T_STRING, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFunction17() { 
+		helpFindFunction("parseDate", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseDate", new Class[] { T_STRING, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFunction18() { 
+		helpFindFunction("parseTimestamp", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+				helpCreateDescriptor("parseTimestamp", new Class[] { T_STRING, T_STRING }) ); //$NON-NLS-1$
+	}
+	
+    @Test public void testFindFunction19() {
+        helpFindFunction("env", new Class[] {T_STRING}, //$NON-NLS-1$
+                         helpCreateDescriptor("env", new Class[] {T_STRING})); //$NON-NLS-1$
+    }
+
+	@Test public void testInvokeFormatTimestamp1() {
+		helpInvokeMethod("formatTimestamp", new Object[] {TimestampUtil.createTimestamp(103, 2, 5, 3, 4, 12, 255), new String("mm/dd/yy h:mm a") }, "04/05/03 3:04 AM");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatTimestamp2() {
+		helpInvokeMethod("formatTimestamp", new Object[] {TimestampUtil.createTimestamp(103, 2, 5, 3, 4, 12, 255), new String("yyyy-mm-dd k:mm a z") }, "2003-04-05 3:04 AM GMT-06:00");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatTimestamp3() {
+			helpInvokeMethod("formatTimestamp", new Object[] {TimestampUtil.createTimestamp(103, 2, 5, 3, 4, 12, 255), new String("yyyy-mm-dd hh:mm:ss.SSSS") }, "2003-04-05 03:04:12.0000");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+		
+	@Test public void testInvokeFormatTimestampFail() throws Exception {
+		helpInvokeMethodFail("formatTimestamp", new Object[] {TimestampUtil.createTimestamp(103, 2, 5, 3, 4, 12, 255), new String("mm/dd/nn h:mm a") }); //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeParseTimestamp1() {
+		helpInvokeMethod("parseTimestamp", new Object[] {new String("05 Mar 2003 03:12:23 CST"), new String("dd MMM yyyy HH:mm:ss z") }, TimestampUtil.createTimestamp(103, 2, 5, 3, 12, 23, 0));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeParseTimestamp2() {
+		helpInvokeMethod("parseTimestamp", new Object[] {new String("05 Mar 2003 03:12:23.333"), new String("dd MMM yyyy HH:mm:ss.SSS") }, TimestampUtil.createTimestamp(103, 2, 5, 3, 12, 23, 333*1000000));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+
+	@Test public void testFindFormatInteger() { 
+		helpFindFunction("formatInteger", new Class[] { T_INTEGER, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatInteger", new Class[] { T_INTEGER, T_STRING}) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFormatFloat() { 
+		helpFindFunction("formatFloat", new Class[] { T_FLOAT, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatFloat", new Class[] { T_FLOAT, T_STRING}) ); //$NON-NLS-1$
+	}
+
+	@Test public void testFindFormatDouble() { 
+		helpFindFunction("formatDouble", new Class[] { T_DOUBLE, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatDouble", new Class[] { T_DOUBLE, T_STRING}) ); //$NON-NLS-1$
+	}
+		
+	@Test public void testFindFormatLong() { 
+		helpFindFunction("formatLong", new Class[] { T_LONG, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatLong", new Class[] { T_LONG, T_STRING}) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindFormatBigInteger() { 
+		helpFindFunction("formatBigInteger", new Class[] { T_BIG_INTEGER, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatBigInteger", new Class[] { T_BIG_INTEGER, T_STRING}) ); //$NON-NLS-1$
+	}
+
+	@Test public void testFindFormatBigDecimal() { 
+		helpFindFunction("formatBigDecimal", new Class[] { T_BIG_DECIMAL, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("formatBigDecimal", new Class[] { T_BIG_DECIMAL, T_STRING}) ); //$NON-NLS-1$
+	}
+			
+	@Test public void testFindParseInteger() { 
+		helpFindFunction("parseInteger", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseInteger", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindParseLong() { 
+		helpFindFunction("parseLong", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseLong", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}
+
+	@Test public void testFindParseDouble() { 
+		helpFindFunction("parseDouble", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseDouble", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}	
+	@Test public void testFindParseFloat() { 
+		helpFindFunction("parseFloat", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseFloat", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}
+	
+	@Test public void testFindParseBigInteger() { 
+		helpFindFunction("parseBigInteger", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseBigInteger", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}
+
+	@Test public void testFindParseBigDecimal() { 
+		helpFindFunction("parseBigDecimal", new Class[] { T_STRING, T_STRING }, //$NON-NLS-1$
+			helpCreateDescriptor("parseBigDecimal", new Class[] { T_STRING, T_STRING}) ); //$NON-NLS-1$
+	}	
+			
+	@Test public void testInvokeParseInteger() {
+		helpInvokeMethod("parseInteger", new Object[] {new String("-1234"), new String("######")}, new Integer(-1234));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeParseLong() {
+		helpInvokeMethod("parseLong", new Object[] {new String("123456"), new String("######.##")}, new Long(123456));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeParseDouble() {
+		helpInvokeMethod("parseDouble", new Object[] {new String("123456.78"), new String("#####.#")}, new Double(123456.78));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeParseFloat() {
+		helpInvokeMethod("parseFloat", new Object[] {new String("1234.56"), new String("####.###")}, new Float(1234.56));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeParseBigInteger() {
+		helpInvokeMethod("parseBigInteger", new Object[] {new String("12345678"), new String("###,###")}, new BigInteger("12345678"));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	}
+	
+	@Test public void testInvokeParseBigDecimal() {
+		helpInvokeMethod("parseBigDecimal", new Object[] {new String("1234.56"), new String("#####")}, new BigDecimal("1234.56"));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	}
+
+	@Test public void testInvokeFormatInteger() {
+		helpInvokeMethod("formatInteger", new Object[] {new Integer(-1234), new String("######")}, "-1234");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatLong() {
+		helpInvokeMethod("formatLong", new Object[] {new Long(123456788), new String("##,###,#")}, "1,2,3,4,5,6,7,8,8");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatDouble() {
+		helpInvokeMethod("formatDouble", new Object[] {new Double(1234.67), new String("####.##")}, "1234.67");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatFloat() {
+		helpInvokeMethod("formatFloat", new Object[] {new Float(1234.67), new String("###.###")}, "1234.67");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeFormatBigInteger() {
+		helpInvokeMethod("formatBigInteger", new Object[] {new BigInteger("45"), new String("###.###")}, "45");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	}
+	
+	@Test public void testInvokeFormatBigDecimal() {
+		helpInvokeMethod("formatBigDecimal", new Object[] {new BigDecimal("1234.56"), new String("###.###")}, "1234.56");	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	}	
+
+	@Test public void testInvokeQuarter1() {
+		//		2003-5-15
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 4, 15)}, new Integer(2));	 //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeQuarter2() {
+		//		2003-5-1
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 3, 31)}, new Integer(2));	 //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeQuarter3() {
+		//		2003-1-31
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 0, 31)}, new Integer(1));	 //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeQuarter4() {
+	//		2003-9-30
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 8, 30)}, new Integer(3));	 //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeQuarter5() {
+	//		2003-12-31
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 11, 31)}, new Integer(4));	 //$NON-NLS-1$
+	}		
+	
+	@Test public void testInvokeQuarter6() {
+		//bad date such as 2003-13-45
+		helpInvokeMethod("quarter", new Object[] {TimestampUtil.createDate(103, 12, 45)}, new Integer(1));	 //$NON-NLS-1$
+	}
+	
+	@Test public void testInvokeIfNull() {
+		helpInvokeMethod("ifnull", new Object[] {new Integer(5), new Integer(10)}, new Integer(5));	 //$NON-NLS-1$
+	}
+
+	@Test public void testInvokeLower() {
+		helpInvokeMethod("lower", new Object[] {new String("LOWER")}, new String("lower"));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+	
+	@Test public void testInvokeUpper() {
+		helpInvokeMethod("upper", new Object[] {new String("upper")}, new String("UPPER"));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+
+	@Test public void testInvokeRepeat() {
+		helpInvokeMethod("repeat", new Object[] {new String("cat"), new Integer(3)}, new String("catcatcat"));	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+	}
+
+	@Test public void testInvokeChar() {
+		helpInvokeMethod("char", new Object[] {new Integer(32) }, new Character(' ')); //$NON-NLS-1$
+	}
+
+	/** normal input */
+	@Test public void testInvokeInsert1() {
+		helpInvokeMethod("insert", new Object[] {new String("Downtown"), new Integer(4),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(2), new String("cat")}, new String("Dowcatown"));	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/** empty string2 */	
+	@Test public void testInvokeInsert2() {
+		helpInvokeMethod("insert", new Object[] {new String("Downtown"), new Integer(4),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(2), new String("")}, new String("Dowown"));	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/** empty string1 with start = 1 and length = 0, so result is just string2 */	
+	@Test public void testInvokeInsert3() {
+		helpInvokeMethod("insert", new Object[] {new String(""), new Integer(1),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(0), new String("cat")}, new String("cat"));	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/** should fail, with start > string1.length() */
+	@Test public void testInvokeInsert4() throws Exception {
+		helpInvokeMethodFail("insert", new Object[] {new String(""), new Integer(2),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(0), new String("cat")}); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/** should fail, with length > 0 and input string1.length() = 0 */
+	@Test public void testInvokeInsert5() throws Exception {
+		helpInvokeMethodFail("insert", new Object[] {new String(""), new Integer(1),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(1), new String("cat")});	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/**  (length + start) > string1.length(), then just append str2 starting at start position */
+	@Test public void testInvokeInsert6() {
+		helpInvokeMethod("insert", new Object[] {new String("Downtown"), new Integer(7),  //$NON-NLS-1$ //$NON-NLS-2$
+			new Integer(5), new String("cat")}, new String("Downtocat"));	 //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+    @Test public void testInvokeTimestampAddDate_ignore_case() {
+        helpInvokeMethod("timestampAdd", new Object[] {"sql_TSI_day",  //$NON-NLS-1$ //$NON-NLS-2$
+            new Integer(28), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(103, 5, 12).getTime()));    
+    }   
+    
+	/** date + month --> count=18, inteval=month, result should be 2004-11-15 */
+	@Test public void testInvokeTimestampAddDate2() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MONTH,  //$NON-NLS-1$
+			new Integer(18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(104, 10, 15).getTime()));	
+	}
+
+	/** date + month --> count=-18, inteval=month, result should be 2001-11-15 */
+	@Test public void testInvokeTimestampAddDate2a() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MONTH,  //$NON-NLS-1$
+			new Integer(-18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(101, 10, 15).getTime()));	
+	}
+	
+	/** date + week --> count=6, inteval=week, result should be 2003-04-03 */
+	@Test public void testInvokeTimestampAddDate3() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_WEEK,  //$NON-NLS-1$
+			new Integer(-6), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(103, 3, 3).getTime()));	
+	}
+
+	/** date + quarter --> count=3, inteval=quarter, result should be 2004-2-15 */
+	@Test public void testInvokeTimestampAddDate4() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_QUARTER,  //$NON-NLS-1$
+			new Integer(3), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(104, 1, 15).getTime()));	
+	}
+
+	/** date + year --> count=-1, inteval=year, result should be 2002-5-15 */
+	@Test public void testInvokeTimestampAddDate5() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_YEAR,  //$NON-NLS-1$
+			new Integer(-1), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(102, 4, 15).getTime()));	
+	}
+			
+	/** time + minute --> count=23, inteval=3, result should be 03:32:12 */
+	@Test public void testInvokeTimestampAddTime1() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MINUTE,  //$NON-NLS-1$
+			new Integer(23), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new Timestamp(TimestampUtil.createTime(3, 32, 12).getTime()));	
+	}
+
+	/** time + hour --> count=21, inteval=4, result should be 00:09:12 and overflow */
+	@Test public void testInvokeTimestampAddTime2() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_HOUR,  //$NON-NLS-1$
+			new Integer(21), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, TimestampUtil.createTimestamp(70, 0, 2, 0, 9, 12, 0));	
+	}
+
+	/** time + hour --> count=2, inteval=4, result should be 01:12:12*/
+	@Test public void testInvokeTimestampAddTime3() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_HOUR,  //$NON-NLS-1$
+			new Integer(2), new Timestamp(TimestampUtil.createTime(23, 12, 12).getTime())}, TimestampUtil.createTimestamp(70, 0, 2, 1, 12, 12, 0));	
+	}
+	
+	/** time + second --> count=23, inteval=2, result should be 03:10:01 */
+	@Test public void testInvokeTimestampAddTime4() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_SECOND,  //$NON-NLS-1$
+			new Integer(49), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new Timestamp(TimestampUtil.createTime(3, 10, 1).getTime()));	
+	}
+
+	/** timestamp + second --> count=23, inteval=2, result should be 2003-05-15 03:09:35.100  */
+	@Test public void testInvokeTimestampAddTimestamp1() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_SECOND,  //$NON-NLS-1$
+			new Integer(23), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 100)}, 
+			TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 35, 100));	
+	}
+
+	/** timestamp + nanos --> count=1, inteval=1, result should be 2003-05-15 03:09:12.000000101  */
+	@Test public void testInvokeTimestampAddTimestamp2() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND,  //$NON-NLS-1$
+			new Integer(1), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 100)}, 
+			TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 101));	
+	}
+
+	/** timestamp + nanos --> count=2100000000, inteval=1, result should be 2003-05-15 03:10:01.100000003
+	 *  with increase in second and minutes, because second already at 59 sec originally
+	 */
+	@Test public void testInvokeTimestampAddTimestamp3() {
+		helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND,  //$NON-NLS-1$
+			new Integer(2100000000), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 59, 1)}, 
+			TimestampUtil.createTimestamp(103, 4, 15, 3, 10, 1, 100000003));	
+	}
+			
+	/** time --> interval=hour, time1 = 03:04:45, time2= 05:05:36 return = 2  */
+	@Test public void testInvokeTimestampDiffTime1() {
+		helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_HOUR,  //$NON-NLS-1$
+				new Timestamp(TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(TimestampUtil.createTime(5, 5, 36).getTime()) }, 
+			new Long(2));	
+	}
+	
+    @Test public void testInvokeTimestampDiffTime1_ignorecase() {
+        helpInvokeMethod("timestampDiff", new Object[] {"SQL_tsi_HOUR",  //$NON-NLS-1$ //$NON-NLS-2$
+        		new Timestamp(TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(TimestampUtil.createTime(5, 5, 36).getTime()) }, 
+            new Long(2));   
+    }
+    
+	/** 
+	 * timestamp --> interval=week, time1 = 2002-06-21 03:09:35.100,
+	 * time2= 2003-05-02 05:19:35.500 return = 45
+	 */
+	@Test public void testInvokeTimestampDiffTimestamp1() {
+		helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_WEEK,  //$NON-NLS-1$
+			TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 100), TimestampUtil.createTimestamp(103, 4, 2, 5, 19, 35, 500) }, 
+			new Long(45));	
+	}
+
+    /** 
+     * timestamp --> interval=frac_second, time1 = 2002-06-21 03:09:35.000000001,
+     * time2= 2002-06-21 03:09:35.100000000 return = 999999999
+     */
+    @Test public void testInvokeTimestampDiffTimestamp2() {
+        helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND,  //$NON-NLS-1$
+            TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 1), TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 100000000) }, 
+            new Long(99999999));  
+    }
+
+    /** 
+     * timestamp --> interval=frac_second, time1 = 2002-06-21 03:09:35.000000002,
+     * time2= 2002-06-22 03:09:35.000000001 return = 
+     */
+    @Test public void testInvokeTimestampDiffTimestamp3() {
+        helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND,  //$NON-NLS-1$
+            TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 2), TimestampUtil.createTimestamp(102, 5, 22, 3, 9, 35, 1) }, 
+            new Long(86399999999999L));  
+    }
+
+    @Test public void testInvokeTimestampCreate1() {
+        helpInvokeMethod("timestampCreate", new Object[] {TimestampUtil.createDate(103, 4, 15), //$NON-NLS-1$
+                                                          TimestampUtil.createTime(23, 59, 59)},
+                                                          TimestampUtil.createTimestamp(103, 4, 15, 23, 59, 59, 0));    
+    }   
+    
+    @Test public void testInvokeBitand() {
+        helpInvokeMethod("bitand", new Object[] {new Integer(0xFFF), new Integer(0x0F0)}, new Integer(0x0F0)); //$NON-NLS-1$
+    }
+    @Test public void testInvokeBitor() {
+        helpInvokeMethod("bitor", new Object[] {new Integer(0xFFF), new Integer(0x0F0)}, new Integer(0xFFF)); //$NON-NLS-1$
+    }
+    @Test public void testInvokeBitxor() {
+        helpInvokeMethod("bitxor", new Object[] {new Integer(0xFFF), new Integer(0x0F0)}, new Integer(0xF0F)); //$NON-NLS-1$
+    }
+    @Test public void testInvokeBitnot() {
+        helpInvokeMethod("bitnot", new Object[] {new Integer(0xF0F)}, new Integer(0xFFFFF0F0)); //$NON-NLS-1$
+    }
+    
+    @Test public void testInvokeRound1() {
+        helpInvokeMethod("round", new Object[] {new Integer(123), new Integer(-1)}, new Integer(120)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeRound2() {
+        helpInvokeMethod("round", new Object[] {new Float(123.456), new Integer(2)}, new Float(123.46)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeRound3() {
+        helpInvokeMethod("round", new Object[] {new Double(123.456), new Integer(2)}, new Double(123.46)); //$NON-NLS-1$
+    }
+
+    @Test public void testInvokeRound4() {
+        helpInvokeMethod("round", new Object[] {new BigDecimal("123.456"), new Integer(2)}, new BigDecimal("123.460")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    /** defect 10941 */
+    @Test public void testInvokeConvertTime() {
+        helpInvokeMethod("convert", new Object[] {"05:00:00", "time"}, TimestampUtil.createTime(5, 0, 0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$                    
+    }
+
+    @Test public void testInvokeXpath1() {
+        helpInvokeMethod("xpathValue",  //$NON-NLS-1$
+                         new Object[] {
+                                       "<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>", //$NON-NLS-1$
+                                       "a/b/c"}, //$NON-NLS-1$ 
+                         "test"); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeXpathWithNill() {
+        helpInvokeMethod("xpathValue",  //$NON-NLS-1$
+                         new Object[] {
+                                       "<?xml version=\"1.0\" encoding=\"utf-8\" ?><a xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><b xsi:nil=\"true\"/></a>", //$NON-NLS-1$
+                                       "//*[local-name()='b' and not(@*[local-name()='nil' and string()='true'])]"}, //$NON-NLS-1$ 
+                         null);
+    }
+    
+    @Test public void testInvokeXpathWithNill1() {
+        helpInvokeMethod("xpathValue",  //$NON-NLS-1$
+                         new Object[] {
+                                       "<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b>value</b></a>", //$NON-NLS-1$
+                                       "//*[local-name()='b' and not(@*[local-name()='nil' and string()='true'])]"}, //$NON-NLS-1$ 
+                         "value"); //$NON-NLS-1$
+    }
+    
+    @Test public void testInvokeModifyTimeZone() {
+        Timestamp ts = Timestamp.valueOf("2004-10-03 23:59:59.123"); //$NON-NLS-1$
+        Timestamp out = Timestamp.valueOf("2004-10-03 22:59:59.123"); //$NON-NLS-1$
+        helpInvokeMethod("modifyTimeZone", new Object[] {ts, "America/Chicago", "America/New_York" }, out); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    // TimestampWithTimezone has a static copy the default timezone object which makes this test not execute properly
+    public void defer_testInvokeModifyTimeZoneFromLocal() {
+        Timestamp ts = Timestamp.valueOf("2004-10-03 23:59:59.123"); //$NON-NLS-1$
+        Timestamp out = Timestamp.valueOf("2004-10-03 21:59:59.123"); //$NON-NLS-1$
+        helpInvokeMethod("modifyTimeZone", new Object[] {ts, "America/New_York" }, out); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testInvokeRand() throws Exception {
+        helpInvokeMethod("rand", new Object[] {new Integer(100)}, new Double(0.7220096548596434)); //$NON-NLS-1$ 
+        // this does not actually fail but returns a result
+        assertNotNull(helpInvokeMethod("rand", new Class[] {Integer.class}, new Object[] {null}, null)); //$NON-NLS-1$
+    }
+    
+    @Test public void testInvokeUser() throws Exception {
+        CommandContext c = new CommandContext();
+        c.setUserName("foodude"); //$NON-NLS-1$
+        helpInvokeMethod("user", new Class[] {}, new Object[] {}, c, "foodude"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testInvokeEnv() throws Exception {
+        CommandContext c = new CommandContext();
+        Properties props = new Properties();
+        props.setProperty("env_test", "env_value"); //$NON-NLS-1$ //$NON-NLS-2$
+        c.setEnvironmentProperties(props);
+        helpInvokeMethod("env", new Class[] {String.class}, new Object[] {"env_test"}, c, "env_value"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$        
+        helpInvokeMethod("env", new Class[] {String.class}, new Object[] {null}, c, null); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeCommandPayload() throws Exception {
+        CommandContext c = new CommandContext();        
+        c.setCommandPayload("payload_too heavy"); //$NON-NLS-1$
+        helpInvokeMethod("commandpayload", new Class[] {}, new Object[] {}, c, "payload_too heavy"); //$NON-NLS-1$ //$NON-NLS-2$ 
+        helpInvokeMethod("commandpayload", new Class[] {String.class}, new Object[] {null}, c, null); //$NON-NLS-1$ 
+        Properties props = new Properties();
+        props.setProperty("payload", "payload_too heavy"); //$NON-NLS-1$ //$NON-NLS-2$
+        c.setCommandPayload(props);
+        helpInvokeMethod("commandpayload", new Class[] {String.class}, new Object[] {"payload"}, c, "payload_too heavy"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }    
+    
+    @Test public void testNullDependent() {
+        FunctionDescriptor actual = library.findFunction("concat2", new Class[] {String.class, String.class}); //$NON-NLS-1$
+        assertTrue(actual.isNullDependent());
+        
+        actual = library.findFunction("concat", new Class[] {String.class, String.class}); //$NON-NLS-1$
+        assertFalse(actual.isNullDependent());
+    }
+    
+    @Test public void testInvokeCeiling() {
+        helpInvokeMethod("ceiling", new Object[] { new Double("3.14") }, new Double("4")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeFloor() {
+        helpInvokeMethod("floor", new Object[] { new Double("3.14") }, new Double("3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeExp() {
+        helpInvokeMethod("exp", new Object[] { new Double("0") }, new Double("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeLog() {
+        helpInvokeMethod("log", new Object[] { new Double("1") }, new Double("0")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeLog10() {
+        helpInvokeMethod("log10", new Object[] { new Double("10") }, new Double("1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeLog10Error() throws Exception {
+        helpInvokeMethodFail("log10", new Object[] { new Double("0") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokePower() {
+        helpInvokeMethod("power", new Object[] { new Double("10"), new Double("2") }, new Double("100")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    }
+    
+    @Test public void testInvokePower1() {
+        helpInvokeMethod("power", new Object[] { new BigDecimal("10"), new Integer(2) }, new BigDecimal("100")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeSqrt() {
+        helpInvokeMethod("sqrt", new Object[] { new Double("4")}, new Double("2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+    
+    @Test public void testInvokeDayName() {
+        for (int i = 0; i < FunctionMethods.dayNames.length; i++) {
+            Date time = TimestampUtil.createDate(100, 0, i + 2);
+            helpInvokeMethod("dayName", new Object[] { time }, FunctionMethods.dayNames[i]); //$NON-NLS-1$ 
+        }
+    }
+    
+    @Test public void testInvokeDayOfMonth() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("dayOfMonth", new Object[] { time }, new Integer(1)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeDayOfWeek() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("dayOfWeek", new Object[] { time }, new Integer(7)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeDayOfYear() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 2, 1, 2, 3, 4);
+        helpInvokeMethod("dayOfYear", new Object[] { time }, new Integer(2)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeMonth() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("month", new Object[] { time }, new Integer(1)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeMonthName() {
+        for (int i = 0; i < FunctionMethods.monthNames.length; i++) {
+            Date time = TimestampUtil.createDate(100, i, 1);
+            helpInvokeMethod("monthName", new Object[] { time }, FunctionMethods.monthNames[i]); //$NON-NLS-1$ 
+        }
+    }
+    
+    @Test public void testInvokeMinute() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("minute", new Object[] { time }, new Integer(2)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeSecond() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("second", new Object[] { time }, new Integer(3)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeWeek() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("week", new Object[] { time }, new Integer(1)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeYear() {
+        Timestamp time = TimestampUtil.createTimestamp(100, 0, 1, 1, 2, 3, 4);
+        helpInvokeMethod("year", new Object[] { time }, new Integer(2000)); //$NON-NLS-1$ 
+    }
+    
+    @Test public void testInvokeCoalesce() {
+    	helpInvokeMethod(FunctionLibrary.COALESCE, new Object[] { Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2) }, Integer.valueOf(0));
+    }
+    
+    @Test public void testInvokeCoalesce1() {
+    	helpInvokeMethod(FunctionLibrary.COALESCE, new Object[] { null, null}, null);
+    }
+    
+    @Test public void testInvokeNull() throws Exception {
+        helpInvokeMethod(SourceSystemFunctions.LTRIM, new Class[] {DataTypeManager.DefaultDataClasses.STRING}, new Object[] { null }, null, null);  
+    }
+    
+    @Test public void testInvokeNull1() throws Exception {
+        helpInvokeMethod(SourceSystemFunctions.CONCAT, new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING}, new Object[] { null, String.valueOf(1) }, null, null);  
+    }  
+    
+	@Test public void testInvokeXslTransform() throws Exception {
+        CommandContext c = new CommandContext();
+        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+        ClobType result = (ClobType)helpInvokeMethod("xsltransform", new Class[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML}, 
+        		new Object[] {DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML), 
+        		DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.XML)}, c);
+        
+        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml);
+    }
+	
+	@Test public void testInvokeXmlConcat() throws Exception {
+        CommandContext c = new CommandContext();
+        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+        XMLType result = (XMLType)helpInvokeMethod("xmlconcat", new Class[] {DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML}, 
+        		new Object[] {DataTypeManager.transformValue("<bar/>", DataTypeManager.DefaultDataClasses.XML), DataTypeManager.transformValue("<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML)}, c);
+        
+        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+        assertEquals("<bar/><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", xml);
+    }
+	
+	@Test public void testInvokeXmlComment() throws Exception {
+        CommandContext c = new CommandContext();
+        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+        XMLType result = (XMLType)helpInvokeMethod("xmlcomment", new Class[] {DataTypeManager.DefaultDataClasses.STRING}, 
+        		new Object[] {"comment"}, c);
+        
+        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+        assertEquals("<!--comment-->", xml);
+    }
+	
+	@Test public void testInvokeXpathQuery() throws Exception {
+        CommandContext c = new CommandContext();
+        c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+        XMLType result = (XMLType)helpInvokeMethod("xpathquery", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING}, 
+        		new Object[] {"<foo><bar>1</bar><bar>2</bar></foo>", "/foo/bar"}, c);
+        
+        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+        assertEquals("<bar>1</bar><bar>2</bar>", xml);
+    }
+	
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionMetadataReader.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionMetadataReader.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionMetadataReader.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionMetadataReader.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,100 @@
+/*
+ * 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 org.teiid.query.function;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.function.metadata.FunctionMetadataReader;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.function.metadata.FunctionParameter;
+
+
+import junit.framework.TestCase;
+
+public class TestFunctionMetadataReader extends TestCase {
+
+	public void testLoadFunctionMethods() throws Exception {
+		
+		List<FunctionMethod>  fns = FunctionMetadataReader.loadFunctionMethods(new FileInputStream(UnitTestUtil.getTestDataPath()+File.separator+"udf.xmi"));
+		
+		assertEquals(3, fns.size());
+		
+		for (FunctionMethod m:fns) {
+			if (m.getName().equals("GetSystemProperty")) {
+				assertEquals("MyFunctions", m.getCategory());
+				assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
+				assertEquals("getProperty", m.getInvocationMethod());
+				assertEquals(FunctionMethod.CAN_PUSHDOWN, m.getPushdown());
+				assertEquals(FunctionMethod.DETERMINISTIC, m.getDeterministic());
+				assertNull(m.getDescription());
+				
+				assertEquals(1, m.getInputParameterCount());
+				FunctionParameter in = m.getInputParameters()[0];
+				assertEquals("prop", in.getName());
+				assertEquals("string", in.getType());
+				assertNull(in.getDescription());
+				
+				assertNotNull(m.getOutputParameter());
+				assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
+				assertEquals("string", m.getOutputParameter().getType());
+				
+			}
+			else if (m.getName().equals("getpushdown")) {
+				assertEquals("MyFunctions", m.getCategory());
+				assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
+				assertEquals("getPropertyNoArgs", m.getInvocationMethod());
+				assertEquals(FunctionMethod.CANNOT_PUSHDOWN, m.getPushdown());
+				assertEquals(FunctionMethod.DETERMINISTIC, m.getDeterministic());
+				assertNull(m.getDescription());
+				
+				assertEquals(0, m.getInputParameterCount());
+				
+				assertNotNull(m.getOutputParameter());
+				assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
+				assertEquals("string", m.getOutputParameter().getType());				
+			}
+			else if (m.getName().equals("getxyz")) {
+				assertEquals("MyFunctions", m.getCategory());
+				assertEquals("com.metamatrix.dqp.embedded.udf.MyFunctions", m.getInvocationClass());
+				assertEquals("getPropertyNoArgs", m.getInvocationMethod());
+				assertEquals(FunctionMethod.CAN_PUSHDOWN, m.getPushdown());
+				assertEquals(FunctionMethod.NONDETERMINISTIC, m.getDeterministic());
+				assertNull(m.getDescription());
+				
+				assertEquals(0, m.getInputParameterCount());
+				
+				assertNotNull(m.getOutputParameter());
+				assertEquals(FunctionParameter.OUTPUT_PARAMETER_NAME, m.getOutputParameter().getName());
+				assertEquals("string", m.getOutputParameter().getType());
+			}
+			else {
+				fail("unknown method");
+			}
+		}
+		
+	}
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionTree.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionTree.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,161 @@
+/*
+ * 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 org.teiid.query.function;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.mockito.Mockito;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.logging.LogManager;
+import org.teiid.query.function.FunctionForm;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionMetadataSource;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.function.metadata.FunctionCategoryConstants;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.function.metadata.FunctionParameter;
+import org.teiid.query.function.source.SystemSource;
+
+
+public class TestFunctionTree extends TestCase {
+
+	// ################################## FRAMEWORK ################################
+	
+	public TestFunctionTree(String name) { 
+		super(name);		
+	}	
+	
+	// ################################## TEST HELPERS ################################
+	
+	// ################################## ACTUAL TESTS ################################
+	
+    /** 
+     * Walk through all functions by metadata and verify that we can look 
+     * each one up by signature
+     */
+    public void testWalkTree() {
+        SystemSource source = new SystemSource();
+        FunctionTree ft = new FunctionTree(source);
+        
+        Collection categories = ft.getCategories();
+        Iterator catIter = categories.iterator();
+        while(catIter.hasNext()) { 
+            String category = (String) catIter.next();
+            LogManager.logInfo("test", "Category: " + category); //$NON-NLS-1$ //$NON-NLS-2$
+            
+            Collection functions = ft.getFunctionForms(category);
+            Iterator functionIter = functions.iterator();
+            while(functionIter.hasNext()) { 
+                FunctionForm form = (FunctionForm) functionIter.next();
+                LogManager.logInfo("test", "\tFunction: " + form.getDisplayString());                 //$NON-NLS-1$ //$NON-NLS-2$
+            }            
+        }        
+    }
+    
+    /**
+     * Test what happens when a function is loaded that does not have a class in the
+     * classpath.  This *should* be ok as long as the function is not invoked.
+     */
+    public void testUnloadableFunction() { 
+        // Create dummy source
+    	FunctionMetadataSource dummySource = new FunctionMetadataSource() {
+    	 	public Collection getFunctionMethods() {
+    	 	    // Build dummy method
+    	 	    FunctionMethod method = new FunctionMethod(
+    	 	    	"dummy", null, "no category", "nonexistentClass", "noMethod",  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    	 	    	new FunctionParameter[0], 
+    	 	    	new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING) ); //$NON-NLS-1$
+
+    	 	    // Wrap method in a list 
+    	 		List methods = new ArrayList();
+    	 		methods.add(method);
+    	 		return methods;    
+    	 	}  
+    	 	
+    	 	public Class getInvocationClass(String className) throws ClassNotFoundException { 
+    	 	    throw new ClassNotFoundException("Could not find class " + className); //$NON-NLS-1$
+    	 	}
+    	};	 
+    	
+    	new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(dummySource.getFunctionMethods())));
+    }
+    
+    public void testNullCategory() {
+    	FunctionMetadataSource fms = Mockito.mock(FunctionMetadataSource.class);
+    	Mockito.stub(fms.getFunctionMethods()).toReturn(Arrays.asList(new FunctionMethod(
+    			"dummy", null, null, FunctionMethod.MUST_PUSHDOWN, "nonexistentClass", "noMethod",  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+	 	    	new FunctionParameter[0], 
+	 	    	new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING) //$NON-NLS-1$
+    	)));
+    	FunctionTree ft = new FunctionTree(fms);
+    	assertEquals(1, ft.getFunctionForms(FunctionCategoryConstants.MISCELLANEOUS).size());
+    }
+	
+/*
+
+//DEBUGGING CODE - this will print out the tree root in readable form
+//(This code will either have to be pasted in to FunctionTree class, or
+//somehow the Map treeRoot must be gotten from the FunctionTree)
+
+    private static void debugPrintTreeRoot(Map treeRoot){
+        System.out.println("<!><!><!><!><!><!><!><!><!><!><!><!>");
+        System.out.println("FunctionTree treeRoot");
+        StringBuffer s = new StringBuffer();
+        debugPrintNode(treeRoot, 0, s);
+        System.out.println(s.toString());
+        System.out.println("<!><!><!><!><!><!><!><!><!><!><!><!>");
+    }
+
+    private static void debugPrintNode(Map node, int depth, StringBuffer s){
+        Iterator i = node.entrySet().iterator();
+        Map.Entry anEntry = null;
+        while(i.hasNext()) {
+            anEntry = (Map.Entry)i.next();
+            appendLine(s, depth, "Key: " + anEntry.getKey());
+            Object value = anEntry.getValue();
+            if (value instanceof Map){
+                s.append(" Map... ");
+                debugPrintNode((Map)value, depth + 1, s);
+            } else {
+                s.append(" Value: " + value);
+            }
+        }
+    }
+
+    private static void appendLine(StringBuffer s, int depth, String value){
+        s.append("\n");
+        for (int i = 0; i< depth; i++){
+            s.append("  ");
+        }
+        s.append(value);
+    }
+*/
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/TestResolvedFunctions.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestResolvedFunctions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,97 @@
+/*
+ * 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 org.teiid.query.function;
+
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.eval.Evaluator;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+import junit.framework.TestCase;
+
+
+public class TestResolvedFunctions extends TestCase {
+
+    public void testPowerIntegers() throws Exception {
+        
+        String sql = "power(10, 10)"; //$NON-NLS-1$
+        
+        //BigInteger is a closer match here since the second argument matches
+        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, getFunctionResult(sql).getClass());
+    }
+    
+    public void testPowerDoubles() throws Exception {
+        
+        String sql = "power(10.01, 10.01)"; //$NON-NLS-1$
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.DOUBLE, getFunctionResult(sql).getClass());
+    }
+
+    public void testPowerFloats() throws Exception {
+        
+        String sql = "power(convert(10.01, float), convert(10.01, float))"; //$NON-NLS-1$
+        
+        //since the second argument cannot be converted to an integer, the result is a double
+        assertEquals(DataTypeManager.DefaultDataClasses.DOUBLE, getFunctionResult(sql).getClass());
+    }
+    
+    public void testPowerBigInteger() throws Exception {
+        
+        String sql = "power(convert(10.01, BigInteger), 10)"; //$NON-NLS-1$
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, getFunctionResult(sql).getClass());
+    }
+    
+    //there should only be one signature for ceiling. The float argument will be converted to a double
+    public void testCeilingFloat() throws Exception {
+        
+        String sql = "ceiling(convert(10.01, float))"; //$NON-NLS-1$
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.DOUBLE, getFunctionResult(sql).getClass());
+    }
+    
+    //same as above
+    public void testFloorFloat() throws Exception {
+        
+        String sql = "floor(convert(10.01, float))"; //$NON-NLS-1$
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.DOUBLE, getFunctionResult(sql).getClass());
+    }
+
+    private Object getFunctionResult(String sql) throws QueryParserException,
+                                              ExpressionEvaluationException,
+                                              BlockedException,
+                                              TeiidComponentException, QueryResolverException {
+        Expression expr = QueryParser.getQueryParser().parseExpression(sql);
+        ResolverVisitor.resolveLanguageObject(expr, FakeMetadataFactory.example1Cached());
+        return Evaluator.evaluate(expr);
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/function/metadata (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/metadata)

Modified: trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/metadata/TestFunctionMetadataValidator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.function.metadata;
+package org.teiid.query.function.metadata;
 
+import org.teiid.api.exception.query.FunctionMetadataException;
+import org.teiid.query.function.metadata.FunctionMetadataValidator;
+import org.teiid.query.function.metadata.FunctionMethod;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.query.FunctionMetadataException;
 
 public class TestFunctionMetadataValidator extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMethod.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/metadata/TestFunctionMethod.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMethod.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.function.metadata;
+package org.teiid.query.function.metadata;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.function.metadata.FunctionCategoryConstants;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.function.metadata.FunctionParameter;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestFunctionMethod extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/function/metadata/TestSystemSource.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/metadata/TestSystemSource.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/function/metadata/TestSystemSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.function.metadata;
+package org.teiid.query.function.metadata;
 
+import org.teiid.query.function.metadata.FunctionMetadataValidator;
+import org.teiid.query.function.source.*;
+import org.teiid.query.report.*;
+
 import junit.framework.*;
-import com.metamatrix.query.function.source.*;
-import com.metamatrix.query.report.*;
 
 public class TestSystemSource extends TestCase {
 

Copied: trunk/engine/src/test/java/org/teiid/query/function/source (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/function/source)

Modified: trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/source/TestXMLSystemFunctions.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.function.source;
+package org.teiid.query.function.source;
 
 import static org.junit.Assert.*;
 
@@ -38,12 +38,13 @@
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.FileUtil;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.function.source.XMLSystemFunctions;
 
-import com.metamatrix.api.exception.query.FunctionExecutionException;
-import com.metamatrix.common.types.SQLXMLImpl;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.core.util.FileUtil;
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestXMLSystemFunctions {

Copied: trunk/engine/src/test/java/org/teiid/query/mapping/xml (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/mapping/xml)

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingAttribute.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingAttribute.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingAttribute.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingChoiceNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingChoiceNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingChoiceNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
+import org.teiid.query.mapping.xml.MappingAllNode;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCriteriaNode;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingDocument.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingDocument.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingDocument.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.MappingSourceNode;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingElement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingElement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingElement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,10 +20,21 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
 import java.util.List;
 
+import org.teiid.query.mapping.xml.MappingAllNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCommentNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
+import org.teiid.query.mapping.xml.Namespace;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingLoader.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingLoader.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingLoader.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -28,9 +28,22 @@
 import java.util.List;
 import java.util.Properties;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingBaseNode;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCriteriaNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingException;
+import org.teiid.query.mapping.xml.MappingLoader;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+import org.teiid.query.mapping.xml.Namespace;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * <p>Test cases for {@link MappingLoader} class. </p>
@@ -98,7 +111,7 @@
      * <p>Utility to get an input stream to a file in the app's classpath. </p>
      */
     private static InputStream getResourceStream( Class appClass, String filename ) {
-        return appClass.getClassLoader().getResourceAsStream(filename);
+        return appClass.getResourceAsStream(filename);
     }
 
     // =========================================================================
@@ -148,7 +161,7 @@
      * Positive test -- load from file in app classpath.
      */
     public void testPos_LoadFromStream() {
-        helpLoad( "com/metamatrix/query/mapping/xml/" + MAPPING_FILE, true, VALID ); //$NON-NLS-1$
+        helpLoad( MAPPING_FILE, true, VALID ); 
     }
 
     /**

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingOutputter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingOutputter.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingOutputter.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -29,6 +29,16 @@
 import java.io.StringWriter;
 import java.util.ArrayList;
 
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCriteriaNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingException;
+import org.teiid.query.mapping.xml.MappingLoader;
+import org.teiid.query.mapping.xml.MappingOutputter;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+
 import junit.framework.TestCase;
 
 /**

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingRecursiveElement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestMappingRecursiveElement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestMappingRecursiveElement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestNamespace.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/mapping/xml/TestNamespace.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/mapping/xml/TestNamespace.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.mapping.xml;
+package org.teiid.query.mapping.xml;
 
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.Namespace;
+
 import junit.framework.TestCase;
 
 public class TestNamespace extends TestCase {

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/FakeFunctionMetadataSource.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/FakeFunctionMetadataSource.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/FakeFunctionMetadataSource.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/FakeFunctionMetadataSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,65 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.teiid.query.function.FunctionMetadataSource;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.function.metadata.FunctionParameter;
+
+
+public class FakeFunctionMetadataSource implements FunctionMetadataSource {
+
+    public Collection getFunctionMethods() {
+        List methods = new ArrayList();
+        methods.add(new FunctionMethod("xyz", "", "misc", FunctionMethod.MUST_PUSHDOWN,  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                                       FakeFunctionMetadataSource.class.getName(), "xyz", //$NON-NLS-1$
+                                       new FunctionParameter[0],  
+                                       new FunctionParameter("out", "integer"))); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        FunctionParameter p1 = new FunctionParameter("astring", "string");  //$NON-NLS-1$  //$NON-NLS-2$
+        FunctionParameter result = new FunctionParameter("trimstring", "string"); //$NON-NLS-1$  //$NON-NLS-2$
+        FunctionMethod method = new FunctionMethod("MYRTRIM", "", "", FakeFunctionMetadataSource.class.getName(), "myrtrim", new FunctionParameter[] {p1}, result);  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        method.setPushdown(FunctionMethod.CAN_PUSHDOWN);
+        methods.add(method);
+        return methods;
+    }
+    
+    public Class getInvocationClass(String className) throws ClassNotFoundException { 
+        return Class.forName(className); 
+    }
+    
+    // dummy function
+    public static Object xyz() {
+        return null;
+    }
+    
+    /** defect 15348*/
+    public static Object myrtrim(Object astring) {
+        String string = (String)astring;
+        return string.trim();
+    }
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/InlineViewCase.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/InlineViewCase.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/InlineViewCase.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/InlineViewCase.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,45 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import java.util.List;
+import java.util.Set;
+
+public class InlineViewCase {
+	public String name;
+	public String userQuery;
+	public String optimizedQuery;
+	public Set<String> sourceQueries;
+	public List<List<Object>> expectedResults;
+	
+	public String getFullyQualifiedQuery() {
+		return optimizedQuery;    	
+	}		
+	public InlineViewCase(String name, String userQuery, String optimizedQuery, Set<String> sourceQueries, List expectedResults) {
+		this.name = name;
+		this.userQuery = userQuery;
+		this.optimizedQuery = optimizedQuery;
+		this.sourceQueries = sourceQueries;
+		this.expectedResults = expectedResults;
+	}	
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAccessPatterns.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestAccessPatterns.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,294 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.validator.TestValidator;
+
+
+
+public class TestAccessPatterns {
+    
+    /**
+     * The virtual access patterns should get satisfied 
+     */
+    @Test public void testVirtualAccessPatternPassing() {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup2 where e0=1 and e1='2'"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), new String[] {"SELECT test.\"group\".e0, test.\"group\".e2 FROM test.\"group\" WHERE (test.\"group\".e0 = 1) AND (test.\"group\".e1 = '2')"}); //$NON-NLS-1$
+    }
+
+    @Test public void testVirtualAccessPatternPassing1() {
+        String sql = "delete from vm1.g37 where e1 = 1"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {});
+    }
+    
+    @Test public void testVirtualAccessPatternFailing() {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup2 where e0=1"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    }
+    
+    @Test public void testVirtualAccessPatternFailing1() {
+        String sql = "delete from vm1.g37"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, null, null, TestOptimizer.SHOULD_FAIL);
+    }
+
+    @Test public void testAccessPattern1() throws Exception {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup where e0=1 and e1='2'"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, 
+                               TestValidator.exampleMetadata4(), 
+                               new String[] {"SELECT g_0.e0, g_0.e2 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2')" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
+    }
+    
+    @Test public void testAccessPattern2() {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup where e0=1"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    }
+    
+    @Test public void testAccessPattern3() {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup where e0=1 and e2='2'"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    } 
+    
+    @Test public void testAccessPattern4() throws Exception {
+        String sql = "(SELECT e0, e2 FROM vTest.vGroup where e0=1 and e1='2') union all (SELECT e0, e2 FROM vTest.vGroup where e0=1 and e1='2')"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), new String[] {"SELECT g_0.e0, g_0.e2 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2')"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    } 
+    
+    @Test public void testAccessPattern5() {
+        String sql = "(SELECT e0, e2 FROM vTest.vGroup where e0=1 and e1='2') union all (SELECT e0, e2 FROM vTest.vGroup where e0=1)"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    } 
+    
+    @Test public void testAccessPattern6() {
+        String sql = "SELECT e0, e2 FROM test.group where e1 IN (SELECT e2 FROM vTest.vGroup where e0=1 and e1='2')"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), new String[] {"SELECT e1, e0, e2 FROM test.\"group\""}); //$NON-NLS-1$
+    }   
+    
+    @Test public void testAccessPattern7() {
+        String sql = "SELECT e0, e2 FROM test.group where e1 IN (SELECT e2 FROM vTest.vGroup where e0=1)"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    } 
+    
+    @Test public void testAccessPattern8() {
+        String sql = "SELECT e0, e2 FROM vTest.vGroup"; //$NON-NLS-1$
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, null, null, TestOptimizer.SHOULD_FAIL); 
+    } 
+        
+    /**
+     * Tests two access nodes, each with access patterns, but one already
+     * satisfied by user criteria - the other should be made dependent
+     */
+    @Test public void testNodesBothHaveAccessPatterns1() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm4.g1.e1 from pm4.g1, pm4.g2 where pm4.g2.e5 = 'abc' and pm4.g1.e1 = pm4.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm4.g2 AS g_0 WHERE g_0.e5 = 'abc'"}, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        TestDependentJoins.checkDependentGroups(plan, new String[] {"pm4.g1"}); //$NON-NLS-1$
+    }
+
+    /**
+     * Tests two access nodes, each with access patterns, but one already
+     * satisfied by user criteria - the other should be made dependent
+     * (same query written slightly different).
+     */
+    @Test public void testNodesBothHaveAccessPatterns1a() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm4.g1.e1 from pm4.g2, pm4.g1 where pm4.g2.e1 = pm4.g1.e1 and pm4.g2.e5 = 'abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm4.g2 AS g_0 WHERE g_0.e5 = 'abc'"}, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        TestDependentJoins.checkDependentGroups(plan, new String[] {"pm4.g1"}); //$NON-NLS-1$
+    }
+
+    /**
+     * Self join - tests that both access nodes are satisfied by the select
+     * criteria (therefore merge join should be used)
+     */
+    @Test public void testSelfJoinAccessPatterns() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm4.g1.e1 from pm4.g1, pm4.g1 as g1A where pm4.g1.e1 = 'abc' and g1A.e1 = 'abc' and pm4.g1.e2 = g1A.e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g1A.e2 FROM pm4.g1 AS g1A WHERE g1A.e1 = 'abc'", "SELECT pm4.g1.e2, pm4.g1.e1 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }, TestOptimizer.getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+
+    @Test public void testAccessPatternsFails() {
+        TestOptimizer.helpPlan("select pm4.g2.e1 from pm4.g2, pm4.g2 as g2A where pm4.g2.e2 = 123 and pm4.g2.e1 = g2A.e5", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            null, null, null,
+            TestOptimizer.SHOULD_FAIL);
+    }
+
+    @Test public void testAccessPatternsFails2() {
+        TestOptimizer.helpPlan("select pm4.g2.e1 from pm4.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            null, null, null,
+            TestOptimizer.SHOULD_FAIL);
+    }
+
+    @Test public void testUnionWithAccessPatternFails() {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION select pm4.g1.e1 from pm4.g1 where pm4.g1.e2 = 1", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, null, null, TestOptimizer.SHOULD_FAIL);
+    }
+
+    @Test public void testUnionWithAccessPatternFails2() {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION select pm4.g1.e1 from pm4.g1", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, null, null, TestOptimizer.SHOULD_FAIL);
+    }
+    
+    @Test public void testUnionWithAccessPattern() {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION ALL select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm4.g1.e1 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testUnionWithAccessPattern2() {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1 UNION ALL select pm4.g1.e1 from pm4.g1 where pm4.g1.e1 = 'abc' and pm4.g1.e2 = 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm4.g1.e1 FROM pm4.g1 WHERE (pm4.g1.e1 = 'abc') AND (pm4.g1.e2 = 1)" }); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test public void testAccessPatternPartialMatch() throws Exception {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g2 where pm1.g1.e1 = pm4.g2.e1 and pm4.g2.e2 = 123", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            new String[] { "SELECT g_0.e1 FROM pm4.g2 AS g_0 WHERE (g_0.e2 = 123) AND (g_0.e1 IN (<dependent values>))", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    /**
+     * Similar to the query above, except the OR instead of an AND produces a
+     * completely different query plan which can't satisfy the access pattern.
+     * @see #testAccessPatternPartialMatch
+     */
+    @Test public void testAccessPatternFails3() {
+        TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g2 where pm1.g1.e1 = pm4.g2.e1 or pm4.g2.e2 = 123",             //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, null, null,
+            TestOptimizer.SHOULD_FAIL);
+    }
+    
+    /**
+     * Access patterns on models that support joins requires that the access patterns are satisfied prior to
+     * RulePlanJoins
+     */
+    @Test public void testAccessPatternsGroupsInSameModelFails() {
+        TestOptimizer.helpPlan("select pm5.g1.e1 from pm5.g1, pm5.g2 where pm5.g1.e1 = pm5.g2.e1",              //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, null, null, TestOptimizer.SHOULD_FAIL);
+    }
+    
+    // ==================================================================================
+    // ACCESS PATTERNS
+    // ==================================================================================
+
+    @Test public void testPushingCriteriaThroughFrameAccessPattern0() {
+        TestOptimizer.helpPlan("select * from vm1.g9 where vm1.g9.e1='abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm4.g1.e1 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'", //$NON-NLS-1$
+                            "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+    }
+
+    /**
+     * pm4.g2.e5 or pm4.g2.e2 also need to be in criteria
+     */
+    @Test public void testPushingCriteriaThroughFrameAccessPattern1() { 
+        TestOptimizer.helpPlan("select * from vm1.g1, vm1.g10 where vm1.g1.e1='abc' and vm1.g1.e1=vm1.g10.e1", FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), //$NON-NLS-1$
+            null, TestOptimizer.SHOULD_FAIL );
+    }
+
+    @Test public void testPushingCriteriaThroughFrameAccessPattern2() { 
+        TestOptimizer.helpPlan("select e1 from vm1.g11 where vm1.g11.e1='abc' and vm1.g11.e2=123", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm4.g2.e1 FROM pm4.g2 WHERE (pm4.g2.e1 = 'abc') AND (pm4.g2.e2 = 123)" }); //$NON-NLS-1$
+    }
+
+    @Test public void testPushingCriteriaThroughFrameAccessPattern3() {
+        TestOptimizer.helpPlan("select * from vm1.g1, vm1.g9 where vm1.g1.e1='abc' and vm1.g1.e1=vm1.g9.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm4.g1.e1 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'", //$NON-NLS-1$
+                          "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", //$NON-NLS-1$
+                          "SELECT g1__1.e1, g1__1.e2, g1__1.e3, g1__1.e4 FROM pm1.g1 AS g1__1 WHERE g1__1.e1 = 'abc'"} ); //$NON-NLS-1$
+    }
+    
+    /**
+     * pm4.g2.e5 or pm4.g2.e2 also need to be in criteria
+     */
+    @Test public void testPushingCriteriaThroughFrameAccessPattern4() { 
+        TestOptimizer.helpPlan("select * from vm1.g10 where vm1.g10.e1='abc'", FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), //$NON-NLS-1$
+           null, TestOptimizer.SHOULD_FAIL );
+    }
+    
+    /**
+     * TODO: in this case we should perform a criteria optimization to create set criteria
+     */
+    @Test public void testCase6425() {
+        String sql = "SELECT e1 FROM pm4.g1 WHERE e1 = '1' OR e1 = '2'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, new String[] {"SELECT e1 FROM pm4.g1 WHERE (e1 = '1') OR (e1 = '2')"}); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+        
+    @Test public void testCase6425_2() {
+        String sql = "SELECT e1 FROM pm4.g1 WHERE e1 = '1' OR (e1 = '2' AND e2 = 3)"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, new String[] {"SELECT e1 FROM pm4.g1 WHERE (e1 = '1') OR ((e1 = '2') AND (e2 = 3))"}); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+        
+    @Test public void testCase6425_4() throws Exception {
+        String sql = "SELECT e1 FROM pm4.g1 WHERE e1 = '1' OR e2 = '2'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        TestOptimizer.helpPlan(sql, metadata, null, TestOptimizer.ComparisonMode.FAILED_PLANNING);
+    }
+    
+    /*
+     * Criteria was preventing rule choose dependent from creating the appropriate dependent join
+     */
+    @Test public void testMultiAccessPatternWithCriteria() throws Exception {
+    	String sql = "SELECT pm1.g1.* FROM pm4.g1, pm5.g1, pm1.g1 where pm4.g1.e1 = pm1.g1.e1 and pm5.g1.e1 = pm1.g1.e1 and pm5.g1.e2 like '%x' "; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        TestOptimizer.helpPlan(sql, metadata,
+						new String[] {
+								"SELECT g_0.e2, g_0.e1 FROM pm5.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", //$NON-NLS-1$ 
+								"SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0", //$NON-NLS-1$
+								"SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)" }, TestOptimizer.getGenericFinder(false), ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$   
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,840 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import org.junit.Test;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestAggregatePushdown {
+
+	public static BasicSourceCapabilities getAggregateCapabilities() {
+		BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_HAVING, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+		return caps;
+	}
+
+    public static CapabilitiesFinder getAggregatesFinder() {
+    	return new DefaultCapabilitiesFinder(getAggregateCapabilities());
+    }
+
+    @Test public void testCase6327() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT a12.intkey AS REGION_NBR, SUM(a11.intnum) AS WJXBFS1 FROM bqt1.smalla AS a11 INNER JOIN bqt2.smalla AS a12 ON a11.stringkey = a12.stringkey WHERE a11.stringkey = 0 GROUP BY a12.intkey"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT SUM(a11.intnum) FROM bqt1.smalla AS a11 WHERE a11.stringkey = '0' HAVING COUNT(*) > 0", "SELECT a12.intkey FROM bqt2.smalla AS a12 WHERE a12.stringkey = '0' group by a12.intkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Note that intnum is retrieved from each source
+     * 
+     * Note also that this test shows that the max aggregate is not placed on the bqt2 query since it would be on one of the group by expressions
+     */
+    @Test public void testAggregateOfJoinExpression() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT a12.intkey, MAX(a12.stringkey), SUM(a11.intnum+a12.intnum) FROM bqt1.smalla AS a11 INNER JOIN bqt2.smalla AS a12 ON a11.stringkey = a12.stringkey GROUP BY a12.intkey"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.stringkey, g_0.intkey, g_0.intnum FROM bqt2.smalla AS g_0 GROUP BY g_0.stringkey, g_0.intkey, g_0.intnum", "SELECT g_0.stringkey, g_0.intnum FROM bqt1.smalla AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Note that even though this grouping is join invariant, we still do not remove the top level group by
+     * since we are not checking the uniqueness of the x side join expressions 
+     */
+    @Test public void testInvariantAggregate() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT max(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by y.e3"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.e3 FROM pm1.g1 AS g_0", "SELECT g_0.e3, MAX(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Test of an aggregate nested in an expression symbol
+     */
+    @Test public void testCase6211() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "select sum(a11.intnum) Profit, (sum(a11.intnum) / sum(a11.floatnum)) WJXBFS2 from bqt1.smalla a11 join bqt2.smallb a12 on a11.intkey=a12.intkey group by a12.intkey"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.intkey, SUM(g_0.intnum), SUM(g_0.floatnum) FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey", "SELECT g_0.intkey FROM bqt2.smallb AS g_0 GROUP BY g_0.intkey"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Note that until we can test the other side cardinality, we cannot fully push the group node
+     */ 
+    @Test public void testAggregatePushdown1() throws Exception {        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleAggregatesCached();
+        String sql = "SELECT o_dealerid, o_productid, sum(o_amount) FROM m1.order, m1.dealer, m2.product " +  //$NON-NLS-1$
+            "WHERE o_dealerid=d_dealerid AND o_productid=p_productid AND d_state = 'CA' AND p_divid = 100 " +  //$NON-NLS-1$
+            "GROUP BY o_dealerid, o_productid"; //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      metadata,
+                                      null, getAggregatesFinder(),
+                                      new String[] {"SELECT DISTINCT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, SUM(g_0.o_amount) AS c_2 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"},  //$NON-NLS-1$ //$NON-NLS-2$
+                                                    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+
+    @Test public void testAggregatePushdown2() throws Exception {        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleAggregatesCached();
+        String sql = "SELECT o_dealerid, o_productid, sum(o_amount) FROM m1.order, m1.dealer, m2.product " +  //$NON-NLS-1$
+            "WHERE o_dealerid=d_dealerid AND o_productid=p_productid AND d_state = 'CA' AND p_divid = 100 " +  //$NON-NLS-1$
+            "GROUP BY o_dealerid, o_productid having max(o_amount) < 100"; //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      metadata,
+                                      null, getAggregatesFinder(),
+                                      new String[] {"SELECT DISTINCT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, MAX(g_0.o_amount) AS c_2, SUM(g_0.o_amount) AS c_3 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"},  //$NON-NLS-1$ //$NON-NLS-2$
+                                                    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        1,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+    
+    /**
+     * Average requires the creation of staged sum and count aggregates
+     */
+    @Test public void testAvgAggregate() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT avg(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2", "SELECT g_0.e3, g_0.e1, SUM(g_0.e2), COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testCountAggregate() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT count(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2", "SELECT g_0.e3, g_0.e1, COUNT(g_0.e2) FROM pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testOuterJoinPreventsPushdown() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        String sql = "SELECT count(y.e2) from pm1.g1 x left outer join pm2.g1 y on x.e3 = y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0", "SELECT g_0.e3, g_0.e1, g_0.e2 FROM pm2.g1 AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Test to ensure count(*) isn't mistakenly pushed to either side, but that
+     * grouping can still be.
+     */
+    @Test public void testCase5724() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+              "select count(*), a.intnum from bqt1.smalla as a, bqt2.smallb as b where a.intkey = b.intkey group by a.intnum",  //$NON-NLS-1$
+              metadata, null, capFinder,
+              new String[] { 
+                "SELECT a.intkey, a.intnum FROM bqt1.smalla AS a group by a.intkey, a.intnum", "SELECT b.intkey FROM bqt2.smallb AS b"},  //$NON-NLS-1$ //$NON-NLS-2$
+                true); 
+                  
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+             2,      // Access
+             0,      // DependentAccess
+             0,      // DependentSelect
+             0,      // DependentProject
+             0,      // DupRemove
+             1,      // Grouping
+             0,      // NestedLoopJoinStrategy
+             1,      // MergeJoinStrategy
+             0,      // Null
+             0,      // PlanExecution
+             1,      // Project
+             0,      // Select
+             0,      // Sort
+             0       // UnionAll
+        });                                    
+    }
+
+    @Test public void testCase6210() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        caps.setFunctionSupport("/", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "select a11.intkey ITEM_ID, sum(a11.intnum) WJXBFS1 from bqt1.smalla a11 join bqt2.smalla a12 on (a11.stringkey = a12.stringkey) join bqt2.smallb a13 on (a11.intkey = a13.intkey) where a13.intnum in (10) group by a11.intkey"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT g_0.stringkey FROM bqt2.smalla AS g_0", "SELECT g_0.stringkey, g_0.intkey, SUM(g_0.intnum) FROM bqt1.smalla AS g_0 GROUP BY g_0.stringkey, g_0.intkey", "SELECT g_0.intkey FROM bqt2.smallb AS g_0 WHERE g_0.intnum = 10"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }               
+    
+    @Test public void testNoGroupAggregatePushdown() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, false);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+              "select count(*) from bqt1.smalla",  //$NON-NLS-1$
+              metadata, null, capFinder,
+              new String[] { 
+                "SELECT count(*) from bqt1.smalla"},  //$NON-NLS-1$
+                true); 
+                  
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testNoHavingAggregate() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+              "select stringkey, max(intkey) from bqt1.smalla group by stringkey having count(intkey) = 1",  //$NON-NLS-1$
+              metadata, null, capFinder,
+              new String[] { 
+                "SELECT COUNT(g_0.intkey), g_0.stringkey, MAX(g_0.intkey) FROM bqt1.smalla AS g_0 GROUP BY g_0.stringkey"},  //$NON-NLS-1$
+                ComparisonMode.EXACT_COMMAND_STRING); 
+                  
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                1,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });                                    
+    }
+    
+    @Test public void testHavingCriteriaPushDown() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select X.e1 FROM vm1.g1 X group by X.e1 having X.e1 = 1 and sum(X.e2) = 2", FakeMetadataFactory.example1Cached(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE pm1.g1.e1 = '1'"}, true); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testBusObjQuestion1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);    
+        
+        capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+        String sql = "SELECT Q1.S, Q2.C, Q1.PRODUCT, Q1.REGION AS Q1R, Q2.REGION AS Q2R FROM " + //$NON-NLS-1$
+            "(SELECT SUM(SALES) AS S, REGION, PRODUCT FROM DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT) Q1 " + //$NON-NLS-1$
+            "FULL OUTER JOIN " +  //$NON-NLS-1$
+            "(SELECT SUM(COSTS) AS C, REGION FROM ORACLE_TABLE WHERE \"YEAR\" = '1999' GROUP BY REGION) Q2 " + //$NON-NLS-1$
+            "ON Q1.REGION = Q2.REGION"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT REGION, SUM(SALES), PRODUCT FROM db2model.DB2_TABLE WHERE PRODUCT IN ('GUNS', 'TOYS', 'VIDEOTAPES') GROUP BY REGION, PRODUCT", //$NON-NLS-1$
+                                                    "SELECT REGION, SUM(COSTS) FROM oraclemodel.Oracle_table WHERE \"YEAR\" = '1999' GROUP BY REGION"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }        
+
+    @Test public void testBusObjQuestion2() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);    
+        
+        capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+        String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " +  //$NON-NLS-1$
+            "FROM SALES F, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
+            "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " +  //$NON-NLS-1$
+            "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " +  //$NON-NLS-1$
+            "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT g_0.\"MONTH\", g_0.\"YEAR\" FROM msModel.\"TIME\" AS g_0 WHERE g_0.\"YEAR\" = '1999'", //$NON-NLS-1$
+                                                    "SELECT DISTINCT g_0.\"MONTH\" AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$ 
+                                                    "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"},  //$NON-NLS-1$
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        1,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }   
+
+    @Test public void testBusObjQuestion2Hint() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);    
+        
+        capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+        String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " +  //$NON-NLS-1$
+            "FROM SALES F MAKEDEP, GEOGRAPHY G, msModel.TIME T " + //$NON-NLS-1$
+            "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " +  //$NON-NLS-1$
+            "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " +  //$NON-NLS-1$
+            "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT g_0.\"MONTH\", g_0.\"YEAR\" FROM msModel.\"TIME\" AS g_0 WHERE g_0.\"YEAR\" = '1999'", //$NON-NLS-1$
+                                          "SELECT DISTINCT g_0.\"MONTH\" AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.\"MONTH\" IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.\"MONTH\", g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$ 
+                                          "SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"},  //$NON-NLS-1$
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        1,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    } 
+
+    @Test public void testBusObjQuestion2HintVariation() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);    
+        
+        capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+        String sql = "SELECT SUM(F.SALES), G.REGION, T.YEAR " +  //$NON-NLS-1$
+            "FROM SALES F MAKEDEP, GEOGRAPHY2 G, msModel.TIME T " + //$NON-NLS-1$
+            "WHERE (F.CITY = G.CITY) AND (F.MONTH = T.MONTH) " +  //$NON-NLS-1$
+            "AND G.REGION IN ('BORDEAUX', 'POLINESIA') AND T.YEAR = '1999' " +  //$NON-NLS-1$
+            "GROUP BY G.REGION, T.YEAR"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT DISTINCT g_0.\"MONTH\" AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.\"MONTH\" IN (<dependent values>)) GROUP BY g_0.\"MONTH\", g_1.REGION ORDER BY c_0", //$NON-NLS-1$ 
+                                                    "SELECT g_0.\"MONTH\" AS c_0, g_0.\"YEAR\" AS c_1 FROM msModel.\"TIME\" AS g_0 WHERE g_0.\"YEAR\" = '1999' ORDER BY c_0"},  //$NON-NLS-1$
+                                                    ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    } 
+
+    @Test public void testBusObjQuestion3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);    
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);    
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);    
+        
+        capFinder.addCapabilities("db2model", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("oraclemodel", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("msmodel", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBusObj();
+
+        String sql = "select sum(c0), sum(b0), c1, b2 FROM db2Table, OraTable where c2=b2 group by c1, b2"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT c2, c1, c0 FROM db2model.DB2TABLE", //$NON-NLS-1$
+                                                    "SELECT DISTINCT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }
+    
+    @Test public void testPushDownOverUnion() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select e1, max(e2) from (select e1, e2 from pm1.g1 union all select e1, e2 from pm1.g2) y group by e1", FakeMetadataFactory.example1Cached(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT v_0.c_0, MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0", //$NON-NLS-1$
+        	"SELECT v_0.c_0, MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g2 AS g_0) AS v_0 GROUP BY v_0.c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+    
+    @Test public void testPushDownOverUnion1() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select max(e2) from (select e1, e2 from pm1.g1 union all select e1, e2 from pm1.g2) z", FakeMetadataFactory.example1Cached(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT MAX(v_0.c_0) FROM (SELECT g_0.e2 AS c_0 FROM pm1.g2 AS g_0) AS v_0 HAVING COUNT(*) > 0", //$NON-NLS-1$
+        	"SELECT MAX(v_0.c_0) FROM (SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0) AS v_0 HAVING COUNT(*) > 0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+    
+    /**
+     * We won't do the pushdown here since the aggregate depends upon the cardinality
+     */
+    @Test public void testPushDownOverUnion2() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select count(e2) from (select e1, e2 from pm1.g1 union select e1, e2 from pm1.g2) z", FakeMetadataFactory.example1Cached(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", //$NON-NLS-1$
+        	"SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+    
+    @Test public void testPushDownOverUnionMixed() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getAggregateCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select max(e2) from (select e1, e2 from pm1.g1 union all select e1, e2 from pm2.g2) z", FakeMetadataFactory.example1Cached(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT MAX(v_0.c_0) FROM (SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0) AS v_0 HAVING COUNT(*) > 0", //$NON-NLS-1$
+        	"SELECT g_0.e2 FROM pm2.g2 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+        
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAnsiJoinPushdown.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,57 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestAnsiJoinPushdown {
+
+	/**
+	 * See {@link TestOptimizer.testPushMultiGroupCriteria}
+	 * 
+	 * Notice that the non-join criteria is still in the on clause.
+	 */
+    @Test public void testAnsiInnerJoin() throws Exception { 
+    	FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_ANSI_JOIN, true);
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+    	
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+        		"select pm2.g1.e1 from pm2.g1, pm2.g2 where pm2.g1.e1 = pm2.g2.e1 and (pm2.g1.e2 = 1 OR pm2.g2.e2 = 2) and pm2.g2.e3 = 1", //$NON-NLS-1$ 
+        		FakeMetadataFactory.example1Cached(), 
+        		null,
+        		capFinder,
+        		new String[] { "SELECT g_0.e1 FROM pm2.g1 AS g_0 INNER JOIN pm2.g2 AS g_1 ON g_0.e1 = g_1.e1 AND ((g_0.e2 = 1) OR (g_1.e2 = 2)) WHERE g_1.e3 = TRUE" }, //$NON-NLS-1$
+        		ComparisonMode.EXACT_COMMAND_STRING); 
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }  
+	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestAnsiJoinPushdown.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestComparableMetadataPushdown.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestComparableMetadataPushdown.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestComparableMetadataPushdown.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestComparableMetadataPushdown.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,78 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.validator.TestValidator;
+
+
+public class TestComparableMetadataPushdown {
+	
+	@Test public void testCantPushSort() throws Exception {
+		String sql = "select e3, e2 from test.group order by e3, e2"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        capFinder.addCapabilities("test", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(),  
+        		new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    }
+	
+	@Test public void testCantPushGroupBy() throws Exception {
+		String sql = "select e3, e2 from test.group group by e3, e2"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        capFinder.addCapabilities("test", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(),  
+        		new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+	}
+	
+	@Test public void testCantPushDup() throws Exception {
+		String sql = "select distinct e3, e2 from test.group"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        capFinder.addCapabilities("test", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(),  
+        		new String[] {"SELECT g_0.e3, g_0.e2 FROM test.\"group\" AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+	}
+	
+	@Test public void testCantPushSetOp() throws Exception {
+		String sql = "select e3, e2 from test.group union select e0, e1 from test.group2"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        capFinder.addCapabilities("test", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata(),  
+        		new String[] {"SELECT test.\"group\".e3, test.\"group\".e2 FROM test.\"group\"", "SELECT test.group2.e0, test.group2.e1 FROM test.group2"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$  
+	}
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestComparableMetadataPushdown.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestDependentJoins.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,811 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.AccessNode;
+import org.teiid.query.processor.relational.DependentAccessNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+
+
+
+public class TestDependentJoins extends TestCase {
+    
+    static void checkDependentGroups(ProcessorPlan plan, String[] groups) {
+        if(! (plan instanceof RelationalPlan)) {
+            return;                
+        }
+                                
+        // Collect all the group names (uppercase) for all the dependent groups in the plan
+        Set depGroups = new HashSet();
+        getDependentGroups(((RelationalPlan)plan).getRootNode(), depGroups);
+
+        // Check that all the expected groups exist in depGroups
+        Set expectedGroups = new HashSet();
+        for(int i=0; i<groups.length; i++) {
+            expectedGroups.add(groups[i].toUpperCase());    
+        }        
+        
+        assertEquals("Expected groups were not made dependent", expectedGroups, depGroups);         //$NON-NLS-1$
+    }
+    
+    static void getDependentGroups(RelationalNode node, Set depGroups) {
+        if(node instanceof DependentAccessNode) {
+            DependentAccessNode accessNode = (DependentAccessNode)node;
+            Command depCommand = accessNode.getCommand();
+            Collection groupSymbols = GroupCollectorVisitor.getGroups(depCommand, true);
+            Iterator groupIter = groupSymbols.iterator();
+            while(groupIter.hasNext()) {
+                GroupSymbol group = (GroupSymbol) groupIter.next();
+                depGroups.add(group.getName().toUpperCase());    
+            }
+        }
+        
+        // Recurse through children
+        RelationalNode[] children = node.getChildren();
+        for(int i=0; i<children.length; i++) {
+            if(children[i] != null) {
+                getDependentGroups(node.getChildren()[i], depGroups);                
+            }
+        }
+    }
+            
+    private void checkNotDependentGroups(ProcessorPlan plan, String[] groups) {
+        if(! (plan instanceof RelationalPlan)) {
+            return;                
+        }
+                                
+        // Collect all the group names (uppercase) for all the dependent groups in the plan
+        Set notDepGroups = new HashSet();
+        getNotDependentGroups(((RelationalPlan)plan).getRootNode(), notDepGroups);
+
+        // Check that all the expected groups exist in depGroups
+        Set expectedGroups = new HashSet();
+        for(int i=0; i<groups.length; i++) {
+            expectedGroups.add(groups[i].toUpperCase());    
+        }        
+        
+        assertEquals("Expected groups were made dependent", expectedGroups, notDepGroups);         //$NON-NLS-1$
+    }
+    
+    private void getNotDependentGroups(RelationalNode node, Set notDepGroups) {
+        if(node instanceof AccessNode && !(node instanceof DependentAccessNode)) {
+            AccessNode accessNode = (AccessNode)node;
+            Command depCommand = accessNode.getCommand();
+            Collection groupSymbols = GroupCollectorVisitor.getGroups(depCommand, true);
+            Iterator groupIter = groupSymbols.iterator();
+            while(groupIter.hasNext()) {
+                GroupSymbol group = (GroupSymbol) groupIter.next();
+                notDepGroups.add(group.getName().toUpperCase());    
+            }
+        }
+        
+        // Recurse through children
+        RelationalNode[] children = node.getChildren();
+        for(int i=0; i<children.length; i++) {
+            if(children[i] != null) {
+                getNotDependentGroups(node.getChildren()[i], notDepGroups);                
+            }
+        }
+    }
+    
+    public void testOptionMakeDep1() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm2.g1 where pm1.g1.e1 = pm2.g1.e1 option makedep pm2.g1", FakeMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm2.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+        checkDependentGroups(plan, new String[] {"pm2.g1"}); //$NON-NLS-1$
+        checkNotDependentGroups(plan, new String[] {"pm1.g1"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    public void testOptionMakeDep2() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1, pm2.g1.e1 from pm1.g1 MAKEDEP INNER JOIN pm2.g1 MAKENOTDEP ON pm1.g1.e1 = pm2.g1.e1", FakeMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
+                new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm2.g1 AS g_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+        checkDependentGroups(plan, new String[] {"pm1.g1"}); //$NON-NLS-1$
+        checkNotDependentGroups(plan, new String[] {"pm2.g1"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    public void testDepJoinHintForceLeft() throws Exception {
+    	ProcessorPlan plan = TestOptimizer.helpPlan("select * FROM vm1.g4 option makedep pm1.g1", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g2 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g1"});                             //$NON-NLS-1$
+    }
+
+    public void testDepJoinHintForceRight() throws Exception {
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * FROM vm1.g4 option makedep pm1.g2", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g2"});                             //$NON-NLS-1$
+    }
+
+	public void testDepJoinMultiGroupBaseline() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select vm1.g4.*, pm1.g3.e1 FROM vm1.g4, pm1.g3 where pm1.g3.e1=vm1.g4.e1", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2", //$NON-NLS-1$
+                            "SELECT pm1.g3.e1 FROM pm1.g3" }, TestOptimizer.getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING ); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[0]);                             
+    }
+
+    public void testDepJoinMultiGroupForceOther() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select vm1.g4.*, pm1.g3.e1 FROM vm1.g4, pm1.g3 where pm1.g3.e1=vm1.g4.e1 option makedep pm1.g2", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g2"});                             //$NON-NLS-1$ 
+    }
+
+    public void testDepJoinHintForceLeft_NotDep() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * FROM vm1.g4 option makedep pm1.g1 makenotdep pm1.g2", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g2 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g1"});                             //$NON-NLS-1$
+        checkNotDependentGroups(plan, new String[] {"pm1.g2"});                             //$NON-NLS-1$
+    }
+
+    public void testDepJoinHintForceRight_NotDep() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * FROM vm1.g4 option makedep pm1.g2 makenotdep pm1.g1", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g2"});                             //$NON-NLS-1$
+        checkNotDependentGroups(plan, new String[] {"pm1.g1"});                             //$NON-NLS-1$
+    }
+
+    public void testDepJoinMultiGroupForceOther_NotDep() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select vm1.g4.*, pm1.g3.e1 FROM vm1.g4, pm1.g3 where pm1.g3.e1=vm1.g4.e1 option makedep pm1.g2 makenotdep pm1.g1, pm1.g3", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+        checkDependentGroups(plan, new String[] {"pm1.g2"}); //$NON-NLS-1$ 
+        checkNotDependentGroups(plan, new String[] {"pm1.g1", "pm1.g3"}); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    /**
+     * Test that access node with unsatisfied access pattern is made dependent
+     */
+    public void testMakeDependentAccessPattern1() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g1 where pm1.g1.e1 = pm4.g1.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[] {"pm4.g1"}); //$NON-NLS-1$
+    }
+
+    /**
+     * Test that access node with unsatisfied access pattern is made dependent
+     * (Same query written slightly different way)
+     */
+    public void testMakeDependentAccessPattern1a() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm4.g1, pm1.g1 where pm4.g1.e1 = pm1.g1.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[] {"pm4.g1"}); //$NON-NLS-1$
+    }
+    
+    /**
+     * Test that access node with unsatisfied access pattern is made dependent
+     */
+    public void testMakeDependentAccessPattern2() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g1 where pm4.g1.e2 = 1 and pm1.g1.e1 = pm4.g1.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm4.g1 AS g_0 WHERE (g_0.e2 = 1) AND (g_0.e1 IN (<dependent values>))", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[] {"pm4.g1"}); //$NON-NLS-1$
+    }
+
+    /**
+     * Test that second access pattern of access node is chosen to make
+     * dependent with
+     */
+    public void testMakeDependentAccessPattern3() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g2 where pm1.g1.e1 = pm4.g2.e5", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e5 FROM pm4.g2 AS g_0 WHERE g_0.e5 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.getGenericFinder(false), TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[] {"pm4.g2"}); //$NON-NLS-1$
+    }
+
+    /**
+     * This case actually tests the dead-tie case - either access node could
+     * be made dependent, but merge join is used since no access pattern 
+     * needs to be fulfilled and there is no cost info available for either source
+     */
+    public void testPushSelectAndMakeDependentAccessPattern1() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g1 where pm4.g1.e1 = 'abc' and pm1.g1.e1 = 'abc' and pm1.g1.e2 = pm4.g1.e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", "SELECT pm4.g1.e2 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }, TestOptimizer.getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[0]); 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * This case actually tests the dead-tie case - either access node could
+     * be made dependent, but merge join is used since no access pattern 
+     * needs to be fulfilled and there is no cost info available for either source
+     * (Same query written slightly different)
+     */
+    public void testPushSelectAndMakeDependentAccessPattern1a() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm4.g1, pm1.g1 where pm4.g1.e2 = pm1.g1.e2 and pm4.g1.e1 = 'abc' and pm1.g1.e1 = 'abc'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", "SELECT pm4.g1.e2 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }, TestOptimizer.getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[0]); 
+    
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Tests that it is enforced if an access node can't be made dependent
+     * because of it's (already-satisfied) access pattern - merge join is used
+     */
+    public void testPushSelectAndMakeDependentAccessPattern2() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g1.e1 from pm1.g1, pm4.g1 where pm4.g1.e1 = 'abc' and pm1.g1.e2 = pm4.g1.e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", "SELECT pm4.g1.e2 FROM pm4.g1 WHERE pm4.g1.e1 = 'abc'" }, TestOptimizer.getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        checkDependentGroups(plan, new String[0] ); 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /** Should use dependent join since one access node is "strong" */
+    public void testUseMergeJoin1() throws Exception {
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(10));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject obj = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+
+    /** Should not use a dependent join since neither access node is "strong" */
+    public void testUseMergeJoin2() throws Exception {
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject obj = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        obj.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2" }, TestOptimizer.ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    /** should have one dependent joins */
+    public void testMultiMergeJoin3() throws Exception {
+        // Create query
+        String sql = "SELECT pm1.g2.e1 FROM pm1.g3, pm1.g2, pm1.g1 WHERE pm1.g2.e1 = pm1.g3.e1 AND pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1 ));
+        FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    } 
+    
+    public void testMultiMergeJoin2() throws Exception {
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g2.e1 = pm1.g3.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+        FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>)", "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    } 
+
+    /**
+     * Defect 13448 
+     * should be one merge join and one dependent join
+     * Unlike the above tests, here the model pm1 supports ORDER BY.
+     */
+    public void testMultiMergeJoin5_defect13448() throws Exception {
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g1.e1 = pm1.g3.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+        FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g3 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    public void testMergeJoinVirtualGroups() throws Exception {
+        String sql = "SELECT vm1.g1.e1 FROM vm1.g1, vm1.g2a WHERE vm1.g1.e1 = vm1.g2a.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    public void testRLMCase2077() throws Exception {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQT();
+        FakeMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata); //$NON-NLS-1$
+        FakeMetadataFactory.setCardinality("bqt2.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+            "SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT g_0.StringKey FROM BQT1.SmallA AS g_0 WHERE g_0.StringKey IN (<dependent values>)", "SELECT g_0.STRINGKEY, g_0.STRINGNUM, g_0.IntKey FROM BQT2.SmallA AS g_0"}, //$NON-NLS-1$ //$NON-NLS-2$
+            TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });             
+
+    }
+
+    public void testRLMCase2077_2() throws Exception {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        TransformationMetadata metadata = FakeMetadataFactory.exampleBQT();
+        FakeMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata); //$NON-NLS-1$
+        FakeMetadataFactory.setCardinality("bqt2.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+            "SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey AND table1comp.key1 = BQT1.SmallA.StringNum",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT g_0.STRINGKEY, g_0.STRINGNUM, g_0.IntKey FROM BQT2.SmallA AS g_0", "SELECT g_0.StringKey, g_0.StringNum FROM BQT1.SmallA AS g_0 WHERE (g_0.StringKey IN (<dependent values>)) AND (g_0.StringNum IN (<dependent values>))"}, //$NON-NLS-1$ //$NON-NLS-2$
+            TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });             
+
+    }  
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestExpressionsInGroupBy.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestExpressionsInGroupBy.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,454 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+import junit.framework.TestCase;
+
+
+/**
+ * expressions in group use lacks robust support in MySQL, PostGres, and Derby Expressions and it's nothing more than syntactic sugar for an inline view,
+ * a new approach was taken to use inline views rather than a non ANSI group by construct.
+ * 
+ * Later we can add a connector binding property to support non-select expressions in group by.
+ */
+public class TestExpressionsInGroupBy extends TestCase {
+
+    public void testCase1565() throws Exception {
+        // Create query
+        String sql = "SELECT x, COUNT(*) FROM (SELECT convert(TimestampValue, date) AS x FROM bqt1.smalla) as y GROUP BY x"; //$NON-NLS-1$
+
+        // Create capabilities
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+            null, capFinder,
+            new String[] { "SELECT convert(TimestampValue, date), COUNT(*) FROM bqt1.smalla GROUP BY convert(TimestampValue, date)" },  //$NON-NLS-1$
+            true);
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);         
+    }   
+    
+    // Merge across multiple virtual groups - should be same outcome as testCase1565
+    public void testCase1565_2() throws Exception {
+        // Create query
+        String sql = "SELECT x, COUNT(*) FROM (SELECT convert(TimestampValue, date) AS x FROM (SELECT TimestampValue from bqt1.smalla) as z) as y GROUP BY x"; //$NON-NLS-1$
+
+        // Create capabilities
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+            null, capFinder,
+            new String[] { "SELECT convert(TimestampValue, date), COUNT(*) FROM bqt1.smalla GROUP BY convert(TimestampValue, date)" },  //$NON-NLS-1$
+            true);
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);         
+    }   
+    
+    // Merge across multiple virtual groups above the physical
+    public void testCase1565_3() throws Exception {
+        String sql = "SELECT x, COUNT(*) FROM (SELECT convert(TimestampValue, date) AS x FROM (SELECT TimestampValue from bqt1.smalla) as z) as y GROUP BY x"; //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+            null, TestOptimizer.getGenericFinder(),
+            new String[] { "SELECT TimestampValue FROM bqt1.smalla" },  //$NON-NLS-1$
+            true);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+             
+    }           
+
+    // Test what happens when not all the functions in the virtual SELECT can be pushed
+    public void testCase1565_4() throws Exception {
+        // Create query
+        String sql = "SELECT x, y FROM (SELECT convert(TimestampValue, date) as x, length(stringkey) as y from bqt1.smalla) as z GROUP BY x, y"; //$NON-NLS-1$
+
+        // Create capabilities
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+            null, capFinder,
+            new String[] { "SELECT TimestampValue, stringkey FROM bqt1.smalla" },  //$NON-NLS-1$
+            true);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+             
+    }       
+    
+    // Test nested functions
+    public void testCase1565_5() throws Exception {
+        // Create query
+        String sql = "SELECT x, COUNT(*) FROM (SELECT convert(intkey + 5, string) AS x FROM bqt1.smalla) as y GROUP BY x"; //$NON-NLS-1$
+
+        // Create capabilities
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+            null, capFinder,
+            new String[] { "SELECT intkey FROM bqt1.smalla" },  //$NON-NLS-1$
+            true);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+             
+    }     
+    
+    // SELECT SUM(x) FROM (SELECT IntKey+1 AS x FROM BQT1.SmallA) AS g
+    public void testAggregateNoGroupByWithNestedFunction() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT SUM(x) FROM (SELECT IntKey+1 AS x FROM BQT1.SmallA) AS g", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { "SELECT IntKey FROM BQT1.SmallA"  }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }     
+    
+    /**
+     * Without inline view support the agg is not pushed down
+     */
+    public void testFunctionInGroupBy() {
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+            "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT CASE WHEN BQT1.SmallA.IntKey >= 5000 THEN '5000 +' ELSE '0-999' END, BQT1.SmallA.IntKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });        
+    }
+    
+    /**
+     * Test what happens when we have a CASE in the GROUP BY and source has aggregate capability but 
+     * does not have CASE capability.  Should not be able to push down GROUP BY.  
+     * 
+     * @since 4.2
+     */
+    public void testFunctionInGroupByCantPush() {
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+            "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, false);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+
+    /**
+     * Test what happens when we have a CASE in the GROUP BY and source has aggregate capability but 
+     * does not have CASE capability.  Should not be able to push down GROUP BY.  
+     * 
+     * @since 4.2
+     */
+    public void testFunctionInGroupByHavingCantPush() {
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+            "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+            "HAVING case when IntKey>=5000 then '5000 +' else '0-999' end = '5000 +'"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, false);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        1,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+    /**
+     * Test what happens when we have a CASE in the GROUP BY and source has aggregate capability but 
+     * does not have CASE capability.  Should not be able to push down GROUP BY.  
+     * 
+     * @since 4.2
+     */
+    public void testFunctionInGroupByCantPushRewritten() {
+        String sql = "SELECT SUM(IntKey), c FROM (SELECT IntKey, case when IntKey>=5000 then '5000 +' else '0-999' end AS c FROM BQT1.SmallA) AS temp GROUP BY c"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, false);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+    
+    public void testFunctionOfAggregateCantPush2() {
+        String sql = "SELECT SUM(length(StringKey || 'x')) + 1 AS x FROM BQT1.SmallA GROUP BY StringKey || 'x' HAVING space(MAX(length((StringKey || 'x') || 'y'))) = '   '"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT StringKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        1,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+    
+    
+    public void testDontPushGroupByUnsupportedFunction() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan(
+            "SELECT e2 as x FROM pm1.g1 GROUP BY upper(e1), e2",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, //$NON-NLS-1$
+            ComparisonMode.EXACT_COMMAND_STRING );
+    
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+                               
+    }
+        
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestInlineView.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestInlineView.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,304 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestInlineView  {
+    
+    public static QueryMetadataInterface createInlineViewMetadata(FakeCapabilitiesFinder capFinder) {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        caps.setFunctionSupport("case", true); //$NON-NLS-1$
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        return metadata;
+    }
+
+	@Test public void testANSIJoinInlineView()  throws Exception {
+		runTest(createANSIJoinInlineView());
+	}	
+	
+	@Test public void testInlineView()  throws Exception {
+		runTest(createInlineView());
+	}
+	
+	@Test public void testInlineViewWithDistinctAndOrderBy() throws Exception {
+		runTest(createInlineViewWithDistinctAndOrderBy());
+	}	
+	
+	@Test public void testInlineViewOfVirtual() throws Exception{
+		runTest(createInlineViewOfVirtual());
+	}
+	
+	@Test public void testInlineViewWithOuterOrderAndGroup() throws Exception {
+		runTest(createInlineViewWithOuterOrderAndGroup());
+	}
+	
+	@Test public void testInlineViewsInUnions() throws Exception {
+		runTest(crateInlineViewsInUnions());
+	}
+	
+	@Test public void testUnionInInlineView() throws Exception{
+		runTest(createUnionInInlineView());
+	}	
+	
+	public static InlineViewCase createANSIJoinInlineView()  throws Exception {
+		String userQuery = "select q1.a from (select count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) q1 left outer join bqt1.smallb on q1.a = bqt1.smallb.intkey where q1.intkey = 1"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT v_0.c_0 FROM (SELECT COUNT(g_0.intkey) AS c_0 FROM bqt1.smalla AS g_0 WHERE g_0.intkey = 1 GROUP BY g_0.intkey) AS v_0 LEFT OUTER JOIN bqt1.smallb AS g_1 ON v_0.c_0 = g_1.intkey"; //$NON-NLS-1$
+		
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1)); 
+		expectedResults.add(row1);
+				
+		Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+        return new InlineViewCase("testANSIJoinInlineView", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);
+        
+	}
+	
+	public static InlineViewCase createInlineView()  throws Exception {
+		String userQuery = "select bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa from (select count(bqt1.smalla.intkey) as aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bqt1.smallb " + //$NON-NLS-1$
+				"where bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.intkey = 1 and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = bqt1.smallb.intkey"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT v_0.c_0 FROM (SELECT COUNT(g_0.intkey) AS c_0 FROM bqt1.smalla AS g_0 WHERE g_0.intkey = 1 GROUP BY g_0.intkey) AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_0 = g_1.intkey"; //$NON-NLS-1$
+		
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1)); 
+		expectedResults.add(row1);
+				
+		Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+        return new InlineViewCase("testInlineView", userQuery, optimizedQuery,  //$NON-NLS-1$
+				sourceQueries, expectedResults);        
+	}	
+	
+	public static InlineViewCase createInlineViewWithDistinctAndOrderBy() throws Exception {
+		String userQuery = "select Q1.a from (select distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2"; //$NON-NLS-1$
+        String optimizedQuery = "SELECT v_0.c_0 FROM (SELECT DISTINCT COUNT(g_0.intkey) AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey HAVING ((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey"; //$NON-NLS-1$
+
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1)); 
+		expectedResults.add(row1);
+				
+        Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+        return new InlineViewCase("testInlineViewWithDistinctAndOrderBy", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);
+        
+	}	
+	
+	public static InlineViewCase createInlineViewOfVirtual() throws Exception{
+		String userQuery = "select q1.A from (select count(intkey) as a, intkey, stringkey from vqt.smalla group by intkey, stringkey) q1 inner join vqt.smallb as q2 on q1.intkey = q2.a12345 where q1.a = 2"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT v_0.c_1 FROM (SELECT g_0.IntKey AS c_0, COUNT(g_0.IntKey) AS c_1 FROM BQT1.SmallA AS g_0 GROUP BY g_0.IntKey, g_0.StringKey HAVING COUNT(g_0.IntKey) = 2) AS v_0, BQT1.SmallA AS g_1 WHERE v_0.c_0 = Concat(g_1.StringKey, g_1.StringNum)"; //$NON-NLS-1$
+
+		List expectedResults = new ArrayList();
+				
+        Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+        return new InlineViewCase("testInlineViewOfVirtual", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);        
+	}	
+	
+	public static InlineViewCase createInlineViewWithOuterOrderAndGroup() throws Exception {
+		String userQuery = "select count(Q1.a) b from (select distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group by Q1.a order by b"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT COUNT(v_0.c_0) AS c_0 FROM (SELECT DISTINCT COUNT(g_0.intkey) AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey HAVING ((COUNT(g_0.intkey) + g_0.intkey) = 2) AND (COUNT(g_0.intkey) = 1)) AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0 ORDER BY c_0"; //$NON-NLS-1$
+
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1));
+		expectedResults.add(row1);
+				
+        Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+        return new InlineViewCase("testInlineViewWithOuterOrderAndGroup", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);        
+	}
+	
+	public static InlineViewCase crateInlineViewsInUnions() throws Exception {
+		String userQuery = "select q1.a from (select count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) q1 left outer join bqt1.smallb on q1.a = bqt1.smallb.intkey where q1.intkey = 1 union all (select count(Q1.a) b from (select distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group by Q1.a order by b)"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT v_1.c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM bqt1.smalla AS g_2 WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN bqt1.smallb AS g_3 ON v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_0) AS c_0 FROM (SELECT DISTINCT COUNT(g_0.IntKey) AS c_0, g_0.IntKey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.IntKey HAVING ((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1)) AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0"; //$NON-NLS-1$
+
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1)); 
+		expectedResults.add(row1);
+		List row2 = new ArrayList();
+        row2.add(new Integer(1)); 
+        expectedResults.add(row2);
+				
+        Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+		return new InlineViewCase("testInlineViewsInUnions", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);
+		
+	}
+	
+	public static InlineViewCase createUnionInInlineView() throws Exception{
+		
+	    String userQuery = "select t1.intkey from (select case when q1.a=1 then 2 else 1 end as a from (select count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) q1 left outer join bqt1.smallb on q1.a = bqt1.smallb.intkey where q1.intkey = 1 union all (select count(Q1.a) b from (select distinct count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey order by bqt1.smalla.intkey) q1 inner join bqt1.smallb as q2 on q1.intkey = q2.intkey where q1.a = 1 and q1.a + q1.intkey = 2 group by Q1.a order by b)) as q3, bqt1.smallb as t1 where q3.a = t1.intkey order by t1.intkey"; //$NON-NLS-1$
+		String optimizedQuery = "SELECT g_4.intkey AS c_0 FROM (SELECT CASE WHEN v_1.c_0 = 1 THEN 2 ELSE 1 END AS c_0 FROM (SELECT COUNT(g_2.intkey) AS c_0 FROM bqt1.smalla AS g_2 WHERE g_2.intkey = 1 GROUP BY g_2.intkey) AS v_1 LEFT OUTER JOIN bqt1.smallb AS g_3 ON v_1.c_0 = g_3.intkey UNION ALL SELECT COUNT(v_0.c_0) AS c_0 FROM (SELECT DISTINCT COUNT(g_0.IntKey) AS c_0, g_0.IntKey AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.IntKey HAVING ((COUNT(g_0.IntKey) + g_0.IntKey) = 2) AND (COUNT(g_0.IntKey) = 1)) AS v_0, bqt1.smallb AS g_1 WHERE v_0.c_1 = g_1.intkey GROUP BY v_0.c_0) AS v_2, bqt1.smallb AS g_4 WHERE v_2.c_0 = g_4.intkey ORDER BY c_0"; //$NON-NLS-1$
+
+		List expectedResults = new ArrayList();
+		List row1 = new ArrayList();
+        row1.add(new Integer(1)); 
+		expectedResults.add(row1);
+		List row2 = new ArrayList();
+        row2.add(new Integer(2)); 
+        expectedResults.add(row2);
+				
+        Set<String> sourceQueries = new HashSet<String>();
+        sourceQueries.add("oracle"); //$NON-NLS-1$ 
+        /*
+         * fails in db2 since the intkey column is in the database as a decimal
+         */
+        //sourceQueries.add("db2"); //$NON-NLS-1$ 
+        sourceQueries.add("sybase"); //$NON-NLS-1$ 
+        sourceQueries.add("sqlserver"); //$NON-NLS-1$ 
+        sourceQueries.add("mysql"); //$NON-NLS-1$
+        sourceQueries.add("postgres"); //$NON-NLS-1$
+		return new InlineViewCase("testUnionInInlineView", userQuery, optimizedQuery, //$NON-NLS-1$
+				sourceQueries, expectedResults);
+		
+	}	
+	
+	protected void runTest(InlineViewCase testCase) throws Exception {
+		FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+    	QueryMetadataInterface metadata = createInlineViewMetadata(capFinder);
+    	
+		ProcessorPlan plan = TestOptimizer.helpPlan(testCase.userQuery, metadata, null, capFinder, new String[] {testCase.optimizedQuery}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); 
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+	}	
+	
+    @Test public void testAliasCreationWithInlineView() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        QueryMetadataInterface metadata = createInlineViewMetadata(capFinder);
+        
+        ProcessorPlan plan = helpPlan("select a, b from (select distinct count(intNum) a, count(stringKey), bqt1.smalla.intkey as b from bqt1.smalla group by bqt1.smalla.intkey) q1 order by q1.a", //$NON-NLS-1$
+                metadata, null, capFinder, new String[] {"SELECT a, b FROM (SELECT DISTINCT COUNT(intNum) AS a, COUNT(stringKey) AS count1, bqt1.smalla.intkey AS b FROM bqt1.smalla GROUP BY bqt1.smalla.intkey) AS q1 ORDER BY a"}, true); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testAliasPreservationWithInlineView() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        QueryMetadataInterface metadata = createInlineViewMetadata(capFinder);
+        
+        ProcessorPlan plan = helpPlan("select q1.a + 1, q1.b from (select count(bqt1.smalla.intNum) as a, bqt1.smalla.intkey as b from bqt1.smalla group by bqt1.smalla.intNum, bqt1.smalla.intkey order by b) q1 where q1.a = 1", //$NON-NLS-1$
+                metadata, null, capFinder, new String[] {"SELECT (q1.a + 1), q1.b FROM (SELECT COUNT(bqt1.smalla.intNum) AS a, bqt1.smalla.intkey AS b FROM bqt1.smalla GROUP BY bqt1.smalla.intNum, bqt1.smalla.intkey HAVING COUNT(bqt1.smalla.intNum) = 1) AS q1"}, true); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);    
+    }
+    
+    /**
+     * Order by's will be added to the atomic queries
+     */
+    @Test public void testCrossSourceInlineView() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        QueryMetadataInterface metadata = createInlineViewMetadata(capFinder);
+        
+        ProcessorPlan plan = helpPlan("select * from (select count(bqt1.smalla.intkey) as a, bqt1.smalla.intkey from bqt1.smalla group by bqt1.smalla.intkey) q1 inner join (select count(bqt2.smallb.intkey) as a, bqt2.smallb.intkey from bqt2.smallb group by bqt2.smallb.intkey) as q2 on q1.intkey = q2.intkey where q1.a = 1", //$NON-NLS-1$
+                metadata, null, capFinder, new String[] {"SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intkey AS c_0, COUNT(g_0.intkey) AS c_1 FROM bqt2.smallb AS g_0 GROUP BY g_0.intkey) AS v_0 ORDER BY c_0", //$NON-NLS-1$
+                                                         "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intkey AS c_0, COUNT(g_0.intkey) AS c_1 FROM bqt1.smalla AS g_0 GROUP BY g_0.intkey HAVING COUNT(g_0.intkey) = 1) AS v_0 ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+                2,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // Join
+                1,      // MergeJoin
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });    
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinOptimization.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,926 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.JoinUtil;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.resource.cci.SourceSystemFunctions;
+
+
+public class TestJoinOptimization {
+    
+    /**
+     * Single group criteria should get pushed and be eligible for copy criteria
+     */
+    @Test public void testInnerJoinPushAndCopyNonJoinCriteria() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla inner join bqt2.smalla on (bqt1.smalla.intkey = bqt2.smalla.intkey and bqt2.smalla.intkey = 1)"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT bqt1.smalla.intkey FROM bqt1.smalla WHERE bqt1.smalla.intkey = 1", "SELECT bqt2.smalla.intkey FROM bqt2.smalla WHERE bqt2.smalla.intkey = 1"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Single group criteria should get pushed when it is on the inner side
+     */
+    @Test public void testOuterJoinPushNonJoinCriteria() {
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join bqt2.smalla on (bqt1.smalla.intkey = bqt2.smalla.intkey and bqt2.smalla.stringkey = 1)"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey AS c_0 FROM bqt1.smalla AS g_0 ORDER BY c_0", "SELECT g_0.intkey AS c_0 FROM bqt2.smalla AS g_0 WHERE g_0.stringkey = '1' ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Single group criteria should not be pushed when it is on the outer side 
+     */
+    @Test public void testOuterJoinPushNonJoinCriteriaA() {
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join bqt2.smalla on (bqt1.smalla.intkey = bqt2.smalla.intkey and bqt1.smalla.stringkey = 1)"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey AS c_0 FROM bqt2.smalla AS g_0 ORDER BY c_0", "SELECT g_0.intkey AS c_0, g_0.stringkey AS c_1 FROM bqt1.smalla AS g_0 ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    @Test public void testOuterJoinPushNonJoinCriteria_Case5547() {
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join bqt2.smalla on (1=1)"; //$NON-NLS-1$
+        String BQT1 = "BQT1";   //$NON-NLS-1$
+        String BQT2 = "BQT2";   //$NON-NLS-1$
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        
+        // ===  Must set the ORDER BY prop on the capabilities object to TRUE
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities(BQT1, caps); 
+        capFinder.addCapabilities(BQT2, caps); 
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, 
+                                                    metadata, 
+                                                    null, 
+                                                    capFinder, 
+                                                    new String[] {"SELECT bqt1.smalla.intkey FROM bqt1.smalla", "SELECT BQT2.SmallA.IntKey FROM bqt2.smalla"}, true ); //$NON-NLS-1$  //$NON-NLS-2$
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+        
+    }
+
+    
+    /**
+     * Single group criteria should not be pushed when it is used in a full outer join
+     * Note that the join has also degraded into a cross join rather than an outer join
+     */
+    @Test public void testFullOuterJoinPushNonJoinCriteria() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla full outer join bqt2.smalla on (bqt1.smalla.intkey = bqt2.smalla.intkey and bqt1.smalla.stringkey = 1 and bqt2.smalla.stringkey = 1)"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey AS c_0, g_0.stringkey AS c_1 FROM bqt2.smalla AS g_0 ORDER BY c_0", "SELECT g_0.intkey AS c_0, g_0.stringkey AS c_1 FROM bqt1.smalla AS g_0 ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Copy criteria should still work here even though the join criteria has an implicit type conversion because
+     * the equality operation on the select criteria can be used. 
+     */
+    @Test public void testCopyCriteriaWithFunction1() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla where bqt1.smalla.stringkey = bqt2.smalla.intkey and bqt2.smalla.intkey = 1"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT bqt1.smalla.intkey FROM bqt1.smalla WHERE bqt1.smalla.stringkey = '1'", "SELECT bqt2.smalla.intkey FROM bqt2.smalla WHERE bqt2.smalla.intkey = 1"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+
+    /**
+     * Copy criteria should not work here as the join criteria has an implicit convert and the where criteria is a non-equality predicate
+     */
+    @Test public void testCopyCriteriaWithFunction2() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla where bqt1.smalla.stringkey = bqt2.smalla.intkey and bqt2.smalla.intkey <> 1"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey FROM bqt2.smalla AS g_0 WHERE g_0.intkey <> 1", "SELECT g_0.stringkey AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * The intkey criteria should not be copied above to bqt1.smalla since the criteria is comming from the inner side in the join below 
+     */
+    @Test public void testInvalidCopyCriteria() {
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla inner join (select bqt3.smalla.intkey from bqt2.smalla left outer join bqt3.smalla on bqt2.smalla.intkey = bqt3.smalla.intkey and bqt3.smalla.intkey = 1) foo on bqt1.smalla.intkey = foo.intkey"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey FROM bqt3.smalla AS g_0 WHERE g_0.intkey = 1", "SELECT g_0.intkey FROM bqt2.smalla AS g_0", "SELECT g_0.intkey AS c_0 FROM bqt1.smalla AS g_0 ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /*
+     * Note that the criteria does not get copied to the outer side.
+     */
+    @Test public void testCopyCriteriaFromInnerSide() throws Exception {
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join (select bqt3.smalla.intkey from bqt3.smalla where bqt3.smalla.intkey = 1) foo on bqt1.smalla.intkey = foo.intkey"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey FROM bqt3.smalla AS g_0 WHERE g_0.intkey = 1", "SELECT g_0.intkey FROM bqt1.smalla AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Check to ensure that the full outer join does not get merged since the where criteria cannot be moved
+     */
+    @Test public void testFullOuterJoinPreservation() {
+        String sql = "select bqt2.mediumb.intkey from bqt2.mediumb full outer join (select bqt2.smallb.intkey from bqt2.smalla left outer join bqt2.smallb on bqt2.smalla.intkey = bqt2.smallb.intkey where bqt2.smalla.stringkey = 1) foo on bqt2.mediumb.intkey = foo.intkey"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                                    new String[] {"SELECT g_1.intkey FROM bqt2.smalla AS g_0 LEFT OUTER JOIN bqt2.smallb AS g_1 ON g_0.intkey = g_1.intkey WHERE g_0.stringkey = '1'", "SELECT g_0.intkey AS c_0 FROM bqt2.mediumb AS g_0 ORDER BY c_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });        
+    }
+    
+    /** 
+     * Same as above but with a 0 group criteria
+     */
+    @Test public void testFullOuterJoinPreservation1() {
+        String sql = "select bqt2.mediumb.intkey from bqt2.mediumb full outer join (select bqt2.smallb.intkey from bqt2.smalla inner join bqt2.smallb on bqt2.smalla.intkey = bqt2.smallb.intkey where ? = 1) foo on bqt2.mediumb.intkey = foo.intkey"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey AS c_0 FROM bqt2.mediumb AS g_0 ORDER BY c_0", "SELECT g_1.intkey FROM bqt2.smalla AS g_0, bqt2.smallb AS g_1 WHERE (g_0.intkey = g_1.intkey) AND (? = 1)"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });        
+    }
+    
+    /** 
+     * Same as above but with a left outer join
+     */
+    @Test public void testOuterJoinPreservation() {
+        String sql = "select bqt2.mediumb.intkey from bqt2.mediumb left outer join (select bqt2.smallb.intkey from bqt2.smalla inner join bqt2.smallb on bqt2.smalla.intkey = bqt2.smallb.intkey where ? = 1) foo on bqt2.mediumb.intkey = foo.intkey"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT g_0.intkey AS c_0 FROM bqt2.mediumb AS g_0 ORDER BY c_0", "SELECT g_1.intkey FROM bqt2.smalla AS g_0, bqt2.smallb AS g_1 WHERE (g_0.intkey = g_1.intkey) AND (? = 1)"}); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });        
+    }
+    
+    @Test public void testCopyCriteriaCreatesFalseCriteria() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla where bqt1.smalla.stringkey = bqt2.smalla.intkey and bqt2.smalla.intkey = 1 and bqt1.smalla.stringkey = '2'"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {});
+
+        TestOptimizer.checkNodeTypes(plan, TestRuleRaiseNull.FULLY_NULL);        
+    }
+    
+    @Test public void testPushNonJoinCriteriaWithFalse() {
+        String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla left outer join bqt2.smalla on (bqt1.smalla.stringkey = bqt2.smalla.intkey and bqt2.smalla.intkey = null)"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {"SELECT bqt1.smalla.intkey, null FROM bqt1.smalla"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);        
+    }
+    
+    @Test public void testPushMultiGroupJoinCriteria() throws Exception {
+        String sql = "select bqt1.smalla.intkey, bqt1.smallb.intkey from bqt1.smalla right outer join (bqt1.smallb cross join (bqt1.mediuma cross join bqt1.mediumb)) on bqt1.smalla.stringkey = bqt1.smallb.stringkey" //$NON-NLS-1$ 
+            +" where bqt1.smallb.intkey + bqt1.mediuma.intkey + bqt1.mediumb.intkey = 1"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[] {"SELECT g_3.intkey, g_0.intkey FROM ((bqt1.smallb AS g_0 CROSS JOIN bqt1.mediuma AS g_1) INNER JOIN bqt1.mediumb AS g_2 ON ((g_0.intkey + g_1.intkey) + g_2.intkey) = 1) LEFT OUTER JOIN bqt1.smalla AS g_3 ON g_3.stringkey = g_0.stringkey"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);        
+    }
+    
+    /**
+     * Since the multigroup criteria spans the inner side, it should not be pushed. 
+     */
+    @Test public void testPushMultiGroupJoinCriteria1() {
+        String sql = "select bqt1.smalla.intkey, bqt1.smallb.intkey from bqt1.smalla right outer join (bqt1.smallb cross join (bqt1.mediuma cross join bqt1.mediumb)) on bqt1.smalla.stringkey = bqt1.smallb.stringkey" //$NON-NLS-1$ 
+            +" where bqt1.smalla.intkey + bqt1.mediuma.intkey + bqt1.mediumb.intkey is null"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[] {"SELECT g_3.intkey, g_0.intkey FROM ((bqt1.smallb AS g_0 CROSS JOIN bqt1.mediuma AS g_1) CROSS JOIN bqt1.mediumb AS g_2) LEFT OUTER JOIN bqt1.smalla AS g_3 ON g_3.stringkey = g_0.stringkey WHERE ((g_3.intkey + g_1.intkey) + g_2.intkey) IS NULL"}, true); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);        
+    }
+    
+    /**
+     * Since the multigroup criteria is not null dependent, it should get pushed. 
+     */
+    @Test public void testPushMultiGroupJoinCriteria2() {
+        String sql = "select bqt1.smalla.intkey, bqt1.smallb.intkey from bqt1.smalla right outer join (bqt1.smallb cross join (bqt1.mediuma cross join bqt1.mediumb)) on bqt1.smalla.stringkey = bqt1.smallb.stringkey" //$NON-NLS-1$ 
+            +" where bqt1.smalla.intkey + bqt1.mediuma.intkey + bqt1.mediumb.intkey = 1"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[] {"SELECT g_3.intkey, g_2.intkey FROM bqt1.mediuma AS g_0, bqt1.mediumb AS g_1, bqt1.smallb AS g_2, bqt1.smalla AS g_3 WHERE (g_3.stringkey = g_2.stringkey) AND (((g_3.intkey + g_0.intkey) + g_1.intkey) = 1)"}, true); //$NON-NLS-1$ 
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);        
+    }
+
+    
+    /**
+     * Having criteria should not be considered as regular criteria (unless it contains no aggregate expressions). 
+     */
+    @Test public void testHavingCriteriaNotUsedAsJoinCriteria() {
+        String sql = "select bqt1.smalla.intkey, max(bqt1.smallb.intkey) from bqt1.smalla, bqt1.smallb where bqt1.smalla.intkey = bqt1.smallb.intnum group by bqt1.smallb.intkey, bqt1.smalla.intkey having max(bqt1.smallb.intkey) = bqt1.smalla.intkey"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_HAVING, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[] {"SELECT bqt1.smalla.intkey, MAX(bqt1.smallb.intkey) FROM bqt1.smalla, bqt1.smallb WHERE bqt1.smalla.intkey = bqt1.smallb.intnum GROUP BY bqt1.smallb.intkey, bqt1.smalla.intkey HAVING MAX(bqt1.smallb.intkey) = bqt1.smalla.intkey"}, true); //$NON-NLS-1$ 
+                
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);  
+    }
+    
+    /**
+     * Ensure that subqueries not initially pushable to the source still get replaced
+     */
+    @Test public void testSubqueryReplacement() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("select Y.e1, Y.e2 FROM vm1.g1 X left outer join vm1.g1 Y on Y.e1 = X.e1 where Y.e3 in (select e3 FROM vm1.g1) or Y.e3 IS NULL", metadata, null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 AS g1__1 LEFT OUTER JOIN pm1.g1 ON pm1.g1.e1 = g1__1.e1 WHERE (pm1.g1.e3 IN (SELECT pm1.g1.e3 FROM pm1.g1)) OR (pm1.g1.e3 IS NULL)"}, true); //$NON-NLS-1$ 
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    @Test public void testRulePushNonJoinCriteriaPreservesOuterJoin() throws Exception {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select b.intkey from (select intkey from bqt1.smalla) a left outer join (select intkey from bqt1.smallb) b on (1 = 1)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, 
+                                                    new String[]{"SELECT g_1.intkey FROM bqt1.smalla AS g_0 LEFT OUTER JOIN bqt1.smallb AS g_1 ON 1 = 1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    @Test public void testOuterToInnerJoinConversion() {
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where bqt1.smallb.intnum = 1"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smalla, bqt1.smallb WHERE (bqt1.smalla.intkey = bqt1.smallb.intkey) AND (bqt1.smallb.intnum = 1)"}); //$NON-NLS-1$
+    }
+    
+    //same as above, but with a right outer join
+    @Test public void testOuterToInnerJoinConversion1() {
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla right outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where bqt1.smalla.intnum = 1"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smallb, bqt1.smalla WHERE (bqt1.smalla.intkey = bqt1.smallb.intkey) AND (bqt1.smalla.intnum = 1)"}); //$NON-NLS-1$
+    }
+    
+    @Test public void testOuterToInnerJoinConversion2() {
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla full outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where bqt1.smallb.intnum = 1"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smallb LEFT OUTER JOIN bqt1.smalla ON bqt1.smalla.intkey = bqt1.smallb.intkey WHERE bqt1.smallb.intnum = 1"}); //$NON-NLS-1$
+    }    
+    
+    @Test public void testOuterToInnerJoinConversion3() {
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla full outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where bqt1.smalla.intnum = 1"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smalla LEFT OUTER JOIN bqt1.smallb ON bqt1.smalla.intkey = bqt1.smallb.intkey WHERE bqt1.smalla.intnum = 1"}); //$NON-NLS-1$
+    }
+    
+    /**
+     * non-depenent criteria on each side of a full outer creates an inner join  
+     */
+    @Test public void testOuterToInnerJoinConversion4() {
+    	QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla full outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where bqt1.smalla.intnum = bqt1.smallb.intnum"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smalla, bqt1.smallb WHERE (bqt1.smalla.intkey = bqt1.smallb.intkey) AND (bqt1.smalla.intnum = bqt1.smallb.intnum)"}); //$NON-NLS-1$
+    }
+        
+    /**
+     * Since concat2 is null dependent the join will not be changed 
+     */
+    @Test public void testOuterToInnerJoinConversionNullDependent() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setFunctionSupport("concat2", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla left outer join bqt1.smallb on (bqt1.smalla.intkey = bqt1.smallb.intkey) where concat2(bqt1.smallb.intnum, '1') = 1"; //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, metadata, null, capFinder, new String[]{"SELECT bqt1.smallb.intnum, bqt1.smalla.intkey FROM bqt1.smalla LEFT OUTER JOIN bqt1.smallb ON bqt1.smalla.intkey = bqt1.smallb.intkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    }
+    
+    @Test public void testInlineViewToHaving() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_HAVING, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        String sql = "select x.y, x.intkey from (select max(intnum) y, intkey from bqt1.smalla group by intkey) x where x.y = 1"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                               new String[]{"SELECT MAX(intnum), intkey FROM bqt1.smalla GROUP BY intkey HAVING MAX(intnum) = 1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    /**
+     * <p>In RuleBreakMultiJoin terminology: 
+     * If any of the regions contains a group with any unsatisfied access patterns, one
+     * of those access patterns could be satisfied by arranging for a dependent join,
+     * provided that group has join criteria which covers the column(s) in an access
+     * pattern, and which joins the group to group(s) in other region(s).  The task, then,
+     * is to ensure that an ordering isn't picked which makes such a dependent join 
+     * impossible.</p>
+     * 
+     * <p>A physical group can have zero or more access patterns; each access pattern can have one
+     * or more columns.  So a group could implicitly be dependent on one or more other physical
+     * groups in one or more other regions.  A table can be used to illustrate the potential
+     * complexity of access patterns:
+     * <pre>
+     * Region with    | Target
+     * Access Patterns| Regions
+     * -------------------------
+     * Reg3           | Reg1, Reg2
+     * Reg3           | Reg4
+     * Reg1           | Reg2
+     * Reg4           | Reg3
+     * </pre></p>
+     * 
+     * This tests now passes with RulePlanJoins
+     */
+    @Test public void testPathologicalAccessPatternCaseCase2976Defect19018() throws Exception{
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        
+        // add single access pattern to pm1.g4 containing elements e1, e2, and e3
+        FakeMetadataStore store = metadata.getStore();
+        FakeMetadataObject pm4g1 = store.findObject("pm4.g1", FakeMetadataObject.GROUP);//$NON-NLS-1$
+        List elementIDs = metadata.getElementIDsInGroupID(pm4g1);
+        elementIDs.remove(2);
+        FakeMetadataObject pm4g1ap1 = FakeMetadataFactory.createAccessPattern("pm4.g1.ap1", pm4g1, elementIDs); //e1,e2,e4 //$NON-NLS-1$
+        store.addObject(pm4g1ap1);
+
+        String sql = "SELECT pm1.g1.e1, pm2.g1.e1, pm4.g1.e1 " +//$NON-NLS-1$
+        "FROM pm1.g1, pm2.g1, pm4.g1 WHERE " +//$NON-NLS-1$
+        "pm1.g1.e1 = pm4.g1.e1 AND pm2.g1.e2 = pm4.g1.e2 AND pm1.g1.e4 = pm2.g1.e4 " +//$NON-NLS-1$
+        "AND pm4.g1.e4 = 3.2";//$NON-NLS-1$
+
+        String[] expected = new String[] {"SELECT g_0.e4 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", //$NON-NLS-1$
+        								  "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm4.g1 AS g_0 WHERE (g_0.e4 = 3.2) AND (g_0.e1 IN (<dependent values>)) AND (g_0.e2 IN (<dependent values>)) ORDER BY c_0, c_1", //$NON-NLS-1$ 
+        								  "SELECT g_0.e4 AS c_0, g_0.e2 AS c_1, g_0.e1 AS c_2 FROM pm2.g1 AS g_0 ORDER BY c_0",//$NON-NLS-1$
+                                          };
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, expected, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        1,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        2,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });          
+    }       
+    
+    /**
+     * non-null dependent criteria should get pushed down
+     */
+    @Test public void testPushMultiGroupCriteriaOuterJoin() { 
+        String sql = "select m.intkey, m.intnum, s.intkey, s.intnum from BQT2.mediuma m left outer join BQT2.smalla s on m.intkey = s.intkey where not (m.intkey + s.intnum = 26)"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_NOT, true); 
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder, 
+                                      new String[] { 
+                                          "SELECT m.intkey, m.intnum, s.intkey, s.intnum FROM BQT2.mediuma AS m, BQT2.smalla AS s WHERE (m.intkey = s.intkey) AND (NOT ((m.intkey + s.intnum) = 26))" }, //$NON-NLS-1$
+                                          TestOptimizer.SHOULD_SUCCEED); 
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+        
+    }
+
+    /**
+     * Assumes that pm1.g1 is the only inner group 
+     */
+    private void helpTestNullDependentVisitor(String critSQL,
+                                              boolean dependent) throws QueryParserException,
+                                                                QueryResolverException,
+                                                                QueryMetadataException,
+                                                                TeiidComponentException {
+        List<GroupSymbol> innerGroups = new ArrayList<GroupSymbol>();
+        innerGroups.add(new GroupSymbol("pm1.g1")); //$NON-NLS-1$
+        
+        Criteria crit = QueryParser.getQueryParser().parseCriteria(critSQL);
+        
+        QueryResolver.resolveCriteria(crit, FakeMetadataFactory.example1Cached());
+        
+        assertEquals(dependent, JoinUtil.isNullDependent(FakeMetadataFactory.example1Cached(), innerGroups, crit));
+    }
+    
+    private void helpTestNullDependent(String expressionSQL,
+                                              boolean dependent) throws QueryParserException,
+                                                                QueryResolverException,
+                                                                QueryMetadataException,
+                                                                TeiidComponentException {
+        List<GroupSymbol> innerGroups = new ArrayList<GroupSymbol>();
+        innerGroups.add(new GroupSymbol("pm1.g1")); //$NON-NLS-1$
+        
+        Expression expr = QueryParser.getQueryParser().parseExpression(expressionSQL);
+        
+        ResolverVisitor.resolveLanguageObject(expr, FakeMetadataFactory.example1Cached());
+        
+        assertEquals(dependent, JoinUtil.isNullDependent(FakeMetadataFactory.example1Cached(), innerGroups, expr));
+    }
+    
+    @Test public void testNullDependentVisitor() throws Exception {
+        helpTestNullDependentVisitor("nvl(pm1.g1.e1, 1) = 1", true); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor1() throws Exception {
+        helpTestNullDependentVisitor("ifnull(pm1.g1.e1, 1) = 1", true); //$NON-NLS-1$
+    }
+
+    @Test public void testNullDependentVisitor2() throws Exception {
+        helpTestNullDependentVisitor("rand(pm1.g1.e2) = 1", true); //$NON-NLS-1$
+    }
+
+    @Test public void testNullDependentVisitor3() throws Exception {
+        helpTestNullDependentVisitor("concat2(pm1.g1.e1, pm1.g1.e2) = '1'", false); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor4() throws Exception {
+        helpTestNullDependentVisitor("nvl(pm1.g2.e1, 1) = 1", true); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor5() throws Exception {
+        helpTestNullDependentVisitor("pm1.g1.e1 is null", true); //$NON-NLS-1$
+    }    
+    
+    @Test public void testNullDependentVisitor6() throws Exception {
+        helpTestNullDependentVisitor("pm1.g1.e1 is not null", false); //$NON-NLS-1$
+    }    
+
+    @Test public void testNullDependentVisitor7() throws Exception {
+        helpTestNullDependentVisitor("pm1.g2.e1 is not null", true); //$NON-NLS-1$
+    }
+    
+    //this is an important test, the or causes this criteria to be null dependent
+    @Test public void testNullDependentVisitor8() throws Exception {
+        helpTestNullDependentVisitor("pm1.g1.e1 = 1 or pm1.g2.e1 = 1", true); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor9() throws Exception {
+        helpTestNullDependentVisitor("pm1.g1.e1 = 1 or pm1.g1.e2 = 2", false); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor10() throws Exception {
+        helpTestNullDependentVisitor("pm1.g1.e1 in (1, pm1.g2.e1)", false); //$NON-NLS-1$
+    }
+    
+    @Test public void testNullDependentVisitor11() throws Exception {
+        helpTestNullDependentVisitor("pm1.g2.e1 in (1, pm1.g1.e1)", true); //$NON-NLS-1$
+    }
+    
+    @Test public void testIsNullDependent() throws Exception {
+        helpTestNullDependent("pm1.g1.e2 + 1", false); //$NON-NLS-1$
+    }
+    
+    @Test public void testIsNullDependent1() throws Exception {
+        helpTestNullDependent("pm1.g2.e2 + 1", true); //$NON-NLS-1$
+    }
+
+    /**
+     *  The criteria will still get pushed to appropriate location, and
+     *  the other side of the join will be removed
+     */
+    @Test public void testCriteriaPushedWithUnionJoin() throws Exception {
+        String sql = "select * from pm1.g1 union join pm1.g2 where g1.e1 = 1"; //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
+                                      null, capFinder, 
+                                      new String[] { 
+                                          "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = '1'" }, //$NON-NLS-1$ 
+                                          TestOptimizer.SHOULD_SUCCEED); 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });
+
+    }
+        
+    /**
+     * union joins allow RuleRemoveVirtual to still take effect 
+     */
+    @Test public void testCriteriaPushedWithUnionJoin1() throws Exception {
+        String sql = "select vm1.g1.e1 from vm1.g1 union join vm1.g2 where g2.e1 = 1"; //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
+                                      null, capFinder, 
+                                      new String[] { 
+                                          "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = '1') AND (g_1.e1 = '1')" }, //$NON-NLS-1$ 
+                                          ComparisonMode.EXACT_COMMAND_STRING);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });
+
+    }
+    
+    /**
+     * null-dependent expressions should prevent merging of virtual layers
+     */
+    @Test public void testNullDependentPreventsMerge() throws Exception { 
+        String sql = "select x from pm1.g1 left outer join (select nvl(e2, 1) x from pm1.g2) y on e2 = x"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);        
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setFunctionSupport(SourceSystemFunctions.IFNULL, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata,
+                                      null, capFinder, 
+                                      new String[] { 
+                                          "SELECT v_0.c_0 FROM pm1.g1 AS g_0 LEFT OUTER JOIN (SELECT ifnull(g_1.e2, 1) AS c_0 FROM pm1.g2 AS g_1) AS v_0 ON g_0.e2 = v_0.c_0" }, //$NON-NLS-1$
+                                          TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); 
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+        
+    }
+    
+    /**
+     * RuleCopyCriteria will remove the first join criteria and the source doesn't support the * function.  However we still
+     * want the join to be pushed since it originally contained proper criteria.
+     */
+    @Test public void testCopyCriteriaJoinPushed() throws Exception {
+    	String sql = "select pm1.g1.e1 from pm1.g1, pm1.g2 where pm1.g1.e1 = pm1.g2.e1 and pm1.g1.e1 = 5 and pm1.g1.e2 * 5 = pm1.g2.e2"; //$NON-NLS-1$
+    	
+    	FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    	
+    	ProcessorPlan plan = TestOptimizer.helpPlan(sql,metadata, 
+    			new String[] { "SELECT g_0.e2, g_1.e2, g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = '5') AND (g_1.e1 = '5')" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    	
+    	TestOptimizer.checkNodeTypes(plan, new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                1,      // Select
+                0,      // Sort
+                0       // UnionAll
+    	});
+    }
+        
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinPushdownRestrictions.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,143 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.resource.cci.ConnectorCapabilities.SupportedJoinCriteria;
+
+
+public class TestJoinPushdownRestrictions {
+
+	@Test public void testThetaRestriction() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1 inner join pm1.g2 on (pm1.g1.e2 + pm1.g2.e2 = 5)"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.THETA);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+        
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.ANY);
+        
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2, g_1.e2 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e2 + g_1.e2) = 5"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+	}
+	
+	@Test public void testEquiRestriction() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1 inner join pm1.g2 on (pm1.g1.e2 < pm1.g2.e2)"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.EQUI);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+        
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.THETA);
+        
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2, g_1.e2 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e2 < g_1.e2"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+	}
+	
+	@Test public void testKeyRestriction() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1 inner join pm1.g2 on (pm1.g1.e2 = pm1.g2.e2)"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.KEY);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+        
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.EQUI);
+        
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2, g_1.e2 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e2 = g_1.e2"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+	}
+	
+	@Test public void testKeyPasses() throws Exception {
+		String sql = "select a.e1, b.e1 from pm4.g1 a, pm4.g2 b where a.e1 = b.e1 and a.e2 = b.e2"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.KEY);
+        capFinder.addCapabilities("pm4", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example4(),  
+        		new String[] {"SELECT g_0.e1, g_1.e1 FROM pm4.g1 AS g_0, pm4.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e2 = g_1.e2)"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$   
+	}
+	
+	@Test public void testCrossJoinWithRestriction() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1, pm1.g2"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.THETA);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+	}
+	
+	@Test public void testOuterRestriction() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1 inner join pm1.g2 on (pm1.g1.e2 + pm1.g2.e2 = 5)"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.ANY);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+	}
+	
+	@Test public void testCriteriaRestrictionWithNonJoinCriteria() throws Exception {
+		String sql = "select pm1.g1.e2, pm1.g2.e2 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e2 = pm1.g2.e2 and pm1.g2.e1 = 'hello')"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.THETA);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm1.g2 AS g_0 WHERE g_0.e1 = 'hello' ORDER BY c_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$   
+	}
+	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinPushdownRestrictions.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinWithFunction.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinWithFunction.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinWithFunction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,438 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2009 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor 
+ * license agreements.  See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ * 
+ * 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 org.teiid.query.optimizer;
+
+import java.util.List;
+
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+
+import junit.framework.TestCase;
+
+
+/**
+ * <p><code>TestCase</code> to cover planning and optimization of JOINs which 
+ * use a scalar function as a symbol or as part of the JOIN criteria.</p>
+ * 
+ * <p>All tests should verify and validate that the scalar function is being  
+ * pushed/merged with the correct layer of the plan.  For example, if a 
+ * non-deterministic function is being merged with a parent node the resulting 
+ * query may alter the final result set.  Most specifically, if the function is 
+ * executed too late during the processing of a command, the results may be 
+ * different than if it were executed earlier during processing.</p>
+ * @since 6.0
+ */
+public class TestJoinWithFunction extends TestCase {
+
+	/**
+	 * <p>Test the use of a non-deterministic function on a user command that 
+	 * performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed on the result returned from the JOIN and
+	 * is expected to be executed for each row of the final result set.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 */
+	public void testNonDeterministicPostJoin() throws Exception {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. RandomTop is the use of RAND() on
+		 * the user command and should result in unique random numbers for each 
+		 * row in the JOINed output.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, RAND() AS RandomTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"("	+ rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0", //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0", //$NON-NLS-1$
+				};
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0  // UnionAll
+		});
+	}
+
+	/**
+	 * <p>Test the use of a non-deterministic function on the source command of a JOIN
+	 * defined by a user command which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed on the result that will be used for one side
+	 * of the JOIN.  The function should only be executed for each row of the the result
+	 * set returned from the left-side of the JOIN which should result in the same return 
+	 * value for multiple rows of the final result set after the JOIN is completed.  For 
+	 * example, if the left-side query is expected to return one row and the right-side 
+	 * query will return three rows which match the JOIN criteria for the one row on the 
+	 * left-side then the expected result should be that the function be executed once to 
+	 * represent the one row from the left-side and the function's return value will be 
+	 * repeated for each of the three post-JOINed results.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 */
+	public void testNonDeterministicPreJoin() throws Exception {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. TopRandom is the use of RAND() on
+		 * the user command while RandomLeft is the use of RAND() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0",  //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+		};
+
+		// create a plan and assert our atomic queries
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				2, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+		});
+	}
+
+	/**
+	 * <p>Test the use of a non-deterministic function on the sub-command of a user
+	 * command and the user command itself, which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 * @see #testNonDeterministicPostJoin
+	 * @see #testNonDeterministicPreJoin
+	 */
+	public void testNonDeterministicPrePostJoin() throws Exception {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. TopRandom is the use of RAND() on
+		 * the user command while RandomLeft is the use of RAND() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft, RAND() AS RandomTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+		
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0",  //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+		};
+
+		// create a plan and assert our atomic queries
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				2, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+		});
+	}
+
+	/**
+	 * <p>Test the use of a deterministic function on the user command which
+	 * performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed prior to the JOIN being executed and should 
+	 * result in the projected symbol becoming a constant.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 */
+	public void testDeterministicPostJoin()  throws Exception {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
+		 * the user command and should result in 10 for each row in the JOINed 
+		 * output.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+		};
+
+		// create a plan and assert our atomic queries
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+		});
+
+		/*
+		 * Retrieve root nodes elements to assert that a constant has 
+		 * has replaced the SQRT() function. 
+		 */
+		List<?> elem = ((RelationalPlan) plan).getRootNode().getElements();
+		Constant expectedConst = new Constant(new Double(10.0));
+		assertEquals("Did not get expected constant value for SqrtTop in root node of plan: ",  //$NON-NLS-1$
+				expectedConst, 
+				((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression()  // should be a AliasSymbol containing an expression 
+			);
+	}
+
+	/**
+	 * <p>The function should be executed prior to the JOIN being executed and should 
+	 * result in the projected symbol becoming a constant.</p>
+
+	 * <p>Test the use of a deterministic function on the source command of a JOIN
+	 * defined by a user command which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed prior to the commands from either side of the
+	 * JOIN being executed and merged into user command prior to the JOIN actually being 
+	 * executed.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 */
+	public void testDeterministicPreJoin() throws Exception {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtLeft is the use of SQRT() 
+		 * within a source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+		};
+
+		// create a plan and assert our atomic queries
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+				});
+
+		/*
+		 * Retrieve root nodes elements to assert that a constant has 
+		 * has replaced the SQRT() function. 
+		 */
+		List<?> elem = ((RelationalPlan) plan).getRootNode().getElements();
+		Constant expectedConst = new Constant(new Double(10.0));
+		assertEquals("Did not get expected constant value for SqrtLeft in root node of plan: ",  //$NON-NLS-1$
+				expectedConst, 
+				((ExpressionSymbol)elem.get(8)).getExpression()  // should be a AliasSymbol containing an expression 
+			); 
+	}
+
+	/**
+	 * <p>Test the use of a deterministic function on the sub-command of a user
+	 * command and the user command itself, which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryValidatorException 
+	 * @throws QueryResolverException 
+	 * @throws QueryParserException 
+	 * @see #testDeterministicPostJoin
+	 * @see #testDeterministicPreJoin
+	 */
+	public void testDeterministicPrePostJoin() throws Exception {
+		// sub-query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// sub-query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
+		 * the user command while SqrtLeft is the use of SQRT() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		// The user command should result in two atomic commands
+		String[] expected = new String[] {
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm1.g1 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+				"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1, g_0.e3 AS c_2, g_0.e4 AS c_3 FROM pm2.g2 AS g_0 ORDER BY c_0",  //$NON-NLS-1$
+		};
+
+		// create a plan and assert our atomic queries
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestOptimizer.example1(), expected, 
+        		ComparisonMode.EXACT_COMMAND_STRING);
+		TestOptimizer.checkNodeTypes(plan, new int[] { 2, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				0, // Grouping
+				0, // NestedLoopJoinStrategy
+				1, // MergeJoinStrategy
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+				});
+
+		/*
+		 * Retrieve root nodes elements to assert that a constant has 
+		 * replaced the SQRT() function for both SqrtTop and SqrtLeft. 
+		 */
+		List<?> elem = ((RelationalPlan) plan).getRootNode().getElements();
+		Constant expectedConst = new Constant(new Double(10.0));
+		assertEquals("Did not get expected constant value for SqrtLeft in root node of plan: ",  //$NON-NLS-1$
+				expectedConst, 
+				((ExpressionSymbol) elem.get(8)).getExpression()  // should be a AliasSymbol containing an expression 
+			); 
+		assertEquals("Did not get expected constant value for SqrtTop in root node of plan: ",  //$NON-NLS-1$
+				expectedConst, 
+				((ExpressionSymbol) ((AliasSymbol) elem.get(9)).getSymbol()).getExpression()  // should be a AliasSymbol containing an expression 
+			);
+	}
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestJoinWithFunction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestLimit.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,890 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.optimizer.TestOptimizer.DependentProjectNode;
+import org.teiid.query.optimizer.TestOptimizer.DependentSelectNode;
+import org.teiid.query.optimizer.TestOptimizer.DupRemoveNode;
+import org.teiid.query.optimizer.TestOptimizer.DupRemoveSortNode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.relational.AccessNode;
+import org.teiid.query.processor.relational.DependentAccessNode;
+import org.teiid.query.processor.relational.GroupingNode;
+import org.teiid.query.processor.relational.LimitNode;
+import org.teiid.query.processor.relational.MergeJoinStrategy;
+import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
+import org.teiid.query.processor.relational.NullNode;
+import org.teiid.query.processor.relational.PlanExecutionNode;
+import org.teiid.query.processor.relational.ProjectNode;
+import org.teiid.query.processor.relational.SelectNode;
+import org.teiid.query.processor.relational.SortNode;
+import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+
+import junit.framework.TestCase;
+
+
+
+/** 
+ * @since 4.3
+ */
+public class TestLimit extends TestCase {
+
+    private static final int[] FULL_PUSHDOWN = new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // Limit
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                0,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            };
+    
+    public static final Class<?>[] NODE_TYPES = new Class[] {
+        AccessNode.class,
+        DependentAccessNode.class,
+        DependentSelectNode.class,
+        DependentProjectNode.class,
+        DupRemoveNode.class,
+        GroupingNode.class,
+        LimitNode.class,
+        NestedLoopJoinStrategy.class,
+        MergeJoinStrategy.class,
+        NullNode.class,
+        PlanExecutionNode.class,
+        ProjectNode.class,
+        SelectNode.class,
+        SortNode.class,
+        UnionAllNode.class
+    };
+    
+    public TestLimit(String name) {
+        super(name);
+    }
+
+    private static FakeMetadataFacade exampleMetadata() {
+        // Create models
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        FakeMetadataObject vm1 = FakeMetadataFactory.createVirtualModel("vm1");  //$NON-NLS-1$
+
+        // Create physical groups
+        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g2 = FakeMetadataFactory.createPhysicalGroup("pm1.g2", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g3 = FakeMetadataFactory.createPhysicalGroup("pm1.g3", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g4 = FakeMetadataFactory.createPhysicalGroup("pm1.g4", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g5 = FakeMetadataFactory.createPhysicalGroup("pm1.g5", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g6 = FakeMetadataFactory.createPhysicalGroup("pm1.g6", pm1); //$NON-NLS-1$
+                
+        // Create physical elements
+        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm1g2e = FakeMetadataFactory.createElements(pm1g2, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm1g3e = FakeMetadataFactory.createElements(pm1g3, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm1g4e = FakeMetadataFactory.createElements(pm1g4,
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        ((FakeMetadataObject)pm1g4e.get(1)).putProperty(FakeMetadataObject.Props.SELECT, Boolean.FALSE);
+        ((FakeMetadataObject)pm1g4e.get(3)).putProperty(FakeMetadataObject.Props.SELECT, Boolean.FALSE);
+        List pm1g5e = FakeMetadataFactory.createElements(pm1g5,
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        ((FakeMetadataObject)pm1g5e.get(0)).putProperty(FakeMetadataObject.Props.SELECT, Boolean.FALSE);
+        List pm1g6e = FakeMetadataFactory.createElements(pm1g6,
+            new String[] { "in", "in3" }, //$NON-NLS-1$ //$NON-NLS-2$ 
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+         
+        // Create virtual groups
+        QueryNode vm1g1n1 = new QueryNode("vm1.g1", "SELECT * FROM pm1.g1 LIMIT 100"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g1 = FakeMetadataFactory.createVirtualGroup("vm1.g1", vm1, vm1g1n1); //$NON-NLS-1$
+
+        // Create virtual elements
+        List vm1g1e = FakeMetadataFactory.createElements(vm1g1, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+
+        QueryNode vm1g2n1 = new QueryNode("vm1.g2", "SELECT * FROM vm1.g1 ORDER BY e1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g2 = FakeMetadataFactory.createVirtualGroup("vm1.g2", vm1, vm1g2n1); //$NON-NLS-1$
+
+        // Create virtual elements
+        List vm1g2e = FakeMetadataFactory.createElements(vm1g2, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+
+        // Add all objects to the store
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(pm1g1);     
+        store.addObjects(pm1g1e);
+        store.addObject(pm1g2);     
+        store.addObjects(pm1g2e);
+        store.addObject(pm1g3); 
+        store.addObjects(pm1g3e);
+        store.addObject(pm1g4);
+        store.addObjects(pm1g4e);
+        store.addObject(pm1g5);
+        store.addObjects(pm1g5e);
+        store.addObject(pm1g6);
+        store.addObjects(pm1g6e);
+        
+        store.addObject(vm1);
+        store.addObject(vm1g1);
+        store.addObjects(vm1g1e);
+        store.addObject(vm1g2);
+        store.addObjects(vm1g2e);
+
+        // Create the facade from the store
+        return new FakeMetadataFacade(store);
+    }
+    public void testLimit() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitPushdown() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+
+    public void testLimitWithOffset() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testPushedLimitWithOffset() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitWithOffsetFullyPushed() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true); 
+        caps.setCapabilitySupport(Capability.ROW_OFFSET, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 50, 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+    
+    public void testSort() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 order by e1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+
+    public void testSortPushed() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm3.g1 order by e1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 ORDER BY pm3.g1.e1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+
+    public void testSortPushedWithLimit() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm3.g1 order by e1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 ORDER BY pm3.g1.e1 LIMIT 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+
+    public void testSortUnderLimitNotRemoved() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM (SELECT * FROM pm3.g1 order by e1 limit 100) AS V1 ORDER BY v1.e2";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            2,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    //TODO: there is a redundent project node here
+    public void testSortAboveLimitNotPushed() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM vm1.g2 order by e1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, exampleMetadata(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitNotPushedWithUnion() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 UNION SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitPushedWithUnion() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2 LIMIT 100", "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 100" //$NON-NLS-1$ //$NON-NLS-2$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitWithOffsetPushedWithUnion() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.ROW_OFFSET, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 50, 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT PM1.g2.e1 AS c_0, PM1.g2.e2 AS c_1, PM1.g2.e3 AS c_2, PM1.g2.e4 AS c_3 FROM PM1.g2 LIMIT (100 + 50)", "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$ //$NON-NLS-2$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitNotPushedWithUnionOrderBy() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 ORDER BY e1 LIMIT 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2", "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" //$NON-NLS-1$ //$NON-NLS-2$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }, NODE_TYPES);
+        TestOptimizer.checkNodeTypes(plan, new int[] {1}, new Class[]{DupRemoveSortNode.class});
+    }
+    
+    public void testCombinedLimits() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x LIMIT 20, 75";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT CASE WHEN (75 + (20 + 10)) < (100 + 10) THEN (75 + (20 + 10)) ELSE (100 + 10) END" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }, NODE_TYPES);
+    }
+
+    public void testCombinedLimitsWithOffset() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.ROW_OFFSET, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x LIMIT 20, 75";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (20 + 10), CASE WHEN 75 < 100 THEN 75 ELSE 100 END" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+
+    public void testInlineView() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        //caps.setCapabilitySupport(SourceCapabilities.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM (SELECT * FROM pm3.g1) as v1 limit 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 LIMIT 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+    
+    /**
+     * This turns out to be an important test for LIMIT: there are several nodes
+     * (e.g. grouping, inline views, aggregates, sorting, joins, etc) that should not be pushed
+     * down (because they change row order or row count) if there is already a limit node in that plan branch,
+     * which can only be placed above LIMIT with an inline view. This test acts as a gatekeeper for avoiding
+     * several of those pushdowns.
+     * 
+     * @since 4.3
+     */
+    public void testInlineViewAboveLimitNotMerged() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM (SELECT * FROM pm3.g1 limit 100) as v1 order by e1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT v_0.c_0, v_0.c_1, v_0.c_2, v_0.c_3 FROM (SELECT pm3.g1.e1 AS c_0, pm3.g1.e2 AS c_1, pm3.g1.e3 AS c_2, pm3.g1.e4 AS c_3 FROM pm3.g1 LIMIT 100) AS v_0 ORDER BY c_0" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    /**
+     * since there is no order by with the nested limit, the criteria can be pushed through 
+     *
+     */
+    public void testCriteriaPushedUnderLimit() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        // pm3 model supports order by
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        String sql = "SELECT * FROM (SELECT * FROM pm3.g1 limit 100) as v1 where v1.e1 = 1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 WHERE pm3.g1.e1 = '1' LIMIT 100" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+    
+    public void testInlineViewJoin() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT x FROM ((SELECT e1 as x FROM pm1.g1 LIMIT 700) c INNER JOIN (SELECT e1 FROM pm1.g2) d ON d.e1 = c.x) order by x LIMIT 5";//$NON-NLS-1$
+        String[] expectedSql = new String[] {"SELECT e1 FROM pm1.g1 LIMIT 700", "SELECT e1 FROM pm1.g2"};//$NON-NLS-1$ //$NON-NLS-2$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                      null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Limit
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        1,      // Sort
+                                        0       // UnionAll
+        }, NODE_TYPES);
+        
+        //test to ensure that the unnecessary inline view removal is done properly
+        FakeDataManager fdm = new FakeDataManager();
+        TestProcessor.sampleData1(fdm);
+        TestProcessor.helpProcess(plan, fdm, new List[] {
+        		Arrays.asList("a"), //$NON-NLS-1$
+        		Arrays.asList("a"), //$NON-NLS-1$
+        		Arrays.asList("a"), //$NON-NLS-1$
+        		Arrays.asList("a"), //$NON-NLS-1$
+        		Arrays.asList("a"), //$NON-NLS-1$
+        });
+    }
+    
+    public void testDontPushSelectWithOrderedLimit() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "select * from (SELECT e1 as x FROM pm1.g1 order by x LIMIT 700) y where x = 1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"};//$NON-NLS-1$ 
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                      null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Limit
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        1,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testDontPushSelectWithOrderedLimit1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "select * from (SELECT e1 as x FROM pm1.g1 order by x LIMIT 10, 700) y where x = 1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"};//$NON-NLS-1$ 
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                      null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Limit
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        1,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitWithNoAccessNode() {
+        String sql = "select 1 limit 1";//$NON-NLS-1$
+        String[] expectedSql = new String[] {};
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), expectedSql);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        0,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Limit
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    /**
+     * Note here that the criteria made it to the having clause 
+     */
+    public void testAggregateCriteriaOverUnSortedLimit() {
+        String sql = "select a from (SELECT MAX(e2) as a FROM pm1.g1 GROUP BY e2 LIMIT 1) x where a = 0"; //$NON-NLS-1$
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        caps.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_HAVING, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        String[] expectedSql = new String[] {"SELECT MAX(e2) FROM pm1.g1 GROUP BY e2 HAVING MAX(e2) = 0 LIMIT 1"};//$NON-NLS-1$ 
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN, NODE_TYPES);
+    }
+    
+    public void testSortWithLimitInlineView() {
+        String sql = "select e1 from (select pm1.g1.e1, pm1.g1.e2 from pm1.g1 order by pm1.g1.e1, pm1.g1.e2 limit 1) x"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0, g_0.e2"}); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                1,      // Limit
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+        }, NODE_TYPES);
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,6782 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.AliasGenerator;
+import org.teiid.query.optimizer.relational.rules.CapabilitiesUtil;
+import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.AccessNode;
+import org.teiid.query.processor.relational.DependentAccessNode;
+import org.teiid.query.processor.relational.GroupingNode;
+import org.teiid.query.processor.relational.JoinNode;
+import org.teiid.query.processor.relational.JoinStrategy;
+import org.teiid.query.processor.relational.MergeJoinStrategy;
+import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
+import org.teiid.query.processor.relational.NullNode;
+import org.teiid.query.processor.relational.PartitionedSortJoin;
+import org.teiid.query.processor.relational.PlanExecutionNode;
+import org.teiid.query.processor.relational.ProjectIntoNode;
+import org.teiid.query.processor.relational.ProjectNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.processor.relational.SelectNode;
+import org.teiid.query.processor.relational.SortNode;
+import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.processor.relational.SortUtility.Mode;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.BindVariableVisitor;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorReport;
+import org.teiid.resource.cci.SourceSystemFunctions;
+
+
+public class TestOptimizer {
+
+    public interface DependentJoin {}
+    public interface DependentSelectNode {}
+    public interface DependentProjectNode {}
+    public interface DupRemoveNode {}
+    public interface DupRemoveSortNode {}
+    
+    public static final int[] FULL_PUSHDOWN = new int[] {
+                                            1,      // Access
+                                            0,      // DependentAccess
+                                            0,      // DependentSelect
+                                            0,      // DependentProject
+                                            0,      // DupRemove
+                                            0,      // Grouping
+                                            0,      // NestedLoopJoinStrategy
+                                            0,      // MergeJoinStrategy
+                                            0,      // Null
+                                            0,      // PlanExecution
+                                            0,      // Project
+                                            0,      // Select
+                                            0,      // Sort
+                                            0       // UnionAll
+                                        };
+    
+    public enum ComparisonMode { EXACT_COMMAND_STRING, CORRECTED_COMMAND_STRING, FAILED_PLANNING }
+    
+    public static final boolean SHOULD_SUCCEED = true;
+    public static final boolean SHOULD_FAIL = false;
+
+	// ################################## TEST HELPERS ################################
+
+    public static BasicSourceCapabilities getTypicalCapabilities() {        
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);    
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);    
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_BETWEEN, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_LIKE, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_LIKE_ESCAPE, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_ISNULL, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_OR, true);    
+        caps.setCapabilitySupport(Capability.CRITERIA_NOT, true);    
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);    
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY_UNRELATED, true);
+        
+        // set typical max set size
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        return caps;    
+    }
+    
+    public static CapabilitiesFinder getGenericFinder(boolean supportsJoins) {
+    	final BasicSourceCapabilities caps = getTypicalCapabilities();
+    	if (!supportsJoins) {
+	    	caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
+		    caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+    	}
+        return new DefaultCapabilitiesFinder(caps);
+    }
+    
+    public static CapabilitiesFinder getGenericFinder() {
+    	return getGenericFinder(true);
+    }
+
+	public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, String[] expectedAtomic) {
+		return helpPlan(sql, md, null, getGenericFinder(), expectedAtomic, SHOULD_SUCCEED);
+	}
+	
+	public static ProcessorPlan helpPlan(String sql,
+			QueryMetadataInterface md, String[] expected,
+			CapabilitiesFinder capFinder,
+			ComparisonMode mode) throws TeiidComponentException, TeiidProcessingException {
+		return helpPlan(sql, md, null, capFinder, expected, mode);
+	}    
+	
+	public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, String[] expectedAtomic, ComparisonMode mode) throws TeiidComponentException, TeiidProcessingException {
+        return helpPlan(sql, md, null, getGenericFinder(), expectedAtomic, mode);
+    }
+	
+    public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, List bindings, CapabilitiesFinder capFinder, String[] expectedAtomic, boolean shouldSucceed) {
+        Command command;
+        try {
+            command = helpGetCommand(sql, md, bindings);
+        } catch (TeiidException err) {
+            throw new TeiidRuntimeException(err);
+        }
+
+        return helpPlanCommand(command, md, capFinder, null, expectedAtomic, shouldSucceed ? ComparisonMode.CORRECTED_COMMAND_STRING : ComparisonMode.FAILED_PLANNING);
+    } 
+    
+    public static ProcessorPlan helpPlan(String sql, QueryMetadataInterface md, List bindings, CapabilitiesFinder capFinder, String[] expectedAtomic, ComparisonMode mode) throws TeiidComponentException, TeiidProcessingException {
+        Command command = helpGetCommand(sql, md, bindings);
+
+        return helpPlanCommand(command, md, capFinder, null, expectedAtomic, mode);
+    } 
+
+    
+    public static Command helpGetCommand(String sql, QueryMetadataInterface md, List bindings) throws TeiidComponentException, TeiidProcessingException { 
+		if(DEBUG) System.out.println("\n####################################\n" + sql);	 //$NON-NLS-1$
+		Command command = QueryParser.getQueryParser().parseCommand(sql);
+		
+		// resolve
+		QueryResolver.resolveCommand(command, md);
+        
+        ValidatorReport repo = Validator.validate(command, md);
+
+        Collection failures = new ArrayList();
+        repo.collectInvalidObjects(failures);
+        if (failures.size() > 0){
+            fail("Exception during validation (" + repo); //$NON-NLS-1$
+        }
+        
+        // bind variables
+        if(bindings != null) {
+            BindVariableVisitor.bindReferences(command, bindings, md);
+        }                       	
+
+		// rewrite
+		command = QueryRewriter.rewrite(command, md, new CommandContext());
+
+        return command;
+    }
+
+    public static ProcessorPlan helpPlanCommand(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, String[] expectedAtomic, ComparisonMode mode) {
+        if (capFinder == null){
+            capFinder = getGenericFinder();
+        }
+        
+        // Collect atomic queries
+        ProcessorPlan plan = getPlan(command, md, capFinder, analysisRecord, mode != ComparisonMode.FAILED_PLANNING);
+               
+        if (mode == ComparisonMode.CORRECTED_COMMAND_STRING) {
+            checkAtomicQueries(expectedAtomic, plan, md, capFinder);
+        } else if (mode == ComparisonMode.EXACT_COMMAND_STRING) {
+            checkAtomicQueries(expectedAtomic, plan);
+        }
+
+        return plan;
+    }
+    
+    public static void checkAtomicQueries(String[] expectedAtomic,
+                                          ProcessorPlan plan) {
+       Set<String> actualQueries = getAtomicQueries(plan);
+       
+       if (actualQueries.size() != 1 || expectedAtomic.length != 1) {
+           // Compare atomic queries
+           HashSet<String> expectedQueries = new HashSet<String>(Arrays.asList(expectedAtomic));
+           assertEquals("Did not get expected atomic queries: ", expectedQueries, actualQueries); //$NON-NLS-1$
+       } else {
+           assertEquals("Did not get expected atomic query: ", expectedAtomic[0], actualQueries.iterator().next()); //$NON-NLS-1$
+       }
+   }
+
+    public static void checkAtomicQueries(String[] expectedAtomic,
+                                           ProcessorPlan plan, QueryMetadataInterface md, CapabilitiesFinder capFinder) {
+        Set actualQueries = getAtomicQueries(plan);
+        
+        HashSet<String> expectedQueries = new HashSet<String>();
+        
+        // Compare atomic queries
+        for (int i = 0; i < expectedAtomic.length; i++) {
+            final String sql = expectedAtomic[i];
+            Command command;
+            try {
+                command = helpGetCommand(sql, md, null);
+                Collection groups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false);
+                final GroupSymbol symbol = (GroupSymbol)groups.iterator().next();
+                Object modelId = md.getModelID(symbol.getMetadataID());
+                boolean supportsGroupAliases = CapabilitiesUtil.supportsGroupAliases(modelId, md, capFinder);
+                command.acceptVisitor(new AliasGenerator(supportsGroupAliases));
+                expectedQueries.add(command.toString());
+            } catch (Exception err) {
+                throw new RuntimeException(err);
+            }
+        } 
+        
+        assertEquals("Did not get expected atomic queries: ", expectedQueries, actualQueries); //$NON-NLS-1$
+    }
+    
+    static ProcessorPlan getPlan(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, boolean shouldSucceed) {
+		// plan
+		ProcessorPlan plan = null;
+		if (analysisRecord == null) {
+        	analysisRecord = new AnalysisRecord(false, DEBUG);
+		}
+		if (shouldSucceed) {
+			try {
+				//do planning
+				plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, new CommandContext());
+
+			} catch (Throwable e) {
+				throw new TeiidRuntimeException(e);
+			} finally {
+                if(DEBUG) {
+                    System.out.println(analysisRecord.getDebugLog());
+                }
+			}
+		} else {
+			Exception exception = null;
+			try {
+				//do planning
+				QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, null);
+
+			} catch (QueryPlannerException e) {
+				exception = e;
+			} catch (TeiidComponentException e) {
+				exception = e;
+			} catch (Throwable e) {
+                throw new TeiidRuntimeException(e);
+            } finally {
+                if(DEBUG) {
+                    System.out.println(analysisRecord.getDebugLog());
+                }
+			}
+			assertNotNull("Expected exception but did not get one.", exception); //$NON-NLS-1$
+			return null;
+		}
+        
+        assertNotNull("Output elements are null", plan.getOutputElements()); //$NON-NLS-1$
+        		
+		if(DEBUG) System.out.println("\n" + plan);	 //$NON-NLS-1$
+		        
+		return plan;
+	}
+    
+    public static Set<String> getAtomicQueries(ProcessorPlan plan) {
+    	Set<Command> atomicQueries = new HashSet<Command>();        
+        if(plan instanceof RelationalPlan) {
+            getAtomicCommands( ((RelationalPlan)plan).getRootNode(), atomicQueries );    
+        } 
+        
+        Set<String> stringQueries = new HashSet<String>();
+        
+        for (Command command : atomicQueries) {
+           stringQueries.add(command.toString());
+        }
+        
+        return stringQueries;
+    }
+    
+    private static void getAtomicCommands(RelationalNode node, Set<Command> atomicQueries) {
+        if(node instanceof AccessNode) {
+            AccessNode accessNode = (AccessNode) node;
+            atomicQueries.add( accessNode.getCommand());   
+        } 
+        
+        // Recurse through children
+        RelationalNode[] children = node.getChildren();
+        for(int i=0; i<children.length; i++) {
+            if(children[i] != null) {
+                getAtomicCommands(children[i], atomicQueries);
+            } else {
+                break;
+            }
+        }
+    }
+    
+    // Counts are (mostly) alphabetical:
+    //   Access, DependentAccess, DependentSelect, DependentProject, DupRemove, Grouping, NestedLoopJoinStrategy, Null, PlanExecution, Project, Select, Sort, UnionAll
+    private static final Class[] COUNT_TYPES = new Class[] {
+        AccessNode.class,
+        DependentAccessNode.class,
+        DependentSelectNode.class,
+        DependentProjectNode.class,
+        DupRemoveNode.class,
+        GroupingNode.class,
+        NestedLoopJoinStrategy.class,
+        MergeJoinStrategy.class,
+        NullNode.class,
+        PlanExecutionNode.class,
+        ProjectNode.class,
+        SelectNode.class,
+        SortNode.class,
+        UnionAllNode.class
+    };
+            
+    public static void checkNodeTypes(ProcessorPlan root, int[] expectedCounts) {
+        checkNodeTypes(root, expectedCounts, COUNT_TYPES);
+    }    
+    
+    public static void checkNodeTypes(ProcessorPlan root, int[] expectedCounts, Class[] types) {
+        if(! (root instanceof RelationalPlan)) {
+            return;
+        }
+                
+        int[] actualCounts = new int[types.length];
+        collectCounts(((RelationalPlan)root).getRootNode(), actualCounts, types);
+
+        for(int i=0; i<expectedCounts.length; i++) {
+            assertEquals("Did not find the correct number of nodes for type " + types[i], //$NON-NLS-1$
+                        expectedCounts[i], actualCounts[i]);
+        }
+    }    
+    
+    /**
+     * Method collectCounts.
+     * @param relationalNode
+     * @return int[]
+     */
+    static void collectCounts(RelationalNode relationalNode, int[] counts, Class<?>[] types) {
+        Class<?> nodeType = relationalNode.getClass();
+        if(nodeType.equals(JoinNode.class)) {
+        	JoinStrategy strategy = ((JoinNode)relationalNode).getJoinStrategy();
+            if (strategy instanceof NestedLoopJoinStrategy) {
+                updateCounts(NestedLoopJoinStrategy.class, counts, types);
+            } else if (strategy instanceof MergeJoinStrategy) {
+                updateCounts(MergeJoinStrategy.class, counts, types);
+                if (strategy instanceof PartitionedSortJoin) {
+                    updateCounts(PartitionedSortJoin.class, counts, types);
+                } 
+            } 
+            if (((JoinNode)relationalNode).isDependent()) {
+                updateCounts(DependentJoin.class, counts, types);
+            }
+        }else if (nodeType.equals(ProjectNode.class)){
+        	if (ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((ProjectNode)relationalNode).getSelectSymbols()).isEmpty()) {
+        		updateCounts(ProjectNode.class, counts, types);
+        	} else {
+        		updateCounts(DependentProjectNode.class, counts, types);
+        	}
+        }else if (nodeType.equals(SelectNode.class)){
+        	if (ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((SelectNode)relationalNode).getCriteria()).isEmpty()) {
+        		updateCounts(SelectNode.class, counts, types);
+        	} else {
+        		updateCounts(DependentSelectNode.class, counts, types);
+        	}
+        } else if (nodeType.equals(SortNode.class)) {
+        	Mode mode = ((SortNode)relationalNode).getMode();
+        	switch(mode) {
+        	case DUP_REMOVE:
+                updateCounts(DupRemoveNode.class, counts, types);
+        		break;
+        	case DUP_REMOVE_SORT:
+                updateCounts(DupRemoveSortNode.class, counts, types);
+        		break;
+        	case SORT:
+                updateCounts(SortNode.class, counts, types);
+        		break;
+        	}
+        } else {
+            updateCounts(nodeType, counts, types);
+        }
+        
+        RelationalNode[] children = relationalNode.getChildren();
+        for(int i=0; i<children.length; i++) {
+            if(children[i] != null) {
+                collectCounts(children[i], counts, types);
+            } else {
+                break;
+            }
+        }
+    }         
+    
+    private static void updateCounts(Class nodeClass, int[] counts, Class[] types) {
+        for(int i=0; i<types.length; i++) {
+            if(types[i].equals(nodeClass)) {
+                counts[i] = counts[i] + 1;
+                return;
+            }    
+        }
+    }    
+    
+    public static void checkDependentJoinCount(ProcessorPlan plan, int expectedCount) {
+        checkNodeTypes(plan, new int[] {expectedCount}, new Class[] {DependentJoin.class});
+    }
+                
+	public static FakeMetadataFacade example1() {
+		// Create models
+		FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        FakeMetadataObject pm2 = FakeMetadataFactory.createPhysicalModel("pm2"); //$NON-NLS-1$
+		FakeMetadataObject vm1 = FakeMetadataFactory.createVirtualModel("vm1");	 //$NON-NLS-1$
+
+		// Create physical groups
+		FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
+		FakeMetadataObject pm1g2 = FakeMetadataFactory.createPhysicalGroup("pm1.g2", pm1); //$NON-NLS-1$
+		FakeMetadataObject pm1g3 = FakeMetadataFactory.createPhysicalGroup("pm1.g3", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g4 = FakeMetadataFactory.createPhysicalGroup("pm1.g4", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g5 = FakeMetadataFactory.createPhysicalGroup("pm1.g5", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g6 = FakeMetadataFactory.createPhysicalGroup("pm1.g6", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g7 = FakeMetadataFactory.createPhysicalGroup("pm1.g7", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm1g8 = FakeMetadataFactory.createPhysicalGroup("pm1.g8", pm1); //$NON-NLS-1$
+        FakeMetadataObject pm2g1 = FakeMetadataFactory.createPhysicalGroup("pm2.g1", pm2); //$NON-NLS-1$
+        FakeMetadataObject pm2g2 = FakeMetadataFactory.createPhysicalGroup("pm2.g2", pm2); //$NON-NLS-1$
+        FakeMetadataObject pm2g3 = FakeMetadataFactory.createPhysicalGroup("pm2.g3", pm2); //$NON-NLS-1$
+				
+		// Create physical elements
+		List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List pm1g2e = FakeMetadataFactory.createElements(pm1g2, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List pm1g3e = FakeMetadataFactory.createElements(pm1g3, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm1g4e = FakeMetadataFactory.createElements(pm1g4, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List pm1g5e = FakeMetadataFactory.createElements(pm1g5, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List pm1g6e = FakeMetadataFactory.createElements(pm1g6, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List pm1g7e = FakeMetadataFactory.createElements(pm1g7, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List pm1g8e = FakeMetadataFactory.createElements(pm1g8, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List pm2g1e = FakeMetadataFactory.createElements(pm2g1, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm2g2e = FakeMetadataFactory.createElements(pm2g2, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List pm2g3e = FakeMetadataFactory.createElements(pm2g3, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+
+		// Create virtual groups
+		QueryNode vm1g1n1 = new QueryNode("vm1.g1", "SELECT * FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1g1 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g1", vm1, vm1g1n1); //$NON-NLS-1$
+
+		QueryNode vm1g2n1 = new QueryNode("vm1.g2", "SELECT * FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1g2 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g2", vm1, vm1g2n1); //$NON-NLS-1$
+
+		//defect 8096
+		QueryNode vm1sub1n1 = new QueryNode("vm1.sub1", "SELECT * FROM vm1.g1 WHERE e1 IN (SELECT e1 FROM vm1.g3)"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1sub1 = FakeMetadataFactory.createVirtualGroup("vm1.sub1", vm1, vm1sub1n1); //$NON-NLS-1$
+
+		QueryNode vm1g3n1 = new QueryNode("vm1.g3", "SELECT * FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1g3 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g3", vm1, vm1g3n1); //$NON-NLS-1$
+
+        QueryNode vm1g4n1 = new QueryNode("vm1.g4", "SELECT pm1.g1.e1, pm1.g2.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1=pm1.g2.e1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g4 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g4", vm1, vm1g4n1); //$NON-NLS-1$
+
+        QueryNode vm1g5n1 = new QueryNode("vm1.g5", "SELECT DISTINCT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g5 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g5", vm1, vm1g5n1); //$NON-NLS-1$
+
+        QueryNode vm1g6n1 = new QueryNode("vm1.g6", "SELECT e1, convert(e2, string), 3 as e3, ((e2+e4)/3) as e4 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g6 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.g6", vm1, vm1g6n1); //$NON-NLS-1$
+
+		QueryNode vm1u1n1 = new QueryNode("vm1.u1", "SELECT * FROM pm1.g1 UNION SELECT * FROM pm1.g2 UNION ALL SELECT * FROM pm1.g3"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1u1 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u1", vm1, vm1u1n1); //$NON-NLS-1$
+
+		QueryNode vm1u2n1 = new QueryNode("vm1.u2", "SELECT * FROM pm1.g1 UNION SELECT * FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1u2 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u2", vm1, vm1u2n1); //$NON-NLS-1$
+
+		QueryNode vm1u3n1 = new QueryNode("vm1.u3", "SELECT e1 FROM pm1.g1 UNION SELECT convert(e2, string) as x FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+		FakeMetadataObject vm1u3 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u3", vm1, vm1u3n1); //$NON-NLS-1$
+
+        QueryNode vm1u4n1 = new QueryNode("vm1.u4", "SELECT concat(e1, 'x') as v1 FROM pm1.g1 UNION ALL SELECT e1 FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u4 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u4", vm1, vm1u4n1); //$NON-NLS-1$
+
+        QueryNode vm1u5n1 = new QueryNode("vm1.u5", "SELECT concat(e1, 'x') as v1 FROM pm1.g1 UNION ALL SELECT concat('a', e1) FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u5 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u5", vm1, vm1u5n1); //$NON-NLS-1$
+
+        QueryNode vm1u6n1 = new QueryNode("vm1.u6", "SELECT x1.e1 AS elem, 'xyz' AS const FROM pm1.g1 AS x1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u6 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u6", vm1, vm1u6n1); //$NON-NLS-1$
+
+        QueryNode vm1u7n1 = new QueryNode("vm1.u7", "SELECT 's1' AS const, e1 FROM pm1.g1 UNION ALL SELECT 's2', e1 FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u7 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u7", vm1, vm1u7n1); //$NON-NLS-1$
+
+        QueryNode vm1u8n1 = new QueryNode("vm1.u8", "SELECT const, e1 FROM vm1.u7 UNION ALL SELECT 's3', e1 FROM pm1.g3"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u8 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u8", vm1, vm1u8n1); //$NON-NLS-1$
+
+        QueryNode vm1u9n1 = new QueryNode("vm1.u9", "SELECT e1 as a, e1 as b FROM pm1.g1 UNION ALL SELECT e1, e1 FROM pm1.g2"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1u9 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.u9", vm1, vm1u9n1); //$NON-NLS-1$
+
+        QueryNode vm1a1n1 = new QueryNode("vm1.a1", "SELECT e1, SUM(e2) AS sum_e2 FROM pm1.g1 GROUP BY e1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a1 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a1", vm1, vm1a1n1); //$NON-NLS-1$
+        
+        QueryNode vm1a2n1 = new QueryNode("vm1.a2", "SELECT e1, SUM(e2) AS sum_e2 FROM pm1.g1 GROUP BY e1 HAVING SUM(e2) > 5"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a2 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a2", vm1, vm1a2n1); //$NON-NLS-1$
+
+        QueryNode vm1a3n1 = new QueryNode("vm1.a3", "SELECT SUM(e2) AS sum_e2 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a3 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a3", vm1, vm1a3n1); //$NON-NLS-1$
+        
+        QueryNode vm1a4n1 = new QueryNode("vm1.a4", "SELECT COUNT(*) FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a4 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a4", vm1, vm1a4n1); //$NON-NLS-1$
+
+        QueryNode vm1a5n1 = new QueryNode("vm1.a5", "SELECT vm1.a4.count FROM vm1.a4 UNION ALL SELECT COUNT(*) FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a5 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a5", vm1, vm1a5n1); //$NON-NLS-1$
+
+        QueryNode vm1a6n1 = new QueryNode("vm1.a6", "SELECT COUNT(*) FROM vm1.u2"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1a6 = FakeMetadataFactory.createUpdatableVirtualGroup("vm1.a6", vm1, vm1a6n1); //$NON-NLS-1$
+        
+        QueryNode vm1g7n1 = new QueryNode("vm1.g7", "select DECODESTRING(e1, 'S,Pay,P,Rec') as e1, e2 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vm1g7 = FakeMetadataFactory.createVirtualGroup("vm1.g7", vm1, vm1g7n1); //$NON-NLS-1$
+        
+		// Create virtual elements
+		List vm1g1e = FakeMetadataFactory.createElements(vm1g1, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List vm1g2e = FakeMetadataFactory.createElements(vm1g2, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List vm1g3e = FakeMetadataFactory.createElements(vm1g3, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		//for defect 8096
+		List vm1sub1e = FakeMetadataFactory.createElements(vm1sub1, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List vm1g4e = FakeMetadataFactory.createElements(vm1g4, 
+            new String[] { "e1", "e2" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+        List vm1g5e = FakeMetadataFactory.createElements(vm1g5, 
+            new String[] { "e1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING});
+        List vm1g6e = FakeMetadataFactory.createElements(vm1g6, 
+            new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.DOUBLE });
+        List vm1g7e = FakeMetadataFactory.createElements(vm1g7, 
+            new String[] { "e1", "e2"}, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER});
+        List vm1u1e = FakeMetadataFactory.createElements(vm1u1, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List vm1u2e = FakeMetadataFactory.createElements(vm1u2, 
+			new String[] { "e1", "e2", "e3", "e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
+		List vm1u3e = FakeMetadataFactory.createElements(vm1u3, 
+			new String[] { "e1" }, //$NON-NLS-1$
+			new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u4e = FakeMetadataFactory.createElements(vm1u4, 
+            new String[] { "v1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u5e = FakeMetadataFactory.createElements(vm1u5, 
+            new String[] { "v1" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u6e = FakeMetadataFactory.createElements(vm1u6, 
+            new String[] { "elem", "const" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u7e = FakeMetadataFactory.createElements(vm1u7, 
+            new String[] { "const", "e1" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u8e = FakeMetadataFactory.createElements(vm1u8, 
+            new String[] { "const", "e1" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+        List vm1u9e = FakeMetadataFactory.createElements(vm1u9, 
+            new String[] { "a", "b" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
+        List vm1a1e = FakeMetadataFactory.createElements(vm1a1, 
+            new String[] { "e1", "sum_e2" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
+        List vm1a2e = FakeMetadataFactory.createElements(vm1a2, 
+            new String[] { "e1", "sum_e2" }, //$NON-NLS-1$ //$NON-NLS-2$
+            new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
+        List vm1a3e = FakeMetadataFactory.createElements(vm1a3, 
+            new String[] { "sum_e2" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
+        List vm1a4e = FakeMetadataFactory.createElements(vm1a4, 
+            new String[] { "count" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
+        List vm1a5e = FakeMetadataFactory.createElements(vm1a5, 
+            new String[] { "count" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
+        List vm1a6e = FakeMetadataFactory.createElements(vm1a6, 
+            new String[] { "count" }, //$NON-NLS-1$
+            new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
+			
+		// Add all objects to the store
+		FakeMetadataStore store = new FakeMetadataStore();
+		store.addObject(pm1);
+		store.addObject(pm1g1);		
+		store.addObjects(pm1g1e);
+		store.addObject(pm1g2);		
+		store.addObjects(pm1g2e);
+ 		store.addObject(pm1g3);		
+		store.addObjects(pm1g3e);
+        store.addObject(pm1g4);     
+        store.addObjects(pm1g4e);
+        store.addObject(pm1g5);     
+        store.addObjects(pm1g5e);
+        store.addObject(pm1g6);     
+        store.addObjects(pm1g6e);
+        store.addObject(vm1g7);
+        store.addObjects(vm1g7e);
+        store.addObject(pm1g7);     
+        store.addObjects(pm1g7e);
+        store.addObject(pm1g8);     
+        store.addObjects(pm1g8e);
+        
+        store.addObject(pm2);
+        store.addObject(pm2g1);     
+        store.addObjects(pm2g1e);
+        store.addObject(pm2g2);     
+        store.addObjects(pm2g2e);
+        store.addObject(pm2g3);     
+        store.addObjects(pm2g3e);
+       	
+		store.addObject(vm1);
+		store.addObject(vm1g1);
+		store.addObjects(vm1g1e);
+		store.addObject(vm1g2);
+		store.addObjects(vm1g2e);
+		store.addObject(vm1g3);
+		store.addObjects(vm1g3e);
+
+		//for defect 8096
+		store.addObject(vm1sub1);
+		store.addObjects(vm1sub1e);
+		
+        store.addObject(vm1g4);
+        store.addObjects(vm1g4e);
+        store.addObject(vm1g5);
+        store.addObjects(vm1g5e);
+        store.addObject(vm1g6);
+        store.addObjects(vm1g6e);
+		store.addObject(vm1u1);
+		store.addObjects(vm1u1e);
+		store.addObject(vm1u2);
+		store.addObjects(vm1u2e);
+		store.addObject(vm1u3);
+		store.addObjects(vm1u3e);
+        store.addObject(vm1u4);
+        store.addObjects(vm1u4e);
+        store.addObject(vm1u5);
+        store.addObjects(vm1u5e);
+        store.addObject(vm1u6);
+        store.addObjects(vm1u6e);
+        store.addObject(vm1u7);
+        store.addObjects(vm1u7e);
+        store.addObject(vm1u8);
+        store.addObjects(vm1u8e);
+        store.addObject(vm1u9);
+        store.addObjects(vm1u9e);
+        store.addObject(vm1a1);
+        store.addObjects(vm1a1e);   
+        store.addObject(vm1a2);
+        store.addObjects(vm1a2e);   
+        store.addObject(vm1a3);
+        store.addObjects(vm1a3e);   
+        store.addObject(vm1a4);
+        store.addObjects(vm1a4e);   
+        store.addObject(vm1a5);
+        store.addObjects(vm1a5e);   
+        store.addObject(vm1a6);
+        store.addObjects(vm1a6e);   
+						
+		// Create the facade from the store
+		return new FakeMetadataFacade(store);
+	}	
+				
+	// ################################## ACTUAL TESTS ################################
+
+	/**
+	 * Test defect 8096 - query a virtual group with subquery of another virtual group 
+	 */
+	@Test public void testVirtualSubqueryINClause_8096() { 
+		helpPlan("SELECT * FROM vm1.sub1", example1(), //$NON-NLS-1$
+			new String[] {"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1"} ); //$NON-NLS-1$
+	}
+
+	@Test public void testQueryPhysical() { 
+		ProcessorPlan plan = helpPlan("SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] {"SELECT pm1.g1.e1, e2, pm1.g1.e3, e4 FROM pm1.g1"} ); //$NON-NLS-1$
+		assertTrue(!plan.requiresTransaction(true));
+        checkNodeTypes(plan, FULL_PUSHDOWN);    
+	}
+    
+	@Test public void testSelectStarPhysical() { 
+		ProcessorPlan plan = helpPlan("SELECT * FROM pm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1"} ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+	}
+
+	@Test public void testQuerySingleSourceVirtual() { 
+		ProcessorPlan plan = helpPlan("SELECT * FROM vm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1"} ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+	}
+	
+	@Test public void testQueryMultiSourceVirtual() { 
+		ProcessorPlan plan = helpPlan("SELECT * FROM vm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "SELECT g_0.e1, g_0.e2, g_1.e3, g_1.e4 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1"} ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+	}
+
+	@Test public void testPhysicalVirtualJoinWithCriteria() throws Exception { 
+		ProcessorPlan plan = helpPlan("SELECT vm1.g2.e1 from vm1.g2, pm1.g3 where vm1.g2.e1=pm1.g3.e1 and vm1.g2.e2 > 0", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1, pm1.g3 AS g_2 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = g_2.e1) AND (g_0.e2 > 0)" }, ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+	}
+    
+    @Test public void testQueryWithExpression() { 
+        helpPlan("SELECT e4 FROM pm3.g1 WHERE e4 < convert('2001-11-01 10:30:40.42', timestamp)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "SELECT e4 FROM pm3.g1 WHERE e4 < {ts'2001-11-01 10:30:40.42'}"} ); //$NON-NLS-1$
+    }
+    
+    @Test public void testInsert() { 
+        helpPlan("Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values ('MyString', 1)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES ('MyString', 1)"} ); //$NON-NLS-1$
+    }
+    
+    @Test public void testUpdate1() { 
+      	helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM('MyString'), pm1.g1.e2= 1 where pm1.g1.e3= 'true'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "UPDATE pm1.g1 SET pm1.g1.e1 = 'MyString', pm1.g1.e2 = 1 WHERE pm1.g1.e3 = TRUE"} ); //$NON-NLS-1$
+  	}
+  	
+    @Test public void testUpdate2() { 
+        helpPlan("Update pm1.g1 Set pm1.g1.e1= LTRIM('MyString'), pm1.g1.e2= 1 where pm1.g1.e2= convert(pm1.g1.e4, integer)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "UPDATE pm1.g1 SET pm1.g1.e1 = 'MyString', pm1.g1.e2 = 1 WHERE pm1.g1.e2 = convert(pm1.g1.e4, integer)"} ); //$NON-NLS-1$
+    }
+    
+    @Test public void testDelete() { 
+    	helpPlan("Delete from pm1.g1 where pm1.g1.e1 = cast(pm1.g1.e2 AS string)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+			new String[] { "DELETE FROM pm1.g1 WHERE pm1.g1.e1 = cast(pm1.g1.e2 AS string)"} ); //$NON-NLS-1$
+  	}
+
+	// ############################# TESTS ON EXAMPLE 1 ############################
+	
+    @Test public void testCopyInAcrossJoin() throws Exception {
+        ProcessorPlan plan = helpPlan("select pm1.g1.e1, pm2.g2.e1 from pm1.g1, pm2.g2 where pm1.g1.e1=pm2.g2.e1 and pm1.g1.e1 IN ('a', 'b')", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 WHERE g_0.e1 IN ('a', 'b') ORDER BY c_0", //$NON-NLS-1$
+        				   "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN ('a', 'b') ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCopyMatchAcrossJoin() throws Exception {
+        helpPlan("select pm1.g1.e1, pm2.g2.e1 from pm1.g1, pm2.g2 where pm1.g1.e1=pm2.g2.e1 and pm1.g1.e1 LIKE '%1'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e1 LIKE '%1' ORDER BY c_0", //$NON-NLS-1$
+        					"SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 WHERE g_0.e1 LIKE '%1' ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    }
+ 
+    @Test public void testCopyOrAcrossJoin() throws Exception {
+        helpPlan("select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 where pm1.g1.e1=pm1.g2.e1 and (pm1.g1.e1 = 'abc' OR pm1.g1.e1 = 'def')", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e1 = 'def')", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e1 = 'def')" }, getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$
+    }
+ 
+    @Test public void testCopyMultiElementCritAcrossJoin() throws Exception {
+        helpPlan("select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 where pm1.g1.e1=pm1.g2.e1 and pm1.g1.e2=pm1.g2.e2 and (pm1.g1.e1 = 'abc' OR pm1.g1.e2 = 5)", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g2.e1, pm1.g2.e2 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)" }, getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testCantCopyAcrossJoin1() throws Exception {
+        helpPlan("select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 where pm1.g1.e1=pm1.g2.e1 and concat(pm1.g1.e1, pm1.g1.e2) = 'abc'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2" }, getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$
+    }
+
+    @Test public void testCantCopyAcrossJoin2() throws Exception {
+        helpPlan("select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 where pm1.g1.e1=pm1.g2.e1 and (pm1.g1.e1 = 'abc' OR pm1.g1.e2 = 5)", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2" }, getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$
+    }
+
+    @Test public void testPushingCriteriaThroughFrame1() { 
+    	helpPlan("select * from vm1.g1, vm1.g2 where vm1.g1.e1='abc' and vm1.g1.e1=vm1.g2.e1", example1(), //$NON-NLS-1$
+			new String[] { "SELECT g1__1.e1, g1__1.e2, g1__1.e3, g1__1.e4 FROM pm1.g1 AS g1__1 WHERE g1__1.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughFrame2() throws Exception { 
+    	helpPlan("select * from vm1.g1, vm1.g3 where vm1.g1.e1='abc' and vm1.g1.e1=vm1.g3.e1", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'",  //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" }, getGenericFinder(false), ComparisonMode.CORRECTED_COMMAND_STRING ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughFrame3() { 
+    	helpPlan("select * from vm1.g1, vm1.g2, vm1.g1 as a where vm1.g1.e1='abc' and vm1.g1.e1=vm1.g2.e1 and vm1.g1.e1=a.e1", example1(), //$NON-NLS-1$
+			new String[] { "SELECT g1__1.e1, g1__1.e2, g1__1.e3, g1__1.e4 FROM pm1.g1 AS g1__1 WHERE g1__1.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT g1__2.e1, g1__2.e2, g1__2.e3, g1__2.e4 FROM pm1.g1 AS g1__2 WHERE g1__2.e1 = 'abc'" } ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughUnion1() { 
+    	helpPlan("select e1 from vm1.u1 where e1='abc'", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughUnion2() { 
+    	helpPlan("select e1 from vm1.u2 where e1='abc'", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughUnion3() { 
+    	helpPlan("select e1 from vm1.u1 where e1='abc' and e2=5", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') AND (pm1.g3.e2 = 5)", //$NON-NLS-1$
+							"SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') AND (pm1.g2.e2 = 5)", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') AND (pm1.g1.e2 = 5)" } ); //$NON-NLS-1$
+  	}
+
+    @Test public void testPushingCriteriaThroughUnion4() { 
+    	helpPlan("select e1 from vm1.u1 where e1='abc' or e2=5", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') OR (pm1.g3.e2 = 5)", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
+							"SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)" } ); //$NON-NLS-1$
+  	}
+
+	// expression in a subquery of the union
+    @Test public void testPushingCriteriaThroughUnion5() { 
+    	helpPlan("select e1 from vm1.u3 where e1='abc'", example1(), //$NON-NLS-1$
+			new String[] { "SELECT DISTINCT e1 FROM pm1.g1 WHERE e1 = 'abc'" } ); //$NON-NLS-1$
+  	}
+
+    /** defect #4956 */
+    @Test public void testPushCriteriaThroughUnion6() { 
+        helpPlan("select v1 from vm1.u4 where vm1.u4.v1='x'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT e1 FROM pm1.g2 WHERE e1 = 'x'" } ); //$NON-NLS-1$
+    }
+
+    @Test public void testPushCriteriaThroughUnion7() { 
+        helpPlan("select v1 from vm1.u5 where vm1.u5.v1='x'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT e1 FROM pm1.g2" } ); //$NON-NLS-1$
+    }
+
+    @Test public void testPushCriteriaThroughUnion8() { 
+        helpPlan("select v1 from vm1.u5 where length(v1) > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT e1 FROM pm1.g2" } ); //$NON-NLS-1$
+    }
+    
+    @Test public void testPushCriteriaThroughUnion11() {
+        helpPlan("select * from vm1.u8 where const = 's3' or e1 is null", example1(), //$NON-NLS-1$
+            new String[] { "SELECT 's3', e1 FROM pm1.g3", //$NON-NLS-1$
+                            "SELECT 's2', e1 FROM pm1.g2 WHERE e1 IS NULL", //$NON-NLS-1$
+                            "SELECT 's1', e1 FROM pm1.g1 WHERE e1 IS NULL" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testPushCriteriaThroughUnion12() {
+        helpPlan("select * from vm1.u8 where const = 's1' or e1 is null", example1(), //$NON-NLS-1$
+            new String[] { "SELECT 's3', e1 FROM pm1.g3 WHERE e1 IS NULL", //$NON-NLS-1$
+                            "SELECT 's2', e1 FROM pm1.g2 WHERE e1 IS NULL", //$NON-NLS-1$
+                            "SELECT 's1', e1 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+
+    /** defect #4997 */
+    @Test public void testCountStarNoRows() { 
+        ProcessorPlan plan = helpPlan("select count(*) from vm1.u4", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g2",  //$NON-NLS-1$
+                            "SELECT e1 FROM pm1.g1" } ); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+
+    @Test public void testPushingCriteriaWithCopy() { 
+    	ProcessorPlan plan = helpPlan("select vm1.u1.e1 from vm1.u1, pm1.g1 where vm1.u1.e1='abc' and vm1.u1.e1=pm1.g1.e1", example1(), //$NON-NLS-1$
+			new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", //$NON-NLS-1$
+                            "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+							"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            4,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            2       // UnionAll
+        }); 
+  	}
+
+    @Test public void testVirtualGroupWithAliasedElement() {
+        helpPlan("select elem FROM vm1.u6 where elem='abc' and const='xyz'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT x1.e1 FROM pm1.g1 AS x1 WHERE x1.e1 = 'abc'" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testPushThroughGroup1() {
+        helpPlan("select * FROM vm1.a1 WHERE e1 = 'x'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1 WHERE e1 = 'x'" } );     //$NON-NLS-1$
+    }
+ 
+    @Test public void testPushThroughGroup2() {
+        helpPlan("select * FROM vm1.a2 WHERE e1 = 'x'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1 WHERE e1 = 'x'" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testPushThroughGroup3() {
+        helpPlan("select * FROM vm1.a3 WHERE sum_e2 > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e2 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testPushMultiGroupCriteria() { 
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1 from pm2.g1, pm2.g2 where pm2.g1.e1 = pm2.g2.e1 and (pm2.g1.e2 = 1 OR pm2.g2.e2 = 2)", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1, pm2.g2 WHERE (pm2.g1.e1 = pm2.g2.e1) AND ((pm2.g1.e2 = 1) OR (pm2.g2.e2 = 2))" } ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    @Test public void testSimpleCrossJoin1() throws Exception {
+        helpPlan("select pm1.g1.e1 FROM pm1.g1, pm1.g2", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$
+                "SELECT pm1.g2.e1 FROM pm1.g2" }, new DefaultCapabilitiesFinder(), ComparisonMode.EXACT_COMMAND_STRING );     //$NON-NLS-1$
+    }
+
+    @Test public void testSimpleCrossJoin2() {
+        helpPlan("select pm2.g1.e1 FROM pm2.g1, pm2.g2", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1, pm2.g2"} ); //$NON-NLS-1$
+               
+    }
+
+    @Test public void testSimpleCrossJoin3() {
+        helpPlan("select pm2.g1.e1 FROM pm2.g1 CROSS JOIN pm2.g2", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1, pm2.g2"} ); //$NON-NLS-1$
+               
+    }
+
+    @Test public void testMultiSourceCrossJoin() throws Exception {
+        helpPlan("select pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$
+                "SELECT pm1.g2.e1 FROM pm1.g2", //$NON-NLS-1$
+                "SELECT pm1.g3.e1 FROM pm1.g3" }, new DefaultCapabilitiesFinder(), ComparisonMode.EXACT_COMMAND_STRING );     //$NON-NLS-1$
+    }
+
+    @Test public void testSingleSourceCrossJoin() {
+        helpPlan("select pm2.g1.e1 FROM pm2.g1, pm2.g2, pm2.g3", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1, pm2.g2, pm2.g3"} ); //$NON-NLS-1$
+    }
+
+    @Test public void testSelfJoins() {
+        helpPlan("select pm2.g1.e1 FROM pm2.g1 JOIN pm2.g1 AS x ON pm2.g1.e1=x.e1", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1 order by e1", //$NON-NLS-1$
+                "SELECT x.e1 FROM pm2.g1 AS x order by e1" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testDefect5282_1() {
+        helpPlan("select * FROM vm1.a4 WHERE vm1.a4.count > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testDefect5282_2() {
+        helpPlan("select count(*) FROM vm1.a4", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testDefect5282_3() {
+        helpPlan("select * FROM vm1.a5 WHERE vm1.a5.count > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+    
+    @Test public void testDepJoinHintBaseline() throws Exception {
+        ProcessorPlan plan = helpPlan("select * FROM vm1.g4", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2" }, new DefaultCapabilitiesFinder(), ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testDefect6425_1() {
+        helpPlan("select * from vm1.u9", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT e1, e1 FROM pm1.g2" } );     //$NON-NLS-1$
+    }
+
+    @Test public void testDefect6425_2() {
+        helpPlan("select count(*) from vm1.u9", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT e1 FROM pm1.g2" } );     //$NON-NLS-1$
+    }
+    
+    @Test public void testPushMatchCritWithReference() {
+        List bindings = new ArrayList();
+        bindings.add("pm1.g2.e1"); //$NON-NLS-1$
+        helpPlan("select e1 FROM pm1.g1 WHERE e1 LIKE ?", example1(), bindings, null,  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 LIKE ?" }, true ); //$NON-NLS-1$
+    }
+    
+    @Test public void testDefect6517() {
+        helpPlan("select count(*) from vm1.g5", example1(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm1.g1.e1 FROM pm1.g1" });     //$NON-NLS-1$
+    }
+    
+    @Test public void testDefect5283() {        
+        helpPlan("select * from vm1.a6", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2" } ); //$NON-NLS-1$
+    }
+    
+    @Test public void testManyJoinsOverThreshold() throws Exception {
+        long begin = System.currentTimeMillis();
+        helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3, pm1.g4, pm1.g5, pm1.g6, pm1.g7, pm1.g8, pm1.g1 AS x, pm1.g2 AS y WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g2.e1 = pm1.g3.e1 AND pm1.g3.e1 = pm1.g4.e1 AND pm1.g4.e1 = pm1.g5.e1 AND pm1.g5.e1=pm1.g6.e1 AND pm1.g6.e1=pm1.g7.e1 AND pm1.g7.e1=pm1.g8.e1", //$NON-NLS-1$
+            example1(), 
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2",  //$NON-NLS-1$
+                            "SELECT pm1.g3.e1 FROM pm1.g3",  //$NON-NLS-1$
+                            "SELECT pm1.g4.e1 FROM pm1.g4", //$NON-NLS-1$
+                            "SELECT pm1.g5.e1 FROM pm1.g5",  //$NON-NLS-1$
+                            "SELECT pm1.g6.e1 FROM pm1.g6",  //$NON-NLS-1$
+                            "SELECT pm1.g7.e1 FROM pm1.g7", //$NON-NLS-1$
+                            "SELECT pm1.g8.e1 FROM pm1.g8", //$NON-NLS-1$
+                            "SELECT x.e1 FROM pm1.g1 AS x", //$NON-NLS-1$
+                            "SELECT y.e1 FROM pm1.g2 AS y" }, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING ); //$NON-NLS-1$
+                            
+        long elapsed = System.currentTimeMillis() - begin;   
+        assertTrue("Did not plan many join query in reasonable time frame: " + elapsed + " ms", elapsed < 4000); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testAggregateWithoutGroupBy() {
+        ProcessorPlan plan = helpPlan("select count(e2) from pm1.g1", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e2 FROM pm1.g1" } );         //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testHavingWithoutGroupBy() {
+        ProcessorPlan plan = helpPlan("select count(e2) from pm1.g1 HAVING count(e2) > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e2 FROM pm1.g1" } );         //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testHavingAndGroupBy() {
+        ProcessorPlan plan = helpPlan("select e1, count(e2) from pm1.g1 group by e1 having count(e2) > 0 and sum(e2) > 0", example1(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1" } );         //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testAllJoinsInSingleClause() throws Exception {
+        ProcessorPlan plan = helpPlan("select pm1.g1.e1 FROM pm1.g1 join (pm1.g2 right outer join pm1.g3 on pm1.g2.e1=pm1.g3.e1) on pm1.g1.e1=pm1.g3.e1", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1",  //$NON-NLS-1$
+                            "SELECT pm1.g2.e1 FROM pm1.g2", //$NON-NLS-1$
+                            "SELECT pm1.g3.e1 FROM pm1.g3" }, new DefaultCapabilitiesFinder(), ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testSelectCountStarFalseCriteria() {
+        ProcessorPlan plan = helpPlan("Select count(*) from pm1.g1 where 1=0", example1(),  //$NON-NLS-1$
+            new String[] { });
+        checkNodeTypes(plan, new int[] {
+            0,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            1,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testSubquery1() {
+        ProcessorPlan plan = helpPlan("Select e1 from (select e1 FROM pm1.g1) AS x", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testSubquery2() {
+        ProcessorPlan plan = helpPlan("Select e1, a from (select e1 FROM pm1.g1) AS x, (select e1 as a FROM pm1.g2) AS y WHERE x.e1=y.a", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1, g_1.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+	@Test public void testSubquery3() {
+		ProcessorPlan plan = helpPlan("Select e1 from (select e1 FROM pm1.g1) AS x WHERE x.e1 = 'a'", example1(), //$NON-NLS-1$
+			new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 = 'a'" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+	@Test public void testSubquery4() {
+		ProcessorPlan plan = helpPlan("Select e1 from (select e1 FROM pm1.g1 WHERE e1 = 'a') AS x", example1(), //$NON-NLS-1$
+			new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 = 'a'" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testSubqueryInClause1() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCompareSubquery1() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 < any (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCompareSubquery2() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 <= some (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCompareSubquery3() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 >= all (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCompareSubquery4() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 > (select e1 FROM pm2.g1 where e2 = 13)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testExistsSubquery1() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where exists (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testScalarSubquery1() {
+        ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') from pm1.g1", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }    
+
+    @Test public void testScalarSubquery2() {
+        ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') as X from pm1.g1", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    } 
+    
+    @Test public void testTempGroup() {
+        ProcessorPlan plan = helpPlan("select e1 from tm1.g1 where e1 = 'x'", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM tm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testNotPushDistinct() throws Exception {
+        ProcessorPlan plan = helpPlan("select distinct e1 from pm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1" }, new DefaultCapabilitiesFinder(), ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testPushDistinct() {
+        ProcessorPlan plan = helpPlan("select distinct e1 from pm3.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT e1 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctSort() {
+        ProcessorPlan plan = helpPlan("select distinct e1 from pm3.g1 order by e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT e1 FROM pm3.g1 ORDER BY e1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctWithCriteria() {
+        ProcessorPlan plan = helpPlan("select distinct e1 from pm3.g1 where e1 = 'x'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT e1 FROM pm3.g1 WHERE e1 = 'x'" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual1() {
+        ProcessorPlan plan = helpPlan("select * from vm1.g12", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual2() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g12", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual3() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g12 ORDER BY e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 ORDER BY pm3.g1.e1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual4() {
+        ProcessorPlan plan = helpPlan("select * from vm1.g13", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual5() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g13", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual6() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g13 ORDER BY e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 ORDER BY pm3.g1.e1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual7() {
+        ProcessorPlan plan = helpPlan("select * from vm1.g14", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual8() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g14", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushDistinctVirtual9() {
+        ProcessorPlan plan = helpPlan("select DISTINCT * from vm1.g14 ORDER BY e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1 ORDER BY pm3.g1.e1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+ 
+    /**
+     * Defect #7819
+     */
+    @Test public void testPushDistinctWithExpressions() {
+        ProcessorPlan plan = helpPlan("SELECT DISTINCT * FROM vm1.g15", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm3.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testNestedSubquery() {
+        ProcessorPlan plan = helpPlan("SELECT IntKey, LongNum FROM (SELECT IntKey, LongNum FROM (SELECT IntKey, LongNum, DoubleNum FROM BQT2.SmallA ) AS x ) AS y ORDER BY IntKey", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { "SELECT IntKey, LongNum FROM BQT2.SmallA order by intkey" }); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    /** Tests a user's order by is pushed to the source */
+    @Test public void testPushOrderBy() {
+        ProcessorPlan plan = helpPlan("SELECT pm3.g1.e1 FROM pm3.g1 ORDER BY e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1 FROM pm3.g1 ORDER BY pm3.g1.e1"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+    
+    /** Tests an order by is not pushed to source due to join */
+    @Test public void testDontPushOrderByWithJoin() {
+        ProcessorPlan plan = helpPlan("SELECT pm3.g1.e1, pm3.g1.e2 FROM pm3.g1 INNER JOIN pm2.g2 ON pm3.g1.e1 = pm2.g2.e1 ORDER BY pm3.g1.e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1, pm3.g1.e2 FROM pm3.g1 ORDER BY pm3.g1.e1", //$NON-NLS-1$
+                           "SELECT pm2.g2.e1 FROM pm2.g2 ORDER BY pm2.g2.e1"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        });                                
+    }    
+
+    /** 
+     * Tests that user's order by gets pushed to the source, but query
+     * transformation order by is discarded 
+     */
+    @Test public void testPushOrderByThroughFrame() {
+        ProcessorPlan plan = helpPlan("SELECT e1, e2 FROM vm1.g14 ORDER BY e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1, pm3.g1.e2 FROM pm3.g1 ORDER BY pm3.g1.e2"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+    
+    /** 
+     * Tests that query transformation order by is discarded by
+     */
+    @Test public void testPushOrderByThroughFrame2() {
+        ProcessorPlan plan = helpPlan("SELECT e1, e2 FROM vm1.g1 ORDER BY e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 order by e2"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }    
+
+    /** 
+     * Tests that query transformation order by is discarded by
+     * user order by, and that user order by is discarded because
+     * of the function in the query transformation 
+     */
+    @Test public void testPushOrderByThroughFrame3() {
+        ProcessorPlan plan = helpPlan("SELECT e, e2 FROM vm1.g16 ORDER BY e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm3.g1"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        });                                    
+    } 
+
+    /** 
+     * Tests that a user's order by does not get pushed to the source
+     * if there is a UNION in the query transformation 
+     */
+    @Test public void testPushOrderByThroughFrame4_Union() {
+        ProcessorPlan plan = helpPlan("SELECT e1, e2 FROM vm1.g17 ORDER BY e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1, pm3.g1.e2 FROM pm3.g1", //$NON-NLS-1$
+                           "SELECT pm3.g2.e1, pm3.g2.e2 FROM pm3.g2"}); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            1,      // Sort
+            1       // UnionAll
+        });                                    
+    }
+
+    /** Tests outer join defect #7945 - see also defect #10050*/
+    @Test public void testOuterJoinDefect7945() {
+        ProcessorPlan plan = helpPlan(
+            "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey, BQT3.MediumB.IntKey AS MediumC_IntKey " +  //$NON-NLS-1$
+            "FROM (BQT1.SmallA RIGHT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey) " +  //$NON-NLS-1$
+            "RIGHT OUTER JOIN BQT3.MediumB ON BQT2.MediumB.IntKey = BQT3.MediumB.IntKey " +   //$NON-NLS-1$
+            "WHERE BQT3.MediumB.IntKey < 1500",  //$NON-NLS-1$
+            FakeMetadataFactory.exampleBQTCached(),
+            new String[] { 
+                "SELECT BQT3.MediumB.IntKey FROM BQT3.MediumB WHERE BQT3.MediumB.IntKey < 1500 order by intkey", //$NON-NLS-1$
+                "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.IntKey < 1500 order by intkey", //$NON-NLS-1$
+                "SELECT BQT2.MediumB.IntKey FROM BQT2.MediumB WHERE BQT2.MediumB.IntKey < 1500 order by intkey" }); //$NON-NLS-1$
+                
+        checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+
+    /** Tests outer join defect #7945 */
+    @Test public void testFunctionSimplification1() {
+        ProcessorPlan plan = helpPlan(
+            "SELECT x FROM vm1.g18 WHERE x = 92.0",   //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            new String[] { 
+                "SELECT e4 FROM pm1.g1 WHERE e4 = 0.92" }); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+            
+    @Test public void testCantPushJoin1() {
+        ProcessorPlan plan = helpPlan(
+            "SELECT a.e1, b.e2 FROM pm1.g1 a, pm1.g2 b WHERE a.e1 = b.e1",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, TestOptimizer.getGenericFinder(false),
+            new String[] {"SELECT a.e1 FROM pm1.g1 AS a", "SELECT b.e1, b.e2 FROM pm1.g2 AS b"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    @Test public void testCantPushJoin2() {
+        ProcessorPlan plan = helpPlan(
+            "SELECT a.e1, b.e2 FROM pm1.g1 a, pm1.g2 b, pm2.g1 c WHERE a.e1 = b.e1 AND b.e1 = c.e1",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, TestOptimizer.getGenericFinder(false),
+            new String[] {"SELECT a.e1 FROM pm1.g1 AS a",  //$NON-NLS-1$
+                           "SELECT b.e1, b.e2 FROM pm1.g2 AS b", //$NON-NLS-1$
+                           "SELECT c.e1 FROM pm2.g1 AS c"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testPushSelfJoin1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT a.e1, b.e2 FROM pm1.g1 a, pm1.g1 b WHERE a.e1 = b.e1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT a.e1, b.e2 FROM pm1.g1 AS a, pm1.g1 AS b WHERE a.e1 = b.e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testPushSelfJoin2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT a.e1 AS x, concat(a.e2, b.e2) AS y FROM pm1.g1 a, pm1.g1 b WHERE a.e1 = b.e1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT a.e1, a.e2, b.e2 FROM pm1.g1 AS a, pm1.g1 AS b WHERE a.e1 = b.e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+        
+    @Test public void testPushOuterJoin1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm1.g2 ON pm1.g1.e1 = pm1.g2.e1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g2 LEFT OUTER JOIN pm1.g1 ON pm1.g1.e1 = pm1.g2.e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testPushOuterJoin2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm1.g2 ON pm1.g1.e1 = pm1.g2.e1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    // With join expression that can't be pushed
+    @Test public void testPushOuterJoin3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm1.g2 ON pm1.g1.e1 = pm1.g2.e1 || 'x'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+                               
+    }
+
+    @Test public void testPushGroupBy1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, e2 as x FROM pm1.g1 GROUP BY e1, e2",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1, e2 FROM pm1.g1 GROUP BY e1, e2"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+                               
+    }
+
+    @Test public void testPushGroupBy2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1, MAX(e2) FROM pm1.g1 GROUP BY e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+                               
+    }
+
+    @Test public void testPushGroupBy3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, e2 as x FROM pm1.g1 GROUP BY e1, e2",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1, e2 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+                               
+    }
+
+    @Test public void testPushGroupBy4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT x+2 AS y FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT MAX(e2) FROM pm1.g1 GROUP BY e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+                               
+    }
+    
+    @Test public void testPushHaving1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1 FROM pm1.g1 GROUP BY e1 HAVING MAX(e1) = 'zzz'",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1 GROUP BY e1 HAVING MAX(e1) = 'zzz'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+
+    @Test public void testPushHaving2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1 FROM pm1.g1 GROUP BY e1 HAVING MAX(e1) = 'zzz'",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                                                  
+    }
+
+    @Test public void testPushHaving3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1 FROM pm1.g1 GROUP BY e1 HAVING MAX(e1) = 'zzz'",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                                                  
+    }
+
+    @Test public void testPushAggregate1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT MAX(e1) FROM pm1.g1",  //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT MAX(e1) FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+    
+    @Test public void testPushAggregate2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT MAX(e1) FROM pm1.g1 GROUP BY e1", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT MAX(e1) FROM pm1.g1 GROUP BY e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+
+    @Test public void testPushAggregate3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e2, MAX(e1) FROM pm1.g1 GROUP BY e2", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e2, MAX(e1) FROM pm1.g1 GROUP BY e2"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+
+    @Test public void testPushAggregate4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e2, MAX(e1) FROM pm1.g1 GROUP BY e2 HAVING COUNT(e1) > 0", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e2, MAX(e1) FROM pm1.g1 GROUP BY e2 HAVING COUNT(e1) > 0"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+
+    /**
+     * Can't push aggs due to not being able to push COUNT in the HAVING clause.
+     */
+    @Test public void testPushAggregate5() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e2, MAX(e1) FROM pm1.g1 GROUP BY e2 HAVING COUNT(e1) > 0", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e2, e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                                                  
+    }
+
+    /**
+     * Can't push aggs due to not being able to push function inside the aggregate
+     */
+    @Test public void testPushAggregate6() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT COUNT(length(e1)) FROM pm1.g1", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                                                  
+    }
+
+    /**
+     * Can't push aggs due to not being able to push function inside having
+     */
+    @Test public void testPushAggregate7() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT COUNT(*) FROM pm1.g1 GROUP BY e1 HAVING length(e1) > 0", //$NON-NLS-1$
+            FakeMetadataFactory.example1Cached(),
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                                                  
+    }
+
+    /**
+     * BQT query that is failing
+     */
+    @Test public void testPushAggregate8() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+         
+        String sqlIn =          
+            "SELECT intkey FROM bqt1.smalla AS sa WHERE (sa.intkey = 46) AND " + //$NON-NLS-1$
+            "(sa.stringkey IN (46)) AND (sa.datevalue = (" + //$NON-NLS-1$
+            "SELECT MAX(sa.datevalue) FROM bqt1.smalla AS sb " + //$NON-NLS-1$
+            "WHERE (sb.intkey = sa.intkey) AND (sa.stringkey = sb.stringkey) ))"; //$NON-NLS-1$
+
+        String sqlOut = "SELECT intkey FROM bqt1.smalla AS sa WHERE (sa.intkey = 46) AND (sa.stringkey = '46') AND (sa.datevalue = (SELECT sa.datevalue FROM bqt1.smalla AS sb WHERE (sb.intkey = sa.intkey) AND (sb.stringkey = sa.stringkey)))"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sqlIn, 
+            FakeMetadataFactory.exampleBQTCached(),
+            null, capFinder,
+            new String[] {sqlOut}, 
+            SHOULD_SUCCEED );
+    
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                                  
+    }
+    
+    @Test public void testQueryManyJoin() throws Exception { 
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        ProcessorPlan plan = helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 JOIN ((pm1.g2 JOIN pm1.g3 ON pm1.g2.e1=pm1.g3.e1) JOIN pm1.g4 ON pm1.g3.e1=pm1.g4.e1) ON pm1.g1.e1=pm1.g4.e1",  //$NON-NLS-1$
+            metadata,
+            new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1, pm1.g3 AS g_2, pm1.g4 AS g_3 WHERE (g_1.e1 = g_2.e1) AND (g_2.e1 = g_3.e1) AND (g_0.e1 = g_3.e1)"}, ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    @Test public void testPushSelectDistinct() { 
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        ProcessorPlan plan = helpPlan("SELECT DISTINCT e1 FROM pm3.g1",  //$NON-NLS-1$
+            metadata,
+            new String[] { "SELECT DISTINCT e1 FROM pm3.g1"} ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    @Test public void testPushFunctionInCriteria1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1 FROM pm1.g1 WHERE upper(e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testPushFunctionInSelect1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT lower(e1) FROM pm1.g1 WHERE upper(e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT lower(e1) FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testPushFunctionInSelect2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE upper(e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testPushFunctionInSelect3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, false); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT lower(e1), upper(e1) FROM pm1.g1 WHERE upper(e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+
+    @Test public void testPushFunctionInSelect4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT x FROM (SELECT lower(e1) AS x, upper(e1) AS y FROM pm1.g1 WHERE upper(e1) = 'X') AS z",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT lcase(e1) FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }    
+
+    @Test public void testPushFunctionInSelect5() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT y, e, x FROM (SELECT lower(e1) AS x, upper(e1) AS y, 5 as z, e1 AS e FROM pm1.g1 WHERE upper(e1) = 'X') AS w",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT ucase(e1), e1, lcase(e1) FROM pm1.g1 WHERE ucase(e1) = 'X'"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }    
+
+    @Test public void testPushFunctionInSelect6_defect_10081() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setFunctionSupport("upper", true); //$NON-NLS-1$
+        caps.setFunctionSupport("lower", false); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT upper(lower(e1)) FROM pm1.g1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+            
+    @Test public void testPushFunctionInSelectWithOrderBy1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, lower(e1) FROM pm1.g1 WHERE upper(e1) = 'X' ORDER BY e1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1, lcase(e1) FROM pm1.g1 WHERE ucase(e1) = 'X' ORDER BY e1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+
+    /** defect 13336 */
+    @Test public void testPushFunctionInSelectWithOrderBy1a() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, lower(e1) AS x FROM pm1.g1 WHERE upper(e1) = 'X' ORDER BY x",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1, lcase(e1) AS x FROM pm1.g1 WHERE ucase(e1) = 'X' ORDER BY x"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }    
+    
+    /** defect 13336 */
+    @Test public void testPushFunctionInSelectWithOrderBy2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport(SourceSystemFunctions.LCASE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1, x FROM (SELECT e1, lower(e1) AS x FROM pm1.g1 WHERE upper(e1) = 'X') AS z ORDER BY x",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1, lcase(e1) AS EXPR FROM pm1.g1 WHERE ucase(e1) = 'X' ORDER BY EXPR"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testPushFunctionInJoin1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = convert(pm1.g2.e2, string) AND upper(pm1.g1.e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND (ucase(convert(pm1.g2.e2, string)) = 'X')"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }    
+
+    @Test public void testPushFunctionInJoin2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2, pm1.g3 WHERE pm1.g1.e1 = convert(pm1.g2.e2, string) AND pm1.g1.e1 = concat(pm1.g3.e1, 'a') AND upper(pm1.g1.e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND (ucase(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
+                    "SELECT pm1.g3.e1 FROM pm1.g3"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+
+    @Test public void testPushFunctionInJoin3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setFunctionSupport(SourceSystemFunctions.UCASE, true); 
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2, (SELECT e1 AS x FROM pm1.g3) AS g WHERE pm1.g1.e1 = convert(pm1.g2.e2, string) AND pm1.g1.e1 = concat(g.x, 'a') AND upper(pm1.g1.e1) = 'X'",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X') AND (ucase(convert(pm1.g2.e2, string)) = 'X')", //$NON-NLS-1$
+                    "SELECT e1 FROM pm1.g3"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+
+    @Test public void testUnionOverFunctions() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT StringCol AS E " +  //$NON-NLS-1$
+            "FROM (SELECT CONVERT(BQT1.SmallA.IntNum, string) AS StringCol, BQT1.SmallA.IntNum AS IntCol FROM BQT1.SmallA " + //$NON-NLS-1$
+            "UNION ALL SELECT BQT1.SmallB.StringNum, CONVERT(BQT1.SmallB.StringNum, integer) FROM BQT1.SmallB) AS x",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT CONVERT(BQT1.SmallA.IntNum, string) FROM BQT1.SmallA", //$NON-NLS-1$
+                    "SELECT BQT1.SmallB.StringNum FROM BQT1.SmallB"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });                                    
+    }    
+
+    @Test public void testDefect9827() { 
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan("SELECT intkey, c FROM (SELECT DISTINCT b.intkey, b.intnum, a.stringkey AS c FROM bqt1.smalla AS a, bqt1.smallb AS b WHERE a.INTKEY = b.INTKEY) AS x ORDER BY x.intkey", metadata, //$NON-NLS-1$
+            new String[] {"SELECT DISTINCT b.intkey, b.intnum, a.stringkey FROM bqt1.smalla AS a, bqt1.smallb AS b WHERE a.INTKEY = b.INTKEY"} ); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    /**
+     * This tests that a criteria with no elements is not pushed down,
+     * but instead is cleaned up properly later
+     * See defect 9865
+     */
+    @Test public void testCrossJoinNoElementCriteriaOptimization2() {
+        ProcessorPlan plan = helpPlan("select Y.e1, Y.e2 FROM vm1.g1 X, vm1.g1 Y where {b'true'} = {b'true'}", example1(),  //$NON-NLS-1$
+            new String[]{"SELECT g1__1.e1 FROM pm1.g1 AS g1__1", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * <p>This tests that a SELECT node with no groups is not pushed down without the capability to have a subquery in the where clause.
+     */
+    @Test public void testCrossJoinNoElementCriteriaOptimization3() {
+        ProcessorPlan plan = helpPlan("select Y.e1, Y.e2 FROM vm1.g1 X, vm1.g1 Y where {b'true'} in (select e3 FROM vm1.g1)", example1(),  //$NON-NLS-1$
+            new String[]{"SELECT g1__1.e1 FROM pm1.g1 AS g1__1", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * <p>This tests that a SELECT node with no groups is pushed down.
+     */
+    @Test public void testCrossJoinNoElementCriteriaOptimization4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select Y.e1, Y.e2 FROM vm1.g1 X, vm1.g1 Y where {b'true'} in (select e3 FROM vm1.g1)", example1(), null, capFinder,  //$NON-NLS-1$
+            new String[]{"SELECT g1__1.e1 FROM pm1.g1 AS g1__1 WHERE TRUE IN (SELECT pm1.g1.e3 FROM pm1.g1)", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, true); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Criteria should be copied across this join
+     */
+    @Test public void testCopyCriteriaWithOuterJoin_defect10050(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1 left outer join pm2.g2 on pm2.g1.e1=pm2.g2.e1 where pm2.g1.e1 IN ('a', 'b')", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1, pm2.g2.e1 FROM pm2.g1 LEFT OUTER JOIN pm2.g2 ON pm2.g1.e1 = pm2.g2.e1 AND pm2.g2.e1 IN ('a', 'b') WHERE pm2.g1.e1 IN ('a', 'b')" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    /**
+     * Criteria should be copied across this join
+     */
+    @Test public void testCopyCriteriaWithOuterJoin2_defect10050(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1 left outer join pm2.g2 on pm2.g1.e1=pm2.g2.e1 and pm2.g1.e2=pm2.g2.e2 where pm2.g1.e1 = 'a' and pm2.g1.e2 = 1", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1, g_1.e1 FROM pm2.g1 AS g_0 LEFT OUTER JOIN pm2.g2 AS g_1 ON g_0.e1 = g_1.e1 AND g_0.e2 = g_1.e2 AND g_1.e2 = 1 AND g_1.e1 = 'a' WHERE (g_0.e1 = 'a') AND (g_0.e2 = 1)" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    /**
+     * See also case 2912.
+     */
+    @Test public void testCopyCriteriaWithOuterJoin5_defect10050(){
+        
+        ProcessorPlan plan = helpPlan(
+            "select pm2.g1.e1, pm2.g2.e1, pm2.g3.e1 from ( (pm2.g1 right outer join pm2.g2 on pm2.g1.e1=pm2.g2.e1) right outer join pm2.g3 on pm2.g2.e1=pm2.g3.e1) where pm2.g3.e1 = 'a'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_2.e1, g_1.e1, g_0.e1 FROM pm2.g3 AS g_0 LEFT OUTER JOIN (pm2.g2 AS g_1 LEFT OUTER JOIN pm2.g1 AS g_2 ON g_2.e1 = g_1.e1 AND g_2.e1 = 'a') ON g_1.e1 = g_0.e1 AND g_1.e1 = 'a' WHERE g_0.e1 = 'a'" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    } 
+    
+    /**
+     * 
+     */
+    @Test public void testCopyCriteriaWithOuterJoin6_defect10050(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1 left outer join pm2.g2 on pm2.g2.e1=pm2.g1.e1 where pm2.g1.e1 IN ('a', 'b')", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1, pm2.g2.e1 FROM pm2.g1 LEFT OUTER JOIN pm2.g2 ON pm2.g2.e1 = pm2.g1.e1 AND pm2.g2.e1 IN ('a', 'b') WHERE pm2.g1.e1 IN ('a', 'b')" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    /**
+     * Same as previous test, only right outer join
+     */
+    @Test public void testCopyCriteriaWithOuterJoin7_defect10050(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1 right outer join pm2.g2 on pm2.g2.e1=pm2.g1.e1 where pm2.g2.e1 IN ('a', 'b')", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1, pm2.g2.e1 FROM pm2.g2 LEFT OUTER JOIN pm2.g1 ON pm2.g2.e1 = pm2.g1.e1 AND pm2.g1.e1 IN ('a', 'b') WHERE pm2.g2.e1 IN ('a', 'b')" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }         
+    
+    @Test public void testCleanCriteria(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1, pm2.g2 where pm2.g1.e1=pm2.g2.e1 and pm2.g1.e2 IN (1, 2)", example1(), //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1, pm2.g2.e1 FROM pm2.g1, pm2.g2 WHERE (pm2.g1.e1 = pm2.g2.e1) AND (pm2.g1.e2 IN (1, 2))" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    @Test public void testCleanCriteria2(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1, pm2.g2 where pm2.g1.e1=pm2.g2.e1 and pm2.g1.e1 = 'a'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1, g_1.e1 FROM pm2.g1 AS g_0, pm2.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'a') AND (g_1.e1 = 'a')" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+
+    @Test public void testCleanCriteria3(){
+        
+        ProcessorPlan plan = helpPlan("select pm2.g1.e1, pm2.g2.e1 from pm2.g1 inner join pm2.g2 on pm2.g1.e1=pm2.g2.e1 where pm2.g1.e1 = 'a'", example1(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1, g_1.e1 FROM pm2.g1 AS g_0, pm2.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'a') AND (g_1.e1 = 'a')" }); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+    }
+    
+    
+    @Test public void testPushSubqueryInWhereClause1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select e1 FROM pm1.g2)", example1(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 IN (SELECT e1 FROM pm1.g2)"}, SHOULD_SUCCEED ); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    @Test public void testPushSubqueryInWhereClause2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select max(e1) FROM pm1.g2)", example1(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 IN (SELECT MAX(e1) FROM pm1.g2)" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+    /**
+     * Check that subquery is pushed if the subquery selects a function that is pushed
+     */
+    @Test public void testPushSubqueryInWhereClause3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setFunctionSupport("ltrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT ltrim(e1) FROM pm1.g2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 IN (SELECT ltrim(e1) FROM pm1.g2)" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    /**
+     * Check that subquery is pushed if the subquery selects an aliased function that is pushed
+     */
+    @Test public void testPushSubqueryInWhereClause4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setFunctionSupport("ltrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT ltrim(e1) as m FROM pm1.g2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 IN (SELECT ltrim(e1) FROM pm1.g2)" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    /** Case 1456, defect 10492*/
+    @Test public void testAliasingDefect1(){
+        // Create query
+        String sql = "SELECT e1 FROM vm1.g1 X WHERE e2 = (SELECT MAX(e2) FROM vm1.g1 Y WHERE X.e1 = Y.e1)";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+            null, capFinder,
+            new String[] { "SELECT g1__1.e1 FROM pm1.g1 AS g1__1 WHERE g1__1.e2 = (SELECT MAX(pm1.g1.e2) FROM pm1.g1 WHERE pm1.g1.e1 = g1__1.e1)" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    /** Case 1456, defect 10492*/
+    @Test public void testAliasingDefect2(){
+        // Create query
+        String sql = "SELECT X.e1 FROM vm1.g1 X, vm1.g1 Z WHERE X.e2 = (SELECT MAX(e2) FROM vm1.g1 Y WHERE X.e1 = Y.e1 AND Y.e2 = Z.e2) AND X.e1 = Z.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g1__1.e1 FROM pm1.g1 AS g1__1, pm1.g1 AS g1__2 WHERE (g1__1.e2 = (SELECT MAX(pm1.g1.e2) FROM pm1.g1 WHERE (pm1.g1.e1 = g1__1.e1) AND (pm1.g1.e2 = g1__2.e2))) AND (g1__1.e1 = g1__2.e1)" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    /** Case 1456, defect 10492*/
+    @Test public void testAliasingDefect3(){
+        // Create query
+        String sql = "SELECT X.e1 FROM pm1.g2, vm1.g1 X WHERE X.e2 = ANY (SELECT MAX(e2) FROM vm1.g1 Y WHERE X.e1 = Y.e1) AND X.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT g_1.e1 FROM pm1.g2 AS g_0, pm1.g1 AS g_1 WHERE (g_1.e1 = g_0.e1) AND (g_1.e2 = SOME (SELECT MAX(g_2.e2) FROM pm1.g1 AS g_2 WHERE g_2.e1 = g_1.e1))" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+        
+    /** Should use merge join since neither access node is "strong" - order by's pushed to source */
+    @Test public void testUseMergeJoin3(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm1.g2.e1 FROM pm1.g2 ORDER BY pm1.g2.e1" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }    
+
+    /** Model supports order by, should be pushed to the source */
+    @Test public void testUseMergeJoin4(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm1.g2.e1 FROM pm1.g2 ORDER BY pm1.g2.e1" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    } 
+
+    /** Should use merge join, since costs are not known, neither access node is "strong" */
+    @Test public void testUseMergeJoin5_CostsNotKnown(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    /** one side of join supports order by, the other doesn't*/
+    @Test public void testUseMergeJoin7(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g2 WHERE pm1.g1.e1 = pm2.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm2.g2.e1 FROM pm2.g2" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }     
+
+    /** reverse of testUseMergeJoin7 */
+    @Test public void testUseMergeJoin7a(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g2 WHERE pm1.g1.e1 = pm2.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm2.g2.e1 FROM pm2.g2 ORDER BY pm2.g2.e1" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }   
+
+    /** function on one side of join should prevent order by from being pushed down*/
+    @Test public void testUseMergeJoin8(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g2 WHERE concat(pm1.g1.e1, 'x') = pm2.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm2.g2.e1 FROM pm2.g2 ORDER BY pm2.g2.e1" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+
+    /** Model supports order by, functions in join criteria */
+    @Test public void testUseMergeJoin9(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE concat(pm1.g1.e1, 'x') = concat(pm1.g2.e1, 'x')";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            3,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    } 
+
+    /** should be one dependent join */
+    @Test public void testMultiMergeJoin1(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2, pm1.g3 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g2.e1 = pm1.g3.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE / 4));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE));
+        FakeMetadataObject g3 = metadata.getStore().findObject("pm1.g3", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g3.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g3.e1 FROM pm1.g3" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    } 
+
+    @Test public void testLargeSetCriteria() {
+        //      Create query
+        String sql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA INNER JOIN BQT2.SmallB ON BQT1.SmallA.IntKey = BQT2.SmallB.IntKey WHERE BQT1.SmallA.IntKey IN (1,2,3,4,5)";     //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+            null, capFinder,
+            new String[] { "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA ORDER BY BQT1.SmallA.IntKey",  //$NON-NLS-1$
+                            "SELECT BQT2.SmallB.IntKey FROM BQT2.SmallB ORDER BY BQT2.SmallB.IntKey" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            2,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });            
+    }
+    
+    @Test public void testMergeJoin_defect11236(){
+        // Create query
+        String sql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE BQT1.SmallA.IntKey = (BQT1.SmallB.IntKey + 1)";     //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT BQT1.SmallB.IntKey FROM BQT1.SmallB",  //$NON-NLS-1$
+                            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA ORDER BY BQT1.SmallA.IntKey" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+        
+    @Test public void testNoFrom() { 
+        ProcessorPlan plan = helpPlan("SELECT 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {} ); 
+
+        checkNodeTypes(plan, new int[] {
+            0,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    @Test public void testINCriteria_defect10718(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm1.g2.e1 FROM pm1.g2 ORDER BY pm1.g2.e1"}, SHOULD_SUCCEED); //$NON-NLS-1$  //$NON-NLS-2$ 
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    @Test public void testDefect10711(){
+        ProcessorPlan plan = helpPlan("SELECT * from vm1.g1a as X", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);         
+
+    }
+    
+    // SELECT 5, SUM(IntKey) FROM BQT1.SmallA
+    @Test public void testAggregateNoGroupByWithExpression() {
+        ProcessorPlan plan = helpPlan("SELECT 5, SUM(IntKey) FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { "SELECT IntKey FROM BQT1.SmallA"  }); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    /** defect 11630 - note that the lookup function is not pushed down, it will actually be evaluated before being sent to the connector */
+    @Test public void testLookupFunction() {
+
+        ProcessorPlan plan = helpPlan("SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 1) IS NULL", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1', 'e1', 'e2', 1) IS NULL"  }); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+
+    }
+    
+    /** case 5213 - note here that the lookup cannot be pushed down since it is dependent upon an element symbol*/
+    @Test public void testLookupFunction2() throws Exception {
+
+        ProcessorPlan plan = helpPlan("SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', e2) IS NULL", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e2, g_0.e1 FROM pm1.g2 AS g_0"  }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+
+    }
+    
+    /** defect 21965 */
+    @Test public void testLookupFunctionInSelect() {
+        ProcessorPlan plan = helpPlan("SELECT e1, LOOKUP('pm1.g1','e1', 'e2', 1) FROM pm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1, LOOKUP('pm1.g1','e1', 'e2', 1) FROM pm1.g2"  }); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    // SELECT * FROM (SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT DISTINCT IntNum FROM BQT1.SmallA) AS x WHERE IntKey = 0
+    @Test public void testCase1649() {
+        ProcessorPlan plan = helpPlan("SELECT * FROM (SELECT DISTINCT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA) AS x WHERE IntKey = 0", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT IntKey FROM BQT1.SmallA WHERE IntKey = 0", "SELECT IntNum FROM BQT1.SmallA WHERE IntNum = 0"  }); //$NON-NLS-1$ //$NON-NLS-2$
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });                                    
+    }   
+
+    // SELECT * FROM (SELECT IntKey a, IntNum b FROM BQT1.SmallA UNION ALL SELECT Intkey, Intkey FROM BQT1.SmallA) as x WHERE b = 0
+    @Test public void testCase1727_1() {
+        ProcessorPlan plan = helpPlan("SELECT * FROM (SELECT IntKey a, IntNum b FROM BQT1.SmallA UNION ALL SELECT Intkey, Intkey FROM BQT1.SmallA) as x WHERE b = 0", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { 
+                "SELECT IntKey, IntNum FROM BQT1.SmallA WHERE IntNum = 0", //$NON-NLS-1$
+                "SELECT IntKey, IntKey FROM BQT1.SmallA WHERE IntKey = 0"  }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });                                    
+    }
+
+    // SELECT * FROM (SELECT IntKey a, IntNum b FROM BQT1.SmallA UNION ALL SELECT Intkey, Intkey FROM BQT1.SmallA) as x WHERE b = 0
+    @Test public void testCase1727_2() {
+        ProcessorPlan plan = helpPlan("SELECT * FROM (SELECT IntKey a, IntKey b FROM BQT1.SmallA UNION ALL SELECT IntKey, IntNum FROM BQT1.SmallA) as x WHERE b = 0", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] { 
+                "SELECT IntKey, IntNum FROM BQT1.SmallA WHERE IntNum = 0", //$NON-NLS-1$
+                "SELECT IntKey, IntKey FROM BQT1.SmallA WHERE IntKey = 0"  }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testCountStarOverSelectDistinct() {
+        ProcessorPlan plan = helpPlan("SELECT COUNT(*) FROM (SELECT DISTINCT IntNum, Intkey FROM bqt1.smalla) AS x", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+                                      new String[] { 
+                                          "SELECT DISTINCT IntNum, Intkey FROM bqt1.smalla" }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });                                    
+    }
+
+    //virtual group with two elements. One selectable, one not
+    @Test public void testVirtualGroup1() {
+        ProcessorPlan plan = helpPlan("select e2 from vm1.g35", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e2 FROM pm1.g1" } ); //$NON-NLS-1$
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);     
+    }
+    
+    @Test public void testBQT9500_126() {
+        String sql = "SELECT IntKey, LongNum, expr FROM (SELECT IntKey, LongNum, concat(LongNum, 'abc') FROM BQT2.SmallA ) AS x ORDER BY IntKey"; //$NON-NLS-1$
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                      new String[] { 
+                                          "SELECT IntKey, LongNum FROM BQT2.SmallA" }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        1,      // Sort
+                                        0       // UnionAll
+        });                                    
+        
+    }
+    
+    public void helpTestUnionPushdown(boolean queryHasOrderBy, boolean hasUnionCapability, boolean hasUnionOrderByCapability) {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, hasUnionCapability);
+        caps.setCapabilitySupport((Capability.QUERY_ORDERBY), hasUnionOrderByCapability);
+        caps.setCapabilitySupport((Capability.QUERY_SET_ORDER_BY), hasUnionOrderByCapability);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sqlUnion = "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB";//$NON-NLS-1$
+        String sqlOrderBy = sqlUnion + " ORDER BY IntKey"; //$NON-NLS-1$
+        String sql = null;
+        if(queryHasOrderBy) {
+            sql = sqlOrderBy;
+        } else {
+            sql = sqlUnion;
+        }
+            
+        String[] expectedSql = null;
+        if(hasUnionCapability) {
+            if(queryHasOrderBy && hasUnionOrderByCapability) {
+                expectedSql = new String[] {sqlOrderBy };
+            } else {
+                expectedSql = new String[] {sqlUnion };
+            }            
+        } else {
+            expectedSql = new String[] { "SELECT IntKey FROM BQT1.SmallA", "SELECT IntKey FROM BQT1.SmallB" };  //$NON-NLS-1$//$NON-NLS-2$
+        }
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql, metadata, 
+                                      null, capFinder, expectedSql, SHOULD_SUCCEED);  
+
+        int accessCount = hasUnionCapability ? 1 : 2;  
+        int projectCount = 0;
+        int sortCount = 0;
+        if(queryHasOrderBy && ! (hasUnionCapability && hasUnionOrderByCapability)) { 
+            sortCount = 1;    
+        }
+        int unionCount = hasUnionCapability ? 0 : 1;
+        
+        
+        
+        checkNodeTypes(plan, new int[] {
+                                        accessCount,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        projectCount,      // Project
+                                        0,      // Select
+                                        sortCount,      // Sort
+                                        unionCount       // UnionAll
+        });                                                   
+    }
+    
+    /**
+     * Query has union but no order by and no capabilities.
+     */
+    @Test public void testUnionPushdown1() {
+        helpTestUnionPushdown(false, false, false);
+    }
+
+    /**
+     * Query has union but no order by and only union capability.
+     */
+    @Test public void testUnionPushdown2() {
+        helpTestUnionPushdown(false, true, false);
+    }
+
+    /**
+     * Query has union with order by and no capabilities.
+     */
+    @Test public void testUnionPushdown3() {
+        helpTestUnionPushdown(true, false, false);
+    }
+
+    /**
+     * Query has union with order by and just union capability.
+     */
+    @Test public void testUnionPushdown4() {
+        helpTestUnionPushdown(true, true, false);
+    }
+
+    /**
+     * Query has union with order by and both capabilities.
+     */
+    @Test public void testUnionPushdown5() {
+        helpTestUnionPushdown(true, true, true);
+    }
+
+    @Test public void testUnionPushdownWithSelectNoFrom() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT 1 UNION ALL SELECT 2", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, new String[] {}, SHOULD_SUCCEED);  
+
+        checkNodeTypes(plan, new int[] {
+                                        0,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+    }
+
+    @Test public void testUnionPushdownWithSelectNoFromFirstBranch() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT 1 UNION ALL SELECT IntKey FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, new String[] {"SELECT IntKey FROM BQT1.SmallA"}, SHOULD_SUCCEED);   //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+    }
+
+    @Test public void testUnionPushdownWithSelectNoFromSecondBranch() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT 1", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, new String[] {"SELECT IntKey FROM BQT1.SmallA"}, SHOULD_SUCCEED);   //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+    }
+    
+    @Test public void testUnionPushdownMultipleBranches() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB UNION ALL SELECT IntKey FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB UNION ALL SELECT IntKey FROM BQT1.SmallA"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+    
+    @Test public void testUnionPushdownMultipleBranchesMixedModels1() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB UNION ALL SELECT IntKey FROM BQT2.SmallA", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB", "SELECT IntKey FROM BQT2.SmallA"},  //$NON-NLS-1$ //$NON-NLS-2$
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        0,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+    }
+    
+    @Test public void testUnionPushdownMultipleBranchesNoDupRemoval() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT IntKey FROM BQT1.SmallA UNION SELECT IntKey FROM BQT1.SmallB UNION SELECT IntKey FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA UNION SELECT IntKey FROM BQT1.SmallB UNION SELECT IntKey FROM BQT1.SmallA"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+    
+    @Test public void testAggregateOverUnionPushdown() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT COUNT(*) FROM (SELECT IntKey FROM BQT1.SmallA UNION SELECT IntKey FROM BQT1.SmallB) AS x", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA UNION SELECT IntKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });                                                   
+    }
+
+    @Test public void testUnionPushdownWithFunctionsAndAliases() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT IntKey+2, StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT (IntKey + 2), StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+    
+    @Test public void testUnionPushdownWithInternalOrderBy() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("(SELECT IntKey FROM BQT1.SmallA ORDER BY IntKey) UNION ALL SELECT IntKey FROM BQT1.SmallB", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }    
+
+    @Test public void testUnionPushdownWithInternalDistinct() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        ProcessorPlan plan = helpPlan("SELECT DISTINCT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB", metadata,  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT DISTINCT IntKey FROM BQT1.SmallA UNION ALL SELECT IntKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    } 
+    
+    @Test public void testUnionNoAllPushdownInInlineView() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT x FROM (SELECT IntKey+2, StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB) AS g", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT (IntKey + 2), StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });                                                   
+    }
+
+    @Test public void testUnionAllPushdownInInlineView() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, false);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT x FROM (SELECT IntKey+2, StringKey AS x FROM BQT1.SmallA UNION ALL SELECT IntKey, StringKey FROM BQT1.SmallB) AS g", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT StringKey AS x FROM BQT1.SmallA UNION ALL SELECT StringKey FROM BQT1.SmallB"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+
+    @Test public void testUnionAllPushdownVirtualGroup() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT * FROM vm1.g4", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT e1 FROM pm1.g1 UNION ALL SELECT convert(e2, string) FROM pm1.g2"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+
+    @Test public void testUnionAllPushdownVirtualGroup2() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        capFinder.addCapabilities("pm3", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT e2 FROM vm1.g17", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+                                      null, capFinder, 
+                                      new String[] {"SELECT pm3.g1.e2 FROM pm3.g1 UNION ALL SELECT pm3.g2.e2 FROM pm3.g2"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+
+    @Test public void testUnionAllPushdownVirtualGroup3() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT * FROM (SELECT intkey, 5 FROM BQT1.SmallA UNION ALL SELECT intnum, 10 FROM bqt1.smalla) AS x",  //$NON-NLS-1$
+                                      FakeMetadataFactory.exampleBQTCached(),  
+                                      null, capFinder, 
+                                      new String[] {"SELECT intkey FROM BQT1.SmallA", "SELECT IntNum FROM bqt1.smalla"},  //$NON-NLS-1$ //$NON-NLS-2$
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        2,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+    }
+
+    // Allow pushing literals
+    @Test public void testUnionAllPushdownVirtualGroup4() {        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT * FROM (SELECT intkey, 5 FROM BQT1.SmallA UNION ALL SELECT intnum, 10 FROM bqt1.smalla) AS x",  //$NON-NLS-1$
+                                      FakeMetadataFactory.exampleBQTCached(),  
+                                      null, capFinder, 
+                                      new String[] {"SELECT intkey, 5 FROM BQT1.SmallA UNION ALL SELECT IntNum, 10 FROM bqt1.smalla"},  //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED);   
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                                   
+    }
+
+    @Test public void testPushCaseInSelect() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT CASE WHEN e1 = 'a' THEN 10 ELSE 0 END FROM pm1.g1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT CASE WHEN e1 = 'a' THEN 10 ELSE 0 END FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testCantPushCaseInSelectWithFunction() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT CASE e1 WHEN 'a' THEN 10 ELSE (e2+0) END FROM pm1.g1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1, e2 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    @Test public void testPushSearchedCaseInSelect() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT CASE WHEN e1 = 'a' THEN 10 ELSE 0 END FROM pm1.g1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT CASE WHEN e1 = 'a' THEN 10 ELSE 0 END FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testCantPushSearchedCaseInSelectWithFunction() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT CASE WHEN e1 = 'a' THEN 10 ELSE (e2+0) END FROM pm1.g1",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1, e2 FROM pm1.g1"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+
+    @Test public void testPushdownFunctionNotEvaluated() {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_NOT, true);
+        caps.setFunctionSupport("xyz", true);         //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FunctionLibrary funcLibrary = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(new FakeFunctionMetadataSource().getFunctionMethods())));
+        FakeMetadataFacade metadata = new FakeMetadataFacade(FakeMetadataFactory.example1Cached().getStore(), funcLibrary);
+        
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT e1 FROM pm1.g1 WHERE xyz() > 0",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT e1 FROM pm1.g1 WHERE xyz() > 0"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+
+    @Test public void testNoSourceQuery() {
+        ProcessorPlan plan = helpPlan("SELECT * FROM (select parsetimestamp(x,'yyyy-MM-dd') as c1 from (select '2004-10-20' as x) as y) as z " +//$NON-NLS-1$ 
+                                      "WHERE c1= '2004-10-20 00:00:00.0'", FakeMetadataFactory.exampleBQTCached(), //$NON-NLS-1$
+            new String[] {  }); 
+
+        checkNodeTypes(plan, new int[] {
+            0,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    /** defect 14510 */
+    @Test public void testDefect14510LookupFunction() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQT();
+        FakeMetadataFactory.setCardinality("bqt1.smallb", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata); //$NON-NLS-1$
+        FakeMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = lookup('BQT1.SmallB', 'IntKey', 'StringKey', BQT1.SmallB.StringKey)) AND (BQT1.SmallA.IntKey = 1)",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.IntKey = 1", "SELECT BQT1.SmallB.StringKey FROM BQT1.SmallB"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });             
+    }    
+
+    /** defect 14510 */
+    @Test public void testDefect14510LookupFunction2() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQT();
+        FakeMetadataFactory.setCardinality("bqt1.mediumb", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata); //$NON-NLS-1$
+        FakeMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT BQT1.SmallA.IntKey, BQT1.MediumB.IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT1.MediumB ON BQT1.SmallA.IntKey = lookup('BQT1.MediumB', 'IntKey', 'StringKey', BQT1.MediumB.StringKey)",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA", "SELECT BQT1.MediumB.StringKey, BQT1.MediumB.IntKey FROM BQT1.MediumB"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+
+    /** defect 14510 */
+    @Test public void testDefect14510LookupFunction3() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQT();
+        FakeMetadataFactory.setCardinality("bqt1.mediumb", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata); //$NON-NLS-1$
+        FakeMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata); //$NON-NLS-1$
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT BQT1.SmallA.IntKey, BQT1.MediumB.IntKey FROM BQT1.MediumB RIGHT OUTER JOIN BQT1.SmallA ON BQT1.SmallA.IntKey = lookup('BQT1.MediumB', 'IntKey', 'StringKey',BQT1.MediumB.StringKey)",  //$NON-NLS-1$          
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA", "SELECT BQT1.MediumB.StringKey, BQT1.MediumB.IntKey FROM BQT1.MediumB"}, //$NON-NLS-1$ //$NON-NLS-2$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }    
+    
+    @Test public void testCase2125() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_NOT, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, false);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);        
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);        
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);        
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT OD.IntKEy, P.IntKEy, O.IntKey " +  //$NON-NLS-1$
+            "FROM (bqt1.smalla AS OD INNER JOIN bqt1.smallb AS P ON OD.StringKey = P.StringKey) " +  //$NON-NLS-1$
+            "INNER JOIN bqt1.mediuma AS O ON O.IntKey = OD.IntKey " +  //$NON-NLS-1$
+            "WHERE (OD.IntNum > (SELECT SUM(IntNum) FROM bqt1.smalla)) AND " +  //$NON-NLS-1$
+            "(P.longnum > (SELECT AVG(LongNum) FROM bqt1.smallb WHERE bqt1.smallb.datevalue = O.datevalue))"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT g_1.longnum, g_2.datevalue, g_0.IntKEy, g_1.IntKEy, g_2.IntKey FROM bqt1.smalla AS g_0, bqt1.smallb AS g_1, bqt1.mediuma AS g_2 WHERE (g_0.StringKey = g_1.StringKey) AND (g_2.IntKey = g_0.IntKey) AND (g_0.IntNum > (SELECT SUM(g_3.IntNum) FROM bqt1.smalla AS g_3))"}, //$NON-NLS-1$ 
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        1,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }
+    
+    @Test public void testPushdownLiteralInSelectUnderAggregate() {  
+        String sql = "SELECT COUNT(*) FROM (SELECT '' AS y, a.IntKey FROM BQT1.SmallA a union all select '', b.intkey from bqt1.smallb b) AS x"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT '' AS y FROM BQT1.SmallA AS a UNION ALL SELECT '' FROM bqt1.smallb AS b"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }
+
+    @Test public void testPushdownLiteralInSelectUnderAggregate2() {  
+        String sql = "SELECT SUM(z) FROM (SELECT '' AS y, a.IntKey as z FROM BQT1.SmallA a union all select b.stringkey, 0 from bqt1.smallb b) AS x group by z"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT a.IntKey AS z FROM BQT1.SmallA AS a UNION ALL SELECT 0 FROM bqt1.smallb AS b"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }
+
+    @Test public void testPushdownLiteralInSelectUnderAggregate3() {  
+        String sql = "SELECT code, SUM(ID) FROM (SELECT IntKey AS ID, '' AS Code FROM BQT1.SmallA union all select intkey, stringkey from bqt1.smallb b) AS x group by code"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT '' AS Code, IntKey AS ID FROM BQT1.SmallA UNION ALL SELECT stringkey, intkey FROM bqt1.smallb AS b"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });
+    }
+
+    @Test public void testPushdownLiteralInSelectWithOrderBy() {  
+        String sql = "SELECT 1, concat('a', 'b' ) AS X FROM BQT1.SmallA where intkey = 0 " +  //$NON-NLS-1$
+            "UNION ALL " +  //$NON-NLS-1$
+            "select 2, 'Hello2' from BQT1.SmallA where intkey = 1 order by X desc"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT 1, 'ab' AS X FROM BQT1.SmallA WHERE intkey = 0 UNION ALL SELECT 2, 'Hello2' FROM BQT1.SmallA WHERE IntKey = 1 ORDER BY X DESC"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+    }
+    
+    @Test public void testUpdateWithElement() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "UPDATE BQT1.SmallA SET IntKey = IntKey + 1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"UPDATE BQT1.SmallA SET IntKey = (IntKey + 1)"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }            
+    
+    @Test public void testCase2187() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        String sql = "SELECT t.intkey FROM (SELECT a.IntKey FROM bqt1.smalla a left outer join bqt1.smallb b on a.intkey=b.intkey, bqt1.smalla x) as t full outer JOIN bqt1.smallb c on t.intkey = c.intkey"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT a.IntKey FROM ((bqt1.smalla AS a LEFT OUTER JOIN bqt1.smallb AS b ON a.intkey = b.intkey) CROSS JOIN bqt1.smalla AS x) FULL OUTER JOIN bqt1.smallb AS c ON a.IntKey = c.intkey"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }        
+    
+    @Test public void testMultiUnionMergeVirtual() throws Exception {
+        String sql = "SELECT * FROM " +  //$NON-NLS-1$
+            "(SELECT IntKey, 'a' AS s FROM (SELECT intkey, stringkey from BQT1.SmallA) as a union all " +  //$NON-NLS-1$
+            "select IntKey, 'b' FROM (SELECT intkey, stringkey from BQT1.SmallA) as b union all " +  //$NON-NLS-1$
+            "select IntKey, 'c' FROM (SELECT intkey, stringkey from BQT1.SmallA) as c " +  //$NON-NLS-1$
+            ") AS x"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"(SELECT g_2.intkey AS c_0, 'a' AS c_1 FROM BQT1.SmallA AS g_2 UNION ALL SELECT g_1.IntKey AS c_0, 'b' AS c_1 FROM BQT1.SmallA AS g_1) UNION ALL SELECT g_0.IntKey AS c_0, 'c' AS c_1 FROM BQT1.SmallA AS g_0"}, //$NON-NLS-1$ 
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);        
+    }
+    
+    @Test public void testDefect16848_groupAliasNotSupported_1() {
+        String sql = "SELECT sa.intkey, sa.objectvalue FROM bqt1.smalla AS sa WHERE (sa.intkey = 46) AND (sa.stringkey IN (46)) AND (sa.datevalue = (SELECT MAX(sb.datevalue) FROM bqt1.smalla AS sb WHERE (sb.intkey = sa.intkey) AND (sa.stringkey = sb.stringkey) ))"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        RelationalPlan plan = (RelationalPlan)helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT bqt1.smalla.datevalue, bqt1.smalla.intkey, bqt1.smalla.stringkey, bqt1.smalla.objectvalue FROM bqt1.smalla WHERE (bqt1.smalla.intkey = 46) AND (bqt1.smalla.stringkey = '46')"}, //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        1,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });   
+        
+        ProcessorPlan subplan = ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(((SelectNode)plan.getRootNode().getChildren()[0]).getCriteria()).get(0).getCommand().getProcessorPlan();
+        
+        // Collect atomic queries
+        Set<String> actualQueries = getAtomicQueries(subplan);
+        
+        // Compare atomic queries
+        HashSet<String> expectedQueries = new HashSet<String>(Arrays.asList(new String[] { "SELECT bqt1.smalla.datevalue FROM bqt1.smalla WHERE (bqt1.smalla.intkey = bqt1.smalla.intkey) AND (bqt1.smalla.stringkey = bqt1.smalla.stringkey)"})); //$NON-NLS-1$
+        assertEquals("Did not get expected atomic queries for subplan: ", expectedQueries, actualQueries); //$NON-NLS-1$
+
+        checkNodeTypes(subplan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });   
+
+    }
+
+    @Test public void testFunctionOfAggregate1() {
+        String sql = "SELECT SUM(IntKey) + 1 AS x FROM BQT1.SmallA GROUP BY IntKey"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT (SUM(IntKey) + 1) FROM BQT1.SmallA GROUP BY IntKey"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);        
+    }
+
+    @Test public void testFunctionOfAggregateCantPush1() {
+        String sql = "SELECT SUM(IntKey) + 1 AS x FROM BQT1.SmallA GROUP BY IntKey"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT IntKey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+
+    @Test public void testFunctionOfAggregateCantPush3() {
+        String sql = "SELECT avg(intkey) * 2 FROM BQT1.SmallA "; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      FakeMetadataFactory.exampleBQTCached(),
+                                      null, capFinder,
+                                      new String[] {"SELECT intkey FROM BQT1.SmallA"}, //$NON-NLS-1$ 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        1,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        1,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        0,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+    }
+
+    private void helpTestCase2589NonPushdown(String sql, String[] expected) {
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, false);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      expected, 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // Join
+                                        1,      // MergeJoin
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });            
+    
+    }
+    
+    private void helpTestCase2589(String sql, String expected) throws Exception {  
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {expected}, 
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);          
+    }
+    
+    @Test public void testCase2589() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589 ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        
+        helpTestCase2589(sql, expected);
+    }     
+
+    @Test public void testCase2589a() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589a ON MediumA.IntKey = SmallA_2589a.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }    
+
+    @Test public void testCase2589b() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }     
+    
+    @Test public void testCase2589c() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB, BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey " + //$NON-NLS-1$
+                     "WHERE BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB INNER JOIN (BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10') ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }    
+
+    @Test public void testCase2589d() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB INNER JOIN " + //$NON-NLS-1$
+                     "(BQT1.MediumA LEFT OUTER JOIN VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey) " + //$NON-NLS-1$
+                     "ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB INNER JOIN (BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10') ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }     
+    
+    @Test public void testCase2589e() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN " +  //$NON-NLS-1$
+                     "(BQT1.MediumA LEFT OUTER JOIN VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey) " +  //$NON-NLS-1$
+                     "ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN (BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10') ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }     
+    
+    @Test public void testCase2589f() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "(BQT1.MediumA INNER JOIN VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey) " + //$NON-NLS-1$
+                     "ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN (BQT1.MediumA INNER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey) ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey AND BQT1.SmallA.StringNum = '10'";//$NON-NLS-1$";
+        helpTestCase2589(sql, expected);
+    }    
+
+    @Test public void testCase2589g() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN " + //$NON-NLS-1$ 
+                     "(BQT1.MediumA INNER JOIN VQT.SmallA_2589c ON MediumA.IntKey = SmallA_2589c.IntKey) " + //$NON-NLS-1$ 
+                     "ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumB LEFT OUTER JOIN " + //$NON-NLS-1$ 
+                     "(BQT1.MediumA INNER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB " + //$NON-NLS-1$ 
+                     "ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey AND " +  //$NON-NLS-1$
+                     "concat(BQT1.SmallA.StringNum, BQT1.SmallB.StringNum) = '1010') " +  //$NON-NLS-1$
+                     "ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey) ON BQT1.MediumB.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }    
+    
+    @Test public void testCase2589h() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN VQT.SmallA_2589c " + //$NON-NLS-1$ 
+                     "ON MediumA.IntKey = SmallA_2589c.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey AND concat(BQT1.SmallA.StringNum, BQT1.SmallB.StringNum) = '1010') ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey"; //$NON-NLS-1$ 
+        helpTestCase2589(sql, expected);
+    }
+    
+    @Test public void testCase2589i() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN VQT.SmallA_2589d " + //$NON-NLS-1$ 
+                     "ON MediumA.IntKey = SmallA_2589d.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' AND BQT1.SmallA.IntNum = 10"; //$NON-NLS-1$ 
+        helpTestCase2589(sql, expected);
+    }
+    
+    /**
+     * Test optimization doesn't happen if an outer join isn't involved 
+     */
+    @Test public void testCase2589j() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA INNER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589 ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA, BQT1.SmallA WHERE (BQT1.MediumA.IntKey = BQT1.SmallA.IntKey) AND (BQT1.SmallA.StringNum = '10')"; //$NON-NLS-1$
+        
+        helpTestCase2589(sql, expected);
+    }     
+    
+    /**
+     * Test optimization doesn't happen if an outer join isn't involved 
+     */
+    @Test public void testCase2589k() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA INNER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey"; //$NON-NLS-1$
+
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA, BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) AND (BQT1.MediumA.IntKey = BQT1.SmallA.IntKey) AND (BQT1.SmallA.StringNum = '10')"; //$NON-NLS-1$
+        
+        
+        helpTestCase2589(sql, expected);
+    }
+
+    /**
+     * Same as testCase2589 except right outer join
+     */
+    @Test public void testCase2589l() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM VQT.SmallA_2589 RIGHT OUTER JOIN " + //$NON-NLS-1$
+                     "BQT1.MediumA ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        
+        helpTestCase2589(sql, expected);
+    }     
+    
+    /**
+     * Same as testCase2589 except full outer join - criteria "below" full outer join cannot be
+     * raised into the join criteria, so basically the virtual groups cannot be merged in this test.
+     */
+    @Test public void testCase2589m() {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM VQT.SmallA_2589 FULL OUTER JOIN " + //$NON-NLS-1$
+                     "BQT1.MediumA ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String[] expected = new String[] { 
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA",  //$NON-NLS-1$
+            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE StringNum = '10'" //$NON-NLS-1$
+        };
+        
+        helpTestCase2589NonPushdown(sql, expected);
+    }       
+
+    /**
+     * Same as testCase2589b except full outer join
+     */
+    @Test public void testCase2589n() {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA FULL OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589b ON MediumA.IntKey = SmallA_2589b.IntKey"; //$NON-NLS-1$
+        
+        String[] expected = new String[] { 
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA", //$NON-NLS-1$
+            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) AND (BQT1.SmallA.StringNum = '10')" //$NON-NLS-1$
+        };
+        helpTestCase2589NonPushdown(sql, expected);
+
+    }     
+    
+    /**
+     * Same as testCase2589 except with two virtual layers instead of one 
+     */
+    @Test public void testCase2589o() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589f ON MediumA.IntKey = SmallA_2589f.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        
+        helpTestCase2589(sql, expected);
+    }     
+
+    /**
+     * Same as testCase2589b except with two virtual layers instead of one 
+     */
+    @Test public void testCase2589p() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589g ON MediumA.IntKey = SmallA_2589g.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }     
+
+    /**
+     * Test 3 frames, where top frame has outer join, middle frame has inner join, and
+     * bottom frame has criteria that must be made into join criteria.  
+     */
+    @Test public void testCase2589q() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589h ON MediumA.IntKey = SmallA_2589h.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }       
+
+    /**
+     * Similar to testCase2589b, except virtual transformation has criteria on an 
+     * element from each physical table
+     */
+    @Test public void testCase2589r() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589i ON MediumA.IntKey = SmallA_2589i.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.StringKey = BQT1.SmallB.StringKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' AND BQT1.SmallB.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }      
+
+    /**
+     * Test user criteria that should NOT be moved into join clause 
+     */
+    @Test public void testCase2589s() throws Exception {  
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589 ON MediumA.IntKey = SmallA_2589.IntKey " + //$NON-NLS-1$
+                     "WHERE BQT1.MediumA.IntNum = 10"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' WHERE BQT1.MediumA.IntNum = 10"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }      
+
+    /**
+     * Test user criteria that should NOT be moved into join clause 
+     */
+    @Test public void testCase2589t() throws Exception {  
+        String sql = "SELECT z.IntKey FROM (SELECT IntKey FROM BQT1.MediumA WHERE BQT1.MediumA.IntNum = 10) as z " + //$NON-NLS-1$
+                     "LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "VQT.SmallA_2589 ON z.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' WHERE BQT1.MediumA.IntNum = 10"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }    
+
+    /**
+     * The above test written with an inline view instead of a virtual group.
+     * This test translates to - how can this query be rewritten without subqueries such
+     * that the same results are produced?  More specifically, where should the criteria
+     * go - WHERE clause or FROM clause? 
+     */
+    @Test public void testCase2589u() throws Exception {  
+        String sql = "SELECT z.IntKey FROM (SELECT IntKey FROM BQT1.MediumA WHERE IntNum = 10) as z " + //$NON-NLS-1$
+                     "LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "(SELECT IntKey FROM BQT1.SmallA WHERE StringNum = '10') as y " + //$NON-NLS-1$
+                     "ON z.IntKey = y.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' WHERE BQT1.MediumA.IntNum = 10"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    } 
+
+    /**
+     * Same sql as testCase2589, but the model doesn't support outer joins, so 
+     * case 2589 optimization shouldn't happen. 
+     */
+    @Test public void testCase2589v() {  
+
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+        "VQT.SmallA_2589 ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected[] = new String[] {
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA", //$NON-NLS-1$
+            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE StringNum = '10'" //$NON-NLS-1$                                          
+        };
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, false);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      expected, 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });          
+    }    
+
+    /**
+     * Same as previous testCase2589v, but with full outer join. 
+     */
+    @Test public void testCase2589w() {  
+
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA FULL OUTER JOIN " + //$NON-NLS-1$
+        "VQT.SmallA_2589 ON MediumA.IntKey = SmallA_2589.IntKey"; //$NON-NLS-1$
+        
+        String expected[] = new String[] {
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA", //$NON-NLS-1$
+            "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE StringNum = '10'" //$NON-NLS-1$                                          
+        };
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, false);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      expected, 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });          
+    }    
+
+    /**
+     * Test a complicated join tree involving multiple models, but with a nested
+     * outer join predicate spanning only one model, and see if the case 2589
+     * fix happens.  The important thing is the criteria "StringNum = '10'" needs
+     * to be put in the join criteria, not the where clause, of the second atomic
+     * query, because in the user query it is on the inner side of an outer join.
+     */
+    @Test public void testCase2589x() throws Exception {  
+
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT2.SmallA INNER JOIN " + //$NON-NLS-1$
+        "(BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+        "(SELECT IntKey FROM BQT1.SmallA WHERE StringNum = '10') as y " + //$NON-NLS-1$
+        "ON MediumA.IntKey = y.IntKey) " + //$NON-NLS-1$
+        "ON BQT2.SmallA.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected[] = new String[] {
+            "SELECT BQT2.SmallA.IntKey FROM BQT2.SmallA", //$NON-NLS-1$
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'" //$NON-NLS-1$                                          
+        };
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      expected, 
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });          
+    }     
+
+    /**
+     * Test two outer joins, one nested within the other, all pushable to one source, 
+     * with inline views having criteria that each need to be migrated to their 
+     * respective join predicate join criteria.
+     * 
+     * The tree below illustrates the canonical plan (plus access nodes).  'y' and
+     * 'z' are two inline views.  Notice each has a SELECT node underneath - the
+     * criteria represented by each of those SELECT nodes is on the inner side of
+     * their respective left outer joins (LOJ).  So, each criteria needs to be
+     * migrated to the join criteria.
+     * 
+     * <pre>
+     *          LOJ
+     *         /    \
+     *      LOJ      SRC z
+     *    /    \       |
+     *  SRC    SRC y  SEL
+     *  MedB    |      |
+     *         SEL    ACC
+     *          |      |
+     *         ACC    SRC SmA
+     *          |
+     *         SRC MedA
+     * </pre>
+     * Here's a diagram of what the join plan of the resulting atomic query should
+     * look like.
+     * <pre>
+     *          ACC 
+     *           |
+     *          LOJ**
+     *         /    \    
+     *      LOJ**    SRC       **criteria migrated to here
+     *    /    \     SmA
+     *  SRC    SRC  
+     *  MedB   MedA           
+     * </pre>
+     */
+    @Test public void testCase2589y() throws Exception {  
+        String sql = "SELECT L.IntKey, y.IntKey, z.IntKey " + //$NON-NLS-1$
+                     "FROM (BQT1.MediumB as L LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "(SELECT IntKey FROM BQT1.MediumA as M WHERE M.IntNum = 4) as y ON y.IntKey = L.IntKey) " + //$NON-NLS-1$
+                     "LEFT OUTER JOIN (SELECT IntKey FROM BQT1.SmallA as S WHERE S.StringNum = '10') as z " + //$NON-NLS-1$
+                     "ON z.IntKey = y.IntKey"; //$NON-NLS-1$
+        
+        String expected = "SELECT BQT1.MediumB.IntKey, BQT1.MediumA.IntKey, BQT1.SmallA.IntKey " + //$NON-NLS-1$
+                     "FROM (BQT1.MediumB LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "BQT1.MediumA ON BQT1.MediumA.IntKey = BQT1.MediumB.IntKey AND BQT1.MediumA.IntNum = 4) " + //$NON-NLS-1$
+                     "LEFT OUTER JOIN BQT1.SmallA " + //$NON-NLS-1$
+                     "ON BQT1.SmallA.IntKey = BQT1.MediumA.IntKey AND BQT1.SmallA.StringNum = '10'"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }    
+    
+    /**
+     * Test a complicated join tree involving multiple models, but with a nested
+     * outer join predicate spanning only one model, and see if the case 2589
+     * fix happens.  The important thing is the criteria "StringNum = '10'" needs
+     * to be put in the join criteria, not the where clause, of the second atomic
+     * query, because in the user query it is on the inner side of an outer join.
+     */
+    @Test public void testCase2589z() {  
+
+        String sql = "SELECT BQT1.MediumA.IntKey FROM BQT2.SmallA INNER JOIN " + //$NON-NLS-1$
+        "(BQT1.MediumA LEFT OUTER JOIN " + //$NON-NLS-1$
+        "(SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB " + //$NON-NLS-1$
+        "WHERE BQT1.SmallA.IntKey = BQT1.SmallB.IntKey AND BQT1.SmallA.StringNum = '10') as y " + //$NON-NLS-1$
+        "ON MediumA.IntKey = y.IntKey) " + //$NON-NLS-1$
+        "ON BQT2.SmallA.IntKey = BQT1.MediumA.IntKey"; //$NON-NLS-1$
+        
+        String expected[] = new String[] {
+            "SELECT BQT2.SmallA.IntKey FROM BQT2.SmallA", //$NON-NLS-1$
+            "SELECT BQT1.MediumA.IntKey FROM BQT1.MediumA LEFT OUTER JOIN (BQT1.SmallA INNER JOIN BQT1.SmallB ON BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10'" //$NON-NLS-1$                                          
+        };
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(sql,           
+                                      metadata,
+                                      null, capFinder,
+                                      expected, 
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // NestedLoopJoinStrategy
+                                        1,      // MergeJoinStrategy
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });          
+    }     
+
+    /**
+     * Union with multiple joins underneath 
+     */
+    @Test public void testCase2589aa() throws Exception {  
+        String sql = "SELECT * FROM (SELECT z.IntKey FROM (SELECT IntKey FROM BQT1.MediumA WHERE IntNum = 10) as z " + //$NON-NLS-1$
+                     "LEFT OUTER JOIN " + //$NON-NLS-1$
+                     "(SELECT IntKey FROM BQT1.SmallA WHERE StringNum = '10') as y " + //$NON-NLS-1$
+                     "ON z.IntKey = y.IntKey " + //$NON-NLS-1$
+                    "UNION ALL SELECT z.IntKey FROM (SELECT IntKey FROM BQT1.MediumA WHERE IntNum = 10) as z " + //$NON-NLS-1$
+                    "LEFT OUTER JOIN " + //$NON-NLS-1$
+                    "(SELECT IntKey FROM BQT1.SmallA WHERE StringNum = '10') as y " + //$NON-NLS-1$
+                    "ON z.IntKey = y.IntKey) as x"; //$NON-NLS-1$
+
+        String expected = "SELECT BQT1.MediumA.IntKey AS c_0 FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' WHERE BQT1.MediumA.IntNum = 10 UNION ALL SELECT BQT1.MediumA.IntKey AS c_0 FROM BQT1.MediumA LEFT OUTER JOIN BQT1.SmallA ON BQT1.MediumA.IntKey = BQT1.SmallA.IntKey AND BQT1.SmallA.StringNum = '10' WHERE BQT1.MediumA.IntNum = 10"; //$NON-NLS-1$
+        helpTestCase2589(sql, expected);
+    }
+
+    /**
+     * Since can now guarantee unique select column names, it's ok to have repeated entries in the order by clause.
+     */
+    @Test public void testOrderByDuplicates() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        String sql = "SELECT intkey, x FROM (select intkey, intkey x from bqt1.smalla) z ORDER BY x, intkey"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT g_0.intkey AS c_0, g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 ORDER BY c_1, c_0"},  //$NON-NLS-1$
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+    }
+
+    //Test use of OrderBy with expression
+    @Test public void testCase2507() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        String sql = "SELECT vqt.smallb.a12345 FROM vqt.smallb ORDER BY vqt.smallb.a12345"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT Concat(stringKey, stringNum) AS EXPR FROM BQT1.SmallA ORDER BY EXPR"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+    }
+    
+    @Test public void testCase2507A() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        String sql = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) as EXPR, bqt1.smalla.stringKey as EXPR_1 FROM bqt1.smalla  ORDER BY EXPR, EXPR_1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) AS EXPR, bqt1.smalla.stringKey AS EXPR_1 FROM bqt1.smalla ORDER BY EXPR, EXPR_1"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+    }  
+    
+    @Test public void testCase2507B() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        String sql = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum), bqt1.smalla.stringKey as EXPR_1 FROM bqt1.smalla ORDER BY EXPR_1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum), bqt1.smalla.stringKey AS EXPR_1 FROM bqt1.smalla ORDER BY EXPR_1"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+    }
+        
+    /**
+     * RulePlanJoins does not initially allow the cross join push.
+     * The subsequent RuleRaiseAccess does since we believe it was the intent of the user
+     */
+    @Test public void testPushCrossJoins() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        String sql = "SELECT b1.intkey from (bqt1.SmallA a1 cross join bqt1.smalla a2 cross join bqt1.mediuma b1) " +    //$NON-NLS-1$ 
+            " left outer join bqt1.mediumb b2 on b1.intkey = b2.intkey"; //$NON-NLS-1$         
+        
+        ProcessorPlan plan = helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT g_2.intkey FROM ((bqt1.SmallA AS g_0 CROSS JOIN bqt1.smalla AS g_1) CROSS JOIN bqt1.mediuma AS g_2) LEFT OUTER JOIN bqt1.mediumb AS g_3 ON g_2.intkey = g_3.intkey"},  //$NON-NLS-1$
+                                      ComparisonMode.EXACT_COMMAND_STRING );
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN);        
+    }
+    
+    @Test public void testCase3023() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        String sql = "SELECT bqt1.SmallA.intkey from (bqt1.SmallA inner join (" //$NON-NLS-1$         
+            + "SELECT BAD.intkey from bqt1.SmallB as BAD left outer join bqt1.MediumB on BAD.intkey = bqt1.MediumB.intkey) as X on bqt1.SmallA.intkey = X.intkey) inner join bqt1.MediumA on X.intkey = bqt1.MediumA.intkey"; //$NON-NLS-1$
+        
+         helpPlan(sql,  
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {"SELECT bqt1.SmallA.intkey FROM (bqt1.SmallA INNER JOIN (bqt1.SmallB AS BAD LEFT OUTER JOIN bqt1.MediumB ON BAD.intkey = bqt1.MediumB.intkey) ON bqt1.SmallA.intkey = BAD.intkey) INNER JOIN bqt1.MediumA ON BAD.intkey = bqt1.MediumA.intkey"},  //$NON-NLS-1$
+                                      SHOULD_SUCCEED );
+    }
+    
+    @Test public void testCase3367() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        FakeMetadataFacade metadata = example1();
+
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select e1 from pm1.g1 where pm1.g1.e1 IN (SELECT pm1.g2.e1 FROM pm1.g2 WHERE (pm1.g1.e1 = 2))", metadata,  //$NON-NLS-1$
+                                      null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE pm1.g1.e1 IN (SELECT pm1.g2.e1 FROM pm1.g2 WHERE pm1.g1.e1 = '2')" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    /*
+     * Set criteria was not getting pushed down correctly when there was a self-join 
+     * of a virtual table containing a join in it's transformation.  All virtual 
+     * models use the same physical model pm1.
+     */
+    @Test public void testCase3778() throws Exception {
+    	
+    	FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+                
+        ProcessorPlan plan = helpPlan(
+        		"select a.e1, b.e1 from vm2.g1 a, vm2.g1 b where a.e1 = b.e1 and a.e2 in (select e2 from vm1.g1)",  //$NON-NLS-1$
+        		metadata, null, capFinder, new String[] {"SELECT g_0.e1, g_2.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1, pm1.g1 AS g_2, pm1.g2 AS g_3 WHERE (g_2.e2 = g_3.e2) AND (g_0.e2 = g_1.e2) AND (g_0.e1 = g_2.e1) AND (g_0.e2 IN (SELECT g_4.e2 FROM pm1.g1 AS g_4))"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        checkNodeTypes(plan, FULL_PUSHDOWN);    
+    }
+    
+    /** 
+     * Ensures that order by expressions are not repeated when multiple criteria span a merge join 
+     */ 
+    @Test public void testCase3832() throws Exception { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = new BasicSourceCapabilities(); 
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true); 
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);         
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true); 
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);   
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$ 
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$ 
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$ 
+         
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+         
+        String sql = "select bqt1.smalla.intkey from bqt1.smalla, bqt2.smalla, bqt2.smallb where bqt1.smalla.intkey = bqt2.smalla.intkey and bqt1.smalla.intkey = bqt2.smallb.intkey and bqt2.smalla.stringkey = bqt2.smallb.stringkey"; //$NON-NLS-1$ 
+         
+        helpPlan(sql, 
+                 metadata, 
+                 null, 
+                 capFinder, 
+                 new String[] { 
+                     "SELECT bqt2.smallb.intkey AS c_0, bqt2.smalla.intkey AS c_1 FROM bqt2.smalla, bqt2.smallb WHERE bqt2.smalla.stringkey = bqt2.smallb.stringkey ORDER BY c_0, c_1", //$NON-NLS-1$ 
+                     "SELECT bqt1.smalla.intkey AS c_0 FROM bqt1.smalla ORDER BY c_0"}, //$NON-NLS-1$ 
+                 ComparisonMode.EXACT_COMMAND_STRING); 
+             
+    } 
+    
+    /*
+     * Functions containing exec statements should not be evaluated
+     */
+    @Test public void testDefect21972() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = new BasicSourceCapabilities(); 
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$ 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+         
+        String sql = "select e1 from pm1.g1 where e1 = convert((exec pm1.sq11(1, 2)), integer)"; //$NON-NLS-1$ 
+         
+        helpPlan(sql, 
+                 FakeMetadataFactory.example1Cached(), 
+                 null, 
+                 capFinder, 
+                 new String[] { 
+                     "SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$ 
+                 SHOULD_SUCCEED); 
+             
+    }
+    
+    @Test public void testExpressionSymbolPreservation() throws Exception { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = new BasicSourceCapabilities(); 
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true); 
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true); 
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$ 
+         
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached(); 
+         
+        String sql = "SELECT * from (select '1' as test, intkey from bqt2.smalla) foo, (select '2' as test, intkey from bqt2.smalla) foo2 where foo.intkey = foo2.intkey"; //$NON-NLS-1$ 
+         
+        helpPlan(sql,  
+                                      metadata, 
+                                      null, capFinder, 
+                                      new String[] {"SELECT '1', g_0.intkey, '2', g_1.IntKey FROM bqt2.smalla AS g_0, bqt2.smalla AS g_1 WHERE g_0.intkey = g_1.IntKey"},  //$NON-NLS-1$ 
+                                      ComparisonMode.EXACT_COMMAND_STRING ); 
+             
+    } 
+            
+    //since this does not support convert, it should not be collapsed
+    @Test public void testBadCollapseUnion() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "select convert(e2+1,string) from pm1.g1 union all select e1 from pm1.g2";//$NON-NLS-1$
+        String[] expectedSql = new String[] {"SELECT e2 FROM pm1.g1", "SELECT e1 FROM pm1.g2"};//$NON-NLS-1$ //$NON-NLS-2$
+        
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                      null, capFinder, expectedSql, SHOULD_SUCCEED);  
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // Join
+                                        0,      // MergeJoin
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        1       // UnionAll
+        });                                                   
+        
+    }
+    
+    @Test public void testCase3966() {
+        ProcessorPlan plan = helpPlan("insert into vm1.g37 (e1, e2, e3, e4) values('test', 1, convert('true', boolean) , convert('12', double) )", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+                                      new String[] {} ); 
+
+        checkNodeTypes(plan, new int[] {
+            0,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            1,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    /*
+     * Select literals created by runtime evaluation should not be pushed down.
+     */
+    @Test public void testCase4017() throws Exception {
+        
+        String sql = "SELECT env('soap_host') AS HOST, intkey from bqt2.smalla"; //$NON-NLS-1$
+        
+        helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(),
+                                      new String[] {"SELECT bqt2.smalla.intkey FROM bqt2.smalla"}, ComparisonMode.EXACT_COMMAND_STRING);  //$NON-NLS-1$      
+    }
+        
+    /**
+     * Test of RuleCopyCriteria.  Criteria should NOT be copied across a join if the join has any other operator
+     * other than an equality operator, but if the single group criteria is equality, then we can copy into a join criteria   
+     */
+    @Test public void testCase4265() throws Exception {
+        String sql = "SELECT X.intkey, Y.intkey FROM BQT1.SmallA X, BQT1.SmallA Y WHERE X.IntKey <> Y.IntKey and Y.IntKey = 1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                      new String[] { 
+                                          "SELECT g_0.IntKey FROM BQT1.SmallA AS g_0 WHERE g_0.IntKey <> 1",  //$NON-NLS-1$ 
+                                          "SELECT g_0.IntKey FROM BQT1.SmallA AS g_0 WHERE g_0.IntKey = 1" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Join
+                                        0,      // MergeJoin
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });                                    
+        
+    }    
+    
+    /**
+     * Test of RuleCopyCriteria.  Criteria should be copied across a join only for an equality operator in
+     * the join criteria.
+     */
+    @Test public void testCase4265ControlTest() throws Exception {
+        String sql = "SELECT X.intkey, Y.intkey FROM BQT1.SmallA X, BQT1.SmallA Y WHERE X.IntKey = Y.IntKey and Y.IntKey = 1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                      new String[] { 
+                                          "SELECT g_0.intkey FROM BQT1.SmallA AS g_0 WHERE g_0.IntKey = 1" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+                                        2,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        1,      // Join
+                                        0,      // MergeJoin
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+        });                                    
+        
+    }     
+    
+    /**
+     * The bug was in FrameUtil.convertCriteria() method, where ExistsCriteria was not being checked for. 
+     */
+    @Test public void testExistsCriteriaInSelect() {
+        String sql = "select intkey, case when exists (select stringkey from bqt1.smallb) then 'nuge' end as a from vqt.smalla"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                      new String[] { 
+                                          "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA" }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                   
+        
+    }    
+    
+    /**
+     * Try substituting "is not null" for "exists" criteria 
+     */
+    @Test public void testScalarSubQueryInSelect() {
+        String sql = "select intkey, case when (select stringkey from bqt1.smallb) is not null then 'nuge' end as a from vqt.smalla"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                      new String[] { 
+                                          "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA" }); //$NON-NLS-1$ 
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                   
+        
+    }
+    
+    @Test public void testCase4263() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        FakeMetadataFacade metadata = example1();
+        
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select vm1.g1.e1 from vm1.g1 left outer join (select * from vm1.g2 as v where v.e1 = (select max(vm1.g2.e1) from vm1.g2 where v.e1 = vm1.g2.e1)) f2 on (f2.e1 = vm1.g1.e1)", metadata,  //$NON-NLS-1$
+                                      null, capFinder,
+            new String[] { "SELECT g1__1.e1 FROM pm1.g1 AS g1__1 LEFT OUTER JOIN pm1.g1 AS g1__2 ON g1__2.e1 = g1__1.e1 AND g1__2.e1 = (SELECT MAX(pm1.g1.e1) FROM pm1.g1 WHERE pm1.g1.e1 = g1__2.e1)" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    @Test public void testCase4263b() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        FakeMetadataFacade metadata = example1();
+        
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select vm1.g1.e1 from vm1.g1 left outer join (select * from vm1.g2 as v where v.e1 = (select max(pm2.g1.e1) from pm2.g1 where v.e1 = pm2.g1.e1)) f2 on (f2.e1 = vm1.g1.e1)", metadata,  //$NON-NLS-1$
+                                      null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1", "SELECT g1__1.e1 FROM pm1.g1 AS g1__1" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testCase4279() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        FakeMetadataFacade metadata = example1();
+        
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select * from (select v1.e1, v2.e1 as e1_1, v1.e2, v2.e2 as e2_2 from (select * from vm1.g7 where vm1.g7.e2 = 1) v1 left outer join (select * from vm1.g7 where vm1.g7.e2 = 1) v2 on v1.e2 = v2.e2) as v3 where v3.e2 = 1", metadata,  //$NON-NLS-1$
+                                      null, capFinder,
+            new String[] { "SELECT CASE WHEN g_0.e1 = 'S' THEN 'Pay' WHEN g_0.e1 = 'P' THEN 'Rec' ELSE g_0.e1 END, CASE WHEN g_1.e1 = 'S' THEN 'Pay' WHEN g_1.e1 = 'P' THEN 'Rec' ELSE g_1.e1 END, g_0.e2, g_1.e2 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g1 AS g_1 ON g_0.e2 = g_1.e2 AND g_1.e2 = 1 WHERE g_0.e2 = 1" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    @Test public void testCase4312() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        helpPlan("select ? + 1, pm1.g1.e1 AS EXPR_1 FROM pm1.g1", example1(), null, capFinder, //$NON-NLS-1$
+                 new String[] {
+                     "SELECT (? + 1) AS expr, pm1.g1.e1 FROM pm1.g1"}, true); //$NON-NLS-1$
+
+    }    
+    
+    @Test public void testCase2507_2(){
+
+        String sql = "SELECT a FROM (SELECT concat(BQT1.SmallA.StringKey, BQT1.SmallA.StringNum) as a " +  //$NON-NLS-1$
+                     "FROM BQT1.SmallA, BQT1.SmallB WHERE SmallA.IntKey = SmallB.IntKey) as X ORDER BY X.a"; //$NON-NLS-1$
+
+        String expected = "SELECT concat(BQT1.SmallA.StringKey, BQT1.SmallA.StringNum) AS EXPR " +  //$NON-NLS-1$
+                     "FROM BQT1.SmallA, BQT1.SmallB WHERE BQT1.SmallA.IntKey = BQT1.SmallB.IntKey ORDER BY EXPR";  //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {expected},
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN);
+    } 
+    
+    private void helpTestCase2430and2507(String sql, String expected) {
+        
+        // TEST PLANNING
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);        
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);  
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,        
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {expected},  
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN);
+    }
+    
+    //Test use of OrderBy with Alias
+    @Test public void testCase2430D() {
+        String sql = "SELECT bqt1.smalla.longnum + bqt1.smalla.longnum as c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
+                     "bqt1.smalla.doublenum as EXPR FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890, EXPR "; //$NON-NLS-1$
+
+        String expected = "SELECT (bqt1.smalla.longnum + bqt1.smalla.longnum) AS c1234567890123456789012345678901234567890, bqt1.smalla.doublenum AS EXPR " + //$NON-NLS-1$
+                     "FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890, EXPR"; //$NON-NLS-1$
+        helpTestCase2430and2507(sql, expected);
+    }     
+
+    /*
+     * If expressionsymbol comparison would ignore expression names then this should just select a single column,
+     * but for now it will select 2.
+     */
+    @Test public void testCase2430E() {
+        String sql = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) as c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
+                     "CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) AS EXPR FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890, EXPR "; //$NON-NLS-1$
+
+        String expected = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) AS c1234567890123456789012345678901234567890, CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) " + //$NON-NLS-1$
+                     "FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
+        helpTestCase2430and2507(sql, expected);
+    }     
+    
+    @Test public void testCase2430G() {
+        String sql = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) as c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
+                     "CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) AS EXPR FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
+
+        String expected = "SELECT CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) AS c1234567890123456789012345678901234567890, CONCAT(bqt1.smalla.stringKey, bqt1.smalla.stringNum) " + //$NON-NLS-1$
+                     "FROM bqt1.smalla ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
+        helpTestCase2430and2507(sql, expected);
+    }  
+    
+    @Test public void testCase2507_1(){
+
+        String sql = "SELECT a FROM (SELECT concat(BQT1.SmallA.StringKey, BQT1.SmallA.StringNum) as a " +  //$NON-NLS-1$
+                     "FROM BQT1.SmallA) as X ORDER BY X.a"; //$NON-NLS-1$
+
+        String expected = "SELECT concat(BQT1.SmallA.StringKey, BQT1.SmallA.StringNum) AS EXPR FROM BQT1.SmallA ORDER BY EXPR";  //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
+                                      metadata,
+                                      null, capFinder,
+                                      new String[] {expected},
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, FULL_PUSHDOWN);        
+    }       
+    
+    /**
+     * This is taken from testPushCorrelatedSubquery1.  However this subquery is not expected to be pushed down since the correlated
+     * reference expression cannot be evaluated by the source.
+     */
+    @Test public void testDefect23614() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT intkey FROM bqt1.smalla AS n WHERE intkey = (SELECT MAX(intkey) FROM bqt1.smallb AS s WHERE s.stringkey = concat(n.stringkey, 'a') )", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT intkey, n.stringkey FROM bqt1.smalla AS n" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }   
+    
+    /**
+     * Normally the following queries would plan as if they were federated, but setting the connector_id source property
+     * allows them to be planned as if they were the same source. 
+     */
+    @Test public void testSameConnector() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setSourceProperty(Capability.CONNECTOR_ID, "1"); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(
+            "SELECT A.IntKey, B.IntKey FROM BQT1.SmallA A LEFT OUTER JOIN BQT2.MediumB B ON A.IntKey = B.IntKey",  //$NON-NLS-1$
+            metadata, null, capFinder,
+            new String[] { 
+              "SELECT A.IntKey, B.IntKey FROM BQT1.SmallA AS A LEFT OUTER JOIN BQT2.MediumB AS B ON A.IntKey = B.IntKey"},  //$NON-NLS-1$
+              true); 
+                
+        checkNodeTypes(plan, FULL_PUSHDOWN);
+        
+        plan = helpPlan(
+              "SELECT A.IntKey FROM BQT1.SmallA A UNION select B.intkey from BQT2.MediumB B",  //$NON-NLS-1$
+              metadata, null, capFinder,
+              new String[] { 
+                "SELECT A.IntKey FROM BQT1.SmallA AS A UNION SELECT B.intkey FROM BQT2.MediumB AS B"},  //$NON-NLS-1$
+                true); 
+                  
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+        
+    /**
+     * Test changes to RuleCollapseSource for removing aliases 
+     */
+    @Test public void testCase4898() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = helpPlan(
+              "SELECT 'a' as A FROM BQT1.SmallA A UNION select 'b' as B from BQT1.MediumB B",  //$NON-NLS-1$
+              metadata, null, capFinder,
+              new String[] { 
+                "SELECT 'a' AS A FROM BQT1.SmallA AS A UNION SELECT 'b' FROM BQT1.MediumB AS B"},  //$NON-NLS-1$
+                true); 
+                  
+        checkNodeTypes(plan, FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testDefect13971() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_DISTINCT, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        String sql = "select b from (select distinct booleanvalue b, intkey from bqt1.smalla) as x"; //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] {"SELECT DISTINCT booleanvalue, intkey FROM bqt1.smalla"}, SHOULD_SUCCEED); //$NON-NLS-1$
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Ensures that aliases are not stripped from projected symbols if they might conflict with an order by element
+     */
+    @Test public void testCase5067() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        String sql = "SELECT a.intkey as stringkey, b.stringkey as key2 from bqt1.smalla a, bqt1.smallb b where a.intkey = b.intkey order by stringkey"; //$NON-NLS-1$ 
+         
+        // Plan query 
+        ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] {"SELECT a.intkey AS stringkey, b.stringkey AS key2 FROM bqt1.smalla AS a, bqt1.smallb AS b WHERE a.intkey = b.intkey ORDER BY stringkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+ 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+        
+    @Test public void testDontPushConvertObject() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT intkey from bqt1.smalla WHERE stringkey = convert(objectvalue, string)",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT stringkey, objectvalue, intkey FROM bqt1.smalla"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testDontPushConvertClobToString() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("LOB", caps); //$NON-NLS-1$
+
+        // Add join capability to pm1
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+         
+        ProcessorPlan plan = helpPlan(
+            "SELECT ClobValue from LOB.LobTbl WHERE convert(ClobValue, string) = ?",  //$NON-NLS-1$
+            metadata,
+            null, capFinder,
+            new String[] {"SELECT ClobValue FROM LOB.LobTbl"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testSelectIntoWithDistinct() throws Exception {
+        String sql = "select distinct e1 into #temp from pm1.g1"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpPlan(sql, metadata, new String[] {"SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+        
+        checkNodeTypes(plan, new int[] {1}, new Class[] {ProjectIntoNode.class});
+    }
+    
+    /**
+     * previously the subqueries were being pushed too far and then not having the appropriate correlated references
+     */
+    @Test public void testCorrelatedSubqueryOverJoin() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_EXISTS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        String sql = "select pm1.g1.e1 from pm1.g1, (select * from pm1.g2) y where (pm1.g1.e1 = y.e1) and exists (select e2 from pm1.g2 where e1 = y.e1) and exists (select e3 from pm1.g2 where e1 = y.e1)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] {"SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 AS g2__1 WHERE (pm1.g1.e1 = g2__1.e1) AND (EXISTS (SELECT e2 FROM pm1.g2 WHERE e1 = g2__1.e1)) AND (EXISTS (SELECT e3 FROM pm1.g2 WHERE e1 = g2__1.e1))"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * see testSimpleCrossJoin3
+     */
+    @Test public void testMaxFromGroups() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setSourceProperty(Capability.MAX_QUERY_FROM_GROUPS, new Integer(1));
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        helpPlan("select pm2.g1.e1 FROM pm2.g1 CROSS JOIN pm2.g2", example1(), null, capFinder, //$NON-NLS-1$
+            new String[] { "SELECT pm2.g1.e1 FROM pm2.g1", "SELECT pm2.g2.e1 FROM pm2.g2"}, true ); //$NON-NLS-1$ //$NON-NLS-2$
+               
+    }
+    
+    @Test public void testCase6249() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FUNCTIONS_IN_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+        
+        String sql = "select count(*) from (select intkey from bqt1.smalla union all select intkey from bqt1.smallb) as a"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT COUNT(*) FROM (SELECT intkey FROM bqt1.smalla UNION ALL SELECT intkey FROM bqt1.smallb) AS a"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+        
+    @Test public void testCase6181() throws Exception {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FUNCTIONS_IN_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        String sql = "select a.e1 from (select 1 e1) a, (select e1, 1 as a, x from (select e1, CASE WHEN e1 = 'a' THEN e2 ELSE e3 END as x from pm1.g2) y group by e1, x) b where a.e1 = b.x"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, 
+                                      new String[] {"SELECT v_1.c_0 FROM (SELECT v_0.c_1 AS c_0 FROM (SELECT g_0.e1 AS c_0, CASE WHEN g_0.e1 = 'a' THEN g_0.e2 ELSE g_0.e3 END AS c_1 FROM pm1.g2 AS g_0 WHERE CASE WHEN g_0.e1 = 'a' THEN g_0.e2 ELSE g_0.e3 END IN (<dependent values>)) AS v_0 GROUP BY v_0.c_0, v_0.c_1) AS v_1 ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, new int[] {
+            0,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testCase6325() {
+        String sql = "select e1 into #temp from pm4.g1 where e1='1'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpPlan(sql, metadata, new String[] {"SELECT e1 FROM pm4.g1 WHERE e1 = '1'"}); //$NON-NLS-1$
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+        
+    @Test public void testCase6364() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_FUNCTIONS_IN_GROUP_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        String sql = "select * from (SELECT 1+ SUM(intnum) AS s FROM bqt1.smalla) a WHERE a.s>10"; //$NON-NLS-1$
+       
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT (1 + SUM(intnum)) FROM bqt1.smalla HAVING SUM(intnum) > 9"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+    
+    @Test public void testExceptPushdown() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_EXCEPT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        String sql = "select e1 from pm1.g1 except select e1 from pm1.g2"; //$NON-NLS-1$
+       
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT g_1.e1 AS c_0 FROM pm1.g1 AS g_1 EXCEPT SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }    
+   
+    @Test public void testCase6597() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_LIKE, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_NOT, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select IntKey from bqt1.smalla where stringkey not like '2%'"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                      new String[] {"SELECT stringkey, IntKey FROM bqt1.smalla"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+        
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testCopyCriteriaWithIsNull() {
+    	String sql = "select * from (select a.intnum, a.intkey y, b.intkey from bqt1.smalla a, bqt2.smalla b where a.intkey = b.intkey) x where intkey is null"; //$NON-NLS-1$
+    	
+    	helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), new String[] {});
+    }
+    
+    /**
+     * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down 
+     * query containing a <code>BETWEEN</code> comparison in the queries 
+     * <code>WHERE</code> statement.
+     * <p>
+     * For example:
+     * <p>
+     * SELECT * FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2
+     */
+    @Test public void testBetween() { 
+        helpPlan("select * from pm1.g1 where e2 between 1 and 2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+    			new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (e2 >= 1) AND (e2 <= 2)"} ); //$NON-NLS-1$
+    }
+
+    /**
+     * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down 
+     * query containing a <code>CASE</code> expression in which a 
+     * <code>BETWEEN</code> comparison is used in the queries 
+     * <code>SELECT</code> statement.
+     * <p>
+     * For example:
+     * <p>
+     * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
+     */
+    @Test public void testBetweenInCase() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        helpPlan("select case when e2 between 3 and 5 then e2 else -1 end from pm1.g1", //$NON-NLS-1$ 
+        		FakeMetadataFactory.example1Cached(), null, capFinder, 
+    			new String[] { "SELECT CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END FROM pm1.g1"},  //$NON-NLS-1$
+    			TestOptimizer.SHOULD_SUCCEED);
+    }
+
+    /**
+     * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down 
+     * query containing an aggregate SUM with a <code>CASE</code> expression 
+     * in which a <code>BETWEEN</code> comparison is used in the queries 
+     * <code>SELECT</code> statement.
+     * <p>
+     * For example:
+     * <p>
+     * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
+     */
+    @Test public void testBetweenInCaseInSum() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        helpPlan("select sum(case when e2 between 3 and 5 then e2 else -1 end) from pm1.g1", //$NON-NLS-1$ 
+        		FakeMetadataFactory.example1Cached(), null, capFinder, 
+    			new String[] { "SELECT SUM(CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END) FROM pm1.g1"},  //$NON-NLS-1$
+    			TestOptimizer.SHOULD_SUCCEED);
+    }
+
+    /**
+     * Test <code>QueryOptimizer</code>'s ability to plan a fully-pushed-down 
+     * query containing an aggregate SUM with a <code>CASE</code> expression 
+     * in which a <code>BETWEEN</code> comparison is used in the queries 
+     * <code>SELECT</code> statement and a GROUP BY is specified.
+     * <p>
+     * For example:
+     * <p>
+     * SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) 
+     * FROM pm1.g1 GROUP BY e1
+     */
+    @Test public void testBetweenInCaseInSumWithGroupBy() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        helpPlan("select sum(case when e2 between 3 and 5 then e2 else -1 end) from pm1.g1 group by e1", //$NON-NLS-1$ 
+        		FakeMetadataFactory.example1Cached(), null, capFinder, 
+    			new String[] { "SELECT SUM(CASE WHEN (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END) FROM pm1.g1 GROUP BY e1"},  //$NON-NLS-1$
+    			TestOptimizer.SHOULD_SUCCEED);
+    }
+
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query.
+     * <p>
+     * No source table is being used.  For example, <code>SELECT A.e2 FROM 
+     * (SELECT e2 FROM (SELECT 1 AS e2) AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasInSubQueryNoSource() {
+        // Create query
+    	String sql = "SELECT A.e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"	SELECT e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"		SELECT 5 AS e2" + //$NON-NLS-1$
+    	"	) AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+        helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {});
+    }
+         
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query
+     * and uses columns belonging to the alias as a parameter to a function.
+     * <p>
+     * No source table is being used.  For example, <code>SELECT CONVERT(A.e2, 
+     * biginteger) AS e2 FROM (SELECT CONVERT(e2, long) AS e2 FROM (SELECT 1 AS 
+     * e2) AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasFunctionInSubQueryNoSource() {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"	SELECT CONVERT(e2, long) AS e2 FROM (" + //$NON-NLS-1$
+    	"		SELECT 5 AS e2" + //$NON-NLS-1$
+    	"	) AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+    	helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {});
+    }
+
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query.
+     * <p>
+     * For example, <code>SELECT A.e2 FROM (SELECT e12FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasInSubQuerySource() {
+        // Create query
+    	String sql = "SELECT A.e2 AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT e2 AS e2 FROM pm1.g1 AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+        helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT e2 FROM pm1.g1 AS A"}); //$NON-NLS-1$
+    }
+         
+    /**
+     * Test the query optimizer's ability to properly plan and optimize a query 
+     * that uses ambiguous alias names in the top level query and its sub-query
+     * and uses columns belonging to the alias as a parameter to a function.
+     * <p>
+     * For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT 
+     * CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAmbiguousAliasFunctionInSubQuerySource() {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+
+    	FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+
+        helpPlan(sql, metadata, new String[] {"SELECT e2 FROM pm1.g1 AS A"}); //$NON-NLS-1$
+
+        // Add convert capability to pm1 and try it again
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        helpPlan(sql, metadata, null, capFinder,
+            new String[] {"SELECT CONVERT(CONVERT(e2, long), biginteger) FROM pm1.g1 AS A"}, //$NON-NLS-1$
+            SHOULD_SUCCEED );
+    }
+
+	public static final boolean DEBUG = false;
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptionalJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,503 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestOptionalJoins {
+    
+    @Test public void testOptionalJoinNode1() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode1_1() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1,pm2.g2.e1  FROM pm1.g1, /* optional */ pm2.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm2.g2.e1 FROM pm2.g2"} ); //$NON-NLS-1$//$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinNode2() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2, pm1.g3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g3 AS g_1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode3() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode3_1() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1, pm2.g2.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm2.g2 on pm1.g1.e1 = pm2.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinNode4() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode5() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g2 AS g_1 ON g_0.e1 = g_1.e1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode6() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g3 AS g_1 ON g_0.e1 = g_1.e1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode7() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g3.e1 FROM pm1.g3"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode8() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ (select * from pm1.g2) as X on pm1.g1.e1 = x.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode9() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g2.e1 FROM pm1.g2, /* optional */ vm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g2.e1 FROM pm1.g2"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode10() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM /* optional */ vm1.g1, pm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode11() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ vm1.g2 on pm1.g1.e1 = vm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode12() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN vm1.g1 on pm1.g1.e1 = vm1.g1.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g3.e1 FROM pm1.g3"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode13() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT count(pm1.g1.e1) FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    /**
+     * The distinct prevents the removal of the optional join 
+     */
+    @Test public void testOptionalJoinNode14() throws Exception { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT ve1 FROM vm1.g4", FakeMetadataFactory.example4(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0", "SELECT DISTINCT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinNode15() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinNode16() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1, (select distinct e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY y, z) AS x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT e2, e3 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinNode17() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT e3 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinWithIntersection() throws Exception { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3 inner join (select pm1.g1.e2 as y from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1) AS x on pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e1 FROM pm1.g3 AS g_0, pm1.g1 AS g_1, pm1.g2 AS g_2 WHERE (g_1.e1 = g_2.e1) AND (g_0.e2 = g_1.e2)"}, ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ 
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);    
+    }
+    
+    @Test public void testOptionalJoinWithNestedOrderBy() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3 inner join (select pm1.g2.e1, pm1.g1.e2 as y from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1 order by pm1.g2.e1 limit 10000) AS x on pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g3 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1 ORDER BY g_1.e1"} ); //$NON-NLS-1$ //$NON-NLS-2$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+
+    /**
+     * Grouping will prevent the removal from happening 
+     */
+    @Test public void testOptionalJoinWithGroupingOverAllColumns() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3, (select max(pm1.g1.e4) y from /* optional */ pm1.g1, pm1.g2 where pm1.g1.e1 = pm1.g2.e1) AS x where pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT g_0.e2, g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e4 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1"} ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            3,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    /**
+     * Union should prevent the removal from happening 
+     */
+    @Test public void testOptionalJoinWithUnion() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g2.e4 from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1 union all select convert(pm1.g2.e2, double) from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT pm1.g2.e4 FROM pm1.g2", "SELECT pm1.g2.e2 FROM pm1.g2"} ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinWithCompoundCriteria() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y and concat(x.y, x.z) = '1'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT e3 FROM pm1.g1"} ); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            0,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    @Test public void testOptionalJoinWithDupRemoval() { 
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT a.e1 from (SELECT distinct pm1.g1.e1, x.y FROM pm1.g1, /* optional */ (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x where pm1.g1.e2=x.y) as a", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] {"SELECT DISTINCT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT DISTINCT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // Join
+            1,      // MergeJoin
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });    
+    }
+    
+    /**
+     * Cross Joins do not allow for join removal
+     * This could be optimized though as an exists predicate
+     */
+    @Test public void testOptionalJoinWithoutHint_crossJoin() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"SELECT distinct pm1.g1.e1 from pm1.g1, pm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+	}
+    
+    @Test public void testOptionalJoinWithoutHint_outerJoin() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"SELECT distinct pm1.g1.e2 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT DISTINCT g_0.e2 FROM pm1.g1 AS g_0" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+	}
+    
+    @Test public void testOptionalJoinWithoutHint_aggregate() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"SELECT pm1.g1.e3, max(pm1.g1.e2) from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) group by pm1.g1.e3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, new int[] { 
+				1, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				1, // Grouping
+				0, // Join
+				0, // MergeJoin
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+				});
+	}
+    
+    /**
+     * The average agg will prevent the join removal
+     */
+    @Test public void testOptionalJoinWithoutHint_aggregate1() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"SELECT pm1.g1.e3, avg(pm1.g1.e2) from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) group by pm1.g1.e3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT g_0.e3, g_0.e2 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g2 AS g_1 ON g_0.e1 = g_1.e1" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, new int[] { 
+				1, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				0, // DupRemove
+				1, // Grouping
+				0, // Join
+				0, // MergeJoin
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0 // UnionAll
+				});
+	}
+    
+    @Test public void testOptionalJoinWithoutHint_union() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"SELECT pm1.g1.e3 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) union select 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT g_0.e3 FROM pm1.g1 AS g_0" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, new int[] { 
+				1, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				1, // DupRemove
+				0, // Grouping
+				0, // Join
+				0, // MergeJoin
+				0, // Null
+				0, // PlanExecution
+				2, // Project
+				0, // Select
+				0, // Sort
+				1 // UnionAll
+				});
+	}
+    
+    @Test public void testOptionalJoinWithOrderedLimit() {
+		ProcessorPlan plan = TestOptimizer
+				.helpPlan(
+						"select distinct * from (SELECT pm1.g1.e3 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) order by e3 limit 10) x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+						new String[] { "SELECT g_0.e3 AS c_0 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g2 AS g_1 ON g_0.e1 = g_1.e1 ORDER BY c_0" }); //$NON-NLS-1$
+
+		TestOptimizer.checkNodeTypes(plan, new int[] { 
+				1, // Access
+				0, // DependentAccess
+				0, // DependentSelect
+				0, // DependentProject
+				1, // DupRemove
+				0, // Grouping
+				0, // Join
+				0, // MergeJoin
+				0, // Null
+				0, // PlanExecution
+				1, // Project
+				0, // Select
+				0, // Sort
+				0  // UnionAll
+				});
+	}
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestPartitionedJoinPlanning.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2009 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor 
+ * license agreements.  See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ * 
+ * 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 org.teiid.query.optimizer;
+
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import org.junit.Test;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.PartitionedSortJoin;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+
+
+public class TestPartitionedJoinPlanning {
+	
+    @Test public void testUsePartitionedMergeJoin(){
+        // Create query
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1";//$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 100);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm1.g2", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE * 16);
+    
+        ProcessorPlan plan = helpPlan(sql, metadata,  
+            null, capFinder,
+            new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm1.g2.e1 FROM pm1.g2" }, SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });  
+        checkNodeTypes(plan, new int[] {1}, new Class[] {PartitionedSortJoin.class});
+    }    
+
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestPartitionedJoinPlanning.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleMergeVirtual.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleMergeVirtual.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,321 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static junit.framework.Assert.*;
+
+import org.junit.Test;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.processor.relational.SortNode;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestRuleMergeVirtual {
+    
+    @Test public void testSimpleMergeGroupBy() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT MAX(e2) AS x FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy1() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT distinct e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT v_0.c_1 FROM (SELECT DISTINCT g_0.e1 AS c_0, MAX(g_0.e2) AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e1) AS v_0"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+
+    /**
+     * Same as above but all required symbols are selected
+     */
+    @Test public void testSimpleMergeGroupBy2() {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x, e1 FROM (SELECT distinct e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      metadata, null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT DISTINCT MAX(e2) AS x, e1 FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy3() {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      metadata, null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT DISTINCT MAX(e2) AS x, e1 FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy4() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x, x FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT v_0.c_0, v_0.c_0 FROM (SELECT MAX(g_0.e2) AS c_0 FROM pm1.g1 AS g_0 GROUP BY g_0.e1) AS v_0"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy5() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z where z.x = 1", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT MAX(e2) AS x FROM pm1.g1 GROUP BY e1 HAVING MAX(e2) = 1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy6() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z where z.x = 1", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT MAX(e2) AS x FROM pm1.g1 GROUP BY e1 HAVING MAX(e2) = 1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeGroupBy7() {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x, e1 FROM (SELECT distinct e1, max(e2) as x FROM pm1.g1 GROUP BY e1) AS z", //$NON-NLS-1$
+                                      metadata, null, TestAggregatePushdown.getAggregatesFinder(),
+                                      new String[] {
+                                          "SELECT DISTINCT MAX(e2) AS x, e1 FROM pm1.g1 GROUP BY e1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeUnion() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (select '1' as x, e2 from pm1.g1 union all select e1, 1 from pm1.g2) x", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                          "SELECT '1' AS x FROM pm1.g1 UNION ALL SELECT e1 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeUnion1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x FROM (select '1' as x, e2 from pm1.g1 union all select e1, 1 from pm1.g2) x", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                          "SELECT '1' AS x FROM pm1.g1 UNION SELECT e1 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }  
+    
+    /**
+     * Same as above, but the expression will prevent the source removal
+     */
+    @Test public void testSimpleMergeUnion2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT distinct x || 'b' FROM (select '1' as x, e2 from pm1.g1 union all select e1, 1 from pm1.g2) x", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                          "SELECT '1' AS x FROM pm1.g1 UNION ALL SELECT e1 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testSimpleMergeUnion3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * from (SELECT distinct x FROM (select '1' as x, e2 from pm1.g1 union all select e1, 1 from pm1.g2) x) y, pm1.g2", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                          "SELECT '1' AS x FROM pm1.g1 UNION SELECT e1 FROM pm1.g2", "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+    
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            1,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    @Test public void testSimpleMergeWithLimit() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * from (select e1 from pm1.g1 limit 1) x", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                          "SELECT e1 FROM pm1.g1 LIMIT 1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    @Test public void testSimpleMergeWithLimit1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+         
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * from (select e1 from pm1.g1 limit 1) x order by e1", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, capFinder,
+                                      new String[] {
+                                        "SELECT e1 FROM pm1.g1 LIMIT 1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // Limit
+            0,      // NestedLoopJoinStrategy
+            
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        }, TestLimit.NODE_TYPES);                                    
+    }
+    
+    /**
+     * Note that the merge is not performed since it would create an expression in the group by clause
+     */
+    @Test public void testViewPreservationWithGroupByExpression() throws Exception {
+        String sql = "SELECT gbl_date " + //$NON-NLS-1$
+            "FROM " + //$NON-NLS-1$
+            "(SELECT a.intkey as x, convert(a.TimestampValue, date) AS gbl_date, b.intkey as y " + //$NON-NLS-1$
+            "FROM bqt1.smalla a INNER JOIN bqt1.smallb b on a.stringkey=b.stringkey) as z " + //$NON-NLS-1$
+            "GROUP BY gbl_date"; //$NON-NLS-1$
+
+        // Create capabilities
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, 
+            null, capFinder,
+            new String[] { "SELECT v_0.c_0 FROM (SELECT convert(g_0.TimestampValue, date) AS c_0 FROM bqt1.smalla AS g_0, bqt1.smallb AS g_1 WHERE g_0.stringkey = g_1.stringkey) AS v_0 GROUP BY v_0.c_0" },  //$NON-NLS-1$
+            TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);         
+    } 
+    
+    @Test public void testSortAliasWithSameName() throws Exception { 
+        String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x order by e1"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+        		new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  
+        
+        SortNode node = (SortNode)plan.getRootNode();
+        assertTrue("Alias was not accounted for in sort node", node.getElements().containsAll(node.getSortElements())); //$NON-NLS-1$
+    }
+    
+    @Test public void testMergeImplicitGroupBy() throws Exception {
+    	BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
+    	caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x FROM (SELECT min(y), max(x) as x FROM (select e1 x, e2 + 1 y from pm1.g1) a) AS b", //$NON-NLS-1$
+                                      FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(caps),
+                                      new String[] {
+                                          "SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleRaiseNull.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRaiseNull.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,359 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import java.util.Arrays;
+
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+import junit.framework.TestCase;
+
+
+
+public class TestRuleRaiseNull extends TestCase {
+    
+    public static final int[] FULLY_NULL = new int[] {
+                0,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                1,      // Null
+                0,      // PlanExecution
+                0,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            };
+
+    /**
+     * Test that criteria will cause a branch of a union to be excised if the criteria renders it
+     * impossible that the branch of the union would return results.  In the following test, 
+     * each branch of the union projects a "null" in a different column.  So, an equality criteria on
+     * one of those columns should render one of the branches of the union unnecessary (since null
+     * never equals anything).  Expected behavior is that a NullNode is inserted in place of the
+     * unnecessary access node. 
+     */
+    public void testUnionCriteriaOptimization() {
+
+        String sql = "select * from ( select intkey as cola, null as colb, intnum as colc from bqt1.smalla union all select null, intkey, intnum from bqt2.smalla) as X where X.cola = 1";  //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),
+                                      new String[] {"SELECT intkey, null, intnum FROM bqt1.smalla WHERE intkey = 1"} ); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);          
+        
+    }
+    
+    public void testRaiseNullWithInnerJoin() {
+        String sql = "select b.intkey from (select intkey from bqt1.smalla where 1 = 0) a inner join (select intkey from bqt1.smallb) b on (a.intkey = b.intkey)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{});
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL);
+    }
+    
+    public void testRaiseNullWithFullOuterJoin() {
+        String sql = "select b.intkey from (select intkey from bqt1.smalla) a full outer join (select intkey from bqt1.smallb where 1 = 0) b on (a.intkey = b.intkey)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT null FROM bqt1.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithOuterJoin() {
+        String sql = "select b.intkey from (select intkey from bqt1.smalla) a left outer join (select intkey from bqt1.smallb where 1 = 0) b on (a.intkey = b.intkey)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT null FROM bqt1.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithOuterJoin1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "select smallb.intkey, smalla.intkey from bqt1.smalla left outer join bqt1.smallb on (1 = 2)"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder,  
+                                                    new String[]{"SELECT null, bqt1.smalla.intkey FROM bqt1.smalla"}, true); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithUnion() {
+        String sql = "select b.x from (select intkey as x from bqt1.smalla where 1 = 0 union all select intnum as y from bqt1.smalla) b"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT IntNum FROM bqt1.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+        
+        assertEquals(Arrays.asList(new Object[] {new ElementSymbol("b.x")}), plan.getOutputElements()); //$NON-NLS-1$
+    }    
+
+    public void testRaiseNullWithUnion1() {
+        String sql = "select b.intkey from (select intkey from bqt1.smalla union all select intnum from bqt1.smalla where 1 = 0) b"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT intkey FROM bqt1.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }    
+    
+    public void testRaiseNullWithUnion2() {
+        String sql = "select b.intkey, b.x from (select intkey, intnum as x from bqt1.smalla where 1 = 0 union all select intnum as a, null from bqt1.smalla union all select 1 as z, intkey as b from bqt1.smallb) b"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT 1, intkey FROM bqt1.smallb", "SELECT IntNum, null FROM bqt1.smalla"}); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });
+    }    
+    
+    public void testRaiseNullWithUnion3() {
+        String sql = "select intkey, intnum as x from bqt1.smalla where 1 = 0 union all select intnum, intkey as z from bqt1.smalla where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{});
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL);
+    } 
+
+    public void testRaiseNullWithUnion4() throws Exception {
+        String sql = "select b.intkey, b.x from (select intkey, intnum as x from bqt1.smalla where 1 = 0 union all select 1 as z, intkey as b from bqt1.smallb) b inner join bqt1.smalla on b.intkey = bqt1.smalla.intkey"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT 1, g_0.intkey FROM bqt1.smallb AS g_0, bqt1.smalla AS g_1 WHERE g_1.IntKey = 1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithUnion5() {
+        String sql = "select intkey from bqt1.smalla union all select intkey from bqt2.smalla where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT intkey FROM bqt1.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithUnion6() {
+        String sql = "select intkey from bqt1.smalla union all select intkey from bqt2.smalla union all select intkey from bqt2.smalla where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT intkey FROM bqt1.smalla", "SELECT intkey FROM bqt2.smalla"}); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });
+    }
+    
+    public void testPushCriteriaThroughUnion9() {
+        TestOptimizer.helpPlan("select * from vm1.u8 where const = 's1'", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT 's1', e1 FROM pm1.g1" } );     //$NON-NLS-1$
+    }
+
+    public void testPushCriteriaThroughUnion10() {
+        TestOptimizer.helpPlan("select * from vm1.u8 where const = 's3'", TestOptimizer.example1(), //$NON-NLS-1$
+            new String[] { "SELECT 's3', e1 FROM pm1.g3" } );     //$NON-NLS-1$
+    }
+    
+    public void testRaiseNullWithOuterJoinAndHaving() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "select smallb.intkey, smalla.intkey from bqt1.smalla left outer join bqt1.smallb on (1 = 2) group by smalla.intkey, smallb.intkey having max(smallb.intkey) = 1"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder,  
+                                                    new String[]{"SELECT bqt1.smalla.intkey FROM bqt1.smalla"}, true); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Ensures proper handling of the removal of the first branch and
+     * duplicate symbol names in the next branch
+     */
+    public void testRaiseNullWithUnion7() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "select max(intkey), intnum from (select intkey, intnum from bqt2.smalla where 1 = 0 union all select intnum, intnum from bqt2.smalla union all select intkey, stringkey from bqt2.smalla) x group by intnum"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[]{"SELECT MAX(v_0.c_1), v_0.c_0 FROM (SELECT g_1.IntNum AS c_0, g_1.IntNum AS c_1 FROM bqt2.smalla AS g_1 UNION ALL SELECT g_0.StringKey AS c_0, g_0.IntKey AS c_1 FROM bqt2.smalla AS g_0) AS v_0 GROUP BY v_0.c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithUnionOrderBy() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "select intkey from bqt1.smalla where 1 = 0 union all select intnum from bqt2.smalla order by intkey"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, null, capFinder, 
+                                                    new String[]{"SELECT intnum AS intkey FROM bqt2.smalla ORDER BY intkey"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithGroupBy() {
+        String sql = "select max(e2), e1 from pm1.g1 where 1 = 0 group by e1"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[]{});
+
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL);
+    }
+
+    public void testRaiseNullWithGroupBy1() {
+        String sql = "select max(e2) from pm1.g1 where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[]{});
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            0,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            1,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            1,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    public void testRaiseNullWithExcept() {
+        String sql = "select e1 from pm1.g1 except select e2 from pm1.g2 where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[]{"SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+
+    public void testRaiseNullWithIntersect() {
+        String sql = "select max(e2) from pm1.g1 intersect select e2 from pm1.g2 where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[]{});
+
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL);
+    }
+    
+    /**
+     * This tests that a criteria with no elements is not pushed down,
+     * but instead is cleaned up properly later
+     * See defect 9865
+     */
+    public void testCrossJoinNoElementCriteriaOptimization() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select Y.e1, Y.e2 FROM vm1.g1 X, vm1.g1 Y where {b'true'} = {b'false'}", TestOptimizer.example1(),  //$NON-NLS-1$
+            new String[0]);
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL); 
+    }
+    
+    public void testSelectLiteralFalseCriteria() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("Select 'x' from pm1.g1 where 1=0", TestOptimizer.example1(),  //$NON-NLS-1$
+            new String[] { });
+        TestOptimizer.checkNodeTypes(plan, FULLY_NULL); 
+    }
+    
+    public void testRaiseNullWithUnionNotAll() {
+        String sql = "select intkey from bqt2.smalla union select intkey from bqt2.smalla where 1 = 0"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),  
+                                                    new String[]{"SELECT DISTINCT intkey FROM bqt2.smalla"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+    public void testRaiseNullWithUnionAndAliases() {
+        String sql = "select pm1.g1.e1 from pm1.g1, (select e1 from pm1.g1 where (1 = 0) union all select e1 as x from pm1.g2) x where pm1.g1.e1 <> x.e1"; //$NON-NLS-1$
+        
+        RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),  
+                                                    new String[]{"SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 <> g_1.e1"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestRuleRemoveSorts.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestRuleRemoveSorts.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,125 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+import junit.framework.TestCase;
+
+
+public class TestRuleRemoveSorts extends TestCase {
+    
+    /** Tests an order by in a query transformation */
+    public void testRemovedOrderByFromQueryTransform() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT e1, e2 FROM vm1.g14", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT pm3.g1.e1, pm3.g1.e2 FROM pm3.g1"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+    
+    /** 
+     * Tests an order by in a query transformation, where the
+     * physical model does not support pushing order bys
+     */
+    public void testRemovedOrderByFromQueryTransform2() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT e, e2 FROM vm1.g8", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }    
+
+    /** 
+     * Tests an order by in a query transformation, where the
+     * query transformation contains a function 
+     */
+    public void testRemovedOrderByFromQueryTransform3() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT e, e2 FROM vm1.g16", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm3.g1"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    }
+    
+    /** Tests an order by in a query transformation */
+    public void testRemovedOrderByFromQueryTransform4() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT e1, e2 FROM vm1.g13", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT DISTINCT pm3.g1.e1, pm3.g1.e2, pm3.g1.e3, pm3.g1.e4 FROM pm3.g1"}); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });                                    
+    } 
+    
+    /** Order by is not removed */
+    public void testOrderByWithLimit() throws Exception {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select * from (SELECT e1, e2 FROM pm1.g1 order by e1 limit 10) x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);                                    
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSortOptimization.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,171 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestSortOptimization {
+
+    @Test public void testSortDupCombination() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select distinct e1, e2 from pm1.g1 order by e2"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT e1, e2 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
+        
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+        checkNodeTypes(plan, new int[] {1}, new Class[] {DupRemoveSortNode.class});
+    }
+    
+    @Test public void testSortDupCombination1() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select e1, e2 from pm1.g1 union select e1, e2 from pm1.g2 order by e2"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT e1, e2 FROM pm1.g1", "SELECT e1, e2 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        checkNodeTypes(plan, new int[] {
+                2,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                0,      // Project
+                0,      // Select
+                0,      // Sort
+                1       // UnionAll
+            });
+        checkNodeTypes(plan, new int[] {1}, new Class[] {DupRemoveSortNode.class});
+    }
+	
+    @Test public void testSortDupCombination2() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select x.*, y.* from (select distinct e1, e2 from pm1.g1) x, (select distinct e1, e2 from pm1.g2) y where x.e1 = y.e1"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT e1, e2 FROM pm1.g1", "SELECT e1, e2 FROM pm1.g2"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        checkNodeTypes(plan, new int[] {
+                2,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                1,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+        checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+    }
+    
+    @Test public void testGroupDupCombination() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select max(e1), e2 from (select distinct e1, e2 from pm1.g1) x group by e2"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                1,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+        checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+    }
+
+    @Test public void testSortGroupCombination() { 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Create query 
+        String sql = "select max(e1), e2 from pm1.g1 x group by e2 order by e2"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, 
+                                      new String[] {"SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ 
+        
+        checkNodeTypes(plan, new int[] {
+                1,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                1,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+        checkNodeTypes(plan, new int[] {0}, new Class[] {DupRemoveSortNode.class});
+    }
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,415 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestStoredProcedurePlanning {
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 1a
+     */
+	@Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery1() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq1()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries
+     */
+	@Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery2() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq1()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 1b
+     */
+	@Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery3() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq2('1')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+	@Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery4() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select x.e1 from (EXEC pm1.sq1()) as x", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+
+    @Test public void testStoredQuery5() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sp1()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp1()" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Test public void testStoredQuery6() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select x.e1 from (EXEC pm1.sp1()) as x", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp1()" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery7() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sqsp1()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp1()" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 1c
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery8() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq3('1', 1)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'", "SELECT e1, e2 FROM pm1.g1 WHERE e2 = 1" }); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 5a
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery9() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq4()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] {"SELECT e1, e2 FROM pm1.g1" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 5b
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery10() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq5('1')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'"}); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+     /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 5c
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery11() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq6()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] {"SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+     /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 6a
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery12() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq7()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 6c
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery13() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq8('1')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 = '1'" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 6b
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery14() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq9('1')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE e1 = '1'" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 6d
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery15() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq10('1', 2)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1 WHERE (e1 = '1') AND (e2 = 2)" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    /**
+     * Test planning stored queries. 
+     */
+    @Test public void testStoredQuery16() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sp2(1)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp2(1)" }); //$NON-NLS-1$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Test planning stored queries. GeminiStoredQueryTestPlan - 6d
+     */
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery17() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq11(1, 2)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp2(?)" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    //GeminiStoredQueryTestPlan - 2a, 2b
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery18() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq12('1', 1)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "INSERT INTO pm1.g1 (e1, e2) VALUES ('1', 1)" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    //GeminiStoredQueryTestPlan - 2c
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery19() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq13('1')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "INSERT INTO pm1.g1 (e1, e2) VALUES ('1', 2)" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    //GeminiStoredQueryTestPlan - 3c
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery20() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq14('1', 2)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "UPDATE pm1.g1 SET e1 = '1' WHERE e2 = 2" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN); 
+    }
+    
+    //GeminiStoredQueryTestPlan - 4b
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery21() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq15('1', 2)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "DELETE FROM pm1.g1 WHERE (e1 = '1') AND (e2 = 2)" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);               
+    }
+    
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery22() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("select e1 from (EXEC pm1.sq1()) as x where e1='a' union (select e1 from vm1.g2 where e1='b')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'b') AND (g_1.e1 = 'b')" }); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });               
+    }
+    
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery23() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq16()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "INSERT INTO pm1.g1 (e1, e2) VALUES ('1', 2)" }); //$NON-NLS-1$
+            
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);               
+    }
+    
+    @Test public void testStoredQuery24() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sp3()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp3()" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);               
+    }
+
+    // test implicit type conversion of argument
+    @Ignore("stored procedure wrapper removal logic has been removed")
+    @Test public void testStoredQuery25() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sq15(1, 2)", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "DELETE FROM pm1.g1 WHERE (e1 = '1') AND (e2 = 2)" }); //$NON-NLS-1$
+
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+    }
+
+    @Test public void testStoredQueryXML1() {
+        TestOptimizer.helpPlan("EXEC pm1.sq18()", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), new String[] { }); //$NON-NLS-1$
+    }
+    
+    /**
+     * union of two stored procs - case #1466
+     */
+    @Test public void testStoredProc1() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT * FROM (EXEC pm1.sp2(1)) AS x UNION ALL SELECT * FROM (EXEC pm1.sp2(2)) AS y", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp2(1)", "EXEC pm1.sp2(2)" }); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            4,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }
+
+    /**
+     * union of stored proc and query - case #1466
+     */
+    @Test public void testStoredProc2() {
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT * FROM (EXEC pm1.sp2(1)) AS x UNION ALL SELECT e1, e2 FROM pm1.g1", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
+            new String[] { "EXEC pm1.sp2(1)", "SELECT e1, e2 FROM pm1.g1" }); //$NON-NLS-1$ //$NON-NLS-2$
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            2,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }); 
+    }    
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestSubqueryPushdown.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,715 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.resource.cci.SourceSystemFunctions;
+
+
+public class TestSubqueryPushdown {
+
+	@Test public void testPushSubqueryBelowVirtual() throws Exception {
+		String sql = "select g3.e1 from (select e1, max(e2) y from pm1.g1 group by e1) x, pm1.g3 where exists (select e1 from pm1.g2 where x.e1 = e1)"; //$NON-NLS-1$
+
+	    // Create capabilities
+	    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+	    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+	    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+	    caps.setCapabilitySupport(Capability.CRITERIA_EXISTS, true);
+	    capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+	    
+	    FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+	
+	    // Plan query
+	    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, 
+	        null, capFinder,
+	        new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE EXISTS (SELECT g_1.e1 FROM pm1.g2 AS g_1 WHERE g_1.e1 = g_0.e1)", //$NON-NLS-1$
+	    		"SELECT g_0.e1 FROM pm1.g3 AS g_0" },  //$NON-NLS-1$
+	        TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                2,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                1,      // Grouping
+                1,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                2,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+	}
+	
+	/**
+	 * Same as above, but using a correlated variable based on an aggregate
+	 * @throws Exception
+	 */
+	@Test public void testDontPushSubqueryBelowVirtual() throws Exception {
+		String sql = "select g3.e1 from (select e1, max(e2) y from pm1.g1 group by e1) x, pm1.g3 where exists (select e1 from pm1.g2 where x.y = e1)"; //$NON-NLS-1$
+
+	    // Create capabilities
+	    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+	    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+	    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+	    caps.setCapabilitySupport(Capability.CRITERIA_EXISTS, true);
+	    capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+	    
+	    FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+	
+	    // Plan query
+	    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, 
+	        null, capFinder,
+	        new String[] { "SELECT g_0.e1 FROM pm1.g3 AS g_0", //$NON-NLS-1$
+	    		"SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0" },  //$NON-NLS-1$
+	        TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                2,      // Access
+                0,      // DependentAccess
+                1,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                1,      // Grouping
+                1,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                2,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+	}
+	
+	@Test public void testPushCorrelatedSubquery1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT intkey FROM bqt1.smalla AS n WHERE intkey = (SELECT MAX(intkey) FROM bqt1.smallb AS s WHERE s.stringkey = n.stringkey )", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT intkey FROM bqt1.smalla AS n WHERE intkey = (SELECT MAX(intkey) FROM bqt1.smallb AS s WHERE s.stringkey = n.stringkey)" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    @Test public void testPushCorrelatedSubquery2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_LIKE, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setFunctionSupport(SourceSystemFunctions.CONCAT, true);
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sqlIn = 
+            "SELECT c37n.intkey " + //$NON-NLS-1$
+            "FROM bqt1.mediuma AS c37n, bqt1.smallb AS m37n " + //$NON-NLS-1$
+            "WHERE (m37n.stringkey LIKE '%0') AND " + //$NON-NLS-1$
+            "(c37n.stringkey = ('1' || (m37n.intkey || '0'))) AND " + //$NON-NLS-1$
+            "(c37n.datevalue = (" + //$NON-NLS-1$
+            "SELECT MAX(c37s.datevalue) " + //$NON-NLS-1$
+            "FROM bqt1.mediuma AS c37s, bqt1.smallb AS m37s " + //$NON-NLS-1$
+            "WHERE (m37s.stringkey LIKE '%0') AND " + //$NON-NLS-1$
+            "(c37s.stringkey = ('1' || (m37s.intkey || '0'))) AND " + //$NON-NLS-1$
+            "(m37s.stringkey = m37n.stringkey) ))"; //$NON-NLS-1$
+
+        String sqlOut = "SELECT g_0.intkey FROM bqt1.mediuma AS g_0, bqt1.smallb AS g_1 WHERE (g_0.stringkey = concat('1', concat(g_1.intkey, '0'))) AND (g_0.datevalue = (SELECT MAX(g_2.datevalue) FROM bqt1.mediuma AS g_2, bqt1.smallb AS g_3 WHERE (g_2.stringkey = concat('1', concat(g_3.intkey, '0'))) AND (g_3.stringkey LIKE '%0') AND (g_3.stringkey = g_1.stringkey))) AND (g_1.stringkey LIKE '%0')"; //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan(sqlIn, FakeMetadataFactory.exampleBQTCached(),  
+            null, capFinder,
+            new String[] { sqlOut }, SHOULD_SUCCEED); 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }   
+
+    @Test public void testPushCorrelatedSubquery3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_LIKE, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sqlIn = 
+            "SELECT intkey " + //$NON-NLS-1$
+            "FROM vqt.smalla AS e " + //$NON-NLS-1$
+            "WHERE (stringkey = 'VOD.L') AND " + //$NON-NLS-1$
+            "(datevalue = (" + //$NON-NLS-1$
+            "SELECT MAX(datevalue) " + //$NON-NLS-1$
+            "FROM vqt.smalla " + //$NON-NLS-1$
+            "WHERE (stringkey = e.stringkey) ))"; //$NON-NLS-1$
+
+        String sqlOut = 
+            "SELECT SmallA__1.IntKey FROM BQT1.SmallA AS SmallA__1 WHERE (SmallA__1.StringKey = 'VOD.L') AND (SmallA__1.DateValue = (SELECT MAX(BQT1.SmallA.DateValue) FROM BQT1.SmallA WHERE BQT1.SmallA.StringKey = SmallA__1.StringKey))"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan(sqlIn, FakeMetadataFactory.exampleBQTCached(),  
+            null, capFinder,
+            new String[] { sqlOut }, SHOULD_SUCCEED); 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }  
+
+    /**
+     * Check that scalar subquery in select is pushed 
+     */
+    public void DEFER_testPushSubqueryInSelectClause1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT stringkey, (SELECT intkey FROM BQT1.SmallA AS b WHERE Intnum = 22) FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT stringkey, (SELECT intkey FROM BQT1.SmallA AS b WHERE Intnum = 22) FROM BQT1.SmallA" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }   
+    
+    @Test public void testCorrelatedSubquery1() {
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select e1 FROM pm2.g1 WHERE pm1.g1.e2 = pm2.g1.e2)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1, pm1.g1.e2 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCorrelatedSubquery2() {
+        ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 WHERE pm1.g1.e2 = pm2.g1.e2) from pm1.g1", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1, pm1.g1.e2 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer1() {
+        ProcessorPlan plan = helpPlan("Select e1 from vm1.g6 where e1 in (select e1 FROM pm2.g1 WHERE vm1.g6.e3 = pm2.g1.e2)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer2() {
+        ProcessorPlan plan = helpPlan("Select e1 from vm1.g6 where e1 in (select e1 FROM pm2.g1 WHERE vm1.g6.e4 = pm2.g1.e4)", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1, e2, e4 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer3() {
+        ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 WHERE vm1.g6.e4 = pm2.g1.e4) from vm1.g6", example1(),  //$NON-NLS-1$
+            new String[] { "SELECT e1, e2, e4 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            1,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    @Test public void testCorrelatedSubqueryInTransformation2() {
+        String sql = "Select * from vm1.g20"; //$NON-NLS-1$
+        ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+            new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" }); //$NON-NLS-1$
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });         
+    }
+    
+    /**
+     * Check that subquery is not pushed if the subquery cannot all be pushed to the source.
+     */
+    @Test public void testNoPushSubqueryInWhereClause1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select max(e1) FROM pm1.g2)", example1(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Check that subquery is not pushed if the subquery is from a different model
+     * than the outer query.
+     */
+    @Test public void testNoPushSubqueryInWhereClause2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", getTypicalCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select e1 FROM pm2.g1)", example1(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Do not support XML query as subquery
+     * Check that subquery is not pushed if the subquery is not relational.
+     */
+    public void defer_testNoPushSubqueryInWhereClause3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (select * from xmltest.doc1)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Check that subquery is not pushed if the subquery has a function that can't be pushed 
+     * in the SELECT clause
+     */
+    @Test public void testNoPushSubqueryInWhereClause4() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT ltrim(e1) FROM pm1.g2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Check that subquery is not pushed if the subquery selects a constant value
+     */
+    @Test public void testNoPushSubqueryInWhereClause5() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT 'xyz' FROM pm1.g2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Check that subquery is not pushed if the subquery does ORDER BY
+     */
+    @Test public void testNoPushSubqueryInWhereClause6() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT e1 FROM pm1.g2 ORDER BY e1 limit 2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+    
+    /**
+     * Check that subquery is not pushed if the subquery has a function that can't be pushed 
+     * in the SELECT clause
+     */
+    @Test public void testNoPushSubqueryInWhereClause7() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setFunctionSupport("ltrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT rtrim(ltrim(e1)) FROM pm1.g2)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Check that subquery is not pushed if the subquery holds non-query access node.
+     */
+    @Test public void testNoPushSubqueryInWhereClause8() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (EXEC pm1.sqsp1())", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }
+
+    /**
+     * Check that subquery is not pushed if the subquery is correlated and correlated not supported
+     */
+    @Test public void testNoPushSubqueryInWhereClause9() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 in (SELECT pm1.g2.e1 FROM pm1.g2 WHERE pm1.g2.e1 = pm1.g1.e1)", FakeMetadataFactory.example1Cached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT e1 FROM pm1.g1" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            1,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        }); 
+    }       
+    
+	@Test public void testPushMultipleCorrelatedSubquery1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_OR, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_SOME, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        ProcessorPlan plan = helpPlan("SELECT intkey FROM bqt1.smalla AS n WHERE intkey = (SELECT MAX(intkey) FROM bqt1.smallb AS s WHERE s.stringkey = n.stringkey ) or intkey = (SELECT MIN(intkey) FROM bqt1.smallb AS s WHERE s.stringkey = n.stringkey )", FakeMetadataFactory.exampleBQTCached(),  //$NON-NLS-1$
+            null, capFinder,
+            new String[] { "SELECT g_0.intkey FROM bqt1.smalla AS g_0 WHERE (g_0.intkey = (SELECT MAX(g_1.intkey) FROM bqt1.smallb AS g_1 WHERE g_1.stringkey = g_0.stringkey)) OR (g_0.intkey = (SELECT MIN(g_2.IntKey) FROM bqt1.smallb AS g_2 WHERE g_2.StringKey = g_0.stringkey))" }, SHOULD_SUCCEED); //$NON-NLS-1$ 
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+	
+    /*
+     * Expressions containing subqueries can be pushed down
+     */
+    @Test public void testProjectSubqueryPushdown() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        FakeMetadataFacade metadata = example1();
+        
+        BasicSourceCapabilities caps = getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setFunctionSupport("+", true); //$NON-NLS-1$
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = helpPlan("select pm1.g1.e1, convert((select max(vm1.g1.e1) from vm1.g1), integer) + 1 from pm1.g1", metadata,  //$NON-NLS-1$
+                                      null, capFinder,
+            new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1), integer) + 1) FROM pm1.g1 AS g_0" }, SHOULD_SUCCEED); //$NON-NLS-1$
+        checkNodeTypes(plan, FULL_PUSHDOWN); 
+    }
+
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestUnionPlanning.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,159 @@
+/*
+ * 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 org.teiid.query.optimizer;
+
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+import junit.framework.TestCase;
+
+public class TestUnionPlanning extends TestCase {
+
+    public void testUnionPushDown() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
+            new String[] { "SELECT IntNum FROM BQT2.SmallA", "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });                                    
+    }
+    
+    /**
+     * Here the change in the all causes us not to pushdown
+     */
+    public void testUnionPushDown1() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
+            new String[] { "SELECT IntNum FROM BQT2.SmallA", "SELECT IntKey FROM BQT1.SmallA", "SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            2       // UnionAll
+        });                                    
+    }
+
+    public void testUnionPushDown2() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
+        capFinder.addCapabilities("BQT3", caps1); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT3.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
+            new String[] { "SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA", "SELECT IntNum FROM BQT3.SmallA", "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            2       // UnionAll
+        });                                    
+    }
+    
+    public void testUnionPushDown3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
+        capFinder.addCapabilities("BQT3", caps1); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT3.SmallA UNION ALL (SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA)", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
+            new String[] { "SELECT IntNum FROM BQT3.SmallA", "SELECT IntNum FROM BQT2.SmallA UNION ALL (SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT2.SmallA)", "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            2       // UnionAll
+        });                                    
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/batch (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/batch/TestBatchedUpdatePlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/batch/TestBatchedUpdatePlanner.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/batch/TestBatchedUpdatePlanner.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,40 +20,41 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.batch;
+package org.teiid.query.optimizer.batch;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.batch.BatchedUpdatePlan;
+import org.teiid.query.processor.relational.AccessNode;
+import org.teiid.query.processor.relational.BatchedUpdateNode;
+import org.teiid.query.processor.relational.ProjectNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorReport;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.batch.BatchedUpdatePlan;
-import com.metamatrix.query.processor.relational.AccessNode;
-import com.metamatrix.query.processor.relational.BatchedUpdateNode;
-import com.metamatrix.query.processor.relational.ProjectNode;
-import com.metamatrix.query.processor.relational.RelationalNode;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.validator.Validator;
-import com.metamatrix.query.validator.ValidatorReport;
 
 
 /** 
@@ -65,7 +66,7 @@
         super(name);
     }
     
-    public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, MetaMatrixProcessingException  { 
+    public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws TeiidComponentException, TeiidProcessingException  { 
         if(DEBUG) System.out.println("\n####################################\n" + sql);  //$NON-NLS-1$
         List<Command> commands = new ArrayList<Command>(sql.length);
         for (int i = 0; i < sql.length; i++) {
@@ -84,12 +85,12 @@
         return commands;
     }
     
-    private BatchedUpdateCommand helpGetCommand(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, MetaMatrixProcessingException { 
+    private BatchedUpdateCommand helpGetCommand(String[] sql, QueryMetadataInterface md) throws TeiidComponentException, TeiidProcessingException { 
         BatchedUpdateCommand command = new BatchedUpdateCommand(helpGetCommands(sql, md));
         return command;
     }
     
-    private BatchedUpdatePlan helpPlanCommand(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException { 
+    private BatchedUpdatePlan helpPlanCommand(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws QueryPlannerException, QueryMetadataException, TeiidComponentException { 
         
         // plan
         ProcessorPlan plan = null;
@@ -113,7 +114,7 @@
 
         } catch (QueryPlannerException e) {
             exception = e;
-        } catch (MetaMatrixComponentException e) {
+        } catch (TeiidComponentException e) {
             exception = e;
         } finally {
             if(DEBUG) {
@@ -128,11 +129,11 @@
         return new DefaultCapabilitiesFinder(new FakeCapabilities(true));
     }
 
-    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md) throws MetaMatrixComponentException, QueryMetadataException, MetaMatrixProcessingException {
+    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
         return helpPlan(sql, md, getGenericFinder(), true);
     }
     
-    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws MetaMatrixComponentException, QueryMetadataException, MetaMatrixProcessingException {
+    private BatchedUpdatePlan helpPlan(String[] sql, QueryMetadataInterface md, CapabilitiesFinder capFinder, boolean shouldSucceed) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
         Command command = helpGetCommand(sql, md);
 
         if (capFinder == null){
@@ -154,7 +155,7 @@
         }
     }
     
-    private void helpTestPlanner(String[] sql, boolean[] expectedBatching) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    private void helpTestPlanner(String[] sql, boolean[] expectedBatching) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
         BatchedUpdatePlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached());
         List plans = plan.getUpdatePlans();
         assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$
@@ -163,7 +164,7 @@
         }
     }    
     
-    private void helpTestPlanner(String[] sql, boolean[] expectedBatching, CapabilitiesFinder capFinder) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    private void helpTestPlanner(String[] sql, boolean[] expectedBatching, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
         BatchedUpdatePlan plan = helpPlan(sql, FakeMetadataFactory.example1Cached(), capFinder, true);
         List plans = plan.getUpdatePlans();
         assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/capabilities)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/capabilities/AllCapabilities.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,8 +23,10 @@
 /**
  * 
  */
-package com.metamatrix.query.optimizer.capabilities;
+package org.teiid.query.optimizer.capabilities;
 
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+
 public class AllCapabilities implements SourceCapabilities {
     public boolean supportsCapability(Capability capability) {
         return true;
@@ -35,7 +37,7 @@
     }
 
     /** 
-     * @see com.metamatrix.query.optimizer.capabilities.SourceCapabilities#getSourceProperty(java.lang.String)
+     * @see org.teiid.query.optimizer.capabilities.SourceCapabilities#getSourceProperty(java.lang.String)
      * @since 4.4
      */
     public Object getSourceProperty(Capability propertyName) {

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/FakeCapabilitiesFinder.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/capabilities/FakeCapabilitiesFinder.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/FakeCapabilitiesFinder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.capabilities;
+package org.teiid.query.optimizer.capabilities;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
 
+
 /**
  */
 public class FakeCapabilitiesFinder implements CapabilitiesFinder {
@@ -46,7 +49,7 @@
     /* (non-Javadoc)
      * @see com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder#findCapabilities(java.lang.String)
      */
-    public SourceCapabilities findCapabilities(String connectorBindingID) throws MetaMatrixComponentException {
+    public SourceCapabilities findCapabilities(String connectorBindingID) throws TeiidComponentException {
         return caps.get(connectorBindingID);
     }
     

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestBasicSourceCapabilities.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/capabilities/TestBasicSourceCapabilities.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestBasicSourceCapabilities.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,9 +20,10 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.capabilities;
+package org.teiid.query.optimizer.capabilities;
 
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
 
 import junit.framework.*;
 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestDefaultCapabilitiesFinder.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/capabilities/TestDefaultCapabilitiesFinder.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/capabilities/TestDefaultCapabilitiesFinder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.capabilities;
+package org.teiid.query.optimizer.capabilities;
 
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+
 import junit.framework.TestCase;
 
 /**

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/proc (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/proc/TestProcedurePlanner.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/proc/TestProcedurePlanner.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,28 +20,29 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.proc;
+package org.teiid.query.optimizer.proc;
 
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorFailure;
+import org.teiid.query.validator.ValidatorReport;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.validator.Validator;
-import com.metamatrix.query.validator.ValidatorFailure;
-import com.metamatrix.query.validator.ValidatorReport;
 
 public class TestProcedurePlanner extends TestCase {
 
@@ -55,14 +56,14 @@
 
 	// ################ getReplacementClause tests ################### 
 
-    private ProcessorPlan helpPlanProcedure(String procedure, String procedureType) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    private ProcessorPlan helpPlanProcedure(String procedure, String procedureType) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
         return helpPlanProcedure(null, procedure, procedureType);
     }
     
 	private ProcessorPlan helpPlanProcedure(String userQuery,
                                             String procedure,
-                                            String procedureType) throws MetaMatrixComponentException,
-                                                                 QueryMetadataException, MetaMatrixProcessingException {
+                                            String procedureType) throws TeiidComponentException,
+                                                                 QueryMetadataException, TeiidProcessingException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 
         QueryParser parser = QueryParser.getQueryParser();

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestAliasGenerator.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,153 @@
+/*
+ * 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 org.teiid.query.optimizer.relational;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.AliasGenerator;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.TestResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestAliasGenerator {
+    
+    private Command helpTest(String sql,
+                          String expected, 
+                          boolean aliasGroups,
+                          QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException {
+        Command command = TestResolver.helpResolve(sql, metadata, null);
+        command = QueryRewriter.rewrite(command, metadata, null);
+        command.acceptVisitor(new AliasGenerator(aliasGroups));
+        assertEquals(expected, command.toString());
+        return command;
+    }
+
+    /**
+     * Ensures that views are named with v_ even without metadata
+     */
+    @Test public void testViewAliasing() throws Exception {
+        String sql = "select y.e1 from (select pm1.g1.e1 from pm1.g1) y"; //$NON-NLS-1$
+        Query command = (Query)QueryParser.getQueryParser().parseCommand(sql);
+        ((ElementSymbol)command.getSelect().getSymbol(0)).setGroupSymbol(new GroupSymbol("y")); //$NON-NLS-1$
+        command.acceptVisitor(new AliasGenerator(true));
+        assertEquals("SELECT v_0.c_0 FROM (SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 AS g_0) AS v_0", command.toString()); //$NON-NLS-1$
+    }
+    
+    @Test public void testLongOrderByAlias() throws Exception {
+        String sql = "select pm1.g1.e1 || pm1.g1.e2 as asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa, pm1.g1.e2 from pm1.g1 order by asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa"; //$NON-NLS-1$
+        String expected = "SELECT concat(g_0.e1, g_0.e2) AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+    }
+    
+    @Test public void testOrderBySymbolName() throws Exception {
+        String sql = "select e1 from pm1.g1 order by e1"; //$NON-NLS-1$
+        String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
+        Query command = (Query)helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+        assertEquals(command.getOrderBy().getSortKeys().get(0).getName(), "e1"); //$NON-NLS-1$
+        assertEquals(((SingleElementSymbol)command.getProjectedSymbols().get(0)).getShortName(), "e1"); //$NON-NLS-1$
+    }
+    
+    @Test public void testInlineViewWithSubQuery() throws Exception {
+        String sql = "select intnum from (select intnum from bqt1.smallb where intnum in (select intnum a from bqt1.smalla)) b"; //$NON-NLS-1$
+        String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM bqt1.smallb AS g_0 WHERE g_0.intnum IN (SELECT g_1.intnum FROM bqt1.smalla AS g_1)) AS v_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testInlineViewOrderBy() throws Exception {
+        String sql = "select intnum from (select intnum from bqt1.smallb) b order by b.intnum"; //$NON-NLS-1$
+        String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM bqt1.smallb AS g_0) AS v_0 ORDER BY c_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testNestedInlineViewOrderBy() throws Exception {
+        String sql = "select x from (select intnum x from (select intnum from bqt1.smallb) b order by x) y order by x"; //$NON-NLS-1$
+        String expected = "SELECT v_1.c_0 FROM (SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM bqt1.smallb AS g_0) AS v_0) AS v_1 ORDER BY c_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testInlineViewWithOnClause() throws Exception {
+        String sql = "select abcd.efg from (select intkey as efg from bqt1.smalla) abcd inner join (select intnum from bqt1.smallb) b on (b.intnum = abcd.efg)"; //$NON-NLS-1$
+        String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intkey AS c_0 FROM bqt1.smalla AS g_0) AS v_0 INNER JOIN (SELECT g_1.intnum AS c_0 FROM bqt1.smallb AS g_1) AS v_1 ON v_1.c_0 = v_0.c_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+
+    @Test public void testUnionOrderBy() throws Exception {
+        String sql = "select e1, e2 as c_0 from pm1.g1 union all select 1, e1 from pm1.g2 order by e1"; //$NON-NLS-1$
+        String expected = "SELECT g_1.e1 AS c_0, g_1.e2 AS c_1 FROM pm1.g1 AS g_1 UNION ALL SELECT '1' AS c_0, g_0.e1 AS c_1 FROM pm1.g2 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+    }
+    
+    @Test public void testDuplicateShortElementName() throws Exception {
+    	String sql = "select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 order by pm1.g1.e1, pm1.g2.e1"; //$NON-NLS-1$
+        String expected = "SELECT g_0.e1 AS c_0, g_1.e1 AS c_1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 ORDER BY c_0, c_1"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+    }
+    
+    @Test public void testCorrelatedRefernce() throws Exception {
+    	String sql = "select intnum, stringnum from (select intnum, stringnum from bqt1.smallb) b where intnum in (select b.stringnum || b.intnum from (select intnum from bqt1.smalla) b) "; //$NON-NLS-1$
+        String expected = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intnum AS c_0, g_0.stringnum AS c_1 FROM bqt1.smallb AS g_0) AS v_0 WHERE v_0.c_0 IN (SELECT concat(v_0.c_1, v_1.c_0) FROM (SELECT g_1.intnum AS c_0 FROM bqt1.smalla AS g_1) AS v_1)"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+
+    @Test public void testCorrelatedRefernce1() throws Exception {
+    	String sql = "select intnum, stringnum from bqt1.smallb where intnum in (select stringnum || b.intnum from (select intnum from bqt1.smalla) b) "; //$NON-NLS-1$
+        String expected = "SELECT g_0.intnum, g_0.stringnum FROM bqt1.smallb AS g_0 WHERE g_0.intnum IN (SELECT concat(g_0.stringnum, v_0.c_0) FROM (SELECT g_1.intnum AS c_0 FROM bqt1.smalla AS g_1) AS v_0)"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testGroupAliasNotSupported() throws Exception {
+    	String sql = "select b.intkey from bqt1.smalla b"; //$NON-NLS-1$
+        String expected = "SELECT bqt1.smalla.intkey FROM bqt1.smalla"; //$NON-NLS-1$
+        helpTest(sql, expected, false, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testUnionAliasing() throws Exception {
+    	String sql = "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA"; //$NON-NLS-1$
+        String expected = "SELECT BQT1.SmallA.IntKey AS c_0 FROM BQT1.SmallA UNION ALL SELECT BQT1.SmallA.IntNum AS c_0 FROM BQT1.SmallA"; //$NON-NLS-1$
+        helpTest(sql, expected, false, FakeMetadataFactory.exampleBQTCached());
+    }
+
+    @Test public void testUnrelatedOrderBy() throws Exception {
+    	String sql = "SELECT b.IntKey FROM BQT1.SmallA a, BQT1.SmallA b ORDER BY a.StringKey"; //$NON-NLS-1$
+        String expected = "SELECT g_1.IntKey AS c_0 FROM BQT1.SmallA AS g_0, BQT1.SmallA AS g_1 ORDER BY g_0.StringKey"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+    @Test public void testUnrelatedOrderBy1() throws Exception {
+    	String sql = "SELECT b.IntKey FROM (select intkey, stringkey from BQT1.SmallA) a, (select intkey, stringkey from BQT1.SmallA) b ORDER BY a.StringKey"; //$NON-NLS-1$
+        String expected = "SELECT v_1.c_0 FROM (SELECT g_0.intkey AS c_0, g_0.stringkey AS c_1 FROM BQT1.SmallA AS g_0) AS v_0, (SELECT g_1.intkey AS c_0, g_1.stringkey AS c_1 FROM BQT1.SmallA AS g_1) AS v_1 ORDER BY v_0.c_1"; //$NON-NLS-1$
+        helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestMaterialization.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,141 @@
+/*
+ * 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 org.teiid.query.optimizer.relational;
+
+import static org.junit.Assert.*;
+import static org.teiid.query.optimizer.TestOptimizer.*;
+
+import java.util.Collection;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.teiid.client.plan.Annotation;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestMaterialization {
+	
+    @Test public void testMaterializedTransformation() throws Exception {
+        String userSql = "SELECT MATVIEW.E1 FROM MATVIEW"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.e1 FROM MatTable.MatTable AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        Collection<Annotation> annotations = analysis.getAnnotations();
+        assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
+        assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+        assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
+    }
+
+    @Ignore("we no longer auto detect this case, if we need this logic it will have to be added to the rewriter since it changes select into to an insert")
+    @Test public void testMaterializedTransformationLoading() throws Exception {
+        String userSql = "SELECT MATVIEW.E1 INTO MatTable.MatStage FROM MATVIEW"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+        Collection<Annotation> annotations = analysis.getAnnotations();
+        assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
+        assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+        assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
+    }    
+    
+    @Test public void testMaterializedTransformationNoCache() throws Exception {
+        String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE MatView.MatView"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        Collection<Annotation> annotations = analysis.getAnnotations();
+        assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
+        assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+        assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
+    }
+    
+    //related to defect 14423
+    @Test public void testMaterializedTransformationNoCache2() throws Exception {
+        String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        Collection<Annotation> annotations = analysis.getAnnotations();
+        assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
+        assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+        assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
+    }
+    
+    @Test public void testNoCacheInTransformation() throws Exception {
+        String userSql = "SELECT VGROUP.E1 FROM VGROUP"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    }
+    
+    @Test public void testTableNoCacheDoesntCascade() throws Exception {
+        String userSql = "SELECT MATVIEW1.E1 FROM MATVIEW1 option nocache matview.matview1"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.e1 FROM MatTable.MatTable AS g_0 WHERE g_0.e1 = '1'"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    }
+    
+    @Test public void testNoCacheCascade() throws Exception {
+        String userSql = "SELECT MATVIEW1.E1 FROM MATVIEW1 option nocache"; //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+        AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+        
+        Command command = helpGetCommand(userSql, metadata, null);
+        
+        TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0 WHERE g_0.x = '1'"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+    }
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestRuleStack.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/TestRuleStack.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestRuleStack.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestRuleStack.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,102 @@
+/*
+ * 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 org.teiid.query.optimizer.relational;
+
+import org.teiid.query.optimizer.relational.OptimizerRule;
+import org.teiid.query.optimizer.relational.RuleStack;
+import org.teiid.query.optimizer.relational.rules.RuleConstants;
+import org.teiid.query.optimizer.relational.rules.RulePushSelectCriteria;
+
+import junit.framework.TestCase;
+
+
+/**
+ */
+public class TestRuleStack extends TestCase {
+
+    /**
+     * Constructor for TestRuleStack.
+     * @param arg0
+     */
+    public TestRuleStack(String arg0) {
+        super(arg0);
+    }
+
+    
+    public void testInitialization() {
+        RuleStack stack = new RuleStack();
+        assertEquals("Initial stack is not empty", true, stack.isEmpty()); //$NON-NLS-1$
+        assertEquals("Initial size is not 0", 0, stack.size()); //$NON-NLS-1$
+        assertNull("Top is not null", stack.pop()); //$NON-NLS-1$
+    }
+    
+    public void helpTestPop(RuleStack stack, OptimizerRule expectedPop, int expectedSize) {
+        OptimizerRule out = stack.pop();
+        int outSize = stack.size();
+        
+        assertSame("Did not get same object", expectedPop, out); //$NON-NLS-1$
+        assertEquals("Stack changed size", expectedSize, outSize);                     //$NON-NLS-1$
+    }
+    
+    public void testPopOneRule() {
+        RuleStack stack = new RuleStack();
+        int expectedSize = stack.size();
+        
+        OptimizerRule rule = new RulePushSelectCriteria();
+        stack.push(rule);
+        
+        helpTestPop(stack, rule, expectedSize);
+    }
+
+    public void testPopNothing() {
+        RuleStack stack = new RuleStack();
+        helpTestPop(stack, null, 0);
+    }
+    
+    public void testRemove() {
+        // Set up
+        RuleStack stack = new RuleStack();
+        stack.push(RuleConstants.ASSIGN_OUTPUT_ELEMENTS);
+        stack.push(RuleConstants.COLLAPSE_SOURCE);
+        stack.push(RuleConstants.ASSIGN_OUTPUT_ELEMENTS);
+        
+        // Remove all instances of ASSIGN_OUTPUT_ELEMENTS
+        stack.remove(RuleConstants.ASSIGN_OUTPUT_ELEMENTS);
+        
+        // Verify size and pop'ed values
+        assertEquals(1, stack.size());
+        assertEquals(RuleConstants.COLLAPSE_SOURCE, stack.pop());
+        assertEquals(null, stack.pop());
+    }
+    
+    public void testContains() {
+        // Set up
+        RuleStack stack = new RuleStack();
+        stack.push(RuleConstants.ASSIGN_OUTPUT_ELEMENTS);
+        stack.push(RuleConstants.COLLAPSE_SOURCE);
+        
+        assertEquals(true, stack.contains(RuleConstants.ASSIGN_OUTPUT_ELEMENTS));
+        assertEquals(false, stack.contains(RuleConstants.PLACE_ACCESS));
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/plantree (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/plantree)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/plantree/TestNodeEditor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/plantree/TestNodeEditor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/plantree/TestNodeEditor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.plantree;
+package org.teiid.query.optimizer.relational.plantree;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeEditor;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  */

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCalculateCostUtil.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,32 +20,33 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import static org.junit.Assert.*;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.rules.NewCalculateCostUtil;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.TestVirtualDepJoin;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
-import com.metamatrix.query.optimizer.relational.RelationalPlanner;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.TestVirtualDepJoin;
-import com.metamatrix.query.processor.relational.RelationalPlan;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestCalculateCostUtil {
 
@@ -53,7 +54,7 @@
     // HELPERS
     // =====================================================================
     
-    private static Criteria helpGetCriteria(String critString, QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException{
+    private static Criteria helpGetCriteria(String critString, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException{
 
         Criteria result = QueryParser.getQueryParser().parseCriteria(critString);
         QueryResolver.resolveCriteria(result, metadata);

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCapabilitiesUtil.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,33 +20,34 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.CapabilitiesUtil;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 /**
  */
@@ -60,7 +61,7 @@
         super(name);
     }
     
-    public void helpTestSupportsSelfJoin(boolean supportsSelfJoin, boolean supportsGroupAlias, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
+    public void helpTestSupportsSelfJoin(boolean supportsSelfJoin, boolean supportsGroupAlias, boolean expectedValue) throws QueryMetadataException, TeiidComponentException {
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -100,7 +101,7 @@
     }
 
     
-    public void helpTestSupportsOuterJoin(boolean capsSupportsOuterJoin, boolean capsSupportsFullOuterJoin, JoinType joinType, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
+    public void helpTestSupportsOuterJoin(boolean capsSupportsOuterJoin, boolean capsSupportsFullOuterJoin, JoinType joinType, boolean expectedValue) throws QueryMetadataException, TeiidComponentException {
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -137,7 +138,7 @@
         helpTestSupportsOuterJoin(true, true, JoinType.JOIN_FULL_OUTER, true); 
     }
 
-    public void helpTestSupportsAggregates(boolean capsSupportsAggregates, boolean supportsFunctionInGroupBy, List groupCols) throws QueryMetadataException, MetaMatrixComponentException {
+    public void helpTestSupportsAggregates(boolean capsSupportsAggregates, boolean supportsFunctionInGroupBy, List groupCols) throws QueryMetadataException, TeiidComponentException {
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -172,7 +173,7 @@
         helpTestSupportsAggregates(false, false, cols);
     }
 
-    public void helpTestSupportsAggregateFunction(SourceCapabilities caps, AggregateSymbol aggregate, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
+    public void helpTestSupportsAggregateFunction(SourceCapabilities caps, AggregateSymbol aggregate, boolean expectedValue) throws QueryMetadataException, TeiidComponentException {
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -368,7 +369,7 @@
         helpTestSupportsAggregateFunction(caps, aggregate, true); 
     }    
 
-    public void helpTestSupportsScalar(SourceCapabilities caps, Function function, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
+    public void helpTestSupportsScalar(SourceCapabilities caps, Function function, boolean expectedValue) throws QueryMetadataException, TeiidComponentException {
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -478,7 +479,7 @@
         assertEquals("Got wrong answer for supports", false, actual); //$NON-NLS-1$
     }    
     
-    public void helpTestSupportsUnion(boolean supports) throws QueryMetadataException, MetaMatrixComponentException {        
+    public void helpTestSupportsUnion(boolean supports) throws QueryMetadataException, TeiidComponentException {        
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -502,7 +503,7 @@
         helpTestSupportsUnion(false);
     }
 
-    public void helpTestSupportsLiterals(boolean supports) throws QueryMetadataException, MetaMatrixComponentException {        
+    public void helpTestSupportsLiterals(boolean supports) throws QueryMetadataException, TeiidComponentException {        
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -526,7 +527,7 @@
         helpTestSupportsLiterals(false);
     }
 
-    public void helpTtestSupportsCaseExpression(boolean supports, boolean searched) throws QueryMetadataException, MetaMatrixComponentException {        
+    public void helpTtestSupportsCaseExpression(boolean supports, boolean searched) throws QueryMetadataException, TeiidComponentException {        
         // Set up metadata
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
         FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCriteriaCapabilityValidatorVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCriteriaCapabilityValidatorVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCriteriaCapabilityValidatorVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,25 +20,26 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.core.TeiidException;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.CriteriaCapabilityValidatorVisitor;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
 
 import static org.junit.Assert.*;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 /**
  */
@@ -55,7 +56,7 @@
         	if (!expectException) {
         		throw new RuntimeException(e);
         	}
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
         	throw new RuntimeException(e);
         }
     }
@@ -72,7 +73,7 @@
         	if (!expectException) {
         		throw new RuntimeException(e);
         	}
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
         	throw new RuntimeException(e);
         }
     }

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestFrameUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestFrameUtil.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestFrameUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import static org.junit.Assert.*;
 
@@ -29,18 +29,19 @@
 import java.util.Set;
 
 import org.junit.Test;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeEditor;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants.Info;
+import org.teiid.query.optimizer.relational.rules.FrameUtil;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.util.SymbolMap;
 
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants.Info;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.util.SymbolMap;
 
 public class TestFrameUtil {
     

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestGroupRecontext.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,19 +20,22 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.teiid.query.optimizer.relational.rules.FrameUtil;
+import org.teiid.query.optimizer.relational.rules.RulePlaceAccess;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SubqueryCompareCriteria;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestGroupRecontext extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestJoinRegion.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestJoinRegion.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestJoinRegion.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.sql.lang.JoinType;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.rules.JoinRegion;
+import org.teiid.query.optimizer.relational.rules.RulePlanJoins;
+import org.teiid.query.sql.lang.JoinType;
 
+
 import junit.framework.TestCase;
 
 public class TestJoinRegion extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAccessPatternValidation.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRuleAccessPatternValidation.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAccessPatternValidation.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import static org.junit.Assert.*;
 
@@ -28,27 +28,27 @@
 import java.util.Collection;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.relational.OptimizerRule;
+import org.teiid.query.optimizer.relational.PlanHints;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.optimizer.relational.RuleStack;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.relational.OptimizerRule;
-import com.metamatrix.query.optimizer.relational.PlanHints;
-import com.metamatrix.query.optimizer.relational.RelationalPlanner;
-import com.metamatrix.query.optimizer.relational.RuleStack;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  * Tests {@link RuleChooseAccessPattern}
@@ -108,7 +108,7 @@
 	 * Simulate execution of the QueryOptimizer rules stack
 	 */
 	private static PlanNode helpExecuteRules(RuleStack rules, PlanNode plan, QueryMetadataInterface metadata, boolean debug)
-		throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+		throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
 		CommandContext context = new CommandContext();
 		while(! rules.isEmpty()) {
 			if(debug) {

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRuleAssignOutputElements.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleAssignOutputElements.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,10 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
-import com.metamatrix.query.optimizer.relational.plantree.*;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.optimizer.relational.plantree.*;
+import org.teiid.query.optimizer.relational.rules.RuleAssignOutputElements;
+import org.teiid.query.sql.lang.SetQuery.Operation;
 
 import junit.framework.*;
 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRuleChooseDependent.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -30,38 +30,43 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.relational.RuleStack;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.rules.FrameUtil;
+import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
+import org.teiid.query.optimizer.relational.rules.RuleChooseJoinStrategy;
+import org.teiid.query.optimizer.relational.rules.RulePlaceAccess;
+import org.teiid.query.processor.relational.JoinNode.JoinStrategyType;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.NotCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.relational.RuleStack;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.processor.relational.JoinNode.JoinStrategyType;
-import com.metamatrix.query.rewriter.QueryRewriter;
-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.From;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.NotCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-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.GroupSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestRuleChooseDependent extends TestCase {
 
@@ -186,7 +191,7 @@
      * @param atomicRequestCrit2 optional, may be null
      * @param joinCriteria Collection of Criteria to add to join node
      * @param expectedMadeDependent one of the three outcome possibility class constants
-     * @throws MetaMatrixComponentException 
+     * @throws TeiidComponentException 
      * @throws QueryMetadataException 
      * @throws QueryPlannerException 
      */
@@ -195,7 +200,7 @@
                                                         GroupSymbol atomicRequestGroup2, 
                                                         Criteria atomicRequestCrit2,
                                                         Collection joinCriteria, 
-                                                        int expectedMadeDependent) throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+                                                        int expectedMadeDependent) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
 
         helpTestChooseSiblingAndMarkDependent(atomicRequestGroup1, 
         atomicRequestCrit1, 
@@ -233,7 +238,7 @@
      * @param atomicJoinCriteria2 optional, may be null
      * @param joinCriteria Collection of Criteria to add to outer join node
      * @param expectedMadeDependent one of the three outcome possibility class constants
-     * @throws MetaMatrixComponentException 
+     * @throws TeiidComponentException 
      * @throws QueryMetadataException 
      * @throws QueryPlannerException 
      */    
@@ -248,7 +253,7 @@
                                                         Criteria atomicRequestCrit2a,  //optional
                                                         Collection atomicJoinCriteria2,  //optional
                                                         Collection joinCriteria, 
-                                                        int expectedMadeDependent) throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+                                                        int expectedMadeDependent) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
 //EXAMPLE:
 //    Project(groups=[])
 //      Join(groups=[], props={21=joinCriteria, 23=true, 22=INNER JOIN})

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePlaceAccess.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePlaceAccess.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,22 +20,24 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import java.util.Collection;
 
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.rules.RulePlaceAccess;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-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.symbol.AllSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestRulePlaceAccess extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRulePushSelectCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRulePushSelectCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
 import static org.junit.Assert.*;
 
@@ -30,27 +30,28 @@
 import java.util.Set;
 
 import org.junit.Test;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.optimizer.relational.RuleStack;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants;
+import org.teiid.query.optimizer.relational.plantree.NodeEditor;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
+import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.plantree.NodeConstants.Info;
+import org.teiid.query.optimizer.relational.rules.RulePushSelectCriteria;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.util.SymbolMap;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
-import com.metamatrix.query.metadata.TempMetadataStore;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.relational.RelationalPlanner;
-import com.metamatrix.query.optimizer.relational.RuleStack;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants;
-import com.metamatrix.query.optimizer.relational.plantree.NodeEditor;
-import com.metamatrix.query.optimizer.relational.plantree.NodeFactory;
-import com.metamatrix.query.optimizer.relational.plantree.PlanNode;
-import com.metamatrix.query.optimizer.relational.plantree.NodeConstants.Info;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.util.SymbolMap;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestRulePushSelectCriteria {
     

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleValidateWhereAll.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestRuleValidateWhereAll.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleValidateWhereAll.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,20 +20,22 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.relational.rules;
+package org.teiid.query.optimizer.relational.rules;
 
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.RuleValidateWhereAll;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestRuleValidateWhereAll extends TestCase {
     

Copied: trunk/engine/src/test/java/org/teiid/query/optimizer/xml (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml)

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/FakeXMLMetadata.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/FakeXMLMetadata.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/FakeXMLMetadata.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingChoiceNode;
-import com.metamatrix.query.mapping.xml.MappingCommentNode;
-import com.metamatrix.query.mapping.xml.MappingCriteriaNode;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingRecursiveElement;
-import com.metamatrix.query.mapping.xml.MappingSequenceNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCommentNode;
+import org.teiid.query.mapping.xml.MappingCriteriaNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestContextReplacerVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestContextReplacerVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestContextReplacerVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.util.Collection;
 
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.query.optimizer.xml.ContextReplacerVisitor;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestHandleNillableNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestHandleNillableNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestHandleNillableNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.util.Properties;
 
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.optimizer.xml.HandleNillableVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestMarkExcludeVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestMarkExcludeVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,21 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Collection;
 
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingOutputter;
+import org.teiid.query.optimizer.xml.XMLPlanner;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingOutputter;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestNameInSourceResolverVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestNameInSourceResolverVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,25 +29,29 @@
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingSourceNode;
+import org.teiid.query.mapping.xml.MappingVisitor;
+import org.teiid.query.mapping.xml.Navigator;
+import org.teiid.query.mapping.xml.ResultSetInfo;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.xml.NameInSourceResolverVisitor;
+import org.teiid.query.optimizer.xml.SourceNodeGenaratorVisitor;
+import org.teiid.query.optimizer.xml.XMLPlannerEnvironment;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingSourceNode;
-import com.metamatrix.query.mapping.xml.MappingVisitor;
-import com.metamatrix.query.mapping.xml.Navigator;
-import com.metamatrix.query.mapping.xml.ResultSetInfo;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestRemoveExcludedVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestRemoveExcludedVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestRemoveExcludedVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,17 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingOutputter;
+import org.teiid.query.optimizer.xml.XMLPlanner;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingOutputter;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLNodeMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLNodeMappingVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLNodeMappingVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,21 +20,24 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.xml.SourceNodeGenaratorVisitor;
+import org.teiid.query.optimizer.xml.XMLNodeMappingVisitor;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-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.unittest.FakeMetadataFacade;
 
 /**
  */
@@ -48,7 +51,7 @@
         super(arg0);
     }
 
-	public void helpTestMapping(Criteria crit, String expectedCritString, MappingDocument mappingDoc, QueryMetadataInterface metadata) throws QueryPlannerException, MetaMatrixComponentException {
+	public void helpTestMapping(Criteria crit, String expectedCritString, MappingDocument mappingDoc, QueryMetadataInterface metadata) throws QueryPlannerException, TeiidComponentException {
         crit = XMLNodeMappingVisitor.convertCriteria(crit, mappingDoc, metadata);
 		String actualCritString = crit.toString();
 		

Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLPlanner.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/xml/TestXMLPlanner.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/xml/TestXMLPlanner.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,48 +20,52 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.optimizer.xml;
+package org.teiid.query.optimizer.xml;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.core.id.IntegerIDFactory;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
+import org.teiid.query.mapping.xml.Namespace;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.xml.CriteriaPlanner;
+import org.teiid.query.optimizer.xml.XMLPlanner;
+import org.teiid.query.optimizer.xml.XMLPlannerEnvironment;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.xml.BlockInstruction;
+import org.teiid.query.processor.xml.EndBlockInstruction;
+import org.teiid.query.processor.xml.ExecSqlInstruction;
+import org.teiid.query.processor.xml.ExecStagingTableInstruction;
+import org.teiid.query.processor.xml.MoveCursorInstruction;
+import org.teiid.query.processor.xml.Program;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.processor.xml.WhileInstruction;
+import org.teiid.query.processor.xml.XMLPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.id.IDGenerator;
-import com.metamatrix.core.id.IntegerIDFactory;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingSequenceNode;
-import com.metamatrix.query.mapping.xml.Namespace;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.xml.BlockInstruction;
-import com.metamatrix.query.processor.xml.EndBlockInstruction;
-import com.metamatrix.query.processor.xml.ExecSqlInstruction;
-import com.metamatrix.query.processor.xml.ExecStagingTableInstruction;
-import com.metamatrix.query.processor.xml.MoveCursorInstruction;
-import com.metamatrix.query.processor.xml.Program;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.processor.xml.WhileInstruction;
-import com.metamatrix.query.processor.xml.XMLPlan;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestXMLPlanner extends TestCase {
 
@@ -78,7 +82,7 @@
         return preparePlan(command, md, TestOptimizer.getGenericFinder(), null);
     }
 
-    private void helpPlanException(String sql, QueryMetadataInterface md) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    private void helpPlanException(String sql, QueryMetadataInterface md) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
         Command command = TestXMLProcessor.helpGetCommand(sql, md);
 
         try {
@@ -784,10 +788,10 @@
      * @return The XML plan returned as an XMLPlan object
      * @throws QueryPlannerException
      * @throws QueryMetadataException
-     * @throws MetaMatrixComponentException
+     * @throws TeiidComponentException
      */
     public static XMLPlan preparePlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context)
-        throws QueryPlannerException, QueryMetadataException, MetaMatrixComponentException {
+        throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
         IDGenerator idGenerator = new IDGenerator();
         idGenerator.setDefaultFactory(new IntegerIDFactory());
         AnalysisRecord analysis = new AnalysisRecord(false, DEBUG);

Copied: trunk/engine/src/test/java/org/teiid/query/parser (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/parser)

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestCallableStatementParsing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestCallableStatementParsing.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestCallableStatementParsing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.parser;
+package org.teiid.query.parser;
 
 import static org.junit.Assert.*;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.StoredProcedure;
 
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.query.sql.lang.StoredProcedure;
 
 public class TestCallableStatementParsing {
     

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.parser;
+package org.teiid.query.parser;
 
 import static org.junit.Assert.*;
 
@@ -29,39 +29,40 @@
 import java.util.List;
 
 import org.junit.Test;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.AbstractCompareCriteria;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.FromClause;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.Option;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.proc.DeclareStatement;
+import org.teiid.query.sql.proc.HasCriteria;
+import org.teiid.query.sql.proc.IfStatement;
+import org.teiid.query.sql.proc.Statement;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
 
-import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.Delete;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.FromClause;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.Option;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.Block;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.proc.CriteriaSelector;
-import com.metamatrix.query.sql.proc.DeclareStatement;
-import com.metamatrix.query.sql.proc.HasCriteria;
-import com.metamatrix.query.sql.proc.IfStatement;
-import com.metamatrix.query.sql.proc.Statement;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
 public class TestOptionsAndHints {
     
     /** Select a From db.g1 MAKENOTDEP, db.g2 MAKENOTDEP WHERE a = b */

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestParser.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.parser;
+package org.teiid.query.parser;
 
 import static org.junit.Assert.*;
 
@@ -33,84 +33,83 @@
 import java.util.List;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Create;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.Drop;
+import org.teiid.query.sql.lang.DynamicCommand;
+import org.teiid.query.sql.lang.ExistsCriteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.FromClause;
+import org.teiid.query.sql.lang.GroupBy;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.Into;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.Limit;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.NotCriteria;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.PredicateCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetClauseList;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.SubqueryCompareCriteria;
+import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.BreakStatement;
+import org.teiid.query.sql.proc.CommandStatement;
+import org.teiid.query.sql.proc.ContinueStatement;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.proc.DeclareStatement;
+import org.teiid.query.sql.proc.HasCriteria;
+import org.teiid.query.sql.proc.IfStatement;
+import org.teiid.query.sql.proc.LoopStatement;
+import org.teiid.query.sql.proc.RaiseErrorStatement;
+import org.teiid.query.sql.proc.Statement;
+import org.teiid.query.sql.proc.TranslateCriteria;
+import org.teiid.query.sql.proc.WhileStatement;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.AllInGroupSymbol;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.ScalarSubquery;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.TestCaseExpression;
+import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
+import org.teiid.query.sql.symbol.XMLAttributes;
+import org.teiid.query.sql.symbol.XMLElement;
+import org.teiid.query.sql.symbol.XMLForest;
+import org.teiid.query.sql.symbol.XMLNamespaces;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.lang.BetweenCriteria;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.Create;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.Delete;
-import com.metamatrix.query.sql.lang.Drop;
-import com.metamatrix.query.sql.lang.DynamicCommand;
-import com.metamatrix.query.sql.lang.ExistsCriteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.FromClause;
-import com.metamatrix.query.sql.lang.GroupBy;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.Into;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.Limit;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.NotCriteria;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.PredicateCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SetClauseList;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.Block;
-import com.metamatrix.query.sql.proc.BreakStatement;
-import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.ContinueStatement;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.proc.CriteriaSelector;
-import com.metamatrix.query.sql.proc.DeclareStatement;
-import com.metamatrix.query.sql.proc.HasCriteria;
-import com.metamatrix.query.sql.proc.IfStatement;
-import com.metamatrix.query.sql.proc.LoopStatement;
-import com.metamatrix.query.sql.proc.RaiseErrorStatement;
-import com.metamatrix.query.sql.proc.Statement;
-import com.metamatrix.query.sql.proc.TranslateCriteria;
-import com.metamatrix.query.sql.proc.WhileStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-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.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-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.symbol.XMLAttributes;
-import com.metamatrix.query.sql.symbol.XMLElement;
-import com.metamatrix.query.sql.symbol.XMLForest;
-import com.metamatrix.query.sql.symbol.XMLNamespaces;
-
 @SuppressWarnings("nls")
 public class TestParser {
 
@@ -147,7 +146,7 @@
         try {
             QueryParser.getQueryParser().parseCommand(sql);
             fail("Expected exception for parsing " + sql); //$NON-NLS-1$
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             if (expected != null) {
                 assertEquals(expected, e.getMessage());
             }
@@ -1409,7 +1408,7 @@
         try {
             QueryParser.getQueryParser().parseCommand(sql);
             fail("Expected exception for parsing " + sql); //$NON-NLS-1$
-        } catch (MetaMatrixException e) {
+        } catch (TeiidException e) {
             //e.printStackTrace();
             //if (e.getMessage().length() > 1000) {
             //    fail("Expected max length of message 1000; but received  " + e.getMessage().length()); //$NON-NLS-1$
@@ -6382,7 +6381,7 @@
         try {
             QueryParser.getQueryParser().parseCommand(""); //$NON-NLS-1$
             fail("Expected exception for parsing empty string"); //$NON-NLS-1$
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             emptyMessage = e.getMessage();
         }       
 
@@ -6390,7 +6389,7 @@
         try {
             QueryParser.getQueryParser().parseCommand(null);
             fail("Expected exception for parsing null string"); //$NON-NLS-1$
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             nullMessage = e.getMessage();
         }     
         

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestParserXQuery.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.parser;
+package org.teiid.query.parser;
 
+import org.teiid.query.sql.lang.XQuery;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.lang.XQuery;
 
 public class TestParserXQuery extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/parser/TestSetQueryParsing.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestSetQueryParsing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,18 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.parser;
+package org.teiid.query.parser;
 
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Limit;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Limit;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
 
 import junit.framework.TestCase;
 

Copied: trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,403 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.logging.LogManager;
+import org.teiid.query.eval.Evaluator;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.ProcedureContainer;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.TranslatableProcedureContainer;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.util.SymbolMap;
+import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
+import org.teiid.query.util.CommandContext;
+
+
+public class FakeDataManager implements ProcessorDataManager {
+	private Map tuples = new HashMap();
+    private static final String LOG_CONTEXT = "FAKE_DATA_MANAGER"; //$NON-NLS-1$
+    
+    //used to test blocked exception. If true,
+    //the first time nextTuple is called on FakeTupleSource,
+    //it will throws BlockedExceptiom
+    private boolean blockOnce;
+
+    // ---- Cached code table stuff ---- 
+    	
+    // upper table name + upper key col name + upper ret col name -> map of values
+    private Map codeTableValues = new HashMap();
+    
+    // throw Blocked on first request
+    private boolean throwBlocked = false;
+    
+    // upper table name + upper key col name + upper ret col name -> flag of whether this table has blocked yet
+    private Map blockedState = new HashMap();
+
+    // Track history to verify it later
+    private List<String> queries = new ArrayList<String>();
+    private boolean recordingCommands = true;
+    
+    /**
+     * Return string form of all queries run against this FDM 
+     * @return List<String> recorded commands
+     */
+    public List<String> getQueries() {
+        return this.queries;
+    }
+	        
+    /**
+     * Clears the list of recorded commands and returns a copy
+     * @return a copy of the recorded commands prior to clearing the list
+     */
+    public List<String> clearQueries() {
+    	List<String> rc = new ArrayList<String>(this.getQueries());
+    	this.queries.clear();
+    	return rc;
+    }
+	        
+	public void registerTuples(Object groupID, List elements, List[] data) {
+		tuples.put(groupID, new Object[] { elements, data });
+	}
+	
+	public void closeRequest(Object requestID) {
+		// does nothing?
+    } 
+	
+	public TupleSource registerRequest(Object processorID, Command command, String modelName, String connectorBindingId, int nodeID)
+		throws TeiidComponentException {
+        
+        LogManager.logTrace(LOG_CONTEXT, new Object[]{"Register Request:", command, ",processorID:", processorID, ",model name:", modelName,",TupleSourceID nodeID:",new Integer(nodeID)}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+        if (this.recordingCommands) {
+            if (! (command instanceof BatchedUpdateCommand) ) {
+            	this.queries.add(command.toString());
+            }
+        }
+
+        if (ReferenceCollectorVisitor.getReferences(command).size() > 0) {
+            throw new IllegalArgumentException("Found references in the command registered with the DataManager."); //$NON-NLS-1$
+        }
+		// Get group ID from atomic command
+		GroupSymbol group = null;
+		if(command instanceof Query){
+			group = getQueryGroup((Query)command);    
+        }else if(command instanceof SetQuery) {
+            SetQuery union = (SetQuery) command;            
+            group = getQueryGroup(union.getProjectedQuery());
+		} else if (command instanceof ProcedureContainer) {
+			group = ((ProcedureContainer) command).getGroup();
+		} else if ( command instanceof BatchedUpdateCommand ) {
+    		if ( command.getSubCommands().get(0) instanceof Update ) {
+    			group = ((Update)command.getSubCommands().get(0)).getGroup();
+    		}
+    		if (this.recordingCommands) {
+            	for ( Iterator<Command> it = ((BatchedUpdateCommand) command).getUpdateCommands().iterator(); it.hasNext(); ) {
+            		this.queries.add(it.next().toString());
+            	}
+    		}
+		}
+		
+		Object groupID = group.getMetadataID();
+		
+		Object[] tupleInfo = (Object[]) tuples.get(groupID);
+		List elements = (List) tupleInfo[0];
+		List[] tuples = (List[]) tupleInfo[1];
+		
+		List projectedSymbols = command.getProjectedSymbols();
+		int[] columnMap = getColumnMap(elements, projectedSymbols);
+		
+		/* 
+		*  updateCommands is used to hold a list of commands that 
+		*  either came from a BatchedUpdateCommand or a signle 
+		*  command from an Update command.
+		*/
+		List<Command> updateCommands = new ArrayList<Command>();
+		
+		// Apply query criteria to tuples
+		if(command instanceof Query){
+			Query query = (Query)command;
+			if(query.getCriteria() != null) {
+			    // Build lookupMap from BOTH all the elements and the projected symbols - both may be needed here
+	            Map lookupMap = new HashMap();
+	            for(int i=0; i<elements.size(); i++) { 
+	                Object element = elements.get(i);
+                    mapElementToIndex(lookupMap, element, new Integer(i), group);        
+	            }
+	            for(int i=0; i<projectedSymbols.size(); i++) { 
+	            	Object element = projectedSymbols.get(i);
+                    mapElementToIndex(lookupMap, element, new Integer(columnMap[i]), group);
+	            }
+			    
+			    List filteredTuples = new ArrayList();
+			    for(int i=0; i<tuples.length; i++) {
+	                try {
+	    				if(new Evaluator(lookupMap, null, null).evaluate(query.getCriteria(), tuples[i])) {
+	                        filteredTuples.add(tuples[i]);
+	                    }
+	                } catch(CriteriaEvaluationException e) {
+	                    throw new TeiidComponentException(e, e.getMessage());
+	                }
+			    }
+			    
+			    tuples = new List[filteredTuples.size()];
+			    filteredTuples.toArray(tuples);
+			}
+		} else if ( command instanceof Insert || command instanceof Update || command instanceof Delete) {
+			// add single update command to a list to be executed
+			updateCommands.add(command);
+		} else if ( command instanceof BatchedUpdateCommand ) {
+			// add all update commands to a list to be executed
+    		updateCommands.addAll(((BatchedUpdateCommand) command).getUpdateCommands());
+		}
+		
+		// if we had update commands added to the list, execute them now
+		if ( updateCommands.size() > 0 ) {
+		    List<List<Integer>> filteredTuples = new ArrayList<List<Integer>>();
+			for ( int c = 0; c < updateCommands.size(); c++ ) {
+				Command cmd = updateCommands.get(c);
+				if (cmd instanceof TranslatableProcedureContainer) {
+					TranslatableProcedureContainer update = (TranslatableProcedureContainer)cmd;
+					if ( update.getCriteria() != null ) {
+					    // Build lookupMap from BOTH all the elements and the projected symbols - both may be needed here
+			            Map<Object, Integer> lookupMap = new HashMap<Object, Integer>();
+			            for(int i=0; i<elements.size(); i++) { 
+			                Object element = elements.get(i);
+		                    mapElementToIndex(lookupMap, element, new Integer(i), group);        
+			            }
+			            for(int i=0; i<projectedSymbols.size(); i++) { 
+			            	Object element = projectedSymbols.get(i);
+		                    mapElementToIndex(lookupMap, element, new Integer(columnMap[i]), group);
+			            }
+					    
+					    int updated = 0;
+					    for(int i=0; i<tuples.length; i++) {
+			                try {
+			    				if(new Evaluator(lookupMap, null, null).evaluate(update.getCriteria(), tuples[i])) {
+			                        updated++;
+			                    }
+			                } catch(CriteriaEvaluationException e) {
+			                    throw new TeiidComponentException(e, e.getMessage());
+			                }
+					    }
+				    	List<Integer> updateTuple = new ArrayList<Integer>(1);
+				    	updateTuple.add( new Integer(updated) );
+	                    filteredTuples.add(updateTuple);
+					}
+				} else {
+					filteredTuples.add(Arrays.asList(1)); //TODO: check for bulk
+				}
+			}
+		    tuples = new List[filteredTuples.size()];
+		    filteredTuples.toArray(tuples);
+		    elements = new ArrayList<Object>(projectedSymbols);
+		    columnMap[0] = 0;
+		}		
+				
+        FakeTupleSource ts= new FakeTupleSource(elements, tuples, projectedSymbols, columnMap);
+		if(this.blockOnce){
+            ts.setBlockOnce();
+		}
+        return ts;
+	}
+    
+    private GroupSymbol getQueryGroup(Query query) throws TeiidComponentException {
+        GroupSymbol group;
+        From from = query.getFrom();
+        List groups = from.getGroups();
+        if(groups.size() != 1) { 
+        	throw new TeiidComponentException("Cannot build fake tuple source for command: " + query);	 //$NON-NLS-1$
+        }
+        group = (GroupSymbol) groups.get(0);
+        Iterator projSymbols = query.getSelect().getProjectedSymbols().iterator();
+        while (projSymbols.hasNext()) {
+            Object symbol = projSymbols.next();
+            if (symbol instanceof ElementSymbol){
+                ElementSymbol elementSymbol = (ElementSymbol)symbol;
+                GroupSymbol g = elementSymbol.getGroupSymbol();
+                if (!g.equals(group)){
+                    throw new TeiidComponentException("Illegal symbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                if (elementSymbol.getMetadataID() == null){
+                    throw new TeiidComponentException("Illegal null metadata ID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
+                } else if (elementSymbol.getMetadataID() instanceof TempMetadataID){
+                    throw new TeiidComponentException("Illegal TempMetadataID in ElementSymbol " + elementSymbol + " in SELECT of command: " + query);    //$NON-NLS-1$ //$NON-NLS-2$
+                }
+            }
+        }
+        return group;
+    }
+
+    /**
+     * @param lookupMap
+     * @param element
+     * @param integer
+     * @param group
+     */
+    private void mapElementToIndex(Map lookupMap, Object element, Integer index, GroupSymbol group) {
+        if (group.getDefinition() != null){
+            String groupAlias = group.getCanonicalName();
+            ElementSymbol elementSymbol = (ElementSymbol)SymbolMap.getExpression((SingleElementSymbol)element);
+            String newName = groupAlias + "." + elementSymbol.getShortName(); //$NON-NLS-1$
+            ElementSymbol aliasedElement = new ElementSymbol(newName, elementSymbol.getDisplayFullyQualified());
+            aliasedElement.setGroupSymbol(elementSymbol.getGroupSymbol());
+            aliasedElement.setMetadataID(elementSymbol.getMetadataID());
+            aliasedElement.setType(elementSymbol.getType());
+            lookupMap.put(aliasedElement, index);
+        } else {
+            lookupMap.put(element, index);
+        }
+    }    
+	
+	//   columnMap[expectedElementIndex] = allElementIndex
+	private int[] getColumnMap(List allElements, List expectedElements) {
+		int[] map = new int[expectedElements.size()];
+		
+		for(int i=0; i<expectedElements.size(); i++) { 
+		    SingleElementSymbol symbol = (SingleElementSymbol) expectedElements.get(i);
+		    
+		    if (symbol instanceof AliasSymbol) {
+		        symbol = ((AliasSymbol)symbol).getSymbol();
+		    }
+		    
+		    String shortName = symbol.getShortName();
+		    
+		    // Find matching short name in all elements
+		    boolean foundMatch = false;
+		    for(int j=0; j<allElements.size(); j++) { 
+				SingleElementSymbol tupleSymbol = (SingleElementSymbol) allElements.get(j);
+				if(tupleSymbol.getShortName().equalsIgnoreCase(shortName)) {
+				    map[i] = j;
+				    foundMatch = true;
+				    break;
+				}
+		    }
+		    
+		    if(! foundMatch) { 
+                map[i] = -1;
+		    }
+		}
+		
+		return map;
+	}
+
+
+    public void setThrowBlocked(boolean throwBlocked) {
+        this.throwBlocked = throwBlocked;
+    }
+
+    public void defineCodeTable(String tableName, String keyCol, String retCol, Map values) {
+        String key = tableName.toUpperCase() + keyCol.toUpperCase() + retCol.toUpperCase();
+        this.codeTableValues.put(key, values);
+        this.blockedState.put(key, Boolean.FALSE);                      
+    }
+	
+    public Object lookupCodeValue(
+        CommandContext context,
+        String codeTableName,
+        String returnElementName,
+        String keyElementName,
+        Object keyValue)
+        throws BlockedException, TeiidComponentException {
+            
+            String tableKey = codeTableName.toUpperCase() + keyElementName.toUpperCase() + returnElementName.toUpperCase();
+            if(! codeTableValues.containsKey(tableKey)) {
+                throw new TeiidComponentException("Unknown code table: " + codeTableName); //$NON-NLS-1$
+            }
+        
+            if(throwBlocked) {
+                if(blockedState.get(tableKey).equals(Boolean.FALSE)) { 
+                    blockedState.put(tableKey, Boolean.TRUE);
+                    throw BlockedException.INSTANCE;
+                }
+            }
+        
+            Map values = (Map) codeTableValues.get(tableKey);
+            return values.get(keyValue);
+    }
+
+    public void setBlockOnce() {
+        blockOnce = true;
+    }
+    
+    @Override
+    public void clearCodeTables() {/* does nothing */}
+
+    /**
+     * Are commands/queries that are registered with the data manager being 
+     * recorded?
+     * <p>
+     * Recorded commands can be retrieved by {@link #getQueries()}
+     * 
+	 * @return whether or not commands should be recorded
+	 */
+	public boolean isRecordingCommands() {
+		return recordingCommands;
+	}
+
+	/**
+	 * Indicate whether or not commands/queries registered with the data 
+	 * manager are to be recorded in {@link #queries}.
+	 * <p>
+	 * Recorded commands can be retrieved by {@link #getQueries()}
+     * 
+	 * @param shouldRecord should commands be recorded?
+	 */
+	public void setRecordingCommands(boolean shouldRecord) {
+		this.recordingCommands = shouldRecord;
+	}
+
+	public void registerTuples(QueryMetadataInterface metadata, String groupName, List[] tuples) throws QueryResolverException, TeiidComponentException {
+	    GroupSymbol group = new GroupSymbol(groupName);
+	    ResolverUtil.resolveGroup(group, metadata);
+	    List<ElementSymbol> elementSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
+		this.registerTuples(group.getMetadataID(), elementSymbols, tuples);
+	}
+
+
+}
\ No newline at end of file

Copied: trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/FakeDataStore.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/FakeDataStore.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,321 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.StoredProcedureInfo;
+import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+
+
+
+/** 
+ * This is sample data go along with FakeMetaDataFactory and FakeDataManager
+ */
+public class FakeDataStore {
+    
+    // Helper to create a list of elements - used in creating sample data
+    public static List createElements(List elementIDs) { 
+        List elements = new ArrayList();
+        for(int i=0; i<elementIDs.size(); i++) {
+            FakeMetadataObject elementID = (FakeMetadataObject) elementIDs.get(i);            
+            ElementSymbol element = new ElementSymbol(elementID.getName());
+            elements.add(element);
+        }        
+        
+        return elements;
+    }     
+    
+    private static List getProcResultSetSymbols(List params){
+        List result = new ArrayList();
+        Iterator iter = params.iterator();
+        while(iter.hasNext()){
+            SPParameter param = (SPParameter)iter.next();
+            if(param.getResultSetColumns() != null){
+                result.addAll(param.getResultSetColumns());
+            }
+        }
+        iter = params.iterator();
+        while(iter.hasNext()){
+            SPParameter param = (SPParameter)iter.next();
+            if(param.getParameterType() == ParameterInfo.INOUT || param.getParameterType() == ParameterInfo.RETURN_VALUE) {
+                result.add(param.getParameterSymbol());
+            }
+        }
+        return result;
+    }
+    
+    public static void sampleData1(FakeDataManager dataMgr) throws QueryMetadataException, TeiidComponentException {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        // Group pm1.g1
+        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+        List elementIDs = metadata.getElementIDsInGroupID(groupID);
+        List elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+
+        // Group pm1.g2
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+
+        // Group pm1.g3
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g3"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+            
+        // Group pm2.g1
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+                
+        // Group pm2.g2
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g2"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+
+        // Group pm2.g3
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g3"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+
+        // Group tm1.g1
+        groupID = (FakeMetadataObject) metadata.getGroupID("tm1.g1"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+                Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+                } );    
+
+        //stored procedure pm1.sp1
+        TempMetadataStore tempStore = new TempMetadataStore();          
+        StoredProcedureInfo procInfo = metadata.getStoredProcedureInfoForProcedure("pm1.sp1"); //$NON-NLS-1$
+        elementSymbols = getProcResultSetSymbols(procInfo.getParameters());
+        tempStore.addTempGroup("pm1.sp1", elementSymbols); //$NON-NLS-1$
+        Object procID = tempStore.getTempGroupID("pm1.sp1"); //$NON-NLS-1$
+        dataMgr.registerTuples(
+            procID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { null,  new Integer(1)}),
+                Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(1)}), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(2)}), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
+                } );    
+    }
+
+    public static void sampleData2(FakeDataManager dataMgr) throws QueryMetadataException, TeiidComponentException {
+		FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+
+		// Group pm1.g1
+		FakeMetadataObject groupID = (FakeMetadataObject) metadata
+				.getGroupID("pm1.g1"); //$NON-NLS-1$
+		List elementIDs = metadata.getElementIDsInGroupID(groupID);
+		List elementSymbols = createElements(elementIDs);
+
+		dataMgr.registerTuples(groupID, elementSymbols,
+
+		new List[] {
+				Arrays.asList(new Object[] {
+						"a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
+		});
+
+		// Group pm1.g2
+		groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
+		elementIDs = metadata.getElementIDsInGroupID(groupID);
+		elementSymbols = createElements(elementIDs);
+
+		dataMgr.registerTuples(groupID, elementSymbols,
+
+		new List[] {
+				Arrays.asList(new Object[] {
+						"a", new Integer(1), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(0), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(5), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(2), Boolean.FALSE, null }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"d", new Integer(2), Boolean.FALSE, new Double(1.0) }), //$NON-NLS-1$
+		});
+
+		// Group pm2.g1
+		groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
+		elementIDs = metadata.getElementIDsInGroupID(groupID);
+		elementSymbols = createElements(elementIDs);
+
+		dataMgr.registerTuples(groupID, elementSymbols,
+
+		new List[] {
+				Arrays.asList(new Object[] {
+						"b", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"d", new Integer(3), Boolean.TRUE, new Double(7.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"e", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
+		});
+
+		// Group pm2.g2
+		groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g2"); //$NON-NLS-1$
+		elementIDs = metadata.getElementIDsInGroupID(groupID);
+		elementSymbols = createElements(elementIDs);
+
+		dataMgr.registerTuples(groupID, elementSymbols,
+
+		new List[] {
+				Arrays.asList(new Object[] {
+						"a", new Integer(1), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(0), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(5), Boolean.TRUE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(2), Boolean.FALSE, null }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"d", new Integer(2), Boolean.FALSE, new Double(1.0) }), //$NON-NLS-1$
+		});
+
+		// Group pm1.table1
+		groupID = (FakeMetadataObject) metadata.getGroupID("pm1.table1"); //$NON-NLS-1$
+		elementIDs = metadata.getElementIDsInGroupID(groupID);
+		elementSymbols = createElements(elementIDs);
+
+		dataMgr.registerTuples(groupID, elementSymbols,
+
+		new List[] {
+				Arrays.asList(new Object[] {
+						"a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
+				Arrays.asList(new Object[] {
+						"c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
+		});
+	}                  
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/FakeProcessorPlan.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/FakeProcessorPlan.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/FakeProcessorPlan.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/FakeProcessorPlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,145 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.CommandContext;
+
+
+/**
+ */
+public class FakeProcessorPlan extends ProcessorPlan {
+
+    private List outputElements;
+    private List batches;
+    int batchIndex = 0;
+    private int nextBatchRow = 1;
+    private boolean opened = false;
+    
+    /**
+     * Constructor for FakeProcessorPlan.
+     * @param batches List of things to return in response to nextBatch() - typically 
+     * this is TupleBatch, but it can also be BlockedException or a 
+     * MetaMatrixComponentException.  
+     */
+    public FakeProcessorPlan(List outputElements, List batches) {
+        this.outputElements = outputElements;
+        this.batches = batches;
+    }
+    
+    public FakeProcessorPlan(int counts) {
+    	List[] rows = new List[counts];
+    	for (int i = 0; i < counts; i++) {
+            rows[i] = Arrays.asList(new Object[] {new Integer(1)});
+        }
+        TupleBatch batch = new TupleBatch(1, rows);
+        batch.setTerminationFlag(true);
+        this.batches = Arrays.asList(batch);
+        this.outputElements = Command.getUpdateCommandSymbol();
+    }
+    
+    public boolean isOpened() {
+		return opened;
+	}
+
+    /**
+     * @see java.lang.Object#clone()
+     */
+    public FakeProcessorPlan clone() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#initialize(org.teiid.query.processor.ProcessorDataManager, java.lang.Object, org.teiid.common.buffer.BufferManager, java.lang.String, int)
+     */
+    public void initialize(
+        CommandContext context,
+        ProcessorDataManager dataMgr,
+        BufferManager bufferMgr) {
+            
+        // nothing
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#getOutputElements()
+     */
+    public List getOutputElements() {
+        return this.outputElements;
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#open()
+     */
+    public void open() throws TeiidComponentException {
+    	assertFalse("ProcessorPlan.open() should not be called more than once", opened); //$NON-NLS-1$
+        opened = true;
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#nextBatch()
+     */
+    public TupleBatch nextBatch() throws BlockedException, TeiidComponentException {
+        if(this.batches == null || this.batches.size() == 0 || batchIndex >= this.batches.size()) {
+            // Return empty terminator batch
+            TupleBatch batch = new TupleBatch(nextBatchRow, Collections.EMPTY_LIST);  
+            batch.setTerminationFlag(true);
+            return batch;  
+        }
+        Object nextReturn = this.batches.get(batchIndex);
+        batchIndex++;
+
+        if(nextReturn instanceof TupleBatch) { 
+            TupleBatch batch = (TupleBatch) nextReturn;
+            nextBatchRow = nextBatchRow + batch.getRowCount();
+            return batch;
+        }
+        throw (TeiidComponentException) nextReturn;
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#close()
+     */
+    public void close() throws TeiidComponentException {
+        // nothing
+    }
+
+    /**
+     * @see org.teiid.query.processor.ProcessorPlan#getSchema()
+     */
+    public List getSchema() {
+        return this.outputElements;
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/FakeTupleSource.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/FakeTupleSource.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/FakeTupleSource.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/FakeTupleSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,125 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.common.buffer.*;
+import org.teiid.core.TeiidComponentException;
+
+
+public class FakeTupleSource implements TupleSource {
+    
+    public static class FakeComponentException extends TeiidComponentException {
+        
+    }
+
+	private List elements;
+	private List[] tuples;
+	private int index = 0;
+	private List expectedSymbols;
+	private int[] columnMap;
+    
+    //used to test blocked exception. If true,
+    //the first time nextTuple is called, it will throws BlockedExceptiom
+    private boolean blockOnce;
+    
+    private boolean exceptionOnClose;
+	
+	public FakeTupleSource(List elements, List[] tuples) {
+		this.elements = elements;
+		this.tuples = tuples; 
+	}
+
+	public FakeTupleSource(List elements, List[] tuples, List expectedSymbols, int[] columnMap) {
+		this.elements = elements;
+		this.tuples = tuples; 
+		this.expectedSymbols = expectedSymbols;
+		this.columnMap = columnMap;
+	}
+
+	public List getSchema() { 
+        List theElements = null;        
+	    if(expectedSymbols != null) {
+			theElements = expectedSymbols;
+	    } else {
+	    	theElements = elements;    
+	    }
+        
+        return theElements;
+	}
+	
+	public void openSource()
+		throws TeiidComponentException {				
+		
+		index = 0;
+	}
+
+	public List nextTuple()
+		throws TeiidComponentException {
+	
+        if(this.blockOnce){
+            this.blockOnce = false;
+            throw BlockedException.INSTANCE;            
+        }
+        
+		if(index < tuples.length) { 
+		    // Get full data tuple, with elements
+		    List tuple = tuples[index++];
+		    
+		    if(expectedSymbols == null) { 
+		        return tuple;
+		    }
+		    // Build mapped data tuple, with expectedSymbols
+		    List mappedTuple = new ArrayList(expectedSymbols.size());
+		    for(int i=0; i<columnMap.length; i++) { 
+		    	int colIndex = columnMap[i];
+                if(colIndex >= 0) {
+                    mappedTuple.add( tuple.get(colIndex) );
+                } else {
+                    mappedTuple.add( null );
+                }
+		    }		    
+			return mappedTuple;
+		}
+		return null;
+	}
+
+	public void closeSource() {
+	}
+    
+    public void setBlockOnce(){
+        this.blockOnce = true;
+    }
+
+    public void setExceptionOnClose(boolean exceptionOnClose) {
+        this.exceptionOnClose = exceptionOnClose;
+    }
+    
+    @Override
+    public int available() {
+    	return 0;
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/HardcodedDataManager.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,157 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.CommandContext;
+
+
+
+/** 
+ * @since 4.2
+ */
+public class HardcodedDataManager implements
+                                 ProcessorDataManager {
+
+    // sql string to data
+    private Map data = new HashMap();
+    
+    // valid models - if null, any is assumed valid
+    private Set validModels;
+    
+    private boolean mustRegisterCommands = true;
+    
+    private boolean blockOnce;
+    
+    // Collect all commands run against this class
+    private Collection commandHistory = new ArrayList(); // Commands
+    
+    public HardcodedDataManager() {
+    	this(true);
+    }
+    
+    public HardcodedDataManager(boolean mustRegisterCommands) {
+    	this.mustRegisterCommands = mustRegisterCommands;
+    }
+    
+    public void addData(String sql, List[] rows) {
+        data.put(sql, rows);
+    }
+    
+    public void clearData() {
+    	this.data.clear();
+    	this.commandHistory.clear();
+    }
+    
+    public void setBlockOnce(boolean blockOnce) {
+		this.blockOnce = blockOnce;
+	}
+    
+    /**
+     * Set of model names that are valid.  Invalid ones will throw an error. 
+     * @param models
+     * @since 4.2
+     */
+    public void setValidModels(Set models) {
+        this.validModels = models;
+    }
+    
+    /**
+     * Return collection of Command that has occurred on this data manager 
+     * @return
+     * @since 4.2
+     */
+    public Collection getCommandHistory() {
+        return this.commandHistory;
+    }
+    
+    /** 
+     * @see org.teiid.query.processor.ProcessorDataManager#lookupCodeValue(org.teiid.query.util.CommandContext, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
+     * @since 4.2
+     */
+    public Object lookupCodeValue(CommandContext context,
+                                  String codeTableName,
+                                  String returnElementName,
+                                  String keyElementName,
+                                  Object keyValue) throws BlockedException,
+                                                  TeiidComponentException {
+        return null;
+    }
+    
+    /** 
+     * @see org.teiid.query.processor.ProcessorDataManager#registerRequest(java.lang.Object, org.teiid.query.sql.lang.Command, java.lang.String, String, int)
+     * @since 4.2
+     */
+    public TupleSource registerRequest(Object processorID,
+                                Command command,
+                                String modelName,
+                                String connectorBindingId, int nodeID) throws TeiidComponentException {
+        
+        if(modelName != null && validModels != null && ! validModels.contains(modelName)) {
+            throw new TeiidComponentException("Detected query against invalid model: " + modelName + ": " + command);  //$NON-NLS-1$//$NON-NLS-2$
+        } 
+        this.commandHistory.add(command);
+        
+        List projectedSymbols = command.getProjectedSymbols();
+
+        List[] rows = (List[]) data.get(command.toString());
+        if(rows == null) {
+            if (mustRegisterCommands) {
+                throw new TeiidComponentException("Unknown command: " + command.toString());  //$NON-NLS-1$
+            }
+            // Create one row of nulls
+            rows = new List[1];
+            rows[0] = new ArrayList();
+            
+            for(int i=0; i<projectedSymbols.size(); i++) {
+                rows[0].add(null);
+            }
+        }
+        
+        FakeTupleSource source = new FakeTupleSource(projectedSymbols, rows);
+        if (blockOnce) {
+        	source.setBlockOnce();
+        }
+        return source;
+    }
+
+    public void setMustRegisterCommands(boolean mustRegisterCommands) {
+        this.mustRegisterCommands = mustRegisterCommands;
+    }
+
+	public void clearCodeTables() {
+		
+	}
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestAggregateProcessing.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,286 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.teiid.query.processor.TestProcessor.*;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestAggregatePushdown;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestAggregateProcessing {
+
+	static void sampleDataBQT3(FakeDataManager dataMgr) throws Exception {
+		QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+		// Group bqt1.smalla
+
+		List[] tuples = new List[20];
+		for (int i = 0; i < tuples.length; i++) {
+			tuples[i] = new ArrayList(17);
+			tuples[i].add(new Integer(i));
+			tuples[i].add("" + i); //$NON-NLS-1$
+			tuples[i].add(new Integer(i + 1));
+			for (int j = 0; j < 14; j++) {
+				tuples[i].add(null);
+			}
+		}
+
+		dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
+
+		tuples = new List[20];
+		for (int i = 0; i < tuples.length; i++) {
+			tuples[i] = new ArrayList(17);
+			tuples[i].add(new Integer(i));
+			for (int j = 0; j < 16; j++) {
+				tuples[i].add(null);
+			}
+		}
+
+		dataMgr.registerTuples(metadata, "bqt2.mediumb", tuples); //$NON-NLS-1$
+	}
+
+	private void sampleDataBQT_defect9842(FakeDataManager dataMgr) throws Exception {
+		QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+		List[] tuples = new List[5];
+		for (int i = 0; i < tuples.length; i++) {
+			int k = i + 10;
+			tuples[i] = new ArrayList(17);
+			if (i < 2) {
+				tuples[i].add(new Integer(1)); // need duplicate values
+			} else {
+				tuples[i].add(new Integer(2)); // need duplicate values
+			}
+			tuples[i].add("" + k); //$NON-NLS-1$
+			tuples[i].add(new Integer(k + 1));
+			tuples[i].add("" + (k + 1)); //$NON-NLS-1$
+			tuples[i].add(new Float(0.5));
+			for (int j = 0; j < 8; j++) {
+				tuples[i].add(null);
+			}
+			tuples[i].add(new Short((short) k));
+			tuples[i].add(null);
+			tuples[i].add(new BigDecimal("" + k)); //$NON-NLS-1$
+			tuples[i].add(null);
+		}
+
+		dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
+	}
+
+	@Test public void testAggregateOnBQT() throws Exception {
+		// Create query
+		String sql = "SELECT IntKey, SUM(IntNum) FROM BQT1.SmallA GROUP BY IntKey, IntNum HAVING IntNum > 10 ORDER BY IntKey"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+				Arrays.asList(new Object[] { new Integer(10), new Long(11) }),
+				Arrays.asList(new Object[] { new Integer(11), new Long(12) }),
+				Arrays.asList(new Object[] { new Integer(12), new Long(13) }),
+				Arrays.asList(new Object[] { new Integer(13), new Long(14) }),
+				Arrays.asList(new Object[] { new Integer(14), new Long(15) }),
+				Arrays.asList(new Object[] { new Integer(15), new Long(16) }),
+				Arrays.asList(new Object[] { new Integer(16), new Long(17) }),
+				Arrays.asList(new Object[] { new Integer(17), new Long(18) }),
+				Arrays.asList(new Object[] { new Integer(18), new Long(19) }),
+				Arrays.asList(new Object[] { new Integer(19), new Long(20) }) };
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleDataBQT3(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
+				.exampleBQTCached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void testAggregateOnBQT2() throws Exception {
+		// Create query
+		String sql = "SELECT IntNum, IsNotNull FROM (SELECT IntNum, LongNum, COUNT(IntNum) AS IsNotNull FROM BQT1.SmallA GROUP BY IntNum, LongNum HAVING LongNum IS NULL ) AS x ORDER BY IntNum, IsNotNull"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+				Arrays.asList(new Object[] { new Integer(1), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(2), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(3), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(4), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(5), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(6), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(7), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(8), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(9), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(10), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(11), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(12), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(13), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(14), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(15), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(16), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(17), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(18), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(19), new Integer(1) }),
+				Arrays.asList(new Object[] { new Integer(20), new Integer(1) }) };
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleDataBQT3(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
+				.exampleBQTCached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void testAggregateOnBQT_defect9842() throws Exception {
+		// Create query
+		String sql = "SELECT IntKey, SUM((BigDecimalValue)*(ShortValue)-(BigDecimalValue)*(ShortValue)*(FloatNum)) " + //$NON-NLS-1$
+				"AS MySum FROM BQT1.SmallA GROUP BY IntKey ORDER BY IntKey"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+				Arrays.asList(new Object[] { new Integer(1),
+						new BigDecimal("110.5") }), //$NON-NLS-1$
+				Arrays.asList(new Object[] { new Integer(2),
+						new BigDecimal("254.5") }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleDataBQT_defect9842(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory
+				.exampleBQTCached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+	
+    @Test public void testCase186260() {
+        /*
+         * This case revealed that an expression like "COUNT( DISTINCT e1 )", where the type of e1 is 
+         * anything but integer, was not handled properly.  We tried to use "integer" (the type of the
+         * COUNT expression) to work with the e1 tuples.
+         */
+        // Create query 
+        String sql = "SELECT COUNT(DISTINCT pm1.g2.e1), COUNT(DISTINCT pm1.g3.e1) FROM pm1.g2, pm1.g3"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(3), new Integer(3) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @SuppressWarnings("unchecked")
+	@Test public void testAggregatePushdown() {
+    	Command command = helpParse("select e1, count(e2), max(e2) from (select e1, e2, e3 from pm1.g1 union all select e1, e2, e3 from pm1.g2 union all select e1, e2, e3 from pm2.g1) z group by e1"); //$NON-NLS-1$
+    	
+    	FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+    	capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities()); //$NON-NLS-1$
+    	capFinder.addCapabilities("pm2", TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+    	HardcodedDataManager dataManager = new HardcodedDataManager();
+    	
+    	dataManager.addData("SELECT v_0.c_0, COUNT(v_0.c_1), MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0", //$NON-NLS-1$ 
+    			new List[] {
+    				Arrays.asList("a", Integer.valueOf(2), Integer.valueOf(1)), //$NON-NLS-1$
+    			});
+    	dataManager.addData("SELECT v_0.c_0, COUNT(v_0.c_1), MAX(v_0.c_1) FROM (SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g2 AS g_0) AS v_0 GROUP BY v_0.c_0", //$NON-NLS-1$ 
+    			new List[] {
+    				Arrays.asList("a", Integer.valueOf(3), Integer.valueOf(2)), //$NON-NLS-1$
+    			});
+    	dataManager.addData("SELECT g_0.e1, g_0.e2 FROM pm2.g1 AS g_0", //$NON-NLS-1$ 
+    			new List[] {
+    				Arrays.asList("a", Integer.valueOf(3)), //$NON-NLS-1$
+    				Arrays.asList("xyz", Integer.valueOf(4)), //$NON-NLS-1$
+    				Arrays.asList(null, Integer.valueOf(5)),
+    			});
+    	
+    	ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+    	
+    	List[] expected = new List[] { 
+                Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(5)),
+                Arrays.asList("a", Integer.valueOf(6), Integer.valueOf(3)), //$NON-NLS-1$
+                Arrays.asList("xyz", Integer.valueOf(1), Integer.valueOf(4)) //$NON-NLS-1$
+            };    
+    	
+    	helpProcess(plan, dataManager, expected);
+    }
+    
+	@Test public void testUnionAggregatePushdown() {
+    	Command command = helpParse("select count(*), max(e3) from (select e1, e2, e3 from pm1.g1 union all (select convert(e2, string) as a, e2, e3 from pm2.g2 order by a limit 10)) x group by e1, e2"); //$NON-NLS-1$
+    	
+    	FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+    	capFinder.addCapabilities("pm1", TestAggregatePushdown.getAggregateCapabilities()); //$NON-NLS-1$
+    	BasicSourceCapabilities bac = TestAggregatePushdown.getAggregateCapabilities();
+    	bac.setFunctionSupport("convert", true); //$NON-NLS-1$
+    	capFinder.addCapabilities("pm2", bac); //$NON-NLS-1$
+    	HardcodedDataManager dataManager = new HardcodedDataManager();
+    	
+    	dataManager.addData("SELECT v_0.c_1, v_0.c_0, COUNT(*), MAX(v_0.c_2) FROM (SELECT g_0.e2 AS c_0, g_0.e1 AS c_1, g_0.e3 AS c_2 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0, v_0.c_1", //$NON-NLS-1$ 
+    			new List[] {
+    				Arrays.asList("2", Integer.valueOf(2), Integer.valueOf(2), Boolean.FALSE), //$NON-NLS-1$
+    				Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(3), Boolean.TRUE), //$NON-NLS-1$
+    			});
+    	dataManager.addData("SELECT v_0.c_1, v_0.c_0, COUNT(*), MAX(v_0.c_2) FROM (SELECT g_0.e2 AS c_0, convert(g_0.e2, string) AS c_1, g_0.e3 AS c_2 FROM pm2.g2 AS g_0 ORDER BY c_1 LIMIT 10) AS v_0 GROUP BY v_0.c_0, v_0.c_1", //$NON-NLS-1$ 
+    			new List[] {
+    				Arrays.asList("1", Integer.valueOf(1), Integer.valueOf(4), Boolean.FALSE), //$NON-NLS-1$
+    			});
+    	
+    	ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+    	
+    	List[] expected = new List[] { 
+                Arrays.asList(Integer.valueOf(7), Boolean.TRUE),
+                Arrays.asList(Integer.valueOf(2), Boolean.FALSE),
+            };    
+    	
+    	helpProcess(plan, dataManager, expected);
+    }
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestBaseProcessorPlan.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestBaseProcessorPlan.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestBaseProcessorPlan.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestBaseProcessorPlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,49 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.teiid.core.TeiidException;
+
+import junit.framework.TestCase;
+
+
+public class TestBaseProcessorPlan extends TestCase {
+
+    public TestBaseProcessorPlan(String name) {
+        super(name);
+    }
+
+    public void testGetAndClearWarnings() {        
+        FakeProcessorPlan plan = new FakeProcessorPlan(Collections.emptyList(), Collections.emptyList());
+        TeiidException warning = new TeiidException("test"); //$NON-NLS-1$
+        plan.addWarning(warning);
+        
+        List warnings = plan.getAndClearWarnings();
+        assertEquals("Did not get expected number of warnings", 1, warnings.size()); //$NON-NLS-1$
+        assertEquals("Did not get expected warning", warning, warnings.get(0)); //$NON-NLS-1$
+        assertNull("Did not clear warnings from plan", plan.getAndClearWarnings());         //$NON-NLS-1$
+    }
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestBatchIterator.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,55 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
+import org.teiid.query.processor.BatchIterator;
+import org.teiid.query.processor.relational.FakeRelationalNode;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
+
+ at SuppressWarnings("nls")
+public class TestBatchIterator {
+
+	@Test public void testReset() throws Exception {
+		BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
+			Arrays.asList(1),
+			Arrays.asList(1),
+			Arrays.asList(1)
+		}, 1));
+		BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
+		bi.setBuffer(bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR), true);  //$NON-NLS-1$
+		bi.mark();
+		bi.nextTuple();
+		bi.nextTuple();
+		bi.reset();
+		bi.nextTuple();
+	}
+	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestCollectionTupleSource.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestCollectionTupleSource.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestCollectionTupleSource.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestCollectionTupleSource.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,71 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.query.processor.CollectionTupleSource;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+
+/**
+ */
+public class TestCollectionTupleSource {
+
+    @Test public void testNullSource() {
+        List<SingleElementSymbol> elements = new ArrayList<SingleElementSymbol>();
+        elements.add(new ElementSymbol("x")); //$NON-NLS-1$
+        elements.add(new ElementSymbol("y")); //$NON-NLS-1$
+        CollectionTupleSource nts = CollectionTupleSource.createNullTupleSource(elements);   
+        
+        // Check schema
+        assertEquals("Didn't get expected schema", elements, nts.getSchema()); //$NON-NLS-1$
+        
+        // Walk it and get no data
+        List tuple = nts.nextTuple();
+        nts.closeSource();
+
+        assertEquals("Didn't get termination tuple for first tuple", null, tuple);             //$NON-NLS-1$
+    }
+    
+    @Test public void testUpdateCountSource() {
+        CollectionTupleSource nts = CollectionTupleSource.createUpdateCountTupleSource(5);   
+        
+        // Check schema
+        assertEquals("Didn't get expected schema", Command.getUpdateCommandSymbol(), nts.getSchema()); //$NON-NLS-1$
+        
+        // Walk it and get no data
+        List tuple = nts.nextTuple();
+        nts.closeSource();
+
+        assertEquals("Didn't get termination tuple for first tuple", Arrays.asList(5), tuple);             //$NON-NLS-1$
+    }
+
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestDependentJoins.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,785 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.relational.JoinNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+
+import junit.framework.TestCase;
+
+
+
+public class TestDependentJoins extends TestCase {
+    
+    /** 
+     * @param sql
+     * @return
+     */
+    static ProcessorPlan helpGetPlan(String sql) {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(2));
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false); //fake data manager doesn't support order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(TestProcessor.helpParse(sql),
+                                                       FakeMetadataFactory.example1Cached(),
+                                                       capFinder);
+        return plan;
+    }
+    
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin1() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin2() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       ProcessorPlan plan = helpGetPlan(sql);
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin3() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin4() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND concat(pm1.g1.e1, 'a') = concat(pm2.g1.e1, 'a') AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin5() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, 'a') = concat(pm2.g1.e1, 'a') AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    public void testMultiCritDepJoin5a() { 
+        // Create query 
+        String sql = "SELECT X.e1 FROM pm1.g1 as X, pm2.g1 WHERE concat(X.e1, 'a') = concat(pm2.g1.e1, 'a') AND X.e2=pm2.g1.e2 order by x.e1"; //$NON-NLS-1$
+       
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };    
+       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+   public void testMultiCritDepJoin5b() { 
+       //Create query 
+       String sql = "SELECT X.e1, X.e2 FROM pm1.g1 as X, pm2.g1 WHERE concat(X.e1, convert(X.e4, string)) = concat(pm2.g1.e1, convert(pm2.g1.e4, string)) AND X.e2=pm2.g1.e2 order by x.e1 option makedep x"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b", new Integer(2) }), //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = concat(pm2.g1.e1, '') AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin6() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = concat(pm2.g1.e1, '') AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, '') = pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 */
+    public void testMultiCritDepJoin7() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE concat(pm1.g1.e1, '') = pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = pm2.g1.e1 AND pm1.g1.e2 <> pm2.g1.e2 */
+    public void testMultiCritDepJoin8() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1 = pm2.g1.e1 AND pm1.g1.e2 <> pm2.g1.e2 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql);
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 <> pm2.g1.e2 */
+    public void testMultiCritDepJoin9() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 <> pm2.g1.e2 option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { null }),
+           Arrays.asList(new Object[] { null }),
+           Arrays.asList(new Object[] { null }),
+           Arrays.asList(new Object[] { null }),
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }     
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e3=pm2.g1.e3 AND pm1.g1.e2=pm2.g1.e2 AND pm2.g1.e1 = 'a' */
+    public void testMultiCritDepJoin10() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e3=pm2.g1.e3 AND pm1.g1.e2=pm2.g1.e2 AND pm2.g1.e1 = 'a' option makedep pm1.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }       
+
+    public void testLargeSetInDepJoinWAccessPatternCausingSortNodeInsertCanHandleAlias() {
+        helpTestDepAccessCausingSortNodeInsert(true);
+    }
+    
+    public void testLargeSetInDepJoinWAccessPatternCausingSortNodeInsertCannotHandleAlias() {
+        helpTestDepAccessCausingSortNodeInsert(false);
+    }
+    
+    public void helpTestDepAccessCausingSortNodeInsert(boolean accessNodeHandlesAliases) {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e2=b.e2 AND a.e1 = b.e1 OPTION MAKEDEP a"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+              Arrays.asList(new Object[] { "aa ", "aa ", new Integer(0)}), //$NON-NLS-1$ //$NON-NLS-2$
+             Arrays.asList(new Object[] { "bb   ", "bb   ", new Integer(1)}), //$NON-NLS-1$ //$NON-NLS-2$
+             Arrays.asList(new Object[] { "cc  ", "cc  ", new Integer(2)}) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData2b(dataManager);
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        if(accessNodeHandlesAliases) {
+            depcaps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        }
+        
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        
+        capFinder.addCapabilities("pm4", depcaps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Slightly modify metadata to set max set size to just a few rows - this
+        // will allow us to test the dependent overflow case
+        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
+        
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
+        
+        //Verify a dependent join (not merge join) was used
+        assertTrue(plan instanceof RelationalPlan);
+        RelationalPlan relationalPlan = (RelationalPlan)plan;
+        RelationalNode project = relationalPlan.getRootNode();
+        RelationalNode join = project.getChildren()[0];
+        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);          
+    }
+    
+    public void testCase5130() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        String sql = "select a.intkey from bqt1.smalla a, bqt1.smallb b where concat(a.stringkey, 't') = b.stringkey option makedep a"; //$NON-NLS-1$ 
+         
+        // Plan query 
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, new String[] {"SELECT a.stringkey, a.intkey FROM bqt1.smalla AS a", "SELECT b.stringkey FROM bqt1.smallb AS b"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] { 
+            2,      // Access 
+            0,      // DependentAccess 
+            0,      // DependentSelect 
+            0,      // DependentProject 
+            0,      // DupRemove 
+            0,      // Grouping 
+            0,      // Join 
+            1,      // MergeJoin 
+            0,      // Null 
+            0,      // PlanExecution 
+            2,      // Project 
+            1,      // Select 
+            0,      // Sort 
+            0       // UnionAll 
+        });
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("SELECT g_0.stringkey FROM bqt1.smallb AS g_0",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1t" }), //$NON-NLS-1$
+                                         Arrays.asList(new Object[] { "2" })}); //$NON-NLS-1$
+        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1) })}); //$NON-NLS-1$
+        
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(1) }), 
+        };
+        
+        TestProcessor.helpProcess(plan, dataManager, expected);
+        
+        assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey, a.intkey FROM bqt1.smalla AS a WHERE concat(a.stringkey, 't') IN ('1', '2')")); //$NON-NLS-1$
+    }
+    
+    public void testCase5130a() throws Exception {
+        HardcodedDataManager dataManager = helpTestDependentJoin(false);
+        
+        assertFalse(dataManager.getCommandHistory().contains("SELECT a.stringkey, a.intkey FROM bqt2.smalla AS a WHERE (concat(a.stringkey, 't') IN ('1t', '2')) AND (a.intkey IN (1))")); //$NON-NLS-1$
+    }
+    
+    public void testUnlimitedIn() throws Exception {
+    	helpTestDependentJoin(true);
+    }
+
+	private HardcodedDataManager helpTestDependentJoin(boolean unlimitIn)
+			throws TeiidComponentException, TeiidProcessingException {
+		FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
+        if (unlimitIn) {
+        	caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, -1);
+        }
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        
+        String sql = "select a.intkey from bqt1.smalla a, bqt2.smallb b where concat(a.stringkey, 't') = b.stringkey and a.intkey = b.intkey option makedep a"; //$NON-NLS-1$ 
+         
+        // Plan query 
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), null, capFinder, 
+                                                    new String[] {"SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0 WHERE g_0.intkey IN (<dependent values>)", "SELECT g_0.stringkey, g_0.intkey FROM bqt2.smallb AS g_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] { 
+            unlimitIn?2:1,      // Access 
+            unlimitIn?0:1,      // DependentAccess 
+            0,      // DependentSelect 
+            0,      // DependentProject 
+            0,      // DupRemove 
+            0,      // Grouping 
+            0,      // Join 
+            1,      // MergeJoin 
+            0,      // Null 
+            0,      // PlanExecution 
+            2,      // Project 
+            1,      // Select 
+            0,      // Sort 
+            0       // UnionAll 
+        });
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt2.smallb AS g_0",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1t", new Integer(1) }), //$NON-NLS-1$
+                                         Arrays.asList(new Object[] { "2t", new Integer(2) })}); //$NON-NLS-1$
+        dataManager.addData("SELECT g_0.stringkey, g_0.intkey FROM bqt1.smalla AS g_0 WHERE g_0.intkey IN (1, 2)",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1) })}); //$NON-NLS-1$
+        
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(1) }), 
+        };
+        
+        TestProcessor.helpProcess(plan, dataManager, expected);
+		return dataManager;
+	}
+    
+    static void sampleData4(FakeDataManager dataMgr) throws Exception {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        // Group pm1.g1
+        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+        List elementIDs = metadata.getElementIDsInGroupID(groupID);
+        List elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                } );       
+            
+        // Group pm6.g1
+        groupID = (FakeMetadataObject) metadata.getGroupID("pm6.g1"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { "b",   new Integer(0) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "d",   new Integer(3) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { "e",   new Integer(1) }), //$NON-NLS-1$
+                } );      
+    }
+
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1 */
+    public void testLargeSetInDepAccess() throws Exception {
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1"; //$NON-NLS-1$
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData4(dataManager);
+
+        // Slightly modify metadata to set max set size to just a few rows - this
+        // will allow us to test the dependent overflow case
+        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm6", depcaps); //$NON-NLS-1$
+
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] {
+                new String("b")})}; //$NON-NLS-1$
+
+        Command command = TestProcessor.helpParse(sql);
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+
+    public void testLargeSetInDepAccessMultiJoinCriteria() {
+        //     Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e1=pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by e1 OPTION MAKEDEP pm2.g1"; //$NON-NLS-1$
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+
+        // Slightly modify metadata to set max set size to just a few rows - this
+        // will allow us to test the dependent overflow case
+        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", depcaps); //$NON-NLS-1$
+
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] {
+                new String("a")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("a")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("a")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("a")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("a")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("b")}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {
+                new String("c")})}; //$NON-NLS-1$
+
+        Command command = TestProcessor.helpParse(sql);
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+
+    }
+
+    public void testLargeSetInDepAccessWithAccessPattern() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e1=b.e1 AND a.e2 = b.e2"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] {
+                "aa ", "aa ", new Integer(0)}), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] {
+                "bb   ", "bb   ", new Integer(1)}), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] {
+                "cc  ", "cc  ", new Integer(2)}) //$NON-NLS-1$ //$NON-NLS-2$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData2b(dataManager);
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+        depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+
+        capFinder.addCapabilities("pm4", depcaps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1Cached();
+
+        Command command = TestProcessor.helpParse(sql);
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
+
+        //Verify a dependent join (not merge join) was used
+        assertTrue(plan instanceof RelationalPlan);
+        RelationalPlan relationalPlan = (RelationalPlan)plan;
+        RelationalNode project = relationalPlan.getRootNode();
+        RelationalNode join = project.getChildren()[0];
+        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    /** SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g1.e2 = -100 OPTION MAKEDEP pm1.g2 */
+    public void testDependentNoRows() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1 AND pm1.g1.e2 = -100 OPTION MAKEDEP pm1.g2"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+       };    
+        
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+
+    /** SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE (pm1.g1.e2+1)=pm2.g1.e2 OPTION MAKEDEP pm1.g2 */
+    public void testExpressionInDepJoin() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE (pm1.g1.e2+1)=pm2.g1.e2 OPTION MAKEDEP pm2.g1"; //$NON-NLS-1$
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
+           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
+           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
+           Arrays.asList(new Object[] { new Integer(0), new Integer(1) }),
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(2), new Integer(3) })
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       TestProcessor.sampleData1(dataManager);
+       
+       // Plan query
+
+       FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+       BasicSourceCapabilities caps = new BasicSourceCapabilities();
+       caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+       caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+       capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+       capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+       
+       Command command = TestProcessor.helpParse(sql);   
+       ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+       // Run query
+       TestProcessor.helpProcess(plan, dataManager, expected);
+   }    
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestInsertProcessing.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,407 @@
+package org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+import static org.teiid.query.processor.TestProcessor.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+
+
+public class TestInsertProcessing {
+	
+    @Test public void testSelectIntoWithTypeConversion() {
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
+                                    new String[] { "e1", "e2", "e3" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataTypes.FLOAT});
+                                
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(pm1g1);     
+        store.addObjects(pm1g1e);
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("BatchedUpdate{I}",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
+        
+        String sql = "SELECT 1, convert(1, float), convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(1) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+        
+        BatchedUpdateCommand buc = (BatchedUpdateCommand)dataManager.getCommandHistory().iterator().next();
+        Insert insert = (Insert)buc.getUpdateCommands().get(0);
+                
+        Constant value0 = (Constant)insert.getValues().get(0);
+        Constant value1 = (Constant)insert.getValues().get(1);
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
+        assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
+    }
+    
+    
+    @Test public void testSelectInto_Case5569a_BATCH_NO_BULK_NO() {
+        boolean doBatching  = false;
+        boolean doBulkInsert = false;
+        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
+    }    
+    
+    @Test public void testSelectInto_Case5569b_BATCH_YES_BULK_NO() {
+        boolean doBatching  = true;
+        boolean doBulkInsert = false;
+        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
+    }
+    
+    @Test public void testSelectInto_Case5569c_BATCH_NO_BULK_YES() {
+        boolean doBatching  = false;
+        boolean doBulkInsert = true;
+        helpSelectInto_Case5569Processor( doBatching, doBulkInsert );
+    }
+
+    public void helpSelectInto_Case5569Processor( boolean doBatching, boolean doBulkInsert ) {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+ 
+        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching); 
+        caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+
+        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
+                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
+        
+        if (doBulkInsert) {
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
+        } 
+        else 
+        if (doBatching) {
+            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
+        } else {
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
+        }
+
+        String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 INTO pm1.g2 from pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(2) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+        
+        // if not doBulkInsert and is doBatching,
+        //    check the command hist to ensure it contains the expected commands
+        if ( !doBulkInsert && doBatching ) {
+            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(1);
+            assertEquals(2, bu.getUpdateCommands().size());
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
+        }        
+    }
+    
+
+    @Test public void testSelectInto_Case5412a() {
+        
+        // test setting BULK_INSERT capability to true
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+ 
+        caps.setCapabilitySupport(Capability.BULK_UPDATE, true); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
+                                    new String[] { "e1", "e2" }, //$NON-NLS-1$ //$NON-NLS-2$ 
+                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT});
+                                
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(pm1g1);     
+        store.addObjects(pm1g1e);
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES (?, ?)",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
+        
+        String sql = "SELECT 1, convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(1) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+    }
+
+    
+    @Test public void testSelectInto_Case5412b() {
+        
+        // test setting BULK_INSERT capability to false
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        FakeMetadataObject pm1g1 = FakeMetadataFactory.createPhysicalGroup("pm1.g1", pm1); //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+ 
+        caps.setCapabilitySupport(Capability.BULK_UPDATE, false); 
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        List pm1g1e = FakeMetadataFactory.createElements(pm1g1, 
+                                    new String[] { "e1", "e2" }, //$NON-NLS-1$ //$NON-NLS-2$ 
+                                    new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT});
+                                
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(pm1g1);     
+        store.addObjects(pm1g1e);
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("INSERT INTO pm1.g1 (pm1.g1.e1, pm1.g1.e2) VALUES (1, 1.0)",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(1) })}); 
+        
+        String sql = "SELECT 1, convert(1, float) INTO pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(1) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+        
+        Insert insert = (Insert)dataManager.getCommandHistory().iterator().next();
+        
+        Constant value0 = (Constant)insert.getValues().get(0);
+        Constant value1 = (Constant)insert.getValues().get(1);
+        
+        assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
+        assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
+    }
+    
+    @Test public void testInsertIntoWithSubquery_None() {
+        helpInsertIntoWithSubquery( null );
+    }    
+    
+    @Test public void testInsertIntoWithSubquery_Batch() {
+        helpInsertIntoWithSubquery( Capability.BATCHED_UPDATES );
+    }
+    
+    @Test public void testInsertIntoWithSubquery_Bulk() {
+        helpInsertIntoWithSubquery( Capability.BULK_UPDATE );
+    }
+    
+    @Test public void testInsertIntoWithSubquery_Pushdown() {
+        helpInsertIntoWithSubquery( Capability.INSERT_WITH_QUERYEXPRESSION );
+    }
+
+    public void helpInsertIntoWithSubquery( Capability cap ) {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+ 
+        caps.setCapabilitySupport(cap, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+
+        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
+                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
+        
+        if (cap != null) {
+        	switch (cap) {
+	        case BULK_UPDATE:
+	            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
+	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
+	            break;
+	        case BATCHED_UPDATES:
+	            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
+	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
+	            break;
+	        case INSERT_WITH_QUERYEXPRESSION:
+	        	dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
+	                    new List[] { Arrays.asList(new Object[] { new Integer(2)})});
+	        	break;
+	        }
+        } else {
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
+        }
+
+        String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(2) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+        
+        // if not doBulkInsert and is doBatching,
+        //    check the command hist to ensure it contains the expected commands
+        if ( cap == Capability.BATCHED_UPDATES ) {
+            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(1);
+            assertEquals(2, bu.getUpdateCommands().size());
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
+        }        
+    }
+    
+    @Test public void testInsertIntoWithSubquery2_BATCH_NO_BULK_NO() {
+        boolean doBatching  = false;
+        boolean doBulkInsert = false;
+        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
+    }    
+    
+    @Test public void testInsertIntoWithSubquery2_BATCH_YES_BULK_NO() {
+        boolean doBatching  = true;
+        boolean doBulkInsert = false;
+        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
+    }
+    
+    @Test public void testInsertIntoWithSubquery2_BATCH_NO_BULK_YES() {
+        boolean doBatching  = false;
+        boolean doBulkInsert = true;
+        helpInsertIntoWithSubquery2( doBatching, doBulkInsert );
+    }
+
+    public void helpInsertIntoWithSubquery2( boolean doBatching, boolean doBulkInsert ) {
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+ 
+        caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching); 
+        caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert); 
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ 
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+
+        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1)}),     //$NON-NLS-1$
+                                         Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) })});    //$NON-NLS-1$
+        
+        if (doBulkInsert) {
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES (?, ?, ?, ?)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
+        } 
+        else 
+        if (doBatching) {
+            dataManager.addData("BatchedUpdate{I,I}",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(2)})});             
+        } else {
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});
+            dataManager.addData("INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)",  //$NON-NLS-1$ 
+                                new List[] { Arrays.asList(new Object[] { new Integer(1)})});             
+        }
+
+        String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1 UNION ALL SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1"; //$NON-NLS-1$
+//        String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 INTO pm1.g2 from pm1.g1"; //$NON-NLS-1$
+        
+        Command command = helpParse(sql); 
+
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder); 
+        
+        List[] expected = new List[] {   
+            Arrays.asList(new Object[] { new Integer(4) }), 
+        }; 
+        
+        helpProcess(plan, dataManager, expected);
+        
+        // if not doBulkInsert and is doBatching,
+        //    check the command hist to ensure it contains the expected commands
+        if ( !doBulkInsert && doBatching ) {
+            BatchedUpdateCommand bu = (BatchedUpdateCommand)new ArrayList(dataManager.getCommandHistory()).get(2);
+            assertEquals(2, bu.getUpdateCommands().size());
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString() );  //$NON-NLS-1$
+            assertEquals( "INSERT INTO pm1.g2 (pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString() );  //$NON-NLS-1$ 
+        }        
+    }
+    
+    @Test public void testInsertIntoVirtualWithQueryExpression() { 
+        String sql = "insert into vm1.g1 (e1, e2, e3, e4) select * from pm1.g1"; //$NON-NLS-1$
+        
+        List[] expected = new List[] { 
+            Arrays.asList(6),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestInsertProcessing.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestJoinWithFunction.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,439 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2009 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor 
+ * license agreements.  See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ * 
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+import junit.framework.TestCase;
+
+
+/**
+ * <p><code>TestCase</code> to cover processing of JOINs which use a scalar 
+ * function as a symbol or as part of the JOIN criteria.</p>
+ * 
+ * <p>All tests should verify and validate that the scalar function's result 
+ * is being used appropriately from the pre-JOIN and post-JOIN aspect.  Most 
+ * specifically, the results returned from the JOIN should match the expected 
+ * results defined in each test method.</p>
+ * @since 6.0
+ */
+public class TestJoinWithFunction extends TestCase {
+
+	/**
+	 * <p>Test the use of a non-deterministic function on a user command that
+	 * performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed on the result returned from the JOIN and
+	 * is expected to be executed for each row of the final result set.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryMetadataException 
+	 */
+	public void testNonDeterministicPostJoin() throws QueryMetadataException, TeiidComponentException {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. RandomTop is the use of RAND() on
+		 * the user command and should result in unique random numbers for each 
+		 * row in the JOINed output.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, RAND() AS RandomTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"("	+ rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		/*
+		 * Populate a List with our expected results. We can predict the return value
+		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
+		 * number generator. 
+		 */
+		List<?>[] expected = new List[] {
+				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(0.24053641567148587) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(0.0), new Double(0.6374174253501083) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(0.5504370051176339) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+						new Boolean(false), null, new Double(0.5975452777972018) }), };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * <p>Test the use of a non-deterministic function on a source command of a JOIN
+	 * defined by a user command that performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed on the result that will be used for one side
+	 * of the JOIN.  The function should only be executed for each row of the the result
+	 * set returned from the left-side of the JOIN which should result in the same return 
+	 * value for multiple rows of the final result set after the JOIN is completed.  For 
+	 * example, if the left-side query is expected to return one row and the right-side 
+	 * query will return three rows which match the JOIN criteria for the one row on the 
+	 * left-side then the expected result should be that the function be executed once to 
+	 * represent the one row from the left-side and the function's return value will be 
+	 * repeated for each of the three post-JOINed results.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryMetadataException 
+	 */
+	public void testNonDeterministicPreJoin() throws QueryMetadataException, TeiidComponentException {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. TopRandom is the use of RAND() on
+		 * the user command while RandomLeft is the use of RAND() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		/*
+		 * Populate a List with our expected results. We can predict the return value
+		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
+		 * number generator. 
+		 */
+		List<?>[] expected = new List[] {
+				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(0.24053641567148587) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(0.0), new Double(0.6374174253501083) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(0.6374174253501083) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+						new Boolean(false), null, new Double(0.6374174253501083) }), 
+		};
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * <p>Test the use of a non-deterministic function on the sub-command of a user
+	 * command and the user command itself, which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
+	 * @see #testNonDeterministicPostJoin
+	 * @see #testNonDeterministicPreJoin
+	 * @throws TeiidComponentException 
+	 * @throws QueryMetadataException 
+	 */
+	public void testNonDeterministicPrePostJoin() throws TeiidComponentException, QueryMetadataException {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, RAND() AS RandomLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. TopRandom is the use of RAND() on
+		 * the user command while RandomLeft is the use of RAND() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.RandomLeft, RAND() AS RandomTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+		
+		/*
+		 * Populate a List with our expected results. We can predict the return value
+		 * for RAND() because the TestProcessor.helpProcess() method seeds the random 
+		 * number generator. 
+		 */
+		List<?>[] expected = new List[] {
+			Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+					new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+					new Boolean(true), new Double(2.0), new Double(0.24053641567148587), new Double(0.5975452777972018) }),
+			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+					new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+					new Boolean(false), new Double(0.0), new Double(0.6374174253501083), new Double(0.3332183994766498) }),
+			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+					new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+					new Boolean(true), new Double(2.0), new Double(0.6374174253501083), new Double(0.3851891847407185) }),
+			Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+					new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+					new Boolean(false), null, new Double(0.6374174253501083), new Double(0.984841540199809) })
+		};
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * <p>Test the use of a deterministic function on the user command which
+	 * performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed prior to the JOIN being executed and should 
+	 * result in the projected symbol becoming a constant.</p>
+	 * @throws TeiidComponentException
+	 * @throws QueryMetadataException
+	 */
+	public void testDeterministicPostJoin() throws TeiidComponentException, QueryMetadataException {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
+		 * the user command and should result in 10 for each row in the JOINed 
+		 * output.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		/*
+		 * Populate a List with our expected results.  
+		 */
+		List<?>[] expected = new List[] {
+				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(0.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+						new Boolean(false), null, new Double(10) }), 
+		};
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * <p>The function should be executed prior to the JOIN being executed and should 
+	 * result in the projected symbol becoming a constant.</p>
+
+	 * <p>Test the use of a deterministic function on the source command of a JOIN
+	 * defined by a user command which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>The function should be executed prior to the commands from either side of the
+	 * JOIN being executed and merged into user command prior to the JOIN actually being 
+	 * executed.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryMetadataException 
+	 */
+	public void testDeterministicPreJoin() throws QueryMetadataException, TeiidComponentException {
+		// source query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// source query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtLeft is the use of SQRT() 
+		 * within a source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		/*
+		 * Populate a List with our expected results. 
+		 */
+		List<?>[] expected = new List[] {
+				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(0.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+						new Boolean(false), null, new Double(10) }), 
+		};
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * <p>Test the use of a deterministic function on the sub-command of a user
+	 * command and the user command itself, which performs a JOIN of two sources.</p>
+	 * 
+	 * <p>This test combines the PostJoin and PreJoin test cases.</p>
+	 * @throws TeiidComponentException 
+	 * @throws QueryMetadataException 
+	 * @see #testDeterministicPostJoin
+	 * @see #testDeterministicPreJoin
+	 */
+	public void testDeterministicPrePostJoin() throws QueryMetadataException, TeiidComponentException {
+		// sub-query for one side of a JOIN
+		String leftQuery = "SELECT pm1.g1.e1 as ID, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4, SQRT(100) AS SqrtLeft " //$NON-NLS-1$
+				+ "FROM pm1.g1"; //$NON-NLS-1$
+		// sub-query for other side of a JOIN
+		String rightQuery = "SELECT pm2.g2.e1 as ID, pm2.g2.e2, pm2.g2.e3, pm2.g2.e4 " //$NON-NLS-1$
+				+ "FROM pm2.g2"; //$NON-NLS-1$
+
+		// User Command
+		/*
+		 * Return everything from the JOIN. SqrtTop is the use of SQRT(100) on
+		 * the user command while SqrtLeft is the use of SQRT() within a
+		 * source node.
+		 */
+		String sql = "SELECT l.ID, l.e2, l.e3, l.e4, r.ID, r.e2, r.e3, r.e4, l.SqrtLeft, SQRT(100) AS SqrtTop " + //$NON-NLS-1$
+				"FROM (" + leftQuery + ") AS l, " + //$NON-NLS-1$ //$NON-NLS-2$
+				"(" + rightQuery + ") AS r " + //$NON-NLS-1$ //$NON-NLS-2$
+				"WHERE l.ID = r.ID"; //$NON-NLS-1$
+
+		/*
+		 * Populate a List with our expected results. 
+		 */
+		List<?>[] expected = new List[] {
+				Arrays.asList(new Object[] { "a", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(2), "a", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10.0), new Double(10.0) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(0), //$NON-NLS-1$
+						new Boolean(false), new Double(0.0), new Double(10.0), new Double(10.0) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(5), //$NON-NLS-1$
+						new Boolean(true), new Double(2.0), new Double(10.0), new Double(10.0) }),
+				Arrays.asList(new Object[] { "b", new Integer(1), //$NON-NLS-1$
+						new Boolean(true), null, "b", new Integer(2), //$NON-NLS-1$
+						new Boolean(false), null, new Double(10.0), new Double(10.0) }), 
+		};
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        FakeDataStore.sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+	}
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestJoinWithFunction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestOptionalJoins.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestOptionalJoins.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,492 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestOptionalJoins {
+    
+    @Test public void testOptionalJoinNode1() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2 where pm1.g1.e1 = 'a'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode2() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2, pm1.g3 where pm1.g1.e1 = 'a' and pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode3() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode4() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode5() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$       
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode6() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode7() { 
+        // Create query 
+        String sql = "SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode8() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ (select * from pm1.g2) as X on pm1.g1.e1 = x.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode9() { 
+        // Create query 
+        String sql = "SELECT pm1.g2.e1 FROM pm1.g2, /* optional */ vm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode10() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM /* optional */ vm1.g1, pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode11() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ vm1.g2 on pm1.g1.e1 = vm1.g2.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode12() { 
+        // Create query 
+        String sql = "SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN vm1.g1 on pm1.g1.e1 = vm1.g1.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode13() { 
+        // Create query 
+        String sql = "SELECT count(pm1.g1.e1) FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(5) }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode15() { 
+        // Create query 
+        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode16() { 
+        // Create query 
+        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x order by x.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode17() { 
+        // Create query 
+        String sql = "SELECT length(z) FROM /* optional */ pm1.g1, (select distinct e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY y, z) AS x"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(5) }),
+            Arrays.asList(new Object[] { new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(5) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode18() { 
+        // Create query 
+        String sql = "SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }), 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOptionalJoinNode19() { 
+        // Create query 
+        String sql = "SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(6) }), 
+            Arrays.asList(new Object[] { new Integer(6) }), 
+            Arrays.asList(new Object[] { new Integer(5) }), 
+            Arrays.asList(new Object[] { new Integer(5) }), 
+            Arrays.asList(new Object[] { new Integer(6) }), 
+            Arrays.asList(new Object[] { new Integer(6) }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }    
+
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcedureRelational.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcedureRelational.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,764 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.proc.CreateCursorResultSetInstruction;
+import org.teiid.query.processor.proc.ProcedurePlan;
+import org.teiid.query.processor.proc.TestProcedureProcessor;
+import org.teiid.query.processor.relational.DependentProcedureExecutionNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+
+
+public class TestProcedureRelational {
+
+    @Test public void testProcInExistsSubquery() throws Exception {
+        String sql = "select pm1.g1.e1 from pm1.g1 where exists (select * from (EXEC pm1.vsp9(pm1.g1.e2 + 1)) x where x.e1 = pm1.g1.e1)"; //$NON-NLS-1$
+
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+        };    
+
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testProcInSelectScalarSubquery() throws Exception {
+        String sql = "select (EXEC pm1.vsp36(pm1.g1.e2)) from pm1.g1 where pm1.g1.e1 = 'a'"; //$NON-NLS-1$
+
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) }), 
+            Arrays.asList(new Object[] { new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(0) }), 
+        };    
+
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testProcAsTable(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    //virtual group with procedure in transformation
+    @Test public void testAliasedProcAsTable(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 as x where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+
+    @Test public void testAliasedJoin(){
+        String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = 2 and y.param2 = 'b'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "a", new Integer(2), "b", "a"}), //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+
+    
+    @Test public void testAliasedJoin1(){
+        String sql = "select x.param1, x.param2, y.param1, y.param2, x.e1 from pm1.vsp26 as x, pm1.vsp26 as y where x.param1=1 and x.param2='a' and y.param1 = x.param1 and y.param2 = x.param2"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "a", new Integer(1), "a", "a"}), //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    /**
+     * Will fail due to access pattern validation (missing param2 assignment) 
+     */
+    @Test public void testProcAsTable1(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1"; //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
+    }
+
+    /**
+     * Will fail since less than does not constitue an input 
+     */
+    @Test public void testProcAsTable2(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1<1 and param2='a'"; //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false); 
+    }
+    
+    @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') order by param1, param2"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { new Integer(1), "b", "b", new Integer(2)}), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { new Integer(2), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { new Integer(2), "b", "b", new Integer(2)}), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { new Integer(3), "a", "a", new Integer(3)}), //$NON-NLS-1$  //$NON-NLS-2$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    /**
+     * Will fail missing param2 assignment 
+     */
+    @Test public void testProcAsTable4(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=1 and not(param2 = 'a')"; //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
+    }
+    
+    /**
+     * Will fail missing param2 assignment 
+     */
+    @Test public void testProcAsTable5(){
+        String sql = "select param1, param2, e1, e2 from pm1.vsp26 where param1=e2 and param2 = 'a'"; //$NON-NLS-1$
+
+        TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(), null, false);
+    }
+    
+    @Test public void testProcAsTableInJoin(){
+        String sql = "select param1, param2, pm1.vsp26.e2 from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(1), "c", new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(2), "b", new Integer(2)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(3), "a", new Integer(3)}), //$NON-NLS-1$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsTableInSubquery(){
+        String sql = "select param1, param2, pm1.vsp26.e2, (select count(e1) from pm1.vsp26 where param1 = 1 and param2 = 'a') x from pm1.vsp26, pm1.g1 where param1 = pm1.g1.e2 and param2 = pm1.g1.e1 order by param1, param2, e2"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(0), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(1), "c", new Integer(1), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(2), "b", new Integer(2), new Integer(1)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(3), "a", new Integer(3), new Integer(1)}), //$NON-NLS-1$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    private void helpTestProcRelational(String userQuery,
+                                        String inputCriteria,
+                                        String atomicQuery) {
+        ProcessorPlan plan = TestOptimizer.helpPlan(userQuery, FakeMetadataFactory.example1Cached(), 
+            new String[] {} ); 
+        
+        RelationalPlan rplan = (RelationalPlan)plan;
+
+        RelationalNode root = rplan.getRootNode();
+        
+        while (root.getChildren() != null) {
+            root = root.getChildren()[0];
+            
+            if (root instanceof DependentProcedureExecutionNode) {
+                break;
+            }
+        }
+        
+        DependentProcedureExecutionNode dep = (DependentProcedureExecutionNode)root;
+        
+        assertEquals(inputCriteria, dep.getInputCriteria().toString()); 
+        
+        ProcedurePlan pp = (ProcedurePlan)dep.getProcessorPlan();
+        
+        CreateCursorResultSetInstruction ccrsi = (CreateCursorResultSetInstruction)pp.getOriginalProgram().getInstructionAt(0);
+        
+        plan = ccrsi.getCommand();
+        
+        TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+        
+        TestOptimizer.checkAtomicQueries(new String[] {atomicQuery}, plan);
+    }
+    
+    //virtual group with procedure in transaformation
+    @Test public void testProcInVirtualGroup1() {
+        
+        String userQuery = "select e1 from pm1.vsp26 where param1=1 and param2='a'"; //$NON-NLS-1$
+        String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
+        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
+        
+        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
+    }
+
+    //virtual group with procedure in transformation
+    @Test public void testCase3403() {        
+        String userQuery = "select e1 from pm1.vsp26 where param1=2 and param2='a' and 'x'='x'"; //$NON-NLS-1$
+        String inputCriteria = "(pm1.vsp26.param1 = 2) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
+        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
+        
+        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
+    }
+    
+    @Test public void testCase3448() {
+        String userQuery = "select e1 from pm1.vsp26 where (param1=1 and e2=2) and param2='a'"; //$NON-NLS-1$
+        String inputCriteria = "(pm1.vsp26.param1 = 1) AND (pm1.vsp26.param2 = 'a')"; //$NON-NLS-1$
+        String atomicQuery = "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0 WHERE (g_0.e2 >= pm1.vsp26.param1) AND (g_0.e1 = pm1.vsp26.param2)"; //$NON-NLS-1$
+        
+        helpTestProcRelational(userQuery, inputCriteria, atomicQuery);
+    }
+    
+    @Test public void testProcAsVirtualGroup2(){
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup3(){
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup4(){
+        String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, pm1.g2 where P.e1=g2.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup5(){
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2='a' and e1='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup6(){
+        String sql = "SELECT P.e1 as ve3 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1 and param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup7(){
+        String sql = "SELECT e1 FROM (SELECT p.e1, param1, param2 FROM pm1.vsp26 as P, vm1.g1 where P.e1=g1.e1) x where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "a"}) //$NON-NLS-1$ 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testProcAsVirtualGroup10_Defect20164(){
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where (param1=1 and param2='a') and e1='c'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testProcAsVirtualGroup8(){
+        String sql = "SELECT P.e1 as ve3, P.e2 as ve4 FROM pm1.vsp26 as P where param1=1 and param2='a' and e2=3"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", new Integer(3)}), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+
+    //virtual group with procedure in transformation
+    @Test public void testProcAsVirtualGroup9(){
+        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "FOO" }), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }    
+    
+    /**
+     * Relies upon a default value of null for param1 
+     * 
+     * This is marked as defered since it is not desirable to support this behavior for a single default value
+     */
+    public void defer_testProcAsVirtualGroup9a(){
+        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(2112), "a" }), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }    
+    
+    /**
+     * Relies upon a default value of null for both parameters 
+     * 
+     * This is marked as defered since it is not desirable to support this behavior for a single default value
+     */
+    public void defer_testProcAsVirtualGroup9b(){
+        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(2112), null }) 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+
+    /**
+     *  test for defect 22376
+     */
+    @Test public void testParameterPassing() throws Exception {
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        
+        FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.rs1", v1, new String[] {"e1"}, new String[] { DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$ 
+        FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);  //$NON-NLS-1$
+
+        QueryNode n1 = new QueryNode("v1.vp1", "CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; SELECT e1 FROM v1.vp2 where v1.vp2.in = VARIABLES.x; END"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualProcedure("v1.vp1", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1 }), n1); //$NON-NLS-1$
+        
+        FakeMetadataObject p1 = FakeMetadataFactory.createParameter("v1.vp2.in", 2, ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING, null);  //$NON-NLS-1$
+        QueryNode n2 = new QueryNode("v1.vp2", "CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x; declare string VARIABLES.y; VARIABLES.x = '2'; VARIABLES.y = v1.vp2.in; select VARIABLES.y; end"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt2 = FakeMetadataFactory.createVirtualProcedure("v1.vp2", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1, p1 }), n2); //$NON-NLS-1$
+                
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(v1);
+        store.addObject(rs1);
+        store.addObject(vt1);
+        store.addObject(vt2);
+        store.addObject(vt2);
+        
+        String sql = "select * from (exec v1.vp1()) foo"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {  
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$ 
+        };        
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        // Construct data manager with data 
+        // Plan query 
+        ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);        
+        // Run query 
+        TestProcedureProcessor.helpTestProcess(plan, expected, new FakeDataManager());  
+               
+    }
+
+    //virtual group with procedure in transformation
+    @Test public void testCase6395ProcAsVirtualGroup9(){
+        String sql = "SELECT P.e2 as ve3, P.e1 as ve4 FROM pm1.vsp47 as P where param1=1 and param2='a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), "FOO" }), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }    
+        
+    /**
+     *  Case 6395 - This test case will now raise a QueryPlannerException.  param2 is required
+     *  and not nullable.  This case is expected to fail because of 'param2 is null' 
+     */
+    @Test public void testProcAsVirtualGroup2WithNull() throws Exception {
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 is null"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        try {
+        	ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
+            // Run query
+            TestProcessor.doProcess(plan, dataManager, expected, TestProcessor.createCommandContext()); 
+            fail("QueryPlannerException was expected.");  //$NON-NLS-1$
+        } catch (QueryValidatorException e) {
+        	assertEquals("The procedure parameter is not nullable, but is set to null: pm1.vsp26.param2",e.getMessage());  //$NON-NLS-1$
+        }
+    }
+    
+    /**
+     *  Case 6395 - This case is expected to succeed.  param1 and param2 are both required, but nulls 
+     *  are acceptable for both.
+     */
+    @Test public void testProcAsVirtualGroup2WithNull2() throws Exception {
+        String sql = "select * from pm1.vsp47 where param1 is null and param2 is null"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+                Arrays.asList(new Object[] { null, new Integer(2112), null, null }) 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+    
+    /**
+     *  Case 6395 - This will not throw an exception and the proc will not be invoked.
+     */
+    @Test public void testProcAsVirtualGroup2WithNull3() throws Exception {
+        String sql = "select e1 from (SELECT * FROM pm1.vsp26 as P where P.e1='a') x where param1=1 and param2 = commandpayload()"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected); 
+    }
+       
+    /*
+     * The following are tests that were removed from the validator.  We are no longer trying to validate a priori whether 
+     * procedure input criteria is valid.  This can be addressed later more generally when we do up front validation of
+     * access patterns and access patterns have a wider range of semantics.
+     * 
+    @Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
+        helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+   
+    @Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
+        helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
+        helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+    
+    @Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
+        helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+    }    
+
+    @Test public void testDefect15861() throws Exception{
+        helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    }
+
+    @Test public void testProcInVirtualGroup1_Defect20164() {
+        helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup2_Defect20164() {
+        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup3_Defect20164() {
+        helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup4_Defect20164() {
+        helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup5_Defect20164() {
+        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup6_Defect20164() {
+        helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }
+
+    @Test public void testProcInVirtualGroup7_Defect20164() {
+        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+    }*/
+    
+    /**
+     * Ensures that dependent procedures are processed 1 at a time so that projected input values
+     * are set correctly.
+     */
+    @Test public void testIssue119() throws Exception {
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        FakeMetadataObject pm1 = FakeMetadataFactory.createPhysicalModel("pm1"); //$NON-NLS-1$
+        
+        FakeMetadataObject in = FakeMetadataFactory.createParameter("v1.vp1.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
+        FakeMetadataObject rs1 = FakeMetadataFactory.createResultSet("v1.vp1.rs1", v1, new String[] {"e1", "e2", "e3", "e4", "e5"}, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ 
+        FakeMetadataObject rs1p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs1);  //$NON-NLS-1$
+
+        QueryNode n1 = new QueryNode("v1.vp1", "CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualProcedure("v1.vp1", v1, Arrays.asList(new FakeMetadataObject[] { rs1p1, in }), n1); //$NON-NLS-1$
+        
+        FakeMetadataObject in1 = FakeMetadataFactory.createParameter("pm1.sp119.in1", 2, SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
+		FakeMetadataObject rs3 = FakeMetadataFactory.createResultSet("pm1.sp119.rs1", pm1, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ 
+        FakeMetadataObject rs3p1 = FakeMetadataFactory.createParameter("ret", 1, SPParameter.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs3);  //$NON-NLS-1$
+		FakeMetadataObject sp1 = FakeMetadataFactory.createStoredProcedure("pm1.sp119", pm1, Arrays.asList(new FakeMetadataObject[] { rs3p1, in1 }), "pm1.sp119");  //$NON-NLS-1$ //$NON-NLS-2$
+
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(pm1);
+        store.addObject(v1);
+        store.addObject(rs1);
+        store.addObject(vt1);
+        store.addObject(sp1);
+        
+        String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5"; //$NON-NLS-1$
+        
+        List<?>[] expected = new List[] {
+        	Arrays.asList(1, 1, 3, 3, 5),	
+        	Arrays.asList(1, 1, 3, 3, 8),
+        	Arrays.asList(1, 1, 6, 6, 8),
+        	Arrays.asList(1, 1, 6, 6, 11),
+        };
+        
+        FakeMetadataFacade metadata = new FakeMetadataFacade(store);
+        
+        // Construct data manager with data 
+        // Plan query 
+        ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);        
+        // Run query 
+        HardcodedDataManager dataManager = new HardcodedDataManager() {
+        	@Override
+        	public TupleSource registerRequest(Object processorID,
+        			Command command, String modelName,
+        			String connectorBindingId, int nodeID)
+        			throws TeiidComponentException {
+        		if (command instanceof StoredProcedure) {
+        			StoredProcedure proc = (StoredProcedure)command;
+        			List<SPParameter> params = proc.getInputParameters();
+        			assertEquals(1, params.size());
+        			int value = (Integer)((Constant)params.get(0).getExpression()).getValue();
+        			return new FakeTupleSource(command.getProjectedSymbols(), new List[] {
+        				Arrays.asList(value+2), Arrays.asList(value+5)
+        			});
+        		}
+        		return super.registerRequest(processorID, command, modelName,
+        				connectorBindingId, nodeID);
+        	}
+        };
+        
+        TestProcedureProcessor.helpTestProcess(plan, expected, dataManager);  
+               
+    }
+    
+    @Test public void testProcRelationalWithNoInputs() {
+    	String sql = "select e1 from pm1.vsp2 order by e1 desc limit 1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+        		Arrays.asList("c") //$NON-NLS-1$
+        };        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        TestProcessor.sampleData1(dataManager);       
+        // Plan query
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, FakeMetadataFactory.example1Cached());  
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,7490 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.Test;
+import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.XMLType;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.FakeFunctionMetadataSource;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestRuleRaiseNull;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.relational.JoinNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.BindVariableVisitor;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.util.VariableContext;
+import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorReport;
+
+
+public class TestProcessor {
+
+	// ################################## TEST HELPERS ################################
+
+    static Command helpParse(String sql) { 
+        // parse
+        try { 
+            return QueryParser.getQueryParser().parseCommand(sql);
+        } catch(TeiidException e) { 
+            throw new TeiidRuntimeException(e);
+        }
+    }
+
+	public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata) { 
+        return helpGetPlan(sql, metadata, null);
+    }
+    
+    public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata, String[] bindings) { 
+        if(DEBUG) System.out.println("\n####################################\n" + sql);  //$NON-NLS-1$
+
+        Command command = helpParse(sql);   
+        
+        // attach bindings
+        if(bindings != null) { 
+            try { 
+                BindVariableVisitor.bindReferences(command, Arrays.asList(bindings), metadata);
+            } catch(Throwable e) {
+                throw new TeiidRuntimeException(e);
+            }
+        }
+        
+    	ProcessorPlan process = helpGetPlan(command, metadata);
+        
+        return process;
+    }
+
+    static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata) {
+        return helpGetPlan(command, metadata, new DefaultCapabilitiesFinder());
+    }
+    
+	static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) {
+        CommandContext context = new CommandContext();
+        context.setProcessorBatchSize(2000);
+        context.setConnectorBatchSize(2000);
+	    return helpGetPlan(command, metadata, capFinder, context);
+    }
+	
+    static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) {
+		if(DEBUG) System.out.println("\n####################################\n" + command); //$NON-NLS-1$
+		AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
+		try {
+			QueryResolver.resolveCommand(command, metadata);
+        
+			ValidatorReport repo  = Validator.validate(command, metadata);
+	        Collection failures = new ArrayList();
+	        repo.collectInvalidObjects(failures);
+	        if (failures.size() > 0){
+	            fail("Exception during validation (" + repo); //$NON-NLS-1$
+	        }        
+			command = QueryRewriter.rewrite(command, metadata, createCommandContext());
+	        ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
+			if(DEBUG) System.out.println("\n" + process); //$NON-NLS-1$
+	        //per defect 10022, clone this plan before processing, just to make sure
+	        //a cloned plan with correlated subquery references (or any cloned plan) can be processed
+	        process = process.clone();
+	        
+	        assertNotNull("Output elements of process plan are null", process.getOutputElements()); //$NON-NLS-1$
+
+			return process;
+        } catch (TeiidComponentException e) {
+            throw new RuntimeException(e);
+		} catch (TeiidProcessingException e) {
+			throw new RuntimeException(e);
+		} finally {
+            if(DEBUG) {
+                System.out.println(analysisRecord.getDebugLog());
+            }
+        }
+	}
+
+    public static void helpProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults) {    
+        CommandContext context = createCommandContext();
+        try {
+			helpProcess(plan, context, dataManager, expectedResults);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+    }
+    
+    public static void helpProcess(ProcessorPlan plan, CommandContext context, ProcessorDataManager dataManager, List[] expectedResults) throws Exception {
+        ProcessorPlan clonePlan = plan.clone();
+        
+        // Process twice to test reset and clone
+        doProcess(plan, dataManager, expectedResults, context);
+        plan.reset();
+        doProcess(plan, dataManager, expectedResults, context);
+
+        // Execute cloned of original plan
+        doProcess(clonePlan, dataManager, expectedResults, context);
+    }
+
+    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager) {
+        helpProcessException(plan, dataManager, null);
+    }
+    
+    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
+    	TupleBuffer tsId = null;
+    	BufferManager bufferMgr = null;
+        try {   
+            bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
+            CommandContext context = new CommandContext("0", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
+            QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
+            processor.setNonBlocking(true);
+            BatchCollector collector = processor.createBatchCollector();
+            tsId = collector.collectTuples();
+            fail("Expected error during processing, but got none."); //$NON-NLS-1$
+        } catch(TeiidException e) {
+            // ignore - this is expected
+            if(expectedErrorMessage != null) {
+                assertEquals(expectedErrorMessage, e.getMessage());
+            }
+        } finally {
+        	if (tsId != null) {
+        		tsId.remove();
+        	}
+        }
+    }
+        
+    public static void doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
+        BufferManagerImpl bufferMgr = BufferManagerFactory.createBufferManager();
+        bufferMgr.setProcessorBatchSize(context.getProcessorBatchSize());
+        bufferMgr.setConnectorBatchSize(context.getProcessorBatchSize());
+        context.getNextRand(0);
+        TupleBuffer id = null;
+        try {
+            QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
+            processor.setNonBlocking(true);
+            BatchCollector collector = processor.createBatchCollector();
+            id = collector.collectTuples();
+            if ( expectedResults != null ) {
+            	examineResults(expectedResults, bufferMgr, id);
+            }
+        } finally {
+        	if (id != null) {
+        		id.remove();
+        	}
+        }
+    }
+
+    /** 
+     * @param expectedResults
+     * @param bufferMgr
+     * @param tsID
+     * @throws TeiidComponentException
+     * @throws TeiidProcessingException 
+     * @since 4.3
+     */
+    static void examineResults(List[] expectedResults,BufferManager bufferMgr,TupleBuffer tsID) 
+        throws TeiidComponentException,SQLException, TeiidProcessingException {
+        
+        // Create QueryResults from TupleSource
+        TupleSource ts = tsID.createIndexedTupleSource();
+        int count = tsID.getRowCount();   
+
+		if(DEBUG) {
+            System.out.println("\nResults:\n" + tsID.getSchema()); //$NON-NLS-1$
+            TupleSource ts2 = tsID.createIndexedTupleSource();
+            for(int j=0; j<count; j++) {
+                System.out.println("" + j + ": " + ts2.nextTuple());	 //$NON-NLS-1$ //$NON-NLS-2$
+            }    
+            ts2.closeSource();
+        }
+        
+        // Compare actual to expected row count
+        assertEquals("Did not get expected row count: ", expectedResults.length, count); //$NON-NLS-1$
+     
+        // Walk results and compare
+        for(int i=0; i<count; i++) { 
+            List record = ts.nextTuple();
+            
+            //handle xml
+            if(record.size() == 1){
+            	Object cellValue = record.get(0);
+            	if(cellValue instanceof XMLType){
+                    XMLType id =  (XMLType)cellValue; 
+                    String actualDoc = id.getString(); 
+                    record = new ArrayList(record);
+                    record.set(0, actualDoc);
+            	}
+            	if (expectedResults[i].size() == 1) {
+                    assertEquals("Row " + i + " does not match expected: ", expectedResults[i].get(0), record.get(0));                 //$NON-NLS-1$ //$NON-NLS-2$
+                    continue;
+            	}
+            }
+            
+            assertEquals("Row " + i + " does not match expected: ", expectedResults[i], record);                 //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        ts.closeSource();
+    }
+
+	public static CommandContext createCommandContext() {
+		Properties props = new Properties();
+		props.setProperty("soap_host", "my.host.com"); //$NON-NLS-1$ //$NON-NLS-2$
+		props.setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
+		CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+        context.setProcessorBatchSize(2000);
+        context.setConnectorBatchSize(2000);
+        context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+		return context;
+	}   
+    	
+    public static void sampleData1(FakeDataManager dataMgr) {
+        try { 
+        	FakeDataStore.sampleData1(dataMgr);
+        } catch(Throwable e) { 
+        	throw new RuntimeException(e);
+        }
+    }                    
+    
+    private void sampleData2(FakeDataManager dataMgr) {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+            List elementIDs = metadata.getElementIDsInGroupID(groupID);
+            List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );       
+
+            // Group pm1.g2
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "a",   new Integer(1),     Boolean.TRUE,   new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(5),     Boolean.TRUE,   new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "d",   new Integer(2),     Boolean.FALSE,  new Double(1.0) }), //$NON-NLS-1$
+                    } ); 
+                
+            // Group pm2.g1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    } );      
+                                     
+            // Group pm1.table1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm1.table1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );                                     
+                                     
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }                  
+
+    private void sampleData2a(FakeDataManager dataMgr) {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+            List elementIDs = metadata.getElementIDsInGroupID(groupID);
+            List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "c",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );       
+                
+            // Group pm2.g1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(7),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    } );      
+
+            // Group pm4.g1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm4.g1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "aa",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "bb",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "cc",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );              
+            
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }    
+    
+    public static void sampleData2b(FakeDataManager dataMgr) {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+            List elementIDs = metadata.getElementIDsInGroupID(groupID);
+            List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "aa ",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "bb   ",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "cc  ",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );       
+                
+            // Group pm2.g1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm2.g1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "b",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "d",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "e",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    } );      
+
+            // Group pm4.g1
+            groupID = (FakeMetadataObject) metadata.getGroupID("pm4.g1"); //$NON-NLS-1$
+            elementIDs = metadata.getElementIDsInGroupID(groupID);
+            elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { "aa ",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "bb   ",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "cc  ",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );       
+            
+            
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }    
+    
+    private void sampleData3(FakeDataManager dataMgr) {
+    	FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+            List elementSymbols = new ArrayList(1);
+            ElementSymbol count = new ElementSymbol("Count"); //$NON-NLS-1$
+            count.setType(Integer.class);
+            elementSymbols.add(count);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { new Integer(1) }),                    
+                    } );    
+        }catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }
+
+    private void sampleDataStringTimestamps(FakeDataManager dataMgr) {
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
+            List elementIDs = metadata.getElementIDsInGroupID(groupID);
+            List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                new List[] { 
+                    Arrays.asList(new Object[] { "Jan 01 2004 12:00:00",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "Dec 31 2004 12:00:00",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "Aug 01 2004 12:00:00",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+                    } );       
+
+                                     
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }     
+    
+    private void sampleDataBQT1(FakeDataManager dataMgr) {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        try { 
+            // Group bqt1.smalla
+        
+            List[] tuples = new List[20];
+            for(int i=0; i<tuples.length; i++) {
+                tuples[i] = new ArrayList(17);
+                tuples[i].add(new Integer(i));
+                for(int j=0; j<16; j++) {
+                    tuples[i].add(null);    
+                }    
+            }
+        
+            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$
+
+            // Group bqt2.mediumb
+            tuples = new List[20];
+            for(int i=0; i<tuples.length; i++) {
+                tuples[i] = new ArrayList(17);
+                tuples[i].add(new Integer(i));
+                for(int j=0; j<16; j++) {
+                    tuples[i].add(null);    
+                }    
+            }
+        
+            dataMgr.registerTuples(metadata, "bqt2.mediumb", tuples); //$NON-NLS-1$
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }
+
+	private void sampleDataBQT2(FakeDataManager dataMgr) {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        String[] groups = new String[] {"bqt1.smalla", "bqt2.smalla", "bqt3.smalla" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    
+        try { 
+            for(int i=0; i<groups.length; i++) {
+                String groupName = groups[i];
+    
+                List[] tuples = new List[30];
+                for(int row=0; row<tuples.length; row++) {
+                    tuples[row] = new ArrayList(17);
+                    tuples[row].add(new Integer(row));
+                    for(int col=0; col<16; col++) {
+                        tuples[row].add(null);    
+                    }    
+                }
+        
+                dataMgr.registerTuples(metadata, groupName, tuples);
+            }
+
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }
+    
+    /**
+     * Just want to register two rows of all the integral types to test AVG 
+     * @param dataMgr
+     * @since 4.2
+     */
+    private void sampleDataBQT_defect11682(FakeDataManager dataMgr) {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        try { 
+            List[] tuples = new List[2];
+            for(int i=1; i<=tuples.length; i++) {
+                int index=i-1;
+                tuples[index] = new ArrayList(17);
+                tuples[index].add(new Integer(i)); //IntKey
+                tuples[index].add(null);
+                tuples[index].add(new Integer(i));
+                tuples[index].add(null);
+                tuples[index].add(new Float(i));
+                tuples[index].add(new Long(i));
+                tuples[index].add(new Double(i));
+                tuples[index].add(new Byte((byte)i));
+                tuples[index].add(null);
+                tuples[index].add(null);
+                tuples[index].add(null);
+                tuples[index].add(null);
+                tuples[index].add(null);
+                tuples[index].add(new Short((short)i));
+                tuples[index].add(new BigInteger(i+"")); //$NON-NLS-1$
+                tuples[index].add(new BigDecimal(i+".0")); //$NON-NLS-1$
+                tuples[index].add(null);
+            }
+            
+            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$ 
+            
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }    
+
+    private void sampleDataBQTSmall(FakeDataManager dataMgr) {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        try { 
+            List[] tuples = new List[1];
+            for(int i=0; i<tuples.length; i++) {
+                tuples[i] = new ArrayList(17);
+                tuples[i].add(new Integer(i));
+                for(int j=0; j<16; j++) {
+                    tuples[i].add(null);    
+                }    
+            }
+        
+            dataMgr.registerTuples(metadata, "bqt1.smalla", tuples); //$NON-NLS-1$ 
+
+        } catch(TeiidException e) { 
+        	throw new RuntimeException(e);
+        }
+    }
+
+    private List createRowWithTimestamp(String tsStr) {
+        Timestamp ts = Timestamp.valueOf(tsStr);
+        return Arrays.asList(new Object[] {
+            new Integer(0), "a", new Integer(1), "a",  //$NON-NLS-1$ //$NON-NLS-2$
+            null, null, null, null, null, null, ts, null, null, null, null, null, null   
+        });
+    }
+            
+    private void sampleDataBQT_case1566(FakeDataManager dataMgr) throws Exception {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        dataMgr.registerTuples(metadata, "bqt1.smalla", new List[] { //$NON-NLS-1$ 
+                createRowWithTimestamp("2002-01-01 10:00:00"), //$NON-NLS-1$
+                createRowWithTimestamp("2002-01-01 14:00:00"), //$NON-NLS-1$
+                createRowWithTimestamp("2002-01-02 10:00:00"), //$NON-NLS-1$
+                createRowWithTimestamp("2002-01-02 14:00:00"), //$NON-NLS-1$
+                createRowWithTimestamp("2002-01-02 19:00:00.01"), //$NON-NLS-1$
+                } );       
+    }                
+                
+    static List getProcResultSetSymbols(List params){
+    	List result = new ArrayList();
+    	Iterator iter = params.iterator();
+    	while(iter.hasNext()){
+    		SPParameter param = (SPParameter)iter.next();
+    		if(param.getResultSetColumns() != null){
+    			result.addAll(param.getResultSetColumns());
+    		}
+    	}
+    	iter = params.iterator();
+    	while(iter.hasNext()){
+    		SPParameter param = (SPParameter)iter.next();
+            if(param.getParameterType() == ParameterInfo.INOUT || param.getParameterType() == ParameterInfo.RETURN_VALUE) {
+                result.add(param.getParameterSymbol());
+            }
+    	}
+    	return result;
+    }      
+    
+    @Test public void test1() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void test2() { 
+        // Create query 
+        String sql = "SELECT COUNT(*) FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(6) })
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void test3() { 
+        // Create query 
+        String sql = "SELECT COUNT(*), COUNT(e1), COUNT(distinct e1), COUNT(distinct e2), COUNT(distinct e3), COUNT(distinct e4) FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(6), new Integer(5), new Integer(3), new Integer(4), new Integer(2), new Integer(4) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+ 
+	/** see also integer average defect 11682 */
+    @Test public void test4() { 
+        // Create query 
+        String sql = "SELECT MIN(e2), MAX(e2), SUM(e2), AVG(e2), SUM(distinct e2), AVG(distinct e2) FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), new Integer(3), new Long(7), new Double(1.1666666666666667), new Long(6), new Double(1.5) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+    
+	@Test public void test5() { 
+        // Create query 
+        String sql = "SELECT MIN(e4), MAX(e4), SUM(e4), AVG(e4), SUM(distinct e4), AVG(distinct e4) FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Double(0.0), new Double(7.0), new Double(12.0), new Double(2.4), new Double(10.0), new Double(2.5) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void test7() { 
+        // Create query 
+        String sql = "SELECT * FROM vm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void test8() { 
+        // Create query 
+        String sql = "SELECT * FROM vm1.g2 order by 1, 2, 3"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,  null }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+    
+	@Test public void test9() { 
+        // Create query 
+        String sql = "SELECT * FROM vm1.g4 order by e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+    
+	@Test public void test10() { 
+        // Create query 
+        String sql = "SELECT e1 FROM vm1.g4 where e1 = 'a'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+    @Test public void testBooleanComparisonGT() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 > {b'false'}"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { Boolean.TRUE }), 
+            Arrays.asList(new Object[] { Boolean.TRUE }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testBooleanComparisonGE() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 >= {b'false'}"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.TRUE }), 
+            Arrays.asList(new Object[] { Boolean.TRUE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testBooleanComparisonLT() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 < {b'true'}"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testBooleanComparisonLE() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e3 FROM pm1.g1 WHERE e3 <= {b'true'}"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.TRUE }), 
+            Arrays.asList(new Object[] { Boolean.TRUE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }), 
+            Arrays.asList(new Object[] { Boolean.FALSE }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+ 
+    @Test public void testConcatOperator() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1 || e2 AS x FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "a3" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a0" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+ 	/** Duplicates defect #4841: SELECT e1 a, e1 b FROM pm1.g1 order by a */
+ 	@Test public void testDefect4841_1() { 
+        // Create query 
+        String sql = "SELECT e1 a, e1 b FROM pm1.g1 order by a"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null,  null }),
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+		};    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+	}
+
+    /** Duplicates defect #4841: SELECT e1 a, e1 b FROM pm1.g1 order by a, b desc */
+    @Test public void testDefect4841_2() { 
+        // Create query 
+        String sql = "SELECT e1 a, e1 b FROM pm1.g1 order by a"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null,  null }),
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** Duplicates defect #5292: SELECT DISTINCT e1, e1 a FROM pm1.g1 */
+    @Test public void testDefect5292_1() { 
+        // Create query 
+        String sql = "SELECT DISTINCT e1, e1 a FROM pm1.g1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null,  null }),
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** Duplicates defect #5292: SELECT DISTINCT e1, e1 a FROM pm1.g1 ORDER BY a */
+    @Test public void testDefect5292_2() { 
+        // Create query 
+        String sql = "SELECT DISTINCT e1, e1 a FROM pm1.g1 ORDER BY a"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null,  null }),
+            Arrays.asList(new Object[] { "a",   "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b",   "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c",   "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** Duplicates defect #5004: SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx' */
+    @Test public void testDefect5004() { 
+        // Create query 
+        String sql = "SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) })
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * Test to ensure that multiple empty batches are handled by the grouping node as well
+     */
+    @Test public void testDefect5004a() throws Exception { 
+        // Create query 
+        String sql = "SELECT COUNT(*) FROM pm1.g1 WHERE e1='xxxx'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) })
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        CommandContext context = createCommandContext();
+        context.setProcessorBatchSize(2);
+        context.setConnectorBatchSize(2);
+        context.setMetadata(FakeMetadataFactory.example1Cached());
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
+
+        // Run query
+        helpProcess(plan, context, dataManager, expected);
+    }
+
+    /** SELECT COUNT(e2), MIN(e2), MAX(e2), SUM(e2), AVG(e2) FROM pm1.g1 WHERE e2=-999999 */
+    @Test public void test13() { 
+        // Create query 
+        String sql = "SELECT COUNT(e2), MIN(e2), MAX(e2), SUM(e2), AVG(e2) FROM pm1.g1 WHERE e2=-999999"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] {new Integer(0), null, null, null, null})
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * This test uncovered a bug in the FakeDataManager; the element
+     * symbol in the atomic query criteria has a canonical name 
+     * of "Y.e4", but the FakeDataManager sends a Map of ElementSymbols
+     * having the unaliased names.  The first symbol cannot be found
+     * in the Map due to the implementation of Symbol.equals() being
+     * based entirely on the canonical name, which causes a NPE.
+     * (Alex says this wasn't previously a problem because aliased groups
+     * did not previously get pushed down to the source.)
+     */
+    @Test public void testCriteriaAliasedGroup() {
+        String sql = "select e1, e2 FROM pm2.g1 Y WHERE 2.0 = e4"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** SELECT e1 FROM pm1.g1 WHERE 'abc' = 'xyz' */
+    @Test public void testCriteriaComparesUnequalConstants() { 
+        // Create query 
+        String sql = "SELECT e1 FROM pm1.g1 WHERE 'abc' = 'xyz'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+     /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
+     @Test public void testRightOuterJoin1() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 RIGHT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { null, "d" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null, "e" }) //$NON-NLS-1$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+     /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 LEFT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
+     @Test public void testLeftOuterJoin1() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 LEFT OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    /** SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1 */
+    @Test public void testFullOuterJoin1() throws Exception { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e1, pm2.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm2.g1 ON pm1.g1.e1=pm2.g1.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null, "d" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null, "e" }) //$NON-NLS-1$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+    
+    @Test public void testFullOuterJoin2() throws Exception { 
+        // Create query 
+        String sql = "SELECT a.e4 c0, b.e4 c1 FROM pm1.g1 a FULL OUTER JOIN pm1.g1 b ON a.e4=b.e4 order by c0"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }),
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { new Double(0), new Double(0) }),
+            Arrays.asList(new Object[] { new Double(2), new Double(2) }), 
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+    
+    @Test public void testFullOuterJoin3() throws Exception { 
+        // Create query 
+        String sql = "SELECT a.e4 c0, b.e4 c1 FROM pm1.g1 b FULL OUTER JOIN (select e4, 1 x from pm1.g1 union all select e4, 2 from pm1.g1) a ON a.e4=b.e4 and a.x = 2 order by c0"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }),
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { null, null }),
+            Arrays.asList(new Object[] { new Double(0), new Double(0) }),
+            Arrays.asList(new Object[] { new Double(0), null }),
+            Arrays.asList(new Object[] { new Double(2), new Double(2) }), 
+            Arrays.asList(new Object[] { new Double(2), null }),
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+     /** SELECT x.e1, pm2.g1.e1 FROM (SELECT e1 FROM pm1.g1) AS x LEFT OUTER JOIN pm2.g1 ON x.e1=pm2.g1.e1 */
+     @Test public void testLeftOuterJoinWithInlineView() { 
+        // Create query 
+        String sql = "SELECT x.e1, pm2.g1.e1 FROM (SELECT e1 FROM pm1.g1) AS x LEFT OUTER JOIN pm2.g1 ON x.e1=pm2.g1.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+    
+    /** SELECT * FROM vm1.g5 ORDER BY expr */
+    @Test public void testDefect5273_1() {
+        // Create query 
+        String sql = "SELECT expr FROM vm1.g5 ORDER BY expr"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    /** SELECT expr AS e FROM vm1.g5 ORDER BY e */
+    @Test public void testDefect5273_2() {
+        // Create query 
+        String sql = "SELECT expr AS e FROM vm1.g5 ORDER BY e"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    /** SELECT e2 AS e FROM vm1.g5 ORDER BY e */
+    @Test public void testDefect5273_3() {
+        // Create query 
+        String sql = "SELECT e2 AS e FROM vm1.g5 ORDER BY e"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(3) })
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    /** SELECT e AS f FROM vm1.g6 ORDER BY f */
+    @Test public void testDefect5273_4() {
+        // Create query 
+        String sql = "SELECT e AS f FROM vm1.g6 ORDER BY f"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }        
+
+    /** SELECT e AS f FROM vm1.g7 ORDER BY f */
+    @Test public void testDefect5273_5() {
+        // Create query 
+        String sql = "SELECT e AS f FROM vm1.g7 ORDER BY f"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a3" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c1" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }        
+
+    /** SELECT e AS f FROM vm1.g7 ORDER BY f */
+    @Test public void testDefect5273_6() {
+        // Create query 
+        String sql = "SELECT e AS f FROM vm1.g8 ORDER BY f"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "aval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "bval" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "cval" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }        
+
+    @Test public void testFalseCriteria1() { 
+        // Create query 
+        String sql = "SELECT 5 FROM pm1.g1 WHERE 0=1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testFalseCriteria2() { 
+        // Create query 
+        String sql = "SELECT count(*) FROM pm1.g1 WHERE 0=1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) }),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testTempGroup() { 
+        // Create query 
+        String sql = "SELECT e1 FROM tm1.g1 WHERE e1 = 'a'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testSubquery1() {
+   		// Create query
+   		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"; //$NON-NLS-1$
+   		
+   		// Create expected results
+   		List[] expected = new List[] {
+   			Arrays.asList(new Object[] { "a" }),	 //$NON-NLS-1$
+   			Arrays.asList(new Object[] { null }),
+   			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+   			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+   			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+   			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+   		}; 	
+   		
+   		// Construct data manager with data
+   		FakeDataManager dataManager = new FakeDataManager();
+   		sampleData1(dataManager);
+   		
+    	// Plan query
+    	ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+   		// Run query
+   		helpProcess(plan, dataManager, expected);
+    }
+
+	@Test public void testSubquerySimple() {
+		// Create query
+		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { null }),
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+	
+	@Test public void testCritInSubquery() {
+		// Create query
+		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1 WHERE e1 = 'a') AS x"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+	
+	@Test public void testCritAboveSubquery() {
+		// Create query
+		String sql = "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x WHERE e1 = 'a'"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}    
+
+	@Test public void testSubqueryInJoinPredicate() {
+		// Create query
+		String sql = "SELECT x.e1 FROM (SELECT e1 FROM pm1.g1) AS x JOIN (SELECT e1 FROM pm1.g1) y ON x.e1=y.e1"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+	@Test public void testSubqueryWithRenaming() {
+		// Create query
+		String sql = "SELECT x.a FROM (SELECT e1 AS a FROM pm1.g1) AS x"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { null }),
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+    @Test public void testNestedSubquery() {
+        // Create query
+        String sql = "SELECT x.a FROM (SELECT e1 AS a FROM (SELECT e1 FROM pm1.g1) AS y) AS x"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null }),
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+	/**
+	 * Tests a single Subquery IN clause criteria
+	 */
+	@Test public void testSubqueryINClause() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * Tests a single Subquery IN clause criteria with nulls
+	 * in sample data
+	 */
+	@Test public void testSubqueryINClauseWithNulls() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e4 IN (SELECT e4 FROM pm2.g1)"; //$NON-NLS-1$
+
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+	
+	/**
+	 * Tests a single Subquery IN clause criteria with nulls
+	 * in sample data
+	 */
+	@Test public void testSubqueryINClauseWithNulls2() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e4 FROM pm2.g1)"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}	
+
+	/**
+	 * Tests a compound criteria of two subqueries in IN clauses
+	 */
+	@Test public void testSubqueryINClauses() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND e1 IN (SELECT e1 FROM pm2.g1)"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+    /**
+     * Tests a compound criteria of a subquery in IN clause and another type of
+     * criteria
+     */
+    @Test public void testSubqueryINClauseMixedCriteria() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND e1 IN ('b')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+	/**
+	 * Tests a compound criteria of a subquery in IN clause and another type of
+	 * criteria
+	 */
+	@Test public void testSubqueryINClauseMixedCriteria2() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1) AND NOT (e1 = 'a')"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+	/**
+	 * Tests nesting of Subquery IN clause criteria
+	 */
+	@Test public void testNestedSubqueryINClauses() {
+		String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1 WHERE e1 IN (SELECT e1 FROM pm1.g1))"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] {
+			Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+		};
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}	
+
+	@Test public void testSubqueryXML() {
+		// Create query
+		String sql = "SELECT * FROM (SELECT * FROM xmltest.doc1) AS x"; //$NON-NLS-1$
+
+		// Create expected results
+		List[] expected = new List[] { 
+			Arrays.asList(new Object[] { 
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
+                    "<root><node1><node2><node3/></node2></node1></root>"             //$NON-NLS-1$
+            })
+		};    
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData1(dataManager);
+
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+		// Run query
+		helpProcess(plan, dataManager, expected);
+	}
+
+    /**
+     * Tests a single Subquery EXISTS predicate criteria
+     */
+    @Test public void testSubqueryExistsPredicate() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Tests a single Subquery EXISTS predicate criteria 
+     * where the subquery returns no rows
+     */
+    @Test public void testSubqueryExistsPredicate2() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1 WHERE e1 = 'ZZTop')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = ANY (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate2() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = SOME (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate3() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 = ALL (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate4() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 <= ALL (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate5() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < SOME (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicate5a() {
+        String sql = "SELECT e1 FROM pm2.g1 WHERE e2 < SOME (SELECT e2 FROM pm1.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "e" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     * without predicate quantifier
+     */
+    @Test public void testSubqueryComparePredicate6() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < (SELECT e2 FROM pm2.g1 WHERE e1 = 'e')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Tests a single Subquery in compare predicate criteria
+     */
+    @Test public void testSubqueryComparePredicateNested() {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 < SOME (SELECT e2 FROM pm2.g1 WHERE EXISTS (SELECT e2 FROM pm2.g1))"; //$NON-NLS-1$
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List[] { Arrays.asList(new Object[] { new Integer(0), "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+                                                                      Arrays.asList(new Object[] { new Integer(1), "b" }), //$NON-NLS-1$
+                                                                      Arrays.asList(new Object[] { new Integer(2), "c" }), //$NON-NLS-1$
+                                                                      });
+        
+        dataManager.addData("SELECT pm2.g1.e2 FROM pm2.g1", new List[] {  //$NON-NLS-1$
+                                                                 Arrays.asList(new Object[] { new Integer(0) }),
+                                                                 Arrays.asList(new Object[] { new Integer(3) }),
+                                                                 Arrays.asList(new Object[] { new Integer(1) }),                    
+                                                                  });              
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$
+        };
+
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * Tests a scalar subquery in the SELECT clause
+     */
+    @Test public void testSubqueryScalar() {
+        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1 WHERE e1 = 'b') FROM pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Tests a scalar subquery which returns no rows in the SELECT clause
+     */
+    @Test public void testSubqueryScalar2() {
+        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1 WHERE e1 = 'a') FROM pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Tests a scalar subquery which returns more than one rows
+     * causes the expected Exception
+     */
+    @Test public void testSubqueryScalarException() throws Exception {
+        String sql = "SELECT e1, (SELECT e2 FROM pm2.g1) FROM pm1.g1"; //$NON-NLS-1$
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcessException(plan, dataManager);
+    }
+    
+    @Test public void testSubqueryScalarInTransformation() {
+        String sql = "select * from vm1.g25"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  new Double(0.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testSubqueryScalarInTransformation2() {
+        String sql = "select * from vm1.g25 where e5 = 0.0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  new Double(0.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  new Double(0.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    @Test public void testCorrelatedSubquery_CASE2022() {
+        String sql = "select * from BQT2_V WHERE BQT2_V.IntKey < 50"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT1(dataManager);
+        sampleDataBQT2(dataManager);
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_QUANTIFIED_ALL, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.exampleBQTCached(), capFinder);
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+    @Test public void testCorrelatedSubquery1() {
+        String sql = "Select e1, e2, e4 from pm1.g1 where e2 in (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0), new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+
+    }
+    
+    /**
+     * There is a bug when the second query in a UNION ALL has a correlated subquery, and both
+     * the outer and inner query are selecting from the same virtual group, and aliasing them
+     * differently to distinguish between them.  The generated atomic query has screwed up
+     * aliasing. 
+     */
+    @Test public void testCorrelatedSubqueryCase3667() {
+
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        // Plan query
+        String sql = "Select e1, e2, e4 from pm2.g1 where 1=2 " + //$NON-NLS-1$
+           "UNION ALL Select e1, e2, e4 from vm1.g1 outg1 where outg1.e2 in (select ing1.e2 FROM vm1.g1 ing1 WHERE outg1.e4 = ing1.e4)";//$NON-NLS-1$
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+        
+        // Run query
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "aString", new Integer(22), new Double(22.0) }), //$NON-NLS-1$
+        };
+
+        dataManager.addData("SELECT g_0.e1, g_0.e2, g_0.e4 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM pm1.g1 AS g_1 WHERE g_1.e4 = g_0.e4)",  //$NON-NLS-1$
+                            expected);
+        
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    /** control query, this test passes */
+    @Test public void testCorrelatedSubqueryCase3667a() {
+
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Plan query
+        String sql = "Select e1, e2, e4 from vm1.g1 outg1 where outg1.e2 in (select ing1.e2 FROM vm1.g1 ing1 WHERE outg1.e4 = ing1.e4)";//$NON-NLS-1$
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+        
+        // Run query
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "aString", new Integer(22), new Double(22.0) }), //$NON-NLS-1$
+        };
+        
+        dataManager.addData("SELECT g_0.e1, g_0.e2, g_0.e4 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM pm1.g1 AS g_1 WHERE g_1.e4 = g_0.e4)",  //$NON-NLS-1$
+                            expected);
+        
+        helpProcess(plan, dataManager, expected);
+    }     
+
+    @Test public void testCorrelatedSubquery2() {
+        String sql = "Select e1, e2 from pm1.g1 where e2 in (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+
+    }
+
+    @Test public void testCorrelatedSubquery3() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 WHERE pm1.g1.e4 = pm2.g1.e4) from pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testCorrelatedSubquery3a() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 WHERE X.e4 = e4) from pm1.g1 X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    @Test public void testCorrelatedSubquery3b() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = e4) from pm1.g1 X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubquery3c() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from pm1.g1 X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testCorrelatedSubquery4() {
+        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select e2 FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    @Test public void testCorrelatedSubquery4a() {
+        String sql = "Select e1, e2 from pm1.g1 X where e2 = some (select e2 FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+    @Test public void testCorrelatedSubquery_defect9968() {
+        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select max(X.e2) FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+
+    @Test public void testCorrelatedSubquery_defect9968a() {
+        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select ((X.e2)/2) as e FROM pm2.g1 WHERE X.e4 = pm2.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+
+    @Test public void testCorrelatedSubquery_defect9968b() {
+        String sql = "Select e1, e2 from pm1.g1 X where e2 in (select (select e2 as e FROM pm2.g1 WHERE X.e4 = pm2.g1.e4) as e FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+
+    @Test public void testCorrelatedSubquery_defect10021() {
+        String sql = "Select e1, e2 from table1 X where e4 in (select max(Y.e4) FROM table1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", new Integer(2) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+    
+    /** 
+     * Note the subquery has a multi-column result - conceptually this is
+     * legal for the EXISTS predicate
+     */
+    @Test public void testCorrelatedSubquery5() {
+        String sql = "Select * from pm1.g1 where exists (select * FROM pm2.g1 WHERE pm1.g1.e1 = e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }       
+
+    /** 
+     * Count the # of parent rows for which no child rows exist
+     */
+    @Test public void testCorrelatedSubquery6() {
+        String sql = "Select count(*) from pm1.g1 where not (exists (select * FROM pm2.g1 WHERE pm1.g1.e1 = e1))"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { new Integer(2) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /** 
+     * Select e2, e4, and the avg of e4 for each group of e1
+     */
+    @Test public void testCorrelatedSubquery7() {
+        String sql = "select e2, e4, (select avg(e4) FROM pm1.g1 Y WHERE X.e1 = e1) from pm1.g1 X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) }),
+            Arrays.asList(new Object[] { new Integer(1), new Double(1.0), null }),
+            Arrays.asList(new Object[] { new Integer(3), new Double(7.0), new Double(3.6666666666666665) }),
+            Arrays.asList(new Object[] { new Integer(1), null ,           null }),
+            Arrays.asList(new Object[] { new Integer(2), new Double(0.0), new Double(0.0) }),
+            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    /** 
+     * Select e2, e4, and the avg of e4 for each group of e1
+     */
+    @Test public void testCorrelatedSubquery8() {
+        String sql = "select X.e2, X.e4, (select avg(Y.e4) FROM pm1.g1 Y WHERE X.e1 = Y.e1) from pm1.g1 X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) }),
+            Arrays.asList(new Object[] { new Integer(1), new Double(1.0), null }),
+            Arrays.asList(new Object[] { new Integer(3), new Double(7.0), new Double(3.6666666666666665) }),
+            Arrays.asList(new Object[] { new Integer(1), null ,           null }),
+            Arrays.asList(new Object[] { new Integer(2), new Double(0.0), new Double(0.0) }),
+            Arrays.asList(new Object[] { new Integer(0), new Double(2.0), new Double(3.6666666666666665) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+    @Test public void testCorrelatedSubqueryVirtualLayer1() {
+        String sql = "Select e1, e2 from vm1.g1 X where e2 in (select e2 FROM vm1.g1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer2() {
+        String sql = "Select e1, e2 from vm1.g2 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g2.e4 = vm1.g1.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer3() {
+        String sql = "Select e2 from vm1.g6 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g6.e = e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer4() {
+        String sql = "Select e2 from vm1.g7 where e2 in (select e2 FROM vm1.g1 WHERE vm1.g7.e = e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer5() {
+        String sql = "Select e1 from vm1.g4 where not (e1 in (select e1 FROM vm1.g1 WHERE vm1.g4.e1 = e1)) order by e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
+        };
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer6() {
+        String sql = "Select e2 from vm1.g1 X where e2 in (select X.e2 FROM vm1.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(3) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(0) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer6a() {
+        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g5)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(3) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(0) })
+        };
+
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer6b() {
+        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g2)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(3) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(0) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer6c() {
+        String sql = "Select e2 from vm1.g7 where e2 in (select vm1.g7.e FROM vm1.g1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer6e() {
+        String sql = "Select e2 from vm1.g1 where e2 in (select vm1.g1.e2 FROM vm1.g2a)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(0) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(3) }),
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(0) })
+        };
+
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryVirtualLayer7() {
+        String sql = "Select e2 from vm1.g7 where e2 in (select vm1.g7.e FROM vm1.g1 WHERE vm1.g7.e = e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[0];
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryInTransformation() {
+        String sql = "Select * from vm1.g21"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+    
+    @Test public void testCorrelatedSubqueryInTransformation2() {
+        String sql = "Select * from vm1.g20"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    @Test public void testCorrelatedSubqueryInTransformation3() {
+        String sql = "Select * from vm1.g19 order by e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * User correlated subquery, and one of the virtual group transformations
+     * also has a correlated subquery
+     */
+    @Test public void testCorrelatedSubqueryInTransformation4() {
+        String sql = "Select * from vm1.g20 where exists (Select * from vm1.g19 where convert(vm1.g20.e2, string) = vm1.g19.e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }     
+
+    /**
+     * User correlated subquery, and one of the virtual group transformations
+     * also has a correlated subquery
+     */
+    @Test public void testCorrelatedSubqueryInTransformation5() {
+        String sql = "Select * from vm1.g19 where exists (Select e2 from vm1.g20 where convert(e2, string) = vm1.g19.e1) order by e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "0" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+    @Test public void testCorrelatedSubqueryInTransformation6() {
+        String sql = "Select * from vm1.g21 where e2 = some (Select e2 from pm1.g1 where e1 = vm1.g21.e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "b",   new Integer(1),     Boolean.TRUE,   null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+    @Test public void testCorrelatedSubqueryInTransformation7() {
+        String sql = "Select * from vm1.g21 where exists (Select e2 from pm1.g2 where e4 = convert(vm1.g21.e2, double))"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testCorrelatedSubqueryInTransformation8() {
+        String sql = "Select * from vm1.g21 where exists (Select e2 from pm1.g1 where e4 = convert(vm1.g21.e2, double))"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation9() {
+        String sql = "Select * from vm1.g22"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),  //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation10() {
+        String sql = "Select * from vm1.g23"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),  //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation11() {
+        String sql = "Select * from vm1.g24"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }),
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation12() {
+        String sql = "Select * from vm1.g24 X where exists (Select * from vm1.g24 Y where X.e2 = Y.e2)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }),
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation13() {
+        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g25 where pm1.g1.e4 = e5 and e4=0.0) as e5 from pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    } 
+    
+    @Test public void testCorrelatedSubqueryInTransformation14() {
+        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g26 where pm1.g1.e4 = e5 and e4=0.0) as e5 from pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }     
+
+    @Test public void testCorrelatedSubqueryInTransformation15() {
+        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a'"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
+    @Test public void testCorrelatedSubqueryInTransformation15a() {
+        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select * from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueryInTransformation15b() {
+        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a' and exists (select * from vm1.g23 where vm1.g22.e3 = e3)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
+    @Test public void testCorrelatedSubqueryInTransformation15c() {
+        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select e1, e2, e3, e4, e5 as e from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }   
+
+    /** Test selecting a virtual element (e5) which is defined by a scalar subquery in the virtual transformation */
+    @Test public void testCorrelatedSubqueryInTransformation15d() {
+        String sql = "Select e1, e2, e3, e4 from pm1.g1 where exists (select e1, e2, e3, e4, ((e4 + e5)/(e4 + 1)) as e from vm1.g26 where pm1.g1.e3 = e3)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,           }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+// Here is select * from vm1.g26
+//  Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }),
+//  Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
+//  Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }),
+//  Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),
+//  Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }),
+//  Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null })
+
+
+    @Test public void testCorrelatedSubqueryInTransformation16() {
+//        String sql = "Select e1, e2, e3, e4, (select e4 from vm1.g23 where vm1.g22.e4 = e5) as e5 from vm1.g22 where e1 = 'a'"/* and exists (select * from vm1.g23 where vm1.g22.e3 = e3)"*/;
+        String sql = "select * from vm1.g26 where e5 = 0.0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[]{
+//            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null }),
+//            Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0),  null }),
+//            Arrays.asList(new Object[] { "a",   new Integer(3),     Boolean.TRUE,   new Double(7.0),  null }),
+//            Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null,             null }),
+            Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0),  new Double(0.0) }), //$NON-NLS-1$
+//            Arrays.asList(new Object[] { "a",   new Integer(0),     Boolean.FALSE,  new Double(2.0),  null })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }  
+
+    @Test public void testCorrelatedSubqueriesNested() {
+        String sql = 
+                    "Select e1, e2, e4 from pm1.g1 where e2 < all (" + //$NON-NLS-1$
+                    "select e2 from pm1.g2 where pm1.g1.e1 = e1 and exists("+ //$NON-NLS-1$
+                    "select e2 from pm2.g1 where pm1.g2.e4 = pm2.g1.e4))"; //$NON-NLS-1$
+        Command query = helpParse(sql);
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0), new Double(2.0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", new Integer(1), null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", new Integer(2), new Double(0.0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(query, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** defect 15124 */
+    @Test public void testCorrelatedSubqueryAndInlineView() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select * from pm1.g1) as X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+    
+    /** defect 15124 */
+    @Test public void testCorrelatedSubqueryAndInlineView2() {
+        String sql = "Select e1 from (select * from pm1.g1) as X WHERE e2 IN (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }    
+
+    /** defect 15124 */
+    @Test public void testCorrelatedSubqueryAndInlineView3() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select * from pm1.g1 UNION ALL select * from pm1.g1) as X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }    
+
+    /** defect 15124 */
+    @Test public void testCorrelatedSubqueryAndInlineView4() {
+        String sql = "Select e1, (select e2 FROM pm2.g1 Y WHERE X.e4 = Y.e4) from (select pm1.g1.e1, (select pm1.g1.e2 from pm1.g1 Z where pm1.g1.e1 = Z.e1), pm1.g1.e3, pm1.g1.e4 from pm1.g1) as X"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", null }), //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }    
+    
+    @Test public void testXMLUnion_defect8373() {
+        // Create query
+        String sql = "SELECT * FROM xmltest.doc5"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] {
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
+                "<root><node1><node2>a</node2></node1><node1><node2/></node1><node1><node2>a</node2></node1><node1><node2>c</node2></node1><node1><node2>b</node2></node1><node1><node2>a</node2></node1><node1><node2>a</node2></node1><node1><node2/></node1><node1><node2>a</node2></node1><node1><node2>c</node2></node1><node1><node2>b</node2></node1><node1><node2>a</node2></node1></root>" //$NON-NLS-1$
+            })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testStoredQuery1() {
+        // Create query
+        String sql = "EXEC pm1.sq1()"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null,  new Integer(1) }),
+            Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c",   new Integer(1) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b",   new Integer(2) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testStoredQuery2() {
+        // Create query
+        String sql = "EXEC pm1.sq2(\'a\')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0) }),  //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(3) }),    //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a",   new Integer(0) })        //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+        
+    @Test public void testStoredQuery3() {
+        // Create query
+        String sql = "select x.e1 from (EXEC pm1.sq1()) as x"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null}),
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testStoredQuery4() {
+        // Create query
+        String sql = "EXEC pm1.sq5('a')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", new Integer(0)}),             //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(3) }),             //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testStoredQuery5() {
+        // Create query
+        String sql = "EXEC pm1.sp1()"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a",   new Integer(0) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { null,  new Integer(1)}),
+                    Arrays.asList(new Object[] { "a",   new Integer(3) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "c",   new Integer(1)}), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b",   new Integer(2)}), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "a",   new Integer(0) }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testStoredQuery6() {
+        // Create query
+        String sql = "EXEC pm1.sqsp1()"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { null}),
+                    Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "c"}), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testStoredQuery7() {
+        // Create query
+        String sql = "EXEC pm1.sq17()"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { 
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
+                    "<root><node1><node2><node3/></node2></node1></root>"             //$NON-NLS-1$
+            })
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+
+    // implict type conversion of parameter
+    @Test public void testStoredQuery8() {
+        // Create query
+        String sql = "EXEC pm1.sq5(5)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    // function for parameter
+    @Test public void testStoredQuery9() {
+        // Create query
+        String sql = "EXEC pm1.sq5(concat('a', ''))"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** named parameters */
+    @Test public void testStoredQuery10() {
+        // Create query
+        String sql = "EXEC pm1.sq3b(\"in\" = 'a', in3 = 'something')"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(0)}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(3) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(0) }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    @Test public void testInsert() {
+        // Create query
+        String sql = "Insert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values ('MyString', 1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1)})
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData3(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA FULL OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
+     @Test public void testDefect7770_FullOuter() { 
+        // Create query 
+        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA FULL OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
+            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
+            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
+            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
+            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
+            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
+            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
+            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
+            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
+            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA RIGHT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
+     @Test public void testDefect7770_RightOuter() { 
+        // Create query 
+        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA RIGHT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
+            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
+            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
+            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
+            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
+            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
+            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
+            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
+            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
+            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+     /** SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20) */
+     @Test public void testDefect7770_LeftOuter() { 
+        // Create query 
+        String sql = "SELECT BQT1.SmallA.IntKey AS SmallA_IntKey, BQT2.MediumB.IntKey AS MediumB_IntKey FROM BQT1.SmallA LEFT OUTER JOIN BQT2.MediumB ON BQT1.SmallA.IntKey = BQT2.MediumB.IntKey WHERE (BQT1.SmallA.IntKey >= 0) AND (BQT1.SmallA.IntKey <= 15) AND (BQT2.MediumB.IntKey >= 5) AND (BQT2.MediumB.IntKey <= 20)"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
+            Arrays.asList(new Object[] { new Integer(6), new Integer(6) }),
+            Arrays.asList(new Object[] { new Integer(7), new Integer(7) }),
+            Arrays.asList(new Object[] { new Integer(8), new Integer(8) }),
+            Arrays.asList(new Object[] { new Integer(9), new Integer(9) }),
+            Arrays.asList(new Object[] { new Integer(10), new Integer(10) }),
+            Arrays.asList(new Object[] { new Integer(11), new Integer(11) }),
+            Arrays.asList(new Object[] { new Integer(12), new Integer(12) }),
+            Arrays.asList(new Object[] { new Integer(13), new Integer(13) }),
+            Arrays.asList(new Object[] { new Integer(14), new Integer(14) }),
+            Arrays.asList(new Object[] { new Integer(15), new Integer(15) })
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testReorder1() {
+        // Create query
+        String sql = "SELECT e1 AS x, {b'false'}, e2+e4, e3 FROM pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(2.0), Boolean.FALSE }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { null, Boolean.FALSE, new Double(2.0), Boolean.FALSE }),
+            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(10.0), Boolean.TRUE }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c", Boolean.FALSE, null, Boolean.TRUE }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "b", Boolean.FALSE, new Double(2.0), Boolean.FALSE }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", Boolean.FALSE, new Double(2.0), Boolean.FALSE }) //$NON-NLS-1$
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testTwoFullOuterJoins1() {
+        // Create query
+        String sql = "SELECT A.IntKey AS A_IntKey, B.IntKey AS B_IntKey, C.IntKey AS C_IntKey " +  //$NON-NLS-1$
+        "FROM (BQT1.SmallA AS A FULL OUTER JOIN BQT2.SmallA AS B ON A.IntKey = B.IntKey) FULL OUTER JOIN BQT3.SmallA AS C ON B.IntKey = C.IntKey " +  //$NON-NLS-1$
+        "WHERE (A.IntKey >= 0) AND (A.IntKey <= 15) " +  //$NON-NLS-1$
+        "AND (B.IntKey >= 5) AND (B.IntKey <= 20) " +  //$NON-NLS-1$
+        "AND (C.IntKey >= 10) AND (C.IntKey <= 30)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(10), new Integer(10), new Integer(10) }),
+            Arrays.asList(new Object[] { new Integer(11), new Integer(11), new Integer(11) }),
+            Arrays.asList(new Object[] { new Integer(12), new Integer(12), new Integer(12) }),
+            Arrays.asList(new Object[] { new Integer(13), new Integer(13), new Integer(13) }),
+            Arrays.asList(new Object[] { new Integer(14), new Integer(14), new Integer(14) }),
+            Arrays.asList(new Object[] { new Integer(15), new Integer(15), new Integer(15) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testSelectDistinctOnBQT() {
+       // Create query
+       String sql = "SELECT DISTINCT IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
+
+       // Create expected results
+       List[] expected = new List[] {
+           Arrays.asList(new Object[] { new Integer(0) }),
+           Arrays.asList(new Object[] { new Integer(1) }),
+           Arrays.asList(new Object[] { new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(3) }),
+           Arrays.asList(new Object[] { new Integer(4) }),
+           Arrays.asList(new Object[] { new Integer(5) }),
+           Arrays.asList(new Object[] { new Integer(6) }),
+           Arrays.asList(new Object[] { new Integer(7) }),
+           Arrays.asList(new Object[] { new Integer(8) }),
+           Arrays.asList(new Object[] { new Integer(9) }),
+           Arrays.asList(new Object[] { new Integer(10) }),
+           Arrays.asList(new Object[] { new Integer(11) }),
+           Arrays.asList(new Object[] { new Integer(12) }),
+           Arrays.asList(new Object[] { new Integer(13) }),
+           Arrays.asList(new Object[] { new Integer(14) }),
+           Arrays.asList(new Object[] { new Integer(15) }),
+           Arrays.asList(new Object[] { new Integer(16) }),
+           Arrays.asList(new Object[] { new Integer(17) }),
+           Arrays.asList(new Object[] { new Integer(18) }),
+           Arrays.asList(new Object[] { new Integer(19) })
+       };
+
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleDataBQT1(dataManager);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+   
+   @Test public void testSelectWithNoFrom() { 
+       // Create query 
+       String sql = "SELECT 5"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(5) })
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+   
+   @Test public void testBetween() { 
+       // Create query 
+       String sql = "SELECT * FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { null,  new Integer(1),     Boolean.FALSE,  new Double(1.0) }),
+           Arrays.asList(new Object[] { "c",   new Integer(1),     Boolean.TRUE,   null }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { "b",   new Integer(2),     Boolean.FALSE,  new Double(0.0) }) //$NON-NLS-1$
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   /**
+    * Test <code>QueryProcessor</code>'s ability to process a query containing 
+    * a <code>CASE</code> expression in which a <code>BETWEEN</code> 
+    * comparison is used in the queries <code>SELECT</code> statement.
+    * <p>
+    * For example:
+    * <p>
+    * SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1
+    */
+   @Test public void testBetweenInCase() { 
+       // Create query 
+       final String sql = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+               Arrays.asList(new Object[] { new Integer(-1) }),
+               Arrays.asList(new Object[] { new Integer(-1) }),
+               Arrays.asList(new Object[] { new Integer(3) }),
+               Arrays.asList(new Object[] { new Integer(-1) }),
+               Arrays.asList(new Object[] { new Integer(-1) }),
+               Arrays.asList(new Object[] { new Integer(-1) }) 
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   /**
+    * Test <code>QueryProcessor</code>'s ability to process a query containing 
+    * an aggregate SUM with a <code>CASE</code> expression in which a 
+    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
+    * statement.
+    * <p>
+    * For example:
+    * <p>
+    * SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1
+    */
+   @Test public void testBetweenInCaseInSum() { 
+       // Create query 
+       final String sql = "SELECT SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Long(-2) })
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   /**
+    * Test <code>QueryProcessor</code>'s ability to process a query containing 
+    * an aggregate SUM with a <code>CASE</code> expression in which a 
+    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
+    * statement and a GROUP BY is specified.
+    * <p>
+    * For example:
+    * <p>
+    * SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) 
+    * FROM pm1.g1 GROUP BY e1 ORDER BY e1
+    */
+   @Test public void testBetweenInCaseInSumWithGroupBy() { 
+       // Create query 
+       final String sql = "SELECT e1, SUM(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END) FROM pm1.g1 GROUP BY e1 ORDER BY e1"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+    	       Arrays.asList(new Object[] { null,  new Long(-1) }),
+    	       Arrays.asList(new Object[] { "a",   new Long(1) }), //$NON-NLS-1$
+    	       Arrays.asList(new Object[] { "b",   new Long(-1) }), //$NON-NLS-1$
+    	       Arrays.asList(new Object[] { "c",   new Long(-1) }) //$NON-NLS-1$
+       };    
+       
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   /**
+    * Test <code>QueryProcessor</code>'s ability to process a query containing 
+    * an aggregate COUNT with a <code>CASE</code> expression in which a 
+    * <code>BETWEEN</code> comparison is used in the queries <code>SELECT</code> 
+    * statement.
+    * <p>
+    * For example:
+    * <p>
+    * SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1
+    */
+   @Test public void testBetweenInCaseInCount() { 
+       // Create query 
+       final String sql = "SELECT COUNT(CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 END) FROM pm1.g1"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1) })
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   @Test public void testCase() { 
+       // Create query 
+       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 ELSE 3 END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(2), new Integer(3) }) 
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+   
+   @Test public void testSelectNoFrom1() { 
+       // Create query 
+       String sql = "SELECT 1"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1) })
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+   
+   @Test public void testSelectNoFrom2() { 
+       // Create query 
+       String sql = "SELECT 1, {b'true'}, 2.0 AS x, {d'2003-11-04'}"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), Boolean.TRUE, new Double(2.0), TimestampUtil.createDate(103, 10, 4)  })
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+
+   @Test public void testCase1566() throws Exception {
+       // Create query
+       String sql = "SELECT x, COUNT(*) FROM (SELECT convert(TimestampValue, date) AS x FROM bqt1.smalla) as y GROUP BY x"; //$NON-NLS-1$
+
+       // Create expected results
+       List[] expected = new List[] {
+               Arrays.asList(new Object[] { java.sql.Date.valueOf("2002-01-01"), new Integer(2) }),
+               Arrays.asList(new Object[] { java.sql.Date.valueOf("2002-01-02"), new Integer(3) }) };
+
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleDataBQT_case1566(dataManager);
+
+       // Create capabilities
+       FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+       BasicSourceCapabilities caps = new BasicSourceCapabilities();
+       caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
+       caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+       capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+       // Parse query
+       Command command = QueryParser.getQueryParser().parseCommand(sql);
+
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder);
+
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }   
+   
+    @Test public void testDefect10976(){
+        String sql = "SELECT * FROM vm1.g28"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { "A", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "B", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "C", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);       
+    }
+         
+    @Test public void testDefect10976_2(){
+        String sql = "SELECT * FROM vm1.g29"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { "A", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "B", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "C", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);       
+    }         
+    
+    @Test public void testDefect10976_3(){
+        String sql = "SELECT * FROM vm1.g30"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);       
+    }
+
+    @Test public void testDefect10976_4(){
+        String sql = "SELECT * FROM vm1.g31 order by x"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);       
+    }
+
+    @Test public void testDefect10976_5(){
+        String sql = "SELECT * FROM vm1.g32"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", "c" }) //$NON-NLS-1$ //$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);       
+    }
+    
+    @Test public void testDefect11236_MergeJoinWithFunctions() { 
+       // Create query 
+       String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1)"; //$NON-NLS-1$
+       boolean pushDown = false;
+       boolean dependent = false;
+       
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+           Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
+           Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
+           Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
+       };    
+        
+       helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
+    }
+    
+    @Test public void testMergeJoinWithFunctionsPushDown() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1)"; //$NON-NLS-1$
+        boolean pushDown = true;
+        boolean dependent = false;
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
+            Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
+        };    
+         
+        helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
+    }
+    
+    @Test public void testMergeJoinWithFunctionsPushDownDependent() { 
+        // Create query 
+        String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm1.g1.e2 = (pm2.g1.e2+1) option makedep pm1.g1"; //$NON-NLS-1$
+        boolean pushDown = true;
+        boolean dependent = true;
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0) }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0)  }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(1)  }), 
+            Arrays.asList(new Object[] { new Integer(3), new Integer(2)  }) 
+        };    
+         
+        helpTestMergeJoinWithExpression(sql, pushDown, dependent, expected);
+    }
+
+
+    /** 
+     * @param sql
+     * @param pushDown
+     * @param expected
+     */
+    private void helpTestMergeJoinWithExpression(String sql,
+                                                 boolean pushDown,
+                                                 boolean dependent,
+                                                 List[] expected) {
+        // Construct data manager with data
+           ProcessorDataManager dataManager = null;
+           if (!pushDown) {
+               FakeDataManager fakeDataManager = new FakeDataManager();
+               sampleData1(fakeDataManager);
+               dataManager = fakeDataManager;
+           } else {
+               HardcodedDataManager hardCoded = new HardcodedDataManager();
+               List[] results = new List[] { 
+                   Arrays.asList(new Object[] {new Integer(0), new Integer(1)}), 
+                   Arrays.asList(new Object[] {new Integer(0), new Integer(1)}), 
+                   Arrays.asList(new Object[] {new Integer(1), new Integer(2)}),
+                   Arrays.asList(new Object[] {new Integer(1), new Integer(2)}), 
+                   Arrays.asList(new Object[] {new Integer(2), new Integer(3)}), 
+                   Arrays.asList(new Object[] {new Integer(3), new Integer(4)}), 
+                   };
+               hardCoded.addData("SELECT g_0.e2 AS c_0, (g_0.e2 + 1) AS c_1 FROM pm2.g1 AS g_0 ORDER BY c_1", results); //$NON-NLS-1$
+               if (!dependent) {
+                   results = new List[] { 
+                       Arrays.asList(new Object[] {new Integer(0),}), 
+                       Arrays.asList(new Object[] {new Integer(0),}), 
+                       Arrays.asList(new Object[] {new Integer(1),}),
+                       Arrays.asList(new Object[] {new Integer(1),}), 
+                       Arrays.asList(new Object[] {new Integer(2),}), 
+                       Arrays.asList(new Object[] {new Integer(3),}), 
+                       };
+                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", results); //$NON-NLS-1$
+               } else {
+                   results = new List[] { 
+                       Arrays.asList(new Object[] {new Integer(1),}),
+                       Arrays.asList(new Object[] {new Integer(2),}),
+                       Arrays.asList(new Object[] {new Integer(1),}), 
+                       };
+                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (1, 2)", results); //$NON-NLS-1$
+                   results = new List[] { 
+                       Arrays.asList(new Object[] {new Integer(3),}), 
+                       };
+                   hardCoded.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e2 IN (3, 4)", results); //$NON-NLS-1$
+               }
+               dataManager = hardCoded;
+           }
+            
+           FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+           FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+           BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+           caps.setCapabilitySupport(Capability.CRITERIA_IN, pushDown);    
+           caps.setCapabilitySupport(Capability.QUERY_ORDERBY, pushDown);
+           caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(2));
+           caps.setFunctionSupport("+", pushDown); //$NON-NLS-1$
+           finder.addCapabilities("pm1", caps); //$NON-NLS-1$
+           finder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+           // Plan query
+           ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, finder);
+
+           // Run query
+           helpProcess(plan, dataManager, expected);
+    }
+    
+   @Test public void testCase2() { 
+       // Create query 
+       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(2), null }) 
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }
+   
+   @Test public void testCase3() { 
+       // Create query 
+       String sql = "SELECT e2, CASE e2 WHEN 1 THEN 2 ELSE null END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(1), new Integer(2) }),
+           Arrays.asList(new Object[] { new Integer(2), null }) 
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }   
+
+   /** nested scalar subquery */
+   @Test public void testCase4() { 
+       // Create query 
+       String nestedExpression = "(SELECT e1 FROM pm1.g2 WHERE e2 = 3)"; //$NON-NLS-1$
+       String sql = "SELECT e2, CASE e2 WHEN 1 THEN " + nestedExpression + " ELSE null END FROM pm1.g1 WHERE e2 BETWEEN 1 AND 2"; //$NON-NLS-1$ //$NON-NLS-2$
+        
+       // Create expected results
+       List[] expected = new List[] { 
+           Arrays.asList(new Object[] { new Integer(1), "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { new Integer(1), "a" }), //$NON-NLS-1$
+           Arrays.asList(new Object[] { new Integer(2), null }) 
+       };    
+    
+       // Construct data manager with data
+       FakeDataManager dataManager = new FakeDataManager();
+       sampleData1(dataManager);
+        
+       // Plan query
+       ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+       // Run query
+       helpProcess(plan, dataManager, expected);
+   }  
+
+    /** nested correlated scalar subquery */
+    @Test public void testCase5() { 
+        // Create query 
+        String nestedExpression = "(SELECT e2 FROM pm1.g2 WHERE pm1.g1.e2 = (e4 + 2))"; //$NON-NLS-1$
+        String sql = "SELECT e2, CASE e2 WHEN " + nestedExpression + " THEN 1 ELSE null END FROM pm1.g1"; //$NON-NLS-1$ //$NON-NLS-2$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), null }), 
+            Arrays.asList(new Object[] { new Integer(1), null }), 
+            Arrays.asList(new Object[] { new Integer(3), null }), 
+            Arrays.asList(new Object[] { new Integer(1), null }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(1) }), 
+            Arrays.asList(new Object[] { new Integer(0), null }) 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /** 
+     * NOTE: this test depends on the ProcessorPlan being executed 
+     * twice and reset in between, which currently is done in the 
+     * helpProcess method  
+     */
+    @Test public void testDefect12135(){
+        String sql = "SELECT pm1.g1.e1, pm1.g2.e1 FROM pm1.g1 LEFT OUTER JOIN pm1.g2 ON pm1.g1.e1=pm1.g2.e1"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", null }) //$NON-NLS-1$ 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);          
+    }
+    
+    @Test public void testDefect12081(){
+        String sql = "SELECT DISTINCT vm1.g1.e1, upper(vm1.g1.e1) as Nuge, pm1.g1.e1, upper(pm1.g1.e1) as Nuge FROM vm1.g1, pm1.g1"; //$NON-NLS-1$
+
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        }; 
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);          
+    }    
+
+    @Test public void testDefect12081_2(){
+        String sql = "SELECT DISTINCT vm1.g1b.e1, vm1.g1b.e1Upper, pm1.g1.e1, upper(pm1.g1.e1) as e1Upper FROM vm1.g1b, pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "c", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);          
+    }  
+    
+    @Test public void testDefect12081_3(){
+        String sql = "SELECT DISTINCT vm1.g1b.e1, vm1.g1b.e1Upper, pm1.g1.e1, vm1.g1b.e1Upper FROM vm1.g1b, pm1.g1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "A", "a", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "b", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "a", "A", "c", "A" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "a", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "b", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "b", "B", "c", "B" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "a", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "b", "C" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+            Arrays.asList(new Object[] { "c", "C", "c", "C" }) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);          
+    }
+    
+    /**
+     * Basically the same as above, but with a limit node between the dup removal and the project
+     */
+    @Test public void testDefect12081_4(){
+        String sql = "SELECT DISTINCT e1, e1 FROM pm1.g1 where e1 = 'a' LIMIT 1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "a"}), //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);          
+    }
+    
+    @Test public void testDefect12719(){
+        String sql = "SELECT e1_, e2_, e2 FROM vm1.g34, pm1.g2 WHERE vm1.g34.e1_ = pm1.g2.e1 order by e1_, e2_"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", new Integer(0), new Integer(1) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(0) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(5) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(0), new Integer(2) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(0) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(5) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", new Integer(1), new Integer(2) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "d", new Integer(3), new Integer(2) }), //$NON-NLS-1$ 
+        };    
+
+		// Construct data manager with data
+		FakeDataManager dataManager = new FakeDataManager();
+		sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    @Test public void testDefect13034() {
+		String sql = "SELECT CONCAT('http://', CONCAT(CASE WHEN (HOST IS NULL) OR (HOST = '') THEN 'soap_host' ELSE HOST END, CASE WHEN (PORT IS NULL) OR (PORT = '') THEN '/metamatrix-soap/services/DataService' ELSE CONCAT(':', CONCAT(PORT, '/metamatrix-soap/services/DataService')) END)) AS location " + //$NON-NLS-1$
+			"FROM (SELECT env('soap_host') AS HOST, env('soap_port') AS PORT) AS props"; //$NON-NLS-1$
+			
+		// Create expected results
+		List[] expected = new List[] { 
+			Arrays.asList(new Object[] { "http://my.host.com:12345/metamatrix-soap/services/DataService" }), //$NON-NLS-1$ 
+		};    
+           
+		// Plan query
+		ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+		// Run query
+		helpProcess(plan, new FakeDataManager(), expected);
+		    	
+    }
+    
+    /** see also integer average defect 11682 */
+    @Test public void testIntAvgDefect11682() { 
+        // Create query 
+        String sql = "SELECT AVG(IntKey), AVG(IntNum), AVG(FloatNum), AVG(LongNum), AVG(DoubleNum), AVG(ByteNum), AVG(ShortValue), AVG(BigIntegerValue), AVG(BigDecimalValue) FROM BQT1.SmallA"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new Double(1.5), new BigDecimal("1.500000000"), new BigDecimal("1.500000000") }),  //$NON-NLS-1$//$NON-NLS-2$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT_defect11682(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    @Test public void testNonJoinCriteriaInFrom() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+        
+    @Test public void testNonJoinCriteriaInWhere() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 WHERE b.e2 = 0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testNonJoinCriteriaInWhere2() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm1.g2 b ON a.e1=b.e1 WHERE (a.e2 + b.e2 = 1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "a", new Integer(1) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    @Test public void testNonJoinCriteriaInWhere3() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm1.g2 b ON a.e1=b.e1 WHERE (a.e2 = 0) OR (b.e2 = 0)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "a", new Integer(1) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }     
+        
+    @Test public void testNonJoinCriteriaInFromNestedInVirtual() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN (SELECT c.e1, d.e2 FROM pm2.g1 c JOIN pm2.g1 d ON c.e1=d.e1 AND d.e2 >= 0) b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+    
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testNonJoinCriteriaInFromUsingDependentJoin() {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a LEFT OUTER JOIN pm2.g1 b ON a.e1=b.e1 AND b.e2 = 0"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", null, null }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "b", "b", new Integer(0) }), //$NON-NLS-1$ //$NON-NLS-2$ 
+            Arrays.asList(new Object[] { "c", null, null }), //$NON-NLS-1$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2a(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }          
+    
+    @Test public void testDefect13700() {
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(10) }), 
+        };    
+           
+        // Plan query
+        ProcessorPlan plan = helpGetPlan("EXEC pm1.vsp36(5)", FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+        
+        // Run query
+        helpProcess(plan, new FakeDataManager(), expected);
+        
+    }
+    
+    @Test public void testDefect13920() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, false);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        Command command = helpParse("SELECT e5, e2, e3, e4 FROM vm1.g1c WHERE e5 >= {ts'2004-08-01 00:00:00.0'}");   //$NON-NLS-1$
+        ProcessorPlan plan = helpGetPlan(command,  
+            FakeMetadataFactory.example1Cached(), capFinder);
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataStringTimestamps(dataManager);
+
+        Calendar cal = Calendar.getInstance();
+        cal.set(2004, Calendar.DECEMBER, 31, 0, 0, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        Timestamp t1 = new Timestamp(cal.getTime().getTime());
+        cal.clear();
+        cal.set(2004, Calendar.AUGUST, 1, 0, 0, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        Timestamp t2 = new Timestamp(cal.getTime().getTime());
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { t1,   new Integer(1),     Boolean.TRUE,   null }), 
+            Arrays.asList(new Object[] { t2,   new Integer(2),     Boolean.FALSE,  new Double(0.0) }), 
+        };    
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+        
+    }
+
+    /** RLM Case 2077 
+     * @throws Exception */
+    @Test public void testComplexJoinExpressionsUsingDependentJoin() throws Exception {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2b(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        caps.setFunctionSupport("rtrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm1.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        
+        Command command = helpParse(sql);   
+        CommandContext context = createCommandContext();
+        context.setMetadata(metadata);
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder,context);
+        
+        //Verify a dependent join (not merge join) was used
+        assertTrue(plan instanceof RelationalPlan);
+        RelationalPlan relationalPlan = (RelationalPlan)plan;
+        RelationalNode project = relationalPlan.getRootNode();
+        RelationalNode join = project.getChildren()[0];
+        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
+
+        // Run query
+        helpProcess(plan, context, dataManager, expected);        
+    }     
+
+    /** RLM Case 2077 
+     * @throws Exception */
+    @Test public void testComplexJoinExpressionsUsingDependentJoinWithAccessPattern() throws Exception {
+        String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) //$NON-NLS-1$ //$NON-NLS-2$ 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2b(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        caps.setFunctionSupport("||", true); //$NON-NLS-1$
+        caps.setFunctionSupport("rtrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm4", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+        FakeMetadataObject g1 = metadata.getStore().findObject("pm4.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g1.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000));
+        FakeMetadataObject g2 = metadata.getStore().findObject("pm2.g1", FakeMetadataObject.GROUP); //$NON-NLS-1$
+        g2.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1));
+        
+        Command command = helpParse(sql);   
+        CommandContext context = createCommandContext();
+        context.setMetadata(metadata);
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
+        
+        //Verify a dependent join (not merge join) was used
+        assertTrue(plan instanceof RelationalPlan);
+        RelationalPlan relationalPlan = (RelationalPlan)plan;
+        RelationalNode project = relationalPlan.getRootNode();
+        RelationalNode join = project.getChildren()[0];
+        assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode); //$NON-NLS-1$
+
+        // Run query
+        helpProcess(plan, context, dataManager, expected);        
+    }      
+    
+    @Test public void testPushingCriteriaUnderJoinButNotToSource() {
+        // Create query
+        String sql = "SELECT A.IntKey AS A_IntKey, B.IntKey AS B_IntKey, C.IntKey AS C_IntKey " +  //$NON-NLS-1$
+        "FROM (BQT1.SmallA AS A FULL OUTER JOIN BQT2.SmallA AS B ON A.IntKey = B.IntKey) LEFT OUTER JOIN BQT3.SmallA AS C ON B.IntKey = C.IntKey " +  //$NON-NLS-1$
+        "WHERE (sin(A.IntKey) >= 0) " +  //$NON-NLS-1$
+        "AND (C.IntKey >= 10)"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(13), new Integer(13), new Integer(13) }),
+            Arrays.asList(new Object[] { new Integer(14), new Integer(14), new Integer(14) }),
+            Arrays.asList(new Object[] { new Integer(15), new Integer(15), new Integer(15) }),
+            Arrays.asList(new Object[] { new Integer(19), new Integer(19), new Integer(19) }),
+            Arrays.asList(new Object[] { new Integer(20), new Integer(20), new Integer(20) }),
+            Arrays.asList(new Object[] { new Integer(21), new Integer(21), new Integer(21) }),
+            Arrays.asList(new Object[] { new Integer(26), new Integer(26), new Integer(26) }),
+            Arrays.asList(new Object[] { new Integer(27), new Integer(27), new Integer(27) }),
+            Arrays.asList(new Object[] { new Integer(28), new Integer(28), new Integer(28) })
+        };
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2(dataManager);
+
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.exampleBQTCached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }    
+    
+    @Test public void testPushdownLiteralInSelectUnderAggregate() {  
+        String sql = "SELECT COUNT(*) FROM (SELECT '' AS y, a.IntKey FROM BQT1.SmallA a union all select '', b.intkey from bqt1.smallb b) AS x"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(30) }) 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testPushdownLiteralInSelectWithOrderBy() {  
+        String sql = "SELECT 1, concat('a', 'b' ) AS X FROM BQT1.SmallA where intkey = 0 " +  //$NON-NLS-1$
+            "UNION ALL " +  //$NON-NLS-1$
+            "select 2, 'Hello2' from BQT1.SmallA where intkey = 1 order by X desc"; //$NON-NLS-1$
+        
+        
+        // Create expected results - would expect these to be:
+        //    1, "ab"
+        //    2, "Hello2"
+        // but our fake tuple source is too dumb to return anything reasonable, so instead get:
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null, null }), 
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQTSmall(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+
+        // Run query
+        helpProcess(plan, dataManager, expected);        
+    }
+    
+    /** defect 15348
+     * @throws Exception */
+    @Test public void testPreparedStatementDefect15348() throws Exception{
+        String sql = "SELECT e1 from pm1.g1 where myrtrim(?)=e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }) //$NON-NLS-1$  
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2a(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport("myrtrim", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FunctionLibrary funcLibrary = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(new FakeFunctionMetadataSource().getFunctionMethods())));
+        FakeMetadataFacade metadata = new FakeMetadataFacade(FakeMetadataFactory.example1Cached().getStore(), funcLibrary);
+        
+        
+        Command command = helpParse(sql);   
+        CommandContext context = createCommandContext();
+        context.setMetadata(metadata);        
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
+        
+        // Collect reference, set value
+        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
+        VariableContext vc = new VariableContext();
+        vc.setGlobalValue(ref.getContextSymbol(),  "a    "); //$NON-NLS-1$
+        context.setVariableContext(vc);
+        // Run query
+        helpProcess(plan, context, dataManager, expected);        
+        
+    }    
+
+    /** defect 15348
+     * @throws Exception */
+    @Test public void testPreparedStatementDefect15348b() throws Exception{
+        String sql = "SELECT e1 from pm4.g1 where myrtrim(concat(?, 'a  '))=e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "aa" }) //$NON-NLS-1$  
+        };    
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2a(dataManager);
+    
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setFunctionSupport("myrtrim", true); //$NON-NLS-1$
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("pm4", caps); //$NON-NLS-1$
+
+        FunctionLibrary funcLibrary = new FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new UDFSource(new FakeFunctionMetadataSource().getFunctionMethods())));
+        FakeMetadataFacade metadata = new FakeMetadataFacade(FakeMetadataFactory.example1Cached().getStore(), funcLibrary);
+        
+        
+        Command command = helpParse(sql);   
+        CommandContext context = createCommandContext();
+        context.setMetadata(metadata);        
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
+        
+        // Collect reference, set value
+        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
+        VariableContext vc = new VariableContext();
+        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
+        context.setVariableContext(vc);
+        
+        // Run query
+        helpProcess(plan, context, dataManager, expected);        
+        
+    }      
+
+    @Test public void testSourceDoesntSupportGroupAlias() {  
+        String sql = "SELECT a.IntKey, b.IntKey FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey"; //$NON-NLS-1$
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
+        assertEquals("Expected one query to get pushed down", 1, atomicQueries.size()); //$NON-NLS-1$
+        String atomicSql = atomicQueries.iterator().next().toString();
+        String expectedSql = "SELECT BQT1.SmallA.IntKey, BQT1.SmallB.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5) AND (BQT1.SmallB.IntKey = 5)"; //$NON-NLS-1$
+        assertEquals(expectedSql, atomicSql); 
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(5), new Integer(5)}), 
+                                  };    
+        
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, expected);
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testSourceDoesntSupportGroupAliasOrCriteria() {  
+        String sql = "SELECT a.IntKey, b.IntKey FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.StringKey = '5' AND A.IntKey = b.IntKey"; //$NON-NLS-1$
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
+        assertEquals("Expected 2 queries to get pushed down", 2, atomicQueries.size()); //$NON-NLS-1$
+        
+        String expectedSql = "SELECT BQT1.SmallA.StringKey, BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
+        String expectedSql2 = "SELECT BQT1.SmallB.IntKey FROM BQT1.SmallB"; //$NON-NLS-1$
+        Set expectedQueries = new HashSet();
+        expectedQueries.add(expectedSql);
+        expectedQueries.add(expectedSql2);
+        assertEquals(expectedQueries, atomicQueries); 
+
+        List[] input1 = new List[] { 
+                                    Arrays.asList(new Object[] { "5", new Integer(5)}), //$NON-NLS-1$ 
+                                };    
+        List[] input2 = new List[] {Arrays.asList(new Object[] {new Integer(5)}), 
+        };
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData(expectedSql, input1);
+        dataManager.addData(expectedSql2, input2);
+        
+        List[] expected = new List[] {Arrays.asList(new Object[] {new Integer(5), new Integer(5)}), 
+        };
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    /**
+     * Same as testSourceDoesntSupportGroupAlias, but query is in an inline view and only 
+     * the first column is selected.
+     * 
+     * @since 4.2
+     */
+    @Test public void testSourceDoesntSupportGroupAliasInVirtual() {  
+        String sql = "SELECT x FROM (SELECT a.IntKey as x, b.IntKey as y FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey) AS z, BQT2.SmallA WHERE y = IntKey"; //$NON-NLS-1$
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
+        assertEquals("Expected 2 queries to get pushed down", 2, atomicQueries.size()); //$NON-NLS-1$
+        
+        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5) AND (BQT1.SmallB.IntKey = 5)"; //$NON-NLS-1$
+        String expectedSql2 = "SELECT BQT2.SmallA.IntKey FROM BQT2.SmallA WHERE BQT2.SmallA.IntKey = 5"; //$NON-NLS-1$
+        
+        Set expectedQueries = new HashSet();
+        expectedQueries.add(expectedSql);
+        expectedQueries.add(expectedSql2);
+        assertEquals(expectedQueries, atomicQueries); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(5), new Integer(5)}), 
+                                  };    
+        List[] input2 = new List[] { 
+                                    Arrays.asList(new Object[] { new Integer(5)}), 
+                                };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+        dataManager.addData(expectedSql2, input2);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(5)}), 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testCaseInGroupBy() {  
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT SUM(X_1.c_1), X_1.c_0 FROM (SELECT CASE WHEN BQT1.SmallA.IntKey >= 5000 THEN '5000 +' ELSE '0-999' END AS c_0, BQT1.SmallA.IntKey AS c_1 FROM BQT1.SmallA) AS v_0 GROUP BY X_1.c_0"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(5), new Integer(10)}), 
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(5), new Integer(10)}), 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testCaseInGroupByAndHavingCantPush() {  
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+        "HAVING case when IntKey>=5000 then '5000 +' else '0-999' end = '5000 +'"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(2)}),  
+                                      Arrays.asList(new Object[] { new Integer(4)}),  
+                                      Arrays.asList(new Object[] { new Integer(10000)}),  
+                                      Arrays.asList(new Object[] { new Integer(10002)}),  
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Long(20002), "5000 +"}), //$NON-NLS-1$ 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testCaseInGroupByAndHavingCantPush2() {  
+        String sql = "SELECT sum (IntKey), case when IntKey>=5000 then '5000 +' else '0-999' end || 'x' " + //$NON-NLS-1$
+        "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+        "HAVING length(case when IntKey>=5000 then '5000 +' else '0-999' end) > 5"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(2)}),  
+                                      Arrays.asList(new Object[] { new Integer(4)}),  
+                                      Arrays.asList(new Object[] { new Integer(10000)}),  
+                                      Arrays.asList(new Object[] { new Integer(10002)}),  
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Long(20002), "5000 +x"}), //$NON-NLS-1$ 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testCaseInGroupByAndHavingCantPush3() {  
+        String sql = "SELECT s, c FROM (" + //$NON-NLS-1$
+            "SELECT sum (IntKey) s, case when IntKey>=5000 then '5000 +' else '0-999' end || 'x' c " + //$NON-NLS-1$
+            "FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000 +' else '0-999' end " + //$NON-NLS-1$
+            ") AS x WHERE length(c) > 5 AND s = 20002"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, false);   // Can't push GROUP BY
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { new Integer(2)}),  
+                                      Arrays.asList(new Object[] { new Integer(4)}),  
+                                      Arrays.asList(new Object[] { new Integer(10000)}),  
+                                      Arrays.asList(new Object[] { new Integer(10002)}),  
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { new Long(20002), "5000 +x"}), //$NON-NLS-1$ 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+
+    @Test public void testFunctionOfAggregateCantPush() {  
+        String sql = "SELECT StringKey || 'x', SUM(length(StringKey || 'x')) + 1 AS x FROM BQT1.SmallA GROUP BY StringKey || 'x' HAVING space(MAX(length((StringKey || 'x') || 'y'))) = '   '"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT BQT1.SmallA.StringKey FROM BQT1.SmallA"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { "0"}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "1"}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "10"}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "11"}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "100"}),   //$NON-NLS-1$
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { "0x", new Long(3)}), //$NON-NLS-1$ 
+                                      Arrays.asList(new Object[] { "1x", new Long(3)}), //$NON-NLS-1$ 
+                                  };    
+        helpProcess(plan, dataManager, expected);        
+    }
+    
+    
+    @Test public void testCase2634() {
+        
+        String sql = "SELECT x, IntKey FROM (SELECT IntKey, 'a' AS x FROM BQT1.SmallA UNION ALL SELECT IntKey, 'b' AS x FROM BQT1.SmallB) as Z"; //$NON-NLS-1$
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Set actualQueries = TestOptimizer.getAtomicQueries(plan);
+        String expectedSql = "SELECT 'a' AS c_0, BQT1.SmallA.IntKey AS c_1 FROM BQT1.SmallA UNION ALL SELECT 'b' AS c_0, BQT1.SmallB.IntKey AS c_1 FROM BQT1.SmallB"; //$NON-NLS-1$
+        assertEquals(1, actualQueries.size());        
+        assertEquals(expectedSql, actualQueries.iterator().next().toString()); 
+
+        List[] input1 = new List[] { 
+                                      Arrays.asList(new Object[] { "a", new Integer(0)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "a", new Integer(1)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "b", new Integer(0)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "b", new Integer(1)}),   //$NON-NLS-1$
+                                  };    
+        HardcodedDataManager dataManager = new HardcodedDataManager();              
+        dataManager.addData(expectedSql, input1);
+
+        List[] expected = new List[] { 
+                                      Arrays.asList(new Object[] { "a", new Integer(0)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "a", new Integer(1)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "b", new Integer(0)}),   //$NON-NLS-1$
+                                      Arrays.asList(new Object[] { "b", new Integer(1)}),   //$NON-NLS-1$
+                                  };    
+        helpProcess(plan, dataManager, expected);          
+        
+    }
+    
+    @Test public void testQueryWithoutFromWithOrderBy() {
+        
+        String sql = "select 'three' as x ORDER BY x"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "three"} ), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        helpProcess(plan, dataManager, expected);         
+        
+    }
+
+    @Test public void testQueryWithoutFromWithOrderBy2() {
+        
+        String sql = "select concat('three', ' sixteen') as x ORDER BY x"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "three sixteen"} ), //$NON-NLS-1$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        helpProcess(plan, dataManager, expected);         
+        
+    }    
+
+    @Test public void testQueryWithoutFromWithOrderBy3() {
+        
+        String sql = "SELECT CONCAT('yy', 'z') as c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
+                     "CONCAT('21', '12') AS EXPR ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "yyz", "2112"} ), //$NON-NLS-1$ //$NON-NLS-2$ 
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        helpProcess(plan, dataManager, expected);         
+        
+    }     
+    
+    @Test public void testCase2507_3(){
+
+        String sql = "SELECT CONCAT('yy', 'z') AS c1234567890123456789012345678901234567890, " + //$NON-NLS-1$
+                            "CONCAT('21', '12') AS EXPR ORDER BY c1234567890123456789012345678901234567890"; //$NON-NLS-1$
+
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+        caps.setFunctionSupport("concat", true); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
+                                      metadata,
+                                      null, capFinder,
+                                      new String[0] ,
+                                      TestOptimizer.SHOULD_SUCCEED );
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                                        0,      // Access
+                                        0,      // DependentAccess
+                                        0,      // DependentSelect
+                                        0,      // DependentProject
+                                        0,      // DupRemove
+                                        0,      // Grouping
+                                        0,      // Join
+                                        0,      // MergeJoin
+                                        0,      // Null
+                                        0,      // PlanExecution
+                                        1,      // Project
+                                        0,      // Select
+                                        0,      // Sort
+                                        0       // UnionAll
+                                    });        
+        
+        // TEST PROCESSING
+
+        List[] expectedResults = new List[] { 
+              Arrays.asList(new Object[] { "yyz", "2112"}), //$NON-NLS-1$ //$NON-NLS-2$ 
+          };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT1(dataManager);
+
+        // Run query
+        helpProcess(plan, dataManager, expectedResults);        
+        
+    }    
+
+    @Test public void testMultiGroupJoinCriteria() {
+        
+        String sql = "SELECT X.NEWFIELD FROM " + //$NON-NLS-1$
+                       "(SELECT SMALLA.STRINGNUM, " + //$NON-NLS-1$
+                        "CASE WHEN SMALLA.STRINGNUM LIKE '1%' THEN SMALLA.INTKEY " + //$NON-NLS-1$
+                             "WHEN SMALLA.STRINGNUM LIKE '2%' THEN SMALLB.INTNUM " + //$NON-NLS-1$
+                             "WHEN SMALLA.STRINGNUM LIKE '3%' THEN MEDIUMA.INTKEY " + //$NON-NLS-1$
+                       "END AS NEWFIELD " + //$NON-NLS-1$
+                       "FROM BQT1.SMALLA, BQT1.SMALLB, BQT1.MEDIUMA " + //$NON-NLS-1$
+                       "WHERE SMALLA.INTKEY = SMALLB.INTKEY AND SMALLA.INTKEY = MEDIUMA.INTKEY) AS X " + //$NON-NLS-1$
+                     "WHERE X.NEWFIELD = -3"; //$NON-NLS-1$
+        
+        String expectedAtomic1 = "SELECT BQT1.SMALLB.INTKEY, BQT1.SMALLB.INTNUM FROM BQT1.SMALLB"; //$NON-NLS-1$
+        String expectedAtomic2 = "SELECT BQT1.MEDIUMA.INTKEY FROM BQT1.MEDIUMA"; //$NON-NLS-1$
+        String expectedAtomic3 = "SELECT BQT1.SMALLA.INTKEY, BQT1.SMALLA.STRINGNUM FROM BQT1.SMALLA"; //$NON-NLS-1$
+        
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql,         
+                          metadata,
+                          null, capFinder,
+                          new String[] {expectedAtomic1, expectedAtomic2, expectedAtomic3} ,
+                          TestOptimizer.SHOULD_SUCCEED );        
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                            3,      // Access
+                            0,      // DependentAccess
+                            0,      // DependentSelect
+                            0,      // DependentProject
+                            0,      // DupRemove
+                            0,      // Grouping
+                            0,      // Join
+                            2,      // MergeJoin
+                            0,      // Null
+                            0,      // PlanExecution
+                            1,      // Project
+                            0,      // Select
+                            0,      // Sort
+                            0       // UnionAll
+                        });        
+    
+        // TEST PROCESSING
+        
+        List[] expectedResults = new List[] { 
+        Arrays.asList(new Object[] { new Integer(-3) }), 
+        };    
+        
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager(); 
+        List[] input1 = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(-4)}), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(-3)}), 
+            Arrays.asList(new Object[] { new Integer(3), new Integer(-2)}), 
+        };    
+        dataManager.addData(expectedAtomic1, input1);
+        List[] input2 = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1)}), 
+            Arrays.asList(new Object[] { new Integer(2)}), 
+            Arrays.asList(new Object[] { new Integer(3)}), 
+        };    
+        dataManager.addData(expectedAtomic2, input2);
+        List[] input3 = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), new String("1")}), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { new Integer(2), new String("2")}), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { new Integer(3), new String("3")}), //$NON-NLS-1$ 
+        };    
+        dataManager.addData(expectedAtomic3, input3);
+        
+        // Run query
+        helpProcess(plan, dataManager, expectedResults);        
+        
+    }    
+    
+    /**
+     * Cross-source join with group by on top but no aggregate functions - running some special cases
+     * where there are no "aggregate groups" (the groups of the aggregate expressions) because there
+     * are no aggregate expressions.  In this case, need to switch the aggregate groups to be all the grouping
+     * columns because they are all being "grouped on".    
+     * 
+     * @since 4.3
+     */
+    @Test public void testDefect18360(){
+
+        String sql = "SELECT a.intkey, a.intnum FROM bqt1.smalla a join bqt2.mediumb b on a.stringkey = b.stringkey " + //$NON-NLS-1$
+            "group by a.intkey, a.intnum"; //$NON-NLS-1$
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        capFinder.addCapabilities("BQT1", new BasicSourceCapabilities()); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", new BasicSourceCapabilities()); //$NON-NLS-1$
+
+        Command command = helpParse(sql);
+        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder);
+        
+        // Construct data manager with data        
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        List[] data1 = new List[] {
+            Arrays.asList(new Object[] { "1", new Integer(1), new Integer(5) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2", new Integer(2), new Integer(6) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3", new Integer(3), new Integer(7) }), //$NON-NLS-1$
+        };        
+        dataManager.addData("SELECT bqt1.smalla.stringkey, bqt1.smalla.intkey, bqt1.smalla.intnum FROM bqt1.smalla", data1);  //$NON-NLS-1$
+
+        List[] data2 = new List[] {
+            Arrays.asList(new Object[] { "1" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "2" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "3" }), //$NON-NLS-1$
+        };        
+        dataManager.addData("SELECT bqt2.mediumb.stringkey FROM bqt2.mediumb", data2);  //$NON-NLS-1$
+
+        // Run query
+        List[] expectedResults = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), new Integer(5) }), 
+            Arrays.asList(new Object[] { new Integer(2), new Integer(6) }), 
+            Arrays.asList(new Object[] { new Integer(3), new Integer(7) }), 
+        };    
+        helpProcess(plan, dataManager, expectedResults);          
+
+    }    
+    
+    @Test public void testDefect17407(){
+        String sql = "select pm1.g1.e1 from pm1.g1, g7 MAKEDEP WHERE pm1.g1.e2=g7.e2 order by e1"; //$NON-NLS-1$
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { null}),
+            Arrays.asList(new Object[] { null}),
+            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "a"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "a"}), //$NON-NLS-1$           
+            Arrays.asList(new Object[] { "b"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "c"}),//$NON-NLS-1$
+            Arrays.asList(new Object[] { "c"}),//$NON-NLS-1$
+        };       
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);   
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());       
+        // Run query
+        helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testDecodeAsCriteria() { 
+        // Create query 
+        String sql = "SELECT x.foo, e2 FROM (select decodestring(e1, 'a,q,b,w') as foo, e2 from vm1.g1) as x where x.foo = 'w'"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+                Arrays.asList(new Object[] { "w", new Integer(2) }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testInputParamInNestedExecParam() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp48('a')"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testVariableInExecParam() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp49()"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b", new Integer(2) }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testVariableInNestedExecParam() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp50()"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testVariableInNestedExecParamInLoop() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp51()"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "bb" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testVariableInNestedExecParamInAssignment() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp52()"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testInputParamInNestedExecParamInLoop() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp53('b')"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "bb" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    @Test public void testInputParamInNestedExecParamInAssignment() { 
+        // Create query 
+        String sql = "EXEC pm1.vsp54('c')"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testBitwiseAggregateProc() { 
+        // Create query 
+        String sql = "EXEC virt.agg()"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), "a", new Integer(19) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(1), "b", new Integer(4) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new Integer(2), "c", new Integer(3) }), //$NON-NLS-1$
+        };    
+    
+        // Plan query
+        FakeMetadataFacade metadata = FakeMetadataFactory.exampleBitwise();
+        ProcessorPlan plan = helpGetPlan(sql, metadata);
+
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBitwise(dataManager, metadata);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    private void sampleDataBitwise(FakeDataManager dataMgr, FakeMetadataFacade metadata) {    
+        try { 
+            // Group pm1.g1
+            FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("phys.t"); //$NON-NLS-1$
+            List elementIDs = metadata.getElementIDsInGroupID(groupID);
+            List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+            dataMgr.registerTuples(
+                groupID,
+                elementSymbols,
+                
+                new List[] { 
+                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(1) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(3) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { new Integer(0), "a", new Integer(16) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { new Integer(1), "b", new Integer(4) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { new Integer(2), "c", new Integer(2) }), //$NON-NLS-1$
+                    Arrays.asList(new Object[] { new Integer(2), "c", new Integer(1) }), //$NON-NLS-1$
+                    } );    
+
+        } catch(Throwable e) { 
+            e.printStackTrace();
+            fail("Exception building test data (" + e.getClass().getName() + "): " + e.getMessage());    //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }  
+    
+    @Test public void testFunctionGroupByInJoinCriteria() {  
+        // Create query  
+        String sql = "SELECT lower(vm1.g1.e1) from vm1.g1, vm1.g2a where vm1.g1.e1 = vm1.g2a.e1 group by lower(vm1.g1.e1)"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$ 
+                Arrays.asList(new Object[] { "c" }) //$NON-NLS-1$ 
+                };     
+
+        // Construct data manager with data 
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleData1(dataManager); 
+         
+        // Plan query 
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached()); 
+ 
+        // Run query 
+        helpProcess(plan, dataManager, expected); 
+    }
+
+    private FakeMetadataFacade createProjectErrorMetadata() {
+        FakeMetadataObject p1 = FakeMetadataFactory.createPhysicalModel("p1"); //$NON-NLS-1$
+        FakeMetadataObject t1 = FakeMetadataFactory.createPhysicalGroup("p1.t", p1); //$NON-NLS-1$
+        List e1 = FakeMetadataFactory.createElements(t1, new String[] {"a", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        QueryNode n1 = new QueryNode("v1.t1", "SELECT convert(a, integer) as c, b FROM p1.t"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt1 = FakeMetadataFactory.createVirtualGroup("v1.t1", v1, n1); //$NON-NLS-1$
+        List vte1 = FakeMetadataFactory.createElements(vt1, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+        QueryNode n2 = new QueryNode("v1.t2", "SELECT convert(a, integer) as c, b FROM p1.t"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vt2 = FakeMetadataFactory.createVirtualGroup("v1.t2", v1, n2); //$NON-NLS-1$
+        List vte2 = FakeMetadataFactory.createElements(vt2, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+        QueryNode n3 = new QueryNode("v1.u1", "SELECT c, b FROM v1.t1 UNION ALL SELECT c, b FROM v1.t1"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject vu1 = FakeMetadataFactory.createVirtualGroup("v1.u1", v1, n3); //$NON-NLS-1$
+        List vtu1 = FakeMetadataFactory.createElements(vu1, new String[] {"c", "b" }, new String[] { "string", "string" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(p1);
+        store.addObject(t1);
+        store.addObjects(e1);
+        store.addObject(v1);
+        store.addObject(vt1);
+        store.addObjects(vte1);
+        store.addObject(vt2);
+        store.addObjects(vte2);
+        store.addObject(vu1);
+        store.addObjects(vtu1);
+        return new FakeMetadataFacade(store);
+    }
+    
+    @Test public void testProjectionErrorOverUnionWithConvert() {  
+        // Create query  
+        FakeMetadataFacade metadata = createProjectErrorMetadata();
+        String sql = "SELECT COUNT(*) FROM v1.u1"; //$NON-NLS-1$ 
+         
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("p1", caps); //$NON-NLS-1$
+
+        Command command = helpParse(sql);
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+         
+        // Run query 
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { new Integer(2) }), 
+                };     
+
+        // Construct data manager with data 
+        HardcodedDataManager dataManager = new HardcodedDataManager(); 
+        dataManager.addData("SELECT g_0.a FROM p1.t AS g_0",  //$NON-NLS-1$
+                            new List[] { Arrays.asList(new Object[] { new Integer(1) })});
+        helpProcess(plan, dataManager, expected); 
+    }
+    
+    @Test public void testUpdatesInLoop() { 
+        String sql = "update vm1.g39 set e2=3"; //$NON-NLS-1$ 
+ 
+        // Plan query 
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());        
+
+        // Construct data manager with data 
+        HardcodedDataManager dataManager = new HardcodedDataManager(); 
+        dataManager.addData("SELECT pm1.g1.e2 FROM pm1.g1", //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(3) } )});
+        dataManager.addData("UPDATE pm1.g1 SET e2 = 3 WHERE pm1.g1.e2 = 3", //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(1) } )});
+        
+        // Create expected results 
+        List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1)})};        
+        
+        // Run query 
+        helpProcess(plan, dataManager, expected);  
+         
+    }
+    
+    @Test public void testRand() { 
+        // Create query 
+        String sql = "SELECT RAND(E2) FROM pm1.g1 where pm1.g1.e2=3"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] {new Double(0.731057369148862)}),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /*
+     *  Prior to case 3994 testInsertTempTableCreation1 worked, but testInsertTempTableCreation did not.
+     *  Now they should both pass
+     * 
+     */    
+    @Test public void testInsertTempTableCreation() {
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        QueryNode n1 = new QueryNode("v1.vp", "CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs);  //$NON-NLS-1$
+        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
+        
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(v1);
+        store.addObject(vp);
+        
+        ProcessorPlan plan = helpGetPlan("exec v1.vp()", new FakeMetadataFacade(store)); //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(1) })
+        };
+        helpProcess(plan, new FakeDataManager(), expected);
+    }
+    
+    @Test public void testInsertTempTableCreation1() {
+        FakeMetadataObject v1 = FakeMetadataFactory.createVirtualModel("v1"); //$NON-NLS-1$
+        QueryNode n1 = new QueryNode("v1.vp", "CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select 2 as var1 into #temp; select #temp.var1 from #temp; END"); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject rs = FakeMetadataFactory.createResultSet("rs", v1, new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
+        FakeMetadataObject paramRS = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs);  //$NON-NLS-1$
+        FakeMetadataObject vp = FakeMetadataFactory.createVirtualProcedure("v1.vp", v1, Arrays.asList(new Object[] {paramRS}), n1); //$NON-NLS-1$
+        
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(v1);
+        store.addObject(vp);
+        
+        ProcessorPlan plan = helpGetPlan("exec v1.vp()", new FakeMetadataFacade(store)); //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(1) }),
+            Arrays.asList(new Object[] { new Integer(2) })
+        };
+        helpProcess(plan, new FakeDataManager(), expected);
+    }    
+        
+    @Test public void testCase4531() { 
+        String sql = "select intkey, intnum from (select intnum as intkey, 1 as intnum from bqt1.smalla union all select intkey, intnum from bqt1.smalla union all select intkey, intnum from bqt2.smalla) x"; //$NON-NLS-1$ 
+ 
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); 
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); 
+        caps.setCapabilitySupport(Capability.QUERY_UNION, true); 
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true); 
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$ 
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$ 
+ 
+        Command command = helpParse(sql); 
+        ProcessorPlan plan = helpGetPlan(command, FakeMetadataFactory.exampleBQTCached(), capFinder); 
+ 
+        // Run query  
+        // Create expected results  
+        List[] expected = new List[] {   
+                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
+                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
+                        Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
+                };      
+         
+        // Construct data manager with data  
+        HardcodedDataManager dataManager = new HardcodedDataManager();  
+        dataManager.addData("SELECT g_0.intkey, g_0.intnum FROM bqt2.smalla AS g_0",  //$NON-NLS-1$ 
+                            new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) })}); 
+        dataManager.addData("SELECT g_1.intnum AS c_0, 1 AS c_1 FROM bqt1.smalla AS g_1 UNION ALL SELECT g_0.IntKey AS c_0, g_0.IntNum AS c_1 FROM bqt1.smalla AS g_0",  //$NON-NLS-1$ 
+                new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), 
+                                 Arrays.asList(new Object[] { new Integer(1), new Integer(1) })}); 
+        helpProcess(plan, dataManager, expected);  
+    }
+        
+    private void sampleDataBQT2a(FakeDataManager dataMgr) throws Exception {
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+    
+        String[] groups = new String[] {"bqt1.smalla", "bqt2.smalla", "bqt3.smalla" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+    
+        for(int groupIndex=0; groupIndex<groups.length; groupIndex++) {
+            String groupName = groups[groupIndex];
+
+            List[] tuples = new List[3];
+            for(int row=0; row<tuples.length; row++) {
+                tuples[row] = new ArrayList(17);
+                tuples[row].add(new Integer(row)); //IntKey
+                tuples[row].add(String.valueOf(row)); //StringKey
+                tuples[row].add(new Integer(row));  //IntNum
+                tuples[row].add(String.valueOf(row)); //StringNum
+                for(int col=0; col<10; col++) { //FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue
+                    tuples[row].add(null);    
+                }    
+                tuples[row].add(new BigInteger(String.valueOf(row))); //BigIntegerValue
+                tuples[row].add(new BigDecimal(row)); //BigDecimalValue
+                tuples[row].add(null);    //ObjectValue
+            }
+            dataMgr.registerTuples(metadata, groupName, tuples);
+        }
+    }    
+    
+    @Test public void testDefect15355() throws Exception {
+        
+        String sql = "SELECT e1, e1 FROM pm1.g1 "   //$NON-NLS-1$
+        +"UNION ALL "   //$NON-NLS-1$
+        +"SELECT e1, (SELECT e1 FROM pm2.g1 WHERE pm2.g1.e2 = pm1.g2.e2) FROM pm1.g2"; //$NON-NLS-1$
+        
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "a", "a" }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "c", "c" }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "a", "e" }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "b" }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$  
+            Arrays.asList(new Object[] { "b", null }), //$NON-NLS-1$  
+            Arrays.asList(new Object[] { "d", null }), //$NON-NLS-1$  
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testDefect15355b() throws Exception {
+        
+        String sql = "SELECT StringKey, BigIntegerValue FROM BQT1.SmallA "   //$NON-NLS-1$
+        +"UNION ALL "   //$NON-NLS-1$
+        +"SELECT StringKey, (SELECT BigIntegerValue FROM BQT3.SmallA WHERE BQT3.SmallA.BigIntegerValue = BQT2.SmallA.StringNum) FROM BQT2.SmallA"; //$NON-NLS-1$
+        
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "1", new BigInteger("1") }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "2", new BigInteger("2") }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "1", new BigInteger("1") }), //$NON-NLS-1$  //$NON-NLS-2$
+            Arrays.asList(new Object[] { "2", new BigInteger("2") }), //$NON-NLS-1$  //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }    
+
+    @Test public void testDefect15355c() throws Exception {
+        
+        String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }       
+    
+    @Test public void testDefect15355d() throws Exception {
+        
+        String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355a WHERE StringKey = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "0", new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }     
+
+    @Test public void testDefect15355e() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue, StringKey FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0"), "0" }), //$NON-NLS-1$  //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }    
+
+    @Test public void testDefect15355f() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }     
+
+    @Test public void testDefect15355f2() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE StringKey LIKE '%0' AND StringKey LIKE '0%'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }      
+    
+    @Test public void testDefect15355g() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue AS a, BigIntegerValue AS b FROM VQT.Defect15355 WHERE StringKey = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0"), new BigInteger("0") }), //$NON-NLS-1$  //$NON-NLS-2$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }     
+
+    @Test public void testDefect15355h() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE BigIntegerValue = '0'";  //$NON-NLS-1$
+                      
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }     
+
+    @Test public void testDefect15355i() throws Exception {
+        
+        String sql = "SELECT BigIntegerValue FROM VQT.Defect15355b WHERE BigIntegerValue = '0'";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$  
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2a(dataManager);
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT1", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
+        capFinder.addCapabilities("BQT3", caps); //$NON-NLS-1$
+        
+        QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }  
+    
+    /**
+     * The inner most A.e1 was mistakenly getting transformed into pm1.g3.e1 
+     */
+    @Test public void testInnerCorrelatedReference() throws Exception {
+        
+        String sql = "SELECT DISTINCT A.e1 FROM pm1.g3 AS A WHERE (A.e1 IN (SELECT A.e1 FROM pm1.g3))";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+        };    
+        
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.addData("SELECT DISTINCT g_0.e1 FROM pm1.g3 AS g_0 WHERE g_0.e1 IN (SELECT g_0.e1 FROM pm1.g3 AS g_1)", expected); //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        // Plan query
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        Command command = helpParse(sql);   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);           
+        
+    }
+    
+    @Test public void testCase5413() throws Exception {
+
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        // Plan query
+        String sql = "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 1) = e1";//$NON-NLS-1$
+        QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
+        Command command = TestProcessor.helpParse(sql);   
+        CommandContext context = createCommandContext();
+        context.setMetadata(metadata);
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
+        
+        // Run query
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
+        };
+        
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        Map valueMap = new HashMap();
+        valueMap.put(1, "b"); //$NON-NLS-1$ //$NON-NLS-2$
+        dataManager.defineCodeTable("pm1.g1", "e2", "e1", valueMap); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        dataManager.setThrowBlocked(true);
+        
+        helpProcess(plan, context, dataManager, expected);
+    } 
+    
+    @Test public void testRaiseNullWithSelectInto() {
+        String sql = "select pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 into pm1.g2 from pm1.g1 where (1=0)"; //$NON-NLS-1$
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder()); 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                0,      // Access
+                0,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                0,      // MergeJoinStrategy
+                1,      // Null
+                0,      // PlanExecution
+                1,      // Project
+                0,      // Select
+                0,      // Sort
+                0       // UnionAll
+            });
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { new Integer(0)}),
+        };
+
+        helpProcess(plan, new FakeDataManager(), expected);
+        
+    }    
+    
+    /*
+     * Test for Case6219
+     */
+    @Test public void testCase6219() {
+        String sql = "SELECT e1 FROM pm1.g1, (SELECT 'ACT' AS StateCode,'A' AS StateAbbrv UNION ALL SELECT 'NSW' AS StateCode, 'N' AS StateAbbrv) AS StateNames_Abbrvs WHERE (pm1.g1.e1 = StateCode) AND ((StateNames_Abbrvs.StateAbbrv || pm1.g1.e1) = 'VVIC')"; //$NON-NLS-1$
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder()); 
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+                0,      // Access
+                1,      // DependentAccess
+                0,      // DependentSelect
+                0,      // DependentProject
+                0,      // DupRemove
+                0,      // Grouping
+                0,      // NestedLoopJoinStrategy
+                1,      // MergeJoinStrategy
+                0,      // Null
+                0,      // PlanExecution
+                3,      // Project
+                0,      // Select
+                0,      // Sort
+                1       // UnionAll
+            });
+        
+        List[] expected = new List[] {
+        };
+        
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+        
+    }
+    
+    @Test public void testSortWithLimit() {
+        String sql = "select e1 from (select pm1.g1.e1, pm1.g1.e2 from pm1.g1 order by pm1.g1.e1, pm1.g1.e2 limit 1) x"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { null}),
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testSortWithLimit1() {
+        String sql = "select c from (select pm1.g1.e1 a, pm1.g1.e2 b, pm1.g1.e3 c from pm1.g1 order by b limit 1) x"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { Boolean.FALSE}),
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+        //note that the e1 column is not used in the source query
+        assertEquals("SELECT pm1.g1.e3, pm1.g1.e2 FROM pm1.g1", (String)manager.getQueries().iterator().next()); //$NON-NLS-1$
+    }
+    
+    @Test public void testSortWithLimit2() {
+        String sql = "select a from (select max(e2) a from pm1.g1 group by e2 order by a limit 1) x where a = 0"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { new Integer(0) }),
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    /**
+     * A more direct test of 1, where the nested order by is unrelated
+     */
+    @Test public void testSortWithLimit3() {
+        String sql = "select c from (select pm1.g1.e3 c from pm1.g1 order by pm1.g1.e2 limit 1) x"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { Boolean.FALSE }),
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testSortWithLimit4() {
+        String sql = "select c from (select pm1.g1.e1 a, pm1.g1.e2 b, pm1.g1.e3 c from pm1.g1 order by b limit 1) x"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_ORDERBY_UNRELATED, false);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(caps));
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { Boolean.FALSE }),
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+        assertEquals("SELECT g_0.e3 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_1", manager.getQueries().iterator().next()); //$NON-NLS-1$
+    }
+
+    @Test public void testCountWithHaving() {
+        String sql = "select e1, count(*) from pm1.g1 group by e1 having count(*) > 1"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { "a" , new Integer(3)}), //$NON-NLS-1$
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testLimitZero() {
+        String sql = "select e1 from pm1.g1 limit 0"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        TestOptimizer.checkNodeTypes(plan, TestRuleRaiseNull.FULLY_NULL);     
+        
+        List[] expected = new List[] {
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testLimitZero1() {
+        String sql = "select distinct vm1.g1.e1, y.e1 from vm1.g1 left outer join (select 1 x, e1 from vm1.g2 limit 0) y on vm1.g1.e1 = y.e1 where vm1.g1.e1 = 'a'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+       });     
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", null }), //$NON-NLS-1$
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testLimitZero2() {
+        String sql = "select vm1.g1.e1 from vm1.g1 union select e1 from pm1.g2 limit 0"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testLimitZero3() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        String sql = "select e1 from pm1.g2 limit 0"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, capFinder);
+        
+        List[] expected = new List[] {
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testUnionWithTypeConversion() {
+        String sql = "select pm1.g1.e1, pm1.g1.e2 from pm1.g1 where e1 = 'b' union select e2, e1 from pm1.g2 where e1 = 'b' order by e1, e2"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "2", "b" }), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList(new Object[] { "b", "2" }), //$NON-NLS-1$ //$NON-NLS-2$
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    /**
+     * Tests non-deterministic evaluation in the select clause.  
+     * 
+     * The evaluation of the rand function is delayed until processing time (which actually has predictable
+     * values since the test initializes the command context with the same seed)
+     * 
+     * If this function were deterministic, it would be evaluated during rewrite to a single value.
+     */
+    @Test public void testNonDeterministicEvaluation() throws Exception {
+        String sql = "select e1, convert(rand()*1000, integer) as x from pm1.g1 where e1 = 'a'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(240) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(637) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "a", new Integer(550) }), //$NON-NLS-1$ 
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    /**
+     * here the rand function is deterministic and should yield a single value
+     */
+    @Test public void testDeterministicEvaluation() throws Exception {
+        String sql = "select e1, convert(rand(0)*1000, integer) as x from pm1.g1 where e1 = 'a'"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { "a", new Integer(730) }), //$NON-NLS-1$ 
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testEmptyAggregate() throws Exception {
+        String sql = "select count(e1) from pm1.g1 where 1 = 0"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(0) })
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testNullAggregate() throws Exception {
+        String sql = "select count(*), count(e1), sum(convert(e1, integer)) from pm1.g1 where e1 is null"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new Integer(1), new Integer(0), null })
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    /**
+     * here the presence of a group by causes no rows to be returned 
+     */
+    @Test public void testNullAggregate1() throws Exception {
+        String sql = "select e1 from pm1.g1 where 1 = 0 group by e1"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testReferenceReplacementWithExpression() throws Exception {
+        String sql = "select e1, e2 from (select e1, convert(e2, string) e2 from pm1.g1) x where exists (select e3 from pm1.g2 where x.e2 = e1)"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {};
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+
+    /**
+     * Here a merge join will be used since there is at least one equi join predicate.
+     * TODO: this can be optimized further
+     */
+    @Test public void testCase6193_1() throws Exception { 
+        // Create query 
+        String sql = "select a.INTKEY, b.intkey from bqt1.smalla a LEFT OUTER JOIN bqt2.SMALLA b on a.intkey=b.intkey and a.intkey=5 where a.intkey <10 "; //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        capFinder.addCapabilities("BQT2", caps);
+
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), null }),
+            Arrays.asList(new Object[] { new Integer(1), null }),
+            Arrays.asList(new Object[] { new Integer(2), null }),
+            Arrays.asList(new Object[] { new Integer(3), null }),
+            Arrays.asList(new Object[] { new Integer(4), null }),
+            Arrays.asList(new Object[] { new Integer(5), new Integer(5) }),
+            Arrays.asList(new Object[] { new Integer(6), null }),
+            Arrays.asList(new Object[] { new Integer(7), null }),
+            Arrays.asList(new Object[] { new Integer(8), null }),
+            Arrays.asList(new Object[] { new Integer(9), null })
+        };
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataBQT2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.exampleBQTCached(), 
+                                                    new String[] {"SELECT b.intkey FROM bqt2.SMALLA AS b", "SELECT a.intkey FROM bqt1.smalla AS a"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            1,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Here a merge join will be used since there is at least one equi join predicate.
+     */
+    @Test public void testCase6193_2() throws Exception { 
+        // Create query 
+        String sql = "select a.e2, b.e2 from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4 and (a.e2+b.e2)=4 order by a.e2"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0), null }),
+            Arrays.asList(new Object[] { new Integer(0), null }),
+            Arrays.asList(new Object[] { new Integer(1), null }),
+            Arrays.asList(new Object[] { new Integer(1), null }),
+            Arrays.asList(new Object[] { new Integer(2), new Integer(2) }),
+            Arrays.asList(new Object[] { new Integer(3), null }),
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    new String[] {"SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            1,      // Sort
+            0       // UnionAll
+        });
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    /**
+     * Here a merge join will be used since there is at least one equi join predicate.
+     * The inner merge join is also a dependent join
+     */
+    @Test public void testCase6193_3() throws Exception { 
+        // Create query 
+        String sql = "select a.x, b.y from (select 4 x union select 1) a LEFT OUTER JOIN (select (a.e2 + b.e2) y from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4) b on (a.x = b.y)"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(1), null }),
+            Arrays.asList(new Object[] { new Integer(4), new Integer(4) }),
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    new String[] {"SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b"}, new DefaultCapabilitiesFinder(), ComparisonMode.CORRECTED_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            4,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });
+        
+        TestOptimizer.checkDependentJoinCount(plan, 1);
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }           
+    
+    /**
+     * A control test to ensure that y will still exist for sorting
+     */
+    @Test public void testOrderByWithDuplicateExpressions() throws Exception {
+        String sql = "select e1 as x, e1 as y from pm1.g1 order by y ASC"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata);
+        
+        List[] expected = new List[] { 
+            Arrays.asList(null, null),
+            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList("a", "a"), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList("b", "b"), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList("c", "c"), //$NON-NLS-1$ //$NON-NLS-2$
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    /**
+     * This is a control test.  It should work regardless of whether the reference is aliased
+     * since accessnodes are now fully positional
+     */
+    @Test public void testPushdownNonAliasedSelectLiteral() throws Exception {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        Command command = helpParse("select ?, e1 from pm1.g1"); //$NON-NLS-1$   
+        ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
+        
+        Reference ref = ReferenceCollectorVisitor.getReferences(command).iterator().next();
+        VariableContext vc = new VariableContext();
+        vc.setGlobalValue(ref.getContextSymbol(), "a"); //$NON-NLS-1$
+        CommandContext context = createCommandContext();
+        context.setVariableContext(vc);
+        
+        List[] expected = new List[] {
+            Arrays.asList("a", "b"), //$NON-NLS-1$ //$NON-NLS-2$
+            Arrays.asList("a", "c") //$NON-NLS-1$ //$NON-NLS-2$
+        };
+
+        HardcodedDataManager manager = new HardcodedDataManager();
+        manager.addData("SELECT 'a', pm1.g1.e1 FROM pm1.g1", expected); //$NON-NLS-1$ 
+        
+        helpProcess(plan, context, manager, expected);
+    }
+    
+    @Test public void testCase6486() { 
+        // Create query 
+        String sql = "select pm2.g1.e1 from pm1.g2, pm2.g1 where pm1.g2.e1=pm2.g1.e1 group by pm2.g1.e1"; //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "d"}) //$NON-NLS-1$
+        };    
+        
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testNonPushedOffset() throws Exception {
+        String sql = "SELECT e1 FROM pm1.g1 LIMIT 1, 5"; //$NON-NLS-1$
+        
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { "b"}), //$NON-NLS-1$
+            Arrays.asList(new Object[] { "c"}), //$NON-NLS-1$
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData2(dataManager);
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (5 + 1)"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        helpProcess(plan, dataManager, expected);          
+    }
+    
+    @Test public void testNonCorrelatedSubQueryExecution() throws Exception {
+        String sql = "SELECT e1 FROM pm1.g1 WHERE e2 IN (SELECT e2 FROM pm2.g1)"; //$NON-NLS-1$
+
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        dataManager.setBlockOnce(true);
+        dataManager.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List[] { //$NON-NLS-1$
+        		Arrays.asList(Integer.valueOf(1), "a"), //$NON-NLS-1$
+        		Arrays.asList(Integer.valueOf(2), "b") //$NON-NLS-1$
+        });
+        dataManager.addData("SELECT pm2.g1.e2 FROM pm2.g1", new List[] { //$NON-NLS-1$
+        		Arrays.asList(Integer.valueOf(2))
+        });
+        
+        ProcessorPlan plan = helpGetPlan(sql, FakeMetadataFactory.example1Cached());
+
+        List[] expected = new List[] {
+                Arrays.asList(new Object[] { "b" }), //$NON-NLS-1$
+            };
+
+        doProcess(plan, dataManager, expected, createCommandContext());
+        
+        //we expect 2 queries, 1 for the outer and 1 for the subquery
+        assertEquals(2, dataManager.getCommandHistory().size());
+    }
+    
+    @Test public void testOrderByOutsideOfSelect() {
+        // Create query 
+        String sql = "SELECT e1 FROM (select e1, e2 || e3 as e2 from pm1.g2) x order by e2"; //$NON-NLS-1$
+        
+        //a, a, null, c, b, a
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList("a"),
+            Arrays.asList("a"),
+            Arrays.asList(new String[] {null}),
+            Arrays.asList("c"),
+            Arrays.asList("b"),
+            Arrays.asList("a"),
+        };    
+    
+        // Construct data manager with data
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        // Plan query
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
+        
+        // Run query
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testOrderByUnrelatedExpression() {
+        String sql = "SELECT e1, e2 + 1 from pm1.g2 order by e3 || e2 limit 1"; //$NON-NLS-1$
+        
+        List[] expected = new List[] { 
+            Arrays.asList("a", 1),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+
+    /**
+     * Test a query that uses ambiguous alias names in the top level query and 
+     * its sub-query and uses columns belonging to the alias as a parameter to a 
+     * function.
+     * <p>
+     * For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT 
+     * CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
+     * <p>
+     * The test is to ensure that A.e2 from the top level is not confused with 
+     * e2 in the second level.
+     * <p>
+     * Related Defects: JBEDSP-1137
+     */
+    @Test public void testAliasReuseInFunctionInSubQuery() throws Exception {
+        // Create query
+    	String sql = "SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + //$NON-NLS-1$
+    	"   SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A WHERE e1 = 'a'" + //$NON-NLS-1$
+    	") AS A"; //$NON-NLS-1$
+        
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());
+        
+        List[] expected = new List[] {
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$
+            Arrays.asList(new Object[] { new BigInteger("3") }), //$NON-NLS-1$ 
+            Arrays.asList(new Object[] { new BigInteger("0") }), //$NON-NLS-1$ 
+        };
+
+        FakeDataManager manager = new FakeDataManager();
+        sampleData1(manager);
+        helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testOrderByDescAll() {
+        String sql = "SELECT distinct e1 from pm1.g2 order by e1 desc limit 1"; //$NON-NLS-1$
+        
+        List[] expected = new List[] { 
+            Arrays.asList("c"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testImplicitAggregateWithInlineView() {
+        String sql = "SELECT * FROM (SELECT b.count, enterprise_id FROM (SELECT COUNT(*), 2 AS enterprise_id FROM (SELECT 'A Name' AS Name, 1 AS enterprise_id) c ) b ) a WHERE enterprise_id = 1"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {};    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+        
+    private static final boolean DEBUG = false;
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestQueryProcessor.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestQueryProcessor.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestQueryProcessor.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestQueryProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,142 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidException;
+import org.teiid.query.processor.BatchCollector;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.util.CommandContext;
+
+import junit.framework.TestCase;
+
+
+/**
+ */
+public class TestQueryProcessor extends TestCase {
+
+    /**
+     * Constructor for TestQueryProcessor.
+     * @param name
+     */
+    public TestQueryProcessor(String name) {
+        super(name);
+    }
+    
+    public void helpTestProcessor(FakeProcessorPlan plan, long timeslice, List[] expectedResults) throws TeiidException {
+        BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
+        FakeDataManager dataManager = new FakeDataManager();
+
+        CommandContext context = new CommandContext("pid", "group", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
+        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
+        BatchCollector collector = processor.createBatchCollector();
+        TupleBuffer tsID = null;
+        while(true) {
+            try {
+                tsID = collector.collectTuples();         
+                break;
+            } catch(BlockedException e) {
+            }
+        }
+        
+        // Compare # of rows in actual and expected
+        assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount()); //$NON-NLS-1$
+        
+        // Compare actual with expected results
+        TupleSource actual = tsID.createIndexedTupleSource();
+        if(expectedResults.length > 0) {
+            for(int i=0; i<expectedResults.length; i++) {
+                List actRecord = actual.nextTuple();
+                List expRecord = expectedResults[i];                    
+                assertEquals("Did not match row at row index " + i, expRecord, actRecord); //$NON-NLS-1$
+            }
+        }
+        tsID.remove();
+    }
+    
+    public void testNoResults() throws Exception {
+        List elements = new ArrayList();
+        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
+        FakeProcessorPlan plan = new FakeProcessorPlan(elements, null);
+        helpTestProcessor(plan, 1000, new List[0]);    
+    }
+
+    public void testBlockNoResults() throws Exception {
+        List elements = new ArrayList();
+        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
+        
+        List batches = new ArrayList();
+        batches.add(BlockedException.INSTANCE);
+        TupleBatch batch = new TupleBatch(1, new List[0]);
+        batch.setTerminationFlag(true);
+        batches.add(batch);
+        
+        FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
+        helpTestProcessor(plan, 1000, new List[0]);    
+    }
+    
+    public void testProcessWithOccasionalBlocks() throws Exception {
+        List elements = new ArrayList();
+        elements.add(new ElementSymbol("a")); //$NON-NLS-1$
+                
+        HashSet blocked = new HashSet(Arrays.asList(new Integer[] { new Integer(0), new Integer(2), new Integer(7) }));
+        int numBatches = 10;
+        int batchRow = 1;        
+        int rowsPerBatch = 50;
+        List[] expectedResults = new List[rowsPerBatch*(numBatches-blocked.size())];
+        List batches = new ArrayList();
+        for(int b=0; b<numBatches; b++) {
+            if(blocked.contains(new Integer(b))) {
+                batches.add(BlockedException.INSTANCE);
+            } else {    
+                List[] rows = new List[rowsPerBatch];
+                for(int i=0; i<rowsPerBatch; i++) {
+                    rows[i] = new ArrayList();
+                    rows[i].add(new Integer(batchRow));
+                    expectedResults[batchRow-1] = rows[i];
+                    batchRow++;
+                }
+                                                
+                TupleBatch batch = new TupleBatch(batchRow-rows.length, rows);
+                if(b == numBatches-1) {
+                    batch.setTerminationFlag(true);
+                } 
+                batches.add(batch);
+            }
+        }
+        
+        FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
+        helpTestProcessor(plan, 1000, expectedResults);                    
+    }
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestSQLXMLProcessing.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,175 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.teiid.query.processor.TestProcessor.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+ at SuppressWarnings("nls")
+public class TestSQLXMLProcessing {
+	
+	@Test public void testXmlElementTextContent() throws Exception {
+		String sql = "SELECT xmlelement(foo, '<bar>', convert('<bar1/>', xml))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<foo>&lt;bar&gt;<bar1/></foo>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+	
+	/**
+	 * Repeat of the above test, but with a document declaration.  Because of the way we do event filtering, we end
+	 * up with a slightly different, but equivalent answer.
+	 */
+	@Test public void testXmlElementTextContent1() throws Exception {
+		String sql = "SELECT xmlelement(foo, '<bar>', convert('<?xml version=\"1.0\" encoding=\"UTF-8\"?><bar1/>', xml))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<foo>&lt;bar&gt;<bar1></bar1></foo>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+	}
+	
+    @Test public void testXmlElement() {
+        String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<e1>1</e1>"),
+        		Arrays.asList("<e1>0</e1>"),
+        		Arrays.asList("<e1>0</e1>"),
+        		Arrays.asList("<e1>3</e1>"),
+        		Arrays.asList("<e1>2</e1>"),
+                Arrays.asList("<e1>1</e1>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithConcat() {
+        String sql = "SELECT xmlelement(e1, e2, xmlconcat(xmlelement(x), xmlelement(y, e3))) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<e1>1<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
+        		Arrays.asList("<e1>3<x></x><y>true</y></e1>"),
+        		Arrays.asList("<e1>2<x></x><y>false</y></e1>"),
+                Arrays.asList("<e1>1<x></x><y>true</y></e1>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithForest() {
+        String sql = "SELECT xmlelement(x, xmlforest(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x><e2>1</e2><val>1</val></x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x><e1>a</e1><e2>0</e2><val>1</val></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithAttributes() {
+        String sql = "SELECT xmlelement(x, xmlattributes(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x e2=\"1\" val=\"1\"></x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x e1=\"a\" e2=\"0\" val=\"1\"></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithPi() {
+        String sql = "SELECT xmlelement(x, xmlpi(name e1, '  1'))"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x><?e1 1?></x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+    
+    @Test public void testXmlElementWithNamespaces() {
+        String sql = "SELECT xmlelement(x, xmlnamespaces(no default, 'http://foo' as x, 'http://foo1' as y), xmlattributes(e1), e2) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
+        
+        List[] expected = new List[] {
+        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\">1</x>"), //note e1 is not present, because it's null
+        		Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\" e1=\"a\">0</x>"),
+        };    
+    
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleData1(dataManager);
+        
+        ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+        
+        helpProcess(plan, dataManager, expected);
+    }
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestSecurityFunctions.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSecurityFunctions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,95 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.eval.SecurityFunctionEvaluator;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
+
+import junit.framework.TestCase;
+
+
+public class TestSecurityFunctions extends TestCase {
+
+    /**
+     *  hasRole should be true without a service
+     */
+    public void testHasRoleWithoutService() throws Exception {
+        
+        String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { 
+            Arrays.asList(new Object[] { new Integer(0) }),
+        };    
+        
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        
+        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { //$NON-NLS-1$
+            Arrays.asList(new Object[] { "fooRole", new Integer(0) }), //$NON-NLS-1$  
+        }); 
+        
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached());
+        
+        // Run query
+        TestProcessor.helpProcess(plan, dataManager, expected);
+    }
+    
+    public void testHasRoleWithService() throws Exception {
+        
+        String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";  //$NON-NLS-1$
+        
+        // Create expected results
+        List[] expected = new List[] { };    
+        
+        // Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+        
+        dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { //$NON-NLS-1$
+            Arrays.asList(new Object[] { "fooRole", new Integer(0) }), //$NON-NLS-1$  
+        }); 
+        
+        CommandContext context = new CommandContext();
+        context.setSecurityFunctionEvaluator(new SecurityFunctionEvaluator() {
+            public boolean hasRole(String roleType,
+                                   String roleName) throws TeiidComponentException {
+                return false;
+            }});
+        
+        Command command = TestProcessor.helpParse(sql);   
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, FakeMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
+        
+        // Run query
+        TestProcessor.helpProcess(plan, context, dataManager, expected);
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSetProcessing.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,87 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestSetProcessing {
+    
+    @Test public void testExcept() throws Exception {
+        String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(), new String[] {"SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g2.e1, pm1.g2.e2 FROM pm1.g2"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  //$NON-NLS-2$
+        
+        List<?>[] expected = new List[] {
+            Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {"a", 3}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {"b", 2}), //$NON-NLS-1$
+            };
+
+        FakeDataManager manager = new FakeDataManager();
+        TestProcessor.sampleData1(manager);
+        TestProcessor.helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testIntersect() throws Exception {
+        String sql = "select e1, e2 from pm1.g2 intersect select e1, 1 from pm1.g2"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(), new String[] {"SELECT pm1.g2.e1 FROM pm1.g2", "SELECT pm1.g2.e1, pm1.g2.e2 FROM pm1.g2"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$  //$NON-NLS-2$
+        
+        List<?>[] expected = new List[] {
+            Arrays.asList(new Object[] {null, 1}),
+            Arrays.asList(new Object[] {"c", 1}), //$NON-NLS-1$
+            };
+
+        FakeDataManager manager = new FakeDataManager();
+        TestProcessor.sampleData1(manager);
+        TestProcessor.helpProcess(plan, manager, expected);
+    }
+    
+    @Test public void testIntersectExcept() {
+        String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2 intersect select 'a', e2 from pm1.g2"; //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1, 1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT 'a', g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$  //$NON-NLS-2$ //$NON-NLS-3$
+        
+        List<?>[] expected = new List[] {
+            Arrays.asList(new Object[] {null, 1}),
+            Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {"a", 3}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {"b", 2}), //$NON-NLS-1$
+            Arrays.asList(new Object[] {"c", 1}), //$NON-NLS-1$
+            };
+
+        FakeDataManager manager = new FakeDataManager();
+        TestProcessor.sampleData1(manager);
+        TestProcessor.helpProcess(plan, manager, expected);
+    }
+
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,94 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.processor.TempTableDataManager;
+import org.teiid.query.tempdata.TempTableStoreImpl;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
+
+public class TestTempTables {
+	
+	private TempMetadataAdapter metadata;
+	private TempTableDataManager dataManager;
+
+	private void execute(String sql, List[] expectedResults) throws Exception {
+		TestProcessor.doProcess(TestProcessor.helpGetPlan(sql, metadata), dataManager, expectedResults, TestProcessor.createCommandContext());
+	}
+
+	@Before public void setUp() throws TeiidComponentException {
+		TempTableStoreImpl tempStore = new TempTableStoreImpl(BufferManagerFactory.getStandaloneBufferManager(), "1", null); //$NON-NLS-1$
+		metadata = new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), tempStore.getMetadataStore());
+		FakeDataManager fdm = new FakeDataManager();
+	    TestProcessor.sampleData1(fdm);
+		dataManager = new TempTableDataManager(fdm, tempStore);
+	}
+
+	@Test public void testInsertWithQueryExpression() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
+	}
+	
+	@Test public void testOutofOrderInsert() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("insert into x (e2, e1) values (1, 'one')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+		execute("select e1, e2 from x", new List[] {Arrays.asList("one", 1)}); //$NON-NLS-1$
+	}
+	
+	@Test public void testUpdate() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("insert into x (e2, e1) values (1, 'one')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("update x set e1 = e2 where e2 > 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
+		execute("select e1 from x where e2 > 0 order by e1", new List[] { //$NON-NLS-1$
+				Arrays.asList((String)null),
+				Arrays.asList("2"), //$NON-NLS-1$
+				Arrays.asList("3"), //$NON-NLS-1$
+				Arrays.asList("c"), //$NON-NLS-1$
+				Arrays.asList("one")}); //$NON-NLS-1$
+	}
+	
+	@Test public void testDelete() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("delete from x where ascii(e1) > e2", new List[] {Arrays.asList(5)}); //$NON-NLS-1$
+		execute("select e1 from x order by e1", new List[] {Arrays.asList((String)null)}); //$NON-NLS-1$
+	}
+	
+	@Test public void testDelete1() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer)", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("delete from x", new List[] {Arrays.asList(6)}); //$NON-NLS-1$
+		execute("select e1 from x order by e1", new List[] {}); //$NON-NLS-1$
+	}
+
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -0,0 +1,774 @@
+/*
+ * 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 org.teiid.query.processor;
+
+import static org.junit.Assert.*;
+
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.BatchCollector;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.TestValidator;
+
+
+public class TestVirtualDepJoin {
+    
+    /** 
+     * @param usAcctsElem
+     * @param is
+     * @param is2
+     * @param object
+     * @param object2
+     * @since 4.3
+     */
+    private static void setStats(List elementObjects,
+                                 int[] ndvs,
+                                 int[] nnvs,
+                                 String[] mins,
+                                 String[] maxs) {
+        
+        Iterator iter = elementObjects.iterator();
+        for(int i=0; iter.hasNext(); i++) {
+            FakeMetadataObject obj = (FakeMetadataObject) iter.next();
+            if(ndvs != null) {
+                obj.putProperty(FakeMetadataObject.Props.DISTINCT_VALUES, new Integer(ndvs[i]));
+            }
+            if(nnvs != null) {
+                obj.putProperty(FakeMetadataObject.Props.NULL_VALUES, new Integer(nnvs[i]));
+            }
+            if(mins != null) {
+                obj.putProperty(FakeMetadataObject.Props.MIN_VALUE, mins[i]);
+            }
+            if(maxs != null) {
+                obj.putProperty(FakeMetadataObject.Props.MAX_VALUE, maxs[i]);
+            }
+            
+        }
+    }
+    
+    public static FakeMetadataFacade exampleVirtualDepJoin() {
+        FakeMetadataObject us = FakeMetadataFactory.createPhysicalModel("US"); //$NON-NLS-1$
+        us.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
+        FakeMetadataObject usAccts = FakeMetadataFactory.createPhysicalGroup("US.Accounts", us); //$NON-NLS-1$
+        usAccts.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000000));
+        List usAcctsElem = FakeMetadataFactory.createElements(usAccts, 
+                                    new String[] { "customer", "account", "txn", "txnid", "pennies" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
+        setStats(usAcctsElem,
+                 new int[] { 1000, 1250, 4, 1000000, 800000}, // NDV per column
+                 new int[] { 0, 0, 0, 0, 0}, // NNV per column
+                 new String[] {"0", null, null, null, "-10"}, // min per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
+                 new String[] {"1000", null, null, null, "-5"}  // max per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
+        );
+
+        FakeMetadataObject europe = FakeMetadataFactory.createPhysicalModel("Europe"); //$NON-NLS-1$
+        europe.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
+        FakeMetadataObject euAccts = FakeMetadataFactory.createPhysicalGroup("Europe.CustAccts", europe); //$NON-NLS-1$
+        euAccts.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000000));
+        List euAcctsElem = FakeMetadataFactory.createElements(euAccts, 
+                                    new String[] { "id", "accid", "type", "amount" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.SHORT, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
+        setStats(euAcctsElem,
+                 new int[] { 10000, 1000000, 4, 1000000, 750000}, // NDV per column
+                 new int[] { 0, 0, 0, 0, 0}, // NNV per column
+                 null, // min per column - use defaults
+                 null  // max per column - use defaults
+        );
+
+        FakeMetadataObject cust = FakeMetadataFactory.createPhysicalModel("CustomerMaster"); //$NON-NLS-1$
+        cust.putProperty(FakeMetadataObject.Props.MAX_SET_SIZE, new Integer(0));
+        FakeMetadataObject customers = FakeMetadataFactory.createPhysicalGroup("CustomerMaster.Customers", cust); //$NON-NLS-1$
+        customers.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1000));
+        List customersElem = FakeMetadataFactory.createElements(customers, 
+                                    new String[] { "id", "first", "last", "birthday" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.DATE });
+        setStats(customersElem,
+                 new int[] { 1000, 800, 800, 365}, // NDV per column
+                 new int[] { 0, 0, 0, 0}, // NNV per column
+                 null, // min per column - use defaults
+                 null  // max per column - use defaults
+        );
+        FakeMetadataObject locations = FakeMetadataFactory.createPhysicalGroup("CustomerMaster.Locations", cust); //$NON-NLS-1$
+        locations.putProperty(FakeMetadataObject.Props.CARDINALITY, new Integer(1200));
+        List locationsElem = FakeMetadataFactory.createElements(locations, 
+                                    new String[] { "id", "location" }, //$NON-NLS-1$ //$NON-NLS-2$ 
+                                    new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING });
+        setStats(locationsElem,
+                 new int[] { 1000, 2}, // NDV per column
+                 new int[] { 0, 0, 0, 0}, // NNV per column
+                 null, // min per column - use defaults
+                 null  // max per column - use defaults
+        );
+
+        FakeMetadataObject vAccts = FakeMetadataFactory.createVirtualModel("Accounts"); //$NON-NLS-1$
+        QueryNode accountsPlan = new QueryNode("Accounts.Accounts", //$NON-NLS-1$
+                                               "SELECT customer as customer_id, convert(account, long) as account_id, convert(txnid, long) as transaction_id, case txn when 'DEP' then 1 when 'TFR' then 2 when 'WD' then 3 else -1 end as txn_type, (pennies + convert('0.00', bigdecimal)) / 100 as amount, 'US' as source FROM US.Accounts where txn != 'X'" +  //$NON-NLS-1$
+                                               "UNION ALL " +  //$NON-NLS-1$
+                                               "SELECT id, convert(accid / 10000, long), mod(accid, 10000), convert(type, integer), amount, 'EU' from Europe.CustAccts"); //$NON-NLS-1$ 
+        FakeMetadataObject accounts = FakeMetadataFactory.createVirtualGroup("Accounts.Accounts", vAccts, accountsPlan); //$NON-NLS-1$
+        List accountsElem = FakeMetadataFactory.createElements(accounts, 
+                                            new String[] { "customer_id", "account_id", "transaction_id", "txn_type", "amount", "source" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+                                            new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL, DataTypeManager.DefaultDataTypes.STRING });
+        
+        FakeMetadataObject master = FakeMetadataFactory.createVirtualModel("Master"); //$NON-NLS-1$
+        QueryNode masterPlan = new QueryNode("Master.Transactions", //$NON-NLS-1$
+                                               "select id as CustomerID, First, Last, a.account_id as AccountID, transaction_id as TransactionID, txn_type AS TxnCode, Amount from CustomerMaster.Customers c, Accounts.Accounts a where c.id=a.customer_id"); //$NON-NLS-1$ 
+        FakeMetadataObject transactions = FakeMetadataFactory.createVirtualGroup("Master.Transactions", master, masterPlan); //$NON-NLS-1$
+        List transactionsElem = FakeMetadataFactory.createElements(transactions, 
+                                            new String[] { "CustomerID", "First", "Last", "AccountID", "TransactionID", "TxnCode", "Amount" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+                                            new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
+        
+        FakeMetadataStore store = new FakeMetadataStore();
+        store.addObject(us);
+        store.addObject(usAccts);
+        store.addObjects(usAcctsElem);
+
+        store.addObject(europe);
+        store.addObject(euAccts);
+        store.addObjects(euAcctsElem);
+
+        store.addObject(cust);
+        store.addObject(customers);
+        store.addObjects(customersElem);
+        store.addObject(locations);
+        store.addObjects(locationsElem);
+        
+        store.addObject(vAccts);
+        store.addObject(accounts);
+        store.addObjects(accountsElem);
+
+        store.addObject(master);
+        store.addObject(transactions);
+        store.addObjects(transactionsElem);
+
+        return new FakeMetadataFacade(store);
+    }
+
+    @Test public void testVirtualDepJoinNoValues() throws Exception {  
+        // Create query  
+        String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first=-9999 group by c.id, first, last"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+ 
+        TestOptimizer.checkDependentJoinCount(plan, 1);
+        // Run query 
+        TestProcessor.helpProcess(plan, context, dataManager, expected); 
+
+        // Second query *will not be run* as no values were passed and dependent side has always false criteria
+        // So, the list should contain only the first query
+        assertEquals(3, dataManager.getQueries().size());       
+    }  
+    
+    public void helpTestVirtualDepJoinSourceSelection(boolean setPushdown) throws Exception {  
+        // Create query  
+        String sql = "select c.id as CustomerID, First, Last, a.account_id as AccountID, transaction_id as TransactionID, txn_type AS TxnCode, Amount, source from (CustomerMaster.Customers c join CustomerMaster.Locations l on c.id=l.id) join Accounts.Accounts a on c.id=a.customer_id and l.location=a.source where c.first='Miles' option makenotdep c, l"; //$NON-NLS-1$
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20"), "EU" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00"), "EU" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00"), "US" }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+        
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, setPushdown);    
+        finder.addCapabilities("US", caps); //$NON-NLS-1$
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+         
+        // Check plan contents
+        int selectCount = !setPushdown ? 2 : 0;
+        int accessCount = setPushdown ? 2 : 4;
+        int depAccessCount = 4 - accessCount;
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            accessCount,      // Access
+            depAccessCount,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            3,      // Project
+            selectCount,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });   
+                
+        // Run query 
+        TestProcessor.helpProcess(plan, context, dataManager, expected); 
+    }
+    
+    @Test public void testVirtualDepJoinSourceSelectionPushdown() throws Exception {
+        helpTestVirtualDepJoinSourceSelection(true);
+    }
+
+    @Test public void testVirtualDepJoinSourceSelectionNoPushdown() throws Exception {
+        helpTestVirtualDepJoinSourceSelection(false);
+    }
+
+    @Test public void testVirtualDepJoinPartialPushdown() throws Exception {  
+        // Create query  
+        String sql = "SELECT * from Master.Transactions where last = 'Davis'"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
+        BasicSourceCapabilities caps2 = TestOptimizer.getTypicalCapabilities();
+        caps2.setCapabilitySupport(Capability.CRITERIA_IN, false);    
+        finder.addCapabilities("US", caps1); //$NON-NLS-1$
+        finder.addCapabilities("Europe", caps2);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps1);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            3,      // Project
+            1,      // Select
+            0,      // Sort
+            1       // UnionAll
+        });   
+        
+        TestOptimizer.checkDependentJoinCount(plan, 1);        
+        // Run query 
+        TestProcessor.helpProcess(plan, context, dataManager, expected); 
+    }    
+
+    @Test public void testVirtualDepJoinOverAggregates() throws Exception {  
+        // Create query  
+        String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first='Miles' group by c.id, first, last"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { "Miles", "Davis", new BigDecimal("1007.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            3,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });   
+        
+        TestOptimizer.checkDependentJoinCount(plan, 1);        
+        // Run query 
+        TestProcessor.helpProcess(plan, context, dataManager, expected); 
+        
+        List<String> expectedQueries = new ArrayList<String>(6);
+        for (int i = 0; i < 3; i++) {
+        	expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.first AS c_1, g_0.last AS c_2 FROM CustomerMaster.Customers AS g_0 WHERE g_0.first = 'Miles' ORDER BY c_0"); //$NON-NLS-1$
+        	expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.amount AS c_1 FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100 ORDER BY c_0"); //$NON-NLS-1$
+        }
+        
+        assertEquals(expectedQueries, dataManager.getQueries());
+    }    
+    
+    @Test public void testVirtualDepJoinSelects() throws Exception {
+        helpTestVirtualDepJoin(false);
+    }
+    
+    @Test public void testVirtualDepJoinPushdown() throws Exception {
+        helpTestVirtualDepJoin(true);
+    }
+    
+    @Test public void testVirtualDepMultipleDependentBatches() throws Exception {  
+        helpTestMultipleBatches(true);
+    }
+    
+    @Test public void testVirtualDepMultipleDependentBatchesNonUnique() throws Exception {  
+        helpTestMultipleBatches(false);
+    }
+
+    private void helpTestMultipleBatches(boolean unique) throws Exception,
+                                          TeiidComponentException,
+                                          TeiidException,
+                                          SQLException {
+        // Create query  
+        String sql = "SELECT * from Master.Transactions where last = 'Davis' order by CustomerID, TransactionID"; //$NON-NLS-1$ 
+         
+        List expected = new LinkedList();
+        
+        
+        // Create expected results 
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        }            
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        if (!unique) {
+            expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        }
+        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(207), new Integer(3), new BigDecimal("12.34") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(299), new Integer(3), new BigDecimal("950.34") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1004), new Integer(3), new BigDecimal("542.20") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1005), new Integer(1), new BigDecimal("99.99") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1006), new Integer(1), new BigDecimal("10000.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1007), new Integer(2), new BigDecimal("0.75") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(630), new Long(1008), new Integer(2), new BigDecimal("62.00") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager();
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+        overrideVirtualDepJoinData(dataManager, metadata, unique);
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+        finder.addCapabilities("US", caps); //$NON-NLS-1$
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+ 
+        // Run query 
+        BufferManager bufferMgr = createCustomBufferMgr(2);
+        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
+        processor.setNonBlocking(true);
+        BatchCollector collector = processor.createBatchCollector();
+        TupleBuffer id = collector.collectTuples();
+
+        TestProcessor.examineResults((List[])expected.toArray(new List[expected.size()]), bufferMgr, id);
+    }
+
+    private BufferManager createCustomBufferMgr(int batchSize) throws TeiidComponentException {
+        BufferManagerImpl bufferMgr = new BufferManagerImpl();
+        bufferMgr.setConnectorBatchSize(batchSize);
+        bufferMgr.setProcessorBatchSize(batchSize);
+        bufferMgr.initialize();
+
+        // Add unmanaged memory storage manager
+        bufferMgr.setStorageManager(new MemoryStorageManager());
+
+        return bufferMgr;
+    }
+
+    public void helpTestVirtualDepJoin(boolean pushCriteria) throws Exception {  
+        // Create query  
+        String sql = "SELECT * from Master.Transactions where last = 'Davis'"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                        Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.CRITERIA_IN, pushCriteria);    
+        finder.addCapabilities("US", caps); //$NON-NLS-1$
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder); 
+ 
+        // Run query 
+        CommandContext context = TestProcessor.createCommandContext();
+        TestProcessor.helpProcess(plan, context, dataManager, expected); 
+    }
+    
+    private void sampleDataVirtualDepJoin(FakeDataManager dataMgr, FakeMetadataFacade metadata) throws Exception {
+        dataMgr.setBlockOnce();
+        // Group US.Accounts
+        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("US.Accounts"); //$NON-NLS-1$
+        List elementIDs = metadata.getElementIDsInGroupID(groupID);
+        List elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "DEP", new Integer(123), new Integer(10000) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "TFR", new Integer(127), new Integer(25000) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(100), new Integer(15000), "WD", new Integer(128), new Integer(100000) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(100), new Integer(15001), "DEP", new Integer(134), new Integer(1000) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(100), new Integer(15001), "DEP", new Integer(201), new Integer(1000) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "WD", new Integer(207), new Integer(1234) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "WD", new Integer(299), new Integer(95034) }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(200), new Integer(16000), "X", new Integer(301), new Integer(5000) }), //$NON-NLS-1$
+                } );    
+
+        // Group Europe.CustAccts
+        groupID = (FakeMetadataObject) metadata.getGroupID("Europe.CustAccts"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols,
+            
+            new List[] { 
+                Arrays.asList(new Object[] { new Long(100), new Long(5401002), new Short((short)1), new BigDecimal("7.20") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(100), new Long(5401003), new Short((short)2), new BigDecimal("1000.00") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(200), new Long(5501004), new Short((short)3), new BigDecimal("542.20") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(200), new Long(5501005), new Short((short)1), new BigDecimal("99.99") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(300), new Long(6201006), new Short((short)1), new BigDecimal("10000.00") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(300), new Long(6201007), new Short((short)2), new BigDecimal("0.75") }), //$NON-NLS-1$
+                Arrays.asList(new Object[] { new Long(300), new Long(6301008), new Short((short)2), new BigDecimal("62.00") }), //$NON-NLS-1$
+                } );    
+
+        // Group CustomerMaster.Customers
+        groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Customers"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        TimestampUtil ts = new TimestampUtil();
+        dataMgr.registerTuples(groupID, elementSymbols,                               
+                               new List[] { 
+                                   Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) }), //$NON-NLS-1$ //$NON-NLS-2$
+                                   Arrays.asList(new Object[] { new Long(200), "John", "Coltrane", ts.createDate(1926, 8, 23) }), //$NON-NLS-1$ //$NON-NLS-2$
+                                   Arrays.asList(new Object[] { new Long(300), "Thelonious", "Monk", ts.createDate(1917, 9, 10) }), //$NON-NLS-1$ //$NON-NLS-2$
+                                   } );    
+
+        // Group CustomerMaster.Locations
+        groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Locations"); //$NON-NLS-1$
+        elementIDs = metadata.getElementIDsInGroupID(groupID);
+        elementSymbols = FakeDataStore.createElements(elementIDs);
+    
+        dataMgr.registerTuples(groupID, elementSymbols,                               
+                               new List[] { 
+                                   Arrays.asList(new Object[] { new Long(100), "US" }), //$NON-NLS-1$ 
+                                   Arrays.asList(new Object[] { new Long(100), "EU" }), //$NON-NLS-1$ 
+                                   Arrays.asList(new Object[] { new Long(200), "US" }), //$NON-NLS-1$ 
+                                   Arrays.asList(new Object[] { new Long(200), "EU" }), //$NON-NLS-1$ 
+                                   Arrays.asList(new Object[] { new Long(300), "EU" }), //$NON-NLS-1$ 
+                                   } );        
+    }                    
+
+    private void overrideVirtualDepJoinData(FakeDataManager dataMgr, FakeMetadataFacade metadata, boolean unique) throws Exception {
+        // Group CustomerMaster.Customers
+        FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("CustomerMaster.Customers"); //$NON-NLS-1$
+        List elementIDs = metadata.getElementIDsInGroupID(groupID);
+        List elementSymbols = FakeDataStore.createElements(elementIDs);
+        
+        TimestampUtil ts = new TimestampUtil();
+        
+        List data = new LinkedList();
+        
+        data.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) })); //$NON-NLS-1$ //$NON-NLS-2$
+        if (!unique) {
+            data.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", ts.createDate(1926, 4, 25) })); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        data.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", ts.createDate(1926, 4, 26) })); //$NON-NLS-1$ //$NON-NLS-2$
+        data.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", ts.createDate(1926, 4, 27) })); //$NON-NLS-1$ //$NON-NLS-2$
+        data.add(Arrays.asList(new Object[] { new Long(400), "CloneC", "Davis", ts.createDate(1926, 4, 28) })); //$NON-NLS-1$ //$NON-NLS-2$
+        
+        dataMgr.registerTuples(
+            groupID,
+            elementSymbols, (List[])data.toArray(new List[data.size()]));
+    }
+    
+    @Test public void testVirtualAccessVirtualDep() throws Exception {
+        String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
+        
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        finder.addCapabilities("test", caps); //$NON-NLS-1$
+        
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, finder, 
+                                                    new String[] {"SELECT g_0.e2 AS c_0 FROM test.\"group\" AS g_0 WHERE (g_0.e0 = 1) AND (g_0.e1 = '2') ORDER BY c_0", //$NON-NLS-1$
+        														  "SELECT g_0.e0 AS c_0, g_0.e1 AS c_1, g_0.e0 AS c_2 FROM test.\"group\" AS g_0 WHERE (g_0.e0 IN (<dependent values>)) AND (g_0.e1 IN (<dependent values>)) ORDER BY c_2, c_1"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+        
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            1,      // Access
+            1,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });
+    }
+    
+    /**
+     * Here the virtual makenotdep hint causes us to throw an exception 
+     *
+     */
+    @Test public void testVirtualAccessVirtualDep2() {
+        String sql = "SELECT a.e0, b.e2 FROM vTest.vGroup a makenotdep inner join vTest.vGroup b on (a.e0 = b.e2 and a.e1 = b.e2) where b.e0=1 and b.e1='2'"; //$NON-NLS-1$
+        
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setFunctionSupport("convert", true); //$NON-NLS-1$
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        finder.addCapabilities("test", caps); //$NON-NLS-1$
+        
+        TestOptimizer.helpPlan(sql, TestValidator.exampleMetadata4(), null, finder, 
+                                                    new String[] {}, TestOptimizer.SHOULD_FAIL);
+        
+    }
+    
+    /**
+     *  same as testVirtualDepJoinOverAggregate, but the makenotdep hint prevents the
+     *  dependent join from happening
+     */
+    @Test public void testVirtualDepJoinOverAggregates2() throws Exception {  
+        // Create query  
+        String sql = "select first, last, sum(amount) from Europe.CustAccts e makenotdep join CustomerMaster.Customers c on c.id=e.id where c.first='Miles' group by c.id, first, last"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { "Miles", "Davis", new BigDecimal("1007.20") }), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = exampleVirtualDepJoin();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        sampleDataVirtualDepJoin(dataManager, metadata); 
+         
+        // Plan query 
+        CommandContext context = TestProcessor.createCommandContext();
+
+        Command command = TestProcessor.helpParse(sql);   
+        FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);    
+        finder.addCapabilities("Europe", caps);//$NON-NLS-1$
+        finder.addCapabilities("CustomerMaster", caps);//$NON-NLS-1$
+        ProcessorPlan plan = TestProcessor.helpGetPlan(command, exampleVirtualDepJoin(), finder, context); 
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            0,      // DupRemove
+            3,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            1,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            0,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });   
+        
+        TestOptimizer.checkDependentJoinCount(plan, 0);        
+        // Run query 
+        TestProcessor.helpProcess(plan, context, dataManager, expected);         
+    }    
+
+    
+    @Test public void testVirtualMakeDepHint() throws Exception {  
+        // Create query  
+        String sql = "select distinct pm1.g1.e1 from (pm1.g1 inner join pm1.g2 on g1.e1 = g2.e1) makedep inner join pm2.g1 on pm2.g1.e1 = pm1.g1.e1 where pm2.g1.e3 = 1"; //$NON-NLS-1$ 
+         
+        // Create expected results 
+        List[] expected = new List[] {  
+                        Arrays.asList(new Object[] { "a" }), //$NON-NLS-1$
+                        Arrays.asList(new Object[] { "c" }), //$NON-NLS-1$
+                };     
+
+        // Construct data manager with data 
+        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();        
+        FakeDataManager dataManager = new FakeDataManager(); 
+        TestProcessor.sampleData1(dataManager); 
+         
+        // Plan query 
+        ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata); 
+ 
+        TestOptimizer.checkNodeTypes(plan, new int[] {
+            3,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            0,      // NestedLoopJoinStrategy
+            2,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            1,      // Project
+            2,      // Select
+            0,      // Sort
+            0       // UnionAll
+        });   
+        
+        TestOptimizer.checkDependentJoinCount(plan, 1);        
+        // Run query 
+        TestProcessor.helpProcess(plan, new CommandContext(), dataManager, expected);         
+    }    
+
+    
+}

Copied: trunk/engine/src/test/java/org/teiid/query/processor/batch (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/batch)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/batch/TestBatchedUpdatePlan.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/batch/TestBatchedUpdatePlan.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/batch/TestBatchedUpdatePlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.batch;
+package org.teiid.query.processor.batch;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.query.processor.FakeProcessorPlan;
+import org.teiid.query.processor.batch.BatchedUpdatePlan;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.query.processor.FakeProcessorPlan;
 
 
 /** 

Copied: trunk/engine/src/test/java/org/teiid/query/processor/dynamic (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/dynamic/SimpleQueryProcessorFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/SimpleQueryProcessorFactory.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/dynamic/SimpleQueryProcessorFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,26 +20,27 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.dynamic;
+package org.teiid.query.processor.dynamic;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.core.id.IDGenerator;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.util.CommandContext;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.CommandContext;
 
 
+
 public class SimpleQueryProcessorFactory implements QueryProcessor.ProcessorFactory {
 
 	private QueryMetadataInterface metadata;
@@ -60,7 +61,7 @@
 
 	@Override
 	public QueryProcessor createQueryProcessor(String sql, String recursionGroup, CommandContext commandContext)
-			throws MetaMatrixProcessingException, MetaMatrixComponentException {
+			throws TeiidProcessingException, TeiidComponentException {
 		Command command = QueryParser.getQueryParser().parseCommand(sql);
 		QueryResolver.resolveCommand(command, metadata);
 		command = QueryRewriter.rewrite(command, metadata, commandContext);

Modified: trunk/engine/src/test/java/org/teiid/query/processor/dynamic/TestSqlEval.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/dynamic/TestSqlEval.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/dynamic/TestSqlEval.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,30 +20,31 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.dynamic;
+package org.teiid.query.processor.dynamic;
 
 import java.util.Collections;
 
 import javax.xml.transform.Source;
 
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.types.StandardXMLTranslator;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.FakeDataStore;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.processor.xquery.SqlEval;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.types.StandardXMLTranslator;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.FakeDataStore;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.processor.xquery.SqlEval;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 

Copied: trunk/engine/src/test/java/org/teiid/query/processor/eval (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/eval)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestCriteriaEvaluator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.eval;
+package org.teiid.query.processor.eval;
 
 import static org.junit.Assert.*;
 
@@ -34,32 +34,32 @@
 import java.util.Map;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.eval.Evaluator;
+import org.teiid.query.sql.lang.CollectionValueIterator;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.ExistsCriteria;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.SubqueryCompareCriteria;
+import org.teiid.query.sql.lang.SubqueryContainer;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.util.ValueIterator;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.CriteriaEvaluationException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.sql.lang.CollectionValueIterator;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.ExistsCriteria;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubqueryContainer;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.util.ValueIterator;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestCriteriaEvaluator {
 
 	// ################################## TEST HELPERS ################################
 	
-    private void helpTestMatch(String value, String pattern, char escape, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
+    private void helpTestMatch(String value, String pattern, char escape, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
         MatchCriteria crit = new MatchCriteria(new Constant(value), new Constant(pattern), escape);
         crit.setNegated(negated);
         boolean actualMatch = Evaluator.evaluate(crit);
@@ -67,11 +67,11 @@
         assertEquals("Match criteria test failed for value=[" + value + "], pattern=[" + pattern + "], hasEscape=" + (escape != MatchCriteria.NULL_ESCAPE_CHAR) + ": ", expectedMatch, actualMatch); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
     
-    private void helpTestMatch(String value, String pattern, char escape, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
+    private void helpTestMatch(String value, String pattern, char escape, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
         helpTestMatch(value, pattern, escape, false, expectedMatch);
     }
 	
-    private void helpTestIsNull(String value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
+    private void helpTestIsNull(String value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
         IsNullCriteria criteria = new IsNullCriteria(new Constant(value));
         criteria.setNegated(negated);
         
@@ -79,11 +79,11 @@
         assertEquals("Result did not match expected value", expectedMatch, result); //$NON-NLS-1$
     }
     
-    private void helpTestSetCriteria(int value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
+    private void helpTestSetCriteria(int value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
         helpTestSetCriteria(new Integer(value), negated, expectedMatch);
     }
     
-    private void helpTestSetCriteria(Integer value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException {
+    private void helpTestSetCriteria(Integer value, boolean negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
         Collection constants = new ArrayList(2);
         constants.add(new Constant(new Integer(1000)));
         constants.add(new Constant(new Integer(5000)));
@@ -93,7 +93,7 @@
         assertEquals("Result did not match expected value", expectedMatch, result); //$NON-NLS-1$
     }
         
-    private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult, final Collection values) throws CriteriaEvaluationException, BlockedException, MetaMatrixComponentException{
+    private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult, final Collection values) throws CriteriaEvaluationException, BlockedException, TeiidComponentException{
         
         Map elementMap = new HashMap();
         ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$
@@ -105,8 +105,8 @@
         	@Override
         	protected ValueIterator evaluateSubquery(
         			SubqueryContainer container, List tuple)
-        			throws MetaMatrixProcessingException, BlockedException,
-        			MetaMatrixComponentException {
+        			throws TeiidProcessingException, BlockedException,
+        			TeiidComponentException {
         		return new CollectionValueIterator(values);
         	}
         }.evaluate(crit, tuple));

Modified: trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.eval;
+package org.teiid.query.processor.eval;
 
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -30,33 +30,34 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidException;
+import org.teiid.query.eval.Evaluator;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.sql.lang.CollectionValueIterator;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SubqueryContainer;
+import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.ScalarSubquery;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.TestCaseExpression;
+import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
+import org.teiid.query.sql.util.ValueIterator;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.eval.Evaluator;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.lang.CollectionValueIterator;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SubqueryContainer;
-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.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-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.util.CommandContext;
 
 /**
  */
@@ -74,12 +75,12 @@
         try {
             Object actualValue = helpEval(expr, elementList, valueList, dataMgr, context, expectedValue);
             assertEquals("Did not get expected result", expectedValue, actualValue); //$NON-NLS-1$
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             fail("Received unexpected exception: " + e.getFullMessage()); //$NON-NLS-1$
         }
     }
 
-    public Object helpEval(Expression expr, SingleElementSymbol[] elementList, Object[] valueList, ProcessorDataManager dataMgr, CommandContext context, Object expectedValue) throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
+    public Object helpEval(Expression expr, SingleElementSymbol[] elementList, Object[] valueList, ProcessorDataManager dataMgr, CommandContext context, Object expectedValue) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
         Map elements = new HashMap();
         if (elementList != null) {
             for(int i=0; i<elementList.length; i++) {
@@ -185,7 +186,7 @@
         try {
             helpEval(e2, elements, values, null, null, null); 
             fail("Exception expected"); //$NON-NLS-1$
-        } catch (MetaMatrixComponentException e){
+        } catch (TeiidComponentException e){
         	//this should be a componentexception, since it is unexpected
             assertEquals(e.getMessage(), "Error Code:ERR.015.006.0033 Message:Unable to evaluate e2: No value was available"); //$NON-NLS-1$
         }
@@ -271,15 +272,15 @@
 	private void helpTestWithValueIterator(ScalarSubquery expr,
 			List<?> values, Object expected)
 			throws BlockedException,
-			MetaMatrixComponentException, ExpressionEvaluationException {
+			TeiidComponentException, ExpressionEvaluationException {
 		final CollectionValueIterator valueIter = new CollectionValueIterator(values);
         CommandContext cc = new CommandContext();
         assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc) {
         	@Override
         	protected ValueIterator evaluateSubquery(
         			SubqueryContainer container, List tuple)
-        			throws MetaMatrixProcessingException, BlockedException,
-        			MetaMatrixComponentException {
+        			throws TeiidProcessingException, BlockedException,
+        			TeiidComponentException {
         		return valueIter;
         	}
         }.evaluate(expr, null) );

Copied: trunk/engine/src/test/java/org/teiid/query/processor/proc (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/proc)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,10 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.proc;
+package org.teiid.query.processor.proc;
 
 import static org.junit.Assert.*;
 
-import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -32,47 +31,39 @@
 import java.util.Map;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryValidatorException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.xml.TestXMLPlanningEnhancements;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorFailure;
+import org.teiid.query.validator.ValidatorReport;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.BatchCollector;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.processor.xml.TestXMLPlanningEnhancements;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.validator.Validator;
-import com.metamatrix.query.validator.ValidatorFailure;
-import com.metamatrix.query.validator.ValidatorReport;
 
 public class TestProcedureProcessor {
 	
@@ -104,97 +95,41 @@
         }
     }
     
-    static void helpTestProcess(ProcessorPlan procPlan, int rowsUpdated, List[] expectedResults, boolean shouldFail, ProcessorDataManager dataMgr, QueryMetadataInterface metadata) throws SQLException, MetaMatrixCoreException {
-        // Process twice, testing reset and clone method of Processor plan
-        for (int i=1; i<=2; i++) {
-        	
-            CommandContext context = new CommandContext("pID", null, null, null, 1); //$NON-NLS-1$
-            context.getNextRand(0);
-            context.setProcessDebug(DEBUG);
-            context.setMetadata(metadata);        	
-        	
-	        BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
-
-            QueryProcessor processor = new QueryProcessor(procPlan, context, bufferMgr, dataMgr);
-            processor.setNonBlocking(true);
-            BatchCollector collector = processor.createBatchCollector();  
-	        TupleBuffer tsID = collector.collectTuples();
-	
-	        // Create QueryResults from TupleSource
-	        TupleSource ts = tsID.createIndexedTupleSource();
-	        int count = tsID.getRowCount();   
-            
-            if(DEBUG) {
-                System.out.println("\nResults:\n" + tsID.getSchema()); //$NON-NLS-1$
-                TupleSource ts2 = tsID.createIndexedTupleSource();
-                for(int j=0; j<count; j++) {
-                    System.out.println("" + j + ": " + ts2.nextTuple());     //$NON-NLS-1$ //$NON-NLS-2$
-                }    
-                ts2.closeSource();
-            }
-            
-            if (shouldFail) {
-                fail("Expected processing to fail"); //$NON-NLS-1$
-            }
-            
-            if (expectedResults == null) {
-                assertEquals("Incorrect number of rows: ", 1, count);   //$NON-NLS-1$
-                List tuple = ts.nextTuple();   	
-    	        assertEquals("Incorrect number of columns: ", 1, tuple.size());	 //$NON-NLS-1$
-                
-                Integer rowCount = (Integer) tuple.get(0);                
-                assertEquals("Rows updated mismatch: ", rowsUpdated, rowCount.intValue()); //$NON-NLS-1$
-            }
-	        
-            if (expectedResults != null) {
-    	        //Walk results and compare
-                ts = tsID.createIndexedTupleSource();
-                assertEquals("Incorrect number of rows: ", expectedResults.length, count);   //$NON-NLS-1$
-                for(int j=0; j<count; j++) { 
-                    List record = ts.nextTuple();  
-                    
-                    //handle xml
-                    if(record.size() == 1 && expectedResults[j].size() == 1){
-                        Object cellValue = record.get(0);
-                        if(cellValue instanceof XMLType){
-                            XMLType id =  (XMLType)cellValue; 
-                            String actualDoc = id.getString(); 
-                            TestXMLProcessor.compareDocuments((String)expectedResults[j].get(0), actualDoc);
-                            continue;
-                        }
-                    }
-                    assertEquals("Row " + j + " does not match expected: ", expectedResults[j], record);                 //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                ts.closeSource();
-            }
-            
-            //reset and clone after 1st run
-            if (i==1) {
-                procPlan.reset();
-                procPlan = procPlan.clone();
-            }
+    static void helpTestProcess(ProcessorPlan procPlan, int rowsUpdated, List[] expectedResults, boolean shouldFail, ProcessorDataManager dataMgr, QueryMetadataInterface metadata) throws Exception {
+        CommandContext context = new CommandContext("pID", null, null, null, 1); //$NON-NLS-1$
+        context.getNextRand(0);
+        context.setProcessDebug(DEBUG);
+        context.setMetadata(metadata);        	
+        
+        if (expectedResults == null) {
+        	expectedResults = new List[] {Arrays.asList(rowsUpdated)};
         }
+
+    	TestProcessor.helpProcess(procPlan, context, dataMgr, expectedResults);
+    	if (shouldFail) {
+    		fail("Expected processing to fail"); //$NON-NLS-1$
+    	}
     }
 
     private void helpTestProcessFailure(boolean optimistic, ProcessorPlan procPlan, 
-                                 FakeDataManager dataMgr, String failMessage) throws SQLException, MetaMatrixCoreException {
+                                 FakeDataManager dataMgr, String failMessage) throws Exception {
         try {
             helpTestProcess(optimistic, procPlan, new List[] {}, dataMgr, true);
-        } catch(MetaMatrixException ex) {
+        } catch(TeiidException ex) {
             assertEquals(failMessage, ex.getMessage());
         }
     }
     
-    public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, ProcessorDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
+    public static void helpTestProcess(ProcessorPlan procPlan, List[] expectedResults, ProcessorDataManager dataMgr) throws Exception {
         helpTestProcess(false, procPlan, expectedResults, dataMgr, false);
     }
     
-    private void helpTestProcess(ProcessorPlan procPlan, int expectedRows, FakeDataManager dataMgr) throws SQLException, MetaMatrixCoreException {
+    private void helpTestProcess(ProcessorPlan procPlan, int expectedRows, FakeDataManager dataMgr) throws Exception {
         helpTestProcess(procPlan, expectedRows, null, false, dataMgr, null);
     }
     
     static void helpTestProcess(boolean optimistic, ProcessorPlan procPlan, List[] expectedResults, 
-    		ProcessorDataManager dataMgr, boolean shouldFail) throws SQLException, MetaMatrixCoreException {
+    		ProcessorDataManager dataMgr, boolean shouldFail) throws Exception {
         helpTestProcess(procPlan, 0, expectedResults, shouldFail, dataMgr, null);
     }
 
@@ -210,7 +145,7 @@
         return elements;
     }    
     
-    private FakeDataManager exampleDataManager(FakeMetadataFacade metadata) throws QueryMetadataException, MetaMatrixComponentException {
+    private FakeDataManager exampleDataManager(FakeMetadataFacade metadata) throws QueryMetadataException, TeiidComponentException {
         FakeDataManager dataMgr = new FakeDataManager();
     
         FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
@@ -244,7 +179,7 @@
         return dataMgr;
     }    
     
-    private FakeDataManager exampleDataManager2(FakeMetadataFacade metadata) throws QueryMetadataException, MetaMatrixComponentException {
+    private FakeDataManager exampleDataManager2(FakeMetadataFacade metadata) throws QueryMetadataException, TeiidComponentException {
         FakeDataManager dataMgr = new FakeDataManager();
     
         FakeMetadataObject groupID = (FakeMetadataObject) metadata.getGroupID("pm1.g1"); //$NON-NLS-1$
@@ -306,7 +241,7 @@
         return dataMgr;
     }    
     
-    private FakeDataManager exampleDataManagerPm5(FakeMetadataFacade metadata) throws QueryMetadataException, MetaMatrixComponentException {
+    private FakeDataManager exampleDataManagerPm5(FakeMetadataFacade metadata) throws QueryMetadataException, TeiidComponentException {
         FakeDataManager dataMgr = new FakeDataManager();
     
         // Group stock.items
@@ -928,7 +863,11 @@
             Arrays.asList(new Object[] { "Second"}),  //$NON-NLS-1$
             Arrays.asList(new Object[] { "Third"}),  //$NON-NLS-1$
             Arrays.asList(new Object[] { "Fourth"})};           //$NON-NLS-1$
-        helpTestProcess(plan, expected, dataMgr);
+        CommandContext context = new CommandContext("pID", null, null, null, 1); //$NON-NLS-1$
+        context.setMetadata(metadata);
+        context.setProcessorBatchSize(1); //ensure that the final temp result set will not be deleted prematurely 
+
+    	TestProcessor.helpProcess(plan, context, dataMgr, expected);
     }
     
     @Test public void testVirtualProcedure17() throws Exception {
@@ -2372,40 +2311,40 @@
         FakeMetadataFacade metadata = TestXMLProcessor.exampleMetadataCached();
         FakeDataManager dataMgr = TestXMLProcessor.exampleDataManagerNested(metadata);
         String expectedDoc = 
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +  //$NON-NLS-1$
-            "<Catalogs>\r\n" + //$NON-NLS-1$
-            "    <Catalog>\r\n" +  //$NON-NLS-1$
-            "        <Items>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"001\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Lamp</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>5</Quantity>\r\n" + //$NON-NLS-1$
-            "                <Suppliers>\r\n" + //$NON-NLS-1$
-            "                    <Supplier SupplierID=\"52\">\r\n" + //$NON-NLS-1$
-            "                        <Name>Biff's Stuff</Name>\r\n" + //$NON-NLS-1$
-            "                        <Zip>22222</Zip>\r\n" + //$NON-NLS-1$
-            "                        <Orders>\r\n" + //$NON-NLS-1$
-            "                            <Order OrderID=\"2\">\r\n" + //$NON-NLS-1$
-            "                                <OrderDate>12/31/01</OrderDate>\r\n" + //$NON-NLS-1$
-            "                                <OrderQuantity>87</OrderQuantity>\r\n" + //$NON-NLS-1$
-            "                                <OrderStatus>complete</OrderStatus>\r\n" + //$NON-NLS-1$
-            "                            </Order>\r\n" + //$NON-NLS-1$
-            "                        </Orders>\r\n" + //$NON-NLS-1$
-            "                    </Supplier>\r\n" + //$NON-NLS-1$
-            "                </Suppliers>\r\n" + //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"002\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Screwdriver</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>100</Quantity>\r\n" +  //$NON-NLS-1$
-            "                <Suppliers/>\r\n" + //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"003\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Goat</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>4</Quantity>\r\n" +  //$NON-NLS-1$
-            "                <Suppliers/>\r\n" + //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "        </Items>\r\n" +  //$NON-NLS-1$
-            "    </Catalog>\r\n" +  //$NON-NLS-1$
-            "</Catalogs>\r\n\r\n"; //$NON-NLS-1$
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +  //$NON-NLS-1$
+            "<Catalogs>\n" + //$NON-NLS-1$
+            "   <Catalog>\n" +  //$NON-NLS-1$
+            "      <Items>\n" +  //$NON-NLS-1$
+            "         <Item ItemID=\"001\">\n" +  //$NON-NLS-1$
+            "            <Name>Lamp</Name>\n" +  //$NON-NLS-1$
+            "            <Quantity>5</Quantity>\n" + //$NON-NLS-1$
+            "            <Suppliers>\n" + //$NON-NLS-1$
+            "               <Supplier SupplierID=\"52\">\n" + //$NON-NLS-1$
+            "                  <Name>Biff's Stuff</Name>\n" + //$NON-NLS-1$
+            "                  <Zip>22222</Zip>\n" + //$NON-NLS-1$
+            "                  <Orders>\n" + //$NON-NLS-1$
+            "                     <Order OrderID=\"2\">\n" + //$NON-NLS-1$
+            "                        <OrderDate>12/31/01</OrderDate>\n" + //$NON-NLS-1$
+            "                        <OrderQuantity>87</OrderQuantity>\n" + //$NON-NLS-1$
+            "                        <OrderStatus>complete</OrderStatus>\n" + //$NON-NLS-1$
+            "                     </Order>\n" + //$NON-NLS-1$
+            "                  </Orders>\n" + //$NON-NLS-1$
+            "               </Supplier>\n" + //$NON-NLS-1$
+            "            </Suppliers>\n" + //$NON-NLS-1$
+            "         </Item>\n" +  //$NON-NLS-1$
+            "         <Item ItemID=\"002\">\n" +  //$NON-NLS-1$
+            "            <Name>Screwdriver</Name>\n" +  //$NON-NLS-1$
+            "            <Quantity>100</Quantity>\n" +  //$NON-NLS-1$
+            "            <Suppliers/>\n" + //$NON-NLS-1$
+            "         </Item>\n" +  //$NON-NLS-1$
+            "         <Item ItemID=\"003\">\n" +  //$NON-NLS-1$
+            "            <Name>Goat</Name>\n" +  //$NON-NLS-1$
+            "            <Quantity>4</Quantity>\n" +  //$NON-NLS-1$
+            "            <Suppliers/>\n" + //$NON-NLS-1$
+            "         </Item>\n" +  //$NON-NLS-1$
+            "      </Items>\n" +  //$NON-NLS-1$
+            "   </Catalog>\n" +  //$NON-NLS-1$
+            "</Catalogs>"; //$NON-NLS-1$
 
         FakeMetadataObject pm1 = metadata.getStore().findObject("xmltest",FakeMetadataObject.MODEL); //$NON-NLS-1$
         

Copied: trunk/engine/src/test/java/org/teiid/query/processor/relational (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/relational)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/BlockingFakeRelationalNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/BlockingFakeRelationalNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/BlockingFakeRelationalNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.List;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.*;
+import org.teiid.common.buffer.*;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
 
+
 public class BlockingFakeRelationalNode extends FakeRelationalNode {
 
     private int count = 1;
@@ -59,7 +60,7 @@
 		this.returnPeriod = returnPeriod;
 	}
 
-    public TupleBatch nextBatchDirect() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
         if (count++%returnPeriod != 0) {
         	throw BlockedException.INSTANCE;
         }

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/FakeRelationalNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/FakeRelationalNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/FakeRelationalNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.*;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.*;
+import org.teiid.common.buffer.*;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.processor.relational.RelationalNode;
 
+
 /**
  */
 public class FakeRelationalNode extends RelationalNode {
@@ -66,10 +68,10 @@
     }
 
     /**
-     * @throws MetaMatrixProcessingException 
+     * @throws TeiidProcessingException 
      * @see com.metamatrix.query.processor.relational.x.RelationalNode#nextBatch()
      */
-    public TupleBatch nextBatchDirect() throws BlockedException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
         if(data != null) {
             if(currentRow < data.length) {
                 int endRow = Math.min(data.length, currentRow+getBatchSize());            
@@ -115,7 +117,7 @@
     
     
     /** 
-     * @see com.metamatrix.query.processor.relational.RelationalNode#getBatchSize()
+     * @see org.teiid.query.processor.relational.RelationalNode#getBatchSize()
      * @since 4.2
      */
     protected int getBatchSize() {

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/NodeTestUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/NodeTestUtil.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/NodeTestUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.Properties;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.StorageManager;
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.buffer.impl.MemoryStorageManager;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.core.TeiidComponentException;
 
 
+
 /** 
  * @since 4.2
  */
@@ -54,7 +55,7 @@
     static BufferManager createBufferManager(BufferManagerImpl bufferManager) {
         try {
 			bufferManager.initialize();
-		} catch (MetaMatrixComponentException e) {
+		} catch (TeiidComponentException e) {
 			throw new RuntimeException(e);
 		}
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestAccessNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,29 +20,32 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.Arrays;
 
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.relational.AccessNode;
+import org.teiid.query.processor.relational.RelationalNodeUtil;
+import org.teiid.query.resolver.TestResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SetClauseList;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.resolver.TestResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompoundCriteria;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SetClauseList;
-import com.metamatrix.query.sql.lang.Update;
-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.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestBatchedUpdateNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestBatchedUpdateNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestBatchedUpdateNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import static org.junit.Assert.*;
 
@@ -31,20 +31,21 @@
 
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.batch.TestBatchedUpdatePlanner;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.relational.BatchedUpdateNode;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.visitor.EvaluatableVisitor;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-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.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.batch.TestBatchedUpdatePlanner;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.visitor.EvaluatableVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 
@@ -210,8 +211,8 @@
         private FakePDM(int numExecutedCommands) {
         	this.numExecutedCommands = numExecutedCommands;
         }
-        public Object lookupCodeValue(CommandContext context,String codeTableName,String returnElementName,String keyElementName,Object keyValue) throws BlockedException,MetaMatrixComponentException {return null;}
-        public TupleSource registerRequest(Object processorID,Command command,String modelName,String connectorBindingId, int nodeID) throws MetaMatrixComponentException {
+        public Object lookupCodeValue(CommandContext context,String codeTableName,String returnElementName,String keyElementName,Object keyValue) throws BlockedException,TeiidComponentException {return null;}
+        public TupleSource registerRequest(Object processorID,Command command,String modelName,String connectorBindingId, int nodeID) throws TeiidComponentException {
             assertEquals("myProcessorID", processorID); //$NON-NLS-1$
             assertEquals("myModelName", modelName); //$NON-NLS-1$
             assertEquals(1, nodeID);
@@ -233,7 +234,7 @@
         }
         public void closeSource() {}
         public List getSchema() {return null;}
-        public List nextTuple() throws MetaMatrixComponentException {
+        public List nextTuple() throws TeiidComponentException {
             if (first) {
             	first = false;
             	throw BlockedException.INSTANCE;

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDependentCriteriaProcessor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDependentCriteriaProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,23 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.Arrays;
 import java.util.List;
 
 import static org.junit.Assert.*;
 import org.junit.Test;
+import org.teiid.query.processor.relational.DependentAccessNode;
+import org.teiid.query.processor.relational.DependentCriteriaProcessor;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.util.CommandContext;
 
-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 {
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDuplicateFilter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestDuplicateFilter.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestDuplicateFilter.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.function.aggregate.Count;
+import org.teiid.query.processor.relational.DuplicateFilter;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.function.aggregate.Count;
 
 /**
  */
@@ -43,7 +45,7 @@
         super(arg0);
     }
     
-    public void helpTestDuplicateFilter(Object[] input, Class dataType, int expected) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestDuplicateFilter(Object[] input, Class dataType, int expected) throws TeiidComponentException, TeiidProcessingException {
         BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
         
         DuplicateFilter filter = new DuplicateFilter(new Count(), mgr, "test"); //$NON-NLS-1$

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestGroupingNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestGroupingNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestGroupingNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import static org.junit.Assert.*;
 
@@ -32,29 +32,32 @@
 import java.util.Map;
 
 import org.junit.Test;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.aggregate.AggregateFunction;
+import org.teiid.query.function.aggregate.NullFilter;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.FakeTupleSource;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.relational.DuplicateFilter;
+import org.teiid.query.processor.relational.GroupingNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.function.aggregate.AggregateFunction;
-import com.metamatrix.query.function.aggregate.NullFilter;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.FakeTupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestGroupingNode {
 
@@ -88,9 +91,9 @@
 	private void helpProcess(BufferManager mgr,
                              GroupingNode node,
                              CommandContext context,
-                             List[] expected, ProcessorDataManager dataMgr) throws MetaMatrixComponentException,
+                             List[] expected, ProcessorDataManager dataMgr) throws TeiidComponentException,
                                              BlockedException,
-                                             MetaMatrixProcessingException {
+                                             TeiidProcessingException {
         TupleSource dataSource = createTupleSource1();
         helpProcess(mgr, node, context, expected, dataSource, dataMgr);
     }
@@ -99,9 +102,9 @@
                              GroupingNode node,
                              CommandContext context,
                              List[] expected,
-                             TupleSource dataSource, ProcessorDataManager dataMgr) throws MetaMatrixComponentException,
+                             TupleSource dataSource, ProcessorDataManager dataMgr) throws TeiidComponentException,
                                                     BlockedException,
-                                                    MetaMatrixProcessingException {
+                                                    TeiidProcessingException {
         RelationalNode dataNode = new FakeRelationalNode(0, dataSource, mgr.getProcessorBatchSize());
         dataNode.setElements(dataSource.getSchema());            
         node.addChild(dataNode);    
@@ -200,8 +203,8 @@
 
     // Same as test2, but uses processor batch size smaller than number of groups
     @Test public void test3() throws Exception {
-        BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
-        ((BufferManagerImpl)mgr).setProcessorBatchSize(5);
+    	BufferManagerImpl mgr = BufferManagerFactory.createBufferManager();
+        mgr.setProcessorBatchSize(5);
 
         GroupingNode node = getExampleGroupingNode();         
         CommandContext context = new CommandContext("pid", "test", null, null,  1);               //$NON-NLS-1$ //$NON-NLS-2$
@@ -298,8 +301,8 @@
     }
 
     private void helpTestLookupFunctionInAggregate(int batchSize) throws Exception {
-        BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
-        ((BufferManagerImpl)mgr).setProcessorBatchSize(batchSize);
+        BufferManagerImpl mgr = BufferManagerFactory.createBufferManager();
+        mgr.setProcessorBatchSize(batchSize);
 
         // Set up
         GroupingNode node = new GroupingNode(1);

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestJoinNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestJoinNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import static org.junit.Assert.assertEquals;
 
@@ -32,24 +32,30 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.relational.JoinNode;
+import org.teiid.query.processor.relational.JoinStrategy;
+import org.teiid.query.processor.relational.MergeJoinStrategy;
+import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
+import org.teiid.query.processor.relational.PartitionedSortJoin;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.MergeJoinStrategy.SortOption;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.relational.MergeJoinStrategy.SortOption;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestJoinNode {
     private static final int NO_CRITERIA = 0;
@@ -212,7 +218,7 @@
         }
     }
         
-    public void helpTestJoin() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestJoin() throws TeiidComponentException, TeiidProcessingException {
     	for (int batchSize : new int[] {1, 10, leftTuples.length, 100}) {
 	        helpCreateJoin();        
 	        if (batchSize == 0) {
@@ -230,7 +236,7 @@
     	}
     }
     
-    public void helpTestJoinDirect(List[] expectedResults, int batchSize) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestJoinDirect(List[] expectedResults, int batchSize) throws TeiidComponentException, TeiidProcessingException {
         BufferManager mgr = NodeTestUtil.getTestBufferManager(1, batchSize);
         CommandContext context = new CommandContext("pid", "test", null, null, 1);               //$NON-NLS-1$ //$NON-NLS-2$
         

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestLimitNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestLimitNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestLimitNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.query.processor.relational.LimitNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.sql.symbol.Constant;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.query.sql.symbol.Constant;
 
 /** 
  * @since 4.3

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectIntoNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,30 +20,33 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.FakeTupleSource;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.relational.ProjectIntoNode;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.tempdata.TempTableStoreImpl;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
-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.FakeTupleSource;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Insert;
-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.tempdata.TempTableStoreImpl;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 
@@ -127,8 +130,8 @@
             this.expectedBatchSize = expectedBatchSize;
             this.exceptionOnClose = exceptionOnClose;
         }
-        public Object lookupCodeValue(CommandContext context,String codeTableName,String returnElementName,String keyElementName,Object keyValue) throws BlockedException,MetaMatrixComponentException {return null;}
-        public TupleSource registerRequest(Object processorID,Command command,String modelName,String connectorBindingId, int nodeID) throws MetaMatrixComponentException, ExpressionEvaluationException {
+        public Object lookupCodeValue(CommandContext context,String codeTableName,String returnElementName,String keyElementName,Object keyValue) throws BlockedException,TeiidComponentException {return null;}
+        public TupleSource registerRequest(Object processorID,Command command,String modelName,String connectorBindingId, int nodeID) throws TeiidComponentException, ExpressionEvaluationException {
             callCount++;
             
             int batchSize = 1;
@@ -188,7 +191,7 @@
         }
         public void closeSource() {}
         public List getSchema() {return null;}
-        public List nextTuple() throws MetaMatrixComponentException {
+        public List nextTuple() throws TeiidComponentException {
             if (currentRow % 100 == 0 && block) {
                 block = false;
                 throw BlockedException.INSTANCE;

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestProjectNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -28,26 +28,28 @@
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.relational.ProjectNode;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-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.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  */
@@ -61,7 +63,7 @@
         super(arg0);
     }
     
-    public ProjectNode helpSetupProject(List elements, List[] data, List childElements, ProcessorDataManager dataMgr) throws MetaMatrixComponentException {
+    public ProjectNode helpSetupProject(List elements, List[] data, List childElements, ProcessorDataManager dataMgr) throws TeiidComponentException {
         BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
         CommandContext context = new CommandContext("pid", "test", null, null, 1);               //$NON-NLS-1$ //$NON-NLS-2$
         
@@ -78,7 +80,7 @@
         return projectNode;        
     }
     
-    public void helpTestProject(List elements, List[] data, List childElements, List[] expected, ProcessorDataManager dataMgr) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestProject(List elements, List[] data, List childElements, List[] expected, ProcessorDataManager dataMgr) throws TeiidComponentException, TeiidProcessingException {
         ProjectNode projectNode = helpSetupProject(elements, data, childElements, dataMgr);
         
         projectNode.open();
@@ -101,7 +103,7 @@
         }
     }
 
-    public void helpTestProjectFails(List elements, List[] data, List childElements, String expectedError) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestProjectFails(List elements, List[] data, List childElements, String expectedError) throws TeiidComponentException, TeiidProcessingException {
         ProjectNode projectNode = helpSetupProject(elements, data, childElements, null);
                 
         try {

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestRelationalNodeStatistics.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,20 +20,22 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.processor.relational.RelationalNodeStatistics;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.util.CommandContext;
 
 /** 
  * @since 4.2
@@ -57,7 +59,7 @@
         assertTrue("The batch timer did not yield an end time", testnodeStatistics.getBatchEndTime()!= 0); //$NON-NLS-1$
     }
 
-    public void testStatsCollection() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testStatsCollection() throws TeiidComponentException, TeiidProcessingException {
         List[] data = createData(1000);
         FakeRelationalNode fakeNode = this.createFakeNode(data);
         

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalPlan.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestRelationalPlan.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalPlan.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.List;
 
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.RelationalPlan;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.TupleBatch;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSelectNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSelectNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSelectNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -28,28 +28,30 @@
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.processor.BatchIterator;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.SelectNode;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.processor.BatchIterator;
-import com.metamatrix.query.processor.BatchIterator;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  */
@@ -63,11 +65,11 @@
         super(arg0);
     }
     
-    public void helpTestSelect(List elements, Criteria criteria, List[] data, List childElements, ProcessorDataManager dataMgr, List[] expected) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestSelect(List elements, Criteria criteria, List[] data, List childElements, ProcessorDataManager dataMgr, List[] expected) throws TeiidComponentException, TeiidProcessingException {
     	helpTestSelect(elements, criteria, childElements, dataMgr, expected, new FakeRelationalNode(2, data));
     }
     
-    public void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child) throws TeiidComponentException, TeiidProcessingException {
         BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
         CommandContext context = new CommandContext("pid", "test", null, null, 1);               //$NON-NLS-1$ //$NON-NLS-2$
         
@@ -100,7 +102,7 @@
     /**
      * Ensures that a final empty batch is reindexed so that the batch iterator works correctly
      */
-    public void testEmptyBatchIndexing() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testEmptyBatchIndexing() throws TeiidComponentException, TeiidProcessingException {
     	ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 
@@ -122,7 +124,7 @@
 
 			@Override
 			protected TupleBatch nextBatchDirect() throws BlockedException,
-					MetaMatrixComponentException, MetaMatrixProcessingException {
+					TeiidComponentException, TeiidProcessingException {
 				if (i++ == 0) {
 					return new TupleBatch(1, new List[] {Arrays.asList(1), Arrays.asList(1)});
 				}
@@ -136,7 +138,7 @@
     	helpTestSelect(elements, crit, childElements, null, new List[0], child);
     }
     
-    public void testNoRows() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testNoRows() throws TeiidComponentException, TeiidProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 
@@ -158,7 +160,7 @@
         
     }
 
-    public void testSimpleSelect() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testSimpleSelect() throws TeiidComponentException, TeiidProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 
@@ -193,7 +195,7 @@
 
     }
 
-    public void testSelectWithLookup() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testSelectWithLookup() throws TeiidComponentException, TeiidProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import static org.junit.Assert.*;
 
@@ -30,27 +30,30 @@
 import java.util.TreeSet;
 
 import org.junit.Test;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.processor.relational.ListNestedSortComparator;
+import org.teiid.query.processor.relational.SortNode;
+import org.teiid.query.processor.relational.SortUtility;
+import org.teiid.query.processor.relational.SortUtility.Mode;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.processor.relational.SortUtility.Mode;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.util.CommandContext;
 
 public class TestSortNode {
     
     public static final int BATCH_SIZE = 100;
     
-    private void helpTestSort(List elements, List[] data, List sortElements, List sortTypes, List[] expected, Mode mode) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    private void helpTestSort(List elements, List[] data, List sortElements, List sortTypes, List[] expected, Mode mode) throws TeiidComponentException, TeiidProcessingException {
         BufferManager mgr = NodeTestUtil.getTestBufferManager(100, BATCH_SIZE, BATCH_SIZE);
         CommandContext context = new CommandContext ("pid", "test", null, null, 1);               //$NON-NLS-1$ //$NON-NLS-2$
         

Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestUnionAllNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestUnionAllNode.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestUnionAllNode.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,22 +20,25 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.relational;
+package org.teiid.query.processor.relational;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  */
@@ -49,7 +52,7 @@
         super(arg0);
     }
     
-    public void helpTestUnion(RelationalNode[] children, RelationalNode union, List[] expected) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestUnion(RelationalNode[] children, RelationalNode union, List[] expected) throws TeiidComponentException, TeiidProcessingException {
         BufferManager mgr = NodeTestUtil.getTestBufferManager(1, 2);
         CommandContext context = new CommandContext("pid", "test", null, null, 1);               //$NON-NLS-1$ //$NON-NLS-2$
         
@@ -87,7 +90,7 @@
         assertEquals("Didn't match expected counts", expected.length, currentRow-1); //$NON-NLS-1$
     }
     
-    public void testNoRows() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testNoRows() throws TeiidComponentException, TeiidProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 
@@ -113,7 +116,7 @@
         helpTestUnion(new RelationalNode[] {leftNode, rightNode}, union, new List[0]);        
     }
 
-    public void helpTestUnionConfigs(int sources, int blockModIndex, int rowsPerSource, int batchSize, List[] expected) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void helpTestUnionConfigs(int sources, int blockModIndex, int rowsPerSource, int batchSize, List[] expected) throws TeiidComponentException, TeiidProcessingException {
         ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
         es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 
@@ -148,7 +151,7 @@
         helpTestUnion(nodes, union, expected);           
     }
     
-    public void testBasicUnion() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testBasicUnion() throws TeiidComponentException, TeiidProcessingException {
         List expected[] = new List[] {
             Arrays.asList(new Object[] { new Integer(0) }),    
             Arrays.asList(new Object[] { new Integer(0) }),    
@@ -161,7 +164,7 @@
         
     }
 
-    public void testBasicUnionMultipleSources() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testBasicUnionMultipleSources() throws TeiidComponentException, TeiidProcessingException {
         List expected[] = new List[] {
             Arrays.asList(new Object[] { new Integer(0) }),    
             Arrays.asList(new Object[] { new Integer(0) }),    
@@ -178,7 +181,7 @@
         helpTestUnionConfigs(5, -1, 2, 50, expected);
     }
 
-    public void testMultipleSourcesHalfBlockingNodes() throws MetaMatrixComponentException, MetaMatrixProcessingException  {
+    public void testMultipleSourcesHalfBlockingNodes() throws TeiidComponentException, TeiidProcessingException  {
         List expected[] = new List[] {
             Arrays.asList(new Object[] { new Integer(1) }),    
             Arrays.asList(new Object[] { new Integer(0) }),    
@@ -190,7 +193,7 @@
         helpTestUnionConfigs(5, 2, 1, 50, expected);
     }
     
-    public void testMultipleSourcesAllBlockingNodes() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testMultipleSourcesAllBlockingNodes() throws TeiidComponentException, TeiidProcessingException {
         List expected[] = new List[] {
             Arrays.asList(new Object[] { new Integer(0) }),    
             Arrays.asList(new Object[] { new Integer(1) }),    
@@ -202,7 +205,7 @@
         helpTestUnionConfigs(5, 1, 1, 50, expected);       
     }    
     
-    public void testMultipleSourceMultiBatchAllBlocking() throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    public void testMultipleSourceMultiBatchAllBlocking() throws TeiidComponentException, TeiidProcessingException {
         List expected[] = new List[] {
             Arrays.asList(new Object[] { new Integer(0) }),    
             Arrays.asList(new Object[] { new Integer(1) }),    

Copied: trunk/engine/src/test/java/org/teiid/query/processor/xml (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/xml)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/FakePlanExecutor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/FakePlanExecutor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
-import com.metamatrix.query.processor.FakeTupleSource;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.FakeTupleSource;
+import org.teiid.query.processor.xml.PlanExecutor;
 
 
+
 class FakePlanExecutor implements PlanExecutor{
     String resultName;
     FakeTupleSource tupleSource;
@@ -47,23 +49,23 @@
         this.schema = schema;
         this.tupleSource = new FakeTupleSource(schema, rows);
     }    
-    public void close() throws MetaMatrixComponentException {
+    public void close() throws TeiidComponentException {
     }
 
-    public List currentRow() throws MetaMatrixComponentException {
+    public List currentRow() throws TeiidComponentException {
         return this.currentRow;
     }
 
-    public void execute(Map values) throws MetaMatrixComponentException, BlockedException {
+    public void execute(Map values) throws TeiidComponentException, BlockedException {
         tupleSource.openSource();
     }
 
-    public List nextRow() throws MetaMatrixComponentException {
+    public List nextRow() throws TeiidComponentException {
         currentRow = tupleSource.nextTuple();
         return currentRow;
     }
 
-    public List getOutputElements() throws MetaMatrixComponentException {
+    public List getOutputElements() throws TeiidComponentException {
         return this.schema;
     }
 }
\ No newline at end of file

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/FakeXMLProcessorEnvironment.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/FakeXMLProcessorEnvironment.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/FakeXMLProcessorEnvironment.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,20 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.query.mapping.xml.ResultSetInfo;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.mapping.xml.ResultSetInfo;
+import org.teiid.query.processor.xml.PlanExecutor;
+import org.teiid.query.processor.xml.XMLProcessorEnvironment;
 
+
 /**
  */
 public class FakeXMLProcessorEnvironment extends XMLProcessorEnvironment {
@@ -45,7 +48,7 @@
     }
 
     public PlanExecutor createResultExecutor(final String resultSetName, ResultSetInfo info) 
-        throws MetaMatrixComponentException{
+        throws TeiidComponentException{
        return new FakePlanExecutor(resultSetName, (List)schemaMap.get(resultSetName), (List[])dataMap.get(resultSetName));
     }
         

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/NoOpInstruction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/NoOpInstruction.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/NoOpInstruction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import org.teiid.client.plan.PlanNode;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.xml.ProcessorInstruction;
+import org.teiid.query.processor.xml.XMLContext;
+import org.teiid.query.processor.xml.XMLProcessorEnvironment;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BlockedException;
 
 /**
  */
@@ -42,7 +45,7 @@
      * @see ProcessorInstruction#process(ProcessorEnvironment)
      */
     public XMLContext process(XMLProcessorEnvironment env, XMLContext context)
-        throws BlockedException, MetaMatrixComponentException {
+        throws BlockedException, TeiidComponentException {
             
         env.incrementCurrentProgramCounter();
         return context;

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestAddNodeInstruction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestAddNodeInstruction.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestAddNodeInstruction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,19 +20,27 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.Properties;
 
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.processor.xml.AddNodeInstruction;
+import org.teiid.query.processor.xml.DocumentInProgress;
+import org.teiid.query.processor.xml.NodeDescriptor;
+import org.teiid.query.processor.xml.ProcessorInstruction;
+import org.teiid.query.processor.xml.Program;
+import org.teiid.query.processor.xml.SAXDocumentInProgress;
+import org.teiid.query.processor.xml.XMLContext;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.util.VariableContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.FileStore;
-import com.metamatrix.core.util.ObjectConverterUtil;
-import com.metamatrix.query.mapping.xml.MappingNodeConstants;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.util.VariableContext;
 
 /**
  * Unit tests {@link AddNodeInstruction} class
@@ -381,7 +389,7 @@
      * Take instruction, make a Program out of it, instantiate a
      * FakeEnvironment and XMLPlan, process instruction, and return result
      * doc
-     * @throws MetaMatrixComponentException
+     * @throws TeiidComponentException
      */
     private String helpGetDocument(AddNodeInstruction addNodeInstruction) throws Exception{
         return helpGetDocument(addNodeInstruction, null);
@@ -391,7 +399,7 @@
      * Take instruction, make a Program out of it, instantiate a
      * FakeEnvironment and XMLPlan, process instruction, and return result
      * doc
-     * @throws MetaMatrixComponentException
+     * @throws TeiidComponentException
      */
     private String helpGetDocument(ProcessorInstruction addNodeInstruction, Properties namespaceDeclarations) throws Exception{
         

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestElement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestElement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestElement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.io.CharArrayWriter;
 import java.util.Properties;
@@ -29,10 +29,13 @@
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.processor.xml.Element;
+import org.teiid.query.processor.xml.NodeDescriptor;
+
 import junit.framework.TestCase;
 import net.sf.saxon.TransformerFactoryImpl;
 
-import com.metamatrix.query.mapping.xml.MappingNodeConstants;
 
 public class TestElement  extends TestCase{
 	private CharArrayWriter streamResultHolder;

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestInstructions.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestInstructions.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestInstructions.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,39 +20,55 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.ResultSetInfo;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.xml.AddNodeInstruction;
+import org.teiid.query.processor.xml.Condition;
+import org.teiid.query.processor.xml.CriteriaCondition;
+import org.teiid.query.processor.xml.EndDocumentInstruction;
+import org.teiid.query.processor.xml.ExecSqlInstruction;
+import org.teiid.query.processor.xml.IfInstruction;
+import org.teiid.query.processor.xml.InitializeDocumentInstruction;
+import org.teiid.query.processor.xml.MoveCursorInstruction;
+import org.teiid.query.processor.xml.MoveDocInstruction;
+import org.teiid.query.processor.xml.NodeDescriptor;
+import org.teiid.query.processor.xml.ProcessorInstruction;
+import org.teiid.query.processor.xml.Program;
+import org.teiid.query.processor.xml.WhileInstruction;
+import org.teiid.query.processor.xml.XMLPlan;
+import org.teiid.query.processor.xml.XMLProcessorEnvironment;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.QueryCommand;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.util.CommandContext;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingNodeConstants;
-import com.metamatrix.query.mapping.xml.ResultSetInfo;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.resolver.util.ResolverVisitor;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.QueryCommand;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  */
@@ -112,7 +128,7 @@
         return new FakeMetadataFacade(store);
     }
     
-    private Command helpGetCommand(String sql, FakeMetadataFacade metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    private Command helpGetCommand(String sql, FakeMetadataFacade metadata) throws TeiidComponentException, TeiidProcessingException {
         // parse
         QueryParser parser = new QueryParser();
         Command command = parser.parseCommand(sql);
@@ -123,7 +139,7 @@
         return command;        
     }
 
-    private Criteria helpGetCriteria(String sql, FakeMetadataFacade metadata) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+    private Criteria helpGetCriteria(String sql, FakeMetadataFacade metadata) throws QueryParserException, QueryResolverException, TeiidComponentException {
         QueryParser parser = new QueryParser();
         Criteria crit = parser.parseCriteria(sql);
    

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestProcessorEnvironment.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestProcessorEnvironment.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
+import org.teiid.query.processor.xml.InitializeDocumentInstruction;
+import org.teiid.query.processor.xml.Program;
+import org.teiid.query.processor.xml.XMLContext;
+
 import junit.framework.TestCase;
 
 /**

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSAXDocumentInProgress.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestSAXDocumentInProgress.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSAXDocumentInProgress.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.processor.xml.NodeDescriptor;
+import org.teiid.query.processor.xml.SAXDocumentInProgress;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.FileStore;
-import com.metamatrix.query.mapping.xml.MappingNodeConstants;
 
 public class TestSAXDocumentInProgress extends TestCase {
     

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSourceNodeGenaratorVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestSourceNodeGenaratorVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestSourceNodeGenaratorVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,24 +20,25 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.List;
 
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingBaseNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingException;
+import org.teiid.query.mapping.xml.MappingLoader;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+import org.teiid.query.mapping.xml.MappingSourceNode;
+import org.teiid.query.optimizer.xml.SourceNodeGenaratorVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingBaseNode;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingException;
-import com.metamatrix.query.mapping.xml.MappingLoader;
-import com.metamatrix.query.mapping.xml.MappingNode;
-import com.metamatrix.query.mapping.xml.MappingRecursiveElement;
-import com.metamatrix.query.mapping.xml.MappingSourceNode;
-import com.metamatrix.query.optimizer.xml.SourceNodeGenaratorVisitor;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLContext.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLContext.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLContext.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.processor.xml.XMLContext;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 
 public class TestXMLContext extends TestCase {
@@ -71,7 +73,7 @@
         try {
             currentRow = context.getCurrentRow(resultSetName);
             fail("must have failed because the results are removed."); //$NON-NLS-1$
-        }catch(MetaMatrixComponentException e) {
+        }catch(TeiidComponentException e) {
         }
     }    
     
@@ -108,7 +110,7 @@
         try {
             parentContext.getCurrentRow(results2);
             fail("should fail to get child contexts results from parent.."); //$NON-NLS-1$
-        } catch (MetaMatrixComponentException e) {
+        } catch (TeiidComponentException e) {
         } 
         
         // note that we only using the current context which is the "child"

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLPlanningEnhancements.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,31 +20,34 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.xml.ExecSqlInstruction;
+import org.teiid.query.processor.xml.ExecStagingTableInstruction;
+import org.teiid.query.processor.xml.XMLPlan;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingNode;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.relational.rules.RuleChooseDependent;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
 
 public class TestXMLPlanningEnhancements extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLProcessor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import static org.junit.Assert.*;
 
@@ -35,52 +35,54 @@
 import java.util.StringTokenizer;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryPlannerException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingChoiceNode;
+import org.teiid.query.mapping.xml.MappingCommentNode;
+import org.teiid.query.mapping.xml.MappingCriteriaNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingNodeConstants;
+import org.teiid.query.mapping.xml.MappingRecursiveElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
+import org.teiid.query.mapping.xml.Namespace;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.optimizer.xml.TestXMLPlanner;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.BatchCollector;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.processor.xml.ExecStagingTableInstruction;
+import org.teiid.query.processor.xml.XMLPlan;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.buffer.TupleBuffer;
-import com.metamatrix.common.buffer.TupleSource;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingChoiceNode;
-import com.metamatrix.query.mapping.xml.MappingCommentNode;
-import com.metamatrix.query.mapping.xml.MappingCriteriaNode;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingNode;
-import com.metamatrix.query.mapping.xml.MappingNodeConstants;
-import com.metamatrix.query.mapping.xml.MappingRecursiveElement;
-import com.metamatrix.query.mapping.xml.MappingSequenceNode;
-import com.metamatrix.query.mapping.xml.Namespace;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.optimizer.xml.TestXMLPlanner;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.processor.BatchCollector;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.QueryProcessor;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.util.CommandContext;
 
 /**
  * Tests XML processing, which involves XMLPlanner making a ProcessorPlan
@@ -2923,7 +2925,7 @@
         return dataMgr;
     }                    
 
-    public static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException { 
+    public static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException { 
         QueryParser parser = new QueryParser();
         Command command = parser.parseCommand(sql);
         QueryResolver.resolveCommand(command, metadata);
@@ -2932,7 +2934,7 @@
     }
 
     static ProcessorPlan helpTestProcess(String sql, String expectedDoc, FakeMetadataFacade metadata, FakeDataManager dataMgr) throws Exception{
-        return helpTestProcess(sql, expectedDoc, metadata, dataMgr, true, MetaMatrixComponentException.class, null);
+        return helpTestProcess(sql, expectedDoc, metadata, dataMgr, true, TeiidComponentException.class, null);
     }
 
     static ProcessorPlan helpTestProcess(String sql, String expectedDoc, FakeMetadataFacade metadata, FakeDataManager dataMgr, final boolean shouldSucceed, Class expectedException, final String shouldFailMsg) throws Exception{
@@ -3043,8 +3045,8 @@
     }
 
 	private void helpTestProcess(String[] expectedDocs, FakeDataManager dataMgr,
-			ProcessorPlan plan) throws MetaMatrixComponentException,
-			MetaMatrixProcessingException, SQLException {
+			ProcessorPlan plan) throws TeiidComponentException,
+			TeiidProcessingException, SQLException {
 		BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
         CommandContext context = new CommandContext("pID", null, null, null, 1);                                 //$NON-NLS-1$
         context.setProcessDebug(DEBUG);
@@ -5841,7 +5843,7 @@
     @Test public void test2b() throws Exception {
         FakeMetadataFacade metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManager(metadata);
-        helpTestProcess("SELECT * FROM xmltest.doc2b", null, metadata, dataMgr, false, MetaMatrixComponentException.class, "Should have failed on default");         //$NON-NLS-1$ //$NON-NLS-2$
+        helpTestProcess("SELECT * FROM xmltest.doc2b", null, metadata, dataMgr, false, TeiidComponentException.class, "Should have failed on default");         //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Test public void test2c() throws Exception {
@@ -6059,10 +6061,10 @@
         QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataMgr);
         processor.setNonBlocking(true);
         BatchCollector collector = processor.createBatchCollector();
-        MetaMatrixComponentException failOnDefaultException = null;
+        TeiidComponentException failOnDefaultException = null;
         try{
             collector.collectTuples();
-        } catch (MetaMatrixComponentException e){
+        } catch (TeiidComponentException e){
             failOnDefaultException = e;
         }
         
@@ -6472,7 +6474,7 @@
     @Test public void testRecursive4Exception() throws Exception {
         FakeMetadataFacade metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManagerNested(metadata);
-        helpTestProcess("SELECT * FROM xmltest.doc15", null, metadata, dataMgr, false, MetaMatrixComponentException.class, "Query processing should have failed on recursion limit."); //$NON-NLS-1$ //$NON-NLS-2$
+        helpTestProcess("SELECT * FROM xmltest.doc15", null, metadata, dataMgr, false, TeiidComponentException.class, "Query processing should have failed on recursion limit."); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     /**
@@ -10059,7 +10061,7 @@
         caps.setFunctionSupport("convert", true); //$NON-NLS-1$
         CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(caps); 
         
-        helpTestProcess("SELECT * FROM xmltest.doc12260", expectedDoc, metadata, dataMgr, true, MetaMatrixComponentException.class, null, capFinder); //$NON-NLS-1$
+        helpTestProcess("SELECT * FROM xmltest.doc12260", expectedDoc, metadata, dataMgr, true, TeiidComponentException.class, null, capFinder); //$NON-NLS-1$
     }
     
     @Test public void testDefect8373() throws Exception{
@@ -10615,7 +10617,7 @@
         FakeMetadataFacade metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManagerNested(metadata);
         
-        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE rowlimitexception(supplier) = 2", null, metadata, dataMgr, false, MetaMatrixProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
+        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE rowlimitexception(supplier) = 2", null, metadata, dataMgr, false, TeiidProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
     }      
     
     /** Two row limits on the same mapping class should be harmless as long as the row limits are identical. */
@@ -10679,7 +10681,7 @@
         FakeMetadataFacade metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManagerNested(metadata);
         
-        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE rowlimitexception(supplier) = 2 AND rowlimitexception(supplierid) = 2", null, metadata, dataMgr, false, MetaMatrixProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
+        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE rowlimitexception(supplier) = 2 AND rowlimitexception(supplierid) = 2", null, metadata, dataMgr, false, TeiidProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
     }      
     
     /** compound criteria */
@@ -10719,7 +10721,7 @@
         FakeMetadataFacade metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManagerNested(metadata);
         
-        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE ItemID='002' AND rowlimitexception(supplier) = 2", null, metadata, dataMgr, false, MetaMatrixProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
+        helpTestProcess("SELECT * FROM xmltest.doc8 WHERE ItemID='002' AND rowlimitexception(supplier) = 2", null, metadata, dataMgr, false, TeiidProcessingException.class, "");         //$NON-NLS-1$ //$NON-NLS-2$
     }     
     
     @Test public void testCase2951MaxRows4() throws Exception {
@@ -11903,7 +11905,7 @@
         try {
             helpTestProcess("SELECT * FROM xmltest.docBounded", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
             fail("should have failed the document restrictions."); //$NON-NLS-1$
-        } catch (MetaMatrixProcessingException e) {
+        } catch (TeiidProcessingException e) {
             // pass
         }
     }

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/TestXMLValueTranslator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,17 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.math.BigInteger;
 import java.sql.Timestamp;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.processor.xml.XMLValueTranslator;
+import org.teiid.query.unittest.TimestampUtil;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.unittest.TimestampUtil;
 
 public class TestXMLValueTranslator extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/XMLProgramUtil.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xml/XMLProgramUtil.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/XMLProgramUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,21 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xml;
+package org.teiid.query.processor.xml;
 
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.query.processor.xml.Condition;
+import org.teiid.query.processor.xml.IfInstruction;
+import org.teiid.query.processor.xml.ProcessorInstruction;
+import org.teiid.query.processor.xml.Program;
+import org.teiid.query.processor.xml.RecurseProgramCondition;
+import org.teiid.query.processor.xml.WhileInstruction;
 
+
 /** 
  * 
  */

Copied: trunk/engine/src/test/java/org/teiid/query/processor/xquery (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/processor/xquery)

Modified: trunk/engine/src/test/java/org/teiid/query/processor/xquery/TestXQueryProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/xquery/TestXQueryProcessor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xquery/TestXQueryProcessor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,26 +20,26 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.processor.xquery;
+package org.teiid.query.processor.xquery;
 
 import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import com.metamatrix.query.processor.FakeDataManager;
-import com.metamatrix.query.processor.FakeDataStore;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.processor.dynamic.SimpleQueryProcessorFactory;
-import com.metamatrix.query.processor.xml.TestXMLProcessor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.util.CommandContext;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.processor.FakeDataManager;
+import org.teiid.query.processor.FakeDataStore;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.processor.dynamic.SimpleQueryProcessorFactory;
+import org.teiid.query.processor.xml.TestXMLProcessor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.util.CommandContext;
 
+
 /**
  * Tests processing XQueries
  */
@@ -53,7 +53,7 @@
     	helpProcess(xquery, new List[] {Arrays.asList(expectedResult)}, dataMgr, metadata);
     }
     
-	private void helpTest(String sql, List[] expected) throws MetaMatrixComponentException {
+	private void helpTest(String sql, List[] expected) throws Exception {
         FakeDataManager dataManager = new FakeDataManager();
         TestProcessor.sampleData1(dataManager);
         FakeMetadataFacade metadata = FakeMetadataFactory.exampleXQueryTransformations();
@@ -63,7 +63,7 @@
 
 	private void helpProcess(String sql, List[] expected,
 			FakeDataManager dataManager, FakeMetadataFacade metadata)
-			throws MetaMatrixComponentException {
+			throws Exception {
 		ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);
         CommandContext cc = TestProcessor.createCommandContext();
         cc.setQueryProcessorFactory(new SimpleQueryProcessorFactory(BufferManagerFactory.getStandaloneBufferManager(), dataManager, new DefaultCapabilitiesFinder(), null, metadata));

Copied: trunk/engine/src/test/java/org/teiid/query/resolver (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/resolver)

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/CheckNoTempMetadataIDsVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/CheckNoTempMetadataIDsVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/CheckNoTempMetadataIDsVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import java.util.*;
-import java.util.ArrayList;
-import java.util.Collection;
 
-import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.sql.*;
-import com.metamatrix.query.sql.navigator.DeepPreOrderNavigator;
-import com.metamatrix.query.sql.symbol.*;
+import org.teiid.query.metadata.TempMetadataID;
+import org.teiid.query.sql.*;
+import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
+import org.teiid.query.sql.symbol.*;
 
+
 /**
  * Used to verify that all symbols in a LanguageObject were resolved
  * with respect to runtime metadata - also that they aren't resolved

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/CheckSymbolsAreResolvedVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/CheckSymbolsAreResolvedVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/CheckSymbolsAreResolvedVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import java.util.ArrayList;
 import java.util.Collection;
 
-import com.metamatrix.query.sql.*;
-import com.metamatrix.query.sql.symbol.*;
+import org.teiid.query.sql.*;
+import org.teiid.query.sql.symbol.*;
 
+
 /**
  * Used to verify that all symbols in a LanguageObject were resolved
  * with respect to runtime metadata

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestAccessPattern.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestAccessPattern.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestAccessPattern.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import com.metamatrix.query.resolver.util.AccessPattern;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
+import org.teiid.query.resolver.util.AccessPattern;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
+
 import junit.framework.TestCase;
 
 public class TestAccessPattern extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestFunctionResolving.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,23 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import static org.junit.Assert.*;
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.util.ResolverVisitor;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestFunctionResolving {
 
@@ -120,14 +120,14 @@
     }
 
 	private Function helpResolveFunction(String sql) throws QueryParserException,
-			QueryResolverException, MetaMatrixComponentException {
+			QueryResolverException, TeiidComponentException {
 		Function func = getFunction(sql);
     	assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType());
     	return func;
 	}
 
 	private Function getFunction(String sql) throws QueryParserException,
-			MetaMatrixComponentException, QueryResolverException {
+			TeiidComponentException, QueryResolverException {
 		Function func = (Function)QueryParser.getQueryParser().parseExpression(sql);
 		ResolverVisitor.resolveLanguageObject(func, FakeMetadataFactory.example1Cached());
 		return func;

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestProcedureResolving.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import static org.junit.Assert.*;
 
@@ -30,37 +30,39 @@
 import java.util.Map;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.ProcedureContainerResolver;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.sql.ProcedureReservedWords;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.GroupContext;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.ProcedureContainer;
+import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.CommandStatement;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.LoopStatement;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
-import com.metamatrix.query.metadata.TempMetadataStore;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.sql.ProcedureReservedWords;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.GroupContext;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.Block;
-import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.proc.LoopStatement;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 public class TestProcedureResolving {
 
@@ -93,7 +95,7 @@
         	if (msg != null) {
                 assertEquals(msg, ex.getMessage());
             }
-        } catch (MetaMatrixComponentException e) {
+        } catch (TeiidComponentException e) {
         	throw new RuntimeException(e);
 		} catch (QueryParserException e) {
 			throw new RuntimeException(e);
@@ -101,7 +103,7 @@
 	}	
 	
     public static Map getProcedureExternalMetadata(GroupSymbol virtualGroup, QueryMetadataInterface metadata)
-    throws QueryMetadataException, MetaMatrixComponentException {
+    throws QueryMetadataException, TeiidComponentException {
         Map externalMetadata = new HashMap();
         
         //TODO: it doesn't seem like these should be in the 
@@ -156,14 +158,14 @@
         assertNull(tempIDs.get("LOOPCURSOR2")); //$NON-NLS-1$
     }
     
-	private CreateUpdateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr, String procedureType) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+	private CreateUpdateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr, String procedureType) throws QueryParserException, QueryResolverException, TeiidComponentException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 		return resolveProcedure(userUpdateStr, metadata);
 	}
 
 	private CreateUpdateProcedureCommand resolveProcedure(String userUpdateStr,
 			QueryMetadataInterface metadata) throws QueryParserException,
-			QueryResolverException, MetaMatrixComponentException,
+			QueryResolverException, TeiidComponentException,
 			QueryMetadataException {
 		ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr); 
         QueryResolver.resolveCommand(userCommand, metadata);
@@ -171,7 +173,7 @@
         return (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
 	}
 
-	private void helpResolveException(String userUpdateStr, QueryMetadataInterface metadata, String msg) throws QueryParserException, MetaMatrixComponentException {
+	private void helpResolveException(String userUpdateStr, QueryMetadataInterface metadata, String msg) throws QueryParserException, TeiidComponentException {
 		try {
 			helpResolve(userUpdateStr, metadata);
 		} catch (QueryResolverException e) {
@@ -179,7 +181,7 @@
 		}
 	}
 
-	private CreateUpdateProcedureCommand helpResolve(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+	private CreateUpdateProcedureCommand helpResolve(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException {
 		return resolveProcedure(userUpdateStr, metadata);
 	}
     

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import static org.junit.Assert.*;
 
@@ -39,61 +39,62 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
+import org.teiid.query.metadata.TempMetadataStore;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.BindVariableVisitor;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.ProcedureReservedWords;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
+import org.teiid.query.sql.proc.CommandStatement;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.SelectSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.sql.visitor.FunctionCollectorVisitor;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.unittest.TimestampUtil;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.function.FunctionDescriptor;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.metadata.TempMetadataStore;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.util.BindVariableVisitor;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.ProcedureReservedWords;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.navigator.DeepPreOrderNavigator;
-import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SelectSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
-import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
-import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
-import com.metamatrix.query.unittest.TimestampUtil;
 
 public class TestResolver {
 
@@ -108,7 +109,7 @@
 	static Command helpParse(String sql) { 
         try { 
             return QueryParser.getQueryParser().parseCommand(sql);
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             throw new RuntimeException(e);
         }
 	}
@@ -170,7 +171,7 @@
         // resolve
         try { 
             QueryResolver.resolveCommand(command, queryMetadataInterface, analysis);
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             throw new RuntimeException(e);
         } 
 
@@ -191,7 +192,7 @@
 			QueryResolver.resolveCommand(command, metadata);
 		} catch(QueryResolverException e) {
 			exception = e;
-		} catch(MetaMatrixException e) {
+		} catch(TeiidException e) {
 			fail("Exception during resolution (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 		assertNotNull("Expected a QueryResolverException but got none.", exception); //$NON-NLS-1$
@@ -204,14 +205,14 @@
         try { 
             criteria = QueryParser.getQueryParser().parseCriteria(sql);
            
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             fail("Exception during parsing (" + e.getClass().getName() + "): " + e.getMessage());    //$NON-NLS-1$ //$NON-NLS-2$
         }   
    
    		// resolve
         try { 
             QueryResolver.resolveCriteria(criteria, metadata);
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             e.printStackTrace();
             fail("Exception during resolution (" + e.getClass().getName() + "): " + e.getMessage());     //$NON-NLS-1$ //$NON-NLS-2$
         } 
@@ -232,7 +233,7 @@
         if(bindings != null) {
             try { 
                 BindVariableVisitor.bindReferences(command, bindings, metadata);
-            } catch(MetaMatrixException e) { 
+            } catch(TeiidException e) { 
                 fail("Exception during binding (" + e.getClass().getName() + "): " + e.getMessage());    //$NON-NLS-1$ //$NON-NLS-2$
             }   
         }
@@ -240,7 +241,7 @@
         // resolve
         try { 
             QueryResolver.resolveCommand(command, metadata);
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             fail("Exception during resolution (" + e.getClass().getName() + "): " + e.getMessage());     //$NON-NLS-1$ //$NON-NLS-2$
         } 
 
@@ -269,7 +270,7 @@
         	if(expectedExceptionMessage != null){
             	assertEquals(expectedExceptionMessage, e.getMessage());
             }
-        } catch(MetaMatrixComponentException e) {
+        } catch(TeiidComponentException e) {
             throw new RuntimeException(e);
         }       
     }
@@ -325,7 +326,7 @@
 		}
 	}
     
-    private void helpTestIsXMLQuery(String sql, boolean isXML) throws QueryResolverException, QueryMetadataException, MetaMatrixComponentException {
+    private void helpTestIsXMLQuery(String sql, boolean isXML) throws QueryResolverException, QueryMetadataException, TeiidComponentException {
         // parse
         Query query = (Query) helpParse(sql);
 
@@ -1578,7 +1579,7 @@
             actual = QueryParser.getQueryParser().parseCriteria("bqt1.smalla.shortvalue IN (1, 2)"); //$NON-NLS-1$
             expected = QueryParser.getQueryParser().parseCriteria("convert(bqt1.smalla.shortvalue, integer) IN (1, 2)"); //$NON-NLS-1$
            
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             fail("Exception during parsing (" + e.getClass().getName() + "): " + e.getMessage());    //$NON-NLS-1$ //$NON-NLS-2$
         }   
    
@@ -1586,7 +1587,7 @@
         try { 
             QueryResolver.resolveCriteria(expected, FakeMetadataFactory.exampleBQTCached());
             QueryResolver.resolveCriteria(actual, FakeMetadataFactory.exampleBQTCached());
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             fail("Exception during resolution (" + e.getClass().getName() + "): " + e.getMessage());     //$NON-NLS-1$ //$NON-NLS-2$
         } 
         
@@ -2723,7 +2724,7 @@
         assertEquals( sExpected, sActual );
     }
 
-    @Test public void testCase6319() throws QueryResolverException, MetaMatrixComponentException {
+    @Test public void testCase6319() throws QueryResolverException, TeiidComponentException {
         String sql = "select floatnum from bqt1.smalla group by floatnum having sum(floatnum) between 51.0 and 100.0 "; //$NON-NLS-1$
         Query query = (Query)helpParse(sql);
         QueryResolver.resolveCommand(query, FakeMetadataFactory.exampleBQTCached());

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestXMLResolver.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestXMLResolver.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,29 +20,31 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.resolver;
+package org.teiid.query.resolver;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.util.ElementSymbolOptimizer;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.util.ElementSymbolOptimizer;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestXMLResolver extends TestCase {
     

Copied: trunk/engine/src/test/java/org/teiid/query/rewriter (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/rewriter)

Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestOrderByRewrite.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestOrderByRewrite.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,38 +20,39 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.rewriter;
+package org.teiid.query.rewriter;
 
-import static com.metamatrix.query.rewriter.TestQueryRewriter.*;
 import static org.junit.Assert.*;
+import static org.teiid.query.rewriter.TestQueryRewriter.*;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import org.junit.Test;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
 
 /**
  * Converted from older resolver tests
  */
 public class TestOrderByRewrite  {
     
-    private static Command getCommand(String sql) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    private static Command getCommand(String sql) throws TeiidComponentException, TeiidProcessingException {
         Command command = QueryParser.getQueryParser().parseCommand(sql);
         
         QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());

Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.rewriter;
+package org.teiid.query.rewriter;
 
 import static org.junit.Assert.*;
 
@@ -33,49 +33,50 @@
 
 import org.junit.Ignore;
 import org.junit.Test;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryValidatorException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.TimestampWithTimezone;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.ProcedureContainer;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.QueryCommand;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.ContextProperties;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryValidatorException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.util.TimestampWithTimezone;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.resolver.util.ResolverVisitor;
-import com.metamatrix.query.sql.lang.Command;
-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.MatchCriteria;
-import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.QueryCommand;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.util.CommandContext;
-import com.metamatrix.query.util.ContextProperties;
 
 @SuppressWarnings("nls")
 public class TestQueryRewriter {
@@ -93,7 +94,7 @@
             QueryResolver.resolveCriteria(crit, metadata);
             
             return crit;
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             throw new RuntimeException(e);
         }   
     }
@@ -106,7 +107,7 @@
         } 
     }   
     
-    private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryMetadataException, MetaMatrixComponentException, MetaMatrixProcessingException {
+    private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException {
         FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached(); 
         Criteria expectedCrit = parseCriteria(expected, metadata);
         if (rewrite) {
@@ -124,13 +125,13 @@
         try { 
             actual = QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
         	throw new RuntimeException(e);
         }
         return actual;
     }  
     
-    private Expression helpTestRewriteExpression(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    private Expression helpTestRewriteExpression(String original, String expected, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException {
     	Expression actualExp = QueryParser.getQueryParser().parseExpression(original);
     	ResolverVisitor.resolveLanguageObject(actualExp, metadata);
     	CommandContext context = new CommandContext();
@@ -144,15 +145,15 @@
     	return actualExp;
     }
     
-	private String getRewritenProcedure(String procedure, String userUpdateStr, String procedureType) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+	private String getRewritenProcedure(String procedure, String userUpdateStr, String procedureType) throws TeiidComponentException, TeiidProcessingException {
         QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
 
         return getRewritenProcedure(userUpdateStr, metadata);
 	}
 
 	private String getRewritenProcedure(String userUpdateStr,
-			QueryMetadataInterface metadata) throws MetaMatrixComponentException,
-			QueryMetadataException, MetaMatrixProcessingException {
+			QueryMetadataInterface metadata) throws TeiidComponentException,
+			QueryMetadataException, TeiidProcessingException {
 		ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr); 
         QueryResolver.resolveCommand(userCommand, metadata);
         CreateUpdateProcedureCommand proc = (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, null);
@@ -164,12 +165,12 @@
     static Command helpTestRewriteCommand(String original, String expected) { 
         try {
             return helpTestRewriteCommand(original, expected, FakeMetadataFactory.example1Cached());
-        } catch(MetaMatrixException e) { 
-            throw new MetaMatrixRuntimeException(e);
+        } catch(TeiidException e) { 
+            throw new TeiidRuntimeException(e);
         }
     }
     
-    static Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixException { 
+    static Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata) throws TeiidException { 
         Command command = QueryParser.getQueryParser().parseCommand(original);            
         QueryResolver.resolveCommand(command, metadata);
         Command rewriteCommand = QueryRewriter.rewrite(command, metadata, null);
@@ -416,7 +417,7 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, null);
             fail("Expected failure"); //$NON-NLS-1$
-        } catch(MetaMatrixException e) { 
+        } catch(TeiidException e) { 
             assertEquals("Error Code:ERR.015.001.0003 Message:Error simplifying criteria: PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", e.getMessage());     //$NON-NLS-1$
         }
     }
@@ -1532,7 +1533,7 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             fail("Expected QueryValidatorException due to divide by 0"); //$NON-NLS-1$
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
         	// looks like message is being wrapped with another exception with same message
             assertEquals("Error Code:ERR.015.001.0003 Message:Unable to evaluate (5 / 0): Error Code:ERR.015.001.0003 Message:Error while evaluating function /", e.getMessage());  //$NON-NLS-1$
         }       
@@ -1546,7 +1547,7 @@
         try { 
             QueryRewriter.rewriteCriteria(origCrit, null, null, metadata);
             fail("Expected QueryValidatorException due to invalid string"); //$NON-NLS-1$
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             assertEquals("Error Code:ERR.015.001.0003 Message:Unable to evaluate convert('x', integer): Error Code:ERR.015.001.0003 Message:Error while evaluating function convert", e.getMessage()); //$NON-NLS-1$
         }       
     }
@@ -1970,7 +1971,7 @@
                                             new Class[] { DataTypeManager.DefaultDataClasses.STRING});
     }
 
-    private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class<?>[] types) throws MetaMatrixComponentException, MetaMatrixProcessingException {
+    private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class<?>[] types) throws TeiidComponentException, TeiidProcessingException {
         SetQuery union = (SetQuery)QueryParser.getQueryParser().parseCommand(unionQuery);
         QueryResolver.resolveCommand(union, FakeMetadataFactory.example1Cached());
         
@@ -2089,11 +2090,11 @@
      * THEN e2 ELSE -1 END) FROM pm1.g1
      * </table>
      * 
-     * @see com.metamatrix.query.rewriter.QueryRewriter
-     * @see com.metamatrix.query.sql.lang.BetweenCriteria
-     * @see com.metamatrix.query.sql.lang.CompoundCriteria
-     * @see com.metamatrix.query.sql.symbol.AggregateSymbol
-     * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+     * @see org.teiid.query.rewriter.QueryRewriter
+     * @see org.teiid.query.sql.lang.BetweenCriteria
+     * @see org.teiid.query.sql.lang.CompoundCriteria
+     * @see org.teiid.query.sql.symbol.AggregateSymbol
+     * @see org.teiid.query.sql.symbol.SearchedCaseExpression
      */
     @Test public void testAggregateWithBetweenInCaseInSelect() {
     	// Define a list of aggregates to test against
@@ -2135,10 +2136,10 @@
      * ELSE -1 END FROM pm1.g1
      * </table>
      * 
-     * @see com.metamatrix.query.rewriter.QueryRewriter
-     * @see com.metamatrix.query.sql.lang.BetweenCriteria
-     * @see com.metamatrix.query.sql.lang.CompoundCriteria
-     * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+     * @see org.teiid.query.rewriter.QueryRewriter
+     * @see org.teiid.query.sql.lang.BetweenCriteria
+     * @see org.teiid.query.sql.lang.CompoundCriteria
+     * @see org.teiid.query.sql.symbol.SearchedCaseExpression
      */
     @Test public void testBetweenInCaseInSelect() {
     	String sqlBefore = "SELECT CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END FROM pm1.g1"; //$NON-NLS-1$
@@ -2167,10 +2168,10 @@
      * (e2 >= 3) AND (e2 <= 5) THEN e2 ELSE -1 END
      * </table>
      * 
-     * @see com.metamatrix.query.rewriter.QueryRewriter
-     * @see com.metamatrix.query.sql.lang.BetweenCriteria
-     * @see com.metamatrix.query.sql.lang.CompoundCriteria
-     * @see com.metamatrix.query.sql.symbol.SearchedCaseExpression
+     * @see org.teiid.query.rewriter.QueryRewriter
+     * @see org.teiid.query.sql.lang.BetweenCriteria
+     * @see org.teiid.query.sql.lang.CompoundCriteria
+     * @see org.teiid.query.sql.symbol.SearchedCaseExpression
      */
     @Test public void testBetweenInCase() {
     	String sqlBefore = "SELECT * FROM pm1.g1 WHERE e3 = CASE WHEN e2 BETWEEN 3 AND 5 THEN e2 ELSE -1 END"; //$NON-NLS-1$

Copied: trunk/engine/src/test/java/org/teiid/query/sql/lang (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/sql/lang)

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestAliasSymbol.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestAliasSymbol.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
 
 public class TestAliasSymbol extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestBetweenCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestBetweenCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestBetweenCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 public class TestBetweenCriteria extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCompoundCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestCompoundCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCompoundCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
 import junit.framework.*;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 /**
  * @author amiller

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCreate.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestCreate.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCreate.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,16 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Create;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestCreate extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,22 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.Arrays;
 import java.util.Collection;
 
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.NotCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
 import junit.framework.*;
 
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDependentSetCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDependentSetCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDependentSetCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.DependentSetCriteria;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 
 /** 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDrop.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDrop.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDrop.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.*;
+
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Drop;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 public class TestDrop extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDynamicCommand.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestDynamicCommand.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestDynamicCommand.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,19 +20,22 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.DynamicCommand;
+import org.teiid.query.sql.lang.SetClauseList;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  * Test for DynamicCommand

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestExpressionSymbol.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestExpressionSymbol.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestExpressionSymbol.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestIsNullCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestIsNullCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestIsNullCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 public class TestIsNullCriteria extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJDBCExecutionHelper.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestJDBCExecutionHelper.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJDBCExecutionHelper.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,7 +22,7 @@
 
 /*
  */
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -32,8 +32,8 @@
 import org.teiid.connector.language.DerivedColumn;
 import org.teiid.connector.language.Literal;
 import org.teiid.connector.language.Select;
+import org.teiid.core.types.DataTypeManager;
 
-import com.metamatrix.common.types.DataTypeManager;
 
 public class TestJDBCExecutionHelper extends TestCase{
     

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJoinPredicate.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestJoinPredicate.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestJoinPredicate.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -19,16 +19,24 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301 USA.
  */
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.FromClause;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 /**
  * Test the <code>JoinPredicate</code> implementation to verify it is producing  

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestLimit.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestLimit.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,10 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.Reference;
+import org.teiid.query.sql.lang.Limit;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.Reference;
 
 import junit.framework.TestCase;
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestMatchCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestMatchCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestMatchCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 public class TestMatchCriteria extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestOption.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestOption.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestOption.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.Arrays;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Option;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestQuery.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestQuery.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,18 +20,24 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.List;
 
+import org.teiid.core.types.BlobType;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Into;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.BlobType;
-import com.metamatrix.common.types.ClobType;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 
 public class TestQuery extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestSelect.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSelect.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 public class TestSelect extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestSetCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.*;
+
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 public class TestSetCriteria extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetQuery.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestSetQuery.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetQuery.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestSetQuery extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubqueryFromClause.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestSubqueryFromClause.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubqueryFromClause.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,20 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestSubqueryFromClause extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubquerySetCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/lang/TestSubquerySetCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSubquerySetCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,20 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.lang;
+package org.teiid.query.sql.lang;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestSubquerySetCriteria extends TestCase {
 

Copied: trunk/engine/src/test/java/org/teiid/query/sql/proc (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/sql/proc)

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestAssignmentStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,21 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
 import java.util.Arrays;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.parser.QueryParser;
-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.UnaryFromClause;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBlock.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBlock.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBlock.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.Statement;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestBlock extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBreakStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBreakStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestBreakStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,10 +22,13 @@
 
 /*
  */
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.BreakStatement;
+import org.teiid.query.sql.proc.ContinueStatement;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestBreakStatement  extends TestCase{
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCommandStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestCommandStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCommandStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.*;
+import org.teiid.query.sql.proc.CommandStatement;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.lang.*;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestContinueStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestContinueStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestContinueStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,11 +22,14 @@
 
 /*
  */
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.BreakStatement;
+import org.teiid.query.sql.proc.ContinueStatement;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * @author LLiang

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestCreateUpdateProcedureCommand.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,21 +20,23 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Option;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.XQuery;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.Option;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.XQuery;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestCriteriaSelector.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCriteriaSelector.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
 import java.util.*;
+
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.symbol.*;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.*;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestDeclareStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestDeclareStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestDeclareStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.DeclareStatement;
+import org.teiid.query.sql.symbol.ElementSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestHasCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestHasCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,10 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.HasCriteria;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestIfStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestIfStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.*;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.IfStatement;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.lang.*;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestLoopStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestLoopStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestLoopStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,16 +22,19 @@
 
 /*
  */
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.LoopStatement;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-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.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestLoopStatement  extends TestCase{
     

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestRaiseErrorStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,13 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.RaiseErrorStatement;
+import org.teiid.query.sql.symbol.Constant;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.Constant;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestTranslateCriteria.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestTranslateCriteria.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,10 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.proc.TranslateCriteria;
+
 import junit.framework.*;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  *

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestWhileStatement.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestWhileStatement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,12 +22,15 @@
 
 /*
  */
-package com.metamatrix.query.sql.proc;
+package org.teiid.query.sql.proc;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.WhileStatement;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.lang.Criteria;
 
 public class TestWhileStatement  extends TestCase{
     

Copied: trunk/engine/src/test/java/org/teiid/query/sql/symbol (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/sql/symbol)

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestAggregateSymbol.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,18 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
 import junit.framework.TestCase;
 
 import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestAggregateSymbol extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestCaseExpression.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestCaseExpression.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestCaseExpression.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,21 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.ArgCheck;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.ArgCheck;
+import org.teiid.query.sql.symbol.AbstractCaseExpression;
+import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
 
 
+
 import junit.framework.TestCase;
 
 public class TestCaseExpression extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestConstant.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestConstant.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestConstant.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,12 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.symbol.Constant;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestConstant extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestElementSymbol.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestElementSymbol.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,14 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestElementSymbol extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestFunction.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestFunction.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestFunction extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestGroupSymbol.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestGroupSymbol.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestGroupSymbol.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,9 +20,11 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
 
+import org.teiid.query.sql.symbol.GroupSymbol;
+
 import junit.framework.TestCase;
 
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestSearchedCaseExpression.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/symbol/TestSearchedCaseExpression.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestSearchedCaseExpression.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,14 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.symbol;
+package org.teiid.query.sql.symbol;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.lang.CompareCriteria;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
 
+
 import junit.framework.TestCase;
 
 public class TestSearchedCaseExpression extends TestCase {

Copied: trunk/engine/src/test/java/org/teiid/query/sql/util (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/sql/util)

Modified: trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestElementSymbolOptimizer.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/util/TestElementSymbolOptimizer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,24 +20,26 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.util;
+package org.teiid.query.sql.util;
 
 import java.util.*;
 
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.util.ElementSymbolOptimizer;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import junit.framework.*;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 /**
  */
@@ -51,7 +53,7 @@
         super(name);
     }
     
-    public Command helpResolve(String sql, QueryMetadataInterface metadata, Map externalMetadata) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+    public Command helpResolve(String sql, QueryMetadataInterface metadata, Map externalMetadata) throws QueryParserException, QueryResolverException, TeiidComponentException {
         Command command = QueryParser.getQueryParser().parseCommand(sql);
 
         final boolean USE_METADATA_COMMANDS = true;
@@ -61,12 +63,12 @@
     }
     
 
-    public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected) throws QueryMetadataException, MetaMatrixComponentException, QueryParserException, QueryResolverException {
+    public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected) throws QueryMetadataException, TeiidComponentException, QueryParserException, QueryResolverException {
         this.helpTestOptimize(sql, metadata, expected, Collections.EMPTY_MAP);    
     }
     
     
-    public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected, Map externalMetadata) throws QueryMetadataException, MetaMatrixComponentException, QueryParserException, QueryResolverException {
+    public void helpTestOptimize(String sql, QueryMetadataInterface metadata, String expected, Map externalMetadata) throws QueryMetadataException, TeiidComponentException, QueryParserException, QueryResolverException {
         Command command = helpResolve(sql, metadata, externalMetadata);
         ElementSymbolOptimizer.optimizeElements(command, metadata);
         String actual = command.toString();
@@ -125,7 +127,7 @@
                             "SELECT 1, 'xyz'"); //$NON-NLS-1$
     }
 
-    public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String expected) throws QueryParserException, QueryResolverException, MetaMatrixComponentException {
+    public void helpTestFullyQualify(String sql, QueryMetadataInterface metadata, String expected) throws QueryParserException, QueryResolverException, TeiidComponentException {
         Command command = helpResolve(sql, metadata, Collections.EMPTY_MAP);
         ElementSymbolOptimizer.fullyQualifyElements(command);
         String actual = command.toString();

Modified: trunk/engine/src/test/java/org/teiid/query/sql/util/TestUpdateProcedureGenerator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/util/TestUpdateProcedureGenerator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/util/TestUpdateProcedureGenerator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,27 +20,28 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.util;
+package org.teiid.query.sql.util;
 
 import java.util.Arrays;
 import java.util.List;
 
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.util.UpdateProcedureGenerator;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
 
 /**
 
@@ -65,7 +66,7 @@
 	        	assertEquals("Didn't get expected generated procedure", expectedProc, actualProc.toString()); //$NON-NLS-1$
 		        QueryParser.getQueryParser().parseCommand(actualProc.toString());
 	        }
-		} catch (MetaMatrixException e) {
+		} catch (TeiidException e) {
 			throw new RuntimeException(e);
 		}
 	}

Copied: trunk/engine/src/test/java/org/teiid/query/sql/visitor (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/sql/visitor)

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
 
 
 public class TestAggregateSymbolCollectorVisitor extends TestCase {

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestDeepGroupCollectorVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestDeepGroupCollectorVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestDeepGroupCollectorVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,17 +20,19 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import java.util.Collection;
 import java.util.Iterator;
 
+import org.teiid.core.TeiidException;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 public class TestDeepGroupCollectorVisitor extends TestCase {
     public TestDeepGroupCollectorVisitor(String name) {
@@ -42,7 +44,7 @@
         try {
             QueryParser parser = new QueryParser();
             obj = parser.parseCommand(sql);
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
             fail("Unexpected exception while parsing: " + e.getFullMessage()); //$NON-NLS-1$
         }
         

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestEvaluatableVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestEvaluatableVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestEvaluatableVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,13 +20,15 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import org.junit.Test;
+import org.teiid.query.resolver.TestResolver;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.visitor.EvaluatableVisitor;
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import static org.junit.Assert.*;
-import com.metamatrix.query.resolver.TestResolver;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestEvaluatableVisitor {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestExpressionMappingVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import static org.junit.Assert.*;
 
@@ -32,21 +32,22 @@
 
 import org.junit.Test;
 import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.TestCaseExpression;
+import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
+import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
 import org.teiid.resource.cci.SourceSystemFunctions;
 
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SetCriteria;
-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.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.TestCaseExpression;
-import com.metamatrix.query.sql.symbol.TestSearchedCaseExpression;
 
 
 public class TestExpressionMappingVisitor {

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestGroupCollectorVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestGroupCollectorVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestGroupCollectorVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -28,18 +28,20 @@
 import java.util.List;
 import java.util.Set;
 
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
-import com.metamatrix.query.sql.lang.Delete;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
 
 /**
  */

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -29,71 +29,72 @@
 
 import org.teiid.client.metadata.ParameterInfo;
 import org.teiid.connector.language.SQLReservedWords;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.DynamicCommand;
+import org.teiid.query.sql.lang.ExistsCriteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.GroupBy;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.JoinPredicate;
+import org.teiid.query.sql.lang.JoinType;
+import org.teiid.query.sql.lang.Limit;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.NotCriteria;
+import org.teiid.query.sql.lang.Option;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.lang.SetQuery;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.SubqueryCompareCriteria;
+import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.XQuery;
+import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.proc.Block;
+import org.teiid.query.sql.proc.CommandStatement;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.proc.DeclareStatement;
+import org.teiid.query.sql.proc.HasCriteria;
+import org.teiid.query.sql.proc.IfStatement;
+import org.teiid.query.sql.proc.RaiseErrorStatement;
+import org.teiid.query.sql.symbol.AggregateSymbol;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.AllInGroupSymbol;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.ScalarSubquery;
+import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.TestCaseExpression;
+import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+import org.teiid.query.unittest.FakeMetadataFactory;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.BetweenCriteria;
-import com.metamatrix.query.sql.lang.Command;
-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.Delete;
-import com.metamatrix.query.sql.lang.DynamicCommand;
-import com.metamatrix.query.sql.lang.ExistsCriteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.GroupBy;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.JoinPredicate;
-import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.lang.Limit;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.NotCriteria;
-import com.metamatrix.query.sql.lang.Option;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubqueryFromClause;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.lang.XQuery;
-import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.proc.Block;
-import com.metamatrix.query.sql.proc.CommandStatement;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.proc.CriteriaSelector;
-import com.metamatrix.query.sql.proc.DeclareStatement;
-import com.metamatrix.query.sql.proc.HasCriteria;
-import com.metamatrix.query.sql.proc.IfStatement;
-import com.metamatrix.query.sql.proc.RaiseErrorStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-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.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.TestCaseExpression;
-import com.metamatrix.query.sql.symbol.TestSearchedCaseExpression;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class TestSQLStringVisitor extends TestCase {
 

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestStaticSymbolMappingVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.sql.visitor;
+package org.teiid.query.sql.visitor;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -28,36 +28,40 @@
 import java.util.List;
 import java.util.Map;
 
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.GroupBy;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
+import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.proc.TranslateCriteria;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.AllInGroupSymbol;
+import org.teiid.query.sql.symbol.AllSymbol;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
+import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Symbol;
+import org.teiid.query.sql.visitor.ElementCollectorVisitor;
+import org.teiid.query.sql.visitor.GroupCollectorVisitor;
+import org.teiid.query.sql.visitor.StaticSymbolMappingVisitor;
+
 import junit.framework.TestCase;
 
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.BetweenCriteria;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Delete;
-import com.metamatrix.query.sql.lang.GroupBy;
-import com.metamatrix.query.sql.lang.Insert;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.lang.UnaryFromClause;
-import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.navigator.DeepPreOrderNavigator;
-import com.metamatrix.query.sql.proc.CriteriaSelector;
-import com.metamatrix.query.sql.proc.TranslateCriteria;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
-import com.metamatrix.query.sql.symbol.AllSymbol;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.Symbol;
 
 
 public class TestStaticSymbolMappingVisitor extends TestCase {

Copied: trunk/engine/src/test/java/org/teiid/query/unittest (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/unittest)

Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFacade.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,27 +29,27 @@
 import java.util.List;
 import java.util.Properties;
 
+import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.ArgCheck;
+import org.teiid.core.util.Assertion;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingBaseNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.mapping.xml.MappingVisitor;
+import org.teiid.query.mapping.xml.Navigator;
+import org.teiid.query.metadata.BasicQueryMetadata;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.StoredProcedureInfo;
+import org.teiid.query.metadata.SupportConstants;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingBaseNode;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingNode;
-import com.metamatrix.query.mapping.xml.MappingVisitor;
-import com.metamatrix.query.mapping.xml.Navigator;
-import com.metamatrix.query.metadata.BasicQueryMetadata;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.StoredProcedureInfo;
-import com.metamatrix.query.metadata.SupportConstants;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 public class FakeMetadataFacade extends BasicQueryMetadata {
 
@@ -71,7 +71,7 @@
 	}
 
     public Object getElementID(String elementName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(elementName);
 
@@ -83,7 +83,7 @@
 	}
 
     public Object getGroupID(String groupName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(groupName);
 
@@ -95,7 +95,7 @@
 	}
 
     public Collection getGroupsForPartialName(String partialGroupName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
 		if(partialGroupName == null) {
 			throw new QueryMetadataException("Group name cannot be null"); //$NON-NLS-1$
@@ -121,7 +121,7 @@
     }
 
     public Object getModelID(Object groupOrElementID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupOrElementID);
     	FakeMetadataObject obj = (FakeMetadataObject) groupOrElementID;
@@ -129,34 +129,34 @@
 	}
 
     public String getInsertPlan(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		FakeMetadataObject obj = (FakeMetadataObject) groupID;
 		return (String) obj.getProperty(FakeMetadataObject.Props.INSERT_PROCEDURE);
     }
 
     public String getUpdatePlan(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		FakeMetadataObject obj = (FakeMetadataObject) groupID;
 		return (String) obj.getProperty(FakeMetadataObject.Props.UPDATE_PROCEDURE);
     }
 
     public String getDeletePlan(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		FakeMetadataObject obj = (FakeMetadataObject) groupID;
 		return (String) obj.getProperty(FakeMetadataObject.Props.DELETE_PROCEDURE);
     }
 
     public String getFullName(Object metadataID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
 		return ((FakeMetadataObject)metadataID).getName();
 	}
 
     public List getElementIDsInGroupID(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		List ids = store.findObjects(FakeMetadataObject.ELEMENT, FakeMetadataObject.Props.GROUP, groupID);
 		Collections.sort(ids);
@@ -164,34 +164,34 @@
 	}
 
     public Object getGroupIDForElementID(Object elementID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
 		FakeMetadataObject element = (FakeMetadataObject) elementID;
 		return element.getProperty(FakeMetadataObject.Props.GROUP);
 	}
 
 	public String getElementType(Object elementID)
-		throws MetaMatrixComponentException, QueryMetadataException {
+		throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject) elementID;
 		return (String) element.getProperty(FakeMetadataObject.Props.TYPE);
 	}
 
 	public Object getDefaultValue(Object elementID)
-		throws MetaMatrixComponentException, QueryMetadataException {
+		throws TeiidComponentException, QueryMetadataException {
 		ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
 		return ((FakeMetadataObject)elementID).getDefaultValue();
 	}
 
     public boolean isVirtualGroup(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
 		return Boolean.TRUE.equals(group.getProperty(FakeMetadataObject.Props.IS_VIRTUAL));
 	}
 
     public boolean isVirtualModel(Object modelID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, modelID);
     	FakeMetadataObject model = (FakeMetadataObject) modelID;
         return ((Boolean)model.getProperty(FakeMetadataObject.Props.IS_VIRTUAL)).booleanValue();
@@ -199,7 +199,7 @@
     }
 
     public QueryNode getVirtualPlan(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
 		QueryNode queryNode = (QueryNode) group.getProperty(FakeMetadataObject.Props.PLAN);
@@ -210,7 +210,7 @@
 	}
 
 	public boolean modelSupports(Object modelID, int supportConstant)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 		ArgCheck.isInstanceOf(FakeMetadataObject.class, modelID);
 		switch(supportConstant) {
 			default:
@@ -219,7 +219,7 @@
 	}
 
     public boolean groupSupports(Object groupID, int groupConstant)
-        throws MetaMatrixComponentException,QueryMetadataException {
+        throws TeiidComponentException,QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
 		Boolean supports = null;
@@ -234,7 +234,7 @@
 	}
 
     public boolean elementSupports(Object elementID, int elementConstant)
-        throws MetaMatrixComponentException,QueryMetadataException {
+        throws TeiidComponentException,QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
     	FakeMetadataObject element = (FakeMetadataObject) elementID;
 		Boolean supports = null;
@@ -286,7 +286,7 @@
 	}
 
     public int getMaxSetSize(Object modelID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, modelID);
     	FakeMetadataObject model = (FakeMetadataObject) modelID;
         Integer maxSetSize = (Integer) model.getProperty(FakeMetadataObject.Props.MAX_SET_SIZE);
@@ -297,7 +297,7 @@
     }
 
     public String getFullElementName(String fullGroupName, String shortElementName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(fullGroupName);
         Assertion.isNotNull(shortElementName);
@@ -306,7 +306,7 @@
     }
 
     public String getShortElementName(String fullElementName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(fullElementName);
 
@@ -318,7 +318,7 @@
     }
 
     public String getGroupName(String fullElementName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(fullElementName);
 
@@ -331,7 +331,7 @@
 
 
     public StoredProcedureInfo getStoredProcedureInfoForProcedure(String fullyQualifiedProcedureName)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
 
         Assertion.isNotNull(fullyQualifiedProcedureName);
 
@@ -390,58 +390,58 @@
 	}
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getIndexesInGroup(java.lang.Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getIndexesInGroup(java.lang.Object)
      */
     public Collection getIndexesInGroup(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
         return getTypeOfKeysInGroup(groupID, FakeMetadataObject.TYPE_INDEX);
     }
 
     public Collection getUniqueKeysInGroup(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	return getTypeOfKeysInGroup(groupID, FakeMetadataObject.TYPE_PRIMARY_KEY);
     }
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getForeignKeysInGroup(java.lang.Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getForeignKeysInGroup(java.lang.Object)
      */
     public Collection getForeignKeysInGroup(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	return getTypeOfKeysInGroup(groupID, FakeMetadataObject.TYPE_FOREIGN_KEY);
     }
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getPrimaryKeyIDForForeignKeyID(java.lang.Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getPrimaryKeyIDForForeignKeyID(java.lang.Object)
      */
     public Object getPrimaryKeyIDForForeignKeyID(Object foreignKeyID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, foreignKeyID);
     	FakeMetadataObject keyObj = (FakeMetadataObject) foreignKeyID;
         return keyObj.getProperty(FakeMetadataObject.Props.REFERENCED_KEY);
     }
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getElementIDsInIndex(java.lang.Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getElementIDsInIndex(java.lang.Object)
      */
     public List getElementIDsInIndex(Object index)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, index);
         FakeMetadataObject keyObj = (FakeMetadataObject) index;
         return (List)keyObj.getProperty(FakeMetadataObject.Props.KEY_ELEMENTS);
     }
 
     public List getElementIDsInKey(Object keyID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, keyID);
 		FakeMetadataObject keyObj = (FakeMetadataObject) keyID;
 		return (List)keyObj.getProperty(FakeMetadataObject.Props.KEY_ELEMENTS);
     }
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getAccessPatternsInGroup(Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getAccessPatternsInGroup(Object)
      */
     public Collection getAccessPatternsInGroup(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	return getTypeOfKeysInGroup(groupID, FakeMetadataObject.TYPE_ACCESS_PATTERN);
     }
 
@@ -469,17 +469,17 @@
 	}
 
     /**
-     * @see com.metamatrix.query.metadata.QueryMetadataInterface#getElementIDsInAccessPattern(Object)
+     * @see org.teiid.query.metadata.QueryMetadataInterface#getElementIDsInAccessPattern(Object)
      */
     public List getElementIDsInAccessPattern(Object accessPattern)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, accessPattern);
     	FakeMetadataObject accessPatternObj = (FakeMetadataObject) accessPattern;
         return (List)accessPatternObj.getProperty(FakeMetadataObject.Props.KEY_ELEMENTS);
     }
 
     public MappingNode getMappingNode(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
         MappingDocument doc = (MappingDocument)group.getProperty(FakeMetadataObject.Props.PLAN);
@@ -487,7 +487,7 @@
         return doc;
     }
 
-    public boolean isXMLGroup(Object groupID) throws MetaMatrixComponentException, QueryMetadataException {
+    public boolean isXMLGroup(Object groupID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
         Object plan = group.getProperty(FakeMetadataObject.Props.PLAN);
@@ -497,11 +497,11 @@
       	return (plan instanceof MappingNode);
     }
 
-    public String getVirtualDatabaseName() throws MetaMatrixComponentException, QueryMetadataException {
+    public String getVirtualDatabaseName() throws TeiidComponentException, QueryMetadataException {
         return "myvdb"; //$NON-NLS-1$
     }
     
-    public boolean isTemporaryTable(Object groupID) throws MetaMatrixComponentException, QueryMetadataException {
+    public boolean isTemporaryTable(Object groupID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
     	FakeMetadataObject group = (FakeMetadataObject) groupID;
         Boolean isTemp = (Boolean)group.getProperty(FakeMetadataObject.Props.TEMP);
@@ -512,7 +512,7 @@
     }    
 
 	public Collection getXMLTempGroups(Object groupID)
-        throws MetaMatrixComponentException, QueryMetadataException{
+        throws TeiidComponentException, QueryMetadataException{
 
 		ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		MappingDocument mappingDoc = (MappingDocument)((FakeMetadataObject)groupID).getProperty(FakeMetadataObject.Props.PLAN);
@@ -537,7 +537,7 @@
     
 
     private List resolveGroups(List groupNames)
-        throws QueryMetadataException, MetaMatrixComponentException {
+        throws QueryMetadataException, TeiidComponentException {
         
         if(groupNames != null && !groupNames.isEmpty()) {
             ArrayList tempGroups = new ArrayList();
@@ -550,10 +550,10 @@
     }
 
 	/**
-	 * @see com.metamatrix.query.metadata.QueryMetadataInterface#getCardinality(java.lang.Object)
+	 * @see org.teiid.query.metadata.QueryMetadataInterface#getCardinality(java.lang.Object)
 	 */
 	public int getCardinality(Object groupID)
-		throws MetaMatrixComponentException, QueryMetadataException {
+		throws TeiidComponentException, QueryMetadataException {
 		ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
 		Integer cardinality = (Integer)((FakeMetadataObject)groupID).getProperty(FakeMetadataObject.Props.CARDINALITY);
 		if (cardinality != null){
@@ -562,18 +562,18 @@
 		return QueryMetadataInterface.UNKNOWN_CARDINALITY;
 	}
 
-    public String getNameInSource(Object metadataID) throws MetaMatrixComponentException, QueryMetadataException {
+    public String getNameInSource(Object metadataID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
         return (String)((FakeMetadataObject)metadataID).getProperty(FakeMetadataObject.Props.NAME_IN_SOURCE);
     }
 
     public Properties getExtensionProperties(Object metadataID)
-        throws MetaMatrixComponentException, QueryMetadataException {
+        throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
         return ((FakeMetadataObject)metadataID).getExtensionProps();
     }
 
-    public int getElementLength(Object elementID) throws MetaMatrixComponentException, QueryMetadataException {
+    public int getElementLength(Object elementID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject) elementID;
 	    return Integer.parseInt((String) element.getProperty(FakeMetadataObject.Props.LENGTH));
@@ -582,13 +582,13 @@
     /**
      * Return position of element in group or result set.  Position returned is 1-based!
      */
-    public int getPosition(Object elementID) throws MetaMatrixComponentException, QueryMetadataException {
+    public int getPosition(Object elementID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
 	    FakeMetadataObject element = (FakeMetadataObject) elementID;
         return ((Integer) element.getProperty(FakeMetadataObject.Props.INDEX)).intValue() + 1;
     }
 
-    public int getPrecision(Object elementID) throws MetaMatrixComponentException, QueryMetadataException {
+    public int getPrecision(Object elementID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject) elementID;
         String precision = (String) element.getProperty(FakeMetadataObject.Props.PRECISION);
@@ -598,7 +598,7 @@
         return Integer.parseInt(precision);
     }
 
-    public int getRadix(Object elementID) throws MetaMatrixComponentException, QueryMetadataException {
+    public int getRadix(Object elementID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject) elementID;
         String radix = (String) element.getProperty(FakeMetadataObject.Props.RADIX);
@@ -608,7 +608,7 @@
         return Integer.parseInt(radix);
     }
 
-    public int getScale(Object elementID) throws MetaMatrixComponentException, QueryMetadataException {
+    public int getScale(Object elementID) throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject) elementID;
         String scale = (String) element.getProperty(FakeMetadataObject.Props.SCALE);
@@ -619,7 +619,7 @@
     }
 
     
-    public String getNativeType(Object elementID) throws MetaMatrixComponentException,
+    public String getNativeType(Object elementID) throws TeiidComponentException,
                                                  QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element =  (FakeMetadataObject) elementID;
@@ -630,21 +630,21 @@
         return nativeType;
     }
     
-    public boolean hasMaterialization(Object groupID) throws MetaMatrixComponentException,
+    public boolean hasMaterialization(Object groupID) throws TeiidComponentException,
                                                      QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
         FakeMetadataObject group = (FakeMetadataObject)groupID;
         return group.getProperty(FakeMetadataObject.Props.MAT_GROUP) != null;
     }
 
-    public Object getMaterialization(Object groupID) throws MetaMatrixComponentException,
+    public Object getMaterialization(Object groupID) throws TeiidComponentException,
                                                     QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
         FakeMetadataObject group =  (FakeMetadataObject) groupID;
         return group.getProperty(FakeMetadataObject.Props.MAT_GROUP);
     }
     
-    public Object getMaterializationStage(Object groupID) throws MetaMatrixComponentException,
+    public Object getMaterializationStage(Object groupID) throws TeiidComponentException,
                                                          QueryMetadataException {
         
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
@@ -652,21 +652,21 @@
         return group.getProperty(FakeMetadataObject.Props.MAT_STAGE);
     }
     
-    public Object getMaximumValue(Object elementID) throws MetaMatrixComponentException,
+    public Object getMaximumValue(Object elementID) throws TeiidComponentException,
                                                    QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element =  (FakeMetadataObject) elementID;
         return element.getProperty(FakeMetadataObject.Props.MAX_VALUE);
     }
     
-    public Object getMinimumValue(Object elementID) throws MetaMatrixComponentException,
+    public Object getMinimumValue(Object elementID) throws TeiidComponentException,
                                                    QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element =  (FakeMetadataObject) elementID;
         return element.getProperty(FakeMetadataObject.Props.MIN_VALUE);
     }
 
-    public int getDistinctValues(Object elementID) throws MetaMatrixComponentException,
+    public int getDistinctValues(Object elementID) throws TeiidComponentException,
                                                    QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject)elementID;
@@ -677,7 +677,7 @@
         return -1;
     }
 
-    public int getNullValues(Object elementID) throws MetaMatrixComponentException,
+    public int getNullValues(Object elementID) throws TeiidComponentException,
                                                    QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element = (FakeMetadataObject)elementID;
@@ -688,7 +688,7 @@
         return -1;
     }
 
-    public List getXMLSchemas(Object groupID) throws MetaMatrixComponentException,
+    public List getXMLSchemas(Object groupID) throws TeiidComponentException,
                                              QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, groupID);
         FakeMetadataObject group =  (FakeMetadataObject) groupID;
@@ -701,23 +701,23 @@
         return FakeMetadataObject.PROCEDURE.equals(element.getType());
 	}
     
-    public byte[] getBinaryVDBResource(String resourcePath) throws MetaMatrixComponentException, QueryMetadataException {
+    public byte[] getBinaryVDBResource(String resourcePath) throws TeiidComponentException, QueryMetadataException {
         return "ResourceContents".getBytes(); //$NON-NLS-1$
     }
 
-    public String getCharacterVDBResource(String resourcePath) throws MetaMatrixComponentException, QueryMetadataException {
+    public String getCharacterVDBResource(String resourcePath) throws TeiidComponentException, QueryMetadataException {
         return "ResourceContents"; //$NON-NLS-1$
     }
 
-    public String[] getVDBResourcePaths() throws MetaMatrixComponentException, QueryMetadataException {
+    public String[] getVDBResourcePaths() throws TeiidComponentException, QueryMetadataException {
         return new String[] {"my/resource/path"}; //$NON-NLS-1$
     }
     
     /** 
-     * @see com.metamatrix.query.metadata.BasicQueryMetadata#getModeledType(java.lang.Object)
+     * @see org.teiid.query.metadata.BasicQueryMetadata#getModeledType(java.lang.Object)
      * @since 5.0
      */
-    public String getModeledType(Object elementID) throws MetaMatrixComponentException,
+    public String getModeledType(Object elementID) throws TeiidComponentException,
                                                   QueryMetadataException {
         
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
@@ -726,10 +726,10 @@
     }
     
     /** 
-     * @see com.metamatrix.query.metadata.BasicQueryMetadata#getModeledBaseType(java.lang.Object)
+     * @see org.teiid.query.metadata.BasicQueryMetadata#getModeledBaseType(java.lang.Object)
      * @since 5.0
      */
-    public String getModeledBaseType(Object elementID) throws MetaMatrixComponentException,
+    public String getModeledBaseType(Object elementID) throws TeiidComponentException,
                                                       QueryMetadataException {
         
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
@@ -738,10 +738,10 @@
     }
     
     /** 
-     * @see com.metamatrix.query.metadata.BasicQueryMetadata#getModeledPrimitiveType(java.lang.Object)
+     * @see org.teiid.query.metadata.BasicQueryMetadata#getModeledPrimitiveType(java.lang.Object)
      * @since 5.0
      */
-    public String getModeledPrimitiveType(Object elementID) throws MetaMatrixComponentException,
+    public String getModeledPrimitiveType(Object elementID) throws TeiidComponentException,
                                                            QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, elementID);
         FakeMetadataObject element =  (FakeMetadataObject) elementID;
@@ -750,7 +750,7 @@
     
     @Override
     public Object addToMetadataCache(Object metadataID, String key, Object value)
-    		throws MetaMatrixComponentException, QueryMetadataException {
+    		throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
     	FakeMetadataObject object = (FakeMetadataObject) metadataID;
     	synchronized (object) {
@@ -762,7 +762,7 @@
     
     @Override
     public Object getFromMetadataCache(Object metadataID, String key)
-    		throws MetaMatrixComponentException, QueryMetadataException {
+    		throws TeiidComponentException, QueryMetadataException {
     	ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
     	FakeMetadataObject object =  (FakeMetadataObject) metadataID;
     	synchronized (object) {

Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -33,21 +33,21 @@
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.SessionMetadata;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.client.metadata.ParameterInfo;
 import org.teiid.connector.metadata.runtime.Table;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingAttribute;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.mapping.xml.MappingSequenceNode;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.sql.symbol.ElementSymbol;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingAttribute;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.mapping.xml.MappingSequenceNode;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 public class FakeMetadataFactory {
 
@@ -64,7 +64,7 @@
         return RealMetadataFactory.exampleBQTCached();
     }
     
-    public static void setCardinality(String group, int cardinality, QueryMetadataInterface metadata) throws QueryMetadataException, MetaMatrixComponentException {
+    public static void setCardinality(String group, int cardinality, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
     	if (metadata instanceof TransformationMetadata) {
     		Table t = (Table)metadata.getGroupID(group);
     		t.setCardinality(cardinality);

Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataObject.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataObject.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataObject.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
 
 import java.io.Serializable;
 import java.util.HashMap;

Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataStore.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataStore.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataStore.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
 
 import java.util.*;
 

Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/RealMetadataFactory.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -39,12 +39,12 @@
 import org.teiid.connector.metadata.runtime.BaseColumn.NullType;
 import org.teiid.connector.metadata.runtime.Column.SearchType;
 import org.teiid.connector.metadata.runtime.ProcedureParameter.Type;
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.metadata.CompositeMetadataStore;
 import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.sql.lang.SPParameter;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.sql.lang.SPParameter;
 
 public class RealMetadataFactory {
 

Copied: trunk/engine/src/test/java/org/teiid/query/util (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/util)

Modified: trunk/engine/src/test/java/org/teiid/query/util/TestPermutation.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/util/TestPermutation.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/util/TestPermutation.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,15 +20,16 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.util;
+package org.teiid.query.util;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
 
-import com.metamatrix.query.util.Permutation;
+import org.teiid.query.util.Permutation;
 
+
 import junit.framework.TestCase;
 
 /**

Copied: trunk/engine/src/test/java/org/teiid/query/validator (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/validator)

Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.validator;
+package org.teiid.query.validator;
 
 import static org.junit.Assert.*;
 
@@ -36,40 +36,42 @@
 import java.util.Set;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingElement;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.StoredProcedureInfo;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.ProcedureContainer;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+import org.teiid.query.unittest.FakeMetadataFacade;
+import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.FakeMetadataObject;
+import org.teiid.query.unittest.FakeMetadataStore;
+import org.teiid.query.validator.Validator;
+import org.teiid.query.validator.ValidatorReport;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.mapping.xml.MappingDocument;
-import com.metamatrix.query.mapping.xml.MappingElement;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.metadata.StoredProcedureInfo;
-import com.metamatrix.query.parser.QueryParser;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.sql.LanguageObject;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.ProcedureContainer;
-import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-import com.metamatrix.query.unittest.FakeMetadataFacade;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
-import com.metamatrix.query.unittest.FakeMetadataObject;
-import com.metamatrix.query.unittest.FakeMetadataStore;
 
 @SuppressWarnings("nls")
 public class TestValidator {
 
     public static Map getStoredProcedureExternalMetadata(GroupSymbol virtualProc, QueryMetadataInterface metadata)
-    throws QueryMetadataException, MetaMatrixComponentException {
+    throws QueryMetadataException, TeiidComponentException {
 
         Map externalMetadata = new HashMap();
 
@@ -328,7 +330,7 @@
 			command = QueryParser.getQueryParser().parseCommand(sql);
 			QueryResolver.resolveCommand(command, externalMetadata, metadata, AnalysisRecord.createNonRecordingRecord());
 		} catch(Exception e) {
-            throw new MetaMatrixRuntimeException(e);
+            throw new TeiidRuntimeException(e);
 		} 
 
 		return command;
@@ -365,8 +367,8 @@
                 assertEquals("Expected and actual sets of strings are not the same: ", expectedStrings, actualStrings); //$NON-NLS-1$
             }
             return report;
-        } catch(MetaMatrixException e) {
-			throw new MetaMatrixRuntimeException(e);
+        } catch(TeiidException e) {
+			throw new TeiidRuntimeException(e);
         }
 	}
 
@@ -387,8 +389,8 @@
             if(actualObjs.size() > 0) {
                 fail("Expected no failures but got some: " + report.getFailureMessage());            	 //$NON-NLS-1$
             }
-        } catch(MetaMatrixException e) {
-            throw new MetaMatrixRuntimeException(e);
+        } catch(TeiidException e) {
+            throw new TeiidRuntimeException(e);
         }
 	}
 	
@@ -406,7 +408,7 @@
             Collection actualObjs = new ArrayList();
             report.collectInvalidObjects(actualObjs);
             assertTrue("Expected some failures but got none for procedure = " + procedure, !actualObjs.isEmpty()); //$NON-NLS-1$ 
-        } catch(MetaMatrixException e) {
+        } catch(TeiidException e) {
 			throw new RuntimeException(e);
         }
 	}	

Copied: trunk/engine/src/test/java/org/teiid/query/xquery (from rev 2112, trunk/engine/src/test/java/com/metamatrix/query/xquery)

Modified: trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/xquery/HardcodedSqlEval.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.xquery;
+package org.teiid.query.xquery;
 
 import java.io.StringReader;
 import java.util.Map;
@@ -28,13 +28,15 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.api.exception.query.ExpressionEvaluationException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.common.buffer.BlockedException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.api.exception.query.QueryParserException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.xquery.XQuerySQLEvaluator;
 
 
+
 /** 
  */
 public class HardcodedSqlEval implements XQuerySQLEvaluator {
@@ -46,7 +48,7 @@
     }
 
     public Source executeSQL(String sql) 
-        throws QueryParserException, MetaMatrixProcessingException, MetaMatrixComponentException {
+        throws QueryParserException, TeiidProcessingException, TeiidComponentException {
         if (this.result != null) {
             return new StreamSource(new StringReader(result));
         }
@@ -54,15 +56,15 @@
     }
 
     /** 
-     * @see com.metamatrix.query.xquery.XQuerySQLEvaluator#close()
+     * @see org.teiid.query.xquery.XQuerySQLEvaluator#close()
      */
-    public void close() throws MetaMatrixComponentException {
+    public void close() throws TeiidComponentException {
     }
 
 	@Override
 	public Object getParameterValue(String key)
 			throws ExpressionEvaluationException, BlockedException,
-			MetaMatrixComponentException {
+			TeiidComponentException {
 		return params.get(key);
 	}
 

Modified: trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/xquery/TestXQueryEngine.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,7 +20,7 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.query.xquery;
+package org.teiid.query.xquery;
 
 import java.io.File;
 import java.io.IOException;
@@ -35,13 +35,15 @@
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.output.XMLOutputter;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.XMLTranslator;
+import org.teiid.core.util.FileUtil;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.query.xquery.XQueryExpression;
+import org.teiid.query.xquery.XQuerySQLEvaluator;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
 
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.types.SQLXMLImpl;
-import com.metamatrix.common.types.XMLTranslator;
-import com.metamatrix.core.util.FileUtil;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.xquery.saxon.SaxonXQueryExpression;
 
 /**
  * Test XQueryEngine and XQueryExpression implementations
@@ -77,7 +79,7 @@
         try {
             expr.evaluateXQuery(sqlEval);
             fail("expected failure");  //$NON-NLS-1$
-        } catch (MetaMatrixProcessingException e) {
+        } catch (TeiidProcessingException e) {
             assertEquals(expectedFailure, e.getClass());
         }
     }
@@ -146,7 +148,7 @@
                         "}\n" +  //$NON-NLS-1$
                         "</friends>"; //$NON-NLS-1$   
         
-        helpTestEngineFails(xquery, MetaMatrixProcessingException.class, new HardcodedSqlEval(xmlOutputter.outputString(doc)));
+        helpTestEngineFails(xquery, TeiidProcessingException.class, new HardcodedSqlEval(xmlOutputter.outputString(doc)));
     }
     
     public void testDocArgReadingFileURI() throws Exception {

Copied: trunk/engine/src/test/java/org/teiid/vdb/runtime (from rev 2112, trunk/engine/src/test/java/com/metamatrix/vdb/runtime)

Modified: trunk/engine/src/test/java/org/teiid/vdb/runtime/TestVDBKey.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/vdb/runtime/TestVDBKey.java	2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/engine/src/test/java/org/teiid/vdb/runtime/TestVDBKey.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,11 +20,12 @@
  * 02110-1301 USA.
  */
 
-package com.metamatrix.vdb.runtime;
+package org.teiid.vdb.runtime;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.vdb.runtime.VDBKey;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.vdb.runtime.VDBKey;
 
+
 import junit.framework.TestCase;
 
 public class TestVDBKey extends TestCase {

Copied: trunk/engine/src/test/resources/org (from rev 2113, trunk/engine/src/test/resources/com)

Copied: trunk/engine/src/test/resources/org/teiid (from rev 2113, trunk/engine/src/test/resources/com/metamatrix)

Deleted: trunk/engine/src/test/resources/org/teiid/query/mapping/xml/testExample.xml
===================================================================
--- trunk/engine/src/test/resources/com/metamatrix/query/mapping/xml/testExample.xml	2010-05-11 16:40:58 UTC (rev 2113)
+++ trunk/engine/src/test/resources/org/teiid/query/mapping/xml/testExample.xml	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?> 
-<!--
-
-    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.
-
--->
-<xmlMapping>
-    <mappingNode> 
-        <name>root</name> 
-        <documentEncoding>UTF-16</documentEncoding> 
-        <formattedDocument>true</formattedDocument> 
-        <mappingNode> 
-            <name>element</name> 
-			<source>source</source>
-            <mappingNode> 
-                <name>data</name> 
-            </mappingNode> 
-            <mappingNode> 
-                <name>recursionRoot</name> 
-	            <isRecursive>true</isRecursive> 
-	            <recursionCriteria>xxxx</recursionCriteria> 
-	            <recursionLimit>1001</recursionLimit> 
-	            <recursionLimitException>true</recursionLimitException> 
-				<recursionRootMappingClass>source</recursionRootMappingClass>
-                <mappingNode> 
-                    <name>data</name> 
-                </mappingNode> 
-            </mappingNode> 
-        </mappingNode> 
-    </mappingNode> 
-</xmlMapping>
-
-

Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -39,11 +39,11 @@
 import org.jboss.metatype.api.values.MetaValueFactory;
 import org.jboss.metatype.api.values.SimpleValue;
 import org.teiid.adminapi.impl.TranslatorMetaData;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.jboss.IntegrationPlugin;
 import org.teiid.templates.TranslatorMetadataICF;
 
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 
 public class AdminObjectBuilder {
@@ -96,9 +96,9 @@
 			}
 			return clazz.cast(t);
 		} catch (InstantiationException e) {
-			throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
 		} catch (IllegalAccessException e) {
-			throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
 		}
 	}
 	
@@ -116,9 +116,9 @@
 			}  
 			return clazz.cast(t);
 		} catch (InstantiationException e) {
-			throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
 		} catch (IllegalAccessException e) {
-			throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, IntegrationPlugin.Util.getString("class_not_found", clazz.getName())); //$NON-NLS-1$
 		}
 	}
 }

Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/ManagedUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -55,9 +55,9 @@
 import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.profileservice.spi.DeploymentOption;
 import org.teiid.adminapi.AdminProcessingException;
+import org.teiid.core.TeiidRuntimeException;
 import org.teiid.jboss.IntegrationPlugin;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 public class ManagedUtil {
 	
@@ -102,7 +102,7 @@
 				SimpleValue simple = (SimpleValue)v1;
 				return simple.getValue().toString();
 			}
-			throw new MetaMatrixRuntimeException("Failed to convert value to string value"); //$NON-NLS-1$
+			throw new TeiidRuntimeException("Failed to convert value to string value"); //$NON-NLS-1$
 		}
 		return null;
 	}	
@@ -189,7 +189,7 @@
 				try {
 					return new SimpleValueSupport(st, SimpleDateFormat.getInstance().parse(value));
 				} catch (ParseException e) {
-					throw new MetaMatrixRuntimeException(e, IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
+					throw new TeiidRuntimeException(e, IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
 				}
 			} else if (SimpleMetaType.DOUBLE.equals(st)) {
 				return new SimpleValueSupport(st, Double.valueOf(value));
@@ -215,7 +215,7 @@
 				return new SimpleValueSupport(st,value);
 			}
 		}
-		throw new MetaMatrixRuntimeException(IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
+		throw new TeiidRuntimeException(IntegrationPlugin.Util.getString("failed_to_convert", type.getClassName())); //$NON-NLS-1$
 	}
 	
 	public static void deployArchive(DeploymentManager deploymentManager, String fileName, final InputStream resource, boolean deployExploded) throws AdminProcessingException {
@@ -275,7 +275,7 @@
 				}
 			});
 		} catch (MalformedURLException e2) {
-			throw new MetaMatrixRuntimeException(e2);
+			throw new TeiidRuntimeException(e2);
 		}
 	}
 
@@ -312,6 +312,6 @@
 				return mo.invoke(args);
 			}
 		}
-		throw new MetaMatrixRuntimeException(IntegrationPlugin.Util.getString("no_operation", operation)); //$NON-NLS-1$ 
+		throw new TeiidRuntimeException(IntegrationPlugin.Util.getString("no_operation", operation)); //$NON-NLS-1$ 
 	}
 }

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,8 +23,9 @@
 
 import java.util.ResourceBundle;
 
-import com.metamatrix.core.BundleUtil;
+import org.teiid.core.BundleUtil;
 
+
 public class IntegrationPlugin {
     private static final String PLUGIN_ID = "org.teiid.jboss" ; //$NON-NLS-1$
     private static final String BUNDLE_NAME = PLUGIN_ID + ".i18n"; //$NON-NLS-1$

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -52,12 +52,19 @@
 import org.teiid.client.DQP;
 import org.teiid.client.security.ILogon;
 import org.teiid.client.util.ExceptionUtil;
+import org.teiid.core.ComponentNotFoundException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidRuntimeException;
 import org.teiid.deployers.VDBRepository;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
 import org.teiid.dqp.internal.process.DQPConfiguration;
 import org.teiid.dqp.internal.process.DQPCore;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.dqp.internal.transaction.TransactionServerImpl;
+import org.teiid.dqp.service.BufferService;
+import org.teiid.dqp.service.SessionService;
+import org.teiid.dqp.service.SessionServiceException;
+import org.teiid.dqp.service.TransactionService;
 import org.teiid.jboss.IntegrationPlugin;
 import org.teiid.logging.Log4jListener;
 import org.teiid.logging.LogConstants;
@@ -70,13 +77,6 @@
 import org.teiid.transport.SocketConfiguration;
 import org.teiid.transport.SocketListener;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.dqp.service.BufferService;
-import com.metamatrix.dqp.service.SessionService;
-import com.metamatrix.dqp.service.SessionServiceException;
-import com.metamatrix.dqp.service.TransactionService;
 
 @ManagementObject(isRuntime=true, componentType=@ManagementComponent(type="teiid",subtype="dqp"), properties=ManagementProperties.EXPLICIT)
 public class RuntimeEngineDeployer extends DQPConfiguration implements DQPManagement, Serializable , ClientServiceRegistry  {
@@ -141,7 +141,7 @@
     	
     	try {
 	    	this.dqpCore.stop();
-    	} catch(MetaMatrixRuntimeException e) {
+    	} catch(TeiidRuntimeException e) {
     		// this bean is already shutdown
     	}
     	
@@ -166,7 +166,7 @@
     	try {
     		this.admin = AdminProvider.getLocal();
     	} catch (AdminComponentException e) {
-    		throw new MetaMatrixRuntimeException(e.getCause());
+    		throw new TeiidRuntimeException(e.getCause());
     	}		        
 	}    
 	
@@ -270,7 +270,7 @@
     public boolean cancelRequest(String sessionId, long requestId) throws AdminException {
     	try {
 			return this.dqpCore.cancelRequest(sessionId, requestId);
-		} catch (MetaMatrixComponentException e) {
+		} catch (TeiidComponentException e) {
 			throw new AdminComponentException(e);
 		}
     }

Modified: trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java
===================================================================
--- trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestManagedUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 import java.net.URL;
 
 import org.junit.Test;
+import org.teiid.core.util.ObjectConverterUtil;
 
-import com.metamatrix.core.util.ObjectConverterUtil;
 
 public class TestManagedUtil {
 

Modified: trunk/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/internal/core/index/BlocksIndexInput.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,8 +20,8 @@
 import org.teiid.core.index.IDocument;
 import org.teiid.core.index.IEntryResult;
 import org.teiid.core.index.IQueryResult;
+import org.teiid.core.util.LRUCache;
 
-import com.metamatrix.core.util.LRUCache;
 
 /**
  * This input is used for reading indexes saved using a BlocksIndexOutput.

Modified: trunk/metadata/src/main/java/org/teiid/internal/core/index/VirtualRandomAccessFile.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/internal/core/index/VirtualRandomAccessFile.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/internal/core/index/VirtualRandomAccessFile.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,8 +25,8 @@
 import java.io.IOException;
 
 import org.jboss.virtual.VirtualFile;
+import org.teiid.core.util.ObjectConverterUtil;
 
-import com.metamatrix.core.util.ObjectConverterUtil;
 
 public class VirtualRandomAccessFile {
 	File indexFile;

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -42,6 +42,7 @@
 import org.jboss.virtual.spi.VirtualFileHandler;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryMetadataException;
 import org.teiid.connector.metadata.runtime.AbstractMetadataRecord;
 import org.teiid.connector.metadata.runtime.Column;
 import org.teiid.connector.metadata.runtime.ColumnSet;
@@ -53,19 +54,18 @@
 import org.teiid.connector.metadata.runtime.ProcedureParameter;
 import org.teiid.connector.metadata.runtime.Schema;
 import org.teiid.connector.metadata.runtime.Table;
+import org.teiid.core.CoreConstants;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.id.UUID;
 import org.teiid.core.index.IEntryResult;
+import org.teiid.core.util.ArgCheck;
+import org.teiid.core.util.StringUtil;
 import org.teiid.internal.core.index.Index;
 import org.teiid.metadata.TransformationMetadata;
+import org.teiid.metadata.VdbConstants;
 import org.teiid.metadata.TransformationMetadata.Resource;
 
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.id.UUID;
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.StringUtil;
-import com.metamatrix.core.vdb.VdbConstants;
 
 /**
  * Loads MetadataRecords from index files.  
@@ -73,6 +73,9 @@
 public class IndexMetadataFactory {
 	
 	private Index[] indexes;
+	private RecordFactory recordFactory = new RecordFactory();
+	private Map<String, String> annotationCache = new HashMap<String, String>();
+	private Map<String, LinkedHashMap<String, String>> extensionCache = new HashMap<String, LinkedHashMap<String,String>>();
     private Map<String, Datatype> datatypeCache;
     private Map<String, KeyRecord> primaryKeyCache = new HashMap<String, KeyRecord>();
     private Map<String, Table> tableCache = new HashMap<String, Table>();
@@ -119,7 +122,13 @@
 	            tmp.add(index);
 			}
 			this.indexes = tmp.toArray(new Index[tmp.size()]);
+			getAnnotationCache();
+			getExtensionCache();			
 			getDatatypeCache();
+			List<KeyRecord> keys = findMetadataRecords(MetadataConstants.RECORD_TYPE.PRIMARY_KEY, null, false);
+			for (KeyRecord keyRecord : keys) {
+				this.primaryKeyCache.put(keyRecord.getUUID(), keyRecord);
+			}
 			getModels();
 			getTables();
 			getProcedures();
@@ -131,6 +140,52 @@
 		return store;
     }
 
+	private void getExtensionCache() {
+		IEntryResult[] properties = queryIndex(MetadataConstants.RECORD_TYPE.PROPERTY, null, false);
+
+		for (IEntryResult iEntryResult : properties) {
+        	final String str = new String(iEntryResult.getWord());
+            final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
+
+            // The tokens are the standard header values
+            int tokenIndex = 2;
+
+            String uuid = (String)tokens.get(1);
+	    	LinkedHashMap<String, String> result = this.extensionCache.get(uuid);
+	    	if (result == null) {
+	    		result = new LinkedHashMap<String, String>(); 
+	    		this.extensionCache.put(uuid, result);
+	    	}
+            result.put( (String)tokens.get(tokenIndex++), (String)tokens.get(tokenIndex++));
+		}
+	}
+
+	private void getAnnotationCache() {
+		IEntryResult[] results = queryIndex(MetadataConstants.RECORD_TYPE.ANNOTATION, null, false);
+		
+		for (IEntryResult iEntryResult : results) {
+	        final String str = new String(iEntryResult.getWord());
+	        final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
+
+	        // Extract the index version information from the record 
+	        int indexVersion = recordFactory.getIndexVersion(iEntryResult.getWord());
+
+	        
+	        String uuid = (String)tokens.get(2);
+	        
+	        // The tokens are the standard header values
+	        int tokenIndex = 6;
+
+	        if(recordFactory.includeAnnotationProperties(indexVersion)) {
+				// The next token are the properties, ignore it not going to be read any way
+	            tokenIndex++;
+	        }
+
+	        // The next token is the description
+	        this.annotationCache.put(uuid, (String)tokens.get(tokenIndex++));
+		}
+	}
+
     public void addIndexFile(VirtualFile f) {
     	this.indexFiles.add(f);
     }
@@ -289,12 +344,11 @@
     }
 
 	private KeyRecord getPrimaryKey(String uuid) {
-		KeyRecord pk = this.primaryKeyCache.get(uuid);
-		if (pk == null) {
-			pk = (KeyRecord)this.getRecordByType(uuid, MetadataConstants.RECORD_TYPE.PRIMARY_KEY);
-			this.primaryKeyCache.put(uuid, pk);
-		}
-		return pk;
+		KeyRecord key = this.primaryKeyCache.get(uuid);
+		if (key == null) {
+            throw new TeiidRuntimeException(uuid+" PrimaryKey "+TransformationMetadata.NOT_EXISTS_MESSAGE); //$NON-NLS-1$
+    	}
+		return key;
 	}
 	
     public Map<String, Datatype> getDatatypeCache() {
@@ -331,11 +385,11 @@
         if(resultSize == 0) {
         	if (mustExist) {
 			// there should be only one for the UUID
-	            throw new MetaMatrixRuntimeException(entityName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+	            throw new TeiidRuntimeException(entityName+TransformationMetadata.NOT_EXISTS_MESSAGE);
         	} 
         	return null;
 		} 
-        throw new MetaMatrixRuntimeException(RuntimeMetadataPlugin.Util.getString("TransformationMetadata.0", entityName)); //$NON-NLS-1$
+        throw new TeiidRuntimeException(RuntimeMetadataPlugin.Util.getString("TransformationMetadata.0", entityName)); //$NON-NLS-1$
     }
     
     public void getProcedures() {
@@ -416,20 +470,13 @@
 
 	private List<AbstractMetadataRecord> loadRecords(
 			IEntryResult[] results) {
-		List<AbstractMetadataRecord> records = RecordFactory.getMetadataRecord(results);
+		List<AbstractMetadataRecord> records = recordFactory.getMetadataRecord(results);
 		
 		for (AbstractMetadataRecord metadataRecord : records) {
 			String uuid = metadataRecord.getUUID();
 			
-			String prefixString  = getUUIDMatchPattern(MetadataConstants.RECORD_TYPE.ANNOTATION, uuid, false);
-			IEntryResult[] annotations = queryIndex(MetadataConstants.RECORD_TYPE.ANNOTATION, prefixString.toCharArray(), false, true, true);
-			if (annotations.length > 0) {
-				metadataRecord.setAnnotation(RecordFactory.createAnnotationRecord(annotations[0].getWord()));
-			}
-			
-			prefixString = String.valueOf(MetadataConstants.RECORD_TYPE.PROPERTY) + IndexConstants.RECORD_STRING.RECORD_DELIMITER + uuid.trim() + IndexConstants.RECORD_STRING.RECORD_DELIMITER;
-			IEntryResult[] properties = queryIndex(MetadataConstants.RECORD_TYPE.PROPERTY, prefixString.toCharArray(), true, true, true);
-			metadataRecord.setProperties(RecordFactory.createPropertyRecord(properties));
+			metadataRecord.setAnnotation(this.annotationCache.get(uuid));
+			metadataRecord.setProperties(this.extensionCache.get(uuid));
 		}
 		return records;
 	}
@@ -582,8 +629,8 @@
 
     	try {
             return SimpleIndexUtil.queryIndex(search, pattern, isPrefix, isCaseSensitive, returnFirstMatch);
-        } catch (MetaMatrixCoreException e) {
-            throw new MetaMatrixRuntimeException(e);
+        } catch (TeiidException e) {
+            throw new TeiidRuntimeException(e);
         }
     }    
 }

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/MetadataConstants.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/MetadataConstants.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/MetadataConstants.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,7 +22,7 @@
 
 package org.teiid.metadata.index;
 
-import com.metamatrix.core.util.StringUtil;
+import org.teiid.core.util.StringUtil;
 
 /**
  * MetadataConstants are all the constant values used to identify all the valid values for a multi-value attribute.

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/RecordFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,7 +25,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 
 import org.teiid.connector.metadata.runtime.AbstractMetadataRecord;
@@ -34,20 +33,20 @@
 import org.teiid.connector.metadata.runtime.Datatype;
 import org.teiid.connector.metadata.runtime.ForeignKey;
 import org.teiid.connector.metadata.runtime.KeyRecord;
-import org.teiid.connector.metadata.runtime.Schema;
-import org.teiid.connector.metadata.runtime.ProcedureParameter;
 import org.teiid.connector.metadata.runtime.Procedure;
+import org.teiid.connector.metadata.runtime.ProcedureParameter;
+import org.teiid.connector.metadata.runtime.Schema;
 import org.teiid.connector.metadata.runtime.Table;
 import org.teiid.connector.metadata.runtime.BaseColumn.NullType;
 import org.teiid.connector.metadata.runtime.Column.SearchType;
 import org.teiid.connector.metadata.runtime.Datatype.Variety;
+import org.teiid.core.id.UUID;
 import org.teiid.core.index.IEntryResult;
+import org.teiid.core.util.Assertion;
+import org.teiid.core.util.StringUtil;
 import org.teiid.internal.core.index.EntryResult;
 import org.teiid.internal.core.index.IIndexConstants;
 
-import com.metamatrix.core.id.UUID;
-import com.metamatrix.core.util.Assertion;
-import com.metamatrix.core.util.StringUtil;
 
 /**
  * RuntimeAdapter
@@ -136,11 +135,9 @@
      * The version number that is encoded with all newly created index records
      */
     public static final int CURRENT_INDEX_VERSION = PROCEDURE_UPDATE_COUNT_VERSION;
-
-    // ==================================================================================
-    //                      P U B L I C   M E T H O D S
-    // ==================================================================================
     
+    private int version = NONVERSIONED_RECORD_INDEX_VERSION;
+    
     /**
      * Return a collection of {@link com.metamatrix.modeler.core.metadata.runtime.MetadataRecord}
      * instances for the result obtained from executing <code>queryEntriesMatching</code>
@@ -148,7 +145,7 @@
      * @param queryResult
      * @param container Container reference to be set on the record
      */
-    public static List<AbstractMetadataRecord> getMetadataRecord(final IEntryResult[] queryResult) {
+    public List<AbstractMetadataRecord> getMetadataRecord(final IEntryResult[] queryResult) {
         final List records = new ArrayList(queryResult.length);
         for (int i = 0; i < queryResult.length; i++) {
             final AbstractMetadataRecord record = getMetadataRecord(queryResult[i].getWord());
@@ -164,7 +161,7 @@
      * instances for specified IEntryResult.
      * @param entryResult
      */
-    private static AbstractMetadataRecord getMetadataRecord(final char[] record) {
+    private AbstractMetadataRecord getMetadataRecord(final char[] record) {
         if (record == null || record.length == 0) {
             return null;
         }
@@ -204,8 +201,6 @@
     public static IEntryResult joinEntryResults(final IEntryResult result, 
                                                 final IEntryResult[] continuationResults, 
                                                 final int blockSize) {
-        Assertion.isNotNull(result);
-
         // If the IEntryResult is not continued on another record, return the original
         char[] baseResult = result.getWord();
         if (baseResult.length < blockSize || baseResult[blockSize-1] != MetadataConstants.RECORD_TYPE.RECORD_CONTINUATION) {
@@ -285,8 +280,6 @@
      * @param result
      */
     public static String extractUUIDString(final IEntryResult result) {
-        Assertion.isNotNull(result);
-        
         char[] word = result.getWord();
         String baseStr = new String(word);
         int beginIndex = baseStr.indexOf(UUID.PROTOCOL);
@@ -309,7 +302,7 @@
     /**
      * Create a ModelRecord instance from the specified index record
      */
-    public static Schema createModelRecord(final char[] record) {
+    public Schema createModelRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final Schema model = new Schema();
@@ -342,7 +335,7 @@
     /**
      * Create a TransformationRecord instance from the specified index record
      */
-    public static TransformationRecordImpl createTransformationRecord(final char[] record) {
+    public TransformationRecordImpl createTransformationRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final TransformationRecordImpl transform = new TransformationRecordImpl();
@@ -394,7 +387,7 @@
     /**
      * Create a TableRecord instance from the specified index record
      */
-    public static Table createTableRecord(final char[] record) {
+    public Table createTableRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final Table table = new Table();
@@ -466,7 +459,7 @@
     /**
      * Create a ColumnRecord instance from the specified index record
      */
-    public static Column createColumnRecord(final char[] record) {
+    public Column createColumnRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final Column column = new Column();
@@ -553,7 +546,7 @@
     /**
      * Create a ColumnSetRecord instance from the specified index record
      */
-    public static ColumnSet createColumnSetRecord(final char[] record, ColumnSet columnSet) {
+    public ColumnSet createColumnSetRecord(final char[] record, ColumnSet columnSet) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
 
@@ -583,7 +576,7 @@
     /**
      * Create a ForeignKeyRecord instance from the specified index record
      */
-    public static ForeignKey createForeignKeyRecord(final char[] record) {
+    public ForeignKey createForeignKeyRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final ForeignKey fkRecord = new ForeignKey();
@@ -613,7 +606,7 @@
     /**
      * Create a DatatypeRecord instance from the specified index record
      */
-    public static Datatype createDatatypeRecord(final char[] record) {
+    public Datatype createDatatypeRecord(final char[] record) {
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
         final Datatype dt = new Datatype();
@@ -696,7 +689,7 @@
     /**
      * Create a ProcedureRecord instance from the specified index record
      */
-    public static Procedure createProcedureRecord(final char[] record) {
+    public Procedure createProcedureRecord(final char[] record) {
 
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
@@ -752,7 +745,7 @@
      * Create a ProcedureParameterRecord instance from the specified index record
      * header|defaultValue|dataType|length|radix|scale|nullType|precision|paramType|footer|
      */
-    public static ProcedureParameter createProcedureParameterRecord(final char[] record) {
+    public ProcedureParameter createProcedureParameterRecord(final char[] record) {
 
         final String str = new String(record);
         final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
@@ -820,50 +813,6 @@
 
         return paramRd;
     }
-
-    /**
-     * Create a AnnotationRecord instance from the specified index record
-     */
-    public static String createAnnotationRecord(final char[] record) {
-        final String str = new String(record);
-        final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
-
-        // Extract the index version information from the record 
-        int indexVersion = getIndexVersion(record);
-
-        // The tokens are the standard header values
-        int tokenIndex = 6;
-
-        if(includeAnnotationProperties(indexVersion)) {
-			// The next token are the properties, ignore it not going to be read any way
-            tokenIndex++;
-        }
-
-        // The next token is the description
-        return (String)tokens.get(tokenIndex++);
-    }
-
-    /**
-     * Create a PropertyRecord instance from the specified index record
-     */
-    public static LinkedHashMap<String, String> createPropertyRecord(IEntryResult[] records) {
-    	if (records == null || records.length == 0) {
-    		return null;
-    	}
-    	LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
-        
-    	for (IEntryResult iEntryResult : records) {
-        	final String str = new String(iEntryResult.getWord());
-            final List tokens = StringUtil.split(str,String.valueOf(IndexConstants.RECORD_STRING.RECORD_DELIMITER));
-
-            // The tokens are the standard header values
-            int tokenIndex = 2;
-
-            result.put( (String)tokens.get(tokenIndex++), (String)tokens.get(tokenIndex++));
-		}
-
-        return result;
-    }
     
     /**
      * Search for and return the version number associated with this record.
@@ -872,38 +821,38 @@
      * @param record
      * @since 4.2
      */
-    private static int getIndexVersion(final char[] record) {
-        Assertion.isNotNull(record);
-        int endIndex   = record.length;
-        int beginIndex = (endIndex - 6 > 0 ? endIndex - 6 : 1);
-        int version    = NONVERSIONED_RECORD_INDEX_VERSION;
-        for (int i = beginIndex; i < endIndex; i++) {
-            if (record[i] == IndexConstants.RECORD_STRING.INDEX_VERSION_MARKER) {
-                char versionPart1 = record[i+1];
-                char versionPart2 = record[i+2];
-                if (Character.isDigit(versionPart1) && Character.isDigit(versionPart2)){
-                    version = Character.digit(versionPart1, 10) * 10 + Character.digit(versionPart2, 10);
-                }
-            }
-        }
+    int getIndexVersion(final char[] record) {
+    	if (version == NONVERSIONED_RECORD_INDEX_VERSION) {
+	        int endIndex   = record.length;
+	        int beginIndex = (endIndex - 6 > 0 ? endIndex - 6 : 1);
+	        for (int i = beginIndex; i < endIndex; i++) {
+	            if (record[i] == IndexConstants.RECORD_STRING.INDEX_VERSION_MARKER) {
+	                char versionPart1 = record[i+1];
+	                char versionPart2 = record[i+2];
+	                if (Character.isDigit(versionPart1) && Character.isDigit(versionPart2)){
+	                	version = Character.digit(versionPart1, 10) * 10 + Character.digit(versionPart2, 10);
+	                }
+	            }
+	        }
+    	}
         return version;
     }
 
-    public static String getObjectValue(final String str) {
+    public String getObjectValue(final String str) {
         if (str != null && str.length() == 1 && str.charAt(0) == IndexConstants.RECORD_STRING.SPACE) {
             return null;
         } 
         return str;
     }
 
-    public static boolean getBooleanValue(final char b) {
+    public boolean getBooleanValue(final char b) {
         if (b == IndexConstants.RECORD_STRING.TRUE) {
             return true;
         } 
         return false;
     }
 
-    public static List<String> getIDs(final String values, final int indexVersionNumber) {
+    public List<String> getIDs(final String values, final int indexVersionNumber) {
         if (StringUtil.isEmpty(values)) {
             return Collections.EMPTY_LIST;
         }
@@ -922,16 +871,16 @@
         return result;
     }
 
-    public static List getStrings(final String values, final int indexVersionNumber) {
+    public List<String> getStrings(final String values, final int indexVersionNumber) {
         if (StringUtil.isEmpty(values)) {
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
         }
         if (values.length() == 1 && values.charAt(0) == IndexConstants.RECORD_STRING.SPACE) {
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
         } 
         final char listDelimiter = getListDelimiter(indexVersionNumber);
         final List tokens = StringUtil.split(values,String.valueOf(listDelimiter));
-        final List result = new ArrayList(tokens.size());
+        final List<String> result = new ArrayList<String>(tokens.size());
         for (Iterator iter = tokens.iterator(); iter.hasNext();) {
             String token = (String)iter.next();
             if (token != null) {
@@ -941,63 +890,63 @@
         return result;
     }
 
-	public static char getListDelimiter(final int indexVersionNumber) {
+	public char getListDelimiter(final int indexVersionNumber) {
         if (indexVersionNumber < DELIMITER_INDEX_VERSION) {
             return IndexConstants.RECORD_STRING.LIST_DELIMITER_OLD;
         }
         return IndexConstants.RECORD_STRING.LIST_DELIMITER;
     }
 
-	public static boolean includeMaterializationFlag(final int indexVersionNumber) {
+	public boolean includeMaterializationFlag(final int indexVersionNumber) {
         if (indexVersionNumber < TABLE_MATERIALIZATION_INDEX_VERSION) {
             return false;
         }
         return true;
     }
 
-	public static boolean includeMaterializedTables(final int indexVersionNumber) {
+	public boolean includeMaterializedTables(final int indexVersionNumber) {
         if (indexVersionNumber < TABLE_MATERIALIZATION_INDEX_VERSION) {
             return false;
         }
         return true;
     }
 
-	public static boolean includeColumnNativeType(final int indexVersionNumber) {
+	public boolean includeColumnNativeType(final int indexVersionNumber) {
         if (indexVersionNumber < COLUMN_NATIVE_TYPE_INDEX_VERSION) {
             return false;
         }
         return true;
     }    
 
-	public static boolean includeColumnNullDistinctValues(final int indexVersionNumber) {
+	public boolean includeColumnNullDistinctValues(final int indexVersionNumber) {
         if (indexVersionNumber < COLUMN_NULL_DISTINCT_INDEX_VERSION) {
             return false;
         }
         return true;
     } 
 
-	public static boolean includePrimitiveTypeIdValue(final int indexVersionNumber) {
+	public boolean includePrimitiveTypeIdValue(final int indexVersionNumber) {
         if (indexVersionNumber < PRIMITIVE_TYPE_ID_INDEX_VERSION) {
             return false;
         }
         return true;
     } 
 
-    public static boolean includeInputParameterFlag(final int indexVersionNumber) {
+    public boolean includeInputParameterFlag(final int indexVersionNumber) {
         if (indexVersionNumber < COLUMN_INPUT_PARAMETER_FLAG_INDEX_VERSION) {
             return false;
         }
         return true;
     }
 
-    public static boolean includeAnnotationProperties(final int indexVersionNumber) {
+    public boolean includeAnnotationProperties(final int indexVersionNumber) {
         if (indexVersionNumber < ANNOTATION_TAGS_INDEX_VERSION) {
             return true;
         }
         return false;
     }
 
-    public static boolean includeTransformationUUID(final int indexVersionNumber) {
+    public boolean includeTransformationUUID(final int indexVersionNumber) {
         if (indexVersionNumber < TRANSFORMATION_UUID_INDEX_VERSION) {
             return false;
         }
@@ -1008,10 +957,6 @@
         return (indexVersionNumber >= PROCEDURE_UPDATE_COUNT_VERSION);
     }
 
-    public static int getCurrentIndexVersionNumber() {
-        return CURRENT_INDEX_VERSION;
-    }
-
     // ==================================================================================
     //                         P R I V A T E   M E T H O D S
     // ==================================================================================
@@ -1023,7 +968,7 @@
      * The order of the fields in the index file header must also 
      * be the order of the arguments in method signature.
      */
-    private static void setRecordHeaderValues(final AbstractMetadataRecord record, final String recordType, 
+    private void setRecordHeaderValues(final AbstractMetadataRecord record, final String recordType, 
                                               final String upperName, final String objectID, String fullName, 
                                               final String nameInSource, 
                                               final String parentObjectID) {
@@ -1054,7 +999,7 @@
      * The order of the fields in the index file header must also 
      * be the order of the arguments in method signature.
      */
-    private static void setRecordFooterValues(final AbstractMetadataRecord record, final List tokens, int tokenIndex) {
+    private void setRecordFooterValues(final AbstractMetadataRecord record, final List tokens, int tokenIndex) {
     	if (record instanceof TransformationRecordImpl) {
     		((TransformationRecordImpl)record).setResourcePath(getOptionalToken(tokens, tokenIndex));
     	}
@@ -1066,7 +1011,7 @@
         getOptionalToken(tokens, tokenIndex++);
     }
 
-    public static String getOptionalToken( final List tokens, int tokenIndex) {
+    public String getOptionalToken( final List tokens, int tokenIndex) {
         if(tokens.size() > tokenIndex) {
             return (String) tokens.get(tokenIndex);     
         }

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/RuntimeMetadataPlugin.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/RuntimeMetadataPlugin.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/RuntimeMetadataPlugin.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,8 +24,9 @@
 
 import java.util.ResourceBundle;
 
-import com.metamatrix.core.BundleUtil;
+import org.teiid.core.BundleUtil;
 
+
 /**
  * CommonPlugin
  * <p>Used here in <code>metadata.runtime</code> to have access to the new

Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/SimpleIndexUtil.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/SimpleIndexUtil.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/SimpleIndexUtil.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,11 +26,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.teiid.core.TeiidException;
 import org.teiid.core.index.IEntryResult;
+import org.teiid.core.util.ArgCheck;
 import org.teiid.internal.core.index.Index;
 
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.util.ArgCheck;
 
 /**
  * IndexUtil
@@ -60,7 +60,7 @@
      * @return results
      * @throws MetamatrixCoreException
      */
-    public static IEntryResult[] queryIndex(final Index[] indexes, final char[] pattern, final boolean isPrefix, final boolean isCaseSensitive, final boolean returnFirstMatch) throws MetaMatrixCoreException {
+    public static IEntryResult[] queryIndex(final Index[] indexes, final char[] pattern, final boolean isPrefix, final boolean isCaseSensitive, final boolean returnFirstMatch) throws TeiidException {
         final List<IEntryResult> queryResult = new ArrayList<IEntryResult>();
         
         try {
@@ -104,7 +104,7 @@
                 }                
             }
         } catch(IOException e) {
-            throw new MetaMatrixCoreException(e);
+            throw new TeiidException(e);
         }
 
         return queryResult.toArray(new IEntryResult[queryResult.size()]);

Modified: trunk/metadata/src/test/java/com/metamatrix/cdk/api/TranslationUtility.java
===================================================================
--- trunk/metadata/src/test/java/com/metamatrix/cdk/api/TranslationUtility.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/test/java/com/metamatrix/cdk/api/TranslationUtility.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,19 +26,19 @@
 import java.net.URL;
 import java.util.Collection;
 
+import org.teiid.cdk.CommandBuilder;
 import org.teiid.connector.language.Command;
 import org.teiid.connector.metadata.runtime.RuntimeMetadata;
 import org.teiid.dqp.internal.datamgr.metadata.RuntimeMetadataImpl;
 import org.teiid.metadata.index.VDBMetadataFactory;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.metadata.BasicQueryMetadataWrapper;
+import org.teiid.query.metadata.QueryMetadataInterface;
 
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.query.function.FunctionLibrary;
-import com.metamatrix.query.function.FunctionTree;
-import com.metamatrix.query.function.SystemFunctionManager;
-import com.metamatrix.query.function.UDFSource;
-import com.metamatrix.query.function.metadata.FunctionMethod;
-import com.metamatrix.query.metadata.BasicQueryMetadataWrapper;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
 
 /**
  * <p>This translation utility can be used to translate sql strings into 

Modified: trunk/metadata/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java
===================================================================
--- trunk/metadata/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/test/java/com/metamatrix/cdk/unittest/FakeTranslationFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,8 +22,9 @@
 
 package com.metamatrix.cdk.unittest;
 
+import org.teiid.query.unittest.FakeMetadataFactory;
+
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 public class FakeTranslationFactory {
 	

Modified: trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
===================================================================
--- trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,16 +32,16 @@
 import java.util.Collection;
 
 import org.teiid.connector.metadata.runtime.MetadataStore;
+import org.teiid.core.CoreConstants;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.FileUtils;
+import org.teiid.core.util.LRUCache;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.metadata.CompositeMetadataStore;
 import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.function.metadata.FunctionMetadataReader;
+import org.teiid.query.function.metadata.FunctionMethod;
 
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.FileUtils;
-import com.metamatrix.core.util.LRUCache;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.function.metadata.FunctionMetadataReader;
-import com.metamatrix.query.function.metadata.FunctionMethod;
 
 @SuppressWarnings("nls")
 public class VDBMetadataFactory {
@@ -52,7 +52,7 @@
 		try {
 			return getVDBMetadata(new File(vdbFile).toURI().toURL(), null);
 		} catch (IOException e) {
-			throw new MetaMatrixRuntimeException(e);
+			throw new TeiidRuntimeException(e);
 		}
     }
 	
@@ -61,7 +61,7 @@
 			IndexMetadataFactory imf = loadMetadata(Thread.currentThread().getContextClassLoader().getResource(CoreConstants.SYSTEM_VDB));
 			return imf.getMetadataStore();
 		} catch (Exception e) {
-			throw new MetaMatrixRuntimeException("System VDB not found");
+			throw new TeiidRuntimeException("System VDB not found");
 		}
     }
 	

Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -33,10 +33,10 @@
 import org.teiid.metadata.CompositeMetadataStore;
 import org.teiid.metadata.TransformationMetadata;
 import org.teiid.metadata.TransformationMetadata.Resource;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.vdb.runtime.VDBKey;
 
-import com.metamatrix.query.function.metadata.FunctionMethod;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.vdb.runtime.VDBKey;
 
 
 public class CompositeVDB {

Modified: trunk/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,10 +29,10 @@
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.core.CoreConstants;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 
-import com.metamatrix.core.CoreConstants;
 
 public class DynamicVDBDeployer extends AbstractVFSParsingDeployer<VDBMetaData> {
 	

Modified: trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,8 +23,9 @@
 
 import java.util.ArrayList;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import org.teiid.core.TeiidRuntimeException;
 
+
 /**
  * This is used with ra.xml properties file to extend the metadata on the properties.
  */
@@ -55,7 +56,7 @@
 		}
 		
 		if (!encodedData.endsWith("}")) { //$NON-NLS-1$
-			throw new MetaMatrixRuntimeException("The description field = "+encodedData+" does not end with \"}\""); //$NON-NLS-1$ //$NON-NLS-2$
+			throw new TeiidRuntimeException("The description field = "+encodedData+" does not end with \"}\""); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 		encodedData = encodedData.substring(1, encodedData.length()-1);
 		

Modified: trunk/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,11 +30,11 @@
 
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
+import org.teiid.core.util.FileUtils;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.core.util.FileUtils;
 
 public class ObjectSerializer {
 	

Modified: trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,12 +25,12 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 
+import org.teiid.core.CoreConstants;
+import org.teiid.core.TeiidRuntimeException;
 import org.teiid.metadata.index.IndexMetadataFactory;
 import org.teiid.metadata.index.RuntimeMetadataPlugin;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 public class SystemVDBDeployer {
 	private VDBRepository vdbRepository;
@@ -40,13 +40,13 @@
 		try {
 			URL url = Thread.currentThread().getContextClassLoader().getResource(CoreConstants.SYSTEM_VDB);
 			if (url == null) {
-				throw new MetaMatrixRuntimeException(RuntimeMetadataPlugin.Util.getString("system_vdb_not_found")); //$NON-NLS-1$
+				throw new TeiidRuntimeException(RuntimeMetadataPlugin.Util.getString("system_vdb_not_found")); //$NON-NLS-1$
 			}
 			this.vdbRepository.setSystemStore(new IndexMetadataFactory(url).getMetadataStore());
 		} catch (URISyntaxException e) {
-			throw new MetaMatrixRuntimeException(e, RuntimePlugin.Util.getString("failed_to_deployed", CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, RuntimePlugin.Util.getString("failed_to_deployed", CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
 		} catch (IOException e) {
-			throw new MetaMatrixRuntimeException(e, RuntimePlugin.Util.getString("failed_to_deployed", CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
+			throw new TeiidRuntimeException(e, RuntimePlugin.Util.getString("failed_to_deployed", CoreConstants.SYSTEM_VDB)); //$NON-NLS-1$
 		}
 	}
 

Modified: trunk/runtime/src/main/java/org/teiid/deployers/TranslatorDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/TranslatorDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/TranslatorDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,6 +32,8 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.teiid.adminapi.impl.TranslatorMetaData;
+import org.teiid.core.TeiidException;
+import org.teiid.core.util.ReflectionHelper;
 import org.teiid.dqp.internal.datamgr.impl.TranslatorRepository;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
@@ -39,8 +41,6 @@
 import org.teiid.resource.cci.TranslatorProperty;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.util.ReflectionHelper;
 
 /**
  * Deployer for the Translator
@@ -104,7 +104,7 @@
 			executionFactory.start();
 			return executionFactory;
 			
-		} catch (MetaMatrixCoreException e) {
+		} catch (TeiidException e) {
 			throw new DeploymentException(e);
 		} catch (ResourceException e) {
 			throw new DeploymentException(e);

Modified: trunk/runtime/src/main/java/org/teiid/deployers/UDFMetaData.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/UDFMetaData.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/UDFMetaData.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,10 +28,10 @@
 
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.virtual.VirtualFile;
+import org.teiid.query.function.metadata.FunctionMetadataReader;
+import org.teiid.query.function.metadata.FunctionMethod;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.query.function.metadata.FunctionMetadataReader;
-import com.metamatrix.query.function.metadata.FunctionMethod;
 
 @ManagementObject
 public class UDFMetaData {

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -36,6 +36,8 @@
 import org.teiid.adminapi.impl.SourceMappingMetadata;
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.connector.metadata.runtime.MetadataStore;
+import org.teiid.core.CoreConstants;
+import org.teiid.core.util.FileUtils;
 import org.teiid.dqp.internal.cache.DQPContextCache;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManager;
 import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
@@ -48,8 +50,6 @@
 import org.teiid.resource.cci.ExecutionFactory;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.util.FileUtils;
 
 public class VDBDeployer extends AbstractSimpleRealDeployer<VDBMetaData> {
 	private VDBRepository vdbRepository;

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -44,15 +44,15 @@
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.core.CoreConstants;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
+import org.teiid.metadata.VdbConstants;
 import org.teiid.metadata.index.IndexConstants;
 import org.teiid.metadata.index.IndexMetadataFactory;
 import org.teiid.runtime.RuntimePlugin;
 import org.xml.sax.SAXException;
 
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.vdb.VdbConstants;
 
 /**
  * This file loads the "vdb.xml" file inside a ".vdb" file, along with all the metadata in the .INDEX files

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -37,11 +37,11 @@
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.connector.metadata.runtime.Datatype;
 import org.teiid.connector.metadata.runtime.MetadataStore;
+import org.teiid.core.types.DataTypeManager;
 import org.teiid.metadata.TransformationMetadata.Resource;
 import org.teiid.runtime.RuntimePlugin;
+import org.teiid.vdb.runtime.VDBKey;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.vdb.runtime.VDBKey;
 
 /**
  * Repository for VDBs

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStructure.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStructure.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStructure.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.teiid.metadata.VdbConstants;
 
-import com.metamatrix.core.vdb.VdbConstants;
 
 
 public class VDBStructure  extends AbstractVFSStructureDeployer{

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VirtualDatabaseException.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VirtualDatabaseException.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VirtualDatabaseException.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,11 +22,11 @@
 
 package org.teiid.deployers;
 
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import org.teiid.core.TeiidProcessingException;
 /**
  * The base exception from which all Runtime Metadata Exceptions extend.
  */
-public class VirtualDatabaseException extends MetaMatrixProcessingException {
+public class VirtualDatabaseException extends TeiidProcessingException {
 
     public static final String NO_MODELS = "1"; //$NON-NLS-1$
     public static final String MODEL_NON_DEPLOYABLE_STATE = "2";  //$NON-NLS-1$

Modified: trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -23,8 +23,9 @@
 
 import java.util.ResourceBundle;
 
-import com.metamatrix.core.BundleUtil;
+import org.teiid.core.BundleUtil;
 
+
 public class RuntimePlugin {
     private static final String PLUGIN_ID = "org.teiid.runtime" ; //$NON-NLS-1$
     private static final String BUNDLE_NAME = PLUGIN_ID + ".i18n"; //$NON-NLS-1$

Modified: trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,18 +30,18 @@
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
+import org.teiid.cache.CacheFactory;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.common.buffer.impl.MemoryStorageManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.FileUtils;
 import org.teiid.dqp.internal.cache.DQPContextCache;
+import org.teiid.dqp.service.BufferService;
 import org.teiid.runtime.RuntimePlugin;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.cache.CacheFactory;
-import com.metamatrix.common.buffer.BufferManager;
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.buffer.impl.FileStorageManager;
-import com.metamatrix.common.buffer.impl.MemoryStorageManager;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.FileUtils;
-import com.metamatrix.dqp.service.BufferService;
 
 /**
  * Implement the BufferService for the DQP Embedded component.  This implementation
@@ -104,10 +104,10 @@
             	this.bufferMgr.setStorageManager(new MemoryStorageManager());
             }
             
-        } catch(MetaMatrixComponentException e) { 
-            throw new MetaMatrixRuntimeException(e, RuntimePlugin.Util.getString("LocalBufferService.Failed_initializing_buffer_manager._8")); //$NON-NLS-1$
+        } catch(TeiidComponentException e) { 
+            throw new TeiidRuntimeException(e, RuntimePlugin.Util.getString("LocalBufferService.Failed_initializing_buffer_manager._8")); //$NON-NLS-1$
         } catch(IOException e) {
-            throw new MetaMatrixRuntimeException(e, RuntimePlugin.Util.getString("LocalBufferService.Failed_initializing_buffer_manager._8")); //$NON-NLS-1$            
+            throw new TeiidRuntimeException(e, RuntimePlugin.Util.getString("LocalBufferService.Failed_initializing_buffer_manager._8")); //$NON-NLS-1$            
         }
     }
    

Modified: trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -44,9 +44,12 @@
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.client.security.InvalidSessionException;
 import org.teiid.client.security.SessionToken;
+import org.teiid.core.util.ArgCheck;
 import org.teiid.deployers.VDBRepository;
 import org.teiid.deployers.VirtualDatabaseException;
 import org.teiid.dqp.internal.process.DQPCore;
+import org.teiid.dqp.service.SessionService;
+import org.teiid.dqp.service.SessionServiceException;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.net.ServerConnection;
@@ -55,9 +58,6 @@
 import org.teiid.security.Credentials;
 import org.teiid.security.SecurityHelper;
 
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.dqp.service.SessionService;
-import com.metamatrix.dqp.service.SessionServiceException;
 
 /**
  * This class serves as the primary implementation of the Session Service.

Modified: trunk/runtime/src/main/java/org/teiid/transport/ClientInstance.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ClientInstance.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ClientInstance.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,11 +24,11 @@
 
 import java.io.Serializable;
 
+import org.teiid.core.crypto.Cryptor;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.net.CommunicationException;
 import org.teiid.net.socket.Message;
 
-import com.metamatrix.common.util.crypto.Cryptor;
 
 /**
  * Represents a ClientConnection from the server's point of view.  This interface

Modified: trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistry.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,9 +22,9 @@
 
 package org.teiid.transport;
 
+import org.teiid.core.ComponentNotFoundException;
 import org.teiid.security.SecurityHelper;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
 
 public interface ClientServiceRegistry {
 	

Modified: trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ClientServiceRegistryImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,11 +24,11 @@
 
 import java.util.HashMap;
 
+import org.teiid.core.ComponentNotFoundException;
+import org.teiid.core.util.ReflectionHelper;
 import org.teiid.runtime.RuntimePlugin;
 import org.teiid.security.SecurityHelper;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.core.util.ReflectionHelper;
 
 public class ClientServiceRegistryImpl implements ClientServiceRegistry {
 

Modified: trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -38,14 +38,14 @@
 import org.teiid.client.security.LogonException;
 import org.teiid.client.security.LogonResult;
 import org.teiid.client.util.ExceptionUtil;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidRuntimeException;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.net.CommunicationException;
 import org.teiid.net.ConnectionException;
 import org.teiid.net.NetPlugin;
 import org.teiid.net.ServerConnection;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 public class LocalServerConnection implements ServerConnection {
 	private static final String TEIID_RUNTIME = "teiid/engine-deployer"; //$NON-NLS-1$
@@ -66,7 +66,7 @@
 			InitialContext ic = new InitialContext();
 			return (ClientServiceRegistry)ic.lookup(TEIID_RUNTIME);
 		} catch (NamingException e) {
-			throw new MetaMatrixRuntimeException(e);
+			throw new TeiidRuntimeException(e);
 		}
 	}
 	
@@ -78,7 +78,7 @@
             // Propagate the original message as it contains the message we want
             // to give to the user
             throw new ConnectionException(e, e.getMessage());
-        } catch (MetaMatrixComponentException e) {
+        } catch (TeiidComponentException e) {
         	if (e.getCause() instanceof CommunicationException) {
         		throw (CommunicationException)e.getCause();
         	}
@@ -91,7 +91,7 @@
 
 			public Object invoke(Object arg0, final Method arg1, final Object[] arg2) throws Throwable {
 				if (!isOpen()) {
-					throw ExceptionUtil.convertException(arg1, new MetaMatrixComponentException(NetPlugin.Util.getString("LocalTransportHandler.Transport_shutdown"))); //$NON-NLS-1$
+					throw ExceptionUtil.convertException(arg1, new TeiidComponentException(NetPlugin.Util.getString("LocalTransportHandler.Transport_shutdown"))); //$NON-NLS-1$
 				}
 				try {
 					final T service = csr.getClientService(iface);

Modified: trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/LogonImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -33,17 +33,17 @@
 import org.teiid.client.security.LogonResult;
 import org.teiid.client.security.SessionToken;
 import org.teiid.client.util.ResultsFuture;
+import org.teiid.core.ComponentNotFoundException;
+import org.teiid.core.CoreConstants;
+import org.teiid.core.TeiidComponentException;
 import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.dqp.service.SessionService;
+import org.teiid.dqp.service.SessionServiceException;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.net.TeiidURL;
 import org.teiid.security.Credentials;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.dqp.service.SessionService;
-import com.metamatrix.dqp.service.SessionServiceException;
 
 public class LogonImpl implements ILogon {
 	
@@ -97,7 +97,7 @@
 		return ResultsFuture.NULL_FUTURE;
 	}
 
-	public ResultsFuture<?> ping() throws InvalidSessionException,MetaMatrixComponentException {
+	public ResultsFuture<?> ping() throws InvalidSessionException,TeiidComponentException {
 		// ping is double used to alert the aliveness of the client, as well as check the server instance is 
 		// alive by socket server instance, so that they can be cached.
 		String id = DQPWorkContext.getWorkContext().getSessionId();
@@ -109,12 +109,12 @@
 	}
 
 	@Override
-	public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, MetaMatrixComponentException {
+	public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
 		SessionMetadata sessionInfo = null;
 		try {
 			sessionInfo = this.service.validateSession(checkSession.getSessionID());
 		} catch (SessionServiceException e) {
-			throw new MetaMatrixComponentException(e);
+			throw new TeiidComponentException(e);
 		}
 		
 		if (sessionInfo == null) {

Modified: trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ObjectDecoder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -39,15 +39,15 @@
 import org.jboss.netty.handler.codec.serialization.CompatibleObjectDecoder;
 import org.jboss.netty.handler.codec.serialization.CompatibleObjectEncoder;
 import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
+import org.teiid.common.buffer.FileStore;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.core.types.InputStreamFactory;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.types.InputStreamFactory.StreamFactoryReference;
+import org.teiid.core.util.ExternalizeUtil;
 import org.teiid.netty.handler.codec.serialization.CompactObjectInputStream;
 import org.teiid.netty.handler.codec.serialization.ObjectEncoderOutputStream;
 
-import com.metamatrix.common.buffer.FileStore;
-import com.metamatrix.common.buffer.StorageManager;
-import com.metamatrix.common.types.InputStreamFactory;
-import com.metamatrix.common.types.Streamable;
-import com.metamatrix.common.types.InputStreamFactory.StreamFactoryReference;
-import com.metamatrix.core.util.ExternalizeUtil;
 
 /**
  * A decoder which deserializes the received {@link ChannelBuffer}s into Java

Modified: trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ObjectEncoder.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -40,10 +40,10 @@
 import org.jboss.netty.channel.MessageEvent;
 import org.jboss.netty.handler.stream.ChunkedInput;
 import org.jboss.netty.handler.stream.ChunkedStream;
+import org.teiid.core.util.ExternalizeUtil;
 import org.teiid.netty.handler.codec.serialization.CompactObjectOutputStream;
 import org.teiid.netty.handler.codec.serialization.ObjectDecoderInputStream;
 
-import com.metamatrix.core.util.ExternalizeUtil;
 
 /**
  * An encoder which serializes a Java object into a {@link ChannelBuffer}.

Modified: trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -51,12 +51,12 @@
 import org.jboss.netty.channel.SimpleChannelHandler;
 import org.jboss.netty.handler.ssl.SslHandler;
 import org.jboss.netty.handler.stream.ChunkedWriteHandler;
+import org.teiid.common.buffer.StorageManager;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.net.NetPlugin;
 import org.teiid.net.socket.ObjectChannel;
 
-import com.metamatrix.common.buffer.StorageManager;
 
 /**
  * Main class for creating Netty Nio Channels 

Modified: trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/SSLConfiguration.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,9 +30,9 @@
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 
+import org.teiid.core.util.Assertion;
 import org.teiid.net.socket.SocketUtil;
 
-import com.metamatrix.core.util.Assertion;
 
 
 public class SSLConfiguration {

Modified: trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/ServerWorkItem.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -33,7 +33,11 @@
 import javax.crypto.SealedObject;
 
 import org.teiid.adminapi.AdminProcessingException;
+import org.teiid.client.util.ExceptionHolder;
 import org.teiid.client.util.ResultsFuture;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.crypto.CryptoException;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.net.socket.Message;
@@ -41,10 +45,6 @@
 import org.teiid.runtime.RuntimePlugin;
 import org.teiid.transport.ClientServiceRegistryImpl.ClientService;
 
-import com.metamatrix.api.exception.ExceptionHolder;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 public class ServerWorkItem implements Runnable {
 	
@@ -121,7 +121,7 @@
 			try {
 				result.setContents(socketClientInstance.getCryptor().sealObject(result.getContents()));
 			} catch (CryptoException e) {
-				throw new MetaMatrixRuntimeException(e);
+				throw new TeiidRuntimeException(e);
 			}
 		}
 		socketClientInstance.send(result, messageKey);
@@ -134,7 +134,7 @@
 		// Case 5558: Differentiate between system level errors and
 		// processing errors. Only log system level errors as errors,
 		// log the processing errors as warnings only
-		if (e instanceof MetaMatrixProcessingException) {
+		if (e instanceof TeiidProcessingException) {
         	logProcessingException(e, context);
 		} else if (e instanceof AdminProcessingException) {
 			logProcessingException(e, context);

Modified: trunk/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,6 +27,10 @@
 import java.net.SocketAddress;
 
 import org.teiid.client.security.ILogon;
+import org.teiid.core.crypto.CryptoException;
+import org.teiid.core.crypto.Cryptor;
+import org.teiid.core.crypto.DhKeyGenerator;
+import org.teiid.core.crypto.NullCryptor;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
@@ -37,10 +41,6 @@
 import org.teiid.net.socket.Message;
 import org.teiid.net.socket.ObjectChannel;
 
-import com.metamatrix.common.util.crypto.CryptoException;
-import com.metamatrix.common.util.crypto.Cryptor;
-import com.metamatrix.common.util.crypto.DhKeyGenerator;
-import com.metamatrix.common.util.crypto.NullCryptor;
 
 /**
  * Sockets implementation of the communication framework class representing the server's view of a client connection.

Modified: trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
+import org.teiid.core.TeiidRuntimeException;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
 
 @ManagementObject(componentType=@ManagementComponent(type="teiid",subtype="dqp"), properties=ManagementProperties.EXPLICIT)
 public class SocketConfiguration {
@@ -82,7 +82,7 @@
 				this.hostName = InetAddress.getLocalHost().getHostName();
 			}
 		} catch (UnknownHostException e) {
-			throw new MetaMatrixRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
+			throw new TeiidRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
 		}
 	}
 
@@ -128,7 +128,7 @@
 			}
 			return addr;
 		} catch (UnknownHostException e) {
-			throw new MetaMatrixRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
+			throw new TeiidRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
 		}		
 	}
 	

Modified: trunk/runtime/src/main/java/org/teiid/transport/SocketListener.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SocketListener.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/main/java/org/teiid/transport/SocketListener.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,6 +30,9 @@
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelFactory;
 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.teiid.common.buffer.StorageManager;
+import org.teiid.core.util.ApplicationInfo;
+import org.teiid.core.util.NamedThreadFactory;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.logging.MessageLevel;
@@ -37,9 +40,6 @@
 import org.teiid.runtime.RuntimePlugin;
 import org.teiid.transport.ChannelListener.ChannelListenerFactory;
 
-import com.metamatrix.common.buffer.StorageManager;
-import com.metamatrix.common.util.ApplicationInfo;
-import com.metamatrix.core.util.NamedThreadFactory;
 
 /**
  * Server-side class to listen for new connection requests and create a SocketClientConnection for each connection request.

Modified: trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java
===================================================================
--- trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -22,13 +22,13 @@
 
 package com.metamatrix.dqp.service.buffer;
 
+import org.teiid.common.buffer.impl.BufferManagerImpl;
+import org.teiid.common.buffer.impl.FileStorageManager;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.services.BufferServiceImpl;
 
 import junit.framework.TestCase;
 
-import com.metamatrix.common.buffer.impl.BufferManagerImpl;
-import com.metamatrix.common.buffer.impl.FileStorageManager;
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestLocalBufferService extends TestCase {
 

Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestObjectSerializer.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestObjectSerializer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestObjectSerializer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,8 +27,8 @@
 import java.io.File;
 
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestObjectSerializer {

Modified: trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestCommSockets.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -38,6 +38,11 @@
 import org.teiid.client.security.ILogon;
 import org.teiid.client.security.LogonException;
 import org.teiid.client.security.LogonResult;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.ComponentNotFoundException;
+import org.teiid.core.crypto.NullCryptor;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.dqp.service.SessionService;
 import org.teiid.net.CommunicationException;
 import org.teiid.net.ConnectionException;
 import org.teiid.net.TeiidURL;
@@ -47,11 +52,6 @@
 import org.teiid.net.socket.UrlServerDiscovery;
 import org.teiid.transport.TestSocketRemoting.FakeService;
 
-import com.metamatrix.api.exception.ComponentNotFoundException;
-import com.metamatrix.common.buffer.BufferManagerFactory;
-import com.metamatrix.common.util.crypto.NullCryptor;
-import com.metamatrix.core.util.ObjectConverterUtil;
-import com.metamatrix.dqp.service.SessionService;
 
 @SuppressWarnings("nls")
 public class TestCommSockets {

Modified: trunk/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestLogonImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,9 +32,9 @@
 import org.teiid.client.security.LogonResult;
 import org.teiid.client.security.SessionToken;
 import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.dqp.service.SessionService;
 import org.teiid.net.TeiidURL;
 
-import com.metamatrix.dqp.service.SessionService;
 
 public class TestLogonImpl extends TestCase {
 

Modified: trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/runtime/src/test/java/org/teiid/transport/TestSocketRemoting.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -43,6 +43,11 @@
 import org.teiid.client.security.SessionToken;
 import org.teiid.client.util.ResultsFuture;
 import org.teiid.client.util.ResultsReceiver;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.crypto.Cryptor;
+import org.teiid.core.crypto.NullCryptor;
+import org.teiid.core.util.ObjectConverterUtil;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.net.CommunicationException;
 import org.teiid.net.ConnectionException;
@@ -55,11 +60,6 @@
 import org.teiid.net.socket.SocketServerInstanceImpl;
 import org.teiid.net.socket.UrlServerDiscovery;
 
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.common.util.crypto.Cryptor;
-import com.metamatrix.common.util.crypto.NullCryptor;
-import com.metamatrix.core.util.ObjectConverterUtil;
 
 public class TestSocketRemoting {
 	
@@ -67,7 +67,7 @@
 		
 		ResultsFuture<Integer> asynchResult();
 		
-		String exceptionMethod() throws MetaMatrixProcessingException;
+		String exceptionMethod() throws TeiidProcessingException;
 		
 		int lobMethod(InputStream is, Reader r) throws IOException;
 		
@@ -83,8 +83,8 @@
 			return result;
 		}
 
-		public String exceptionMethod() throws MetaMatrixProcessingException {
-			throw new MetaMatrixProcessingException();
+		public String exceptionMethod() throws TeiidProcessingException {
+			throw new TeiidProcessingException();
 		}
 		
 		@Override
@@ -166,25 +166,25 @@
 				public ResultsFuture<?> logoff()
 						throws InvalidSessionException {
 					ResultsFuture<?> result = new ResultsFuture<Void>();
-					result.getResultsReceiver().exceptionOccurred(new MetaMatrixComponentException("some exception")); //$NON-NLS-1$
+					result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception")); //$NON-NLS-1$
 					return result;
 				}
 
 				public LogonResult logon(Properties connectionProperties)
-						throws LogonException, MetaMatrixComponentException {
+						throws LogonException, TeiidComponentException {
 					return new LogonResult();
 				}
 
 				// tests asynch where we don't care about the result
 				public ResultsFuture<?> ping() throws InvalidSessionException,
-						MetaMatrixComponentException {
+						TeiidComponentException {
 					return null;
 				}
 				
 				@Override
 				public void assertIdentity(SessionToken sessionId)
 					throws InvalidSessionException,
-					MetaMatrixComponentException {
+					TeiidComponentException {
 				}
 
 			}, "foo"); //$NON-NLS-1$
@@ -199,7 +199,7 @@
 			result.get(0, TimeUnit.MICROSECONDS);
 			fail("exception expected"); //$NON-NLS-1$
 		} catch (ExecutionException e) {
-			assertTrue(e.getCause() instanceof MetaMatrixComponentException);
+			assertTrue(e.getCause() instanceof TeiidComponentException);
 		}
 		FakeService service = connection.getService(FakeService.class);
 		Future<Integer> asynchInteger = service.asynchResult();
@@ -207,7 +207,7 @@
 		try {
 			service.exceptionMethod();
 			fail("exception expected"); //$NON-NLS-1$
-		} catch (MetaMatrixProcessingException e) {
+		} catch (TeiidProcessingException e) {
 			
 		}
 		DQP dqp = connection.getService(DQP.class);

Modified: trunk/test-integration/common/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java
===================================================================
--- trunk/test-integration/common/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/com/metamatrix/cdk/api/TestTranslationUtility.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 import org.teiid.connector.language.NamedTable;
 import org.teiid.connector.language.Select;
 import org.teiid.connector.metadata.runtime.AbstractMetadataRecord;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 public class TestTranslationUtility extends TestCase {
 

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestElement.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestElement.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestElement.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,9 +32,9 @@
 import org.teiid.connector.language.Select;
 import org.teiid.connector.metadata.runtime.BaseColumn.NullType;
 import org.teiid.connector.metadata.runtime.Column.SearchType;
+import org.teiid.core.util.UnitTestUtil;
 
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestGroup.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestGroup.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestGroup.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,9 +29,9 @@
 
 import org.teiid.connector.language.NamedTable;
 import org.teiid.connector.language.Select;
+import org.teiid.core.util.UnitTestUtil;
 
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestMetadataObject.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestMetadataObject.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestMetadataObject.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,9 +31,9 @@
 import org.teiid.connector.language.DerivedColumn;
 import org.teiid.connector.language.NamedTable;
 import org.teiid.connector.language.Select;
+import org.teiid.core.util.UnitTestUtil;
 
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestParams.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestParams.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestParams.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,9 +31,9 @@
 import org.teiid.connector.language.Call;
 import org.teiid.connector.language.Argument.Direction;
 import org.teiid.connector.metadata.runtime.BaseColumn.NullType;
+import org.teiid.core.util.UnitTestUtil;
 
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
 
 
 /** 

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestProcedure.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestProcedure.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/metadata/runtime/TestProcedure.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,9 +28,9 @@
 import junit.framework.TestCase;
 
 import org.teiid.connector.language.Call;
+import org.teiid.core.util.UnitTestUtil;
 
 import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -68,10 +68,10 @@
 import org.teiid.dqp.internal.datamgr.language.TestSubqueryInCriteriaImpl;
 import org.teiid.dqp.internal.datamgr.language.TestUpdateImpl;
 import org.teiid.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.JoinType;
 
 import com.metamatrix.cdk.unittest.FakeTranslationFactory;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.JoinType;
 
 public class TestSQLStringVisitor  {
 

Modified: trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,20 +25,20 @@
 
 import junit.framework.TestCase;
 
+import org.teiid.dqp.message.RequestID;
 import org.teiid.metadata.TransformationMetadata;
 import org.teiid.metadata.index.VDBMetadataFactory;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.TestProcessor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.CommandContext;
 
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.QueryOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
-import com.metamatrix.query.processor.ProcessorDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.processor.TestProcessor;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.util.CommandContext;
 
 
 /** 

Modified: trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestTPCR.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,18 +25,18 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.dqp.internal.datamgr.impl.CapabilitiesConverter;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.unittest.TimestampUtil;
 import org.teiid.translator.jdbc.oracle.OracleCapabilities;
 import org.teiid.translator.jdbc.sqlserver.SQLServerCapabilities;
 
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.TestOptimizer;
-import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.processor.HardcodedDataManager;
-import com.metamatrix.query.processor.ProcessorPlan;
-import com.metamatrix.query.unittest.TimestampUtil;
 
 
 public class TestTPCR extends BaseQueryTest {

Modified: trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,18 +31,18 @@
 
 import org.mockito.Mockito;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.dqp.message.RequestID;
 import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.unittest.TimestampUtil;
 import org.teiid.resource.cci.SourceSystemFunctions;
 
-import com.metamatrix.core.util.ObjectConverterUtil;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.dqp.message.RequestID;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities.Capability;
-import com.metamatrix.query.processor.HardcodedDataManager;
-import com.metamatrix.query.unittest.TimestampUtil;
 
 public class TestXMLTypeTranslations extends BaseQueryTest {
 

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/AbstractMMQueryTestCase.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/AbstractMMQueryTestCase.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/AbstractMMQueryTestCase.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -31,9 +31,9 @@
 import java.sql.SQLException;
 import java.util.Stack;
 
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.TeiidDriver;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 
 /** 

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,6 +32,7 @@
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.client.DQP;
 import org.teiid.client.security.ILogon;
+import org.teiid.common.queue.FakeWorkManager;
 import org.teiid.connector.metadata.runtime.MetadataStore;
 import org.teiid.connector.metadata.runtime.Schema;
 import org.teiid.deployers.MetadataStoreGroup;
@@ -41,8 +42,11 @@
 import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
 import org.teiid.dqp.internal.process.DQPConfiguration;
 import org.teiid.dqp.internal.process.DQPCore;
+import org.teiid.dqp.service.FakeBufferService;
 import org.teiid.metadata.index.IndexMetadataFactory;
 import org.teiid.metadata.index.VDBMetadataFactory;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
 import org.teiid.resource.ConnectorException;
 import org.teiid.services.SessionServiceImpl;
 import org.teiid.transport.ClientServiceRegistry;
@@ -50,10 +54,6 @@
 import org.teiid.transport.LocalServerConnection;
 import org.teiid.transport.LogonImpl;
 
-import com.metamatrix.common.queue.FakeWorkManager;
-import com.metamatrix.dqp.service.FakeBufferService;
-import com.metamatrix.query.optimizer.capabilities.BasicSourceCapabilities;
-import com.metamatrix.query.optimizer.capabilities.SourceCapabilities;
 
 public class FakeServer extends ClientServiceRegistryImpl {
 

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,8 +28,8 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -46,11 +46,11 @@
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.teiid.core.CoreConstants;
+import org.teiid.core.util.ApplicationInfo;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.util.ResultSetUtil;
 
-import com.metamatrix.common.util.ApplicationInfo;
-import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  */

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestQueryPlans.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestQueryPlans.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestQueryPlans.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,8 +30,8 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestQueryPlans {

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestResultsCache.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -30,8 +30,8 @@
 
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestResultsCache {

Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -1,8 +1,8 @@
 package org.teiid.jdbc;
 
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestVDBMerge extends AbstractMMQueryTestCase {

Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestPartsDatabaseMetadata.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestPartsDatabaseMetadata.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestPartsDatabaseMetadata.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,10 +29,10 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.FakeServer;
 import org.teiid.jdbc.TestMMDatabaseMetaData;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * Test the DatabaseMetadata results using the Parts VDB.

Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestResultSetMetadata.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestResultSetMetadata.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestResultSetMetadata.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -27,10 +27,10 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.AbstractMMQueryTestCase;
 import org.teiid.jdbc.FakeServer;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestResultSetMetadata extends AbstractMMQueryTestCase {

Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,10 +25,10 @@
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.AbstractMMQueryTestCase;
 import org.teiid.jdbc.FakeServer;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * Exercises each virtual table in the system model.

Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -25,10 +25,10 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.AbstractMMQueryTestCase;
 import org.teiid.jdbc.FakeServer;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * Tests xml virtual documents which are built on top of virtual

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ClassFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,10 +24,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.teiid.core.util.ReflectionHelper;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.core.util.ReflectionHelper;
 
 /**
  * @author vanhalbert

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/QueryScenario.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,14 +29,14 @@
 import java.util.List;
 import java.util.Properties;
 
+import org.teiid.core.util.FileUtils;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.test.client.TestProperties.RESULT_MODES;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.util.FileUtils;
 
 
 /**

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/TestClient.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -28,6 +28,9 @@
 import java.util.Properties;
 
 import org.junit.Assert;
+import org.teiid.core.util.FileUtils;
+import org.teiid.core.util.PropertiesUtils;
+import org.teiid.core.util.StringUtil;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.ConfigPropertyNames;
 import org.teiid.test.framework.TestLogger;
@@ -37,9 +40,6 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.util.FileUtils;
-import com.metamatrix.core.util.StringUtil;
 
 
 /**

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/ListNestedSortComparator.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/ListNestedSortComparator.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/ListNestedSortComparator.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -24,10 +24,11 @@
 
 import java.util.List;
 
-import com.metamatrix.core.util.ArgCheck;
+import org.teiid.core.util.ArgCheck;
 
 
 
+
 /**
  * This class can be used for comparing lists of elements, when the fields to
  * be sorted on and the comparison mechanism are dynamically specified. <p>

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/QueryResults.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,14 +32,15 @@
 import java.util.List;
 import java.util.Map;
 
-import com.metamatrix.common.buffer.TupleBatch;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
 
 
+
 /**
  * This class encapsulates results associated with a query.
  * <p>

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLExpectedResults.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -41,6 +41,7 @@
 import java.util.Properties;
 
 import org.jdom.JDOMException;
+import org.teiid.core.util.StringUtil;
 import org.teiid.test.client.ClassFactory;
 import org.teiid.test.client.ExpectedResults;
 import org.teiid.test.client.QueryScenario;
@@ -53,7 +54,6 @@
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 
-import com.metamatrix.core.util.StringUtil;
 
 
 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLGenerateResults.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -42,14 +42,14 @@
 import org.jdom.JDOMException;
 import org.jdom.output.XMLOutputter;
 import org.junit.Assert;
+import org.teiid.core.util.FileUtils;
+import org.teiid.core.util.StringUtil;
+import org.teiid.internal.core.xml.JdomHelper;
 import org.teiid.test.client.ResultsGenerator;
 import org.teiid.test.client.TestProperties;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.util.TestResultSetUtil;
 
-import com.metamatrix.core.util.FileUtils;
-import com.metamatrix.core.util.StringUtil;
-import com.metamatrix.internal.core.xml.JdomHelper;
 
 public class XMLGenerateResults implements ResultsGenerator {
     private static final SimpleDateFormat FILE_NAME_DATE_FORMATER = new SimpleDateFormat(

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryReader.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -32,6 +32,8 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.core.util.FileUtils;
+import org.teiid.core.util.StringUtil;
 import org.teiid.test.client.QueryTest;
 import org.teiid.test.client.QueryReader;
 import org.teiid.test.framework.ConfigPropertyLoader;
@@ -40,8 +42,6 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.core.util.FileUtils;
-import com.metamatrix.core.util.StringUtil;
 
 public class XMLQueryReader implements QueryReader {
  

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/ctc/XMLQueryVisitationStrategy.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -42,6 +42,10 @@
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.internal.core.xml.SAXBuilderHelper;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.symbol.ElementSymbol;
 import org.teiid.test.client.QuerySQL;
 import org.teiid.test.client.QueryTest;
 import org.teiid.test.client.ctc.QueryResults.ColumnInfo;
@@ -49,10 +53,6 @@
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 import org.teiid.test.util.StringUtil;
 
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.internal.core.xml.SAXBuilderHelper;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
 
 
 /**

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ExpectedResultsImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -29,13 +29,13 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.core.util.SqlUtil;
 import org.teiid.test.client.ExpectedResults;
 import org.teiid.test.client.ctc.ResultsHolder;
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.util.TestResultSetUtil;
 
-import com.metamatrix.common.util.SqlUtil;
 
 public class ExpectedResultsImpl implements ExpectedResults {
 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/client/impl/ResultsGeneratorImpl.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -34,12 +34,12 @@
 import java.util.Properties;
 
 import org.junit.Assert;
+import org.teiid.core.util.FileUtils;
 import org.teiid.test.client.ResultsGenerator;
 import org.teiid.test.client.TestProperties;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.util.TestResultSetUtil;
 
-import com.metamatrix.core.util.FileUtils;
 
 public class ResultsGeneratorImpl implements ResultsGenerator {
     private static final SimpleDateFormat FILE_NAME_DATE_FORMATER = new SimpleDateFormat(

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -4,11 +4,11 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.test.framework.datasource.DataSourceFactory;
 import org.teiid.test.framework.datasource.DataStore;
 import org.teiid.test.util.PropUtils;
 
-import com.metamatrix.common.util.PropertiesUtils;
 
 
 /**

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -4,9 +4,9 @@
  */
 package org.teiid.test.framework;
 
+import org.teiid.core.util.StringUtil;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.core.util.StringUtil;
 
 public abstract class TransactionContainer {
 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -20,6 +20,7 @@
 import org.teiid.adminapi.AdminFactory;
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.VDB;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.jdbc.ConnectionImpl;
 import org.teiid.jdbc.JDBCURL;
 import org.teiid.test.framework.ConfigPropertyLoader;
@@ -31,7 +32,6 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
 
 public abstract class ConnectionStrategy {
 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -12,6 +12,7 @@
 import javax.sql.XAConnection;
 import javax.sql.XADataSource;
 
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.jdbc.BaseDataSource;
 import org.teiid.jdbc.TeiidDataSource;
 import org.teiid.test.framework.TestLogger;
@@ -19,7 +20,6 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
 
 public class DataSourceConnection extends ConnectionStrategy {
 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -9,14 +9,14 @@
 import java.util.Properties;
 import java.util.Set;
 
+import org.teiid.core.util.PropertiesUtils;
+import org.teiid.core.util.StringUtil;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.ConfigPropertyNames;
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.core.util.StringUtil;
 
 
 /**

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -12,13 +12,13 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.ConfigPropertyNames;
 import org.teiid.test.framework.TestLogger;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
 
 /**
  * The DataSourceMgr is responsible for loading and managing the datasources

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/exception/QueryTestFailedException.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/exception/QueryTestFailedException.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/exception/QueryTestFailedException.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -6,9 +6,10 @@
 import java.io.Serializable;
 import java.util.List;
 
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.MetaMatrixExceptionUtil;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.ExceptionUtil;
 
+
 /**
  */
 
@@ -91,7 +92,7 @@
 
 	    /**
 	     * Construct an instance with a linked exception specified.  If the exception is a MetaMatrixException or a
-	     * {@link MetaMatrixRuntimeException}, then the code will be set to the exception's code.
+	     * {@link TeiidRuntimeException}, then the code will be set to the exception's code.
 	     * @param e An exception to chain to this exception
 	     */
 	    public QueryTestFailedException(final Throwable e) {
@@ -106,7 +107,7 @@
 	    /**
 	     * Construct an instance with the linked exception and error message specified.  If the message is actually a key, the error
 	     * message will be retrieved from a resource bundle the key, and code will be set to that key.  Otherwise, if the specified
-	     * exception is a MetaMatrixException or a {@link MetaMatrixRuntimeException}, the code will be set to the exception's code.
+	     * exception is a MetaMatrixException or a {@link TeiidRuntimeException}, the code will be set to the exception's code.
 	     * @param e       The exception to chain to this exception
 	     * @param message The error message or a resource bundle key
 	     */
@@ -186,7 +187,7 @@
 	     * @see #getFormattedMessage
 	     */
 	    public String getFullMessage() {
-	        return MetaMatrixExceptionUtil.getLinkedMessages(this, 0 );
+	        return ExceptionUtil.getLinkedMessages(this, 0 );
 	    }
 
 	    /* (non-Javadoc)

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/util/PropUtils.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -5,10 +5,10 @@
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.test.framework.ConfigPropertyLoader;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
-import com.metamatrix.common.util.PropertiesUtils;
 
 public class PropUtils {
 	

Modified: trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
--- trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -34,9 +34,9 @@
 import org.teiid.adminapi.Transaction;
 import org.teiid.adminapi.Translator;
 import org.teiid.adminapi.VDB;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.core.util.UnitTestUtil;
 
-import com.metamatrix.core.util.ObjectConverterUtil;
-import com.metamatrix.core.util.UnitTestUtil;
 
 @SuppressWarnings("nls")
 public class TestConnectorBindings extends BaseConnection {

Modified: trunk/test-integration/db/src/test/java/org/teiid/dynamicvdb/TestVDBLessExecution.java
===================================================================
--- trunk/test-integration/db/src/test/java/org/teiid/dynamicvdb/TestVDBLessExecution.java	2010-05-11 22:01:58 UTC (rev 2117)
+++ trunk/test-integration/db/src/test/java/org/teiid/dynamicvdb/TestVDBLessExecution.java	2010-05-11 22:15:35 UTC (rev 2118)
@@ -26,9 +26,9 @@
 import java.sql.DatabaseMetaData;
 
 import org.junit.Test;
+import org.teiid.core.util.UnitTestUtil;
 import org.teiid.jdbc.AbstractMMQueryTestCase;
 
-import com.metamatrix.core.util.UnitTestUtil;
 
 /**
  * Test the DatabaseMetadata results using the Parts VDB.



More information about the teiid-commits mailing list