[KYUUBI #1784][FOLLOWUP][TRINO] Fix float types lose precision

<!--
Thanks for sending a pull request!

Here are some tips for you:
  1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
  2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
  3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
-->

### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
  1. If you add a feature, you can talk about the use case of it.
  2. If you fix a bug, you can clarify why it is a bug.
-->

The end-to-end test case should be added after the Trino engine test framework has been refined.

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1802 from cfmcgrady/kyuubi-1784-trino.

Closes #1784

8b19aafb [Fu Chen] fix

Authored-by: Fu Chen <cfmcgrady@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Fu Chen 2022-01-19 16:50:41 +08:00 committed by Cheng Pan
parent c06e042287
commit a4de0e67f6
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
2 changed files with 6 additions and 3 deletions

View File

@ -114,7 +114,7 @@ object RowSet {
case REAL =>
val values = getOrSetAsNull[java.lang.Float](rows, ordinal, nulls, 0.toFloat)
.asScala.map(n => java.lang.Double.valueOf(n.toDouble)).asJava
.asScala.map(n => java.lang.Double.valueOf(n.toString)).asJava
TColumn.doubleVal(new TDoubleColumn(values, nulls))
case DOUBLE =>
@ -200,7 +200,10 @@ object RowSet {
case REAL =>
val tDoubleValue = new TDoubleValue
if (row(ordinal) != null) tDoubleValue.setValue(row(ordinal).asInstanceOf[Float])
if (row(ordinal) != null) {
val doubleValue = java.lang.Double.valueOf(row(ordinal).asInstanceOf[Float].toString)
tDoubleValue.setValue(doubleValue)
}
TColumnValue.doubleVal(tDoubleValue)
case DOUBLE =>

View File

@ -182,7 +182,7 @@ class RowSetSuite extends KyuubiFunSuite {
val floatCol = cols.next().getDoubleVal
floatCol.getValues.asScala.zipWithIndex.foreach {
case (b, 11) => assert(b === 0)
case (b, i) => assert(b === java.lang.Float.valueOf(s"$i.$i"))
case (b, i) => assert(b.toFloat === java.lang.Float.valueOf(s"$i.$i"))
}
val doubleCol = cols.next().getDoubleVal