You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@livy.apache.org by GitBox <gi...@apache.org> on 2020/04/03 19:40:17 UTC

[GitHub] [incubator-livy] mgaido91 commented on a change in pull request #288: [LIVY-754][THRIFT] Encode precision and scale for decimal type.

mgaido91 commented on a change in pull request #288: [LIVY-754][THRIFT] Encode precision and scale for decimal type.
URL: https://github.com/apache/incubator-livy/pull/288#discussion_r403271842
 
 

 ##########
 File path: thriftserver/server/src/main/scala/org/apache/livy/thriftserver/types/Schema.scala
 ##########
 @@ -109,9 +109,42 @@ object Schema {
       case _ => TTypeId.STRING_TYPE
     }
     val primitiveEntry = new TPrimitiveTypeEntry(typeId)
+    if (dt == DataType.DECIMAL) {
+      val qualifiers = getDecimalQualifiers(name)
+      primitiveEntry.setTypeQualifiers(qualifiers)
+    }
     val entry = TTypeEntry.primitiveEntry(primitiveEntry)
     val desc = new TTypeDesc
     desc.addToTypes(entry)
     desc
   }
+
+  private def getDecimalQualifiers(name: String): TTypeQualifiers = {
+    // name can be one of
+    // 1. decimal
+    // 2. decimal(p)
+    // 3. decimal(p, s)
+    val (precision, scale) =
+      if (name == "decimal") {
+        (10, 0)
+      } else {
+        val suffix = name.substring("decimal".length)
+        require(suffix.startsWith("(") && suffix.endsWith(")"),
+          name + " is not of the form decimal(<precision>,<scale>)")
+        val parts = suffix.substring(1, suffix.length - 1).split(",")
+        if (parts.length == 1) {
+          (parts(0).trim.toInt, 0)
+        } else {
+          (parts(0).trim.toInt, parts(1).trim.toInt)
+        }
 
 Review comment:
   nit:
   ```suggestion
           val parts = suffix.substring(1, suffix.length - 1).split(",").map(_.trim.toInt)
           (parts(0), parts.lift(1).getOrElse(0))
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services