use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatement method testInsertWithMultipleValues.
@Test
public void testInsertWithMultipleValues() throws Exception {
// $NON-NLS-1$
String preparedSql = "insert into pm1.g1 (e1, e2) values (?, ?), (?, ?)";
List<?>[] expected = new List<?>[] { Arrays.asList(2) };
// $NON-NLS-1$
List<?> values = Arrays.asList("a", "1", "b", "2");
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
dataManager.addData("INSERT INTO g1 (e1, e2) VALUES ('a', 1)", new List<?>[] { Arrays.asList(1) });
dataManager.addData("INSERT INTO g1 (e1, e2) VALUES ('b', 2)", new List<?>[] { Arrays.asList(1) });
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
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 testAnonBlockIn.
@Test
public void testAnonBlockIn() throws Exception {
// $NON-NLS-1$
String preparedSql = "begin insert into pm1.g1 (e1, e2) select ?, ?; select rowcount; end;";
List<?>[] expected = new List<?>[] { Arrays.asList(1) };
// $NON-NLS-1$
List<?> values = Arrays.asList("a", "1");
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
dataManager.addData("INSERT INTO g1 (e1, e2) VALUES ('a', 1)", new List<?>[] { Arrays.asList(1) });
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
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 testBatchedUpdatePushdown1.
@Test
public void testBatchedUpdatePushdown1() throws Exception {
// TODO: just use straight ddl
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, "GX");
Table t = metadata.getMetadataStore().getSchemas().get("VM1").getTables().get("GX");
t.setDeletePlan("");
t.setUpdatePlan("");
t.setInsertPlan("FOR EACH ROW BEGIN insert into pm1.g1 (e1) values (new.x); END");
// $NON-NLS-1$
String preparedSql = "insert into gx (x, y) 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(metadata);
// $NON-NLS-1$
dataManager.addData("INSERT INTO g1 (e1) VALUES (convert(?, string))", new List[] { Arrays.asList(2) });
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
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, 4)));
values.add(new ArrayList<Object>(Arrays.asList(5, 6)));
List<?>[] expected = new List[] { Arrays.asList(2) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, metadata, prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
org.teiid.language.Insert insert = (org.teiid.language.Insert) dataManager.getPushdownCommands().iterator().next();
Parameter p = CollectorVisitor.collectObjects(Parameter.class, insert).iterator().next();
assertEquals(0, p.getValueIndex());
assertEquals(Arrays.asList(3), insert.getParameterValues().next());
assertTrue(insert.getParameterValues().hasNext());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBatchedUpdateNotPushdown.
@Test
public void testBatchedUpdateNotPushdown() 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 = 'a', e3 = FALSE WHERE pm1.g1.e2 = 0", new List[] { Arrays.asList(2) });
// $NON-NLS-1$
dataManager.addData("UPDATE pm1.g1 SET e1 = null, e3 = FALSE WHERE pm1.g1.e2 = 1", new List[] { Arrays.asList(2) });
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BULK_UPDATE, false);
// $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(2), Arrays.asList(2) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
}
use of org.teiid.query.processor.HardcodedDataManager in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBulkBytePushdown.
@Test
public void testBulkBytePushdown() throws Exception {
// $NON-NLS-1$
String preparedSql = "insert into g1 (e1) values (?)";
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table g1 (e1 varbinary) options (updatable true)", "y", "z");
// 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("INSERT INTO g1 (e1) VALUES (?)", new List[] { Arrays.asList(1), Arrays.asList(1) });
// 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("z", caps);
ArrayList<List<?>> values = new ArrayList<List<?>>(2);
// $NON-NLS-1$
values.add(Arrays.asList(new byte[1]));
// $NON-NLS-1$
values.add(Arrays.asList(new byte[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, tm, prepPlanCache, false, false, false, tm.getVdbMetaData());
Insert insert = (Insert) dataManager.getCommandHistory().iterator().next();
Constant c = (Constant) insert.getValues().get(0);
assertTrue(c.isMultiValued());
assertTrue(((List<?>) c.getValue()).get(0) instanceof BinaryType);
}
Aggregations