Skip to content

Commit

Permalink
[Fix](hive-transactional-table) Fix NPE when query empty hive transac…
Browse files Browse the repository at this point in the history
…tional table.
  • Loading branch information
kaka11chen committed Nov 24, 2023
1 parent dfe3a2d commit 44eb203
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
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;
Expand Down Expand Up @@ -789,6 +790,9 @@ public List<FileCacheValue> getFilesByTransaction(List<HivePartition> partitions
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ A
B
CC

-- !q03 --
3 CC
-- !q04 --

-- !q05 --
0

-- !q01 --
1 A 20230101
Expand All @@ -31,3 +33,8 @@ F
-- !q03 --
2 BB 20230101

-- !q04 --

-- !q05 --
0

Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}

Expand All @@ -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")) {
Expand Down

0 comments on commit 44eb203

Please sign in to comment.