Search in sources :

Example 56 with SymbolMap

use of org.teiid.query.sql.util.SymbolMap in project teiid by teiid.

the class TestFrameUtil method testJoinGroups.

@Test
public void testJoinGroups() throws Exception {
    PlanNode joinNode = getExamplePlan();
    PlanNode projectNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    e1.setGroupSymbol(getGroup(3));
    projectNode.setProperty(Info.PROJECT_COLS, Arrays.asList(e1));
    projectNode.addFirstChild(joinNode);
    projectNode.addGroup(getGroup(3));
    PlanNode sourceNode = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
    sourceNode.addFirstChild(projectNode);
    GroupSymbol four = getGroup(4);
    sourceNode.addGroup(four);
    // $NON-NLS-1$
    ElementSymbol e2 = new ElementSymbol("e2");
    e2.setGroupSymbol(four);
    SymbolMap sm = SymbolMap.createSymbolMap(Arrays.asList(e2), Arrays.asList(e1));
    sourceNode.setProperty(Info.SYMBOL_MAP, sm);
    PlanNode projectNode1 = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
    projectNode1.addFirstChild(sourceNode);
    projectNode1.addGroup(four);
    projectNode1.setProperty(Info.PROJECT_COLS, Arrays.asList(e2));
    // removing source node 3 completely
    SymbolMap replacement = SymbolMap.createSymbolMap(Arrays.asList(e1), Arrays.asList(new Constant(null)));
    FrameUtil.convertFrame(NodeEditor.findNodePreOrder(joinNode, NodeConstants.Types.SOURCE), getGroup(3), null, replacement.asMap(), null);
    // even though this is a cross join it should still retain its groups
    assertEquals(2, joinNode.getGroups().size());
    assertEquals(0, NodeEditor.findNodePreOrder(joinNode, NodeConstants.Types.SELECT).getGroups().size());
    assertEquals(1, projectNode1.getGroups().size());
    assertEquals(0, projectNode.getGroups().size());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SymbolMap(org.teiid.query.sql.util.SymbolMap) Test(org.junit.Test)

Aggregations

SymbolMap (org.teiid.query.sql.util.SymbolMap)56 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)37 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)28 Expression (org.teiid.query.sql.symbol.Expression)28 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)21 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Criteria (org.teiid.query.sql.lang.Criteria)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 HashMap (java.util.HashMap)6 Constant (org.teiid.query.sql.symbol.Constant)6 LinkedHashSet (java.util.LinkedHashSet)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)5 OrderBy (org.teiid.query.sql.lang.OrderBy)5 HashSet (java.util.HashSet)4 ExpressionMappingVisitor (org.teiid.query.sql.visitor.ExpressionMappingVisitor)4 LinkedHashMap (java.util.LinkedHashMap)3 Set (java.util.Set)3