2023/4 Dataform database、schema 関数使いたい
#Dataform #OSS
dataform-co/dataform@5148923 - core/compilers.ts#L125
ここに database, schema を足したら使えるんじゃないかな〜
database, schema といった関数が使えそうだけど、実際には使えない
on @dataform/core@2.4.2, @dataform/cli@2.4.2
ITableContext - Dataform core reference  |  Google Cloud
ここにあるのは ITableContext のメソッド
CommonContext - Dataform core reference  |  Google Cloud
CommonContext では schema や database を使える
Context methods are available when evaluating contextable SQL code, such as within SQLX files, or ...
なので使えてほしい
dataform-co/dataform@5148923 - core/table.ts#L365
ITableContext extends ICommonContext
database 関数増えたのは最近
Database function by a2wd · Pull Request 1438 · dataform-co/dataform
2.3 かな?
schema
Added schema function by a2wd · Pull Request 1432 · dataform-co/dataform
同じ頃
内部的にしか使わないつもりでやっているのかも
これはまあ issue で聞く
ビルドして実行してみる
dataform/contributing.md at main · dataform-co/dataform · GitHub
Error while resolving toolchains for target in @npm//@bazel/labs/grpc_web on M1 Mac (arm64) · Issue 2733 · bazelbuild/rules_nodejs
rules_nodejs/os_name.bzl at 004da08145bb6d54bb7355418444850d6b30a329 · bazelbuild/rules_nodejs
手元でパッチ当てて arm64 対応したつもりだが cpu-features でコケるなあ
rules_nodejs を 1.6 → 3.8 にして darwin_arm64 追加
他の依存とか @bazel/ パッケージも更新しないといけない
Version 0.0.3 installs on M1 Mac (ARM64) but fails at runtime · Issue 9 · mscdex/cpu-features
ヴォエー
Docker で --platform=linux/x86_64 してエミュレート
なんか全然うまくいかないが、キャッシュディレクトリを消しつつ何回かリトライするとビルドできることがある(なんじゃそりゃ)
ビルドできた!! と思ったけどおそすぎてtimeoutする
dataform-co/dataform@main - api/commands/compile.ts#L120
激重だしツラい
bazel server が x86 で動いててあらゆることが遅くなってそう
もう Linux でやるかと Cloud Shell で作業したら楽
Visual Studio CodeでGoogle Cloud Shellを開く - Qiita
cli のビルドはいけたがテストが落ちる
~/.cache でディスク埋まったあじゃぱー
5GBじゃたりん
integration test 実行に色々必要
Compute Engine のストレージを mount できねえのかな → できないらしい
適当な Compute Engine instance 立てるしかないのか?
C3 最高!!
https://gyazo.com/cd7c8bfa27f71c2bd4382675cae870dc
最初からこれにすりゃよかった
code:~/.ssh/config
Host computeengine
ProxyCommand gcloud compute ssh --zone "asia-southeast1-a" "dataform-dev" --project "pokutuna-playground" --ssh-flag='-W localhost:22'
User pokutuna
IdentityFile ~/.ssh/google_compute_engine
StrictHostKeyChecking no
こうして VSCode でつなぎに行って作業する、快適
bazel でビルドしたやつを使えるようにする
$ bazel build //packages/@dataform/cli:package //packages/@dataform/core:package
bazel-bin の生成物が置かれるところで npm link
$ cd bazel-bin/packages/@dataform/core/package && npm link
$ cd bazel-bin/packages/@dataform/cli/package && npm link
使う側でも link
うまく動いた...
ビルド対象列挙
$ bazel query ...
$ bazel build //packages/... で //packages 以下をまとめてビルド
テスト通らん
KMS 使ってるやん...
dataform-co/dataform@main - test_credentials/BUILD
code:error
ERROR: /home/pokutuna/dataform/test_credentials/BUILD:5:14: Action test_credentials/bigquery.json failed: (Exit 1): gcloud failed: error executing command external/gcloud_sdk/bin/gcloud kms decrypt '--ciphertext-file=test_credentials/bigquery.json.enc' '--plaintext-file=bazel-out/k8-py2-fastbuild/bin/test_credentials/bigquery.json' ... (remaining 4 arguments skipped)
ERROR: (gcloud.kms.decrypt) PERMISSION_DENIED: Request had insufficient authentication scopes.
- '@type': type.googleapis.com/google.rpc.ErrorInfo
domain: googleapis.com
metadata:
method: google.cloud.kms.v1.KeyManagementService.Decrypt
service: cloudkms.googleapis.com
reason: ACCESS_TOKEN_SCOPE_INSUFFICIENT
外部の人間が通せるわけなくないか
dataform-public プロジェクトの KMS が見れたらよい
$ gcloud --project=dataform-public kms decrypt --location=us --keyring=dataform-builder-keyring --key=dataform-builder-key --ciphertext-file=./test_credentials/bigquery.json.enc --plaintext-file=./bigquery.json
まあダメ
$ bazel test --build_tests_only -- ... -tests/integration/... -tests/cli/...
cli も credentials に依存している?
ようやく落ちるべきやつ以外落ちて走りきった
dataform-co/dataform@main - core/compilers.ts#L7
この compile メソッドは sandbox から呼ばれる
dataform-co/dataform@main - sandbox/vm/compile.ts#L25
---
GitHub のオープンソースプロジェクトへの Issue を作成して、問題を報告したいです
以下の内容を掲示板でコードの所有者に報告するような体裁にまとめてください
---
code:issue.md
- database(), schema() の関数が sqlx ファイル内で使えない
- これら関数は以下のプルリクエストで追加された機能
- https://github.com/dataform-co/dataform/pull/1438
- https://github.com/dataform-co/dataform/pull/1432
- ItableContext と CommonContext のドキュメントでは SQLX ファイル内で利用可能とある
- https://cloud.google.com/dataform/docs/reference/dataform-core-reference#commoncontext
- https://cloud.google.com/dataform/docs/reference/dataform-core-reference#itablecontext
- 利用できないことを確認したバージョンは最新の 2.4.2
- ユースケースは限られるが、私としてはサポートしてほしい
- BigQuery において以下のユースケースが考えられる
- operations で BigQuery データセット(schema)を削除する
- データセット中のテーブルの存在を確認して処理を分岐する
- プロジェクトの INFORMATION_SCHEMA を参照して利用状況などのテーブルを作る
- 追ってプルリクエストを送信します
---
code:issue_en.md
Title: database() and schema() functions not working within sqlx files
I've noticed that the database() and schema() functions, which were added in the following pull requests, cannot be used within sqlx files.
- #1432
- #1438
According to the documentation for ItableContext and CommonContext, these functions should be available for use within sqlx files
Context methods are available when evaluating contextable SQL code, such as within SQLX files, ...
- https://cloud.google.com/dataform/docs/reference/dataform-core-reference#itablecontext
- https://cloud.google.com/dataform/docs/reference/dataform-core-reference#commoncontext
These functions are not available in the latest version 2.4.2.
Are these functions intended for API-level use from core?
It would be helpful if these functions could be used from sqlx.
For BigQuery, the following use cases can be considered:
- Query usage with INFORMATION_SCHEMA in project(database) or dataset(schema)
- Check existence of table in dataset(schema) and branch processing
I will send a pull request to fix this issue shortly.
database() and schema() functions not working within sqlx files · Issue 1484 · dataform-co/dataform
Add schema & database to contextFunctions in compile time by pokutuna · Pull Request 1485 · dataform-co/dataform
---
code:issue2.md
GitHub のオープンソースプロジェクトへの Issue を作成して、問題を報告したいです
以下の内容を自然な英語に翻訳してください
---
以下にコントリビューター向けの案内があります
https://github.com/dataform-co/dataform/blob/f58bbddf599ba1efe3c1d927213c3209a4b8681b/contributing.md#L35-L43
このコマンドは以下の出力と共に失敗します
`
ERROR: /home/pokutuna/dataform/test_credentials/BUILD:5:14: Action test_credentials/bigquery.json failed: (Exit 1): gcloud failed: error executing command external/gcloud_sdk/bin/gcloud kms decrypt '--ciphertext-file=test_credentials/bigquery.json.enc' '--plaintext-file=bazel-out/k8-py2-fastbuild/bin/test_credentials/bigquery.json' ... (remaining 4 arguments skipped)
ERROR: (gcloud.kms.decrypt) PERMISSION_DENIED: Request had insufficient authentication scopes.
- '@type': type.googleapis.com/google.rpc.ErrorInfo
domain: googleapis.com
metadata:
method: google.cloud.kms.v1.KeyManagementService.Decrypt
service: cloudkms.googleapis.com
reason: ACCESS_TOKEN_SCOPE_INSUFFICIENT
`
これは暗号化されたシークレットに依存するテスト以外を実行するコマンドですが, 実際には tests/cli/ 以下のテストも Cloud KMS に依存しています。従って外部の開発者はテストを実行できません。
https://github.com/dataform-co/dataform/blob/f58bbddf599ba1efe3c1d927213c3209a4b8681b/tests/cli/BUILD#L17
Title: External contributors cannot execute test commands in contributing.md
ChatGPT に聞いたけどなんかネイティブすぎる & 日本語のせいかもってまわった感じになるので参考にしつつ手で書いた...
External contributors cannot pass the test commands in contributing.md · Issue 1483 · dataform-co/dataform