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 にて BigQuery のビューを参照する際の Access Denied エラーに対する対応方法

Last updated at Posted at 2025-05-01

概要

BigQuery でテーブルとビューが異なるデータセットにある場合、ビュー(またはビューのデータセット)に対してのみ参照権限を付与すると、下記のようなエラーが発生することがあります。

Py4JJavaError: An error occurred while calling t.addCustomDisplayData.
: bigquery.storageapi.shaded.com.google.cloud.bigquery.connector.common.BigQueryConnectorException: Error creating destination table using the following query: [SELECT id,name,score FROM axial-triode-368703.view_dataset_01.view_01 ]

Caused by: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.com.google.common.util.concurrent.UncheckedExecutionException: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryException: Access Denied: Table axial-triode-368703:source_dataset_01.table_01: User does not have permission to query table axial-triode-368703:source_dataset_01.table_01, or perhaps it does not exist.

image.png

テーブルのデータセット自体には権限を付与しない前提で、次の2つの方法で対応可能です。

  1. Authorize Datasets を設定する
  2. Authorize View を設定する

本記事では、エラー発生時の状況とそれに対する対応策を紹介します。

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

image.png

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

事前準備

BigQuery でテーブルとビューを別々のデータセットに作成

-- テーブルを作成
CREATE SCHEMA IF NOT EXISTS `source_dataset_01`;
CREATE OR REPLACE TABLE `source_dataset_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)
]);


-- ビューを作成
CREATE SCHEMA IF NOT EXISTS `view_dataset_01`;
CREATE OR REPLACE VIEW `view_dataset_01.view_01` AS
SELECT * FROM `source_dataset_01.table_01`;


SELECT * FROM `view_dataset_01.view_01`;

image.png

サービスアカウント作成後にキーを発行

image.png

プロジェクトレベルで BigQuery Job UserBigQuery Read Session User を付与

image.png

ビューのデータセットに対して BigQuery Data Editor を付与

image.png

エラーの発生方法

Databricks で BigQuery のビューを参照

Py4JJavaError: An error occurred while calling t.addCustomDisplayData.
: bigquery.storageapi.shaded.com.google.cloud.bigquery.connector.common.BigQueryConnectorException: Error creating destination table using the following query: [SELECT id,name,score FROM axial-triode-368703.view_dataset_01.view_01 ]

Caused by: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.com.google.common.util.concurrent.UncheckedExecutionException: bigquery.storageapi.shaded.com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryException: Access Denied: Table axial-triode-368703:source_dataset_01.table_01: User does not have permission to query table axial-triode-368703:source_dataset_01.table_01, or perhaps it does not exist.

image.png

対応方法

1. Authorize Datasets を設定する

1-1. ソースのデータセット画面で Sharing -> Authorize Datasets を選択

image.png

1-2. ビューのデータセットを指定し、Add Authorization を選択

image.png

1-3. Databricks でデータが取得できることを確認

image.png

2. Authorize View を設定する

2-1. ソースのデータセット画面で Sharing -> Authorize Views を選択

image.png

2-2. ビューを指定し、Add Authorization を選択

image.png

2-3. Databricks でデータが取得できることを確認

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?