Export the query result to a local file using hive

Source: Internet
Author: User

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:

  1. Bin/hive-e "select * from test"> res.csv
  2. Or:
  3. Bin/hive-f SQL. q> res.csv
  4. The file SQL. Q is written into the query statement you want to execute.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.