@@ -54,6 +54,10 @@ use crate::errors::{
5454 ProtocolError , TablesMetadataError , UdtMetadataError , ViewsMetadataError ,
5555} ;
5656
57+ type PerKeyspace < T > = HashMap < String , T > ;
58+ type PerTable < T > = HashMap < String , T > ;
59+ type PerKsTable < T > = HashMap < ( String , String ) , T > ;
60+
5761/// Allows to read current metadata from the cluster
5862pub ( crate ) struct MetadataReader {
5963 connection_config : ConnectionConfig ,
@@ -221,7 +225,7 @@ impl PreCqlType {
221225 pub ( crate ) fn into_cql_type (
222226 self ,
223227 keyspace_name : & String ,
224- keyspace_udts : & HashMap < String , Arc < UserDefinedType > > ,
228+ keyspace_udts : & PerTable < Arc < UserDefinedType > > ,
225229 ) -> CqlType {
226230 match self {
227231 PreCqlType :: Native ( n) => CqlType :: Native ( n) ,
@@ -357,7 +361,7 @@ impl PreCollectionType {
357361 pub ( crate ) fn into_collection_type (
358362 self ,
359363 keyspace_name : & String ,
360- keyspace_udts : & HashMap < String , Arc < UserDefinedType > > ,
364+ keyspace_udts : & PerTable < Arc < UserDefinedType > > ,
361365 ) -> CollectionType {
362366 match self {
363367 PreCollectionType :: List ( t) => {
@@ -998,7 +1002,7 @@ async fn query_keyspaces(
9981002 conn : & Arc < Connection > ,
9991003 keyspaces_to_fetch : & [ String ] ,
10001004 fetch_schema : bool ,
1001- ) -> Result < HashMap < String , Keyspace > , QueryError > {
1005+ ) -> Result < PerKeyspace < Keyspace > , QueryError > {
10021006 let rows = query_filter_keyspace_name :: < ( String , HashMap < String , String > ) > (
10031007 conn,
10041008 "select keyspace_name, replication from system_schema.keyspaces" ,
@@ -1099,7 +1103,7 @@ impl TryFrom<UdtRow> for UdtRowWithParsedFieldTypes {
10991103async fn query_user_defined_types (
11001104 conn : & Arc < Connection > ,
11011105 keyspaces_to_fetch : & [ String ] ,
1102- ) -> Result < HashMap < String , HashMap < String , Arc < UserDefinedType > > > , QueryError > {
1106+ ) -> Result < PerKeyspace < PerTable < Arc < UserDefinedType > > > , QueryError > {
11031107 let rows = query_filter_keyspace_name :: < UdtRow > (
11041108 conn,
11051109 "select keyspace_name, type_name, field_names, field_types from system_schema.types" ,
@@ -1419,8 +1423,8 @@ mod toposort_tests {
14191423async fn query_tables (
14201424 conn : & Arc < Connection > ,
14211425 keyspaces_to_fetch : & [ String ] ,
1422- tables : & mut HashMap < ( String , String ) , Table > ,
1423- ) -> Result < HashMap < String , HashMap < String , Table > > , QueryError > {
1426+ tables : & mut PerKsTable < Table > ,
1427+ ) -> Result < PerKeyspace < PerTable < Table > > , QueryError > {
14241428 let rows = query_filter_keyspace_name :: < ( String , String ) > (
14251429 conn,
14261430 "SELECT keyspace_name, table_name FROM system_schema.tables" ,
@@ -1455,8 +1459,8 @@ async fn query_tables(
14551459async fn query_views (
14561460 conn : & Arc < Connection > ,
14571461 keyspaces_to_fetch : & [ String ] ,
1458- tables : & mut HashMap < ( String , String ) , Table > ,
1459- ) -> Result < HashMap < String , HashMap < String , MaterializedView > > , QueryError > {
1462+ tables : & mut PerKsTable < Table > ,
1463+ ) -> Result < PerKeyspace < PerTable < MaterializedView > > , QueryError > {
14601464 let rows = query_filter_keyspace_name :: < ( String , String , String ) > (
14611465 conn,
14621466 "SELECT keyspace_name, view_name, base_table_name FROM system_schema.views" ,
@@ -1498,8 +1502,8 @@ async fn query_views(
14981502async fn query_tables_schema (
14991503 conn : & Arc < Connection > ,
15001504 keyspaces_to_fetch : & [ String ] ,
1501- udts : & HashMap < String , HashMap < String , Arc < UserDefinedType > > > ,
1502- ) -> Result < HashMap < ( String , String ) , Table > , QueryError > {
1505+ udts : & PerKeyspace < PerTable < Arc < UserDefinedType > > > ,
1506+ ) -> Result < PerKsTable < Table > , QueryError > {
15031507 // Upon migration from thrift to CQL, Cassandra internally creates a surrogate column "value" of
15041508 // type EmptyType for dense tables. This resolves into this CQL type name.
15051509 // This column shouldn't be exposed to the user but is currently exposed in system tables.
@@ -1736,7 +1740,7 @@ fn freeze_type(type_: PreCqlType) -> PreCqlType {
17361740
17371741async fn query_table_partitioners (
17381742 conn : & Arc < Connection > ,
1739- ) -> Result < HashMap < ( String , String ) , Option < String > > , QueryError > {
1743+ ) -> Result < PerKsTable < Option < String > > , QueryError > {
17401744 let mut partitioner_query = Query :: new (
17411745 "select keyspace_name, table_name, partitioner from system_schema.scylla_tables" ,
17421746 ) ;
0 commit comments