Skip to content

Commit 744a0d6

Browse files
authored
HIVE-26493: Hive throws error when querying a view that was created successfully (#6093)
1 parent 008f4d1 commit 744a0d6

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

ql/src/java/org/apache/hadoop/hive/ql/ddl/view/create/CreateViewAnalyzer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ private String getExpandedText(List<FieldSchema> imposedSchema, ASTNode select,
111111
}
112112

113113
String expandedText = ctx.getTokenRewriteStream().toString(select.getTokenStartIndex(), select.getTokenStopIndex());
114+
String trimmedExpandedText = expandedText.trim();
115+
while (trimmedExpandedText.startsWith("(") && trimmedExpandedText.endsWith(")")) {
116+
trimmedExpandedText = trimmedExpandedText.substring(1, trimmedExpandedText.length() - 1);
117+
expandedText = trimmedExpandedText;
118+
trimmedExpandedText = trimmedExpandedText.trim();
119+
}
114120

115121
if (imposedSchema != null) {
116122
// Merge the names from the imposed schema into the types from the derived schema.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create table tbl_x (a int, b string);
2+
insert into tbl_x values (1, 'Prince'); insert into tbl_x values (2, 'John');
3+
create view vw_x (b) as (select a from tbl_x);
4+
select * from vw_x;
5+
6+
create view vw_y (col_b) as (
7+
( ( select b from tbl_x ) )
8+
);
9+
select * from vw_y;
10+
11+
create view vw_z as (
12+
( ( select * from tbl_x )
13+
)
14+
);
15+
select * from vw_z;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
PREHOOK: query: create table tbl_x (a int, b string)
2+
PREHOOK: type: CREATETABLE
3+
PREHOOK: Output: database:default
4+
PREHOOK: Output: default@tbl_x
5+
POSTHOOK: query: create table tbl_x (a int, b string)
6+
POSTHOOK: type: CREATETABLE
7+
POSTHOOK: Output: database:default
8+
POSTHOOK: Output: default@tbl_x
9+
PREHOOK: query: insert into tbl_x values (1, 'Prince')
10+
PREHOOK: type: QUERY
11+
PREHOOK: Input: _dummy_database@_dummy_table
12+
PREHOOK: Output: default@tbl_x
13+
POSTHOOK: query: insert into tbl_x values (1, 'Prince')
14+
POSTHOOK: type: QUERY
15+
POSTHOOK: Input: _dummy_database@_dummy_table
16+
POSTHOOK: Output: default@tbl_x
17+
POSTHOOK: Lineage: tbl_x.a SCRIPT []
18+
POSTHOOK: Lineage: tbl_x.b SCRIPT []
19+
PREHOOK: query: insert into tbl_x values (2, 'John')
20+
PREHOOK: type: QUERY
21+
PREHOOK: Input: _dummy_database@_dummy_table
22+
PREHOOK: Output: default@tbl_x
23+
POSTHOOK: query: insert into tbl_x values (2, 'John')
24+
POSTHOOK: type: QUERY
25+
POSTHOOK: Input: _dummy_database@_dummy_table
26+
POSTHOOK: Output: default@tbl_x
27+
POSTHOOK: Lineage: tbl_x.a SCRIPT []
28+
POSTHOOK: Lineage: tbl_x.b SCRIPT []
29+
PREHOOK: query: create view vw_x (b) as (select a from tbl_x)
30+
PREHOOK: type: CREATEVIEW
31+
PREHOOK: Input: default@tbl_x
32+
PREHOOK: Output: database:default
33+
PREHOOK: Output: default@vw_x
34+
POSTHOOK: query: create view vw_x (b) as (select a from tbl_x)
35+
POSTHOOK: type: CREATEVIEW
36+
POSTHOOK: Input: default@tbl_x
37+
POSTHOOK: Output: database:default
38+
POSTHOOK: Output: default@vw_x
39+
POSTHOOK: Lineage: vw_x.b SIMPLE [(tbl_x)tbl_x.FieldSchema(name:a, type:int, comment:null), ]
40+
PREHOOK: query: select * from vw_x
41+
PREHOOK: type: QUERY
42+
PREHOOK: Input: default@tbl_x
43+
PREHOOK: Input: default@vw_x
44+
#### A masked pattern was here ####
45+
POSTHOOK: query: select * from vw_x
46+
POSTHOOK: type: QUERY
47+
POSTHOOK: Input: default@tbl_x
48+
POSTHOOK: Input: default@vw_x
49+
#### A masked pattern was here ####
50+
1
51+
2
52+
PREHOOK: query: create view vw_y (col_b) as (
53+
( ( select b from tbl_x ) )
54+
)
55+
PREHOOK: type: CREATEVIEW
56+
PREHOOK: Input: default@tbl_x
57+
PREHOOK: Output: database:default
58+
PREHOOK: Output: default@vw_y
59+
POSTHOOK: query: create view vw_y (col_b) as (
60+
( ( select b from tbl_x ) )
61+
)
62+
POSTHOOK: type: CREATEVIEW
63+
POSTHOOK: Input: default@tbl_x
64+
POSTHOOK: Output: database:default
65+
POSTHOOK: Output: default@vw_y
66+
POSTHOOK: Lineage: vw_y.col_b SIMPLE [(tbl_x)tbl_x.FieldSchema(name:b, type:string, comment:null), ]
67+
PREHOOK: query: select * from vw_y
68+
PREHOOK: type: QUERY
69+
PREHOOK: Input: default@tbl_x
70+
PREHOOK: Input: default@vw_y
71+
#### A masked pattern was here ####
72+
POSTHOOK: query: select * from vw_y
73+
POSTHOOK: type: QUERY
74+
POSTHOOK: Input: default@tbl_x
75+
POSTHOOK: Input: default@vw_y
76+
#### A masked pattern was here ####
77+
Prince
78+
John
79+
PREHOOK: query: create view vw_z as (
80+
( ( select * from tbl_x )
81+
)
82+
)
83+
PREHOOK: type: CREATEVIEW
84+
PREHOOK: Input: default@tbl_x
85+
PREHOOK: Output: database:default
86+
PREHOOK: Output: default@vw_z
87+
POSTHOOK: query: create view vw_z as (
88+
( ( select * from tbl_x )
89+
)
90+
)
91+
POSTHOOK: type: CREATEVIEW
92+
POSTHOOK: Input: default@tbl_x
93+
POSTHOOK: Output: database:default
94+
POSTHOOK: Output: default@vw_z
95+
POSTHOOK: Lineage: vw_z.a SIMPLE [(tbl_x)tbl_x.FieldSchema(name:a, type:int, comment:null), ]
96+
POSTHOOK: Lineage: vw_z.b SIMPLE [(tbl_x)tbl_x.FieldSchema(name:b, type:string, comment:null), ]
97+
PREHOOK: query: select * from vw_z
98+
PREHOOK: type: QUERY
99+
PREHOOK: Input: default@tbl_x
100+
PREHOOK: Input: default@vw_z
101+
#### A masked pattern was here ####
102+
POSTHOOK: query: select * from vw_z
103+
POSTHOOK: type: QUERY
104+
POSTHOOK: Input: default@tbl_x
105+
POSTHOOK: Input: default@vw_z
106+
#### A masked pattern was here ####
107+
1 Prince
108+
2 John

0 commit comments

Comments
 (0)