|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +suite("test_materialized_view_common_expr_push_down") { |
| 19 | + def baseTable = "test_base_tbl" |
| 20 | + def mvTable = "test_mv" |
| 21 | + |
| 22 | + def getJobState = { tableName -> |
| 23 | + def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName='${tableName}' ORDER BY CreateTime DESC LIMIT 1; """ |
| 24 | + return jobStateResult[0][8] |
| 25 | + } |
| 26 | + |
| 27 | + sql """set enable_common_expr_pushdown = true""" |
| 28 | + |
| 29 | + sql "DROP TABLE IF EXISTS ${baseTable}" |
| 30 | + sql """ |
| 31 | + CREATE TABLE `${baseTable}` ( |
| 32 | + `companyId` bigint NULL, |
| 33 | + `jobId` bigint NULL, |
| 34 | + `province` text NULL, |
| 35 | + `vCallerId` bigint NULL DEFAULT "0", |
| 36 | + `aCallerId` bigint NULL DEFAULT "-1" |
| 37 | + ) ENGINE=OLAP |
| 38 | + DUPLICATE KEY(`companyId`) |
| 39 | + DISTRIBUTED BY HASH(`companyId`) BUCKETS 8 |
| 40 | + PROPERTIES ( |
| 41 | + "replication_allocation" = "tag.location.default: 1" |
| 42 | + ); |
| 43 | + """ |
| 44 | + sql """ |
| 45 | + CREATE materialized VIEW ${mvTable} AS SELECT |
| 46 | + companyId as company_id, |
| 47 | + jobId as job_id, |
| 48 | + province as p, |
| 49 | + vCallerId as v_caller_id, |
| 50 | + aCallerId as a_caller_id |
| 51 | + FROM ${baseTable} |
| 52 | + GROUP BY company_id, job_id, p, v_caller_id, a_caller_id; |
| 53 | + """ |
| 54 | + int max_try_secs = 60 |
| 55 | + while (max_try_secs--) { |
| 56 | + String res = getJobState(baseTable) |
| 57 | + if (res == "FINISHED" || res == "CANCELLED") { |
| 58 | + assertEquals("FINISHED", res) |
| 59 | + sleep(3000) |
| 60 | + break |
| 61 | + } else { |
| 62 | + Thread.sleep(2000) |
| 63 | + if (max_try_secs < 1) { |
| 64 | + println "test timeout," + "state:" + res |
| 65 | + assertEquals("FINISHED",res) |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + sql "insert into ${baseTable} values(100,100,'北京',3,3)" |
| 71 | + sql "insert into ${baseTable} values(100,100,'广东',3,3)" |
| 72 | + |
| 73 | + qt_sql """ select company_id from ${baseTable} index ${mvTable} where v_caller_id = 3 and if(`a_caller_id` is null,-1, `a_caller_id`) = 3 """ |
| 74 | + |
| 75 | + sql "DROP TABLE ${baseTable} FORCE;" |
| 76 | +} |
0 commit comments