Skip to content

Commit

Permalink
Merge branch 'master' into refactor-storage-writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Aug 27, 2024
2 parents 98a8cc2 + a2ab0dc commit 2bd2a01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions clients/bigquery/converters/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strconv"

"github.com/artie-labs/transfer/lib/typing/ext"

"github.com/artie-labs/transfer/lib/typing/decimal"
)

Expand All @@ -17,6 +19,8 @@ func (StringConverter) Convert(value any) (any, error) {
return castedValue.String(), nil
case bool:
return fmt.Sprint(castedValue), nil
case *ext.ExtendedTime:
return castedValue.String(""), nil
default:
return nil, fmt.Errorf("expected string/*decimal.Decimal/bool received %T with value %v", value, value)
}
Expand Down
9 changes: 8 additions & 1 deletion clients/bigquery/storagewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,21 @@ func rowToMessage(row map[string]any, columns []columns.Column, messageDescripto
message.Set(field, protoreflect.ValueOfFloat64(float64(value)))
case int64:
message.Set(field, protoreflect.ValueOfFloat64(float64(value)))
case *decimal.Decimal:
float, err := value.Value().Float64()
if err != nil {
return nil, fmt.Errorf("failed to convert decimal to float64: %w", err)
}

message.Set(field, protoreflect.ValueOfFloat64(float))
case string:
floatValue, err := strconv.ParseFloat(value, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse string to float64: %w", err)
}
message.Set(field, protoreflect.ValueOfFloat64(floatValue))
default:
return nil, fmt.Errorf("expected float32/float64/int32/int64/string received %T with value %v", value, value)
return nil, fmt.Errorf("expected float32/float64/int32/int64/*decimal.Decimal/string received %T with value %v", value, value)
}
case typing.EDecimal.Kind:
decimalValue, err := typing.AssertType[*decimal.Decimal](value)
Expand Down

0 comments on commit 2bd2a01

Please sign in to comment.