Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void addValue(Type type, Object field) {
break;
case FLOAT_TYPE:
nulls.set(size, field == null);
doubleVars()[size] = field == null ? 0 : ((Float)field).doubleValue();
doubleVars()[size] = field == null ? 0 : new Double(field.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the problem is the precision, isn't enough to cast it to Double instead of creating a double out of a string?

Copy link
Author

@zuotingbing zuotingbing Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i am not sure what is your meaning. use “Double.parseDouble(String.valueOf(field))” ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean ((Double)field)

Copy link
Author

@zuotingbing zuotingbing Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you are wrong. we cannot cast Float to Double like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now the issue, so we cannot convert directly from float to double, we have to pass through another object which may be a string as in this your solution. Please disregard my comment, thanks.

break;
case DOUBLE_TYPE:
nulls.set(size, field == null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,14 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
assert(pipeoutFileList(sessionID).length == 0)
}
}

test("SPARK-24829 Checks cast as float") {
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery("SELECT CAST('4.56' AS FLOAT)")
resultSet.next()
assert(resultSet.getString(1) === "4.56")
}
}
}

class SingleSessionSuite extends HiveThriftJdbcTest {
Expand Down Expand Up @@ -766,6 +774,14 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion)
}
}

test("SPARK-24829 Checks cast as float") {
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery("SELECT CAST('4.56' AS FLOAT)")
resultSet.next()
assert(resultSet.getString(1) === "4.56")
}
}
}

object ServerMode extends Enumeration {
Expand Down