use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestFunctionPushdown method testSimpleFunctionPushdown2.
@Test
public void testSimpleFunctionPushdown2() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "CREATE FOREIGN FUNCTION func(a object, b object) RETURNS string;"), new DDLHolder("z", "CREATE FOREIGN FUNCTION func1(a object, b object) RETURNS string; create foreign table g1 (e1 object)"));
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select e1 from g1 where func(1, 1) = '2'";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT func(1, 1)", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] {});
// $NON-NLS-1$
sql = "select e1 from g1 where func1(1, 1) = '2'";
plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT z.g1.e1 FROM z.g1 WHERE func1(1, 1) = '2'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
dataManager = new HardcodedDataManager(tm);
dataManager.addData("SELECT g1.e1 FROM g1 WHERE func1(1, 1) = '2'", new List[] { Arrays.asList("hello world") });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("hello world") });
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestEnginePerformance method helpTestXMLTable.
private void helpTestXMLTable(int iterations, int threadCount, String file, int expectedRowCount) throws QueryParserException, TeiidException, InterruptedException, Exception {
// $NON-NLS-1$
String sql = "select * from xmltable('/root/child' passing xmlparse(document cast(? as clob) wellformed) columns x integer path '@id', y long path 'gc2') as x";
List<?> preparedValues = Arrays.asList(TestTextTable.clobFromFile(file));
Command command = QueryParser.getQueryParser().parseCommand(sql);
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder();
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, createCommandContext());
runTask(iterations, threadCount, new PreparedPlanTask(preparedValues, metadata, plan, command, expectedRowCount));
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestMultiSourcePlanToProcessConverter method helpTestMultiSourcePlan.
public ProcessorPlan helpTestMultiSourcePlan(QueryMetadataInterface metadata, String userSql, String multiModel, int sourceCount, ProcessorDataManager dataMgr, List<?>[] expectedResults, VDBMetaData vdb, List<?> params, Options options, SourceCapabilities bsc) throws Exception {
Map<String, String> multiSourceModels = MultiSourceMetadataWrapper.getMultiSourceModels(vdb);
for (String model : multiSourceModels.keySet()) {
char sourceID = 'a';
// by default every model has one binding associated, but for multi-source there were none assigned.
ModelMetaData m = vdb.getModel(model);
int x = m.getSourceNames().size();
for (int i = x; i < sourceCount; i++, sourceID++) {
// $NON-NLS-1$ //$NON-NLS-2$
m.addSourceMapping("" + sourceID, "translator", null);
}
}
QueryMetadataInterface wrapper = new MultiSourceMetadataWrapper(metadata, multiSourceModels);
wrapper = new TempMetadataAdapter(wrapper, new TempMetadataStore());
DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(wrapper, vdb);
AnalysisRecord analysis = new AnalysisRecord(DEBUG, DEBUG);
Command command = TestResolver.helpResolve(userSql, wrapper);
ValidatorReport report = Validator.validate(command, metadata);
if (report.hasItems()) {
fail(report.toString());
}
// Plan
command = QueryRewriter.rewrite(command, wrapper, null);
DefaultCapabilitiesFinder fakeFinder = new DefaultCapabilitiesFinder(bsc);
CapabilitiesFinder finder = new TempCapabilitiesFinder(fakeFinder);
IDGenerator idGenerator = new IDGenerator();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
CommandContext context = new CommandContext("test", "user", null, vdb.getName(), vdb.getVersion(), false);
context.setDQPWorkContext(workContext);
context.setOptions(options);
ProcessorPlan plan = QueryOptimizer.optimizePlan(command, wrapper, idGenerator, finder, analysis, context);
if (DEBUG) {
System.out.println(analysis.getDebugLog());
// $NON-NLS-1$
System.out.println("\nMultiSource Plan:");
System.out.println(plan);
}
if (params != null) {
TestProcessor.setParameterValues(params, command, context);
}
TestProcessor.helpProcess(plan, context, dataMgr, expectedResults);
return plan;
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestOptimizer method testDistinctConstant2.
@Test
public void testDistinctConstant2() throws Exception {
// $NON-NLS-1$
String sql = "select distinct 1 from pm1.g1";
BasicSourceCapabilities bsc = getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.ROW_LIMIT, true);
CapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
ProcessorPlan plan = helpPlan(sql, RealMetadataFactory.example1Cached(), null, capFinder, new String[] { "SELECT 1 AS c_0 FROM pm1.g1 AS g_0 LIMIT 1" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
checkNodeTypes(plan, FULL_PUSHDOWN);
}
use of org.teiid.query.optimizer.capabilities.CapabilitiesFinder in project teiid by teiid.
the class TestSortOptimization method testProjectionRaisingWithComplexOrdering1.
@Test
public void testProjectionRaisingWithComplexOrdering1() {
// $NON-NLS-1$
String sql = "select e1 || 1 as a, e2 / 2 from pm1.g1 as x order by a, e2 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, c_1 LIMIT 2" }, // $NON-NLS-1$
TestOptimizer.SHOULD_SUCCEED);
assertTrue(plan.getRootNode() instanceof ProjectNode);
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("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, c_1 LIMIT 2", Arrays.asList("c1", 2), Arrays.asList("d1", 3));
TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList("c1", 1), Arrays.asList("d1", 1) });
}
Aggregations