Skip to content

Commit d538997

Browse files
authored
[rest] Add tagNamePrefix definition for listTagsPaged (#6947)
1 parent 9ed304b commit d538997

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

docs/static/rest-catalog-open-api.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,11 @@ paths:
11471147
in: query
11481148
schema:
11491149
type: string
1150+
- name: tagNamePrefix
1151+
description: A prefix for tag names. All tags will be returned if not set or empty.
1152+
in: query
1153+
schema:
1154+
type: string
11501155
responses:
11511156
"200":
11521157
description: OK

paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public class RESTApi {
147147
public static final String VIEW_NAME_PATTERN = "viewNamePattern";
148148
public static final String FUNCTION_NAME_PATTERN = "functionNamePattern";
149149
public static final String PARTITION_NAME_PATTERN = "partitionNamePattern";
150+
public static final String TAG_NAME_PREFIX = "tagNamePrefix";
150151

151152
public static final long TOKEN_EXPIRATION_SAFE_TIME_MILLIS = 3_600_000L;
152153

@@ -917,18 +918,23 @@ public void createTag(
917918
* max results.
918919
* @param pageToken Optional parameter indicating the next page token allows list to be start
919920
* from a specific point.
921+
* @param tagNamePrefix A prefix for tag names. All tags will be returned if not set or empty.
920922
* @return {@link PagedList}: elements and nextPageToken.
921923
* @throws NoSuchResourceException Exception thrown on HTTP 404 means the table not exists
922924
* @throws ForbiddenException Exception thrown on HTTP 403 means don't have the permission for
923925
* this table
924926
*/
925927
public PagedList<String> listTagsPaged(
926-
Identifier identifier, @Nullable Integer maxResults, @Nullable String pageToken) {
928+
Identifier identifier,
929+
@Nullable Integer maxResults,
930+
@Nullable String pageToken,
931+
@Nullable String tagNamePrefix) {
927932
ListTagsResponse response =
928933
client.get(
929934
resourcePaths.tags(
930935
identifier.getDatabaseName(), identifier.getObjectName()),
931-
buildPagedQueryParams(maxResults, pageToken),
936+
buildPagedQueryParams(
937+
maxResults, pageToken, Pair.of(TAG_NAME_PREFIX, tagNamePrefix)),
932938
ListTagsResponse.class,
933939
restAuthFunction);
934940
List<String> tags = response.tags();

paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,10 @@ public void createTag(
521521

522522
@Override
523523
public PagedList<String> listTagsPaged(
524-
Identifier identifier, @Nullable Integer maxResults, @Nullable String pageToken)
524+
Identifier identifier,
525+
@Nullable Integer maxResults,
526+
@Nullable String pageToken,
527+
@Nullable String tagNamePrefix)
525528
throws TableNotExistException {
526529
throw new UnsupportedOperationException();
527530
}

paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ default boolean supportsListTableByType() {
631631
* <li>{@link #listBranches(Identifier)}.
632632
* <li>{@link #getTag(Identifier, String)}.
633633
* <li>{@link #createTag(Identifier, String, Long, String, boolean)}.
634-
* <li>{@link #listTagsPaged(Identifier, Integer, String)}.
634+
* <li>{@link #listTagsPaged(Identifier, Integer, String, String)}.
635635
* <li>{@link #deleteTag(Identifier, String)}.
636636
* </ul>
637637
*/
@@ -830,6 +830,7 @@ void createTag(
830830
* max results.
831831
* @param pageToken Optional parameter indicating the next page token allows list to be start
832832
* from a specific point.
833+
* @param tagNamePrefix A prefix for tag names. All tags will be returned if not set or empty.
833834
* @return a list of the names of tags with provided page size in this table and next page
834835
* token, or a list of the names of all tags in this table if the catalog does not {@link
835836
* #supportsListObjectsPaged()}.
@@ -838,7 +839,10 @@ void createTag(
838839
* #supportsVersionManagement()} or it does not {@link #supportsListByPattern()}
839840
*/
840841
PagedList<String> listTagsPaged(
841-
Identifier identifier, @Nullable Integer maxResults, @Nullable String pageToken)
842+
Identifier identifier,
843+
@Nullable Integer maxResults,
844+
@Nullable String pageToken,
845+
@Nullable String tagNamePrefix)
842846
throws TableNotExistException;
843847

844848
/**

paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ public void createTag(
252252

253253
@Override
254254
public PagedList<String> listTagsPaged(
255-
Identifier identifier, @Nullable Integer maxResults, @Nullable String pageToken)
255+
Identifier identifier,
256+
@Nullable Integer maxResults,
257+
@Nullable String pageToken,
258+
@Nullable String tagNamePrefix)
256259
throws TableNotExistException {
257-
return wrapped.listTagsPaged(identifier, maxResults, pageToken);
260+
return wrapped.listTagsPaged(identifier, maxResults, pageToken, tagNamePrefix);
258261
}
259262

260263
@Override

paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,10 +1053,13 @@ public void createTag(
10531053
*/
10541054
@Override
10551055
public PagedList<String> listTagsPaged(
1056-
Identifier identifier, @Nullable Integer maxResults, @Nullable String pageToken)
1056+
Identifier identifier,
1057+
@Nullable Integer maxResults,
1058+
@Nullable String pageToken,
1059+
@Nullable String tagNamePrefix)
10571060
throws TableNotExistException {
10581061
try {
1059-
return api.listTagsPaged(identifier, maxResults, pageToken);
1062+
return api.listTagsPaged(identifier, maxResults, pageToken, tagNamePrefix);
10601063
} catch (NoSuchResourceException e) {
10611064
throw new TableNotExistException(identifier);
10621065
} catch (ForbiddenException e) {

paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
import static org.apache.paimon.rest.RESTApi.PARTITION_NAME_PATTERN;
154154
import static org.apache.paimon.rest.RESTApi.TABLE_NAME_PATTERN;
155155
import static org.apache.paimon.rest.RESTApi.TABLE_TYPE;
156+
import static org.apache.paimon.rest.RESTApi.TAG_NAME_PREFIX;
156157
import static org.apache.paimon.rest.RESTApi.VIEW_NAME_PATTERN;
157158
import static org.apache.paimon.rest.ResourcePaths.FUNCTIONS;
158159
import static org.apache.paimon.rest.ResourcePaths.FUNCTION_DETAILS;
@@ -1736,6 +1737,16 @@ private MockResponse tagApiHandle(
17361737
// GET /v1/{prefix}/databases/{database}/tables/{table}/tags
17371738
// Page list tags
17381739
List<String> tags = new ArrayList<>(tagManager.allTagNames());
1740+
1741+
// Filter by tagNamePrefix if provided
1742+
String tagNamePrefix = parameters.get(TAG_NAME_PREFIX);
1743+
if (StringUtils.isNotEmpty(tagNamePrefix)) {
1744+
tags =
1745+
tags.stream()
1746+
.filter(tag -> matchNamePattern(tag, tagNamePrefix))
1747+
.collect(Collectors.toList());
1748+
}
1749+
17391750
if (tags.isEmpty()) {
17401751
response = new ListTagsResponse(Collections.emptyList(), null);
17411752
return mockResponse(response, 200);

paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,15 +1966,20 @@ void testTags() throws Exception {
19661966
SnapshotNotExistException.class,
19671967
() -> restCatalog.createTag(identifier, "my_tag_v3", 99999L, null, false));
19681968

1969-
// Test listTags
1970-
PagedList<String> tags = restCatalog.listTagsPaged(identifier, null, "my_tag");
1969+
// Test listTags for pageToken
1970+
PagedList<String> tags = restCatalog.listTagsPaged(identifier, 1, null, null);
1971+
tags = restCatalog.listTagsPaged(identifier, 1, tags.getNextPageToken(), null);
19711972
assertThat(tags.getElements()).containsExactlyInAnyOrder("my_tag_v2");
1972-
tags = restCatalog.listTagsPaged(identifier, null, null);
1973+
tags = restCatalog.listTagsPaged(identifier, null, null, null);
19731974
assertThat(tags.getElements()).containsExactlyInAnyOrder("my_tag", "my_tag_v2");
19741975

1976+
// Test listTags for tagNamePrefix
1977+
tags = restCatalog.listTagsPaged(identifier, 1, null, "my_tag_v2");
1978+
assertThat(tags.getElements()).containsExactlyInAnyOrder("my_tag_v2");
1979+
19751980
// Test deleteTag
19761981
restCatalog.deleteTag(identifier, "my_tag");
1977-
tags = restCatalog.listTagsPaged(identifier, null, null);
1982+
tags = restCatalog.listTagsPaged(identifier, null, null, null);
19781983
assertThat(tags.getElements()).containsExactlyInAnyOrder("my_tag_v2");
19791984

19801985
// Test deleteTag with non-existent tag
@@ -1988,7 +1993,7 @@ void testTags() throws Exception {
19881993

19891994
// Delete remaining tag
19901995
restCatalog.deleteTag(identifier, "my_tag_v2");
1991-
tags = restCatalog.listTagsPaged(identifier, null, null);
1996+
tags = restCatalog.listTagsPaged(identifier, null, null, null);
19921997
assertThat(tags.getElements()).isEmpty();
19931998
}
19941999

0 commit comments

Comments
 (0)