本文介绍了使用参数在 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 中创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 16:06