【问题标题】:Convert Oracle query into hive将 Oracle 查询转换为配置单元
【发布时间】:2017-03-08 05:54:19
【问题描述】:

Oracle 查询:

select col_name INTO XYZ from table_name where <conditions1 and condition2....> --- 这让我将查询的值放入变量 XYZ,它不是一个表,而只是一个平面变量 [oracle 查询将单个值返回到 XYZ]。然后这个 XYZ 被另一个函数消耗以进行比较,例如。它在查询中与 ABC>XYZ 等关系运算符一起使用(ABC 是一个变量名)。

我本可以在 hive 中使用 create table XYZ..as .. 子句来做到这一点,但是这不能与 hive(ABC>XYZ) 中的关系运算符一起使用。

我尝试通过 shell 脚本填充变量 XYZ,例如: hive -e 'select col_name from table_name where ' >a.txt(将输出移动到a.txt)

temp=cata.txt(现在我可以在 temp 中获取值)

hive -e 'use database ; set hivevar:XYZ=$temp'(现在我试图在 hive-shell 中设置这个变量并将其用作 ${hivevar:XYZ} ) 这里的问题是temp 在 bash-shell 中,运行此命令后它将转到 hive-shell 并在 hive 中搜索 temp。有什么方法可以让我在 bash 中将temp 设置为 hive 中的 XYZ=temp

P.S:甚至尝试使用 hiveconf,但问题与 hivevar 相同。

【问题讨论】:

    标签: bash shell hadoop hive hql


    【解决方案1】:

    在这个特定的用例中,你可以运行

     echo 'use database ; set hivevar:XYZ=$temp' > initFile
     hive -i initFile
    

    hive -i 运行初始化文件中的命令,然后打开 hive-shell。

    【讨论】:

      猜你喜欢
      • 2022-11-17
      • 2019-07-29
      • 2018-11-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      相关资源
      最近更新 更多