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

fix: correct get_view_names for older sqlalchemy #393

Closed
wants to merge 11 commits into from

Conversation

alitrack
Copy link
Contributor

@alitrack alitrack commented Aug 26, 2022

  • fix bug
AttributeError: 'Connection' object has no attribute 'exec_driver_sql'
  • add schema support.

BEGIN_COMMIT_OVERRIDE
fix: add schema support to get_view_names
END_COMMIT_OVERRIDE

@conventional-commit-lint-gcf
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

Copy link

@forestlzj forestlzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basing on my testing in superset 2, i have those comments. please review

s = "SELECT name FROM sqlite_master WHERE type='view' ORDER BY name"
rs = connection.exec_driver_sql(s)
s = f"SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' and table_schema=?"
rs = connection.execute(s, schema if schema is not None else "main")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to use fetchall() to get the query result
rs = connection.execute(s, schema if schema is not None else "main").fetchall()

@@ -207,7 +207,7 @@ def get_view_names(
include: Any = ...,
**kw: Any,
) -> Any:
s = "SELECT name FROM sqlite_master WHERE type='view' ORDER BY name"
rs = connection.exec_driver_sql(s)
s = f"SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' and table_schema=?"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is filter condition: table_type='VIEW' required? since it is also called from superset - list table function, in such case, no need this filter or specify table_type= 'Base Table'

Copy link
Owner

@Mause Mause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs some work, many tests are broken

I'd also like to see a new test covering the new schema usage

@codecov
Copy link

codecov bot commented Sep 7, 2022

Codecov Report

Merging #393 (10b8153) into master (53c3961) will decrease coverage by 0.34%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #393      +/-   ##
==========================================
- Coverage   93.46%   93.11%   -0.35%     
==========================================
  Files           8        8              
  Lines         459      465       +6     
==========================================
+ Hits          429      433       +4     
- Misses         30       32       +2     
Impacted Files Coverage Δ
duckdb_engine/__init__.py 90.57% <75.00%> (-1.09%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Mause Mause changed the title fix bug of get_view_names fix: correct get_view_names for older sqlalchemy Sep 7, 2022
@alitrack
Copy link
Contributor Author

alitrack commented Sep 7, 2022

just notice,
Superset does not support sqlalchemy 1.4 and newer,
so does not support exec_driver_sql

so for new version sqlalchemy,

s = f"SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' and table_schema=%s "
schema = schema if schema is not None else "main"
rs = connection.exec_driver_sql(s % schema)

and for old version, should

s = f"SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' and table_schema=? "
schema = schema if schema is not None else "main"
rs = connection.execute(s ,schema)
``

or view will not show.

alitrack and others added 2 commits September 7, 2022 16:57
supports both old and new version sqlalchemy and supports schema
@Mause
Copy link
Owner

Mause commented Sep 7, 2022

Which old versions of sqlalchemy are you trying to support?

@Mause
Copy link
Owner

Mause commented Sep 7, 2022

It looks like the current superset version only supports >=1.4

https://github.com/apache/superset/blob/master/setup.py#L118

@alitrack
Copy link
Contributor Author

alitrack commented Sep 7, 2022

the last release version apache superset 2.0 still needs <1.4
and need another parameter: schema
image

@Mause
Copy link
Owner

Mause commented Sep 8, 2022

I've merged most of these changes in another pr, #404 so thanks for those. The remaining changes don't seem to be required and in fact introduce a potential security issue

The fixes will be released shortly

@Mause Mause closed this Sep 8, 2022
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

Successfully merging this pull request may close these issues.

3 participants