TomBruns commented on code in PR #2751:
URL: https://github.com/apache/avro/pull/2751#discussion_r1497516192


##########
lang/csharp/src/apache/test/Schema/SchemaTests.cs:
##########
@@ -548,12 +549,77 @@
             testToString(sc);
         }
 
+        // Make sure unknown type is carried thru to LogicalTypeName
         [TestCase("{\"type\": \"int\", \"logicalType\": \"unknown\"}", 
"unknown")]
         public void TestUnknownLogical(string s, string unknownType)
         {
-            var err = Assert.Throws<AvroTypeException>(() => Schema.Parse(s));
+            //var err = Assert.Throws<AvroTypeException>(() => 
Schema.Parse(s));
+            //Assert.AreEqual("Logical type '" + unknownType + "' is not 
supported.", err.Message);
 
-            Assert.AreEqual("Logical type '" + unknownType + "' is not 
supported.", err.Message);
+            var schema = Schema.Parse(s);
+            Assert.IsInstanceOf(typeof(LogicalSchema), schema);
+
+            var logicalSchema = schema as LogicalSchema;
+            Assert.IsInstanceOf(typeof(UnknownLogicalType), 
logicalSchema.LogicalType);
+
+            Assert.AreEqual(logicalSchema.LogicalTypeName, unknownType);
+        }
+
+        /*
+            {
+              "fields": [
+                {
+                  "default": 0,
+                  "name": "firstField",
+                  "type": "int"
+                },
+                {
+                  "default": null,
+                  "name": "secondField",
+                  "type": [
+                    "null",
+                    {
+                      "logicalType": "varchar",
+                      "maxLength": 65,
+                      "type": "string"
+                    }
+                  ]
+                }
+              ],
+              "name": "sample_schema",
+              "type": "record"
+            }
+         */
+
+        // Before Change will throw Avro.AvroTypeException: 'Logical type 
'varchar' is not supported.'
+        // Per AVRO Spec (v1.8.0 - v1.11.1) ... Logical Types Section
+        //  Language implementations must ignore unknown logical types when 
reading, and should use the underlying Avro type.
+        [TestCase("{\"fields\": [{\"default\": 0,\"name\": 
\"firstField\",\"type\": \"int\"},{\"default\": null,\"name\": 
\"secondField\",\"type\": [\"null\",{\"logicalType\": 
\"varchar\",\"maxLength\": 65,\"type\": \"string\"}]}],\"name\": 
\"sample_schema\",\"type\": \"record\"}")]
+        public void TestUnknownLogicalType(string schemaText)
+        {
+            var schema = Avro.Schema.Parse(schemaText);
+            Assert.IsNotNull(schema);
+
+            var secondField = ((RecordSchema)schema).Fields.FirstOrDefault(f 
=> f.Name == @"secondField");
+            Assert.IsNotNull(secondField);
+
+            var secondFieldSchema = ((Field)secondField).Schema;

Review Comment:
   removed cast in new 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to