Code Monkey home page Code Monkey logo

Comments (4)

tylertreat avatar tylertreat commented on September 13, 2024

I'm not sure if I like this over the current design. For example, with query, it's perfectly reasonable to set timeout=0. This simply means the query is submitted and the results will be fetched at some point in the future. It wouldn't make sense to force people to catch an exception there. I think the current design encourages people to think asynchronously, which they should.

That's not to say the API can't be improved. Maybe using futures would make more sense?

job_id, results_future = client.query('SELECT * FROM dataset.my_table LIMIT 1000')
try:
    results_future.result(timeout=5)
except TimeoutException:
    print "Timeout"

Just something to think about.

from bigquery-python.

pirsquare avatar pirsquare commented on September 13, 2024

How about setting query timeout default value to 0 so that it will run asynchronously by default or when the user wants to?

My suggestions was because there isn't a straightforward way to know if a query is returning empty list due to timeout or due to empty result.

If users wants to run asynchronously, they can still use

job_id, _results = client.query('SELECT * FROM dataset.my_table LIMIT 1000')
# Do other stuffs
complete, row_count = client.check_job(job_id)
if not complete:
    print "Timeout

If they want to run in synchronous manner with timeout, they can use

try:
    job_id, results = client.query('SELECT * FROM dataset.my_table LIMIT 1000', timeout=5)
except BigQueryTimeoutException:
    print "Timeout"

Futures is another possible way but I'm biased here and I prefer the appoarch above =). For my use case, I need to run queries in a synchronous way with timeouts since the second query depends on the first query. Async would still work here, though not as clean as I wanted it to be.

from bigquery-python.

tylertreat avatar tylertreat commented on September 13, 2024

Yes, I like the synchronous approach you describe and defaulting to async. That makes sense to me.

from bigquery-python.

pirsquare avatar pirsquare commented on September 13, 2024

Great, I'll follow up with a PR

from bigquery-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.