diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java index 114d455ff8..06ee9394f0 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java @@ -294,8 +294,12 @@ public int execute(DriverContext driverContext) { //'sourcePath' result of 'select ...' part of CTAS statement assert lfd.getIsDfsDir(); FileSystem srcFs = sourcePath.getFileSystem(conf); - List newFiles = new ArrayList<>(); - Hive.moveAcidFiles(srcFs, srcFs.globStatus(sourcePath), targetPath, newFiles); + FileStatus[] srcs = srcFs.globStatus(sourcePath); + if(srcs != null) { + LOG.debug("No files found to move from " + sourcePath + " to " + targetPath); + List newFiles = new ArrayList<>(); + Hive.moveAcidFiles(srcFs, srcs, targetPath, newFiles); + } } else { moveFile(sourcePath, targetPath, lfd.getIsDfsDir()); diff --git ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java index bd63f5bdea..437031c143 100644 --- ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java +++ ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java @@ -221,6 +221,15 @@ public void testCTAS() throws Exception { }; 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("create table myctas stored as ORC as" + + " select a, b from " + Table.NONACIDORCTBL); + List 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