Parquetファイル用のコマンドラインツール「parquet-tools」のインストール手順(on Mac OSX)と使い方

2020.08.11

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

書籍『AWSで始めるデータレイク』を使った読書会を現在部内で開催しているのは以前書評エントリを公開した際にも言及しましたが、読書会自体1回1時間枠でここまで計6回実践してきて進んだのが第1章の終わりまで...という状況です。記録的には『めっちゃ進み遅いw』というところですが、これはむしろ『語りたい部分が多く、また予想以上に盛り上がっているために中々トピックを消化しきれていない』というのが実情です。モヤモヤしていた部分が解消されたり、新たな視点や知見が共有される事が多く、催しとしても非常に意義のあるものになっています。

先日も『Parquetファイルの内容を確認する際、皆さんどういったツールとかを使っていますか?』という問い掛けに対し、有識者から『parquet-toolsという便利なツールがある』という紹介がありました。非常に便利なツールでしたので当エントリにて導入方法と簡単な使い方について紹介したいと思います。

目次

 

parquet-toolsとは

Parquetは、オープンソースの列指向のデータストレージ形式です。公式サイトは以下。

Parquetは以下の特徴を備えています。データレイク環境で扱うファイル形式としても良く利用されるものの1つです。

  • CSVなどの行ベースのファイルと比較して、データを効率的に列に格納するように設計されている
  • 複雑なネストされたデータ構造を念頭に置いてゼロから構築されている
  • 効率的な圧縮とエンコーディングをサポートするように構築されている
  • Amazon Athena、Amazon Redshift Spectrum、Google Dataprocなどのサーバーレステクノロジーを使用して、データストレージコストを削減し、データのクエリの効果を最大化できる

parquet-toolsは、そんなParquetファイルに対してCLI形式で内容を確認出来るツールとなっています。

 

インストール

ではインストールから始めてみます。幾つか方法がある模様ですが、ここではMac環境にHomebrewを使ってインストールする方法で進めます。

インストールする環境の情報は以下。Homebrewが利用出来るような環境を予め整えておいてください。

% sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.3
BuildVersion:	19D76

% brew --version
Homebrew 2.4.10
Homebrew/homebrew-core (git revision 57ade; last commit 2020-08-10)
Homebrew/homebrew-cask (git revision 2edc8; last commit 2020-08-11)

Homebrewが導入済みであれば、インストールはとても簡単です。まず下記Rubyコマンドを実行し、

% ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Password:
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 60fa2ead4 Merge pull request #8280 from dtrodrigues/pypi-blocklist
Updated 2 taps (homebrew/core and homebrew/cask).
:
==> Deleted Casks
daily-english-listening                  webponize
pprows                                   yourkit-java-profiler
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh
%

次いでbrewコマンドでparquet-toolsをインストール(parquet-tools)するだけです。

% brew install parquet-tools
==> Downloading https://homebrew.bintray.com/bottles/parquet-tools-1.10.0.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/663df850056a24973c7a164823fe859efdd8b1b84bc5b622f12f2922bcad5eb8?response-content-disposition=attachment%3Bfilename%3D%22
######################################################################## 100.0%
==> Pouring parquet-tools-1.10.0.catalina.bottle.tar.gz
?  /usr/local/Cellar/parquet-tools/1.10.0: 8 files, 41.3MB
%

 

parquet-toolsコマンド実践

ここからは実際にどういうコマンドが使えるのかを試してみます。コマンドの一覧とその使い方についてはparquet-tools --helpでその内容を確認可能です。

% parquet-tools --help

扱うファイルについては、以下の形でAmazon Redshiftに格納しているブログ投稿データをParquetにUNLOADしたものを手元にダウンロードして確認したいと思います。

