This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new f19e43f44a [rest] add test case for ListPartitionsPaged WithMultiLevel
(#5745)
f19e43f44a is described below
commit f19e43f44ac055fd6b0b7b4402a5b05341ccdc2f
Author: XiaoHongbo <[email protected]>
AuthorDate: Mon Jun 16 20:45:16 2025 +0800
[rest] add test case for ListPartitionsPaged WithMultiLevel (#5745)
---
.../apache/paimon/partition/PartitionUtils.java | 13 ++++++
.../org/apache/paimon/rest/RESTCatalogServer.java | 3 +-
.../org/apache/paimon/rest/RESTCatalogTest.java | 54 ++++++++++++++++++++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/partition/PartitionUtils.java
b/paimon-core/src/main/java/org/apache/paimon/partition/PartitionUtils.java
index 576c0f09bf..15c7b09601 100644
--- a/paimon-core/src/main/java/org/apache/paimon/partition/PartitionUtils.java
+++ b/paimon-core/src/main/java/org/apache/paimon/partition/PartitionUtils.java
@@ -29,6 +29,8 @@ import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
/** Utils to fetch partition map information from data schema and row type. */
public class PartitionUtils {
@@ -69,4 +71,15 @@ public class PartitionUtils {
public static PartitionInfo create(@Nullable Pair<int[], RowType> pair,
BinaryRow binaryRow) {
return pair == null ? null : new PartitionInfo(pair.getLeft(),
pair.getRight(), binaryRow);
}
+
+ public static String buildPartitionName(Map<String, String> partitionSpec)
{
+ if (partitionSpec.isEmpty()) {
+ return "";
+ }
+ List<String> partitionName =
+ partitionSpec.keySet().stream()
+ .map(key -> key + "=" + partitionSpec.get(key))
+ .collect(Collectors.toList());
+ return String.join("/", partitionName);
+ }
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
index 672426f7d1..739a99d7b0 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java
@@ -41,6 +41,7 @@ import org.apache.paimon.operation.Lock;
import org.apache.paimon.options.Options;
import org.apache.paimon.partition.Partition;
import org.apache.paimon.partition.PartitionStatistics;
+import org.apache.paimon.partition.PartitionUtils;
import org.apache.paimon.rest.auth.AuthProvider;
import org.apache.paimon.rest.auth.RESTAuthParameter;
import org.apache.paimon.rest.requests.AlterDatabaseRequest;
@@ -2100,7 +2101,7 @@ public class RESTCatalogServer {
} else if (entity instanceof GetViewResponse) {
return ((GetViewResponse) entity).getName();
} else if (entity instanceof Partition) {
- return ((Partition) entity).spec().toString().replace("{",
"").replace("}", "");
+ return PartitionUtils.buildPartitionName(((Partition)
entity).spec());
} else {
return entity.toString();
}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
index 4a10a316fc..1f5fc12fdb 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
@@ -1205,6 +1205,60 @@ public abstract class RESTCatalogTest extends
CatalogTestBase {
() -> catalog.listPartitionsPaged(identifier, null, null,
"dt=01%01"));
}
+ @Test
+ public void testListPartitionsPagedWithMultiLevel() throws Exception {
+ if (!supportPartitions()) {
+ return;
+ }
+
+ String databaseName = "partitions_paged_db";
+ Map<String, String> partitionSpec =
+ new HashMap<String, String>() {
+ {
+ put("dt", "20250101");
+ put("col", "0");
+ }
+ };
+
+ Map<String, String> partitionSpec2 =
+ new HashMap<String, String>() {
+ {
+ put("dt", "20250102");
+ put("col", "0");
+ }
+ };
+ List<Map<String, String>> partitionSpecs =
Arrays.asList(partitionSpec, partitionSpec2);
+ catalog.dropDatabase(databaseName, true, true);
+ catalog.createDatabase(databaseName, true);
+ Identifier identifier = Identifier.create(databaseName, "table");
+
+ catalog.createTable(
+ identifier,
+ Schema.newBuilder()
+ .option(METASTORE_PARTITIONED_TABLE.key(), "true")
+ .option(METASTORE_TAG_TO_PARTITION.key(), "dt")
+ .column("col", DataTypes.INT())
+ .column("dt", DataTypes.STRING())
+ .partitionKeys("dt", "col")
+ .build(),
+ true);
+
+ BatchWriteBuilder writeBuilder =
catalog.getTable(identifier).newBatchWriteBuilder();
+ try (BatchTableWrite write = writeBuilder.newWrite();
+ BatchTableCommit commit = writeBuilder.newCommit()) {
+ for (Map<String, String> partition : partitionSpecs) {
+ write.write(GenericRow.of(0,
BinaryString.fromString(partition.get("dt"))));
+ }
+ commit.commit(write.prepareCommit());
+ }
+ PagedList<Partition> pagedPartitions =
+ catalog.listPartitionsPaged(identifier, null, null,
"dt=20250101/col=0");
+ assertPagedPartitions(pagedPartitions, 1, partitionSpecs.get(0));
+
+ pagedPartitions = catalog.listPartitionsPaged(identifier, null, null,
"dt=20250102%");
+ assertPagedPartitions(pagedPartitions, 1, partitionSpecs.get(1));
+ }
+
@Test
void testRefreshFileIO() throws Exception {
this.catalog = newRestCatalogWithDataToken();