From 973ebf437385a1e095bb98dd74fc25efd0e813dd Mon Sep 17 00:00:00 2001 From: Daniel Harrison Date: Thu, 28 Dec 2017 15:33:15 -0500 Subject: [PATCH] sqlbase/testutils: also produce negatives in RandDatum Closes #20902. Release note: None --- pkg/sql/sqlbase/testutils.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/sql/sqlbase/testutils.go b/pkg/sql/sqlbase/testutils.go index 29ba24b5cb51..eb2fc4662aac 100644 --- a/pkg/sql/sqlbase/testutils.go +++ b/pkg/sql/sqlbase/testutils.go @@ -76,13 +76,15 @@ func RandDatum(rng *rand.Rand, typ ColumnType, nullOk bool) tree.Datum { case ColumnType_BOOL: return tree.MakeDBool(rng.Intn(2) == 1) case ColumnType_INT: - return tree.NewDInt(tree.DInt(rng.Int63())) + // int64(rng.Uint64()) to get negative numbers, too + return tree.NewDInt(tree.DInt(int64(rng.Uint64()))) case ColumnType_FLOAT: return tree.NewDFloat(tree.DFloat(rng.NormFloat64())) case ColumnType_DECIMAL: d := &tree.DDecimal{} d.Decimal.SetExponent(int32(rng.Intn(40) - 20)) - d.Decimal.SetCoefficient(rng.Int63()) + // int64(rng.Uint64()) to get negative numbers, too + d.Decimal.SetCoefficient(int64(rng.Uint64())) return d case ColumnType_DATE: return tree.NewDDate(tree.DDate(rng.Intn(10000))) @@ -147,7 +149,8 @@ func RandDatum(rng *rand.Rand, typ ColumnType, nullOk bool) tree.Datum { } return tree.NewDName(string(p)) case ColumnType_OID: - return tree.NewDOid(tree.DInt(rng.Int63())) + // int64(rng.Uint64()) to get negative numbers, too + return tree.NewDOid(tree.DInt(int64(rng.Uint64()))) case ColumnType_NULL: return tree.DNull case ColumnType_ARRAY: