use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestPreparedStatement method testObjectCast.
@Test
public void testObjectCast() throws Exception {
// Create query
// $NON-NLS-1$
String preparedSql = "SELECT array_length(cast(? as object))";
// Create expected results
List<?>[] expected = new List<?>[] { // $NON-NLS-1$
Arrays.asList(1) };
List<?> values = Arrays.asList(new double[] { 1.0 });
FakeDataManager dataManager = new FakeDataManager();
helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, RealMetadataFactory.example1VDB());
values = Arrays.asList(new Object[] { new Double[] { 1.0 } });
helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, RealMetadataFactory.example1VDB());
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestPreparedStatement method helpTestProcessing.
public static void helpTestProcessing(String preparedSql, List<?> values, List<?>[] expected, ProcessorDataManager dataManager, CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, boolean callableStatement, boolean isSessionSpecific, boolean isAlreadyCached, VDBMetaData vdb) throws Exception {
if (dataManager == null) {
// Construct data manager with data
dataManager = new FakeDataManager();
TestProcessor.sampleData1((FakeDataManager) dataManager);
}
if (capFinder == null) {
capFinder = new DefaultCapabilitiesFinder();
}
if (prepPlanCache == null) {
// $NON-NLS-1$
prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
}
// expected cache hit count
int exHitCount = -1;
/*
* If the plan is already cached we want our expected hit
* count of the cache to be at least 2 because we will
* get the plan twice. Otherwise, we want it to be 1.
*/
if (isAlreadyCached) {
exHitCount = prepPlanCache.getCacheHitCount() + 2;
} else {
exHitCount = prepPlanCache.getCacheHitCount() + 1;
}
// Create plan or used cache plan if isPlanCached
PreparedStatementRequest plan = TestPreparedStatement.helpGetProcessorPlan(preparedSql, values, capFinder, metadata, prepPlanCache, SESSION_ID, callableStatement, false, vdb);
// Run query
TestProcessor.doProcess(plan.processPlan, dataManager, expected, plan.context);
// test cached plan
plan = TestPreparedStatement.helpGetProcessorPlan(preparedSql, values, capFinder, metadata, prepPlanCache, SESSION_ID, callableStatement, false, vdb);
// make sure the plan is only created once
// $NON-NLS-1$
assertEquals("should reuse the plan", exHitCount, prepPlanCache.getCacheHitCount());
// If we are using FakeDataManager, stop command recording to prevent
// duplicate commands
boolean dmir = false;
if (dataManager instanceof FakeDataManager && ((FakeDataManager) dataManager).isRecordingCommands()) {
dmir = true;
((FakeDataManager) dataManager).setRecordingCommands(false);
}
// Run query again
TestProcessor.doProcess(plan.processPlan, dataManager, expected, plan.context);
// start it back up again
if (dmir == true) {
((FakeDataManager) dataManager).setRecordingCommands(true);
}
// get the plan again with a new connection
assertNotNull(TestPreparedStatement.helpGetProcessorPlan(preparedSql, values, capFinder, metadata, prepPlanCache, 7, callableStatement, false, vdb));
/*
* If the command is not specific to a session we expect
* another hit against the cache because we will use the
* cached plan, otherwise, a new plan would have been
* created and the hit count will be unchanged.
*/
if (!isSessionSpecific)
exHitCount++;
assertEquals(exHitCount, prepPlanCache.getCacheHitCount());
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testUpdateSameNumCmds.
/**
* Test prepared statements that use batched updates using the same prepared
* command with same number of commands in the batch.
* <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 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
* UPDATE pm1.g1 SET pm1.g1.e1='b', pm1.g1.e3=true WHERE pm1.g1.e2=5
* <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() 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
List<List<Object>> values = new ArrayList<List<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) }), Arrays.asList(new Object[] { new Integer(0) }) };
// batch with two commands
values = new ArrayList<List<Object>>(1);
// $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(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 = 'b', e3 = TRUE WHERE pm1.g1.e2 = 5"));
// 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());
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestUnionPlanning method testCostingWithGroupingAndOrder.
@Test
public void testCostingWithGroupingAndOrder() throws Exception {
String sql = "select e1 as admissionid,e2 as patgroup,e3 as ward,e4 as admtime, 'wh' as origin from pm1.g1 gd " + " group by e1,e2,e3,e4 UNION ALL select e1,e2,e3,e4, 'prod' from pm1.g2 gd" + " group by e1,e2,e3,e4 order by admtime limit 1";
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
TransformationMetadata tm = RealMetadataFactory.example1();
RealMetadataFactory.setCardinality("pm1.g1", 1000, tm);
RealMetadataFactory.setCardinality("pm1.g2", 1000, tm);
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
sql, // $NON-NLS-1$
tm, // $NON-NLS-1$
null, // $NON-NLS-1$
new DefaultCapabilitiesFinder(caps), new String[] { "SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2, g_0.e3, g_0.e4 FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING);
FakeDataManager dataManager = new FakeDataManager();
FakeDataStore.sampleData2(dataManager);
TestProcessor.helpProcess(plan, dataManager, new List[] { Arrays.asList("b", 1, true, null, "wh") });
}
use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.
the class TestLimit method testInlineViewJoin.
@Test
public void testInlineViewJoin() throws TeiidComponentException, TeiidProcessingException {
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);
// $NON-NLS-1$
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$ //$NON-NLS-2$
String[] expectedSql = new String[] { "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 LIMIT 700", "SELECT g_0.e1 FROM pm1.g2 AS g_0" };
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, expectedSql, ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // Limit
1, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
1, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
1, // UnionAll
0 }, 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[] { // $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$
Arrays.asList("a") });
}
Aggregations