Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions paimon-api/src/main/java/org/apache/paimon/rest/RESTApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,28 @@ public PagedList<GetTableResponse> listTableDetailsPaged(
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.
* @return a list of table details.
* @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<GetTableResponse> listTableDetails(String databaseName) {
return listDataFromPageApi(
queryParams ->
client.get(
resourcePaths.tableDetails(databaseName),
queryParams,
ListTableDetailsResponse.class,
restAuthFunction));
}

/**
* List table for a catalog.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ protected PagedList<Table> listTableDetailsPagedImpl(
pagedTableNames.getNextPageToken());
}

@Override
public List<Table> listTableDetails(String databaseName) throws DatabaseNotExistException {
List<Table> result = new ArrayList<>();
for (String tableName : listTables(databaseName)) {
try {
result.add(getTable(Identifier.create(databaseName, tableName)));
} catch (TableNotExistException e) {
// ignore
}
}
return result;
}

@Override
public void dropTable(Identifier identifier, boolean ignoreIfNotExists)
throws TableNotExistException {
Expand Down
11 changes: 11 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ PagedList<Table> listTableDetailsPaged(
@Nullable String tableType)
throws DatabaseNotExistException;

/**
* Get list of table details under this database. An empty list is returned if none exists.
*
* <p>NOTE: System tables will not be listed.
*
* @param databaseName Name of the database to list table details.
* @return a list of the details of all tables in this database.
* @throws DatabaseNotExistException if the database does not exist
*/
List<Table> listTableDetails(String databaseName) throws DatabaseNotExistException;

/**
* Gets an array of tables for a catalog.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public PagedList<Table> listTableDetailsPaged(
databaseName, maxResults, pageToken, tableNamePattern, tableType);
}

@Override
public List<Table> listTableDetails(String databaseName) throws DatabaseNotExistException {
return wrapped.listTableDetails(databaseName);
}

@Override
public PagedList<Identifier> listTablesPagedGlobally(
String databaseNamePattern,
Expand Down
10 changes: 10 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ public PagedList<Table> listTableDetailsPaged(
}
}

@Override
public List<Table> listTableDetails(String databaseName) throws DatabaseNotExistException {
try {
List<GetTableResponse> tables = api.listTableDetails(databaseName);
return tables.stream().map(t -> toTable(databaseName, t)).collect(Collectors.toList());
} catch (NoSuchResourceException e) {
throw new DatabaseNotExistException(databaseName);
}
}

@Override
public PagedList<Identifier> listTablesPagedGlobally(
@Nullable String databaseNamePattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,32 @@ public void testListTableDetailsPagedWithTableType() throws Exception {
assertThat(nonExistentTypeWithMaxResults.getNextPageToken()).isNull();
}

@Test
public void testListTableDetails() throws Exception {
// List table details returns an empty list when there are no tables in the database
String databaseName = "table_details_db";
catalog.createDatabase(databaseName, false);
List<Table> tableDetails = catalog.listTableDetails(databaseName);
assertThat(tableDetails).isEmpty();

String[] tableNames = {"table1", "table2", "table3", "abd", "def", "opr", "table_name"};
String[] expectedTableNames = Arrays.stream(tableNames).sorted().toArray(String[]::new);
for (String tableName : tableNames) {
catalog.createTable(
Identifier.create(databaseName, tableName), DEFAULT_TABLE_SCHEMA, false);
}

tableDetails = catalog.listTableDetails(databaseName);
assertThat(tableDetails).hasSize(tableNames.length);
List<String> actualTableNames =
tableDetails.stream().map(Table::name).sorted().collect(Collectors.toList());
assertThat(actualTableNames).containsExactly(expectedTableNames);

// List table details throws DatabaseNotExistException when the database does not exist
assertThatExceptionOfType(Catalog.DatabaseNotExistException.class)
.isThrownBy(() -> catalog.listTableDetails("non_existing_db"));
}

@Test
public void testListTablesPagedWithTableType() throws Exception {
String databaseName = "tables_paged_table_type_db";
Expand Down