JingsongLi commented on code in PR #8179:
URL: https://github.com/apache/paimon/pull/8179#discussion_r3457930307
##########
paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java:
##########
@@ -910,6 +914,139 @@ public PagedList<Function> listFunctionDetailsPaged(
}
}
+ @Override
+ public List<String> listResources(String databaseName) throws
DatabaseNotExistException {
+ try {
+ return api.listResources(databaseName);
+ } catch (NoSuchResourceException e) {
+ throw new DatabaseNotExistException(databaseName);
+ } catch (ForbiddenException e) {
+ throw new DatabaseNoPermissionException(databaseName, e);
+ }
+ }
+
+ @Override
+ public Resource getResource(Identifier identifier) throws
ResourceNotExistException {
+ try {
+ GetResourceResponse response = api.getResource(identifier);
+ return toResource(identifier, response);
+ } catch (NoSuchResourceException e) {
+ throw new ResourceNotExistException(identifier, e);
+ } catch (ForbiddenException e) {
+ throw new TableNoPermissionException(identifier, e);
+ }
+ }
+
+ @Override
+ public void createResource(Identifier identifier, Resource resource,
boolean ignoreIfExists)
+ throws ResourceAlreadyExistException, DatabaseNotExistException {
+ RESTFunctionValidator.checkFunctionName(identifier.getObjectName());
+ try {
+ api.createResource(
+ identifier,
+ resource.comment().orElse(null),
+ resource.uri(),
+ resource.resourceType());
+ } catch (NoSuchResourceException e) {
+ throw new DatabaseNotExistException(identifier.getDatabaseName(),
e);
+ } catch (AlreadyExistsException e) {
+ if (ignoreIfExists) {
+ return;
+ }
+ throw new ResourceAlreadyExistException(identifier, e);
+ }
+ }
+
+ @Override
+ public void dropResource(Identifier identifier, boolean ignoreIfNotExists)
+ throws ResourceNotExistException {
+ RESTFunctionValidator.checkFunctionName(identifier.getObjectName());
+ try {
+ api.dropResource(identifier);
+ } catch (NoSuchResourceException e) {
+ if (ignoreIfNotExists) {
+ return;
+ }
+ throw new ResourceNotExistException(identifier, e);
+ }
+ }
+
+ @Override
+ public void alterResource(
+ Identifier identifier, List<ResourceChange> changes, boolean
ignoreIfNotExists)
+ throws ResourceNotExistException {
+ try {
+ api.alterResource(identifier, changes);
+ } catch (NoSuchResourceException e) {
+ if (!ignoreIfNotExists) {
+ throw new ResourceNotExistException(identifier, e);
+ }
+ } catch (ForbiddenException e) {
+ throw new TableNoPermissionException(identifier, e);
+ } catch (BadRequestException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
+ @Override
+ public PagedList<String> listResourcesPaged(
+ String databaseName,
+ @Nullable Integer maxResults,
+ @Nullable String pageToken,
+ @Nullable String resourceNamePattern)
+ throws DatabaseNotExistException {
+ try {
+ return api.listResourcesPaged(databaseName, maxResults, pageToken,
resourceNamePattern);
+ } catch (NoSuchResourceException e) {
+ throw new DatabaseNotExistException(databaseName);
+ }
+ }
+
+ @Override
+ public PagedList<Resource> listResourceDetailsPaged(
+ String databaseName,
+ @Nullable Integer maxResults,
+ @Nullable String pageToken,
+ @Nullable String resourceNamePattern)
+ throws DatabaseNotExistException {
+ try {
+ PagedList<GetResourceResponse> resources =
+ api.listResourceDetailsPaged(
+ databaseName, maxResults, pageToken,
resourceNamePattern);
+ return new PagedList<>(
+ resources.getElements().stream()
+ .map(r ->
toResource(Identifier.create(databaseName, r.name()), r))
+ .collect(Collectors.toList()),
+ resources.getNextPageToken());
+ } catch (NoSuchResourceException e) {
+ throw new DatabaseNotExistException(databaseName);
+ }
+ }
+
+ private Resource toResource(Identifier identifier, GetResourceResponse
response) {
+ String uri = response.uri();
+ return Resource.toResource(
+ ResourceType.fromValue(response.resourceType()),
+ identifier,
+ response.comment(),
+ uri,
+ response.size(),
+ response.lastModifiedTime(),
+ fileIOForData(new Path(uri), identifier));
Review Comment:
This still breaks resource reads when the REST catalog has
`data-token.enabled=true`. `fileIOForData` wraps the URI with
`RESTTokenFileIO`, and `RESTTokenFileIO.refreshToken()` always calls
`loadTableToken(identifier)`. Here the identifier is the resource identifier,
not a table identifier, so `resource.toBytes()` / `newInputStream()` will try
to fetch `/tables/<resource>/token` and fail as soon as a token-enabled catalog
is used. Please either use a non-table-token FileIO for resources or add a
resource-token path instead of reusing the table-token flow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]