Package org.eigenbase.rel

Examples of org.eigenbase.rel.RelNode


    LinkedHashMap<RelNode, ImmutableMap<String, Integer>> relToHiveColNameOptiqPosMap = new LinkedHashMap<RelNode, ImmutableMap<String, Integer>>();

    private ASTNode getOptimizedAST(Map<String, PrunedPartitionList> partitionCache)
        throws SemanticException {
      ASTNode optiqOptimizedAST = null;
      RelNode optimizedOptiqPlan = null;
      this.partitionCache = partitionCache;

      try {
        optimizedOptiqPlan = Frameworks.withPlanner(this,
            Frameworks.newConfigBuilder().typeSystem(new HiveTypeSystemImpl()).build());
View Full Code Here


          || t instanceof UndeclaredThrowableException;
    }

    @Override
    public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
      RelNode optiqGenPlan = null;
      RelNode optiqPreCboPlan = null;
      RelNode optiqOptimizedPlan = null;

      /*
       * recreate cluster, so that it picks up the additional traitDef
       */
      RelOptPlanner planner = HiveVolcanoPlanner.createPlanner();
      final RelOptQuery query = new RelOptQuery(planner);
      final RexBuilder rexBuilder = cluster.getRexBuilder();
      cluster = query.createCluster(rexBuilder.getTypeFactory(), rexBuilder);

      this.cluster = cluster;
      this.relOptSchema = relOptSchema;

      try {
        optiqGenPlan = genLogicalPlan(qb, true);
        topLevelFieldSchema = convertRowSchemaToResultSetSchema(relToHiveRR.get(optiqGenPlan),
            HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_RESULTSET_USE_UNIQUE_COLUMN_NAMES));
      } catch (SemanticException e) {
        semanticException = e;
        throw new RuntimeException(e);
      }

      optiqPreCboPlan = applyPreCBOTransforms(optiqGenPlan, HiveDefaultRelMetadataProvider.INSTANCE);
      List<RelMetadataProvider> list = Lists.newArrayList();
      list.add(HiveDefaultRelMetadataProvider.INSTANCE);
      RelTraitSet desiredTraits = cluster.traitSetOf(HiveRel.CONVENTION, RelCollationImpl.EMPTY);

      HepProgram hepPgm = null;
      HepProgramBuilder hepPgmBldr = new HepProgramBuilder().addMatchOrder(HepMatchOrder.BOTTOM_UP)
          .addRuleInstance(new ConvertMultiJoinRule(HiveJoinRel.class));
      hepPgmBldr.addRuleInstance(new LoptOptimizeJoinRule(HiveJoinRel.HIVE_JOIN_FACTORY,
          HiveProjectRel.DEFAULT_PROJECT_FACTORY, HiveFilterRel.DEFAULT_FILTER_FACTORY));

      hepPgm = hepPgmBldr.build();
      HepPlanner hepPlanner = new HepPlanner(hepPgm);

      hepPlanner.registerMetadataProviders(list);
      RelMetadataProvider chainedProvider = ChainedRelMetadataProvider.of(list);
      cluster.setMetadataProvider(new CachingRelMetadataProvider(chainedProvider, hepPlanner));

      RelNode rootRel = optiqPreCboPlan;
      hepPlanner.setRoot(rootRel);
      if (!optiqPreCboPlan.getTraitSet().equals(desiredTraits)) {
        rootRel = hepPlanner.changeTraits(optiqPreCboPlan, desiredTraits);
      }
      hepPlanner.setRoot(rootRel);
View Full Code Here

    }

    private RelNode hepPlan(RelNode basePlan, boolean followPlanChanges,
        RelMetadataProvider mdProvider, RelOptRule... rules) {

      RelNode optimizedRelNode = basePlan;
      HepProgramBuilder programBuilder = new HepProgramBuilder();
      if (followPlanChanges) {
        programBuilder.addMatchOrder(HepMatchOrder.TOP_DOWN);
        programBuilder = programBuilder.addRuleCollection(ImmutableList.copyOf(rules));
      } else {
View Full Code Here

        }
      }

      // 5. Introduce Project Rel above original left/right inputs if cast is
      // needed for type parity
      RelNode unionLeftInput = leftRel;
      RelNode unionRightInput = rightRel;
      if (leftNeedsTypeCast) {
        unionLeftInput = HiveProjectRel.create(leftRel, leftProjs, leftRel.getRowType()
            .getFieldNames());
      }
      if (rightNeedsTypeCast) {
View Full Code Here

      return unionRel;
    }

    private RelNode genJoinRelNode(RelNode leftRel, RelNode rightRel, JoinType hiveJoinType,
        ASTNode joinCond) throws SemanticException {
      RelNode joinRel = null;

      // 1. construct the RowResolver for the new Join Node by combining row
      // resolvers from left, right
      RowResolver leftRR = this.relToHiveRR.get(leftRel);
      RowResolver rightRR = this.relToHiveRR.get(rightRel);
View Full Code Here

     * @return
     * @throws SemanticException
     */
    private RelNode genJoinLogicalPlan(ASTNode joinParseTree, Map<String, RelNode> aliasToRel)
        throws SemanticException {
      RelNode leftRel = null;
      RelNode rightRel = null;
      JoinType hiveJoinType = null;

      if (joinParseTree.getToken().getType() == HiveParser.TOK_UNIQUEJOIN) {
        String msg = String.format("UNIQUE JOIN is currently not supported in CBO,"
            + " turn off cbo to use UNIQUE JOIN.");
View Full Code Here

      ImmutableMap<String, Integer> hiveColNameOptiqPosMap = this.relToHiveColNameOptiqPosMap
          .get(srcRel);
      RexNode convertedFilterExpr = new RexNodeConverter(cluster, srcRel.getRowType(),
          hiveColNameOptiqPosMap, 0, true).convert(filterCondn);
      RexNode factoredFilterExpr = RexUtil.pullFactors(cluster.getRexBuilder(), convertedFilterExpr);
      RelNode filterRel = new HiveFilterRel(cluster, cluster.traitSetOf(HiveRel.CONVENTION),
          srcRel, factoredFilterExpr);
      this.relToHiveColNameOptiqPosMap.put(filterRel, hiveColNameOptiqPosMap);
      relToHiveRR.put(filterRel, relToHiveRR.get(srcRel));
      relToHiveColNameOptiqPosMap.put(filterRel, hiveColNameOptiqPosMap);
View Full Code Here

          QB qbSQ = new QB(subQuery.getOuterQueryId(), subQuery.getAlias(), true);
          qbSQ.setSubQueryDef(subQuery.getSubQuery());
          Phase1Ctx ctx_1 = initPhase1Ctx();
          doPhase1(subQuery.getSubQueryAST(), qbSQ, ctx_1, null);
          getMetaData(qbSQ);
          RelNode subQueryRelNode = genLogicalPlan(qbSQ, false);
          aliasToRel.put(subQuery.getAlias(), subQueryRelNode);
          RowResolver sqRR = relToHiveRR.get(subQueryRelNode);

          /*
           * Check.5.h :: For In and Not In the SubQuery must implicitly or
           * explicitly only contain one select item.
           */
          if (subQuery.getOperator().getType() != SubQueryType.EXISTS
              && subQuery.getOperator().getType() != SubQueryType.NOT_EXISTS
              && sqRR.getColumnInfos().size() - subQuery.getNumOfCorrelationExprsAddedToSQSelect() > 1) {
            throw new SemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg(subQueryAST,
                "SubQuery can contain only 1 item in Select List."));
          }

          /*
           * If this is a Not In SubQuery Predicate then Join in the Null Check
           * SubQuery. See QBSubQuery.NotInCheck for details on why and how this
           * is constructed.
           */
          if (subQuery.getNotInCheck() != null) {
            QBSubQuery.NotInCheck notInCheck = subQuery.getNotInCheck();
            notInCheck.setSQRR(sqRR);
            QB qbSQ_nic = new QB(subQuery.getOuterQueryId(), notInCheck.getAlias(), true);
            qbSQ_nic.setSubQueryDef(notInCheck.getSubQuery());
            ctx_1 = initPhase1Ctx();
            doPhase1(notInCheck.getSubQueryAST(), qbSQ_nic, ctx_1, null);
            getMetaData(qbSQ_nic);
            RelNode subQueryNICRelNode = genLogicalPlan(qbSQ_nic, false);
            aliasToRel.put(notInCheck.getAlias(), subQueryNICRelNode);
            srcRel = genJoinRelNode(srcRel, subQueryNICRelNode,
            // set explicitly to inner until we figure out SemiJoin use
            // notInCheck.getJoinType(),
                JoinType.INNER, notInCheck.getJoinConditionAST());
View Full Code Here

      return selRel;
    }

    private RelNode genFilterLogicalPlan(QB qb, RelNode srcRel, Map<String, RelNode> aliasToRel,
        boolean forHavingClause) throws SemanticException {
      RelNode filterRel = null;

      Iterator<ASTNode> whereClauseIterator = getQBParseInfo(qb).getDestToWhereExpr().values()
          .iterator();
      if (whereClauseIterator.hasNext()) {
        filterRel = genFilterRelNode(qb, (ASTNode) whereClauseIterator.next().getChild(0), srcRel,
View Full Code Here

      if (gbChildProjLst.isEmpty()) {
        // This will happen for count(*), in such cases we arbitarily pick
        // first element from srcRel
        gbChildProjLst.add(this.cluster.getRexBuilder().makeInputRef(srcRel, 0));
      }
      RelNode gbInputRel = HiveProjectRel.create(srcRel, gbChildProjLst, null);

      HiveRel aggregateRel = null;
      try {
        aggregateRel = new HiveAggregateRel(cluster, cluster.traitSetOf(HiveRel.CONVENTION),
            gbInputRel, groupSet, aggregateCalls);
View Full Code Here

TOP

Related Classes of org.eigenbase.rel.RelNode

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.