avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject svn commit: r899185 - in /hadoop/avro/trunk: ./ lang/java/src/java/org/apache/avro/io/ lang/java/src/java/org/apache/avro/io/parsing/ lang/java/src/test/java/org/apache/avro/io/
Date Thu, 14 Jan 2010 12:53:33 GMT
Author: thiru
Date: Thu Jan 14 12:53:32 2010
New Revision: 899185

URL: http://svn.apache.org/viewvc?rev=899185&view=rev
Log:
AVRO-313. Default values for fields or records and array (or map) don't work with ResolvingDecoder

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/JsonEncoder.java
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ValidatingDecoder.java
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Parser.java
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/SkipParser.java
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Symbol.java
    hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Thu Jan 14 12:53:32 2010
@@ -309,6 +309,8 @@
     AVRO-207. Fix Python to detect duplicate enum symbols and add
     tests for duplicates in unions.  (Jeff Hammerbacher via cutting)
 
+    AVRO-313. Default values for fields or records and array (or map) don't work with ResolvingDecoder
(thiru)
+
 Avro 1.2.0 (14 October 2009)
 
   INCOMPATIBLE CHANGES

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/JsonEncoder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/JsonEncoder.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/JsonEncoder.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/JsonEncoder.java Thu Jan 14 12:53:32
2010
@@ -53,7 +53,7 @@
 
   @Override
   public void flush() throws IOException {
-    parser.processImplicitActions();
+    parser.processTrailingImplicitActions();
     out.flush();
   }
 

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ResolvingDecoder.java Thu Jan
14 12:53:32 2010
@@ -198,6 +198,12 @@
       parser.pushSymbol(branches.getSymbol(in.readIndex()));
     } else if (top instanceof Symbol.ErrorAction) {
       throw new AvroTypeException(((Symbol.ErrorAction) top).msg);
+    } else if (top instanceof Symbol.DefaultStartAction) {
+      Symbol.DefaultStartAction dsa = (Symbol.DefaultStartAction) top;
+      backup = in;
+      in = (new JsonDecoder(dsa.root, new ByteArrayInputStream(dsa.contents)));
+    } else if (top == Symbol.DEFAULT_END_ACTION) {
+      in = backup;
     }
   }
 }

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ValidatingDecoder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ValidatingDecoder.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ValidatingDecoder.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/ValidatingDecoder.java Thu Jan
14 12:53:32 2010
@@ -164,6 +164,7 @@
 
   @Override
   public long arrayNext() throws IOException {
+    parser.processTrailingImplicitActions();
     long result = in.arrayNext();
     if (result == 0) {
       parser.advance(Symbol.ARRAY_END);
@@ -195,6 +196,7 @@
 
   @Override
   public long mapNext() throws IOException {
+    parser.processTrailingImplicitActions();
     long result = in.mapNext();
     if (result == 0) {
       parser.advance(Symbol.MAP_END);

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Parser.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Parser.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Parser.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Parser.java Thu Jan 14
12:53:32 2010
@@ -21,6 +21,7 @@
 import java.util.Arrays;
 
 import org.apache.avro.AvroTypeException;
+import org.apache.avro.io.parsing.Symbol.ImplicitAction;
 
 /**
  * Parser is the class that maintains the stack for parsing. This class
@@ -89,20 +90,15 @@
   }
   
   /**
-   * Performs any implicit actions at the top the stack, expanding any
-   * production (other than the root) that may be encountered.
-   * This method will fail if there are any repeaters on the stack.
-   * @throws IOException
+   * Performs any "trailing" implicit actions at the top the stack. 
    */
-  public final void processImplicitActions() throws IOException {
-     while (pos > 1) {
+  public final void processTrailingImplicitActions() throws IOException {
+    while (pos >= 1) {
       Symbol top = stack[pos - 1];
-      if (top.kind == Symbol.Kind.IMPLICIT_ACTION) {
+      if (top.kind == Symbol.Kind.IMPLICIT_ACTION 
+        && ((Symbol.ImplicitAction) top).isTrailing) {
         pos--;
         symbolHandler.doAction(null, top);
-      } else if (top.kind != Symbol.Kind.TERMINAL) {
-        pos--;
-        pushProduction(null, top);
       } else {
         break;
       }

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/SkipParser.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/SkipParser.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/SkipParser.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/SkipParser.java Thu Jan
14 12:53:32 2010
@@ -55,6 +55,7 @@
    * parser stack reaches the target level.
    */
   public final void skipTo(int target) throws IOException {
+    outer:
     while (target < pos) {
       Symbol top = stack[pos - 1];
       while (top.kind != Symbol.Kind.TERMINAL) {
@@ -65,7 +66,7 @@
           --pos;
           pushProduction(null, top);
         }
-        top = stack[pos - 1];
+        continue outer;
       }
       skipHandler.skipTopSymbol();
     }

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Symbol.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Symbol.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Symbol.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/parsing/Symbol.java Thu Jan 14
12:53:32 2010
@@ -143,9 +143,21 @@
     public String toString() { return printName; }
   }
 
-  private static class ImplicitAction extends Symbol {
+  public static class ImplicitAction extends Symbol {
+    /**
+     * Set to <tt>true</tt> if and only if this implicit action is 
+     * a trailing action. That is, it is an action that follows
+     * real symbol. E.g {@link Symbol#DEFAULT_END_ACTION}.
+     */
+    public final boolean isTrailing;
+
     private ImplicitAction() {
+      this(false);
+    }
+    
+    private ImplicitAction(boolean isTrailing) {
       super(Kind.IMPLICIT_ACTION);
+      this.isTrailing = isTrailing;
     }
   }
   
@@ -371,11 +383,11 @@
   public static final Symbol FIELD_ACTION =
     new Symbol.Terminal("field-action");
 
-  public static final Symbol RECORD_START = new ImplicitAction();
-  public static final Symbol RECORD_END = new ImplicitAction();
-  public static final Symbol UNION_END = new ImplicitAction();
+  public static final Symbol RECORD_START = new ImplicitAction(false);
+  public static final Symbol RECORD_END = new ImplicitAction(true);
+  public static final Symbol UNION_END = new ImplicitAction(true);
   
-  public static final Symbol DEFAULT_END_ACTION = new ImplicitAction();
+  public static final Symbol DEFAULT_END_ACTION = new ImplicitAction(true);
   public static final Symbol MAP_KEY_MARKER =
     new Symbol.Terminal("map-key-marker");
 }

Modified: hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java?rev=899185&r1=899184&r2=899185&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
(original)
+++ hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestResolvingIOResolving.java
Thu Jan 14 12:53:32 2010
@@ -95,6 +95,13 @@
           "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
           + "{\"name\":\"f\", \"type\":\"int\", \"default\": 100}]}", "I",
           new Object[] { 100 } },
+        // default string value
+        { "{\"type\":\"record\",\"name\":\"r\",\"fields\":[]}", "",
+            new Object[] { },
+            "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+            + "{\"name\":\"f\", \"type\":\"string\", \"default\": \"hello\"}]}",
+            "S50",
+            new Object[] { "hello" } },
         { "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
             + "{\"name\":\"f2\", \"type\":\"int\"}]}", "I",
           new Object[] { 10 },
@@ -103,18 +110,36 @@
           + "{\"name\":\"f2\", \"type\":\"int\"}]}", "II",
           new Object[] { 10, 101 } },
         { "{\"type\":\"record\",\"name\":\"outer\",\"fields\":["
-            + "{\"name\": \"g1\", " +
-                        "\"type\":{\"type\":\"record\",\"name\":\"inner\",\"fields\":["
-                + "{\"name\":\"f2\", \"type\":\"int\"}]}}, "
+            + "{\"name\": \"g1\", "
+            + "\"type\":{\"type\":\"record\",\"name\":\"inner\",\"fields\":["
+            + "{\"name\":\"f2\", \"type\":\"int\"}]}}, "
             + "{\"name\": \"g2\", \"type\": \"long\"}]}", "IL",
           new Object[] { 10, 11L },
           "{\"type\":\"record\",\"name\":\"outer\",\"fields\":["
-            + "{\"name\": \"g1\", " +
-                        "\"type\":{\"type\":\"record\",\"name\":\"inner\",\"fields\":["
-                + "{\"name\":\"f1\", \"type\":\"int\", \"default\": 101},"
-                + "{\"name\":\"f2\", \"type\":\"int\"}]}}, "
+            + "{\"name\": \"g1\", "
+            + "\"type\":{\"type\":\"record\",\"name\":\"inner\",\"fields\":["
+            + "{\"name\":\"f1\", \"type\":\"int\", \"default\": 101},"
+            + "{\"name\":\"f2\", \"type\":\"int\"}]}}, "
           + "{\"name\": \"g2\", \"type\": \"long\"}]}}", "IIL",
           new Object[] { 10, 101, 11L } },
+        // Default + array
+        { "{\"type\": \"array\", \"items\":" +
+            "{\"type\":\"record\",\"name\":\"r\",\"fields\":[]}}", "[c1s]",
+          new Object[] { },
+          "{\"type\": \"array\", \"items\":"
+            + "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+            + "{\"name\":\"f\", \"type\":\"int\", \"default\": 100}]}}",
+          "[c1sI]",
+          new Object[] { 100 } },
+        // Default + map
+        { "{\"type\": \"map\", \"values\":" +
+            "{\"type\":\"record\",\"name\":\"r\",\"fields\":[]}}", "{c1sS10}",
+          new Object[] { "key" },
+          "{\"type\": \"map\", \"values\":"
+            + "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
+            + "{\"name\":\"f\", \"type\":\"int\", \"default\": 100}]}}",
+          "{c1sS10I}",
+          new Object[] { "key", 100 } },
     };
   }
 }



Mime
View raw message