Skip to content

Commit 93ae19b

Browse files
authored
HIVE-27562: Iceberg: Fetching virtual columns failing. (#4546). (Ayush Saxena, reviewed by Denys Kuzmenko, zhangbutao)
1 parent 39c3861 commit 93ae19b

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,12 @@ private static Schema readSchema(Configuration conf, Table table, boolean caseSe
534534
}
535535

536536
String[] selectedColumns = InputFormatConfig.selectedColumns(conf);
537-
if (selectedColumns == null) {
538-
return table.schema();
539-
}
537+
readSchema = table.schema();
540538

541-
readSchema = caseSensitive ? table.schema().select(selectedColumns) :
542-
table.schema().caseInsensitiveSelect(selectedColumns);
539+
if (selectedColumns != null) {
540+
readSchema =
541+
caseSensitive ? readSchema.select(selectedColumns) : readSchema.caseInsensitiveSelect(selectedColumns);
542+
}
543543

544544
if (InputFormatConfig.fetchVirtualColumns(conf)) {
545545
return IcebergAcidUtil.createFileReadSchemaWithVirtualColums(readSchema.columns(), table);

iceberg/iceberg-handler/src/test/queries/positive/query_iceberg_virtualcol.q

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ drop table if exists tbl_ice;
22
create external table tbl_ice(a int, b string) partitioned by (c int) stored by iceberg stored as orc tblproperties ('format-version'='2');
33
insert into tbl_ice values (1, 'one', 50), (2, 'two', 50), (3, 'three', 50), (4, 'four', 52), (5, 'five', 54), (111, 'one', 52), (333, 'two', 56);
44

5+
select tbl_ice.ROW__POSITION from tbl_ice;
6+
57
select a, c, tbl_ice.PARTITION__SPEC__ID, tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION from tbl_ice
68
order by tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION desc;
79

810
select a, c, tbl_ice.PARTITION__SPEC__ID, tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION from tbl_ice
911
sort by tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION desc;
12+
13+
14+
-- create a table with more than 4 columns
15+
create table ice01 (a int, b int, c int, d int, e int) stored by iceberg tblproperties ('format-version'='2');
16+
insert into ice01 values (1,2,3,4,5), (6,7,8,9,10);
17+
18+
select ice01.ROW__POSITION from ice01;

iceberg/iceberg-handler/src/test/results/positive/query_iceberg_virtualcol.q.out

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ POSTHOOK: query: insert into tbl_ice values (1, 'one', 50), (2, 'two', 50), (3,
2020
POSTHOOK: type: QUERY
2121
POSTHOOK: Input: _dummy_database@_dummy_table
2222
POSTHOOK: Output: default@tbl_ice
23+
PREHOOK: query: select tbl_ice.ROW__POSITION from tbl_ice
24+
PREHOOK: type: QUERY
25+
PREHOOK: Input: default@tbl_ice
26+
PREHOOK: Output: hdfs://### HDFS PATH ###
27+
POSTHOOK: query: select tbl_ice.ROW__POSITION from tbl_ice
28+
POSTHOOK: type: QUERY
29+
POSTHOOK: Input: default@tbl_ice
30+
POSTHOOK: Output: hdfs://### HDFS PATH ###
31+
0
32+
1
33+
2
34+
0
35+
1
36+
0
37+
0
2338
PREHOOK: query: select a, c, tbl_ice.PARTITION__SPEC__ID, tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION from tbl_ice
2439
order by tbl_ice.PARTITION__HASH, tbl_ice.ROW__POSITION desc
2540
PREHOOK: type: QUERY
@@ -54,3 +69,29 @@ POSTHOOK: Output: hdfs://### HDFS PATH ###
5469
4 52 0 83 0
5570
5 54 0 85 0
5671
333 56 0 87 0
72+
PREHOOK: query: create table ice01 (a int, b int, c int, d int, e int) stored by iceberg tblproperties ('format-version'='2')
73+
PREHOOK: type: CREATETABLE
74+
PREHOOK: Output: database:default
75+
PREHOOK: Output: default@ice01
76+
POSTHOOK: query: create table ice01 (a int, b int, c int, d int, e int) stored by iceberg tblproperties ('format-version'='2')
77+
POSTHOOK: type: CREATETABLE
78+
POSTHOOK: Output: database:default
79+
POSTHOOK: Output: default@ice01
80+
PREHOOK: query: insert into ice01 values (1,2,3,4,5), (6,7,8,9,10)
81+
PREHOOK: type: QUERY
82+
PREHOOK: Input: _dummy_database@_dummy_table
83+
PREHOOK: Output: default@ice01
84+
POSTHOOK: query: insert into ice01 values (1,2,3,4,5), (6,7,8,9,10)
85+
POSTHOOK: type: QUERY
86+
POSTHOOK: Input: _dummy_database@_dummy_table
87+
POSTHOOK: Output: default@ice01
88+
PREHOOK: query: select ice01.ROW__POSITION from ice01
89+
PREHOOK: type: QUERY
90+
PREHOOK: Input: default@ice01
91+
PREHOOK: Output: hdfs://### HDFS PATH ###
92+
POSTHOOK: query: select ice01.ROW__POSITION from ice01
93+
POSTHOOK: type: QUERY
94+
POSTHOOK: Input: default@ice01
95+
POSTHOOK: Output: hdfs://### HDFS PATH ###
96+
0
97+
1

0 commit comments

Comments
 (0)