This commit is contained in:
Shai Keren 2020-01-01 13:25:28 +02:00
Родитель 42dca4bbcd
Коммит 643e7f7ea1
2 изменённых файлов: 19 добавлений и 30 удалений

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

@ -389,8 +389,8 @@ def pack_dictionary(): raise NotImplemented # TODO
# def parse_ipv4(self): return
def parse_json(expr: Union[StringType, DynamicType]) -> MappingExpression:
return MappingExpression(KQL('parse_json({})'.format(expr)))
def parse_json(expr: Union[StringType, DynamicType]) -> DynamicExpression:
return DynamicExpression(KQL('parse_json({})'.format(expr)))
# def parse_path(self): return

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

@ -269,51 +269,40 @@ class TestFunction(TestBase):
Query().where(col.foo < f.now(datetime.timedelta(-3))).render()
)
def test_parse_json(self):
def test_parse_json_to_string(self):
self.assertEqual(
" | where (tostring(parse_json(foo))) contains \"ABC\"",
' | where (tostring(parse_json(foo))) contains "ABC"',
Query().where(f.parse_json(col.foo).to_string().contains('ABC')).render()
)
def test_parse_json_elements(self):
def test_parse_json_brackets(self):
self.assertEqual(
" | where (tostring(parse_json(foo)[\"bar\"])) contains \"ABC\"",
' | where (tostring(parse_json(foo)["bar"])) contains "ABC"',
Query().where(f.parse_json(col.foo)['bar'].to_string().contains('ABC')).render()
)
def test_parse_json_dot(self):
self.assertEqual(
" | where (tostring(parse_json(foo).bar)) contains \"ABC\"",
' | where (tostring(parse_json(foo).bar)) contains "ABC"',
Query().where(f.parse_json(col.foo).bar.to_string().contains('ABC')).render()
)
def test_parse_json_number_expression(self):
self.assertEqual(
" | where (todouble(parse_json(foo).bar)) > 4",
' | where (todouble(parse_json(foo).bar)) > 4',
Query().where(f.todouble(f.parse_json(col.foo).bar) > 4).render()
)
def test_parse_json_all_types(self):
def test_parse_json_array(self):
self.assertEqual(
"| where parse_json(foo)['a']['b'] contains 'bar'",
Query().where(f.parse_json(col.foo)['a']['b'].contains('bar')).render()
' | where (parse_json(foo)[2]) == 3',
Query().where(f.parse_json(col.foo)[2] == 3).render()
)
def test_parse_json_nesting(self):
self.assertEqual(
"| where parse_json(foo).a.b == 'bar'",
Query().where(f.parse_json(col.foo).a.b == 'bar').render()
)
self.assertEqual(
"| where foo[4] contains 'bar'",
Query().where(col.foo[4].contains('bar')).render()
)
self.assertEqual(
"| where foo.a.b contains 'bar'",
Query().where(col.foo.a.b.contains('bar')).render()
)
self.assertEqual(
"| where foo['a']['b'] == 'bar'",
Query().where(col.foo['a']['b'] == 'bar').render()
)
self.assertEqual(
"| where foo[4].a contains 'bar'",
Query().where(col.foo[4].a.contains('bar')).render()
)
' | where (parse_json(foo)["a"].b[2]) contains "bar"',
Query().where(f.parse_json(col.foo)['a'].b[2].contains('bar')).render())
def test_pow(self):
self.assertEqual(