Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

zuotingbing
Copy link

@zuotingbing zuotingbing commented Jul 17, 2018

What changes were proposed in this pull request?

SELECT CAST('4.56' AS FLOAT)

the result is 4.559999942779541

2018-07-18_110944

it should be 4.56 as same as in spark-shell or spark-sql.

2018-07-18_111111

How was this patch tested?

add unit tests

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

test("Checks cast as float") {
Copy link
Member

Choose a reason for hiding this comment

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

Duplicated code?

Copy link
Author

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

Copy link
Contributor

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?

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.

HiveThriftJdbcTest is an abstract class,there are two classess HiveThriftBinaryServerSuite & HiveThriftBinaryServerSuite extends from HiveThriftJdbcTest.

Copy link
Contributor

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....

Copy link
Author

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 .

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a 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.

@zuotingbing
Copy link
Author

yes, only in STS, i will update the title

@zuotingbing zuotingbing changed the title [SPARK-24829][SQL]CAST AS FLOAT inconsistent with Hive [SPARK-24829][SQL]In Spark Thrift Server, CAST AS FLOAT inconsistent with spark-shell or spark-sql Jul 18, 2018
@@ -766,6 +774,14 @@ class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
assert(resultSet.getString(2) === HiveUtils.builtinHiveVersion)
}
}

test("Checks cast as float") {
Copy link
Contributor

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());
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.

@mgaido91
Copy link
Contributor

@cloud-fan @gatorsmile this change seems reasonable to me. Do you think we can trigger a build? Thanks.

@mgaido91
Copy link
Contributor

@zuotingbing I think what @dongjoon-hyun was suggesting you was to put [STS] instead of [SQL] in the title of the PR. May you please update accordingly? Thanks.

@zuotingbing zuotingbing changed the title [SPARK-24829][SQL]In Spark Thrift Server, CAST AS FLOAT inconsistent with spark-shell or spark-sql [SPARK-24829][STS]In Spark Thrift Server, CAST AS FLOAT inconsistent with spark-shell or spark-sql Jul 20, 2018
@zuotingbing
Copy link
Author

zuotingbing commented Jul 20, 2018

@mgaido91 ok, update it. Thanks.

@HyukjinKwon
Copy link
Member

ok to test

@SparkQA
Copy link

SparkQA commented Jul 21, 2018

Test build #93383 has finished for PR 21789 at commit ffcff14.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zuotingbing
Copy link
Author

zuotingbing commented Jul 23, 2018

@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。

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Jul 23, 2018

Test build #93438 has finished for PR 21789 at commit ffcff14.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zuotingbing
Copy link
Author

zuotingbing commented Jul 23, 2018

retest this please @HyukjinKwon

@mgaido91
Copy link
Contributor

retest this please

1 similar comment
@HyukjinKwon
Copy link
Member

retest this please

@HyukjinKwon
Copy link
Member

ok to test

@SparkQA
Copy link

SparkQA commented Jul 23, 2018

Test build #93442 has finished for PR 21789 at commit 05cbdc8.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 23, 2018

Test build #93440 has finished for PR 21789 at commit 05cbdc8.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zuotingbing
Copy link
Author

@gatorsmile org.apache.spark.sql.hive.thriftserver.UISeleniumSuite.(It is not a test it is a sbt.testing.SuiteSelector) , Could you give a help to check it please? i find you are the latest person who update the UISeleniumSuite class , Thanks.

@HyukjinKwon
Copy link
Member

I think you better take a look for it because that looks related with the current change.

…iftJdbcTest" which makes the UISeleniumSuite test failed
@SparkQA
Copy link

SparkQA commented Jul 24, 2018

Test build #93482 has finished for PR 21789 at commit 88dff75.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@mgaido91
Copy link
Contributor

LGTM, I checked and the same hack is done also in Hive.

@zuotingbing
Copy link
Author

@HyukjinKwon could you help to merge this to master branch? Thanks.

@HyukjinKwon
Copy link
Member

Let me leave this open for few days in case some reviewers have more comments on this.

@HyukjinKwon
Copy link
Member

Merged to master.

@asfgit asfgit closed this in dc3713c Jul 27, 2018
@zuotingbing zuotingbing deleted the SPARK-24829 branch July 27, 2018 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants