Skip to content

Commit

Permalink
Rename variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 20, 2024
1 parent 175e027 commit adb66ce
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lib/debezium/converters/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ var SupportedDateTimeWithTimezoneFormats = []string{
"2006-01-02T15:04:05.000000000Z", // 9 digits
}

type DateTimeWithTimezone struct{}
type ZonedTimestamp struct{}

func (DateTimeWithTimezone) ToKindDetails() typing.KindDetails {
func (ZonedTimestamp) ToKindDetails() typing.KindDetails {
return typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType)
}

func (DateTimeWithTimezone) Convert(value any) (any, error) {
func (ZonedTimestamp) Convert(value any) (any, error) {
valString, isOk := value.(string)
if !isOk {
return nil, fmt.Errorf("expected string got '%v' with type %T", value, value)
Expand Down
28 changes: 14 additions & 14 deletions lib/debezium/converters/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,101 +11,101 @@ import (
"github.com/stretchr/testify/assert"
)

func TestConvertDateTimeWithTimezone(t *testing.T) {
func TestZonedTimestamp_Convert(t *testing.T) {
{
// Invalid data
_, err := DateTimeWithTimezone{}.Convert(123)
_, err := ZonedTimestamp{}.Convert(123)
assert.ErrorContains(t, err, "expected string got '123' with type int")
}
{
// Edge case (Year exceeds 9999)
val, err := DateTimeWithTimezone{}.Convert("+275760-09-13T00:00:00.000000Z")
val, err := ZonedTimestamp{}.Convert("+275760-09-13T00:00:00.000000Z")
assert.NoError(t, err)
assert.Nil(t, val)
}
{
// Edge case (Negative year)
val, err := DateTimeWithTimezone{}.Convert("-0999-10-10T10:10:10.000000Z")
val, err := ZonedTimestamp{}.Convert("-0999-10-10T10:10:10.000000Z")
assert.NoError(t, err)
assert.Nil(t, val)
}
{
// Valid
{
// No fractional seconds
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 000000000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 1 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.1Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 100000000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.0Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 2 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.12Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 120000000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.00Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 3 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.123Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123000000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 4 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.1234Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1234Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123400000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.0000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 5 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.12345Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12345Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123450000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.00000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 6 digits (microseconds)
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.123456Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123456Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456000, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.000000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 7 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.1234567Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1234567Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456700, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.0000000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 8 digits
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.12345678Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12345678Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456780, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.00000000Z")
assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime))
}
{
// 9 digits (nanoseconds)
val, err := DateTimeWithTimezone{}.Convert("2025-09-13T00:00:00.123456789Z")
val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123456789Z")
assert.NoError(t, err)

expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456789, time.UTC), ext.TimestampTzKindType, "2006-01-02T15:04:05.000000000Z")
Expand Down
4 changes: 2 additions & 2 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (f Field) ToValueConverter() (converters.ValueConverter, error) {
return &converters.Int64Passthrough{}, nil
case Bits:
return converters.Base64{}, nil
case DateTimeWithTimezone:
return converters.DateTimeWithTimezone{}, nil
case ZonedTimestamp:
return converters.ZonedTimestamp{}, nil
case TimeWithTimezone:
return converters.TimeWithTimezone{}, nil
case GeometryPointType:
Expand Down
2 changes: 1 addition & 1 deletion lib/debezium/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestField_ToKindDetails(t *testing.T) {
{
// Timestamp
// Datetime (for now)
for _, dbzType := range []SupportedDebeziumType{Timestamp, TimestampKafkaConnect, MicroTimestamp, NanoTimestamp, DateTimeWithTimezone} {
for _, dbzType := range []SupportedDebeziumType{Timestamp, TimestampKafkaConnect, MicroTimestamp, NanoTimestamp, ZonedTimestamp} {
kd, err := Field{DebeziumType: dbzType}.ToKindDetails()
assert.NoError(t, err)
assert.Equal(t, typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), kd)
Expand Down
10 changes: 5 additions & 5 deletions lib/debezium/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const (
Bits SupportedDebeziumType = "io.debezium.data.Bits"

// Dates
Date SupportedDebeziumType = "io.debezium.time.Date"
DateKafkaConnect SupportedDebeziumType = "org.apache.kafka.connect.data.Date"
DateTimeWithTimezone SupportedDebeziumType = "io.debezium.time.ZonedTimestamp"
MicroDuration SupportedDebeziumType = "io.debezium.time.MicroDuration"
Year SupportedDebeziumType = "io.debezium.time.Year"
Date SupportedDebeziumType = "io.debezium.time.Date"
DateKafkaConnect SupportedDebeziumType = "org.apache.kafka.connect.data.Date"
ZonedTimestamp SupportedDebeziumType = "io.debezium.time.ZonedTimestamp"
MicroDuration SupportedDebeziumType = "io.debezium.time.MicroDuration"
Year SupportedDebeziumType = "io.debezium.time.Year"

// Time
Time SupportedDebeziumType = "io.debezium.time.Time"
Expand Down

0 comments on commit adb66ce

Please sign in to comment.