Skip to content

Conversation

@heary-cao
Copy link
Contributor

What changes were proposed in this pull request?

spark-sql>SELECT ceil(1234567890123456);
1234567890123456

spark-sql>SELECT ceil(12345678901234567);
12345678901234568

spark-sql>SELECT ceil(123456789012345678);
123456789012345680

when the length of the getText is greater than 16. long to double will be precision loss.

but mysql handle the value is ok.

mysql> SELECT ceil(1234567890123456);
+------------------------+
| ceil(1234567890123456) |
+------------------------+
| 1234567890123456 |
+------------------------+
1 row in set (0.00 sec)

mysql> SELECT ceil(12345678901234567);
+-------------------------+
| ceil(12345678901234567) |
+-------------------------+
| 12345678901234567 |
+-------------------------+
1 row in set (0.00 sec)

mysql> SELECT ceil(123456789012345678);
+--------------------------+
| ceil(123456789012345678) |
+--------------------------+
| 123456789012345678 |
+--------------------------+
1 row in set (0.00 sec)

How was this patch tested?

Supplement the unit test.

@heary-cao heary-cao changed the title Improve ceil handle the value which is not expected [SPARK-20786][SQL]Improve ceil handle the value which is not expected May 17, 2017
Copy link
Member

Choose a reason for hiding this comment

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

I think the question is, why is it a valid long but being used as a double (?) elsewhere?
Also you can use methods on BigDecimal to query its precision and scale. toString isn't the right approach

@hvanhovell
Copy link
Contributor

+1 on Sean's comment. This is not a parser issue. Can you just fix this by adding LongType to Ceil.inputTypes?

@heary-cao heary-cao changed the title [SPARK-20786][SQL]Improve ceil handle the value which is not expected [SPARK-20786][SQL]Improve ceil and floor handle the value which is not expected May 18, 2017
@heary-cao
Copy link
Contributor Author

@hvanhovell @srowen
I have modify it again. and floor is same problem.
review please.
thanks.

@gatorsmile
Copy link
Member

ok to test

Copy link
Member

Choose a reason for hiding this comment

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

Could yo move all these new tests to the end of operators.sql?

You can run the following command to generate the result files.

SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "sql/test-only *SQLQueryTestSuite"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, add new tests to the end of operators.sql.
please review it again.
thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Could you revert the changes you made in this file MathFunctionsSuite.scala?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK,
please review it again.
thanks.

@SparkQA
Copy link

SparkQA commented May 18, 2017

Test build #77061 has finished for PR 18016 at commit 9888e16.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@heary-cao heary-cao force-pushed the ceil_long branch 2 times, most recently from 68ecf5e to 1f771bd Compare May 19, 2017 01:41
@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77073 has finished for PR 18016 at commit 68ecf5e.

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

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77074 has finished for PR 18016 at commit 1f771bd.

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

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77077 has finished for PR 18016 at commit 8b346e6.

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

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77078 has finished for PR 18016 at commit 6d51c07.

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

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77083 has started for PR 18016 at commit 437343e.

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77087 has finished for PR 18016 at commit 1698e80.

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

@gatorsmile
Copy link
Member

LGTM except one comment.

@heary-cao heary-cao force-pushed the ceil_long branch 2 times, most recently from 6d8f507 to 6c50fec Compare May 22, 2017 01:31
@SparkQA
Copy link

SparkQA commented May 22, 2017

Test build #77162 has finished for PR 18016 at commit 6d8f507.

  • This patch fails PySpark unit tests.
  • This patch does not merge cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented May 22, 2017

Test build #77163 has finished for PR 18016 at commit 6c50fec.

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

@SparkQA
Copy link

SparkQA commented May 22, 2017

Test build #77164 has finished for PR 18016 at commit f7afebf.

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

@gatorsmile
Copy link
Member

LGTM

@gatorsmile
Copy link
Member

Thanks! Merging to master.

Could you submit another PR to backport it to 2.2?

@asfgit asfgit closed this in 3c9eef3 May 22, 2017
lycplus pushed a commit to lycplus/spark that referenced this pull request May 24, 2017
…ot expected

## What changes were proposed in this pull request?

spark-sql>SELECT ceil(1234567890123456);
1234567890123456

spark-sql>SELECT ceil(12345678901234567);
12345678901234568

spark-sql>SELECT ceil(123456789012345678);
123456789012345680

when the length of the getText is greater than 16. long to double will be precision loss.

but mysql handle the value is ok.

mysql> SELECT ceil(1234567890123456);
+------------------------+
| ceil(1234567890123456) |
+------------------------+
|       1234567890123456 |
+------------------------+
1 row in set (0.00 sec)

mysql> SELECT ceil(12345678901234567);
+-------------------------+
| ceil(12345678901234567) |
+-------------------------+
|       12345678901234567 |
+-------------------------+
1 row in set (0.00 sec)

mysql> SELECT ceil(123456789012345678);
+--------------------------+
| ceil(123456789012345678) |
+--------------------------+
|       123456789012345678 |
+--------------------------+
1 row in set (0.00 sec)

## How was this patch tested?

Supplement the unit test.

Author: caoxuewen <cao.xuewen@zte.com.cn>

Closes apache#18016 from heary-cao/ceil_long.
@ueshin
Copy link
Member

ueshin commented May 25, 2017

@heary-cao Hi, I found Ceil and Floor modified by this pr produce different results between interpret and codegen.
We also need to modify doGenCode() to handle LongType correctly.
Can you fix it at a follow-up pr?

@rxin
Copy link
Contributor

rxin commented May 25, 2017

hm guys please don’t use the end-to-end tests to test expression behavior. use unit tests which automatically tests code gen, interpreted, and different data types.

@heary-cao
Copy link
Contributor Author

@ueshin ,
thank you for your suggestion.
modify doGenCode() pr: #18103

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.

7 participants