Search in sources :

Example 1 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestPreparedStatement method testWhere.

@Test
public void testWhere() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1 WHERE e2=?";
    // Create expected results
    List<?>[] expected = new List<?>[] { // $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) }) };
    List<?> values = Arrays.asList((short) 0);
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestPreparedStatement method testUpdateProcedureCriteria.

@Test
public void testUpdateProcedureCriteria() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "delete from vm1.g37 where e1=?";
    List<?>[] expected = new List<?>[] { Arrays.asList(1) };
    // $NON-NLS-1$
    List<String> values = Arrays.asList("aa ");
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData2b(dataManager, RealMetadataFactory.example1Cached());
    helpTestProcessing(preparedSql, values, expected, dataManager, TestOptimizer.getGenericFinder(), RealMetadataFactory.example1Cached(), null, false, false, false, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestPreparedStatement method testSessionSpecificFunction.

@Test
public void testSessionSpecificFunction() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "SELECT session_id(), e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1 WHERE e2=?";
    // Create expected results
    List<?>[] expected = new List<?>[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "6", new Integer(0), Boolean.FALSE, new Double(2.0) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "6", new Integer(0), Boolean.FALSE, new Double(2.0) }) };
    List<?> values = Arrays.asList((short) 0);
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, true, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestPreparedStatement method testLimitValidation.

@Test(expected = QueryValidatorException.class)
public void testLimitValidation() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "select pm1.g1.e1 from pm1.g1 limit ?";
    List<?> values = Arrays.asList(-1);
    FakeDataManager dataManager = new FakeDataManager();
    helpTestProcessing(preparedSql, values, null, dataManager, RealMetadataFactory.example1Cached(), false, false, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) Test(org.junit.Test)

Example 5 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestPreparedStatementBatchedUpdate method testUpdateVarNumCmds.

/**
 * Test prepared statements that use batched updates using the same prepared
 * command with varying number of commands in the batch.
 * <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 pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?"
 * will appear as:
 * <p>
 * UPDATE pm1.g1 SET pm1.g1.e1='a', pm1.g1.e3=false WHERE pm1.g1.e2=0
 * UPDATE pm1.g1 SET pm1.g1.e1=null, pm1.g1.e3=false WHERE pm1.g1.e2=1
 * <p>
 * UPDATE pm1.g1 SET pm1.g1.e1='a', pm1.g1.e3=false WHERE pm1.g1.e2=0
 * <p>
 * UPDATE pm1.g1 SET pm1.g1.e1='a', pm1.g1.e3=false WHERE pm1.g1.e2=0
 * UPDATE pm1.g1 SET pm1.g1.e1=null, pm1.g1.e3=false WHERE pm1.g1.e2=1
 * UPDATE pm1.g1 SET pm1.g1.e1='c', pm1.g1.e3=true WHERE pm1.g1.e2=4
 * UPDATE pm1.g1 SET pm1.g1.e1='b', pm1.g1.e3=true WHERE pm1.g1.e2=5
 * <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() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.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
    // first command should result in 2 rows affected
    // second command should result in 2 rows affected
    List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(2) }), Arrays.asList(new Object[] { new Integer(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) })));
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, 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 = 'a', e3 = FALSE WHERE pm1.g1.e2 = 0"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = null, e3 = FALSE 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
    // Create expected results
    // first command should result in 2 rows affected
    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[] { "a", Boolean.FALSE, new Integer(0) })));
    // 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"));
    // 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
    // Create expected results
    // first command should result in 2 rows affected
    // second command should result in 2 rows affected
    // third command should result in 0 rows affected
    // fourth command should result in 0 rows affected
    expected = new List[] { Arrays.asList(new Object[] { new Integer(2) }), Arrays.asList(new Object[] { new Integer(2) }), Arrays.asList(new Object[] { new Integer(0) }), Arrays.asList(new Object[] { new Integer(0) }) };
    // batch with four commands
    values = new ArrayList<ArrayList<Object>>(4);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "a", Boolean.FALSE, new Integer(0) })));
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, Boolean.FALSE, new Integer(1) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "c", Boolean.TRUE, new Integer(4) })));
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "b", Boolean.TRUE, new Integer(5) })));
    // 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 = null, e3 = FALSE WHERE pm1.g1.e2 = 1"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'c', e3 = TRUE WHERE pm1.g1.e2 = 4"));
    // $NON-NLS-1$
    finalQueryList.add(new String("UPDATE pm1.g1 SET e1 = 'b', e3 = TRUE WHERE pm1.g1.e2 = 5"));
    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)

Aggregations

FakeDataManager (org.teiid.query.processor.FakeDataManager)112 Test (org.junit.Test)103 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)86 ArrayList (java.util.ArrayList)81 List (java.util.List)81 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)48 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 CommandContext (org.teiid.query.util.CommandContext)8 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)6 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 BufferManager (org.teiid.common.buffer.BufferManager)4 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)3 Constant (org.teiid.query.sql.symbol.Constant)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Function (org.teiid.query.sql.symbol.Function)3 Evaluator (org.teiid.query.eval.Evaluator)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2