Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes queries return nil, second execution returns results #22

Open
vanetten opened this issue Jun 12, 2015 · 5 comments
Open

Sometimes queries return nil, second execution returns results #22

vanetten opened this issue Jun 12, 2015 · 5 comments

Comments

@vanetten
Copy link

Thank you BTW.

I've been using BigBroda for several months against VERY large BigQuery databases.

I have an issue where queries occasionally return nil.

If I reload the same query, it works fine the second time.
My gut tells me this is a BigQuery "too big" or "timeout" issue.
Where the second execution, BigQuery has cached the result.
Have you ever seen this?
Any workarounds?

Bill

@michelson
Copy link
Owner

Its hard to tell what might be the problem , but it could be the cache thing that you mention
how large is your dataset ?
ps: I'm sorry by the delay , I'm on vacations right now and my response time could be slow

@vanetten
Copy link
Author

The largest table is 3TB.
As I mentioned, occasionally queries return nil, then return what they're supposed to on reload.
I can deal with that, but I would like to rescue from it somewhere.
Can't figure out what to code to catch the error.
Hate to place a rescue around every single big BigQuery query.

@michelson
Copy link
Owner

yeah , but it seems to be not an exception to catch, is a nil object instead. so a retry with a timeout is needed.

this behavior occurs only for the first query or this occurs for the subsequents ones?

@vanetten
Copy link
Author

Found a solution to my issue!!!
Retry on result['jobComplete'] == false.
I will fork and generate a pull request.

class JobIncomplete < Exception
end
def exec_query(sql, name = nil, binds = [])
log(sql, name, binds) do
result = nil
Retriable.retriable on: JobIncomplete, tries: 10 do
result = BigBroda::Jobs.query(@config[:project], {"query"=> sql })
unless result['jobComplete']
log("BigQuery Job Incomplete, trying again, #{Time.now}", nil) {}
raise JobIncomplete
end
end
cols = result["schema"]["fields"].map{|o| o["name"] }
records = result["totalRows"].to_i.zero? ? [] : result["rows"].map{|o| o["f"].map{|k,v| k["v"]} }
stmt = records
ActiveRecord::Result.new(cols, stmt)
end
end

@michelson
Copy link
Owner

that's great @vanetten. I'll be looking for that PR.

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants