如何在变量中获取配置单元输出



如何将配置单元查询结果放入一个变量中?在SQL中,我们使用以下查询。

Declare @cnt as int Select @cnt= count(*) from tabname

@cnt将在整个过程中使用。我不知道如何在HIVE中实现同样的目标。有人能告诉我如何在蜂箱提示和外壳提示中实现这一点吗?

last_processed_time=`hive -S -e "USE db; select MAX(processed_time) from job_details where event_id = 'XXXX'"`
`echo $last_processed_time
pig -useHCatalog -Dmapred.job.queue.name=highPriority -Dtez.queue.name=highPriority -x tez -param last_processed_time=$last_processed_time test.pig`
> After executing above shell , It displays the required MAX value as
> well as pass the same value to Pig as external parameter for internal
> use within pig. Hope this will be helpful to make the same case with
> hive call using 'hiveconf'

这很简单。在你的壳里,

countinfo=$(hdfs dfs -cat <-directory location}->) 
**hive -hivevar countNum="$countinfo" 
     -f '/Filepath/file.hql' **

在file.hql中,在查询中使用这个${countNum}

没有简单的方法。。。。

  1. 一个简单的方法是:

    catchData=$(beeline/hive -u jdbc:hive2://$hiveServer2:10000 -n $userName -e "select count(*) from table")

但这是无效的,因为它甚至会打印蜂箱连接语句,info&警告语句和数据

2.最好的方法是..

INSERT OVERWRITE DIRECTORY <-directory location}->
SELECT COUNT(*) FROM TABLE
countinfo=$(hdfs dfs -cat <-directory location}->)

希望这一点2有帮助。。。

#!/bin/bash -e
hive -e "use schema_name; INSERT OVERWRITE DIRECTORY '/tmp/ank' row format delimited 
FIELDS TERMINATED BY ',' select * from table_name limit 1;"
a=$(hdfs dfs -cat /tmp/ank/000000_0)
echo $a

这将为变量a 中表的第一行提供逗号分隔的输出

用shell脚本做它有点困难。

我可以建议您使用Perl脚本吗?因为在Perl中它相当容易。

您可以在Perl脚本中这样做。

$query_total_recs ="SELECT COUNT(*) FROM table";

最新更新