我正在尝试创建我想稍后在数据提取中使用的查询内维度表。在MS SQL中,我可以使用这个CTE,它将使用值作为表:
with tbl_test_values as (select * from (
VALUES
('Number','1','One'),
('Number','5','Five'),
('Letter','A','First Letter'),
('Human','Bob','Dude')
) as
TestValues --equivalent of table name
(Name, Value, Descript) --essentially field names
)
select * from actual_data_table f
left outer join tbl_test_values d on f.Name=d.Name
有没有办法在Hive中复制上面的CTE“tbl_test_values”,即查询自定义值集作为表?
由于
答案 0 :(得分:2)
<强>内联强>
with tbl_test_values as
(
select inline
(
array
(
struct ('Number','1','One')
,struct ('Number','5','Five')
,struct ('Letter','A','First Letter')
,struct ('Human','Bob','Dude')
)
) as (Name, Value, Descript)
)
select * from tbl_test_values
;
+--------+-------+--------------+
| name | value | descript |
+--------+-------+--------------+
| Number | 1 | One |
| Number | 5 | Five |
| Letter | A | First Letter |
| Human | Bob | Dude |
+--------+-------+--------------+
<强>堆强>
with tbl_test_values as
(
select stack
(
4
,'Number' ,'1' ,'One'
,'Number' ,'5' ,'Five'
,'Letter' ,'A' ,'First Letter'
,'Human' ,'Bob' ,'Dude'
) as (Name, Value, Descript)
)
select * from tbl_test_values
;
+--------+-------+--------------+
| name | value | descript |
+--------+-------+--------------+
| Number | 1 | One |
| Number | 5 | Five |
| Letter | A | First Letter |
| Human | Bob | Dude |
+--------+-------+--------------+