diff --git a/pykusto/functions.py b/pykusto/functions.py index 210958f..f2e6ab0 100644 --- a/pykusto/functions.py +++ b/pykusto/functions.py @@ -389,7 +389,8 @@ def pack_dictionary(): raise NotImplemented # TODO # def parse_ipv4(self): return -def parse_json(): raise NotImplemented # TODO +def parse_json(expr: Union[StringType, DynamicType]) -> DynamicExpression: + return DynamicExpression(KQL('parse_json({})'.format(expr))) # def parse_path(self): return diff --git a/setup.py b/setup.py index 01983a5..543081f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='pykusto', - version='0.0.6', + version='0.0.7', packages=find_packages(exclude=['test']), url='https://github.com/Azure/pykusto', license='MIT License', diff --git a/test/test_functions.py b/test/test_functions.py index 55fc998..b41765a 100644 --- a/test/test_functions.py +++ b/test/test_functions.py @@ -269,6 +269,41 @@ class TestFunction(TestBase): Query().where(col.foo < f.now(datetime.timedelta(-3))).render() ) + def test_parse_json_to_string(self): + self.assertEqual( + ' | where (tostring(parse_json(foo))) contains "ABC"', + Query().where(f.parse_json(col.foo).to_string().contains('ABC')).render() + ) + + def test_parse_json_brackets(self): + self.assertEqual( + ' | 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"', + 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', + Query().where(f.todouble(f.parse_json(col.foo).bar) > 4).render() + ) + + def test_parse_json_array(self): + self.assertEqual( + ' | 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[2]) contains "bar"', + Query().where(f.parse_json(col.foo)['a'].b[2].contains('bar')).render()) + def test_pow(self): self.assertEqual( " | where (pow(foo, bar)) > 3",