Skip to content

Commit 3d51c5c

Browse files
authored
Merge pull request #2966 from dolthub/macneale4/float-bigint-conversion
Fix float to bigint conversion result
2 parents c5f7d51 + 0be302e commit 3d51c5c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,29 @@ var AlterTableScripts = []ScriptTest{
10061006
},
10071007
},
10081008
},
1009+
{
1010+
// https://github.com/dolthub/dolt/issues/9178
1011+
Name: "alter modify column type float to bigint",
1012+
SetUpScript: []string{
1013+
"create table t1 (pk int primary key, c1 float);",
1014+
"insert into t1 values (1, 0.0)",
1015+
"insert into t1 values (2, 127.9)",
1016+
"insert into t1 values (3, 42.1)",
1017+
},
1018+
Assertions: []ScriptTestAssertion{
1019+
{
1020+
Query: "alter table t1 modify column c1 bigint",
1021+
},
1022+
{
1023+
Query: "select * from t1 order by pk",
1024+
Expected: []sql.Row{
1025+
{1, int64(0)},
1026+
{2, int64(128)},
1027+
{3, int64(42)},
1028+
},
1029+
},
1030+
},
1031+
},
10091032
}
10101033

10111034
var RenameTableScripts = []ScriptTest{

enginetest/queries/queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11791,6 +11791,6 @@ func MustParseTime(layout, value string) time.Time {
1179111791

1179211792
func UnixTimeInLocal(sec, nsec int64) time.Time {
1179311793
t := time.Unix(sec, nsec)
11794-
_, offset := t.Zone()
11794+
_, offset := time.Now().Zone()
1179511795
return t.Add(time.Second * time.Duration(offset)).In(time.UTC)
1179611796
}

sql/types/number.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ func convertToInt64(t NumberTypeImpl_, v interface{}) (int64, sql.ConvertInRange
969969
} else if v < float32(math.MinInt64) {
970970
return math.MinInt64, sql.OutOfRange, nil
971971
}
972-
return int64(math.Round(float64(v))), sql.OutOfRange, nil
972+
return int64(math.Round(float64(v))), sql.InRange, nil
973973
case float64:
974974
if v > float64(math.MaxInt64) {
975975
return math.MaxInt64, sql.OutOfRange, nil

0 commit comments

Comments
 (0)