hive sql
来源:互联网 发布:淘宝键盘 编辑:程序博客网 时间:2024/06/11 20:57
一、修改列名
1.1、MySQL修改列名的格式
添加列:alter table 表名 add column 列名 varchar(30);
删除列:alter table 表名 drop column 列名;
修改列名MySQL: alter table bbb change oldname newname int;
1.2、hive修改列的名称,类型,位置, 注释
alter table tablename change column old_name new_name 类型 comment 'xxxxx' after clo2;
1.2.1、案例:修改列name
hive (test)> desc t1;OKname string age int Time taken: 0.097 seconds, Fetched: 2 row(s)hive (test)> alter table t1 change column name new_name string comment "change the column name to new" after age;OKTime taken: 0.196 secondshive (test)> desc t1;OKage int new_name string change the column name to newTime taken: 0.081 seconds, Fetched: 2 row(s)hive (test)>
二、添加列名
2.1、MySQL增加列名
alter table test add column name varchar(10); --添加表列
2.2、hive添加列名, 增加列名: 注意是columns
增加列名: 注意是columnshive (test)> alter table t1 add columns(sex string);OKTime taken: 0.159 secondshive (test)> desc t1;OKage int new_name string change the column name to newsex string Time taken: 0.113 seconds, Fetched: 3 row(s)hive (test)>
三、删除列
3.1、MySQL中删除列
删除列:alter table 表名 drop column 列名;
3.2、hive中没有删除列, 但是提供一种方式replace ,但是不推荐, 如果要删除列, 最好重新创建表结构
接下来看看replace的问题。
3.2.1、创建表
hive (test)> create table t2 (name string , age int) row format delimited fields terminated by ",";OKTime taken: 0.652 secondshive (test)> desc t2;OKname string age int Time taken: 0.102 seconds, Fetched: 2 row(s)hive (test)>
3.2.2、加载样例数据
加载数据hive (test)> load data local inpath "/home/hive/t2" into table t2;Loading data to table test.t2Table test.t2 stats: [numFiles=1, totalSize=51]OKTime taken: 0.755 secondshive (test)> select * from t2;OKzhangsan 67lisi 89wangwu 23zhangliu 12gouzi 34Time taken: 0.415 seconds, Fetched: 5 row(s)hive (test)>
3.2.3、增加一列
增加一列sexhive (test)> alter table t2 add columns(sex int);OKTime taken: 0.177 secondshive (test)> ###注意: 此时sex都为NULLhive (test)> select * from t2;OKzhangsan 67 NULLlisi 89 NULLwangwu 23 NULLzhangliu 12 NULLgouzi 34 NULLTime taken: 0.485 seconds, Fetched: 5 row(s)hive (test)>
3.2.4 使用replace 删除列, 注意age被删除,但是数据没有删除, 现在age的值变成sex的值, 导致数据混乱。所以不推荐使用replace
###使用replace 删除列hive (test)> alter table t2 replace columns(name string, sex int);OKTime taken: 0.198 secondshive (test)> select * from t2; ###注意age被删除,但是数据没有删除, 现在age的值变成sex的值OKzhangsan 67lisi 89wangwu 23zhangliu 12gouzi 34Time taken: 0.398 seconds, Fetched: 5 row(s)hive (test)> desc t2;OKname string sex int Time taken: 0.072 seconds, Fetched: 2 row(s)hive (test)>
阅读全文
0 0
- hive sql
- HIVE SQL
- hive sql
- hive sql执行计划
- hive sql分区表
- hive sql 用法
- hive的sql解析
- hive sql分区表
- hive sql 优化
- Hive-sql的特性
- Hive SQL详解
- hadoop hive sql
- hive meta sql
- hive sql语法解读
- hive sql 优化
- hive sql执行计划
- hive sql分区表
- Hive sql 语法解读
- 地平线发布中国首款 AI 视觉芯片,还想让每一辆自动驾驶汽车都有中国芯
- 深度 | AI芯片之智能边缘计算的崛起
- 阿里云AI走下PPT :我存在于这六大产业场景
- LTE-A为5G时代打头阵,高通持续引领移动通讯技术升级
- 专访| 绘画机器人Andy的诞生,与美图秀秀在人工智能技术上的野心
- hive sql
- chrome iphone返回pc userAgent没变回去 ,导致坑死爹了
- [LC]3. Longest Substring Without Repeating Characters
- 中国信通院:2017年Q3共享单车行业发展指数报告(附下载)
- 微服务下的APM全链路监控
- SpringMVC通过xxx.action中的xxx寻找出对应的RequestMapping
- 英特尔「机密档案」:严防死守背后,是怎样的一条AI硬件进击路
- CNN入门材料:《解析卷积神经网络——深度学习实践手册》
- 一文概览深度学习中的五大正则化方法和七大优化策略