IMPALA-10173: (Addendum) Fix substitution for unsafe expressions, column-level compatibility check

Expression substitution recreates cast expressions without considering
the compatibility level introduced by IMPALA-10173. In unsafe mode, the
recreation causes IllegalStateException. This change fixes this
behavior by storing the compatibility level in each CastExpr, and
reusing it when the expression substitution recreates the cast
expression.

For example: 'select "1", "1" union select 1, "1"'

Also, Set operation's common type calculations did not distinguish
compatibility levels for each column slot, if one column slot's common
type was considered unsafe, every other slot was treated as unsafe.
This change fixes this behavior by reinitializing the compatibility
level for every column slot, enabling cases where one column slot
contains unsafely casted constant values and another contains
non-constant expressions with regular casts.
These queries failed before this change with 'Unsafe implicit cast is
prohibited for non-const expression' error.

For example: 'select "1", 1 union select 1, int_col from unsafe_insert'

Tests:
 - test cases added to insert-unsafe.test

Change-Id: I39d13f177482f74ec39570118adab609444c6929
Reviewed-on: http://gerrit.cloudera.org:8080/20184
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
Peter Rozsa
2023-07-11 12:00:44 +02:00
committed by Impala Public Jenkins
parent e27e4eb54a
commit a570ee866e
12 changed files with 103 additions and 55 deletions

View File

@@ -213,4 +213,13 @@ AnalysisException: Unsafe implicit cast is prohibited for non-const expression:
INSERT INTO unsafe_insert(double_col) select string_col from unsafe_insert;
---- CATCH
AnalysisException: Unsafe implicit cast is prohibited for non-const expression: string_col
====
---- QUERY
# Mixing unsafe and regular compatibility on column level, unsafe union between 1 and "1"
# regular union between column 'string_col' and "100".
INSERT INTO unsafe_insert(int_col, string_col) select 1, string_col from unsafe_insert union select "1", "100";
====
---- QUERY
# Regression test for expression substitution on unsafe casts.
INSERT INTO unsafe_insert(int_col, string_col) select "1", "1" from unsafe_insert union select 1, "1";
====