schema设计
hive pattern && hive anti-pattern
1.Table by day 按照天分割数据,在relation中,这个参数不推荐,在hive中使用
create table supply(id int,part string,quantity int) partitioned by (int day)
alter table supply add partition (day=20120102)
partition的负面影响:
1.namenode limition
但是partition产生的子目录,子文件都会保存在hdfs中,namenode会存在内存中,所以这得负面效果是namenode的filesystem的容量上限(hadoop has this upper limit on the total number of file,mapr and amazon s3 don't have this limitation)
2.一个job分解成几个task,每个task是一个jvm实例,每一个file对应一个独立的task,每个task是jvm中独立的一个实例(进程),过多的实例会给jvm压力(start up and tear down),这使得计算速度降低
因此不能有太多partition,每个文件要尽可能的大
一个好的table by day的设计,是设计出相似大小的数据在不同的时间间断,时间间断可以适当增大。同时保证每个file大于filesystem block size。目的是让partition足够的大。另一种方法,是用多维度的partition分解数据。
2.unique keys and normalization 主键,格式化数据
关系数据库最爱用地策略,但是在hive中没有这种概念。因为hive可以存储denormalized data非格式化的数据,如array,map,struct。这样可以避免one-to-many的关联关系,加快了io速度。但是也pay the penalty of denormalization,比如数据复制,数据不一致的概率
3.making multiple passes over the same data 同数据源的操作优化
insert overwrite table sales
select * from history where action='purchased';
insert overwrite table credits
select * from history where action='returned';
from history
insert overwrite sales select * where action='purchased'
insert overwrite credits select * where action = 'returned'
4.the case for partitioning every table
为了避免job fail而使得数据被删除,在insert数据的时候可以使用table pardae table1 partition(day=20120102).但是需要删除这个中间换转者partition
5.bucketing table data storage
当table没有明显的partition特征时,或是减轻filesystem的负担,可以使用bucketing,他的优点是不会随着增加数据使得文件个数变动,而且对于取样sample是很容易的,对于一些joins操作也比较便利。
create table weblog(user_id int,url string,source_ip string) partition by (dt string) clustered by (user_id) into 96 buckets;
为了生成正确个数的reducer对应hash出得bucket
在查询的时候设置 set hive.enforce.bucketing=true;
from raw_logs或是设置reduce数直接等于bucket数set mapred.reduce.tasks=96
insert overwrite table weblog partition(dt='2009-02-25') select user_id,url,source_ip where dt='2009-02-25'
6.adding colums to a table
hive是没有格式化的数据仓库,随着数据需求可以增加一列,数据少于期待列数,则填补null,数据多于,则舍弃。
create table weblogs(version long,url string) partitioned by (hit_data int) row format delimited fields terminated by '\t'
加载数据,可以用int补上缺少的数据
load data local inpath 'log1.txt' int weblogs partition(20110101)
7.(almost)always use compression
相关推荐
第8章 MapReduce的特性 计数器 内置计数器 用户定义的Java计数器 用户定义的Streaming计数器 排序 准备 部分排序 总排序 二次排序 联接 map端联接 reduce端联接 边数据分布 利用JobConf...
第8章 MapReduce的特性 计数器 内置计数器 用户定义的Java计数器 用户定义的Streaming计数器 排序 准备 部分排序 总排序 二次排序 联接 map端联接 reduce端联接 边数据分布 利用JobConf来配置作业 分布式缓存 ...
第8章 数据索引与排序 127 8.1 数据库索引的基本概念 127 8.2 MongoDB的索引与排序 128 8.3 MongoDB里创建和使用索引 131 8.3.1 组合与嵌套键 136 8.3.2 创建唯一索引和稀疏索引 138 8.3.3 基于关键字的搜索和...
useUnicode=true&characterEncoding=utf8` - 若切换到SQL Server数据库,则设置 `jdbc.url=jdbc:sqlserver://localhost:1433;databaseName=jeecgdb` - 第二步,定位到 `jeecg_database.properties` 文件,并修改...
Hadoop definitive 第三版, 目录如下 1. Meet Hadoop . . . 1 Data! 1 Data Storage and Analysis 3 Comparison with Other Systems 4 RDBMS 4 Grid Computing 6 Volunteer Computing 8 A Brief History of Hadoop 9...
5. **从Hive表**:如果已配置了Hive支持,SparkSQL可以透明地访问Hive的表和分区,使用`sql("SELECT * FROM table")`即可。 6. **从数据库**:SparkSQL可以通过JDBC连接到各种关系型数据库,使用`spark.read.jdbc()...