You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2021/12/29 19:50:24 UTC

[GitHub] [avro] csplugins opened a new pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

csplugins opened a new pull request #1438:
URL: https://github.com/apache/avro/pull/1438


   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO/) issues and references them in the PR title. For example, "AVRO-1234: My Avro PR"
     - https://issues.apache.org/jira/browse/AVRO-2862
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Tests
   
   - [ ] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   ### 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](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"
   
   ### 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
   


-- 
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] martin-g merged pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

Posted by GitBox <gi...@apache.org>.
martin-g merged pull request #1438:
URL: https://github.com/apache/avro/pull/1438


   


-- 
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] KyleSchoonover commented on pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

Posted by GitBox <gi...@apache.org>.
KyleSchoonover commented on pull request #1438:
URL: https://github.com/apache/avro/pull/1438#issuecomment-1027040232


   @martin-g Can you 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] martin-g commented on a change in pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

Posted by GitBox <gi...@apache.org>.
martin-g commented on a change in pull request #1438:
URL: https://github.com/apache/avro/pull/1438#discussion_r796969994



##########
File path: lang/csharp/src/apache/test/Schema/SchemaTests.cs
##########
@@ -167,6 +167,49 @@ private static void testToString(Schema sc)
             }
         }
 
+        [TestCase("{ \"type\": \"null\", \"metafield\": \"abc\" }", Schema.Type.Null)]
+        [TestCase("{ \"type\": \"boolean\", \"metafield\": \"abc\" }", Schema.Type.Boolean)]
+        [TestCase("{ \"type\": \"int\", \"metafield\": \"abc\" }", Schema.Type.Int)]
+        [TestCase("{ \"type\": \"long\", \"metafield\": \"abc\" }", Schema.Type.Long)]
+        [TestCase("{ \"type\": \"float\", \"metafield\": \"abc\" }", Schema.Type.Float)]
+        [TestCase("{ \"type\": \"double\", \"metafield\": \"abc\" }", Schema.Type.Double)]
+        [TestCase("{ \"type\": \"bytes\", \"metafield\": \"abc\" }", Schema.Type.Bytes)]
+        [TestCase("{ \"type\": \"string\", \"metafield\": \"abc\" }", Schema.Type.String)]
+        public void TestPrimitiveWithMetadata(string s, Schema.Type type)
+        {
+            Schema sc1 = Schema.Parse(s);

Review comment:
       Please use better names for the variables than `s`, `sc1`, `rc`, etc.




-- 
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] KyleSchoonover commented on a change in pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

Posted by GitBox <gi...@apache.org>.
KyleSchoonover commented on a change in pull request #1438:
URL: https://github.com/apache/avro/pull/1438#discussion_r792066664



##########
File path: lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
##########
@@ -82,7 +82,19 @@ public static PrimitiveSchema NewInstance(string type, PropertyMap props = null)
         /// <param name="encspace"></param>
         protected internal override void WriteJson(JsonTextWriter w, SchemaNames names, string encspace)
         {
-            w.WriteValue(Name);
+            if(this.Props != null && this.Props.Count > 0)
+            {
+                w.WriteStartObject();
+                w.WritePropertyName("type");
+                w.WriteValue(Name);
+                foreach(var prop in Props)
+                {
+                    w.WritePropertyName(prop.Key);
+                    w.WriteRawValue(prop.Value);
+                }
+                w.WriteEndObject();
+            }
+            else w.WriteValue(Name);

Review comment:
       Put else within brackets. Fixes styling related to SA1503

##########
File path: lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs
##########
@@ -82,7 +82,19 @@ public static PrimitiveSchema NewInstance(string type, PropertyMap props = null)
         /// <param name="encspace"></param>
         protected internal override void WriteJson(JsonTextWriter w, SchemaNames names, string encspace)
         {
-            w.WriteValue(Name);
+            if(this.Props != null && this.Props.Count > 0)

Review comment:
       shorthand for same check `if(this.Props?.Any() == true)`

##########
File path: lang/csharp/src/apache/main/Schema/Schema.cs
##########
@@ -202,8 +202,15 @@ internal static Schema ParseJson(JToken jtok, SchemaNames names, string encspace
                 }
                 else if (jtype.Type == JTokenType.Array)
                     return UnionSchema.NewInstance(jtype as JArray, props, names, encspace);
-                else if (jtype.Type == JTokenType.Object && null != jo["logicalType"]) // logical type based on a complex type
-                    return LogicalSchema.NewInstance(jtok, props, names, encspace);
+                else if (jtype.Type == JTokenType.Object)
+                {
+                    if (null != jo["logicalType"]) // logical type based on a complex type
+                        return LogicalSchema.NewInstance(jtok, props, names, encspace);

Review comment:
       Put within brackets. Fixes styling related to SA1503

##########
File path: lang/csharp/src/apache/main/Schema/Schema.cs
##########
@@ -202,8 +202,15 @@ internal static Schema ParseJson(JToken jtok, SchemaNames names, string encspace
                 }
                 else if (jtype.Type == JTokenType.Array)
                     return UnionSchema.NewInstance(jtype as JArray, props, names, encspace);
-                else if (jtype.Type == JTokenType.Object && null != jo["logicalType"]) // logical type based on a complex type
-                    return LogicalSchema.NewInstance(jtok, props, names, encspace);
+                else if (jtype.Type == JTokenType.Object)
+                {
+                    if (null != jo["logicalType"]) // logical type based on a complex type
+                        return LogicalSchema.NewInstance(jtok, props, names, encspace);
+
+                    var schema = ParseJson(jtype, names, encspace); // primitive schemas are allowed to have additional metadata properties
+                    if (schema is PrimitiveSchema)
+                        return schema;

Review comment:
       Put within brackets. Fixes styling related to SA1503




-- 
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] martin-g commented on pull request #1438: Avro-2862: Fix primitive schemas losing metadata properties

Posted by GitBox <gi...@apache.org>.
martin-g commented on pull request #1438:
URL: https://github.com/apache/avro/pull/1438#issuecomment-1028298979


   Thank you for the contribution, @csplugins !


-- 
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