Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector#getPrimitiveCategory()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector#getPrimitiveCategory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntegerOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    final ObjectInspector argOI = getObjectInspector(argOIs, argIndex);
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(argIndex,
            "Only primitive type arguments are accepted but " + argOI.getTypeName()
                    + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example 2
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntegerOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example 3
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asLongCompatibleOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case LONG:
        case INT:
        case SHORT:
        case BYTE:
        case BOOLEAN:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case STRING:
        case TIMESTAMP:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example 4
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntCompatibleOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case BOOLEAN:
        case BYTE:
        case STRING:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example 5
Source File: HiveObjectConverter.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
public static Object convert(ObjectInspector objectInspector, Object o, TypeInfo odpsTypeInfo) {

    if (objectInspector.getCategory().equals(Category.PRIMITIVE)) {
      PrimitiveObjectInspector primitiveObjectInspector =
          (PrimitiveObjectInspector) objectInspector;
      AbstractHiveObjectConverter hiveObjectConverter =
          primitiveCategoryToObjectConverter.get(primitiveObjectInspector.getPrimitiveCategory());
      if (hiveObjectConverter == null) {
        throw new IllegalArgumentException(
            "Unsupported hive data type:" + primitiveObjectInspector.getPrimitiveCategory());
      }
      return hiveObjectConverter.convert(objectInspector, o, odpsTypeInfo);

    } else if (objectInspector.getCategory().equals(Category.LIST)) {

      return hiveListObjectConverter.convert(objectInspector, o, odpsTypeInfo);
    } else if (objectInspector.getCategory().equals(Category.MAP)) {
      return hiveMapObjectConverter.convert(objectInspector, o, odpsTypeInfo);
    } else if (objectInspector.getCategory().equals(Category.STRUCT)) {
      return hiveStructObjectConverter.convert(objectInspector, o, odpsTypeInfo);
    } else {
      throw new IllegalArgumentException(
          "Unsupported hive data type: " + objectInspector.getCategory());
    }
  }
 
Example 6
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
static void validateIntegralParameter(final ObjectInspector inspector, final int index)
    throws UDFArgumentTypeException {
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  switch (primitiveInspector.getPrimitiveCategory()) {
  case BYTE:
  case SHORT:
  case INT:
  case LONG:
    break;
  // all other types are invalid
  default:
    throw new UDFArgumentTypeException(index, "Only integral type parameters are expected but "
        + primitiveInspector.getPrimitiveCategory().name() + " was passed as parameter " + (index + 1));
  }
}
 
Example 7
Source File: ST_Bin.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] OIs)
		throws UDFArgumentException {
	
	if (OIs.length != 2) {
		throw new UDFArgumentException("Function takes exactly 2 arguments");
	}

	if (OIs[0].getCategory() != Category.PRIMITIVE) {
		throw new UDFArgumentException("Argument 0 must be a number - got: " + OIs[0].getCategory());
	}

	oiBinSize = (PrimitiveObjectInspector)OIs[0];
	if (!EnumSet.of(PrimitiveCategory.DECIMAL,PrimitiveCategory.DOUBLE,PrimitiveCategory.INT,PrimitiveCategory.LONG,PrimitiveCategory.SHORT, PrimitiveCategory.FLOAT).contains(oiBinSize.getPrimitiveCategory())) {
		throw new UDFArgumentException("Argument 0 must be a number - got: " + oiBinSize.getPrimitiveCategory());
	}

	geomHelper = HiveGeometryOIHelper.create(OIs[1], 1);
	binSizeIsConstant = ObjectInspectorUtils.isConstantObjectInspector(OIs[0]);

	return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
}
 
