Skip to content

Commit

Permalink
Clean up more.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 17, 2024
1 parent dae917e commit a2eadd2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions clients/redshift/dialect/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (
case "double precision":
return typing.Float, nil
case "timestamp with time zone", "timestamp without time zone":
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), nil
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
case "time without time zone":
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType), nil
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
case "date":
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType), nil
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
case "boolean":
return typing.Boolean, nil
}
Expand Down
4 changes: 2 additions & 2 deletions lib/debezium/converters/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

type Date struct{}

func (Date) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType)
func (Date) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
}

func (Date) Convert(value any) (any, error) {
Expand Down
36 changes: 22 additions & 14 deletions lib/debezium/converters/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

type Time struct{}

func (Time) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)
func (Time) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
}

func (Time) Convert(val any) (any, error) {
Expand All @@ -27,34 +27,42 @@ func (Time) Convert(val any) (any, error) {

type NanoTime struct{}

func (NanoTime) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)
func (NanoTime) layout() string {
return "15:04:05.000000000"
}

func (NanoTime) Convert(value any) (any, error) {
func (n NanoTime) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, n.layout())
}

func (n NanoTime) Convert(value any) (any, error) {
castedVal, err := typing.AssertType[int64](value)
if err != nil {
return nil, err
}

// Represents the number of nanoseconds past midnight, and does not include timezone information.
return ext.NewExtendedTime(time.UnixMicro(castedVal/1_000).In(time.UTC), ext.TimeKindType, "15:04:05.000000000"), nil
return ext.NewExtendedTime(time.UnixMicro(castedVal/1_000).In(time.UTC), ext.TimeKindType, n.layout()), nil
}

type MicroTime struct{}

func (MicroTime) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)
func (MicroTime) layout() string {
return "15:04:05.000000"
}

func (m MicroTime) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, m.layout())
}

func (MicroTime) Convert(value any) (any, error) {
func (m MicroTime) Convert(value any) (any, error) {
castedVal, err := typing.AssertType[int64](value)
if err != nil {
return nil, err
}

// Represents the number of microseconds past midnight, and does not include timezone information.
return ext.NewExtendedTime(time.UnixMicro(castedVal).In(time.UTC), ext.TimeKindType, "15:04:05.000000"), nil
return ext.NewExtendedTime(time.UnixMicro(castedVal).In(time.UTC), ext.TimeKindType, m.layout()), nil
}

var SupportedDateTimeWithTimezoneFormats = []string{
Expand All @@ -72,8 +80,8 @@ var SupportedDateTimeWithTimezoneFormats = []string{

type ZonedTimestamp struct{}

func (ZonedTimestamp) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType)
func (ZonedTimestamp) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
}

func (ZonedTimestamp) Convert(value any) (any, error) {
Expand Down Expand Up @@ -114,8 +122,8 @@ var SupportedTimeWithTimezoneFormats = []string{

type TimeWithTimezone struct{}

func (TimeWithTimezone) ToKindDetails() typing.KindDetails {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)
func (TimeWithTimezone) ToKindDetails() (typing.KindDetails, error) {
return typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
}

func (TimeWithTimezone) Convert(value any) (any, error) {
Expand Down

0 comments on commit a2eadd2

Please sign in to comment.