use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatement method testInherentlyUpdatableViewCompensation.
@Test
public void testInherentlyUpdatableViewCompensation() throws Exception {
// $NON-NLS-1$
String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN /*+ no_unnest */ (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)";
List<?>[] expected = new List<?>[] { Arrays.asList("a") };
// $NON-NLS-1$
List<?> values = Arrays.asList("a");
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM g2 AS g_1 WHERE g_1.e1 = 'a')", new List<?>[] { Arrays.asList("a") });
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
helpTestProcessing(preparedSql, values, expected, dataManager, new DefaultCapabilitiesFinder(caps), metadata, null, false, false, false, RealMetadataFactory.example1VDB());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatement method testWithSubqueryPushdown.
@Test
public void testWithSubqueryPushdown() throws Exception {
// $NON-NLS-1$
String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN /*+ no_unnest */ (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)";
List<?>[] expected = new List<?>[] { Arrays.asList("a") };
// $NON-NLS-1$
List<?> values = Arrays.asList("a");
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM g2 AS g_1 WHERE g_1.e1 = 'a')", new List<?>[] { Arrays.asList("a") });
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
helpTestProcessing(preparedSql, values, expected, dataManager, new DefaultCapabilitiesFinder(caps), metadata, null, false, false, false, RealMetadataFactory.example1VDB());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBatchedUpdatePushdown.
@Test
public void testBatchedUpdatePushdown() 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
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData("UPDATE pm1.g1 SET e1 = ?, e3 = ? WHERE pm1.g1.e2 = ?", new List[] { Arrays.asList(4) });
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BULK_UPDATE, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// 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) })));
List<?>[] expected = new List[] { Arrays.asList(4) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
Update update = (Update) dataManager.getCommandHistory().iterator().next();
assertTrue(((Constant) update.getChangeList().getClauses().get(0).getValue()).isMultiValued());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBatchedMerge.
@Test
public void testBatchedMerge() throws Exception {
String ddl = "CREATE foreign table x (y string primary key, z integer) options (updatable true)";
QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");
// Create query
// $NON-NLS-1$
String preparedSql = "merge into x (y, z) values (?, ?)";
// Create a testable prepared plan cache
SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData("SELECT 1 FROM phy.x AS g_0 WHERE g_0.y = 'a'", new List[] { Arrays.asList(1) });
// $NON-NLS-1$
dataManager.addData("UPDATE x SET z = 0 WHERE y = 'a'", new List[] { Arrays.asList(1) });
// $NON-NLS-1$
dataManager.addData("INSERT INTO x (y, z) VALUES (null, 1)", new List[] { Arrays.asList(1) });
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
// $NON-NLS-1$
capFinder.addCapabilities("phy", caps);
// 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", new Integer(0) })));
values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, new Integer(1) })));
List<?>[] expected = new List[] { Arrays.asList(1), Arrays.asList(1) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, metadata, prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBatchedUpdatePushdown2.
/**
* Test batch handling when a function cannot be pushed
*/
@Test
public void testBatchedUpdatePushdown2() throws Exception {
// TODO: just use straight ddl
TransformationMetadata metadata = RealMetadataFactory.example1Cached();
// $NON-NLS-1$
String preparedSql = "insert into pm1.g1 (e1) values (? + 1)";
// Create a testable prepared plan cache
SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
dataManager.addData("INSERT INTO g1 (e1) VALUES ('4')", Arrays.asList(1));
dataManager.addData("INSERT INTO g1 (e1) VALUES ('6')", Arrays.asList(1));
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, false);
caps.setCapabilitySupport(Capability.BULK_UPDATE, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// batch with two commands
ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
// $NON-NLS-1$
values.add(new ArrayList<Object>(Arrays.asList(3)));
values.add(new ArrayList<Object>(Arrays.asList(5)));
List<?>[] expected = new List[] { Arrays.asList(1), Arrays.asList(1) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, metadata, prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
}
Aggregations