Skip to content

Commit

Permalink
some deprecated features were removed
Browse files Browse the repository at this point in the history
  • Loading branch information
tengu-alt committed Nov 15, 2024
1 parent 34fdeeb commit 0e38c4c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 151 deletions.
46 changes: 1 addition & 45 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"
"unicode"

inf "gopkg.in/inf.v0"
"gopkg.in/inf.v0"
)

func TestEmptyHosts(t *testing.T) {
Expand Down Expand Up @@ -2199,45 +2199,6 @@ func TestGetColumnMetadata(t *testing.T) {
}
}

func TestViewMetadata(t *testing.T) {
session := createSession(t)
defer session.Close()
createViews(t, session)

views, err := getViewsMetadata(session, "gocql_test")
if err != nil {
t.Fatalf("failed to query view metadata with err: %v", err)
}
if views == nil {
t.Fatal("failed to query view metadata, nil returned")
}

if len(views) != 1 {
t.Fatal("expected one view")
}

textType := TypeText
if flagCassVersion.Before(3, 0, 0) {
textType = TypeVarchar
}

expectedView := ViewMetadata{
Keyspace: "gocql_test",
Name: "basicview",
FieldNames: []string{"birthday", "nationality", "weight", "height"},
FieldTypes: []TypeInfo{
NativeType{typ: TypeTimestamp},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: textType},
},
}

if !reflect.DeepEqual(views[0], expectedView) {
t.Fatalf("view is %+v, but expected %+v", views[0], expectedView)
}
}

