Skip to content

Commit

Permalink
Removing data_helpers.go and all references (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
gogingersnap777 authored Jun 4, 2024
1 parent 49e6265 commit dd45741
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 165 deletions.
21 changes: 2 additions & 19 deletions lib/column/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/ClickHouse/ch-go/proto"
"reflect"
"time"

"github.com/ClickHouse/ch-go/proto"
)

var (
Expand Down Expand Up @@ -101,19 +102,13 @@ func (col *Date) Append(v any) (nulls []uint8, err error) {
switch v := v.(type) {
case []time.Time:
for _, t := range v {
if err := dateOverflow(minDate, maxDate, t, defaultDateFormatNoZone); err != nil {
return nil, err
}
col.col.Append(t)
}
case []*time.Time:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
if err := dateOverflow(minDate, maxDate, *v, defaultDateFormatNoZone); err != nil {
return nil, err
}
col.col.Append(*v)
default:
nulls[i] = 1
Expand Down Expand Up @@ -181,16 +176,10 @@ func (col *Date) Append(v any) (nulls []uint8, err error) {
func (col *Date) AppendRow(v any) error {
switch v := v.(type) {
case time.Time:
if err := dateOverflow(minDate, maxDate, v, defaultDateFormatNoZone); err != nil {
return err
}
col.col.Append(v)
case *time.Time:
switch {
case v != nil:
if err := dateOverflow(minDate, maxDate, *v, defaultDateFormatNoZone); err != nil {
return err
}
col.col.Append(*v)
default:
col.col.Append(time.Time{})
Expand Down Expand Up @@ -257,12 +246,6 @@ func parseDate(value string, minDate time.Time, maxDate time.Time, location *tim
if location == nil {
location = time.Local
}

defer func() {
if err == nil {
err = dateOverflow(minDate, maxDate, tv, defaultDateFormatNoZone)
}
}()
if tv, err = time.Parse(defaultDateFormatWithZone, value); err == nil {
return tv, nil
}
Expand Down
12 changes: 0 additions & 12 deletions lib/column/date32.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,13 @@ func (col *Date32) Append(v any) (nulls []uint8, err error) {
switch v := v.(type) {
case []time.Time:
for _, t := range v {
if err := dateOverflow(minDate32, maxDate32, t, "2006-01-02"); err != nil {
return nil, err
}
col.col.Append(t)
}
case []*time.Time:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
if err := dateOverflow(minDate32, maxDate32, *v, "2006-01-02"); err != nil {
return nil, err
}
col.col.Append(*v)
default:
nulls[i] = 1
Expand Down Expand Up @@ -172,16 +166,10 @@ func (col *Date32) Append(v any) (nulls []uint8, err error) {
func (col *Date32) AppendRow(v any) error {
switch v := v.(type) {
case time.Time:
if err := dateOverflow(minDate32, maxDate32, v, "2006-01-02"); err != nil {
return err
}
col.col.Append(v)
case *time.Time:
switch {
case v != nil:
if err := dateOverflow(minDate32, maxDate32, *v, "2006-01-02"); err != nil {
return err
}
col.col.Append(*v)
default:
col.col.Append(time.Time{})
Expand Down
47 changes: 0 additions & 47 deletions lib/column/date_helpers.go

This file was deleted.

53 changes: 0 additions & 53 deletions lib/column/date_helpers_test.go

This file was deleted.

21 changes: 2 additions & 19 deletions lib/column/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/ClickHouse/ch-go/proto"
"reflect"
"strings"
"time"

"github.com/ClickHouse/ch-go/proto"

"github.com/ClickHouse/clickhouse-go/v2/lib/timezone"
)

Expand Down Expand Up @@ -131,9 +132,6 @@ func (col *DateTime) Append(v any) (nulls []uint8, err error) {
case []time.Time:
nulls = make([]uint8, len(v))
for i := range v {
if err := dateOverflow(minDateTime, maxDateTime, v[i], defaultDateTimeFormatNoZone); err != nil {
return nil, err
}
col.col.Append(v[i])
}

Expand All @@ -142,9 +140,6 @@ func (col *DateTime) Append(v any) (nulls []uint8, err error) {
for i := range v {
switch {
case v[i] != nil:
if err := dateOverflow(minDateTime, maxDateTime, *v[i], defaultDateTimeFormatNoZone); err != nil {
return nil, err
}
col.col.Append(*v[i])
default:
nulls[i] = 1
Expand Down Expand Up @@ -223,16 +218,10 @@ func (col *DateTime) AppendRow(v any) error {
col.col.Append(time.Time{})
}
case time.Time:
if err := dateOverflow(minDateTime, maxDateTime, v, defaultDateTimeFormatNoZone); err != nil {
return err
}
col.col.Append(v)
case *time.Time:
switch {
case v != nil:
if err := dateOverflow(minDateTime, maxDateTime, *v, defaultDateTimeFormatNoZone); err != nil {
return err
}
col.col.Append(*v)
default:
col.col.Append(time.Time{})
Expand Down Expand Up @@ -309,12 +298,6 @@ func (col *DateTime) row(i int) time.Time {
}

func (col *DateTime) parseDateTime(value string) (tv time.Time, err error) {
defer func() {
if err == nil {
err = dateOverflow(minDateTime, maxDateTime, tv, defaultDateFormatNoZone)
}
}()

if tv, err = time.Parse(defaultDateTimeFormatWithZone, value); err == nil {
return tv, nil
}
Expand Down
15 changes: 2 additions & 13 deletions lib/column/datetime64.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/ClickHouse/ch-go/proto"
"math"
"reflect"
"strconv"
"strings"
"time"

"github.com/ClickHouse/ch-go/proto"

"github.com/ClickHouse/clickhouse-go/v2/lib/timezone"
)

Expand Down Expand Up @@ -152,19 +153,13 @@ func (col *DateTime64) Append(v any) (nulls []uint8, err error) {
case []time.Time:
nulls = make([]uint8, len(v))
for i := range v {
if err := dateOverflow(minDateTime64, maxDateTime64, v[i], "2006-01-02 15:04:05"); err != nil {
return nil, err
}
col.col.Append(v[i])
}
case []*time.Time:
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v[i] != nil:
if err := dateOverflow(minDateTime64, maxDateTime64, *v[i], "2006-01-02 15:04:05"); err != nil {
return nil, err
}
col.col.Append(*v[i])
default:
col.col.Append(time.Time{})
Expand Down Expand Up @@ -227,16 +222,10 @@ func (col *DateTime64) AppendRow(v any) error {
col.col.Append(time.Time{})
}
case time.Time:
if err := dateOverflow(minDateTime64, maxDateTime64, v, "2006-01-02 15:04:05"); err != nil {
return err
}
col.col.Append(v)
case *time.Time:
switch {
case v != nil:
if err := dateOverflow(minDateTime64, maxDateTime64, *v, "2006-01-02 15:04:05"); err != nil {
return err
}
col.col.Append(*v)
default:
col.col.Append(time.Time{})
Expand Down
2 changes: 0 additions & 2 deletions lib/proto/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ func (e *BlockError) Error() string {
switch err := e.Err.(type) {
case *column.Error:
return fmt.Sprintf("clickhouse [%s]: (%s %s) %s", e.Op, e.ColumnName, err.ColumnType, err.Err)
case *column.DateOverflowError:
return fmt.Sprintf("clickhouse: dateTime overflow. %s must be between %s and %s", e.ColumnName, err.Min.Format(err.Format), err.Max.Format(err.Format))
}
return fmt.Sprintf("clickhouse [%s]: %s %s", e.Op, e.ColumnName, e.Err)
}

0 comments on commit dd45741

Please sign in to comment.