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..4e804ba04b 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,13 @@ 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) { + List 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()); diff --git ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java index bd63f5bdea..3c6b6be1ba 100644 --- ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java +++ ql/src/test/org/apache/hadoop/hive/ql/TestTxnNoBuckets.java @@ -178,6 +178,7 @@ public void testNoBuckets() throws Exception { */ @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 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("drop table if exists myctas"); + 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