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;
}
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;
}
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) });
}
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) });
}
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) });
}
Aggregations