Skip to content

Commit

Permalink
fix: fix some nil checks (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
markandrus authored May 8, 2024
1 parent cd37406 commit 544f2a7
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/column/bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (col *BigInt) Append(v any) (nulls []uint8, err error) {
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
col.append(v[i])
default:
nulls[i] = 1
Expand Down
6 changes: 4 additions & 2 deletions lib/column/codegen/column.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ func (col *{{ .ChType }}) Append(v any) (nulls []uint8,err error) {
nulls = make([]uint8, len(v))
for i := range v {
val := int8(0)
if *v[i] {
if v[i] == nil {
nulls[i] = 1
} else if *v[i] {
val = 1
}
col.col.Append(val)
Expand Down Expand Up @@ -432,4 +434,4 @@ func (col *{{ .ChType }}) Encode(buffer *proto.Buffer) {
col.col.EncodeColumn(buffer)
}

{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion lib/column/column_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/column/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (col *DateTime) Append(v any) (nulls []uint8, err error) {
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
col.col.Append(time.Unix(*v[i], 0))
default:
col.col.Append(time.Time{})
Expand Down
2 changes: 1 addition & 1 deletion lib/column/datetime64.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (col *DateTime64) Append(v any) (nulls []uint8, err error) {
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
col.col.Append(time.UnixMilli(*v[i]))
default:
col.col.Append(time.UnixMilli(0))
Expand Down
10 changes: 8 additions & 2 deletions lib/column/geo_multi_polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ func (col *MultiPolygon) Append(v any) (nulls []uint8, err error) {
}
return col.set.Append(values)
case []*orb.MultiPolygon:
nulls = make([]uint8, len(v))
values := make([][]orb.Polygon, 0, len(v))
for _, v := range v {
values = append(values, *v)
for i, v := range v {
if v == nil {
nulls[i] = 1
values = append(values, orb.MultiPolygon{})
} else {
values = append(values, *v)
}
}
return col.set.Append(values)
default:
Expand Down
15 changes: 10 additions & 5 deletions lib/column/geo_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ func (col *Point) Append(v any) (nulls []uint8, err error) {
}
case []*orb.Point:
nulls = make([]uint8, len(v))
for _, v := range v {
col.col.Append(proto.Point{
X: v.Lon(),
Y: v.Lat(),
})
for i, v := range v {
if v == nil {
nulls[i] = 1
col.col.Append(proto.Point{})
} else {
col.col.Append(proto.Point{
X: v.Lon(),
Y: v.Lat(),
})
}
}
default:
if valuer, ok := v.(driver.Valuer); ok {
Expand Down
10 changes: 8 additions & 2 deletions lib/column/geo_polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ func (col *Polygon) Append(v any) (nulls []uint8, err error) {
}
return col.set.Append(values)
case []*orb.Polygon:
nulls = make([]uint8, len(v))
values := make([][]orb.Ring, 0, len(v))
for _, v := range v {
values = append(values, *v)
for i, v := range v {
if v == nil {
nulls[i] = 1
values = append(values, orb.Polygon{})
} else {
values = append(values, *v)
}
}
return col.set.Append(values)
default:
Expand Down
10 changes: 8 additions & 2 deletions lib/column/geo_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ func (col *Ring) Append(v any) (nulls []uint8, err error) {
}
return col.set.Append(values)
case []*orb.Ring:
nulls = make([]uint8, len(v))
values := make([][]orb.Point, 0, len(v))
for _, v := range v {
values = append(values, *v)
for i, v := range v {
if v == nil {
nulls[i] = 1
values = append(values, orb.Ring{})
} else {
values = append(values, *v)
}
}
return col.set.Append(values)
default:
Expand Down
6 changes: 3 additions & 3 deletions lib/column/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
ips := make([]netip.Addr, len(v), len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
ip, err := strToIPV4(*v[i])
if err != nil {
return nulls, err
Expand All @@ -164,7 +164,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
col.col.Append(proto.ToIPv4(*v[i]))
default:
nulls[i] = 1
Expand Down Expand Up @@ -196,7 +196,7 @@ func (col *IPv4) Append(v any) (nulls []uint8, err error) {
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v != nil:
case v[i] != nil:
col.col.Append(proto.IPv4(*v[i]))
default:
nulls[i] = 1
Expand Down

0 comments on commit 544f2a7

Please sign in to comment.