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

cursor.list_tables() is returning views as well #591

Open
vi3k6i5 opened this issue Sep 27, 2021 · 3 comments
Open

cursor.list_tables() is returning views as well #591

vi3k6i5 opened this issue Sep 27, 2021 · 3 comments
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@vi3k6i5
Copy link
Contributor

vi3k6i5 commented Sep 27, 2021

cursor.list_tables() is returning views as well

Environment details

  • OS type and version: Mac, latest
  • Python version: python --version 3.9
  • google-cloud-spanner 3.10.0

Steps to reproduce

  1. Create a view
  2. cursor.list_tables() # will return the view as well.

Thanks!

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Sep 27, 2021
@vi3k6i5 vi3k6i5 assigned vi3k6i5 and larkee and unassigned larkee Sep 27, 2021
@vi3k6i5
Copy link
Contributor Author

vi3k6i5 commented Oct 5, 2021

@larkee : what would be the right way to fix this, should we add a parameter in this method

cursor.list_tables(include_views=<boolean>)

based on the value of include_views it will include views?

Another approach would be to not modify the method signature and update the query to return only tables.
Create a separate method to list views?

cursor.list_tables() # returns list of tables. <backend Sql will be updated for this>
cursor.list_views() # returns list of views.

Any other suggestion is welcome.

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Nov 3, 2021
@skuruppu skuruppu added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Dec 7, 2021
@rajatbhatta
Copy link
Contributor

Spanner treats both tables and views as tables, and the nomenclature is BASE TABLE for standard tables, and VIEW for views. (Reference)

IMO, we can consider going with the first approach and have the include_views as True by default (to match the spanner nomenclature as mentioned above).
We can have separate SQL statements being executed based on the flag.

// Includes both base tables and views (include_views is true - default)

SQL_LIST_TABLES = """
SELECT table_name
FROM information_schema.tables
WHERE table_catalog = '' AND table_schema = ''
"""

// Includes only base tables (include_views is false)

SQL_LIST_BASE_TABLES = """
SELECT table_name
FROM information_schema.tables
WHERE table_catalog = '' AND table_schema = '' AND table_type = 'BASE TABLE'
"""

@asthamohta
Copy link
Contributor

I agree with Rajat
Suddenly creating two functions as you suggested might be a breaking change for people who might be using this fxn already and want views. Rather we can set default value to true and then if people want they can set it to false.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 26, 2022
@ansh0l ansh0l removed the 🚨 This issue needs some love. label May 14, 2022
@ansh0l ansh0l assigned asthamohta and unassigned vi3k6i5 and larkee May 14, 2022
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

7 participants