Search in sources :

Example 21 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestOptimizer method testPlanNodeAnnotation.

@Test
public void testPlanNodeAnnotation() throws Exception {
    PlanNode pn = new PlanNode();
    TransformationMetadata metadata = RealMetadataFactory.example1Cached();
    Object modelID = metadata.getMetadataStore().getSchema("pm1");
    AnalysisRecord record = new AnalysisRecord(true, true);
    pn.recordDebugAnnotation("hello", modelID, "world", record, metadata);
    assertEquals("[LOW [Relational Planner] hello pm1 - world Unknown: 0(groups=[]]", record.getAnnotations().toString());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) LanguageObject(org.teiid.query.sql.LanguageObject) Test(org.junit.Test)

Example 22 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestProcedurePlanner method helpPlanProcedure.

// ################ getReplacementClause tests ###################
private ProcessorPlan helpPlanProcedure(String userQuery, String procedure, TriggerEvent procedureType) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
    QueryParser parser = QueryParser.getQueryParser();
    Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
    if (userCommand instanceof CreateProcedureCommand) {
        GroupSymbol gs = new GroupSymbol("proc");
        gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
        ((CreateProcedureCommand) userCommand).setVirtualGroup(gs);
    }
    QueryResolver.resolveCommand(userCommand, metadata);
    ValidatorReport report = Validator.validate(userCommand, metadata);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        throw new QueryValidatorException(firstFailure.getMessage());
    }
    userCommand = QueryRewriter.rewrite(userCommand, metadata, null);
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    try {
        return QueryOptimizer.optimizePlan(userCommand, metadata, null, new DefaultCapabilitiesFinder(), analysisRecord, null);
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 23 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestRuleAccessPatternValidation method helpExecuteRules.

/**
 * Simulate execution of the QueryOptimizer rules stack
 */
private static PlanNode helpExecuteRules(RuleStack rules, PlanNode plan, QueryMetadataInterface metadata, boolean debug) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
    CommandContext context = new CommandContext();
    while (!rules.isEmpty()) {
        if (debug) {
            // $NON-NLS-1$
            System.out.println("\n============================================================================");
        }
        OptimizerRule rule = rules.pop();
        if (debug) {
            // $NON-NLS-1$
            System.out.println("EXECUTING " + rule);
        }
        plan = rule.execute(plan, metadata, FINDER, rules, new AnalysisRecord(false, debug), context);
        if (debug) {
            // $NON-NLS-1$
            System.out.println("\nAFTER: \n" + plan);
        }
    }
    return plan;
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) OptimizerRule(org.teiid.query.optimizer.relational.OptimizerRule)

Example 24 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestMaterialization method testMaterializedTransformationNoCache2.

// related to defect 14423
@Test
public void testMaterializedTransformationNoCache2() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE";
    QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    // $NON-NLS-1$
    TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] { "SELECT g_0.x FROM MatSrc.MatSrc AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING);
    Collection<Annotation> annotations = analysis.getAnnotations();
    // $NON-NLS-1$
    assertNotNull("Expected annotations but got none", annotations);
    // $NON-NLS-1$
    assertTrue("Expected one annotation", annotations.size() == 1);
    // $NON-NLS-1$
    assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW);
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Example 25 with AnalysisRecord

use of org.teiid.query.analysis.AnalysisRecord in project teiid by teiid.

the class TestMaterialization method testDefaultMaterialization.

@Test
public void testDefaultMaterialization() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup2";
    TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    CommandContext cc = new CommandContext();
    GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata);
    cc.setGlobalTableStore(gts);
    ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT #MAT_MATVIEW.VGROUP2.x FROM #MAT_MATVIEW.VGROUP2" }, plan);
    Collection<Annotation> annotations = analysis.getAnnotations();
    // $NON-NLS-1$
    assertNotNull("Expected annotations but got none", annotations);
    // $NON-NLS-1$
    assertEquals("Expected one annotation", 1, annotations.size());
    // $NON-NLS-1$
    assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Aggregations

AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)31 Command (org.teiid.query.sql.lang.Command)21 Test (org.junit.Test)19 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)16 Annotation (org.teiid.client.plan.Annotation)9 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)9 CommandContext (org.teiid.query.util.CommandContext)8 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)7 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)4 ValidatorReport (org.teiid.query.validator.ValidatorReport)4 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)3 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)3 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)3 GlobalTableStoreImpl (org.teiid.query.tempdata.GlobalTableStoreImpl)3 TeiidComponentException (org.teiid.core.TeiidComponentException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2