-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-24829][STS]In Spark Thrift Server, CAST AS FLOAT inconsistent with spark-shell or spark-sql #21789
Conversation
@@ -766,6 +774,14 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest { | |||
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion) | |||
} | |||
} | |||
|
|||
test("Checks cast as float") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for two different modes: binary & http
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then probably better to add it into HiveThriftJdbcTest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HiveThriftJdbcTest
is an abstract class,there are two classess HiveThriftBinaryServerSuite
& HiveThriftBinaryServerSuite
extends from HiveThriftJdbcTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, so if you add the test to HiveThriftJdbcTest
it will be executed in both in HiveThriftBinaryServerSuite
and HiveThriftBinaryServerSuite
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i do not agree with you. HiveThriftBinaryServerSuite and HiveThriftHttpServerSuite ,which have exist before, are different cases for different ServerMode, we should test them all. if we add test in HiveThriftJdbcTest , we need to set different ServerMode in HiveThriftJdbcTest for the two cases, which break the design of abstract class of HiveThriftJdbcTest .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. If you add:
test("Checks cast as float") {
withJdbcStatement() { statement =>
val resultSet = statement.executeQuery("SELECT CAST('4.56' AS FLOAT)")
resultSet.next()
assert(resultSet.getString(1) === "4.56")
}
}
to the abstract class you need to change nothing else and the test would be executed both as a part of HiveThriftHttpServerSuite with one mode and as a part of HiveThriftBinaryServerSuite with the other mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see, i will fix it now. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zuotingbing. Could you narrow down the scope of title more specifically because this only happens in STS? All other shells like spark-shell
and spark-sql
works as expected. We had better call this as Spark's inconsistency.
yes, only in STS, i will update the title |
@@ -766,6 +774,14 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest { | |||
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion) | |||
} | |||
} | |||
|
|||
test("Checks cast as float") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then probably better to add it into HiveThriftJdbcTest?
@@ -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()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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))” ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean ((Double)field)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@cloud-fan @gatorsmile this change seems reasonable to me. Do you think we can trigger a build? Thanks. |
@zuotingbing I think what @dongjoon-hyun was suggesting you was to put |
@mgaido91 ok, update it. Thanks. |
ok to test |
Test build #93383 has finished for PR 21789 at commit
|
@HyukjinKwon i am not sure what is the reason about the tests failed. i checked the unit-tests.log and it seems the test "SPARK-24829 Checks cast as float" , which i added, have finished with no error. Could you give a help to check it or tell me how to fix the failure please? Thanks。 |
retest this please |
Test build #93438 has finished for PR 21789 at commit
|
retest this please @HyukjinKwon |
retest this please |
1 similar comment
retest this please |
ok to test |
Test build #93442 has finished for PR 21789 at commit
|
Test build #93440 has finished for PR 21789 at commit
|
@gatorsmile |
I think you better take a look for it because that looks related with the current change. |
…iftJdbcTest" which makes the UISeleniumSuite test failed
Test build #93482 has finished for PR 21789 at commit
|
LGTM, I checked and the same hack is done also in Hive. |
@HyukjinKwon could you help to merge this to master branch? Thanks. |
Let me leave this open for few days in case some reviewers have more comments on this. |
Merged to master. |
What changes were proposed in this pull request?
SELECT CAST('4.56' AS FLOAT)
the result is 4.559999942779541
it should be 4.56 as same as in spark-shell or spark-sql.
How was this patch tested?
add unit tests