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

colexec: reject CASE operator with Bytes output type #44660

Merged
merged 1 commit into from Feb 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/sql/colexec/execplan.go
Expand Up @@ -1193,7 +1193,15 @@ func planProjectionOperators(
buffer := NewBufferOp(input)
caseOps := make([]Operator, len(t.Whens))
caseOutputType := typeconv.FromColumnType(t.ResolvedType())
if caseOutputType == coltypes.Unhandled {
switch caseOutputType {
case coltypes.Bytes:
// Currently, there is a contradiction between the way CASE operator
// works (which populates its output in arbitrary order) and the flat
// bytes implementation of Bytes type (which prohibits sets in arbitrary
// order), so we reject such scenario to fall back to row-by-row engine.
return nil, resultIdx, ct, internalMemUsed, errors.Newf(
"unsupported type %s in CASE operator", t.ResolvedType().String())
case coltypes.Unhandled:
return nil, resultIdx, ct, internalMemUsed, errors.Newf(
"unsupported type %s", t.ResolvedType().String())
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/vectorize
Expand Up @@ -1083,3 +1083,13 @@ CREATE TABLE t44304(c0 INT); INSERT INTO t44304 VALUES (0)
query I
SELECT * FROM t44304 WHERE CASE WHEN t44304.c0 > 0 THEN NULL END
----

# Regression test for CASE operator and flat bytes.
statement ok
CREATE TABLE t44624(c0 STRING, c1 BOOL); INSERT INTO t44624(rowid, c0, c1) VALUES (0, '', true), (1, '', NULL)

query TB
SELECT * FROM t44624 ORDER BY CASE WHEN c1 IS NULL THEN c0 WHEN true THEN c0 END
----
· true
· NULL