Skip to content

Commit 544f2a7

Browse files
authored
fix: fix some nil checks (#1283)
1 parent cd37406 commit 544f2a7

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
lines changed

lib/column/bigint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (col *BigInt) Append(v any) (nulls []uint8, err error) {
9090
nulls = make([]uint8, len(v))
9191
for i := range v {
9292
switch {
93-
case v != nil:
93+
case v[i] != nil:
9494
col.append(v[i])
9595
default:
9696
nulls[i] = 1

lib/column/codegen/column.tpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ func (col *{{ .ChType }}) Append(v any) (nulls []uint8,err error) {
309309
nulls = make([]uint8, len(v))
310310
for i := range v {
311311
val := int8(0)
312-
if *v[i] {
312+
if v[i] == nil {
313+
nulls[i] = 1
314+
} else if *v[i] {
313315
val = 1
314316
}
315317
col.col.Append(val)
@@ -432,4 +434,4 @@ func (col *{{ .ChType }}) Encode(buffer *proto.Buffer) {
432434
col.col.EncodeColumn(buffer)
433435
}
434436

435-
{{- end }}
437+
{{- end }}

lib/column/column_gen.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/column/datetime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (col *DateTime) Append(v any) (nulls []uint8, err error) {
121121
nulls = make([]uint8, len(v))
122122
for i := range v {
123123
switch {
124-
case v != nil:
124+
case v[i] != nil:
125125
col.col.Append(time.Unix(*v[i], 0))
126126
default:
127127
col.col.Append(time.Time{})

lib/column/datetime64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (col *DateTime64) Append(v any) (nulls []uint8, err error) {
142142
nulls = make([]uint8, len(v))
143143
for i := range v {
144144
switch {
145-
case v != nil:
145+
case v[i] != nil:
146146
col.col.Append(time.UnixMilli(*v[i]))
147147
default:
148148
col.col.Append(time.UnixMilli(0))

lib/column/geo_multi_polygon.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ func (col *MultiPolygon) Append(v any) (nulls []uint8, err error) {
8686
}
8787
return col.set.Append(values)
8888
case []*orb.MultiPolygon:
89+
nulls = make([]uint8, len(v))
8990
values := make([][]orb.Polygon, 0, len(v))
90-
for _, v := range v {
91-
values = append(values, *v)
91+
for i, v := range v {
92+
if v == nil {
93+
nulls[i] = 1
94+
values = append(values, orb.MultiPolygon{})
95+
} else {
96+
values = append(values, *v)
97+
}
9298
}
9399
return col.set.Append(values)
94100
default:

lib/column/geo_point.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ func (col *Point) Append(v any) (nulls []uint8, err error) {
8989
}
9090
case []*orb.Point:
9191
nulls = make([]uint8, len(v))
92-
for _, v := range v {
93-
col.col.Append(proto.Point{
94-
X: v.Lon(),
95-
Y: v.Lat(),
96-
})
92+
for i, v := range v {
93+
if v == nil {
94+
nulls[i] = 1
95+
col.col.Append(proto.Point{})
96+
} else {
97+
col.col.Append(proto.Point{
98+
X: v.Lon(),
99+
Y: v.Lat(),
100+
})
101+
}
97102
}
98103
default:
99104
if valuer, ok := v.(driver.Valuer); ok {

lib/column/geo_polygon.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ func (col *Polygon) Append(v any) (nulls []uint8, err error) {
8686
}
8787
return col.set.Append(values)
8888
case []*orb.Polygon:
89+
nulls = make([]uint8, len(v))
8990
values := make([][]orb.Ring, 0, len(v))
90-
for _, v := range v {
91-
values = append(values, *v)
91+
for i, v := range v {
92+
if v == nil {
93+
nulls[i] = 1
94+
values = append(values, orb.Polygon{})
95+
} else {
96+
values = append(values, *v)
97+
}
9298
}
9399
return col.set.Append(values)
94100
default:

lib/column/geo_ring.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ func (col *Ring) Append(v any) (nulls []uint8, err error) {
8686
}
8787
return col.set.Append(values)
8888
case []*orb.Ring:
89+
nulls = make([]uint8, len(v))
8990
values := make([][]orb.Point, 0, len(v))
90-
for _, v := range v {
91-
values = append(values, *v)
91+
for i, v := range v {
92+
if v == nil {
93+
nulls[i] = 1
94+
values = append(values, orb.Ring{})
95+
} else {
96+
values = append(values, *v)
97+
}
9298
}
9399
return col.set.Append(values)
94100
default:

lib/column/ipv4.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
145145
ips := make([]netip.Addr, len(v), len(v))
146146
for i := range v {
147147
switch {
148-
case v != nil:
148+
case v[i] != nil:
149149
ip, err := strToIPV4(*v[i])
150150
if err != nil {
151151
return nulls, err
@@ -164,7 +164,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
164164
nulls = make([]uint8, len(v))
165165
for i := range v {
166166
switch {
167-
case v != nil:
167+
case v[i] != nil:
168168
col.col.Append(proto.ToIPv4(*v[i]))
169169
default:
170170
nulls[i] = 1
@@ -196,7 +196,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
196196
nulls = make([]uint8, len(v))
197197
for i := range v {
198198
switch {
199-
case v != nil:
199+
case v[i] != nil:
200200
col.col.Append(proto.IPv4(*v[i]))
201201
default:
202202
nulls[i] = 1

0 commit comments

Comments
 (0)