Search in sources :

Example 26 with AnalysisRecord

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

the class TestMaterialization method testDefaultMaterializationWithCacheHint.

@Test
public void testDefaultMaterializationWithCacheHint() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup4";
    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.VGROUP4.x FROM #MAT_MATVIEW.VGROUP4" }, 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)

Example 27 with AnalysisRecord

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

the class TestMaterialization method testNoCacheInTransformation.

@Test
public void testNoCacheInTransformation() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT VGROUP.E1 FROM VGROUP";
    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);
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 28 with AnalysisRecord

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

the class TestMaterialization method testDefaultMaterializationWithPK.

@Test
public void testDefaultMaterializationWithPK() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup3 where x = 'foo'";
    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);
    RelationalPlan plan = (RelationalPlan) TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
    assertEquals(1f, plan.getRootNode().getEstimateNodeCardinality());
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT #MAT_MATVIEW.VGROUP3.x, #MAT_MATVIEW.VGROUP3.y FROM #MAT_MATVIEW.VGROUP3 WHERE #MAT_MATVIEW.VGROUP3.x = 'foo'" }, 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) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Example 29 with AnalysisRecord

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

the class TestMaterialization method testManagedMaterializedTransformationUnion.

@Test
public void testManagedMaterializedTransformationUnion() throws Exception {
    // make sure view removal is not inhibited
    // $NON-NLS-1$
    String userSql = "SELECT * FROM ManagedMatView union all SELECT * FROM ManagedMatView";
    QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    BasicSourceCapabilities capabilities = getTypicalCapabilities();
    capabilities.setCapabilitySupport(Capability.QUERY_UNION, true);
    TestOptimizer.helpPlanCommand(command, metadata, new DefaultCapabilitiesFinder(capabilities), analysis, new String[] { // $NON-NLS-1$
    "SELECT g_1.e1 AS c_0 FROM MatTable.MatTable AS g_1 WHERE mvstatus('MatView', 'ManagedMatView') = 1 UNION ALL SELECT g_0.e1 AS c_0 FROM MatTable.MatTable AS g_0" }, ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) Command(org.teiid.query.sql.lang.Command) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 30 with AnalysisRecord

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

the class TestProcedureProcessor method getProcedurePlan.

public static ProcessorPlan getProcedurePlan(String userQuery, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws Exception {
    Command userCommand = QueryParser.getQueryParser().parseCommand(userQuery);
    QueryResolver.resolveCommand(userCommand, metadata);
    ValidatorReport report = Validator.validate(userCommand, metadata);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        throw new QueryValidatorException(firstFailure.getMessage());
    }
    QueryRewriter.rewrite(userCommand, metadata, new CommandContext());
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    try {
        if (capabilitiesFinder == null) {
            capabilitiesFinder = new DefaultCapabilitiesFinder();
        }
        ProcessorPlan plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, capabilitiesFinder, analysisRecord, null);
        return plan;
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) ValidatorReport(org.teiid.query.validator.ValidatorReport)

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