未验证 提交 57f252d1 编写于 作者: H Hui Li 提交者: GitHub

Merge pull request #8489 from taosdata/udf_master_reload

[TD-6137]<test>:add test case for udf to support all query ways
......@@ -73,21 +73,18 @@ class TDTestCase:
tdSql.error(sql)
sql = 'select abs_max(c2) from db.stb'
tdSql.query(sql)
tdSql.checkData(0,0,1410065607)
tdSql.checkData(0,0,10000000199)
def test_udf_values(self):
tdSql.execute("drop function abs_max")
tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype int")
tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype bigint;")
tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype int bufsize 128;")
tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint;")
# UDF bug no 1 -> follow 3 cases about this bug ;
# tdSql.error("create aggregate function max as '/tmp/abs_max.so' outputtype bigint ;")
# tdSql.error("create aggregate function avg as '/tmp/abs_max.so' outputtype bigint ;")
# tdSql.error("create aggregate function dbs as '/tmp/abs_max.so' outputtype bigint ;")
tdSql.execute("drop database if exists test")
tdSql.execute("create database test")
tdSql.execute("use test")
......@@ -117,7 +114,7 @@ class TDTestCase:
tdSql.execute("insert into bound values(%d, %d , %f, %d , %s)"%(epoch_time+1000,intdata2+1,float(intdata2+1),bigintdata2+1,"'binary"+str(intdata2+1)+"'"))
# check super table calculation results
tdSql.query("select add_one(id) from st")
tdSql.query("select add_one(id) test from st")
tdSql.checkData(0,0,1)
tdSql.checkData(1,0,2)
tdSql.checkData(4,0,5)
......@@ -157,29 +154,266 @@ class TDTestCase:
tdLog.info(" ====== unexpected error occured about UDF function =====")
sys.exit()
# UDF bug no 2 -> values of abs_max not inconsistent from common table and stable.
# tdSql.query("select abs_max(val) from st") # result is 0 rows
# tdSql.query("select abs_max(val) from tb1")
# tdSql.checkData(0,0,0) # this is error result
# tdSql.query("select sum_double(val) from st") # result is 0 rows
# tdSql.query("select sum_double(val) from tb1")
# tdSql.checkData(0,0,0) # this is error result
tdSql.query("select abs_max(val) from st")
tdSql.query("select abs_max(val) from tb1")
tdSql.checkRows(0)
tdSql.query("select sum_double(val) from st")
tdSql.query("select sum_double(val) from tb1")
tdSql.checkRows(0)
# UDF bug no 3 -> values of abs_max will error for boundary number
# check super table calculation results
# tdSql.query("select abs_max(number) from st")
# tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from st")
tdSql.checkData(0,0,9223372036854775807)
# check common table calculation results
tdSql.query("select abs_max(number) from tb1")
tdSql.checkData(0,0,400)
tdSql.query("select abs_max(number) from tb2")
tdSql.checkData(0,0,400)
tdSql.execute("select add_one(id) from st limit 10 offset 2")
tdSql.query("select add_one(id) from st where ts > 1604298064000 and ts < 1604298064020 ")
tdSql.checkData(0,0,1)
tdSql.checkData(1,0,-2147483644)
tdSql.query("select add_one(id) from tb1 where ts > 1604298064000 and ts < 1604298064020 ")
tdSql.checkData(0,0,1)
tdSql.query("select sum_double(id) from st where ts > 1604298064030 and ts < 1604298064060 ")
tdSql.checkData(0,0,14)
tdSql.query("select sum_double(id) from tb2 where ts > 1604298064030 and ts < 1604298064060 ")
tdSql.checkRows(0)
tdSql.query("select add_one(id) from st where ts = 1604298064000 ")
tdSql.checkData(0,0,-2147483645)
tdSql.query("select add_one(id) from st where ts > 1604298064000 and id in (2,3) and ind =1;")
tdSql.checkData(0,0,3)
tdSql.checkData(1,0,4)
tdSql.query("select id , add_one(id) from tb1 where ts > 1604298064000 and id in (2,3)")
tdSql.checkData(0,0,2)
tdSql.checkData(0,1,3)
tdSql.checkData(1,0,3)
tdSql.checkData(1,1,4)
tdSql.query("select sum_double(id) from tb1 where ts > 1604298064000 and id in (2,3)")
tdSql.checkData(0,0,10)
tdSql.query("select sum_double(id) from st where ts > 1604298064000 and id in (2,3) and ind =1")
tdSql.checkData(0,0,10)
tdSql.query("select abs_max(number) from st where ts > 1604298064000 and id in (2,3) and ind =1")
tdSql.checkData(0,0,300)
tdSql.query("select sum_double(id) from st where ts = 1604298064030 ")
tdSql.checkData(0,0,4)
tdSql.query("select abs_max(number) from st where ts = 1604298064100 ")
tdSql.checkData(0,0,9223372036854775806)
tdSql.query("select abs_max(number) from tb2 where ts = 1604298064100 ")
tdSql.checkData(0,0,400)
tdSql.query("select sum_double(id) from tb2 where ts = 1604298064100 ")
tdSql.checkData(0,0,8)
tdSql.query("select add_one(id) from st where ts >= 1604298064000 and ts <= 1604298064010")
tdSql.checkData(0,0,1)
tdSql.checkData(1,0,-2147483645)
tdSql.checkData(2,0,-2147483644)
tdSql.query("select add_one(id) from tb1 where ts >= 1604298064000 and ts <= 1604298064010")
tdSql.checkData(0,0,1)
tdSql.query("select sum_double(id) from st where ts >= 1604298064030 and ts <= 1604298064050")
tdSql.checkData(0,0,18)
tdSql.query("select sum_double(id) from tb2 where ts >= 1604298064030 and ts <= 1604298064100")
tdSql.checkData(0,0,20)
tdSql.query("select abs_max(number) from tb2 where ts >= 1604298064030 and ts <= 1604298064100")
tdSql.checkData(0,0,400)
tdSql.query("select abs_max(number) from st where ts >= 1604298064030 and ts <= 1604298064100")
tdSql.checkData(0,0,9223372036854775806)
tdSql.query("select id from st where id != 0 and ts >=1604298064070")
tdSql.checkData(0,0,1)
tdSql.query("select add_one(id) from st where id != 0 and ts >=1604298064070")
tdSql.checkData(0,0,2)
tdSql.query("select add_one(id) from st where id <> 0 and ts >=1604298064010")
tdSql.checkData(0,0,2)
tdSql.query("select sum_double(id) from st where id in (2,3,4) and ts >=1604298064070")
tdSql.checkData(0,0,18)
tdSql.query("select sum_double(id) from tb2 where id in (2,3,4) and ts >=1604298064070")
tdSql.checkData(0,0,18)
tdSql.query("select abs_max(number) from st where id in (2,3,4) and ts >=1604298064070")
tdSql.checkData(0,0,400)
tdSql.query("select add_one(id) from st where id = 0 ")
tdSql.checkData(0,0,1)
tdSql.checkData(1,0,1)
tdSql.query("select add_one(id) from tb2 where id = 0 ")
tdSql.checkData(0,0,1)
tdSql.query("select sum_double(id) from st where id = 1")
tdSql.checkData(0,0,4)
tdSql.query("select sum_double(id) from tb2 where id = 1")
tdSql.checkData(0,0,2)
tdSql.query("select add_one(id) from st where id is not null and ts >=1604298065000 ")
tdSql.checkData(0,0,None)
tdSql.query("select abs_max(number) from st where id is not null and ts >=1604298065000 ")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from bound where id is not null and ts >=1604298065000 ")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select sum_double(id) from st where id is not null and ts >=1604298064000 and ind = 1 ")
tdSql.checkData(0,0,20)
tdSql.query("select sum_double(id) from tb1 where id is not null and ts >=1604298064000 ")
tdSql.checkData(0,0,20)
tdSql.query("select add_one(id) from st where id is null and ts >=1604298065000 ")
tdSql.checkRows(0)
tdSql.query("select abs_max(number) from st where id is null and ts >=1604298065000 ")
tdSql.checkRows(0)
tdSql.query("select abs_max(number) from tb1 where id is null and ts >=1604298065000 ")
tdSql.checkRows(0)
tdSql.query("select add_one(id) from bound where id is not null and ts >=1604298065000;")
tdSql.checkData(0,0,None)
tdSql.query("select id,add_one(id) from bound;")
tdSql.checkRowCol(4,2)
tdSql.checkData(3,1,None)
tdSql.query("select add_one(id) from st where ts between 1604298064000 and 1604298064010")
tdSql.checkRows(3)
tdSql.query("select add_one(id) from tb1 where ts between 1604298064000 and 1604298064010")
tdSql.checkRows(1)
tdSql.query("select sum_double(id) from st where ts between 1604298064000 and 1604298064010 and id>=0")
tdSql.checkData(0,0,0)
tdSql.query("select sum_double(id) from tb1 where ts between 1604298064000 and 1604298064010 and id>=0")
tdSql.checkData(0,0,0)
tdSql.query("select add_one(id) from st where id in (1,2)")
tdSql.checkData(0,0,2)
tdSql.checkData(1,0,3)
tdSql.checkData(2,0,2)
tdSql.checkData(3,0,3)
tdSql.checkRows(4)
tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(1s)")
tdSql.checkData(0,1,20)
tdSql.error("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) fill (NULL) ")
tdSql.error("select sum_double(id) from st session(ts, 1s)")
tdSql.query("select sum_double(id) from tb1 session(ts, 1s)")
tdSql.checkData(0,1,20)
# intervals sliding values calculation
tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2")
tdSql.checkData(0,1,20)
tdSql.checkData(1,1,20)
# scalar_function can't work when using interval and sliding =========
tdSql.error("select add_one(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2 ")
tdSql.error("select add_one(id) from st order by ts")
tdSql.error("select ts,id,add_one(id) from st order by ts asc;")
# # UDF not support order by
tdSql.error("select ts,id,add_one(id) from st order by ts desc;")
# UDF function union all
tdSql.query("select add_one(id) from tb1 union all select add_one(id) from tb2;")
tdSql.checkRows(10)
tdSql.checkData(0,0,1)
tdSql.checkData(5,0,1)
tdSql.query("select sum_double(id) from tb1 union all select sum_double(id) from tb2;")
tdSql.checkRows(2)
tdSql.checkData(0,0,20)
tdSql.checkData(1,0,20)
tdSql.query("select abs_max(number) from tb1 union all select abs_max(number) from bound;")
tdSql.checkRows(2)
tdSql.checkData(0,0,400)
tdSql.checkData(1,0,9223372036854775807)
tdSql.execute("create stable stb (ts timestamp,id int , val double , number bigint, chars binary(200)) tags (ind int)")
tdSql.execute("create table stb1 using stb tags(3)")
tdSql.execute("insert into stb1 values(1604298064000 , 1 , 1.0 , 10000 ,'chars')")
tdSql.query("select add_one(id) from st union all select add_one(id) from stb;")
tdSql.checkRows(15)
tdSql.checkData(13,0,None)
tdSql.checkData(14,0,2)
tdSql.query("select add_one(id) from st union all select add_one(id) from stb1;")
tdSql.checkRows(15)
tdSql.checkData(13,0,None)
tdSql.checkData(14,0,2)
tdSql.query("select id ,add_one(id) from tb1 union all select id ,add_one(id) from stb1;")
tdSql.checkRows(6)
tdSql.checkData(0,0,0)
tdSql.checkData(0,1,1)
tdSql.checkData(1,0,1)
tdSql.checkData(1,1,2)
# aggregate union all for different stables
tdSql.query("select sum_double(id) from st union all select sum_double(id) from stb;")
tdSql.checkRows(2)
tdSql.checkData(0,0,44)
tdSql.checkData(1,0,2)
tdSql.query("select id from st union all select id from stb1;")
tdSql.checkRows(15)
tdSql.query("select id from tb1 union all select id from stb1")
tdSql.checkRows(6)
tdSql.query("select sum_double(id) from tb1 union all select sum_double(id) from stb")
tdSql.checkData(0,0,20)
tdSql.checkData(1,0,2)
tdSql.query("select sum_double(id) from st union all select sum_double(id) from stb1;")
tdSql.checkRows(2)
tdSql.checkData(0,0,44)
tdSql.checkData(1,0,2)
tdSql.query("select abs_max(number) from st union all select abs_max(number) from stb;")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from bound union all select abs_max(number) from stb1;")
tdSql.checkData(0,0,9223372036854775807)
tdSql.checkData(1,0,10000)
tdSql.query("select abs_max(number) from st union all select abs_max(number) from stb1;")
tdSql.checkData(0,0,9223372036854775807)
tdSql.checkData(1,0,10000)
# group by for aggegate function ;
tdSql.query("select sum_double(id) from st group by tbname;")
tdSql.checkData(0,0,20)
tdSql.checkData(0,1,'tb1')
tdSql.checkData(1,0,20)
tdSql.checkData(1,1,'tb2')
tdSql.query("select sum_double(id) from st group by id;")
tdSql.checkRows(9)
tdSql.query("select sum_double(id) from st group by ts")
tdSql.checkRows(12)
tdSql.query("select sum_double(id) from st group by ind")
tdSql.checkRows(3)
tdSql.query("select sum_double(id) from st group by tbname order by ts asc;")
tdSql.query("select abs_max(number) from st group by id")
tdSql.checkRows(9)
tdSql.checkData(0,0,9223372036854775806)
tdSql.checkData(8,0,9223372036854775807)
tdSql.query("select abs_max(number) from st group by ts")
tdSql.checkRows(12)
tdSql.checkData(11,0,9223372036854775807)
tdSql.checkData(1,0,9223372036854775805)
tdSql.query("select abs_max(number) from st group by ind")
tdSql.checkRows(3)
tdSql.checkData(0,0,400)
tdSql.checkData(2,0,9223372036854775807)
# UDF join
tdSql.query("select add_one(tb1.id),add_one(bound.id) from tb1,bound where tb1.ts=bound.ts;")
tdSql.checkData(0,0,1)
tdSql.checkData(0,1,-2147483644)
tdSql.query("select stb1.ts,add_one(stb1.id),bound.ts,add_one(bound.id) from stb1,bound where stb1.ts=bound.ts")
tdSql.checkData(0,1,2)
tdSql.checkData(0,3,-2147483645)
tdSql.query("select st.ts,add_one(st.id),stb.ts,add_one(stb.id) from st,stb where st.ts=stb.ts and st.ind=stb.ind")
tdSql.checkData(0,1,-2147483645)
tdSql.checkData(0,3,2)
tdSql.query("select sum_double(tb1.id),sum_double(bound.id) from tb1,bound where tb1.ts=bound.ts;")
tdSql.checkData(0,0,0)
tdSql.checkData(0,1,-4294967290)
tdSql.query("select sum_double(stb1.id),sum_double(bound.id) from stb1,bound where stb1.ts=bound.ts")
tdSql.checkData(0,0,2)
tdSql.checkData(0,1,-4294967292)
#UDF join for stables
tdSql.query("select sum_double(st.id),sum_double(stb.id) from st,stb where st.ts=stb.ts and st.ind=stb.ind")
tdSql.checkData(0,0,-4294967292)
tdSql.checkData(0,1,2)
tdSql.query("select abs_max(tb1.number),abs_max(bound.number) from tb1,bound where tb1.ts=bound.ts;")
tdSql.checkData(0,0,0)
tdSql.checkData(0,1,9223372036854775805)
tdSql.query("select abs_max(stb1.number),abs_max(bound.number) from stb1,bound where stb1.ts=bound.ts")
tdSql.checkData(0,0,10000)
tdSql.checkData(0,1,9223372036854775806)
tdSql.query("select abs_max(st.number),abs_max(stb.number) from st,stb where st.ts=stb.ts and st.ind=stb.ind")
tdSql.checkData(0,0,9223372036854775806)
tdSql.checkData(0,1,10000)
# check boundary
# tdSql.query("select abs_max(number) from bound")
# tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from bound")
tdSql.checkData(0,0,9223372036854775807)
tdLog.info("======= UDF function sum_double check =======")
......@@ -189,14 +423,10 @@ class TDTestCase:
tdSql.query("select sum_double(id) from tb1")
tdSql.checkData(0,0,20)
# UDF bug no 4 -> values error while two function work : it is limit that udf can't work with build-in functions.
# tdSql.query("select sum_double(id) , abs_max(number) from tb1")
# tdSql.checkData(0,0,20)
# tdSql.checkData(0,0,400)
# tdSql.query("select sum_double(id) , abs_max(number) from st")
# tdSql.checkData(0,0,44)
# tdSql.checkData(0,0,9223372036854775807)
# only one udf function in SQL can use ,follow errors notice.
tdSql.error("select sum_double(id) , abs_max(number) from tb1")
tdSql.error("select sum_double(id) , abs_max(number) from st")
# UDF not support mix up with build-in functions
# it seems like not support scalar_function mix up with aggregate functions
......@@ -204,147 +434,162 @@ class TDTestCase:
tdSql.error("select sum_double(id) ,add_one(id) from tb1")
tdSql.error("select sum_double(id) ,max(id) from st")
tdSql.error("select sum_double(id) ,max(id) from tb1")
tdSql.error("select twa(id),add_one(id) from st")
tdSql.error("select twa(id),add_one(id) from tb1")
# UDF function not support Arithmetic ===================
tdSql.query("select max(id) + 5 from st")
tdSql.query("select max(id) + 5 from tb1")
tdSql.query("select max(id) + avg(val) from st")
tdSql.query("select abs_max(number)*5 from st")
tdSql.checkData(0,0,46116860184273879040.000000000)
tdSql.query("select abs_max(number)*5 from tb1")
tdSql.checkData(0,0,2000.000000000)
tdSql.query("select max(id) + avg(val) from tb1")
tdSql.query("select abs_max(number) + 5 from st")
tdSql.query("select add_one(id) + 5 from st")
tdSql.checkData(4,0,10.000000000)
tdSql.query("select add_one(id)/5 from tb1")
tdSql.checkData(4,0,1.000000000)
tdSql.query("select sum_double(id)-5 from st")
tdSql.checkData(0,0,39.000000000)
tdSql.query("select sum_double(id)*5 from tb1")
tdSql.checkData(0,0,100.000000000)
tdSql.query("select abs_max(number) + 5 from tb1")
tdSql.error("select abs_max(number) + max(id) from st")
tdSql.query("select abs_max(number)*abs_max(val) from st")
tdSql.query("select abs_max(number)*abs_max(val) from st")
tdSql.query("select sum_double(id) + sum_double(id) from st")
tdSql.checkData(0,0,88.000000000)
tdLog.info("======= UDF Nested query test =======")
tdSql.query("select sum(id) from (select id from st)")
tdSql.checkData(0,0,22)
#UDF bug no 5 -> not support Nested query
# tdSql.query("select abs_max(number) from (select number from st)")
# tdSql.checkData(0,0,9223372036854775807)
# tdSql.query("select abs_max(number) from (select number from bound)")
# tdSql.checkData(0,0,9223372036854775807)
# tdSql.query("select sum_double(id) from (select id from st)")
# tdSql.checkData(0,0,44)
# tdSql.query("select sum_double(id) from (select id from tb1)")
# tdSql.checkData(0,0,10)
#UDF bug -> Nested query
# outer nest query
tdSql.query("select abs_max(number) from (select number from st)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from (select number from bound)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select sum_double(id) from (select id from st)")
tdSql.checkData(0,0,44)
tdSql.query("select sum_double(id) from (select id from bound)")
tdSql.checkData(0,0,4)
tdSql.query("select add_one(id) from (select id from st);")
tdSql.checkRows(14)
tdSql.checkData(1,0,2)
tdSql.query("select add_one(id) from (select id from bound);")
tdSql.checkRows(4)
tdSql.checkData(1,0,-2147483644)
# UDF bug no 6 -> group by work error
tdLog.info("======= UDF work with group by =======")
# inner nest query
tdSql.query("select id from (select add_one(id) id from st)")
tdSql.checkRows(14)
tdSql.checkData(13,0,None)
tdSql.query("select id from (select add_one(id) id from bound)")
tdSql.checkRows(4)
tdSql.checkData(3,0,None)
# tdSql.query("select sum_double(id) from st group by tbname;")
# tdSql.checkData(0,0,6)
# tdSql.checkData(0,1,'tb1')
# tdSql.checkData(1,0,2)
# tdSql.checkData(1,1,'tb2')
# tdSql.query("select sum_double(id) from st group by id;")
# tdSql.checkRows(2)
# tdSql.query("select sum_double(id) from st group by tbname order by ts asc;")
tdSql.query("select id from (select sum_double(id) id from bound)")
tdSql.checkData(0,0,4)
tdSql.query("select id from (select sum_double(id) id from st)") # it will crash taos shell
tdSql.checkData(0,0,44)
tdSql.query("select id from (select abs_max(number) id from st)") # it will crash taos shell
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select id from (select abs_max(number) id from bound)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(1s)")
tdSql.checkData(0,1,20)
tdSql.error("select sum_double(id) from st session(ts, 1s) interval (10s,1s) sliding(10s) fill (NULL) ")
tdSql.error("select sum_double(id) from st session(ts, 1s)")
tdSql.query("select sum_double(id) from tb1 session(ts, 1s)")
tdSql.checkData(0,1,20)
# inner and outer nest query
# UDF -> bug no 7 : intervals sliding values calculation error
# tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2")
# tdSql.checkData(0,1,20)
# tdSql.checkData(1,1,20)
tdSql.query("select add_one(id) from (select add_one(id) id from st)")
tdSql.checkRows(14)
tdSql.checkData(0,0,2)
tdSql.checkData(1,0,3)
tdSql.query("select add_one(id) from (select add_one(id) id from tb1)")
tdSql.checkRows(5)
tdSql.checkData(0,0,2)
tdSql.checkData(1,0,3)
tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from st)")
tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from tb1)")
# scalar_function can't work when using interval and sliding =========
tdSql.error("select add_one(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2 ")
tdSql.query("select abs_max(number) from (select abs_max(number) number from st)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from (select abs_max(number) number from bound)")
tdSql.checkData(0,0,9223372036854775807)
# nest inner and outer with build-in func
tdSql.query("select max(number) from (select abs_max(number) number from st)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select max(number) from (select abs_max(number) number from bound)")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from st)")
tdSql.query("select sum(sumdb) from (select sum_double(id) sumdb from tb1)")
tdSql.checkData(0,0,20)
tdLog.info(" =====================test illegal creation method =====================")
tdSql.execute("drop function add_one")
# tdSql.execute("drop function add_one")
tdSql.execute("drop function abs_max")
tdSql.execute("drop function sum_double")
tdSql.execute("create aggregate function error_use1 as '/tmp/abs_max.so' outputtype bigint ")
tdSql.error("select error_use1(number) from st")
# UDF -> bug no 8: error return values when create aggregate functions as an scalar_function
# illega UDF create aggregate functions as an scalar_function
# with no aggregate
# tdSql.execute("create function abs_max as '/tmp/abs_max.so' outputtype bigint bufsize 128")
# tdSql.query("select abs_max(number) from st") # this bug will return 3 rows
# tdSql.checkRows(1)
# tdSql.execute("create function sum_double as '/tmp/sum_double.so' outputtype bigint bufsize 128")
# tdSql.execute("select sum_double(id) from st")
# tdSql.checkRows(1)
# UDF -> bug no 9: give bufsize for scalar_function add_one;
# UDF -> need improve : when outputtype is not match datatype which is defined in function codes
tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128")
# tdSql.error("select add_one(val) from st") # it should return error not [] for not match col datatype
# tdSql.query("select add_one(id) from st") # return error query result
# tdSql.checkData(0,0,1)
# tdSql.checkData(1,0,2)
# tdSql.checkData(5,0,1)
# tdSql.checkData(10,0,-2147483645)
# tdSql.checkData(13,0,None)
tdSql.execute("create function abs_max as '/tmp/abs_max.so' outputtype bigint bufsize 128")
tdSql.error("select abs_max(number) from st")
tdSql.execute("create function sum_double as '/tmp/sum_double.so' outputtype bigint bufsize 128")
tdSql.error("select sum_double(id) from st")
# UDF -> improve : aggregate function with no bufsize : it seems with no affect
# tdSql.execute("drop function abs_max")
# tdSql.execute("drop function sum_double")
tdSql.execute("drop function abs_max")
tdSql.execute("drop function sum_double")
tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype bigint ")
tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype int ")
tdSql.query("select sum_double(id) from st")
tdSql.checkData(0,0,44)
tdSql.query("select sum_double(id) from tb1")
tdSql.checkData(0,0,20)
# tdSql.query("select abs_max(number) from st")
# tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from st")
tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from tb1")
tdSql.checkData(0,0,400)
#UDF bug no 10 -> create function datatype of outputtype not match col datatype
tdSql.execute("drop function abs_max")
tdSql.execute("drop function sum_double")
tdSql.execute("drop function add_one")
tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype bigint;")
tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype int bufsize 128;")
tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype double bufsize 128;")
# tdSql.query("select sum_double(id) from st") this bug will return 0.000000
# tdSql.checkData(0,0,44)
# tdSql.query("select sum_double(id) from tb1")
# tdSql.checkData(0,0,20) this bug will return 0.000000
# tdSql.query("select add_one(id) from st") this bug will return series error values
# tdSql.checkData(0,0,1)
# tdSql.checkData(1,0,2)
# tdSql.checkData(5,0,1)
# tdSql.checkData(10,0,-2147483645)
# tdSql.checkData(13,0,None)
# tdSql.query("select add_one(id) from tb1") this bug will return series error values
# tdSql.checkData(0,0,1)
# tdSql.checkData(2,0,3)
# tdSql.query("select abs_max(id) from st")
# tdSql.checkData(0,0,9223372036854775807)
tdSql.query("select abs_max(number) from tb1") # it seems work well
tdSql.checkData(0,0,400)
# UDF scalar function not support group by
tdSql.error("select add_one(id) from st group by tbname")
# UDF bug no 11 -> follow test case will coredump for taosd and let data lost
# tdSql.query("select add_one(id) from st group by tbname")
# UDF -> bug no 12: give aggregate for scalar_function add_one ,it will let taosd coredump as data lost
# tdSql.execute("drop function add_one")
# tdSql.execute("create aggregate function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128")
# tdSql.query("select add_one(id) from st")
# UDF bug no 13 -> follow test case will coredump for taosc
# tdSql.query("select add_one(*) from st ")
# tdSql.query("select add_one(*) from tb1 ")
# UDF bug no 14 -> follow test case will coredump for taosc
# tdSql.query("select abs_max(id),abs_max(number) from st ")
# tdSql.query("select abs_max(number),abs_max(number) from st ")
# tdSql.query("select sum_double(id),sum_double(id) from st ")
# UDF : give aggregate for scalar_function add_one ,it can't work well
tdSql.execute("drop function add_one")
tdSql.execute("create aggregate function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128")
tdSql.error("select add_one(id) from st")
# udf must give col list
tdSql.error("select add_one(*) from st ")
tdSql.error("select add_one(*) from tb1 ")
# one udf function can multi use
tdSql.query("select abs_max(id),abs_max(number) from st ")
tdSql.query("select abs_max(number),abs_max(number)*3 from st ")
tdSql.query("select abs_max(number),abs_max(number)*3 from tb1 ")
tdSql.query("select sum_double(id),sum_double(id) from st ")
def run(self):
tdSql.prepare()
......@@ -366,4 +611,4 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
......@@ -10,7 +10,7 @@ sql connect
print ======================== dnode1 start
sql create function add_one as '/tmp/add_one.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint;
sql show functions;
if $rows != 2 then
return -1
......
......@@ -11,7 +11,7 @@ print ======================== dnode1 start
sql create function add_one as '/tmp/add_one.so' outputtype int;
sql create function add_one_64232 as '/tmp/add_one_64232.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int;
sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint;
sql show functions;
if $rows != 3 then
return -1
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
typedef struct SUdfInit{
int maybe_null; /* 1 if function can return NULL */
int decimals; /* for real functions */
long long length; /* For string functions */
int64_t length; /* For string functions */
char *ptr; /* free pointer for function data */
int const_item; /* 0 if result is independent of arguments */
} SUdfInit;
......@@ -14,31 +15,36 @@ typedef struct SUdfInit{
#define TSDB_DATA_INT_NULL 0x80000000L
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput,
void abs_max(char* data, short itype, short ibytes, int numOfRows, int64_t* ts, char* dataOutput, char* interBuf, char* tsOutput,
int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
int i;
int r = 0;
printf("abs_max input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
int64_t r = 0;
// printf("abs_max input data:%p, type:%d, rows:%d, ts:%p, %" PRId64 ", dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if (itype == 5) {
r=*(long *)dataOutput;
r=*(int64_t *)dataOutput;
*numOfOutput=0;
for(i=0;i<numOfRows;++i) {
if (*((long *)data + i) == TSDB_DATA_BIGINT_NULL) {
if (*((int64_t *)data + i) == TSDB_DATA_BIGINT_NULL) {
continue;
}
*numOfOutput=1;
long v = abs(*((long *)data + i));
//int64_t v = abs(*((int64_t *)data + i));
int64_t v = *((int64_t *)data + i);
if (v < 0) {
v = 0 - v;
}
if (v > r) {
r = v;
}
}
*(long *)dataOutput=r;
*(int64_t *)dataOutput=r;
printf("abs_max out, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput);
} else {
// printf("abs_max out, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}else {
*numOfOutput=0;
}
}
......@@ -47,44 +53,43 @@ void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts
void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) {
int i;
int r = 0;
printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf);
printf("abs_max finalize, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput);
//int64_t r = 0;
// printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf);
// *numOfOutput=1;
// printf("abs_max finalize, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}
void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) {
int r = 0;
int64_t r = 0;
if (numOfRows > 0) {
r = *((long *)data);
r = *((int64_t *)data);
}
printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
// printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
for (int i = 1; i < numOfRows; ++i) {
printf("abs_max_merge %d - %ld\n", i, *((long *)data + i));
if (*((long*)data + i) > r) {
r= *((long*)data + i);
// printf("abs_max_merge %d - %" PRId64"\n", i, *((int64_t *)data + i));
if (*((int64_t*)data + i) > r) {
r= *((int64_t*)data + i);
}
}
*(long*)dataOutput=r;
*(int64_t*)dataOutput=r;
if (numOfRows > 0) {
*numOfOutput=1;
} else {
*numOfOutput=0;
}
printf("abs_max_merge, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput);
// printf("abs_max_merge, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}
int abs_max_init(SUdfInit* buf) {
printf("abs_max init\n");
// printf("abs_max init\n");
return 0;
}
void abs_max_destroy(SUdfInit* buf) {
printf("abs_max destroy\n");
}
// printf("abs_max destroy\n");
}
\ No newline at end of file
......@@ -14,20 +14,18 @@ void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts
int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
int i;
int r = 0;
printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
// printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if (itype == 4) {
for(i=0;i<numOfRows;++i) {
printf("input %d - %d", i, *((int *)data + i));
// printf("input %d - %d", i, *((int *)data + i));
*((int *)dataOutput+i)=*((int *)data + i) + 1;
printf(", output %d\n", *((int *)dataOutput+i));
// printf(", output %d\n", *((int *)dataOutput+i));
if (tsOutput) {
*(long long*)tsOutput=1000000;
}
}
*numOfOutput=numOfRows;
printf("add_one out, numOfOutput:%d\n", *numOfOutput);
// printf("add_one out, numOfOutput:%d\n", *numOfOutput);
}
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ void add_one_64232(char* data, short itype, short ibytes, int numOfRows, long lo
printf("add_one_64232 input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if (itype == 5) {
for(i=0;i<numOfRows;++i) {
printf("input %d - %d", i, *((long *)data + i));
printf("input %d - %ld", i, *((long *)data + i));
*((int *)dataOutput+i)=(int)*((long *)data + i) + 1;
printf(", output %d\n", *((int *)dataOutput+i));
if (tsOutput) {
......@@ -28,6 +28,4 @@ void add_one_64232(char* data, short itype, short ibytes, int numOfRows, long lo
printf("add_one_64232 out, numOfOutput:%d\n", *numOfOutput);
}
}
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
typedef struct SUdfInit{
int maybe_null; /* 1 if function can return NULL */
int decimals; /* for real functions */
long long length; /* For string functions */
int64_t length; /* For string functions */
char *ptr; /* free pointer for function data */
int const_item; /* 0 if result is independent of arguments */
} SUdfInit;
......@@ -13,13 +14,13 @@ typedef struct SUdfInit{
#define TSDB_DATA_INT_NULL 0x80000000L
void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput,
void sum_double(char* data, short itype, short ibytes, int numOfRows, int64_t* ts, char* dataOutput, char* interBuf, char* tsOutput,
int* numOfOutput, short otype, short obytes, SUdfInit* buf) {
int i;
int r = 0;
printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
int64_t r = 0;
printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%"PRId64", dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf);
if (itype == 4) {
r=*(int *)dataOutput;
r=*(int64_t *)dataOutput;
*numOfOutput=0;
for(i=0;i<numOfRows;++i) {
......@@ -29,10 +30,10 @@ void sum_double(char* data, short itype, short ibytes, int numOfRows, long long*
*numOfOutput=1;
r+=*((int *)data + i);
*(int *)dataOutput=r;
}
*(int64_t *)dataOutput=r;
}
printf("sum_double out, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
// printf("sum_double out, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}
}
......@@ -40,45 +41,44 @@ void sum_double(char* data, short itype, short ibytes, int numOfRows, long long*
void sum_double_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) {
int i;
int r = 0;
printf("sum_double_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf);
*numOfOutput=1;
*(int*)(buf->ptr)=*(int*)dataOutput*2;
*(int*)dataOutput=*(int*)(buf->ptr);
printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
int64_t r = 0;
// printf("sum_double_finalize dataoutput:%p:%"PRId64", numOfOutput:%d, buf:%p\n", dataOutput, *(int64_t*)dataOutput, *numOfOutput, buf);
// *numOfOutput=1;
*(int64_t*)(buf->ptr)=*(int64_t*)dataOutput*2;
*(int64_t*)dataOutput=*(int64_t*)(buf->ptr);
// printf("sum_double finalize, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}
void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) {
void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int* numOfOutput, SUdfInit* buf) {
int r = 0;
int sum = 0;
int64_t sum = 0;
printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
// printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf);
for (int i = 0; i < numOfRows; ++i) {
printf("sum_double_merge %d - %d\n", i, *((int*)data + i));
sum +=*((int*)data + i);
// printf("sum_double_merge %d - %"PRId64"\n", i, *((int64_t*)data + i));
sum +=*((int64_t*)data + i);
}
*(int*)dataOutput+=sum;
*(int64_t*)dataOutput+=sum;
if (numOfRows > 0) {
*numOfOutput=1;
} else {
*numOfOutput=0;
}
printf("sum_double_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput);
// printf("sum_double_merge, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput);
}
int sum_double_init(SUdfInit* buf) {
buf->maybe_null=1;
buf->ptr = malloc(sizeof(int));
printf("sum_double init\n");
buf->ptr = malloc(sizeof(int64_t));
// printf("sum_double init\n");
return 0;
}
void sum_double_destroy(SUdfInit* buf) {
free(buf->ptr);
printf("sum_double destroy\n");
}
// printf("sum_double destroy\n");
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册