From c53c3654dc8acfc0ace976e1535cb0b8abb027a4 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Fri, 8 Feb 2019 14:11:38 -0800 Subject: [PATCH] Don't fetch aggregates/UDFs on version 2.1 (#1265) The system.schema_aggregates and system.schema_functions tables don't exists in 2.1 (these were added in 2.2). I added a version.AtLeast() function that inverts version.Before(). Normally you are checking for a minimum version, so this avoids additional negatives and makes things more readable. --- host_source.go | 4 ++++ metadata.go | 4 ++-- session.go | 10 ++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/host_source.go b/host_source.go index 8d95e5d6d..97f9455b7 100644 --- a/host_source.go +++ b/host_source.go @@ -89,6 +89,10 @@ func (c cassVersion) Before(major, minor, patch int) bool { return false } +func (c cassVersion) AtLeast(major, minor, patch int) bool { + return !c.Before(major, minor, patch) +} + func (c cassVersion) String() string { return fmt.Sprintf("v%d.%d.%d", c.Major, c.Minor, c.Patch) } diff --git a/metadata.go b/metadata.go index a691dfa1a..5a17559b0 100644 --- a/metadata.go +++ b/metadata.go @@ -913,7 +913,7 @@ func getViewsMetadata(session *Session, keyspaceName string) ([]ViewMetadata, er } func getFunctionsMetadata(session *Session, keyspaceName string) ([]FunctionMetadata, error) { - if session.cfg.ProtoVersion == protoVersion1 { + if session.cfg.ProtoVersion == protoVersion1 || !session.hasAggregatesAndFunctions { return nil, nil } var tableName string @@ -968,7 +968,7 @@ func getFunctionsMetadata(session *Session, keyspaceName string) ([]FunctionMeta } func getAggregatesMetadata(session *Session, keyspaceName string) ([]AggregateMetadata, error) { - if session.cfg.ProtoVersion == protoVersion1 { + if session.cfg.ProtoVersion == protoVersion1 || !session.hasAggregatesAndFunctions { return nil, nil } var tableName string diff --git a/session.go b/session.go index e88da5303..28331612c 100644 --- a/session.go +++ b/session.go @@ -62,8 +62,9 @@ type Session struct { schemaEvents *eventDebouncer // ring metadata - hosts []HostInfo - useSystemSchema bool + hosts []HostInfo + useSystemSchema bool + hasAggregatesAndFunctions bool cfg ClusterConfig @@ -240,8 +241,9 @@ func (s *Session) init() error { newer, _ := checkSystemSchema(s.control) s.useSystemSchema = newer } else { - host := s.ring.rrHost() - s.useSystemSchema = host.Version().Major >= 3 + version := s.ring.rrHost().Version() + s.useSystemSchema = version.AtLeast(3, 0, 0) + s.hasAggregatesAndFunctions = version.AtLeast(2, 2, 0) } if s.pool.Size() == 0 {