@@ -1667,8 +1667,30 @@ def __init__(self, connection, timeout):
1667
1667
self .connection = connection
1668
1668
self .timeout = timeout
1669
1669
1670
- def _handle_results (self , success , result ):
1671
- if success :
1670
+ def _handle_results (self , success , result , expected_failures = tuple ()):
1671
+ """
1672
+ Given a bool and a ResultSet (the form returned per result from
1673
+ Connection.wait_for_responses), return a dictionary containing the
1674
+ results. Used to process results from asynchronous queries to system
1675
+ tables.
1676
+
1677
+ ``expected_failures`` will usually be used to allow callers to ignore
1678
+ ``InvalidRequest`` errors caused by a missing system keyspace. For
1679
+ example, some DSE versions report a 4.X server version, but do not have
1680
+ virtual tables. Thus, running against 4.X servers, SchemaParserV4 uses
1681
+ expected_failures to make a best-effort attempt to read those
1682
+ keyspaces, but treat them as empty if they're not found.
1683
+
1684
+ :param success: A boolean representing whether or not the query
1685
+ succeeded
1686
+ :param result: The resultset in question.
1687
+ :expected_failures: An Exception class or an iterable thereof. If the
1688
+ query failed, but raised an instance of an expected failure class, this
1689
+ will ignore the failure and return an empty list.
1690
+ """
1691
+ if not success and isinstance (result , expected_failures ):
1692
+ return []
1693
+ elif success :
1672
1694
return dict_factory (* result .results ) if result else []
1673
1695
else :
1674
1696
raise result
@@ -1784,11 +1806,9 @@ def get_table(self, keyspaces, keyspace, table):
1784
1806
table_result = self ._handle_results (cf_success , cf_result )
1785
1807
col_result = self ._handle_results (col_success , col_result )
1786
1808
1787
- # handle the triggers table not existing in Cassandra 1.2
1788
- if not triggers_success and isinstance (triggers_result , InvalidRequest ):
1789
- triggers_result = []
1790
- else :
1791
- triggers_result = self ._handle_results (triggers_success , triggers_result )
1809
+ # the triggers table doesn't exist in C* 1.2
1810
+ triggers_result = self ._handle_results (triggers_success , triggers_result ,
1811
+ expected_failures = InvalidRequest )
1792
1812
1793
1813
if table_result :
1794
1814
return self ._build_table_metadata (table_result [0 ], col_result , triggers_result )
@@ -2531,12 +2551,21 @@ def _query_all(self):
2531
2551
self .indexes_result = self ._handle_results (indexes_success , indexes_result )
2532
2552
self .views_result = self ._handle_results (views_success , views_result )
2533
2553
# V4-only results
2534
- self .virtual_keyspaces_result = self ._handle_results (virtual_ks_success ,
2535
- virtual_ks_result )
2536
- self .virtual_tables_result = self ._handle_results (virtual_table_success ,
2537
- virtual_table_result )
2538
- self .virtual_columns_result = self ._handle_results (virtual_column_success ,
2539
- virtual_column_result )
2554
+ # These tables don't exist in some DSE versions reporting 4.X so we can
2555
+ # ignore them if we got an error
2556
+ self .virtual_keyspaces_result = self ._handle_results (
2557
+ virtual_ks_success , virtual_ks_result ,
2558
+ expected_failures = InvalidRequest
2559
+ )
2560
+ self .virtual_tables_result = self ._handle_results (
2561
+ virtual_table_success , virtual_table_result ,
2562
+ expected_failures = InvalidRequest
2563
+ )
2564
+ self .virtual_columns_result = self ._handle_results (
2565
+ virtual_column_success , virtual_column_result ,
2566
+ expected_failures = InvalidRequest
2567
+ )
2568
+
2540
2569
self ._aggregate_results ()
2541
2570
2542
2571
def _aggregate_results (self ):
@@ -2722,9 +2751,7 @@ def export_as_string(self):
2722
2751
2723
2752
def get_schema_parser (connection , server_version , timeout ):
2724
2753
server_major_version = int (server_version .split ('.' )[0 ])
2725
- # check for DSE version
2726
- has_build_version = len (server_version .split ('.' )) > 3
2727
- if server_major_version >= 4 and not has_build_version :
2754
+ if server_major_version >= 4 :
2728
2755
return SchemaParserV4 (connection , timeout )
2729
2756
if server_major_version >= 3 :
2730
2757
return SchemaParserV3 (connection , timeout )
0 commit comments