使用参数在Hive中创建视图 [英] Creating Views in Hive with parameter

查看:2487
本文介绍了使用参数在Hive中创建视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含属于各种日期的行的表。
我想创建一个视图,它应该给我基于日期的数据

I have a table that contains rows belonging to various dates. I want to CREATE A VIEW which should give me the data based on the date

CREATE VIEW newusers
AS
SELECT DISTINCT T1.uuid
FROM user_visit T1
WHERE T1.firstSeen="20140522";

我不想修复WHERE T1.firstSeen =20140522;
它可以是任何日期,如20140525等。
有没有什么办法可以创建一个视图作为参数?

I do not want to fix WHERE T1.firstSeen="20140522"; it can be any date like 20140525 etc. Is there any way that I can create a view with date as parameter?

推荐答案

不确定是否用这样的变量创建视图实际上可行。随着Hive 1.2的发展,这就是你创建表时会发生什么。

Not really sure if creating a view with such variable actually works. With Hive 1.2 an onwards, this is what happens when you create table.

hive> create view v_t1 as select * from t_t1 where d1="${hiveconf:v_val_dt}";
OK
Time taken: 6.222 seconds
hive> show create table v_t1;
OK
CREATE VIEW `v_t1` AS select `t_t1`.`f1`, `t_t1`.`d1` from `default`.`t_t1` where `t_t1`.`d1`="'2016-01-02'"
Time taken: 0.202 seconds, Fetched: 1 row(s)

在创建视图时,它始终采用静态常量值。可能有效的一件事就是停留在提示符之外,就像这样。

When creating a view, it always takes the static constant value. The one thing that might work would be staying outside the prompt, something like this.

[hdfs@sandbox ~]$ hive -hiveconf v_val_dt=2016-01-01 -e 'select * from v_t1 where d1="${hiveconf:v_val_dt}";' 
Logging initialized using configuration in file:/etc/hive/2.3.2.0-2950/0/hive-log4j.properties 
OK 
string_1    2016-01-01 
Time taken: 7.967 seconds, Fetched: 1 row(s) 

[hdfs@sandbox ~]$ hive -hiveconf v_val_dt=2016-01-06 -e 'select * from v_t1 where d1="${hiveconf:v_val_dt}";' 
Logging initialized using configuration in file:/etc/hive/2.3.2.0-2950/0/hive-log4j.properties 
OK 
string_6    2016-01-06 
Time taken: 10.967 seconds, Fetched: 1 row(s) 

这篇关于使用参数在Hive中创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