Skip to content

Commit b9f60ac

Browse files
committed
fix: remove show tables column retrieval index based
1 parent cad716e commit b9f60ac

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

es/elastic/api.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def __init__(self, url: str, es: Elasticsearch, **kwargs: Any) -> None:
8989
super().__init__(url, es, **kwargs)
9090
self.sql_path = kwargs.get("sql_path") or "_sql"
9191

92+
def _get_value_for_col_name(self, row: Tuple[Any], name: str) -> Any:
93+
"""
94+
Get the value of a specific column name from a row
95+
:param row: The result row
96+
:param name: The column name
97+
:return: Value
98+
"""
99+
for idx, col_description in enumerate(self.description):
100+
if col_description.name == name:
101+
return row[idx]
102+
92103
def get_valid_table_view_names(self, type_filter: str) -> "Cursor":
93104
"""
94105
Custom for "SHOW VALID_TABLES" excludes empty indices from the response
@@ -108,11 +119,14 @@ def get_valid_table_view_names(self, type_filter: str) -> "Cursor":
108119
is_empty = False
109120
for item in response:
110121
# First column is TABLE_NAME
111-
if item["index"] == result[0]:
122+
if item["index"] == self._get_value_for_col_name(result, "name"):
112123
if int(item["docs.count"]) == 0:
113124
is_empty = True
114125
break
115-
if not is_empty and result[1] == type_filter:
126+
if (
127+
not is_empty
128+
and self._get_value_for_col_name(result, "type") == type_filter
129+
):
116130
_results.append(result)
117131
self._results = _results
118132
return self

es/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class NotSupportedError(DatabaseError):
3939

4040

4141
class UnexpectedESInitError(Error):
42-
""" Should never happen, when a cursor is requested
42+
"""Should never happen, when a cursor is requested
4343
without an ElasticSearch object being initialized"""
4444

4545

4646
class UnexpectedRequestResponse(Error):
47-
""" When perform request returns False, only when HTTP method HEAD
48-
and status code 404 """
47+
"""When perform request returns False, only when HTTP method HEAD
48+
and status code 404"""

0 commit comments

Comments
 (0)