You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/07/03 22:33:00 UTC

[jira] [Work logged] (AVRO-3424) C# Add support to parse string into Schema.Type

     [ https://issues.apache.org/jira/browse/AVRO-3424?focusedWorklogId=787448&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-787448 ]

ASF GitHub Bot logged work on AVRO-3424:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Jul/22 22:32
            Start Date: 03/Jul/22 22:32
    Worklog Time Spent: 10m 
      Work Description: KalleOlaviNiemitalo commented on code in PR #1571:
URL: https://github.com/apache/avro/pull/1571#discussion_r912544555


##########
lang/csharp/src/apache/main/Schema/Schema.cs:
##########
@@ -380,5 +381,91 @@ 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 ? RemoveQuotes(type) : type;
+
+            switch (newValue)
+            {
+                case "null":
+                    return Schema.Type.Null;
+
+                case "boolean":
+                    return Schema.Type.Boolean;
+
+                case "int":
+                    return Schema.Type.Int;
+
+                case "long":
+                    return Schema.Type.Long;
+
+                case "float":
+                    return Schema.Type.Float;
+
+                case "double":
+                    return Schema.Type.Double;
+
+                case "bytes":
+                    return Schema.Type.Bytes;
+
+                case "string":
+                    return Schema.Type.String;
+
+                case "record":
+                    return Schema.Type.Record;
+
+                case "enumeration":

Review Comment:
   I am surprised that this is "enumeration", rather than "enum" like in <https://avro.apache.org/docs/current/spec.html#Enums>.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 787448)
    Time Spent: 4.5h  (was: 4h 20m)

> 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
>            Assignee: Kyle Schoonover
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.11.1, 1.12.0
>
>          Time Spent: 4.5h
>  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.10#820010)