Repository: hive Updated Branches: refs/heads/master 464a3f61a -> c2e335fc0
HIVE-18606 CTAS on empty table throws NPE from org.apache.hadoop.hive.ql.exec.MoveTask (Eugene Koifman, reviewed by Sergey Shelukhin) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/c2e335fc Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/c2e335fc Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/c2e335fc Branch: refs/heads/master Commit: c2e335fc0b4a8144d8d93ff10e9191432ae6547e Parents: 464a3f6 Author: Eugene Koifman <[email protected]> Authored: Fri Feb 2 12:14:36 2018 -0800 Committer: Eugene Koifman <[email protected]> Committed: Fri Feb 2 12:14:36 2018 -0800 ---------------------------------------------------------------------- ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java | 9 +++++++-- .../test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/c2e335fc/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java index 114d455..4e804ba 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java @@ -294,8 +294,13 @@ public class MoveTask extends Task<MoveWork> implements Serializable { //'sourcePath' result of 'select ...' part of CTAS statement assert lfd.getIsDfsDir(); FileSystem srcFs = sourcePath.getFileSystem(conf); - List<Path> newFiles = new ArrayList<>(); - Hive.moveAcidFiles(srcFs, srcFs.globStatus(sourcePath), targetPath, newFiles); + FileStatus[] srcs = srcFs.globStatus(sourcePath); + if(srcs != null) { + List<Path> newFiles = new ArrayList<>(); + Hive.moveAcidFiles(srcFs, srcs, targetPath, newFiles); + } else { + LOG.debug("No files found to move from " + sourcePath + " to " + targetPath); + } } else { moveFile(sourcePath, targetPath, lfd.getIsDfsDir()); http://git-wip-us.apache.org/repos/asf/hive/blob/c2e335fc/ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java b/ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java index bd63f5b..3c6b6be 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java @@ -178,6 +178,7 @@ public class TestTxnNoBuckets extends TxnCommandsBaseForTests { */ @Test public void testCTAS() throws Exception { + runStatementOnDriver("drop table if exists myctas"); int[][] values = {{1,2},{3,4}}; runStatementOnDriver("insert into " + Table.NONACIDORCTBL + makeValuesClause(values)); runStatementOnDriver("create table myctas stored as ORC TBLPROPERTIES ('transactional" + @@ -221,6 +222,16 @@ public class TestTxnNoBuckets extends TxnCommandsBaseForTests { }; checkExpected(rs, expected4, "Unexpected row count after ctas from union distinct query"); } + @Test + public void testCtasEmpty() throws Exception { + MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true); + runStatementOnDriver("drop table if exists myctas"); + runStatementOnDriver("create table myctas stored as ORC as" + + " select a, b from " + Table.NONACIDORCTBL); + List<String> rs = runStatementOnDriver("select ROW__ID, a, b, INPUT__FILE__NAME" + + " from myctas order by ROW__ID"); + } + /** * Insert into unbucketed acid table from union all query * Union All is flattend so nested subdirs are created and acid move drops them since
