I’m looking for the SQL equivalent of SET varname = value in Hive QL
I know I can do something like this:
SET CURRENT_DATE = '2012-09-16';
SELECT * FROM foo WHERE day >= @CURRENT_DATE
But then I get this error:
character ‘@’ not supported here
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to use the special hiveconf for variable substitution.
e.g.
similarly, you could pass on command line:
Note that there are env and system variables as well, so you can reference
${env:USER}for example.To see all the available variables, from the command line, run
or from the hive prompt, run
Update:
I’ve started to use hivevar variables as well, putting them into hql snippets I can include from hive CLI using the
sourcecommand (or pass as -i option from command line).The benefit here is that the variable can then be used with or without the hivevar prefix, and allow something akin to global vs local use.
So, assume have some setup.hql which sets a tablename variable:
then, I can bring into hive:
and use in query:
or
I could also set a "local" tablename, which would affect the use of ${tablename}, but not ${hivevar:tablename}
vs
Probably doesn’t mean too much from the CLI, but can have hql in a file that uses source, but set some of the variables "locally" to use in the rest of the script.