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