[ https://issues.apache.org/jira/browse/SPARK-39865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17634465#comment-17634465 ]
Catalin Toda edited comment on SPARK-39865 at 11/15/22 6:02 PM: ---------------------------------------------------------------- [~Gengliang.Wang] here are the SQL statements that fail in my environment {code:java} DROP TABLE IF EXISTS test_table; CREATE TABLE test_table ( tmp decimal(38,9) ) STORED AS PARQUET; INSERT INTO TABLE test_table SELECT 1.2 test; DROP TABLE IF EXISTS comp; CREATE TABLE IF NOT EXISTS comp ( column1 decimal(38,9), column2 decimal(38,9) ) STORED AS PARQUET; WITH test as ( select sum(tmp) as tmp from test_table ) INSERT OVERWRITE TABLE comp select case when tmp = 0 then null else 1.0/tmp end as column1, if(tmp = 0,0, 1.0/tmp) as column2 from test {code} was (Author: catalinii): [~Gengliang.Wang] here is the SQL statements that fail in my environment {code:java} DROP TABLE IF EXISTS test_table; CREATE TABLE test_table ( tmp decimal(38,9) ) STORED AS PARQUET; INSERT INTO TABLE test_table SELECT 1.2 test; DROP TABLE IF EXISTS comp; CREATE TABLE IF NOT EXISTS comp ( column1 decimal(38,9), column2 decimal(38,9) ) STORED AS PARQUET; WITH test as ( select sum(tmp) as tmp from test_table ) INSERT OVERWRITE TABLE comp select case when tmp = 0 then null else 1.0/tmp end as column1, if(tmp = 0,0, 1.0/tmp) as column2 from test {code} > Show proper error messages on the overflow errors of table insert > ----------------------------------------------------------------- > > Key: SPARK-39865 > URL: https://issues.apache.org/jira/browse/SPARK-39865 > Project: Spark > Issue Type: Sub-task > Components: SQL > Affects Versions: 3.3.0, 3.4.0 > Reporter: Gengliang Wang > Assignee: Gengliang Wang > Priority: Major > Fix For: 3.3.1 > > > In Spark 3.3, the error message of ANSI CAST is improved. However, the table > insertion is using the same CAST expression: > {code:java} > > create table tiny(i tinyint); > > insert into tiny values (1000); > org.apache.spark.SparkArithmeticException[CAST_OVERFLOW]: The value 1000 of > the type "INT" cannot be cast to "TINYINT" due to an overflow. Use `try_cast` > to tolerate overflow and return NULL instead. If necessary set > "spark.sql.ansi.enabled" to "false" to bypass this error. > {code} > > Showing the hint of `If necessary set "spark.sql.ansi.enabled" to "false" to > bypass this error` doesn't help at all. This PR is to fix the error message. > After changes, the error message of this example will become: > {code:java} > org.apache.spark.SparkArithmeticException: [CAST_OVERFLOW_IN_TABLE_INSERT] > Fail to insert a value of "INT" type into the "TINYINT" type column `i` due > to an overflow. Use `try_cast` on the input value to tolerate overflow and > return NULL instead.{code} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org