これは datatech-jp Advent Calendar 2024 の20日目の記事です。
こんにちは chanyou です。
先日、 datatech-jp の Data Contract事例共有会 というイベントに登壇させていただきました。 Data Contract の導入の難しさを語り合う貴重な機会でした。
イベントではそこまで触れていなかったですが Data Contract CLI というオープンソースのツールがあります。 Data Contract CLI を使うことで、Data Contract の YAML ファイルの読み書きやカタログ生成が容易に行えます。
Data Contract CLI の実装を読む機会がありましたので、この記事で触れていきたいと思います。
Data Contract CLI とは? ドキュメントは以下から確認できます。
https://cli.datacontract.com
ソースコードは以下で、MIT ライセンスで公開されています。
datacontract/datacontract-cli - GitHub
Data Contract CLI の基本的な使い方 インストール pip でインストールできます。
pip install 'datacontract-cli' 依存関係が切り出されており、使いたい機能に応じて追加モジュールをインストールできます。
pip install datacontract-cli[bigquery] インストールすると datacontract コマンドが使えるようになっています。
$ datacontract Usage: datacontract [OPTIONS] COMMAND [ARGS]... The datacontract CLI is an open source command-line tool for working with Data Contracts (https://datacontract.com). It uses data contract YAML files to lint the data contract, connect to data sources and execute schema and quality tests, detect breaking changes, and export to different formats. ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Prints the current version. │ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ init Download a datacontract.yaml template and write it to file. │ │ lint Validate that the datacontract.yaml is correctly formatted. │ │ test Run schema and quality tests on configured servers. │ │ export Convert data contract to a specific format. Saves to file specified by `output` option if present, otherwise prints to stdout. │ │ import Create a data contract from the given source location. Saves to file specified by `output` option if present, otherwise prints to stdout. │ │ publish Publish the data contract to the Data Mesh Manager. │ │ catalog Create an html catalog of data contracts. │ │ breaking Identifies breaking changes between data contracts. Prints to stdout. │ │ changelog Generate a changelog between data contracts. Prints to stdout. │ │ diff PLACEHOLDER. Currently works as 'changelog' does. │ │ serve Start the datacontract web server. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ できることは出力の通りですが、一通り触ってみましょう。
...