You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "alexrosenfeld10 (via GitHub)" <gi...@apache.org> on 2023/05/07 13:31:14 UTC
[GitHub] [avro] alexrosenfeld10 opened a new pull request, #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
alexrosenfeld10 opened a new pull request, #2215:
URL: https://github.com/apache/avro/pull/2215
<!--
*Thank you very much for contributing to Apache Avro - we are happy that you want to help us improve Avro. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Avro a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "AVRO-XXXX: [component] Title of the pull request", where *AVRO-XXXX* should be replaced by the actual issue number.
The *component* is optional, but can help identify the correct reviewers faster: either the language ("java", "python") or subsystem such as "build" or "doc" are good candidates.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests. You can [build the entire project](https://github.com/apache/avro/blob/master/BUILD.md) or just the [language-specific SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Every commit message references Jira issues in their subject lines. In addition, commits follow the guidelines from [How to write a good git commit message](https://chris.beams.io/posts/git-commit/)
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
-->
## What is the purpose of the change
This PR adds the ability to write types directly back to the user, instead of forcing writing to disk. This is critical for use in scenarios where the code generation is done in a CI job, where disk permissions might not be flexible.
## Verifying this change
This change can be verified as follows:
- Manually verified the change by building and using the new methods locally in C# Source Generators (see https://github.com/alexrosenfeld10/avro-sourcegen-csharp/pull/4)
## Documentation
- Does this pull request introduce a new feature? yes
- If yes, how is the feature documented? C# XML docs. This change is not exposed by the `avrogen` tool because in that context it doesn't really make sense to do anything _other_ than write directly to disk. This is meant for use from other C# code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228551968
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
@zcsizmadia I looked at this, it requires changing the `LangVersion` for the project.

Happy to make these changes, but it seems out of scope for this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228597731
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
oh duh. I haven't been in old C# in a while.. apologies
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1589896405
@alexrosenfeld10 I tthink one simple use case of what you intend to use this should be enough. I assume you will create a CodeGen object, add some schemas and call GetTypes. That output should be checked for expected result. I agree that the pattern can be fine tuned later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1589657128
@RyanSkraba @zcsizmadia @martin-g @KyleSchoonover I found your names from recent PRs, would someone be available to push this over the line? Thanks very much in adv.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] RyanSkraba commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "RyanSkraba (via GitHub)" <gi...@apache.org>.
RyanSkraba commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1589699551
Hey -- thanks for the contribution! I've had limited time (and I've been pre-occupied with the 1.11.2 release prep).
I'm not a C# dev, but it _seems_ like this is a pretty safe change and could be included safely in the minor release. If any C# committers can take a look and confirm, that would be great -- but any C# dev's review is valued!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1542250897
@RyanSkraba When you have time, please review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1189421942
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
## Missing Dispose call on local IDisposable
Disposable 'CSharpCodeProvider' is created but not disposed.
[Show more details](https://github.com/apache/avro/security/code-scanning/2987)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228496176
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
I have no issue if you add "using" tin this PR where those other places are. new CSharpCodeProvider is used without using. (if not too many). If too many lets make another PR
Not having "using" IMO is considered a resource leak bug, so breaking the pattern in such case is poreferred.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1591188245
@zcsizmadia I beg your pardon, there already was a place to put a unit test. I've added one. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1589702350
Thanks @RyanSkraba , I appreciate the response.
Yes, this is a super benign change - it's purely additive, and has no side effects. This sets up the stage for something larger I and @alfhv are working on - getting the C# side of Avro able to make cross-file schema references by namespace.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228470018
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
Please add using to this just to avoid any potential resource leaks. Probably the other places should get the using as well (you mentioned that you followed the pattern of other code snippets)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1589737356
I always like top get some basic test coverage to set the minimal baseline. Those initial unit tests can be removed or rewritten when a better rework is happening in the future
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] RyanSkraba commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "RyanSkraba (via GitHub)" <gi...@apache.org>.
RyanSkraba commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1591625630
Cherry-picked to [branch-1.11](https://github.com/apache/avro/commit/aa450f35caf4ed209018bf3a70fb9352989b936c).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1591627901
Thanks @RyanSkraba
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1591460728
Thanks @alexrosenfeld10 !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228593759
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
That using format is only C# 8+. You need to use using with brackets. Which sepcifies the scope explicitly.

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1229687123
##########
lang/csharp/src/apache/test/CodGen/CodeGenTest.cs:
##########
@@ -81,6 +82,32 @@
Protocol protocol = null;
Assert.Throws<ArgumentNullException>(() => this.GenerateNames(protocol));
}
+
+
+ [Test]
+ public void GetTypesShouldReturnTypes()
+ {
+ AddSchema(@"
+{
+ ""name"": ""PlanetEnum"",
+ ""namespace"": ""Space.Models"",
+ ""type"": ""enum"",
+ ""symbols"": [
+ ""Earth"",
+ ""Mars"",
+ ""Jupiter"",
+ ""Saturn"",
+ ""Uranus"",
+ ""Neptune""
+ ]
+}
+");
+ GenerateCode();
+ var types = GetTypes();
+ Assert.That(types.Count, Is.EqualTo(1));
+ Assert.That(types.ContainsKey("PlanetEnum"));
Review Comment:
## Inefficient use of ContainsKey
Inefficient use of 'ContainsKey' and [indexer](1).
[Show more details](https://github.com/apache/avro/security/code-scanning/2990)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia merged pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia merged PR #2215:
URL: https://github.com/apache/avro/pull/2215
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on PR #2215:
URL: https://github.com/apache/avro/pull/2215#issuecomment-1591358965
@zcsizmadia other than the 3 workflows awaiting approval, I think this can be merged now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1228476759
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
Sure, I can do that. My approach with OSS PRs is to match existing patterns and introduce as little deviation / other changes as possible to achieve the feature. Happy to add `using` here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #2215: AVRO-3756: [csharp] Add a method to return types instead of writing them to disk
Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #2215:
URL: https://github.com/apache/avro/pull/2215#discussion_r1189941870
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1136,6 +1136,48 @@
}
}
+ /// <summary>
+ /// Gets names and generated code of the schema(s) types
+ /// </summary>
+ /// <returns></returns>
+ public virtual IDictionary<string, string> GetTypes()
+ {
+ var cscp = new CSharpCodeProvider();
Review Comment:
just copying patterns from the other (very similar) methods. If desired, I can update this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org