Skip to content

CASE When: result type should be coercible to a common type #2818

@liukun4515

Description

@liukun4515

Describe the bug

❯ select case when 1=1 then true else 1 end;
+--------------------------------------------------------------------+
| CASE WHEN Int64(1) = Int64(1) THEN Boolean(true) ELSE Int64(1) END |
+--------------------------------------------------------------------+
| true                                                               |
+--------------------------------------------------------------------+
1 row in set. Query took 0.042 seconds.
❯ explain select case when 1=1 then true else 1 end;
+---------------+---------------------------------------------------------------------------------------------------+
| plan_type     | plan                                                                                              |
+---------------+---------------------------------------------------------------------------------------------------+
| logical_plan  | Projection: Boolean(true) AS CASE WHEN Int64(1) = Int64(1) THEN Boolean(true) ELSE Int64(1) END   |
|               |   EmptyRelation                                                                                   |
| physical_plan | ProjectionExec: expr=[true as CASE WHEN Int64(1) = Int64(1) THEN Boolean(true) ELSE Int64(1) END] |
|               |   EmptyExec: produce_one_row=true                                                                 |
|               |                                                                                                   |
+---------------+---------------------------------------------------------------------------------------------------+
2 rows in set. Query took 0.003 seconds.
❯ explain select case when 1>1 then true else 1 end;
+---------------+---------------------------------------------------------------------------------------------------+
| plan_type     | plan                                                                                              |
+---------------+---------------------------------------------------------------------------------------------------+
| logical_plan  | Projection: Boolean(true) AS CASE WHEN Int64(1) > Int64(1) THEN Boolean(true) ELSE Int64(1) END   |
|               |   EmptyRelation                                                                                   |
| physical_plan | ProjectionExec: expr=[true as CASE WHEN Int64(1) > Int64(1) THEN Boolean(true) ELSE Int64(1) END] |
|               |   EmptyExec: produce_one_row=true                                                                 |
|               |                                                                                                   |
+---------------+---------------------------------------------------------------------------------------------------+
2 rows in set. Query took 0.004 seconds.
❯  select case when 1>1 then true else 1 end;
+--------------------------------------------------------------------+
| CASE WHEN Int64(1) > Int64(1) THEN Boolean(true) ELSE Int64(1) END |
+--------------------------------------------------------------------+
| true                                                               |
+--------------------------------------------------------------------+

One case when sql has two diff result data type.

From other system, case when should have the common data type, but now the result type is the first non-null data type.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions