【AWS】AWS Glue ~ Glue Version 3.0 ~

■ はじめに

https://dk521123.hatenablog.com/entry/2020/08/19/130118

で、AWS Glue2.0 を扱ったが、
2021/08/19に Glue3.0がリリースされたらしいので、
調べてみた。

まずは、ざっくり知りたいなら、以下の公式サイト参照のこと。

https://aws.amazon.com/jp/about-aws/whats-new/2021/08/spark-3-1-runtime-aws-glue-3-0/

目次

【1】Glue各バージョン
 1)依存するライブラリ一覧
 2)JDBC更新一覧
【2】リリースノートより
 1)リリース項目
 2)制限事項 - Limitations
【3】ブログより - AWS Glue version 3.0 の目玉
 1)Sparkランタイム の パフォーマンス最適化
 2)より早い Read/Write アクセス
 3)より早く効果的なパーティション・プルーニング
 4)きめ細かいアクセス管理
 5)ACID トランザクション
 6)ユーザーエクスペリエンス向上
【4】関連用語
 1)Adaptive Query Execution (AQE)
 2)SIMD(Single Instruction/Multiple Data)
 3)Partition pruning(パーティション・プルーニング)
【5】メモ

【1】Glue各バージョン

* 公式・リリースノート より
 => 2021/09/15現在、日本語だとまだ載っていない
 =>  Sparkのバージョンが3.X系にグレードアップしている

https://docs.aws.amazon.com/glue/latest/dg/release-notes.html

Glue バージョン Spark Python2 Python3 備考
0.9 Spark 2.2.1 Python 2.7 - -
1.0 Spark 2.4.3 Python 2.7 Python 3.6 -
2.0 Spark 2.4.3 - Python 3.7 -
3.0 Spark 3.1.1 - Python 3.7 ★今回のテーマ★

1)依存するライブラリ一覧

* 以下の公式サイトの「Appendix A: notable dependency upgrades」を
 みておくといいかも。(気になったものを一部抜粋)

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html#migrating-version-30-appendix-dependencies

* Apache Arrow については、以下の関連記事を参照のこと。

Apache Arrow / PyArrow ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2021/09/21/224959

Dependency v0.9 v1.0 v2.0 v3.0
Spark 2.2.1 2.4.3 2.4.3 3.1.1-amzn-0
Hadoop 2.7.3-amzn-6 2.8.5-amzn-1 2.8.5-amzn-5 3.2.1-amzn-3
Hive 1.2 1.2 1.2 2.3.7-amzn-4
EMRFS 2.20.0 2.30.0 2.38.0 2.46.0
Arrow N/A 0.10.0 0.10.0 2.0.0

2)JDBC更新一覧

* 以下のURLの「Appendix B: JDBC driver upgrades」より抜粋

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html#migrating-version-30-appendix-jdbc-driver

Driver JDBC driver version in past AWS Glue versions JDBC driver version in AWS Glue 3.0
MySQL 5.1 8.0.23
Microsoft SQL Server 6.1.0 7.0.0
Oracle Databaes 11.2 21.1
PostgreSQL 42.1.0 42.2.18
MongoDB 2.0.0 4.0.0

【2】リリースノートより

* 公式・リリースノート を読んでみた
 => 2021/09/18 現在、日本語だとまだ載っていない

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html

1)リリース項目

Builds the AWS Glue ETL Library against Spark 3.0, which is a major release for Spark.
=> SparkのメジャーリリースであるSpark 3.0に対応した
  AWS Glue ETLライブラリを構築

Streaming jobs are supported on AWS Glue 3.0.
=> ストリーミングジョブがAWS Glue 3.0でサポート

Includes new AWS Glue Spark runtime optimizations
 for performance and reliability:
=> パフォーマンスと信頼性のための
 新しいGlue Sparkランタイムの最適化を含んでいる

Faster in-memory columnar processing based on Apache Arrow for reading CSV data.
=> CSVデータの読み込みのために、Apache Arrowベースでのより早いインメモリの列処理

SIMD based execution for vectorized reads with CSV data.
=> SIMDベースによるCSVデータに対するベクトル演算のための実行

Spark upgrade also includes additional optimizations developed on Amazon EMR.
=> Sparkアップグレードは、Amazon EMR上で開発された追加した最適化を含む

