-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
test_udf.py
60 lines (44 loc) · 1.58 KB
/
test_udf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!python3
import unittest
from chdb.udf import chdb_udf
from chdb.session import Session
from chdb import query, sql
@chdb_udf()
def sum_udf(lhs, rhs):
return int(lhs) + int(rhs)
@chdb_udf(return_type="Int32")
def mul_udf(lhs, rhs):
return int(lhs) * int(rhs)
class TestUDF(unittest.TestCase):
def test_sum_udf(self):
ret = query("select sum_udf(12,22)", "Debug")
self.assertEqual(str(ret), '"34"\n')
def test_return_Int32(self):
ret = query("select mul_udf(12,22) + 1", "Debug")
self.assertEqual(str(ret), "265\n")
def test_define_in_function(self):
@chdb_udf()
def sum_udf2(lhs, rhs):
return int(lhs) + int(rhs)
# sql is a alias for query
ret = sql("select sum_udf2(11, 22)", "Debug")
self.assertEqual(str(ret), '"33"\n')
class TestUDFinSession(unittest.TestCase):
def test_sum_udf(self):
with Session() as session:
ret = session.query("select sum_udf(12,22)", "Debug")
self.assertEqual(str(ret), '"34"\n')
def test_return_Int32(self):
with Session() as session:
ret = session.query("select mul_udf(12,22) + 1", "Debug")
self.assertEqual(str(ret), "265\n")
def test_define_in_function(self):
@chdb_udf()
def sum_udf2(lhs, rhs):
return int(lhs) + int(rhs)
with Session() as session:
# sql is a alias for query
ret = session.sql("select sum_udf2(11, 22)", "Debug")
self.assertEqual(str(ret), '"33"\n')
if __name__ == "__main__":
unittest.main()