This commit is contained in:
Amos Rimon 2019-08-11 16:12:22 +03:00
Родитель 2e4dc1a2b5
Коммит a41e3f3436
3 изменённых файлов: 24 добавлений и 9 удалений

Просмотреть файл

@ -32,21 +32,20 @@ def dynamic_to_kql(d: Union[Mapping, List, Tuple]) -> KQL:
# Issue #11
counter = 0
prev = ""
for i in range(len(query)):
for i, c in enumerate(query):
if counter == 0:
if query[i] == "[":
if c == "[":
query[i] = "("
elif query[i] == "]":
elif c == "]":
query[i] = ")"
elif query[i] == '"' and prev != "\\":
elif c in ['"', '\''] and prev != "\\":
counter += 1
elif counter > 0:
if query[i] == '"' and prev != "\\":
if c in ['"', '\''] and prev != "\\":
counter -= 1
prev = query[i]
i += 1
assert counter == 0
return KQL("".join([c for c in query]))
return KQL("".join(query))
def bool_to_kql(b: bool) -> KQL:

Просмотреть файл

@ -79,5 +79,5 @@ class TestExpressions(TestBase):
)
self.assertEqual(
" | where foo in (\"[\", \"[[\", \"]\")",
Query().where(col.foo.is_in(["[", "[[", "]"])).render()
)
Query().where(col.foo.is_in(['[', "[[", "]"])).render()
)

16
test/test_utils.py Normal file
Просмотреть файл

@ -0,0 +1,16 @@
from pykusto import utils
from test.test_base import TestBase
class TestUtils(TestBase):
def test_dynamic_to_kql(self):
dict ={
"name": "Alan",
"age": 21,
"address": ("NY", 36),
"pets": ["Libby", "Panda", "]", "["]
}
self.assertEqual(
"{\"name\": \"Alan\", \"age\": 21, \"address\": (\"NY\", 36), \"pets\": (\"Libby\", \"Panda\", \"]\", \"[\")}",
utils.to_kql(dict)
)