[英]Adding Column at partition level in hive
蜂巢的新功能,我們需要向現有的蜂巢表中添加列。 我是在以下命令的幫助下完成的。 alter table tableName添加列(colName數據類型)級聯;
但是在蜂巢文檔中,我們有alter命令在分區級別添加列。 我嘗試了以下命令。
hive> SET hive.exec.dynamic.partition = true;
hive> alter table test_alter_col partition(c=1) add columns (d1 int);
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Duplicate column name: d1
hive> select d1 from test_alter_col where c=1;
FAILED: SemanticException [Error 10004]: Line 1:7 Invalid table alias or column reference 'd1': (possible column names are: a1, b1, d, c)
hive> alter table test_alter_col partition(c=1) add columns (d2 int);
OK
Time taken: 0.178 seconds
hive> select d2 from test_alter_col where c=1;
FAILED: SemanticException [Error 10004]: Line 1:7 Invalid table alias or column reference 'd2': (possible column names are: a1, b1, d, c)
hive>
上面命令的作用是什么,在分區級別使用alter命令是否有用例。
編輯1-
也嘗試過以下命令,但仍然無法查詢新添加的列或插入數據。
create table test_partn (a int, b int, c int) partitioned by (d int) row format delimited fields terminated by '\t' stored as textfile;
insert into table test_partn partition(d) values (1, 11, 111, 1111), (2, 22, 222, 2222), (3, 33, 333, 3333);
SET hive.exec.dynamic.partition = true;
alter table test_partn partition(d=1111) add columns (e int);
insert into test_partn partition(d=1111) values (1, 12, 13, 14);
FAILED: SemanticException [Error 10044]: Line 1:12 Cannot insert into target table because column number/types are different '1111': Table insclause-0 has 3 columns, but query has 4 columns.
alter table test_partn partition(d=3333) add columns (e int) restrict;
insert into test_partn partition(d=3333) values (1, 12, 13, 14);
謝謝你,維傑
蜂巢>更改表test_alter_col分區(c = 1)添加列(d1 int); 失敗:執行錯誤,從org.apache.hadoop.hive.ql.exec.DDLTask返回代碼1。 列名稱重復:d1小時
關於您的第一個命令,您的配置單元表中似乎已經有重復的列名。 您需要使用其他列。
另外,如果要將列添加到已分區的配置單元表中,則可以使用以下命令:
ALTER TABLE <table name> ADD columns (column1 string) CASCADE;
上面應該完成將列添加到已分區表中的工作。 此處捕獲的是CASCADE關鍵字,它將對配置單元中所有分區的更改進行級聯。
希望這可以幫助 :)
我認為在分區級別添加列只會在元數據級別添加列名稱。
我嘗試使用查詢- describe extended tablename partition (keycol=value)
以下是結果。
hive> describe extended test_partn partition(d=1111);
OK
a int
b int
c int
e int
d int
# Partition Information
# col_name data_type comment
d int
Detailed Partition Information Partition(values:[1111], dbName:test, tableName:test_partn, createTime:1539261860, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:int, comment:null), FieldSchema(name:b, type:int, comment:null), FieldSchema(name:c, type:int, comment:null), FieldSchema(name:e, type:int, comment:null), FieldSchema(name:d, type:int, comment:null)], location:maprfs:/user/hive/warehouse/test.db/test_partn/d=1111, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format= , field.delim=
Time taken: 0.139 seconds, Fetched: 12 row(s)
hive>
我只能看到此分區的新添加的列
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.