# UNLOAD ('SELECT * FROM cmdevio.t_blogposts ORDER BY post_date DESC')
TO 's3://xxxxxxxxxxxxxxxxxxx/parquet-export/t_blogposts'
CREDENTIALS 'aws_iam_role=arn:aws:iam::999999999999:role/xxxxxxxxxxxxxxx-role'
# PARQUET;
INFO:  UNLOAD completed, 23054 record(s) unloaded successfully.
UNLOAD
% pwd
/xxxxxxxxxx/xxxxxxxxxxxx/Desktop/parquet-export
% ll
total 4848
-rw-r--r--@ 1 xxxxxxxxxx  staff  618531  8 11 xx:xx t_blogposts0003_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff  615366  8 11 xx:xx t_blogposts0002_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff  618667  8 11 xx:xx t_blogposts0001_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff  617042  8 11 xx:xx t_blogposts0000_part_00.parquet

 

parquet-tools cat
(Paqrquetファイルの内容を出力)

Parquetファイルの内容を出力します。出力にはデータのみが含まれ、メタデータが表示される形となります。

parquet-tools cat:
Prints the content of a Parquet file. The output contains only the data, no
metadata is displayed
usage: parquet-tools cat [option...] <input>
where option is one of:
       --debug     Enable debug output
    -h,--help      Show this help string
    -j,--json      Show records in JSON format.
       --no-color  Disable color output even if supported
where <input> is the parquet file to print to stdout

実行結果:

% parquet-tools cat t_blogposts0000_part_00.parquet 
post_id = 611870
post_date = AOyP47sCAADBhSUA
title = SysOps アドミニストレーター – アソシエイト(SOA)に合格したので勉強法をまとめてみた
url = https://dev.classmethod.jp/articles/soa-exam-passed-report/
author_id = hashimoto-yuki
social = 0
twitter = 0
facebook = 0
hatena = 0
view = 3

post_id = 611669
post_date = AED6+D4uAADAhSUA
title = Amazon GuardDuty 입문부터 실전까지 바로 적용해봅시다
url = https://dev.classmethod.jp/articles/amazon-guardduty-explained-korean/
author_id = kim-taewoo
social = 24
twitter = 2
facebook = 21
hatena = 1
view = 9

post_id = 609145
post_date = AIiNE6s/AAC/hSUA
title = [AWS 입문] AWS CLI 에서 S3 + CloudFront 로 Vue.js 웹페이지 배포하기
url = https://dev.classmethod.jp/articles/aws-cli-s3-cloudfront-kr/
author_id = jung-haeun
social = 49
twitter = 6
facebook = 42
hatena = 1
view = 27

post_id = 611310
post_date = AOjqTVZHAAC9hSUA
title = AWS Elemental Linkのサムネイル画像をAWS CLI経由で取得してみた
url = https://dev.classmethod.jp/articles/aws-elemental-link-aws-medialive-describe-input-device-thumbnail/
author_id = shimizu-toshiya
social = 9
twitter = 6
facebook = 2
hatena = 1
view = 216

post_id = 611205
post_date = AATsf3k5AAC9hSUA
title = AWS Elemental Linkが東京リージョンで使えるようになりました!
url = https://dev.classmethod.jp/articles/aws-elemental-link-is-now-available-in-tokyo/
author_id = shimizu-toshiya
social = 36
twitter = 6
facebook = 29
hatena = 1
view = 1193
:
:
:
(以降、対象全件を表示)

 

parquet-tools head
(Parquetファイルの先頭N件のレコード内容を出力)

Parquetファイルの先頭N件のレコード内容を出力します。

parquet-tools head:
Prints the first n record of the Parquet file
usage: parquet-tools head [option...] <input>
where option is one of:
       --debug          Enable debug output
    -h,--help           Show this help string
    -n,--records <arg>  The number of records to show (default: 5)
       --no-color       Disable color output even if supported
where <input> is the parquet file to print to stdout

実行結果:

% parquet-tools head --records 3 t_blogposts0000_part_00.parquet
post_id = 611870
post_date = AOyP47sCAADBhSUA
title = SysOps アドミニストレーター – アソシエイト(SOA)に合格したので勉強法をまとめてみた
url = https://dev.classmethod.jp/articles/soa-exam-passed-report/
author_id = hashimoto-yuki
social = 0
twitter = 0
facebook = 0
hatena = 0
view = 3

