use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.
the class TestPreparedPlanCache method testGet.
@Test
public void testGet() {
SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
helpPutPreparedPlans(cache, token, 0, 10);
helpPutPreparedPlans(cache, token2, 0, 15);
// read an entry for session2 (token2)
PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12));
// $NON-NLS-1$
assertNotNull("Unable to get prepared plan from cache", pPlan);
// $NON-NLS-1$
assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString());
// $NON-NLS-1$
assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString());
// $NON-NLS-1$
assertNotNull("Error getting plan description from cache", pPlan.getAnalysisRecord());
// $NON-NLS-1$
assertEquals("Error gettting reference from cache", new Reference(1), pPlan.getReferences().get(0));
}
use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.
the class TestPreparedPlanCache method helpPutPreparedPlans.
// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
for (int i = 0; i < count; i++) {
Command dummy;
try {
dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
} catch (QueryParserException e) {
throw new RuntimeException(e);
}
CacheID id = new CacheID(session, pi, dummy.toString());
PreparedPlan pPlan = new PreparedPlan();
cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
pPlan.setCommand(dummy);
pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
pPlan.setAnalysisRecord(analysisRecord);
ArrayList<Reference> refs = new ArrayList<Reference>();
refs.add(new Reference(1));
pPlan.setReferences(refs);
}
}
use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.
the class TestMultiSourcePlanToProcessConverter method testMultiReplacementWithLimit1.
@Test
public void testMultiReplacementWithLimit1() throws Exception {
final QueryMetadataInterface metadata = RealMetadataFactory.exampleMultiBinding();
// $NON-NLS-1$
final String userSql = "SELECT a, b FROM MultiModel.Phys limit 1, 1";
// $NON-NLS-1$
final String multiModel = "MultiModel";
final int sources = 2;
final List<?>[] expected = new List<?>[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList("x", "z") };
final HardcodedDataManager dataMgr = new HardcodedDataManager();
// $NON-NLS-1$
dataMgr.addData(// $NON-NLS-1$
"SELECT g_0.a AS c_0, g_0.b AS c_1 FROM MultiModel.Phys AS g_0 LIMIT 2", new List<?>[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList("y", "z"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList("x", "z") });
RelationalPlan plan = (RelationalPlan) helpTestMultiSourcePlan(metadata, userSql, multiModel, sources, dataMgr, expected, RealMetadataFactory.exampleMultiBindingVDB());
assertTrue(plan.getRootNode() instanceof LimitNode);
}
use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.
the class TestDependentJoins method testNestedLeftOuterJoin.
@Test
public void testNestedLeftOuterJoin() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
String sql = "select pm1.g1.e2, 'a', trim(pm1.g3.e1) from (pm1.g1 left outer join pm1.g2 on pm1.g1.e2 = pm1.g2.e2) left outer join pm1.g3 on pm1.g3.e3 = pm1.g2.e3 and pm1.g3.e4 = pm1.g1.e4";
QueryMetadataInterface metadata = RealMetadataFactory.example1();
// $NON-NLS-1$
RealMetadataFactory.setCardinality("pm1.g2", 6, metadata);
// $NON-NLS-1$
RealMetadataFactory.setCardinality("pm1.g1", 0, metadata);
// $NON-NLS-1$
RealMetadataFactory.setCardinality("pm1.g3", 0, metadata);
CapabilitiesFinder finder = TestOptimizer.getGenericFinder(false);
ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.e3, g_0.e4, g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e2, g_0.e4 FROM pm1.g1 AS g_0", "SELECT g_0.e2, g_0.e3 FROM pm1.g2 AS g_0 WHERE g_0.e2 IN (<dependent values>)" }, finder, ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
1, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // Join
0, // MergeJoin
2, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
0, // UnionAll
0 });
RelationalPlan rPlan = (RelationalPlan) plan;
RelationalNode node = rPlan.getRootNode().getChildren()[0];
assertTrue(node instanceof JoinNode);
node = node.getChildren()[0];
assertTrue(node instanceof JoinNode);
assertEquals(JoinType.JOIN_LEFT_OUTER, ((JoinNode) node).getJoinType());
}
use of org.teiid.query.processor.relational.RelationalPlan in project teiid by teiid.
the class TestJoinOptimization method testCopyCriteriaMultiway.
@Test
public void testCopyCriteriaMultiway() throws Exception {
// $NON-NLS-1$
String sql = "select bqt1.smalla.intkey, bqt2.smalla.intkey from bqt1.smalla, bqt2.smalla, bqt1.smallb where bqt1.smalla.intnum = bqt2.smalla.intnum and cast(bqt1.smalla.stringkey as integer) = coalesce(bqt2.smalla.intkey, bqt1.smallb.intkey) and bqt2.smalla.intkey = 1";
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.exampleBQTCached(), new String[] { "SELECT g_0.IntKey FROM BQT1.SmallB AS g_0", "SELECT g_0.IntNum AS c_0, g_0.IntKey AS c_1 FROM BQT2.SmallA AS g_0 WHERE g_0.IntKey = 1 ORDER BY c_0", "SELECT g_0.IntNum AS c_0, g_0.StringKey AS c_1, g_0.IntKey AS c_2 FROM BQT1.SmallA AS g_0 ORDER BY c_0" });
RelationalPlan relationalPlan = (RelationalPlan) plan;
JoinNode joinNode = (JoinNode) relationalPlan.getRootNode().getChildren()[0];
assertNotNull(joinNode.getJoinCriteria());
}
Aggregations