All of a sudden starting today (2023-12-13) I cannot save Results to a BQ Table. I tried by saving from the editor and also tried scheduling the query, specifying the output table. It seems to be confined to just one query. Actually, I see that query tables that I was able to write yesterday will no longer write.
I am the Owner of the account and should have all perms to allow basically any operation, incl. writing tables, etc.
Has anyone else ever encountered this issue?
Error code 7 : Access Denied: Table ps-analytics-329721:XT_Web_Logs.qt_Ford_Month: Permission bigquery.tables.get denied on table ps-analytics-329721:XT_Web_Logs.qt_Ford_Month (or it may not exist).
Solved! Go to Solution.
It's good to hear that you were able to create a new table using the CREATE OR REPLACE TABLE
statement with your query. This indicates that you do have the necessary permissions to create and write to a table in BigQuery. The issue seems to be specific to the way you were initially trying to save the query results to a table.
Given this new information, here are a few additional considerations:
Query Execution Context:
CREATE OR REPLACE TABLE
as part of your query, it directly creates or replaces a table with the result set of the query. This is a different operation compared to running a query and then saving the results to a table. The former is a DDL (Data Definition Language) operation, while the latter is more of a DML (Data Manipulation Language) operation followed by a write operation.Permissions for Different Operations:
Interface or Tool-Specific Issues:
Query Complexity:
CREATE OR REPLACE TABLE
approach might be more robust in handling such complexities.Next Steps:
CREATE OR REPLACE TABLE
approach works for your needs, it might be a good workaround for the issue you're facing. However, if you need to use the original method (running a query and then saving the results), you might want to explore different tools or interfaces, or even reach out to Google Cloud Support for more specific guidance.While the root cause of the initial issue isn't entirely clear, the successful creation of a table using a different method suggests that it might be related to the specific way you were trying to save the results initially. Exploring alternative methods or tools could be a practical next step.
Here are a few suggestions:
Check for UI-Specific Limitations or Bugs:
Use CREATE TABLE
as a Workaround:
CREATE TABLE
approach works, you can use it as a workaround. If you need to regularly update the table with new data, you can modify the query to use CREATE OR REPLACE TABLE
, which will overwrite the existing table with new data.Scheduling the Query:
CREATE TABLE
or CREATE OR REPLACE TABLE
statement. The query itself will handle the creation and filling of the table.Contact Google Cloud Support:
Here are some steps you can take to troubleshoot and resolve this issue:
Check IAM Permissions:
BigQuery Admin
or BigQuery Data Editor
, which allow for table creation and data manipulation.Examine the Specific Table:
ps-analytics-329721:XT_Web_Logs.qt_Ford_Month
. Verify that this table exists and that you have the necessary permissions to access and modify it. If the table doesn't exist, the error might be misleading, and the real issue could be with table creation.Review Recent Changes:
Try a Different Query or Table:
Use the bq
Command-Line Tool:
bq
command-line tool to attempt the same operation. Sometimes, the command-line tool provides more detailed error messages.Review Quotas and Limits:
Inspect the Query:
Check Dataset Permissions:
XT_Web_Logs
as well, not just the table.Thank you. I am now going to go thru the checklist and do each of those steps. I will post results and let you know what happened.
2. Examine the Specific Table: - I believe this is misleading bc it's a new table I am trying to write, so it does NOT exist yet
3. Review Recent Changes: - I've not touched IAM perms in many months (years?)
4. Try a Different Query or Table:
Well this is interesting. I tried a brain-dead simple query and was able to export the results to a BQ Table. Now, one thing I notice is that the original query (that I referenced) is under the category of "Shared queries". The one I was able to run is under "(Classic) Queries (122)->"Project queries". Could that be causing this? I rarely use the resident BQ Editor anymore. I switched over to using Coginiti for editing, but that product doesnt support reading JSON tables so I created the new queries in BQ. But again, it was working yesterday...
SELECT DISTINCT
*,
DATE_TRUNC(CURRENT_DATE(), WEEK(MONDAY)) AS HistoryWeek
FROM `ps-analytics-329721.Query_Tables.qt_LoE_Perf`
5. Use thebqCommand-Line Tool: - I am not familiar with using the bq CMD line so I'd need to figure that out.
6. Review Quotas and Limits: - Hmmm I am seeing this "Current usage > 90%". When I go to "Edit Quota", there no Quotas to choose. Could this be the issue?
7. Inspect the Query:
# Day 1
SELECT
meta.count,
meta.`completed-in`,
data.country,
data.language,
(SELECT STRING_AGG(CAST(entityTags AS STRING), '\n') FROM UNNEST(data.entityTags) entityTags) AS entityTags,
(SELECT STRING_AGG(modelTags, '\n') FROM UNNEST(data.modelTags) modelTags) AS modelTags,
(SELECT STRING_AGG(makeTags, '\n') FROM UNNEST(data.makeTags) makeTags) AS makeTags,
data.sa,
data.messageType,
(SELECT STRING_AGG(classTags, '\n') FROM UNNEST(data.classTags) classTags) AS classTags,
data.published,
data.author,
data.content,
data.link,
data.queue,
(SELECT STRING_AGG(userTags, '\n') FROM UNNEST(data.userTags) userTags) AS userTags,
data.title,
data.dataSource,
data.threadId,
data.dataCategory,
data.id,
DATE_TRUNC(CAST(data.published AS DATE), DAY) AS min_Week,
DATE_ADD(CAST(data.published AS DATE), INTERVAL 1 WEEK) AS max_Week
FROM `ps-analytics-329721.XT_Web_Logs.xt_Ford_01` CROSS JOIN UNNEST(`data`) as data
WHERE
(data.dataSource LIKE '%Mustang%' OR data.dataSource LIKE '%F150%' OR data.dataSource LIKE '%Escape%')
AND data.messageType ='public'
AND (data.country ='USA' OR data.country='Canada')
AND data.queue <> 'Not Relevant'
UNION ALL
# Day 2
Repeats for 31 Days ...
I am wondering if this is because the data is JSON and has repeatable sections?
Based on the detailed information you've provided, there are a few key points to consider that might be causing the issue with saving results to a BigQuery table:
IAM Permissions:
bigquery.tables.create
or bigquery.tables.update
. These permissions are crucial for creating new tables or updating existing ones. It's worth checking if these permissions are included in any of the roles you have.Shared Queries vs. Project Queries:
Quotas and Limits:
Complexity of the Query:
JSON Data and Table Structure:
Dataset Permissions:
Given these points, here are some steps to take:
I will recheck everything, as you suggest. Btw, yes the UNION is complex. But even when I dont union tables 2-31, I still get the error. So it's not the UNION.
Guess what. When I wrap the query in a CREATE Table, the table gets created no problem:
CREATE OR REPLACE TABLE
XT_Web_Logs.qt_Ford_Month (
datePublished DATE,
count INT64, --1
`completed-in`INT64, --2
country STRING, --3
`language` STRING, --4
entityTags STRING, --5
modelTags STRING, --6
makeTags STRING, --7
sa STRING, --8
messageType STRING, --9
classTags STRING, --10
published TIMESTAMP,--11
author STRING, --12
content STRING, --13
link STRING, --14
queue STRING, --15
userTags STRING, --16
title STRING, --17
dataSource STRING, --18
threadId STRING, --19
dataCategory STRING, --20
id STRING, --21
min_Week DATE,
max_Week DATE
)
AS (
WITH
# All Days
Month AS...
It's good to hear that you were able to create a new table using the CREATE OR REPLACE TABLE
statement with your query. This indicates that you do have the necessary permissions to create and write to a table in BigQuery. The issue seems to be specific to the way you were initially trying to save the query results to a table.
Given this new information, here are a few additional considerations:
Query Execution Context:
CREATE OR REPLACE TABLE
as part of your query, it directly creates or replaces a table with the result set of the query. This is a different operation compared to running a query and then saving the results to a table. The former is a DDL (Data Definition Language) operation, while the latter is more of a DML (Data Manipulation Language) operation followed by a write operation.Permissions for Different Operations:
Interface or Tool-Specific Issues:
Query Complexity:
CREATE OR REPLACE TABLE
approach might be more robust in handling such complexities.Next Steps:
CREATE OR REPLACE TABLE
approach works for your needs, it might be a good workaround for the issue you're facing. However, if you need to use the original method (running a query and then saving the results), you might want to explore different tools or interfaces, or even reach out to Google Cloud Support for more specific guidance.While the root cause of the initial issue isn't entirely clear, the successful creation of a table using a different method suggests that it might be related to the specific way you were trying to save the results initially. Exploring alternative methods or tools could be a practical next step.
Thanks. Btw, I was just using the BQ Web UI "Save Results" to a BQ Table. That's how I got/get the Error 7. Funny thing is that when I Save Results to a Sheet, it works fine. I have never encountered this before and frankly dont know what's going on cause even with no union, e.g., 1 table, it still fails. I guess (I hope) I can still schedule the current query version (with the CREATE Table) to run per schedule. I assume I would just not add a Table name to save results. I do this type of thing when I train ML models, so I expect that should be ok.
Here are a few suggestions:
Check for UI-Specific Limitations or Bugs:
Use CREATE TABLE
as a Workaround:
CREATE TABLE
approach works, you can use it as a workaround. If you need to regularly update the table with new data, you can modify the query to use CREATE OR REPLACE TABLE
, which will overwrite the existing table with new data.Scheduling the Query:
CREATE TABLE
or CREATE OR REPLACE TABLE
statement. The query itself will handle the creation and filling of the table.Contact Google Cloud Support: