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

Examples of org.apache.hadoop.hive.ql.optimizer.optiq.OptiqSemanticException


            SemanticAnalyzer.this.nameToSplitSample.containsKey(tableAlias)) {
          String msg = String.format("Table Sample specified for %s." +
              " Currently we don't support Table Sample clauses in CBO," +
              " turn off cbo for queries on tableSamples.", tableAlias);
          LOG.debug(msg);
          throw new OptiqSemanticException(msg);
        }

        // 2. Get Table Metadata
        Table tab = qb.getMetaData().getSrcForAlias(tableAlias);
View Full Code Here


        !filterCondn.getTypeString().equals(serdeConstants.BOOLEAN_TYPE_NAME)) {
        // queries like select * from t1 where 'foo';
        // Optiq's rule PushFilterThroughProject chokes on it. Arguably, we can insert a cast to
        // boolean in such cases, but since Postgres, Oracle and MS SQL server fail on compile time
        // for such queries, its an arcane corner case, not worth of adding that complexity.
        throw new OptiqSemanticException("Filter expression with non-boolean return type.");
      }
      ImmutableMap<String, Integer> hiveColNameOptiqPosMap = this.relToHiveColNameOptiqPosMap
          .get(srcRel);
      RexNode convertedFilterExpr = new RexNodeConverter(cluster, srcRel.getRowType(),
          hiveColNameOptiqPosMap, 0, true).convert(filterCondn);
View Full Code Here

        String msg = String.format("Encountered Grouping Set/Cube/Rollup%s"
            + " Currently we don't support Grouping Set/Cube/Rollup"
            + " clauses in CBO," + " turn off cbo for these queries.",
            gbyClause);
        LOG.debug(msg);
        throw new OptiqSemanticException(msg);
      }

      // 1. Gather GB Expressions (AST) (GB + Aggregations)
      // NOTE: Multi Insert is not supported
      String detsClauseName = qbp.getClauseNames().iterator().next();
      List<ASTNode> grpByAstExprs = getGroupByForClause(qbp, detsClauseName);
      HashMap<String, ASTNode> aggregationTrees = qbp.getAggregationExprsForClause(detsClauseName);
      boolean hasGrpByAstExprs = (grpByAstExprs != null && !grpByAstExprs.isEmpty()) ? true : false;
      boolean hasAggregationTrees = (aggregationTrees != null && !aggregationTrees.isEmpty()) ? true
          : false;

      if (hasGrpByAstExprs || hasAggregationTrees) {
        ArrayList<ExprNodeDesc> gbExprNDescLst = new ArrayList<ExprNodeDesc>();
        ArrayList<String> outputColumnNames = new ArrayList<String>();

        // 2. Input, Output Row Resolvers
        RowResolver groupByInputRowResolver = this.relToHiveRR.get(srcRel);
        RowResolver groupByOutputRowResolver = new RowResolver();
        groupByOutputRowResolver.setIsExprResolver(true);

        if (hasGrpByAstExprs) {
          // 3. Construct GB Keys (ExprNode)
          for (int i = 0; i < grpByAstExprs.size(); ++i) {
            ASTNode grpbyExpr = grpByAstExprs.get(i);
            Map<ASTNode, ExprNodeDesc> astToExprNDescMap = TypeCheckProcFactory.genExprNode(
                grpbyExpr, new TypeCheckCtx(groupByInputRowResolver));
            ExprNodeDesc grpbyExprNDesc = astToExprNDescMap.get(grpbyExpr);
            if (grpbyExprNDesc == null)
              throw new OptiqSemanticException("Invalid Column Reference: " + grpbyExpr.dump());

            addToGBExpr(groupByOutputRowResolver, groupByInputRowResolver, grpbyExpr,
                grpbyExprNDesc, gbExprNDescLst, outputColumnNames);
          }
        }
View Full Code Here

                  return new RexInputRef(input.getIndex(), input.getType());
                }
              });
          RowResolver obSyntheticProjectRR = new RowResolver();
          if (!RowResolver.add(obSyntheticProjectRR, inputRR)) {
            throw new OptiqSemanticException(
                "Duplicates detected when adding columns to RR: see previous message");
          }
          int vcolPos = inputRR.getRowSchema().getSignature().size();
          for (Pair<ASTNode, TypeInfo> astTypePair : vcASTTypePairs) {
            obSyntheticProjectRR.putExpression(astTypePair.getKey(), new ColumnInfo(
                getColumnInternalName(vcolPos), astTypePair.getValue(), null, false));
            vcolPos++;
          }
          obInputRel = genSelectRelNode(CompositeList.of(originalInputRefs, newVCLst),
              obSyntheticProjectRR, srcRel);

          if (outermostOB) {
            if (!RowResolver.add(outputRR, inputRR)) {
              throw new OptiqSemanticException(
                  "Duplicates detected when adding columns to RR: see previous message");
            }

          } else {
            if (!RowResolver.add(outputRR, obSyntheticProjectRR)) {
              throw new OptiqSemanticException(
                  "Duplicates detected when adding columns to RR: see previous message");
            }
            originalOBChild = srcRel;
          }
        } else {
          if (!RowResolver.add(outputRR, inputRR)) {
            throw new OptiqSemanticException(
                "Duplicates detected when adding columns to RR: see previous message");
          }
        }

        // 4. Construct SortRel
