39
39
from cassandra .encoder import Encoder
40
40
from cassandra .marshal import varint_unpack
41
41
from cassandra .protocol import QueryMessage
42
- from cassandra .query import dict_factory , bind_params , Statement
42
+ from cassandra .query import dict_factory , bind_params
43
43
from cassandra .util import OrderedDict
44
44
from cassandra .pool import HostDistance
45
45
@@ -408,9 +408,9 @@ def __init__(self, name, options_map):
408
408
self .options_map ['class' ] = self .name
409
409
410
410
def __eq__ (self , other ):
411
- return (isinstance (other , _UnknownStrategy )
412
- and self .name == other .name
413
- and self .options_map == other .options_map )
411
+ return (isinstance (other , _UnknownStrategy ) and
412
+ self .name == other .name and
413
+ self .options_map == other .options_map )
414
414
415
415
def export_for_schema (self ):
416
416
"""
@@ -658,11 +658,11 @@ def export_as_string(self):
658
658
Returns a CQL query string that can be used to recreate the entire keyspace,
659
659
including user-defined types and tables.
660
660
"""
661
- cql = "\n \n " .join ([self .as_cql_query () + ';' ]
662
- + self .user_type_strings ()
663
- + [f .export_as_string () for f in self .functions .values ()]
664
- + [a .export_as_string () for a in self .aggregates .values ()]
665
- + [t .export_as_string () for t in self .tables .values ()])
661
+ cql = "\n \n " .join ([self .as_cql_query () + ';' ] +
662
+ self .user_type_strings () +
663
+ [f .export_as_string () for f in self .functions .values ()] +
664
+ [a .export_as_string () for a in self .aggregates .values ()] +
665
+ [t .export_as_string () for t in self .tables .values ()])
666
666
if self ._exc_info :
667
667
import traceback
668
668
ret = "/*\n Warning: Keyspace %s is incomplete because of an error processing metadata.\n " % \
@@ -1530,6 +1530,7 @@ def __repr__(self):
1530
1530
return "<%s: %s>" % (self .__class__ .__name__ , self .value )
1531
1531
__str__ = __repr__
1532
1532
1533
+
1533
1534
MIN_LONG = - (2 ** 63 )
1534
1535
MAX_LONG = (2 ** 63 ) - 1
1535
1536
@@ -1870,8 +1871,8 @@ def _build_table_metadata(self, row, col_rows=None, trigger_rows=None):
1870
1871
is_compact = False
1871
1872
has_value = False
1872
1873
clustering_size = num_column_name_components - 2
1873
- elif (len (column_aliases ) == num_column_name_components - 1
1874
- and issubclass (last_col , types .UTF8Type )):
1874
+ elif (len (column_aliases ) == num_column_name_components - 1 and
1875
+ issubclass (last_col , types .UTF8Type )):
1875
1876
# aliases?
1876
1877
is_compact = False
1877
1878
has_value = False
@@ -2064,11 +2065,11 @@ def _query_all(self):
2064
2065
]
2065
2066
2066
2067
responses = self .connection .wait_for_responses (* queries , timeout = self .timeout , fail_on_error = False )
2067
- (ks_success , ks_result ), (table_success , table_result ), \
2068
- (col_success , col_result ), (types_success , types_result ), \
2069
- (functions_success , functions_result ), \
2070
- (aggregates_success , aggregates_result ), \
2071
- (triggers_success , triggers_result ) = responses
2068
+ (( ks_success , ks_result ), (table_success , table_result ),
2069
+ (col_success , col_result ), (types_success , types_result ),
2070
+ (functions_success , functions_result ),
2071
+ (aggregates_success , aggregates_result ),
2072
+ (triggers_success , triggers_result ) ) = responses
2072
2073
2073
2074
self .keyspaces_result = self ._handle_results (ks_success , ks_result )
2074
2075
self .tables_result = self ._handle_results (table_success , table_result )
@@ -2208,10 +2209,13 @@ def get_table(self, keyspaces, keyspace, table):
2208
2209
where_clause = bind_params (" WHERE keyspace_name = %s AND view_name = %s" , (keyspace , table ), _encoder )
2209
2210
view_query = QueryMessage (query = self ._SELECT_VIEWS + where_clause ,
2210
2211
consistency_level = cl )
2211
- (cf_success , cf_result ), (col_success , col_result ), (indexes_sucess , indexes_result ), \
2212
- (triggers_success , triggers_result ), (view_success , view_result ) \
2213
- = self .connection .wait_for_responses (cf_query , col_query , indexes_query , triggers_query , view_query ,
2214
- timeout = self .timeout , fail_on_error = False )
2212
+ ((cf_success , cf_result ), (col_success , col_result ),
2213
+ (indexes_sucess , indexes_result ), (triggers_success , triggers_result ),
2214
+ (view_success , view_result )) = (
2215
+ self .connection .wait_for_responses (
2216
+ cf_query , col_query , indexes_query , triggers_query ,
2217
+ view_query , timeout = self .timeout , fail_on_error = False )
2218
+ )
2215
2219
table_result = self ._handle_results (cf_success , cf_result )
2216
2220
col_result = self ._handle_results (col_success , col_result )
2217
2221
if table_result :
@@ -2372,13 +2376,13 @@ def _query_all(self):
2372
2376
]
2373
2377
2374
2378
responses = self .connection .wait_for_responses (* queries , timeout = self .timeout , fail_on_error = False )
2375
- (ks_success , ks_result ), (table_success , table_result ), \
2376
- (col_success , col_result ), (types_success , types_result ), \
2377
- (functions_success , functions_result ), \
2378
- (aggregates_success , aggregates_result ), \
2379
- (triggers_success , triggers_result ), \
2380
- (indexes_success , indexes_result ), \
2381
- (views_success , views_result ) = responses
2379
+ (( ks_success , ks_result ), (table_success , table_result ),
2380
+ (col_success , col_result ), (types_success , types_result ),
2381
+ (functions_success , functions_result ),
2382
+ (aggregates_success , aggregates_result ),
2383
+ (triggers_success , triggers_result ),
2384
+ (indexes_success , indexes_result ),
2385
+ (views_success , views_result ) ) = responses
2382
2386
2383
2387
self .keyspaces_result = self ._handle_results (ks_success , ks_result )
2384
2388
self .tables_result = self ._handle_results (table_success , table_result )
@@ -2410,6 +2414,10 @@ def _schema_type_to_cql(type_string):
2410
2414
return type_string
2411
2415
2412
2416
2417
+ class SchemaParserV4 (SchemaParserV3 ):
2418
+ pass
2419
+
2420
+
2413
2421
class TableMetadataV3 (TableMetadata ):
2414
2422
compaction_options = {}
2415
2423
@@ -2529,12 +2537,12 @@ def as_cql_query(self, formatted=False):
2529
2537
2530
2538
properties = TableMetadataV3 ._property_string (formatted , self .clustering_key , self .options )
2531
2539
2532
- ret = "CREATE MATERIALIZED VIEW %(keyspace)s.%(name)s AS%(sep)s" \
2533
- "SELECT %(selected_cols)s%(sep)s" \
2534
- "FROM %(keyspace)s.%(base_table)s%(sep)s" \
2535
- "WHERE %(where_clause)s%(sep)s" \
2536
- "PRIMARY KEY %(pk)s%(sep)s" \
2537
- "WITH %(properties)s" % locals ()
2540
+ ret = ( "CREATE MATERIALIZED VIEW %(keyspace)s.%(name)s AS%(sep)s"
2541
+ "SELECT %(selected_cols)s%(sep)s"
2542
+ "FROM %(keyspace)s.%(base_table)s%(sep)s"
2543
+ "WHERE %(where_clause)s%(sep)s"
2544
+ "PRIMARY KEY %(pk)s%(sep)s"
2545
+ "WITH %(properties)s" ) % locals ()
2538
2546
2539
2547
if self .extensions :
2540
2548
registry = _RegisteredExtensionType ._extension_registry
@@ -2551,6 +2559,8 @@ def export_as_string(self):
2551
2559
2552
2560
def get_schema_parser (connection , server_version , timeout ):
2553
2561
server_major_version = int (server_version .split ('.' )[0 ])
2562
+ if server_major_version >= 4 :
2563
+ return SchemaParserV4 (connection , timeout )
2554
2564
if server_major_version >= 3 :
2555
2565
return SchemaParserV3 (connection , timeout )
2556
2566
else :
0 commit comments