Hive build appearances and partitions

Source: Internet
Author: User

The advantage of having the CREATE table and create external table,external table in hive is that the table structure and data are unbound, and deleting the table does not delete the data, the table is equivalent to defining the specification to parse the corresponding file.

A more common scenario is to create a façade of the site's users ' browsing data, and then do the partitioning by day to speed up the search efficiency.

Create a table

Create Table sms_detail (    int,    bigintby by  ' \t'by'\ n '  as Textfile;

We built a look called sms_detail, and now we don't need any data, we define the partition field Data_date. The partition field is the equivalent of a field in the data table, which is not present at select *, but can be placed after

Inserting data and partitions

Many times we will partition by day, such as our HDFS file structure is such a/home/user1/smsdata/2015-03-18,/home/user1/smsdata/2015-03-19 ... And now we're going to have to match the data with the appearances, command the following.

ALTER TABLE Sms_detail add if not exists partition (data_date= ' 2015-03-18 ') location '/share/comm/esp/sms/sms_detail/ 2015-03-18 '

This command adds a new partition to the exterior, and maps the data corresponding to the location to the partition. After this, when the hive executes select * from Sms_detail where data_date= ' 2015-03-18 ', the program will go directly to '/share/comm/esp/sms/sms_detail/2015-03-18 ' Folder to find the. Data for 2015-03-19 can also be added in the same way.

Hive build appearances and partitions

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.