Search in sources :

Example 6 with FakeCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder in project teiid by teiid.

the class TestPreparedStatementBatchedUpdate method testUpdateVarNumCmds_Virtual.

/**
 * Test prepared statements that use batched updates using the same prepared
 * command with varying number of commands in the batch.  Update is
 * performed against a view model instead of a source model.
 * <p>
 * The test verifies that no errors occur when planning and executing the
 * same batched command SQL with varying number of batched command parameter
 * value sets.  For example, if the first executeBatch() call were to occur
 * with two batched commands a repeated call with only one batched command
 * should not result in an error during planning or execution.
 * <p>
 * The test also verifies that the correct SQL is pushed to the data manager
 * to verify that the parameter substitution occurred and is correct and the
 * correct number of statements made it to the data manager for the respective
 * batch command.
 * <p>
 * The batched command "UPDATE vm1.g1 SET vm1.g1.e1=?, vm1.g1.e3=? WHERE vm1.g1.e2=?"
 * will appear as:
 * <p>
 * UPDATE pm1.g1 SET e1='a', e3=false WHERE pm1.g1.e2=0
 * UPDATE pm1.g1 SET e1='b', e3=true WHERE pm1.g1.e2=1
 * <p>
 * UPDATE pm1.g1 SET e1='c', e3=false WHERE pm1.g1.e2=1
 * <p>
 * UPDATE pm1.g1 SET e1='d', e3=false WHERE pm1.g1.e2=1
 * UPDATE pm1.g1 SET e1='e', e3=false WHERE pm1.g1.e2=0
 * UPDATE pm1.g1 SET e1='f', e3=true WHERE pm1.g1.e2=2
 * UPDATE pm1.g1 SET e1='g', e3=true WHERE pm1.g1.e2=3
 * <p>
 * The result should be that three commands are in the plan cache and
 * no plan creation, validation, or execution errors will occur and
 * a predetermined set of queries were executed in the data manager.
 *
 * @throws Exception
 */