Upgraded EMRFS from 2.38 to 2.46 enabling new features and bug fixes for Amazon S3 access.
=> EMRFS の v2.38 から v2.46へのアップグレードは、Amazon S3アクセスのための
  新しい特徴およびバグ修正が有効になっている

Upgraded several dependencies that were required for the new Spark version.
=> 新しいSparkバージョンのために必要ないくつかの依存ライブラリを更新している

See Appendix A: notable dependency upgrades.
=> 「Appendix A: 著名な依存ライブラリの更新」を参照。

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html#migrating-version-30-appendix-dependencies

Upgraded JDBC drivers for our natively supported data sources.
=> データソースをネーティブにサポートしたJDBCドライバが更新された

See Appendix B: JDBC driver upgrades.
=> 「Appendix B: JDBCドライバの更新」を参照。

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html#migrating-version-30-appendix-jdbc-driver

2)制限事項 - Limitations

The following are limitations with AWS Glue 3.0:
=> 以下は、AWS Glue 3.0 での制限事項です。

AWS Glue machine learning transforms are not yet available in AWS Glue 3.0.
=> AWS Glue コンソールでの機械学習変換については、
  Glue3.0上では、まだ対応されていない。

Some custom Spark connectors do not work with AWS Glue 3.0
 if they depend on Spark 2.4 and do not have compatibility with Spark 3.1.
=> もし、それらがSpark2.4に依存、かつ、それがSpark 3.1で互換性がない場合、
  いくつかの独自のSparkコネクタは、Glue3.0では動作しません。

For more information about migrating to AWS Glue version 3.0,
 see Migrating AWS Glue jobs to AWS Glue version 3.0 Actions
 to migrate to AWS Glue 3.0.
=> AWS Glue v3.0への移行に関する更に情報については、
 「AWS Glueジョブに関するAWS Glue v3.0への移行」
 (以下のURL)を参照ください。

https://docs.aws.amazon.com/glue/latest/dg/migrating-version-30.html

【3】ブログより - AWS Glue version 3.0 の目玉

以下の公式サイトのブログ「AWS Glue version 3.0 highlights」より抜粋

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

1)Sparkランタイム の パフォーマンス最適化

* 「Performance-optimized Spark runtime」より抜粋

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

Performance-optimized Spark runtime based on open-source Apache Spark 3.1.1
 and enhanced with innovative optimizations
 developed by the AWS Glue and Amazon EMR teams.
=> オープンソースApache Spark 3.1.1に基づき、
 革新的な最適化により強化された
 パフォーマンス最適化されたSpark ランタイム は、
 AWS GlueとAmazon EMRチームによって開発された
=> 要するに、Glue3.0は、Spark 3.1.1ベースで作っているっと。

These optimizations accelerate data integration and query processing with advanced techniques,
 such as SIMD based vectorized readers developed in native language (C++),
 in-memory columnar formats for processing, optimized shuffles, partition coalescing,
 and Spark’s adaptive query execution.
=> それらの最適化は、高度な技術
  例えば、ネイティブ言語(C++)で開発された
  ベクタリーダ(vectorized readers)をベースにしているSIMD(*1)
  処理のためのインメモリの列指向データフォーマット、
  最適化されたシャッフル、partition coalescing、
  そしてSparkのAdaptive Query Execution(AQE *1)と共に
  データ統合と問合せ処理を加速します。
=> 要するに、Spark 3.1.1には、AQEなど技術が導入されてて
  処理速度が向上したっと。

*1 SIMD:「【4】関連用語」の「2)SIMD(Single Instruction/Multiple Data)」
*2 AQE:「【4】関連用語」の「1)Adaptive Query Execution (AQE)」

The AWS Glue 3.0 runtime is built with upgraded JDBC drivers 
for all AWS Glue native sources, 
including MySQL, Microsoft SQL Server, Oracle, PostgreSQL, and MongoDB,
 to enable simpler, faster,
 and secure integration with new versions of database engines.
=> AWS Glue 3.0 ランタイムは、全てのAWS Glueネイティブソースのために、
 アップグレードされたJDBCドライバによって構築されている
 それは、よりシンプルで、より早く そして 
 Databaseエンジンの新しいバージョンを使ったセキュア統合が可能にするために、
 MySQL、Microsoft SQL Server, Oracle, PostgreSQL,
 そして MongoDBを含んでいます。

