Search in sources :

Example 31 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestDependentJoins method testRLMCase2077_2.

@Test
public void testRLMCase2077_2() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_SEARCHED_CASE, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setCapabilitySupport(Capability.ARRAY_TYPE, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
    // $NON-NLS-1$
    caps.setFunctionSupport("||", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT2", caps);
    TransformationMetadata metadata = RealMetadataFactory.exampleBQT();
    // $NON-NLS-1$
    RealMetadataFactory.setCardinality("bqt1.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    // $NON-NLS-1$
    RealMetadataFactory.setCardinality("bqt2.smalla", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    ProcessorPlan plan = TestOptimizer.helpPlan(// $NON-NLS-1$
    "SELECT table1comp.IntKey, table1comp.key1, BQT1.SmallA.StringKey FROM (SELECT t1.*, (STRINGKEY || STRINGNUM) AS key1 FROM BQT2.SmallA AS t1) AS table1comp, BQT1.SmallA WHERE table1comp.key1 = BQT1.SmallA.StringKey AND table1comp.key1 = BQT1.SmallA.StringNum", metadata, null, capFinder, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "SELECT g_0.StringKey, g_0.StringNum, g_0.IntKey FROM BQT2.SmallA AS g_0", "SELECT g_0.StringKey, g_0.StringNum FROM BQT1.SmallA AS g_0 WHERE (g_0.StringNum = g_0.StringKey) AND (g_0.StringKey IN (<dependent values>))" }, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    1, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    2, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 32 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestEqualityOnly method testPushdown.

@Test
public void testPushdown() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table t (x string options (searchable 'equality_only'))", "x", "y");
    // should push
    TestOptimizer.helpPlan("select x from t where x = 'a'", tm, new String[] { "SELECT g_0.x FROM y.t AS g_0 WHERE g_0.x = 'a'" });
    // should not push
    TestOptimizer.helpPlan("select x from t where x > 'b'", tm, new String[] { "SELECT g_0.x FROM y.t AS g_0" });
    TestOptimizer.helpPlan("select x from t where x like 'c%'", tm, new String[] { "SELECT g_0.x FROM y.t AS g_0" });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Test(org.junit.Test)

Example 33 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestJoinOptimization method testLateralProcedurePushdown.

@Test
public void testLateralProcedurePushdown() throws Exception {
    String sql = "select smallb.intkey, x.stringkey, x.intkey " + // $NON-NLS-1$
    "from smallb left outer join lateral (exec spTest5(smallb.intkey)) as x on (true)";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.ROW_LIMIT, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_PROCEDURE_TABLE, true);
    bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    bsc.setCapabilitySupport(Capability.QUERY_ONLY_FROM_JOIN_LATERAL_PROCEDURE, true);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table smallb (intkey integer, stringkey string); " + "create foreign procedure spTest5 (param integer) returns table(stringkey string, intkey integer)", "x", "y");
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.intkey, v_0.stringkey, v_0.intkey FROM y.smallb AS g_0 LEFT OUTER JOIN LATERAL(EXEC spTest5(g_0.intkey)) AS v_0 ON 1 = 1" }, new DefaultCapabilitiesFinder(bsc), // $NON-NLS-1$ //$NON-NLS-2$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    hdm.addData("SELECT g_0.intkey, v_0.stringkey, v_0.intkey FROM smallb AS g_0 LEFT OUTER JOIN LATERAL (EXEC spTest5(g_0.intkey)) AS v_0 ON 1 = 1", Arrays.asList(1, "2", 1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1, "2", 1) });
    bsc.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
    // with an extra inline view, should result in same plan - but is not currently as we can't remove the intermediate view without
    // a lot of work
    sql = "SELECT g_0.intkey, v_1.c_0, v_1.c_1 FROM y.smallb AS g_0 LEFT OUTER JOIN LATERAL(SELECT v_0.stringkey AS c_0, v_0.intkey AS c_1 FROM (EXEC spTest5(g_0.intkey)) AS v_0 limit 1) AS v_1 ON 1 = 1";
    plan = TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.intkey FROM y.smallb AS g_0", "EXEC spTest5(g_0.intkey)" }, new DefaultCapabilitiesFinder(bsc), // $NON-NLS-1$ //$NON-NLS-2$
    ComparisonMode.EXACT_COMMAND_STRING);
    hdm.addData("SELECT g_0.intkey FROM smallb AS g_0", Arrays.asList(1));
    hdm.addData("EXEC spTest5(1)", Arrays.asList("2", 1));
    TestProcessor.helpProcess(plan, hdm, new List<?>[] { Arrays.asList(1, "2", 1) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 34 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestJoinOptimization method testDistinctDetectionWithUnion.

@Test
public void testDistinctDetectionWithUnion() throws Exception {
    String sql = "select avg(t1.a) from (select 3 as a, 3 as b union " + "select 1 as a, 1 as b union select 3 as a, 3 as b) as t1 " + "join (select 1 as a, 1 as b union all select 1 as a, 1 as b union all " + "select 2 as a, 2 as b union all select 2 as a, 2 as b union all " + "select 3 as a, 3 as b union all select 3 as a, 3 as b) as t2 on t1.a=t2.a";
    TransformationMetadata metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager hdm = new HardcodedDataManager();
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);
    TestProcessor.helpProcess(plan, TestProcessor.createCommandContext(), hdm, new List<?>[] { Arrays.asList(BigDecimal.valueOf(2)) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 35 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestJoinOptimization method testLateralOnlyProcedurePushdown.

@Test
public void testLateralOnlyProcedurePushdown() throws Exception {
    String sql = "select smallb.intkey, x.stringkey, x.intkey " + // $NON-NLS-1$
    "from smallb left outer join lateral (select * from smalla where intkey = smallb.intkey) as x on (true)";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, true);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_PROCEDURE_TABLE, true);
    bsc.setCapabilitySupport(Capability.QUERY_ONLY_FROM_JOIN_LATERAL_PROCEDURE, true);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table smallb (intkey integer, stringkey string); " + "create foreign table smalla (intkey integer, stringkey string);", "x", "y");
    TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.stringkey, g_0.intkey FROM y.smalla AS g_0 WHERE g_0.intkey = y.smallb.intkey", "SELECT g_0.intkey FROM y.smallb AS g_0" }, new DefaultCapabilitiesFinder(bsc), // $NON-NLS-1$ //$NON-NLS-2$
    ComparisonMode.EXACT_COMMAND_STRING);
    bsc.setCapabilitySupport(Capability.QUERY_ONLY_FROM_JOIN_LATERAL_PROCEDURE, false);
    TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.intkey, v_0.c_0, v_0.c_1 FROM y.smallb AS g_0 LEFT OUTER JOIN LATERAL(SELECT g_1.stringkey AS c_0, g_1.intkey AS c_1 FROM y.smalla AS g_1 WHERE g_1.intkey = g_0.intkey) AS v_0 ON 1 = 1" }, new DefaultCapabilitiesFinder(bsc), // $NON-NLS-1$ //$NON-NLS-2$
    ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20