Skip to content

Commit

Permalink
HIVE-7077 : Hive contrib compilation maybe broken with removal of org…
Browse files Browse the repository at this point in the history
….apache.hadoop.record (Ashutosh Chauhan via Navis)

git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1597698 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ashutoshc committed May 27, 2014
1 parent d20e4e1 commit 97b1a64
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.TreeMap;

import org.apache.hadoop.io.WritableUtils;
import org.apache.hadoop.record.Buffer;

/**
* Provides functionality for reading typed bytes.
Expand All @@ -51,7 +50,7 @@ protected synchronized Object initialValue() {

/**
* Get a thread-local typed bytes input for the supplied {@link DataInput}.
*
*
* @param in
* data input object
* @return typed bytes input corresponding to the supplied {@link DataInput}.
Expand All @@ -71,7 +70,7 @@ public TypedBytesInput(DataInput in) {
* Reads a typed bytes sequence and converts it to a Java object. The first
* byte is interpreted as a type code, and then the right number of subsequent
* bytes are read depending on the obtained type.
*
*
* @return the obtained object or null when the end of the file is reached
* @throws IOException
*/
Expand All @@ -82,9 +81,7 @@ public Object read() throws IOException {
} catch (EOFException eof) {
return null;
}
if (code == Type.BYTES.code) {
return new Buffer(readBytes());
} else if (code == Type.BYTE.code) {
if (code == Type.BYTE.code) {
return readByte();
} else if (code == Type.BOOL.code) {
return readBool();
Expand All @@ -108,8 +105,6 @@ public Object read() throws IOException {
return readMap();
} else if (code == Type.MARKER.code) {
return null;
} else if (50 <= code && code <= 200) { // application-specific typecodes
return new Buffer(readBytes());
} else {
throw new RuntimeException("unknown type");
}
Expand All @@ -119,7 +114,7 @@ public Object read() throws IOException {
* Reads a typed bytes sequence. The first byte is interpreted as a type code,
* and then the right number of subsequent bytes are read depending on the
* obtained type.
*
*
* @return the obtained typed bytes sequence or null when the end of the file
* is reached
* @throws IOException
Expand Down Expand Up @@ -147,12 +142,6 @@ public byte[] readRaw() throws IOException {
return readRawDouble();
} else if (code == Type.STRING.code) {
return readRawString();
} else if (code == Type.VECTOR.code) {
return readRawVector();
} else if (code == Type.LIST.code) {
return readRawList();
} else if (code == Type.MAP.code) {
return readRawMap();
} else if (code == Type.MARKER.code) {
return null;
} else if (50 <= code && code <= 200) { // application-specific typecodes
Expand All @@ -164,7 +153,7 @@ public byte[] readRaw() throws IOException {

/**
* Reads a type byte and returns the corresponding {@link Type}.
*
*
* @return the obtained Type or null when the end of the file is reached
* @throws IOException
*/
Expand All @@ -185,7 +174,7 @@ public Type readType() throws IOException {

/**
* Skips a type byte.
*
*
* @return true iff the end of the file was not reached
* @throws IOException
*/
Expand All @@ -200,7 +189,7 @@ public boolean skipType() throws IOException {

/**
* Reads the bytes following a <code>Type.BYTES</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -213,7 +202,7 @@ public byte[] readBytes() throws IOException {

/**
* Reads the raw bytes following a <code>Type.BYTES</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -231,7 +220,7 @@ public byte[] readRawBytes() throws IOException {

/**
* Reads the byte following a <code>Type.BYTE</code> code.
*
*
* @return the obtained byte
* @throws IOException
*/
Expand All @@ -241,7 +230,7 @@ public byte readByte() throws IOException {

/**
* Reads the raw byte following a <code>Type.BYTE</code> code.
*
*
* @return the obtained byte
* @throws IOException
*/
Expand All @@ -254,7 +243,7 @@ public byte[] readRawByte() throws IOException {

/**
* Reads the boolean following a <code>Type.BOOL</code> code.
*
*
* @return the obtained boolean
* @throws IOException
*/
Expand All @@ -264,7 +253,7 @@ public boolean readBool() throws IOException {

/**
* Reads the raw bytes following a <code>Type.BOOL</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -277,7 +266,7 @@ public byte[] readRawBool() throws IOException {

/**
* Reads the integer following a <code>Type.INT</code> code.
*
*
* @return the obtained integer
* @throws IOException
*/
Expand All @@ -287,7 +276,7 @@ public int readInt() throws IOException {

/**
* Reads the short following a <code>Type.SHORT</code> code.
*
*
* @return the obtained short
* @throws IOException
*/
Expand All @@ -297,7 +286,7 @@ public short readShort() throws IOException {

/**
* Reads the raw bytes following a <code>Type.INT</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -310,7 +299,7 @@ public byte[] readRawInt() throws IOException {

/**
* Reads the long following a <code>Type.LONG</code> code.
*
*
* @return the obtained long
* @throws IOException
*/
Expand All @@ -320,7 +309,7 @@ public long readLong() throws IOException {

/**
* Reads the raw bytes following a <code>Type.LONG</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -333,7 +322,7 @@ public byte[] readRawLong() throws IOException {

/**
* Reads the float following a <code>Type.FLOAT</code> code.
*
*
* @return the obtained float
* @throws IOException
*/
Expand All @@ -343,7 +332,7 @@ public float readFloat() throws IOException {

/**
* Reads the raw bytes following a <code>Type.FLOAT</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -356,7 +345,7 @@ public byte[] readRawFloat() throws IOException {

/**
* Reads the double following a <code>Type.DOUBLE</code> code.
*
*
* @return the obtained double
* @throws IOException
*/
Expand All @@ -366,7 +355,7 @@ public double readDouble() throws IOException {

/**
* Reads the raw bytes following a <code>Type.DOUBLE</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -379,7 +368,7 @@ public byte[] readRawDouble() throws IOException {

/**
* Reads the string following a <code>Type.STRING</code> code.
*
*
* @return the obtained string
* @throws IOException
*/
Expand All @@ -389,7 +378,7 @@ public String readString() throws IOException {

/**
* Reads the raw bytes following a <code>Type.STRING</code> code.
*
*
* @return the obtained bytes sequence
* @throws IOException
*/
Expand All @@ -407,7 +396,7 @@ public byte[] readRawString() throws IOException {

/**
* Reads the vector following a <code>Type.VECTOR</code> code.
*
*
* @return the obtained vector
* @throws IOException
*/
Expand All @@ -421,27 +410,9 @@ public ArrayList readVector() throws IOException {
return result;
}

/**
* Reads the raw bytes following a <code>Type.VECTOR</code> code.
*
* @return the obtained bytes sequence
* @throws IOException
*/
public byte[] readRawVector() throws IOException {
Buffer buffer = new Buffer();
int length = readVectorHeader();
buffer.append(new byte[] {(byte) Type.VECTOR.code,
(byte) (0xff & (length >> 24)), (byte) (0xff & (length >> 16)),
(byte) (0xff & (length >> 8)), (byte) (0xff & length)});
for (int i = 0; i < length; i++) {
buffer.append(readRaw());
}
return buffer.get();
}

/**
* Reads the header following a <code>Type.VECTOR</code> code.
*
*
* @return the number of elements in the vector
* @throws IOException
*/
Expand All @@ -451,7 +422,7 @@ public int readVectorHeader() throws IOException {

/**
* Reads the list following a <code>Type.LIST</code> code.
*
*
* @return the obtained list
* @throws IOException
*/
Expand All @@ -466,26 +437,9 @@ public List readList() throws IOException {
return list;
}

/**
* Reads the raw bytes following a <code>Type.LIST</code> code.
*
* @return the obtained bytes sequence
* @throws IOException
*/
public byte[] readRawList() throws IOException {
Buffer buffer = new Buffer(new byte[] {(byte) Type.LIST.code});
byte[] bytes = readRaw();
while (bytes != null) {
buffer.append(bytes);
bytes = readRaw();
}
buffer.append(new byte[] {(byte) Type.MARKER.code});
return buffer.get();
}

/**
* Reads the map following a <code>Type.MAP</code> code.
*
*
* @return the obtained map
* @throws IOException
*/
Expand All @@ -501,28 +455,9 @@ public TreeMap readMap() throws IOException {
return result;
}

/**
* Reads the raw bytes following a <code>Type.MAP</code> code.
*
* @return the obtained bytes sequence
* @throws IOException
*/
public byte[] readRawMap() throws IOException {
Buffer buffer = new Buffer();
int length = readMapHeader();
buffer.append(new byte[] {(byte) Type.MAP.code,
(byte) (0xff & (length >> 24)), (byte) (0xff & (length >> 16)),
(byte) (0xff & (length >> 8)), (byte) (0xff & length)});
for (int i = 0; i < length; i++) {
buffer.append(readRaw());
buffer.append(readRaw());
}
return buffer.get();
}

/**
* Reads the header following a <code>Type.MAP</code> code.
*
*
* @return the number of key-value pairs in the map
* @throws IOException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map.Entry;

import org.apache.hadoop.io.WritableUtils;
import org.apache.hadoop.record.Buffer;

/**
* Provides functionality for writing typed bytes.
Expand Down Expand Up @@ -77,9 +76,7 @@ public TypedBytesOutput(DataOutput out) {
* @throws IOException
*/
public void write(Object obj) throws IOException {
if (obj instanceof Buffer) {
writeBytes(((Buffer) obj).get());
} else if (obj instanceof Byte) {
if (obj instanceof Byte) {
writeByte((Byte) obj);
} else if (obj instanceof Boolean) {
writeBool((Boolean) obj);
Expand Down
Loading

0 comments on commit 97b1a64

Please sign in to comment.