Test BigQuery query using BigQuery
Project description
BigQueryのクエリをテストするためのツール
BigQueryへのクエリロジックのテストができます
Basic Usage
Simple
from bqqtest import QueryTest
from google.cloud import bigquery
# expected
expected_schema = [("name", "STRING"), ("value", "INT64")]
expected_datum = [["abc", 100], ["bbb", 333]]
expected = {"schema": expected_schema, "datum": expected_datum}
# actual
target_schema = [("name", "STRING"), ("value", "INT64")]
target_datum = [["abc", 100], ["bbb", 333]]
tables = {"test.target_table": {"schema": target_schema, "datum": target_datum}}
eval_query = {"query": "SELECT * FROM test.target_table", "params": []}
qt = QueryTest(bigquery.Client(), expected, tables, eval_query)
success, diff = qt.run()
success # True
Group By
from bqqtest import QueryTest
from google.cloud import bigquery
# expected
expected_schema = [("item", "STRING"), ("total", "INT64")]
expected_datum = [["abc", 300], ["bbb", 333]]
expected = {"schema": expected_schema, "datum": expected_datum}
# actual
target_schema = [("item", "STRING"), ("value", "INT64")]
target_datum = [["abc", 100], ["bbb", 333], ["abc", 200]]
tables = {"test.target_table": {"schema": target_schema, "datum": target_datum}}
eval_query = {
"query": "SELECT item, SUM(value) AS total FROM test.target_table GROUP BY item",
"params": [],
}
qt = QueryTest(bigquery.Client(), expected, tables, eval_query)
success, diff = qt.run()
success # True
Multi Table
from bqqtest import QueryTest
from google.cloud import bigquery
# expected
expected_schema = [("name", "STRING"), ("value", "INT64")]
expected_datum = [["abc", 100], ["bbb", 333], ["xxxx", 888], ["zzzz", 999]]
expected = {"schema": expected_schema, "datum": expected_datum}
# actual
target_schema = [("name", "STRING"), ("value", "INT64")]
target_datum1 = [["abc", 100], ["bbb", 333]]
target_datum2 = [["xxxx", 888], ["zzzz", 999]]
tables = {
"test.table1": {"schema": target_schema, "datum": target_datum1},
"test.table2": {"schema": target_schema, "datum": target_datum2},
}
eval_query = {
"query": "SELECT * FROM `test.table1` UNION ALL SELECT * FROM `test.table2`",
"params": [],
}
qt = QueryTest(bigquery.Client(), expected, tables, eval_query)
success, diff = qt.run()
success # True
特徴
- WITH を利用して、 BigQuery に保存されないテストデータを一時的に生成します。
- BigQuery は保存されているデータ走査した量とAPIリクエスト数で課金されるため、費用抑えてユニットテストができます。
- 料金の詳細は、 BigQuery の公式ドキュメントを参照してください
- テストをするために、クエリを書き直す必要はありません
- ライブラリ内部では、対象テーブルの Identifier を書き換えてテーブルを差し替えます
注意
BigQuery へ直接クエリを発行します。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bqqtest-0.5.0.tar.gz
(9.3 kB
view details)
Built Distribution
bqqtest-0.5.0-py3-none-any.whl
(10.1 kB
view details)
File details
Details for the file bqqtest-0.5.0.tar.gz
.
File metadata
- Download URL: bqqtest-0.5.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.7.6 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85734f53f06e340b821c83ff362bfdee547c8bfd14ac91c78e2245663ab48267 |
|
MD5 | bfb91d8e402491b226dcb6bbd8ccbef2 |
|
BLAKE2b-256 | 929ae90addbea121302c9651f4529bfdda1147fe0b124b485b05a7109aee19d5 |
File details
Details for the file bqqtest-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: bqqtest-0.5.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.7.6 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 829733da6e325acd407a3d98652c7beb5170da391af7429a2e6e0c1a168194b7 |
|
MD5 | 1e0d414efe668abed88d936699a89ff4 |
|
BLAKE2b-256 | 26e4865720cb84426854f1378d3643df8a2bc70ad7c3c73783588bbe148b55ee |