本文主要是介绍impala 不可轻易更换列类型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.建表
[slave01:21000] > use tmp;
Query: use tmp
[slave01:21000] > create table ml_2(a int ,b double,c varchar(10));
Query: create table ml_2(a int ,b double,c varchar(10))Fetched 0 row(s) in 0.17s
[slave01:21000] > show create table ml_2;
Query: show create table ml_2
+---------------------------------------------------------------+
| result |
+---------------------------------------------------------------+
| CREATE TABLE tmp.ml_2 ( |
| a INT, |
| b DOUBLE, |
| c VARCHAR(10) |
| ) |
| STORED AS TEXTFILE |
| LOCATION 'hdfs://master:8020/user/hive/warehouse/tmp.db/ml_2' |
| |
+---------------------------------------------------------------+
Fetched 1 row(s) in 4.88s
2. 插入一条数据
[slave01:21000] > insert into ml_2(a,b,c) values(22,22.44,cast('99' as varchar(10)));
Query: insert into ml_2(a,b,c) values(22,22.44,cast('99' as varchar(10)))
Query submitted at: 2017-10-11 15:11:53 (Coordinator: http://slave01:25000)
Query progress can be monitored at: http://slave01:25000/query_plan?query_id=854afd0054173c92:1df06c4e00000000
Modified 1 row(s) in 0.22s
[slave01:21000] > select * from ml_2;
Query: select * from ml_2
Query submitted at: 2017-10-11 15:12:03 (Coordinator: http://slave01:25000)
Query progress can be monitored at: http://slave01:25000/query_plan?query_id=73446eb417d3d311:7720be2d00000000
+----+-------+----+
| a | b | c |
+----+-------+----+
| 22 | 22.44 | 99 |
+----+-------+----+
Fetched 1 row(s) in 0.34s
3.更换类型
[slave01:21000] > alter table ml_2 change b b_int int;
Query: alter table ml_2 change b b_int intFetched 0 row(s) in 0.42s
[slave01:21000] > select * from ml_2;
Query: select * from ml_2
Query submitted at: 2017-10-11 15:12:43 (Coordinator: http://slave01:25000)
Query progress can be monitored at: http://slave01:25000/query_plan?query_id=47c3066e47d4e1:85ce76b100000000
+----+-------+----+
| a | b_int | c |
+----+-------+----+
| 22 | NULL | 99 |
+----+-------+----+
WARNINGS: Error converting column: 1 to INT
Error parsing row: file: hdfs://master:8020/user/hive/warehouse/tmp.db/ml_2/854afd0054173c92-1df06c4e00000000_349445573_data.0., before offset: 12Fetched 1 row(s) in 0.14s
4. 修改回来,也可以正常使用。
[slave01:21000] > alter table ml_2 change b_int b double;
Query: alter table ml_2 change b_int b doubleFetched 0 row(s) in 0.34s
[slave01:21000] > select * from ml_2;
Query: select * from ml_2
Query submitted at: 2017-10-11 15:13:09 (Coordinator: http://slave01:25000)
Query progress can be monitored at: http://slave01:25000/query_plan?query_id=7b403624be3e00a1:649c943b00000000
+----+-------+----+
| a | b | c |
+----+-------+----+
| 22 | 22.44 | 99 |
+----+-------+----+
Fetched 1 row(s) in 0.24s
[slave01:21000] >
这篇关于impala 不可轻易更换列类型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!