Querying the Metadata of the Spark Databases and Tables
Description
This section describes how to use AI DataLake SDK to query metadata of databases and tables.
Prerequisites
LakeFormation APIs and related permissions have been configured. For details about the permissions, see Permissions and Supported Actions.
Functions
# List catalogs.
listCatalogs();
# List databases.
listDatabases("yourCatalogName");
# List tables.
listTables("yourCatalogName", "yourDBName"); | Parameter | Mandatory (Yes/No) | Default Value | Description |
|---|---|---|---|
| yourCatalogName | No | None | Data catalog name. |
| yourDBName | Yes | None | Database name. |
Sample Code
- Querying catalogs
public static void listCatalogs(AIDataLakeLakeFormationClient lakeformationClient) { Catalogs catalogs = lakeformationClient.listCatalogs(); for (Catalog item : catalogs) { System.out.println(item.getCatalogName()); } Catalog catalog = catalogs.getCatalog("yourCatalogName") }
- Querying databases
public static void listDatabases(AIDataLakeLakeFormationClient lakeformationClient) { Databases databases = lakeformationClient.listDatabases("yourCatalogName"); for (Database item : databases) { System.out.println(item.getDatabaseName()); } Database database = databases.getDatabase("yourDBName") }
- Querying tables
public static void listTables(AIDataLakeLakeFormationClient lakeformationClient) throws AIDataLakeException { Tables tables = lakeformationClient.listTables("yourCatalogName", "yourDBName"); for (Table item : tables) { System.out.println(item.getTableName()); } // get table Table table = tables.getTable("yourTableName"); // filter table TableFilter tableFilter = new TableFilter(); tableFilter.setTblPattern("table_name_xxx"); tableFilter.setTblPattern("table_type_xxx"); Iterable<Table> tableA = tables.iterableWithDatabaseAndFilter("yourDBName", tableFilter); // get table meta TableMeta tableMeta = tables.getTableMeta("yourTableName"); }
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot