-
Notifications
You must be signed in to change notification settings - Fork 14k
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(dataset): create ES-View dataset raise exception #16623 #16624
Conversation
Hi @aniaan, Thanks for the fix. Could you fix failed CI? |
superset/connectors/sqla/utils.py
Outdated
@@ -43,7 +43,7 @@ def get_physical_table_metadata( | |||
# ensure empty schema | |||
_schema_name = schema_name if schema_name else None | |||
# Table does not exist or is not visible to a connection. | |||
if not database.has_table_by_name(table_name, schema=_schema_name): | |||
if not database.has_table_or_view_by_name(table_name, schema=_schema_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we decouple has_table_by_name
and has_view_by_name
?
if any([
database.has_table_by_name(table_name, schema=_schema_name),
database.has_view_by_name(table_name, schema=_schema_name),
]):
....
superset/db_engine_specs/base.py
Outdated
view_name: str, | ||
schema: Optional[str] = None, | ||
): | ||
view_names = dialect.get_view_names(connection=conn, schema=schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should catch NotImplementedError
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed, please review
superset/db_engine_specs/base.py
Outdated
return view_name in view_names | ||
|
||
@classmethod | ||
def has_view(cls, engine: Engine, view_name: str, schema: Optional[str] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move has_view
to superset.models.core
in order to follow has_table
pattern.
superset/models/core.py
Outdated
engine=engine, view_name=view_name, schema=schema | ||
) | ||
|
||
def has_table_or_view_by_name( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same before, decouple has_table_by_name
and has_view_by_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to add a test case for this, probably specific to ES mocking the API
) -> bool: | ||
view_names: List[str] = [] | ||
try: | ||
view_names = dialect.get_view_names(connection=conn, schema=schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bugs me that we were only checking for has_table
since this should just check for tables, the base dialect class on SQLAlchemy:
def has_table(self, connection, table_name, schema=None):
"""Check the existence of a particular table in the database.
Given a :class:`.Connection` object and a string
`table_name`, return True if the given table (possibly within
the specified `schema`) exists in the database, False
otherwise.
"""
raise NotImplementedError()
So this seems like a valid solution to me, kind of surprises me that this not happen on other engines.
@villebro @betodealmeida what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add test cases. Please review. The problem is essentially that there is no judgment on the view, but I found the problem when I happened to use ES, so I think the test case should be judged for the general view. Not just ES
Codecov Report
@@ Coverage Diff @@
## master #16624 +/- ##
==========================================
+ Coverage 76.77% 76.94% +0.16%
==========================================
Files 1003 1007 +4
Lines 53959 54125 +166
Branches 7330 7346 +16
==========================================
+ Hits 41427 41646 +219
+ Misses 12293 12239 -54
- Partials 239 240 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for the fix @aniaan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ache#16624) * fix(dataset): create es-view dataset raise exception apache#16623 * fix(database): fix has_view logic * refactor(database): fix logic * style(lint): remove unused typing * fix(test): add test case * fix(test): fix test case
…ache#16624) * fix(dataset): create es-view dataset raise exception apache#16623 * fix(database): fix has_view logic * refactor(database): fix logic * style(lint): remove unused typing * fix(test): add test case * fix(test): fix test case
SUMMARY
Fix the error of creating es-view dataset
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
before:
after:
TESTING INSTRUCTIONS
Manually create a dataset of ES-View type to see if it is successfully created. The same is true for view types of other databases, but because of the limited conditions, I only tested ES + MySQL.
ADDITIONAL INFORMATION