hive command in bash script won't load file in

2019-03-04 05:09发布

问题:

I am writing a bash script that - among other things - has to create a hive table and load a csv file (whose name is not known a priori) into that table. I have exported the name of the file foo.csv into the environment variable myfile and have tried the command

hive --hiveconf mf=$myfile -e 'set mf; set hiveconf:mf; load data local inpath ${hiveconf:mf} into table mytable'

It returns the error

FAILED: ParseException line 1:23 mismatched input 'foo' expecting StringLiteral near 'inpath' in load statement

I already tried using the absolute path to the file and it won't work either: if the path is /mypath/foo.csv the error will be

FAILED: ParseException line 1:23 mismatched input '/' expecting StringLiteral near 'inpath' in load statement

Even trying to directly put the file name like this

hive -e 'load data local inpath foo.csv into table mytable'

doesn't work at all, and the thrown error is the same as before.

Does anybody have any idea on what is wrong with these commands? I could really appreciate some help, thanks.

回答1:

Filename should be placed inside '' :

load data local inpath 'foo.csv' into table mytable

In your script you should probably escape these symbols so you won't get another parse exception.

Also, look at Language Manual on loading