public NamespaceKey(List<String> pathComponents) { checkNotNull(pathComponents); this.pathComponents = ImmutableList.copyOf(pathComponents); this.schemaPath = PathUtils.constructFullPath(pathComponents); }
public NamespacePath(String path) { this(PathUtils.parseFullPath(path)); }
/** * Convert fs path to dotted schema path. * /a/b/c -> a.b.c * @param fsPath filesystem path * @return schema path. */ public static String toDottedPath(Path fsPath) { return constructFullPath(toPathComponents(fsPath)); }
/** * Resolve given table path relative to source resolve it to a valid path in filesystem. * If the resolved path refers to an entity not under the base of the source then a permission error is thrown. * @param tablePath * @return */ public Path resolveTablePathToValidPath(String tablePath) { String relativePathClean = PathUtils.removeLeadingSlash(tablePath); Path combined = new Path(basePath, relativePathClean); PathUtils.verifyNoAccessOutsideBase(basePath, combined); return combined; }
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()); } }
/** * Convert fully or partially dotted path to file system path. * a.b.c -> /a/b/c * a.`b/c` -> /a/b/c * @param path a fully or partially dotted path * @return {@code fs Path} */ public static Path toFSPath(String path) { final List<String> pathComponents = Lists.newArrayList(); for (String component: parseFullPath(path)) { if (component.contains(SLASH)) { pathComponents.addAll(toPathComponents(new Path(component))); } else { pathComponents.add(component); } } return toFSPath(pathComponents); }
public static Map<String, NameSpaceContainer> listFolder(NamespaceService ns, String parent) throws Exception { Map<String, NameSpaceContainer> children = new HashMap<>(); for (NameSpaceContainer container : ns.list(new NamespaceKey(PathUtils.parseFullPath(parent)))) { children.put(PathUtils.constructFullPath(container.getFullPathList()), container); } return children; }
/** * Convert fs path to list of strings. * /a/b/c -> [a,b,c] * @param fsPath filesystem path * @return list of path components */ public static List<String> toPathComponents(Path fsPath) { if (fsPath == null ) { return EMPTY_SCHEMA_PATHS; } return toPathComponents(fsPath.toUri().getPath()); }
/** * Helper method which resolves the table name to actual file/folder on the filesystem. * If the resolved path refers to an entity not under the base of the source then a permission error is thrown. * * Ex. For given source named "dfs" which has base path of "/base" tableSchemaPath * [dfs, tmp, a] -> "/base/tmp/a" * [dfs, "/tmp/b"] -> "/base/tmp/b" * [dfs, "value", tbl] -> "/base/value/tbl" * @param tableSchemaPath * @return */ public List<String> resolveTableNameToValidPath(List<String> tableSchemaPath) { List<String> fullPath = new ArrayList<>(); fullPath.addAll(PathUtils.toPathComponents(basePath)); for (String pathComponent : tableSchemaPath.subList(1 /* need to skip the source name */, tableSchemaPath.size())) { fullPath.add(PathUtils.removeQuotes(pathComponent)); } PathUtils.verifyNoAccessOutsideBase(basePath, PathUtils.toFSPath(fullPath)); return fullPath; }
/** * Convert list of path components into fs path, skip root of path if its same as given root. * schema path : [a,b,c] and root: a -> /b/c * @param schemaPath list of path components * @param root of path to be ignored. * @return {@code fs Path} */ public static Path toFSPathSkipRoot(final List<String> schemaPath, final String root) { if (schemaPath == null || schemaPath.isEmpty()) { return ROOT_PATH; } if (root == null || !root.equals(schemaPath.get(0))) { return toFSPath(schemaPath); } else { return toFSPath(schemaPath.subList(1, schemaPath.size())); } }
final Path fsPath = PathUtils.toFSPath(fullPath); .message("Failed to drop table: %s", PathUtils.constructFullPath(tableSchemaPath)) .build(logger);
/** * Fetches a single item from the filesystem plugin */ public SchemaEntity get(List<String> path, String userName) { try { final FileStatus status = getFS(userName).getFileStatus(PathUtils.toFSPath(resolveTableNameToValidPath(path))); final Set<List<String>> tableNames = Sets.newHashSet(); final NamespaceService ns = context.getNamespaceService(userName); final NamespaceKey folderNSKey = new NamespaceKey(path); if (ns.exists(folderNSKey)) { for(NameSpaceContainer entity : ns.list(folderNSKey)) { if (entity.getType() == Type.DATASET) { tableNames.add(resolveTableNameToValidPath(entity.getDataset().getFullPathList())); } } } List<String> p = PathUtils.toPathComponents(status.getPath()); return getSchemaEntity(status, tableNames, p); } catch (IOException | NamespaceException e) { throw new RuntimeException(e); } }
/** * Remove leading "/"s in the given path string. * @param path * @return */ public static String removeLeadingSlash(String path) { if (path.length() > 0 && path.charAt(0) == '/') { String newPath = path.substring(1); return removeLeadingSlash(newPath); } else { return path; } } }
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)); }
fileSelection = FileSelection.createWithFullSchema(fs, PathUtils.toFSPathString(parentSchemaPath), tableName); if (fileSelection == null) { return null; // no table found } else { final List<String> tableNamePathComponents = PathUtils.parseFullPath(tableName); tableName = tableNamePathComponents.remove(tableNamePathComponents.size() - 1);
List<String> cleanedPathComponents = Lists.newArrayList(); if (rootEntityName.indexOf(PathUtils.getPathDelimiter()) > -1) { final List<String> spacePathComponents = PathUtils.parseFullPath(path.getRoot()); cleanedPathComponents.addAll(spacePathComponents); List<String> pathComponents = path.getPathComponents();
inputValidation.validate(fileName); List<String> pathList = PathUtils.toPathComponents(path); pathList.add(SqlUtils.quoteIdentifier(fileName.getName())); final FilePath filePath = FilePath.fromURLPath(homeName, PathUtils.toFSPathString(pathList));
public String toUrlEncodedString() { return PathUtils.encodeURIComponent(schemaPath); }
public NamespacePath(final List<String> path) { final List<String> pathComponents = new ArrayList<>(path); int length = pathComponents.size(); if (length < getMinimumComponents()) { throw new IllegalArgumentException("path too short: " + PathUtils.getPathJoiner().join(pathComponents)); } if (getMaximumComponents() != -1 && length > getMaximumComponents()) { throw new IllegalArgumentException("path too long: " + PathUtils.getPathJoiner().join(pathComponents)); } this.root = getRoot(pathComponents.remove(0)); --length; if (length > 0) { --length; this.leaf = getLeaf(pathComponents.remove(length)); } else { this.leaf = null; } final List<FolderName> folders = new ArrayList<>(); for (final String folder : pathComponents) { folders.add(new FolderName(folder)); } this.folderPath = Collections.unmodifiableList(folders); this.namespaceKey = new NamespaceKey(path); }
public static Path getPathBasedOnFullPath(List<String> fullPath) { String parent = Joiner.on(PATH_SEPARATOR).join(fullPath.subList(0, fullPath.size() - 1)); if (Strings.isNullOrEmpty(parent)) { parent = "/"; } parent = Path.getPathWithoutSchemeAndAuthority(new Path(Path.SEPARATOR, parent)).toString(); String path = PathUtils.removeQuotes(fullPath.get(fullPath.size() - 1)); return new Path(parent, removeLeadingSlash(path)); }