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

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector#getTypeName() . 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 asDoubleCompatibleOI(
        @Nonnull final ObjectInspector[] argOIs, final int argIndex)
        throws UDFArgumentException {
    final PrimitiveObjectInspector oi = asPrimitiveObjectInspector(argOIs, argIndex);
    switch (oi.getPrimitiveCategory()) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case STRING:
        case TIMESTAMP:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Only numeric or string type arguments are accepted but " + oi.getTypeName()
                        + " is passed for argument index " + argIndex);
    }
    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 asNumberOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    final PrimitiveObjectInspector oi = asPrimitiveObjectInspector(argOIs, argIndex);
    switch (oi.getPrimitiveCategory()) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Only numeric argument is accepted but " + oi.getTypeName() + " is passed.");
    }
    return oi;
}
 
Example 3
Source File: CacheableObjectInspectorConverters.java    From transport with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Converter getConverter(PrimitiveObjectInspector inputOI, PrimitiveObjectInspector outputOI) {
  Converter c = getConverterFromCache(inputOI, outputOI);
  if (c != null) {
    return c;
  }
  switch (outputOI.getPrimitiveCategory()) {
    case BOOLEAN:
      c = new CacheablePrimitiveObjectInspectorConverter.BooleanConverter(inputOI,
          (SettableBooleanObjectInspector) outputOI);
      break;
    case BYTE:
      c = new CacheablePrimitiveObjectInspectorConverter.ByteConverter(inputOI,
          (SettableByteObjectInspector) outputOI);
      break;
    case SHORT:
      c = new CacheablePrimitiveObjectInspectorConverter.ShortConverter(inputOI,
          (SettableShortObjectInspector) outputOI);
      break;
    case INT:
      c = new CacheablePrimitiveObjectInspectorConverter.IntConverter(inputOI, (SettableIntObjectInspector) outputOI);
      break;
    case LONG:
      c = new CacheablePrimitiveObjectInspectorConverter.LongConverter(inputOI,
          (SettableLongObjectInspector) outputOI);
      break;
    case FLOAT:
      c = new CacheablePrimitiveObjectInspectorConverter.FloatConverter(inputOI,
          (SettableFloatObjectInspector) outputOI);
      break;
    case DOUBLE:
      c = new CacheablePrimitiveObjectInspectorConverter.DoubleConverter(inputOI,
          (SettableDoubleObjectInspector) outputOI);
      break;
    case STRING:
      if (outputOI instanceof WritableStringObjectInspector) {
        c = new CacheablePrimitiveObjectInspectorConverter.TextConverter(inputOI);
      } else if (outputOI instanceof JavaStringObjectInspector) {
        c = new CacheablePrimitiveObjectInspectorConverter.StringConverter(inputOI);
      }
      break;
    case CHAR:
      c = new CacheablePrimitiveObjectInspectorConverter.HiveCharConverter(inputOI,
          (SettableHiveCharObjectInspector) outputOI);
      break;
    case VARCHAR:
      c = new CacheablePrimitiveObjectInspectorConverter.HiveVarcharConverter(inputOI,
          (SettableHiveVarcharObjectInspector) outputOI);
      break;
    case DATE:
      c = new CacheablePrimitiveObjectInspectorConverter.DateConverter(inputOI,
          (SettableDateObjectInspector) outputOI);
      break;
    case TIMESTAMP:
      c = new CacheablePrimitiveObjectInspectorConverter.TimestampConverter(inputOI,
          (SettableTimestampObjectInspector) outputOI);
      break;
    case BINARY:
      c = new CacheablePrimitiveObjectInspectorConverter.BinaryConverter(inputOI,
          (SettableBinaryObjectInspector) outputOI);
      break;
    case DECIMAL:
      c = new CacheablePrimitiveObjectInspectorConverter.HiveDecimalConverter(inputOI,
          (SettableHiveDecimalObjectInspector) outputOI);
      break;
    default:
      throw new UnsupportedOperationException(
          "Hive internal error: conversion of " + inputOI.getTypeName() + " to " + outputOI.getTypeName()
              + " not supported yet.");
  }
  cacheConverter(inputOI, outputOI, c);
  return c;
}
 
Example 4
Source File: HiveColumnarSerdeResolver.java    From pxf with Apache License 2.0 4 votes vote down vote up
private void resolvePrimitive(Object o, PrimitiveObjectInspector oi) throws IOException {

        if (!firstColumn) {
            builder.append(delimiter);
        }

        if (o == null) {
            builder.append(nullChar);
        } else {
            switch (oi.getPrimitiveCategory()) {
                case BOOLEAN:
                    builder.append(((BooleanObjectInspector) oi).get(o));
                    break;
                case SHORT:
                    builder.append(((ShortObjectInspector) oi).get(o));
                    break;
                case INT:
                    builder.append(((IntObjectInspector) oi).get(o));
                    break;
                case LONG:
                    builder.append(((LongObjectInspector) oi).get(o));
                    break;
                case FLOAT:
                    builder.append(((FloatObjectInspector) oi).get(o));
                    break;
                case DOUBLE:
                    builder.append(((DoubleObjectInspector) oi).get(o));
                    break;
                case DECIMAL:
                    builder.append(((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o).bigDecimalValue());
                    break;
                case STRING:
                    builder.append(((StringObjectInspector) oi).getPrimitiveJavaObject(o));
                    break;
                case BINARY:
                    byte[] bytes = ((BinaryObjectInspector) oi).getPrimitiveJavaObject(o);
                    Utilities.byteArrayToOctalString(bytes, builder);
                    break;
                case TIMESTAMP:
                    builder.append(((TimestampObjectInspector) oi).getPrimitiveJavaObject(o));
                    break;
                case BYTE:  /* TINYINT */
                    builder.append(Short.valueOf(((ByteObjectInspector) oi).get(o)));
                    break;
                default:
                    throw new UnsupportedTypeException(oi.getTypeName()
                            + " conversion is not supported by HiveColumnarSerdeResolver");
            }
        }
        firstColumn = false;
    }