diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveDlaTable.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveDlaTable.java index 91b1aaa0cc7466..b517ca999835be 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveDlaTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveDlaTable.java @@ -97,7 +97,7 @@ public MTMVSnapshotIf getTableSnapshot(MTMVRefreshContext context, Optional partitionList = cache.getAllPartitionsWithCache(hmsTable, Lists.newArrayList(hivePartitionValues.getPartitionValuesMap().values())); if (CollectionUtils.isEmpty(partitionList)) { - throw new AnalysisException("partitionList is empty, table name: " + hmsTable.getName()); + return new MTMVMaxTimestampSnapshot(hmsTable.getName(), 0L); } for (HivePartition hivePartition : partitionList) { visibleVersionTime = hivePartition.getLastModifiedTime(); diff --git a/regression-test/suites/mtmv_p0/test_hive_empty_partition_mtmv.groovy b/regression-test/suites/mtmv_p0/test_hive_empty_partition_mtmv.groovy new file mode 100644 index 00000000000000..9a2df5c0e8a466 --- /dev/null +++ b/regression-test/suites/mtmv_p0/test_hive_empty_partition_mtmv.groovy @@ -0,0 +1,81 @@ +// 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_hive_empty_partition_mtmv", "p0,external,hive,external_docker,external_docker_hive") { + String enabled = context.config.otherConfigs.get("enableHiveTest") + if (enabled == null || !enabled.equalsIgnoreCase("true")) { + logger.info("diable Hive test.") + return; + } + String suiteName = "test_excluded_trigger_table_mtmv" + String dbName = "default"; + String tableName = "${suiteName}_empty_table" + String mvName = "${suiteName}_mv" + for (String hivePrefix : ["hive2", "hive3"]) { + setHivePrefix(hivePrefix) + // prepare catalog + String hms_port = context.config.otherConfigs.get(hivePrefix + "HmsPort") + String catalogName = "${hivePrefix}_${suiteName}_catalog" + String externalEnvIp = context.config.otherConfigs.get("externalEnvIp") + + sql """drop catalog if exists ${catalogName}""" + sql """create catalog if not exists ${catalogName} properties ( + "type"="hms", + 'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hms_port}' + );""" + sql """drop table if exists ${catalogName}.`${dbName}`.${tableName};""" + sql """ + CREATE TABLE ${catalogName}.`${dbName}`.${tableName} ( + `col1` BOOLEAN COMMENT 'col1', + `pt1` VARCHAR COMMENT 'pt1' + ) ENGINE=hive + PARTITION BY LIST (pt1) () + PROPERTIES ( + 'file_format'='orc', + 'compression'='zlib' + ); + """ + // partition + sql """drop materialized view if exists ${mvName};""" + sql """ + CREATE MATERIALIZED VIEW ${mvName} + REFRESH AUTO ON MANUAL + partition by(`pt1`) + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS + SELECT * FROM ${catalogName}.`${dbName}`.${tableName}; + """ + waitingMTMVTaskFinishedByMvName(mvName) + // not partition + sql """drop materialized view if exists ${mvName};""" + sql """ + CREATE MATERIALIZED VIEW ${mvName} + REFRESH AUTO ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS + SELECT * FROM ${catalogName}.`${dbName}`.${tableName}; + """ + waitingMTMVTaskFinishedByMvName(mvName) + + sql """drop materialized view if exists ${mvName};""" + sql """drop table if exists ${catalogName}.`${dbName}`.${tableName};""" + sql """drop catalog if exists ${catalogName}""" + } +} +