[
https://issues.apache.org/jira/browse/AVRO-3424?focusedWorklogId=738846&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-738846
]
ASF GitHub Bot logged work on AVRO-3424:
----------------------------------------
Author: ASF GitHub Bot
Created on: 09/Mar/22 15:35
Start Date: 09/Mar/22 15:35
Worklog Time Spent: 10m
Work Description: KyleSchoonover commented on a change in pull request
#1571:
URL: https://github.com/apache/avro/pull/1571#discussion_r822782217
##########
File path: lang/csharp/src/apache/test/Schema/SchemaTests.cs
##########
@@ -439,5 +439,57 @@ public void TestUnionSchemaWithoutTypeProperty(string
schemaJson, string expecte
var schema = Schema.Parse(schemaJson);
Assert.AreEqual(schema.ToString(), expectedSchemaJson);
}
+
+ [TestFixture]
+ public class SchemaTypeExtensionsTests
+ {
+ [TestCase("null", Schema.Type.Null)]
+ [TestCase("boolean", Schema.Type.Boolean)]
+ [TestCase("int", Schema.Type.Int)]
+ [TestCase("long", Schema.Type.Long)]
+ [TestCase("float", Schema.Type.Float)]
+ [TestCase("double", Schema.Type.Double)]
+ [TestCase("bytes", Schema.Type.Bytes)]
+ [TestCase("string", Schema.Type.String)]
+ [TestCase("record", Schema.Type.Record)]
+ [TestCase("enumeration", Schema.Type.Enumeration)]
+ [TestCase("array", Schema.Type.Array)]
+ [TestCase("map", Schema.Type.Map)]
+ [TestCase("union", Schema.Type.Union)]
+ [TestCase("fixed", Schema.Type.Fixed)]
+ [TestCase("error", Schema.Type.Error)]
+ [TestCase("logical", Schema.Type.Logical)]
+ [TestCase("Logical", null)]
+ [TestCase("InvalidValue", null)]
+ [TestCase("\"null\"", null)]
+ [TestCase("", null)]
+ [TestCase(null, null)]
+ public void ParseTypeTest(string value, object expectedResult)
+ {
+ if (expectedResult is Schema.Type expectedType)
+ {
+ Assert.AreEqual(Schema.ParseType(value), expectedType);
+ }
+ else
+ {
+ Assert.AreEqual(Schema.ParseType(value), expectedResult);
+ }
+ }
+
+ [TestCase("\"null\"", Schema.Type.Null)]
+ [TestCase("\"nu\"ll\"", null)]
+ [TestCase("\"\"", null)]
+ public void ParseTypeRemoveQuotesTest(string value, object
expectedResult)
Review comment:
Using the existing pattern. If we want to change the pattern I would
recommend a separate story with subtasks to update all the existing test files.
##########
File path: lang/csharp/src/apache/main/Schema/Schema.cs
##########
@@ -380,5 +381,73 @@ protected static int getHashCode(object obj)
{
return obj == null ? 0 : obj.GetHashCode();
}
+
+ /// <summary>
+ /// Parses the Schema.Type from a string.
+ /// </summary>
+ /// <param name="type">The type to convert.</param>
+ /// <param name="removeQuotes">if set to <c>true</c> [remove
quotes].</param>
+ /// <returns>A Schema.Type unless it could not parse then
null</returns>
+ /// <remarks>
+ /// usage ParseType("string") returns Schema.Type.String
+ /// </remarks>
+ public static Schema.Type? ParseType(string type, bool removeQuotes =
false)
+ {
+ string newValue = removeQuotes ? type.Trim('"') : type;
Review comment:
Updated
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 738846)
Time Spent: 3h 10m (was: 3h)
> C# Add support to parse string into Schema.Type
> -----------------------------------------------
>
> Key: AVRO-3424
> URL: https://issues.apache.org/jira/browse/AVRO-3424
> Project: Apache Avro
> Issue Type: Improvement
> Components: csharp
> Reporter: Kyle Schoonover
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 3h 10m
> Remaining Estimate: 0h
>
> Right now this just revolves around the PrimitiveSchema NewInstance method,
> but this would create a feature for parsing a string into a Schema.Type enum.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)