栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Hive常用命令

Hive常用命令

一、HQL

1.修改字段类型

alter table 表名 change column 字段名 字段名 目标的字段类型

#例子:将表test中的字段a的类型转换为bigint
alter table test change column a a bigint

2.删除库及库中所有表(数据也会删除)

DROp DATAbase IF EXISTS 数据库名 CASCADE;

# 例子:删除student库
DROP DATAbase IF EXISTS student CASCADE;

3.创建数据库

# 语法
CREATE (DATAbase|SCHEMA) [IF NOT EXISTS] database_name
  [COMMENT database_comment]
  [LOCATION hdfs_path]
  [WITH DBPROPERTIES (property_name=property_value, ...)];

database_name:数据库名
database_comment:数据库的描述
hdfs_path:在hdfs上的存储路径,不填则默认存储在'/usr/hive/warehouse/数据库名.db'

#例子
CREATE DATAbase IF NOT EXISTS student
COMMENT '学生数据库'
LOCATION '/usr/hive/warehouse/student.db'

4.创建表

create table if not exists 表名
(
    字段名 类型 [COMMENT],
    字段名 类型 [COMMENT]
    ...
)
PARTITIonED BY ( 
分区字段1 类型, 
分区字段2 类型
...
)
row format delimited fields terminated by 分隔符
location hdfs路径;


# 例子
create table if not exists att
(
`attserial` bigint comment '序列号',
`filename` string comment '文件名'
)
COMMENT '学生档案表'
PARTITIonED BY ( 
`year` string, 
`month` string, 
`day` string)
row format delimited fields terminated by 't'
location '/user/hive/warehouse/student.db/att';

5.修改字段分隔符

alter table mytable set serdeproperties('field.delim'='t');

 6.当前时间

from_unixtime(unix_timestamp())
二、hive cli命令

1.从mysql全量导入表数据到hive分区表

sqoop import 
--connect jdbc:mysql://10.xxx.xx.xx:4000/db_base_data?tinyInt1isBit=false 
--username xxxx 
--password xxxx 
--query "select *  from att where $CONDITIONS" 
--fields-terminated-by 't' 
--delete-target-dir 
--hive-import 
--m 1 
--hive-partition-key record_date 
--hive-partition-value 2021-12-09 
--hive-database shenzhen_shenba 
--hive-table tbl_base_line 
--target-dir /user/hive/warehouse/busgroupdb.db/att/year=2021/month=12/day=09
--delete-target-dir 
--direct

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/682771.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号