Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-3459 use keywords instead of struct types #1607

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

KyleSchoonover
Copy link
Contributor

Jira

Tests

  • My PR does not need testing for this extremely good reason: Updated existing tests

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

@github-actions github-actions bot added the C# label Mar 18, 2022
@zcsizmadia
Copy link
Contributor

This seems to be breaking change for some users. The generated code should not be different by default. If a user does some post processing on the generated code, this will potentially break them. Maybe a future --nullable option to avrogen, however I am not sure I see the actual benefit. Beside maybe the generated code looks more modern, but the compiled code will be pretty much identical.

Is there any known benefit making those changes in the generated code?

@KyleSchoonover
Copy link
Contributor Author

@zcsizmadia I'm running into a problem with nested records. I was actually thinking about creating a targeted C# version (--csharp-version 7.3) as an option for avrogen. Let me switch this to draft and think about how I want to change it up. I reached out to you on the ASF slack about this PR.

@KyleSchoonover KyleSchoonover marked this pull request as draft March 19, 2022 02:33
@zcsizmadia
Copy link
Contributor

Could you post the actual schema which gives you trouble? Maybe there is another solution for your problem.

@KyleSchoonover
Copy link
Contributor Author

{"namespace": "org.apache.avro.codegentest.some",
  "type": "record",
  "name": "NestedSomeNamespaceRecord",
  "doc" : "Test nested types with different namespace than the outer type",
  "fields": [
    {
      "name": "nestedRecord",
      "type": {
        "namespace": "org.apache.avro.codegentest.other",
        "type": "record",
        "name": "NestedOtherNamespaceRecord",
        "fields": [
          {
            "name": "someField",
            "type": "int"
          }
        ]
      }
    }]
}

@zcsizmadia
Copy link
Contributor

What is the issue with that schema?

@KyleSchoonover
Copy link
Contributor Author

KyleSchoonover commented Mar 21, 2022

It will generate the following. Specifically the type for _someField

// ------------------------------------------------------------------------------
// <auto-generated>
//    Generated by avrogen, version 1.12.0.0
//    Changes to this file may cause incorrect behavior and will be lost if code
//    is regenerated
// </auto-generated>
// ------------------------------------------------------------------------------
namespace org.apache.avro.codegentest.other
{
	using System;
	using System.Collections.Generic;
	using System.Text;
	using global::Avro;
	using global::Avro.Specific;
	
	public partial class NestedOtherNamespaceRecord : global::Avro.Specific.ISpecificRecord
	{
		public static global::Avro.Schema _SCHEMA = global::Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"NestedOtherNamespaceRecord\",\"namespace\":\"org.apache.avro" +
				".codegentest.other\",\"fields\":[{\"name\":\"someField\",\"type\":\"int\"}]}");
		private @int _someField;
		public virtual global::Avro.Schema Schema
		{
			get
			{
				return NestedOtherNamespaceRecord._SCHEMA;
			}
		}
		public @int someField
		{
			get
			{
				return this._someField;
			}
			set
			{
				this._someField = value;
			}
		}
		public virtual object Get(int fieldPos)
		{
			switch (fieldPos)
			{
			case 0: return this.someField;
			default: throw new global::Avro.AvroRuntimeException("Bad index " + fieldPos + " in Get()");
			};
		}
		public virtual void Put(int fieldPos, object fieldValue)
		{
			switch (fieldPos)
			{
			case 0: this.someField = (int)fieldValue; break;
			default: throw new global::Avro.AvroRuntimeException("Bad index " + fieldPos + " in Put()");
			};
		}
	}
}

@zcsizmadia
Copy link
Contributor

Is there anything wrong with the current code generation?

@KyleSchoonover
Copy link
Contributor Author

The type is @int

@zcsizmadia
Copy link
Contributor

Hmmmm. I am confused. My avrogen installed from nuget.org generates this:

// ------------------------------------------------------------------------------
// <auto-generated>
//    Generated by avrogen, version 1.11.0.0
//    Changes to this file may cause incorrect behavior and will be lost if code
//    is regenerated
// </auto-generated>
// ------------------------------------------------------------------------------
namespace org.apache.avro.codegentest.other
{
	using System;
	using System.Collections.Generic;
	using System.Text;
	using Avro;
	using Avro.Specific;
	
	public partial class NestedOtherNamespaceRecord : ISpecificRecord
	{
		public static Schema _SCHEMA = Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"NestedOtherNamespaceRecord\",\"namespace\":\"org.apache.avro" +
				".codegentest.other\",\"fields\":[{\"name\":\"someField\",\"type\":\"int\"}]}");
		private int _someField;
		public virtual Schema Schema
		{
			get
			{
				return NestedOtherNamespaceRecord._SCHEMA;
			}
		}
		public int someField
		{
			get
			{
				return this._someField;
			}
			set
			{
				this._someField = value;
			}
		}
		public virtual object Get(int fieldPos)
		{
			switch (fieldPos)
			{
			case 0: return this.someField;
			default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()");
			};
		}
		public virtual void Put(int fieldPos, object fieldValue)
		{
			switch (fieldPos)
			{
			case 0: this.someField = (System.Int32)fieldValue; break;
			default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()");
			};
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants