private static List<String> relativePath(List<String> tableSchemaPath, Path rootPath) { List<String> rootPathComponents = PathUtils.toPathComponents(rootPath); List<String> tablePathComponents = PathUtils.toPathComponents(PathUtils.toFSPathSkipRoot(tableSchemaPath, null)); return tablePathComponents.subList(rootPathComponents.size(), tablePathComponents.size()); } }
@Test public void testToFSPathSkipRoot() throws Exception { assertEquals(new Path("/b/c"), PathUtils.toFSPathSkipRoot(Arrays.asList("a", "b", "c"), "a")); assertEquals(new Path("/a/b/c"), PathUtils.toFSPathSkipRoot(Arrays.asList("a", "b", "c"), "z")); assertEquals(new Path("/a/b/c"), PathUtils.toFSPathSkipRoot(Arrays.asList("a", "b", "c"), null)); assertEquals(new Path("/"), PathUtils.toFSPathSkipRoot(null, "a")); assertEquals(new Path("/"), PathUtils.toFSPathSkipRoot(Collections.<String>emptyList(), "a")); }