Avro
  1. Avro
  2. AVRO-221

Mangle conflicting names in generated code for Java

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.0
    • Component/s: java
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      Generated Java code should support fields that conflict with Java reserved words.

      1. AVRO-221.patch.txt
        10 kB
        Philip Zeyliger
      2. AVRO-221.patch
        9 kB
        Doug Cutting

        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 -

        +1.

        Show
        Philip Zeyliger added a comment - +1.
        Hide
        Doug Cutting added a comment -

        Here's a version that uses dollar instead of underscore. Dollar is not permitted in Avro identifiers and is thus preferred.

        Show
        Doug Cutting added a comment - Here's a version that uses dollar instead of underscore. Dollar is not permitted in Avro identifiers and is thus preferred.
        Hide
        Philip Zeyliger added a comment -

        Here's an attempt at this. This doesn't support evil things, like schemas with both "finally_" and "finally", but it does generate what ought to be valid code.

        Really, the tests ought to compile (using javac from tools.jar, say), but this patch doesn't do that.

        Show
        Philip Zeyliger added a comment - Here's an attempt at this. This doesn't support evil things, like schemas with both "finally_" and "finally", but it does generate what ought to be valid code. Really, the tests ought to compile (using javac from tools.jar, say), but this patch doesn't do that.
        Hide
        Philip Zeyliger added a comment -

        From the -dev list:

        Philip Zeyliger wrote:

        I think that for keywords, that language's implementation should
        generate something sensible if there's code generation installed. So,
        the Java specific compiler could have a list of Java keywords
        embedded. If it sees "long", it just replaces it with "long_" in the
        generated code. The only reserved words in Avro are the names of
        built-in avro types...

        Would that be sensible?

        +1 I agree that we should only mangle names when they conflict.

        Doug

        Show
        Philip Zeyliger added a comment - From the -dev list: Philip Zeyliger wrote: I think that for keywords, that language's implementation should generate something sensible if there's code generation installed. So, the Java specific compiler could have a list of Java keywords embedded. If it sees "long", it just replaces it with "long_" in the generated code. The only reserved words in Avro are the names of built-in avro types... Would that be sensible? +1 I agree that we should only mangle names when they conflict. Doug

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development