Multiple Dimension Spreadのご紹介

>100 Views

November 19, 18

スライド概要

MDS(Multiple Dimension Spread)は、スキーマレスのカラム型ストレージフォーマットです。
JSONのような柔軟な表現と、他のカラム型ストレージフォーマットに似た効率的な読み込みを提供します。

OSSとして公開しています。
興味がある方は気軽にご連絡ください!

GitHub:
https://github.com/yahoojapan/multiple-dimension-spread

profile-image

2023年10月からSpeaker Deckに移行しました。最新情報はこちらをご覧ください。 https://speakerdeck.com/lycorptech_jp

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Multiple-DimensionSpread 2018年11月19日 ヤフー株式会社 井島 洸二 、大戸 康紀 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

2.

自己紹介 井島 洸二 ヤフー株式会社 データ&サイエンスソリューション統括本部 データプラットフォーム本部データデリバリー部 所属 大戸 康紀 ヤフー株式会社 データ&サイエンスソリューション統括本部 データプラットフォーム本部データデリバリー部 所属 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 2

3.

目次 1. 目的/背景 2. ゴール設定 3. 構成 4. チュートリアル 5. 開発状況 6. パフォーマンス 7. 今後の予定 8. まとめ Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 3

4.

目的/背景 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

5.

目的 Data Lake に最適な データフォーマットを提供 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

6.

Data Lake とは データを湖のように蓄えておく • • 保存時には使われ方(データ形式)を気にしない SQL/HQL でアクセス 利用時に考える 柔軟なデータ利用 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Data Lake 生データで保存

7.

データフォーマット (初期) 生データを保存、利用時に解釈 • • テキスト や JSON など SQL/HQL でアクセス Ex. Apache log 柔軟なデータ利用 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Data Lake 生データで保存

8.

問題 溢れるデータ データが級数的に増加 総務省 平成29年版 情報通信白書 データ流通量の爆発的増大 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. http://www.soumu.go.jp/johotsusintokei/whitepaper/ja/h29/html/nc121210.html

9.

問題 溢れるデータ 生データ保存では、 増え続けるデータに対抗できない SQL/HQL でアクセス Data Lake 生データで保存 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

10.

問題 溢れるデータ 増え続けるデータに対抗する • 効率の良いデータ圧縮 • 利用しやすいデータ形式 効率的なデータ保存、利用 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

11.

データフォーマット (現在) カラムナデータフォーマットで保存 • ORC, Parquet, Carbondata SQL/HQL でアクセス Data Lake カラムナデータフォーマットで保存 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

12.

カラムナ データフォーマット 列方向にデータを収集、圧縮する • 同種データによる圧縮率の向上 • 集計時にデータ全体を解凍しなくて良い • 生成時に データ形式/Schema が 必要 圧縮 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

13.

カラムナ データフォーマット 列方向にデータを収集、圧縮する 効率性 • 同種データによる圧縮率の向上 • 集計時にデータ全体を解凍しなくて良い • 生成時に データ形式/Schema が 必要 柔軟性 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 圧縮

14.

既存技術 事前に Schema の 設定が必要 Schema registry MR/TEZ Request Web/App API JSON message Spark カラムナー フォーマット ETL HDFS HIVE/Presto Server Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 14

15.

既存技術 まとめ 大量のデータを柔軟に処理したい • Data Lake 構想 • カラムナーフォーマットによる効率的な保存 • データ保存時の柔軟性が犠牲 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

16.

ゴール設定 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

17.

モチベーション 事象を自然なデータ構造で表現できる世界 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 17

18.

目指すところ 効率 Apache ORC Apache Parquet Apache Carbondata MDS 生データ JSON 柔軟性 効率と柔軟性の両立 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 18

19.

効率 • 処理で必要最小限の読み込み Col-1 Col-2 Col-3 Col-4 Col-5 Col-1 Col-2 Col-3 Col-4 Col-5 Network,Disk/IO Col-1 Col-4 Col-1 Col-4 Col-1 Col-4 Decompress/Copy InputStream Main Processing In-Memory Storage Volume Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 19

20.

柔軟性 • データ保存時に Schema 設定がいらない Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 20

21.

Other • Hadoop エコシステムに連携 • MR/TEZ • Spark • Hive/Presto … Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 21

22.

ユースケース Schema registry MR/TEZ Request Web/App API JSON message Spark MDS ETL HDFS HIVE/Presto Schema-less data pipeline Server Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 22

23.

構成 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

24.

言語 • Java Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

25.

前提 • 分散ストレージ上での蓄積と分散処理 フレームワークに対応にフォーカス Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 25

