[ 
https://issues.apache.org/jira/browse/AVRO-1702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16421703#comment-16421703
 ] 

ASF GitHub Bot commented on AVRO-1702:
--------------------------------------

thiru-apache commented on a change in pull request #302: AVRO-1702: Added 
support for logical types in the C++ client.
URL: https://github.com/apache/avro/pull/302#discussion_r178462083
 
 

 ##########
 File path: lang/c++/impl/Compiler.cc
 ##########
 @@ -327,6 +338,50 @@ static NodePtr makeRecordNode(const Entity& e,
         fieldValues, fieldNames, defaultValues));
 }
 
+static LogicalType makeLogicalType(const Entity& e, const Object& m) {
+    if (!containsField(e, m, "logicalType")) {
+        return LogicalType(LogicalType::NONE);
+    }
+
+    const std::string& typeField = getStringField(e, m, "logicalType");
+
+    if (typeField == "decimal") {
+        LogicalType decimalType(LogicalType::DECIMAL);
+        try {
+            decimalType.setPrecision(getLongField(e, m, "precision"));
+            if (containsField(e, m, "scale")) {
+                decimalType.setScale(getLongField(e, m, "scale"));
+            }
+        } catch (Exception& ex) {
+            // If any part of the logical type is malformed, per the standard 
we
+            // must ignore the whole attribute.
+            return LogicalType(LogicalType::NONE);
+        }
+        return decimalType;
+    }
+    if (typeField == "date") {
 
 Review comment:
   I think this will save some code and become more readable if we do something 
like:
   
       LogicalType::Type t = LogicalType::NONE;
       if (typeField == "date") {
           t = LogicalType::DATE;
       else if (typeField == "time-millis") {
           t = LogicalType::TIME_MILLIS;
      else if ... {
      }
      return LogicalType(t);

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add LogicalType support to c++ library
> --------------------------------------
>
>                 Key: AVRO-1702
>                 URL: https://issues.apache.org/jira/browse/AVRO-1702
>             Project: Avro
>          Issue Type: New Feature
>          Components: c++
>            Reporter: peter liu
>            Assignee: peter liu
>            Priority: Major
>
> I'd like to port the logicaltype support to c++ library



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to