前边已经搭建好了hive,也通过cli登录上了hive,那我们来简单说一下hive
Hive是基于Hadoop的一个数据仓库工具
使用Hive前需要的准备工作
- 启动hadoop集群:因为hql语句会被编译成MR任务提交到集群运行;hive表数据一般存储在HDFS上
- mysql服务:因为对hive操作过程中,需要访问mysql中存储元数据的库及表
hive --service hiveserver2 #前台启动hiveserver2,进行beeline登录时需要克隆一个新的窗口
或
nohup hive --service hiveserver2 & #后台启动hiveserver2
beeline --color=true #启动beeline
beeline> !connect jdbc:hive2://hadoop02:10000 #使用JDBC登录Hive
hive -e "show databases"
cd /bigdata/install/hive-3.1.4/
vi hive.sql
#在hive.sql中输入以下HQL语句,保存退出
create database if not exists myhive;
#执行脚本
hive -f /bigdata/install/hive-3.1.4/hive.sql
类型名称 | 描述 | 举例 |
---|---|---|
boolean | true/false | true |
tinyint | 1字节的有符号整数 | 1 |
smallint | 2字节的有符号整数 | 1 |
int | 4字节的有符号整数 | 1 |
bigint | 8字节的有符号整数 | 1 |
float | 4字节单精度浮点数 | 1.0 |
double | 8字节单精度浮点数 | 1.0 |
string | 字符串(不设长度) | “abc” |
varchar | 字符串(1-65355长度,超长截断) | “abc” |
timestamp | 时间戳 | 1563157873 |
date | 日期 | 20190715 |
类型名称 | 描述 | 举例 |
---|---|---|
array | 一组有序的字段,字段类型必须相同 array(元素1,元素2) | Array(1,2,3) |
map | 一组无序的键值对 map(k1,v1,k2,v2) | Map(‘a’,1,‘b‘,2) |
struct | 一组命名的字段,字段类型可以不同 struct(元素1,元素2) | Struct(‘a‘,1,2,0) |
原文:https://www.cnblogs.com/tenic/p/14720085.html