Skip to content

Add booleans support to the CASE statement #1156

@alamb

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Sometimes it is useful to use a CASE statement to evaluate predicates within a project operation

Describe the solution you'd like

I would like to be able to create a CASE statement that has a boolean result

For example the following query should return false but instead returns a runtime error:

> explain select case when 'cpu' != 'cpu' then true else false end;
Execution("CASE does not support 'Boolean'")

A workaround is to use a different type like string:

> explain select case when 'cpu' != 'cpu' then 'yes' else 'no' end;
+---------------+-----------------------------------------+
| plan_type     | plan                                    |
+---------------+-----------------------------------------+
| logical_plan  | Projection: Utf8("no")                  |
|               |   EmptyRelation                         |
| physical_plan | ProjectionExec: expr=[no as Utf8("no")] |
|               |   EmptyExec: produce_one_row=true       |
|               |                                         |
+---------------+-----------------------------------------+
2 rows in set. Query took 0.003 seconds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions