HIVE学习笔记:Hive CLI基本操作
来源:互联网 发布:淘宝手机充值利润 编辑:程序博客网 时间:2024/04/28 23:38
Hive Command Line
进入shell
直接键入hive进入Hive CLI:
hive
新建表
新建表(comment为备注):
create table if not exists test(name string comment 'name value',addr string comment 'addr value');
显示创建表时的相关信息
show create table test;
打印表信息
显示表的详细信息:
desc formatted test;
外部表
创建外部表并打印表信息:
create external table if not exists test_ext(name string comment 'name value',addr string comment 'addr value');
内外表的区别
官方给出的信息:
A table created without the EXTERNAL clause is called a managed table because Hive manages its data.
内部表(managed table)的数据是由HIVE来管理的,而外部表则不是。两者的区别主要体现在表的删除上,当删除一个表时,若为内部表,则表在HDFS上关联的数据也会被删除;删除外部表时其在HDFS上关联的数据不会被删除。
指定表的分隔格式
创建预设格式的表(field表示每行的字段,以制表符为分割):
create table if not exists test_formatted(name string comment 'name value',addr string comment 'addr value')row format delimitedfields terminated by '\t'lines terminated by '\n'stored as textfile;
以已有表的格式创建新表
只复制格式不复制内容
create table copy like test_formatted;desc formatted copy;
从本地加载数据到表中
local指定本地文件,本地文件会被上传到HDFS中;overwrite以覆盖方式写入,否则以追加方式写入:
load data local inpath '/home/daya/test/students.txt' overwrite into table test_formatted;select * from test_formatted;
查找条目
select * from test_formatted where name='wang';
删除表
drop table test_formatted;
表的存储位置
表数据默认存放在HDFS中:
复杂表的基本运用
array,map,struct都属于collection item,它们内部的条目设为以逗号分隔:
create external table if not exists employees(name string,salary float,subordinates array<string>,deductions map<string,float>,address struct<street:string,city:string,state:string,zip:int>)row format delimitedfields terminated by '\t'collection items terminated by ','map keys terminated by ':'lines terminated by '\n'stored as textfilelocation '/data/';load data local inpath '/home/daya/test/test.txt' overwrite into table employees;select * from employees;
本地文本内容:
输出信息:
查找:
select subordinates[0] from employees;select deductions["k4"] from employees;select address.city from employees;
官方HIVECLI命令指南
阅读全文
0 0
- HIVE学习笔记:Hive CLI基本操作
- Hive基本操作笔记
- Hive学习之Hive CLI
- hive学习笔记-hive的基本语法
- Hive笔记三:基本操作
- Hive学习笔记 --- Hive分区表的操作
- 【Hive】 cli 的基本用法
- hive学习笔记-表操作
- hive学习笔记-数据操作
- Hive Cli
- hive cli
- Hive Cli
- Hive Cli
- hive cli
- Hive CLI
- hive cli
- Hive Cli
- hive.cli
- 621. Task Scheduler
- hibernate连接oracle数据库
- iOS 开发者帐号 App转让/转移 及转移后的证书问题解答
- 354. Russian Doll Envelopes 类似最长递增子序列
- JS实现气泡提示框
- HIVE学习笔记:Hive CLI基本操作
- DesiredCapabilities参数设置
- 207. Course Schedule
- 417. Pacific Atlantic Water Flow
- Spring体系结构
- 200. Number of Islands
- 301. Remove Invalid Parentheses
- 判断变量的类型(typeof、instanceof、Object.prototype.toString)
- 58赶集基于 Docker 的自动化部署实践