Search code examples
hadoophcatalog

Hadoop Hcatalog -How to pass key value pair


I have a create table script where the table name will be decided at runtime. How do I pass the value to sql script?

I'm trying something like this

hcat -e "create table ${D:TAB_NAME} (name string)" -DTAB_NAME=person

But I keep getting errors. Can I get the correct syntax?


Solution

  • Try this:

    hcat -e 'create table ${hiveconf:TAB_NAME} (name string);' -DTAB_NAME=person2
    

    Here are two things to note:

    1. In shell, default variable expansion is $ so your ${D:TAB_NAME} is getting expanded to nothing before even getting passed to hcat parser. So, either escape the $ or use strong quoting using: ''.

    2. Use hiveconf instead of D for variable substitution as hcat under the hoods is still using hive to parse commands.