Skip to content

Commit 45e8f5c

Browse files
committed
Revert "randgen: fix recent regression in tuple generation"
This reverts commit ed045f3.
1 parent 9469c4b commit 45e8f5c

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

pkg/sql/randgen/datum.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,16 @@ func RandDatumWithNullChance(
239239
}
240240
return tree.NewDJsonpath(*jp.AST)
241241
case types.TupleFamily:
242-
tuple := tree.DTuple{D: make(tree.Datums, len(typ.TupleContents()))}
243242
if nullChance == 0 {
244-
// Even if nullOk=false (which is when nullChance=0), we still want
245-
// to generate a NULL _element_ in 10% of cases.
246243
nullChance = 10
247244
}
245+
datums := make([]tree.Datum, len(typ.TupleContents()))
248246
for i := range typ.TupleContents() {
249-
tuple.D[i] = RandDatumWithNullChance(
247+
datums[i] = RandDatumWithNullChance(
250248
rng, typ.TupleContents()[i], nullChance, favorCommonData, targetColumnIsUnique,
251249
)
252250
}
253-
// Calling ResolvedType causes the internal TupleContents types to be
254-
// populated (as well as resolves the type of each tuple element).
255-
tuple.ResolvedType()
256-
return &tuple
251+
return tree.NewDTuple(typ, datums...)
257252
case types.BitFamily:
258253
width := typ.Width()
259254
if width == 0 {

pkg/sql/randgen/types_test.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"testing"
1111

12-
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
1312
"github.com/cockroachdb/cockroach/pkg/sql/types"
1413
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
1514
"github.com/cockroachdb/cockroach/pkg/util/randutil"
@@ -67,30 +66,7 @@ func TestCanonical(t *testing.T) {
6766
datum := RandDatum(rng, typ, false)
6867
datumTyp := datum.ResolvedType()
6968
if !datumTyp.Equivalent(typ.Canonical()) {
70-
var tupleHasNullElement func(tree.Datum) bool
71-
tupleHasNullElement = func(d tree.Datum) bool {
72-
tup, ok := d.(*tree.DTuple)
73-
if !ok {
74-
return false
75-
}
76-
for _, el := range tup.D {
77-
if el == tree.DNull {
78-
return true
79-
}
80-
if tupleHasNullElement(el) {
81-
return true
82-
}
83-
}
84-
return false
85-
}
86-
// If we have a tuple, then we might have included a NULL element.
87-
// By construction in RandDatum, TupleContents[i] has been updated
88-
// to types.Unknown. In such case, we give an exception and don't
89-
// fail the test.
90-
tupleException := tupleHasNullElement(datum)
91-
if !tupleException {
92-
t.Errorf("fail: canonical type of %+v is %+v and the datum's type is %+v", typ, typ.Canonical(), datumTyp)
93-
}
69+
t.Errorf("fail: canonical type of %+v is %+v and the datum's type is %+v", typ, typ.Canonical(), datumTyp)
9470
}
9571

9672
if datumTyp.Oid() != typ.Canonical().Oid() {

0 commit comments

Comments
 (0)