Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector. These examples are extracted from open source projects. 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 Project: transport   Source File: HiveMap.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void put(StdData key, StdData value) {
  if (_mapObjectInspector instanceof SettableMapObjectInspector) {
    Object keyObj = ((HiveData) key).getUnderlyingDataForObjectInspector(_keyObjectInspector);
    Object valueObj = ((HiveData) value).getUnderlyingDataForObjectInspector(_valueObjectInspector);

    ((SettableMapObjectInspector) _mapObjectInspector).put(
        _object,
        keyObj,
        valueObj
    );
    _isObjectModified = true;
  } else {
    throw new RuntimeException("Attempt to modify an immutable Hive object of type: "
        + _mapObjectInspector.getClass());
  }
}
 
Example 2
public MapConverter(ObjectInspector inputOI, SettableMapObjectInspector outputOI) {
  if (inputOI instanceof MapObjectInspector) {
    this.inputOI = (MapObjectInspector) inputOI;
    this.outputOI = outputOI;
    inputKeyOI = this.inputOI.getMapKeyObjectInspector();
    outputKeyOI = outputOI.getMapKeyObjectInspector();
    inputValueOI = this.inputOI.getMapValueObjectInspector();
    outputValueOI = outputOI.getMapValueObjectInspector();
    keyConverter = getConverter(inputKeyOI, outputKeyOI);
    valueConverter = getConverter(inputValueOI, outputValueOI);
  } else if (!(inputOI instanceof VoidObjectInspector)) {
    throw new UnsupportedOperationException(
        "Hive internal error: conversion of " + inputOI.getTypeName() + " to " + outputOI.getTypeName()
            + "not supported yet.");
  }
}
 
Example 3
/**
 * Returns a converter that converts objects from one OI to another OI. The
 * returned (converted) object does not belong to the converter. Hence once convertor can be used
 * multiple times within one eval invocation.
 */
public Converter getConverter(ObjectInspector inputOI, ObjectInspector outputOI) {
  // If the inputOI is the same as the outputOI, just return an
  // IdentityConverter.
  if (inputOI.equals(outputOI)) {
    return new ObjectInspectorConverters.IdentityConverter();
  }
  Converter c = getConverterFromCache(inputOI, outputOI);
  if (c != null) {
    return c;
  }
  switch (outputOI.getCategory()) {
    case PRIMITIVE:
      return getConverter((PrimitiveObjectInspector) inputOI, (PrimitiveObjectInspector) outputOI);
    case STRUCT:
      c = new StructConverter(inputOI, (SettableStructObjectInspector) outputOI);
      break;
    case LIST:
      c = new ListConverter(inputOI, (SettableListObjectInspector) outputOI);
      break;
    case MAP:
      c = new MapConverter(inputOI, (SettableMapObjectInspector) 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;
}