Skip to content

Commit 0bf67f3

Browse files
committed
test: add testListPartitionNamesIsolationAcrossTables
Signed-off-by: pufan <[email protected]>
1 parent 5044bb3 commit 0bf67f3

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

fe/fe-core/src/test/java/com/starrocks/connector/paimon/PaimonMetadataTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import mockit.MockUp;
7272
import mockit.Mocked;
7373
import org.apache.paimon.CoreOptions;
74+
import org.apache.paimon.catalog.CachingCatalog;
7475
import org.apache.paimon.catalog.Catalog;
7576
import org.apache.paimon.catalog.CatalogContext;
7677
import org.apache.paimon.catalog.CatalogFactory;
@@ -83,6 +84,7 @@
8384
import org.apache.paimon.data.Timestamp;
8485
import org.apache.paimon.fs.Path;
8586
import org.apache.paimon.io.DataFileMeta;
87+
import org.apache.paimon.options.CatalogOptions;
8688
import org.apache.paimon.options.Options;
8789
import org.apache.paimon.partition.Partition;
8890
import org.apache.paimon.predicate.Predicate;
@@ -130,6 +132,7 @@
130132
import java.util.Arrays;
131133
import java.util.Collections;
132134
import java.util.HashMap;
135+
import java.util.LinkedHashMap;
133136
import java.util.List;
134137
import java.util.Map;
135138
import java.util.Optional;
@@ -1013,4 +1016,72 @@ public void testGetTableVersionRange() throws Exception {
10131016
catalog.dropDatabase("test_db", true, true);
10141017
Files.delete(tmpDir);
10151018
}
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+
}
10161087
}

0 commit comments

Comments
 (0)