=> 要するに、AWS Glue3.0ランタイムは、
 以下の公式サイト「Appendix B: JDBC driver upgrades」のように
 各DBのJDBCドライバのバージョンを更新していますよっと。

補足:Spark 3.1.1

* Spark 3.1.1 に対応したことにより、PySpark で使用できる関数が増えた
 + max_by
 + make_date
 + extract, date_part
 + count_if
 + from_csv

and so on...

 => 詳細は、以下のサイトを参照。

https://kakehashi-dev.hatenablog.com/entry/2021/12/23/080000

2)より早い Read/Write アクセス

* 「Faster read and write access」より抜粋

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

Faster read and write access with the AWS Glue 3.0 runtime
 to Amazon Simple Storage Service (Amazon S3) using vectorized readers
 with Glue Dynamic Frames, and Amazon S3 optimized output committers.
=> AWS Glue3.0ランタイムによる Amazon S3への
 より早い読み込みと書き込みアクセスは、
 Glue Dynamic Framesでのベクタリーダ(vectorized readers)を使ったもの
 そして、Amazon S3は出力コミッターで最適化される
=> 要するに、S3への読み込みは、Glue Dynamic Framesで、
  S3への書き込みは、出力コミッターで最適化されて
  アクセス速度が増していたってこと?

These optimizations improve Spark application performance
 for popular customer workloads reading row-based formats
 such as CSV and writing to columnar formats such as Apache Parquet.
=> それらの最適化は、
 CSVのような行ベースのフォーマットの読み込みや
 Apache Parquetのようなカラムなフォーマットの書き込み
 を行うポピュラーな独自のワークロードのための
 Sparkアプリケーションのパフォーマンスを向上する
=> 要するに、Glue3.0は、CSVの読み込みや
 Apache Parquetの書き込みのパフォーマンスを向上した

ベクタリーダ(vectorized readers)
https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-format.html#aws-glue-programming-etl-format-simd-csv-reader

3)より早く効果的なパーティション・プルーニング

* 「Faster and efficient partition pruning (*1)」より抜粋

*1 partition pruning:「【4】関連用語」の
 「3)Partition pruning(パーティション・プルーニング)」

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

Faster and efficient partition pruning with the AWS Glue 3.0 runtime
 when analyzing large, highly partitioned tables managed AWS Glue Data Catalog.
=> 大規模な分析する時、AWS Glue 3.0ランタイムを使った
 より早く効果的なパーティション・プルーニングにより、
 高度なパーティションテーブルは、AWS Glueデータカタログで管理された。

For highly partitioned datasets,
 partition pruning can significantly reduce the cost of catalog partition listing
 and query planning by filtering out unnecessary partitions using partition indexes.
=> 高度なパーティションデータセットのために、
 パーティション・プルーニング は、カタログのパーティションリストのコスト
 及びパーティションインデックスを使った不必要なパーティションの除外による
 クエリ計画について、十分な削減が可能です。

=> 要するに、AWS Glue 3.0ランタイムでは、パーティション・プルーニングにより、
  絞り込む問合せのパフォーマンス向上やコスト削減ができるってこと?

4)きめ細かいアクセス管理

* 「Fine-grained access control」より抜粋
* cf. Fine-grained = きめの細かい、微粒状の

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

Fine-grained access control with the AWS Glue 3.0 runtime
 for your batch jobs using AWS Lake Formation.
=> AWS Lake Formationを使ったバッチジョブのための
  AWS Glue 3.0ランタイムによるきめ細かいアクセス管理

You can now access your data at the database, table, column, row, 
and cell-level using resource names and Lake Formation tag attributes
 (available in preview).
=> リソース名とLake Formationのタグ属性を使って
  データベース、テーブル、項目、列 そして セルレベルでアクセス可能
 (プレビュー版で有効)

=> 要するに、Lake Formationと連携して、
  細かいレベルでアクセス制限を掛けることが可能
 (ってゆーかー、これって、Lake Formationの機能では?)

https://dev.classmethod.jp/articles/20201210-aws-lake-formation-new-3-feature-preview/

5)ACID トランザクション

* 「ACID transactions」より抜粋

* ACID
 => Atomicity (不可分性) = これ以上分けることができない
 => Consistency (一貫性)
 => Isolation (独立性)
 => Durability (永続性)

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

