Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 25, 2024
1 parent 4e97ef4 commit cbc00a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions clients/redshift/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (RedshiftDialect) DataTypeForKind(kd typing.KindDetails, _ bool) string {
switch kd.Kind {
case typing.Integer.Kind:
switch kd.OptionalIntKind {
case typing.SmallIntKind:
case typing.SmallIntegerKind:
return "INT2"
case typing.IntegerKind:
return "INT4"
case typing.NotSpecifiedKind, typing.BigIntKind:
case typing.NotSpecifiedKind, typing.BigIntegerKind:
fallthrough
default:
// By default, we are using a larger data type to avoid the possibility of an integer overflow.
Expand Down Expand Up @@ -98,7 +98,7 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (
case "smallint":
return typing.KindDetails{
Kind: typing.Integer.Kind,
OptionalIntKind: typing.SmallIntKind,
OptionalIntKind: typing.SmallIntegerKind,
}, nil
case "integer":
return typing.KindDetails{
Expand All @@ -108,7 +108,7 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (
case "bigint":
return typing.KindDetails{
Kind: typing.Integer.Kind,
OptionalIntKind: typing.BigIntKind,
OptionalIntKind: typing.BigIntegerKind,
}, nil
case "double precision":
return typing.Float, nil
Expand Down
25 changes: 18 additions & 7 deletions clients/redshift/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,30 @@ func TestRedshiftDialect_KindForDataType(t *testing.T) {
{
// Integers
{
kd, err := dialect.KindForDataType("integer", "")
// Small integer
kd, err := dialect.KindForDataType("smallint", "")
assert.NoError(t, err)
assert.Equal(t, typing.Integer, kd)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntKind: typing.SmallIntegerKind}, kd)
}
{
kd, err := dialect.KindForDataType("bigint", "")
assert.NoError(t, err)
assert.Equal(t, typing.Integer, kd)
{
// Regular integers (upper)
kd, err := dialect.KindForDataType("INTEGER", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntKind: typing.IntegerKind}, kd)
}
{
// Regular integers (small)
kd, err := dialect.KindForDataType("integer", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntKind: typing.IntegerKind}, kd)
}
}
{
kd, err := dialect.KindForDataType("INTEGER", "")
// Big integer
kd, err := dialect.KindForDataType("bigint", "")
assert.NoError(t, err)
assert.Equal(t, typing.Integer, kd)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntKind: typing.BigIntegerKind}, kd)
}
}
{
Expand Down
4 changes: 2 additions & 2 deletions lib/typing/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type IntKind int

const (
NotSpecifiedKind = iota
SmallIntKind
SmallIntegerKind
IntegerKind
BigIntKind
BigIntegerKind
)

type KindDetails struct {
Expand Down

0 comments on commit cbc00a2

Please sign in to comment.