|
71 | 71 | import mockit.MockUp; |
72 | 72 | import mockit.Mocked; |
73 | 73 | import org.apache.paimon.CoreOptions; |
| 74 | +import org.apache.paimon.catalog.CachingCatalog; |
74 | 75 | import org.apache.paimon.catalog.Catalog; |
75 | 76 | import org.apache.paimon.catalog.CatalogContext; |
76 | 77 | import org.apache.paimon.catalog.CatalogFactory; |
|
83 | 84 | import org.apache.paimon.data.Timestamp; |
84 | 85 | import org.apache.paimon.fs.Path; |
85 | 86 | import org.apache.paimon.io.DataFileMeta; |
| 87 | +import org.apache.paimon.options.CatalogOptions; |
86 | 88 | import org.apache.paimon.options.Options; |
87 | 89 | import org.apache.paimon.partition.Partition; |
88 | 90 | import org.apache.paimon.predicate.Predicate; |
|
130 | 132 | import java.util.Arrays; |
131 | 133 | import java.util.Collections; |
132 | 134 | import java.util.HashMap; |
| 135 | +import java.util.LinkedHashMap; |
133 | 136 | import java.util.List; |
134 | 137 | import java.util.Map; |
135 | 138 | import java.util.Optional; |
@@ -1013,4 +1016,72 @@ public void testGetTableVersionRange() throws Exception { |
1013 | 1016 | catalog.dropDatabase("test_db", true, true); |
1014 | 1017 | Files.delete(tmpDir); |
1015 | 1018 | } |
| 1019 | + |
| 1020 | + @Test |
| 1021 | + public void testListPartitionNamesIsolationAcrossTables(@Mocked FileStoreTable mockPaimonTable1, |
| 1022 | + @Mocked FileStoreTable mockPaimonTable2) |
| 1023 | + throws Catalog.TableNotExistException { |
| 1024 | + |
| 1025 | + Options options = new Options(); |
| 1026 | + options.set(CatalogOptions.CACHE_ENABLED, true); |
| 1027 | + Catalog cachingCatalog = CachingCatalog.tryToCreate(paimonNativeCatalog, options); |
| 1028 | + PaimonMetadata newMetadata = new PaimonMetadata("test_catalog", new HdfsEnvironment(), cachingCatalog, |
| 1029 | + new ConnectorProperties(ConnectorType.PAIMON)); |
| 1030 | + |
| 1031 | + Identifier tblIdentifier1 = new Identifier("db1", "tbl1"); |
| 1032 | + List<String> partitionKeys1 = Lists.newArrayList("year", "month"); |
| 1033 | + Identifier tblIdentifier2 = new Identifier("db2", "tbl2"); |
| 1034 | + List<String> partitionKeys2 = Lists.newArrayList("year", "month"); |
| 1035 | + |
| 1036 | + RowType tblRowType1 = RowType.of(new DataType[] {new IntType(true), new IntType(true)}, new String[] {"year", "month"}); |
| 1037 | + RowType tblRowType2 = RowType.of(new DataType[] {new IntType(true), new IntType(true)}, new String[] {"year", "month"}); |
| 1038 | + |
| 1039 | + org.apache.paimon.partition.Partition db1PaimonPartition1 = |
| 1040 | + new org.apache.paimon.partition.Partition(new LinkedHashMap<String, String>() {{ |
| 1041 | + put("year", "2020"); |
| 1042 | + put("month", "1"); |
| 1043 | + }}, 100L, 2048L, 2L, System.currentTimeMillis(), false); |
| 1044 | + org.apache.paimon.partition.Partition db2PaimonPartition1 = |
| 1045 | + new org.apache.paimon.partition.Partition(new LinkedHashMap<String, String>() {{ |
| 1046 | + put("year", "2021"); |
| 1047 | + put("month", "1"); |
| 1048 | + }}, 100L, 2048L, 2L, System.currentTimeMillis(), false); |
| 1049 | + org.apache.paimon.partition.Partition db2PaimonPartition2 = |
| 1050 | + new org.apache.paimon.partition.Partition(new LinkedHashMap<String, String>() {{ |
| 1051 | + put("year", "2022"); |
| 1052 | + put("month", "1"); |
| 1053 | + }}, 100L, 2048L, 2L, System.currentTimeMillis(), false); |
| 1054 | + |
| 1055 | + new Expectations() { |
| 1056 | + { |
| 1057 | + // Table 1 |
| 1058 | + paimonNativeCatalog.getTable(tblIdentifier1); |
| 1059 | + result = mockPaimonTable1; |
| 1060 | + paimonNativeCatalog.listPartitions(tblIdentifier1); |
| 1061 | + result = Lists.newArrayList(db1PaimonPartition1); |
| 1062 | + mockPaimonTable1.partitionKeys(); |
| 1063 | + result = partitionKeys1; |
| 1064 | + mockPaimonTable1.rowType(); |
| 1065 | + result = tblRowType1; |
| 1066 | + |
| 1067 | + // Table 2 |
| 1068 | + paimonNativeCatalog.getTable(tblIdentifier2); |
| 1069 | + result = mockPaimonTable2; |
| 1070 | + paimonNativeCatalog.listPartitions(tblIdentifier2); |
| 1071 | + result = Lists.newArrayList(db2PaimonPartition1, db2PaimonPartition2); |
| 1072 | + mockPaimonTable2.partitionKeys(); |
| 1073 | + result = partitionKeys2; |
| 1074 | + mockPaimonTable2.rowType(); |
| 1075 | + result = tblRowType2; |
| 1076 | + |
| 1077 | + } |
| 1078 | + }; |
| 1079 | + |
| 1080 | + List<String> result1 = newMetadata.listPartitionNames("db1", "tbl1", null); |
| 1081 | + List<String> result2 = newMetadata.listPartitionNames("db2", "tbl2", null); |
| 1082 | + |
| 1083 | + // Before fix, if the key does not contain "db" and "table", it will return 2. After fix, it will return 3. |
| 1084 | + assertEquals(2, result2.size()); |
| 1085 | + |
| 1086 | + } |
1016 | 1087 | } |
0 commit comments