public static FileStatus testAndGetResult(final String query, final String testName) throws Exception { final String tableName = format("%s%d", testName, random.nextInt(100000)); final String ctasQuery = format("CREATE TABLE dfs_test.%s STORE AS (type => 'json', prettyPrint => false) WITH SINGLE WRITER AS %s", tableName, query); final Path tableDir = new Path(getDfsTestTmpSchemaLocation(), tableName); test(ctasQuery); // find file final FileStatus fileStatus = localFs.listStatus(tableDir, new GlobFilter("*.json"))[0]; return fileStatus; }
public static GlobFilter getGlobFilter(String suffix) { try { return new GlobFilter(format("*%s", suffix)); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
/** * Copy a directory to a new FS -both paths must be qualified. If * a directory needs to be created, supplied permissions can override * the default values. Existing directories are not touched * @param conf conf file * @param srcDirPath src dir * @param destDirPath dest dir * @param permission permission for the dest directory; null means "default" * @return # of files copies */ public static int copyDirectory(Configuration conf, Path srcDirPath, Path destDirPath, FsPermission permission) throws IOException, BadClusterStateException { FileSystem srcFS = FileSystem.get(srcDirPath.toUri(), conf); FileSystem destFS = FileSystem.get(destDirPath.toUri(), conf); //list all paths in the src. if (!srcFS.exists(srcDirPath)) { throw new FileNotFoundException("Source dir not found " + srcDirPath); } if (!srcFS.isDirectory(srcDirPath)) { throw new FileNotFoundException( "Source dir not a directory " + srcDirPath); } GlobFilter dotFilter = new GlobFilter("[!.]*"); FileStatus[] entries = srcFS.listStatus(srcDirPath, dotFilter); int srcFileCount = entries.length; if (srcFileCount == 0) { return 0; } if (permission == null) { permission = FsPermission.getDirDefault(); } if (!destFS.exists(destDirPath)) { new SliderFileSystem(destFS, conf).createWithPermissions(destDirPath, permission); } Path[] sourcePaths = new Path[srcFileCount]; for (int i = 0; i < srcFileCount; i++) { FileStatus e = entries[i]; Path srcFile = e.getPath(); if (srcFS.isDirectory(srcFile)) { String msg = "Configuration dir " + srcDirPath + " contains a directory " + srcFile; log.warn(msg); throw new IOException(msg); } log.debug("copying src conf file {}", srcFile); sourcePaths[i] = srcFile; } log.debug("Copying {} files from {} to dest {}", srcFileCount, srcDirPath, destDirPath); FileUtil.copy(srcFS, sourcePaths, destFS, destDirPath, false, true, conf); return srcFileCount; }
/** * Creates a list-status executor. * * @param path the directory to retrieve the status of its contents. * @param filter glob filter to use. * * @throws IOException thrown if the filter expression is incorrect. */ public FSListStatus(String path, String filter) throws IOException { this.path = new Path(path); this.filter = (filter == null) ? this : new GlobFilter(filter); }
/** * Creates a list-status executor. * * @param path * the directory to retrieve the status of its contents. * @param filter * glob filter to use. * @throws IOException * thrown if the filter expression is incorrect. */ public FSListStatus(String path, String filter) throws IOException { this.path = new Path(path); this.filter = (filter == null) ? this : new GlobFilter(filter); }