我正在学习scala的ProcessBuilderAPI,为了像在shell脚本中运行一样运行shell命令,我可以运行一些脚本,但是有一种配置单元查询执行的问题。
当我运行以下命令时,它运行成功,但有一种格式失败:
正在运行shell命令(成功):
scala> import sys.process._
scala> "ls -lrt /home/cloudera/Desktop".!
total 164
-rwxrwxr-x 1 cloudera cloudera 237 Apr 5 2016 Parcels.desktop
-rwxrwxr-x 1 cloudera cloudera 238 Apr 5 2016 Kerberos.desktop
-rwxrwxr-x 1 cloudera cloudera 259 Apr 5 2016 Express.desktop
使用文件选项运行配置单元查询(成功):
scala> "hive -f /home/cloudera/hi.hql" !!
warning: there was one feature warning; re-run with -feature for
details
ls: cannot access /usr/lib/spark/lib/spark-assembly-*.jar: No such
file or directory
2017-09-03 23:20:34,392 WARN [main] mapreduce.TableMapReduceUtil: The
hbase-prefix-tree module jar containing PrefixTreeCodec is not
present. Continuing without it.
Logging initialized using configuration in
file:/etc/hive/conf.dist/hive-log4j.properties
OK
Time taken: 0.913 seconds, Fetched: 2 row(s)
res20: String =
"100 Amit 12000 10
101 Allen 22000 20 .
"
使用-e选项运行配置单元查询(失败):
如果我在终端上运行下面的查询,我可以用下面给定的格式运行。
bash$ hive -e "select * staging.from employee_canada;"
在scala终端中运行同一查询时出现的问题由于select查询中的双引号(“”)而失败。我怎样才能逃脱这些,并成功地运行。尝试使用三重引号和以及转义“\”序列,但仍然无法执行。
scala> "hive -e select * staging.from employee_canada; "!!
错误如下:
FAILED: ParseException line 1:6 cannot recognize input near '<EOF>'
'<EOF>' '<EOF>' in select clause
java.lang.RuntimeException: Nonzero exit value: 64
at scala.sys.package$.error(package.scala:27)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(
ProcessBuilderImpl.scala:102)
... 32 elided
暂无答案!
目前还没有任何答案,快来回答吧!