post_id = 611669
post_date = AED6+D4uAADAhSUA
title = Amazon GuardDuty 입문부터 실전까지 바로 적용해봅시다
url = https://dev.classmethod.jp/articles/amazon-guardduty-explained-korean/
author_id = kim-taewoo
social = 24
twitter = 2
facebook = 21
hatena = 1
view = 9

post_id = 609145
post_date = AIiNE6s/AAC/hSUA
title = [AWS 입문] AWS CLI 에서 S3 + CloudFront 로 Vue.js 웹페이지 배포하기
url = https://dev.classmethod.jp/articles/aws-cli-s3-cloudfront-kr/
author_id = jung-haeun
social = 49
twitter = 6
facebook = 42
hatena = 1
view = 27

 

parquet-tools schema
(Parquetファイルのスキーマ情報を出力)

Parquetファイルのスキーマ情報を出力します。

parquet-tools schema:
Prints the schema of Parquet file(s)
usage: parquet-tools schema [option...] <input>
where option is one of:
    -d,--detailed  Show detailed information about the schema.
       --debug     Enable debug output
    -h,--help      Show this help string
       --no-color  Disable color output even if supported
where <input> is the parquet file containing the schema to show

実行結果:

% parquet-tools schema --detailed t_blogposts0000_part_00.parquet
message schema {
  optional int32 post_id (INT_32);
  optional int96 post_date;
  optional binary title (UTF8);
  optional binary url (UTF8);
  optional binary author_id (UTF8);
  optional int32 social (INT_32);
  optional int32 twitter (INT_32);
  optional int32 facebook (INT_32);
  optional int32 hatena (INT_32);
  optional int32 view (INT_32);
}

creator: Amazon Redshift

file schema: schema
--------------------------------------------------------------------------------
post_id: OPTIONAL INT32 O:INT_32 R:0 D:1
post_date: OPTIONAL INT96 R:0 D:1
title: OPTIONAL BINARY O:UTF8 R:0 D:1
url: OPTIONAL BINARY O:UTF8 R:0 D:1
author_id: OPTIONAL BINARY O:UTF8 R:0 D:1
social: OPTIONAL INT32 O:INT_32 R:0 D:1
twitter: OPTIONAL INT32 O:INT_32 R:0 D:1
facebook: OPTIONAL INT32 O:INT_32 R:0 D:1
hatena: OPTIONAL INT32 O:INT_32 R:0 D:1
view: OPTIONAL INT32 O:INT_32 R:0 D:1

row group 1: RC:5764 TS:614504 OFFSET:4
--------------------------------------------------------------------------------
post_id:  INT32 SNAPPY DO:4 FPO:23085 SZ:32517/32506/1.00 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 23, max: 611870, num_nulls: 0]
post_date:  INT96 SNAPPY DO:32592 FPO:84750 SZ:61580/78568/1.28 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[no stats for this column]
title:  BINARY SNAPPY DO:94219 FPO:405599 SZ:321032/539340/1.68 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min:[お知らせ]「クラウド分解辞典−Amazon Web Services編 【第1回】AWSをより良く知るための基礎知識」をIT Leadersに寄稿しました, max: [小ネタ]PandasでExcelファイルを扱う(OpenPyXL), num_nulls: 0]
url:  BINARY SNAPPY DO:415526 FPO:546262 SZ:140440/420536/2.99 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: https://dev.classmethod.jp/articles/aaaaaaaaaaaaaaa/, max: https://dev.classmethod.jp/articles/zsh/, num_nulls: 0]
author_id:  BINARY SNAPPY DO:556291 FPO:560645 SZ:10916/14143/1.30 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: xxxxxxxxxx, max: yyyyyyy num_nulls: 0]
social:  INT32 SNAPPY DO:567282 FPO:568748 SZ:8016/8006/1.00 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 0, max: 5596, num_nulls: 0]
twitter:  INT32 SNAPPY DO:575368 FPO:576038 SZ:5226/5258/1.01 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 0, max: 2226, num_nulls: 0]
facebook:  INT32 SNAPPY DO:580665 FPO:581465 SZ:6324/6621/1.05 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 0, max: 5019, num_nulls: 0]
hatena:  INT32 SNAPPY DO:587061 FPO:587911 SZ:6219/6664/1.07 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 0, max: 1135, num_nulls: 0]
view:  INT32 SNAPPY DO:593350 FPO:606869 SZ:22234/22213/1.00 VC:5764 ENC:PLAIN_DICTIONARY,PLAIN,RLE ST:[min: 1, max: 579795, num_nulls: 0]

 

