From a2eadd2c5324a4dc7e28ff553a940aca503c6553 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 17 Oct 2024 09:15:32 -0700 Subject: [PATCH] Clean up more. --- clients/redshift/dialect/typing.go | 6 ++--- lib/debezium/converters/date.go | 4 ++-- lib/debezium/converters/time.go | 36 ++++++++++++++++++------------ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/clients/redshift/dialect/typing.go b/clients/redshift/dialect/typing.go index 8af577c26..5fd60c743 100644 --- a/clients/redshift/dialect/typing.go +++ b/clients/redshift/dialect/typing.go @@ -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 } diff --git a/lib/debezium/converters/date.go b/lib/debezium/converters/date.go index e615e7464..96d33dad8 100644 --- a/lib/debezium/converters/date.go +++ b/lib/debezium/converters/date.go @@ -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) { diff --git a/lib/debezium/converters/time.go b/lib/debezium/converters/time.go index ed5d12823..95cee3328 100644 --- a/lib/debezium/converters/time.go +++ b/lib/debezium/converters/time.go @@ -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) { @@ -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{ @@ -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) { @@ -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) {