0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Databricks にて Spark-BQ コネクターによりテーブルを参照する際に必要な権限に関する検証

Last updated at Posted at 2025-05-01

概要

Databricks にて BigQuery から Spark-BQ コネクター(Apache Spark SQL connector for Google BigQuery)によりテーブルを参照する際に必要となる Google Cloud の権限に関する検証結果を共有します。検証の結果、下記の権限が必要となります。

  • BigQuery Data Viewer
  • BigQuery Read Session User

Databricks Federation を実施際の動作も確認します。Databricks Runtime 16.1 以降のクラスターでは Spark Connector が利用される仕様変更がされたため、 16.4 と 15.4 のバージョンでそれぞれ実行しています。仕様変更内容について下記の記事で整理しています。

本記事は下記シリーズの一部です。

image.png

出所:Databricks で BigQuery のデータを取得する方法の徹底ガイド - Qiita

事前準備

BigQuery にオブジェクトを作成

-- データセットを作成
CREATE SCHEMA IF NOT EXISTS `auth_test_01`;

-- テーブルを作成
CREATE OR REPLACE TABLE `auth_test_01.table_01` AS
SELECT *
FROM UNNEST([
  STRUCT(1 AS id, 'Alice' AS name, 100 AS score),
  STRUCT(2 AS id, 'Bob'   AS name,  95 AS score),
  STRUCT(3 AS id, 'Carol' AS name,  98 AS score)
]);


SELECT * FROM `auth_test_01.table_01`;

image.png

サービスアカウント作成後にキーを取得

image.png

BigQuery を Databricks の外部カタログに登録

image.png

Databricks にてノートブック作成後に実行するコードを記述

json_str = b"""{json_key}"""

image.png

import base64

encoded_string = base64.b64encode(json_str).decode('utf-8')

# プロジェクト ID を設定
parent_project_id = "axial-triode-XXXXX"

# データ取得元のテーブル名を設定
table_name = "auth_test_01.table_01"

df = (
    spark.read
    .format("bigquery")
    .option("parentProject", parent_project_id)
    .option("credentials", encoded_string)
    .option("table",table_name)
    .load()
)

df.limit(50).display()

権限検証

BigQuery Data Viewer権限の追加

権限不足によるエラーが発生します。

image.png

Py4JJavaError: An error occurred while calling t.addCustomDisplayData.
: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.com.google.api.gax.rpc.PermissionDeniedException: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.io.grpc.StatusRuntimeException: PERMISSION_DENIED: request failed: the user does not have 'bigquery.readsessions.create' permission for 'projects/axial-triode-XXXXX'

image.png

BigQuery Read Session User権限の追加

データを取得できます。

image.png

image.png

Databricks Lakehouse Fedearation の検証

Databricks Runtime 16.4 での実行可否確認

データを取得できます。

image.png

Databricks Runtime 15.4 での実行可否確認

権限不足によるエラーが発生します。

[FAILED_JDBC.UNCLASSIFIED] Failed JDBC jdbc: on the operation: Failed table existence check: auth_test_01.table_01 SQLSTATE: HV000

image.png

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?