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 ...
随机推荐
- 【书上讲解】最大m段子段和问题
描述 [题解] 设f[i][j]表示前i个数字分成了j段的最大子段和. 则f[i][j] = max(f[i-1][j]+a[i] (第i个数字和第j段合在一起),f[k][j-1]+a[i] (第i ...
- 【dart学习】-- Dart之元数据
一,概述 元数据概述 元数据(Metadata),又称中介数据.中继数据,为描述数据的数据(data about data),主要是描述数据属性(property)的信息,用来支持如指示存储位置.历 ...
- Robotframework之下拉列表select
下拉框控件很常见啊,主要说一下robotframework中怎么玩转下拉框,第一点要注意的就是,别看到下拉的就用select控件去操作,因为很多下拉列表用的不一定就是select控件.robotfra ...
- python安装 cvxpy 巨坑,一堆C++错误
https://www.lfd.uci.edu/~gohlke/pythonlibs/#ecos 下载scs,ecos,cvxpy的whl,一个个安装即可 之前被一堆C++错误搞晕了2小时
- form表单和CSS基础
form 表单 input type="" 表单的组合标签,用来确定需要的是什么输入类型 type属性值: 文本输入框:text 密码输入框:password 单选按钮:radio ...
- 人人开源打包jar
先在renren-security执行mvn clean install 再到renren-admin目录下,执行mvn clean package,就可以打成renren-admin.jar 如果想 ...
- Vuex篇
[Vuex篇] vuex源码你学会了吗? 我来免费教你!~ 1.vuex是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的 ...
- 高级UI晋升之View渲染机制(二)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 优化性能一般从渲染,运算与内存,电量三个方面进行,今天开始说聊一聊Android ...
- 自动化监控系统(三) 搭建xadmin做网站后台
Django有个自带的admin后台,不过界面不怎么好看,这里我用xadmin 我的python版本是3.5,可以使用支持py3的xadmin:https://github.com/sshwsfc/x ...
- 获取文件或目录的属性 stat 函数
头文件: <sys/types.h> <sys/stat.h> <unistd.h> int stat(const char *path, struct ...