[Hive - LanguageManual] Alter Table/Partition/Column
2015-01-24 21:28
495 查看
Alter Table/Partition/Column
Alter TableRename Table
Alter Table Properties
Alter Table Comment
Add SerDe Properties
Alter Table Storage Properties
Additional Alter Table Statements
Alter Partition
Add Partitions
Dynamic Partitions
Rename Partition
Exchange Partition
Recover Partitions (MSCK REPAIR TABLE)
Drop Partitions
(Un)Archive Partition
Alter Either Table or Partition
Alter Table/Partition File Format
Alter Table/Partition Location
Alter Table/Partition Touch
Alter Table/Partition Protections
Alter Table/Partition Compact
Alter Table/Partition Concatenate
Alter Column
Rules for Column Names
Change Column Name/Type/Position/Comment
Add/Replace Columns
Partial Partition Specification
Alter table statements enable you to change the structure of an existing table. You can add columns/partitions, change SerDe, add table and SerDe properties, or rename the table itself. Similarly, alter table partition statements allow you change the properties of a specific partition in the named table.
Alter Table
Rename Table
As of version 0.6, a rename on a managed table moves its HDFS location as well. (Older Hive versions just renamed the table in the metastore without moving the HDFS location.)
Alter Table Properties
Alter Table Comment
To change the comment of a table you have to change the
commentproperty of the
TBLPROPERTIES:
Add SerDe Properties
The SerDe properties are passed to the table's SerDe when it is being initialized by Hive to serialize and deserialize data. So users can store any information required for their custom SerDe here. Refer to the SerDe documentation and Hive SerDe in the Developer Guide for more information, and see Row Format, Storage Format, and SerDe above for details about setting a table's SerDe and SERDEPROPERTIES in a CREATE TABLE statement.
Example, note that both
property_nameand
property_valuemust be quoted:
Alter Table Storage Properties
NOTE: These commands will only modify Hive's metadata, and will NOT reorganize or reformat existing data. Users should make sure the actual data layout conforms with the metadata definition.
Additional Alter Table Statements
See Alter Either Table or Partition below for more DDL statements that alter tables.Alter Partition
Add Partitions
Note that it is proper syntax to have multiple partition_spec in a single ALTER TABLE, but if you do this in version 0.7, your partitioning scheme will fail. That is, every query specifying a partition will always use only the first partition. Instead, you should use the following form if you want to add many partitions in Hive 0.7:
An error is thrown if the partition_spec for the table already exists. You can use IF NOT EXISTS to skip the error.
Dynamic Partitions
Partitions can be added to a table dynamically, using a Hive INSERT statement (or a Pig STORE statement). See these documents for details and examples:
Design Document for Dynamic Partitions
Tutorial: Dynamic-Partition Insert
Hive DML: Dynamic Partition Inserts
HCatalog Dynamic Partitioning
Usage with Pig
Usage from MapReduce
Rename Partition
Version informationIcon
As of Hive 0.9.
Exchange Partition
Version informationIcon
As of Hive 0.12 (HIVE-4095).
Recover Partitions (MSCK REPAIR TABLE)
Hive stores a list of partitions for each table in its metastore. If, however, new partitions are directly added to HDFS (say by usinghadoop fs -putcommand), the metastore (and hence Hive) will not be aware of these partitions unless the user runs
ALTER TABLE table_name ADD PARTITIONcommands on each of the newly added partitions.
However, users can run
The equivalent command on Amazon Elastic MapReduce (EMR)'s version of Hive is
Drop Partitions
For tables that are protected by NO_DROP CASCADE, you can use the predicate IGNORE PROTECTION to drop a specified partition or set of partitions (for example, when splitting a table between two Hadoop clusters).
In Hive 0.7.0 or later, DROP returns an error if the partition doesn't exist, unless IF EXISTS is specified or the configuration variable hive.exec.drop.ignorenonexistent is set to true.
(Un)Archive Partition
Alter Either Table or Partition
Alter Table/Partition File Format
Alter Table/Partition Location
Alter Table/Partition Touch
Also, it may be useful later if we incorporate reliable last modified times. Then touch would update that time as well.
Note that TOUCH doesn't create a table or partition if it doesn't already exist. (See Create Table.)
Alter Table/Partition Protections
Version informationIcon
As of Hive 0.7.0 (HIVE-1413). The CASCADE clause for NO_DROP was added in HIVE 0.8.0 (HIVE-2605).
If any partition in a table has NO_DROP enabled, the table cannot be dropped either. Conversely, if a table has NO_DROP enabled then partitions may be dropped, but with NO_DROP CASCADE then partitions cannot be dropped either.
Alter Table/Partition Compact
Version informationIcon
In Hive release 0.13.0 and later when transactions are being used, the ALTER TABLE statement can request compaction of a table or partition.
The compaction_type can be MAJOR or MINOR. See the Basic Design section in Hive Transactions for more information.
Alter Table/Partition Concatenate
Version informationIcon
In Hive release 0.8.0 RCFile added support for fast block level merging of small RCFiles using concatenate command. In Hive release 0.14.0 ORC files added support fast stripe level merging of small ORC files using concatenate command.
Alter Column
Rules for Column Names
Column names are case insensitive.Version information
Icon
In Hive release 0.12.0 and earlier, column names can only contain alphanumeric and underscore characters.
In Hive release 0.13.0 and later, by default column names can be specified within backticks (
`) and contain any Unicode character (HIVE-6013). Within a string delimited by backticks, all characters are treated literally except that double backticks (
``) represent one backtick character. The pre-0.13.0 behavior can be used by setting
hive.support.quoted.identifiersto
none, in which case backticked names are interpreted as regular expressions. See Supporting Quoted Identifiers in Column Names for details.
Change Column Name/Type/Position/Comment
The CASCADE|RESTRICT clause is available in Hive 0.15.0. ALTER TABLE CHANGE COLUMN with CASCADE command changes the columns of a table's metadata, and cascades the same change to all the partition metadata. RESTRICT is the default, limiting column change only to table metadata.
Icon
ALTER TABLE CHANGE COLUMN CASCADE clause will override the table partition's column metadata regardless of the table or partition's protection mode. Use with discretion.
Icon
The column change command will only modify Hive's metadata, and will not modify data. Users should make sure the actual data layout of the table/partition conforms with the metadata definition.
Example:
Add/Replace Columns
"
ALTER TABLE test_change REPLACE COLUMNS (a int, b int);" will remove column 'c' from test_change's schema.
The PARTITION clause is available in Hive 0.14.0 and later; see Upgrading Pre-Hive 0.13.0 Decimal Columns for usage.
The CASCADE|RESTRICT clause is available in Hive 0.15.0. ALTER TABLE ADD|REPLACE COLUMNS with CASCADE command changes the columns of a table's metadata, and cascades the same change to all the partition metadata. RESTRICT is the default, limiting column changes only to table metadata.
Icon
ALTER TABLE ADD|REPLACE COLUMNS CASCADE clause will override the table partition's column metadata regardless of the table or partition's protection mode. Use with discretion.
Icon
The column change command will only modify Hive's metadata, and will not modify data. Users should make sure the actual data layout of the table/partition conforms with the metadata definition.
Partial Partition Specification
As of Hive 0.14 (HIVE-8411), users are able to provide a partial partition spec for certain above alter column statements, similar to dynamic partitioning. So rather than having to issue an alter column statement for each partition that needs to be changed:Change column
Add column
Replace column
File Format
Serde Properties
相关文章推荐
- [Hive - LanguageManual] Create/Drop/Alter -View、 Index 、 Function
- ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION
- oracle分区表之交换分区 altertable exchange partition with table
- faster alter table add column
- hive中简单介绍分区表(partition table),含动态分区(dynamic partition)与静态分区(static partition)
- [Hive - LanguageManual] Import/Export
- [Hive - LanguageManual] Hive Concurrency Model (待)
- Hive – partition table query failed when stored as parquet
- hive中简单介绍分区表(partition table),含动态分区(dynamic partition)与静态分区(static partition)
- 由于一个或多个对象访问此列,ALTER TABLE DROP COLUMN *** 失败。
- MSSql Server 索引'uq_f_userName' 依赖于 列'f_userName'。由于一个或多个对象访问此列,ALTER TABLE ALTER COLUMN f_userName 失败
- [HIve - LanguageManual] Sort/Distribute/Cluster/Order By
- [Hive - LanguageManual ] ]SQL Standard Based Hive Authorization
- oracle分区表之交换分区 altertable exchange partition with table
- MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
- [HIve - LanguageManual] Transform [没懂]
- hive中简单介绍分区表(partition table),含动态分区(dynamic partition)与静态分区(static partition)
- Hive查询报错 Invalid table alias or column reference 'create_time': (possible column names are: _c0, _c1
- hive alter table (删除某一列)语句
- alter table image alter column id int IDENTITY (1, 1) NOT NULL 帮我看看语句是否正确!!