Skip to content

Commit

Permalink
Merge branch 'master' into deprecate-create-all-cols
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Jul 8, 2024
2 parents 29e3c0e + 4c37ef2 commit 933a5c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
10 changes: 4 additions & 6 deletions clients/redshift/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (RedshiftDialect) DataTypeForKind(kd typing.KindDetails, _ bool) string {

func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (typing.KindDetails, error) {
rawType = strings.ToLower(rawType)
// TODO: Check if there are any missing Redshift data types.
if strings.HasPrefix(rawType, "numeric") {
_, parameters, err := sql.ParseDataTypeDefinition(rawType)
if err != nil {
Expand All @@ -75,15 +74,14 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (
}

if strings.Contains(rawType, "character varying") {
var strPrecision *int
precision, err := strconv.Atoi(stringPrecision)
if err == nil {
strPrecision = &precision
if err != nil {
return typing.Invalid, fmt.Errorf("failed to parse string precision: %q, err: %w", stringPrecision, err)
}

return typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: strPrecision,
OptionalStringPrecision: &precision,
}, nil
}

Expand All @@ -104,7 +102,7 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (
return typing.Boolean, nil
}

return typing.Invalid, nil
return typing.Invalid, fmt.Errorf("unsupported data type: %s", rawType)
}

func (RedshiftDialect) IsColumnAlreadyExistsErr(err error) bool {
Expand Down
12 changes: 0 additions & 12 deletions clients/redshift/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ func TestRedshiftDialect_KindForDataType(t *testing.T) {
},
expectedKd: typing.Integer,
},
{
name: "String w/o precision",
rawTypes: []rawTypeAndPrecision{
{rawType: "character varying"},
{rawType: "character varying(65535)"},
{
rawType: "character varying",
precision: "not a number",
},
},
expectedKd: typing.String,
},
{
name: "String w/ precision",
rawTypes: []rawTypeAndPrecision{
Expand Down
1 change: 1 addition & 0 deletions lib/typing/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type KindDetails struct {
ExtendedDecimalDetails *decimal.Details

// Optional kind details metadata
// TODO: Consider changing this to an int32
OptionalStringPrecision *int
}

Expand Down

0 comments on commit 933a5c3

Please sign in to comment.