Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BigQuery] StringConverter to support INT64 #986

Merged
merged 19 commits into from
Oct 24, 2024
4 changes: 2 additions & 2 deletions clients/bigquery/converters/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s StringConverter) Convert(value any) (any, error) {
return castedValue, nil
case *decimal.Decimal:
return castedValue.String(), nil
case bool:
case bool, int64:
return fmt.Sprint(castedValue), nil
case *ext.ExtendedTime:
if err := s.kd.EnsureExtendedTimeDetails(); err != nil {
Expand All @@ -32,7 +32,7 @@ func (s StringConverter) Convert(value any) (any, error) {

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)
return nil, fmt.Errorf("expected string/*decimal.Decimal/bool/int64 received %T with value %v", value, value)
}
}

Expand Down
8 changes: 7 additions & 1 deletion clients/bigquery/converters/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ func TestStringConverter_Convert(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "true", val)
}
{
// int64
val, err := NewStringConverter(typing.Integer).Convert(int64(123))
assert.NoError(t, err)
assert.Equal(t, "123", val)
}
{
// Invalid
_, err := NewStringConverter(typing.Integer).Convert(123)
assert.ErrorContains(t, err, "expected string/*decimal.Decimal/bool received int with value 123")
assert.ErrorContains(t, err, "expected string/*decimal.Decimal/bool/int64 received int with value 123")
}
{
// Extended time
Expand Down