public static List<String> getRefreshPath(final JobId jobId, final JobData jobData, final Path accelerationBasePath) { // extract written path from writer's metadata JobDataFragment data = jobData.range(0, 1); Text text = (Text) Preconditions.checkNotNull(data.extractValue(RecordWriter.PATH_COLUMN, 0), "Empty write path for job %s", jobId.getId()); // relative path to the acceleration base path final String path = PathUtils.relativePath(new Path(text.toString()), accelerationBasePath); // extract first 2 components of the path "<reflection-id>."<modified-materialization-id>" List<String> components = PathUtils.toPathComponents(path); Preconditions.checkState(components.size() >= 2, "Refresh path %s is incomplete", path); return ImmutableList.of(ACCELERATOR_STORAGEPLUGIN_NAME, components.get(0), components.get(1)); }
@Test public void testRelativePath() throws Exception { assertEquals("a", PathUtils.relativePath(new Path("/a"), new Path("/"))); assertEquals("b", PathUtils.relativePath(new Path("/a/b"), new Path("/a"))); assertEquals("b/c.json", PathUtils.relativePath(new Path("/a/b/c.json"), new Path("/a"))); assertEquals("c/d/e", PathUtils.relativePath(new Path("/a/b/c/d/e"), new Path("/a/b"))); assertEquals("/a/b", PathUtils.relativePath(new Path("/a/b"), new Path("/c/d"))); // no common prefix }
if (fileStatus.isDirectory()) { cachedEntities.add(FileSystemCachedEntity.newBuilder() .setPath(PathUtils.relativePath(filePath, rootLocation)) .setLastModificationTime(fileStatus.getModificationTime()) .setIsDir(true) } else if (fileStatus.isFile()) { cachedEntities.add(FileSystemCachedEntity.newBuilder() .setPath(PathUtils.relativePath(filePath, rootLocation)) .setLastModificationTime(fileStatus.getModificationTime()) .setIsDir(false)