Catalog
Defined in: catalog.ts:23
Access to Spark’s catalog for inspecting and managing databases, tables, functions, views, and cached tables.
Obtained via SparkSession.catalog.
Example
Section titled “Example”const dbs = await spark.catalog.listDatabases();const tables = await spark.catalog.listTables("analytics");await spark.catalog.cacheTable("analytics.events");Methods
Section titled “Methods”cacheTable()
Section titled “cacheTable()”cacheTable(tableName, storageLevel?): Promise<void>;Defined in: catalog.ts:131
Cache the specified table in-memory with an optional storage level.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
storageLevel? | StorageLevel |
Returns
Section titled “Returns”Promise<void>
clearCache()
Section titled “clearCache()”clearCache(): Promise<void>;Defined in: catalog.ts:141
Remove all cached tables from the in-memory cache.
Returns
Section titled “Returns”Promise<void>
createExternalTable()
Section titled “createExternalTable()”createExternalTable(tableName, options?): DataFrame;Defined in: catalog.ts:198
Create an external table based on the dataset in a data source.
Returns a DataFrame associated with the external table.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
options? | { options?: Record<string, string>; path?: string; schema?: StructType; source?: string; } |
options.options? | Record<string, string> |
options.path? | string |
options.schema? | StructType |
options.source? | string |
Returns
Section titled “Returns”createTable()
Section titled “createTable()”createTable(tableName, options?): DataFrame;Defined in: catalog.ts:168
Create a table based on the dataset in a data source.
When path is specified, an external table is created from the data at
the given path. Otherwise a managed table is created.
Returns a DataFrame associated with the new table.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
options? | { description?: string; options?: Record<string, string>; path?: string; schema?: StructType; source?: string; } |
options.description? | string |
options.options? | Record<string, string> |
options.path? | string |
options.schema? | StructType |
options.source? | string |
Returns
Section titled “Returns”currentCatalog()
Section titled “currentCatalog()”currentCatalog(): Promise<string>;Defined in: catalog.ts:120
Get the current default catalog name.
Returns
Section titled “Returns”Promise<string>
currentDatabase()
Section titled “currentDatabase()”currentDatabase(): Promise<string>;Defined in: catalog.ts:109
Get the current database name.
Returns
Section titled “Returns”Promise<string>
databaseExists()
Section titled “databaseExists()”databaseExists(dbName): Promise<boolean>;Defined in: catalog.ts:79
Check if a database exists.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dbName | string |
Returns
Section titled “Returns”Promise<boolean>
dropGlobalTempView()
Section titled “dropGlobalTempView()”dropGlobalTempView(viewName): Promise<boolean>;Defined in: catalog.ts:103
Drops the global temporary view. Returns true if the view existed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
viewName | string |
Returns
Section titled “Returns”Promise<boolean>
dropTempView()
Section titled “dropTempView()”dropTempView(viewName): Promise<boolean>;Defined in: catalog.ts:97
Drops the local temporary view. Returns true if the view existed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
viewName | string |
Returns
Section titled “Returns”Promise<boolean>
functionExists()
Section titled “functionExists()”functionExists(functionName, dbName?): Promise<boolean>;Defined in: catalog.ts:85
Check if a function exists.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
functionName | string |
dbName? | string |
Returns
Section titled “Returns”Promise<boolean>
getDatabase()
Section titled “getDatabase()”getDatabase(dbName): DataFrame;Defined in: catalog.ts:58
Get the database with the specified name. Returns a single-row DataFrame.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dbName | string |
Returns
Section titled “Returns”getFunction()
Section titled “getFunction()”getFunction(functionName, dbName?): DataFrame;Defined in: catalog.ts:68
Get the function with the specified name. Returns a single-row DataFrame.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
functionName | string |
dbName? | string |
Returns
Section titled “Returns”getTable()
Section titled “getTable()”getTable(tableName, dbName?): DataFrame;Defined in: catalog.ts:63
Get the table or view with the specified name. Returns a single-row DataFrame.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
dbName? | string |
Returns
Section titled “Returns”isCached()
Section titled “isCached()”isCached(tableName): Promise<boolean>;Defined in: catalog.ts:91
Returns true if the table is currently cached in-memory.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
Returns
Section titled “Returns”Promise<boolean>
listCatalogs()
Section titled “listCatalogs()”listCatalogs(pattern?): DataFrame;Defined in: catalog.ts:53
List all catalogs. Returns a DataFrame with catalog metadata.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
pattern? | string |
Returns
Section titled “Returns”listColumns()
Section titled “listColumns()”listColumns(tableName, dbName?): DataFrame;Defined in: catalog.ts:43
List all columns of a table. Returns a DataFrame with column metadata.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
dbName? | string |
Returns
Section titled “Returns”listDatabases()
Section titled “listDatabases()”listDatabases(pattern?): DataFrame;Defined in: catalog.ts:33
List all databases. Returns a DataFrame with database metadata.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
pattern? | string |
Returns
Section titled “Returns”listFunctions()
Section titled “listFunctions()”listFunctions(dbName?, pattern?): DataFrame;Defined in: catalog.ts:48
List all functions in a database. Returns a DataFrame with function metadata.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dbName? | string |
pattern? | string |
Returns
Section titled “Returns”listTables()
Section titled “listTables()”listTables(dbName?, pattern?): DataFrame;Defined in: catalog.ts:38
List all tables in a database. Returns a DataFrame with table metadata.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dbName? | string |
pattern? | string |
Returns
Section titled “Returns”recoverPartitions()
Section titled “recoverPartitions()”recoverPartitions(tableName): Promise<void>;Defined in: catalog.ts:156
Recover all partitions of the given table and update the catalog.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
Returns
Section titled “Returns”Promise<void>
refreshByPath()
Section titled “refreshByPath()”refreshByPath(path): Promise<void>;Defined in: catalog.ts:151
Invalidate and refresh cached data for any DataFrame containing the given path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
refreshTable()
Section titled “refreshTable()”refreshTable(tableName): Promise<void>;Defined in: catalog.ts:146
Invalidate and refresh all cached data and metadata for the given table.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
Returns
Section titled “Returns”Promise<void>
setCurrentCatalog()
Section titled “setCurrentCatalog()”setCurrentCatalog(catalogName): Promise<void>;Defined in: catalog.ts:126
Set the current default catalog.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
catalogName | string |
Returns
Section titled “Returns”Promise<void>
setCurrentDatabase()
Section titled “setCurrentDatabase()”setCurrentDatabase(dbName): Promise<void>;Defined in: catalog.ts:115
Set the current database.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
dbName | string |
Returns
Section titled “Returns”Promise<void>
tableExists()
Section titled “tableExists()”tableExists(tableName, dbName?): Promise<boolean>;Defined in: catalog.ts:73
Check if a table exists.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
dbName? | string |
Returns
Section titled “Returns”Promise<boolean>
uncacheTable()
Section titled “uncacheTable()”uncacheTable(tableName): Promise<void>;Defined in: catalog.ts:136
Remove the specified table from the in-memory cache.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
Returns
Section titled “Returns”Promise<void>