You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Begin a QueryJob without waiting for it to finish #5435
In previous versions of the BQ python client, there was a method in QueryJob (or maybe _AsyncJob) called begin() that began the job without waiting for it to finish. There doesn't appear to be an equivalent of that anymore, despite the presence of other methods like done(), exists(), running(), etc. that depend on a job having been run asynchronously. Would it be possible to add back the begin() method?
PR #4242 renamed the begin method to _begin, making it private: the expected usage pattern is that the caller use job.result() to begin the job, and then use the future it returns.
I can explain my use case a little more: I'm trying to start a query and print out the query if there's syntax error. The following code does not work:
try:
return query_job.result()
except GoogleCloudError as e:
msg = str(e)
# This craziness puts line numbers next to the SQL.
lines = query.split('\n')
longest = max(len(l) for l in lines)
# Print out a 'ruler' above and below the SQL so we can judge columns.
ruler = ' ' * 4 + '|' # Left pad for the line numbers (4 digits plus ':')
for _ in range(longest / 10):
ruler += ' ' * 4 + '.' + ' ' * 4 + '|'
header = '-----Offending Sql Follows-----'
padding = ' ' * ((longest - len(header)) / 2)
msg += '\n\n{}{}\n\n{}\n{}\n{}'.format(padding, header, ruler, '\n'.join(
'{:4}:{}'.format(n + 1, line) for n, line in enumerate(lines)), ruler)
raise RuntimeError(msg)
Because the Retry object has a try/except block, so having this method in a try/except will bypass the Retry functionality due to nested try/excepts being weird in python.
What I want to do is begin the job, then check the job for errors periodically, and print the query and error if there are any errors and continue if the job executed successfully.
Activity
tseaver commentedon Jun 4, 2018
PR #4242 renamed the
beginmethod to_begin, making it private: the expected usage pattern is that the caller usejob.result()to begin the job, and then use the future it returns.@tswast I'll defer to your opinion here.
bencaine1 commentedon Jun 4, 2018
I can explain my use case a little more: I'm trying to start a query and print out the query if there's syntax error. The following code does not work:
Because the Retry object has a try/except block, so having this method in a try/except will bypass the Retry functionality due to nested try/excepts being weird in python.
What I want to do is begin the job, then check the job for errors periodically, and print the query and error if there are any errors and continue if the job executed successfully.
bencaine1 commentedon Jun 4, 2018
It actually looks like _begin is called when the query_job is created via Client.query(). So you can actually close this ticket. Thanks!
tswast commentedon Jun 4, 2018
@bencaine1 Is correct. Calling
Client.query()starts the job. No need to callresult()if you don't need to wait for it to finish.