26.

ファイルレイアウト File File Header Block-1 Block Metadata MDS形式のファイルとして認識する ための情報や読み込みに必要な設定が 含まれる。 Spread-1 Spread-2 … Spread-X Block-2 Block Metadata Spread-1 Block-X ファイルは複数のブロックで構成され る。 ブロックはカラムの構成や統計情報を 保持するメタデータと複数の Spread で構成される。 Block Metadata Spread-1 … Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Spread は複数の Column で構成さ れる。 26

27.

Spread Root Spread は Root を持つ木構 造で表現される。 Root Spread Col Col Col Child Spread Col Col Col 単一の Spread は Column[] と同等の意味を持つ。 Child Spread Col Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Column は子を持つことがで きる。 そのノード以下は子 Spread として表現される。 Col 27

28.

Column String : encoding class name String : compress class name Root String : column name ColumnType : column type Int : row count Col Col Col Int : raw data size Int : logical data size Int : cardinality Int : binary start offset Int : binary length Byte[] : data Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 28

29.

File Header File File Header Magic BlockSize Class name length of BlockReader Byte[] 4byte Int 4byte Int 4byte Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Class name of BlockReader Char[] Xbyte 29

30.

Block Block-1 Block index Byte[] Xbyte Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Block Metadata Number of spread Int 4byte Spread row counts Metadata length Int[] Xbyte Int 4byte 30

31.

Spread Block-1 Spread-1 Spread-2 … Spread-X Spread metadata Byte[] Xbyte Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Spread data Byte[] Xbyte 31

32.

Write/Read ETL Message deserializer serializer Message object MDSRecordReader Spread Spread MDSReader MDSWriter IColumnBinaryMaker IColumnBinaryMaker IBlockReader IBlockMaker Byte[] Spread List<ColumnBinary> List<ColumnBinary> Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Processing Message object MDSRecordWriter Spread Message MDS File Byte[] 32

33.

Message のシリアライズ/デシリアライズ • 同時に開発したスキーマライブラリを利用 https://github.com/yahoojapan/dataplatform-schema-lib Avro JSON Etc… Reader AvroReader JsonReader Writer IParser AvroWriter JsonWriter Avro JSON Etc… 共通のインターフェースを通じてデータのアクセスと変換を提供 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 33

34.

入力データからデータ構造を構築 初期状態では何もデータ構造をもっ ていない、入力データに応じた構造 が構築される。 Col-3 { “col-3” : “val” } Col-1 Null { “col-1” : “val” , “col-5” : “val” } Col-5 入力データで新規に出現したキーが ある場合には、データ構造に追加さ れる。 Null Null { “col-2” : “val” , “col-4” : “val” , “col-5” : “val” } message Col-3 Col-1 Col-2 Null Null Null Null Col-3 Null Col-4 Col-5 Null Null Null これによりスキーマレスな書き込み を実現。 Null Spread Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 34

35.

カラム毎の独立したエンコーディング Col-1 Null Null Column Col-2 Null Null Column Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Col-1 IColumnBinaryMaker Encoder ICompressor Col-1 ColumnBinary Col-2 IColumnBinaryMaker Encoder ICompressor Col-2 ColumnBinary 35

36.

オプティマイザ Column Analyzer カラムを解析し統計情報を(rows, cardinality…)を取得する。 IColumnAnalizeResult MDSWriter IColumnAnalizeResult IOptimizer 統計情報に応じてエンコーディング 方式を選定する。 IColumnBinaryMaker Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 36

37.

高速なファイルのマージ deserializer MDS File Message object File Header MDSRecordWriter Block-1 Spread Block-2 MDSWriter IColumnBinaryMaker MDS File File Header Block-1 List<ColumnBinary> List<ColumnBinary> IBlockMaker ファイルのマージはメッセージ のデシリアライズ、カラムのエ ンコーディング/圧縮をスキッ プできる。 ボトルネックをディスク/ネッ トワークIOとする事により HDFS 上に数GB単位のファイ ルを作成する事が可能。 Block-2 Byte[] Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. MDS File 37

38.

Splitable MDS File Processing File Header 128MB Block-1 128MB Block-2 128MB Block-3 128MB Block-4 XMB Block-5 Processing Processing MDS はブロック単位で並列して処 理が可能。 ブロックサイズはファイルのオプ ションで設定できる。 デフォルトは128MBとなる。 Processing Processing Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 38

39.

Projection Pushdown MDS File 読み込むカラムを設定 File Header Block-1 Spread-1 Processing [ col2 , col5] Skip Read Col-1 Col-2 Skip Col-3 Col-4 List<ColumnBinary> [ col-2,col-3] MDSReader Spread Read Col-5 ストレージから必要なカラムのデータのみを読み込み Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 39

