Creating Views in Hive with parameter

前端 未结 3 1934
清歌不尽
清歌不尽 2021-01-03 05:44

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
A         


        
3条回答
  •  孤城傲影
    2021-01-03 06:11

    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) 
    

提交回复
热议问题