avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject svn commit: r1041903 - in /avro/trunk: CHANGES.txt lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java
Date Fri, 03 Dec 2010 16:39:42 GMT
Author: thiru
Date: Fri Dec  3 16:39:42 2010
New Revision: 1041903

URL: http://svn.apache.org/viewvc?rev=1041903&view=rev
Log:
Fixed AVRO-706. Java: Type promotion not succeeding for long -> float

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java
    avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1041903&r1=1041902&r2=1041903&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Dec  3 16:39:42 2010
@@ -56,6 +56,8 @@ Avro 1.5.0 (unreleased)
 
     AVRO-702. Java: Fix a bug printing nested record namespaces. (cutting)
 
+    AVRO-706. Java: Type promotion not succeeding for long -> float. (thiru)
+
 Avro 1.4.1 (13 October 2010)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java?rev=1041903&r1=1041902&r2=1041903&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java Fri Dec  3 16:39:42
2010
@@ -155,6 +155,19 @@ public class ResolvingDecoder extends Va
   }
 
   @Override
+  public float readFloat() throws IOException {
+    Symbol actual = parser.advance(Symbol.FLOAT);
+    if (actual == Symbol.INT) {
+      return (float) in.readInt();
+    } else if (actual == Symbol.LONG) {
+      return (float) in.readLong();
+    } else {
+      assert actual == Symbol.FLOAT;
+      return (float) in.readFloat();
+    }
+  }
+  
+  @Override
   public double readDouble() throws IOException {
     Symbol actual = parser.advance(Symbol.DOUBLE);
     if (actual == Symbol.INT) {

Modified: avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java?rev=1041903&r1=1041902&r2=1041903&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
(original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
Fri Dec  3 16:39:42 2010
@@ -130,12 +130,18 @@ public class ResolvingGrammarGenerator e
       case LONG:
         switch (writerType) {
         case INT:
-        case DOUBLE:
-        case FLOAT:
           return Symbol.resolve(super.generate(writer, seen), Symbol.LONG);
         }
         break;
   
+      case FLOAT:
+        switch (writerType) {
+        case INT:
+        case LONG:
+          return Symbol.resolve(super.generate(writer, seen), Symbol.FLOAT);
+        }
+        break;
+  
       case DOUBLE:
         switch (writerType) {
         case INT:
@@ -156,7 +162,6 @@ public class ResolvingGrammarGenerator e
       case BOOLEAN:
       case INT:
       case STRING:
-      case FLOAT:
       case BYTES:
       case ENUM:
       case ARRAY:

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java?rev=1041903&r1=1041902&r2=1041903&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIO.java Fri Dec  3
16:39:42 2010
@@ -124,12 +124,12 @@ public class TestResolvingIO {
   private static Object[][] testSchemas() {
     // The mnemonics are the same as {@link TestValidatingIO#testSchemas}
     return new Object[][] {
-        // { "\"int\"", "I", "\"float\"", "F" }, // makes sense?
+        { "\"int\"", "I", "\"float\"", "F" },
         { "\"int\"", "I", "\"double\"", "D" },
-        // { "\"long\"", "L", "\"float\"", "F" }, // And this?
+        { "\"int\"", "I", "\"long\"", "L" },
+        { "\"long\"", "L", "\"float\"", "F" },
         { "\"long\"", "L", "\"double\"", "D" },
         { "\"float\"", "F", "\"double\"", "D" },
-        { "\"double\"", "D", "\"long\"", "L" },
 
         { "{\"type\":\"array\", \"items\": \"int\"}", "[]",
           "{\"type\":\"array\", \"items\": \"long\"}", "[]", },



Mime
View raw message