Cloud Intelligence™Cloud Intelligence™

Cloud Intelligence™

Google BigQuery データモデラー

このページはEnglishDeutschEspañolFrançaisItalianoPortuguêsでもご覧いただけます。

By Eben Du ToitMar 5, 20202 min read
Eben Du Toit

About Eben Du Toit

I lead engineering teams in the Partner Channel space, building the tooling that helps customers make sense of their revenue — turning complex partner and billing data into something they can actually see, trust, and act on. The work sits at the intersection of cloud cost management, FinOps, and billing integrations, with data flowing across GCP, BigQuery, MongoDB Atlas, Snowflake, and the wider cloud ecosystem. It's technically meaty, and I love that about it.

My days are split between people and systems — growing and aligning multiple teams, helping the team navigate the environment, hiring, and partnering with stakeholders across the org. I shift between maker mode and manager mode depending on what's needed: sometimes I'm deep in the code building features, sometimes I'm in the room helping my teams move forward. I care a lot about building teams where good engineers can do their best work.

What I work on

Partner Channel engineering and revenue management tooling · Cloud cost management and FinOps · Billing data pipelines and integrations · Engineering leadership, hiring, and team process

Good topics to find me for

Anything Partner Channel, revenue, FinOps, or billing-related · Data engineering and pipeline architecture · Engineering management, hiring, or team culture

Outside work

When I'm not in a terminal, I'm usually behind a camera — shooting on a Nikon Z or whatever vintage film body I'm currently infatuated with. I follow mountain biking and trail running closely, have strong opinions about mechanical keyboards and good stationery, and watch more anime than I probably admit. I also play Rocket League with more optimism than results.

Cape Town · SAST (UTC+2)

My personal page

1 tzqg2nhqfudmca2bc6vilw

Google BigQueryでのデータモデリング、どこから始めればよいか迷っていませんか?シンプルなリポジトリと実例で解説します。

1 tzqg2nhqfudmca2bc6vilwPhoto by Steady Hand Co. on Unsplash。荒れたデータの中を、見通しの良い道筋で進みましょう。

世の中には、扱いにくいデータが大量に飛び交っています。多くの担当者が、何から手をつけて意味を読み解けばよいのか、そしてさらに重要な点として、自社で活用できる形にどう構造化すればよいのかと頭を抱えています。

本記事では、整形済みのデータをビューとしてGoogle BigQueryに投入できる、シンプルなスクリプトとリポジトリをご紹介します。さらにJinjaのテンプレート機能を使えば作業がぐっと楽になり、お好みで変数をあらかじめ定義しておくことも可能です。

PerfectScale™ for Kubernetes

Ready to optimize?

Get your free Kubernetes savings analysis

仕組みは?

select_101.sql.j2というファイルに、次のようなクエリを記述します。

SELECT {{aNumber}} as num

テンプレート内のaNumberは、設定ファイルconfiguration.jsonであらかじめ定義した変数から読み込まれます。

{
"aNumber": 101
}

あわせて、select_101.jsonというスキーマファイルも用意します。

{
"metric": "First example",
"metric_description": "Select only a constant number as output",
"purpose" : "",
"usage_example" : "",
"usage_description" : "",
"fields": [\
```\
\
```\
{\
```\
\
```\
"field": "num",\
```\
\
```\
"description": "A small number",\
```\
\
```\
"type": "INTEGER",\
```\
\
```\
"typical_values": [ 4 ]\
```\
\
```\
}\
```\
\
```\
]
````

}

これでGoogle BigQueryへデプロイする準備が整いました。
`-m` デプロイするメトリックを指定
`-v` ビューとしてデプロイすることを指定
`-d` 対象のデータセットを指定
`-p` 対象のprojectIdを指定

./compile.py -m select_101.sql.j2 -v -d -p

実行すると、以下のような結果が表示されます。
![1 xjb6e ziayoryplnz53ytq](https://media.doit.com/imports/wordpress/2020/03/1306ab6a6531-1_xjb6e_ziayoryplnz53ytq.png)
## テンプレートの中にテンプレートを読み込む
テンプレートの中に別のテンプレートを読み込むこともできます。
`select_101_include.sql.j2`というファイルに、次のようなクエリを記述します。

SELECT *

FROM (

{% include 'select_101/select_101.sql.j2' %}

)

このクエリは次のように展開され、デプロイされます。

SELECT * FROM ( SELECT 101 as num )


それでは、よいモデリングを!

ほかの記事もぜひ[ブログ](https://doit.com/blog/)でご覧ください。[EbenのTwitter](https://twitter.com/eebsidian)もおすすめです。

Your cloud bill shouldn't be a mystery

Optimization, automation, expertise. In one platform.