在bash脚本中的hive命令不会将文件加载到表中 [英] hive command in bash script won't load file into table
问题描述
我正在编写一个bash脚本,除其他外,它必须创建一个配置表格,并将一个csv文件(其名称不能事先知道)加载到该表中。
我已经将文件 foo.csv
的名称导出到环境变量 myfile
中,并尝试了命令
hive --hiveconf mf = $ myfile -e'set mf;设置hiveconf:mf;将数据本地inpath $ {hiveconf:mf}载入表mytable'
它返回错误
FAILED:ParseException行1:23不匹配的输入'foo'在加载语句中期望StringLiteral接近'inpath'
我已经尝试过使用文件的绝对路径,它也不会工作:如果路径是 / mypath / foo.csv
错误将会是
FAILED:ParseException行1:23不匹配的输入' /'在加载语句中期待StringLiteral在'inpath'附近
即使试图直接将文件名称
hive -e'load data local inpath foo.csv into table mytable'
根本不起作用,抛出的错误和以前一样。
有人知道这些命令有什么问题吗?我可以真的欣赏一些帮助,谢谢。 c>':
载入数据local inpath'foo.csv'into mytable
在脚本中,您应该可以转义这些符号,这样您就不会得到另一个解析异常。
另请参阅加载语言手册
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 variablemyfile
and have tried the commandhive --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 beFAILED: 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.
解决方案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
这篇关于在bash脚本中的hive命令不会将文件加载到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!