Skip to content

Commit 2bc2efb

Browse files
committed
topology: fetch view information in a schema pull
In order to keep information about materialized views too, system_schema.views system table is queried, instead of fetching the info only from system_schema.tables.
1 parent 672204a commit 2bc2efb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

scylla/src/transport/load_balancing/token_aware.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ mod tests {
312312
replication_factor: 2,
313313
},
314314
tables: HashMap::new(),
315+
views: HashMap::new(),
315316
user_defined_types: HashMap::new(),
316317
},
317318
),
@@ -322,6 +323,7 @@ mod tests {
322323
replication_factor: 3,
323324
},
324325
tables: HashMap::new(),
326+
views: HashMap::new(),
325327
user_defined_types: HashMap::new(),
326328
},
327329
),
@@ -413,6 +415,7 @@ mod tests {
413415
.collect::<HashMap<_, _>>(),
414416
},
415417
tables: HashMap::new(),
418+
views: HashMap::new(),
416419
user_defined_types: HashMap::new(),
417420
},
418421
)]

scylla/src/transport/topology.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct Keyspace {
5353
/// Empty HashMap may as well mean that the client disabled schema fetching in SessionConfig
5454
pub tables: HashMap<String, Table>,
5555
/// Empty HashMap may as well mean that the client disabled schema fetching in SessionConfig
56+
pub views: HashMap<String, Table>,
57+
/// Empty HashMap may as well mean that the client disabled schema fetching in SessionConfig
5658
pub user_defined_types: HashMap<String, Vec<(String, CqlType)>>,
5759
}
5860

@@ -460,13 +462,22 @@ async fn query_keyspaces(
460462
))?;
461463

462464
let mut result = HashMap::with_capacity(rows.len());
463-
let (mut all_tables, mut all_user_defined_types) = if fetch_schema {
465+
let (mut all_tables, mut all_views, mut all_user_defined_types) = if fetch_schema {
464466
(
465-
query_tables(conn).await?,
467+
query_tables(
468+
conn,
469+
"SELECT keyspace_name, table_name FROM system_schema.tables",
470+
)
471+
.await?,
472+
query_tables(
473+
conn,
474+
"SELECT keyspace_name, view_name FROM system_schema.views",
475+
)
476+
.await?,
466477
query_user_defined_types(conn).await?,
467478
)
468479
} else {
469-
(HashMap::new(), HashMap::new())
480+
(HashMap::new(), HashMap::new(), HashMap::new())
470481
};
471482

472483
for row in rows.into_typed::<(String, HashMap<String, String>)>() {
@@ -476,6 +487,7 @@ async fn query_keyspaces(
476487

477488
let strategy: Strategy = strategy_from_string_map(strategy_map)?;
478489
let tables = all_tables.remove(&keyspace_name).unwrap_or_default();
490+
let views = all_views.remove(&keyspace_name).unwrap_or_default();
479491
let user_defined_types = all_user_defined_types
480492
.remove(&keyspace_name)
481493
.unwrap_or_default();
@@ -485,6 +497,7 @@ async fn query_keyspaces(
485497
Keyspace {
486498
strategy,
487499
tables,
500+
views,
488501
user_defined_types,
489502
},
490503
);
@@ -533,8 +546,9 @@ async fn query_user_defined_types(
533546

534547
async fn query_tables(
535548
conn: &Connection,
549+
query_str: impl Into<String>,
536550
) -> Result<HashMap<String, HashMap<String, Table>>, QueryError> {
537-
let mut tables_query = Query::new("select keyspace_name, table_name from system_schema.tables");
551+
let mut tables_query = Query::new(query_str.into());
538552
tables_query.set_page_size(1024);
539553

540554
let rows = conn

0 commit comments

Comments
 (0)