Skip to content

Commit ba15a2e

Browse files
authored
fix: remove show tables column retrieval index based (#81)
* fix: remove show tables column retrieval index based * add ES 7.15 to tests and python 3.9
1 parent cad716e commit ba15a2e

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
runs-on: ubuntu-18.04
3939
strategy:
4040
matrix:
41-
python-version: [3.6, 3.7, 3.8]
41+
python-version: [3.7, 3.8, 3.9]
4242
services:
4343
elasticsearch:
4444
image: elasticsearch:7.3.2
@@ -64,6 +64,12 @@ jobs:
6464
discovery.type: single-node
6565
ports:
6666
- 39200:9200
67+
elasticsearch_7_16:
68+
image: elasticsearch:7.16.1
69+
env:
70+
discovery.type: single-node
71+
ports:
72+
- 49200:9200
6773

6874
steps:
6975
- uses: actions/checkout@v2
@@ -90,6 +96,11 @@ jobs:
9096
export ES_URI="http://localhost:39200"
9197
export ES_PORT=39200
9298
nosetests -v --with-coverage --cover-package=es es.tests
99+
- name: Run tests on Elasticsearch 7.16.X
100+
run: |
101+
export ES_URI="http://localhost:49200"
102+
export ES_PORT=49200
103+
nosetests -v --with-coverage --cover-package=es es.tests
93104
- name: Run tests on Opendistro
94105
run: |
95106
export ES_DRIVER=odelasticsearch

es/elastic/api.py

Lines changed: 16 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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)