Skip to content

Commit

Permalink
fix(dataset): create es-view dataset raise exception apache#16623
Browse files Browse the repository at this point in the history
  • Loading branch information
aniaan committed Sep 7, 2021
1 parent 519baa6 commit 7f40cb3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/connectors/sqla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
raise NoSuchTableError

cols = database.get_columns(table_name, schema=_schema_name)
Expand Down
21 changes: 21 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,27 @@ def has_table_by_name(self, table_name: str, schema: Optional[str] = None) -> bo
engine = self.get_sqla_engine()
return engine.has_table(table_name, schema)

def has_table_or_view_by_name(
self, name: str, schema: Optional[str] = None
) -> bool:

table_names: List[str]
view_names: List[str]
if schema:
table_names = [
ds.table for ds in self.get_all_table_names_in_schema(schema=schema)
]
view_names = [
ds.table for ds in self.get_all_view_names_in_schema(schema=schema)
]
else:
table_names = [ds.table for ds in self.get_all_table_names_in_database()]
view_names = [ds.table for ds in self.get_all_view_names_in_database()]

all_datasource_names: List[str] = table_names + view_names

return name in all_datasource_names

@memoized
def get_dialect(self) -> Dialect:
sqla_url = url.make_url(self.sqlalchemy_uri_decrypted)
Expand Down

0 comments on commit 7f40cb3

Please sign in to comment.