转载于: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表操作(转)的更多相关文章

  1. spark使用Hive表操作

    spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...

  2. Hive 表操作(HIVE的数据存储、数据库、表、分区、分桶)

    1.Hive的数据存储 Hive的数据存储基于Hadoop HDFS Hive没有专门的数据存储格式 存储结构主要包括:数据库.文件.表.试图 Hive默认可以直接加载文本文件(TextFile),还 ...

  3. 从零自学Hadoop(15):Hive表操作

    阅读目录 序 创建表 查看表 修改表 删除表 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceL ...

  4. spark+hcatalog操作hive表及其数据

    package iie.hadoop.hcatalog.spark; import iie.udps.common.hcatalog.SerHCatInputFormat; import iie.ud ...

  5. Hive基础之Hive表常用操作

    本案例使用的数据均来源于Oracle自带的emp和dept表 创建表 语法: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name ...

  6. Hive(五)数据类型与库表操作以及中文乱码

    一.数据类型 1.基本数据类型 Hive 支持关系型数据中大多数基本数据类型 类型 描述 示例 boolean true/false TRUE tinyint 1字节的有符号整数 -128~127 1 ...

  7. hive表信息查询:查看表结构、表操作等--转

    原文地址:http://www.aboutyun.com/forum.PHP?mod=viewthread&tid=8590&highlight=Hive 问题导读:1.如何查看hiv ...

  8. luigi操作hive表

    关于luigi框架下查询hive表的操作 class JoinQuery(HiveQueryTask): date=luigi.DateParameter() def hiveconfs(self): ...

  9. hive表信息查询:查看表结构、表操作等

    转自网友的,主要是自己备份下 有时候不记得! 问题导读:1.如何查看hive表结构?2.如何查看表结构信息?3.如何查看分区信息?4.哪个命令可以模糊搜索表 1.hive模糊搜索表 show tabl ...

随机推荐

  1. ajax验证用户名是否存在,手机号是不是匹配

    <label class="col-sm-2 control-label font">用户名</label> <div class="col ...

  2. php-验证码类-PDO类-缩略图类

    Verify.class.php 验证码类 <?php class Verify{ const VERIFY_TYPE_NUM=1; const VERIFY_TYPE_EN=2; const ...

  3. Ajax请求参数为文件类型

    1.图片用get请求,回调函数中返回的数据就是流文件(至于是什么流文件还不清楚), 在回调函数中再使用post请求2.JS将文件像form表单一样提交到后台  :  https://www.cnblo ...

  4. Python 中练习题涉及到的无穷大和无穷小问题。

    首先来看一下所见的python联系题. inf = infinite 无限制的 float("inf")-1执行后的结果是:() A 1 B inf C -inf D 0 该考点考 ...

  5. tp U函数 logs

    注意 U 函数 项目今天已经搞定了本以为可以上线了没问题了,但是 当我把tp调试模式关闭后:      define('APP_DEBUG',false); 页面完全加载不出来,于是开启:  'SHO ...

  6. CSS:CSS 伪类(Pseudo-classes)

    ylbtech-CSS:CSS 伪类(Pseudo-classes) 1.返回顶部 1. CSS 伪类(Pseudo-classes) CSS伪类是用来添加一些选择器的特殊效果. 语法 伪类的语法: ...

  7. pandas读取文件出现路径不存在的问题

    我写的路径是绝对路径,其他的文件读写完全是没有问题的但是pandas就是不行,于是我改写为全路径:'E:/Python/KNN/iris.csv' 即可解决

  8. LitJson使用中的一些问题

    http://blog.csdn.net/n5/article/details/45030063

  9. springMvc请求路径解析

    一开始我的代码是: //index.jsp<%@ page contentType="text/html;charset=UTF-8" language="java ...

  10. Java 序列化和反序列化(三)Serializable 源码分析 - 2

    目录 Java 序列化和反序列化(三)Serializable 源码分析 - 2 1. ObjectStreamField 1.1 数据结构 1.2 构造函数 2. ObjectStreamClass ...