seawinde commented on code in PR #62951: URL: https://github.com/apache/doris/pull/62951#discussion_r3272677598
########## regression-test/suites/nereids_rules_p0/mv/date_trunc/test_date_trunc_whole_month_rewrite.groovy: ########## @@ -0,0 +1,353 @@ +package mv.date_trunc +// 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("test_date_trunc_whole_month_rewrite") { + 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 tb_detail + """ + + sql """ + CREATE TABLE tb_detail ( + dt DATE NOT NULL, + uuid VARCHAR(50) NOT NULL, + amt DECIMAL(10, 2) NOT NULL + ) DUPLICATE KEY(dt, uuid) + AUTO PARTITION BY RANGE (date_trunc(dt, 'day')) () + DISTRIBUTED BY HASH(uuid) BUCKETS 3 + PROPERTIES ("replication_num" = "1") + """ + + sql """ + insert into tb_detail values + ('2025-01-01', 'uuid1', 100.00), + ('2025-01-15', 'uuid2', 200.00), + ('2025-01-31', 'uuid3', 300.00), + ('2025-02-01', 'uuid4', 400.00), + ('2025-02-28', 'uuid5', 500.00), + ('2024-02-01', 'uuid6', 600.00), + ('2024-02-29', 'uuid7', 700.00) + """ + + sql """analyze table tb_detail with sync""" + + // Create MV with date_trunc by month + def mv_name = "mv_month" + sql """ + drop materialized view if exists ${mv_name} + """ + + sql """ + CREATE MATERIALIZED VIEW ${mv_name} + BUILD IMMEDIATE + REFRESH ON MANUAL + PARTITION BY (month_dt) + DISTRIBUTED BY RANDOM BUCKETS AUTO + PROPERTIES ('replication_num' = '1') + AS SELECT + date_trunc(dt, 'month') AS month_dt, + SUM(amt) AS gmv, + COUNT(DISTINCT uuid) AS uv + FROM tb_detail + GROUP BY month_dt + """ + + def job_name = getJobName(db, mv_name) + waitingMTMVTaskFinished(job_name) + + sql """analyze table ${mv_name} with sync""" + + // Test 1: Whole month range with <= (January 2025) + def query1 = """ + SELECT SUM(amt) AS gmv + FROM tb_detail + WHERE dt >= '2025-01-01' AND dt <= '2025-01-31' + """ + + explain { + sql("${query1}") + contains("${mv_name} chose") + } + + def result1 = sql "${query1}" + def expected1 = sql """ Review Comment: The expected result here is computed by executing essentially the same query while MV rewrite is still enabled. If the rewrite is incorrect, both `result1` and `expected1` may use the same incorrect MV plan, so this assertion may still pass. Could we use hard-coded expected results, or temporarily disable materialized view rewrite when computing the expected result? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
