Skip to content

Commit ba3df4c

Browse files
committed
Fix build on 32 bit systems.
1 parent 7bc2294 commit ba3df4c

File tree

11 files changed

+41
-34
lines changed

11 files changed

+41
-34
lines changed

.github/workflows/server-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
env:
2121
CI_TEST: "true"
2222
SERVER_ENGINE_TEST: "true"
23+
- name: Test using Server Engine (32 bit)
24+
run: go test ./...
25+
env:
26+
GOARCH: "386"
27+
CI_TEST: "true"
28+
SERVER_ENGINE_TEST: "true"
2329
- name: Test using Server Engine
2430
run: go test -race ./...
2531
env:

sql/expression/function/export_set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestExportSet(t *testing.T) {
6161
{"negative number of bits", []interface{}{5, "1", "0", ",", -5}, "1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", false},
6262

6363
// Large numbers
64-
{"large number", []interface{}{4294967295, "1", "0", ",", 32}, "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", false},
64+
{"large number", []interface{}{int64(4294967295), "1", "0", ",", 32}, "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", false},
6565
{"powers of 2", []interface{}{1024, "1", "0", ",", 12}, "0,0,0,0,0,0,0,0,0,0,1,0", false},
6666

6767
// NULL handling

sql/expression/function/extract.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
169169
ss := dateTime.Second()
170170
return dd + hh + mm + ss, nil
171171
case "DAY_MICROSECOND":
172-
dd := dateTime.Day() * 1_00_00_00_000000
173-
hh := dateTime.Hour() * 1_00_00_000000
174-
mm := dateTime.Minute() * 1_00_000000
175-
ss := dateTime.Second() * 1_000000
176-
mmmmmm := dateTime.Nanosecond() / 1000
172+
dd := int64(dateTime.Day()) * 1_00_00_00_000000
173+
hh := int64(dateTime.Hour()) * 1_00_00_000000
174+
mm := int64(dateTime.Minute()) * 1_00_000000
175+
ss := int64(dateTime.Second()) * 1_000000
176+
mmmmmm := int64(dateTime.Nanosecond()) / 1000
177177
return dd + hh + mm + ss + mmmmmm, nil
178178
case "HOUR_MINUTE":
179179
hh := dateTime.Hour() * 1_00
@@ -185,19 +185,19 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
185185
ss := dateTime.Second()
186186
return hh + mm + ss, nil
187187
case "HOUR_MICROSECOND":
188-
hh := dateTime.Hour() * 1_00_00_000000
189-
mm := dateTime.Minute() * 1_00_000000
190-
ss := dateTime.Second() * 1_000000
191-
mmmmmm := dateTime.Nanosecond() / 1000
188+
hh := int64(dateTime.Hour()) * 1_00_00_000000
189+
mm := int64(dateTime.Minute()) * 1_00_000000
190+
ss := int64(dateTime.Second()) * 1_000000
191+
mmmmmm := int64(dateTime.Nanosecond()) / 1000
192192
return hh + mm + ss + mmmmmm, nil
193193
case "MINUTE_SECOND":
194194
mm := dateTime.Minute() * 1_00
195195
ss := dateTime.Second()
196196
return mm + ss, nil
197197
case "MINUTE_MICROSECOND":
198-
mm := dateTime.Minute() * 1_00_000000
199-
ss := dateTime.Second() * 1_000000
200-
mmmmmm := dateTime.Nanosecond() / 1000
198+
mm := int64(dateTime.Minute()) * 1_00_000000
199+
ss := int64(dateTime.Second()) * 1_000000
200+
mmmmmm := int64(dateTime.Nanosecond()) / 1000
201201
return mm + ss + mmmmmm, nil
202202
case "SECOND_MICROSECOND":
203203
ss := dateTime.Second() * 1_000000

sql/expression/function/extract_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestExtract(t *testing.T) {
132132
name: "get day_microsecond",
133133
unit: "DAY_MICROSECOND",
134134
dateTime: "2023-11-12 11:22:33.445566",
135-
expected: 12112233445566,
135+
expected: int64(12112233445566),
136136
},
137137
{
138138
name: "get hour_minute",
@@ -150,7 +150,7 @@ func TestExtract(t *testing.T) {
150150
name: "get hour_microsecond",
151151
unit: "HOUR_MICROSECOND",
152152
dateTime: "2023-11-12 11:22:33.445566",
153-
expected: 112233445566,
153+
expected: int64(112233445566),
154154
},
155155
{
156156
name: "get minute_second",
@@ -162,7 +162,7 @@ func TestExtract(t *testing.T) {
162162
name: "get minute_microsecond",
163163
unit: "MINUTE_MICROSECOND",
164164
dateTime: "2023-11-12 11:22:33.445566",
165-
expected: 2233445566,
165+
expected: int64(2233445566),
166166
},
167167
{
168168
name: "get second_microsecond",

sql/expression/function/make_set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestMakeSet(t *testing.T) {
7676

7777
// Large numbers
7878
{"max uint64 bits", []interface{}{^uint64(0), "a", "b", "c"}, "a,b,c", false},
79-
{"large positive number", []interface{}{4294967295, "a", "b", "c"}, "a,b,c", false},
79+
{"large positive number", []interface{}{int64(4294967295), "a", "b", "c"}, "a,b,c", false},
8080

8181
// Empty strings
8282
{"empty string values", []interface{}{3, "", "test", ""}, ",test", false},

sql/expression/function/oct_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func TestOct(t *testing.T) {
5757
// Edge cases
5858
{"max int32", types.Int32, sql.NewRow(math.MaxInt32), "17777777777"},
5959
{"min int32", types.Int32, sql.NewRow(math.MinInt32), "1777777777760000000000"},
60-
{"max int64", types.Int64, sql.NewRow(math.MaxInt64), "777777777777777777777"},
61-
{"min int64", types.Int64, sql.NewRow(math.MinInt64), "1000000000000000000000"},
60+
{"max int64", types.Int64, sql.NewRow(int64(math.MaxInt64)), "777777777777777777777"},
61+
{"min int64", types.Int64, sql.NewRow(int64(math.MinInt64)), "1000000000000000000000"},
6262

6363
// Decimal numbers
6464
{"decimal", types.Float64, sql.NewRow(15.5), "17"},

sql/rowexec/ddl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bufio"
1919
"fmt"
2020
"io"
21+
"math"
2122
"os"
2223
"strings"
2324
"time"
@@ -94,7 +95,7 @@ func (b *BaseBuilder) buildLoadData(ctx *sql.Context, n *plan.LoadData, row sql.
9495
}
9596

9697
scanner := bufio.NewScanner(reader)
97-
scanner.Buffer(nil, int(types.LongTextBlobMax))
98+
scanner.Buffer(nil, int(min(types.LongTextBlobMax, math.MaxInt)))
9899
scanner.Split(n.SplitLines)
99100

100101
sch := n.Schema()

sql/rowexec/proc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (b *BaseBuilder) buildLoop(ctx *sql.Context, n *plan.Loop, row sql.Row) (sq
306306
// It's technically valid to make an infinite loop, but we don't want to actually allow that
307307
const maxIterationCount = 10_000_000_000
308308

309-
for loopIteration := 0; loopIteration <= maxIterationCount; loopIteration++ {
309+
for loopIteration := int64(0); loopIteration <= maxIterationCount; loopIteration++ {
310310
if loopIteration >= maxIterationCount {
311311
return nil, fmt.Errorf("infinite LOOP detected")
312312
}

sql/types/geometry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func (t GeometryType) MatchSRID(v interface{}) error {
546546
}
547547

548548
func ValidateSRID(srid int, funcName string) error {
549-
if srid < 0 || srid > math.MaxUint32 {
549+
if srid < 0 || srid > min(math.MaxUint32, math.MaxInt) {
550550
return sql.ErrInvalidSRID.New(funcName)
551551
}
552552
if _, ok := SupportedSRIDs[uint32(srid)]; !ok {

sql/types/number.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,27 +1114,27 @@ func convertToUint64(t NumberTypeImpl_, v interface{}) (uint64, sql.ConvertInRan
11141114
return uint64(v.UTC().Unix()), sql.InRange, nil
11151115
case int:
11161116
if v < 0 {
1117-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1117+
return math.MaxUint64 - uint64(-v-1), sql.OutOfRange, nil
11181118
}
11191119
return uint64(v), sql.InRange, nil
11201120
case int8:
11211121
if v < 0 {
1122-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1122+
return math.MaxUint64 - uint64(-v-1), sql.OutOfRange, nil
11231123
}
11241124
return uint64(v), sql.InRange, nil
11251125
case int16:
11261126
if v < 0 {
1127-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1127+
return math.MaxUint64 - uint64(-v-1), sql.OutOfRange, nil
11281128
}
11291129
return uint64(v), sql.InRange, nil
11301130
case int32:
11311131
if v < 0 {
1132-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1132+
return math.MaxUint64 - uint64(-v-1), sql.OutOfRange, nil
11331133
}
11341134
return uint64(v), sql.InRange, nil
11351135
case int64:
11361136
if v < 0 {
1137-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1137+
return math.MaxUint64 - uint64(-v-1), sql.OutOfRange, nil
11381138
}
11391139
return uint64(v), sql.InRange, nil
11401140
case uint:
@@ -1205,28 +1205,28 @@ func convertToUint32(t NumberTypeImpl_, v interface{}) (uint32, sql.ConvertInRan
12051205
case int:
12061206
if v < 0 {
12071207
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1208-
} else if v > math.MaxUint32 {
1208+
} else if v > min(math.MaxUint32, math.MaxInt) {
12091209
return uint32(math.MaxUint32), sql.OutOfRange, nil
12101210
}
12111211
return uint32(v), sql.InRange, nil
12121212
case int8:
12131213
if v < 0 {
12141214
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1215-
} else if int(v) > math.MaxUint32 {
1215+
} else if int(v) > min(math.MaxUint32, math.MaxInt) {
12161216
return uint32(math.MaxUint32), sql.OutOfRange, nil
12171217
}
12181218
return uint32(v), sql.InRange, nil
12191219
case int16:
12201220
if v < 0 {
12211221
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1222-
} else if int(v) > math.MaxUint32 {
1222+
} else if int(v) > min(math.MaxUint32, math.MaxInt) {
12231223
return uint32(math.MaxUint32), sql.OutOfRange, nil
12241224
}
12251225
return uint32(v), sql.InRange, nil
12261226
case int32:
12271227
if v < 0 {
12281228
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1229-
} else if int(v) > math.MaxUint32 {
1229+
} else if int(v) > min(math.MaxUint32, math.MaxInt) {
12301230
return uint32(math.MaxUint32), sql.OutOfRange, nil
12311231
}
12321232
return uint32(v), sql.InRange, nil

0 commit comments

Comments
 (0)