Skip to content

Commit

Permalink
[KYUUBI #1784][FOLLOWUP][TRINO] Fix float types lose precision
Browse files Browse the repository at this point in the history
<!--
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

8b19aaf [Fu Chen] fix

Authored-by: Fu Chen <cfmcgrady@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
  • Loading branch information
cfmcgrady authored and pan3793 committed Jan 19, 2022
1 parent c06e042 commit a4de0e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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 =>
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit a4de0e6

Please sign in to comment.