use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder 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.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestJoinOptimization method testCrossJoinAvoidance.
@Test
public void testCrossJoinAvoidance() throws Exception {
CapabilitiesFinder capFinder = TestOptimizer.getGenericFinder();
QueryMetadataInterface metadata = RealMetadataFactory.exampleBQT();
// $NON-NLS-1$
RealMetadataFactory.setCardinality("bqt1.smallb", 1800, metadata);
// $NON-NLS-1$
RealMetadataFactory.setCardinality("bqt1.smalla", -1, metadata);
// $NON-NLS-1$
RealMetadataFactory.setCardinality("bqt2.smallb", 15662, metadata);
TestOptimizer.helpPlan(// $NON-NLS-1$
"SELECT BQT1.SmallA.IntKey FROM BQT1.SmallB, BQT1.Smalla, bqt2.smallb where bqt2.smallb.intkey = bqt1.smallb.intkey and bqt2.smallb.stringkey = bqt1.smalla.stringkey", metadata, null, capFinder, new String[] { "SELECT g_0.IntKey, g_0.StringKey FROM BQT2.SmallB AS g_0 WHERE g_0.IntKey IN (<dependent values>)", "SELECT g_0.StringKey AS c_0, g_0.IntKey AS c_1 FROM BQT1.SmallA AS g_0 ORDER BY c_0", "SELECT g_0.IntKey AS c_0 FROM BQT1.SmallB AS g_0 ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestSortOptimization method testProjectionRaisingWithComplexOrdering.
@Test
public void testProjectionRaisingWithComplexOrdering() {
// $NON-NLS-1$
String sql = "select e1 || 1, e2 / 2 from pm1.g1 as x order by e1 || 1 limit 2";
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setFunctionSupport(SourceSystemFunctions.CONCAT, true);
bsc.setCapabilitySupport(Capability.ROW_LIMIT, true);
CapabilitiesFinder finder = new DefaultCapabilitiesFinder(bsc);
RelationalPlan plan = (RelationalPlan) helpPlan(sql, RealMetadataFactory.example1Cached(), null, finder, new String[] { "SELECT concat(g_0.e1, '1') AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0 LIMIT 2" }, // $NON-NLS-1$
TestOptimizer.SHOULD_SUCCEED);
assertTrue(plan.getRootNode() instanceof ProjectNode);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class SubqueryAwareEvaluator method evaluatePushdown.
/**
* Implements must pushdown function handling if supported by the source.
*
* The basic strategy is to create a dummy subquery to represent the evaluation
*/
@Override
protected Object evaluatePushdown(Function function, List<?> tuple, Object[] values) throws TeiidComponentException, TeiidProcessingException {
final FunctionDescriptor fd = function.getFunctionDescriptor();
if (fd.getMethod() == null) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
String schema = null;
if (fd.getMethod().getParent() == null || !fd.getMethod().getParent().isPhysical()) {
// find a suitable target
// TODO: do better than a linear search
VDBMetaData vdb = this.context.getVdb();
CapabilitiesFinder capabiltiesFinder = this.context.getQueryProcessorFactory().getCapabiltiesFinder();
for (ModelMetaData mmd : vdb.getModelMetaDatas().values()) {
if (!mmd.isSource()) {
continue;
}
SourceCapabilities caps = capabiltiesFinder.findCapabilities(mmd.getName());
if (caps.supportsCapability(Capability.SELECT_WITHOUT_FROM) && caps.supportsFunction(fd.getMethod().getFullName())) {
schema = mmd.getName();
break;
}
}
if (schema == null) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
} else {
if (!CapabilitiesUtil.supports(Capability.SELECT_WITHOUT_FROM, fd.getMethod().getParent(), context.getMetadata(), context.getQueryProcessorFactory().getCapabiltiesFinder())) {
if (elements != null) {
Integer index = (Integer) elements.get(function);
if (index != null) {
return tuple.get(index.intValue());
}
}
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, fd.getFullName()));
}
schema = fd.getSchema();
}
ScalarSubquery ss = null;
if (functionState != null) {
ss = functionState.get(function);
}
Expression[] functionArgs = new Expression[values.length];
for (int i = 0; i < values.length; i++) {
functionArgs[i] = new Constant(values[i]);
}
if (ss == null) {
final Query command = new Query();
Select select = new Select();
command.setSelect(select);
Function f = new Function(function.getName(), functionArgs);
f.setType(function.getType());
f.setFunctionDescriptor(fd);
select.addSymbol(f);
ss = new ScalarSubquery(command);
SymbolMap correlatedReferences = new SymbolMap();
Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(function, true);
if (!elements.isEmpty()) {
for (ElementSymbol es : elements) {
correlatedReferences.addMapping(es, es);
}
command.setCorrelatedReferences(correlatedReferences);
}
command.setProcessorPlan(new SimpleProcessorPlan(command, schema, fd, Arrays.asList(new Constant(null, fd.getReturnType()))));
} else {
((Function) ((ExpressionSymbol) ss.getCommand().getProjectedSymbols().get(0)).getExpression()).setArgs(functionArgs);
}
if (functionState == null) {
this.functionState = new HashMap<Function, ScalarSubquery>(2);
}
functionState.put(function, ss);
return internalEvaluate(ss, tuple);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestWithClauseProcessing method testWithAndUncorrelatedSubquery.
@Test
public void testWithAndUncorrelatedSubquery() throws Exception {
// $NON-NLS-1$
String sql = "WITH t(n) AS /*+ no_inline */ ( select e1 from pm2.g1 ) SELECT n FROM t as t1, pm1.g1 where e1 = (select n from t)";
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT t.n FROM t", "SELECT 1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = (SELECT t.n FROM t)" }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
dataManager.addData("SELECT 1 FROM g1 AS g_0 WHERE g_0.e1 = 'a'", Arrays.asList(1));
List<?>[] expected = new List[] { Arrays.asList("a") };
helpProcess(plan, TestProcessor.createCommandContext(), dataManager, expected);
}
Aggregations