You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2023/08/23 00:27:07 UTC

[impala] branch master updated: IMPALA-12386: Fix clone constructor in CastExpr

This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new c5ecd8e66 IMPALA-12386: Fix clone constructor in CastExpr
c5ecd8e66 is described below

commit c5ecd8e666e6dbdeba4fd9d25acb222eceaa240a
Author: Peter Rozsa <pr...@cloudera.com>
AuthorDate: Mon Aug 21 09:46:24 2023 +0200

    IMPALA-12386: Fix clone constructor in CastExpr
    
    This commit addresses an issue in the CastExpr class where the clone
    constructor was not properly preserving compatibility settings. The
    clone constructor assigned the default compatibility regardless of the
    source expression, causing substitution errors for partitioned tables.
    
    Example:
      'insert into unsafe_insert_partitioned(int_col, string_col)
       values("1", null), (null, "1")'
    Throws:
      ERROR: IllegalStateException: Failed analysis after expr substitution.
      CAUSED BY: IllegalStateException: cast STRING to INT
    
    Tests:
      - new test case added to insert-unsafe.test
    
    Change-Id: Iff64ce02539651fcb3a90db678f74467f582648f
    Reviewed-on: http://gerrit.cloudera.org:8080/20385
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 fe/src/main/java/org/apache/impala/analysis/CastExpr.java             | 2 +-
 .../workloads/functional-query/queries/QueryTest/insert-unsafe.test   | 4 ++++
 tests/query_test/test_insert.py                                       | 3 +++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/fe/src/main/java/org/apache/impala/analysis/CastExpr.java b/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
index 909f3bedd..400d4d399 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CastExpr.java
@@ -123,7 +123,7 @@ public class CastExpr extends Expr {
     isImplicit_ = other.isImplicit_;
     noOp_ = other.noOp_;
     castFormat_ = other.castFormat_;
-    compatibility_ = TypeCompatibility.DEFAULT;
+    compatibility_ = other.compatibility_;
   }
 
   private static String getFnName(Type targetType) {
diff --git a/testdata/workloads/functional-query/queries/QueryTest/insert-unsafe.test b/testdata/workloads/functional-query/queries/QueryTest/insert-unsafe.test
index 0b258fc3c..e8aba55b2 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/insert-unsafe.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/insert-unsafe.test
@@ -222,4 +222,8 @@ INSERT INTO unsafe_insert(int_col, string_col) select 1, string_col from unsafe_
 ---- 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";
+====
+---- QUERY
+# Regression test for expression substitution on unsafe casts with partitioned tables.
+INSERT INTO unsafe_insert_partitioned(int_col, string_col)  values("1", null), (null, "1");
 ====
\ No newline at end of file
diff --git a/tests/query_test/test_insert.py b/tests/query_test/test_insert.py
index c3cb270b2..4d87fd9cb 100644
--- a/tests/query_test/test_insert.py
+++ b/tests/query_test/test_insert.py
@@ -555,6 +555,9 @@ class TestUnsafeImplicitCasts(ImpalaTestSuite):
       double_col double, decimal_col decimal, timestamp_col timestamp, date_col date,
       string_col string, varchar_col varchar(100), char_col char(100),
       bool_col boolean, binary_col binary)""".format(unique_database)
+    create_partitioned_stmt = """create table {0}.unsafe_insert_partitioned(int_col int,
+      tinyint_col tinyint) partitioned by(string_col string)""".format(unique_database)
     self.client.execute(create_stmt)
+    self.client.execute(create_partitioned_stmt)
     vector.get_value('exec_option')['allow_unsafe_casts'] = "true"
     self.run_test_case('QueryTest/insert-unsafe', vector, unique_database)