diff --git a/clients/bigquery/converters/converters.go b/clients/bigquery/converters/converters.go index e071e49c7..efe9952e5 100644 --- a/clients/bigquery/converters/converters.go +++ b/clients/bigquery/converters/converters.go @@ -4,13 +4,21 @@ import ( "fmt" "strconv" + "github.com/artie-labs/transfer/lib/typing" + "github.com/artie-labs/transfer/lib/typing/decimal" "github.com/artie-labs/transfer/lib/typing/ext" ) -type StringConverter struct{} +type StringConverter struct { + kd typing.KindDetails +} + +func NewStringConverter(kd typing.KindDetails) StringConverter { + return StringConverter{kd: kd} +} -func (StringConverter) Convert(value any) (any, error) { +func (s StringConverter) Convert(value any) (any, error) { switch castedValue := value.(type) { case string: return castedValue, nil @@ -19,7 +27,11 @@ func (StringConverter) Convert(value any) (any, error) { case bool: return fmt.Sprint(castedValue), nil case *ext.ExtendedTime: - return castedValue.String(""), nil + if err := s.kd.EnsureExtendedTimeDetails(); err != nil { + return nil, err + } + + return castedValue.GetTime().Format(s.kd.ExtendedTimeDetails.Format), nil default: return nil, fmt.Errorf("expected string/*decimal.Decimal/bool received %T with value %v", value, value) } diff --git a/clients/bigquery/storagewrite.go b/clients/bigquery/storagewrite.go index 63605a827..d6933eb98 100644 --- a/clients/bigquery/storagewrite.go +++ b/clients/bigquery/storagewrite.go @@ -158,7 +158,7 @@ func rowToMessage(row map[string]any, columns []columns.Column, messageDescripto message.Set(field, protoreflect.ValueOfString(decimalValue.String())) case typing.String.Kind: - val, err := converters.StringConverter{}.Convert(value) + val, err := converters.NewStringConverter(column.KindDetails).Convert(value) if err != nil { return nil, err } diff --git a/lib/typing/ext/time.go b/lib/typing/ext/time.go index d84c2ea5b..93243eb41 100644 --- a/lib/typing/ext/time.go +++ b/lib/typing/ext/time.go @@ -81,8 +81,3 @@ func (e *ExtendedTime) GetTime() time.Time { func (e *ExtendedTime) GetNestedKind() NestedKind { return e.nestedKind } - -func (e *ExtendedTime) String(overrideFormat string) string { - format := cmp.Or(overrideFormat, e.nestedKind.Format) - return e.ts.Format(format) -} diff --git a/lib/typing/typing.go b/lib/typing/typing.go index 1441ddaf3..38c71af5d 100644 --- a/lib/typing/typing.go +++ b/lib/typing/typing.go @@ -33,6 +33,10 @@ func (k *KindDetails) EnsureExtendedTimeDetails() error { return fmt.Errorf("extended time details is not set") } + if k.ExtendedTimeDetails.Format == "" { + return fmt.Errorf("extended time details format is not set") + } + return nil }