Package org.apache.hadoop.hive.serde2

Examples of org.apache.hadoop.hive.serde2.SerDeException


  @Override
  public Object deserialize(Writable blob) throws SerDeException {

    if (inputPattern == null) {
      throw new SerDeException(
          "This table does not have serde property \"input.regex\"!");
    }
    Text rowText = (Text) blob;

    Matcher m = inputPattern.matcher(rowText.toString());
View Full Code Here


  @Override
  public Writable serialize(Object obj, ObjectInspector objInspector)
      throws SerDeException {

    if (outputFormatString == null) {
      throw new SerDeException(
          "Cannot write data into table because \"output.format.string\""
          + " is not specified in serde properties of the table.");
    }

    // Get all the fields out.
    // NOTE: The correct way to get fields out of the row is to use
    // objInspector.
    // The obj can be a Java ArrayList, or a Java class, or a byte[] or
    // whatever.
    // The only way to access the data inside the obj is through
    // ObjectInspector.

    StructObjectInspector outputRowOI = (StructObjectInspector) objInspector;
    List<? extends StructField> outputFieldRefs = outputRowOI
        .getAllStructFieldRefs();
    if (outputFieldRefs.size() != numColumns) {
      throw new SerDeException("Cannot serialize the object because there are "
          + outputFieldRefs.size() + " fields but the table has " + numColumns
          + " columns.");
    }

    // Get all data out.
    for (int c = 0; c < numColumns; c++) {
      Object field = outputRowOI
          .getStructFieldData(obj, outputFieldRefs.get(c));
      ObjectInspector fieldOI = outputFieldRefs.get(c)
          .getFieldObjectInspector();
      // The data must be of type String
      StringObjectInspector fieldStringOI = (StringObjectInspector) fieldOI;
      // Convert the field to Java class String, because objects of String type
      // can be
      // stored in String, Text, or some other classes.
      outputFields[c] = fieldStringOI.getPrimitiveJavaObject(field);
    }

    // Format the String
    String outputRowString = null;
    try {
      outputRowString = String.format(outputFormatString, outputFields);
    } catch (MissingFormatArgumentException e) {
      throw new SerDeException("The table contains " + numColumns
          + " columns, but the outputFormatString is asking for more.", e);
    }
    outputRowText.set(outputRowString);
    return outputRowText;
  }
View Full Code Here

        throw new UnsupportedOperationException("not allowed to run copy() on LazyHCatRecord");
    }

    public LazyHCatRecord(Object wrappedObject, ObjectInspector oi) throws Exception {
        if (oi.getCategory() != Category.STRUCT) {
            throw new SerDeException(getClass().toString() +
                " can only make a lazy hcat record from " +
                "objects of struct types, but we got: " + oi.getTypeName());
        }

        this.soi = (StructObjectInspector)oi;
View Full Code Here

        try {
            schema = HCatSchemaUtils.getHCatSchema(rowTypeInfo).get(0).getStructSubSchema();
            LOG.debug("schema : {}", schema);
            LOG.debug("fields : {}", schema.getFieldNames());
        } catch (HCatException e) {
            throw new SerDeException(e);
        }

        jsonFactory = new JsonFactory();
    }
View Full Code Here

                populateRecord(r, token, p, schema);
            }
        } catch (JsonParseException e) {
            LOG.warn("Error [{}] parsing json text [{}].", e, t);
            LOG.debug(null, e);
            throw new SerDeException(e);
        } catch (IOException e) {
            LOG.warn("Error [{}] parsing json text [{}].", e, t);
            LOG.debug(null, e);
            throw new SerDeException(e);
        }

        return new DefaultHCatRecord(r);
    }
View Full Code Here

                sb.append(SerDeUtils.RBRACE);
            }

        } catch (IOException e) {
            LOG.warn("Error generating json text from object.", e);
            throw new SerDeException(e);
        }
        return new Text(sb.toString());
    }
View Full Code Here

     * it wants it.
     */
    @Override
    public Object deserialize(Writable data) throws SerDeException {
        if (!(data instanceof HCatRecord)) {
            throw new SerDeException(getClass().getName() + ": expects HCatRecord!");
        }

        return (HCatRecord) data;
    }
View Full Code Here

     */
    @Override
    public Writable serialize(Object obj, ObjectInspector objInspector)
        throws SerDeException {
        if (objInspector.getCategory() != Category.STRUCT) {
            throw new SerDeException(getClass().toString()
                + " can only serialize struct types, but we got: "
                + objInspector.getTypeName());
        }
        return new DefaultHCatRecord((List<Object>) serializeStruct(obj, (StructObjectInspector) objInspector));
    }
View Full Code Here

        } else if (fieldObjectInspector.getCategory() == Category.LIST) {
            res = serializeList(field, (ListObjectInspector) fieldObjectInspector);
        } else if (fieldObjectInspector.getCategory() == Category.MAP) {
            res = serializeMap(field, (MapObjectInspector) fieldObjectInspector);
        } else {
            throw new SerDeException(HCatRecordSerDe.class.toString()
                + " does not know what to do with fields of unknown category: "
                + fieldObjectInspector.getCategory() + " , type: " + fieldObjectInspector.getTypeName());
        }
        return res;
    }
View Full Code Here

            for (int i = 0; i < l.size(); i++) {
                list.add(serializeMap(l.get(i), (MapObjectInspector) eloi));
            }
            return list;
        } else {
            throw new SerDeException(HCatRecordSerDe.class.toString()
                + " does not know what to do with fields of unknown category: "
                + eloi.getCategory() + " , type: " + eloi.getTypeName());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.serde2.SerDeException

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.