Skip to content

Comments

[SPARK-42427][SQL] ANSI MODE: Conv should return an error if the internal conversion overflows#40001

Closed
gengliangwang wants to merge 1 commit intoapache:masterfrom
gengliangwang:fixConv
Closed

[SPARK-42427][SQL] ANSI MODE: Conv should return an error if the internal conversion overflows#40001
gengliangwang wants to merge 1 commit intoapache:masterfrom
gengliangwang:fixConv

Conversation

@gengliangwang
Copy link
Member

What changes were proposed in this pull request?

In ANSI SQL mode, function Conv() should return an error if the internal conversion overflows
For example, before the change:

> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
18446744073709551615

After the change

> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
org.apache.spark.SparkArithmeticException: [ARITHMETIC_OVERFLOW] Overflow in function conv(). If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
== SQL(line 1, position 8) ==
select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why are the changes needed?

Similar to the other SQL functions, this PR shows the overflow errors of conv() to users under ANSI SQL mode, instead of returning an unexpected number.

Does this PR introduce any user-facing change?

Yes, function conv() will return an error if the internal conversion overflows

How was this patch tested?

UTs

@gengliangwang
Copy link
Member Author

Merging to master/3.4

gengliangwang added a commit that referenced this pull request Feb 15, 2023
…rnal conversion overflows

### What changes were proposed in this pull request?

In ANSI SQL mode, function Conv() should return an error if the internal conversion overflows
For example, before the change:
```
> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
18446744073709551615
```
After the change
```
> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
org.apache.spark.SparkArithmeticException: [ARITHMETIC_OVERFLOW] Overflow in function conv(). If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
== SQL(line 1, position 8) ==
select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

### Why are the changes needed?

Similar to the other SQL functions, this PR shows the overflow errors of `conv()` to users under ANSI SQL mode, instead of returning an unexpected number.

### Does this PR introduce _any_ user-facing change?

Yes, function `conv()` will return an error if the internal conversion overflows

### How was this patch tested?

UTs

Closes #40001 from gengliangwang/fixConv.

Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
(cherry picked from commit cb463fb)
Signed-off-by: Gengliang Wang <gengliang@apache.org>
snmvaughan pushed a commit to snmvaughan/spark that referenced this pull request Jun 20, 2023
…rnal conversion overflows

### What changes were proposed in this pull request?

In ANSI SQL mode, function Conv() should return an error if the internal conversion overflows
For example, before the change:
```
> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
18446744073709551615
```
After the change
```
> select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
org.apache.spark.SparkArithmeticException: [ARITHMETIC_OVERFLOW] Overflow in function conv(). If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
== SQL(line 1, position 8) ==
select conv('fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, 10)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

### Why are the changes needed?

Similar to the other SQL functions, this PR shows the overflow errors of `conv()` to users under ANSI SQL mode, instead of returning an unexpected number.

### Does this PR introduce _any_ user-facing change?

Yes, function `conv()` will return an error if the internal conversion overflows

### How was this patch tested?

UTs

Closes apache#40001 from gengliangwang/fixConv.

Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
(cherry picked from commit cb463fb)
Signed-off-by: Gengliang Wang <gengliang@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants