Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 10, 2024
1 parent 6e3d2ae commit 0858b5c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion clients/bigquery/storagewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func rowToMessage(row map[string]any, columns []columns.Column, messageDescripto
return nil, fmt.Errorf("extended time details for column kind details is nil")
}

extTime, err := ext.ParseFromInterfaceNew(value, column.KindDetails.ExtendedTimeDetails.Type)
extTime, err := ext.ParseFromInterface(value, column.KindDetails.ExtendedTimeDetails.Type)
if err != nil {
return nil, fmt.Errorf("failed to cast value as time.Time, value: %v, err: %w", value, err)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/mssql/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func parseValue(colVal any, colKind columns.Column) (any, error) {
return "", fmt.Errorf("column kind details for extended time details is not set")
}

extTime, err := ext.ParseFromInterfaceNew(colVal, colKind.KindDetails.ExtendedTimeDetails.Type)
extTime, err := ext.ParseFromInterface(colVal, colKind.KindDetails.ExtendedTimeDetails.Type)
if err != nil {
return "", fmt.Errorf("failed to cast colVal as time.Time, colVal: %v, err: %w", colVal, err)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/shared/default_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func DefaultValue(column columns.Column, dialect sql.Dialect) (any, error) {
return nil, fmt.Errorf("column kind details for extended time is not set")
}

extTime, err := ext.ParseFromInterfaceNew(column.DefaultValue(), column.KindDetails.ExtendedTimeDetails.Type)
extTime, err := ext.ParseFromInterface(column.DefaultValue(), column.KindDetails.ExtendedTimeDetails.Type)
if err != nil {
return "", fmt.Errorf("failed to cast colVal as time.Time, colVal: %v, err: %w", column.DefaultValue(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/shared/default_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var dialects = []sql.Dialect{

func TestColumn_DefaultValue(t *testing.T) {
birthday := time.Date(2022, time.September, 6, 3, 19, 24, 942000000, time.UTC)
birthdayExtDateTime, err := ext.ParseExtendedDateTimeNew(birthday.Format(ext.ISO8601), ext.DateTimeKindType)
birthdayExtDateTime, err := ext.ParseExtendedDateTime(birthday.Format(ext.ISO8601), ext.DateTimeKindType)
assert.NoError(t, err)

// date
Expand Down
2 changes: 1 addition & 1 deletion lib/optimization/table_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (t *TableData) DistinctDates(colName string) ([]string, error) {
return nil, fmt.Errorf("col: %v does not exist on row: %v", colName, row)
}

extTime, err := ext.ParseFromInterfaceNew(val, ext.DateKindType)
extTime, err := ext.ParseFromInterface(val, ext.DateKindType)
if err != nil {
return nil, fmt.Errorf("col: %v is not a time column, value: %v, err: %w", colName, val, err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/parquetutil/parse_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ParseValue(colVal any, colKind columns.Column) (any, error) {
return "", fmt.Errorf("column kind details for extended time details is not set")
}

extTime, err := ext.ParseFromInterfaceNew(colVal, colKind.KindDetails.ExtendedTimeDetails.Type)
extTime, err := ext.ParseFromInterface(colVal, colKind.KindDetails.ExtendedTimeDetails.Type)
if err != nil {
return "", fmt.Errorf("failed to cast colVal as time.Time, colVal: %v, err: %w", colVal, err)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/typing/ext/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func ParseTimeExactMatch(layout, value string) (time.Time, error) {
return ts, nil
}

func ParseFromInterfaceNew(val any, kindType ExtendedTimeKindType) (*ExtendedTime, error) {
func ParseFromInterface(val any, kindType ExtendedTimeKindType) (*ExtendedTime, error) {
switch convertedVal := val.(type) {
case nil:
return nil, fmt.Errorf("val is nil")
case *ExtendedTime:
return convertedVal, nil
case string:
extendedTime, err := ParseExtendedDateTimeNew(convertedVal, kindType)
extendedTime, err := ParseExtendedDateTime(convertedVal, kindType)
if err != nil {
return nil, fmt.Errorf("failed to parse colVal: %q, err: %w", val, err)
}
Expand All @@ -38,7 +38,7 @@ func ParseFromInterfaceNew(val any, kindType ExtendedTimeKindType) (*ExtendedTim
}
}

func ParseExtendedDateTimeNew(val string, kindType ExtendedTimeKindType) (*ExtendedTime, error) {
func ParseExtendedDateTime(val string, kindType ExtendedTimeKindType) (*ExtendedTime, error) {
switch kindType {
case DateTimeKindType:
return parseDateTime(val)
Expand Down
18 changes: 9 additions & 9 deletions lib/typing/ext/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ func TestParseFromInterface(t *testing.T) {
vals = append(vals, NewExtendedTime(time.Now().UTC(), TimeKindType, PostgresTimeFormat))

for _, val := range vals {
extTime, err := ParseFromInterfaceNew(val, DateTimeKindType)
extTime, err := ParseFromInterface(val, DateTimeKindType)
assert.NoError(t, err)
assert.Equal(t, val, extTime)
}
}
{
// Nil
_, err := ParseFromInterfaceNew(nil, DateTimeKindType)
_, err := ParseFromInterface(nil, DateTimeKindType)
assert.ErrorContains(t, err, "val is nil")
}
{
// True
_, err := ParseFromInterfaceNew(true, DateTimeKindType)
_, err := ParseFromInterface(true, DateTimeKindType)
assert.ErrorContains(t, err, "failed to parse colVal, expected type string or *ExtendedTime and got: bool")
}
{
// False
_, err := ParseFromInterfaceNew(false, DateTimeKindType)
_, err := ParseFromInterface(false, DateTimeKindType)
assert.ErrorContains(t, err, "failed to parse colVal, expected type string or *ExtendedTime and got: bool")
}
}

func TestParseFromInterfaceDateTime(t *testing.T) {
now := time.Now().In(time.UTC)
for _, supportedDateTimeLayout := range supportedDateTimeLayouts {
et, err := ParseFromInterfaceNew(now.Format(supportedDateTimeLayout), DateTimeKindType)
et, err := ParseFromInterface(now.Format(supportedDateTimeLayout), DateTimeKindType)
assert.NoError(t, err)
assert.Equal(t, DateTimeKindType, et.GetNestedKind().Type)
assert.Equal(t, et.String(""), now.Format(supportedDateTimeLayout))
Expand All @@ -51,7 +51,7 @@ func TestParseFromInterfaceDateTime(t *testing.T) {
func TestParseFromInterfaceTime(t *testing.T) {
now := time.Now()
for _, supportedTimeFormat := range SupportedTimeFormatsLegacy {
et, err := ParseFromInterfaceNew(now.Format(supportedTimeFormat), TimeKindType)
et, err := ParseFromInterface(now.Format(supportedTimeFormat), TimeKindType)
assert.NoError(t, err)
assert.Equal(t, TimeKindType, et.GetNestedKind().Type)
// Without passing an override format, this should return the same preserved dt format.
Expand All @@ -62,7 +62,7 @@ func TestParseFromInterfaceTime(t *testing.T) {
func TestParseFromInterfaceDate(t *testing.T) {
now := time.Now()
for _, supportedDateFormat := range supportedDateFormats {
et, err := ParseFromInterfaceNew(now.Format(supportedDateFormat), DateKindType)
et, err := ParseFromInterface(now.Format(supportedDateFormat), DateKindType)
assert.NoError(t, err)
assert.Equal(t, DateKindType, et.GetNestedKind().Type)

Expand All @@ -73,7 +73,7 @@ func TestParseFromInterfaceDate(t *testing.T) {

func TestParseExtendedDateTime_Timestamp(t *testing.T) {
tsString := "2023-04-24T17:29:05.69944Z"
extTime, err := ParseExtendedDateTimeNew(tsString, DateTimeKindType)
extTime, err := ParseExtendedDateTime(tsString, DateTimeKindType)
assert.NoError(t, err)
assert.Equal(t, "2023-04-24T17:29:05.69944Z", extTime.String(""))
}
Expand All @@ -83,7 +83,7 @@ func TestTimeLayout(t *testing.T) {

for _, supportedFormat := range SupportedTimeFormatsLegacy {
parsedTsString := ts.Format(supportedFormat)
extTime, err := ParseExtendedDateTimeNew(parsedTsString, TimeKindType)
extTime, err := ParseExtendedDateTime(parsedTsString, TimeKindType)
assert.NoError(t, err)
assert.Equal(t, parsedTsString, extTime.String(""))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/typing/values/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ToString(colVal any, colKind typing.KindDetails) (string, error) {
return "", fmt.Errorf("column kind details for extended time details is null")
}

extTime, err := ext.ParseFromInterfaceNew(colVal, colKind.ExtendedTimeDetails.Type)
extTime, err := ext.ParseFromInterface(colVal, colKind.ExtendedTimeDetails.Type)
if err != nil {
return "", fmt.Errorf("failed to cast colVal as time.Time, colVal: %v, err: %w", colVal, err)
}
Expand Down

0 comments on commit 0858b5c

Please sign in to comment.