View Full Code Here

        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");
        }
        ImmutableMap<String, Integer> hiveColNameOptiqPosMap = buildHiveToOptiqColumnMap(outputRR,
            sortRel);
        relToHiveRR.put(sortRel, outputRR);
View Full Code Here

            selExprList.getChild(0).getTokenStartIndex(),
            selExprList.getChild(0).getTokenStopIndex());
        String msg = String.format("Hint specified for %s."
            + " Currently we don't support hints in CBO, turn off cbo to use hints.", hint);
        LOG.debug(msg);
        throw new OptiqSemanticException(msg);
      }

      // 4. Bailout if select involves Transform
      boolean isInTransform = (selExprList.getChild(posn).getChild(0).getType() == HiveParser.TOK_TRANSFORM);
      if (isInTransform) {
        String msg = String.format("SELECT TRANSFORM is currently not supported in CBO,"
            + " turn off cbo to use TRANSFORM.");
        LOG.debug(msg);
        throw new OptiqSemanticException(msg);
      }

      // 5. Bailout if select involves UDTF
      ASTNode expr = (ASTNode) selExprList.getChild(posn).getChild(0);
      int exprType = expr.getType();
      if (exprType == HiveParser.TOK_FUNCTION || exprType == HiveParser.TOK_FUNCTIONSTAR) {
        String funcName = TypeCheckProcFactory.DefaultExprProcessor.getFunctionText(expr, true);
        FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName);
        if (fi != null && fi.getGenericUDTF() != null) {
          String msg = String.format("UDTF " + funcName + " is currently not supported in CBO,"
              + " turn off cbo to use UDTF " + funcName);
          LOG.debug(msg);
          throw new OptiqSemanticException(msg);
        }
      }

      // 6. Iterate over all expression (after SELECT)
      ASTNode exprList = selExprList;
      int startPosn = posn;
      int wndProjPos = 0;
      List<String> tabAliasesForAllProjs = getTabAliases(inputRR);
      for (int i = startPosn; i < exprList.getChildCount(); ++i) {

        // 6.1 child can be EXPR AS ALIAS, or EXPR.
        ASTNode child = (ASTNode) exprList.getChild(i);
        boolean hasAsClause = (!isInTransform) && (child.getChildCount() == 2);

        // 6.2 EXPR AS (ALIAS,...) parses, but is only allowed for UDTF's
        // This check is not needed and invalid when there is a transform b/c
        // the
        // AST's are slightly different.
        if (child.getChildCount() > 2) {
          throw new SemanticException(generateErrorMessage((ASTNode) child.getChild(2),
              ErrorMsg.INVALID_AS.getMsg()));
        }

        String tabAlias;
        String colAlias;

        // 6.3 Get rid of TOK_SELEXPR
        expr = (ASTNode) child.getChild(0);
        String[] colRef = getColAlias(child, autogenColAliasPrfxLbl, inputRR,
            autogenColAliasPrfxIncludeFuncName, i);
        tabAlias = colRef[0];
        colAlias = colRef[1];

        // 6.4 Build ExprNode corresponding to colums
        if (expr.getType() == HiveParser.TOK_ALLCOLREF) {
          pos = genColListRegex(".*",
              expr.getChildCount() == 0 ? null : getUnescapedName((ASTNode) expr.getChild(0))
                  .toLowerCase(), expr, col_list, excludedColumns, inputRR, pos, out_rwsch,
                  tabAliasesForAllProjs, true);
          selectStar = true;
        } else if (expr.getType() == HiveParser.TOK_TABLE_OR_COL && !hasAsClause
            && !inputRR.getIsExprResolver()
            && isRegex(unescapeIdentifier(expr.getChild(0).getText()), conf)) {
          // In case the expression is a regex COL.
          // This can only happen without AS clause
          // We don't allow this for ExprResolver - the Group By case
          pos = genColListRegex(unescapeIdentifier(expr.getChild(0).getText()), null, expr,
              col_list, excludedColumns, inputRR, pos, out_rwsch, tabAliasesForAllProjs, true);
        } else if (expr.getType() == HiveParser.DOT
            && expr.getChild(0).getType() == HiveParser.TOK_TABLE_OR_COL
            && inputRR.hasTableAlias(unescapeIdentifier(expr.getChild(0).getChild(0).getText()
                .toLowerCase())) && !hasAsClause && !inputRR.getIsExprResolver()
            && isRegex(unescapeIdentifier(expr.getChild(1).getText()), conf)) {
          // In case the expression is TABLE.COL (col can be regex).
          // This can only happen without AS clause
          // We don't allow this for ExprResolver - the Group By case
          pos = genColListRegex(unescapeIdentifier(expr.getChild(1).getText()),
              unescapeIdentifier(expr.getChild(0).getChild(0).getText().toLowerCase()), expr,
              col_list, excludedColumns, inputRR, pos, out_rwsch, tabAliasesForAllProjs, true);
        } else if (expr.toStringTree().contains("TOK_FUNCTIONDI") && !(srcRel instanceof HiveAggregateRel)) {
          // Likely a malformed query eg, select hash(distinct c1) from t1;
          throw new OptiqSemanticException("Distinct without an aggreggation.");
        } else {
          // Case when this is an expression
          TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR);
          // We allow stateful functions in the SELECT list (but nowhere else)
          tcCtx.setAllowStatefulFunctions(true);
          ExprNodeDesc exp = genExprNodeDesc(expr, inputRR, tcCtx);
          String recommended = recommendName(exp, colAlias);
          if (recommended != null && out_rwsch.get(null, recommended) == null) {
            colAlias = recommended;
          }
          col_list.add(exp);

          ColumnInfo colInfo = new ColumnInfo(getColumnInternalName(pos),
              exp.getWritableObjectInspector(), tabAlias, false);
          colInfo.setSkewedCol((exp instanceof ExprNodeColumnDesc) ? ((ExprNodeColumnDesc) exp)
              .isSkewedCol() : false);
          if (!out_rwsch.putWithCheck(tabAlias, colAlias, null, colInfo)) {
            throw new OptiqSemanticException("Cannot add column to RR: " + tabAlias + "."
                + colAlias + " => " + colInfo + " due to duplication, see previous warnings");
          }

          if (exp instanceof ExprNodeColumnDesc) {
            ExprNodeColumnDesc colExp = (ExprNodeColumnDesc) exp;
View Full Code Here

      if (reason != null) {
        String msg = "CBO can not handle Sub Query";
        if (LOG.isDebugEnabled()) {
          LOG.debug(msg + " because it: " + reason);
        }
        throw new OptiqSemanticException(msg);
      }

      // 1. Build Rel For Src (SubQuery, TS, Join)
      // 1.1. Recurse over the subqueries to fill the subquery part of the plan
      for (String subqAlias : qb.getSubqAliases()) {
        QBExpr qbexpr = qb.getSubqForAlias(subqAlias);
        aliasToRel.put(subqAlias, genLogicalPlan(qbexpr));
      }

      // 1.2 Recurse over all the source tables
      for (String tableAlias : qb.getTabAliases()) {
        RelNode op = genTableLogicalPlan(tableAlias, qb);
        aliasToRel.put(tableAlias, op);
      }

      if (aliasToRel.isEmpty()) {
        // // This may happen for queries like select 1; (no source table)
        // We can do following which is same, as what Hive does.
        // With this, we will be able to generate Optiq plan.
        // qb.getMetaData().setSrcForAlias(DUMMY_TABLE, getDummyTable());
        // RelNode op = genTableLogicalPlan(DUMMY_TABLE, qb);
        // qb.addAlias(DUMMY_TABLE);
        // qb.setTabAlias(DUMMY_TABLE, DUMMY_TABLE);
        // aliasToRel.put(DUMMY_TABLE, op);
        // However, Hive trips later while trying to get Metadata for this dummy
        // table
        // So, for now lets just disable this. Anyway there is nothing much to
        // optimize in such cases.
        throw new OptiqSemanticException("Unsupported");

      }
      // 1.3 process join
      if (qb.getParseInfo().getJoinExpr() != null) {
        srcRel = genJoinLogicalPlan(qb.getParseInfo().getJoinExpr(), aliasToRel);
View Full Code Here

      ASTNode havingClause = qbp.getHavingForClause(qbp.getClauseNames().iterator().next());

      if (havingClause != null) {
        if (!(srcRel instanceof HiveAggregateRel)) {
          // ill-formed query like select * from t1 having c1 > 0;
          throw new OptiqSemanticException("Having clause without any group-by.");
        }
        validateNoHavingReferenceToAlias(qb,  (ASTNode) havingClause.getChild(0));
        gbFilter = genFilterRelNode(qb, (ASTNode) havingClause.getChild(0), srcRel, aliasToRel,
            true);
      }
View Full Code Here

              "Encountered Select alias '%s' in having clause '%s'"
                  + " This non standard behavior is not supported with cbo on."
                  + " Turn off cbo for these queries.", aliasToCheck,
              havingClause);
          LOG.debug(msg);
          throw new OptiqSemanticException(msg);
        }
      }

    }
View Full Code Here

      QBParseInfo qbp = qb.getParseInfo();
      if (qbp.getClauseNames().size() > 1) {
        String msg = String.format("Multi Insert is currently not supported in CBO,"
            + " turn off cbo to use Multi Insert.");
        LOG.debug(msg);
        throw new OptiqSemanticException(msg);
      }
      return qbp;
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.optimizer.optiq.OptiqSemanticException

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.