@Test
public void testUpdateVarNumCmds_Virtual() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "UPDATE vm1.g1 SET vm1.g1.e1=?, vm1.g1.e3=? WHERE vm1.g1.e2=?";
    // Create a testable prepared plan cache
    SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    // Source capabilities must support batched updates
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Something to hold our final query list
    List<String> finalQueryList = new ArrayList<String>(13);
    // Create expected results
    List<?>[] expected = new List[] { Arrays.asList(2), Arrays.asList(2) };
    // batch with two commands
    ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "a", Boolean.FALSE, new Integer(0) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "b", Boolean.TRUE, new Integer(1) })));
    // Add our expected queries to the final query list
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'a', e3 = FALSE WHERE pm1.g1.e2 = 0"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'b', e3 = TRUE WHERE pm1.g1.e2 = 1"));
    // Create the plan and process the query
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
    // Repeat with different number of commands in batch
    expected = new List[] { Arrays.asList(new Object[] { new Integer(2) }) };
    // batch with one command
    values = new ArrayList<ArrayList<Object>>(1);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "c", Boolean.FALSE, new Integer(1) })));
    // Add our expected queries to the final query list
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'c', e3 = FALSE WHERE pm1.g1.e2 = 1"));
    // Use the cached plan and process the query
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, true, RealMetadataFactory.example1VDB());
    // Repeat with different number of commands in batch
    expected = new List[] { Arrays.asList(2), Arrays.asList(2), Arrays.asList(1), Arrays.asList(1) };
    // batch with four commands
    values = new ArrayList<ArrayList<Object>>(4);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "d", Boolean.FALSE, new Integer(1) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "e", Boolean.FALSE, new Integer(0) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "f", Boolean.TRUE, new Integer(2) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "g", Boolean.TRUE, new Integer(3) })));
    // Add our expected queries to the final query list
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'd', e3 = FALSE WHERE pm1.g1.e2 = 1"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'e', e3 = FALSE WHERE pm1.g1.e2 = 0"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'f', e3 = TRUE WHERE pm1.g1.e2 = 2"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'g', e3 = TRUE WHERE pm1.g1.e2 = 3"));
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, true, RealMetadataFactory.example1VDB());
    // Verify all the queries that were run
    // $NON-NLS-1$
    assertEquals("Unexpected queries executed -", finalQueryList, dataManager.getQueries());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FakeDataManager(org.teiid.query.processor.FakeDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with FakeCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder in project teiid by teiid.

the class TestPreparedStatementBatchedUpdate method testUpdateSameNumCmds_Virtual.

/**
 * Test prepared statements that use batched updates using the same prepared
 * command with same number of commands in the batch.  Update is performed
 * against a view model instead of a source model.
 * <p>
 * The test verifies that no errors occur when planning and executing the
 * same batched command SQL with the same number of batched command parameter
 * value sets.  For example, if the first executeBatch() call were to occur
 * with two batched commands a repeated call with two batched commands
 * should not result in an error during planning or execution and the value
 * used in the second batched command should be used instead of any values
 * from the first batched command.
 * <p>
 * The test also verifies that the correct SQL is pushed to the data manager
 * to verify that the parameter substitution occurred and is correct and the
 * correct number of statements made it to the data manager for the respective
 * batch command.
 * <p>
 * The batched command "UPDATE vm1.g1 SET vm1.g1.e2=? WHERE vm1.g1.e1=?"
 * will appear as:
 * <p>
 * UPDATE pm1.g1 SET e2=0 WHERE pm1.g1.e1='a'
 * UPDATE pm1.g1 SET e2=1 WHERE pm1.g1.e1='b'
 * <p>
 * UPDATE pm1.g1 SET e2=2 WHERE pm1.g1.e1='c'
 * UPDATE pm1.g1 SET e2=3 WHERE pm1.g1.e1='d'
 * <p>
 * The result should be that one command is in the plan cache and
 * no plan creation, validation, or execution errors will occur and
 * a predetermined set of queries were executed in the data manager.
 *
 * @throws Exception
 */
@Test
public void testUpdateSameNumCmds_Virtual() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "UPDATE vm1.g1 SET vm1.g1.e2=? WHERE vm1.g1.e1=?";
    // Create a testable prepared plan cache
    SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    // Source capabilities must support batched updates
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Something to hold our final query list
    List<String> finalQueryList = new ArrayList<String>();
    // Create expected results
    List<?>[] expected = new List[] { Arrays.asList(3), Arrays.asList(1) };
    // batch with two commands
    ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(0), "a" })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(1), "b" })));
    // Add our expected queries to the final query list
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e2 = 0 WHERE pm1.g1.e1 = 'a'"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e2 = 1 WHERE pm1.g1.e1 = 'b'"));
    // Create the plan and process the query
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
    // Repeat
    expected = new List[] { Arrays.asList(1), Arrays.asList(0) };
    // batch with two commands
    values = new ArrayList<ArrayList<Object>>(1);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(2), "c" })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(3), "d" })));
    // Add our expected queries to the final query list
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e2 = 2 WHERE pm1.g1.e1 = 'c'"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e2 = 3 WHERE pm1.g1.e1 = 'd'"));
    // Use the cached plan and process the query
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, true, RealMetadataFactory.example1VDB());
    // Verify all the queries that were run
    // $NON-NLS-1$
    assertEquals("Unexpected queries executed -", finalQueryList, dataManager.getQueries());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FakeDataManager(org.teiid.query.processor.FakeDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with FakeCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder in project teiid by teiid.

the class TestPreparedStatement method testCopiedWhere.

@Test
public void testCopiedWhere() throws Exception {
    String preparedSql = "SELECT mediuma.bigdecimalvalue as a FROM bqt1.smalla inner join  bqt1.mediuma " + "on (smalla.bigdecimalvalue = mediuma.bigdecimalvalue) " + // $NON-NLS-1$
    "WHERE smalla.bigdecimalvalue in (?,?) and mediuma.bigdecimalvalue in (1,2)";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    List<?> values = Arrays.asList(0, 1);
    PreparedStatementRequest plan = helpGetProcessorPlan(preparedSql, values, capFinder, metadata, new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0), SESSION_ID, false, false, RealMetadataFactory.exampleBQTVDB());
    TestOptimizer.checkNodeTypes(plan.processPlan, TestOptimizer.FULL_PUSHDOWN);
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT g_1.BigDecimalValue FROM BQT1.SmallA AS g_0, BQT1.MediumA AS g_1 WHERE (g_0.BigDecimalValue = g_1.BigDecimalValue) AND (g_0.BigDecimalValue IN (?, ?)) AND (g_0.BigDecimalValue IN (1, 2)) AND (g_1.BigDecimalValue IN (1, 2)) AND (g_1.BigDecimalValue IN (?, ?))" }, plan.processPlan);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 9 with FakeCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder in project teiid by teiid.

the class TestOptimizer method testUnionNoAllPushdownInInlineView.

@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);
    // $NON-NLS-1$
    caps.setFunctionSupport("+", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    ProcessorPlan plan = helpPlan(// $NON-NLS-1$
    "SELECT x FROM (SELECT IntKey+2, StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB) AS g", // $NON-NLS-1$
    RealMetadataFactory.exampleBQTCached(), null, capFinder, // $NON-NLS-1$
    new String[] { "SELECT (IntKey + 2), StringKey AS x FROM BQT1.SmallA UNION SELECT IntKey, StringKey FROM BQT1.SmallB" }, SHOULD_SUCCEED);
    checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    0, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    0, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 10 with FakeCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder in project teiid by teiid.

the class TestOptimizer method testPushFunctionInSelect2.

@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);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Add join capability to pm1
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    ProcessorPlan plan = helpPlan(// $NON-NLS-1$
    "SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE upper(e1) = 'X'", metadata, null, capFinder, // $NON-NLS-1$
    new String[] { "SELECT lower(e1), upper(e1), e2 FROM pm1.g1 WHERE ucase(e1) = 'X'" }, SHOULD_SUCCEED);
    checkNodeTypes(plan, FULL_PUSHDOWN);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)544 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)513 Test (org.junit.Test)497 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)288 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)182 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)91 Command (org.teiid.query.sql.lang.Command)64 List (java.util.List)63 BigInteger (java.math.BigInteger)32 ArrayList (java.util.ArrayList)28 CommandContext (org.teiid.query.util.CommandContext)27 Schema (org.teiid.metadata.Schema)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)13 ColumnSet (org.teiid.metadata.ColumnSet)9 BigDecimal (java.math.BigDecimal)7 LinkedList (java.util.LinkedList)7 Column (org.teiid.metadata.Column)7 FunctionTree (org.teiid.query.function.FunctionTree)7 FakeFunctionMetadataSource (org.teiid.query.optimizer.FakeFunctionMetadataSource)6 FakeDataManager (org.teiid.query.processor.FakeDataManager)6