diff --git a/src/infi/clickhouse_orm/funcs.py b/src/infi/clickhouse_orm/funcs.py index 3de6a56..60520da 100644 --- a/src/infi/clickhouse_orm/funcs.py +++ b/src/infi/clickhouse_orm/funcs.py @@ -653,7 +653,31 @@ class F(Cond, FunctionOperatorsMixin): def tryBase64Decode(s): return F('tryBase64Decode', s) - # Functions for searching and replacing in strings + @staticmethod + def endsWith(s, suffix): + return F('endsWith', s, suffix) + + @staticmethod + def startsWith(s, prefix): + return F('startsWith', s, prefix) + + @staticmethod + def trimLeft(s): + return F('trimLeft', s) + + @staticmethod + def trimRight(s): + return F('trimRight', s) + + @staticmethod + def trimBoth(s): + return F('trimBoth', s) + + @staticmethod + def CRC32(s): + return F('CRC32', s) + + # Functions for replacing in strings @staticmethod def replace(haystack, pattern, replacement): diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 52a5c58..5068409 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -208,7 +208,7 @@ class FuncsTestCase(TestCaseWithData): self._test_func(F.toRelativeMinuteNum(dt, 'Europe/Athens'), 25770922) self._test_func(F.toRelativeSecondNum(dt), 1546255353) self._test_func(F.toRelativeSecondNum(dt, 'Europe/Athens'), 1546255353) - self._test_func(F.now(), datetime.utcnow().replace(tzinfo=pytz.utc, microsecond=0)) + self._test_func(F.now(), datetime.utcnow().replace(tzinfo=pytz.utc, microsecond=0)) # FIXME this may fail if the timing is just right self._test_func(F.today(), date.today()) self._test_func(F.yesterday(), date.today() - timedelta(days=1)) self._test_func(F.timeSlot(dt), datetime(2018, 12, 31, 11, 0, 0, tzinfo=pytz.utc)) @@ -294,6 +294,14 @@ class FuncsTestCase(TestCaseWithData): self._test_func(F.appendTrailingCharIfAbsent('Hello', '!'), 'Hello!') self._test_func(F.appendTrailingCharIfAbsent('Hello!', '!'), 'Hello!') self._test_func(F.convertCharset(F.convertCharset('Hello', 'latin1', 'utf16'), 'utf16', 'latin1'), 'Hello') + self._test_func(F.startsWith('aaa', 'aa'), True) + self._test_func(F.startsWith('aaa', 'bb'), False) + self._test_func(F.endsWith('aaa', 'aa'), True) + self._test_func(F.endsWith('aaa', 'bb'), False) + self._test_func(F.trimLeft(' abc '), 'abc ') + self._test_func(F.trimRight(' abc '), ' abc') + self._test_func(F.trimBoth(' abc '), 'abc') + self._test_func(F.CRC32('whoops'), 3361378926) def test_base64_functions(self): try: