use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.
the class TestMaterialization method testManagedMaterializedTransformationJoin.
@Test
public void testManagedMaterializedTransformationJoin() throws Exception {
// make sure view removal is not inhibited
// $NON-NLS-1$
String userSql = "SELECT MatTable1.*,ManagedMatView.* FROM ManagedMatView left outer join MatTable1 on ManagedMatView.e1 = MatTable1.e1";
QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] { // $NON-NLS-1$
"SELECT g_1.e1, g_0.e1 FROM MatTable.MatTable AS g_0 LEFT OUTER JOIN MatTable.MatTable1 AS g_1 ON g_0.e1 = g_1.e1 WHERE mvstatus('MatView', 'ManagedMatView') = 1" }, ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.
the class XMLQuery method compileXqueryExpression.
// TODO: display the analysis record info
public void compileXqueryExpression() throws QueryResolverException {
this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, null);
this.xqueryExpression.useDocumentProjection(null, new AnalysisRecord(false, false));
}
use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.
the class QueryProcessorFactoryImpl method getPreparedPlan.
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException {
if (recursionGroup != null) {
commandContext.pushCall(recursionGroup);
}
PreparedPlan pp = commandContext.getPlan(query);
if (pp == null) {
ParseInfo parseInfo = new ParseInfo();
Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
QueryResolver.resolveCommand(newCommand, metadata);
List<Reference> references = ReferenceCollectorVisitor.getReferences(newCommand);
AbstractValidationVisitor visitor = new ValidationVisitor();
Request.validateWithVisitor(visitor, metadata, newCommand);
newCommand = QueryRewriter.rewrite(newCommand, metadata, commandContext);
AnalysisRecord record = new AnalysisRecord(false, false);
ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, finder, record, commandContext);
pp = new PreparedPlan();
pp.setPlan(plan, commandContext);
pp.setReferences(references);
pp.setAnalysisRecord(record);
pp.setCommand(newCommand);
commandContext.putPlan(query, pp, commandContext.getDeterminismLevel());
}
return pp;
}
use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.
the class QueryOptimizer method optimizePlan.
public static ProcessorPlan optimizePlan(Command command, QueryMetadataInterface metadata, IDGenerator idGenerator, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context) throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
if (analysisRecord == null) {
analysisRecord = new AnalysisRecord(false, false);
}
if (context == null) {
context = new CommandContext();
}
if (!(capFinder instanceof TempCapabilitiesFinder)) {
capFinder = new TempCapabilitiesFinder(capFinder);
}
boolean debug = analysisRecord.recordDebug();
if (!(metadata instanceof TempMetadataAdapter)) {
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
}
if (context.getMetadata() == null) {
context.setMetadata(metadata);
}
// Create an ID generator that can be used for all plans to generate unique data node IDs
if (idGenerator == null) {
idGenerator = new IDGenerator();
}
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n----------------------------------------------------------------------------");
// $NON-NLS-1$
analysisRecord.println("OPTIMIZE: \n" + command);
}
if (command instanceof Insert) {
Insert insert = (Insert) command;
if (insert.isUpsert()) {
// if not supported or there are trigger actions, then rewrite as a procedure
// we do this here since we're changing the command type.
// TODO: we could push this back into the rewrite, but it will need to be capabilities aware
GroupSymbol group = insert.getGroup();
Object modelId = metadata.getModelID(group.getMetadataID());
boolean supportsUpsert = CapabilitiesUtil.supports(Capability.UPSERT, modelId, metadata, capFinder);
if (!supportsUpsert) {
try {
command = QueryRewriter.rewriteAsUpsertProcedure(insert, metadata, context);
} catch (TeiidProcessingException e) {
throw new QueryPlannerException(e);
}
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n----------------------------------------------------------------------------");
// $NON-NLS-1$
analysisRecord.println("OPTIMIZE UPSERT PROCEDURE: \n" + command);
}
}
}
}
ProcessorPlan result = null;
switch(command.getType()) {
case Command.TYPE_UPDATE_PROCEDURE:
CreateProcedureCommand cupc = (CreateProcedureCommand) command;
if (cupc.getUpdateType() != Command.TYPE_UNKNOWN || cupc.getVirtualGroup() == null) {
// row update procedure or anon block
result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
} else {
Object pid = cupc.getVirtualGroup().getMetadataID();
if (pid instanceof TempMetadataID) {
TempMetadataID tid = (TempMetadataID) pid;
if (tid.getOriginalMetadataID() != null) {
pid = tid.getOriginalMetadataID();
}
}
String fullName = metadata.getFullName(pid);
// $NON-NLS-1$
fullName = "procedure cache:" + fullName;
PreparedPlan pp = context.getPlan(fullName);
if (pp == null) {
Determinism determinismLevel = context.resetDeterminismLevel();
try {
CommandContext clone = context.clone();
ProcessorPlan plan = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, clone);
// note that this is not a full prepared plan. It is not usable by user queries.
if (pid instanceof Procedure) {
clone.accessedPlanningObject(pid);
}
pp = new PreparedPlan();
pp.setPlan(plan, clone);
context.putPlan(fullName, pp, context.getDeterminismLevel());
} finally {
context.setDeterminismLevel(determinismLevel);
}
}
result = pp.getPlan().clone();
for (Object id : pp.getAccessInfo().getObjectsAccessed()) {
context.accessedPlanningObject(id);
}
}
break;
case Command.TYPE_BATCHED_UPDATE:
result = BATCHED_UPDATE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
break;
case Command.TYPE_ALTER_PROC:
case Command.TYPE_ALTER_TRIGGER:
case Command.TYPE_ALTER_VIEW:
result = DDL_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
break;
case Command.TYPE_SOURCE_EVENT:
result = SOURCE_EVENT_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
break;
default:
try {
RelationalPlanner planner = new RelationalPlanner();
planner.initialize(command, idGenerator, metadata, capFinder, analysisRecord, context);
result = planner.optimize(command);
} catch (QueryResolverException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30245, e);
}
}
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n----------------------------------------------------------------------------");
// $NON-NLS-1$
analysisRecord.println("OPTIMIZATION COMPLETE:");
// $NON-NLS-1$
analysisRecord.println("PROCESSOR PLAN:\n" + result);
// $NON-NLS-1$
analysisRecord.println("============================================================================");
}
return result;
}
use of org.teiid.query.analysis.AnalysisRecord 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;
}
Aggregations