Spark ORC文件

2019-11-03  本文已影响0人  lj72808up

一. ORC文件的格式

1. 什么是orc文件

2. 格式

3. orc中的统计信息, 助力提升where条件查询

orc文件包含统计信息, 比如字段的min, max, count, 是否有空值等信息. 在执行sql语句时助力谓词下推. 比如: min,max助力"<或>"条件. 当进行查询的时候, 如果发现满足查询条件的行并不在统计信息之内, 则可以跳过这个strip, 甚至整个文件.ORC中的统计信息分为3个层次:

4. orc文件数据访问方法

5. 使用布隆过滤器加快strip中的index选择

前面提到, strip里的统计信息(min,max)可以助力where语句中, 关于"<或>"条件的检索, 避免把不满足条件的strip读入到内存. 那么如果where语句中是"="条件的呢? 这是可以通过让strip对某些列进行布隆过滤器.

6. hive使用orc文件存储时的高级参数

paramorc.png
create table if not exists ${distTable}(
    featureindex string,
    t1_primarykey string, 
    t1_clusterid string, 
    t1_xid string, 
    d1 map<string,string>, 
    t1_id string, 
    t1_zid string, 
    features string, 
    t2_primarykey string, 
    t2_clusterid string, 
    t2_xid string, 
    d2 map<string,string>, 
    t2_id string, 
    t2_zid string, 
    status string
)
partitioned by (save_time string)
STORED AS ORC
tblproperties ("orc.compress"="ZLIB")

二. Spark读取ORC文件的方式

spark读取orc有3种不同方式, 不同方式的主要区别在于对文件划分split的方式不同(一般不需要修改)
原文描述: The HYBRID mode reads the footers for all files if there are fewer files than expected mapper count, switching over to generating 1 split per file if the average file sizes are smaller than the default HDFS blocksize. ETL strategy always reads the ORC footers before generating splits, while the BI strategy generates per-file splits fast without reading any data from HDFS.

val sparkSession = SparkSession
  .builder()
  .appName("PvMvToBase")
  .config("hive.exec.orc.default.stripe.size", 268435456L)
  .config("hive.exec.orc.split.strategy", "BI")  // 可以设置成以BI策略读取orc文件, 减小
  .enableHiveSupport()
  .getOrCreate()

如果发生spark任务迟迟无法生成UI界面, 很可能是load orc表数据时, 计算split的时间太长; 此时是driver节点在读取每个文件的footer进行split划分计算, 可以通过将策略设置成BI模式, 跳过计算split的步骤

三. Spark-ORC日常操作

1. orc+zlib 和 orc+snappy的对比

ORC+Zlib after the columnar improvements no longer has the historic weaknesses of Zlib, so it is faster than SNAPPY to read, smaller than SNAPPY on disk and only ~10% slower than SNAPPY to write it out.

2. 查看生成的orc文件

$ hdfs fsck hdfs://yq01-ns1/user/hive/warehouse/tmp.db/table1_hive/001319_0 -files -blocks
spark-orc-block.png
$ hive --orcfiledump hdfs://yq01-ns1/user/hive/warehouse/tmp.db/table1_hive/001319_0 | less
spark-orc-stripe.png

四. 控制Spark输出文件的个数

上一篇 下一篇

猜你喜欢

热点阅读