opwvhk commented on a change in pull request #1411:
URL: https://github.com/apache/avro/pull/1411#discussion_r764002710
##########
File path:
lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
##########
@@ -1444,15 +1443,42 @@ Schema UnannotatedType(Map<String, JsonNode> props):
{
Schema s;
}
+{
+ (
+ s = NullableType(props)
+ | (
+ s = UnionDefinition()
+ | s = ArrayType()
+ | s = MapType()
+ )
+ {
+ // NullableType also applies properties, inside any union with null it
may create.
+ for (String key : props.keySet())
+ Accessor.addProp(s, key, props.get(key));
+ }
+ )
+ {
+ return s;
+ }
+}
+
+Schema NullableType(Map<String, JsonNode> props):
+{
+ Schema s;
+ boolean optional = false;
+}
{
(
s = ReferenceType() { if (!props.isEmpty()) { throw error("Type
references may not be annotated", token); } }
| s = PrimitiveType()
- | s = UnionDefinition()
- | s = ArrayType()
- | s = MapType()
- )
+ ) [ <QUESTION_MARK> { optional = true; } ]
{
+ // By applying the properties here (before creating the union), type
annotations modify the optional type instead of the union.
+ for (String key : props.keySet())
+ Accessor.addProp(s, key, props.get(key));
+ if (optional) {
+ s = Schema.createUnion(Schema.create(Schema.Type.NULL), s);
+ }
Review comment:
Note: when AVRO-2976 (PR #985) is merged, this need to be adjusted.
Conversely, if this PR is merged first, #985 needs to be adjusted.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]