Search in sources :

Example 36 with TransformationMetadata

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

the class TestJoinOptimization method testPathologicalAccessPatternCaseCase2976Defect19018.

/**
 * <p>In RuleBreakMultiJoin terminology:
 * If any of the regions contains a group with any unsatisfied access patterns, one
 * of those access patterns could be satisfied by arranging for a dependent join,
 * provided that group has join criteria which covers the column(s) in an access
 * pattern, and which joins the group to group(s) in other region(s).  The task, then,
 * is to ensure that an ordering isn't picked which makes such a dependent join
 * impossible.</p>
 *
 * <p>A physical group can have zero or more access patterns; each access pattern can have one
 * or more columns.  So a group could implicitly be dependent on one or more other physical
 * groups in one or more other regions.  A table can be used to illustrate the potential
 * complexity of access patterns:
 * <pre>
 * Region with    | Target
 * Access Patterns| Regions
 * -------------------------
 * Reg3           | Reg1, Reg2
 * Reg3           | Reg4
 * Reg1           | Reg2
 * Reg4           | Reg3
 * </pre></p>
 *
 * This tests now passes with RulePlanJoins
 */
@Test
public void testPathologicalAccessPatternCaseCase2976Defect19018() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    // add single access pattern to pm1.g4 containing elements e1, e2, and e3
    Table pm4g1 = metadata.getGroupID("pm4.g1");
    List<Column> cols = new ArrayList<Column>(pm4g1.getColumns());
    cols.remove(2);
    RealMetadataFactory.createKey(Type.AccessPattern, "pm4.g1.ap1", pm4g1, cols);
    String sql = // $NON-NLS-1$
    "SELECT pm1.g1.e1, pm2.g1.e1, pm4.g1.e1 " + // $NON-NLS-1$
    "FROM pm1.g1, pm2.g1, pm4.g1 WHERE " + // $NON-NLS-1$
    "pm1.g1.e1 = pm4.g1.e1 AND pm2.g1.e2 = pm4.g1.e2 AND pm1.g1.e4 = pm2.g1.e4 " + // $NON-NLS-1$
    "AND pm4.g1.e4 = 3.2";
    String[] expected = new String[] { // $NON-NLS-1$
    "SELECT g_0.e4 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", // $NON-NLS-1$
    "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm4.g1 AS g_0 WHERE (g_0.e4 = 3.2) AND (g_0.e1 IN (<dependent values>)) AND (g_0.e2 IN (<dependent values>)) ORDER BY c_0, c_1", // $NON-NLS-1$
    "SELECT g_0.e4 AS c_0, g_0.e2 AS c_1, g_0.e1 AS c_2 FROM pm2.g1 AS g_0 ORDER BY c_0" };
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, metadata, expected, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    1, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    2, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    0, // UnionAll
    0 });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 37 with TransformationMetadata

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

the class TestJoinOptimization method testInnerOuterOptimizationCrossJoin.

@Test
public void testInnerOuterOptimizationCrossJoin() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    String sql = "select pm1.g2.e2, pm1.g3.e2, pm1.g4.e1, pm1.g4.e3 from ((pm1.g2 cross join pm1.g3) inner join pm1.g1 on pm1.g1.e1 = pm1.g2.e1) left outer join pm1.g4 on (pm1.g2.e4 = pm1.g4.e4)";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
    TransformationMetadata tm = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", 1, tm);
    RealMetadataFactory.setCardinality("pm1.g2", 1, tm);
    RealMetadataFactory.setCardinality("pm1.g3", 1, tm);
    // $NON-NLS-1$ //$NON-NLS-2$
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, tm, new String[] { "SELECT g_2.e2, g_0.e2, g_3.e1, g_3.e3 FROM (pm1.g3 AS g_0 CROSS JOIN pm1.g1 AS g_1) INNER JOIN (pm1.g2 AS g_2 LEFT OUTER JOIN pm1.g4 AS g_3 ON g_2.e4 = g_3.e4) ON g_1.e1 = g_2.e1" }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 38 with TransformationMetadata

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

