Index: ql/src/test/results/clientpositive/null_column.q.out =================================================================== --- ql/src/test/results/clientpositive/null_column.q.out (revision 0) +++ ql/src/test/results/clientpositive/null_column.q.out (revision 0) @@ -0,0 +1,52 @@ +query: drop table temp_null +query: drop table tt +query: drop table tt_b +query: create table temp_null(a int) stored as textfile +query: load data local inpath '../data/files/test.dat' overwrite into table temp_null +query: select null, null from temp_null +Input: default/temp_null +Output: file:/data/users/nzhang/work/734/734-trunk-apache-hive/build/ql/tmp/2083094836/10000 +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +query: create table tt(a int, b string) +query: insert overwrite table tt select null, null from temp_null +Input: default/temp_null +Output: default/tt +query: select * from tt +Input: default/tt +Output: file:/data/users/nzhang/work/734/734-trunk-apache-hive/build/ql/tmp/2090243542/10000 +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +query: create table tt_b(a int, b string) row format serde "org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe" +query: insert overwrite table tt_b select null, null from temp_null +Input: default/temp_null +Output: default/tt_b +query: select * from tt_b +Input: default/tt_b +Output: file:/data/users/nzhang/work/734/734-trunk-apache-hive/build/ql/tmp/1191541403/10000 +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +NULL NULL +query: insert overwrite directory "../build/ql/test/data/warehouse/null_columns.out" select null, null from temp_null +Input: default/temp_null +Output: ../build/ql/test/data/warehouse/null_columns.out +\N\N +\N\N +\N\N +\N\N +\N\N +\N\N +query: drop table tt +query: drop table tt_b +query: drop table temp_null Index: ql/src/test/queries/clientpositive/null_column.q =================================================================== --- ql/src/test/queries/clientpositive/null_column.q (revision 0) +++ ql/src/test/queries/clientpositive/null_column.q (revision 0) @@ -0,0 +1,23 @@ +drop table temp_null; +drop table tt; +drop table tt_b; + +create table temp_null(a int) stored as textfile; +load data local inpath '../data/files/test.dat' overwrite into table temp_null; + +select null, null from temp_null; + +create table tt(a int, b string); +insert overwrite table tt select null, null from temp_null; +select * from tt; + +create table tt_b(a int, b string) row format serde "org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe"; +insert overwrite table tt_b select null, null from temp_null; +select * from tt_b; + +insert overwrite directory "../build/ql/test/data/warehouse/null_columns.out" select null, null from temp_null; +dfs -cat ../build/ql/test/data/warehouse/null_columns.out/*; + +drop table tt; +drop table tt_b; +drop table temp_null; Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 803206) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -128,6 +128,8 @@ import org.apache.hadoop.hive.ql.hooks.ReadEntity; import org.apache.hadoop.hive.ql.hooks.WriteEntity; +import org.apache.hadoop.hive.serde.Constants; + /** * Implementation of the semantic analyzer */ @@ -2525,7 +2527,21 @@ first = false; cols = cols.concat(colInfo.getInternalName()); - colTypes = colTypes.concat(colInfo.getType().getTypeName()); + + // Replace VOID type with string when the output is a temp table or local files. + // A VOID type can be generated under the query: + // + // select NULL from tt; + // or + // insert overwrite local directory "abc" select NULL from tt; + // + // where there is no column type to which the NULL value should be converted. + // + String tName = colInfo.getType().getTypeName(); + if ( tName.equals(Constants.VOID_TYPE_NAME) ) + colTypes = colTypes.concat(Constants.STRING_TYPE_NAME); + else + colTypes = colTypes.concat(tName); } if (!ctx.isMRTmpFileURI(destStr)) {