You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2021/12/04 13:35:55 UTC

[avro] branch branch-1.11 updated: AVRO-3217: Allow any identifier as annotation name (#1414)

This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 757bfd5  AVRO-3217: Allow any identifier as annotation name (#1414)
757bfd5 is described below

commit 757bfd566367ec6077bef5595105103ca9bb01c6
Author: Oscar Westra van Holthe - Kind <op...@users.noreply.github.com>
AuthorDate: Sat Dec 4 14:35:16 2021 +0100

    AVRO-3217: Allow any identifier as annotation name (#1414)
    
    A field schema can be annotated with the property `avro.java.string`:
    
        {
          "name": "fieldName",
          "type": {
            "type": "string",
            "avro.java.string": "String"
          }
        }
    
    The corresponding IDL is:
    
        @avro.java.`string`("String") string fieldName;
    
    The IDL parser fails on the `. This change fixes that.
---
 .../compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj   | 7 ++++---
 lang/java/compiler/src/test/idl/input/simple.avdl                  | 2 +-
 lang/java/compiler/src/test/idl/output/simple.avpr                 | 5 ++++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
index 0a2b696..15d251e 100644
--- a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
+++ b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
@@ -1551,14 +1551,15 @@ Schema ResultType():
 String PropertyName():
 {
   Token t;
+  String s;
   StringBuilder name = new StringBuilder();
 }
 {
-  t = <IDENTIFIER>   { name.append(t.image); }
+  s = Identifier()   { name.append(s); }
   ( t = <DASH>       { name.append(t.image); }
-    t = <IDENTIFIER> { name.append(t.image); } |
+    s = Identifier() { name.append(s); } |
     t = <DOT>        { name.append(t.image); }
-    t = <IDENTIFIER> { name.append(t.image); }
+    s = Identifier() { name.append(s); }
   ) *
   { return name.toString(); }
 }
diff --git a/lang/java/compiler/src/test/idl/input/simple.avdl b/lang/java/compiler/src/test/idl/input/simple.avdl
index 10e50c9..0d09272 100644
--- a/lang/java/compiler/src/test/idl/input/simple.avdl
+++ b/lang/java/compiler/src/test/idl/input/simple.avdl
@@ -42,7 +42,7 @@ protocol Simple {
   /** A TestRecord. */
   @my-property({"key":3})
   record TestRecord {
-    string @order("ignore") name = "foo";
+    @avro.java.`string`("String") string @order("ignore") name = "foo";
 
     /** The kind of record. */
     Kind @order("descending") kind;
diff --git a/lang/java/compiler/src/test/idl/output/simple.avpr b/lang/java/compiler/src/test/idl/output/simple.avpr
index ddcb626..5710f08 100644
--- a/lang/java/compiler/src/test/idl/output/simple.avpr
+++ b/lang/java/compiler/src/test/idl/output/simple.avpr
@@ -26,7 +26,10 @@
     "doc" : "A TestRecord.",
     "fields" : [ {
       "name" : "name",
-      "type" : "string",
+      "type" : {
+        "type": "string",
+        "avro.java.string": "String"
+      },
       "default" : "foo",
       "order" : "ignore"
     }, {