Hive基本使用

2021-08-13 21:07:14 字數 1430 閱讀 1725

啟動hadoop:

$/sbin/start-all.sh

啟動hive:

$/bin/hive

建立表:

create  table table_name

[(col_name data_type [comment col_comment])]

create table hive_wordcount(context string);

載入資料到hive表

load data local inpath 'filepath' into table tablename 

load data local inpath '/home/hadoop/data/hello.txt' into table hive_wordcount;

查詢:

select word, count(1) from hive_wordcount lateral view explode(split(context,'\t')) wc as word group by word;

lateral view explode(): 是把每行記錄按照指定分隔符進行拆解

hive ql提交執行以後會生成mr作業,並在yarn上執行

刪除表:

drop table hive_wordcount;

完整例子:

create table emp(

empno int,

ename string,

job string,

mgr int,

hiredate string,

sal double,

comm double,

deptno int

) row format delimited fields terminated by '\t';

create table dept(

deptno int,

dname string,

location string

) row format delimited fields terminated by '\t';

load data local inpath '/home/hadoop/data/emp.txt' into table emp;

load data local inpath '/home/hadoop/data/dept.txt' into table dept;

求每個部門的人數

select deptno, count(1) from emp group by deptno;

HIVE基本使用

筆者注 這裡安裝的版本為hive 0.13.1 注 表示可選 create database if not exists db hive use db hive drop database if exists db hive create table stu id int name string r...

Hive基本使用

hive基本使用 庫操作 建立庫 進入終端 beeline u jdbc hive2 n user 判斷是否存在並新增注釋 create database if not exists zxl test comment hive test 新增屬性 create database if not exi...

Hive 3 Hive 基本使用

1 建立庫 create database if not exists mydb 2 檢視庫 show databases 3 切換資料庫 use mydb 4 建立表 create table if not exists t user id string,name string 或 create ...