Skip to content

Commit dc3713c

Browse files
zuotingbingHyukjinKwon
authored andcommitted
[SPARK-24829][STS] In Spark Thrift Server, CAST AS FLOAT inconsistent with spark-shell or spark-sql
## What changes were proposed in this pull request? SELECT CAST('4.56' AS FLOAT) the result is 4.559999942779541 ![2018-07-18_110944](https://user-images.githubusercontent.com/24823338/42857199-7c6783da-8a7b-11e8-8c69-1e9302102525.png) it should be 4.56 as same as in spark-shell or spark-sql. ![2018-07-18_111111](https://user-images.githubusercontent.com/24823338/42857210-80c89e96-8a7b-11e8-9f8c-de1a79a73752.png) ## How was this patch tested? add unit tests Author: zuotingbing <[email protected]> Closes apache#21789 from zuotingbing/SPARK-24829.
1 parent 094aa59 commit dc3713c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/Column.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public void addValue(Type type, Object field) {
349349
break;
350350
case FLOAT_TYPE:
351351
nulls.set(size, field == null);
352-
doubleVars()[size] = field == null ? 0 : ((Float)field).doubleValue();
352+
doubleVars()[size] = field == null ? 0 : new Double(field.toString());
353353
break;
354354
case DOUBLE_TYPE:
355355
nulls.set(size, field == null);

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,14 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
636636
assert(pipeoutFileList(sessionID).length == 0)
637637
}
638638
}
639+
640+
test("SPARK-24829 Checks cast as float") {
641+
withJdbcStatement() { statement =>
642+
val resultSet = statement.executeQuery("SELECT CAST('4.56' AS FLOAT)")
643+
resultSet.next()
644+
assert(resultSet.getString(1) === "4.56")
645+
}
646+
}
639647
}
640648

641649
class SingleSessionSuite extends HiveThriftJdbcTest {
@@ -766,6 +774,14 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
766774
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion)
767775
}
768776
}
777+
778+
test("SPARK-24829 Checks cast as float") {
779+
withJdbcStatement() { statement =>
780+
val resultSet = statement.executeQuery("SELECT CAST('4.56' AS FLOAT)")
781+
resultSet.next()
782+
assert(resultSet.getString(1) === "4.56")
783+
}
784+
}
769785
}
770786

771787
object ServerMode extends Enumeration {

0 commit comments

Comments
 (0)