Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 26, 2024
1 parent ef1a01d commit c767dca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clients/redshift/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (

const maxRedshiftLength int32 = 65535

func canIncreasePrecision(colKind typing.KindDetails) bool {
if colKind.Kind == typing.String.Kind && colKind.OptionalStringPrecision != nil {
return maxRedshiftLength > *colKind.OptionalStringPrecision
}

return false
}

func replaceExceededValues(colVal string, colKind typing.KindDetails, truncateExceededValue bool) string {
if colKind.Kind == typing.Struct.Kind || colKind.Kind == typing.String.Kind {
maxLength := maxRedshiftLength
Expand Down
29 changes: 29 additions & 0 deletions clients/redshift/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ import (
"github.com/stretchr/testify/assert"
)

func (r *RedshiftTestSuite) TestCanIncreasePrecision() {
{
// Not a string
assert.False(r.T(), canIncreasePrecision(typing.Struct))
}
{
// String, but precision is not specified
assert.False(r.T(), canIncreasePrecision(typing.String))
}
{
// String, but maxed out already
assert.False(r.T(), canIncreasePrecision(
typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: typing.ToPtr(maxRedshiftLength),
}),
)
}
{
// String, precision is low and can be increased
assert.True(r.T(), canIncreasePrecision(
typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: typing.ToPtr(maxRedshiftLength - 1),
}),
)
}
}

func (r *RedshiftTestSuite) TestReplaceExceededValues() {
{
// Irrelevant data type
Expand Down

0 comments on commit c767dca

Please sign in to comment.