Index: hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java =================================================================== --- hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java (revision 1448002) +++ hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseSerDe.java (working copy) @@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hive.serde.serdeConstants; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.ByteStream; import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.serde2.SerDeException; @@ -58,7 +59,7 @@ * HBaseSerDe can be used to serialize object into an HBase table and * deserialize objects from an HBase table. */ -public class HBaseSerDe implements SerDe { +public class HBaseSerDe extends AbstractSerDe { public static final String HBASE_COLUMNS_MAPPING = "hbase.columns.mapping"; public static final String HBASE_TABLE_NAME = "hbase.table.name"; @@ -546,10 +547,11 @@ throw new SerDeException("HBase row key cannot be NULL"); } - if(putTimestamp >= 0) + if(putTimestamp >= 0) { put = new Put(key,putTimestamp); - else + } else { put = new Put(key); + } // Serialize each field for (int i = 0; i < fields.size(); i++) { Index: contrib/src/java/org/apache/hadoop/hive/contrib/serde2/TypedBytesSerDe.java =================================================================== --- contrib/src/java/org/apache/hadoop/hive/contrib/serde2/TypedBytesSerDe.java (revision 1448002) +++ contrib/src/java/org/apache/hadoop/hive/contrib/serde2/TypedBytesSerDe.java (working copy) @@ -32,7 +32,7 @@ import org.apache.hadoop.hive.ql.io.NonSyncDataInputBuffer; import org.apache.hadoop.hive.ql.io.NonSyncDataOutputBuffer; import org.apache.hadoop.hive.serde.serdeConstants; -import org.apache.hadoop.hive.serde2.SerDe; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.SerDeUtils; @@ -40,11 +40,11 @@ import org.apache.hadoop.hive.serde2.io.DoubleWritable; import org.apache.hadoop.hive.serde2.io.ShortWritable; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.StructField; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector; @@ -73,7 +73,7 @@ * this, which is apparently 25% faster than the python version is available at * http://github.com/klbostee/ctypedbytes/tree/master */ -public class TypedBytesSerDe implements SerDe { +public class TypedBytesSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(TypedBytesSerDe.class .getName()); Index: contrib/src/java/org/apache/hadoop/hive/contrib/serde2/s3/S3LogDeserializer.java =================================================================== --- contrib/src/java/org/apache/hadoop/hive/contrib/serde2/s3/S3LogDeserializer.java (revision 1448002) +++ contrib/src/java/org/apache/hadoop/hive/contrib/serde2/s3/S3LogDeserializer.java (working copy) @@ -27,7 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.serde2.Deserializer; +import org.apache.hadoop.hive.serde2.AbstractDeserializer; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -42,7 +42,7 @@ * S3LogDeserializer. * */ -public class S3LogDeserializer implements Deserializer { +public class S3LogDeserializer extends AbstractDeserializer { public static final Log LOG = LogFactory.getLog(S3LogDeserializer.class .getName()); @@ -73,6 +73,7 @@ S3LogStruct deserializeCache = new S3LogStruct(); + @Override public void initialize(Configuration job, Properties tbl) throws SerDeException { @@ -132,6 +133,7 @@ return (c); } + @Override public Object deserialize(Writable field) throws SerDeException { String row = null; if (field instanceof BytesWritable) { @@ -155,6 +157,7 @@ } } + @Override public ObjectInspector getObjectInspector() throws SerDeException { return cachedObjectInspector; } @@ -202,6 +205,7 @@ } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null; Index: contrib/src/java/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java =================================================================== --- contrib/src/java/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java (revision 1448002) +++ contrib/src/java/org/apache/hadoop/hive/contrib/serde2/RegexSerDe.java (working copy) @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; -import org.apache.hadoop.hive.serde2.SerDe; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -70,7 +70,7 @@ * writableStringObjectInspector. We should switch to that when we have a UTF-8 * based Regex library. */ -public class RegexSerDe implements SerDe { +public class RegexSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(RegexSerDe.class.getName()); Index: serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazySimpleSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazySimpleSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazySimpleSerDe.java (working copy) @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.ByteStream; import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.serde2.SerDeException; @@ -35,11 +36,11 @@ import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.StructField; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; @@ -59,7 +60,7 @@ * Also LazySimpleSerDe outputs typed columns instead of treating all columns as * String like MetadataTypedColumnsetSerDe. */ -public class LazySimpleSerDe implements SerDe { +public class LazySimpleSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(LazySimpleSerDe.class .getName()); Index: serde/src/java/org/apache/hadoop/hive/serde2/columnar/ColumnarSerDeBase.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/columnar/ColumnarSerDeBase.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/columnar/ColumnarSerDeBase.java (working copy) @@ -18,14 +18,14 @@ package org.apache.hadoop.hive.serde2.columnar; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.ByteStream; -import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.io.Writable; -public abstract class ColumnarSerDeBase implements SerDe { +public abstract class ColumnarSerDeBase extends AbstractSerDe { // The object for storing row data ColumnarStructBase cachedLazyStruct; Index: serde/src/java/org/apache/hadoop/hive/serde2/NullStructSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/NullStructSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/NullStructSerDe.java (working copy) @@ -32,7 +32,7 @@ * Placeholder SerDe for cases where neither serialization nor deserialization is needed * */ -public class NullStructSerDe implements SerDe { +public class NullStructSerDe extends AbstractSerDe { class NullStructField implements StructField { @Override Index: serde/src/java/org/apache/hadoop/hive/serde2/MetadataTypedColumnsetSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/MetadataTypedColumnsetSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/MetadataTypedColumnsetSerDe.java (working copy) @@ -30,10 +30,10 @@ import org.apache.hadoop.hive.serde.serdeConstants; import org.apache.hadoop.hive.serde2.objectinspector.MetadataListStructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.StructField; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; @@ -42,7 +42,7 @@ * MetadataTypedColumnsetSerDe. * */ -public class MetadataTypedColumnsetSerDe implements SerDe { +public class MetadataTypedColumnsetSerDe extends AbstractSerDe { public static final Log LOG = LogFactory .getLog(MetadataTypedColumnsetSerDe.class.getName()); @@ -95,6 +95,7 @@ return defaultVal; } + @Override public void initialize(Configuration job, Properties tbl) throws SerDeException { String altSep = tbl.getProperty(serdeConstants.SERIALIZATION_FORMAT); separator = getByteValue(altSep, DefaultSeparator); @@ -167,6 +168,7 @@ ColumnSet deserializeCache = new ColumnSet(); + @Override public Object deserialize(Writable field) throws SerDeException { String row = null; if (field instanceof BytesWritable) { @@ -193,16 +195,19 @@ } } + @Override public ObjectInspector getObjectInspector() throws SerDeException { return cachedObjectInspector; } + @Override public Class getSerializedClass() { return Text.class; } Text serializeCache = new Text(); + @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { @@ -232,6 +237,7 @@ return serializeCache; } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null; Index: serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java (working copy) @@ -28,9 +28,9 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.ByteStream; import org.apache.hadoop.hive.serde2.ByteStream.Output; -import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.io.BigDecimalWritable; @@ -67,7 +67,7 @@ * deserialized until required. Binary means a field is serialized in binary * compact format. */ -public class LazyBinarySerDe implements SerDe { +public class LazyBinarySerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(LazyBinarySerDe.class .getName()); Index: serde/src/java/org/apache/hadoop/hive/serde2/dynamic_type/DynamicSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/dynamic_type/DynamicSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/dynamic_type/DynamicSerDe.java (working copy) @@ -19,7 +19,6 @@ package org.apache.hadoop.hive.serde2.dynamic_type; import java.io.ByteArrayInputStream; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -28,8 +27,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.ByteStream; -import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -50,7 +49,7 @@ * DynamicSerDe. * */ -public class DynamicSerDe implements SerDe, Serializable { +public class DynamicSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(DynamicSerDe.class.getName()); Index: serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftDeserializer.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftDeserializer.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/thrift/ThriftDeserializer.java (working copy) @@ -21,7 +21,7 @@ import java.util.Properties; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.serde2.Deserializer; +import org.apache.hadoop.hive.serde2.AbstractDeserializer; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -32,13 +32,14 @@ * ThriftDeserializer. * */ -public class ThriftDeserializer implements Deserializer { +public class ThriftDeserializer extends AbstractDeserializer { private ThriftByteStreamTypedSerDe tsd; public ThriftDeserializer() { } + @Override public void initialize(Configuration job, Properties tbl) throws SerDeException { try { @@ -68,14 +69,17 @@ } } + @Override public Object deserialize(Writable field) throws SerDeException { return tsd.deserialize(field); } + @Override public ObjectInspector getObjectInspector() throws SerDeException { return tsd.getObjectInspector(); } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null; Index: serde/src/java/org/apache/hadoop/hive/serde2/Deserializer.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/Deserializer.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/Deserializer.java (working copy) @@ -31,8 +31,10 @@ * HiveDeserializer also provides the ObjectInspector which can be used to * inspect the internal structure of the object (that is returned by deserialize * function). - * + * All deserializers should extend the abstract class AbstractDeserializer, and eventually + * Deserializer interface should be removed */ +@Deprecated public interface Deserializer { /** @@ -50,7 +52,7 @@ * Deserialize an object out of a Writable blob. In most cases, the return * value of this function will be constant since the function will reuse the * returned object. If the client wants to keep a copy of the object, the - * client needs to clone the returned value by calling + * client needs to clone the returnDeserializered value by calling * ObjectInspectorUtils.getStandardObject(). * * @param blob Index: serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerDe.java (working copy) @@ -17,24 +17,24 @@ */ package org.apache.hadoop.hive.serde2.avro; +import java.util.List; +import java.util.Properties; + import org.apache.avro.Schema; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.serde2.SerDe; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.io.Writable; -import java.util.List; -import java.util.Properties; - /** * Read or write Avro data from Hive. */ -public class AvroSerDe implements SerDe { +public class AvroSerDe extends AbstractSerDe { private static final Log LOG = LogFactory.getLog(AvroSerDe.class); private ObjectInspector oi; private List columnNames; @@ -48,8 +48,9 @@ @Override public void initialize(Configuration configuration, Properties properties) throws SerDeException { // Reset member variables so we don't get in a half-constructed state - if(schema != null) + if(schema != null) { LOG.info("Resetting already initialized AvroSerDe"); + } schema = null; oi = null; @@ -80,13 +81,17 @@ @Override public Writable serialize(Object o, ObjectInspector objectInspector) throws SerDeException { - if(badSchema) throw new BadSchemaException(); + if(badSchema) { + throw new BadSchemaException(); + } return getSerializer().serialize(o, objectInspector, columnNames, columnTypes, schema); } @Override public Object deserialize(Writable writable) throws SerDeException { - if(badSchema) throw new BadSchemaException(); + if(badSchema) { + throw new BadSchemaException(); + } return getDeserializer().deserialize(columnNames, columnTypes, writable, schema); } @@ -102,13 +107,17 @@ } private AvroDeserializer getDeserializer() { - if(avroDeserializer == null) avroDeserializer = new AvroDeserializer(); + if(avroDeserializer == null) { + avroDeserializer = new AvroDeserializer(); + } return avroDeserializer; } private AvroSerializer getSerializer() { - if(avroSerializer == null) avroSerializer = new AvroSerializer(); + if(avroSerializer == null) { + avroSerializer = new AvroSerializer(); + } return avroSerializer; } Index: serde/src/java/org/apache/hadoop/hive/serde2/RegexSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/RegexSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/RegexSerDe.java (working copy) @@ -57,7 +57,7 @@ * writableStringObjectInspector. We should switch to that when we have a UTF-8 * based Regex library. */ -public class RegexSerDe implements SerDe { +public class RegexSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(RegexSerDe.class.getName()); @@ -249,6 +249,7 @@ "Regex SerDe doesn't support the serialize() method"); } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null; Index: serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/BinarySortableSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/BinarySortableSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/BinarySortableSerDe.java (working copy) @@ -33,7 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.serde.serdeConstants; -import org.apache.hadoop.hive.serde2.SerDe; +import org.apache.hadoop.hive.serde2.AbstractSerDe; import org.apache.hadoop.hive.serde2.SerDeException; import org.apache.hadoop.hive.serde2.SerDeStats; import org.apache.hadoop.hive.serde2.io.BigDecimalWritable; @@ -99,7 +99,7 @@ * fields in the same top-level field will have the same sort order. * */ -public class BinarySortableSerDe implements SerDe { +public class BinarySortableSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(BinarySortableSerDe.class .getName()); @@ -111,7 +111,7 @@ StructObjectInspector rowObjectInspector; boolean[] columnSortOrderIsDesc; - + private static byte[] decimalBuffer = null; private static Charset decimalCharSet = Charset.forName("US-ASCII"); @@ -186,7 +186,7 @@ static Object deserialize(InputByteBuffer buffer, TypeInfo type, boolean invert, Object reuse) throws IOException { - + // Is this field a null? byte isNull = buffer.read(invert); if (isNull == 0) { @@ -378,33 +378,33 @@ } t.setBinarySortable(bytes, 0); return t; - + case DECIMAL: { // See serialization of decimal for explanation (below) BigDecimalWritable bdw = (reuse == null ? new BigDecimalWritable() : (BigDecimalWritable) reuse); - + int b = buffer.read(invert) - 1; assert (b == 1 || b == -1 || b == 0); boolean positive = b != -1; - + int factor = buffer.read(invert) ^ 0x80; for (int i = 0; i < 3; i++) { factor = (factor << 8) + (buffer.read(invert) & 0xff); } - + if (!positive) { factor = -factor; } - + int start = buffer.tell(); int length = 0; - + do { b = buffer.read(positive ? invert : !invert); assert(b != 1); - + if (b == 0) { // end of digits break; @@ -412,7 +412,7 @@ length++; } while (true); - + if(decimalBuffer == null || decimalBuffer.length < length) { decimalBuffer = new byte[length]; } @@ -428,11 +428,11 @@ String digits = new String(decimalBuffer, 0, length, decimalCharSet); BigInteger bi = new BigInteger(digits); BigDecimal bd = new BigDecimal(bi).scaleByPowerOfTen(factor-length); - + if (!positive) { bd = bd.negate(); } - + bdw.set(bd); return bdw; } @@ -443,7 +443,7 @@ } } } - + case LIST: { ListTypeInfo ltype = (ListTypeInfo) type; TypeInfo etype = ltype.getListElementTypeInfo(); @@ -690,32 +690,32 @@ BigDecimalObjectInspector boi = (BigDecimalObjectInspector) poi; BigDecimal dec = boi.getPrimitiveJavaObject(o).stripTrailingZeros(); - + // get the sign of the big decimal int sign = dec.compareTo(BigDecimal.ZERO); - + // we'll encode the absolute value (sign is separate) dec = dec.abs(); - + // get the scale factor to turn big decimal into a decimal < 1 int factor = dec.precision() - dec.scale(); factor = sign == 1 ? factor : -factor; - + // convert the absolute big decimal to string dec.scaleByPowerOfTen(Math.abs(dec.scale())); String digits = dec.unscaledValue().toString(); - + // finally write out the pieces (sign, scale, digits) buffer.write((byte) ( sign + 1), invert); buffer.write((byte) ((factor >> 24) ^ 0x80), invert); buffer.write((byte) ( factor >> 16), invert); buffer.write((byte) ( factor >> 8), invert); buffer.write((byte) factor, invert); - serializeBytes(buffer, digits.getBytes(decimalCharSet), + serializeBytes(buffer, digits.getBytes(decimalCharSet), digits.length(), sign == -1 ? !invert : invert); return; } - + default: { throw new RuntimeException("Unrecognized type: " + poi.getPrimitiveCategory()); Index: serde/src/java/org/apache/hadoop/hive/serde2/SerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/SerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/SerDe.java (working copy) @@ -20,14 +20,16 @@ /** * A union of HiveDeserializer and HiveSerializer interface. - * + * * If a developer wants his hive table to be read-only, then he just want to * return - * + * * both readable and writable, then - * - * + * + * All serdes should extend the abstract class AbstractSerDe, and eventually SerDe interface + * should be removed */ +@Deprecated public interface SerDe extends Deserializer, Serializer { } Index: serde/src/java/org/apache/hadoop/hive/serde2/AbstractDeserializer.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/AbstractDeserializer.java (revision 0) +++ serde/src/java/org/apache/hadoop/hive/serde2/AbstractDeserializer.java (working copy) @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.serde2; + +import java.util.Properties; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.io.Writable; + +/** + * Abstract class for implementing Deserializer. The abstract class has been created, so that + * new methods can be added in the underlying interface, Deserializer, and only implementations + * that need those methods overwrite it. + */ +public abstract class AbstractDeserializer implements Deserializer { + + /** + * Initialize the HiveDeserializer. + * + * @param conf + * System properties + * @param tbl + * table properties + * @throws SerDeException + */ + public abstract void initialize(Configuration conf, Properties tbl) throws SerDeException; + + /** + * Deserialize an object out of a Writable blob. In most cases, the return + * value of this function will be constant since the function will reuse the + * returned object. If the client wants to keep a copy of the object, the + * client needs to clone the returned value by calling + * ObjectInspectorUtils.getStandardObject(). + * + * @param blob + * The Writable object containing a serialized object + * @return A Java object representing the contents in the blob. + */ + public abstract Object deserialize(Writable blob) throws SerDeException; + + /** + * Get the object inspector that can be used to navigate through the internal + * structure of the Object returned from deserialize(...). + */ + public abstract ObjectInspector getObjectInspector() throws SerDeException; + + /** + * Returns statistics collected when serializing + */ + public abstract SerDeStats getSerDeStats(); +} Index: serde/src/java/org/apache/hadoop/hive/serde2/TypedSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/TypedSerDe.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/TypedSerDe.java (working copy) @@ -33,7 +33,7 @@ * TypedSerDe. * */ -public abstract class TypedSerDe implements SerDe { +public abstract class TypedSerDe extends AbstractSerDe { protected Type objectType; protected Class objectClass; @@ -52,6 +52,7 @@ protected Object deserializeCache; + @Override public Object deserialize(Writable blob) throws SerDeException { if (deserializeCache == null) { return ReflectionUtils.newInstance(objectClass, null); @@ -61,6 +62,7 @@ } } + @Override public ObjectInspector getObjectInspector() throws SerDeException { return ObjectInspectorFactory.getReflectionObjectInspector(objectType, getObjectInspectorOptions()); @@ -70,18 +72,22 @@ return ObjectInspectorFactory.ObjectInspectorOptions.JAVA; } + @Override public void initialize(Configuration job, Properties tbl) throws SerDeException { // do nothing } + @Override public Class getSerializedClass() { return BytesWritable.class; } + @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { throw new RuntimeException("not supported"); } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null; Index: serde/src/java/org/apache/hadoop/hive/serde2/Serializer.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/Serializer.java (revision 1448002) +++ serde/src/java/org/apache/hadoop/hive/serde2/Serializer.java (working copy) @@ -28,8 +28,10 @@ * HiveSerializer is used to serialize data to a Hadoop Writable object. The * serialize In addition to the interface below, all implementations are assume * to have a ctor that takes a single 'Table' object as argument. - * + * All serializers should extend the abstract class AbstractSerializer, and eventually + * Serializer interface should be removed */ +@Deprecated public interface Serializer { /** Index: serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerDe.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerDe.java (revision 0) +++ serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerDe.java (working copy) @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.serde2; + +import java.util.Properties; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.io.Writable; + +/** + * Abstract class for implementing SerDe. The abstract class has been created, so that + * new methods can be added in the underlying interface, SerDe, and only implementations + * that need those methods overwrite it. + */ +public abstract class AbstractSerDe implements SerDe { + + /** + * Initialize the HiveSerializer. + * + * @param conf + * System properties + * @param tbl + * table properties + * @throws SerDeException + */ + public abstract void initialize(Configuration conf, Properties tbl) throws SerDeException; + + /** + * Returns the Writable class that would be returned by the serialize method. + * This is used to initialize SequenceFile header. + */ + public abstract Class getSerializedClass(); + + /** + * Serialize an object by navigating inside the Object with the + * ObjectInspector. In most cases, the return value of this function will be + * constant since the function will reuse the Writable object. If the client + * wants to keep a copy of the Writable, the client needs to clone the + * returned value. + */ + public abstract Writable serialize(Object obj, ObjectInspector objInspector) + throws SerDeException; + + /** + * Returns statistics collected when serializing + */ + public abstract SerDeStats getSerDeStats(); + + /** + * Deserialize an object out of a Writable blob. In most cases, the return + * value of this function will be constant since the function will reuse the + * returned object. If the client wants to keep a copy of the object, the + * client needs to clone the returned value by calling + * ObjectInspectorUtils.getStandardObject(). + * + * @param blob + * The Writable object containing a serialized object + * @return A Java object representing the contents in the blob. + */ + public abstract Object deserialize(Writable blob) throws SerDeException; + + /** + * Get the object inspector that can be used to navigate through the internal + * structure of the Object returned from deserialize(...). + */ + public abstract ObjectInspector getObjectInspector() throws SerDeException; +} Index: serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerializer.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerializer.java (revision 0) +++ serde/src/java/org/apache/hadoop/hive/serde2/AbstractSerializer.java (working copy) @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.serde2; + +import java.util.Properties; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.io.Writable; + +/** + * Abstract class for implementing Serializer. The abstract class has been created, so that + * new methods can be added in the underlying interface, Serializer, and only implementations + * that need those methods overwrite it. + */ +public abstract class AbstractSerializer implements Serializer { + + /** + * Initialize the HiveSerializer. + * + * @param conf + * System properties + * @param tbl + * table properties + * @throws SerDeException + */ + public abstract void initialize(Configuration conf, Properties tbl) throws SerDeException; + + /** + * Returns the Writable class that would be returned by the serialize method. + * This is used to initialize SequenceFile header. + */ + public abstract Class getSerializedClass(); + + /** + * Serialize an object by navigating inside the Object with the + * ObjectInspector. In most cases, the return value of this function will be + * constant since the function will reuse the Writable object. If the client + * wants to keep a copy of the Writable, the client needs to clone the + * returned value. + */ + public abstract Writable serialize(Object obj, ObjectInspector objInspector) + throws SerDeException; + + /** + * Returns statistics collected when serializing + */ + public abstract SerDeStats getSerDeStats(); +} Index: ql/src/test/org/apache/hadoop/hive/serde2/TestSerDe.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/serde2/TestSerDe.java (revision 1448002) +++ ql/src/test/org/apache/hadoop/hive/serde2/TestSerDe.java (working copy) @@ -41,7 +41,7 @@ * TestSerDe. * */ -public class TestSerDe implements SerDe { +public class TestSerDe extends AbstractSerDe { public static final Log LOG = LogFactory.getLog(TestSerDe.class.getName()); @@ -83,6 +83,7 @@ separator = DefaultSeparator; } + @Override public void initialize(Configuration job, Properties tbl) throws SerDeException { separator = DefaultSeparator; String altSep = tbl.getProperty("testserde.default.serialization.format"); @@ -133,6 +134,7 @@ ColumnSet deserializeCache = new ColumnSet(); + @Override public Object deserialize(Writable field) throws SerDeException { String row = null; if (field instanceof BytesWritable) { @@ -159,16 +161,19 @@ } } + @Override public ObjectInspector getObjectInspector() throws SerDeException { return cachedObjectInspector; } + @Override public Class getSerializedClass() { return Text.class; } Text serializeCache = new Text(); + @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { @@ -198,6 +203,7 @@ return serializeCache; } + @Override public SerDeStats getSerDeStats() { // no support for statistics return null;