wypoon commented on a change in pull request #296:
URL: https://github.com/apache/incubator-livy/pull/296#discussion_r429563925



##########
File path: 
thriftserver/session/src/main/java/org/apache/livy/thriftserver/session/ResultSet.java
##########
@@ -88,7 +88,7 @@ private String toHiveString(Object value, boolean 
quoteStrings) {
     } else if (quoteStrings && value instanceof String) {
       return "\"" + value + "\"";
     } else if (value instanceof BigDecimal) {
-      return ((BigDecimal) value).stripTrailingZeros().toString();
+      return ((BigDecimal) value).toString();

Review comment:
       Well, I stand corrected about Spark SQL. However, Hive, like other SQL 
databases (MySQL, MS SQL Server), does not allow negative scale:
   ```
   > create table dec_test1 (id int, foo decimal(10, 1));
   INFO  : Compiling 
command(queryId=hive_20200523170810_7a19e5b9-bb45-4b28-888c-1a4af5650d9e): 
create table dec_test1 (id int, foo decimal(10, 1))
   INFO  : Semantic Analysis Completed (retrial = false)
   INFO  : Created Hive schema: Schema(fieldSchemas:null, properties:null)
   INFO  : Completed compiling 
command(queryId=hive_20200523170810_7a19e5b9-bb45-4b28-888c-1a4af5650d9e); Time 
taken: 0.025 seconds
   INFO  : Executing 
command(queryId=hive_20200523170810_7a19e5b9-bb45-4b28-888c-1a4af5650d9e): 
create table dec_test1 (id int, foo decimal(10, 1))
   INFO  : Starting task [Stage-0:DDL] in serial mode
   INFO  : Completed executing 
command(queryId=hive_20200523170810_7a19e5b9-bb45-4b28-888c-1a4af5650d9e); Time 
taken: 0.08 seconds
   INFO  : OK
   No rows affected (0.137 seconds)
   ```
   while
   ```
   > create table dec_test2 (id int, foo decimal(10, -1));
   Error: Error while compiling statement: FAILED: ParseException line 1:48 
extraneous input '-' expecting Number near '<EOF>' (state=42000,code=40000)
   ```
   
   My change here produces the correct behavior for non-negative scale, which I 
believe is what most users will care about, and is also consistent for negative 
scale (since as I pointed out above, `BigDecimal#toString` allows faithful 
roundtrip back to `BigDecimal` from the String).




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to