Skip to content

Commit

Permalink
Don't fetch aggregates/UDFs on version 2.1 (apache#1265)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Muir Manders authored and Zariel committed Feb 8, 2019
1 parent 252acab commit c53c365
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type Session struct {
schemaEvents *eventDebouncer

// ring metadata
hosts []HostInfo
useSystemSchema bool
hosts []HostInfo
useSystemSchema bool
hasAggregatesAndFunctions bool

cfg ClusterConfig

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c53c365

Please sign in to comment.