40.

Predicate Pushdown 入力に必要なデータの条件を設定 MDS File File Header Block-1 Skip Spread-1 Read Spread-2 Block-2 Skip Spread-1 List<ColumnBinary> MDSReader Spread-1 Spread-2 Spread Col-1 Spread-2 Block-3 Read Processing Col-1 < X and Col-3 = X Col-2 Col-3 Col-4 Col-5 Read Skip Read 確実にデータが含まれない行をスキップ 確実にデータが含まれない Block , Spread をスキップ Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 40

41.

Expand 展開したいArray要素のカラムを設定 Items (ARRAY) timestamp (BIGINT) total_price (BIGINT) 1516773762 1000 1516773765 200 Expand ‘items’ Items (Struct) item_id (STRING) price (BIGINT) number (INT) I_001 300 1 I_005 350 2 I_002 50 4 Spread Processing MDSReader Spread timestamp (BIGINT) total_price (BIGINT) 1516773762 Items (STRUCT) item_id (STRING) price (BIGINT) number (INT) 1000 I_001 300 1 1516773762 1000 I_005 350 2 1516773765 200 I_002 50 4 Expand Spread 指定されたカラムを展開した Spread を作成 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 41

42.

Flatten 平坦化したいカラムを設定 timestamp (BIGINT) total_price (BIGINT) 1516773762 Flatten items.item_id -> item_id items.price -> price items.number -> number Items (STRUCT) item_id (STRING) price (BIGINT) number (INT) 1000 I_001 300 1 1516773762 1000 I_005 350 2 1516773765 200 I_002 50 4 Spread MDSReader Processing Spread timestamp (BIGINT) total_price (BIGINT) item_id (STRING) price (BIGINT) number (INT) 1516773762 1000 I_001 300 1 1516773762 1000 I_005 350 2 1516773765 200 I_002 50 4 Flatten Spread 指定されたカラムを平坦化した Spread を作成 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 42

43.

Expand & Flatten Expand , Flatten を設定 Items (ARRAY) timestamp (BIGINT) total_price (BIGINT) 1516773762 1000 1516773765 200 Items (Struct) Processing Expand ‘items’ item_id (STRING) price (BIGINT) number (INT) I_001 300 1 I_005 350 2 I_002 50 4 Flatten items.item_id -> item_id items.price -> price items.number -> number MDSReader Spread timestamp (BIGINT) total_price (BIGINT) 1516773762 Spread Items (STRUCT) item_id (STRING) price (BIGINT) number (INT) timestamp (BIGINT) total_price (BIGINT) item_id (STRING) price (BIGINT) number (INT) 1000 I_001 300 1 1516773762 1000 I_001 300 1 1516773762 1000 I_005 350 2 1516773762 1000 I_005 350 2 1516773765 200 I_002 50 4 1516773765 200 I_002 50 4 Expand Spread Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Expand & Flatten Spread 43

44.

チュートリアル Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

45.

環境構築 $ git clone https://github.com/yahoojapan/multiple-dimension-spread.git $ cd multiple-dimension-spread/ $ mvn package $ bin/setup.sh Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

46.
[beta]
JSON メッセージの変換
$ bin/mds.sh create -i src/example/src/main/resources/sample_json.txt -f
json -o /tmp/sample.mds
$ bin/mds.sh cat -i /tmp/sample.mds -o '-' # show whole data
{"summary":{"total_price":550,"total_weight":412},"number":5,"price":110
,"name":"apple","class":"fruits"}
{"summary":{"total_price":800,"total_weight":600},"number":10,"price":80
,"name":"orange","class":"fruits"}

Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

47.
[beta]
Hive テーブルの作成
$ hive -i jars/mds/add_jar.hql
> create database test;
> use test;
> create external table sample_json (
summary struct<total_price: bigint, total_weight: bigint>,
number bigint,
price bigint,
name string,
class string
)
ROW FORMAT SERDE 'jp.co.yahoo.dataplatform.mds.hadoop.hive.MDSSerde‘
STORED AS INPUTFORMAT 'jp.co.yahoo.dataplatform.mds.hadoop.hive.io.MDSHiveLineInputFormat‘
OUTPUTFORMAT 'jp.co.yahoo.dataplatform.mds.hadoop.hive.io.MDSHiveParserOutputFormat‘
LOCATION '/tmp/ss';
> select * from sample_json;
{"total_price":550,"total_weight":412} 5 110 apple fruits
{"total_price":800,"total_weight":600} 10 80 orange fruits

Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

