You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Ravisankar Mani <rr...@gmail.com> on 2015/06/05 13:22:41 UTC
Set variable in hive query
Hi everyone,
I assign values for set variable. Please refer following query
SET Row_Number_0 = 0;
SELECT
criticid AS criticid,
sum(rating) as rating,
${hiveconf:Row_Number_0}= ${hiveconf:Row_Number_0} + 1 AS
R_N_1
FROM
GROUP BY recommend_ratings2.criticid
ORDER BY criticid ASC;
the assign variable(3 or select values) only returns true or false
But the same query returns 1,2,3......... (row number) in mysql. Could you
please help exact query to return assign values?
Regards,
Ravisankar M R
Re: Set variable in hive query
Posted by gabriel balan <ga...@oracle.com>.
Hi
It seems (see here <https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/Driver.java#L388>) Hive substitutes the variables before parsing the query.
So the query being parsed is actually:
SELECT
criticid AS criticid,
sum(rating) as rating,
0= 0 + 1 AS R_N_1
...
Once the constants are folded, I expect it becomes:
SELECT
criticid AS criticid,
sum(rating) as rating,
false AS R_N_1
...
hth
GB
On 6/5/2015 7:22 AM, Ravisankar Mani wrote:
> Hi everyone,
>
> I assign values for set variable. Please refer following query
>
> SET Row_Number_0 = 0;
> SELECT
> criticid AS criticid,
> sum(rating) as rating,
> ${hiveconf:Row_Number_0}= ${hiveconf:Row_Number_0} + 1 AS R_N_1
> FROM
> GROUP BY recommend_ratings2.criticid
> ORDER BY criticid ASC;
>
> the assign variable(3 or select values) only returns true or false
>
> But the same query returns 1,2,3......... (row number) in mysql. Could you please help exact query to return assign values?
>
>
> Regards,
>
> Ravisankar M R
--
The statements and opinions expressed here are my own and do not necessarily represent those of Oracle Corporation.