Avro
  1. Avro
  2. AVRO-154

Tool to induce schema using reflection

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.0
    • Component/s: java
    • Labels:
      None

      Description

      Patch that follows gives command-line access to ReflectData's getSchema() API, which creates an AVRO schema based on reflection.

      Here's an example:

         $ src/scripts/avroj.sh induce build/test/classes org.apache.avro.BarRecord
          {"type":"record","name":"BarRecord","namespace":"org.apache.avro","fields":[{"name":"beerMsg","type":"string"}]}
      
      1. AVRO-154.patch.txt
        4 kB
        Philip Zeyliger
      2. AVRO-154.patch.txt
        4 kB
        Philip Zeyliger
      3. AVRO-154.patch.txt
        4 kB
        Philip Zeyliger

        Activity

        Hide
        Doug Cutting added a comment -

        I just committed this. Thanks, Philip!

        Show
        Doug Cutting added a comment - I just committed this. Thanks, Philip!
        Hide
        Philip Zeyliger added a comment -

        Updated patch to work on current trunk.

        Show
        Philip Zeyliger added a comment - Updated patch to work on current trunk.
        Hide
        Philip Zeyliger added a comment -

        Doug,

        Now that AVRO-149 is done, this is ready for review/commit.

        Thanks,

        – Philip

        Show
        Philip Zeyliger added a comment - Doug, Now that AVRO-149 is done, this is ready for review/commit. Thanks, – Philip
        Hide
        Philip Zeyliger added a comment -

        1-line change to previous patch to get the singleton ReflectData instead of constructing a new one.

        [0]doorstop:induce:avro(213828)$git show
        commit aa3c28c9ba2fc058fcd4b275eeff80090c54e8fc
        Author: Philip Zeyliger <philip@cloudera.com>
        Date:   Fri Oct 16 15:26:52 2009 -0700
        
            Grabbing singleton instance of ReflectData.
        
        diff --git a/src/java/org/apache/avro/reflect/InduceSchemaTool.java b/src/java/org/apache/avro/reflect/InduceSchemaTool.java
        index de6121f..4245dff 100644
        --- a/src/java/org/apache/avro/reflect/InduceSchemaTool.java
        +++ b/src/java/org/apache/avro/reflect/InduceSchemaTool.java
        @@ -54,6 +54,6 @@ public class InduceSchemaTool implements Tool {
             }
         
             Class<?> klass = classLoader.loadClass(className);
        -    System.out.println(new ReflectData().getSchema(klass).toString());
        +    System.out.println(ReflectData.get().getSchema(klass).toString());
           }
         }
        
        Show
        Philip Zeyliger added a comment - 1-line change to previous patch to get the singleton ReflectData instead of constructing a new one. [0]doorstop:induce:avro(213828)$git show commit aa3c28c9ba2fc058fcd4b275eeff80090c54e8fc Author: Philip Zeyliger <philip@cloudera.com> Date: Fri Oct 16 15:26:52 2009 -0700 Grabbing singleton instance of ReflectData. diff --git a/src/java/org/apache/avro/reflect/InduceSchemaTool.java b/src/java/org/apache/avro/reflect/InduceSchemaTool.java index de6121f..4245dff 100644 --- a/src/java/org/apache/avro/reflect/InduceSchemaTool.java +++ b/src/java/org/apache/avro/reflect/InduceSchemaTool.java @@ -54,6 +54,6 @@ public class InduceSchemaTool implements Tool { } Class<?> klass = classLoader.loadClass(className); - System.out.println(new ReflectData().getSchema(klass).toString()); + System.out.println(ReflectData.get().getSchema(klass).toString()); } }
        Hide
        Philip Zeyliger added a comment -

        Should we add an option to pretty-print the schema?

        Yes, but not quite yet? I want to figure out how to do command-line parsing for tools, but I want to do some more research and have a couple more examples before I get there.

        Should we add an option/command to induce protocols from an interface too?

        Probably, but I'm not yet sure how to do it. getProtocol() requires paranamer, so whereas it makes sense to point "induce" at a POJO, I'm not sure if it makes sense to point it at an arbitrary class — chances are, it won't have the paranamer data. We could run paranamer from within the tool, but that's sufficiently different that I'd rather leave it for a different JIRA.

        Show
        Philip Zeyliger added a comment - Should we add an option to pretty-print the schema? Yes, but not quite yet? I want to figure out how to do command-line parsing for tools, but I want to do some more research and have a couple more examples before I get there. Should we add an option/command to induce protocols from an interface too? Probably, but I'm not yet sure how to do it. getProtocol() requires paranamer, so whereas it makes sense to point "induce" at a POJO, I'm not sure if it makes sense to point it at an arbitrary class — chances are, it won't have the paranamer data. We could run paranamer from within the tool, but that's sufficiently different that I'd rather leave it for a different JIRA.
        Hide
        Doug Cutting added a comment -

        This is a great addition.

        Should we add an option to pretty-print the schema?

        Should we add an option/command to induce protocols from an interface too?

        Show
        Doug Cutting added a comment - This is a great addition. Should we add an option to pretty-print the schema? Should we add an option/command to induce protocols from an interface too?
        Hide
        Philip Zeyliger added a comment -

        Patch depends on AVRO-149, naturally.

        Show
        Philip Zeyliger added a comment - Patch depends on AVRO-149 , naturally.

          People

          • Assignee:
            Philip Zeyliger
            Reporter:
            Philip Zeyliger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development