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?
Try this:
hcat -e 'create table ${hiveconf:TAB_NAME} (name string);' -DTAB_NAME=person2
Here are two things to note:
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: ''
.
Use hiveconf
instead of D
for variable substitution as hcat under the hoods is still using hive to parse commands.