Search in sources :

Example 71 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestInherintlyUpdatableViews method helpTest.

private Command helpTest(String userSql, String viewSql, String expectedSql, ProcessorDataManager dm) throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView(viewSql, metadata, "gx");
    Command command = TestQueryRewriter.helpTestRewriteCommand(userSql, expectedSql, metadata);
    if (dm != null) {
        CommandContext context = createCommandContext();
        SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
        // $NON-NLS-1$
        context.setPreparedPlanCache(planCache);
        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
        caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
        ProcessorPlan plan = helpGetPlan(helpParse(userSql), metadata, new DefaultCapabilitiesFinder(caps), context);
        List<?>[] expected = new List[] { Arrays.asList(1) };
        helpProcess(plan, context, dm, expected);
        assertEquals(0, planCache.getTotalCacheEntries());
    }
    return command;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)

Example 72 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestRuleAccessPatternValidation method helpPlan.

/**
 * Parses and resolves the command, creates a canonical relational plan,
 * and runs some of the optimizer rules, ending with the
 * RuleChooseAccessPattern.
 * @param command String command to parse, resolve and use for planning
 * @param rules empty RuleStack
 * @param groups Collection to add parsed and resolved GroupSymbols to
 * @return the root PlanNode of the query plan
 */
private PlanNode helpPlan(String command) throws Exception {
    Command query = QueryParser.getQueryParser().parseCommand(command);
    QueryResolver.resolveCommand(query, METADATA);
    // Generate canonical plan
    RelationalPlanner p = new RelationalPlanner();
    p.initialize(query, null, METADATA, FINDER, null, new CommandContext());
    PlanNode planNode = p.generatePlan(query);
    RelationalPlanner planner = new RelationalPlanner();
    final RuleStack rules = planner.buildRules();
    PlanNode testPlan = helpExecuteRules(rules, planNode, METADATA, DEBUG);
    return testPlan;
}
Also used : RelationalPlanner(org.teiid.query.optimizer.relational.RelationalPlanner) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) RuleStack(org.teiid.query.optimizer.relational.RuleStack)

Example 73 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestInsertProcessing method testInsertDefaultResolvingExpression.

@Test
public void testInsertDefaultResolvingExpression() throws Exception {
    // $NON-NLS-1$
    String sql = "insert into x (y) values ('1')";
    TransformationMetadata tm = RealMetadataFactory.fromDDL("" + "create foreign table t (y string, z string) options (updatable true); " + "create view x (y string, z string default 'a' || user()) options (updatable true) as select * from t; " + "create trigger on x instead of insert as for each row begin insert into t (y, z) values (new.y, new.z); end;", "vdb", "source");
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, tm, TestOptimizer.getGenericFinder());
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("INSERT INTO t (y, z) VALUES ('1', 'auser')", new List<?>[] { Arrays.asList(1) });
    helpProcess(plan, dataManager, new List<?>[] { Arrays.asList(1) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) Test(org.junit.Test)

Example 74 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestInsertProcessing method testInsertDefaultResolving.

@Test
public void testInsertDefaultResolving() throws Exception {
    // $NON-NLS-1$
    String sql = "insert into x (y) values ('1')";
    TransformationMetadata tm = RealMetadataFactory.fromDDL("" + "create foreign table t (y string, z string) options (updatable true); " + "create view x (y string, z string default 'a') options (updatable true) as select * from t; " + "create trigger on x instead of insert as for each row begin insert into t (y, z) values (new.y, new.z); end;", "vdb", "source");
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, tm, TestOptimizer.getGenericFinder());
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("INSERT INTO t (y, z) VALUES ('1', 'a')", new List<?>[] { Arrays.asList(1) });
    helpProcess(plan, dataManager, new List<?>[] { Arrays.asList(1) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) Test(org.junit.Test)

Example 75 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestInsertProcessing method testMerge.

@Test
public void testMerge() throws Exception {
    String ddl = "create foreign table t1 (x integer primary key, y string) options (updatable true);";
    TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "y");
    // $NON-NLS-1$
    String sql = "merge into t1 (x, y) select 1, 'a' union all select 2, 'b'";
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, tm, TestOptimizer.getGenericFinder());
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("SELECT 1 FROM t1 AS g_0 WHERE g_0.x = 1", new List<?>[] { Arrays.asList(1) });
    dataManager.addData("UPDATE t1 SET y = 'a' WHERE t1.x = 1", new List<?>[] { Arrays.asList(1) });
    dataManager.addData("SELECT 1 FROM t1 AS g_0 WHERE g_0.x = 2", new List<?>[] {});
    dataManager.addData("INSERT INTO t1 (x, y) VALUES (2, 'b')", new List<?>[] { Arrays.asList(1) });
    helpProcess(plan, dataManager, new List<?>[] { Arrays.asList(2) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) Test(org.junit.Test)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10