2

I have a shell script file which I parse both numeric and string variables. An example below:

Shell Script

hive --hiveconf time_1=34600 --hiveconf time_2=34588 --hiveconf message="hello_world" -f mytask.hql

Also I have a Hive query in the respective file 'mytask.hql' as follows:

HiveQL file

SELECT col1, col2, ${hiveconf:message} AS myMessage
FROM table1
WHERE trtime between ${hiveconf:time_1} and ${hiveconf:time_2};

The problem is that I want to have a column that contains the message "Hello world" or whatever the external - from Unix Shell Script - variable contains, in every line, but I got the following error:

[Error 10004]: Line xxx Invalid table alias or column reference 'hello_world': (possible column names are: col1, col2 ... (Etc.)

The output that I want to have is something like this:

enter image description here

6
  • try hivevar instead of hiveconf in the shell and call as ${message} in the script Commented Oct 26, 2018 at 14:20
  • What does it say when you do DESC table1 ? Commented Oct 26, 2018 at 14:34
  • are you using hive command line interface or Beeline? Commented Oct 26, 2018 at 15:27
  • @VamsiPrabhala I use command line. The suggestion of '${hiveconf:message}' worked. Thank you! Commented Oct 29, 2018 at 8:27
  • @octano It described the table1, no problem for this table, it is used correctly. I found the solution in the problem using the '${hiveconf:message}'. Thank you! Commented Oct 29, 2018 at 8:28

1 Answer 1

1

String constants in SQL should be quoted using single quotes: '${hiveconf:message}':

SELECT col1, col2, '${hiveconf:message}' AS myMessage
FROM table1
WHERE trtime between ${hiveconf:time_1} and ${hiveconf:time_2};

And without quotes ${hiveconf:message} is resolved in hello_world, without quotes it looks like column, not a constant, this is why you got such exception.

Sign up to request clarification or add additional context in comments.

8 Comments

If have an array, lets say: names=("Nick" "Helen") And I want to parse the first name from shell AND to use it in hiveql to create a table with the name mytable_'${hiveconf:names}', Could I use the same syntax?
@Vamkos it will work without quotes, and of course not with array, if you parse it in a shell as you said. You do not need quotes inside table_name.
I found that time_1 and time_2 are not parsed correctly into the HiveQL code. Do you have any idea?
@Vamkos Testing it: hive --hiveconf time_1=34600 --hiveconf time_2=34588 then in the hive: hive> select ${hiveconf:time_1} as time_1, ${hiveconf:time_2} as time_2; OK 34600 34588 Time taken: 2.101 seconds, Fetched: 1 row(s)
@Vamkos So, it works as expected. Check your shell script, maybe it is some issue in it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.