From aebc70d75a378571339763cf739164aebde30654 Mon Sep 17 00:00:00 2001 From: seawinde <149132972+seawinde@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:16:57 +0800 Subject: [PATCH] revert [improvement](mv) Support to use cast when create sync materialized view #38008 (#39378) ## Proposed changes this is brought by https://github.com/apache/doris/pull/38008 if use cast(FLOOR(MINUTE(time) / 15) as decimal(9, 0)) in group by clause when sync materialized view. if downgrade from 2.1.6 to 2.1.5 or upgrade 2.1.6 to 3.0.0 this may cause fe can not run. So revert the function. --- .../analysis/CreateMaterializedViewStmt.java | 5 +- .../mv_p0/contain_cast/mv_contains_cast.out | 11 -- .../contain_cast/mv_contains_cast.groovy | 130 ------------------ 3 files changed, 2 insertions(+), 144 deletions(-) delete mode 100644 regression-test/data/mv_p0/contain_cast/mv_contains_cast.out delete mode 100644 regression-test/suites/mv_p0/contain_cast/mv_contains_cast.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java index a7fb91657caa8e..ace179410d14a8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java @@ -273,9 +273,8 @@ public void analyzeSelectClause(Analyzer analyzer) throws AnalysisException { Expr selectListItemExpr = selectListItem.getExpr(); selectListItemExpr.setDisableTableName(true); - Expr realItem = selectListItemExpr.unwrapExpr(false); - if (!(realItem instanceof SlotRef) && !(realItem instanceof FunctionCallExpr) - && !(realItem instanceof ArithmeticExpr)) { + if (!(selectListItemExpr instanceof SlotRef) && !(selectListItemExpr instanceof FunctionCallExpr) + && !(selectListItemExpr instanceof ArithmeticExpr)) { throw new AnalysisException("The materialized view only support the single column or function expr. " + "Error column: " + selectListItemExpr.toSql()); } diff --git a/regression-test/data/mv_p0/contain_cast/mv_contains_cast.out b/regression-test/data/mv_p0/contain_cast/mv_contains_cast.out deleted file mode 100644 index 1d7f84992de560..00000000000000 --- a/regression-test/data/mv_p0/contain_cast/mv_contains_cast.out +++ /dev/null @@ -1,11 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !query_before -- -cc 2024-07-0300000:00 1 -cc 2024-07-0300015:00 1 -cd 2024-07-0300000:00 1 - --- !query_after -- -cc 2024-07-0300000:00 1 -cc 2024-07-0300015:00 1 -cd 2024-07-0300000:00 1 - diff --git a/regression-test/suites/mv_p0/contain_cast/mv_contains_cast.groovy b/regression-test/suites/mv_p0/contain_cast/mv_contains_cast.groovy deleted file mode 100644 index a60e3e574534ee..00000000000000 --- a/regression-test/suites/mv_p0/contain_cast/mv_contains_cast.groovy +++ /dev/null @@ -1,130 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -suite("mv_contains_cast") { - String db = context.config.getDbNameByFile(context.file) - sql "use ${db}" - sql "set runtime_filter_mode=OFF"; - sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" - - sql """ - drop table if exists test; - """ - - sql """ - CREATE TABLE IF NOT EXISTS test ( - `app_name` VARCHAR(64) NULL COMMENT '标识', - `event_id` VARCHAR(128) NULL COMMENT '标识', - `decision` VARCHAR(32) NULL COMMENT '枚举值', - `time` DATETIME NULL COMMENT '查询时间', - `id` VARCHAR(35) NOT NULL COMMENT 'od', - `code` VARCHAR(64) NULL COMMENT '标识', - `event_type` VARCHAR(32) NULL COMMENT '事件类型' - ) - DUPLICATE KEY(app_name, event_id) - PARTITION BY RANGE(time) - ( - FROM ("2024-07-01 00:00:00") TO ("2024-07-15 00:00:00") INTERVAL 1 HOUR - ) - DISTRIBUTED BY HASH(event_id) - BUCKETS 3 PROPERTIES ("replication_num" = "1"); - """ - - sql """ - insert into test values - ('aa', 'bc', 'cc', '2024-07-03 01:15:30', 'dd', 'ee', 'ff'), - ('as', 'bd', 'cd', '2024-07-03 06:09:30', 'dd', 'ee', 'ff'), - ('ad', 'be', 'cc', '2024-07-03 07:06:30', 'dd', 'ee', 'ff'), - ('af', 'bf', 'ce', '2024-07-04 10:01:30', 'dd', 'ee', 'ff'), - ('ag', 'bc', 'cc', '2024-07-04 12:55:30', 'dd', 'ee', 'ff'), - ('aa', 'bc', 'cc', '2024-07-05 01:15:30', 'dd', 'ee', 'ff'), - ('as', 'bd', 'cd', '2024-07-05 06:09:30', 'dd', 'ee', 'ff'), - ('ad', 'be', 'cc', '2024-07-06 07:06:30', 'dd', 'ee', 'ff'), - ('af', 'bf', 'ce', '2024-07-07 10:01:30', 'dd', 'ee', 'ff'), - ('ag', 'bc', 'cc', '2024-07-08 12:55:30', 'dd', 'ee', 'ff'); - """ - - def query_sql = """ - SELECT - decision, - CONCAT( - CONCAT( - DATE_FORMAT( - `time`, '%Y-%m-%d' - ), - '', - LPAD( - cast(FLOOR(MINUTE(`time`) / 15) as decimal(9, 0)) * 15, - 5, - '00' - ), - ':00' - ) - ) as time, - count(id) as cnt - from - test - where - date_trunc(time, 'minute') BETWEEN '2024-07-02 18:00:00' - AND '2024-07-03 20:00:00' - group by - decision, - DATE_FORMAT( - `time`, "%Y-%m-%d" - ), - cast(FLOOR(MINUTE(`time`) / 15) as decimal(9, 0)); - """ - - order_qt_query_before "${query_sql}" - - createMV(""" - CREATE MATERIALIZED VIEW sync_mv - AS - SELECT - decision, - code, - app_name, - event_id, - event_type, - date_trunc(time, 'minute'), - DATE_FORMAT( - `time`, '%Y-%m-%d' - ), - cast(FLOOR(MINUTE(time) / 15) as decimal(9, 0)), - count(id) as cnt - from - test - group by - code, - app_name, - event_id, - event_type, - date_trunc(time, 'minute'), - decision, - DATE_FORMAT(time, '%Y-%m-%d'), - cast(FLOOR(MINUTE(`time`) / 15) as decimal(9, 0)); - """) - - explain { - sql("""${query_sql}""") - // query rewrite by async materialized view capacity is not on 2.1 but on master, so tmp comment out - // when 2.1 support query rewrite by async materialized view, this can be uncomment - // contains "(sync_mv)" - } - - order_qt_query_after "${query_sql}" -}