hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rubin, Bradley S." <BSRU...@stthomas.edu>
Subject How to Write a Simple SerDe?
Date Mon, 21 May 2012 19:41:47 GMT
My Hadoop MR job emits a value with three primitives via a custom Writable (see below).  How
do I write a corresponding custom SerDe so that Hive can read the output from HDFS?  I can
find complex SerDe examples (RegEx, JSON), but I can't find something simple to model from.

I think that my create table should look like this, correct?

CREATE EXTERNAL TABLE rats (time INT, frequency SMALLINT, convolution FLOAT)
ROW FORMAT SERDE 'neurohadoop.RatSerde'
STORED AS SEQUENCEFILE LOCATION '/neuro/output/rats';

----------

public class RatWritable implements Writable {
  int timestamp;
  short frequency;
  float convolution;
  
  public void readFields(DataInput in) throws IOException {
	  timestamp = in.readInt();
	  frequency = in.readShort();
	  convolution = in.readFloat();
  }
  
  public void write(DataOutput out) throws IOException {
	  out.writeInt(timestamp);
	  out.writeShort(frequency);
	  out.writeFloat(convolution);
  }
}

-- Brad
Mime
View raw message