存储类型(rcfile textfile parquet)
在hive中索引 一般基于key 建立另一套存储机制,索引的存储可以与原有的存储格式不一样。建立索引一般都有分区,用空间换时间
ratings(userid)注意此处指定列名:
hive> create index index_ratings on table ratings(userid) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild;
//查看索引信息
hive> show index on ratings;
//查看索引发现是空的
hive> dfs -ls /bigdata/hive/warehouse/hivestudy.db/hivestudy__ratings_index_ratings__;
一般都要进行下面的alter,注意rebuild小写
ALTER INDEX index_ratings on ratings rebuild;
上面的方法不推荐,一般都在分区上建立索引
假如在创建索引是我们使用“ WITH DEFERRED REBUILD”语句,则索引创建是为空,可以通过“Alter index ... rebuild”在一个partition上或所有partition上构建索引。
CREATE INDEX index_ratings ON TABLE users(userid) AS 'org.apache.hadoop.hive.sql.index.compact.CompactIndexHandler' WITH DEFERRED REBUILD;
上面的方法创建的索引看不到所以的数据;
一般都要进行下面的alter,注意rebuild小写
ALTER INDEX index_users on users rebuild;
第一列:userid(我们是给予userid建立的) 第二列:数据在什么地方 第三列:partition
创建存储格式为rcfile的表
hive> create table table_rc(userid INT,name String,salary Double,address String,gender String) row format delimited fields terminated by '\t' lines terminated by '\n' stored as rcfile;
//注意执行load data local 会报错
hive> load data local inpath '/bigdata/learn_data/testHiveDriver.txt' into table table_rc;
Loading data to table default.table_rc
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
用insert插入
hive> insert into table_rc select * from employeeforhaving;
桶表
大表一般用 桶表,提高大表的查询效率
桶表一般设置:hive.enforce.bucketing=true; 会有很多目录,可以认为每个目录就是一个桶,进行分门别类。
两张全表join操作用桶表
数据存储格式:
rcfile 能直接读进来一个数据进行rcfile吗???
不能必须先加载到表里然后导入;