Package org.apache.hadoop.hive.ql.parse

Examples of org.apache.hadoop.hive.ql.parse.ASTNode


   * @throws SemanticException
   */
  private static void doSemanticAnalysis(SemanticAnalyzer sem,
      ASTNode ast, Context ctx) throws SemanticException {
    QB qb = new QB(null, null, false);
    ASTNode child = ast;
    ParseContext subPCtx = ((SemanticAnalyzer) sem).getParseContext();
    subPCtx.setContext(ctx);
    ((SemanticAnalyzer) sem).init(subPCtx);

    LOG.info("Starting Sub-query Semantic Analysis");
View Full Code Here


        tableName = BaseSemanticAnalyzer.getUnescapedName((ASTNode) ast
                .getChild(0));
        boolean likeTable = false;

        for (int num = 1; num < numCh; num++) {
            ASTNode child = (ASTNode) ast.getChild(num);

            switch (child.getToken().getType()) {

                case HiveParser.TOK_QUERY: // CTAS
                    throw new SemanticException(
                            "Operation not supported. Create table as " +
                            "Select is not a valid operation.");

                case HiveParser.TOK_TABLEBUCKETS:
                    break;

                case HiveParser.TOK_TBLSEQUENCEFILE:
                    inputFormat = HCatConstants.SEQUENCEFILE_INPUT;
                    outputFormat = HCatConstants.SEQUENCEFILE_OUTPUT;
                    break;

                case HiveParser.TOK_TBLTEXTFILE:
                    inputFormat      = org.apache.hadoop.mapred.TextInputFormat.class.getName();
                    outputFormat     = org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat.class.getName();

                    break;

                case HiveParser.TOK_LIKETABLE:
                    likeTable = true;
                    break;

                case HiveParser.TOK_IFNOTEXISTS:
                    try {
                        List<String> tables = db.getTablesByPattern(tableName);
                        if (tables != null && tables.size() > 0) { // table
                                                                   // exists
                            return ast;
                        }
                    } catch (HiveException e) {
                        throw new SemanticException(e);
                    }
                    break;

                case HiveParser.TOK_TABLEPARTCOLS:
                    List<FieldSchema> partCols = BaseSemanticAnalyzer
                            .getColumns((ASTNode) child.getChild(0), false);
                    for (FieldSchema fs : partCols) {
                        if (!fs.getType().equalsIgnoreCase("string")) {
                            throw new SemanticException(
                                    "Operation not supported. HCatalog only " +
                                    "supports partition columns of type string. "
                                            + "For column: "
                                            + fs.getName()
                                            + " Found type: " + fs.getType());
                        }
                    }
                    break;

                case HiveParser.TOK_STORAGEHANDLER:
                    String storageHandler = BaseSemanticAnalyzer
                            .unescapeSQLString(child.getChild(0).getText());
                    if (org.apache.commons.lang.StringUtils
                            .isNotEmpty(storageHandler)) {
                        return ast;
                    }

                    break;

                case HiveParser.TOK_TABLEFILEFORMAT:
                    if (child.getChildCount() < 2) {
                        throw new SemanticException(
                                "Incomplete specification of File Format. " +
                                "You must provide InputFormat, OutputFormat.");
                    }
                    inputFormat = BaseSemanticAnalyzer.unescapeSQLString(child
                            .getChild(0).getText());
                    outputFormat = BaseSemanticAnalyzer.unescapeSQLString(child
                            .getChild(1).getText());
                    break;

                case HiveParser.TOK_TBLRCFILE:
                    inputFormat = RCFileInputFormat.class.getName();
View Full Code Here

    int numCh = ast.getChildCount();

    databaseName = BaseSemanticAnalyzer.getUnescapedName((ASTNode)ast.getChild(0));

    for (int num = 1; num < numCh; num++) {
      ASTNode child = (ASTNode) ast.getChild(num);

      switch (child.getToken().getType()) {

      case HiveParser.TOK_IFNOTEXISTS:
        try {
          List<String> dbs = db.getDatabasesByPattern(databaseName);
          if (dbs != null && dbs.size() > 0) { // db exists
View Full Code Here

      ctx = new Context(conf);
      ctx.setTryCount(getTryCount());
      ctx.setCmd(command);

      ParseDriver pd = new ParseDriver();
      ASTNode tree = pd.parse(command, ctx);
      tree = ParseUtils.findRootNonNullToken(tree);

      BaseSemanticAnalyzer sem = SemanticAnalyzerFactory.get(conf, tree);
      List<AbstractSemanticAnalyzerHook> saHooks =
          getHooks(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK,
View Full Code Here

      if (desc != null)
      {
        return desc;
      }

      ASTNode expr = (ASTNode) nd;
      Boolean bool = null;

      switch (expr.getToken().getType())
      {
      case Windowing2Parser.TRUE:
        bool = Boolean.TRUE;
        break;
      case Windowing2Parser.FALSE:
View Full Code Here

      if (desc != null)
      {
        return desc;
      }

      ASTNode expr = (ASTNode) nd;
      ASTNode parent = stack.size() > 1 ? (ASTNode) stack.get(stack.size() - 2) : null;
      RowResolver input = ctx.getInputRR();

      if (expr.getType() != Windowing2Parser.TABLEORCOL)
      {
        ctx.setError(ErrorMsg.INVALID_COLUMN.getMsg(expr), expr);
        return null;
      }

      assert (expr.getChildCount() == 1);
      String tableOrCol = BaseSemanticAnalyzer.unescapeIdentifier(expr.getChild(0).getText());

      boolean isTableAlias = input.hasTableAlias(tableOrCol);
      ColumnInfo colInfo = input.get(null, tableOrCol);

      if (isTableAlias)
      {
        if (colInfo != null)
        {
          if (parent != null && parent.getType() == Windowing2Parser.DOT)
          {
            // It's a table alias.
            return null;
          }
          // It's a column.
          return new ExprNodeColumnDesc(colInfo.getType(),
              colInfo.getInternalName(), colInfo.getTabAlias(),
              colInfo.getIsVirtualCol());
        }
        else
        {
          // It's a table alias.
          // We will process that later in DOT.
          return null;
        }
      }
      else
      {
        if (colInfo == null)
        {
          // It's not a column or a table alias.
          if (input.getIsExprResolver())
          {
            ASTNode exprNode = expr;
            if (!stack.empty())
            {
              ASTNode tmp = (ASTNode) stack.pop();
              if (!stack.empty())
              {
                exprNode = (ASTNode) stack.peek();
              }
              stack.push(tmp);
View Full Code Here

    Iterator<Object> it = selectSpec.getColumnListAndAlias();
    while(it.hasNext())
    {
      Object[] selectColDetails = (Object[]) it.next();
      String selectColName = (String) selectColDetails[1];
      ASTNode selectColumnNode = (ASTNode) selectColDetails[2];
      ExprNodeDesc selectColumnExprNode = TranslateUtils.buildExprNode(selectColumnNode, selectListInputTypeCheckCtx);
      ExprNodeEvaluator selectColumnExprEval = ExprNodeEvaluatorFactory.get(selectColumnExprNode);
      ObjectInspector selectColumnOI = null;
      try
      {
View Full Code Here

      if (ctx.getError() != null)
      {
        return null;
      }

      ASTNode expr = (ASTNode) nd;

      // If the first child is a TOK_TABLE_OR_COL, and nodeOutput[0] is
      // NULL,
      // and the operator is a DOT, then it's a table column reference.
      if (expr.getType() == Windowing2Parser.DOT
          && expr.getChild(0).getType() == Windowing2Parser.TABLEORCOL
          && nodeOutputs[0] == null)
      {

        RowResolver input = ctx.getInputRR();
        String tableAlias = BaseSemanticAnalyzer
            .unescapeIdentifier(expr.getChild(0).getChild(0)
                .getText());
        // NOTE: tableAlias must be a valid non-ambiguous table alias,
        // because we've checked that in TOK_TABLE_OR_COL's process
        // method.
        ColumnInfo colInfo = input.get(tableAlias,
            ((ExprNodeConstantDesc) nodeOutputs[1]).getValue()
                .toString());

        if (colInfo == null)
        {
          ctx.setError(
              ErrorMsg.INVALID_COLUMN.getMsg(expr.getChild(1)),
              expr);
          return null;
        }
        return new ExprNodeColumnDesc(colInfo.getType(),
            colInfo.getInternalName(), colInfo.getTabAlias(),
            colInfo.getIsVirtualCol());
      }

      // Return nulls for conversion operators
      if (conversionFunctionTextHashMap.keySet().contains(expr.getType())
          || specialFunctionTextHashMap.keySet().contains(
              expr.getType())
          || expr.getToken().getType() == Windowing2Parser.CharSetName
          || expr.getToken().getType() == Windowing2Parser.CharSetLiteral)
      {
        return null;
      }

      boolean isFunction = (expr.getType() == Windowing2Parser.FUNCTION);

      // Create all children
      int childrenBegin = (isFunction ? 1 : 0);
      ArrayList<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(
          expr.getChildCount() - childrenBegin);
      for (int ci = childrenBegin; ci < expr.getChildCount(); ci++)
      {
        children.add((ExprNodeDesc) nodeOutputs[ci]);
      }

      // If any of the children contains null, then return a null
      // this is a hack for now to handle the group by case
      if (children.contains(null))
      {
        return null;
      }

      // Create function desc
      try
      {
        return getXpathOrFuncExprNodeDesc(expr, isFunction, children,
            ctx);
      }
      catch (UDFArgumentTypeException e)
      {
        throw new SemanticException(
            ErrorMsg.INVALID_ARGUMENT_TYPE.getMsg(expr
                .getChild(childrenBegin + e.getArgumentId()), e
                .getMessage()));
      }
      catch (UDFArgumentLengthException e)
      {
View Full Code Here

    // encounter
    // a constant, we convert that into an exprNodeConstantDesc. For others
    // we
    // just
    // build the exprNodeFuncDesc with recursively built children.
    ASTNode expr = (ASTNode) nd;
    TypeCheckCtx ctx = (TypeCheckCtx) procCtx;
    RowResolver input = ctx.getInputRR();
    ExprNodeDesc desc = null;

    // If the current subExpression is pre-calculated, as in Group-By etc.
View Full Code Here

      {
        return desc;
      }

      Number v = null;
      ASTNode expr = (ASTNode) nd;
      // The expression can be any one of Double, Long and Integer. We
      // try to parse the expression in that order to ensure that the
      // most specific type is used for conversion.
      try
      {
        if (expr.getText().endsWith("L"))
        {
          // Literal bigint.
          v = Long.valueOf(expr.getText().substring(0,
              expr.getText().length() - 1));
        }
        else if (expr.getText().endsWith("S"))
        {
          // Literal smallint.
          v = Short.valueOf(expr.getText().substring(0,
              expr.getText().length() - 1));
        }
        else if (expr.getText().endsWith("Y"))
        {
          // Literal tinyint.
          v = Byte.valueOf(expr.getText().substring(0,
              expr.getText().length() - 1));
        }
        else
        {
          v = Double.valueOf(expr.getText());
          v = Long.valueOf(expr.getText());
          v = Integer.valueOf(expr.getText());
        }
      }
      catch (NumberFormatException e)
      {
        // do nothing here, we will throw an exception in the following
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.parse.ASTNode

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.