Package org.teiid.query.sql.util

Examples of org.teiid.query.sql.util.SymbolMap


                //if a source has access patterns that are unsatisfied, then the raise cannot occur
                if (parentNode.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS)) {
                    return null;
                }
               
                SymbolMap references = (SymbolMap)parentNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
                if (references != null) {
                  return null;
                }
               
                //raise only if there is no intervening project into
View Full Code Here


                            CommandContext context) throws QueryPlannerException,
                                                   QueryMetadataException,
                                                   TeiidComponentException {
     
      for (PlanNode sourceNode : NodeEditor.findAllNodes(plan, NodeConstants.Types.SOURCE, NodeConstants.Types.ACCESS)) {
        SymbolMap references = (SymbolMap)sourceNode.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
          if (references != null) {
            Set<GroupSymbol> groups = GroupsUsedByElementsVisitor.getGroups(references.getValues());
            PlanNode joinNode = NodeEditor.findParent(sourceNode, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE);
            while (joinNode != null) {
              joinNode.setProperty(NodeConstants.Info.JOIN_STRATEGY, JoinStrategyType.NESTED_TABLE);
              if (joinNode.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE) != null) {
                //sanity check
View Full Code Here

    boolean cardinalityDependent = AggregateSymbol.areAggregatesCardinalityDependent(aggregates);

    LinkedList<PlanNode> unionChildren = new LinkedList<PlanNode>();
    findUnionChildren(unionChildren, cardinalityDependent, setOp);

    SymbolMap parentMap = (SymbolMap)child.getProperty(NodeConstants.Info.SYMBOL_MAP);

    //partitioned union
    if (partitionInfo != null && !Collections.disjoint(partitionInfo.keySet(), groupingExpressions)) {
      decomposeGroupBy(groupNode, child, groupingExpressions, aggregates, unionChildren, parentMap, context, metadata, capFinder);
      return;
    }

    /*
     * if there are no aggregates, this is just duplicate removal
     * mark the union as not all, which should be removed later but
     * serves as a hint to distribute a distinct to the union queries
     */
    if (aggregates.isEmpty()) {
      if (groupingExpressions != null && !groupingExpressions.isEmpty()) {
        setOp.setProperty(NodeConstants.Info.USE_ALL, Boolean.FALSE);
      }
      return;
    }
   
    //TODO: merge virtual, plan unions, raise null - change the partition information
   
    if (unionChildren.size() < 2) {
      return;
    }
   
    List<ElementSymbol> virtualElements = parentMap.getKeys();
    List<SingleElementSymbol> copy = new ArrayList<SingleElementSymbol>(aggregates);
    aggregates.clear();
    Map<AggregateSymbol, Expression> aggMap = buildAggregateMap(copy, metadata, aggregates);

    boolean shouldPushdown = false;
    List<Boolean> pushdownList = new ArrayList<Boolean>(unionChildren.size());
    for (PlanNode planNode : unionChildren) {
      boolean pushdown = canPushGroupByToUnionChild(metadata, capFinder, groupingExpressions, aggregates, planNode);
      pushdownList.add(pushdown);
      shouldPushdown |= pushdown;
    }
   
    if (!shouldPushdown) {
      return;
    }

    Iterator<Boolean> pushdownIterator = pushdownList.iterator();
    for (PlanNode planNode : unionChildren) {
        addView(plan, planNode, pushdownIterator.next(), groupingExpressions, aggregates, virtualElements, metadata, capFinder);
    }
   
    //update the parent plan with the staged aggregates and the new projected symbols
    List<SingleElementSymbol> projectedViewSymbols = (List<SingleElementSymbol>)NodeEditor.findNodePreOrder(child, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS);
    List<ElementSymbol> updatedVirturalElement = new ArrayList<ElementSymbol>(virtualElements);
   
    //hack to introduce aggregate symbols to the parent view TODO: this should change the metadata properly.
    GroupSymbol virtualGroup = child.getGroups().iterator().next();
    for (int i = updatedVirturalElement.size(); i < projectedViewSymbols.size(); i++) {
      SingleElementSymbol symbol = projectedViewSymbols.get(i);
      String name = symbol.getShortName();
            String virtualElementName = virtualGroup.getCanonicalName() + ElementSymbol.SEPARATOR + name;
            ElementSymbol virtualElement = new ElementSymbol(virtualElementName);
            virtualElement.setGroupSymbol(virtualGroup);
            virtualElement.setType(symbol.getType());
            virtualElement.setMetadataID(new TempMetadataID(virtualElementName, symbol.getType()));
            updatedVirturalElement.add(virtualElement);
    }
    SymbolMap newParentMap = SymbolMap.createSymbolMap(updatedVirturalElement, projectedViewSymbols);
    child.setProperty(NodeConstants.Info.SYMBOL_MAP, newParentMap);
    Map<AggregateSymbol, ElementSymbol> projectedMap = new HashMap<AggregateSymbol, ElementSymbol>();
    Iterator<AggregateSymbol> aggIter = aggregates.iterator();
    for (ElementSymbol projectedViewSymbol : newParentMap.getKeys().subList(projectedViewSymbols.size() - aggregates.size(), projectedViewSymbols.size())) {
      projectedMap.put(aggIter.next(), projectedViewSymbol);
    }
    for (Expression expr : aggMap.values()) {
      ExpressionMappingVisitor.mapExpressions(expr, projectedMap);
    }
View Full Code Here

              //continue to raise
            }
        }
    }
    GroupSymbol modifiedGroup = group.clone();
    SymbolMap symbolMap = createSymbolMap(modifiedGroup, symbols, sourceNode, metadata);
    sourceNode.setProperty(Info.SYMBOL_MAP, symbolMap);
   
    FrameUtil.convertFrame(sourceNode, group, Collections.singleton(modifiedGroup), symbolMap.inserseMapping(), metadata);
  }
