|
| 1 | +package limit |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The ASF licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the |
| 7 | +// "License"); you may not use this file except in compliance |
| 8 | +// with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, |
| 13 | +// software distributed under the License is distributed on an |
| 14 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +// KIND, either express or implied. See the License for the |
| 16 | +// specific language governing permissions and limitations |
| 17 | +// under the License. |
| 18 | + |
| 19 | +suite("refresh_with_sql_limit") { |
| 20 | + String db = context.config.getDbNameByFile(context.file) |
| 21 | + sql "use ${db}" |
| 22 | + sql "set runtime_filter_mode=OFF"; |
| 23 | + sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" |
| 24 | + |
| 25 | + sql """ |
| 26 | + drop table if exists orders; |
| 27 | + """ |
| 28 | + |
| 29 | + sql """ |
| 30 | + CREATE TABLE IF NOT EXISTS orders ( |
| 31 | + o_orderkey INTEGER NOT NULL, |
| 32 | + o_custkey INTEGER NOT NULL, |
| 33 | + o_orderstatus CHAR(1) NOT NULL, |
| 34 | + o_totalprice DECIMALV3(15,2) NOT NULL, |
| 35 | + o_orderdate DATE NOT NULL, |
| 36 | + o_orderpriority CHAR(15) NOT NULL, |
| 37 | + o_clerk CHAR(15) NOT NULL, |
| 38 | + o_shippriority INTEGER NOT NULL, |
| 39 | + O_COMMENT VARCHAR(79) NOT NULL |
| 40 | + ) |
| 41 | + DUPLICATE KEY(o_orderkey, o_custkey) |
| 42 | + PARTITION BY RANGE(o_orderdate) ( |
| 43 | + PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), |
| 44 | + PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), |
| 45 | + PARTITION `day_4` VALUES LESS THAN ("2023-12-30") |
| 46 | + ) |
| 47 | + DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 |
| 48 | + PROPERTIES ( |
| 49 | + "replication_num" = "1" |
| 50 | + ); |
| 51 | + """ |
| 52 | + |
| 53 | + sql """ |
| 54 | + insert into orders values |
| 55 | + (1, 1, 'o', 9.5, '2023-12-08', 'a', 'b', 1, 'yy'), |
| 56 | + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), |
| 57 | + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), |
| 58 | + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), |
| 59 | + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), |
| 60 | + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), |
| 61 | + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), |
| 62 | + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), |
| 63 | + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), |
| 64 | + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), |
| 65 | + (3, 1, 'o', 33.5, '2023-12-10', 'a', 'b', 1, 'yy'), |
| 66 | + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), |
| 67 | + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), |
| 68 | + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), |
| 69 | + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), |
| 70 | + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), |
| 71 | + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), |
| 72 | + (5, 2, 'o', 1.2, '2023-12-12', 'c','d',2, 'mi'); |
| 73 | + """ |
| 74 | + sql """analyze table orders with sync""" |
| 75 | + |
| 76 | + |
| 77 | + sql """DROP MATERIALIZED VIEW IF EXISTS mv_1""" |
| 78 | + sql """set default_order_by_limit = 2;""" |
| 79 | + sql """set sql_select_limit = 2;""" |
| 80 | + sql""" |
| 81 | + CREATE MATERIALIZED VIEW mv_1 |
| 82 | + BUILD DEFERRED REFRESH COMPLETE ON MANUAL |
| 83 | + DISTRIBUTED BY RANDOM BUCKETS 2 |
| 84 | + PROPERTIES ('replication_num' = '1') |
| 85 | + AS select * from orders; |
| 86 | + """ |
| 87 | + sql """refresh materialized view mv_1 auto;""" |
| 88 | + def job_name = getJobName(db, "mv_1"); |
| 89 | + waitingMTMVTaskFinished(job_name) |
| 90 | + |
| 91 | + // Reset and test mv data is right or not |
| 92 | + sql """set default_order_by_limit = -1;""" |
| 93 | + sql """set sql_select_limit = -1;""" |
| 94 | + order_qt_query_mv_1 "select * from mv_1" |
| 95 | + sql """ DROP MATERIALIZED VIEW IF EXISTS mv_1""" |
| 96 | + |
| 97 | + |
| 98 | + sql """DROP MATERIALIZED VIEW IF EXISTS mv_2""" |
| 99 | + sql """set default_order_by_limit = 2""" |
| 100 | + sql """set sql_select_limit = 2""" |
| 101 | + sql""" |
| 102 | + CREATE MATERIALIZED VIEW mv_2 |
| 103 | + BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL |
| 104 | + DISTRIBUTED BY RANDOM BUCKETS 2 |
| 105 | + PROPERTIES ('replication_num' = '1') |
| 106 | + AS select * from orders; |
| 107 | + """ |
| 108 | + waitingMTMVTaskFinished(getJobName(db, "mv_2")) |
| 109 | + |
| 110 | + // Reset and test mv data is right or not |
| 111 | + sql """set default_order_by_limit = -1;""" |
| 112 | + sql """set sql_select_limit = -1;""" |
| 113 | + order_qt_query_mv_2 "select * from mv_2" |
| 114 | + sql """ DROP MATERIALIZED VIEW IF EXISTS mv_2""" |
| 115 | +} |
0 commit comments