use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.
the class TestOptimizer method testAmbiguousAliasFunctionInSubQuerySource.
/**
* Test the query optimizer's ability to properly plan and optimize a query
* that uses ambiguous alias names in the top level query and its sub-query
* and uses columns belonging to the alias as a parameter to a function.
* <p>
* For example, <code>SELECT CONVERT(A.e2, biginteger) AS e2 FROM (SELECT
* CONVERT(e2, long) AS e2 FROM pm1.g1 AS A) AS A</code>
* <p>
* The test is to ensure that A.e2 from the top level is not confused with
* e2 in the second level.
* <p>
* Related Defects: JBEDSP-1137
*/
@Test
public void testAmbiguousAliasFunctionInSubQuerySource() throws Exception {
// Create query
String sql = // $NON-NLS-1$
"SELECT CONVERT(A.e2, biginteger) AS e2 FROM (" + // $NON-NLS-1$
" SELECT CONVERT(e2, long) AS e2 FROM pm1.g1 AS A" + // $NON-NLS-1$
") AS A";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
// $NON-NLS-1$
helpPlan(sql, metadata, new String[] { "SELECT e2 FROM pm1.g1 AS A" });
// Add convert capability to pm1 and try it again
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
// $NON-NLS-1$
caps.setFunctionSupport("convert", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
helpPlan(sql, metadata, null, capFinder, // $NON-NLS-1$
new String[] { "SELECT CONVERT(CONVERT(g_0.e2, long), biginteger) FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.
the class TestOptimizer method testCase2507.
// Test use of OrderBy with expression
@Test
public void testCase2507() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
// $NON-NLS-1$
caps.setFunctionSupport("||", true);
// $NON-NLS-1$
caps.setFunctionSupport("concat", true);
// $NON-NLS-1$
capFinder.addCapabilities("BQT1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
// $NON-NLS-1$
String sql = "SELECT vqt.smallb.a12345 FROM vqt.smallb ORDER BY vqt.smallb.a12345";
ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, // $NON-NLS-1$
new String[] { "SELECT Concat(stringKey, stringNum) AS EXPR FROM BQT1.SmallA ORDER BY EXPR" }, SHOULD_SUCCEED);
checkNodeTypes(plan, FULL_PUSHDOWN);
}
use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.
the class TestOptimizer method testUseMergeJoin7.
/**
* one side of join supports order by, the other doesn't
*/
@Test
public void testUseMergeJoin7() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm2.g2 WHERE pm1.g1.e1 = pm2.g2.e1";
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1();
RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 500, metadata);
RealMetadataFactory.setCardinality("pm2.g2", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1", "SELECT pm2.g2.e1 FROM pm2.g2" }, // $NON-NLS-1$ //$NON-NLS-2$
SHOULD_SUCCEED);
checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
1, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
0, // UnionAll
0 });
}
use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.
the class TestOptimizer method testSelectIntoWithDistinct.
@Test
public void testSelectIntoWithDistinct() throws Exception {
// $NON-NLS-1$
String sql = "select distinct e1 into #temp from pm1.g1";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
// $NON-NLS-1$
ProcessorPlan plan = helpPlan(sql, metadata, new String[] { "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING);
// txn required, since the insert could be split
assertTrue(plan.requiresTransaction(false));
checkNodeTypes(plan, FULL_PUSHDOWN);
checkNodeTypes(plan, new int[] { 1 }, new Class[] { ProjectIntoNode.class });
}
use of org.teiid.query.metadata.QueryMetadataInterface in project teiid by teiid.
the class TestOptimizer method testPushFunctionInJoin1.
@Test
public void testPushFunctionInJoin1() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
caps.setFunctionSupport(SourceSystemFunctions.UCASE, true);
// $NON-NLS-1$
caps.setFunctionSupport("convert", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// Add join capability to pm1
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
ProcessorPlan plan = helpPlan(// $NON-NLS-1$
"SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = convert(pm1.g2.e2, string) AND upper(pm1.g1.e1) = 'X'", metadata, null, capFinder, // $NON-NLS-1$
new String[] { "SELECT pm1.g1.e1, pm1.g2.e3 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e1 = convert(pm1.g2.e2, string)) AND (ucase(pm1.g1.e1) = 'X')" }, SHOULD_SUCCEED);
checkNodeTypes(plan, FULL_PUSHDOWN);
}
Aggregations