47

48.

開発状況 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

49.

機能 機能 Row Store Compress Data type specific Change by column base Format Splittable Vectorization Pushdown Projection Predication Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. MDS ORC Text, JSON, ORC, Avro Text, Sequence, Avro ○ ○ ○ ☓ GZIP,LZ4,ZSTD ZLIB, SNAPPY, LZO ○ ○ ○ ○ ○ ○ ○ ○

50.

データ型 基本型 Boolean Byte Bytes Short Integer Long Float Double String Null 説明 true/false 8ビット整数 バイト列 16ビット整数 32ビット整数 64ビット整数 32ビット単精度浮動小数点数 64ビット倍精度浮動小数点数 文字列 欠損データ Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 複合型 Array Map Struct Union 説明 配列 マップ 構造体 共用体(異なる型を保持)

51.

MDSの対応エコシステム エコシステム Hive Spark Presto Drill Impala Arrow 対応 ○ △※1 △※1 ☓ ☓ ○ URL hive.apache.org spark.apache.org prestodb.io drill.apache.org impala.apache.org arrow.apache.org ※1:本資料公開時にはOSSには公開していません Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

52.

パフォーマンス Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

53.

TPC-H 1000 TPC-H スケール1000(GB)で比較 MDS,Apache ORC,Apache parquet で比較 圧縮フォーマットは全てGZIP 各データは Hive で変換を実施 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 53

54.

バージョン Hive:1.2.1 Spark:2.2.0 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 54

55.

TPC-H 1000 - データサイズ データサイズ(GB) 300 250 200 Law is better 150 100 50 0 MDS Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Apache ORC Apache parquet 55

56.

TPC-H 1000 - テーブル別のサイズ テーブル別データサイズ(GB) 180 160 140 120 100 Law is better 80 60 40 20 0 region nation supplier part MDS Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. Apache ORC customer partsupp orders lineitem Apache parquet 56

57.

TPC-H 1000 - Hive CPU TIME(SEC) 100000 90000 80000 70000 60000 50000 Law is better 40000 30000 20000 10000 0 q6 q16 q14 q1 q15 q11 q22 q2 q12 MDS q20 Apache ORC ※テーブルスキャンオペレーション(Map)のみ計測 ※q19:いずれも実行に時間がかかりすぎたため計測を断念 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. q13 q10 q4 q3 q7 q8 q5 q9 q17 q18 q21 Apache parquet 57

58.

TPC-H 1000 - Spark Executor CPU TIME(SEC) 80000 70000 60000 50000 40000 Law is better 30000 20000 10000 0 q6 q14 q12 q1 q10 q13 q3 MDS Apache ORC q20 q8 q7 q9 q4 q17 Apache parquet ※q2,11,15,18,21,22:テーブル作成の HQL を書き換えなければいけないため断念 ※q16,19:いずれも実行に時間がかかりすぎたため計測を断念 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. q5 58

59.

Expand&Flatten 社内で利用しているArrayを使って状態を表しているログを利用 元のデータ構造のまま SQL で展開して処理する場合と、利用する フィールドだけフラットにして単純な SQL を実行した場合の速度 を比較する Items (ARRAY) timestamp (BIGINT) MDS File Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. total_price (BIGINT) Items (Struct) item_id (STRING) price (BIGINT) number (INT) I_001 300 1 I_005 350 2 151677376 2 1000 timestamp (BIGINT) total_price (BIGINT) item_id (STRING) price (BIGINT) number (INT) 1516773762 1000 I_001 300 1 1516773762 1000 I_005 350 2 Array 展開のSQL SQL ※図は処理のイメージであり実際に利用されているログではありません。 59

60.

Expand&Flatten - Hive CPU TIME(SEC) 160000 140000 120000 90% down 100000 80000 60000 40000 20000 0 not flatten Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. flatten 60

61.

今後の予定 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved.

62.

今後の提供機能 各フレームワークの型に対応 Sparkに対応したコードをOSS公開 型の拡張(Date,Timestamp…etc) Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 62

63.

パフォーマンス ベンチマークの整備 Write処理の効率化 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 63

64.

OSS 活動について コントリビューター募集 利用者・導入事例を増やす取り組み ドキュメントや運営周りの整備 イベントでの宣伝 Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 64

65.

まとめ Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 65

66.

MDS とは 事象を自然なデータ構造で表現できる世界 を実現する 大量のデータを柔軟に効率よく扱うための フォーマット Copyright (C) 2018 Yahoo Japan Corporation. All Rights Reserved. 66