From c767dca9df19bf0d92f1f66edbbdefb3fab62adb Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 26 Sep 2024 10:41:23 -0700 Subject: [PATCH] WIP. --- clients/redshift/cast.go | 8 ++++++++ clients/redshift/cast_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/clients/redshift/cast.go b/clients/redshift/cast.go index 52af74d7f..22cf1be98 100644 --- a/clients/redshift/cast.go +++ b/clients/redshift/cast.go @@ -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 diff --git a/clients/redshift/cast_test.go b/clients/redshift/cast_test.go index 7867e164f..abe30773a 100644 --- a/clients/redshift/cast_test.go +++ b/clients/redshift/cast_test.go @@ -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