Github user vdiravka commented on a diff in the pull request: https://github.com/apache/drill/pull/877#discussion_r133143191 --- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetMetadataCache.java --- @@ -452,33 +458,202 @@ public void testMoveCache() throws Exception { @Test public void testMetadataCacheAbsolutePaths() throws Exception { + final String absolutePathsMetadata = "absolute_paths_metadata"; try { test("use dfs_test.tmp"); - final String relative_path_metadata_t1 = RELATIVE_PATHS_METADATA + "/t1"; - final String relative_path_metadata_t2 = RELATIVE_PATHS_METADATA + "/t2"; - test("create table `%s` as select * from cp.`tpch/nation.parquet`", relative_path_metadata_t1); - test("create table `%s` as select * from cp.`tpch/nation.parquet`", relative_path_metadata_t2); + // creating two inner directories to leverage METADATA_DIRECTORIES_FILENAME metadata file as well + final String absolutePathsMetadataT1 = absolutePathsMetadata + "/t1"; + final String absolutePathsMetadataT2 = absolutePathsMetadata + "/t2"; + test("create table `%s` as select * from cp.`tpch/nation.parquet`", absolutePathsMetadataT1); + test("create table `%s` as select * from cp.`tpch/nation.parquet`", absolutePathsMetadataT2); copyMetaDataCacheToTempReplacingInternalPaths("parquet/metadata_with_absolute_path/" + - "metadata_directories_with_absolute_paths.requires_replace.txt", RELATIVE_PATHS_METADATA, Metadata.METADATA_DIRECTORIES_FILENAME); + "metadata_directories_with_absolute_paths.requires_replace.txt", absolutePathsMetadata, Metadata.METADATA_DIRECTORIES_FILENAME); copyMetaDataCacheToTempReplacingInternalPaths("parquet/metadata_with_absolute_path/" + - "metadata_table_with_absolute_paths.requires_replace.txt", RELATIVE_PATHS_METADATA, Metadata.METADATA_FILENAME); + "metadata_table_with_absolute_paths.requires_replace.txt", absolutePathsMetadata, Metadata.METADATA_FILENAME); copyMetaDataCacheToTempReplacingInternalPaths("parquet/metadata_with_absolute_path/" + - "metadata_table_with_absolute_paths_t1.requires_replace.txt", relative_path_metadata_t1, Metadata.METADATA_FILENAME); + "metadata_table_with_absolute_paths_t1.requires_replace.txt", absolutePathsMetadataT1, Metadata.METADATA_FILENAME); copyMetaDataCacheToTempReplacingInternalPaths("parquet/metadata_with_absolute_path/" + - "metadata_table_with_absolute_paths_t2.requires_replace.txt", relative_path_metadata_t2, Metadata.METADATA_FILENAME); + "metadata_table_with_absolute_paths_t2.requires_replace.txt", absolutePathsMetadataT2, Metadata.METADATA_FILENAME); + String query = String.format("select * from %s", absolutePathsMetadata); + int expectedRowCount = 50; + int expectedNumFiles = 1; // point to selectionRoot since no pruning is done in this query + int actualRowCount = testSql(query); + assertEquals("An incorrect result was obtained while querying a table with metadata cache files", + expectedRowCount, actualRowCount); + String numFilesPattern = "numFiles=" + expectedNumFiles; + String usedMetaPattern = "usedMetadataFile=true"; + String cacheFileRootPattern = String.format("cacheFileRoot=%s/%s", getDfsTestTmpSchemaLocation(), absolutePathsMetadata); + PlanTestBase.testPlanMatchingPatterns(query, new String[]{numFilesPattern, usedMetaPattern, cacheFileRootPattern}, + new String[] {"Filter"}); + } finally { + test("drop table if exists %s", absolutePathsMetadata); + } + } - int rowCount = testSql(String.format("select * from %s", RELATIVE_PATHS_METADATA)); - assertEquals("An incorrect result was obtained while querying a table with metadata cache files", 50, rowCount); + @Test + public void testSpacesInMetadataCachePath() throws Exception { + final String pathWithSpaces = "path with spaces"; + try { + test("use dfs_test.tmp"); + // creating multilevel table to store path with spaces in both metadata files (METADATA and METADATA_DIRECTORIES) + test("create table `%s` as select * from cp.`tpch/nation.parquet`", pathWithSpaces); + test("create table `%1$s/%1$s` as select * from cp.`tpch/nation.parquet`", pathWithSpaces); + test("refresh table metadata `%s`", pathWithSpaces); + checkForMetadataFile(pathWithSpaces); + String query = String.format("select * from `%s`", pathWithSpaces); + int expectedRowCount = 50; + int expectedNumFiles = 1; // point to selectionRoot since no pruning is done in this query + int actualRowCount = testSql(query); + assertEquals("An incorrect result was obtained while querying a table with metadata cache files", + expectedRowCount, actualRowCount); + String numFilesPattern = "numFiles=" + expectedNumFiles; + String usedMetaPattern = "usedMetadataFile=true"; + String cacheFileRootPattern = String.format("cacheFileRoot=%s/%s", getDfsTestTmpSchemaLocation(), pathWithSpaces); + PlanTestBase.testPlanMatchingPatterns(query, new String[]{numFilesPattern, usedMetaPattern, cacheFileRootPattern}, + new String[] {"Filter"}); + } finally { + test("drop table if exists `%s`", pathWithSpaces); + } + } + + @Test + public void testFutureUnsupportedMetadataVersion() throws Exception { + final String unsupportedMetadataVersion = "unsupported_metadata_version"; + try { + test("use dfs_test.tmp"); + test("create table `%s` as select * from cp.`tpch/nation.parquet`", unsupportedMetadataVersion); + MetadataVersion lastVersion = MetadataVersion.Constants.SUPPORTED_VERSIONS.last(); + // Get the future version, which is absent in MetadataVersions.SUPPORTED_VERSIONS set + String futureVersion = new MetadataVersion(lastVersion.getMajor() + 1, 0).toString(); + copyMetaDataCacheToTempWithReplacements("parquet/unsupported_metadata/unsupported_metadata_version.requires_replace.txt", + unsupportedMetadataVersion, Metadata.METADATA_FILENAME, futureVersion); + String query = String.format("select * from %s", unsupportedMetadataVersion); + int expectedRowCount = 25; + int expectedNumFiles = 1; + int actualRowCount = testSql(query); + assertEquals("An incorrect result was obtained while querying a table with metadata cache files", + expectedRowCount, actualRowCount); + String numFilesPattern = "numFiles=" + expectedNumFiles; + String usedMetaPattern = "usedMetadataFile=false"; // ignoring metadata cache file + PlanTestBase.testPlanMatchingPatterns(query, new String[]{numFilesPattern, usedMetaPattern}, + new String[] {"Filter"}); + } finally { + test("drop table if exists %s", unsupportedMetadataVersion); + } + } + + @Test + public void testCorruptedMetadataFile() throws Exception { + final String corruptedMetadata = "corrupted_metadata"; + try { + test("use dfs_test.tmp"); + test("create table `%s` as select * from cp.`tpch/nation.parquet`", corruptedMetadata); + copyMetaDataCacheToTempReplacingInternalPaths("parquet/unsupported_metadata/" + + "corrupted_metadata.requires_replace.txt", corruptedMetadata, Metadata.METADATA_FILENAME); + String query = String.format("select * from %s", corruptedMetadata); + int expectedRowCount = 25; + int expectedNumFiles = 1; + int actualRowCount = testSql(query); + assertEquals("An incorrect result was obtained while querying a table with metadata cache files", + expectedRowCount, actualRowCount); + String numFilesPattern = "numFiles=" + expectedNumFiles; + String usedMetaPattern = "usedMetadataFile=false"; // ignoring metadata cache file + PlanTestBase.testPlanMatchingPatterns(query, new String[]{numFilesPattern, usedMetaPattern}, + new String[] {"Filter"}); + } finally { + test("drop table if exists %s", corruptedMetadata); + } + } + + @Test + public void testEmptyMetadataFile() throws Exception { + final String emptyMetadataFile = "empty_metadata_file"; + try { + test("use dfs_test.tmp"); + test("create table `%s` as select * from cp.`tpch/nation.parquet`", emptyMetadataFile); + copyMetaDataCacheToTempReplacingInternalPaths("parquet/unsupported_metadata/" + + "empty_metadata_file.requires_replace.txt", emptyMetadataFile, Metadata.METADATA_FILENAME); + String query = String.format("select * from %s", emptyMetadataFile); + int expectedRowCount = 25; + int expectedNumFiles = 1; + int actualRowCount = testSql(query); + assertEquals("An incorrect result was obtained while querying a table with metadata cache files", + expectedRowCount, actualRowCount); + String numFilesPattern = "numFiles=" + expectedNumFiles; + String usedMetaPattern = "usedMetadataFile=false"; // ignoring metadata cache file + PlanTestBase.testPlanMatchingPatterns(query, new String[]{numFilesPattern, usedMetaPattern}, + new String[] {"Filter"}); + } finally { + test("drop table if exists %s", emptyMetadataFile); + } + } + + @Test + public void testRootMetadataFileIsAbsent() throws Exception { + try { --- End diff -- Created local tables in these two tests. Done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---