Package org.apache.hadoop.hive.ql.udf.generic

Examples of org.apache.hadoop.hive.ql.udf.generic.GenericUDF$DeferredObject


      long numRows = stats.getNumRows();

      if (child instanceof ExprNodeGenericFuncDesc) {

        ExprNodeGenericFuncDesc genFunc = (ExprNodeGenericFuncDesc) child;
        GenericUDF udf = genFunc.getGenericUDF();

        if (udf instanceof GenericUDFOPEqual ||
            udf instanceof GenericUDFOPEqualNS) {
          String colName = null;
          String tabAlias = null;
View Full Code Here


    ExprNodeConstantDesc folded = foldConstant(((ExprNodeGenericFuncDesc) expr));
    return folded == null ? expr : folded;
  }

  private static ExprNodeConstantDesc foldConstant(ExprNodeGenericFuncDesc func) {
    GenericUDF udf = func.getGenericUDF();
    if (!FunctionRegistry.isDeterministic(udf) || FunctionRegistry.isStateful(udf)) {
      return null;
    }
    try {
      // If the UDF depends on any external resources, we can't fold because the
      // resources may not be available at compile time.
      if (udf instanceof GenericUDFBridge) {
        UDF internal = ReflectionUtils.newInstance(((GenericUDFBridge) udf).getUdfClass(), null);
        if (internal.getRequiredFiles() != null || internal.getRequiredJars() != null) {
          return null;
        }
      } else {
        if (udf.getRequiredFiles() != null || udf.getRequiredJars() != null) {
          return null;
        }
      }

      if (func.getChildren() != null) {
View Full Code Here

      } else {
        throw new IllegalStateException("Unexpected non-null ExprNodeConstantDesc: "
          + expr.getExprString());
      }
    } else if (expr instanceof ExprNodeGenericFuncDesc) {
      GenericUDF udf = ((ExprNodeGenericFuncDesc)expr).getGenericUDF();
      boolean isAnd = udf instanceof GenericUDFOPAnd;
      boolean isOr = udf instanceof GenericUDFOPOr;
     
      if (isAnd || isOr) {
        List<ExprNodeDesc> children = expr.getChildren();
View Full Code Here

    return new ExprNodeConstantDesc(ti, convObj);
  }

  public static ExprNodeDesc foldExpr(ExprNodeGenericFuncDesc funcDesc) {

    GenericUDF udf = funcDesc.getGenericUDF();
    if (!isDeterministicUdf(udf)) {
      return funcDesc;
    }
    return evaluateFunction(funcDesc.getGenericUDF(),funcDesc.getChildren(), funcDesc.getChildren());
  }
View Full Code Here

      boolean propagate) {
    if (desc instanceof ExprNodeGenericFuncDesc) {
      ExprNodeGenericFuncDesc funcDesc = (ExprNodeGenericFuncDesc) desc;

      // The function must be deterministic, or we can't fold it.
      GenericUDF udf = funcDesc.getGenericUDF();
      if (!isDeterministicUdf(udf)) {
        LOG.debug("Function " + udf.getClass() + " undeterministic, quit folding.");
        return desc;
      }

      boolean propagateNext = propagate && propagatableUdfs.contains(udf.getClass());
      List<ExprNodeDesc> newExprs = new ArrayList<ExprNodeDesc>();
      for (ExprNodeDesc childExpr : desc.getChildren()) {
        newExprs.add(foldExpr(childExpr, constants, cppCtx, op, tag, propagateNext));
      }
View Full Code Here

  }

  protected Object processExpression(ExprNodeGenericFuncDesc func, Object[] nodeOutputs)
      throws SemanticException {
    // a binary operator (gt, lt, ge, le, eq, ne)
    GenericUDF genericUdf = func.getGenericUDF();

    // Find the argument to the operator which is a constant
    ExprNodeConstantDesc constantDesc = null;
    ExprNodeColumnDesc columnDesc = null;
    ExprNodeDesc leftHandNode = null;
    for (Object nodeOutput : nodeOutputs) {
      if (nodeOutput instanceof ExprNodeConstantDesc) {
        // Ordering of constant and column in expression is important in correct range generation
        if (null == leftHandNode) {
          leftHandNode = (ExprNodeDesc) nodeOutput;
        }

        constantDesc = (ExprNodeConstantDesc) nodeOutput;
      } else if (nodeOutput instanceof ExprNodeColumnDesc) {
        // Ordering of constant and column in expression is important in correct range generation
        if (null == leftHandNode) {
          leftHandNode = (ExprNodeDesc) nodeOutput;
        }

        columnDesc = (ExprNodeColumnDesc) nodeOutput;
      }
    }

    // If it's constant = constant or column = column, we can't fetch any ranges
    // TODO We can try to be smarter and push up the value to some node which
    // we can generate ranges from e.g. rowid > (4 + 5)
    if (null == constantDesc || null == columnDesc) {
      return null;
    }

    // Reject any clauses that are against a column that isn't the rowId mapping
    if (!this.hiveRowIdColumnName.equals(columnDesc.getColumn())) {
      return null;
    }

    ConstantObjectInspector objInspector = constantDesc.getWritableObjectInspector();

    Text constText;
    switch (rowIdMapping.getEncoding()) {
      case STRING:
        constText = getUtf8Value(objInspector);
        break;
      case BINARY:
        try {
          constText = getBinaryValue(objInspector);
        } catch (IOException e) {
          throw new SemanticException(e);
        }
        break;
      default:
        throw new SemanticException("Unable to parse unknown encoding: "
            + rowIdMapping.getEncoding());
    }

    Class<? extends CompareOp> opClz;
    try {
      opClz = predicateHandler.getCompareOpClass(genericUdf.getUdfName());
    } catch (NoSuchCompareOpException e) {
      throw new IllegalArgumentException("Unhandled UDF class: " + genericUdf.getUdfName());
    }

    if (leftHandNode instanceof ExprNodeConstantDesc) {
      return getConstantOpColumnRange(opClz, constText);
    } else if (leftHandNode instanceof ExprNodeColumnDesc) {
View Full Code Here

      if (nodeEvaluator instanceof ExprNodeGenericFuncEvaluator) {
        if (((ExprNodeGenericFuncEvaluator) nodeEvaluator).isEager) {
          isEager = true;
        }
        // Base case:  we are eager if a child is stateful
        GenericUDF childUDF =
          ((ExprNodeGenericFuncDesc) child).getGenericUDF();
        if (FunctionRegistry.isStateful(childUDF)) {
          isEager = true;
        }
      }
View Full Code Here

      }

      List<RexNode> args = new LinkedList<RexNode>();
      boolean argsPruned = false;

      GenericUDF hiveUDF = SqlFunctionConverter.getHiveUDF(call.getOperator(),
          call.getType(), call.operands.size());
      if (hiveUDF != null &&
          !FunctionRegistry.isDeterministic(hiveUDF)) {
        return null;
      }
View Full Code Here

    List<RexNode> childRexNodeLst = new LinkedList<RexNode>();
    Builder<RelDataType> argTypeBldr = ImmutableList.<RelDataType> builder();

    // TODO: 1) Expand to other functions as needed 2) What about types other than primitive.
    TypeInfo tgtDT = null;
    GenericUDF tgtUdf = func.getGenericUDF();
    boolean isNumeric = tgtUdf instanceof GenericUDFBaseNumeric,
        isCompare = !isNumeric && tgtUdf instanceof GenericUDFBaseCompare;
    if (isNumeric) {
      tgtDT = func.getTypeInfo();
View Full Code Here

  private RexNode handleExplicitCast(ExprNodeGenericFuncDesc func, List<RexNode> childRexNodeLst)
      throws OptiqSemanticException {
    RexNode castExpr = null;

    if (childRexNodeLst != null && childRexNodeLst.size() == 1) {
      GenericUDF udf = func.getGenericUDF();
      if ((udf instanceof GenericUDFToChar) || (udf instanceof GenericUDFToVarchar)
          || (udf instanceof GenericUDFToDecimal) || (udf instanceof GenericUDFToDate)
          || (udf instanceof GenericUDFToBinary) || castExprUsingUDFBridge(udf)) {
        castExpr = cluster.getRexBuilder().makeAbstractCast(
            TypeConverter.convert(func.getTypeInfo(), cluster.getTypeFactory()),
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.udf.generic.GenericUDF$DeferredObject

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.