美文网首页
Hive 基础

Hive 基础

作者: 歌哥居士 | 来源:发表于2019-03-30 12:32 被阅读0次

Hive 基础

Hive启动:

$ start-dfs.sh
$ start-yarn.sh
$ systemctl start mysqld
$ hive

插入数据:

创建表
hive> create table student(id int, name string);
插入数据
hive> insert into student values(1,"baozi");
查询
hive> select * from student;

插入数据文件:

创建表
hive> create table emp(id int,name string)  row format delimited fields terminated by '\t';
插入数据 
$ vim emp-data
1       baozi1
2       baozi2
3       baozi3
hive> load data local inpath '/home/user000/data/emp-data' into table emp;
查询
hive> select * from emp;

Hive交互命令:

hive -S                静默模式进入
hive -e                '要执行的语句'; 直接执行
hive -f xxx.hql        执行hql文件
dfs ...                hive命令窗口使用hdfs dfs ...命令
! 命令                  执行操作系统命令

参数配置方式:

  • hive> set ......
  • hive -hiveconf ......
  • 配置文件

查看数据库与表:

$ show databases;
$ show databases like 'hive*';

类型转换
默认:自动向上转型,BOOLEAN除外。
手动:CAST('1' AS INT),失败返回NULL。

Hive 数据类型

Hive基本数据类型 Java数据类型 长度 例子
TINYINT byte 1byte 有符号整数 20
SMALINT short 2byte 有符号整数 20
INT int 4byte 有符号整数 20
BIGINT long 8byte 有符号整数 20
BOOLEAN boolean true或false TRUE FALSE
FLOAT float 单精度浮点数 3.14159
DOUBLE double 双精度浮点数 3.14159
STRING String 相当于varchar 不过不能生命存储多少个
TIMESTAMP 时间类型 BINARY 字节数组
复杂数据类型 描述
ARRAY 使用“array名[下标]”访问:friends[1]
MAP 使用“map名['属性名']”访问:children['xiao song']
STRUCT 类似于C语言的struct使用“struct名.属性”访问:address.city与Map不同的就是,map是根据键找值,struct是访问属性

数据类型示例

$ vim test.txt
songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing

操作
直接将数据文件放到/user/hive/warehouse/test/目录下,可以免去load data ......
$ hdfs dfs -mkdir /user/hive/warehouse/test/
$ hdfs dfs -put ~/data/test.txt /user/hive/warehouse/test/
hive> create table test(
    name string,
    friends array<string>,
    children map<string,int>,
    address struct<street:string,city:string>
)
row format delimited
fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

hive> select * from test;
test.name   test.friends    test.children   test.address
songsong    ["bingbing","lili"] {"xiao song":18,"xiaoxiao song":19} {"street":"hui long guan","city":"beijing"}
yangyang    ["caicai","susu"]   {"xiao yang":18,"xiaoxiao yang":19} {"street":"chao yang","city":"beijing"}

hive> select friends[1], children['xiao song'],address.city from test;
_c0 _c1 city
lili    18  beijing
susu    NULL    beijing

Hive hiveserver2

A 终端
$ hiveserver2

B 终端
$ ~/tools/hive/bin/beeline
beeline> !connect jdbc:hive2://host000:10000
Enter username for jdbc:hive2://host000:10000: user000
Enter password for jdbc:hive2://host000:10000:

0: jdbc:hive2://host000:10000> show databases;
0: jdbc:hive2://host000:10000> show tables;
0: jdbc:hive2://host000:10000> select * from test;

默认thriftserver的端口是10000,可以通过启动thriftserver时设置hive.server2.thrift.port=<listening-port>参数更改

相关文章

  • Hive 基础

    Hive 基础 Hive启动: 插入数据: 插入数据文件: Hive交互命令: 参数配置方式: hive> set...

  • Hive编程指南笔记整理

    hive编程指南阅读笔记 1.基础操作 1.1.启动hive HIVE_HOME$ bin/hive 1.2.1....

  • Hive框架基础(二)

    * Hive框架基础(二) 我们继续讨论hive框架 * Hive的外部表与内部表 内部表:hive默认创建的是内...

  • hive相关基础

    hive相关基础 1、进入到hive命令下;(linux下直接输入hive即可) hive 2、查看工作分区下的h...

  • Hive 基础搭建教程

    需要安装Hadoop,教程:Hadoop 基础搭建教程 需要了解Hive基本概念:Hive 基础知识 1. 相关依...

  • Hive常用命令

    hive官网:http://hive.apache.org/ 基础内容学习: https://cwiki.apac...

  • 无标题文章

    Hive 学习笔记 学习笔记 Hive 简介 Hive 是建立在 Hadoop 上的数据仓库基础构架,可以用来进行...

  • Hive架构及搭建方式

    Hive架构及搭建方式 [TOC] 前言 本文档基于hive 3.1.2编写 hive的基础知识 基本架构 整个h...

  • 2017年10月24日

    大数据系统基础 4.7-4.14《Hive编程指南》第1章《Hive编程指南》第2章《Hive编程指南》第3章

  • hive学习(三):练习题——collect_set及array

    前言: 以sql为基础,利用题目进行hive的语句练习,逐步体会sql与hive的不同之处。 题目用到hive的集...

网友评论

      本文标题:Hive 基础

      本文链接:https://www.haomeiwen.com/subject/yydxvqtx.html