Search in sources :

Example 71 with HardcodedDataManager

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());
}
Also used : HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 72 with HardcodedDataManager

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());
}
Also used : HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 73 with HardcodedDataManager

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());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) Insert(org.teiid.query.sql.lang.Insert) Parameter(org.teiid.language.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 74 with HardcodedDataManager

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());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 75 with HardcodedDataManager

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);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BinaryType(org.teiid.core.types.BinaryType) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Insert(org.teiid.query.sql.lang.Insert) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)140 Test (org.junit.Test)134 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)97 List (java.util.List)75 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)63 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)53 ArrayList (java.util.ArrayList)44 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)42 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)29 CommandContext (org.teiid.query.util.CommandContext)19 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)14 Options (org.teiid.query.util.Options)6 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)5 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)4 Command (org.teiid.query.sql.lang.Command)4 TupleSource (org.teiid.common.buffer.TupleSource)3 Insert (org.teiid.query.sql.lang.Insert)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2