Hive creates external tables and partitions

Source: Internet
Author: User
Create an external table with partitions

The advantage of creating an external table is that the data can be mounted to the table from hdfs at any time.

Partitioning can shorten the query range.

The following example shows how to create an external table.

Create external table my_daily_report (last_update string, col_a string, col_ B string, col_c string, col_d string, col_e string, col_f string, col_g string, col_h string, col_ I string, col_j string) partitioned by (par_dt string) location '/user/chenshu/data/daily ';


Mount a partition folder

Alter table my_daily_report add partition (par_dt = '000000') location '/user/chenshu/data/daily/my_daily_report/100 ';


In the preceding example, only one partition is used. In fact, multiple partitions can be used. For example, if a partition is used for daily report management, the partition corresponds to a folder and can have hour partitions under this folder, use different folders to store reports for different hours. In this case, the relationship between partitions is the relationship between the folder tree.


Delete partition

Of course, you also need to provide a method to delete the part_dt = '000000' partition:

Alter table my_daily_report drop partition (par_dt = '000000 ')

Drop partition deletes all partitions and data. drop partition_spec only deletes partition metadata and does not delete data.

Note: There is no delete from statement in HIVE. If you only delete all statements in a partition, you can use drop partition here.


Query by partition

Now that you have a partition, it is faster to find the data in the partition and specify the partition folder as the query condition in the where clause.

Select count (*) from my_daily_report where par_dt = '000000 ';



Recommended articles:

Http://my.oschina.net/leejun2005/blog/82065

Hive creates external tables 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.