Skip to content

Commit 770e70c

Browse files
authored
HIVE-29297: The directory of the direct insert manifest files should be hidden from read queries (#6160)
1 parent 388e806 commit 770e70c

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,10 +1052,25 @@ public static Path toTaskTempPath(Path orig) {
10521052
}
10531053

10541054
public static Path toTempPath(Path orig) {
1055-
if (orig.getName().indexOf(tmpPrefix) == 0) {
1055+
return toTempPath(orig, tmpPrefix);
1056+
}
1057+
1058+
private static Path toTempPath(Path orig, String prefix) {
1059+
if (orig.getName().indexOf(prefix) == 0) {
10561060
return orig;
10571061
}
1058-
return new Path(orig.getParent(), tmpPrefix + orig.getName());
1062+
return new Path(orig.getParent(), prefix + orig.getName());
1063+
}
1064+
1065+
/**
1066+
* This method is to convert a path into a temporary path for the direct insert manifest files.
1067+
* It is important to use a prefix which starts with '_', like '_tmp.', so the content of this
1068+
* directory would be filtered out by the AcidUtils.acidHiddenFileFilter.
1069+
* @param orig
1070+
* @return
1071+
*/
1072+
public static Path toManifestDirTempPath(String orig) {
1073+
return toTempPath(new Path(orig), hadoopTmpPrefix);
10591074
}
10601075

10611076
/**
@@ -4564,7 +4579,7 @@ private static Path getManifestDir(Path specPath, long writeId, int stmtId, Stri
45644579
if (isDelete) {
45654580
deltaDir = AcidUtils.deleteDeltaSubdir(writeId, writeId, stmtId);
45664581
}
4567-
Path manifestPath = new Path(manifestRoot, Utilities.toTempPath(deltaDir));
4582+
Path manifestPath = new Path(manifestRoot, Utilities.toManifestDirTempPath(deltaDir));
45684583

45694584
if (isInsertOverwrite) {
45704585
// When doing a multi-statement insert overwrite query with dynamic partitioning, the

ql/src/test/org/apache/hadoop/hive/ql/exec/TestUtilities.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
import org.apache.hadoop.conf.Configuration;
5252
import org.apache.hadoop.fs.FileStatus;
5353
import org.apache.hadoop.fs.FileSystem;
54+
import org.apache.hadoop.fs.LocatedFileStatus;
5455
import org.apache.hadoop.fs.Path;
56+
import org.apache.hadoop.fs.RemoteIterator;
5557
import org.apache.hadoop.fs.permission.FsPermission;
5658
import org.apache.hadoop.hive.common.type.Timestamp;
5759
import org.apache.hadoop.hive.conf.HiveConf;
@@ -836,6 +838,38 @@ public void testSetPermissionsOnExistingDir() throws IOException {
836838
Assert.assertEquals((short) 0777, fs.getFileStatus(path).getPermission().toShort());
837839
}
838840

841+
@Test
842+
public void testWritingManifestFile() throws HiveException, IOException {
843+
String testTableName = "testWritingManifest";
844+
JobConf jobConf = new JobConf();
845+
FileSystem fs = FileSystem.getLocal(jobConf);
846+
Path testTablePath = new Path(HiveConf.getVar(jobConf, HiveConf.ConfVars.LOCAL_SCRATCH_DIR) + "/" + testTableName);
847+
try {
848+
fs.mkdirs(testTablePath);
849+
List<Path> commitPaths = new ArrayList<>();
850+
commitPaths.add(new Path(testTableName + "/delta00001_00001/00000_0"));
851+
Utilities.writeCommitManifest(commitPaths, testTablePath, fs,
852+
"00001", 2L, 0, null, false,
853+
false, null, null, false);
854+
855+
RemoteIterator<LocatedFileStatus> it = fs.listFiles(testTablePath, true);
856+
List<Path> resultPaths = new ArrayList<>();
857+
while(it.hasNext()) {
858+
resultPaths.add(it.next().getPath());
859+
}
860+
assertEquals(1, resultPaths.size());
861+
Path resultPath = resultPaths.get(0);
862+
assertEquals("00001.manifest", resultPath.getName());
863+
assertEquals("_tmp.delta_0000002_0000002_0000", resultPath.getParent().getName());
864+
FileStatus[] files = fs.listStatus(testTablePath, AcidUtils.acidHiddenFileFilter);
865+
assertEquals(0, files.length);
866+
} finally {
867+
if (fs.exists(testTablePath)) {
868+
fs.delete(testTablePath, true);
869+
}
870+
}
871+
}
872+
839873
private FileStatus[] generateTestNotEmptyFileStatuses(String... fileNames) {
840874
return generateTestNotEmptyFileStatuses(null, fileNames);
841875
}

0 commit comments

Comments
 (0)