зеркало из https://github.com/Azure/pykusto.git
Issue #11 - fix dynamic rendering
This commit is contained in:
Родитель
2e4dc1a2b5
Коммит
a41e3f3436
|
@ -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()
|
||||
)
|
|
@ -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)
|
||||
)
|
Загрузка…
Ссылка в новой задаче