Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 22, 2024
1 parent 80f299b commit 034ee78
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
14 changes: 11 additions & 3 deletions clients/shared/default_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ func TestColumn_DefaultValue(t *testing.T) {

// date
dateKind := typing.ETime
dateKind.ExtendedTimeDetails = &ext.Date
dateNestedKind, err := ext.NewNestedKind(ext.DateKindType, "")
assert.NoError(t, err)
dateKind.ExtendedTimeDetails = &dateNestedKind

// time
timeKind := typing.ETime
timeKind.ExtendedTimeDetails = &ext.Time
timeNestedKind, err := ext.NewNestedKind(ext.TimeKindType, "")
assert.NoError(t, err)
timeKind.ExtendedTimeDetails = &timeNestedKind

// date time
dateTimeKind := typing.ETime
dateTimeKind.ExtendedTimeDetails = &ext.TimestampTZ
dateTimeNestedKind, err := ext.NewNestedKind(ext.TimestampTZKindType, "")
assert.NoError(t, err)
dateTimeKind.ExtendedTimeDetails = &dateTimeNestedKind

testCases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion clients/snowflake/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestSnowflakeDialect_KindForDataType_DateTime(t *testing.T) {
for _, expectedDateTime := range expectedDateTimes {
kd, err := SnowflakeDialect{}.KindForDataType(expectedDateTime, "")
assert.NoError(t, err)
assert.Equal(t, ext.TimestampTZ.Type, kd.ExtendedTimeDetails.Type, expectedDateTime)
assert.Equal(t, ext.TimestampTZKindType, kd.ExtendedTimeDetails.Type, expectedDateTime)
}
}
{
Expand Down
5 changes: 4 additions & 1 deletion lib/optimization/table_data_merge_columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) {
tableData.AddInMemoryCol(columns.NewColumn("foo", typing.String))

extTime := typing.ETime
extTime.ExtendedTimeDetails = &ext.Date
nestedKind, err := ext.NewNestedKind(ext.DateKindType, "")
assert.NoError(t, err)

extTime.ExtendedTimeDetails = &nestedKind
tsCol := columns.NewColumn("foo", extTime)
assert.NoError(t, tableData.MergeColumnsFromDestination(tsCol))

Expand Down
2 changes: 1 addition & 1 deletion lib/optimization/table_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestTableData_UpdateInMemoryColumns(t *testing.T) {

col, isOk := tableData.ReadOnlyInMemoryCols().GetColumn("CHANGE_me")
assert.True(t, isOk)
assert.Equal(t, ext.TimestampTZ.Type, col.KindDetails.ExtendedTimeDetails.Type)
assert.Equal(t, ext.TimestampTZKindType, col.KindDetails.ExtendedTimeDetails.Type)

// It went from invalid to boolean.
col, isOk = tableData.ReadOnlyInMemoryCols().GetColumn("bar")
Expand Down
15 changes: 12 additions & 3 deletions lib/parquetutil/parse_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,32 @@ func TestParseValue(t *testing.T) {
{
// Time
eTime := typing.ETime
eTime.ExtendedTimeDetails = &ext.Time
nestedKind, err := ext.NewNestedKind(ext.TimeKindType, "")
assert.NoError(t, err)

eTime.ExtendedTimeDetails = &nestedKind
value, err := ParseValue("03:15:00", columns.NewColumn("", eTime))
assert.NoError(t, err)
assert.Equal(t, "03:15:00+00", value)
}
{
// Date
eDate := typing.ETime
eDate.ExtendedTimeDetails = &ext.Date
nestedKind, err := ext.NewNestedKind(ext.DateKindType, "")
assert.NoError(t, err)

eDate.ExtendedTimeDetails = &nestedKind
value, err := ParseValue("2022-12-25", columns.NewColumn("", eDate))
assert.NoError(t, err)
assert.Equal(t, "2022-12-25", value)
}
{
// Timestamp TZ
eDateTime := typing.ETime
eDateTime.ExtendedTimeDetails = &ext.TimestampTZ
nestedKind, err := ext.NewNestedKind(ext.TimestampTZKindType, "")
assert.NoError(t, err)

eDateTime.ExtendedTimeDetails = &nestedKind
value, err := ParseValue("2023-04-24T17:29:05.69944Z", columns.NewColumn("", eDateTime))
assert.NoError(t, err)
assert.Equal(t, int64(1682357345699), value)
Expand Down
14 changes: 12 additions & 2 deletions lib/typing/ext/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ func ParseExtendedDateTime(value string, kindType ExtendedTimeKindType) (*Extend

// If that doesn't work, try timestamp
if et, err := parseDateTime(value); err == nil {
et.nestedKind = Date
nestedKind, err := NewNestedKind(DateKindType, "")
if err != nil {
return nil, err
}

et.nestedKind = nestedKind
return et, nil
}
case TimeKindType:
Expand All @@ -61,7 +66,12 @@ func ParseExtendedDateTime(value string, kindType ExtendedTimeKindType) (*Extend

// If that doesn't work, try timestamp
if et, err := parseDateTime(value); err == nil {
et.nestedKind = Time
nestedKind, err := NewNestedKind(TimeKindType, "")
if err != nil {
return nil, err
}

et.nestedKind = nestedKind
return et, nil
}
}
Expand Down
15 changes: 7 additions & 8 deletions lib/typing/ext/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ type NestedKind struct {
Format string
}

var (
TimestampTZ = NestedKind{
Type: TimestampTZKindType,
Format: time.RFC3339Nano,
func NewNestedKind(kindType ExtendedTimeKindType, optionalFormat string) (NestedKind, error) {
defaultLayout, err := kindType.defaultLayout()
if err != nil {
return NestedKind{}, err
}

Date = NestedKind{
Type: DateKindType,
Format: PostgresDateFormat,
}
return NestedKind{Type: kindType, Format: cmp.Or(optionalFormat, defaultLayout)}, nil
}

var (
Time = NestedKind{
Type: TimeKindType,
Format: PostgresTimeFormat,
Expand Down

0 comments on commit 034ee78

Please sign in to comment.