LoginSignup
1
0

More than 1 year has passed since last update.

オープンソースデータ品質検査CLI - Piperiderのクイックスタート

Last updated at Posted at 2022-06-20

Piperiderについて

本文記載時点はPipeRider 0.4.1 を参考にしています。

Piperiderはオープンソースデータ品質検査CLIツールとして、データプロファイリングとリポートを掲げて、データ観測プラットホームを目指す。

CLIについて

プロジェクトの初期化

piperider init

データプロファイリングとポートを作成する

piperider run

プロファイリング比較対照リポートを作成する

piperider compare-reports

Quick Start

Python 3.7+ 必要、3.9+ 推奨する

インストレーションする

pip install piperider

範例SQLite Databaseの用意する

mkdir dataproject && cd dataproject
curl -o sp500.db https://piperider-data.s3.ap-northeast-1.amazonaws.com/getting-started/sp500_20220401.db

プロジェクトの初期化する

piperider init

プロジェクトの名称を入力する

Initialize piperider to path /Users/gabriel/Workspace/github/pipe_stable/.piperider
Start to search dbt project ...
[Skip] No dbt project found
[?] What is your project name? (alphanumeric only):

データソースを選ぶ (sqliteを選んでください)

What data source would you like to connect to?
  snowflake
  postgres
> sqlite

バスを入力する (sp500.dbを入力してください)

Please enter the following fields for sqlite
[?] Path of database file:

プロジェクトの設定を確認する

piperider diagnose

Output 範例

diagnose...
PipeRider Version: 0.4.1
Check config files:
  /path/to/dataproject/.piperider/config.yml: [OK]
✅ PASS

Check format of data sources:
  dataproject: [OK]
✅ PASS

Check connections:
  Name: dataproject 
  Type: sqlite
  Available Tables: ['ACTION', 'PRICE', 'SYMBOL']
  Connection: [OK]
✅ PASS

Check assertion files:
✅ PASS

🎉 You are all set!

Next step:
  Please execute command 'piperider run' to generate your first report

データプロファイリングをする

piperider run

Output 範例

DataSource: dataproject
─────────────────────────────────────────────────────────────────────────────────────── Profiling ────────────────────────────────────────────────────────────────────────────────────────
fetching metadata
profiling [ACTION.SYMBOL] type=VARCHAR(16777216)
profiling [ACTION.DATE] type=DATE
profiling [ACTION.DIVIDENDS] type=NUMERIC(8, 4)
profiling [ACTION.SPLITS] type=NUMERIC(10, 2)
profiling [PRICE.SYMBOL] type=VARCHAR(16777216)
profiling [PRICE.DATE] type=DATE
profiling [PRICE.OPEN] type=NUMERIC(10, 2)
profiling [PRICE.HIGH] type=NUMERIC(10, 2)
profiling [PRICE.LOW] type=NUMERIC(10, 2)
profiling [PRICE.CLOSE] type=NUMERIC(10, 2)
profiling [PRICE.VOLUME] type=NUMERIC(38, 0)
profiling [PRICE.ADJCLOSE] type=NUMERIC(10, 2)
profiling [PRICE.MA5] type=NUMERIC(10, 2)
profiling [PRICE.MA20] type=NUMERIC(10, 2)
profiling [PRICE.MA60] type=NUMERIC(10, 2)
profiling [SYMBOL.SYMBOL] type=VARCHAR(16777216)
profiling [SYMBOL.NAME] type=VARCHAR(16777216)
profiling [SYMBOL.START_DATE] type=DATE
profiling [SYMBOL.END_DATE] type=DATE
profiling [SYMBOL.DESCRIPTION] type=VARCHAR(16777216)
profiling [SYMBOL.EXCHANGE_CODE] type=VARCHAR(16777216)
profiling [SYMBOL.MARKET] type=VARCHAR(16777216)
profiling [SYMBOL.COUNTRY] type=VARCHAR(16777216)
profiling [SYMBOL.SECTOR] type=VARCHAR(16777216)
profiling [SYMBOL.INDUSTRY] type=VARCHAR(16777216)
profiling [SYMBOL.RECOMMENDATION_KEY] type=VARCHAR(16777216)

自動生成のアサーションを作成して、実行する (yesを入力してください)

No assertion found
Do you want to auto generate recommended assertions for this datasource [Yes/no]? Yes

自動生成のアサーションを実行する (yesを入力してください)

Output 範例

Recommended Assertion: /path/to/dataproject/.piperider/assertions/recommended_ACTION.yml
Recommended Assertion: /path/to/dataproject/.piperider/assertions/recommended_PRICE.yml
Recommended Assertion: /path/to/dataproject/.piperider/assertions/recommended_SYMBOL.yml
Do you want to run above recommended assertions for this datasource [yes/no]? yes

