Recently, when using hive, You need to export the data queried by hive to the local file system. The hql syntax is as follows:
Insert overwrite [local] Directory directory1 select_statement1 after the query result is exported to a local file, it is difficult to use Excel to load the file: do not know the delimiter used when the hive exports the file, garbled characters are displayed when you use a text editor. At last, I found that hive uses ^ A as the domain Separator in the official documents. The original Article is: data written to the filesystem is serialized as text with columns separated by ^.
In python, line. Split ('\ x01') can be used for splitting.
If you need to export the query results to a local file, you 'd better use the hive command:
- Bin/hive-e "select * from test"> res.csv
- Or:
- Bin/hive-f SQL. q> res.csv
- The file SQL. Q is written into the query statement you want to execute.