Git Product home page Git Product logo

Comments (5)

gforsyth avatar gforsyth commented on August 28, 2024 1

So, as a workaround, I had to figure out every exception and catch specific ones depending on backend.

Welcome to Ibis! 😀

from ibis.

jcrist avatar jcrist commented on August 28, 2024

the best way to check table existence is by running table_name in list_tables(like=table_name)

Depending on what you intend to do if it does exist, it might be more efficient to do con.table(table_name) and branch if that operation fails. In the case it exists though, creating the table will do some work to fetch the schema and construct a ibis.Table object.

try:
    t = con.table(table_name)
except Exception:
    # table doesn't exist
    ...
else:
    # table does exist
    ...

That said, a builtin method on con just checking for existence could definitely be made more efficient.

Can you comment a little more on your use case here? In what cases are you checking for the existence of tables?

from ibis.

asiunov avatar asiunov commented on August 28, 2024

Thank you for your reply @jcrist

The problem with this approach is that Exception is too broad; what if some sort of connection failure happens? Table existence is not checked in this case. And there is no any specific exception for missing table error: all implementations of backend.table(...) raise their own exception types. So, as a workaround, I had to figure out every exception and catch specific ones depending on backend.

About the use case: I develop a service that manages tables, I do not work with hardcoded table names, they are supplied by users. User provides a table name and the service needs to check whether the table exists.

from ibis.

jcrist avatar jcrist commented on August 28, 2024

I develop a service that manages tables, I do not work with hardcoded table names, they are supplied by users. User provides a table name and the service needs to check whether the table exists.

What actions do you do if the table exists already? What do you do if it doesn't exist?

Not asking to argue against adding table_exists (or some other equivalent method with a different name), just wondering if there are other methods where we might want to add overwrite, or exists_ok kwargs to to improve this usecase.

from ibis.

asiunov avatar asiunov commented on August 28, 2024

What actions do you do if the table exists already? What do you do if it doesn't exist?

Mostly 2 cases:

  1. create_table. In this case, it would be nice to have a syntax that runs create table if not exists. In some cases it is helpful to get as a result whether the table was created or existed before (so to make some actions on it, like migration or data cleanup).
  2. some business logic, i.e. there is no immediate calls to Ibis afterwards, or it requires some mode complex custom logic before any further Ibis method is called.

from ibis.

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.