Package org.apache.hadoop.hive.serde2.objectinspector

Examples of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector


    row = new ArrayList<Writable>(numColumns);
   
    // set each value in rowBase to the writable that corresponds with its PrimitiveObjectInspector
    for (int c = 0; c < numColumns; c++) {
     
      PrimitiveObjectInspector poi = (PrimitiveObjectInspector)columnOIs.get(c);
      Writable writable;
     
      try {
        writable = (Writable)poi.getPrimitiveWritableClass().newInstance();
      } catch (InstantiationException e) {
        throw new SerDeException("Error creating Writable from ObjectInspector", e);
      } catch (IllegalAccessException e) {
        throw new SerDeException("Error creating Writable from ObjectInspector", e);
      }
View Full Code Here


   * @throws JsonParseException
   * @throws IOException
   */
  private void setRowFieldFromParser(int fieldIndex, JsonParser parser) throws JsonParseException, IOException{

    PrimitiveObjectInspector poi = (PrimitiveObjectInspector)this.columnOIs.get(fieldIndex);
   
    // set the field in the row to the writable from rowBase
    row.set(fieldIndex, rowBase.get(fieldIndex));

    switch (poi.getPrimitiveCategory()){
    case SHORT:
      ((ShortWritable)row.get(fieldIndex)).set(parser.getShortValue());
      break;
    case INT:
      ((IntWritable)row.get(fieldIndex)).set(parser.getIntValue());
View Full Code Here

   * @throws IOException
   */
  private void generateJsonFromValue(Writable value, int fieldIndex, JsonGenerator jsonGen)
    throws JsonProcessingException, IOException {

    PrimitiveObjectInspector poi = (PrimitiveObjectInspector)this.columnOIs.get(fieldIndex);

    switch (poi.getPrimitiveCategory()) {
    case SHORT:
      jsonGen.writeObjectField(columnNames.get(fieldIndex), ((ShortWritable)value).get());
      break;
    case INT:
      jsonGen.writeObjectField(columnNames.get(fieldIndex), ((IntWritable)value).get());
View Full Code Here

    }

    private static ObjectInspector getJavaObjectInspector(ObjectInspector objectInspector)
    {
        checkArgument(objectInspector.getCategory() == Category.PRIMITIVE, "Unsupported object inspector category %s", objectInspector.getCategory());
        PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) objectInspector);
        switch (poi.getPrimitiveCategory()) {
            case BOOLEAN:
                return javaBooleanObjectInspector;
            case BYTE:
                return javaByteObjectInspector;
            case SHORT:
                return javaShortObjectInspector;
            case INT:
                return javaIntObjectInspector;
            case LONG:
                return javaLongObjectInspector;
            case STRING:
                return javaStringObjectInspector;
        }
        throw new RuntimeException("Unsupported type: " + poi.getPrimitiveCategory());
    }
View Full Code Here

    }

    private static DeferredObject getJavaDeferredObject(Object object, ObjectInspector objectInspector)
    {
        checkArgument(objectInspector.getCategory() == Category.PRIMITIVE, "Unsupported object inspector category %s", objectInspector.getCategory());
        PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) objectInspector);
        switch (poi.getPrimitiveCategory()) {
            case BOOLEAN:
                return new DeferredJavaObject(object);
            case BYTE:
                return new DeferredJavaObject(((Long) object).byteValue());
            case SHORT:
                return new DeferredJavaObject(((Long) object).shortValue());
            case INT:
                return new DeferredJavaObject(((Long) object).intValue());
            case LONG:
                return new DeferredJavaObject(object);
            case STRING:
                return new DeferredJavaObject(((Slice) object).toStringUtf8());
        }
        throw new RuntimeException("Unsupported type: " + poi.getPrimitiveCategory());
    }
View Full Code Here

  // Also, throws IOException when Binary is detected.
  private static void buildJSONString(StringBuilder sb, Object o, ObjectInspector oi) throws IOException {

    switch (oi.getCategory()) {
    case PRIMITIVE: {
      PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
      if (o == null) {
        sb.append("null");
      } else {
        switch (poi.getPrimitiveCategory()) {
        case BOOLEAN: {
          boolean b = ((BooleanObjectInspector) poi).get(o);
          sb.append(b ? "true" : "false");
          break;
        }
        case BYTE: {
          sb.append(((ByteObjectInspector) poi).get(o));
          break;
        }
        case SHORT: {
          sb.append(((ShortObjectInspector) poi).get(o));
          break;
        }
        case INT: {
          sb.append(((IntObjectInspector) poi).get(o));
          break;
        }
        case LONG: {
          sb.append(((LongObjectInspector) poi).get(o));
          break;
        }
        case FLOAT: {
          sb.append(((FloatObjectInspector) poi).get(o));
          break;
        }
        case DOUBLE: {
          sb.append(((DoubleObjectInspector) poi).get(o));
          break;
        }
        case STRING: {
          sb.append('"');
          sb.append(SerDeUtils.escapeString(((StringObjectInspector) poi)
              .getPrimitiveJavaObject(o)));
          sb.append('"');
          break;
        }
        case TIMESTAMP: {
          sb.append('"');
          sb.append(((TimestampObjectInspector) poi)
              .getPrimitiveWritableObject(o));
          sb.append('"');
          break;
        }
        case BINARY: {
          throw new IOException("JsonSerDe does not support BINARY type");
        }
        default:
          throw new RuntimeException("Unknown primitive type: "
              + poi.getPrimitiveCategory());
        }
      }
      break;
    }
    case LIST: {
View Full Code Here

    // Convert the search condition into a restriction on the HBase scan
    byte [] startRow = HConstants.EMPTY_START_ROW, stopRow = HConstants.EMPTY_END_ROW;
    for (IndexSearchCondition sc : searchConditions){

      ExprNodeConstantEvaluator eval = new ExprNodeConstantEvaluator(sc.getConstantDesc());
      PrimitiveObjectInspector objInspector;
      Object writable;

      try{
        objInspector = (PrimitiveObjectInspector)eval.initialize(null);
        writable = eval.evaluate(null);
View Full Code Here

          "The function IF(expr1,expr2,expr3) accepts exactly 3 arguments.");
    }

    boolean conditionTypeIsOk = (arguments[0].getCategory() == ObjectInspector.Category.PRIMITIVE);
    if (conditionTypeIsOk) {
      PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) arguments[0]);
      conditionTypeIsOk = (poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.BOOLEAN
          || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.VOID);
    }
    if (!conditionTypeIsOk) {
      throw new UDFArgumentTypeException(0,
          "The first argument of function IF should be \""
          + Constants.BOOLEAN_TYPE_NAME + "\", but \""
View Full Code Here

      if ( fOI.getCategory() != Category.PRIMITIVE )
      {
        throw new WindowingException("Cannot handle non primitve fields for partitioning/sorting");
      }
     
      PrimitiveObjectInspector pOI = (PrimitiveObjectInspector) fOI;
      switch(pOI.getPrimitiveCategory())
      {
      case BOOLEAN:
        elementTypes[i] = BOOLEAN;
        break;
      case DOUBLE:
        elementTypes[i] = DOUBLE;
        break;
      case BYTE:
        elementTypes[i] = BYTE;
        break;
      case FLOAT:
        elementTypes[i] = FLOAT;
        break;
      case INT:
        elementTypes[i] = INT;
        break;
      case LONG:
        elementTypes[i] = LONG;
        break;
      case SHORT:
        elementTypes[i] = SHORT;
        break;
      case STRING:
        elementTypes[i] = TEXT;
        break;
      default :
        throw new WindowingException(Utils.sprintf("Cannot handle datatype %s for partitioning/sorting", pOI.toString()));
      }
      i++;
    }
   
    return new CompositeDataType(",", elementTypes);
View Full Code Here

    if ( oi.getCategory() != Category.PRIMITIVE )
    {
      throw new IOException("Cannot handle non primitve fields for partitioning/sorting");
    }
   
    PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
    switch (poi.getPrimitiveCategory())
    {
    case BOOLEAN:
    {
      BooleanObjectInspector boi = (BooleanObjectInspector) poi;
      BooleanWritable r = (BooleanWritable) elements[i];
      r.set(boi.get(o));
      return;
    }
    case BYTE:
    {
      ByteObjectInspector boi = (ByteObjectInspector) poi;
      ByteWritable r = (ByteWritable) elements[i];
      r.set(boi.get(o));
      return;
    }
    case SHORT:
    {
      ShortObjectInspector spoi = (ShortObjectInspector) poi;
      ShortWritable r = (ShortWritable) elements[i];
      r.set(spoi.get(o));
      return;
    }
    case INT:
    {
      IntObjectInspector ioi = (IntObjectInspector) poi;
      IntWritable r = (IntWritable) elements[i];
      r.set(ioi.get(o));
      return;
    }
    case LONG:
    {
      LongObjectInspector loi = (LongObjectInspector) poi;
      LongWritable r = (LongWritable) elements[i];
      r.set(loi.get(o));
      return;
    }
    case FLOAT:
    {
      FloatObjectInspector foi = (FloatObjectInspector) poi;
      FloatWritable r = (FloatWritable) elements[i];
      r.set(foi.get(o));
      return;
    }
    case DOUBLE:
    {
      DoubleObjectInspector doi = (DoubleObjectInspector) poi;
      DoubleWritable r = (DoubleWritable) elements[i];
      r.set(doi.get(o));
      return;
    }
    case STRING:
    {
      StringObjectInspector soi = (StringObjectInspector) poi;
      elements[i] = soi.getPrimitiveWritableObject(o);
      return;
    }
    default:
    {
      throw new RuntimeException("Unsupported type: " + poi.getPrimitiveCategory());
    }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.