the class TestJoinPushdownRestrictions method testAllowJoinFalse.

@Test
public void testAllowJoinFalse() throws Exception {
    // $NON-NLS-1$
    String sql = "select a.e1, b.e1 from pm4.g1 a, pm4.g2 b where a.e1 = b.e1 and a.e2 = b.e2";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    caps.setSourceProperty(Capability.JOIN_CRITERIA_ALLOWED, SupportedJoinCriteria.KEY);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm4", caps);
    TransformationMetadata example4 = RealMetadataFactory.example4();
    example4.getMetadataStore().getSchema("pm4").getTable("g2").getForeignKeys().get(0).setProperty(ForeignKey.ALLOW_JOIN, Boolean.FALSE.toString());
    TestOptimizer.helpPlan(sql, example4, new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm4.g1 AS g_0 ORDER BY c_0, c_1", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm4.g2 AS g_0 ORDER BY c_0, c_1" }, capFinder, // $NON-NLS-1$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Test(org.junit.Test)

Example 39 with TransformationMetadata

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

the class TestSortOptimization method testOrderedLimitOvewPreservedView.

@Test
public void testOrderedLimitOvewPreservedView() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table x (a string, b string, c integer, primary key (a, b)) options (updatable true); " + "create view SvcView (RowId integer PRIMARY KEY, code string, name string) as select c as x, a, b from x limit 2;", "x", "y");
    String sql = "select rowid, code, name from svcview order by rowid limit 1 ";
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.c, g_0.a, g_0.b FROM y.x AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.c, g_0.a, g_0.b FROM y.x AS g_0", Arrays.asList(1, "x", "a"), Arrays.asList(2, "z", "b"));
    List<?>[] expected = new List<?>[] { Arrays.asList(1, "x", "a") };
    helpProcess(plan, dataManager, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) List(java.util.List) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 40 with TransformationMetadata

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

the class TestSubqueryPushdown method testNManySubqueryProcessingFalsePredicate.

@Test
public void testNManySubqueryProcessingFalsePredicate() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT INTKEY, FLOATNUM FROM BQT1.SMALLA AS A WHERE FLOATNUM = /*+ NO_UNNEST */ (SELECT MIN(FLOATNUM) FROM BQT1.SMALLA AS B WHERE (INTKEY >= 9) AND (A.INTKEY = B.INTKEY))";
    TransformationMetadata metadata = RealMetadataFactory.exampleBQT();
    HardcodedDataManager dataMgr = new HardcodedDataManager(metadata);
    dataMgr.addData("SELECT g_0.FloatNum, g_0.IntKey FROM SmallA AS g_0", Arrays.asList(.1f, 1));
    dataMgr.addData("SELECT MIN(g_0.FloatNum) FROM SmallA AS g_0 WHERE g_0.IntKey >= 9 AND g_0.IntKey = 1");
    BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
    bsc.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
    bsc.setCapabilitySupport(Capability.CRITERIA_ONLY_LITERAL_COMPARE, true);
    ProcessorPlan pp = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(bsc));
    TestProcessor.helpProcess(pp, dataMgr, new List[] {});
    sql = "SELECT INTKEY, STRINGKEY, DOUBLENUM FROM BQT1.SMALLA GROUP BY INTKEY, STRINGKEY, DOUBLENUM HAVING DOUBLENUM = /*+ NO_UNNEST */ (SELECT DOUBLENUM FROM BQT1.SMALLA WHERE STRINGKEY = 20)";
    pp = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(bsc));
    dataMgr.clearData();
    dataMgr.addData("SELECT g_0.DoubleNum FROM SmallA AS g_0 WHERE g_0.StringKey = '20'");
    TestProcessor.helpProcess(pp, dataMgr, new List[] {});
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) 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