Skip to content

Conversation

@xy720
Copy link
Member

@xy720 xy720 commented Sep 22, 2020

Proposed changes

Fix #4645

Relevant pr #3396

To Reproduce
Steps to reproduce the behavior:

  1. create table
+----------------------+-------------+------+-------+---------------------+---------+
| Field                | Type        | Null | Key   | Default             | Extra   |
+----------------------+-------------+------+-------+---------------------+---------+
| event_day            | INT         | No   | true  | NULL                |         |
| event_hour           | TINYINT     | No   | true  | 0                   |         |
| event_minute         | TINYINT     | No   | true  | 0                   |         |
| event_time           | DATETIME    | No   | true  | 1970-01-01 00:00:00 |         |
| search_page          | VARCHAR(30) | No   | true  |                     |         |
| search_source        | TINYINT     | No   | true  | 0                   |         |
| soft_version         | VARCHAR(30) | No   | true  |                     |         |
| not_arrived_category | VARCHAR(30) | No   | true  |                     |         |
| pv                   | FLOAT       | No   | false | 0                   | REPLACE |
+----------------------+-------------+------+-------+---------------------+---------+
CREATE TABLE `test_tbl` (
  `event_day` int(11) NOT NULL COMMENT "日期,如20191016",
  `event_hour` tinyint(4) NOT NULL DEFAULT "0" COMMENT "小时,如8",
  `event_minute` tinyint(4) NOT NULL DEFAULT "0" COMMENT "分钟,如59",
  `event_time` datetime NOT NULL DEFAULT "1970-01-01 00:00:00" COMMENT "隶属时间(区间查询用)",
  `search_page` varchar(30) NOT NULL DEFAULT "" COMMENT "page来源",
  `search_source` tinyint(4) NOT NULL DEFAULT "0" COMMENT "search_source来源",
  `soft_version` varchar(30) NOT NULL DEFAULT "" COMMENT "APP版本,如11.15.0.2",
  `not_arrived_category` varchar(30) NOT NULL DEFAULT "" COMMENT "未到达原因",
  `pv` float NOT NULL DEFAULT "0" COMMENT "聚合pv数"
) ENGINE=OLAP
UNIQUE KEY(`event_day`, `event_hour`, `event_minute`, `event_time`, `search_page`, `search_source`, `soft_version`, `not_arrived_category`)
COMMENT "OLAP"
PARTITION BY RANGE(`event_day`)
(PARTITION p202006 VALUES [("20200601"), ("20200701")),
PARTITION p202007 VALUES [("20200701"), ("20200801")),
PARTITION p202008 VALUES [("20200801"), ("20200901")),
PARTITION p202009 VALUES [("20200901"), ("20201001")),
PARTITION p202010 VALUES [("20201001"), ("20201101")),
PARTITION p202011 VALUES [("20201101"), ("20201201")),
PARTITION p202012 VALUES [("20201201"), ("20210101")))
DISTRIBUTED BY HASH(`event_day`) BUCKETS 16
PROPERTIES (
"replication_num" = "3",
"in_memory" = "false",
"storage_format" = "V2"
);
  1. input sql
    SELECT
        case when "condition" = ' ' then 'string' else search_source end as search_source
    FROM test_tbl
    GROUP BY search_source
  1. doris report an analysis error.

In the sql above, search_source is a TINYINT type and 'string' is VARCHAR(*) type. Because the value of WhenExpr "condition" = ' ' is false, so this case-when clause will produce a CastExpr as SelectListItem with a TINYINT type SlotRef child represents search_source after rewriting the sql. However, the analyzeAggregation() method cannot handle the case where SelectListItem is CaseExpr(implicitCast).

Expected behavior
Analysis successfully.

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman added area/planner Issues or PRs related to the query planner kind/fix Categorizes issue or PR as related to a bug. approved Indicates a PR has been approved by one committer. labels Sep 22, 2020
@morningman morningman merged commit e7d9438 into apache:master Sep 23, 2020
@yangzhg yangzhg mentioned this pull request Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. area/planner Issues or PRs related to the query planner kind/fix Categorizes issue or PR as related to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] An analysis error will report when there are different types in case-when-then-else with group by clause

2 participants