Skip to content

Commit d4a805f

Browse files
committed
Add test for escaping special ES characters
1 parent fed09dd commit d4a805f

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

test/splitgraph/commands/test_es_fdw_queries.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _extract_queries_from_explain(result):
3030

3131

3232
@pytest.mark.mounting
33-
def test_patern_matching_queries(local_engine_empty):
33+
def test_pattern_matching_queries(local_engine_empty):
3434
_mount_elasticsearch()
3535

3636
# Test pattern matching conversion mechanism on generic examples
@@ -78,6 +78,29 @@ def test_patern_matching_queries(local_engine_empty):
7878
}
7979
}
8080

81+
# Special ES pattern characters are escaped
82+
query = r"""
83+
SELECT *
84+
FROM es.account
85+
WHERE firstname ~~ 'star: *; question-mark: ?; multiple-stars-and-question-marks: ****??'
86+
"""
87+
88+
# Ensure proper query translation
89+
result = local_engine_empty.run_sql("EXPLAIN " + query)
90+
assert _extract_queries_from_explain(result)[0] == {
91+
"query": {
92+
"bool": {
93+
"must": [
94+
{
95+
"wildcard": {
96+
r"firstname": "star: \*; question-mark: \?; multiple-stars-and-question-marks: \*\*\*\*\?\?"
97+
}
98+
}
99+
]
100+
}
101+
}
102+
}
103+
81104
# Test meaningful pattern match query returns correct result
82105
query = "SELECT firstname FROM es.account WHERE firstname ~~ 'Su_an%'"
83106

0 commit comments

Comments
 (0)