以下の内容はhttps://yujiorama.hatenablog.com/entry/hatenaadvent2024より取得しました。


Implementing Google BigQuery REST API (v2) jobs.query

これは はてなエンジニア Advent Calendar 2024 25日目の記事です。

github.com

Google BigQuery REST API (v2)のjobs.query を実装した Perl モジュールを作りました。

おすすめポイント

  • 列の値をフラットな hashref へ変換します
    • ->{f}->[0]->{v} みたいな値の探り方をしなくていいので便利です
    • なぜこういうデータ構造になっているのか全然わからない
  • 列の値のデータ型を JSON Schema で定義できるようになっています
    • データ入出力の境界には型があると安心です

やったこと

MinillaPerlモジュールの雛形を作るだけでした。簡単。

モジュールを作ろうと思った理由

Google::BigQueryDiscovery document という仕組みを使っていて、リクエスト先のURLを実行時に組み立てるようになっています。

しかし、いつからか Discovery document の返り値の path 要素に含まれるパス変数の形式が変化してしまい、動かなくなってしまっていました。

  • 期待値 projects/{projectId}/queries
  • 実際の値 projects/{+projectId}/queries
    •   "query": {
          "description": "Runs a BigQuery SQL query synchronously and returns query results if the query completes within a specified timeout.",
          "flatPath": "projects/{projectsId}/queries",
          "httpMethod": "POST",
          "id": "bigquery.jobs.query",
          "parameterOrder": [
            "projectId"
          ],
          "parameters": {
            "projectId": {
              "description": "Required. Project ID of the query request.",
              "location": "path",
              "pattern": "^[^/]+$",
              "required": true,
              "type": "string"
            }
          },
          "path": "projects/{+projectId}/queries",
          "request": {
            "$ref": "QueryRequest"
          },
          "response": {
            "$ref": "QueryResponse"
          },
          "scopes": [
            "https://www.googleapis.com/auth/bigquery",
            "https://www.googleapis.com/auth/cloud-platform",
            "https://www.googleapis.com/auth/cloud-platform.read-only"
          ]
        }
      

やらなかったこと

CPANへの登録

perlnewmod - 新しいモジュールを配布するには - perldoc.jp を読んで片手間ではやりきれんな、と思ってやめました。

Google::BigQuery に変更を提案

10年前に作られたモジュールで、GitHub リポジトリも消えているので、これ以上時間かけてもな、と思ってやめました。

明日の担当は id:k1s1eee さんです。




以上の内容はhttps://yujiorama.hatenablog.com/entry/hatenaadvent2024より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14