parquet-tools meta
(Parquetファイルのメタデータを出力)

Parquetファイルのメタデータを出力します。

parquet-tools meta:
Prints the metadata of Parquet file(s)
usage: parquet-tools meta [option...] <input>
where option is one of:
       --debug     Enable debug output
    -h,--help      Show this help string
       --no-color  Disable color output even if supported
where <input> is the parquet file to print to stdout
% parquet-tools meta t_blogposts0000_part_00.parquet 
file:        file:/Users/xxxxxxxxxxxxxx/Desktop/parquet-export/t_blogposts0000_part_00.parquet 
creator:     Amazon Redshift 

file schema: schema 
--------------------------------------------------------------------------------
post_id:     OPTIONAL INT32 O:INT_32 R:0 D:1
post_date:   OPTIONAL INT96 R:0 D:1
title:       OPTIONAL BINARY O:UTF8 R:0 D:1
url:         OPTIONAL BINARY O:UTF8 R:0 D:1
author_id:   OPTIONAL BINARY O:UTF8 R:0 D:1
social:      OPTIONAL INT32 O:INT_32 R:0 D:1
twitter:     OPTIONAL INT32 O:INT_32 R:0 D:1
facebook:    OPTIONAL INT32 O:INT_32 R:0 D:1
hatena:      OPTIONAL INT32 O:INT_32 R:0 D:1
view:        OPTIONAL INT32 O:INT_32 R:0 D:1

row group 1: RC:5764 TS:614504 OFFSET:4 
--------------------------------------------------------------------------------
post_id:      INT32 SNAPPY DO:4 FPO:23085 SZ:32517/32506/1.00 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 23, max: 611870, num_nulls: 0]
post_date:    INT96 SNAPPY DO:32592 FPO:84750 SZ:61580/78568/1.28 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[no stats for this column]
title:        BINARY SNAPPY DO:94219 FPO:405599 SZ:321032/539340/1.68 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min:[お知らせ]「クラウド分解辞典−Amazon Web Services編 【第1回】AWSをより良く知るための基礎知識」をIT Leadersに寄稿しました, max: [小ネタ]PandasでExcelファイルを扱う(OpenPyXL), num_nulls: 0]
url:          BINARY SNAPPY DO:415526 FPO:546262 SZ:140440/420536/2.99 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: https://dev.classmethod.jp/articles/aaaaaaaaaaaaaaa/, max: https://dev.classmethod.jp/articles/zsh/, num_nulls: 0]
author_id:    BINARY SNAPPY DO:556291 FPO:560645 SZ:10916/14143/1.30 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: xxxxxxxxxx, max: yyyyyyy, num_nulls: 0]
social:       INT32 SNAPPY DO:567282 FPO:568748 SZ:8016/8006/1.00 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 0, max: 5596, num_nulls: 0]
twitter:      INT32 SNAPPY DO:575368 FPO:576038 SZ:5226/5258/1.01 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 0, max: 2226, num_nulls: 0]
facebook:     INT32 SNAPPY DO:580665 FPO:581465 SZ:6324/6621/1.05 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 0, max: 5019, num_nulls: 0]
hatena:       INT32 SNAPPY DO:587061 FPO:587911 SZ:6219/6664/1.07 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 0, max: 1135, num_nulls: 0]
view:         INT32 SNAPPY DO:593350 FPO:606869 SZ:22234/22213/1.00 VC:5764 ENC:RLE,PLAIN_DICTIONARY,PLAIN ST:[min: 1, max: 579795, num_nulls: 0]

 

parquet-tools dump
(Parquetファイルの内容とメタデータを出力)

Parquetファイルの内容とメタデータを出力します。

