Hive Partitioned & Index

来源:互联网 发布:linux grub引导修复 编辑:程序博客网 时间:2024/05/22 16:53
 

hive特性:

数据存储在hdfs上,依托hadoop集群实现并行计算,采用hiveQL作为查询语言,与SQL极其相似,Hive中存储的数据无固定格式要求,可随用户自定义可追加数据,但不支持更改,可扩展性强,支持大规模并行计算。

Create table xxxData(VStart string,VEnd string......)
partitioned by (PID int,Daytime string)
row format delimited fields terminated by '\t' stored as textfile;

加载数据: LOAD DATA LOCAL INPATH ‘../data/test.txt’ OVERWRITE INTO TABLE myTable PARTITION (ds=’2011-11-12′);

查询时有可能遇到以下问题:错误信息如下:
FAILED: Hive Internal Error: java.lang.RuntimeException(Error while making MR scratch directory - check filesystem config (null))
java.lang.RuntimeException: Error while making MR scratch directory - check filesystem config (null)
    at org.apache.hadoop.hive.ql.Context.getMRScratchDir(Context.java:196)
    at org.apache.hadoop.hive.ql.Context.getMRTmpFileURI(Context.java:247)

..........................

解决办法:

HIVE的安装只依赖于$HADOOP_HOME是否正确,解决hive查询错误的办法是,将hdfs://ip 改为hdfs://domain,  并在/etc/hostname中正确配置domain的解析

<property>
    <name>fs.default.name</name>
    <value>hdfs://domain:9060/ </value>
    <description>The name of the default file system.  A URI whose
    scheme and authority determine the FileSystem implementation.  The
    uri's scheme determines the config property (fs.SCHEME.impl) naming
    the FileSystem implementation class.  The uri's authority is used to
    determine the host, port, etc. for a filesystem.</description>
</property>

 

 ===============================================

Hive 数据导出

很多时候,我们在hive中执行select语句,希望将最终的结果保存到本地文件或者保存到hdfs系统中或者保存到一个新的表中,hive提供了方便的关键词,来实现上面所述的功能。

1.将select的结果放到一个的的表格中(首先要用create table创建新的表格)

 insert overwrite table test

 select uid,name from test2;

2.将select的结果放到本地文件系统中

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/reg_3' SELECT a.* FROM events a;

3.将select的结果放到hdfs文件系统中

INSERT OVERWRITE DIRECTORY '/tmp/hdfs_out' SELECT a.* FROM invites a WHERE a.ds='<DATE>';

 

 ================================================

启动Hive Thrift Server 

Java代码  收藏代码
  1. hive --service hiveserver  



默认使用10000端口,也可以使用HIVE_PORT来指定端口 

Java代码  收藏代码
  1. root@master:/data/soft/hive/bin# ./hive --service hiveserver --help  
  2. usage HIVE_PORT=xxxx ./hive --service hiveserver  
  3.   HIVE_PORT : Specify the server port  



6)启动hwi 

Java代码  收藏代码
  1. bin/hive --service hwi  


取消日志的方式 

Java代码  收藏代码
  1. nohup bin/hive --service hwi > /dev/null 2> /dev/null &  


 

原创粉丝点击