This commit is contained in:
Amos Rimon 2019-08-11 14:33:23 +03:00
Родитель 13fc2f12a8
Коммит 2e4dc1a2b5
2 изменённых файлов: 29 добавлений и 1 удалений

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

@ -28,7 +28,25 @@ def timedelta_to_kql(td: timedelta) -> KQL:
def dynamic_to_kql(d: Union[Mapping, List, Tuple]) -> KQL:
return KQL(json.dumps(d))
query = list(json.dumps(d))
# Issue #11
counter = 0
prev = ""
for i in range(len(query)):
if counter == 0:
if query[i] == "[":
query[i] = "("
elif query[i] == "]":
query[i] = ")"
elif query[i] == '"' and prev != "\\":
counter += 1
elif counter > 0:
if query[i] == '"' and prev != "\\":
counter -= 1
prev = query[i]
i += 1
assert counter == 0
return KQL("".join([c for c in query]))
def bool_to_kql(b: bool) -> KQL:

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

@ -71,3 +71,13 @@ class TestExpressions(TestBase):
" | project ['foo.bar']",
Query().project(col['foo.bar']).render(),
)
def test_is_in(self):
self.assertEqual(
" | where foo in (\"A\", \"B\", \"C\")",
Query().where(col.foo.is_in(["A", "B", "C"])).render()
)
self.assertEqual(
" | where foo in (\"[\", \"[[\", \"]\")",
Query().where(col.foo.is_in(["[", "[[", "]"])).render()
)