19 个回答
hive表中数据导出:
#将查询的结果导出到本地
insert overwrite local directory '/export/servers/exporthive' select * from score;
#将查询的结果格式化导出到本地:
insert overwrite local directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from student;
#将查询的结果导出到HDFS上(没有local):
insert overwrite directory '/export/servers/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from score;
#export导出到HDFS上
export table score to '/export/exporthive/score';
发布于:1个月前 (03-18) IP属地:
向hive表中加载数据:
#直接向分区表中插入数据:
insert into table score partition(month ='202107') values ('001','002','100');
#通过load方式加载数据:
load data local inpath '/export/servers/hivedatas/score.csv' overwrite into table score partition(month='201806');
#通过查询方式加载数据:
insert overwrite table score2 partition(month = '202106') select s_id,c_id,s_score from score1;
#查询语句中创建表并加载数据:
create table score2 as select * from score1;
#在创建表是通过location指定加载数据的路径:
create external table score6 (s_id string,c_id string,s_score int) row format delimited fields terminated by ',' location '/myscore';
#export导出与import 导入 hive表数据
create table techer2 like techer; --依据已有表结构创建表
export table techer to '/export/techer';
import table techer2 from '/export/techer';
发布于:1个月前 (03-18) IP属地:
清空表:
truncate table score6;
发布于:1个月前 (03-18) IP属地:
删除表:
drop table score5;
发布于:1个月前 (03-18) IP属地:
强制删除数据库:
drop database myhive2 cascade;
发布于:1个月前 (03-18) IP属地:
删除空数据库:
drop database myhive2;
发布于:1个月前 (03-18) IP属地:
添加分区:
alter table table_name add partition (dt='2021-11-30');
发布于:1个月前 (03-18) IP属地:
删除分区:
alter table table_name drop partition(dt='2021-11-30');
发布于:1个月前 (03-18) IP属地:
hive修改字段:
alter table table_name change old_column new_column string comment 'comm_text';
发布于:1个月前 (03-18) IP属地:
hive添加字段:
alter table table_name add columns(columns_values bigint comment 'comm_text');
发布于:1个月前 (03-18) IP属地:
hive复制表结构:
create table new_table_name like table_name;
发布于:1个月前 (03-18) IP属地:
hive修改表名:
alter table old_table_name rename to new_table_name;
发布于:1个月前 (03-18) IP属地:
创建表时指定的一些属性:
#字段分隔符:
row format delimited fields terminated by '\t'
#行分隔符:
row format delimited lines terminated by '\n'
#文件格式为文本型存储:
stored as textfile
发布于:1个月前 (03-18) IP属地:
导出数据到本地系统:
insert overwrite local directory '/tmp/text' select a.* from table_name a order by 1;
发布于:1个月前 (03-18) IP属地:
从查询语句给table插入数据:
insert overwrite table table_name partition(dt) select * from table_name;
发布于:1个月前 (03-18) IP属地:
加载本地文件:
load data local inpath '/xxx/test.txt' overwrite into table dm.table_name;
发布于:1个月前 (03-18) IP属地:
查看分区信息:
show partitions table_name;
发布于:1个月前 (03-18) IP属地:
查看表结构信息:
desc table_name;
发布于:1个月前 (03-18) IP属地:
hive模糊搜索表:
show tables like '*name*';
发布于:1个月前 (03-18) IP属地:
我来回答
您需要 登录 后回答此问题!