Search in sources :

Example 66 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityWithKeyComplexCrit3.

@Test
public void testCardinalityWithKeyComplexCrit3() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    GroupSymbol group1 = getPhysicalGroup(1, 2);
    ElementSymbol g1e2 = getElementSymbol(1, 2, 2);
    GroupSymbol group2 = getPhysicalGroup(3, 3);
    ElementSymbol g2e1 = getElementSymbol(3, 3, 1);
    ElementSymbol g2e2 = getElementSymbol(3, 3, 2);
    // Join criteria
    ArrayList crits = new ArrayList(1);
    crits.add(new CompareCriteria(g1e2, CompareCriteria.EQ, g2e2));
    Criteria atomicCrit1 = null;
    Criteria crit1 = new CompareCriteria(g2e1, CompareCriteria.GE, new Constant(new Integer(5)));
    Criteria crit2 = new CompareCriteria(g2e1, CompareCriteria.NE, new Constant(new Integer(7)));
    Criteria atomicCrit2 = new CompoundCriteria(CompoundCriteria.OR, crit1, crit2);
    atomicCrit2 = new NotCriteria(atomicCrit2);
    Criteria crit3 = new CompareCriteria(g2e1, CompareCriteria.LE, new Constant(new Integer(25)));
    atomicCrit2 = new CompoundCriteria(CompoundCriteria.AND, atomicCrit2, crit3);
    int expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group2, atomicCrit2, crits, expected);
    expected = RIGHT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group2, atomicCrit2, group1, atomicCrit1, crits, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 67 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityAndKey.

/**
 * Tests that heuristics will take cardinality of a group into account when
 * making a dependent join, and that this information supercedes a key
 * in the atomic criteria.
 */
@Test
public void testCardinalityAndKey() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    GroupSymbol group1 = getPhysicalGroup(1, 2);
    GroupSymbol group2 = getPhysicalGroup(2, 2);
    // Join criteria
    ElementSymbol pm1g2e1 = getElementSymbol(1, 2, 1);
    ElementSymbol pm2g2e1 = getElementSymbol(2, 2, 1);
    CompareCriteria crit = new CompareCriteria(pm2g2e1, CompareCriteria.EQ, pm1g2e1);
    ArrayList crits = new ArrayList(1);
    crits.add(crit);
    ElementSymbol pm1g2e2 = getElementSymbol(1, 2, 2);
    ElementSymbol pm2g2e2 = getElementSymbol(2, 2, 2);
    CompareCriteria crit2 = new CompareCriteria(pm1g2e2, CompareCriteria.EQ, pm2g2e2);
    crits.add(crit2);
    Criteria atomicCrit1 = null;
    Criteria atomicCrit2 = null;
    int expected = RIGHT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group2, atomicCrit2, crits, expected);
    expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group2, atomicCrit2, group1, atomicCrit1, crits, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 68 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityWithCriteriaAndJoin.

/**
 * Tests that join side with larger cardinality will still have a lower
 * cost computed because it has a criteria including a primary key
 */
@Test
public void testCardinalityWithCriteriaAndJoin() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    // no key
    GroupSymbol group1 = getPhysicalGroup(2, 2);
    GroupSymbol group1a = null;
    // has key
    GroupSymbol group2 = getPhysicalGroup(3, 3);
    // has key
    GroupSymbol group2a = getPhysicalGroup(3, 1);
    ElementSymbol group1e1 = getElementSymbol(2, 2, 1);
    ElementSymbol group2e1 = getElementSymbol(3, 3, 1);
    ElementSymbol group2e2 = getElementSymbol(3, 3, 2);
    ElementSymbol group2ae1 = getElementSymbol(3, 1, 1);
    ElementSymbol group2ae2 = getElementSymbol(3, 1, 2);
    // Outer Join criteria
    CompareCriteria crit = new CompareCriteria(group2e1, CompareCriteria.EQ, group1e1);
    ArrayList crits = new ArrayList(1);
    crits.add(crit);
    // atomic select criteria
    Criteria atomicCrit1 = null;
    Criteria atomicCrit1a = null;
    Criteria atomicCrit2 = new CompareCriteria(group2e1, CompareCriteria.EQ, new Constant(new Integer(5)));
    Criteria atomicCrit2a = new CompareCriteria(group2ae1, CompareCriteria.EQ, new Constant(new Integer(5)));
    // atomic Join criteria 1
    Collection atomicJoinCrits1 = null;
    // atomic Join criteria 2
    CompareCriteria atomicJoinCrit2 = new CompareCriteria(group2ae2, CompareCriteria.EQ, group2e2);
    ArrayList atomicJoinCrits2 = new ArrayList(1);
    atomicJoinCrits2.add(atomicJoinCrit2);
    int expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group1a, atomicCrit1a, atomicJoinCrits1, group2, atomicCrit2, group2a, atomicCrit2a, atomicJoinCrits2, crits, expected, 1000, 1);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 69 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestRuleChooseDependent method getPhysicalGroupWithAlias.

public GroupSymbol getPhysicalGroupWithAlias(int num, String alias) throws Exception {
    // $NON-NLS-1$
    String id = "pm1.g" + num;
    GroupSymbol gs = new GroupSymbol(alias, id);
    ResolverUtil.resolveGroup(gs, metadata);
    return gs;
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 70 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityWithKeyIsNullCrit.

/**
 * Tests SetCriteria in the atomic criteria
 */
@Test
public void testCardinalityWithKeyIsNullCrit() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    GroupSymbol group1 = getPhysicalGroup(1, 2);
    ElementSymbol g1e2 = getElementSymbol(1, 2, 2);
    GroupSymbol group2 = getPhysicalGroup(3, 3);
    ElementSymbol g2e1 = getElementSymbol(3, 3, 1);
    ElementSymbol g2e2 = getElementSymbol(3, 3, 2);
    // Join criteria
    ArrayList crits = new ArrayList(1);
    CompareCriteria crit2 = new CompareCriteria(g1e2, CompareCriteria.EQ, g2e2);
    crits.add(crit2);
    Criteria atomicCrit1 = null;
    Criteria atomicCrit2 = new IsNullCriteria(g2e1);
    int expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group2, atomicCrit2, crits, expected);
    expected = RIGHT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group2, atomicCrit2, group1, atomicCrit1, crits, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)299 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)146 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)92 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)59 Expression (org.teiid.query.sql.symbol.Expression)52 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 Constant (org.teiid.query.sql.symbol.Constant)48 List (java.util.List)43 HashSet (java.util.HashSet)32 Query (org.teiid.query.sql.lang.Query)31 From (org.teiid.query.sql.lang.From)29 SymbolMap (org.teiid.query.sql.util.SymbolMap)29 Select (org.teiid.query.sql.lang.Select)26 Criteria (org.teiid.query.sql.lang.Criteria)22 TempMetadataID (org.teiid.query.metadata.TempMetadataID)21 LinkedList (java.util.LinkedList)20 Command (org.teiid.query.sql.lang.Command)20 Set (java.util.Set)17 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)17