View Full Code Here

      }
    }
    GroupSymbol group = new GroupSymbol("X"); //$NON-NLS-1$
       
    PlanNode intermediateView = createView(group, virtualElements, unionSource, metadata);
      SymbolMap symbolMap = (SymbolMap)intermediateView.getProperty(Info.SYMBOL_MAP);
      unionSource = intermediateView;
     
        Set<SingleElementSymbol> newGroupingExpressions = Collections.emptySet();
        if (groupingExpressions != null) {
          newGroupingExpressions = new HashSet<SingleElementSymbol>();
          for (SingleElementSymbol singleElementSymbol : groupingExpressions) {
        newGroupingExpressions.add((SingleElementSymbol)symbolMap.getKeys().get(virtualElements.indexOf(singleElementSymbol)).clone());
      }
        }

        List<SingleElementSymbol> projectedViewSymbols = Util.deepClone(symbolMap.getKeys(), SingleElementSymbol.class);

        PlanNode parent = NodeEditor.findParent(unionSource, NodeConstants.Types.SOURCE);
        SymbolMap parentMap = (SymbolMap) parent.getProperty(NodeConstants.Info.SYMBOL_MAP);
        SymbolMap viewMapping = SymbolMap.createSymbolMap(parentMap.getKeys(), projectedViewSymbols);
        for (AggregateSymbol agg : aggregates) {
          agg = (AggregateSymbol)agg.clone();
          ExpressionMappingVisitor.mapExpressions(agg, viewMapping.asMap());
          if (pushdown) {
            projectedViewSymbols.add(agg);
          } else {
            if (agg.getAggregateFunction() == Type.COUNT) {
              if (agg.getExpression() == null) {
View Full Code Here

        }
    }
 
  static PlanNode createView(GroupSymbol group, List<? extends SingleElementSymbol> virtualElements, PlanNode child, QueryMetadataInterface metadata) throws TeiidComponentException {
    PlanNode intermediateView = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
      SymbolMap symbolMap = createSymbolMap(group, virtualElements, child, metadata);
      intermediateView.setProperty(NodeConstants.Info.SYMBOL_MAP, symbolMap);
      child.addAsParent(intermediateView);
      intermediateView.addGroup(group);
      return intermediateView;
  }
View Full Code Here

      group.setMetadataID(ResolverUtil.addTempGroup(tma, group, virtualElements, false));
    } catch (QueryResolverException e) {
      throw new TeiidComponentException(e);
    }
      List<ElementSymbol> projectedSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
      SymbolMap symbolMap = SymbolMap.createSymbolMap(projectedSymbols,
        (List<Expression>)NodeEditor.findNodePreOrder(child, NodeConstants.Types.PROJECT).getProperty(NodeConstants.Info.PROJECT_COLS));
    return symbolMap;
  }
