Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions influxdb3_system_tables/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,17 @@ impl AllSystemSchemaTablesProvider {
InfluxdbSchemaTable::new(Arc::clone(&db_schema)),
))),
);
if db_schema.name.as_ref() == INTERNAL_DB_NAME {
let is_internal_database = db_schema.name.as_ref() == INTERNAL_DB_NAME;
// `system.tables` is available for all databases but restricts tables
// to that contained in the mentioned database only.
tables.insert(
TABLES_TABLE_NAME,
Arc::new(SystemTableProvider::new(Arc::new(TablesTable::new(
Arc::clone(&catalog),
(!is_internal_database).then_some(Arc::clone(&db_schema.name)),
)))),
);
if is_internal_database {
tables.insert(
TOKENS_TABLE_NAME,
Arc::new(SystemTableProvider::new(Arc::new(TokenSystemTable::new(
Expand All @@ -202,12 +212,6 @@ impl AllSystemSchemaTablesProvider {
Arc::clone(&catalog),
)))),
);
tables.insert(
TABLES_TABLE_NAME,
Arc::new(SystemTableProvider::new(Arc::new(TablesTable::new(
Arc::clone(&catalog),
)))),
);
tables.insert(
GENERATION_DURATIONS_TABLE_NAME,
Arc::new(SystemTableProvider::new(Arc::new(
Expand Down
14 changes: 12 additions & 2 deletions influxdb3_system_tables/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ use iox_system_tables::IoxSystemTable;
#[derive(Debug)]
pub(crate) struct TablesTable {
catalog: Arc<Catalog>,
database: Option<Arc<str>>,
Comment thread
vrongmeal marked this conversation as resolved.
Outdated
schema: SchemaRef,
}

impl TablesTable {
pub(crate) fn new(catalog: Arc<Catalog>) -> Self {
pub(crate) fn new(catalog: Arc<Catalog>, database: Option<Arc<str>>) -> Self {
Self {
catalog,
database,
schema: tables_schema(),
}
}
Expand Down Expand Up @@ -52,7 +54,15 @@ impl IoxSystemTable for TablesTable {
_filters: Option<Vec<Expr>>,
_limit: Option<usize>,
) -> Result<RecordBatch, DataFusionError> {
let databases = self.catalog.list_db_schema();
let databases = if let Some(database) = &self.database {
let db_schema = self
.catalog
.db_schema(database)
.ok_or_else(|| DataFusionError::Plan(format!("database not found: {database}")))?;
vec![db_schema]
} else {
self.catalog.list_db_schema()
};

// Count total tables across all databases
let total_tables: usize = databases
Expand Down