Мой запрос состоит в том, что я хочу получить данные из таблицы, и этот запрос отлично работает в редакторе Big Query. но я хочу создать функцию Google Cloud, чтобы иметь API и получать доступ к этому запросу напрямую по URL-адресу.
Я создал учетную запись службы с помощью этой команды:
Код: Выделить всё
gcloud iam service-accounts create connect-to-bigquery
gcloud projects add-iam-policy-binding test-24s --member="serviceAccount:connect-to-bigquery@test-24s.iam.gserviceaccount.com" --role="roles/owner"
Создание облачной функции
Настройки учетной записи службы
Вот мой код для файла main.py:
Код: Выделить всё
from google.cloud import bigquery
def hello_world(request):
client = bigquery.Client()
query = "SELECT order_id, MAX(status) AS last_status FROM `test-24s.Dataset.Order_Status` GROUP BY order_id"
query_job = client.query(query)
print("The query data:")
for row in query_job:
print("name={}, count ={}".format(row[0], row["last_status"]))
return f'The query run successfully'
Код: Выделить всё
# Function dependencies, for example:
# package>=version
google-cloud-bigquery
Код: Выделить всё
Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Details:
500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Код: Выделить всё
403 Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.
Подробнее здесь: https://stackoverflow.com/questions/700 ... ion-python