1.hive中一次性使用命令:
hive -e "select * from ldh_table limit 3";
静默执行且保存一次性命令: hive -S -e "select * from ldh_table limit 3" 》 /temp/myfile
2.从文件中执行hive
hive -f /path/file/myhive.sql
在hive shell中用 source /path/file/myhive.sql
3.hive中执行shell命令
加感叹号,以分号结尾
4.hive中执行hadoop的dfs命令
去掉hadoop关键字,以分号结尾
5.注释 --
6.显示字段名称
第一行加上 set hive.cli.print.header = true;
7.hive的数据类型:
7.1 基本数据类型
7.2 集合数据类型
STRUCT
MAP
ARRAY
7.3 分隔符
\n:
^A:分隔列
^B:STRUCT、ARRAY分隔
^C:MAP分隔
create table ldh_table(name string,weight float) row format delimited fields terminated by ',';
8.数据定义
8.1 数据库:
create database human_resource;
show databases like 'h.*';
drop database if exists financials cascade; --加上cascade自动删除financials中的表
8.2 表
create table if not exists t1 like t2;
show tables 't.*';
describe extended t1; --查看详细结构信息
create table emp1 (name string , salary string) partitioned by (county string,stat string);
alter table t1 rename to emp1;--重命名
alter table t1 change columns hms hoiers INT COMMENT 'the hours,the minutes,and secode' after severity;
9.数据操作
装载数据:load data local inpath 'path' overwrite into table employees;
查询语句向表中插入数据:(overwrite和into差别:into是追加,overwrite会覆盖掉之前的内容)
insert overwrite table employees partition (county = 'us',stat='or')
select * from stag;
hive使用
最新推荐文章于 2022-03-29 09:13:14 发布