[Fix](hive-transactional-table) Fix NPE when query empty hive transactional table. (#27563)

This commit is contained in:
Qi Chen
2023-11-25 10:29:39 +08:00
committed by GitHub
parent 6b1428dba1
commit cc395f5428
4 changed files with 35 additions and 4 deletions

View File

@ -632,6 +632,17 @@ insert into `schema_evo_test_orc` select 2, "messi", from_unixtime(to_unix_times
SET hive.support.concurrency=true;
SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
create table orc_full_acid_empty (id INT, value STRING)
CLUSTERED BY (id) INTO 3 BUCKETS
STORED AS ORC
TBLPROPERTIES ('transactional' = 'true');
create table orc_full_acid_par_empty (id INT, value STRING)
PARTITIONED BY (part_col INT)
CLUSTERED BY (id) INTO 3 BUCKETS
STORED AS ORC
TBLPROPERTIES ('transactional' = 'true');
create table orc_full_acid (id INT, value STRING)
CLUSTERED BY (id) INTO 3 BUCKETS
STORED AS ORC

View File

@ -90,6 +90,7 @@ import java.io.FileNotFoundException;
import java.net.URI;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -789,6 +790,9 @@ public class HiveMetaStoreCache {
directory = AcidUtils.getAcidState(new Path(partition.getPath()), jobConf, validWriteIds, false,
true);
}
if (directory == null || directory.getBaseDirectory() == null) {
return Collections.emptyList();
}
if (!directory.getOriginalFiles().isEmpty()) {
throw new Exception("Original non-ACID files in transactional tables are not supported");
}

View File

@ -9,8 +9,10 @@ A
B
CC
-- !q03 --
3 CC
-- !q04 --
-- !q05 --
0
-- !q01 --
1 A 20230101
@ -31,3 +33,8 @@ F
-- !q03 --
2 BB 20230101
-- !q04 --
-- !q05 --
0

View File

@ -23,8 +23,11 @@ suite("test_transactional_hive", "p0,external,hive,external_docker,external_dock
qt_q02 """
select value from orc_full_acid order by id;
"""
qt_q03 """
select * from orc_full_acid where value = 'CC' order by id;
qt_q04 """
select * from orc_full_acid_empty;
"""
qt_q05 """
select count(*) from orc_full_acid_empty;
"""
}
@ -38,6 +41,12 @@ suite("test_transactional_hive", "p0,external,hive,external_docker,external_dock
qt_q03 """
select * from orc_full_acid_par where value = 'BB' order by id;
"""
qt_q04 """
select * from orc_full_acid_par_empty;
"""
qt_q05 """
select count(*) from orc_full_acid_par_empty;
"""
}
String enabled = context.config.otherConfigs.get("enableHiveTest")
if (enabled != null && enabled.equalsIgnoreCase("true")) {