oushudb 中 orc 格式的使用

目录

1 介绍

2 建表语法

2.1 Native ORC

2.2 External ORC

3 与 HIVE 数据类型的转换

4 关于Update/Delete 的并行

5 ORC 相关工具

6 实践中的使用限制


1 介绍

ORC(Optimized RC File)表是一种行列混合存储。用户可以通过内表/外表的形式创建ORC格式的表。在OushuDB中,其查询性能相比Parquet 更有优势。从 4.5.0.0 版本开始,默认建表格式改为 ORC,带 LZ4 压缩。

2 建表语法

2.1 Native ORC

CREATE [TEMPORARY | TEMP] TABLE <table_name> (
  [ { <column_name> <data_type> [ DEFAULT <default_expr> ]
      [ <column_constraint> [ ... ] ]
      | <table_constraint>
      | LIKE <other_table> [ { INCLUDING | EXCLUDING }
                             { DEFAULTS | CONSTRAINTS } ] ... } ]
  [, ... ] ]
)
[ INHERITS ( parent_table [, ... ] ) ]
[ WITH ( <storage_parameter> [, ... ] )
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE <tablespace> ]
[ DISTRIBUTED BY (<column>, [ ... ] ) | DISTRIBUTED RANDOMLY ]
[ PARTITION BY <partition_type> (<column>)
  [ SUBPARTITION BY <partition_type> (<column>) ]
  [ SUBPARTITION TEMPLATE ( <template_spec> ) ]
  [...]
  ( <partition_spec> )
​
where <column_constraint> is:
​
  [ CONSTRAINT <constraint_name> ]
  NOT NULL | NULL | CHECK ( <expression> )
   
and <table_constraint> is:
​
  [ CONSTRAINT <constraint_name> ]
  | CHECK ( <expression> )
   
and <storage_parameter> is:
​
  APPENDONLY = {TRUE}
  ORIENTATION = {ORC}
  COMPRESSTYPE = {LZ4|ZSTD|ZLIB|SNAPPY|NONE}
  OIDS = {FALSE}
  DICTHRESHOLD = [0-1]
  BLOOMFILTER = '<column_names>'
​
and <partition_specification> is:
​
    <partition_element> [, ...]
​
and <partition_element> is:
​
  DEFAULT PARTITION <name>
  | [ PARTITION <name> ] VALUES ( <list_value> [,...] )
  | [ PARTITION <name> ]
    START ( [<datatype>] '<start_value>' ) [ INCLUSIVE | EXCLUSIVE ]
    [ END ( [<datatype>] '<end_value>' ) [ INCLUSIVE | EXCLUSIVE ] ]
    [ EVERY ( [<datatype>] [<number> | INTERVAL] '<interval_value>' ) ]
  | [ PARTITION <name> ]
    END ( [<datatype>] '<end_value>') [ INCLUSIVE | EXCLUSIVE ]
    [ EVERY ( [ <datatype> ] [ <number> | INTERVAL] '<interval_value>' ) ]
  [ WITH ( <partition_storage_parameter> [, ... ] ) ]
  [ TABLESPACE <tablespace> ]

说明:

  1. 不支持 primary key

  2. 不支持指定 column 级别的存储选项(比如 compresstype),不支持 blocksize, compresslevel, fillfactor 存储选项,不支持 gzip 压缩

  3. 支持的数据类型:bool, int2, int4, int8, float4, float8, char, text, varchar, char(), varchar(), date, time, timestamp, timestamptz, numeric, UDT

  4. decimal 缺省的精度为 decimal(10, 0)

  5. 支持的压缩类型:lz4, zstd, zlib, snappy

  6. ORC 中字符串可以使用 dictionary encoding 压缩存储空间,如果 distinct-count / non-null-count > DICTHRESHOLD,就会自动关闭这一功能。实践中推荐 DICTHRESHOLD=0.8,压缩格式使用 lz4

  7. bloom filter主要用于提升相关列的查找性能,默认为空

  8. 默认的建表选项为 {appendonly=true,orientation=orc,compresstype=lz4}

2.2 External ORC

CREATE READABLE EXTERNAL TABLE <table_name>
( <column_name> <data_type> [, ...] | LIKE <other_table> )
LOCATION ('gpfdist://<filehost>[:<port>]/<file_pattern>[#<transform>]' [, ...])
  | ('gpfdists://<filehost>[:<port>]/<file_pattern>[#<transform>]' [, ...])
  | ('hdfs://<host>[:<port>]/<path-to-data-directory>' [, ...])
  | ('hive://<host>[:<port>]/<hive-db-name>/<hive-table-name>' [, ...])
  | ('s3://S3_endpoint[:port]/bucket_name/[S3_prefix] [config=config_file_location]')
FORMAT 'ORC'
[ ENCODING '<encoding>' ]
[ [ LOG ERRORS INTO <error_table>] SEGMENT REJECT LIMIT <count> [ ROWS | PERCENT ] ]
     
​
CREATE [WRITABLE] EXTERNAL TABLE <table_name>
( <column_name> <data_type> [, ...] | LIKE <other_table> )
LOCATION ('gpfdist://<filehost>[:<port>]/<file_pattern>[#<transform>]' [, ...])
  | ('gpfdists://<filehost>[:<port>]/<file_pattern>[#<transform>]' [, ...])
  | ('hdfs://<host>[:<port>]/<path-to-data-directory>' [, ...])
  | ('hive://<host>[:<port>]/<hive-db-name>/<hive-table-name>' [, ...])
  | ('s3://S3_endpoint[:port]/bucket_name/[S3_prefix] [config=config_file_location]')
FORMAT 'ORC'
[ ( [COMPRESSTYPE = 'NONE' | 'SNAPPY' | 'LZ4' | 'ZSTD' | 'ZLIB' ]
  [DICTHRESHOLD [0-1]]
  [BLOOMFILTER 'column_names'] ) ]
[ ENCODING '<encoding>' ]
[ [ LOG ERRORS INTO <error_table>] SEGMENT REJECT LIMIT <count> [ ROWS | PERCENT ] ]
[ DISTRIBUTED RANDOMLY ]

说明:

  1. 与 Native ORC 所有限制相同

  2. encoding 目前只支持 utf-8

  3. 额外不支持 constraint,不支持 inherit

  4. 不支持 update/delete 操作

  5. 不支持 partition,不支持 distributed by column

3 与 HIVE 数据类型的转换

ORC中支持的类型与HIVE数据类型,基本上名称一一对应。

OushuDB-TypeHive-Type
booltinyint
int2smallint
int4int
int8bigint
float4float
float8double
textstring

4 关于Update/Delete 的并行

目前 native orc update/delete 的上锁级别为 ExclusiveLock,会阻塞除 AccessShareLock 外的所有锁级别。

简单理解就是:对于同一个表,update/delete 只能串行执行,只能与普通 select 并行,会阻塞其他所有操作。

实践中,推荐用于 update/delete 数据比例较高的场景,不适合用于小批量数据的更新。

5 ORC 相关工具

  1. orc-contents: 以 json 格式显示 orc 文件里的内容,可以使用 columns 参数来显示特定列

% orc-contents  [--columns=0,1,...] <filename>
  1. orc-metadata: 以 json 格式显示 orc 文件的元数据,可以使用 -v 获取更多信息

% orc-metadata [-v] [--raw] <filename>
  1. orc-statistics: 显示文件级别和 stripe 级别的列统计信息

% orc-statistics [--withIndex] <filename>

6 实践中的使用限制

  1. 不适合single row insert或者小批量数据频繁插入/更新

  2. decimal默认精度建表,新执行器运算过程中可能会精度溢出报错

  3. decimal默认精度建表,写出来的orc文件和社区不兼容,开源社区引擎读取会丢失精度,被截断成整型

  4. 不支持以下datatype:bit, varbit, box, cidr, circle, inet, interval, lseg, macaddr, money, path, point, polygon, timetz, array, json, xml

  5. 不支持madlib,需要把默认建表改回row表: set default_create_table_opt_with = "appendonly=true, orientation=row"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值