• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > Hive编程指南_学习笔记01,hive编程指南

Hive编程指南_学习笔记01,hive编程指南

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含Hive编程指南_学习笔记01,hive编程指南等服务器相关知识,网友希望可以进行参考

Hive编程指南_学习笔记01,hive编程指南


第四章: HQl的数据定义
1:创建数据库
  create database financials;
  create database  if not exists financials;


2: 查看数据库
  show databases;
   模糊查询数据库
  show databases like 'h.*' ;


3:创建数据库修改数据库的默认位置
   create database financials localtion '/my/preferred/directory'


4:增加数据库的描述信息
   create database financials comment 'holds all financials tables'
5: 显示数据库的描述的信息
  describe database financials;
6: 增加一些和相关属性的键-值对属性信息
  create database financials
  with dbproperties ('create'= 'Mark Moneybags', 'data'='2012-12-12');
  describe database  extended  financials;
  
7:没有命令提示让用户查看当前所在的是那个数据库。可以重复使用use
  use financials;
  可以通过设置一个属性值来在提示符里面显示当前所在的数据库
  set hive.cli.print.current.db = true;
  set hive.cli.print.current.db= false;
  
8:删除数据库
 drop database if exists financials;
 Hive是不允许删除一个包含表的数据库,
 当时如果加上关键字: cascade,就可以了,hive自动删除数据库中的表
  drop database if exists financials  cascade; 
 
9:修改数据库,设置dbproperties键值对属性值
 alert database financials set  dbproperties('edited-by'='joe dba');
 
10:创建表:
 create table if not  exists employees (
  name string comment 'employee name',
  salary float comment 'employee salary ',
  subordinates array<string> comment 'employee name of subordinates ' ,
  deductions Map<string,FLOAT>,
  address struct<street:string,city:string,state:String,zip:int>
  )
  comment ' description  of the table ' 
  tblproperties ('creater'= 'me', 'created_at'='2012-12-12');
  location '/user/hive/warehouse/mydb.db/employees'
  
  -- tblproperties 的主要作用是:按键-值对的格式为表增加额外的文档说明
  
11: 列举某个表的tblproperties 属性信息
  show  tblproperties employees;
 
12: 拷贝表
create table if not exists mydb.employees2 like mydb.employees2  


13:选择数据库
    use mydb
   显示表
show tables;
show tables  IN  mydb;
14: 查看这个表的详细结果信息
describe extended mydb.employees
    使用formatted 关键字代替 extended
describe formatted mydb.employees

15: 管理表:内部表:删除表时,会删除这个表的数据
   创建一个外部表:其可以读取所有位于/data/stocks目录下的以逗号分割的数据
   create external table if not exists stocks(
   exchange string,
   symbol string,
   ymd String,
   price_open float,
   price_hight float,
   price_low float,
   price_close float,
   volume int,price_adj_close float)
   row  format delimited fields terminated by ','
   location '/data/stocks'

16: 查看表是否是管理表还是外部表
 describe extended tablename
   输出信息:
   tableType.managed_table--管理表
   tableType.external_table--外部表
   
   -- 复制表但不会复制数据
create table if not exists mydb.employees3(新表)
like mydb.employees2(原表)    location '/data/stocks'
   

17: 创建分区表
  create table employees (
  name string,
  salary float,
  subordinates array<string>,
  deductions Map<string,FLOAT>,
  address struct<street:string,city:string,state:String,zip:int>
  )
  partitioned by (country String,state string);

  分区自段:
  country String,state string 和普通字段一样,相当于索引字段,
  根据分区字段查询,提交效率,提高查询性能
  
18: set hive.mapred.mode=strict;
   如果对分区表进行查询而where子句没有加分区过滤的话,
   将会禁止提交这个任务。
   可以设置为:nostrict
  
19: 查看表中存在的所有分区
   show partitions employees;
   
20: 查看是否存储某个特定分区键的分区的话
show partitions employees   partition(country='US');
     describe extended employees 命令也会显示分区键


  管理大型生产数据集最常见的情况:使用外部分区表
21:在管理表中用户可以通过载入数据的方式创建分区:
   load data local inpath '/home/hive/California-employees'
   INTO table employees
   partition(country='US',state='CA');


   hive 将会创建这个分区对应的目录..../employees/country=US/state=CA


22:创建外部分区表
   
   create table  if not exists log_messages (
hms  int,
severity string,
server string,
process_id  int,
message  string
 
  )
  partitioned by (year int,month int,day int) 
  row  format delimited fields terminated by '\t'





1:order by  会对输入做全局排序

2: sort可以控制每个reduce产生的文件都是排序,再对多个排序的好的文件做二次归并排序。

sort by 特点如下:
 1) . sort by 基本受hive.mapred.mode是否为strict、nonstrict的影响,但若有分区需要指定分区。
 2). sort by 的数据在同一个reduce中数据是按指定字段排序。
 3). sort by 可以指定执行的reduce个数,如:set mapred.reduce.tasks=5 ,对输出的数据再执行归并排序,即可以得到全部结果。

结果说明:严格模式下,sort by 不指定limit 数,可以正常执行。sort by 受hive.mapred.mode=sctrict 的影响较小。

3:distribute by 
distribute by 是控制在map端如何拆分给reduce端。根据distribute by 后面的列及reduce个数进行数据分发,默认采用hash算法。distribute可以使用length方法会根据string类型的长度划分到不同的reduce中,最终输出到不同的文件中。 length 是内建函数,也可以指定其他的函数或这使用自定义函数。

4:    cluster by 

cluster by 除了distribute by 的功能外,还会对该字段进行排序,所以cluster by = distribute by +sort by



































分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Hive编程指南_学习笔记01,hive编程指南

相关文章

  • Hadoop之——HDFS命令,hadoophdfs
  • 1006-HBase操作实战(JAVA API模式),1006-hbaseapi
  • Openstack中为虚拟机使用CDROM光驱设备,openstackcdrom
  • HDP出现Could not create the Java Virtual Machine解决方法,hdpvirtual
  • 最笨的方法解决 使用Snappy 压缩方式报错“java.lang.UnsatisfiedLinkError: no snappyjava in java.library.path”,java.library.path
  • hive join详解,hivejoin
  • 从Hadoop URL中读取数据,hadoopurl读取数据
  • Machine Learning On Spark——第一节:基础数据结构(一),learningspark
  • Neutron数据库同步错误 NotImplementedError: No support for ALTER of constraints in SQLite dialect,sqlitealtertable
  • [Hive]MapReduce将数据写入Hive分区表,mapreducehive

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • Binary Tree Preorder Traversal (leetcode 144),preorderleetcode
    • Ryu拓扑发现原理分析,Ryu拓扑原理分析
    • hadoop2.6.0伪分布式安装,hadoop2.6.0伪
    • 金典依旧,钱龙金典版
    • NOSQL(六)集群并发计算模型Map-Reduce,nosqlmap-reduce
    • hive schema详解,hiveschema
    • Hadoop之——数据类型,hadoop数据类型
    • zookeeper——分布式锁,zookeeper
    • Spark中配置Parquet参数,sparkparquet参数
    • [Sqoop]利用sqoop对mysql执行DML操作,sqoopdml

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有