Package org.apache.hadoop.hive.ql.exec

Examples of org.apache.hadoop.hive.ql.exec.FunctionInfo


    int udtfExprType = udtfExpr.getType();
    if (udtfExprType == HiveParser.TOK_FUNCTION
        || udtfExprType == HiveParser.TOK_FUNCTIONSTAR) {
      String funcName = TypeCheckProcFactory.DefaultExprProcessor
          .getFunctionText(udtfExpr, true);
      FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName);
      if (fi != null) {
        genericUDTF = fi.getGenericUDTF();
      }
      isUDTF = (genericUDTF != null);
      if (isUDTF) {
        globalLimitCtx.setHasTransformOrUDTF(true);
      }
      if (isUDTF && !fi.isNative()) {
        unparseTranslator.addIdentifierTranslation((ASTNode) udtfExpr
            .getChild(0));
      }
      if (isUDTF && (selectStar = udtfExprType == HiveParser.TOK_FUNCTIONSTAR)) {
        genColListRegex(".*", null, (ASTNode) udtfExpr.getChild(0),
View Full Code Here


          String funcSQL = funcSQL(columnsMapping, func);
          String colStr = getColumnFromExpr(func,
              columnsMapping);

          Class<? extends UDF> udfClass = func.getUDFClass();
          FunctionInfo funcInfo = FunctionRegistry
              .getInfo(udfClass);
          String funcName = funcInfo.getDisplayName();
          String funcAlias = funcName + "_" + colStr;
          if (exprAlias != null) {
            funcAlias = exprAlias;
            columns.remove(exprAlias);
          }

          sqlStructure.addColumn(funcSQL, "string");
          sqlStructure.putColumnAlias(funcSQL, funcAlias);

          groupKeys.add(funcSQL);
          sqlGroupBy.append(", ").append(funcAlias);

          sb.append(" - func: ").append(funcSQL).append(
              " AS ").append(funcAlias);

        }

        sb.append("\n");

        sqlStructure.retainColumns(groupKeys);

      }
    }

    if (conf.getAggregators() != null) {
      sb.append(" - AGGREGATORS: ");
      for (aggregationDesc a : conf.getAggregators()) {

        Class<? extends UDAFEvaluator> aggClass = a
            .getAggregationClass();

        FunctionInfo aggInfo = FunctionRegistry
            .getInfo(aggClass);

        sb.append("UDFAggClass : ").append(aggClass.getName())
            .append(" ");
        sb.append(aggInfo.getDisplayName() + " with ");
        sb.append("params {");
        for (exprNodeDesc expr : a.getParameters()) {
          sb.append(", ").append(expr.getClass().getName())
              .append(" - ").append(expr.getExprString());
        }
        sb.append("} ");
        sb.append(a.getExprString() + ", ");

        String aggName = aggInfo.getDisplayName();
        String colStr = getColumnFromExpr(a.getParameters()
            .get(0), columnsMapping);

        String aggSQL = aggName + "(" + colStr + ")";
        String aggAlias = aggName + "_" + colStr;
View Full Code Here

      exprNodeFuncDesc func) {

    StringBuilder sb = new StringBuilder();

    Class<? extends UDF> udfClass = func.getUDFClass();
    FunctionInfo funcInfo = FunctionRegistry.getInfo(udfClass);
    LOG.debug(" udfClass " + udfClass.getName() + " "
        + funcInfo.getDisplayName());

    List<String> params = new ArrayList<String>();

    for (exprNodeDesc funcParam : func.getChildExprs()) {

      LOG.debug(" funcParam : " + funcParam.getClass().getName() + " "
          + funcParam.getExprString());

      if (funcParam instanceof exprNodeColumnDesc) {
        exprNodeColumnDesc col = (exprNodeColumnDesc) funcParam;

        String colStr = columnsMapping.get(col.getColumn());
        if (colStr == null) {
          colStr = col.getColumn();
        }
        params.add(colStr);
      }
      else if (funcParam instanceof exprNodeConstantDesc) {
        exprNodeConstantDesc cons = (exprNodeConstantDesc) funcParam;
        params.add(cons.getExprString());
      }
      else if (funcParam instanceof exprNodeFuncDesc) {
        // recursion
        params
            .add(funcSQL(columnsMapping,
                (exprNodeFuncDesc) funcParam));
      }
    }

    if (funcInfo.isOperator()) {

      switch (funcInfo.getOpType()) {
      case PREFIX:
        sb.append("( ").append(funcInfo.getDisplayName()).append(" ");
        sb.append(params.get(0)).append(") ");
        break;
      case INFIX:
        sb.append(" (").append(params.get(0)).append(" ");
        sb.append(funcInfo.getDisplayName()).append(" ");
        sb.append(params.get(1)).append(") ");
        break;
      case POSTFIX:
        sb.append(" (").append(params.get(0)).append(" ");
        sb.append(funcInfo.getDisplayName()).append(") ");
        break;
      default:
        break;
      }
    } else {
      LOG.debug("Not an operator - must handle specially!");

      if (udfClass == UDFSubstr.class) {
        sb.append(funcInfo.getDisplayName());
        sb.append("(").append(params.get(0)).append(",");
        sb.append(params.get(1)).append(",");
        sb.append(params.get(2)).append(") ");
      }
      else if(udfClass == UDFYear.class) {
        sb.append(funcInfo.getDisplayName());
        sb.append("(").append(params.get(0));
        sb.append(") ");
      }
    }
View Full Code Here

      if ((null == catalogName || "".equals(catalogName))
          && (null == schemaName || "".equals(schemaName))) {
        Set<String> functionNames =  FunctionRegistry
            .getFunctionNames(CLIServiceUtils.patternToRegex(functionName));
        for (String functionName : functionNames) {
          FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName);
          Object rowData[] = new Object[] {
              null, // FUNCTION_CAT
              null, // FUNCTION_SCHEM
              functionInfo.getDisplayName(), // FUNCTION_NAME
              "", // REMARKS
              (functionInfo.isGenericUDTF() ?
                  DatabaseMetaData.functionReturnsTable
                  : DatabaseMetaData.functionNoTable), // FUNCTION_TYPE
             functionInfo.getClass().getCanonicalName()
          };
          rowSet.addRow(rowData);
        }
      }
      setState(OperationState.FINISHED);
View Full Code Here

      if (expressionTree.getChild(0).getType() == HiveParser.Identifier) {
        String functionName = unescapeIdentifier(expressionTree.getChild(0)
            .getText());
        if (FunctionRegistry.getGenericUDAFResolver(functionName) != null) {
          aggregations.put(expressionTree.toStringTree(), expressionTree);
          FunctionInfo fi = FunctionRegistry.getFunctionInfo(functionName);
          if (!fi.isNative()) {
            unparseTranslator.addIdentifierTranslation((ASTNode) expressionTree
                .getChild(0));
          }
          return;
        }
View Full Code Here

    int udtfExprType = udtfExpr.getType();
    if (udtfExprType == HiveParser.TOK_FUNCTION
        || udtfExprType == HiveParser.TOK_FUNCTIONSTAR) {
      String funcName = TypeCheckProcFactory.DefaultExprProcessor
          .getFunctionText(udtfExpr, true);
      FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName);
      if (fi != null) {
        genericUDTF = fi.getGenericUDTF();
      }
      isUDTF = (genericUDTF != null);
      if (isUDTF) {
        globalLimitCtx.setHasTransformOrUDTF(true);
      }
      if (isUDTF && !fi.isNative()) {
        unparseTranslator.addIdentifierTranslation((ASTNode) udtfExpr
            .getChild(0));
      }
    }
View Full Code Here

     * @throws UDFArgumentException
     */
    public static ExprNodeDesc getFuncExprNodeDesc(String udfName,
        ExprNodeDesc... children) throws UDFArgumentException {

      FunctionInfo fi = FunctionRegistry.getFunctionInfo(udfName);
      if (fi == null) {
        throw new UDFArgumentException(udfName + " not found.");
      }

      GenericUDF genericUDF = fi.getGenericUDF();
      if (genericUDF == null) {
        throw new UDFArgumentException(udfName
            + " is an aggregation function or a table function.");
      }

View Full Code Here

          throw new SemanticException(ErrorMsg.NON_COLLECTION_TYPE.getMsg(expr,
              myt.getTypeName()));
        }
      } else {
        // other operators or functions
        FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcText);

        if (fi == null) {
          if (isFunction) {
            throw new SemanticException(ErrorMsg.INVALID_FUNCTION
                .getMsg((ASTNode) expr.getChild(0)));
          } else {
            throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(expr));
          }
        }

        if (!fi.isNative()) {
          ctx.getUnparseTranslator().addIdentifierTranslation(
              (ASTNode) expr.getChild(0));
        }

        // Detect UDTF's in nested SELECT, GROUP BY, etc as they aren't
        // supported
        if (fi.getGenericUDTF() != null) {
          throw new SemanticException(ErrorMsg.UDTF_INVALID_LOCATION.getMsg());
        }
        // UDAF in filter condition, group-by caluse, param of funtion, etc.
        if (fi.getGenericUDAFResolver() != null) {
          if (isFunction) {
            throw new SemanticException(ErrorMsg.UDAF_INVALID_LOCATION.
                getMsg((ASTNode) expr.getChild(0)));
          } else {
            throw new SemanticException(ErrorMsg.UDAF_INVALID_LOCATION.getMsg(expr));
          }
        }
        if (!ctx.getAllowStatefulFunctions() && (fi.getGenericUDF() != null)) {
          if (FunctionRegistry.isStateful(fi.getGenericUDF())) {
            throw new SemanticException(
              ErrorMsg.UDF_STATEFUL_INVALID_LOCATION.getMsg());
          }
        }

        // Try to infer the type of the constant only if there are two
        // nodes, one of them is column and the other is numeric const
        if (fi.getGenericUDF() instanceof GenericUDFBaseCompare
            && children.size() == 2
            && ((children.get(0) instanceof ExprNodeConstantDesc
                && children.get(1) instanceof ExprNodeColumnDesc)
                || (children.get(0) instanceof ExprNodeColumnDesc
                    && children.get(1) instanceof ExprNodeConstantDesc))) {
          int constIdx =
              children.get(0) instanceof ExprNodeConstantDesc ? 0 : 1;

          Set<String> inferTypes = new HashSet<String>(Arrays.asList(
              serdeConstants.TINYINT_TYPE_NAME.toLowerCase(),
              serdeConstants.SMALLINT_TYPE_NAME.toLowerCase(),
              serdeConstants.INT_TYPE_NAME.toLowerCase(),
              serdeConstants.BIGINT_TYPE_NAME.toLowerCase(),
              serdeConstants.FLOAT_TYPE_NAME.toLowerCase(),
              serdeConstants.DOUBLE_TYPE_NAME.toLowerCase(),
              serdeConstants.STRING_TYPE_NAME.toLowerCase()
              ));

          String constType = children.get(constIdx).getTypeString().toLowerCase();
          String columnType = children.get(1 - constIdx).getTypeString().toLowerCase();

          if (inferTypes.contains(constType) && inferTypes.contains(columnType)
              && !columnType.equalsIgnoreCase(constType)) {
            String constValue =
                ((ExprNodeConstantDesc) children.get(constIdx)).getValue().toString();
            boolean triedDouble = false;

            Number value = null;
            try {
              if (columnType.equalsIgnoreCase(serdeConstants.TINYINT_TYPE_NAME)) {
                value = new Byte(constValue);
              } else if (columnType.equalsIgnoreCase(serdeConstants.SMALLINT_TYPE_NAME)) {
                value = new Short(constValue);
              } else if (columnType.equalsIgnoreCase(serdeConstants.INT_TYPE_NAME)) {
                value = new Integer(constValue);
              } else if (columnType.equalsIgnoreCase(serdeConstants.BIGINT_TYPE_NAME)) {
                value = new Long(constValue);
              } else if (columnType.equalsIgnoreCase(serdeConstants.FLOAT_TYPE_NAME)) {
                value = new Float(constValue);
              } else if (columnType.equalsIgnoreCase(serdeConstants.DOUBLE_TYPE_NAME)
                  || (columnType.equalsIgnoreCase(serdeConstants.STRING_TYPE_NAME)
                     && !constType.equalsIgnoreCase(serdeConstants.BIGINT_TYPE_NAME))) {
                // no smart inference for queries like "str_col = bigint_const"
                triedDouble = true;
                value = new Double(constValue);
              }
            } catch (NumberFormatException nfe) {
              // this exception suggests the precise type inference did not succeed
              // we'll try again to convert it to double
              // however, if we already tried this, or the column is NUMBER type and
              // the operator is EQUAL, return false due to the type mismatch
              if (triedDouble ||
                  (fi.getGenericUDF() instanceof GenericUDFOPEqual
                  && !columnType.equals(serdeConstants.STRING_TYPE_NAME))) {
                return new ExprNodeConstantDesc(false);
              }

              try {
                value = new Double(constValue);
              } catch (NumberFormatException ex) {
                return new ExprNodeConstantDesc(false);
              }
            }

            if (value != null) {
              children.set(constIdx, new ExprNodeConstantDesc(value));
            }
          }
        }

        desc = ExprNodeGenericFuncDesc.newInstance(fi.getGenericUDF(), children);
      }
      // UDFOPPositive is a no-op.
      // However, we still create it, and then remove it here, to make sure we
      // only allow
      // "+" for numeric types.
