How to solve undeclared query parameters error in biqquery? - google-bigquery

SELECT
#run_date,
Country_PG,
SUM(Weighted_Revenue) AS Weighted_Pipe
FROM
`revenue.data`
GROUP BY
1,2
When I run this query I am getting an undeclared query error for #run_date.
How do I solve this error?
For your information: this is a scheduled query.

When you are running the query manually, it is expected to fail if #run_date is not defined (by you).
When you are running it as scheduled query, based on documentation #run_date should be passed in by BigQuery, if you got error telling #run_date is not defined, create a bug to BigQuery here.

When you attempt to test a scheduled query with either the parameter #run_date or #run_time in the UI it will return the error: "Undeclared query parameters"
However, when run as part of a backfill or at the scheduled time it will work correctly.
This is a bit ugly from a UI standpoint, but in order to test the scheduled query you should use the BQ command line as stated in the documentation

Related

Datastudio BigQuery connector: The query returned an error

When creating a BigQuery data connector for Google Data Studio, my query works until I attempt to parameterize some fields. As soon as I add parameters, I get the unhelpful and unspecific error:
The query returned an error.
Error ID: xyz
How can I figure out what the underlying issue is that is causing this problem?
1. Check BigQuery Logs in Cloud Logging
If there is an error executing a query in BigQuery, the underlying cause will likely be visible in Cloud Logging. In Cloud Logging, execute this query to show these errors, and hopefully get insight into the underlying problem:
resource.type="bigquery_resource"
severity=ERROR
Its possible these logs will show that the query is failing because the format of certain data is invalid -- in that case its likely because having no default values for parameters is preventing the BigQuery query from succeeding. In that case:
2. Give Parameters Default Values
The connector passes the query to BigQuery, which executes it. In order for this to work correctly, the parameters need to have some values. Provide them in the form of parameter default values that will result in a valid query.

DataGrip only executing first 19 lines of SQL query

I'm attempting to execute a 236 line query in DataGrip in an attached BigQuery console. When I select the whole script to run, it always only executes up to the 19th line. Because of that, I get this error
[HY000][100032] [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Syntax error: Unexpected end of script at [19:49] com.simba.googlebigquery.support.exceptions.GeneralException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Syntax error: Unexpected end of script at [19:49]
I've tried running it as a SQL file as well, but that resulted in the same error. I Know that this query is valid because it returns the desired results when I run it directly in the Google Cloud query editor. Has anyone else run into this issue, and is there a fix?
We introduced BigQuery dialect recently and it does not apply to your previously created data source after update, since this data source was created with custom driver with 'Generic' dialect as default. It is needed to change dialect in driver options, then you'll have all related consoles and datasources with correct one.

Google BigQuery Scheduling Query error on Manual Run

I can successfully run Bigquery Scheduled Queries with #Run_time, #run_date parameters.
You can review Google's inadequate documentation on https://cloud.google.com/bigquery/docs/scheduling-queries
But when I try, manual run fails; "Error in starting transfer runs: Request contains an invalid argument. Dismiss" not any detail :(
Example code: (please be attentions i use #run_date)
Destination table: test_{run_time|"%Y%m%d"}
The parameter named table serves to create a different table for each day.
For example
test_20181112
test_20181113 etc.
SELECT
#run_date AS mydate,
title,
author,
text
FROM `bigquery-public-data.hacker_news.stories`
LIMIT
10
I think the problem is caused by the #run_date parameter in the query during manual operation.
My project is a little more complicated, I've added this code so everyone can try it easily.
 
As I mentioned above, this scheduled task works correctly in the initial setup. But when I try to run manual, it gives an error.
Can you show me the way?
Thanks for your helps.
I think that there is a bug in manunal run.
You should choose carefully the start date and the end date ( the same as a previous run ) in order to not get this error
I just wanted to add something here, since this is a "gotcha" in the BigQuery UI: using today's date as the end date in a scheduled query run will cause an issue, but setting it to one day ahead (i.e. tomorrow) should allow you to create a request with #run_date set to today.

"Invalid snapshot time" error without table decorator usage

We got an error that {"message":"Invalid snapshot time 1472342794519, unable to read before 1472342794785","reason":"invalid"}. Other QA describes that such an error happens when table decorators' parameters are invalid, however, our query does not have table decorators.
The query uses TABLE_DATE_RANGE, but its arguments are date timestamp, so the lower digits must be 0s, not like that in the above error.
Retrying the same query succeeded.
I can provide the job ID, but because it includes internal information of our company. I apologize that I cannot directly write it here.
The tables that the TABLE_DATE_RANGE wildcard evaluates to are resolved as of the time of the start of the query. Looking at the timestamps, it looks like the table was deleted right after the job started execution. This causes the table resolution to throw that error.

BigQuery executing only one query

I'm trying to run a query in the UI, but I get the error:
Error: 6.1 - 0.0: Only one query can be executed at a time.
I don't think there is any other queries running, and this has lasted for a while now. Surely it can handle more than one query at a time?? How long will this be stuck? How can I turn bigquery off and on again :p
This error means that the query string has been parsed as containing multiple queries. Check that you do not have multiple top-level SELECT statements in the query text box.
From the specific message, I would guess your second query begins on or around line 6.