Hive Learning changes the properties of a table

Source: Internet
Author: User
Tags hadoop fs

1. Modify the table name
ALTER TABLE table_name Rename to new_table_name;
2. Modify column names
ALTER TABLE tablename change column column_orign column_new int (property of modified column) Comment ' column_name '
after severity;//can put the column behind the specified column, or use ' first ' to place
Modify the column column_orign in table TableName to Column_new, specifying the properties of the modified column name, comment is the comment for this column
3. Add Columns
ALTER TABLE tablename Add columns (column1 string comment ' xxxx ', column2 long comment ' yyyy ')
4. View the properties of a table
DESC formatted tablename;
5. Modifying the properties of a table
(1) ALTER TABLE table_name set tblproperties (' property_name ' = ' new_value ');
Modify the value of the comment attribute in the table_name table to ' New_value ';
(2) ALTER TABLE table_name set Serdepropertyes (' field.delim ' = ' \ t ');
Modify the field delimiter in table table_name to ' \ t ', note that this is the case where the table does not have a partition
Example 1:create table T8 (Time String,country string,province string,city string) row format delimited fields terminated b Y ' # ' lines terminated by ' \ n ' stored as textfile;
ALTER TABLE T8 set Serdepropertyes (' field.delim ' = ' \ t '), this statement modifies the field delimiter ' # ' in the T8 table to ' \ t ';
Example 2:create table T9 (Time string,country string,province string,city string) partitioned by (dt=string) row Foramt de Limited fields terminated by ' \ n ' stored as textfile;
ALTER TABLE T9 partition (dt= ' 20140901 ') set Serdepropertyes (' field.delim=\t ');
(3) ALTER TABLE table_name[partition] set location ' path '
ALTER TABLE table_name set tblproperties (' EXTERNAL ' = ' TRUE ');//internal table converted to external table
ALTER TABLE table_name set tblproperties (' EXTERNAL ' = ' FALSE ');//external table to internal table
Tip: First create a new folder on Hadoop, ' Hadoop fs-mkdir/fould_name ', and then upload the data to the folder: ' Hadoop fs Copyfromlocal/root/data/location ', This order
represents the upload of the data file in the '/root/data ' directory to the location folder of Hadoop, and you can view the files under the Location folder by commanding the ' Hadoop fs-ls/location ' command.
In (2), the position of the T9 table is in: '/hive/t9 ' directory, then by command: ' ALTER TABLE City set location ' Hdfs://hadoop:9000/location ' You can change the location of the table T9 to: Under/location folder under Hadoop;
It is also important to note that since T9 default is the inner table, when the table T9 is deleted, its data including the file directory is all deleted, in order to prevent this situation, you can change the table T9 to appearance, through the statement: ALTER TABLE T9 set Tblproperties (' EXTERNAL ' = ' TRUE ');
and so on, the external table can also be modified to internal table, can be through the statement: ALTER TABLE City set Tblproperties (' EXTERNAL ' = ' FALSE ');
(4) Other commands to modify table properties: ALTER TABLE property, alter Serde properties, alter table/partition file format, ALTER TABLE Stora GE Properties; ALTER TABLE rename partition; ALTER TABLE set location;
Detailed instructions can be consulted: Hive official website, find: wiki languagemanual DDL to query detailed description

Hive Learning changes the properties of a table

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.