2

I have a programmatically generated query for BigQuery. It has part like

select *,
       IF(cond1, val1, IF(cond2, val2, IF (cond3, val3, ...))) as x

But when the number of IFs grows, I start getting Fatal error: Reason: invalidQuery, message: BAD_QUERY (The query requires too many resources to parse)

I would like to know how many resources are available to parse the query and where those limits are documented. The query size itself is well under 256KB.

I didn't try yet, but wondering if rewriting query with

CASE WHEN THEN

might help here to stay under the limit.

Thank you.

1
  • FWIW, rewriting query with CASE/WHEN/THEN helped in my particular case, but I didn't check whether it can be as long as 256KB. Commented Jul 10, 2015 at 7:45

1 Answer 1

3

The limitation in this case is not static, and not on the length of the query, but rather on number of function nesting levels. BigQuery checks stack depth during parsing, and if it goes too deep - the error is raised. Every function that could go deep, has variadic version, i.e. CONCAT with multiple arguments, CASE instead of IF - and this is a preferred solution for cases like that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.