Package org.apache.hadoop.hive.ql.optimizer.optiq.reloperators

Examples of org.apache.hadoop.hive.ql.optimizer.optiq.reloperators.HiveSortRel


    return hiveAST.getAST();
  }

  private void convertLimitToASTNode(HiveSortRel limit) {
    if (limit != null) {
      HiveSortRel hiveLimit = (HiveSortRel) limit;
      RexNode limitExpr = hiveLimit.getFetchExpr();
      if (limitExpr != null) {
        Object val = ((RexLiteral) limitExpr).getValue2();
        hiveAST.limit = ASTBuilder.limit(val);
      }
    }
View Full Code Here


    }
  }

  private void convertOBToASTNode(HiveSortRel order) {
    if (order != null) {
      HiveSortRel hiveSort = (HiveSortRel) order;
      if (!hiveSort.getCollation().getFieldCollations().isEmpty()) {
        // 1 Add order by token
        ASTNode orderAst = ASTBuilder.createAST(HiveParser.TOK_ORDERBY, "TOK_ORDERBY");

        schema = new Schema((HiveSortRel) hiveSort);
        Map<Integer, RexNode> obRefToCallMap = hiveSort.getInputRefToCallMap();
        RexNode obExpr;
        ASTNode astCol;
        for (RelFieldCollation c : hiveSort.getCollation().getFieldCollations()) {

          // 2 Add Direction token
          ASTNode directionAST = c.getDirection() == RelFieldCollation.Direction.ASCENDING ? ASTBuilder
              .createAST(HiveParser.TOK_TABSORTCOLNAMEASC, "TOK_TABSORTCOLNAMEASC") : ASTBuilder
              .createAST(HiveParser.TOK_TABSORTCOLNAMEDESC, "TOK_TABSORTCOLNAMEDESC");
View Full Code Here

      throws OptiqSemanticException {
    if (!(topSelparentPair.getKey() instanceof SortRel)
        || !HiveOptiqUtil.orderRelNode(topSelparentPair.getKey())) {
      return;
    }
    HiveSortRel obRel = (HiveSortRel) topSelparentPair.getKey();
    ProjectRelBase obChild = (ProjectRelBase) topSelparentPair.getValue();
    if (obChild.getRowType().getFieldCount() <= resultSchema.size()) {
      return;
    }

    RelDataType rt = obChild.getRowType();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    Set<Integer> collationInputRefs = new HashSet(
        RelCollationImpl.ordinals(obRel.getCollation()));
    ImmutableMap.Builder<Integer, RexNode> inputRefToCallMapBldr = ImmutableMap.builder();
    for (int i = resultSchema.size(); i < rt.getFieldCount(); i++) {
      if (collationInputRefs.contains(i)) {
        inputRefToCallMapBldr.put(i, obChild.getChildExps().get(i));
      }
    }
    ImmutableMap<Integer, RexNode> inputRefToCallMap = inputRefToCallMapBldr.build();

    if ((obChild.getRowType().getFieldCount() - inputRefToCallMap.size()) != resultSchema.size()) {
      LOG.error(generateInvalidSchemaMessage(obChild, resultSchema, inputRefToCallMap.size()));
      throw new OptiqSemanticException("Result Schema didn't match Optimized Op Tree Schema");
    }
    // This removes order-by only expressions from the projections.
    HiveProjectRel replacementProjectRel = HiveProjectRel.create(obChild.getChild(), obChild
        .getChildExps().subList(0, resultSchema.size()), obChild.getRowType().getFieldNames()
        .subList(0, resultSchema.size()));
    obRel.replaceInput(0, replacementProjectRel);
    obRel.setInputRefToCallMap(inputRefToCallMap);
  }
View Full Code Here

        }

        // 4. Construct SortRel
        RelTraitSet traitSet = cluster.traitSetOf(HiveRel.CONVENTION);
        RelCollation canonizedCollation = traitSet.canonize(RelCollationImpl.of(fieldCollations));
        sortRel = new HiveSortRel(cluster, traitSet, obInputRel, canonizedCollation, null, null);

        // 5. Update the maps
        // NOTE: Output RR for SortRel is considered same as its input; we may
        // end up not using VC that is present in sort rel. Also note that
        // rowtype of sortrel is the type of it child; if child happens to be
View Full Code Here

      if (limit != null) {
        RexNode fetch = cluster.getRexBuilder().makeExactLiteral(BigDecimal.valueOf(limit));
        RelTraitSet traitSet = cluster.traitSetOf(HiveRel.CONVENTION);
        RelCollation canonizedCollation = traitSet.canonize(RelCollationImpl.EMPTY);
        sortRel = new HiveSortRel(cluster, traitSet, srcRel, canonizedCollation, null, fetch);

        RowResolver outputRR = new RowResolver();
        if (!RowResolver.add(outputRR, relToHiveRR.get(srcRel))) {
          throw new OptiqSemanticException(
              "Duplicates detected when adding columns to RR: see previous message");
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.optimizer.optiq.reloperators.HiveSortRel

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.