@Test public void testDynamicUpdate() throws Exception { 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("FOR EACH ROW BEGIN execute immediate 'update pm1.g1 set e1 = new.x where e2 = new.y'; END"); t.setInsertPlan(""); String sql = "update gx set x = 1 where y = 2"; HardcodedDataManager dm = new HardcodedDataManager(); dm.addData("UPDATE pm1.g1 SET e1 = '1' WHERE e2 = 2", new List[] {Arrays.asList(1)}); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); }
private UpdateValidator helpTest(String sql, TransformationMetadata md, boolean shouldFail) { return helpTest(sql, md, shouldFail, shouldFail, shouldFail); }
public static TransformationMetadata example1() { return example1(true); }
private UpdateValidator helpTest(String sql, TransformationMetadata md, boolean failInsert, boolean failUpdate, boolean failDelete) { try { String vGroup = "gx"; Command command = createView(sql, md, vGroup); UpdateValidator uv = new UpdateValidator(md, UpdateType.INHERENT, UpdateType.INHERENT, UpdateType.INHERENT); GroupSymbol gs = new GroupSymbol(vGroup); ResolverUtil.resolveGroup(gs, md); uv.validate(command, ResolverUtil.resolveElementsInGroup(gs, md)); UpdateInfo info = uv.getUpdateInfo(); assertEquals(uv.getReport().getFailureMessage(), failInsert, info.getInsertValidationError() != null); assertEquals(uv.getReport().getFailureMessage(), failUpdate, info.getUpdateValidationError() != null); assertEquals(uv.getReport().getFailureMessage(), failDelete, info.getDeleteValidationError() != null); return uv; } catch (TeiidException e) { throw new RuntimeException(e); } }
@Test public void testBatchedUpdatePushdown1() throws Exception { 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("");
@Test public void testInsertWithDefault() throws Exception { 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"); String sql = "insert into gx (x) values (1)"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); }
@Test public void testUpdateWithNonConstant() throws Exception { 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("FOR EACH ROW BEGIN update pm1.g1 set e2 = new.y where e2 = old.y; END"); t.setInsertPlan(""); String sql = "update gx set y = x"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); assertEquals("UPDATE pm1.g1 SET e2 = 1 WHERE e2 = 2", dm.getQueries().get(0)); }
@Test public void testDynamic() throws Exception { 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("FOR EACH ROW BEGIN ATOMIC END"); t.setUpdatePlan(""); t.setInsertPlan("FOR EACH ROW BEGIN execute immediate 'delete from gx where gx.x = new.x'; END"); String sql = "insert into gx (x, y) select e1, e2 from pm1.g1"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(6)}; helpProcess(plan, context, dm, expected); }
@Test public void testInsert() throws Exception { 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"); String sql = "insert into gx (x, y) values (1, 2)"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); }
@Test public void testInsertWithQueryExpression() throws Exception { 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"); String sql = "insert into gx (x, y) select e1, e2 from pm1.g1"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(6)}; helpProcess(plan, context, dm, expected); }
@Test public void testDelete() throws Exception { 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("FOR EACH ROW BEGIN delete from pm1.g1 where e2 = old.x; END"); t.setUpdatePlan(""); t.setInsertPlan(""); String sql = "delete from gx where y = 2"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); }
@Test public void testUpdate() throws Exception { 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("FOR EACH ROW BEGIN update pm1.g1 set e2 = new.y where e2 = old.y; END"); t.setInsertPlan(""); String sql = "update gx set y = 5"; FakeDataManager dm = new FakeDataManager(); FakeDataStore.addTable("pm1.g1", dm, metadata); CommandContext context = createCommandContext(); BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); assertEquals("UPDATE pm1.g1 SET e2 = 5 WHERE e2 = 2", dm.getQueries().get(0)); }