Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: add volatility info for Unknown to Tuple cast #50436

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/sql/opt/memo/testdata/logprops/scalar
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,23 @@ project
├── fd: (3)-->(1,2)
├── prune: (1-3)
└── interesting orderings: (+3)

# Regression test for #50258: cast from unknown to tuple.
expr
(Values
[
(Tuple [ (Cast (Null "unknown") "tuple{string}") ] "tuple{string}" )
]
[ (Cols [ (NewColumn "a" "tuple{string}") ]) ]
)
----
values
├── columns: a:1(tuple{string})
├── cardinality: [1 - 1]
├── immutable
├── key: ()
├── fd: ()-->(1)
├── prune: (1)
└── tuple [type=tuple{string}]
└── cast: [type=tuple{string}]
└── null [type=unknown]
3 changes: 3 additions & 0 deletions pkg/sql/sem/tree/casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ var validCasts = []castInfo{
{from: types.StringFamily, to: types.EnumFamily, volatility: VolatilityImmutable},
{from: types.EnumFamily, to: types.EnumFamily, volatility: VolatilityImmutable},
{from: types.BytesFamily, to: types.EnumFamily, volatility: VolatilityImmutable},

// Casts to TupleFamily.
{from: types.UnknownFamily, to: types.TupleFamily, volatility: VolatilityImmutable},
}

type castsMapKey struct {
Expand Down
19 changes: 19 additions & 0 deletions pkg/sql/sem/tree/casts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,22 @@ func TestCastsVolatilityMatchesPostgres(t *testing.T) {
}
}
}

// TestCastsFromUnknown verifies that there is a cast from Unknown defined for
// all type families.
func TestCastsFromUnknown(t *testing.T) {
defer leaktest.AfterTest(t)()

for v := range types.Family_name {
switch fam := types.Family(v); fam {
case types.UnknownFamily, types.AnyFamily:
// These type families are exceptions.

default:
cast := lookupCast(types.UnknownFamily, fam)
if cast == nil {
t.Errorf("cast from Unknown to %s does not exist", fam)
}
}
}
}