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 ...
随机推荐
- ES6(简单了解)
1.import类似于var,不过是定义对外接口的,接受外部的文件. import xx from xx ,有点像var i =3: 如import profile from './prof ...
- [NOIP模拟测试12]题解
A. 找规律题.儿子的编号减去 小于它编号的最大的fibonacci数 即可得到它父亲的编号. 然后两个节点都暴力上跳就好了.预处理一下fibonacci数,每次二分查找即可. #include< ...
- Entity Framework 应用程序有以下优缺点
优点: 1.跨数据库支持能力强大,只需修改配置就可以轻松实现数据库切换2.提升了开发效率,不需要在编写Sql脚本,但是有些特殊Sql脚本EF无法实现,需要我们自己编写(通过EF中的ExecuteSql ...
- 测试常用——linux 基础命令
测试常用 的 linux 基础命令 1,查看服务器日志vi 查看文件(查找关键字:exception/exception : 从上往下找,按n查找下一个关键字,按shift+n查找上一个关键字?e ...
- PE代码段中的数据
PE代码段中可能包含一些数据,比如 optional header中的data directory会索引到一些数据,比如import/export table等等: 还有一些jump table/sw ...
- 使用uc进行手机页面调试
最近使用uc浏览器的时候发现了,一个有趣的现象,就是uc会处理h5web app为全屏,并屏蔽一些手机上的操作,这样就会使web app更加接近本地应用.所以就研究 了一下uc的手机调试. 1.准备工 ...
- Java 设计模式之 装饰者模式
装饰者模式(Decorator Pattern): 概述:装饰模式是在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象 特点: (1) ...
- Java 8 终于支持 Docker !
]; v.add(b); Runtime rt = Runtime.getRuntime(); System.out.println( "free memory ...
- js面向对象(一)---基本的概念、属性、方法
一.什么是面向对象编程 1.用对象的思想去写代码,就是面向对象编程 2.我们一直在使用对象,如数组Array 时间Date //我们把系统自带的对象,叫做系统对象 var arr = new A ...
- 8-MySQL-Ubuntu-数据表中数据的增加(一)
增(insert) (1)全部字段插入数据:按表中字段顺序增加数据 注:(1)主键字段可以使用0/null/default来占位.(2)gender字段中数据类型是枚举,可以使用索引数字1,2,3,4 ...