File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
## Change log
2
2
3
+ ### Next
4
+
5
+ - fix: OpenDistro dialect quotes properly with backticks now (#99 ) [ Beto Dealmeida]
6
+
3
7
### 0.2.9
4
8
5
9
- fix: remove six dependency (#84 ) [ Daniel Vaz Gaspar]
Original file line number Diff line number Diff line change 5
5
from es import basesqlalchemy
6
6
import es .opendistro
7
7
from sqlalchemy .engine import Connection
8
+ from sqlalchemy .sql import compiler
8
9
9
10
logger = logging .getLogger (__name__ )
10
11
@@ -17,13 +18,21 @@ class ESTypeCompiler(basesqlalchemy.BaseESTypeCompiler): # pragma: no cover
17
18
pass
18
19
19
20
21
+ class ESTypeIdentifierPreparer (compiler .IdentifierPreparer ):
22
+ def __init__ (self , * args : Any , ** kwargs : Any ):
23
+ super ().__init__ (* args , ** kwargs )
24
+
25
+ self .initial_quote = self .final_quote = "`"
26
+
27
+
20
28
class ESDialect (basesqlalchemy .BaseESDialect ):
21
29
22
30
name = "odelasticsearch"
23
31
scheme = "http"
24
32
driver = "rest"
25
33
statement_compiler = ESCompiler
26
34
type_compiler = ESTypeCompiler
35
+ preparer = ESTypeIdentifierPreparer
27
36
28
37
@classmethod
29
38
def dbapi (cls ) -> ModuleType :
Original file line number Diff line number Diff line change 3
3
import unittest
4
4
from unittest .mock import Mock , patch
5
5
6
+ from es .elastic .sqlalchemy import ESDialect as ElasticDialect
6
7
from es .exceptions import DatabaseError
8
+ from es .opendistro .sqlalchemy import ESDialect as OpenDistroDialect
7
9
from es .tests .fixtures .fixtures import data1_columns , flights_columns
8
10
from sqlalchemy import func , inspect , select
9
11
from sqlalchemy .engine import create_engine
@@ -325,3 +327,21 @@ def test_opendistro_ping_failed(self):
325
327
conn = self .engine .raw_connection ()
326
328
with self .assertRaises (DatabaseError ):
327
329
self .engine .dialect .do_ping (conn )
330
+
331
+
332
+ class TestQuote (unittest .TestCase ):
333
+ """
334
+ Test quoting identifiers in ES and OD.
335
+ """
336
+
337
+ def test_elastic (self ) -> None :
338
+ assert (
339
+ ElasticDialect .preparer (dialect = ElasticDialect ()).quote ("DATE(123)" )
340
+ == '"DATE(123)"'
341
+ )
342
+
343
+ def test_opendistro (self ) -> None :
344
+ assert (
345
+ OpenDistroDialect .preparer (dialect = OpenDistroDialect ()).quote ("DATE(123)" )
346
+ == "`DATE(123)`"
347
+ )
Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ readme_renderer==24.0
11
11
mypy == 0.790
12
12
requests-aws4auth == 1.0.1
13
13
boto3 == 1.16.63
14
+ pytest == 7.2.1
You can’t perform that action at this time.
0 commit comments