parquet-tools dump:
Prints the content and metadata of a Parquet file
usage: parquet-tools dump [option...] <input>
where option is one of:
    -c,--column <arg>  Dump only the given column, can be specified more than
                       once
    -d,--disable-data  Do not dump column data
       --debug         Enable debug output
    -h,--help          Show this help string
    -m,--disable-meta  Do not dump row group and page metadata
    -n,--disable-crop  Do not crop the output based on console width
       --no-color      Disable color output even if supported
where <input> is the parquet file to print to stdout
% parquet-tools dump t_blogposts0000_part_00.parquet 
row group 0 
--------------------------------------------------------------------------------
post_id:    INT32 SNAPPY DO:4 FPO:23085 SZ:32517/32506/1.00 VC:5764 EN [more]...
post_date:  INT96 SNAPPY DO:32592 FPO:84750 SZ:61580/78568/1.28 VC:5764 [more]...
title:      BINARY SNAPPY DO:94219 FPO:405599 SZ:321032/539340/1.68 VC:5764 [more]...
url:        BINARY SNAPPY DO:415526 FPO:546262 SZ:140440/420536/2.99 VC:5764 [more]...
author_id:  BINARY SNAPPY DO:556291 FPO:560645 SZ:10916/14143/1.30 VC:5764 [more]...
social:     INT32 SNAPPY DO:567282 FPO:568748 SZ:8016/8006/1.00 VC:5764 [more]...
twitter:    INT32 SNAPPY DO:575368 FPO:576038 SZ:5226/5258/1.01 VC:5764 [more]...
facebook:   INT32 SNAPPY DO:580665 FPO:581465 SZ:6324/6621/1.05 VC:5764 [more]...
hatena:     INT32 SNAPPY DO:587061 FPO:587911 SZ:6219/6664/1.07 VC:5764 [more]...
view:       INT32 SNAPPY DO:593350 FPO:606869 SZ:22234/22213/1.00 VC:5764 [more]...

    post_id TV=5764 RL=0 DL=1 DS:   5764 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    post_date TV=5764 RL=0 DL=1 DS: 5761 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    title TV=5764 RL=0 DL=1 DS:     5763 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    url TV=5764 RL=0 DL=1 DS:       5764 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    author_id TV=5764 RL=0 DL=1 DS: 439 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    social TV=5764 RL=0 DL=1 DS:    361 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    twitter TV=5764 RL=0 DL=1 DS:   162 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    facebook TV=5764 RL=0 DL=1 DS:  195 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    hatena TV=5764 RL=0 DL=1 DS:    207 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

    view TV=5764 RL=0 DL=1 DS:      3371 DE:PLAIN_DICTIONARY
    ----------------------------------------------------------------------------
    page 0:                          DLE:RLE RLE:RLE VLE:PLAIN_DICTIONARY [more]... VC:5764

INT32 post_id 
--------------------------------------------------------------------------------
*** row group 1 of 1, values 1 to 5764 *** 
value 1:    R:0 D:1 V:611870
value 2:    R:0 D:1 V:611669
value 3:    R:0 D:1 V:609145
:
:
value 5762: R:0 D:1 V:374
value 5763: R:0 D:1 V:215
value 5764: R:0 D:1 V:23

INT96 post_date 
--------------------------------------------------------------------------------
*** row group 1 of 1, values 1 to 5764 *** 
value 1:    R:0 D:1 V:0x00EC8FE3BB020000C1852500
value 2:    R:0 D:1 V:0x0040FAF83E2E0000C0852500
value 3:    R:0 D:1 V:0x00888D13AB3F0000BF852500
:
:
value 5762: R:0 D:1 V:0x00BE50DEC2040000C6782500
value 5763: R:0 D:1 V:0x001A238F53350000C5782500
value 5764: R:0 D:1 V:0x002045F994390000C4782500

