class Cassandra::Cluster::Schema::Fetchers::V3_0_x
Constants
- SELECT_AGGREGATE
- SELECT_AGGREGATES
- SELECT_COLUMNS
- SELECT_FUNCTION
- SELECT_FUNCTIONS
- SELECT_INDEXES
- SELECT_KEYSPACE
- SELECT_KEYSPACES
- SELECT_KEYSPACE_AGGREGATES
- SELECT_KEYSPACE_COLUMNS
- SELECT_KEYSPACE_FUNCTIONS
- SELECT_KEYSPACE_INDEXES
- SELECT_KEYSPACE_TABLES
- SELECT_KEYSPACE_TRIGGERS
- SELECT_KEYSPACE_TYPES
- SELECT_KEYSPACE_VIEWS
- SELECT_TABLE
- SELECT_TABLES
- SELECT_TABLE_COLUMNS
- SELECT_TABLE_INDEXES
- SELECT_TABLE_TRIGGERS
- SELECT_TRIGGERS
- SELECT_TYPE
- SELECT_TYPES
- SELECT_VIEW
- SELECT_VIEWS
Public Instance Methods
parse_argument_types(connection, keyspace_name, argument_types)
click to toggle source
parse an array of string argument types and return an array of [Cassandra::Type]s. @param connection a connection to a Cassandra
node. @param keyspace_name [String] name of the keyspace. @param argument_types [Array<String>] array of argument types. @return [Array<Cassandra::Type>] array of parsed types.
# File lib/cassandra/cluster/schema/fetchers.rb 1028 def parse_argument_types(connection, keyspace_name, argument_types) 1029 types = @schema.keyspace(keyspace_name).send(:raw_types) 1030 argument_types.map do |argument_type| 1031 @type_parser.parse(argument_type, types).first 1032 end 1033 end
Private Instance Methods
create_aggregate(aggregate_data, functions, types = nil)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1204 def create_aggregate(aggregate_data, functions, types = nil) 1205 keyspace_name = aggregate_data['keyspace_name'] 1206 aggregate_name = aggregate_data['aggregate_name'] 1207 types ||= @schema.keyspace(keyspace_name).send(:raw_types) 1208 aggregate_type = 1209 @type_parser.parse(aggregate_data['return_type'], types).first 1210 argument_types = aggregate_data['argument_types'].map do |argument_type| 1211 @type_parser.parse(argument_type, types).first 1212 end.freeze 1213 state_type = @type_parser.parse(aggregate_data['state_type'], types).first 1214 initial_state = aggregate_data['initcond'] || 'null' 1215 1216 # The state-function takes arguments: first the stype, then the args of the 1217 # aggregate. 1218 state_function = functions.get(aggregate_data['state_func'], 1219 [state_type].concat(argument_types)) 1220 1221 # The final-function takes an stype argument. 1222 final_function = functions.get(aggregate_data['final_func'], 1223 [state_type]) 1224 1225 Aggregate.new(keyspace_name, 1226 aggregate_name, 1227 aggregate_type, 1228 argument_types, 1229 state_type, 1230 initial_state, 1231 state_function, 1232 final_function) 1233 end
create_column(column_data, types)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1361 def create_column(column_data, types) 1362 name = column_data['column_name'] 1363 is_static = column_data['kind'].to_s.casecmp('STATIC').zero? 1364 order = column_data['clustering_order'] == 'desc' ? :desc : :asc 1365 if column_data['type'][0] == "'" 1366 # This is a custom column type. 1367 type = Types.custom(column_data['type'].slice(1, column_data['type'].length - 2)) 1368 is_frozen = false 1369 else 1370 type, is_frozen = @type_parser.parse(column_data['type'], types) 1371 end 1372 1373 Column.new(name, type, order, is_static, is_frozen) 1374 end
create_compaction_strategy(table_data)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1326 def create_compaction_strategy(table_data) 1327 options = table_data['compaction'] || {} 1328 klass = options.delete('class') || '' 1329 klass.slice!('org.apache.cassandra.db.compaction.') 1330 ColumnContainer::Compaction.new(klass, options) 1331 end
create_function(function_data, types = nil)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1178 def create_function(function_data, types = nil) 1179 keyspace_name = function_data['keyspace_name'] 1180 function_name = function_data['function_name'] 1181 function_lang = function_data['language'] 1182 types ||= @schema.keyspace(keyspace_name).send(:raw_types) 1183 function_type = @type_parser.parse(function_data['return_type'], types).first 1184 function_body = function_data['body'] 1185 called_on_null = function_data['called_on_null_input'] 1186 1187 arguments = [] 1188 1189 function_data['argument_names'] 1190 .zip(function_data['argument_types']) do |argument_name, argument_type| 1191 arguments << Argument.new(argument_name, 1192 @type_parser.parse(argument_type, types).first) 1193 end 1194 1195 Cassandra::Function.new(keyspace_name, 1196 function_name, 1197 function_lang, 1198 function_type, 1199 arguments, 1200 function_body, 1201 called_on_null) 1202 end
create_index(table, row_index)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1454 def create_index(table, row_index) 1455 options = row_index['options'] 1456 table.add_index(Cassandra::Index.new(table, row_index['index_name'], 1457 row_index['kind'].downcase.to_sym, 1458 options['target'], options)) 1459 end
create_keyspace(keyspace_data, rows_tables, rows_columns, rows_types, rows_functions, rows_aggregates, rows_views, rows_indexes, rows_triggers)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1270 def create_keyspace(keyspace_data, rows_tables, rows_columns, rows_types, 1271 rows_functions, rows_aggregates, rows_views, rows_indexes, rows_triggers) 1272 keyspace_name = keyspace_data['keyspace_name'] 1273 replication = create_replication(keyspace_data) 1274 1275 types = ::Hash.new 1276 create_types(rows_types, types) 1277 1278 # Create a FunctionCollection for the functions and aggregates. 1279 functions = Cassandra::FunctionCollection.new 1280 rows_functions.each do |row| 1281 functions.add_or_update(create_function(row, types)) 1282 end 1283 1284 aggregates = Cassandra::FunctionCollection.new 1285 rows_aggregates.each do |row| 1286 aggregates.add_or_update(create_aggregate(row, functions, types)) 1287 end 1288 1289 # lookup_columns is a hash of <table-name, rows_columns for that table>. 1290 # However, views are analogous to tables in this context, so we get 1291 # view columns organized by view-name also. 1292 1293 lookup_columns = map_rows_by(rows_columns, 'table_name') 1294 lookup_indexes = map_rows_by(rows_indexes, 'table_name') 1295 lookup_triggers = map_rows_by(rows_triggers, 'table_name') 1296 tables = rows_tables.each_with_object({}) do |row, h| 1297 table_name = row['table_name'] 1298 h[table_name] = create_table(row, lookup_columns[table_name], 1299 lookup_indexes[table_name], lookup_triggers[table_name], types) 1300 end 1301 1302 views = rows_views.each_with_object({}) do |row, h| 1303 view_name = row['view_name'] 1304 h[view_name] = create_materialized_view(row, 1305 lookup_columns[view_name], 1306 types) 1307 end 1308 1309 Keyspace.new(keyspace_name, 1310 keyspace_data['durable_writes'], 1311 replication, 1312 tables, 1313 types, 1314 functions, 1315 aggregates, 1316 views) 1317 end
create_materialized_view(view_data, rows_columns, types = nil)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1461 def create_materialized_view(view_data, rows_columns, types = nil) 1462 keyspace_name = view_data['keyspace_name'] 1463 view_name = view_data['view_name'] 1464 base_table_name = view_data['base_table_name'] 1465 include_all_columns = view_data['include_all_columns'] 1466 where_clause = view_data['where_clause'] 1467 1468 # Separate out partition key, clustering columns, other columns 1469 partition_key = [] 1470 clustering_columns = [] 1471 other_columns = [] 1472 types ||= @schema.keyspace(keyspace_name).send(:raw_types) 1473 1474 rows_columns.each do |row| 1475 next if row['column_name'].empty? 1476 1477 column = create_column(row, types) 1478 kind = row['kind'].to_s 1479 index = row['position'] || 0 1480 1481 case kind.upcase 1482 when 'PARTITION_KEY' 1483 partition_key[index] = column 1484 when 'CLUSTERING' 1485 clustering_columns[index] = column 1486 else 1487 other_columns << column 1488 end 1489 end 1490 1491 compaction_strategy = create_compaction_strategy(view_data) 1492 view_options = create_table_options(view_data, compaction_strategy, false) 1493 1494 MaterializedView.new(@schema.keyspace(keyspace_name), 1495 view_name, 1496 partition_key, 1497 clustering_columns, 1498 other_columns, 1499 view_options, 1500 include_all_columns, 1501 where_clause, 1502 base_table_name, 1503 view_data['id']) 1504 end
create_replication(keyspace_data)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1319 def create_replication(keyspace_data) 1320 options = keyspace_data['replication'] 1321 klass = options.delete('class') 1322 klass.slice!(REPLICATION_PACKAGE_PREFIX) 1323 Keyspace::Replication.new(klass, options) 1324 end
create_table(table_data, rows_columns, rows_indexes, rows_triggers, types = nil)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1376 def create_table(table_data, rows_columns, rows_indexes, rows_triggers, types = nil) 1377 keyspace_name = table_data['keyspace_name'] 1378 table_name = table_data['table_name'] 1379 table_flags = table_data['flags'] 1380 1381 is_dense = table_flags.include?('dense') 1382 is_super = table_flags.include?('super') 1383 is_compound = table_flags.include?('compound') 1384 is_compact = is_super || is_dense || !is_compound 1385 is_static_compact = !is_super && !is_dense && !is_compound 1386 1387 # Separate out partition-key, clustering columns, other columns. 1388 partition_key = [] 1389 clustering_columns = [] 1390 clustering_order = [] 1391 other_columns = [] 1392 types ||= @schema.keyspace(keyspace_name).send(:raw_types) 1393 1394 rows_columns.each do |row| 1395 next if row['column_name'].empty? 1396 1397 kind = row['kind'].to_s 1398 index = row['position'] || 0 1399 1400 if is_static_compact 1401 if kind.casecmp('CLUSTERING').zero? || kind.casecmp('REGULAR').zero? 1402 # Skip clustering columns in static-compact tables; they are internal to C*. 1403 # Oddly so are regular columns. 1404 next 1405 end 1406 if kind.casecmp('STATIC').zero? 1407 # Coerce static type to regular. 1408 kind = 'REGULAR' 1409 row['kind'] = 'regular' 1410 end 1411 end 1412 1413 column = create_column(row, types) 1414 case kind.upcase 1415 when 'PARTITION_KEY' 1416 partition_key[index] = column 1417 when 'CLUSTERING' 1418 clustering_columns[index] = column 1419 clustering_order[index] = column.order 1420 else 1421 other_columns << column 1422 end 1423 end 1424 1425 # Default the crc_check_chance to 1.0 (Java driver does this, so we 1426 # should, too). 1427 table_data['crc_check_chance'] ||= 1.0 1428 compaction_strategy = create_compaction_strategy(table_data) 1429 table_options = 1430 create_table_options(table_data, compaction_strategy, is_compact) 1431 1432 table = Cassandra::Table.new(@schema.keyspace(keyspace_name), 1433 table_name, 1434 partition_key, 1435 clustering_columns, 1436 other_columns, 1437 table_options, 1438 clustering_order, 1439 table_data['id']) 1440 rows_indexes.each do |row| 1441 create_index(table, row) 1442 end 1443 1444 # Create Trigger objects and add them to the table. 1445 rows_triggers.each do |row_trigger| 1446 table.add_trigger(Cassandra::Trigger.new(table, 1447 row_trigger['trigger_name'], 1448 row_trigger['options'])) 1449 end 1450 1451 table 1452 end
create_table_options(table_data, compaction_strategy, is_compact)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1333 def create_table_options(table_data, compaction_strategy, is_compact) 1334 compression = table_data['compression'] || {} 1335 compression['class'].slice!(COMPRESSION_PACKAGE_PREFIX) if compression['class'] 1336 1337 Cassandra::ColumnContainer::Options.new( 1338 table_data['comment'], 1339 table_data['read_repair_chance'], 1340 table_data['dclocal_read_repair_chance'], 1341 table_data['gc_grace_seconds'], 1342 table_data['caching'], 1343 table_data['bloom_filter_fp_chance'], 1344 nil, 1345 table_data['memtable_flush_period_in_ms'], 1346 table_data['default_time_to_live'], 1347 table_data['speculative_retry'], 1348 nil, 1349 nil, 1350 table_data['min_index_interval'], 1351 table_data['max_index_interval'], 1352 compaction_strategy, 1353 compression, 1354 is_compact, 1355 table_data['crc_check_chance'], 1356 table_data['extensions'], 1357 table_data['cdc'] 1358 ) 1359 end
create_types(rows_types, types)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1235 def create_types(rows_types, types) 1236 skipped_rows = ::Array.new 1237 1238 loop do 1239 rows_size = rows_types.size 1240 1241 until rows_types.empty? 1242 type_data = rows_types.shift 1243 type_name = type_data['type_name'] 1244 type_keyspace = type_data['keyspace_name'] 1245 type_fields = ::Array.new 1246 1247 begin 1248 field_names = type_data['field_names'] 1249 field_types = type_data['field_types'] 1250 field_names.each_with_index do |field_name, i| 1251 field_type = @type_parser.parse(field_types[i], types).first 1252 type_fields << [field_name, field_type] 1253 end 1254 1255 types[type_name] = Types.udt(type_keyspace, type_name, type_fields) 1256 rescue CQLTypeParser::IncompleteTypeError 1257 skipped_rows << type_data 1258 next 1259 end 1260 end 1261 1262 break if skipped_rows.empty? 1263 1264 raise 'Unable to resolve circular references among UDTs when parsing' if rows_size == skipped_rows.size 1265 1266 rows_types, skipped_rows = skipped_rows, rows_types 1267 end 1268 end
select_aggregate(connection, keyspace_name, aggregate_name, aggregate_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1172 def select_aggregate(connection, keyspace_name, aggregate_name, aggregate_args) 1173 params = [keyspace_name, aggregate_name, aggregate_args.map(&:to_s)] 1174 hints = [Types.varchar, Types.varchar, Types.list(Types.varchar)] 1175 send_select_request(connection, SELECT_AGGREGATE, params, hints) 1176 end
select_aggregates(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1069 def select_aggregates(connection) 1070 send_select_request(connection, SELECT_AGGREGATES) 1071 end
select_columns(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1053 def select_columns(connection) 1054 send_select_request(connection, SELECT_COLUMNS) 1055 end
select_function(connection, keyspace_name, function_name, function_args)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1166 def select_function(connection, keyspace_name, function_name, function_args) 1167 params = [keyspace_name, function_name, function_args.map(&:to_s)] 1168 hints = [Types.varchar, Types.varchar, Types.list(Types.varchar)] 1169 send_select_request(connection, SELECT_FUNCTION, params, hints) 1170 end
select_functions(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1065 def select_functions(connection) 1066 send_select_request(connection, SELECT_FUNCTIONS) 1067 end
select_indexes(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1045 def select_indexes(connection) 1046 send_select_request(connection, SELECT_INDEXES) 1047 end
select_keyspace(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1073 def select_keyspace(connection, keyspace_name) 1074 params = [keyspace_name] 1075 hints = [Types.varchar] 1076 send_select_request(connection, SELECT_KEYSPACE, params, hints) 1077 end
select_keyspace_aggregates(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1121 def select_keyspace_aggregates(connection, keyspace_name) 1122 params = [keyspace_name] 1123 hints = [Types.varchar] 1124 send_select_request(connection, SELECT_KEYSPACE_AGGREGATES, params, hints) 1125 end
select_keyspace_columns(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1085 def select_keyspace_columns(connection, keyspace_name) 1086 params = [keyspace_name] 1087 hints = [Types.varchar] 1088 send_select_request(connection, SELECT_KEYSPACE_COLUMNS, params, hints) 1089 end
select_keyspace_functions(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1115 def select_keyspace_functions(connection, keyspace_name) 1116 params = [keyspace_name] 1117 hints = [Types.varchar] 1118 send_select_request(connection, SELECT_KEYSPACE_FUNCTIONS, params, hints) 1119 end
select_keyspace_indexes(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1091 def select_keyspace_indexes(connection, keyspace_name) 1092 params = [keyspace_name] 1093 hints = [Types.varchar] 1094 send_select_request(connection, SELECT_KEYSPACE_INDEXES, params, hints) 1095 end
select_keyspace_materialized_views(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1097 def select_keyspace_materialized_views(connection, keyspace_name) 1098 params = [keyspace_name] 1099 hints = [Types.varchar] 1100 send_select_request(connection, SELECT_KEYSPACE_VIEWS, params, hints) 1101 end
select_keyspace_tables(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1079 def select_keyspace_tables(connection, keyspace_name) 1080 params = [keyspace_name] 1081 hints = [Types.varchar] 1082 send_select_request(connection, SELECT_KEYSPACE_TABLES, params, hints) 1083 end
select_keyspace_triggers(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1103 def select_keyspace_triggers(connection, keyspace_name) 1104 params = [keyspace_name] 1105 hints = [Types.varchar] 1106 send_select_request(connection, SELECT_KEYSPACE_TRIGGERS, params, hints) 1107 end
select_keyspace_types(connection, keyspace_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1109 def select_keyspace_types(connection, keyspace_name) 1110 params = [keyspace_name] 1111 hints = [Types.varchar] 1112 send_select_request(connection, SELECT_KEYSPACE_TYPES, params, hints) 1113 end
select_keyspaces(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1037 def select_keyspaces(connection) 1038 send_select_request(connection, SELECT_KEYSPACES) 1039 end
select_materialized_view(connection, keyspace_name, view_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1148 def select_materialized_view(connection, keyspace_name, view_name) 1149 params = [keyspace_name, view_name] 1150 hints = [Types.varchar, Types.varchar] 1151 send_select_request(connection, SELECT_VIEW, params, hints) 1152 end
select_materialized_views(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1049 def select_materialized_views(connection) 1050 send_select_request(connection, SELECT_VIEWS) 1051 end
select_table(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1127 def select_table(connection, keyspace_name, table_name) 1128 params = [keyspace_name, table_name] 1129 hints = [Types.varchar, Types.varchar] 1130 send_select_request(connection, SELECT_TABLE, params, hints) 1131 end
select_table_columns(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1133 def select_table_columns(connection, keyspace_name, table_name) 1134 # This is identical to the 2.0 impl, but the SELECT_TABLE_COLUMNS query 1135 # is different between the two, so we need two impls. :( 1136 # Also, this method works fine for finding view columns as well. 1137 params = [keyspace_name, table_name] 1138 hints = [Types.varchar, Types.varchar] 1139 send_select_request(connection, SELECT_TABLE_COLUMNS, params, hints) 1140 end
select_table_indexes(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1142 def select_table_indexes(connection, keyspace_name, table_name) 1143 params = [keyspace_name, table_name] 1144 hints = [Types.varchar, Types.varchar] 1145 send_select_request(connection, SELECT_TABLE_INDEXES, params, hints) 1146 end
select_table_triggers(connection, keyspace_name, table_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1154 def select_table_triggers(connection, keyspace_name, table_name) 1155 params = [keyspace_name, table_name] 1156 hints = [Types.varchar, Types.varchar] 1157 send_select_request(connection, SELECT_TABLE_TRIGGERS, params, hints) 1158 end
select_tables(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1041 def select_tables(connection) 1042 send_select_request(connection, SELECT_TABLES) 1043 end
select_triggers(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1057 def select_triggers(connection) 1058 send_select_request(connection, SELECT_TRIGGERS) 1059 end
select_type(connection, keyspace_name, type_name)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1160 def select_type(connection, keyspace_name, type_name) 1161 params = [keyspace_name, type_name] 1162 hints = [Types.varchar, Types.varchar] 1163 send_select_request(connection, SELECT_TYPE, params, hints) 1164 end
select_types(connection)
click to toggle source
# File lib/cassandra/cluster/schema/fetchers.rb 1061 def select_types(connection) 1062 send_select_request(connection, SELECT_TYPES) 1063 end