ACID transactions offered with the AWS Glue 3.0 runtime
 for Lake Formation Governed Tables and query acceleration
 with automatic file compaction on your data lake
 (available in preview).
=> データレイク上の自動ファイル圧縮による
  Lake FormationのGoverned Table と クエリ促進のために、
  ACIDトランザクションは、AWS Glue 3.0ランタイムで提供された
 (プレビュー版で有効)

=> 要するに、ACIDトランザクションができるようになった。
 (ってゆーかー、これも、Lake Formationの機能では?)

https://dev.classmethod.jp/articles/20201210-aws-lake-formation-new-3-feature-preview/

6)ユーザーエクスペリエンス向上

* 「Improved user experience for monitoring, debugging, and tuning Spark applications」より抜粋

https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/

Improved user experience for monitoring, debugging, and tuning Spark applications.
=> Sparkアプリケーションのモニタリング、デバッグ、チューニングのための
  ユーザーエクスペリエンス向上

Spark 3.1.1 enables an improved Spark UI experience
 that includes new Spark executor memory metrics
 and Spark Structured Streaming metrics that are useful for AWS Glue streaming jobs.
=> Spark 3.1.1 は、改善されたSpark UIが有効になった
  それは、AWS Glueストリーミングジョブのために役立つ
  新しいSpark実行メモリマトリックや
  Spark構造化ストリーミングマトリックを含んでいます

=> 要するに、AWS Glueストリーミングジョブのために
  改善されたSpark UIが利用可能になった

【4】関連用語

1)Adaptive Query Execution (AQE)

* Adaptive Query Execution = 適応型クエリ実行
* Spark SQL実行中に実データの統計情報からクエリを再最適化する機能

https://recruit.gmo.jp/engineer/jisedai/blog/query_performance_tuning_using_spark_3_new_functions/

2)SIMD(Single Instruction/Multiple Data)

* シムディー or シムド と読むらしい
* 一つの命令を同時に複数のデータに適用する並列処理方式

https://e-words.jp/w/SIMD.html

3)Partition pruning(パーティション・プルーニング)

* Partition pruning = パーティション除去
 => cf. pruning (プルーニング) = 剪定(センテイ), 刈り込み

* パーティション化された項目の絞り込みに対して、
 特定のパーティションにしかアクセスしないこと
 => 読み込むブロックを減らし、処理を高速化できる

https://qiita.com/MotohiroSiobara/items/e862b8ae420fdc32f7ad

【5】メモ

https://d1.awsstatic.com/webinars/jp/pdf/services/202108_Blackbelt_glue_etl_performance2.pdf

より抜粋
~~~~~~~~~~~~
* Glue 3.0(Spark3.1.1)ではコストベースオプティマイザにより、
 データ量も考慮されてjoinの順番も最適化される

* Glue 3.0ではAdaptive Query Executionという新機能により、
 ⾃動的にcoalesceによってパーティション数を最適化してくれる

* Glue 3.0(Spark 3.1.1)では、Adaptive Query Executionという新機能により、
 動的にSkew Joinを⾏われる
~~~~~~~~~~~~

補足:coalesce について

* 与えられた引数から NULLでない最初の引数を返却する関数
* coalesce (コーレス) の詳細は、以下の関連記事を参照のこと。

https://dk521123.hatenablog.com/entry/2021/06/22/213241

参考文献

公式サイト
https://aws.amazon.com/jp/blogs/big-data/introducing-aws-glue-3-0-with-optimized-apache-spark-3-1-runtime-for-faster-data-integration/
一般サイト
https://codezine.jp/article/detail/14714

関連記事

AWS Glue ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/01/221926
AWS Glue ~ 基本編 / ジョブ ~
https://dk521123.hatenablog.com/entry/2019/11/17/231505
AWS Glue ~ Glue Version 2.0 ~
https://dk521123.hatenablog.com/entry/2020/08/19/130118
AWS Glue ~ Glue Version 4.0 ~
https://dk521123.hatenablog.com/entry/2023/03/15/000000
Hive / HiveQL ~ HiveQL関数 / NULL関連編 ~
https://dk521123.hatenablog.com/entry/2021/06/22/213241
Apache Arrow / PyArrow ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2021/09/21/224959