当前位置: 首页>>代码示例>>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;未经允许,请勿转载。