Skip to content

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Jul 7, 2020

What changes were proposed in this pull request?

In this PR, I suppose we support 'f'-suffixed float literal, e.g. select 1.1f

Why are the changes needed?

a very common feature across platforms, checked with pg, presto, hive, MySQL...

Does this PR introduce any user-facing change?

yes,

select 1.1f results float value 1.1 instead of throwing AnlaysisExceptiionCan't extract value from 1: need struct type but got int;

How was this patch tested?

add unit tests

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 7, 2020

cc @cloud-fan @maropu @HyukjinKwon thanks for reviewing this in advance.

@cloud-fan
Copy link
Contributor

I don't know why it's not supported before, and looks fine to me. cc @maropu @viirya @bart-samwel

@bart-samwel
Copy link

SGTM!

@HyukjinKwon
Copy link
Member

+1

@maropu
Copy link
Member

maropu commented Jul 7, 2020

Oh, I see. Looks okay to add this.

Copy link
Member

@wangyum wangyum left a comment

Choose a reason for hiding this comment

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

Hive 2.3 and PostgreSQL seem to be aliases:

hive> CREATE TABLE test_float1 as SELECT 1.0F, 2.0D;
hive> DESC test_float1;
OK
f                   	decimal(1,0)
_c1                 	double
Time taken: 0.763 seconds, Fetched: 2 row(s)
postgres=# CREATE TABLE test_float1 as SELECT 1.0F, 2.0D;
postgres=# \d test_float1;
            Table "public.test_float1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 f      | numeric |           |          |
 d      | numeric |           |          |

@bart-samwel
Copy link

Hive 2.3 and PostgreSQL seem to be aliases:

hive> CREATE TABLE test_float1 as SELECT 1.0F, 2.0D;
hive> DESC test_float1;
OK
f                   	decimal(1,0)
_c1                 	double
Time taken: 0.763 seconds, Fetched: 2 row(s)
postgres=# CREATE TABLE test_float1 as SELECT 1.0F, 2.0D;
postgres=# \d test_float1;
            Table "public.test_float1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 f      | numeric |           |          |
 d      | numeric |           |          |

I wonder what postgresql does with 1.0e2 -- does it treat it like 1.0 with alias e2 or like 1.0 * 10^2? And 1.0e probably is an alias then. These kinds of discontinuities are terrible and we should stay far away from them...

@SparkQA
Copy link

SparkQA commented Jul 7, 2020

Test build #125202 has finished for PR 29022 at commit f260e41.

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

@wangyum
Copy link
Member

wangyum commented Jul 7, 2020

postgres=# CREATE TABLE test_float2 as SELECT 1.0F, 2.0D, 1.0e2, 1.0e;
SELECT 1
postgres=# \d test_float2;
             Table "public.test_float2"
  Column  |  Type   | Collation | Nullable | Default
----------+---------+-----------+----------+---------
 f        | numeric |           |          |
 d        | numeric |           |          |
 ?column? | numeric |           |          |
 e        | numeric |           |          |

postgres=# select * from test_float2;
  f  |  d  | ?column? |  e
-----+-----+----------+-----
 1.0 | 2.0 |      100 | 1.0
(1 row)

@SparkQA
Copy link

SparkQA commented Jul 7, 2020

Test build #125206 has finished for PR 29022 at commit 90bb546.

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

@viirya
Copy link
Member

viirya commented Jul 7, 2020

I noticed this too when I played with other PR. I thought it was by purpose. If it is not, looks okay to add it.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125236 has finished for PR 29022 at commit 90bb546.

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

@maropu
Copy link
Member

maropu commented Jul 8, 2020

Could you update the doc, too? https://github.com/apache/spark/blob/master/docs/sql-ref-literals.md#numeric-literal
cc: @huaxingao

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 8, 2020

documentation updated, thanks for reminding me @maropu

Case insensitive, indicates `DOUBLE`, which is an 8-byte double-precision floating point number.
* **D**
Copy link
Contributor

Choose a reason for hiding this comment

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

F

Copy link
Member

@maropu maropu left a comment

Choose a reason for hiding this comment

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

LGTM except for the @cloud-fan comment.

Long.MinValue, Long.MaxValue, LongType.simpleString)(_.toLong)
}

override def visitFloatLiteral(ctx: FloatLiteralContext): Literal = {
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 add a function description like the other functions around here, @yaooqinn ?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

+1, LGTM (except @cloud-fan 's comment and mine)

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125287 has finished for PR 29022 at commit 4439bb6.

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

@HyukjinKwon
Copy link
Member

retest this please

@wangyum
Copy link
Member

wangyum commented Jul 8, 2020

Maybe we should convert suffix to alias. Please see these examples for more details:

Presto:
image

MySQL 5.7.26:
image

MySQL 8.0.16:
image

MariaDB 10.4.6:
image

PostgreSQL 11.3:
image

Hive 3.1.2:
image

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 8, 2020

Maybe we should convert suffix to alias. Please see these examples for more details:

If the digits part is integral, e.g. 2f, 2a, these systems vary from each other..., not always alias. on the other hand, inside spark, we have different error msg for 2.1f(Can't extract value from 1: need struct type but got int;) and 2f(cannot resolve '2f' given input columns: []), but 2d and 2.1d are valid inputs. IMHO, it's better to keep the consistency of our
own first.

@wangyum
Copy link
Member

wangyum commented Jul 8, 2020

Is there a system support F-suffixed as float Literal?

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125298 has finished for PR 29022 at commit 4439bb6.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125307 has finished for PR 29022 at commit 6e422ff.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@cloud-fan
Copy link
Contributor

Seems like most databases don't support the D suffix. Spark can't drop the D support now, I think it makes more sense to be consistent and support F as well.

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125320 has started for PR 29022 at commit 6e422ff.

@maropu
Copy link
Member

maropu commented Jul 8, 2020

Yea, the @cloud-fan comment above sounds fine to me.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125384 has finished for PR 29022 at commit 6e422ff.

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

@cloud-fan
Copy link
Contributor

retest this please

1 similar comment
@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 8, 2020

retest this please

@SparkQA
Copy link

SparkQA commented Jul 8, 2020

Test build #125388 has finished for PR 29022 at commit 6e422ff.

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

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 9, 2020

retest this please

@SparkQA
Copy link

SparkQA commented Jul 9, 2020

Test build #125425 has finished for PR 29022 at commit 6e422ff.

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

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 9, 2020

retest this please

@SparkQA
Copy link

SparkQA commented Jul 9, 2020

Test build #125435 has finished for PR 29022 at commit 6e422ff.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Jul 9, 2020

Test build #125443 has finished for PR 29022 at commit 6e422ff.

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

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Jul 9, 2020

Test build #125491 has started for PR 29022 at commit 6e422ff.

@yaooqinn
Copy link
Member Author

yaooqinn commented Jul 9, 2020

retest this please

@dongjoon-hyun
Copy link
Member

Retest this please

@SparkQA
Copy link

SparkQA commented Jul 10, 2020

Test build #125505 has finished for PR 29022 at commit 6e422ff.

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

@dongjoon-hyun
Copy link
Member

Thank you, @yaooqinn and all. Merged to master.

@yaooqinn
Copy link
Member Author

Thanks for merging @dongjoon-hyun and all for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants