From b82880738cc4078fcf6147e7ce072eda5ea023d8 Mon Sep 17 00:00:00 2001 From: Alex Behm Date: Sun, 13 Oct 2013 22:08:00 -0700 Subject: [PATCH] IMPALA-617: Cast NULLs in INSERT statement due to incomplete permutation list to expected column type. Inserting NULLs with NULL_TYPE into Parquet tables cases a crash. Change-Id: I350c7ee2789c017cee5c4b6a1292c9fae36087f1 Reviewed-on: http://gerrit.ent.cloudera.com:8080/696 Reviewed-by: Marcel Kornacker Tested-by: jenkins --- .../com/cloudera/impala/analysis/InsertStmt.java | 7 +++---- .../queries/QueryTest/insert_permutation.test | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fe/src/main/java/com/cloudera/impala/analysis/InsertStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/InsertStmt.java index a667d70a5..1daceba6d 100644 --- a/fe/src/main/java/com/cloudera/impala/analysis/InsertStmt.java +++ b/fe/src/main/java/com/cloudera/impala/analysis/InsertStmt.java @@ -399,10 +399,9 @@ public class InsertStmt extends StatementBase { // expression. if (!matchFound) { if (tblColumn.getPosition() >= numClusteringCols) { - // Unmentioned non-clustering columns get NULL expressions. Note that we do not - // analyze them, nor do we type-check them, on the assumption that neither is - // necessary. - permutedSelectListExprs.add(new NullLiteral()); + // Unmentioned non-clustering columns get NULL literals with the appropriate + // target type because Parquet cannot handle NULL_TYPE (IMPALA-617). + permutedSelectListExprs.add(new NullLiteral().castTo(tblColumn.getType())); } } } diff --git a/testdata/workloads/functional-query/queries/QueryTest/insert_permutation.test b/testdata/workloads/functional-query/queries/QueryTest/insert_permutation.test index b0af26637..617d86183 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/insert_permutation.test +++ b/testdata/workloads/functional-query/queries/QueryTest/insert_permutation.test @@ -10,6 +10,8 @@ use insert_permutation_test ---- QUERY create table perm_nopart(int_col1 int, string_col string, int_col2 int); create table perm_part(int_col1 int, string_col string) partitioned by (p1 int, p2 string); +create table parquet_part(int_col1 int, string_col string) +partitioned by (p1 int, p2 string) stored as parquetfile; ---- RESULTS ==== ---- QUERY @@ -178,3 +180,17 @@ NULL,'NULL',NULL ---- TYPES INT,STRING,INT ==== +---- QUERY +# Test inserting NULLs due to an incomplete column mapping into a Parquet table. +# Regression test against IMPALA-671. +insert into parquet_part() partition(p1, p2='foo') values(2) +---- RESULTS +p1=2/p2=foo/: 1 +==== +---- QUERY +select * from parquet_part +---- RESULTS +NULL,'NULL',2,'foo' +---- TYPES +INT,STRING,INT,STRING +====