View Full Code Here

    }

    PlanNode newUnion = buildUnion(unionNode, right, criteria, matches, branches, otherBranches);
    PlanNode view = rebuild(left.getGroups().iterator().next(), joinNode, newUnion, metadata, context, left, right);

    SymbolMap symbolmap = (SymbolMap)view.getProperty(Info.SYMBOL_MAP);
    HashMap<ElementSymbol, List<Set<Constant>>> newPartitionInfo = new LinkedHashMap<ElementSymbol, List<Set<Constant>>>();
    for (int[] match : matches) {
      updatePartitionInfo(partitionInfo, matches, symbolmap, newPartitionInfo, 0, match[0]);
      updatePartitionInfo(rightPartionInfo, matches, symbolmap, newPartitionInfo, partitionInfo.size(), match[1]);
    }
View Full Code Here

    PlanNode projectNode = NodeEditor.findNodePreOrder(newUnion, NodeConstants.Types.PROJECT);
    List<? extends SingleElementSymbol> projectedSymbols = (List<? extends SingleElementSymbol>)projectNode.getProperty(Info.PROJECT_COLS);

    PlanNode view = RulePushAggregates.createView(group, projectedSymbols, newUnion, metadata);
   
    SymbolMap newSymbolMap = (SymbolMap)view.getProperty(Info.SYMBOL_MAP);
   
    Map<Expression, ElementSymbol> inverseMap = newSymbolMap.inserseMapping();
    toReplace.getParent().replaceChild(toReplace, view);
    Set<GroupSymbol> newGroups = Collections.singleton(group);
    for (PlanNode node : toMap) {
      FrameUtil.convertFrame(view, node.getGroups().iterator().next(), newGroups, inverseMap, metadata);
    }
View Full Code Here

  }

  private PlanNode buildUnion(PlanNode unionNode, PlanNode otherSide,
      List<Criteria> criteria, List<int[]> matches,
      List<PlanNode> branches, List<PlanNode> otherBranches) {
    SymbolMap symbolMap = (SymbolMap)unionNode.getParent().getProperty(Info.SYMBOL_MAP);
    SymbolMap otherSymbolMap = (SymbolMap)otherSide.getProperty(Info.SYMBOL_MAP);

    List<PlanNode> joins = new LinkedList<PlanNode>();
    for (int i = 0; i < matches.size(); i++) {
      int[] is = matches.get(i);
      PlanNode branch = branches.get(is[0]);
      PlanNode branchSource = createSource(unionNode.getParent().getGroups().iterator().next(), branch, symbolMap);
     
      PlanNode otherBranch = otherBranches.get(is[1]);
      PlanNode otherBranchSource = createSource(otherSide.getGroups().iterator().next(), otherBranch, otherSymbolMap);
     
      PlanNode newJoinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
      newJoinNode.addLastChild(branchSource);
      newJoinNode.addLastChild(otherBranchSource);
     
      newJoinNode.setProperty(Info.JOIN_STRATEGY, JoinStrategyType.NESTED_LOOP);
      newJoinNode.setProperty(Info.JOIN_TYPE, JoinType.JOIN_INNER);
      newJoinNode.setProperty(Info.JOIN_CRITERIA, LanguageObject.Util.deepClone(criteria, Criteria.class));
      newJoinNode.addGroups(branchSource.getGroups());
      newJoinNode.addGroups(otherBranchSource.getGroups());
     
      PlanNode projectPlanNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
      newJoinNode.addAsParent(projectPlanNode);
     
      Select allSymbols = new Select(symbolMap.getKeys());
      allSymbols.addSymbols(otherSymbolMap.getKeys());
      if (i == 0) {
        QueryRewriter.makeSelectUnique(allSymbols, false);
      }
      projectPlanNode.setProperty(NodeConstants.Info.PROJECT_COLS, allSymbols.getSymbols());
          projectPlanNode.addGroups(newJoinNode.getGroups());
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.util.SymbolMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.