Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cassandra/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ def export_schema_as_string(self):
def refresh(self, connection, timeout, target_type=None, change_type=None, fetch_size=None,
metadata_request_timeout=None, **kwargs):

server_version = self.get_host(connection.original_endpoint).release_version
dse_version = self.get_host(connection.original_endpoint).dse_version
host = self.get_host(connection.original_endpoint)
server_version = host.release_version if host else None
dse_version = host.dse_version if host else None
parser = get_schema_parser(connection, server_version, dse_version, timeout, metadata_request_timeout, fetch_size)

if not target_type:
Expand Down Expand Up @@ -3410,7 +3411,21 @@ def __init__(


def get_schema_parser(connection, server_version, dse_version, timeout, metadata_request_timeout, fetch_size=None):
version = Version(server_version)
if server_version is None and dse_version is None:
local_query = QueryMessage(
query=maybe_add_timeout_to_query(
"SELECT * FROM system.local WHERE key='local'",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need '*' here? Unsure, but I'm unsure if it matters much, or at all.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system.local has a lot of stuff not needed by the driver, we should not use *.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata_request_timeout),
consistency_level=ConsistencyLevel.ONE)
success, local_result = connection.wait_for_response(
local_query, timeout=timeout, fail_on_error=False)
if success and local_result.parsed_rows:
local_rows = dict_factory(local_result.column_names, local_result.parsed_rows)
local_row = local_rows[0]
server_version = local_row.get("release_version")
dse_version = local_row.get("dse_version")

version = Version(server_version or "0")
if dse_version:
v = Version(dse_version)
if v >= Version('6.8.0'):
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
UserType, KeyspaceMetadata, get_schema_parser,
_UnknownStrategy, ColumnMetadata, TableMetadata,
IndexMetadata, Function, Aggregate,
Metadata, TokenMap, ReplicationFactor)
Metadata, TokenMap, ReplicationFactor,
SchemaParserDSE68)
from cassandra.policies import SimpleConvictionPolicy
from cassandra.pool import Host
from tests.util import assertCountEqual
Expand Down Expand Up @@ -616,6 +617,22 @@ def test_build_index_as_cql(self):
assert index_meta.as_cql_query() == "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'"


class SchemaParserLookupTests(unittest.TestCase):

def test_reads_versions_from_system_local_when_missing(self):
connection = Mock()
local_result = Mock()
local_result.column_names = ["release_version", "dse_version"]
local_result.parsed_rows = [["4.0.0", "6.8.0"]]
connection.wait_for_response.return_value = (True, local_result)

parser = get_schema_parser(connection, None, None, 0.1, None)

assert isinstance(parser, SchemaParserDSE68)
message = connection.wait_for_response.call_args[0][0]
assert "system.local" in message.query


class UnicodeIdentifiersTests(unittest.TestCase):
"""
Exercise cql generation with unicode characters. Keyspace, Table, and Index names
Expand Down
Loading