HADOOP-6492. Make some Avro serialization APIs public. Contributed by Aaron Kimball.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@899866 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2010-01-16 01:06:57 +00:00
parent a90d3205d2
commit 4cd159e83e
6 changed files with 17 additions and 14 deletions

View File

@ -101,6 +101,9 @@ Trunk (unreleased changes)
HADOOP-6155. Deprecate RecordIO anticipating Avro. (Tom White via cdouglas) HADOOP-6155. Deprecate RecordIO anticipating Avro. (Tom White via cdouglas)
HADOOP-6492. Make some Avro serialization APIs public.
(Aaron Kimball via cutting)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -78,7 +78,7 @@ public Serializer<T> getSerializer(Class<T> c) {
public abstract DeserializerBase<T> getDeserializer( public abstract DeserializerBase<T> getDeserializer(
Map<String, String> metadata); Map<String, String> metadata);
protected Class<?> getClassFromMetadata(Map<String, String> metadata) { public Class<?> getClassFromMetadata(Map<String, String> metadata) {
String classname = metadata.get(CLASS_KEY); String classname = metadata.get(CLASS_KEY);
if (classname == null) { if (classname == null) {
return null; return null;

View File

@ -46,18 +46,18 @@ public boolean accept(Map<String, String> metadata) {
} }
@Override @Override
protected DatumReader getReader(Map<String, String> metadata) { public DatumReader getReader(Map<String, String> metadata) {
Schema schema = Schema.parse(metadata.get(AVRO_SCHEMA_KEY)); Schema schema = Schema.parse(metadata.get(AVRO_SCHEMA_KEY));
return new GenericDatumReader<Object>(schema); return new GenericDatumReader<Object>(schema);
} }
@Override @Override
protected Schema getSchema(Map<String, String> metadata) { public Schema getSchema(Map<String, String> metadata) {
return Schema.parse(metadata.get(AVRO_SCHEMA_KEY)); return Schema.parse(metadata.get(AVRO_SCHEMA_KEY));
} }
@Override @Override
protected DatumWriter getWriter(Map<String, String> metadata) { public DatumWriter getWriter(Map<String, String> metadata) {
return new GenericDatumWriter<Object>(); return new GenericDatumWriter<Object>();
} }

View File

@ -76,7 +76,7 @@ private void getPackages() {
} }
@Override @Override
protected DatumReader getReader(Map<String, String> metadata) { public DatumReader getReader(Map<String, String> metadata) {
try { try {
return new ReflectDatumReader(getClassFromMetadata(metadata)); return new ReflectDatumReader(getClassFromMetadata(metadata));
} catch (Exception e) { } catch (Exception e) {
@ -85,13 +85,13 @@ protected DatumReader getReader(Map<String, String> metadata) {
} }
@Override @Override
protected Schema getSchema(Map<String, String> metadata) { public Schema getSchema(Map<String, String> metadata) {
Class<?> c = getClassFromMetadata(metadata); Class<?> c = getClassFromMetadata(metadata);
return ReflectData.get().getSchema(c); return ReflectData.get().getSchema(c);
} }
@Override @Override
protected DatumWriter getWriter(Map<String, String> metadata) { public DatumWriter getWriter(Map<String, String> metadata) {
return new ReflectDatumWriter(); return new ReflectDatumWriter();
} }

View File

@ -51,17 +51,17 @@ public SerializerBase<T> getSerializer(Map<String, String> metadata) {
/** /**
* Return an Avro Schema instance for the given class and metadata. * Return an Avro Schema instance for the given class and metadata.
*/ */
protected abstract Schema getSchema(Map<String, String> metadata); public abstract Schema getSchema(Map<String, String> metadata);
/** /**
* Create and return Avro DatumWriter for the given metadata. * Create and return Avro DatumWriter for the given metadata.
*/ */
protected abstract DatumWriter<T> getWriter(Map<String, String> metadata); public abstract DatumWriter<T> getWriter(Map<String, String> metadata);
/** /**
* Create and return Avro DatumReader for the given metadata. * Create and return Avro DatumReader for the given metadata.
*/ */
protected abstract DatumReader<T> getReader(Map<String, String> metadata); public abstract DatumReader<T> getReader(Map<String, String> metadata);
class AvroSerializer extends SerializerBase<T> { class AvroSerializer extends SerializerBase<T> {

View File

@ -47,7 +47,7 @@ public boolean accept(Map<String, String> metadata) {
} }
@Override @Override
protected DatumReader getReader(Map<String, String> metadata) { public DatumReader getReader(Map<String, String> metadata) {
try { try {
return new SpecificDatumReader(getClassFromMetadata(metadata)); return new SpecificDatumReader(getClassFromMetadata(metadata));
} catch (Exception e) { } catch (Exception e) {
@ -56,13 +56,13 @@ protected DatumReader getReader(Map<String, String> metadata) {
} }
@Override @Override
protected Schema getSchema(Map<String, String> metadata) { public Schema getSchema(Map<String, String> metadata) {
Class<?> c = getClassFromMetadata(metadata); Class<?> c = getClassFromMetadata(metadata);
return SpecificData.get().getSchema(c); return SpecificData.get().getSchema(c);
} }
@Override @Override
protected DatumWriter getWriter(Map<String, String> metadata) { public DatumWriter getWriter(Map<String, String> metadata) {
return new SpecificDatumWriter(); return new SpecificDatumWriter();
} }