avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1586265 - in /avro/trunk: ./ doc/src/content/xdocs/ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/ipc/src/test/java/org/apache/avro/
Date Thu, 10 Apr 2014 10:35:04 GMT
Author: tomwhite
Date: Thu Apr 10 10:35:03 2014
New Revision: 1586265

URL: http://svn.apache.org/r1586265
Log:
Revert r1584605. AVRO-1402. Support for DECIMAL type (as a record mapping).

Removed:
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/DecimalRecordMapping.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/RecordMapping.java
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/doc/src/content/xdocs/spec.xml
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Apr 10 10:35:03 2014
@@ -11,8 +11,6 @@ Trunk (not yet released)
     AVRO-1471. Java: Permit writing generated code in different
     character encodings. (Eugene Mustaphin via cutting)
 
-    AVRO-1402. Support for DECIMAL type (as a record mapping). (tomwhite)
-
   OPTIMIZATIONS
 
     AVRO-1455. Deep copy does not need to create new instances for primitives.

Modified: avro/trunk/doc/src/content/xdocs/spec.xml
URL: http://svn.apache.org/viewvc/avro/trunk/doc/src/content/xdocs/spec.xml?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/doc/src/content/xdocs/spec.xml (original)
+++ avro/trunk/doc/src/content/xdocs/spec.xml Thu Apr 10 10:35:03 2014
@@ -1336,34 +1336,6 @@ void initFPTable() {
       </section>
     </section>
 
-    <section>
-      <title>Record Mappings</title>
-
-      <p>Implementations may optionally map the following record schemas to an appropriate
-        native type.</p>
-
-      <section>
-        <title>Decimal</title>
-        <p>The <code>Decimal</code> type represents arbitrary-precision
signed decimal
-          numbers. A <code>Decimal</code> is encoded as an <code>int</code>
<em>scale</em>
-          followed by a <code>bytes</code> <em>value</em> field containing
the
-          two's-complement representation of the unscaled integer value in big-endian
-          byte order.</p>
-        <p>The value of the number represented by this <code>Decimal</code>
type is
-          <em>value &#215; 10<sup>-scale</sup></em>.</p>
-        <source>
-{
-  "type": "record",
-  "name": "org.apache.avro.Decimal",
-  "fields": [
-    {"name": "scale", "type": "int"},
-    {"name": "value", "type": "bytes"}
-  ]
-}
-        </source>
-      </section>
-    </section>
-
   <p><em>Apache Avro, Avro, Apache, and the Avro and Apache logos are
    trademarks of The Apache Software Foundation.</em></p>
 

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Thu Apr
10 10:35:03 2014
@@ -64,12 +64,6 @@ public class GenericData {
 
   private final ClassLoader classLoader;
 
-  private final Map<String, RecordMapping<?>> recordMappings =
-      new HashMap<String, RecordMapping<?>>();
-
-  private final Map<Class<?>, RecordMapping<?>> recordMappingClasses =
-      new HashMap<Class<?>, RecordMapping<?>>();
-
   /** Set the Java type to be used when reading this schema.  Meaningful only
    * only string schemas and map schemas (for the keys). */
   public static void setStringType(Schema s, StringType stringType) {
@@ -97,22 +91,6 @@ public class GenericData {
   /** Return the class loader that's used (by subclasses). */
   public ClassLoader getClassLoader() { return classLoader; }
 
-  /** Register a {@link org.apache.avro.generic.RecordMapping} to be used when reading or
-   * writing records using {@link org.apache.avro.generic.GenericDatumReader} or
-   * {@link org.apache.avro.generic.GenericDatumWriter}.
-   */
-  public <T> void addRecordMapping(RecordMapping<T> recordMapping) {
-    recordMappings.put(recordMapping.getSchema().getFullName(), recordMapping);
-    recordMappingClasses.put(recordMapping.getRecordClass(), recordMapping);
-  }
-
-  /** Return the  {@link org.apache.avro.generic.RecordMapping} for the given record
-   * schema, or <code>null</code> if there is no mapping registered.
-   */
-  public RecordMapping<?> getRecordMapping(Schema schema) {
-    return recordMappings.get(schema.getFullName());
-  }
-
   /** Default implementation of {@link GenericRecord}. Note that this implementation
    * does not fill in default values for fields if they are not specified; use {@link
    * GenericRecordBuilder} in that case.
@@ -699,25 +677,14 @@ public class GenericData {
 
   /** Called by the default implementation of {@link #instanceOf}.*/
   protected boolean isRecord(Object datum) {
-    return datum instanceof IndexedRecord || isRecordMapping(datum);
-  }
-
-  /** Return true if the given <code>datum</code> has a registered record mapping
class.
-   * Called by the default implementation of {@link #isRecord(Object)}.
-   */
-  protected boolean isRecordMapping(Object datum) {
-    return datum != null && recordMappingClasses.containsKey(datum.getClass());
+    return datum instanceof IndexedRecord;
   }
 
   /** Called to obtain the schema of a record.  By default calls
-   * {@link GenericContainer#getSchema()}, or uses a registered record mapper if not a
-   * {@link GenericContainer}. May be overridden for alternate
-   * record representations. */
+   * {GenericContainer#getSchema().  May be overridden for alternate record
+   * representations. */
   protected Schema getRecordSchema(Object record) {
-    if (record instanceof GenericContainer) {
-      return ((GenericContainer) record).getSchema();
-    }
-    return recordMappingClasses.get(record.getClass()).getSchema();
+    return ((GenericContainer)record).getSchema();
   }
 
   /** Called by the default implementation of {@link #instanceOf}.*/

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
Thu Apr 10 10:35:03 2014
@@ -170,10 +170,6 @@ public class GenericDatumReader<D> imple
    * representations.*/
   protected Object readRecord(Object old, Schema expected, 
       ResolvingDecoder in) throws IOException {
-    RecordMapping<?> recordMapping = data.getRecordMapping(expected);
-    if (recordMapping != null) {
-      return recordMapping.read(old, in);
-    }
     Object r = data.newRecord(old, expected);
     Object state = data.getRecordState(r, expected);
     

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumWriter.java
Thu Apr 10 10:35:03 2014
@@ -99,11 +99,6 @@ public class GenericDatumWriter<D> imple
    * representations.*/
   protected void writeRecord(Schema schema, Object datum, Encoder out)
     throws IOException {
-    RecordMapping<?> recordMapping = data.getRecordMapping(schema);
-    if (recordMapping != null) {
-      recordMapping.write(datum, out);
-      return;
-    }
     Object state = data.getRecordState(datum, schema);
     for (Field f : schema.getFields()) {
       writeField(datum, f, out, state);

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1586265&r1=1586264&r2=1586265&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Thu Apr 10 10:35:03
2014
@@ -26,7 +26,6 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -43,7 +42,6 @@ import org.apache.avro.data.Json;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.generic.GenericDatumWriter;
-import org.apache.avro.generic.DecimalRecordMapping;
 import org.apache.avro.io.DatumReader;
 import org.apache.avro.io.DatumWriter;
 import org.apache.avro.io.Decoder;
@@ -542,40 +540,6 @@ public class TestSchema {
     }
   }
 
-  @Test
-  public void testDecimalRecordMapping() throws Exception {
-    String recordJson = "{\"type\":\"record\"," +
-        "\"name\":\"org.apache.avro.Decimal\"," +
-        "\"fields\":[\n" +
-        "  {\"name\":\"scale\",\"type\":\"int\"},\n" +
-        "  {\"name\":\"value\",\"type\":\"bytes\"}\n" +
-        "]}";
-    Schema schema = Schema.parse(recordJson);
-    BigDecimal decimal = new BigDecimal("12.45");
-    GenericData data = new GenericData();
-    data.addRecordMapping(new DecimalRecordMapping());
-    checkBinary(schema, decimal,
-        new GenericDatumWriter<Object>(schema, data),
-        new GenericDatumReader<Object>(schema, schema, data));
-  }
-
-  @Test
-  public void testDecimalRecordMappingUnion() throws Exception {
-    String recordJson = "{\"type\":\"record\"," +
-        "\"name\":\"org.apache.avro.Decimal\"," +
-        "\"fields\":[\n" +
-        "  {\"name\":\"scale\",\"type\":\"int\"},\n" +
-        "  {\"name\":\"value\",\"type\":\"bytes\"}\n" +
-        "]}";
-    Schema schema = Schema.parse("[\"null\",\"string\"," + recordJson + "]");
-    BigDecimal decimal = new BigDecimal("12.45");
-    GenericData data = new GenericData();
-    data.addRecordMapping(new DecimalRecordMapping());
-    checkBinary(schema, decimal,
-        new GenericDatumWriter<Object>(schema, data),
-        new GenericDatumReader<Object>(schema, schema, data));
-  }
-
   private static void checkParseError(String json) {
     try {
       Schema.parse(json);



Mime
View raw message