- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
hive view parameter and union all
- Labels:
-
Apache Hive
Created ‎11-30-2018 04:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have two tables. test1 and test2
hive> select * from test1; OK
id year
1 2017
2 2017
hive> select * from test2; OK
no year
2 2017
3 2017
query :
select id, year from test1 where id > 1
union all
select no, year from test2 where no > 1
question 1: if i put the above query in a view and can I pass a parameter to it to use in the where clause (for id and no) ?
question 2 : can i frame the above query without the union all
appreciate the feedback.
Created ‎11-30-2018 04:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried the below but it didn't work :
hive> create view testview as select * from test1 where id = "{$hiveconf:id}"; OK Time taken: 0.13 seconds
hive> set id=1;
hive> select * from testview;
Above query did not return any rows.
Created ‎12-01-2018 03:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To define a variable in hive we need to use hivevar and hiveconf is used to set hive configurations
Please follow the below steps:
hive> set hivevar:id=1; //define id variable with 1 value
hive> create view testview as select * from test1 where id = ${hivevar:id}; //create view
hive> select * from testview; //select from view
for more details regards to hivevar vs hiveconf refer to this link.
