HiveSQL的常用的一些语句

--使用注意
1、不支持删除字段
2、不支持修改操作

--查询表字段及注释
desc table_name;

--查询建表语句
show create table_name;

--查询表分区
show partitions table_name;

--查询表数据
select t.* from dm_gis.gis_rds_omsto t where inc_day='20190601' limit 1000;

--增加分区
alter table dm_gis.table_name add if not exists partition (inc_day = '20190601');

--删除分区
alter table dm_gis.table_name add if not exists partition (inc_day = '20190601');

-- 增加列字段(最后)
alter table `dm_gis.table_name` add columns (
`name` string comment '名字',
`age` int comment '年龄',
`height` float comment '身高');

--改变列字段名称
alter table table_name change column old_column_name new_column_name column_type;

--修改表字段注释
alter table table_name change [cloumn] col_old_name col_new_name column_type [conmment col_conmment] [first|after column_name];
alter table table_name change cloumn col_old_name col_new_name column_type conmment col_conmment;


--给表重命名
alter table old_table_name rename to new_old_name;

--根据已存在的表结构建新表
create table new_table_name like source_table_name;

--清除表数据
truncate table table_name;

--删除表
drop table table_name;

--创建表(内部表)
create table if not exists `dm_gis.person`(
`name` string comment '名字',
`age` int comment '年龄',
`hight` string comment '身高'
)comment '个人信息' partitioned by (`year` string) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile;

--创建外部表
create external table if not exists dm_gis.bee_logs_gis_ass_rds_chk_dispatch(
log string comment "一行日志数据"
) comment 'rds派件原始日志外部映射表' partitioned by (`inc_day` string) 
row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile 
location '/user/mario/warehouse/bee_logs_gis_ass_rds_chk_dispatch' ;

--根据查询语句结果创建表并加载数据(非分区表)
create table dm_gis.gis_copy_test001 as 
select citycode,tc,inc_day from dm_gis.dlv_addr_tc_count where inc_day='20190501' limit 100;

--外部表新增映射分区
alter table dm_gis.bee_logs_gis_ass_rds_chk_dispatch add if not exists partition (inc_day='20181108') 
location '/user/mario/warehouse/bee_logs_gis_ass_rds_chk_dispatch/20181108';

--加载数据到hdfs路径下(先建好分区,文件格式需和定义的表格式一致)
load data inpath '/user/01375125/upload/file/aoi_id.csv' into table dm_gis.aoi_id_addr_type partition(inc_day='20190322');

--表之间倒腾数据
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table dm_gis.dlv_addr_tc_rate partition(inc_day)
select citycode,waybill_count,tc_match_count,tc_mismatch_count,tc_match_rate,inc_day,other,`inc_day`
from dm_gis.dlv_tc_rate_info
where inc_day between '20190301' and '20190331';

 

转载于:https://www.cnblogs.com/david227/p/10977965.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.上传tar包 2.解压 tar -zxvf hive-1.2.1.tar.gz 3.安装mysql数据库 推荐yum 在线安装 4.配置hive (a)配置HIVE_HOME环境变量 vi conf/hive-env.sh 配置其中的$hadoop_home (b)配置元数据库信息 vi hive-site.xml 添加如下内容: javax.jdo.option.ConnectionURL jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true JDBC connect string for a JDBC metastore javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName root username to use against metastore database javax.jdo.option.ConnectionPassword hadoop password to use against metastore database 5.安装hive和mysq完成后,将mysql的连接jar包拷贝到$HIVE_HOME/lib目录下 如果出现没有权限的问题,在mysql授权(在安装mysql的机器上执行) mysql -uroot -p #(执行下面的语句 *.*:所有库下的所有表 %:任何IP地址或主机都可以连接) GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES; 6. Jline包版本不一致的问题,需要拷贝hive的lib目录中jline.2.12.jar的jar包替换掉hadoop中的 /home/hadoop/app/hadoop-2.6.4/share/hadoop/yarn/lib/jline-0.9.94.jar 启动hive bin/hive ---------------------------------------------------------------------------------------------------- Hive几种使用方式: 1.Hive交互shell bin/hive 2.Hive JDBC服务(参考java jdbc连接mysql) 3.hive启动为一个服务器,来对外提供服务 bin/hiveserver2 nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/var/log/hiveserver.err & 启动成功后,可以在别的节点上用beeline去连接 bin/beeline -u jdbc:hive2://mini1:10000 -n root 或者 bin/beeline ! connect jdbc:hive2://mini1:10000 4.Hive命令 hive -e ‘sql’ bin/hive -e 'select * from t_test'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值