/** * Read the table metadata from a data path. This assumes certain hierarchy of files which should * be changed once a better way is figured out to pass in the hoodie meta directory */ protected static HoodieTableMetaClient getTableMetaClient(FileSystem fs, Path dataPath) { int levels = HoodieHiveUtil.DEFAULT_LEVELS_TO_BASEPATH; if (HoodiePartitionMetadata.hasPartitionMetadata(fs, dataPath)) { HoodiePartitionMetadata metadata = new HoodiePartitionMetadata(fs, dataPath); metadata.readFromFS(); levels = metadata.getPartitionDepth(); } Path baseDir = HoodieHiveUtil.getNthParent(dataPath, levels); LOG.info("Reading hoodie metadata from path " + baseDir.toString()); return new HoodieTableMetaClient(fs.getConf(), baseDir.toString()); } }
if (HoodiePartitionMetadata.hasPartitionMetadata(fs, folder)) { HoodiePartitionMetadata metadata = new HoodiePartitionMetadata(fs, folder); metadata.readFromFS(); baseDir = HoodieHiveUtil.getNthParent(folder, metadata.getPartitionDepth()); } else {
/** * Ensure presence of partition meta-data at known depth * * @param partitionPaths Partition paths to check * @param fs File System * @throws IOException in case of error */ void assertPartitionMetadata(String[] partitionPaths, FileSystem fs) throws IOException { for (String partitionPath : partitionPaths) { assertTrue(HoodiePartitionMetadata.hasPartitionMetadata(fs, new Path(basePath, partitionPath))); HoodiePartitionMetadata pmeta = new HoodiePartitionMetadata(fs, new Path(basePath, partitionPath)); pmeta.readFromFS(); assertEquals(DEFAULT_PARTITION_DEPTH, pmeta.getPartitionDepth()); } }