Show Tables
Show Tables
Description:
Displays all tables present in the currently selected database by reading table metadata from the in-memory catalog.
Function:
pub fn show_tables(
catalog: &Catalog,
db_name: &str,
)
Input:
catalog— Read-only reference to the in-memory catalog containing database and table metadata.db_name— Name of the database whose tables should be displayed.
Output:
- No return value (
()). - Prints all table names in the specified database.
- Prints an appropriate message if the database does not exist or contains no tables.
Implementation:
- Validate that the specified database exists in the catalog.
- If the database does not exist:
- Print an error message.
- Return immediately.
- Retrieve the database metadata from:
catalog.databases - Check whether the database contains any tables.
- If no tables exist:
- Print:
No tables found. - Return immediately.
- Print:
- Iterate through all table names stored in:
database.tables - Print each table name to the console.
- Log the displayed table information.
Internal API Calls:
-
catalog.databases.get(db_name)- Retrieves the database metadata from the catalog.
-
database.tables.is_empty()- Checks whether the selected database contains any tables.
-
database.tables.keys()- Retrieves all table names stored in the database metadata.
-
println!(...)- Displays table names and status messages.
-
log::info!(...)- Records informational messages in the log.
-
log::debug!(...)- Records debug information in the log.
Files Created/Modified:
- None.
Catalog Updates:
- None.
- The function only reads metadata from the catalog.
Notes:
- Table names are retrieved entirely from the in-memory catalog.
- No table files are opened or scanned during this operation.
- The function is read-only and does not modify database state.