module Cassandra::Cluster::Schema::Fetcher
@private
Constants
- COMPRESSION_PACKAGE_PREFIX
- FUTURE_EMPTY_LIST
- REPLICATION_PACKAGE_PREFIX
Public Instance Methods
fetch(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 28 def fetch(connection) 29 # rubocop:disable Metrics/LineLength 30 Ione::Future.all(select_keyspaces(connection), 31 select_tables(connection), 32 select_columns(connection), 33 select_types(connection), 34 select_functions(connection), 35 select_aggregates(connection), 36 select_materialized_views(connection), 37 select_indexes(connection), 38 select_triggers(connection)) 39 .map do |rows_keyspaces, rows_tables, rows_columns, rows_types, rows_functions, rows_aggregates, rows_views, rows_indexes, rows_triggers| 40 lookup_tables = map_rows_by(rows_tables, 'keyspace_name') 41 lookup_columns = map_rows_by(rows_columns, 'keyspace_name') 42 lookup_types = map_rows_by(rows_types, 'keyspace_name') 43 lookup_functions = map_rows_by(rows_functions, 'keyspace_name') 44 lookup_aggregates = map_rows_by(rows_aggregates, 'keyspace_name') 45 lookup_views = map_rows_by(rows_views, 'keyspace_name') 46 lookup_indexes = map_rows_by(rows_indexes, 'keyspace_name') 47 lookup_triggers = map_rows_by(rows_triggers, 'keyspace_name') 48 49 rows_keyspaces.map do |keyspace_data| 50 name = keyspace_data['keyspace_name'] 51 52 create_keyspace(keyspace_data, 53 lookup_tables[name], 54 lookup_columns[name], 55 lookup_types[name], 56 lookup_functions[name], 57 lookup_aggregates[name], 58 lookup_views[name], 59 lookup_indexes[name], 60 lookup_triggers[name]) 61 end 62 end 63 end
fetch_aggregate(connection, keyspace_name, aggregate_name, aggregate_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 144 def fetch_aggregate(connection, keyspace_name, aggregate_name, aggregate_args) 145 select_aggregate(connection, keyspace_name, aggregate_name, aggregate_args) 146 .map do |rows_aggregates| 147 if rows_aggregates.empty? 148 nil 149 else 150 create_aggregate(rows_aggregates.first, @schema.keyspace(keyspace_name) 151 .send(:raw_functions)) 152 end 153 end 154 end
fetch_function(connection, keyspace_name, function_name, function_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 133 def fetch_function(connection, keyspace_name, function_name, function_args) 134 select_function(connection, keyspace_name, function_name, function_args) 135 .map do |rows_functions| 136 if rows_functions.empty? 137 nil 138 else 139 create_function(rows_functions.first) 140 end 141 end 142 end
fetch_keyspace(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 65 def fetch_keyspace(connection, keyspace_name) 66 Ione::Future.all(select_keyspace(connection, keyspace_name), 67 select_keyspace_tables(connection, keyspace_name), 68 select_keyspace_columns(connection, keyspace_name), 69 select_keyspace_types(connection, keyspace_name), 70 select_keyspace_functions(connection, keyspace_name), 71 select_keyspace_aggregates(connection, keyspace_name), 72 select_keyspace_materialized_views(connection, keyspace_name), 73 select_keyspace_indexes(connection, keyspace_name), 74 select_keyspace_triggers(connection, keyspace_name)) 75 .map do |rows_keyspaces, rows_tables, rows_columns, rows_types, rows_functions, rows_aggregates, rows_views, rows_indexes, rows_triggers| 76 if rows_keyspaces.empty? 77 nil 78 else 79 create_keyspace(rows_keyspaces.first, 80 rows_tables, 81 rows_columns, 82 rows_types, 83 rows_functions, 84 rows_aggregates, 85 rows_views, 86 rows_indexes, 87 rows_triggers) 88 end 89 end 90 end
fetch_materialized_view(connection, keyspace_name, view_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 109 def fetch_materialized_view(connection, keyspace_name, view_name) 110 Ione::Future.all(select_materialized_view(connection, keyspace_name, view_name), 111 select_table_columns(connection, keyspace_name, view_name)) 112 .map do |rows_views, rows_columns| 113 if rows_views.empty? 114 nil 115 else 116 view_row = rows_views.first 117 create_materialized_view(view_row, 118 rows_columns) 119 end 120 end 121 end
fetch_table(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 92 def fetch_table(connection, keyspace_name, table_name) 93 Ione::Future.all(select_table(connection, keyspace_name, table_name), 94 select_table_columns(connection, keyspace_name, table_name), 95 select_table_indexes(connection, keyspace_name, table_name), 96 select_table_triggers(connection, keyspace_name, table_name)) 97 .map do |(rows_tables, rows_columns, rows_indexes, rows_triggers)| 98 if rows_tables.empty? 99 nil 100 else 101 create_table(rows_tables.first, 102 rows_columns, 103 rows_indexes, 104 rows_triggers) 105 end 106 end 107 end
fetch_type(connection, keyspace_name, type_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 123 def fetch_type(connection, keyspace_name, type_name) 124 select_type(connection, keyspace_name, type_name).map do |rows_types| 125 if rows_types.empty? 126 nil 127 else 128 create_type(rows_types.first) 129 end 130 end 131 end
Private Instance Methods
map_rows_by(rows, key_name) { |row| ... }
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 280 def map_rows_by(rows, key_name, &block) 281 rows.each_with_object(::Hash.new { EMPTY_LIST }) do |row, map| 282 key = row[key_name] 283 map[key] = [] unless map.key?(key) 284 285 map[key] << if block 286 yield(row) 287 else 288 row 289 end 290 end 291 end
select_aggregate(connection, keyspace_name, aggregate_name, aggregate_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 258 def select_aggregate(connection, keyspace_name, aggregate_name, aggregate_args) 259 FUTURE_EMPTY_LIST 260 end
select_aggregates(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 190 def select_aggregates(connection) 191 FUTURE_EMPTY_LIST 192 end
select_columns(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 170 def select_columns(connection) 171 FUTURE_EMPTY_LIST 172 end
select_function(connection, keyspace_name, function_name, function_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 254 def select_function(connection, keyspace_name, function_name, function_args) 255 FUTURE_EMPTY_LIST 256 end
select_functions(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 186 def select_functions(connection) 187 FUTURE_EMPTY_LIST 188 end
select_indexes(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 174 def select_indexes(connection) 175 FUTURE_EMPTY_LIST 176 end
select_keyspace(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 194 def select_keyspace(connection, keyspace_name) 195 FUTURE_EMPTY_LIST 196 end
select_keyspace_aggregates(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 226 def select_keyspace_aggregates(connection, keyspace_name) 227 FUTURE_EMPTY_LIST 228 end
select_keyspace_columns(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 206 def select_keyspace_columns(connection, keyspace_name) 207 FUTURE_EMPTY_LIST 208 end
select_keyspace_functions(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 222 def select_keyspace_functions(connection, keyspace_name) 223 FUTURE_EMPTY_LIST 224 end
select_keyspace_indexes(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 210 def select_keyspace_indexes(connection, keyspace_name) 211 FUTURE_EMPTY_LIST 212 end
select_keyspace_materialized_views(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 202 def select_keyspace_materialized_views(connection, keyspace_name) 203 FUTURE_EMPTY_LIST 204 end
select_keyspace_tables(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 198 def select_keyspace_tables(connection, keyspace_name) 199 FUTURE_EMPTY_LIST 200 end
select_keyspace_triggers(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 214 def select_keyspace_triggers(connection, keyspace_name) 215 FUTURE_EMPTY_LIST 216 end
select_keyspace_types(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 218 def select_keyspace_types(connection, keyspace_name) 219 FUTURE_EMPTY_LIST 220 end
select_keyspaces(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 158 def select_keyspaces(connection) 159 FUTURE_EMPTY_LIST 160 end
select_materialized_view(connection, keyspace_name, view_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 234 def select_materialized_view(connection, keyspace_name, view_name) 235 FUTURE_EMPTY_LIST 236 end
select_materialized_views(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 166 def select_materialized_views(connection) 167 FUTURE_EMPTY_LIST 168 end
select_table(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 230 def select_table(connection, keyspace_name, table_name) 231 FUTURE_EMPTY_LIST 232 end
select_table_columns(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 238 def select_table_columns(connection, keyspace_name, table_name) 239 FUTURE_EMPTY_LIST 240 end
select_table_indexes(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 242 def select_table_indexes(connection, keyspace_name, table_name) 243 FUTURE_EMPTY_LIST 244 end
select_table_triggers(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 246 def select_table_triggers(connection, keyspace_name, table_name) 247 FUTURE_EMPTY_LIST 248 end
select_tables(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 162 def select_tables(connection) 163 FUTURE_EMPTY_LIST 164 end
select_triggers(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 178 def select_triggers(connection) 179 FUTURE_EMPTY_LIST 180 end
select_type(connection, keyspace_name, type_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 250 def select_type(connection, keyspace_name, type_name) 251 FUTURE_EMPTY_LIST 252 end
select_types(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 182 def select_types(connection) 183 FUTURE_EMPTY_LIST 184 end
send_select_request(connection, cql, params = EMPTY_LIST, types = EMPTY_LIST)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 262 def send_select_request(connection, cql, params = EMPTY_LIST, types = EMPTY_LIST) 263 backtrace = caller 264 connection.send_request( 265 Protocol::QueryRequest.new(cql, params, types, :one) 266 ).map do |r| 267 case r 268 when Protocol::RowsResultResponse 269 r.rows 270 when Protocol::ErrorResponse 271 e = r.to_error(nil, VOID_STATEMENT, VOID_OPTIONS, EMPTY_LIST, :one, 0) 272 e.set_backtrace(backtrace) 273 raise e 274 else 275 raise Errors::InternalError, "Unexpected response #{r.inspect}", caller 276 end 277 end 278 end