func TestMaterializedViewMetadata(t *testing.T) {
if flagCassVersion.Before(3, 0, 0) {
return
Expand Down Expand Up @@ -2520,11 +2481,6 @@ func TestKeyspaceMetadata(t *testing.T) {
if aggregate.StateFunc.Name != "avgstate" {
t.Fatalf("expected state function %s, but got %s", "avgstate", aggregate.StateFunc.Name)
}

_, found = keyspaceMetadata.Views["basicview"]
if !found {
t.Fatal("failed to find the view in metadata")
}
_, found = keyspaceMetadata.UserTypes["basicview"]
if !found {
t.Fatal("failed to find the types in metadata")
Expand Down
10 changes: 1 addition & 9 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ func (fn connErrorHandlerFn) HandleError(conn *Conn, err error, closed bool) {
fn(conn, err, closed)
}

// If not zero, how many timeouts we will allow to occur before the connection is closed
// and restarted. This is to prevent a single query timeout from killing a connection
// which may be serving more queries just fine.
// Default is 0, should not be changed concurrently with queries.
//
// Deprecated.
var TimeoutLimit int64 = 0

// Conn is a single connection to a Cassandra node. It can be used to execute
// queries, but users are usually advised to use a more reliable, higher
// level API.
Expand Down Expand Up @@ -752,7 +744,7 @@ func (c *Conn) releaseStream(call *callReq) {
}

func (c *Conn) handleTimeout() {
if TimeoutLimit > 0 && atomic.AddInt64(&c.timeouts, 1) > TimeoutLimit {
if atomic.AddInt64(&c.timeouts, 1) > 0 {
c.closeWithError(ErrTooManyTimeouts)
}
}
Expand Down
11 changes: 0 additions & 11 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,6 @@ func ParseConsistencyWrapper(s string) (consistency Consistency, err error) {
return
}

// MustParseConsistency is the same as ParseConsistency except it returns
// an error (never). It is kept here since breaking changes are not good.
// DEPRECATED: use ParseConsistency if you want a panic on parse error.
func MustParseConsistency(s string) (Consistency, error) {
c, err := ParseConsistencyWrapper(s)
if err != nil {
panic(err)
}
return c, nil
}

type SerialConsistency uint16

const (
Expand Down
40 changes: 0 additions & 40 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2435,14 +2435,6 @@ type TypeInfo interface {
Version() byte
Custom() string

// New creates a pointer to an empty version of whatever type
// is referenced by the TypeInfo receiver.
//
// If there is no corresponding Go type for the CQL type, New panics.
//
// Deprecated: Use NewWithError instead.
New() interface{}

// NewWithError creates a pointer to an empty version of whatever type
// is referenced by the TypeInfo receiver.
//
Expand All @@ -2468,14 +2460,6 @@ func (t NativeType) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t NativeType) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (s NativeType) Type() Type {
return s.typ
}
Expand Down Expand Up @@ -2511,14 +2495,6 @@ func (t CollectionType) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t CollectionType) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (c CollectionType) String() string {
switch c.typ {
case TypeMap:
Expand Down Expand Up @@ -2556,14 +2532,6 @@ func (t TupleTypeInfo) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (t TupleTypeInfo) New() interface{} {
val, err := t.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

type UDTField struct {
Name string
Type TypeInfo
Expand All @@ -2584,14 +2552,6 @@ func (u UDTTypeInfo) NewWithError() (interface{}, error) {
return reflect.New(typ).Interface(), nil
}

func (u UDTTypeInfo) New() interface{} {
val, err := u.NewWithError()
if err != nil {
panic(err.Error())
}
return val
}

func (u UDTTypeInfo) String() string {
buf := &bytes.Buffer{}

Expand Down
68 changes: 22 additions & 46 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import (

// schema metadata for a keyspace
type KeyspaceMetadata struct {
Name string
DurableWrites bool
StrategyClass string
StrategyOptions map[string]interface{}
Tables map[string]*TableMetadata
Functions map[string]*FunctionMetadata
Aggregates map[string]*AggregateMetadata
// Deprecated: use the MaterializedViews field for views and UserTypes field for udts instead.
Views map[string]*ViewMetadata
Name string
DurableWrites bool
StrategyClass string
StrategyOptions map[string]interface{}
Tables map[string]*TableMetadata
Functions map[string]*FunctionMetadata
Aggregates map[string]*AggregateMetadata
MaterializedViews map[string]*MaterializedViewMetadata
UserTypes map[string]*UserTypeMetadata
}
Expand Down Expand Up @@ -85,15 +83,6 @@ type AggregateMetadata struct {
finalFunc string
}

// ViewMetadata holds the metadata for views.
// Deprecated: this is kept for backwards compatibility issues. Use MaterializedViewMetadata.
type ViewMetadata struct {
Keyspace string
Name string
FieldNames []string
FieldTypes []TypeInfo
}

// MaterializedViewMetadata holds the metadata for materialized views.
type MaterializedViewMetadata struct {
Keyspace string
Expand Down Expand Up @@ -280,7 +269,7 @@ func (s *schemaDescriber) refreshSchema(keyspaceName string) error {
if err != nil {
return err
}
views, err := getViewsMetadata(s.session, keyspaceName)
userTypes, err := getUserTypeMetadata(s.session, keyspaceName)
if err != nil {
return err
}
Expand All @@ -290,7 +279,7 @@ func (s *schemaDescriber) refreshSchema(keyspaceName string) error {
}

// organize the schema data
compileMetadata(s.session.cfg.ProtoVersion, keyspace, tables, columns, functions, aggregates, views,
compileMetadata(s.session.cfg.ProtoVersion, keyspace, tables, columns, functions, aggregates, userTypes,
materializedViews, s.session.logger)

// update the cache
Expand All @@ -311,7 +300,7 @@ func compileMetadata(
columns []ColumnMetadata,
functions []FunctionMetadata,
aggregates []AggregateMetadata,
views []ViewMetadata,
uTypes []UserTypeMetadata,
materializedViews []MaterializedViewMetadata,
logger StdLogger,
) {
Expand All @@ -331,22 +320,9 @@ func compileMetadata(
aggregates[i].StateFunc = *keyspace.Functions[aggregates[i].stateFunc]
keyspace.Aggregates[aggregates[i].Name] = &aggregates[i]
}
keyspace.Views = make(map[string]*ViewMetadata, len(views))
for i := range views {
keyspace.Views[views[i].Name] = &views[i]
}
// Views currently holds the types and hasn't been deleted for backward compatibility issues.
// That's why it's ok to copy Views into Types in this case. For the real Views use MaterializedViews.
types := make([]UserTypeMetadata, len(views))
for i := range views {
types[i].Keyspace = views[i].Keyspace
types[i].Name = views[i].Name
types[i].FieldNames = views[i].FieldNames
types[i].FieldTypes = views[i].FieldTypes
}
keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(views))
for i := range types {
keyspace.UserTypes[types[i].Name] = &types[i]
keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(uTypes))
for i := range uTypes {
keyspace.UserTypes[uTypes[i].Name] = &uTypes[i]
}
keyspace.MaterializedViews = make(map[string]*MaterializedViewMetadata, len(materializedViews))
for i, _ := range materializedViews {
Expand Down Expand Up @@ -930,7 +906,7 @@ func getTypeInfo(t string, logger StdLogger) TypeInfo {
return getCassandraType(t, logger)
}

func getViewsMetadata(session *Session, keyspaceName string) ([]ViewMetadata, error) {
func getUserTypeMetadata(session *Session, keyspaceName string) ([]UserTypeMetadata, error) {
if session.cfg.ProtoVersion == protoVersion1 {
return nil, nil
}
Expand All @@ -948,31 +924,31 @@ func getViewsMetadata(session *Session, keyspaceName string) ([]ViewMetadata, er
FROM %s
WHERE keyspace_name = ?`, tableName)

var views []ViewMetadata
var uTypes []UserTypeMetadata

rows := session.control.query(stmt, keyspaceName).Scanner()
for rows.Next() {
view := ViewMetadata{Keyspace: keyspaceName}
uType := UserTypeMetadata{Keyspace: keyspaceName}
var argumentTypes []string
err := rows.Scan(&view.Name,
&view.FieldNames,
err := rows.Scan(&uType.Name,
&uType.FieldNames,
&argumentTypes,
)
if err != nil {
return nil, err
}
view.FieldTypes = make([]TypeInfo, len(argumentTypes))
uType.FieldTypes = make([]TypeInfo, len(argumentTypes))
for i, argumentType := range argumentTypes {
view.FieldTypes[i] = getTypeInfo(argumentType, session.logger)
uType.FieldTypes[i] = getTypeInfo(argumentType, session.logger)
}
views = append(views, view)
uTypes = append(uTypes, uType)
}

if err := rows.Err(); err != nil {
return nil, err
}

return views, nil
return uTypes, nil
}

func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]MaterializedViewMetadata, error) {
Expand Down

0 comments on commit 0e38c4c

Please sign in to comment.