From cc0f2c4e91cfb9bfac86815eed78a6ff5f49f1ad Mon Sep 17 00:00:00 2001 From: Itai Shirav Date: Sat, 13 Jul 2019 23:01:37 +0300 Subject: [PATCH] Functions WIP --- src/infi/clickhouse_orm/funcs.py | 24 ++++++++++++++++-------- tests/test_funcs.py | 9 +++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/infi/clickhouse_orm/funcs.py b/src/infi/clickhouse_orm/funcs.py index 29c3728..bac17ba 100644 --- a/src/infi/clickhouse_orm/funcs.py +++ b/src/infi/clickhouse_orm/funcs.py @@ -1136,14 +1136,6 @@ class F(Cond, FunctionOperatorsMixin): def unhex(x): return F('unhex', x) - @staticmethod - def UUIDNumToString(s): - return F('UUIDNumToString', s) - - @staticmethod - def UUIDStringToNum(s): - return F('UUIDStringToNum', s) - @staticmethod def bitmaskToArray(x): return F('bitmaskToArray', x) @@ -1152,7 +1144,23 @@ class F(Cond, FunctionOperatorsMixin): def bitmaskToList(x): return F('bitmaskToList', x) + # Functions for working with UUID + @staticmethod + def generateUUIDv4(): + return F('generateUUIDv4') + + @staticmethod + def toUUID(s): + return F('toUUID', s) + + @staticmethod + def UUIDNumToString(s): + return F('UUIDNumToString', s) + + @staticmethod + def UUIDStringToNum(s): + return F('UUIDStringToNum', s) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 32170ce..37844ed 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -440,9 +440,14 @@ class FuncsTestCase(TestCaseWithData): self._test_func(F.randConstant(17)) def test_encoding_functions(self): - uuid = '123e4567-e89b-12d3-a456-426655440000' self._test_func(F.hex(F.unhex('0FA1')), '0FA1') - self._test_func(F.UUIDNumToString(F.UUIDStringToNum(uuid)), uuid) self._test_func(F.bitmaskToArray(17)) self._test_func(F.bitmaskToList(18)) + def test_uuid_functions(self): + from uuid import UUID + uuid = self._test_func(F.generateUUIDv4()) + self.assertEqual(type(uuid), UUID) + s = str(uuid) + self._test_func(F.toUUID(s), uuid) + self._test_func(F.UUIDNumToString(F.UUIDStringToNum(s)), s)