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 5690dff018 [core] Add documention in RESTApi class (#5612)
5690dff018 is described below
commit 5690dff018ab4d6178f0f4f895593467b1478a68
Author: Jingsong Lee <[email protected]>
AuthorDate: Fri May 16 15:20:18 2025 +0800
[core] Add documention in RESTApi class (#5612)
---
.../src/main/java/org/apache/paimon/PagedList.java | 2 +
.../main/java/org/apache/paimon/rest/RESTApi.java | 442 ++++++++++++++++++++-
.../java/org/apache/paimon/rest/RESTCatalog.java | 6 +-
3 files changed, 436 insertions(+), 14 deletions(-)
diff --git a/paimon-api/src/main/java/org/apache/paimon/PagedList.java
b/paimon-api/src/main/java/org/apache/paimon/PagedList.java
index ca39c92aaa..eb2d8cc8d0 100644
--- a/paimon-api/src/main/java/org/apache/paimon/PagedList.java
+++ b/paimon-api/src/main/java/org/apache/paimon/PagedList.java
@@ -38,10 +38,12 @@ public class PagedList<T> {
this.nextPageToken = nextPageToken;
}
+ /** An array of element objects. */
public List<T> getElements() {
return this.elements;
}
+ /** Page token to retrieve the next page of results. Absent if there are
no more pages. */
@Nullable
public String getNextPageToken() {
return this.nextPageToken;
diff --git a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
index 50b734fbe2..f050520653 100644
--- a/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
+++ b/paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
@@ -29,6 +29,9 @@ import org.apache.paimon.partition.Partition;
import org.apache.paimon.partition.PartitionStatistics;
import org.apache.paimon.rest.auth.AuthProvider;
import org.apache.paimon.rest.auth.RESTAuthFunction;
+import org.apache.paimon.rest.exceptions.AlreadyExistsException;
+import org.apache.paimon.rest.exceptions.ForbiddenException;
+import org.apache.paimon.rest.exceptions.NoSuchResourceException;
import org.apache.paimon.rest.requests.AlterDatabaseRequest;
import org.apache.paimon.rest.requests.AlterFunctionRequest;
import org.apache.paimon.rest.requests.AlterTableRequest;
@@ -93,6 +96,28 @@ import static
org.apache.paimon.rest.auth.AuthProviderFactory.createAuthProvider
/**
* REST API for REST Catalog.
*
+ * <p>This API class only includes interaction with REST Server and does not
have file read and
+ * write operations, which makes this API lightweight enough to avoid
introducing dependencies such
+ * as Hadoop and file systems.
+ *
+ * <p>The following example show how to use the RESTApi:
+ *
+ * <pre>{@code
+ * Options options = new Options();
+ * options.set(URI, "<rest server url>");
+ * options.set(WAREHOUSE, "my_instance_name");
+ * options.set(TOKEN_PROVIDER, "dlf");
+ * options.set(DLF_ACCESS_KEY_ID, "<access-key-id>");
+ * options.set(DLF_ACCESS_KEY_SECRET, "<access-key-secret>");
+ *
+ * RESTApi api = new RESTApi(options);
+ * List<String> tables = api.listTables("my_database");
+ * System.out.println(tables);
+ * }</pre>
+ *
+ * <p>This class also provide util methods for serializing json {@link
#toJson} and deserializing
+ * json {@link #fromJson}.
+ *
* @since 1.2.0
*/
@Public
@@ -115,10 +140,27 @@ public class RESTApi {
private final Options options;
private final ResourcePaths resourcePaths;
+ /**
+ * Initializes a newly created {@code RESTApi} object.
+ *
+ * <p>By default, {@code configRequired} is true, this means that there
will be one REST request
+ * to merge configurations during initialization.
+ *
+ * @param options contains authentication and catalog information for REST
Server
+ */
public RESTApi(Options options) {
this(options, true);
}
+ /**
+ * Initializes a newly created {@code RESTApi} object.
+ *
+ * <p>If the {@code options} are already obtained through {@link
#options()}, you can configure
+ * configRequired to be false.
+ *
+ * @param options contains authentication and catalog information for REST
Server
+ * @param configRequired is there one REST request to merge configurations
during initialization
+ */
public RESTApi(Options options, boolean configRequired) {
this.client = new HttpClient(options.get(RESTCatalogOptions.URI));
AuthProvider authProvider = createAuthProvider(options);
@@ -146,10 +188,17 @@ public class RESTApi {
this.resourcePaths = ResourcePaths.forCatalogProperties(options);
}
+ /** Get the configured options which has been merged from REST Server. */
public Options options() {
return options;
}
+ /**
+ * List databases.
+ *
+ * <p>Gets an array of databases for a catalog. There is no guarantee of a
specific ordering of
+ * the elements in the array.
+ */
public List<String> listDatabases() {
return listDataFromPageApi(
queryParams ->
@@ -160,6 +209,19 @@ public class RESTApi {
restAuthFunction));
}
+ /**
+ * List databases.
+ *
+ * <p>Gets an array of databases for a catalog. There is no guarantee of a
specific ordering of
+ * the elements in the array.
+ *
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @return {@link PagedList}: elements and nextPageToken.
+ */
public PagedList<String> listDatabasesPaged(
@Nullable Integer maxResults, @Nullable String pageToken) {
ListDatabasesResponse response =
@@ -175,20 +237,55 @@ public class RESTApi {
return new PagedList<>(databases, response.getNextPageToken());
}
+ /**
+ * Create a database.
+ *
+ * @param name name of this database
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means a
database already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public void createDatabase(String name, Map<String, String> properties) {
CreateDatabaseRequest request = new CreateDatabaseRequest(name,
properties);
client.post(resourcePaths.databases(), request, restAuthFunction);
}
+ /**
+ * Get a database.
+ *
+ * @param name name of this database
+ * @return {@link GetDatabaseResponse}
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public GetDatabaseResponse getDatabase(String name) {
return client.get(
resourcePaths.database(name), GetDatabaseResponse.class,
restAuthFunction);
}
+ /**
+ * Drop a database.
+ *
+ * @param name name of this database
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public void dropDatabase(String name) {
client.delete(resourcePaths.database(name), restAuthFunction);
}
+ /**
+ * Alter a database.
+ *
+ * @param name name of this database
+ * @param removals options to be removed
+ * @param updates options to be updated or added
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public void alterDatabase(String name, List<String> removals, Map<String,
String> updates) {
client.post(
resourcePaths.database(name),
@@ -197,6 +294,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * List tables for a database.
+ *
+ * @param databaseName name of this database
+ * @return a list of table names
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public List<String> listTables(String databaseName) {
return listDataFromPageApi(
queryParams ->
@@ -207,6 +313,25 @@ public class RESTApi {
restAuthFunction));
}
+ /**
+ * List tables for a database.
+ *
+ * <p>Gets an array of tables for a database. There is no guarantee of a
specific ordering of
+ * the elements in the array.
+ *
+ * @param databaseName name of database.
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @param tableNamePattern A sql LIKE pattern (%) for table names. All
tables will be returned
+ * if not set or empty. Currently, only prefix matching is supported.
+ * @return {@link PagedList}: elements and nextPageToken.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public PagedList<String> listTablesPaged(
String databaseName,
@Nullable Integer maxResults,
@@ -226,14 +351,33 @@ public class RESTApi {
return new PagedList<>(tables, response.getNextPageToken());
}
+ /**
+ * List table details for a database.
+ *
+ * <p>Gets an array of table details for a database. There is no guarantee
of a specific
+ * ordering of the elements in the array.
+ *
+ * @param databaseName name of database.
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @param tableNamePattern A sql LIKE pattern (%) for table names. All
tables will be returned
+ * if not set or empty. Currently, only prefix matching is supported.
+ * @return {@link PagedList}: elements and nextPageToken.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public PagedList<GetTableResponse> listTableDetailsPaged(
- String db,
+ String databaseName,
@Nullable Integer maxResults,
@Nullable String pageToken,
@Nullable String tableNamePattern) {
ListTableDetailsResponse response =
client.get(
- resourcePaths.tableDetails(db),
+ resourcePaths.tableDetails(databaseName),
buildPagedQueryParams(
maxResults, pageToken, TABLE_NAME_PATTERN,
tableNamePattern),
ListTableDetailsResponse.class,
@@ -245,6 +389,15 @@ public class RESTApi {
return new PagedList<>(tables, response.getNextPageToken());
}
+ /**
+ * Get table.
+ *
+ * @param identifier database name and table name.
+ * @return {@link GetTableResponse}
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public GetTableResponse getTable(Identifier identifier) {
return client.get(
resourcePaths.table(identifier.getDatabaseName(),
identifier.getObjectName()),
@@ -252,6 +405,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Load latest snapshot for table.
+ *
+ * @param identifier database name and table name.
+ * @return {@link TableSnapshot} Optional snapshot.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public TableSnapshot loadSnapshot(Identifier identifier) {
GetTableSnapshotResponse response =
client.get(
@@ -262,6 +424,17 @@ public class RESTApi {
return response.getSnapshot();
}
+ /**
+ * Commit snapshot for table.
+ *
+ * @param identifier database name and table name.
+ * @param snapshot snapshot for committing
+ * @param statistics statistics for this snapshot incremental
+ * @return true if commit success
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public boolean commitSnapshot(
Identifier identifier, Snapshot snapshot,
List<PartitionStatistics> statistics) {
CommitTableRequest request = new CommitTableRequest(snapshot,
statistics);
@@ -275,6 +448,15 @@ public class RESTApi {
return response.isSuccess();
}
+ /**
+ * Rollback instant for table.
+ *
+ * @param identifier database name and table name.
+ * @param instant instant to rollback
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void rollbackTo(Identifier identifier, Instant instant) {
RollbackTableRequest request = new RollbackTableRequest(instant);
client.post(
@@ -284,16 +466,45 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Create table.
+ *
+ * @param identifier database name and table name.
+ * @param schema schema to create table
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means a
table already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * creating table
+ */
public void createTable(Identifier identifier, Schema schema) {
CreateTableRequest request = new CreateTableRequest(identifier,
schema);
client.post(resourcePaths.tables(identifier.getDatabaseName()),
request, restAuthFunction);
}
+ /**
+ * Rename table.
+ *
+ * @param fromTable from table
+ * @param toTable to table
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
fromTable not exists
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means the
toTable already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * renaming table
+ */
public void renameTable(Identifier fromTable, Identifier toTable) {
RenameTableRequest request = new RenameTableRequest(fromTable,
toTable);
client.post(resourcePaths.renameTable(), request, restAuthFunction);
}
+ /**
+ * Alter table.
+ *
+ * @param identifier database name and table name.
+ * @param changes changes to alter table
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void alterTable(Identifier identifier, List<SchemaChange> changes) {
AlterTableRequest request = new AlterTableRequest(changes);
client.post(
@@ -302,6 +513,16 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Auth table query.
+ *
+ * @param identifier database name and table name.
+ * @param select select columns
+ * @param filter pushed filter
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void authTableQuery(Identifier identifier, List<String> select,
List<String> filter) {
AuthTableQueryRequest request = new AuthTableQueryRequest(select,
filter);
client.post(
@@ -310,12 +531,29 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Drop table.
+ *
+ * @param identifier database name and table name.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void dropTable(Identifier identifier) {
client.delete(
resourcePaths.table(identifier.getDatabaseName(),
identifier.getObjectName()),
restAuthFunction);
}
+ /**
+ * Mark done partitions for table.
+ *
+ * @param identifier database name and table name.
+ * @param partitions partitions to be marked done
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void markDonePartitions(Identifier identifier, List<Map<String,
String>> partitions) {
MarkDonePartitionsRequest request = new
MarkDonePartitionsRequest(partitions);
client.post(
@@ -325,6 +563,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * List partitions for table.
+ *
+ * @param identifier database name and table name.
+ * @return a list for partitions
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public List<Partition> listPartitions(Identifier identifier) {
return listDataFromPageApi(
queryParams ->
@@ -336,6 +583,25 @@ public class RESTApi {
restAuthFunction));
}
+ /**
+ * List partitions for a table.
+ *
+ * <p>Gets an array of partitions for a table. There is no guarantee of a
specific ordering of
+ * the elements in the array.
+ *
+ * @param identifier database name and table name.
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @param partitionNamePattern A sql LIKE pattern (%) for partition names.
All partitions will
+ * be returned if not set or empty. Currently, only prefix matching is
supported.
+ * @return {@link PagedList}: elements and nextPageToken.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public PagedList<Partition> listPartitionsPaged(
Identifier identifier,
@Nullable Integer maxResults,
@@ -359,6 +625,18 @@ public class RESTApi {
return new PagedList<>(partitions, response.getNextPageToken());
}
+ /**
+ * Create branch for table.
+ *
+ * @param identifier database name and table name.
+ * @param branch branch name
+ * @param fromTag optional from tag
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table or fromTag not
+ * exists
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means the
branch already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void createBranch(Identifier identifier, String branch, @Nullable
String fromTag) {
CreateBranchRequest request = new CreateBranchRequest(branch, fromTag);
client.post(
@@ -367,6 +645,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Drop branch for table.
+ *
+ * @param identifier database name and table name.
+ * @param branch branch name
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
branch not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void dropBranch(Identifier identifier, String branch) {
client.delete(
resourcePaths.branch(
@@ -374,6 +661,16 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Forward branch for table.
+ *
+ * @param identifier database name and table name.
+ * @param branch branch name
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
branch or table not
+ * exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public void fastForward(Identifier identifier, String branch) {
ForwardBranchRequest request = new ForwardBranchRequest();
client.post(
@@ -383,6 +680,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * List branches for table.
+ *
+ * @param identifier database name and table name.
+ * @return a list of branches
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public List<String> listBranches(Identifier identifier) {
ListBranchesResponse response =
client.get(
@@ -396,6 +702,7 @@ public class RESTApi {
return response.branches();
}
+ /** TODO. */
public List<String> listFunctions() {
return listDataFromPageApi(
queryParams ->
@@ -406,20 +713,24 @@ public class RESTApi {
restAuthFunction));
}
+ /** TODO. */
public GetFunctionResponse getFunction(String functionName) {
return client.get(
resourcePaths.function(functionName),
GetFunctionResponse.class, restAuthFunction);
}
- public void createFunction(String functionName,
org.apache.paimon.function.Function function) {
+ /** TODO. */
+ public void createFunction(org.apache.paimon.function.Function function) {
client.post(
resourcePaths.functions(), new
CreateFunctionRequest(function), restAuthFunction);
}
+ /** TODO. */
public void dropFunction(String functionName) {
client.delete(resourcePaths.function(functionName), restAuthFunction);
}
+ /** TODO. */
public void alterFunction(String functionName, List<FunctionChange>
changes) {
client.post(
resourcePaths.function(functionName),
@@ -427,6 +738,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Get view.
+ *
+ * @param identifier database name and view name.
+ * @return {@link GetViewResponse}
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
view not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this view
+ */
public GetViewResponse getView(Identifier identifier) {
return client.get(
resourcePaths.view(identifier.getDatabaseName(),
identifier.getObjectName()),
@@ -434,17 +754,43 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Drop view.
+ *
+ * @param identifier database name and view name.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
view not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this view
+ */
public void dropView(Identifier identifier) {
client.delete(
resourcePaths.view(identifier.getDatabaseName(),
identifier.getObjectName()),
restAuthFunction);
}
+ /**
+ * Create view.
+ *
+ * @param identifier database name and view name.
+ * @param schema schema of the view
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means the
view already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this view
+ */
public void createView(Identifier identifier, ViewSchema schema) {
CreateViewRequest request = new CreateViewRequest(identifier, schema);
client.post(resourcePaths.views(identifier.getDatabaseName()),
request, restAuthFunction);
}
+ /**
+ * List views for a database.
+ *
+ * @param databaseName name of this database
+ * @return a list of view names
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public List<String> listViews(String databaseName) {
return listDataFromPageApi(
queryParams ->
@@ -455,6 +801,25 @@ public class RESTApi {
restAuthFunction));
}
+ /**
+ * List views.
+ *
+ * <p>Gets an array of views for a database. There is no guarantee of a
specific ordering of the
+ * elements in the array.
+ *
+ * @param databaseName database name
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @param viewNamePattern A sql LIKE pattern (%) for view names. All views
will be returned if
+ * not set or empty. Currently, only prefix matching is supported.
+ * @return {@link PagedList}: elements and nextPageToken.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public PagedList<String> listViewsPaged(
String databaseName,
@Nullable Integer maxResults,
@@ -474,14 +839,33 @@ public class RESTApi {
return new PagedList<>(views, response.getNextPageToken());
}
+ /**
+ * List view details.
+ *
+ * <p>Gets an array of view details for a database. There is no guarantee
of a specific ordering
+ * of the elements in the array.
+ *
+ * @param databaseName database name
+ * @param maxResults Optional parameter indicating the maximum number of
results to include in
+ * the result. If maxResults is not specified or set to 0, will return
the default number of
+ * max results.
+ * @param pageToken Optional parameter indicating the next page token
allows list to be start
+ * from a specific point.
+ * @param viewNamePattern A sql LIKE pattern (%) for view names. All views
will be returned if
+ * not set or empty. Currently, only prefix matching is supported.
+ * @return {@link PagedList}: elements and nextPageToken.
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
database not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this database
+ */
public PagedList<GetViewResponse> listViewDetailsPaged(
- String db,
+ String databaseName,
@Nullable Integer maxResults,
@Nullable String pageToken,
@Nullable String viewNamePattern) {
ListViewDetailsResponse response =
client.get(
- resourcePaths.viewDetails(db),
+ resourcePaths.viewDetails(databaseName),
buildPagedQueryParams(
maxResults, pageToken, VIEW_NAME_PATTERN,
viewNamePattern),
ListViewDetailsResponse.class,
@@ -493,11 +877,30 @@ public class RESTApi {
return new PagedList<>(views, response.getNextPageToken());
}
+ /**
+ * Rename view.
+ *
+ * @param fromView from view
+ * @param toView to view
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means
fromView not exists
+ * @throws AlreadyExistsException Exception thrown on HTTP 409 means
toView already exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * views
+ */
public void renameView(Identifier fromView, Identifier toView) {
RenameTableRequest request = new RenameTableRequest(fromView, toView);
client.post(resourcePaths.renameView(), request, restAuthFunction);
}
+ /**
+ * Alter view.
+ *
+ * @param identifier database name and view name.
+ * @param viewChanges view changes
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
view not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this view
+ */
public void alterView(Identifier identifier, List<ViewChange> viewChanges)
{
AlterViewRequest request = new AlterViewRequest(viewChanges);
client.post(
@@ -506,6 +909,15 @@ public class RESTApi {
restAuthFunction);
}
+ /**
+ * Load token for File System of this table.
+ *
+ * @param identifier database name and view name.
+ * @return {@link GetTableTokenResponse}
+ * @throws NoSuchResourceException Exception thrown on HTTP 404 means the
table not exists
+ * @throws ForbiddenException Exception thrown on HTTP 403 means don't
have the permission for
+ * this table
+ */
public GetTableTokenResponse loadTableToken(Identifier identifier) {
return client.get(
resourcePaths.tableToken(identifier.getDatabaseName(),
identifier.getObjectName()),
@@ -513,6 +925,18 @@ public class RESTApi {
restAuthFunction);
}
+ /** Util method to deserialize object from json. */
+ public static <T> T fromJson(String json, Class<T> clazz) throws
JsonProcessingException {
+ return OBJECT_MAPPER.readValue(json, clazz);
+ }
+
+ /** Util method to serialize object to json. */
+ public static <T> String toJson(T t) throws JsonProcessingException {
+ return OBJECT_MAPPER.writeValueAsString(t);
+ }
+
+ // ============================== Inner methods
================================
+
@VisibleForTesting
<T> List<T> listDataFromPageApi(Function<Map<String, String>,
PagedResponse<T>> pageApi) {
List<T> results = new ArrayList<>();
@@ -561,12 +985,4 @@ public class RESTApi {
RESTAuthFunction authFunction() {
return restAuthFunction;
}
-
- public static <T> T fromJson(String json, Class<T> clazz) throws
JsonProcessingException {
- return OBJECT_MAPPER.readValue(json, clazz);
- }
-
- public static <T> String toJson(T t) throws JsonProcessingException {
- return OBJECT_MAPPER.writeValueAsString(t);
- }
}
diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
index 3c450a15ca..428fc3da26 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
@@ -206,6 +206,8 @@ public class RESTCatalog implements Catalog {
return api.listTables(databaseName);
} catch (NoSuchResourceException e) {
throw new DatabaseNotExistException(databaseName);
+ } catch (ForbiddenException e) {
+ throw new DatabaseNoPermissionException(databaseName);
}
}
@@ -489,6 +491,8 @@ public class RESTCatalog implements Catalog {
api.markDonePartitions(identifier, partitions);
} catch (NoSuchResourceException e) {
throw new TableNotExistException(identifier);
+ } catch (ForbiddenException e) {
+ throw new TableNoPermissionException(identifier);
} catch (NotImplementedException ignored) {
// not a metastore partitioned table
}
@@ -630,7 +634,7 @@ public class RESTCatalog implements Catalog {
boolean ignoreIfExists)
throws FunctionAlreadyExistException {
try {
- api.createFunction(functionName, function);
+ api.createFunction(function);
} catch (AlreadyExistsException e) {
if (ignoreIfExists) {
return;