當前位置: 首頁>>代碼示例>>Java>>正文


Java PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector方法的典型用法代碼示例。如果您正苦於以下問題:Java PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector方法的具體用法?Java PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector怎麽用?Java PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory的用法示例。


在下文中一共展示了PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入方法依賴的package包/類
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException(
            "extract_weight() has an single arguments: string feature");
    }

    argumentOI = (PrimitiveObjectInspector) arguments[0];
    if (argumentOI.getPrimitiveCategory() != PrimitiveCategory.STRING) {
        throw new UDFArgumentTypeException(0, "Type mismatch: feature");
    }

    return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.DOUBLE);
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:15,代碼來源:ExtractWeightUDFWrapper.java

示例2: initializeNumber

import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; //導入方法依賴的package包/類
private ObjectInspector initializeNumber(ObjectInspector[] arguments)
    throws UDFArgumentException {
  if (arguments.length < 1 || arguments.length > 2) {
    throw new UDFArgumentLengthException(
        "TRUNC requires one or two argument, got " + arguments.length);
  }

  if (arguments[0].getCategory() != Category.PRIMITIVE) {
    throw new UDFArgumentTypeException(0,
        "TRUNC input only takes primitive types, got " + arguments[0].getTypeName());
  }
  inputOI = (PrimitiveObjectInspector) arguments[0];

  if (arguments.length == 2) {
    if (arguments[1].getCategory() != Category.PRIMITIVE) {
      throw new UDFArgumentTypeException(1,
          "TRUNC second argument only takes primitive types, got " + arguments[1].getTypeName());
    }

    inputScaleOI = (PrimitiveObjectInspector) arguments[1];
    inputSacleConst = arguments[1] instanceof ConstantObjectInspector;
    if (inputSacleConst) {
      try {
        Object obj = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue();
        fmtInput = obj != null ? obj.toString() : null;
        scale = Integer.parseInt(fmtInput);
      } catch (Exception e) {
        throw new UDFArgumentException("TRUNC input only takes integer values, got " + fmtInput);
      }
    } else {
      switch (inputScaleOI.getPrimitiveCategory()) {
      case BYTE:
        byteConverter = ObjectInspectorConverters.getConverter(arguments[1],
            PrimitiveObjectInspectorFactory.writableByteObjectInspector);
        break;
      case SHORT:
        shortConverter = ObjectInspectorConverters.getConverter(arguments[1],
            PrimitiveObjectInspectorFactory.writableShortObjectInspector);
        break;
      case INT:
        intConverter = ObjectInspectorConverters.getConverter(arguments[1],
            PrimitiveObjectInspectorFactory.writableIntObjectInspector);
        break;
      case LONG:
        longConverter = ObjectInspectorConverters.getConverter(arguments[1],
            PrimitiveObjectInspectorFactory.writableLongObjectInspector);
        break;
      default:
        throw new UDFArgumentTypeException(1,
            getFuncName().toUpperCase() + " second argument only takes integer values");
      }
    }
  }

  inputType1 = inputOI.getPrimitiveCategory();
  ObjectInspector outputOI = null;
  switch (inputType1) {
  case DECIMAL:
    outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType1);
    break;
  case VOID:
  case BYTE:
  case SHORT:
  case INT:
  case LONG:
  case FLOAT:
  case DOUBLE:
    outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputType1);
    break;
  default:
    throw new UDFArgumentTypeException(0,
        "Only numeric or string group data types are allowed for TRUNC function. Got "
            + inputType1.name());
  }

  return outputOI;
}
 
開發者ID:myui,項目名稱:hive-udf-backports,代碼行數:78,代碼來源:GenericUDFTrunc.java


注:本文中的org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。