Help Center/ AI DataLake/ SDK Reference/ Engine-specific SDKs/ Java SDKs/ Spark SDK (Java)/ Querying the Metadata of the Spark Databases and Tables
Updated on 2026-11-09 GMT+08:00

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

AIDataLakeLakeFormationClient
# 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");
    }