From c0dd6b6ac53f1b5c9d58ce268ef8aa59ca72434e Mon Sep 17 00:00:00 2001 From: Martin Hilton Date: Wed, 5 Jun 2024 11:22:06 +0100 Subject: [PATCH 1/2] feat: upgrade github.com/benbjohnson/immutable Newer versions of this package were changed to use generics, making them incompatible with the current code. Update to the newest version. This has the nice side effect of reducing the amount of type assertions. --- go.mod | 2 +- go.sum | 4 ++-- values/dict.go | 36 ++++++++++++++++++------------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 9d5ac6ad2c..d700047326 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/SAP/go-hdb v0.14.1 github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 github.com/apache/arrow/go/v7 v7.0.1 - github.com/benbjohnson/immutable v0.3.0 + github.com/benbjohnson/immutable v0.4.3 github.com/bonitoo-io/go-sql-bigquery v0.3.4-1.4.0 github.com/c-bata/go-prompt v0.2.2 github.com/cespare/xxhash/v2 v2.2.0 diff --git a/go.sum b/go.sum index 253df24bcd..aa4885277f 100644 --- a/go.sum +++ b/go.sum @@ -161,8 +161,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.10.0 h1:1jh8J+JjYRp+QWKOsaZt7rGUgoyr github.com/aws/aws-sdk-go-v2/service/sts v1.10.0/go.mod h1:jLKCFqS+1T4i7HDqCP9GM4Uk75YW1cS0o82LdxpMyOE= github.com/aws/smithy-go v1.9.0 h1:c7FUdEqrQA1/UVKKCNDFQPNKGp4FQg3YW4Ck5SLTG58= github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= -github.com/benbjohnson/immutable v0.3.0 h1:TVRhuZx2wG9SZ0LRdqlbs9S5BZ6Y24hJEHTCgWHZEIw= -github.com/benbjohnson/immutable v0.3.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI= +github.com/benbjohnson/immutable v0.4.3 h1:GYHcksoJ9K6HyAUpGxwZURrbTkXA0Dh4otXGqbhdrjA= +github.com/benbjohnson/immutable v0.4.3/go.mod h1:qJIKKSmdqz1tVzNtst1DZzvaqOU1onk1rc03IeM3Owk= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= diff --git a/values/dict.go b/values/dict.go index 2bf5fcc715..9dcdaaffe6 100644 --- a/values/dict.go +++ b/values/dict.go @@ -131,7 +131,7 @@ func (d emptyDict) Release() {} type dict struct { t semantic.MonoType - data *immutable.SortedMap + data *immutable.SortedMap[(Value), (Value)] } func (d dict) Get(key, def Value) Value { @@ -163,11 +163,11 @@ func (d dict) Remove(key Value) Dictionary { func (d dict) Range(f func(key, value Value)) { itr := d.data.Iterator() for { - key, value := itr.Next() - if key == nil { + key, value, ok := itr.Next() + if !ok { return } - f(key.(Value), value.(Value)) + f(key, value) } } @@ -266,8 +266,8 @@ type ( timeComparer struct{} ) -func (c intComparer) Compare(a, b interface{}) int { - if i, j := a.(Value).Int(), b.(Value).Int(); i < j { +func (c intComparer) Compare(a, b Value) int { + if i, j := a.Int(), b.Int(); i < j { return -1 } else if i > j { return 1 @@ -275,8 +275,8 @@ func (c intComparer) Compare(a, b interface{}) int { return 0 } -func (c uintComparer) Compare(a, b interface{}) int { - if i, j := a.(Value).UInt(), b.(Value).UInt(); i < j { +func (c uintComparer) Compare(a, b Value) int { + if i, j := a.UInt(), b.UInt(); i < j { return -1 } else if i > j { return 1 @@ -284,8 +284,8 @@ func (c uintComparer) Compare(a, b interface{}) int { return 0 } -func (c floatComparer) Compare(a, b interface{}) int { - if i, j := a.(Value).Float(), b.(Value).Float(); i < j { +func (c floatComparer) Compare(a, b Value) int { + if i, j := a.Float(), b.Float(); i < j { return -1 } else if i > j { return 1 @@ -293,8 +293,8 @@ func (c floatComparer) Compare(a, b interface{}) int { return 0 } -func (c stringComparer) Compare(a, b interface{}) int { - if i, j := a.(Value).Str(), b.(Value).Str(); i < j { +func (c stringComparer) Compare(a, b Value) int { + if i, j := a.Str(), b.Str(); i < j { return -1 } else if i > j { return 1 @@ -302,8 +302,8 @@ func (c stringComparer) Compare(a, b interface{}) int { return 0 } -func (c timeComparer) Compare(a, b interface{}) int { - if i, j := a.(Value).Time(), b.(Value).Time(); i < j { +func (c timeComparer) Compare(a, b Value) int { + if i, j := a.Time(), b.Time(); i < j { return -1 } else if i > j { return 1 @@ -311,7 +311,7 @@ func (c timeComparer) Compare(a, b interface{}) int { return 0 } -func dictComparer(dictType semantic.MonoType) immutable.Comparer { +func dictComparer(dictType semantic.MonoType) immutable.Comparer[(Value)] { if dictType.Nature() != semantic.Dictionary { panic(UnexpectedKind(dictType.Nature(), semantic.Dictionary)) } @@ -339,7 +339,7 @@ func dictComparer(dictType semantic.MonoType) immutable.Comparer { func NewDict(dictType semantic.MonoType) Dictionary { return dict{ t: dictType, - data: immutable.NewSortedMap( + data: immutable.NewSortedMap[(Value), (Value)]( dictComparer(dictType), ), } @@ -350,13 +350,13 @@ func NewDict(dictType semantic.MonoType) Dictionary { // that create new Dictionary values. type DictionaryBuilder struct { t semantic.MonoType - b *immutable.SortedMapBuilder + b *immutable.SortedMapBuilder[(Value), (Value)] } // NewDictBuilder will create a new DictionaryBuilder for the given // key type. func NewDictBuilder(dictType semantic.MonoType) DictionaryBuilder { - builder := immutable.NewSortedMapBuilder(dictComparer(dictType)) + builder := immutable.NewSortedMapBuilder[(Value), (Value)](dictComparer(dictType)) return DictionaryBuilder{t: dictType, b: builder} } From f991672922c422299905910858f4e476eefff555 Mon Sep 17 00:00:00 2001 From: Martin Hilton Date: Wed, 5 Jun 2024 11:44:19 +0100 Subject: [PATCH 2/2] fix: staticcheck --- values/dict.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/values/dict.go b/values/dict.go index 9dcdaaffe6..c1d13f7442 100644 --- a/values/dict.go +++ b/values/dict.go @@ -138,7 +138,7 @@ func (d dict) Get(key, def Value) Value { if !key.IsNull() { v, ok := d.data.Get(key) if ok { - return v.(Value) + return v } } return def @@ -241,7 +241,7 @@ func (d dict) Equal(v Value) bool { equal = false return } - equal = value.Equal(v.(Value)) + equal = value.Equal(v) }) return equal } @@ -374,7 +374,7 @@ func (d *DictionaryBuilder) Get(key Value) (Value, bool) { if !ok { return nil, false } - return v.(Value), true + return v, true } // Insert will insert a new key/value pair into the Dictionary.