BINARY title 
--------------------------------------------------------------------------------
*** row group 1 of 1, values 1 to 5764 *** 
value 1:    R:0 D:1 V:SysOps アドミニストレーター – アソシエイト(SOA)に合格したので勉強法をまとめてみた
value 2:    R:0 D:1 V:Amazon GuardDuty 입문부터 실전까지 바로 적용해봅시다
value 3:    R:0 D:1 V:[AWS 입문] AWS CLI 에서 S3 + CloudFront 로 Vue.js 웹페이지 배포하기
:
:
value 5762: R:0 D:1 V:Amazon S3 のバージョン管理について
value 5763: R:0 D:1 V:クラスメソッドブログはじめました!
value 5764: R:0 D:1 V:CMブログ始めました♪

:
(以降、カラム数分表示が続く)

 

parquet-tools merge
(複数のParquetファイルを1つにマージ)

複数のParquetファイルを1つにマージします。このコマンドは行のグループをマージするのではなく、1つずつ順番に配置していきます。多くの小さなファイルをマージするために使用された場合、結果のファイルには小さな行グループが含まれます。

parquet-tools merge:
Merges multiple Parquet files into one. The command doesn't merge row groups,
just places one after the other. When used to merge many small files, the
resulting file will still contain small row groups, which usually leads to bad
query performance.
usage: parquet-tools merge [option...] <input> [<input> ...] <output>
where option is one of:
       --debug     Enable debug output
    -h,--help      Show this help string
       --no-color  Disable color output even if supported
where <input> is the source parquet files/directory to be merged
   <output> is the destination parquet file

実行結果:

% parquet-tools merge t_blogposts0000_part_00.parquet t_blogposts0001_part_00.parquet t_blogposts0002_part_00.parquet t_blogposts0003_part_00.parquet t_blogposts_merged.parquet
Warning: file t_blogposts0000_part_00.parquet is too small, length: 617042
Warning: file t_blogposts0001_part_00.parquet is too small, length: 618667
Warning: file t_blogposts0002_part_00.parquet is too small, length: 615366
Warning: file t_blogposts0003_part_00.parquet is too small, length: 618531
Warning: you merged too small files. Although the size of the merged file is bigger, it STILL contains small row groups, thus you don't have the advantage of big row groups, which usually leads to bad query performance!
% ll
total 9664
-rw-r--r--  1 xxxxxxxxxx  staff  2464502  8 11 xx:xx t_blogposts_merged.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff   618531  8 11 xx:xx t_blogposts0003_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff   615366  8 11 xx:xx t_blogposts0002_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff   618667  8 11 xx:xx t_blogposts0001_part_00.parquet
-rw-r--r--@ 1 xxxxxxxxxx  staff   617042  8 11 xx:xx t_blogposts0000_part_00.parquet

 

parquet-tools rowcount
(Parquetファイルの行数を表示)

Parquetファイルの行数を表示します。

Prints the count of rows in Parquet file(s)
usage: parquet-tools rowcount [option...] <input>
where option is one of:
    -d,--detailed  Detailed rowcount of each matching file
       --debug     Enable debug output
    -h,--help      Show this help string
       --no-color  Disable color output even if supported
where <input> is the parquet file to count rows to stdout

実行結果:

 % parquet-tools rowcount --detailed t_blogposts_merged.parquet
t_blogposts_merged.parquet row count: 23054
Total RowCount: 23054

 

parquet-tools size
(Parquetファイルのサイズを出力)

Parquetファイルのサイズを出力します。

parquet-tools size:
Prints the size of Parquet file(s)
usage: parquet-tools size [option...] <input>
where option is one of:
    -d,--detailed      Detailed size of each matching file
       --debug         Enable debug output
    -h,--help          Show this help string
       --no-color      Disable color output even if supported
    -p,--pretty        Pretty size
    -u,--uncompressed  Uncompressed size
where <input> is the parquet file to get size & human readable size to stdout

実行結果:

% parquet-tools size --detailed t_blogposts_merged.parquet
t_blogposts_merged.parquet: 2459922 bytes
Total Size: 2459922 bytes

 

まとめ

というわけで、Parquet用コマンドラインツール「parquet tools」の紹介でした。

データレイク関連であればまず使わないことは無いであろう「Parquet」ファイル。CUI形式でお手軽に使えるこのツールがあればだいぶ色々捗りそうですね。