☆☆☆★☆☆☆

唯有努力才能活成自己想要活成的样子

导航

hive操作记录

1.在hive部署节点使用hive的shell,在./bin/hive目录下进入hive的客户端,执行我们的sql语句

--删除表
drop table if exists iov_gather_table;
--创建数据库
create database if not exists db_hive;
--使用表
use iov_gather_table;
--自动修复hive的分区(自动检查目录增加分区)
msck repair table table_name;
--给表添加分区
ALTER TABLE iov_gather_table ADD IF NOT EXISTS PARTITION (f="20220101")
--删除指定分区
ALTER TABLE iov_gather_table DROP IF EXISTS PARTITION (f="20220101")
--查看hive建表语句:
show create table tablename;
--查看hive表结构:
describe tablename; 简写:desc tablename;
--查看表分区:
$ show partitions dataitem1_202304;
--hive Shell命令导出
$ bin/hive -e ‘select id,name from tablename;’ > /root/hadoop/tn.txt
--Export导出到HDFS
hive>export table tablename to/user/export/tn’;
--创建表
CREATE TABLE IF NOT EXISTS iov_gather_table(tid bigint,ty string,val string) COMMENT '数据库' PARTITIONED BY (f string) stored AS ORC ;
--外部表 
external CREATE TABLE IF NOT EXISTS gps_hot( tid bigint, hot_type int, hash_code string, lng double, lat double, cnt int) PARTITIONED BY (pt string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' stored AS txtfile;

2.启动服务端,使用beeline进行交互

注意该方式要先启动服务
nohup /export/server/hive-2.1.0/bin/hive --service hiveserver2 &

3.使用hive命令行的交互

hive -e  'sql语句' 不进入hive的客户端,直接执行hql语句:
ssh azkaban@txj2data01 "hive -e 'use "${dbname}";ALTER TABLE iov_etl_table ADD IF NOT EXISTS PARTITION (f="${date}")'"
hive -f /hive-script.sql 不进入hive的客户端,直接执行hive的脚本(适合多语句):
#!/usr/bin/env bash
ym=$1
ymd=$2
ssh azkaban@txj2data01 "hive --hivevar ym=${ym} --hivevar ymd=${ymd} -f ${dirname}/hive.sql"

 4.把文件导入hive表中

把本地数据导入到Hive表中
load data local inpath '/202107recostationinfo.txt' into table recostationinfo;
把HDFS上的数导入到HIve表中
load data inpath '/data/mid/hotspot/cnt/sq/month/202204/*' overwrite into table gps_hot partition(pt=202204);

 

posted on 2022-06-15 11:23  Yr-Zhang  阅读(136)  评论(0编辑  收藏  举报