Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hive >> mail # user >> working with HIVE VARIALBE: Pls suggest


Copy link to this message
-
Re: working with HIVE VARIALBE: Pls suggest
wow. that's pretty clever! a+ for ingenuity! :)

As a side bar I tend to use shell variables more often than not using this
idiom.

#!/bin/bash
id=blah
hive <<SQL
   select foo from bar where id='$id';
   quit;
SQL

and if you wanted the output in a *shell* variable then:

#!/bin/bash
id=blah
var=$(hive <<SQL
       select foo from bar where id='$id';
       quit;
SQL
)

of course for one liners like the above you might as well use -e though.
eg. var=$(hive -e 'select foo from bar where id='$id') but for longer stuff
the "here doc" makes for better reading.

something to keep in mind anyway.
On Mon, Jan 6, 2014 at 6:48 PM, Sun, Rui <[EMAIL PROTECTED]> wrote:

>  Directly saving the query result into a variable is not supported now.
> You may consider saving the result into an intermediate table or file to be
> used by subsequent queries.
>
>
>
> If you indeed want a variable, here is some trick you may try:
>
>
>
> Hive –e "insert overwrite local directory ‘/tmp/result’ select
> max(salary) from Hive_employe_table"
>
> Hive –e -hiveconf MY_VAR =`cat /tmp/result/000000_0`
>
>
>
>
>
> *From:* yogesh dhari [mailto:[EMAIL PROTECTED]]
> *Sent:* Tuesday, January 07, 2014 2:25 AM
> *To:* [EMAIL PROTECTED]
> *Subject:* Re: working with HIVE VARIALBE: Pls suggest
>
>
>
> Thanks all for your help..
>
> I think was not so much clear about what I was trying to do...
>
> I was just trying to create a variable  in Hive like in RDBMS,  and want
> to store  the result of a query into that variable.
>
> lets say,
> I have declared a variable MY_VAR
>
> I want to store the result  of hive query "select max(salary) from
> Hive_employe_table" ;
> into MY_VAR
>
> Is it possible in Hive ? if yes then how to achieve..
>
> Thanks a lot in advance.
> Pls suggest or to work around it
>
>
>
>
>
> Thanks & Regards
>
> Yogesh
>
>
>
> On Mon, Jan 6, 2014 at 12:36 PM, lxw <[EMAIL PROTECTED]> wrote:
>
>
> maybe you can see:
>
>
> https://cwiki.apache.org/confluence/plugins/viewsource/viewpagesrc.action?pageId=30754722
>
>
>
> ------------------ Original ------------------
>
> *From: * "yogesh dhari";<[EMAIL PROTECTED]>;
>
> *Date: * Fri, Jan 3, 2014 01:13 AM
>
> *To: * "user"<[EMAIL PROTECTED]>;
>
> *Subject: * working with HIVE VARIALBE: Pls suggest
>
>
>
> Hello Hive Champs,
>
> I have a case statement, where I need to check the date passed through
> parameter,
>
> If date is 1st date of the month then keep it as it as
>
> else
>
> set the parameter date to 1st date of the month.
>
> and then later opretation are being performed on that date into hive
> quries,
>
> I have wrote this Hive QL
>
> *select case when as_of_dt = ${hivevar:as_of_dt} then ${hivevar:as_of_dt}
> else date_sub(${hivevar:as_of_dt} , (day(${hivevar:as_of_dt} )) -1 ) end as
> as_of_dt from TABLE group by as_of_dt ;*
>
> O/P of this query is, lets say = 2012-08-01
>
>
>
> I want to store the value of this Query into a variable.
>
> like
>
> MY_VARIABLE = (*select case when as_of_dt = ${hivevar:as_of_dt} then
> ${hivevar:as_of_dt} else date_sub(${hivevar:as_of_dt} ,
> (day(${hivevar:as_of_dt} )) -1 ) end as as_of_dt from TABLE group by
> as_of_dt; )*
>
>
>
>
>
>
>
> How to achieve that.
>
> Pls suggest,
>
> Thanks in advance
>
>
>