hive表操作(转)
转载于:http://blog.csdn.net/lovelovelovelovelo/article/details/52234971
数据类型
基本数据类型
集合类型,array、map、struct
文件格式,textfile、sequencefile、rcfile
创建表(内部表)
create table employee(
name string comment 'name',
salary float,
subordinates array<string>,
deductions map<string,float>,
address struct<street:string,city:string,state:string,zip:int>
)
row format delimited fields termited by '\t' lines terminated by '\n' stored as textfile;
从文件加载数据,覆盖源表
load data local infile 'path' overwrite into table 'table'
创建外部表
create external table employee(
name string comment 'name',
salary float,
subordinates array<string>,
deductions map<string,float>,
address struct<street:string,city:string,state:string,zip:int>
)
row format delimited fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':'
lines terminated by '\n'
stored as textfile
location '/data/';
表中数据
lucy 11000 tom,jack,dave,kate tom:1200,jack:1560 beijing,changanjie,xichengqu,10000
lily 13000 dave,kate dave:1300,kate:1260 beijing,changanjie,xichengqu,10000
和我们熟悉的关系型数据库不一样,Hive现在还不支持在insert语句里面直接给出一组记录的文字形式,也就是说,hive并不支持INSERT INTO …. VALUES形式的语句。
新建employee.txt,将数据存入文件中,注意字段间用tab,行间换行enter
通过hive命令加载数据
hive> load data local inpath '/root/employee.txt' into table employee;
hive> select * from employee;
OK
lucy 11000.0 ["tom","jack","dave","kate"] {"tom":1200.0,"jack":1560.0} {"street":"beijing","city":"changanjie","state":"xichengqu","zip":10000}
lily 13000.0 ["dave","kate"] {"dave":1300.0,"kate":1260.0} {"street":"beijing","city":"changanjie","state":"xichengqu","zip":10000}
Time taken: 0.054 seconds, Fetched: 2 row(s) select * from table不走mapreduce
由一个表创建另一个表
create table table2 like table1;
从其他表查询创建表
create table table2 as select name,age,add from table1;
hive不同文件读取
stored as textfile:
hadoop fs -text
stored as sequencefile:
hadoop fs -text
stored as rcfile:
hive -service rcfilecat path
stored as input format 'class':
outformat 'class'
分区表操作
alter table employee add if not exists partition(country='')
alter table employee drop if exists partition(country='')
hive分桶
create table bucket_table(
id int,
name string
)
clustered by(id) sorted by(name) into 4 buckets
row format delimited fields terminated by '\t' stored as textfile;
set hive.enforce.bucketing=true;
创建分区表
create table partitionTable(
name string,
age int
)
partitioned by(dt string)
row format delimited fields terminated by '\t'
lines terminated by '\n'
stored as textfile;
hive表操作(转)的更多相关文章
- spark使用Hive表操作
spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...
- Hive 表操作(HIVE的数据存储、数据库、表、分区、分桶)
1.Hive的数据存储 Hive的数据存储基于Hadoop HDFS Hive没有专门的数据存储格式 存储结构主要包括:数据库.文件.表.试图 Hive默认可以直接加载文本文件(TextFile),还 ...
- 从零自学Hadoop(15):Hive表操作
阅读目录 序 创建表 查看表 修改表 删除表 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceL ...
- spark+hcatalog操作hive表及其数据
package iie.hadoop.hcatalog.spark; import iie.udps.common.hcatalog.SerHCatInputFormat; import iie.ud ...
- Hive基础之Hive表常用操作
本案例使用的数据均来源于Oracle自带的emp和dept表 创建表 语法: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name ...
- Hive(五)数据类型与库表操作以及中文乱码
一.数据类型 1.基本数据类型 Hive 支持关系型数据中大多数基本数据类型 类型 描述 示例 boolean true/false TRUE tinyint 1字节的有符号整数 -128~127 1 ...
- hive表信息查询:查看表结构、表操作等--转
原文地址:http://www.aboutyun.com/forum.PHP?mod=viewthread&tid=8590&highlight=Hive 问题导读:1.如何查看hiv ...
- luigi操作hive表
关于luigi框架下查询hive表的操作 class JoinQuery(HiveQueryTask): date=luigi.DateParameter() def hiveconfs(self): ...
- hive表信息查询:查看表结构、表操作等
转自网友的,主要是自己备份下 有时候不记得! 问题导读:1.如何查看hive表结构?2.如何查看表结构信息?3.如何查看分区信息?4.哪个命令可以模糊搜索表 1.hive模糊搜索表 show tabl ...
随机推荐
- Yii2 自定义组件
basic\components\HelloWidget namespace app\components; use yii\base\Widget; use yii\helpers\Html; cl ...
- CSS3布局篇(多列布局)
我们通过学习 CSS3,能够创建多个列来对文本进行布局 ,就像报纸那样排版那样! 可以参考详细说明:http://www.w3school.com.cn/css3/css3_multiple_colu ...
- 画PCB时检查点总结
一.画原理图时 NPN的引脚是否对应.继电器的引脚是否对应 设计通信电路时,MCU_RX和通信芯片RS232的ROUT接.同理MCU_TX和RS232的TIN接. MCU最好留个外接晶振接口,用NPN ...
- webpack 添加eslint代码审查
1). 添加包 npm install eslint --save-dev npm install eslint-loader --save-dev npm install eslint-plugin ...
- python使用threading获取线程函数返回值的实现方法
python使用threading获取线程函数返回值的实现方法 这篇文章主要介绍了python使用threading获取线程函数返回值的实现方法,需要的朋友可以参考下 threading用于提供线程相 ...
- C++——类
1.类和结构体,只有的默认访问权限的区别 2.类内不能定义和类外类型名相同的类型名.为什么?typedef机制? typedef double money; class Account { priva ...
- Codeforces 1173B Nauuo and Chess
题目链接:http://codeforces.com/problemset/problem/1173/B 思路参考:https://www.cnblogs.com/blowhail/p/1099123 ...
- vuex-along解决vuex中存储的数据在页面刷新之后失去的问题
1. 为什么会失去? vuex可以看成是一个"提升变量"的一个工具,它是将state当做全局变量存储.F5刷新页面之后自然随着页面的刷新重新初始化state. 2. 如果解决数据保 ...
- Vue之获取用户当前所在省市
今天小编给大家带来的是使用Vue获取用户所在城市,Vue是很强大的,给大家准备好现成的插件供大家调用,下面的Demo小编使用的是百度API. 首先我们从百度平台申请百度地图的秘钥,申请成功后我们将&l ...
- element ui设置表格表头高度和每一行的高度
填坑记录:今天用element ui的表格组件做用户信息展示,直接拉取的官网的代码过来,发现表头和每一行都太高了,如下: 因为第一次使用element ui的表格组件,不太清楚会遇到这样的坑,以为能轻 ...