使用参数化位置创建表

时间:2016-06-22 16:24:59

标签: hadoop hive hiveql

这适用于Hive 1.1.0和Cloudera 5.4.8。

我已尝试过建议here的解决方案,但它似乎对我不起作用。我通过“hive -e”和脚本文件尝试了类似下面的内容:

SELECT * 
FROM   (SELECT nb_policy.last_updated, 
               nb_policy.policy_id, 
               nb_policy.policy_name, 
               customer.name, 
               customer.vantive_id, 
               customer.siebel_id, 
               nbrp.job.job_id, 
               nbrp.job.job_type, 
               nbrp.job.job_state, 
               nbrp.job.schedule_name, 
               nbrp.job.schedule_type, 
               nbrp.job.kbytes, 
               nbrp.job.backup_type, 
               Row_number() 
                 over ( 
                   PARTITION BY nb_policy.last_updated, nb_policy.policy_id, 
                 nb_policy.policy_name, customer.name, customer.vantive_id, 
                 customer.siebel_id, 
                 nbrp.job.job_id, nbrp.job.job_type, nbrp.job.job_state, 
                 nbrp.job.schedule_name, 
                 nbrp.job.schedule_type, nbrp.job.kbytes, nbrp.job.backup_type 
                   ORDER BY nb_policy.last_updated DESC) AS rn 
        FROM   nb_policy 
               left join customer 
                      ON nb_policy.customer_id = customer.customer_id 
               right join nbrp.job 
                       ON nb_policy.policy_name = nbrp.job.class_name 
        WHERE  customer.active = 1 
               AND ( customer.vantive_id > 0 
                      OR customer.siebel_id > 0 )) t 
WHERE  rn = 1

我刚收到错误:

set rootpath = 'hdfs:///user/myuser/data'; 
DROP TABLE mytable; 
CREATE [EXTERNAL] TABLE mytable (
     Dim1 STRING,
     Dim2 STRING,
     Dim3 STRING ) 
 LOCATION ${hiveconf:rootpath};

我能做些什么来解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您的脚本需要进行一些小的更改

set hiveconf:rootpath='hdfs:///user/myuser/data'; 
DROP TABLE mytable; 
CREATE [EXTERNAL] TABLE mytable (
     Dim1 STRING,
     Dim2 STRING,
     Dim3 STRING ) 
 LOCATION '${hiveconf:rootpath}';