企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] # 分区 必须是个分区表 ## 增加分区 * 语法结构 ~~~ ALTER TABLE table_name ADD [IF NOT EXISTS] partition_spec [ LOCATION 'location1' ] partition_spec [ LOCATION 'location2' ] ... partition_spec: : PARTITION (partition_col = partition_col_value, partition_col = partiton_col_value, ...) ALTER TABLE table_name DROP partition_spec, partition_spec,... ~~~ # 重命名表 * 语法结构 ~~~ ALTER TABLE table_name RENAME TO new_table_name ~~~ * 具体实例 ~~~ alter table t_patition rename to t_p1; ~~~ ### 增加列 * 语法结构 ~~~ ALTER TABLE table_name ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) ~~~ 注:ADD是代表新增一字段,字段位置在所有列后面(partition列前),REPLACE则是表示替换表中所有字段。 ~~~ ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name] ~~~ * 具体实例 增加列.增加的这个列会放在分区列的前面,其他列的最后面 ~~~ alter table t_p1 add columns (city string); ~~~ ### 更新列 ~~~ //把ip这列改为 ipv4 int alter table t_p1 change column ip ipv4 int; //把表除了分区的,其他都改为name_new string alter table t_p1 replace columns (name_new string); ~~~ ### 显示命令 ~~~ show tables show databases //显示分区 show partitions show functions desc t_name; //显示表信息 desc extended t_name; //显示表更详细信息 desc formatted table_name; //对上面格式化的显示 ~~~ hive可以和linux的命令有交互,在linux命令前面加! ~~~ !clear; !ls; ~~~ 还可以和hdfs交互,dfs命令 ~~~ dfs -ls /; dfs -cat /hello.txt; ~~~