Example 8
Source File: BetweenHiveExpr.java    From multiple-dimension-spread with Apache License 2.0 6 votes vote down vote up
public static IExpressionNode getRangeExecuter( boolean invert , final PrimitiveObjectInspector minPrimitiveObjectInspector , final PrimitiveObjectInspector maxPrimitiveObjectInspector , final IExtractNode targetColumn ){
  switch( minPrimitiveObjectInspector.getPrimitiveCategory() ){
    case STRING:
      String minStr =  ( (WritableConstantStringObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().toString();
      String maxStr =  ( (WritableConstantStringObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().toString();
      IFilter filter = new RangeStringCompareFilter( minStr , true , maxStr , true , invert );
      return new ExecuterNode( targetColumn , filter );
    case BYTE:
      return getNumberRangeExecuter( invert , new ByteObj( ( (WritableConstantByteObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new ByteObj( ( (WritableConstantByteObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case SHORT:
      return getNumberRangeExecuter( invert , new ShortObj( ( (WritableConstantShortObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new ShortObj( ( (WritableConstantShortObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case INT:
      return getNumberRangeExecuter( invert , new IntegerObj( ( (WritableConstantIntObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new IntegerObj( ( (WritableConstantIntObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case LONG:
      return getNumberRangeExecuter( invert , new LongObj( ( (WritableConstantLongObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new LongObj( ( (WritableConstantLongObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case FLOAT:
      return getNumberRangeExecuter( invert , new FloatObj( ( (WritableConstantFloatObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new FloatObj( ( (WritableConstantFloatObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    case DOUBLE:
      return getNumberRangeExecuter( invert , new DoubleObj( ( (WritableConstantDoubleObjectInspector)minPrimitiveObjectInspector ).getWritableConstantValue().get() ) , new DoubleObj( ( (WritableConstantDoubleObjectInspector)maxPrimitiveObjectInspector ).getWritableConstantValue().get() ) , targetColumn );
    default:
      return null;
  }
}
 
Example 9
Source File: FeatureUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private static void validateFeatureOI(@Nonnull ObjectInspector argOI)
        throws UDFArgumentException {
    if (!HiveUtils.isPrimitiveOI(argOI)) {
        throw new UDFArgumentException(
            "_FUNC_ expects integer type or string for `feature` but got "
                    + argOI.getTypeName());
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
        case STRING:
            break;
        default: {
            throw new UDFArgumentException(
                "_FUNC_ expects integer type or string for `feature` but got "
                        + argOI.getTypeName());
        }
    }
}
 
Example 10
Source File: DataToItemsSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info)
    throws SemanticException {
  final ObjectInspector[] inspectors = info.getParameterObjectInspectors();
  if (inspectors.length != 2) {
    throw new UDFArgumentException("Two arguments expected");
  }

  if (inspectors[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
    throw new UDFArgumentTypeException(0, "Primitive argument expected, but "
        + inspectors[0].getTypeName() + " was recieved");
  }

  if (inspectors[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
    throw new UDFArgumentTypeException(0, "Primitive argument expected, but "
        + inspectors[1].getTypeName() + " was recieved");
  }
  final PrimitiveObjectInspector inspector2 = (PrimitiveObjectInspector) inspectors[1];
  if (inspector2.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.INT) {
    throw new UDFArgumentTypeException(0, "Integer value expected as the second argument, but "
        + inspector2.getPrimitiveCategory().name() + " was received");
  }

  return createEvaluator();
}
 
Example 11
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
static void validateIntegralParameter(final ObjectInspector inspector, final int index)
    throws UDFArgumentTypeException {
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  switch (primitiveInspector.getPrimitiveCategory()) {
  case BYTE:
  case SHORT:
  case INT:
  case LONG:
    break;
  // all other types are invalid
  default:
    throw new UDFArgumentTypeException(index, "Only integral type parameters are expected but "
        + primitiveInspector.getPrimitiveCategory().name() + " was passed as parameter " + (index + 1));
  }
}
 
Example 12
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
static void validateIntegralParameter(final ObjectInspector inspector, final int index)
    throws UDFArgumentTypeException {
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  switch (primitiveInspector.getPrimitiveCategory()) {
  case BYTE:
  case SHORT:
  case INT:
  case LONG:
    break;
  // all other types are invalid
  default:
    throw new UDFArgumentTypeException(index, "Only integral type parameters are expected but "
        + primitiveInspector.getPrimitiveCategory().name() + " was passed as parameter " + (index + 1));
  }
}
 
Example 13
Source File: DataToSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException {
  final ObjectInspector[] inspectors = info.getParameterObjectInspectors();

  if (inspectors.length < 2) {
    throw new UDFArgumentException("Expected at least 2 arguments");
  }
  ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0);

  // No validation of the value inspector since it can be anything.
  // Override this method to validate if needed.

  // nominal number of entries
  if (inspectors.length > 2) {
    ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2);
  }

  // sampling probability
  if (inspectors.length > 3) {
    ObjectInspectorValidator.validateCategoryPrimitive(inspectors[3], 3);
    final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspectors[3];
    if ((primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.FLOAT)
        && (primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.DOUBLE)) {
      throw new UDFArgumentTypeException(3, "float or double value expected as parameter 4 but "
          + primitiveInspector.getPrimitiveCategory().name() + " was received");
    }
  }

  checkExtraArguments(inspectors);

  return createEvaluator();
}
 
Example 14
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
static void validateGivenPrimitiveCategory(final ObjectInspector inspector, final int index,
    final PrimitiveObjectInspector.PrimitiveCategory category) throws SemanticException
{
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  if (primitiveInspector.getPrimitiveCategory() != category) {
    throw new UDFArgumentTypeException(index, category.name() + " value expected as the argument "
        + (index + 1) + " but " + primitiveInspector.getPrimitiveCategory().name() + " was received");
  }
}
 
Example 15
Source File: ObjectInspectorValidator.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
static void validateGivenPrimitiveCategory(final ObjectInspector inspector, final int index,
    final PrimitiveObjectInspector.PrimitiveCategory category) throws SemanticException
{
  validateCategoryPrimitive(inspector, index);
  final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspector;
  if (primitiveInspector.getPrimitiveCategory() != category) {
    throw new UDFArgumentTypeException(index, category.name() + " value expected as the argument "
        + (index + 1) + " but " + primitiveInspector.getPrimitiveCategory().name() + " was received");
  }
}
 
Example 16
Source File: HiveORCVectorizedReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private ColumnVector getPrimitiveColumnVector(PrimitiveObjectInspector poi) {
    switch (poi.getPrimitiveCategory()) {
    case BOOLEAN:
    case BYTE:
    case SHORT:
    case INT:
    case LONG:
    case DATE:
      return new LongColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    case TIMESTAMP:
      return new TimestampColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    case FLOAT:
    case DOUBLE:
      return new DoubleColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    case BINARY:
    case STRING:
    case CHAR:
    case VARCHAR:
      return new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
    case DECIMAL:
      DecimalTypeInfo tInfo = (DecimalTypeInfo) poi.getTypeInfo();
      return new DecimalColumnVector(VectorizedRowBatch.DEFAULT_SIZE,
        tInfo.precision(), tInfo.scale()
      );
    default:
      throw UserException.unsupportedError()
        .message("Vectorized ORC reader is not supported for datatype: %s", poi.getPrimitiveCategory())
        .build(logger);
    }
}
 
Example 17
Source File: SketchState.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
void update(final Object data, final PrimitiveObjectInspector keyObjectInspector, final U value) {
  switch (keyObjectInspector.getPrimitiveCategory()) {
  case BINARY:
    sketch_.update(PrimitiveObjectInspectorUtils.getBinary(data, keyObjectInspector).copyBytes(), value);
    return;
  case BYTE:
    sketch_.update(PrimitiveObjectInspectorUtils.getByte(data, keyObjectInspector), value);
    return;
  case DOUBLE:
    sketch_.update(PrimitiveObjectInspectorUtils.getDouble(data, keyObjectInspector), value);
    return;
  case FLOAT:
    sketch_.update(PrimitiveObjectInspectorUtils.getFloat(data, keyObjectInspector), value);
    return;
  case INT:
    sketch_.update(PrimitiveObjectInspectorUtils.getInt(data, keyObjectInspector), value);
    return;
  case LONG:
    sketch_.update(PrimitiveObjectInspectorUtils.getLong(data, keyObjectInspector), value);
    return;
  case STRING:
    sketch_.update(PrimitiveObjectInspectorUtils.getString(data, keyObjectInspector), value);
    return;
  default:
    throw new IllegalArgumentException(
        "Unrecongnized input data type, please use data of type: "
    + "byte, double, float, int, long, or string only.");
  }
}
 
Example 18
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
public static boolean isIntegerOI(@Nonnull final ObjectInspector argOI) {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        return false;
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
            return true;
        default:
            return false;
    }
}
 
Example 19
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntCompatibleOI(
        @Nonnull final ObjectInspector[] argOIs, final int argIndex)
        throws UDFArgumentException {
    ObjectInspector argOI = getObjectInspector(argOIs, argIndex);
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(argIndex,
            "Only primitive type arguments are accepted but " + argOI.getTypeName()
                    + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case BOOLEAN:
        case BYTE:
        case STRING:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example 20
Source File: UnionState.java    From incubator-datasketches-hive with Apache License 2.0 4 votes vote down vote up
@Override
void update(final Object data, final PrimitiveObjectInspector objectInspector) {
  switch (objectInspector.getPrimitiveCategory()) {
    case BINARY:
      union_.update(PrimitiveObjectInspectorUtils.getBinary(data, objectInspector)
          .copyBytes());
      return;
    case BYTE:
      union_.update(PrimitiveObjectInspectorUtils.getByte(data, objectInspector));
      return;
    case DOUBLE:
      union_.update(PrimitiveObjectInspectorUtils.getDouble(data, objectInspector));
      return;
    case FLOAT:
      union_.update(PrimitiveObjectInspectorUtils.getFloat(data, objectInspector));
      return;
    case INT:
      union_.update(PrimitiveObjectInspectorUtils.getInt(data, objectInspector));
      return;
    case LONG:
      union_.update(PrimitiveObjectInspectorUtils.getLong(data, objectInspector));
      return;
    case STRING:
      // conversion to char[] avoids costly UTF-8 encoding
      union_.update(PrimitiveObjectInspectorUtils.getString(data, objectInspector)
          .toCharArray());
      return;
    case CHAR:
      union_.update(PrimitiveObjectInspectorUtils.getHiveChar(data, objectInspector)
          .getValue().toCharArray());
      return;
    case VARCHAR:
      union_.update(PrimitiveObjectInspectorUtils.getHiveVarchar(data, objectInspector)
          .getValue().toCharArray());
      return;
    default:
      throw new IllegalArgumentException(
        "Unrecongnized input data type " + data.getClass().getSimpleName() + " category "
        + objectInspector.getPrimitiveCategory() + ", please use data of the following types: "
        + "byte, double, float, int, long, char, varchar or string.");
  }
}