@Override public void write(DataOutput out) throws IOException { DataReaderWriter.writeDatum(out, filename); DataReaderWriter.writeDatum(out, offset); }
public static Object readDatum(DataInput in, byte type) throws IOException, ExecException { switch (type) { case DataType.TUPLE: return bytesToTuple(in); return bytesToBag(in); return bytesToMap(in); return bytesToInternalMap(in); return bytesToBigCharArray(in); return bytesToCharArray(in); return bytesToWritable(in);
@Override public void write(WritableComparable wc, Tuple t) throws IOException, InterruptedException { // we really only want to write the tuple (value) out here out.write(RECORD_1); out.write(RECORD_2); out.write(RECORD_3); DataReaderWriter.writeDatum(out, t); }
public static Object readDatum(DataInput in) throws IOException, ExecException { // Read the data type byte b = in.readByte(); return readDatum(in, b); }
public byte[] toBytes(Double d) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, d); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting double to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
public byte[] toBytes(Float f) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, f); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting float to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
public byte[] toBytes(DateTime dt) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, dt); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting datetime to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
@Override public void readFields(DataInput in) throws IOException { long size = in.readLong(); for (long i = 0; i < size; i++) { try { Object o = DataReaderWriter.readDatum(in); add((Tuple)o); } catch (ExecException ee) { throw ee; } } }
public byte[] toBytes(Long l) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, l); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting long to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
/** * Read a bag from disk. * @param in DataInput to read data from. * @throws IOException (passes it on from underlying calls). */ public void readFields(DataInput in) throws IOException { long size = in.readLong(); for (long i = 0; i < size; i++) { try { Object o = DataReaderWriter.readDatum(in); add((Tuple)o); } catch (ExecException ee) { throw ee; } } }
@Override public void write(DataOutput out) throws IOException { out.writeByte(DataType.TUPLE); int sz = size(); out.writeInt(sz); for (int i = 0; i < sz; i++) { DataReaderWriter.writeDatum(out, mFields.get(i)); } }
/** * Read a bag from disk. * @param in DataInput to read data from. * @throws IOException (passes it on from underlying calls). */ public void readFields(DataInput in) throws IOException { long size = in.readLong(); for (long i = 0; i < size; i++) { try { Object o = DataReaderWriter.readDatum(in); add((Tuple)o); } catch (ExecException ee) { throw ee; } } }
public byte[] toBytes(String s) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, s); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting chararray to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
public static Writable bytesToWritable(DataInput in) throws IOException { String className = (String) readDatum(in); // create the writeable class . It needs to have a default constructor Class<?> objClass = null ; try { objClass = Class.forName(className); } catch (ClassNotFoundException e) { throw new IOException("Could not find class " + className + ", while attempting to de-serialize it ", e); } Writable writable = null; try { writable = (Writable) objClass.newInstance(); } catch (Exception e) { String msg = "Could create instance of class " + className + ", while attempting to de-serialize it. (no default constructor ?)"; throw new IOException(msg, e); } //read the fields of the object from DataInput writable.readFields(in); return writable; }
public byte[] toBytes(Boolean b) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, b); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting boolean to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }
public static DataBag bytesToBag(DataInput in) throws IOException { DataBag bag = mBagFactory.newDefaultBag(); long size = in.readLong(); for (long i = 0; i < size; i++) { try { Object o = readDatum(in); bag.add((Tuple)o); } catch (ExecException ee) { throw ee; } } return bag; }
public byte[] toBytes(Map<String, Object> m) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { DataReaderWriter.writeDatum(dos, m); } catch (Exception ee) { int errCode = 2105; String msg = "Error while converting map to bytes."; throw new ExecException(msg, errCode, PigException.BUG, ee); } return baos.toByteArray(); }