View Full Code Here

      if ((null == catalogName || "".equals(catalogName))
          && (null == schemaName || "".equals(schemaName))) {
        Set<String> functionNames =  FunctionRegistry
            .getFunctionNames(CLIServiceUtils.patternToRegex(functionName));
        for (String functionName : functionNames) {
          FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName);
          Object rowData[] = new Object[] {
              null, // FUNCTION_CAT
              null, // FUNCTION_SCHEM
              functionInfo.getDisplayName(), // FUNCTION_NAME
              "", // REMARKS
              (functionInfo.isGenericUDTF() ?
                  DatabaseMetaData.functionReturnsTable
                  : DatabaseMetaData.functionNoTable), // FUNCTION_TYPE
             functionInfo.getClass().getCanonicalName()
          };
          rowSet.addRow(RESULT_SET_SCHEMA, rowData);
        }
      }
      setState(OperationState.FINISHED);
View Full Code Here

      if (expressionTree.getChild(0).getType() == HiveParser.Identifier) {
        String functionName = unescapeIdentifier(expressionTree.getChild(0)
            .getText());
        if (FunctionRegistry.getGenericUDAFResolver(functionName) != null) {
          aggregations.put(expressionTree.toStringTree(), expressionTree);
          FunctionInfo fi = FunctionRegistry.getFunctionInfo(functionName);
          if (!fi.isNative()) {
            unparseTranslator.addIdentifierTranslation((ASTNode) expressionTree
                .getChild(0));
          }
          return;
        }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.exec.FunctionInfo

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.