Search in sources :

Example 81 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestTriggerActions method testUpdateWithChanging.

@Test
public void testUpdateWithChanging() 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 = case when changing.y then new.y end 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));
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 82 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestTriggerActions method testInsertWithQueryExpressionAndAlias.

@Test
public void testInsertWithQueryExpressionAndAlias() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table tablea (TEST_ID integer, TEST_NBR bigdecimal) options (updatable true);\n" + "create foreign table tableb (TEST_ID integer, TEST_NBR bigdecimal);\n" + "create view viewa options (updatable true) as SELECT TEST_ID, TEST_NBR FROM tablea;\n" + "create trigger on viewa instead of insert as for each row begin atomic " + "INSERT INTO tablea (tablea.TEST_ID, tablea.TEST_NBR) VALUES (\"NEW\".TEST_ID, \"NEW\".TEST_NBR); END;", "x", "y");
    String sql = "insert into viewa (TEST_ID, TEST_NBR) SELECT TEST_ID AS X, TEST_NBR FROM tableb";
    HardcodedDataManager dm = new HardcodedDataManager();
    dm.addData("INSERT INTO tablea (TEST_ID, TEST_NBR) VALUES (1, 2.0)", Arrays.asList(1));
    dm.addData("SELECT g_0.TEST_ID, g_0.TEST_NBR FROM y.tableb AS g_0", Arrays.asList(1, 2.0));
    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);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 83 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testAnonBlockResolveFails.

/**
 * Should fail as the results conflict from multiple statements
 */
@Test(expected = QueryValidatorException.class)
public void testAnonBlockResolveFails() throws Exception {
    // $NON-NLS-1$
    String sql = "begin insert into #temp (e1) select e1 from pm1.g1; select * from #temp; select * from pm1.g1; end;";
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    getProcedurePlan(sql, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Test(org.junit.Test)

Example 84 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testUDF.

@Test
public void testUDF() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL FUNCTION f1(VARIADIC e1 integer) RETURNS integer as return array_length(e1);", "x", "y");
    ProcessorPlan plan = helpGetPlan("select f1(1, 2, 1)", metadata);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    helpProcess(plan, cc, new HardcodedDataManager(), new List[] { Arrays.asList(3) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 85 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testDynamicCreate.

@Test(expected = TeiidProcessingException.class)
public void testDynamicCreate() throws Exception {
    // $NON-NLS-1$
    String sql = "exec p1(1)";
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create virtual procedure p1(a long) returns (res long) as " + "begin execute immediate 'create local temporary table t (x string)' as res long;  end;", "x", "y");
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    // $NON-NLS-1$
    List[] expected = new List[] {};
    helpTestProcess(plan, expected, dataManager, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20