Output 範例

──────────────────────────────────────────── Assertion Results ────────────────────────────────────────────
[  OK  ] SYMBOL                     assert_row_count_in_range   Expected: {'count': [454, 555]} Actual: 505
[  OK  ] SYMBOL.SYMBOL              assert_column_type          Expected: {'type': 'string'} Actual: string
[  OK  ] SYMBOL.SYMBOL              assert_column_unique        Expected: {'success': True} Actual: {'success': True}
[  OK  ] SYMBOL.NAME                assert_column_type          Expected: {'type': 'string'} Actual: string
[  OK  ] SYMBOL.NAME                assert_column_unique        Expected: {'success': True} Actual: {'success': True}
[  OK  ] SYMBOL.START_DATE          assert_column_type          Expected: {'type': 'datetime'} Actual: datetime
[  OK  ] SYMBOL.END_DATE            assert_column_type          Expected: {'type': 'datetime'} Actual: datetime
...
...
...
[  OK  ] PRICE.MA60                 assert_column_max_in_range  Expected: {'max': [4959.585, 6061.715]} Actual:
{'max': 5510.65}

──────────────────────────────────────────────── Summary ───────────────────────────────────────────────────────
Table 'ACTION'
  4 columns profiled
  9 test executed

Table 'PRICE'
  11 columns profiled
  30 test executed

Table 'SYMBOL'
  11 columns profiled
  14 test executed

プロファイリングの結果(run.json)によって、リポート(index.html)を作成した
Output 範例 (ブラウザでHTMLリポートを見る)

Generating reports from: /path/to/dataproject/.piperider/outputs/latest/run.json
Report generated in /path/to/dataproject/.piperider/outputs/latest/index.html

Recording #4.gif

.piperider/assertions/で自動生成されたアサーションPRICE.ymlビルトインアサーションファンクションで構成された

description:のメッセージは生成されたレポートのtool tipsになる

# Auto-generated by Piperider based on table "PRICE"
PRICE:  # Table Name
  description: 'Stock price'
  # Test Cases for Table
  tests:
  - name: assert_row_count
    assert:
      min: 160271
    tags:
    - RECOMMENDED
  columns:
    SYMBOL:  # Column Name
      description: 'Stock symobl'
      # Test Cases for Column
      tests:
      - name: assert_column_schema_type
        assert:
          schema_type: VARCHAR(16777216)
        tags:
        - RECOMMENDED
      - name: assert_column_not_null
        tags:
        - RECOMMENDED
    DATE: # Column Name
      description: 'recorded date'
      # Test Cases for Column
      tests:
      - name: assert_column_schema_type
        assert:
          schema_type: DATE
        tags:
        - RECOMMENDED
      - name: assert_column_not_null
        tags:
        - RECOMMENDED
    OPEN: # Column Name
      description: 'Opening price'
      # Test Cases for Column
      tests:
      - name: assert_column_schema_type
        assert:
          schema_type: NUMERIC(10, 2)
        tags:
        - RECOMMENDED
      - name: assert_column_max_in_range
        assert:
          max:
          - 5379.849
          - 6575.371
        tags:
        - RECOMMENDED
      - name: assert_column_not_null
        tags:
        - RECOMMENDED
...
...
...

次、更新されたSqlite databaseを用意する

curl -o sp500.db https://piperider-data.s3.ap-northeast-1.amazonaws.com/getting-started/sp500_20220527.db

また、更新されたデータをプロファイリングをするとリポートを作成する

piperider run

プロファイリング比較対照リポートを作成する

piperider compare-reports

Output 範例 (Spaceキーで同じテーブル名前を選択する)

[?] Please select the 2 reports to compare ( SPACE to select, and ENTER to confirm ):
   X dataproject  #table=3      #pass=51    #fail=2     2022-06-23T13:01:37.543978Z
 > X dataproject  #table=3      #pass=53    #fail=0     2022-06-23T12:48:11.794525Z

ブラウザで比較対照リポートを見る
Output 範例

Selected reports:
  Base:  /path/to/dataproject/.piperider/outputs/dataproject-20220623130137/run.json
  Input: /path/to/dataproject/.piperider/outputs/dataproject-20220623124811/run.json

Comparison report: /path/to/dataproject/.piperider/comparisons/20220623130337/index.html

Recording #6.gif

以上です

参考する

ドキュメントサイト

リポジトリー

公式サイト

ブログ

Discordで気軽に何でも聞いてください。

追記

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0