如何定位/导出Hive查询?

时间:2018-04-04 16:15:34

标签: hive hiveql

我是Hive的新手,我正在尝试将hive查询导出到计算机上的本地文件,这样我就可以将结果导入excel。

当我从蜂巢内部做的时候;

  

hive -e select * from TABLE limit 10"> output.txt;

我得到"失败:ParseException第1:0行无法识别附近的输入' hive' ' - ' ' E'"

当我做的时候

  

hive -S -e"使用数据库; select * from TABLE limit 10" > /tmp/test/test.csv;

来自shell OR

  

插入覆盖本地目录' / tmp / hello'   select * from TABLE limit 10;

它转到Hive中的hdfs系统 - 如何将其发送到本地计算机?

2 个答案:

答案 0 :(得分:0)

您可以将查询导出为CSV文件,如:

hive -e 'select * from your_Table' > /home/yourfile.csv

要将此文件提供给本地计算机,您应该使用HDFS:

HDFS DFS -get /tmp/hello /PATHinLocalMachine

查看此Question

答案 1 :(得分:0)

在配置单元REPL中运行hive -e命令时,您看到错误,如下所示

hive (venkat)> hive -e 'select * from a';
NoViableAltException(26@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1084)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:202)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:437)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:320)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1219)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1260)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1156)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1146)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:216)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:168)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:379)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:739)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:684)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:624)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
FAILED: ParseException line 1:0 cannot recognize input near 'hive' '-' 'e'

您必须按照如下所示在OS Shell中进行操作

[venkata_udamala@gw02 ~]$ hive -e 'use database_name;select * from table_name;' > temp.txt