Skip to content

Commit 1ff2229

Browse files
authored
fix: Scalar set now accepts scalar type (#902)
This brings back functionally that we had in cqtypes which needs to keep all our resolver working (specifically the ParentColumnResolver)
1 parent f5f7cd7 commit 1ff2229

23 files changed

+184
-0
lines changed

scalar/binary.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,24 @@ func (s *Binary) String() string {
3333
return string(s.Value)
3434
}
3535

36+
func (s *Binary) Get() any {
37+
return s.Value
38+
}
39+
3640
func (s *Binary) Set(val any) error {
3741
if val == nil {
3842
s.Valid = false
3943
return nil
4044
}
4145

46+
if sc, ok := val.(Scalar); ok {
47+
if !sc.IsValid() {
48+
s.Valid = false
49+
return nil
50+
}
51+
return s.Set(sc.Get())
52+
}
53+
4254
switch value := val.(type) {
4355
case []byte:
4456
if value == nil {

scalar/bool.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,24 @@ func (s *Bool) String() string {
3737
return strconv.FormatBool(s.Value)
3838
}
3939

40+
func (s *Bool) Get() any {
41+
return s.Value
42+
}
43+
4044
func (s *Bool) Set(val any) error {
4145
if val == nil {
4246
s.Valid = false
4347
return nil
4448
}
49+
50+
if sc, ok := val.(Scalar); ok {
51+
if !sc.IsValid() {
52+
s.Valid = false
53+
return nil
54+
}
55+
return s.Set(sc.Get())
56+
}
57+
4558
switch value := val.(type) {
4659
case bool:
4760
s.Value = value

scalar/bool_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestBoolSet(t *testing.T) {
1717
{source: "f", result: Bool{Value: false, Valid: true}},
1818
{source: _bool(true), result: Bool{Value: true, Valid: true}},
1919
{source: _bool(false), result: Bool{Value: false, Valid: true}},
20+
{source: &Bool{Value: true, Valid: true}, result: Bool{Value: true, Valid: true}},
2021
{source: nil, result: Bool{}},
2122
}
2223

scalar/float.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,24 @@ func (s *Float32) Equal(rhs Scalar) bool {
3838
return s.Valid == r.Valid && s.Value == r.Value
3939
}
4040

41+
func (s *Float32) Get() any {
42+
return s.Value
43+
}
44+
4145
func (s *Float32) Set(val any) error {
4246
if val == nil {
4347
s.Valid = false
4448
return nil
4549
}
4650

51+
if sc, ok := val.(Scalar); ok {
52+
if !sc.IsValid() {
53+
s.Valid = false
54+
return nil
55+
}
56+
return s.Set(sc.Get())
57+
}
58+
4759
switch value := val.(type) {
4860
case int8:
4961
s.Value = float32(value)
@@ -126,6 +138,10 @@ func (*Float64) DataType() arrow.DataType {
126138
return arrow.PrimitiveTypes.Float64
127139
}
128140

141+
func (s *Float64) Get() any {
142+
return s.Value
143+
}
144+
129145
func (s *Float64) Equal(rhs Scalar) bool {
130146
if rhs == nil {
131147
return false
@@ -150,6 +166,14 @@ func (s *Float64) Set(val any) error {
150166
return nil
151167
}
152168

169+
if sc, ok := val.(Scalar); ok {
170+
if !sc.IsValid() {
171+
s.Valid = false
172+
return nil
173+
}
174+
return s.Set(sc.Get())
175+
}
176+
153177
switch value := val.(type) {
154178
case int8:
155179
s.Value = float64(value)

scalar/float_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestFloat32Set(t *testing.T) {
2323
{source: uint64(1), result: Float32{Value: 1, Valid: true}},
2424
{source: "1", result: Float32{Value: 1, Valid: true}},
2525
{source: _int8(1), result: Float32{Value: 1, Valid: true}},
26+
{source: &Float32{Value: 1, Valid: true}, result: Float32{Value: 1, Valid: true}},
2627
}
2728

2829
for i, tt := range successfulTests {
@@ -59,6 +60,7 @@ func TestFloat64Set(t *testing.T) {
5960
{source: uint64(1), result: Float64{Value: 1, Valid: true}},
6061
{source: "1", result: Float64{Value: 1, Valid: true}},
6162
{source: _int8(1), result: Float64{Value: 1, Valid: true}},
63+
{source: &Float64{Value: 1, Valid: true}, result: Float64{Value: 1, Valid: true}},
6264
}
6365

6466
for i, tt := range successfulTests {

scalar/inet.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,23 @@ func (s *Inet) String() string {
4141
return s.Value.String()
4242
}
4343

44+
func (s *Inet) Get() any {
45+
return s.Value
46+
}
47+
4448
func (s *Inet) Set(val any) error {
4549
if val == nil {
4650
return nil
4751
}
4852

53+
if sc, ok := val.(Scalar); ok {
54+
if !sc.IsValid() {
55+
s.Valid = false
56+
return nil
57+
}
58+
return s.Set(sc.Get())
59+
}
60+
4961
switch value := val.(type) {
5062
case net.IPNet:
5163
s.Value = &value

scalar/inet_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func TestInetSet(t *testing.T) {
7171
b.WriteString(s)
7272
return &b
7373
}("127.0.0.1"), result: Inet{Value: mustParseInet(t, "127.0.0.1"), Valid: true}},
74+
{source: &Inet{Value: &net.IPNet{IP: net.ParseIP("::ffff:0.0.0.0"), Mask: net.CIDRMask(104, 128)}, Valid: true}, result: Inet{Value: &net.IPNet{IP: net.ParseIP("::ffff:0.0.0.0"), Mask: net.CIDRMask(104, 128)}, Valid: true}},
7475
}
7576

7677
for i, tt := range successfulTests {

scalar/int.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,24 @@ func (s *Int64) Equal(rhs Scalar) bool {
3838
return s.Valid == r.Valid && s.Value == r.Value
3939
}
4040

41+
func (s *Int64) Get() any {
42+
return s.Value
43+
}
44+
4145
func (s *Int64) Set(val any) error {
4246
if val == nil {
4347
s.Valid = false
4448
return nil
4549
}
4650

51+
if sc, ok := val.(Scalar); ok {
52+
if !sc.IsValid() {
53+
s.Valid = false
54+
return nil
55+
}
56+
return s.Set(sc.Get())
57+
}
58+
4759
switch value := val.(type) {
4860
case int8:
4961
s.Value = int64(value)

scalar/int_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestInt8Set(t *testing.T) {
2323
{source: float64(1), result: Int64{Value: 1, Valid: true}},
2424
{source: "1", result: Int64{Value: 1, Valid: true}},
2525
{source: _int8(1), result: Int64{Value: 1, Valid: true}},
26+
{source: &Int64{Value: 1, Valid: true}, result: Int64{Value: 1, Valid: true}},
2627
}
2728

2829
for i, tt := range successfulTests {

scalar/json.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func (*JSON) DataType() arrow.DataType {
2222
return types.ExtensionTypes.JSON
2323
}
2424

25+
func (s *JSON) Get() any {
26+
return s.Value
27+
}
28+
2529
func (s *JSON) Equal(rhs Scalar) bool {
2630
if rhs == nil {
2731
return false
@@ -57,6 +61,14 @@ func (s *JSON) Set(val any) error {
5761
return nil
5862
}
5963

64+
if sc, ok := val.(Scalar); ok {
65+
if !sc.IsValid() {
66+
s.Valid = false
67+
return nil
68+
}
69+
return s.Set(sc.Get())
70+
}
71+
6072
switch value := val.(type) {
6173
case string:
6274
if value == "" {

0 commit comments

Comments
 (0)