|
9 | 9 | "fmt"
|
10 | 10 | "testing"
|
11 | 11 |
|
| 12 | + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" |
12 | 13 | "github.com/cockroachdb/cockroach/pkg/sql/types"
|
13 | 14 | "github.com/cockroachdb/cockroach/pkg/util/leaktest"
|
14 | 15 | "github.com/cockroachdb/cockroach/pkg/util/randutil"
|
@@ -66,7 +67,30 @@ func TestCanonical(t *testing.T) {
|
66 | 67 | datum := RandDatum(rng, typ, false)
|
67 | 68 | datumTyp := datum.ResolvedType()
|
68 | 69 | if !datumTyp.Equivalent(typ.Canonical()) {
|
69 |
| - t.Errorf("fail: canonical type of %+v is %+v and the datum's type is %+v", typ, typ.Canonical(), datumTyp) |
| 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 | + } |
70 | 94 | }
|
71 | 95 |
|
72 | 96 | if datumTyp.Oid() != typ.Canonical().Oid() {
|
|
0 commit comments