提交 6345952f 编写于 作者: A Alex Duan

test: debug python file

上级 cb59cc83
...@@ -17,6 +17,7 @@ import time ...@@ -17,6 +17,7 @@ import time
import datetime import datetime
import inspect import inspect
import importlib import importlib
import traceback
from util.log import * from util.log import *
...@@ -75,6 +76,7 @@ class TDCases: ...@@ -75,6 +76,7 @@ class TDCases:
case.run() case.run()
except Exception as e: except Exception as e:
tdLog.notice(repr(e)) tdLog.notice(repr(e))
traceback.print_exc()
tdLog.exit("%s failed" % (fileName)) tdLog.exit("%s failed" % (fileName))
case.stop() case.stop()
runNum += 1 runNum += 1
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
def init(): def init():
pass pass
# destory # destroy
def destory(): def destroy():
pass pass
# return origin column one value # return origin column one value
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
def init(): def init():
pass pass
# destory # destroy
def destory(): def destroy():
pass pass
# return origin column one value # return origin column one value
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
def init(): def init():
pass pass
# destory # destroy
def destory(): def destroy():
pass pass
# return origin column one value # return origin column one value
......
...@@ -98,21 +98,15 @@ class TDTestCase: ...@@ -98,21 +98,15 @@ class TDTestCase:
tdLog.info(f" create {count} child tables ok.") tdLog.info(f" create {count} child tables ok.")
def create_udfpy_impl(self, funs, filename): # create with dicts
for name, outtype in funs.items(): def create_sf_dicts(self, dicts, filename):
sql = f' create function {name} as "{self.udf_path}/{filename} {outtype} " language "Python" ' for fun_name, out_type in dicts.items():
sql = f' create function {fun_name} as "{self.udf_path}/{filename}" outputtype {out_type} language "Python" '
tdSql.execute(sql) tdSql.execute(sql)
tdLog.info(sql)
def create_udfpy_dicts(self, dicts, filename):
for k,v in dicts:
self.create_udfpy_impl(k, v, filename)
# create_udfpy_function # create_udfpy_function
def create_udfpy_function(self): def create_scalar_udfpy(self):
# function
# scalar funciton # scalar funciton
self.scalar_funs = { self.scalar_funs = {
'sf1': 'tinyint', 'sf1': 'tinyint',
...@@ -149,18 +143,19 @@ class TDTestCase: ...@@ -149,18 +143,19 @@ class TDTestCase:
} }
# files # files
self.create_udfpy_function(self.scalar_funs, "fun_origin") self.create_sf_dicts(self.scalar_funs, "sf_origin.py")
self.create_udf_sf("sf_multi_args", "binary(1024)") self.create_udf_sf("sf_multi_args", "binary(1024)")
#self.create_udfpy_function(self.agg_funs, None) # fun_name == fun_name.py
def create_udf_sf(self, fun_name, out_type): def create_udf_sf(self, fun_name, out_type):
sql = f'create function {fun_name} as {self.udf_path}{fun_name}.py {out_type} language "Python"' sql = f'create function {fun_name} as "{self.udf_path}/{fun_name}.py" outputtype {out_type} language "Python" '
tdSql.execute(sql) tdSql.execute(sql)
tdLog.info(sql)
def create_udf_af(self, fun_name, out_type, bufsize): def create_udf_af(self, fun_name, out_type, bufsize):
sql = f'create aggregate function {fun_name} as {self.udf_path}{fun_name}.py {out_type} bufsize {bufsize} language "Python"' sql = f'create aggregate function {fun_name} as "{self.udf_path}/{fun_name}.py" outputtype {out_type} bufsize {bufsize} language "Python" '
tdSql.execute(sql) tdSql.execute(sql)
tdLog.info(sql)
# sql1 query result eual with sql2 # sql1 query result eual with sql2
...@@ -174,7 +169,7 @@ class TDTestCase: ...@@ -174,7 +169,7 @@ class TDTestCase:
tdSql.checkData(i, j, result1[i][j]) tdSql.checkData(i, j, result1[i][j])
# same value like select col1, udf_fun1(col1) from st # same value like select col1, udf_fun1(col1) from st
def verfiy_same_value(sql): def verify_same_value(sql):
tdSql.query(sql) tdSql.query(sql)
nrows = tdSql.getRows() nrows = tdSql.getRows()
for i in range(nrows): for i in range(nrows):
...@@ -205,11 +200,13 @@ class TDTestCase: ...@@ -205,11 +200,13 @@ class TDTestCase:
# query_udfpy # query_udfpy
def query_scalar_udfpy(self): def query_scalar_udfpy(self):
# col # col
for col_name, col_type in self.column_dict: for col_name, col_type in self.column_dict.items():
for fun_name, out_type in self.scalar_funs: for fun_name, out_type in self.scalar_funs.items():
sql = f'select {col_name}, {fun_name}({col_name}) from {self.stbname}' sql = f'select {col_name}, {fun_name}({col_name}) from {self.stbname}'
tdLog.info(sql)
self.verify_same_value(sql) self.verify_same_value(sql)
sql = f'select * from (select {col_name} as a, {fun_name}({col_name}) as b from {self.stbname} ) order by b,a desc' sql = f'select * from (select {col_name} as a, {fun_name}({col_name}) as b from {self.stbname} ) order by b,a desc'
tdLog.info(sql)
self.verify_same_value(sql) self.verify_same_value(sql)
...@@ -262,8 +259,8 @@ class TDTestCase: ...@@ -262,8 +259,8 @@ class TDTestCase:
ts = 1670000000000 ts = 1670000000000
for i in range(self.child_count): for i in range(self.child_count):
for j in range(rows): for j in range(rows):
ti = j % 128 tj = j % 128
cols = f'{ti},{ti},{i},{i},{ti},{ti},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' cols = f'{tj},{tj},{j},{j},{tj},{tj},{j},{j},{j}.000{j},{j}.000{j},true,"var{j}","nch{j}",now'
sql = f'insert into {tbname}{i} values({ts+j},{cols});' sql = f'insert into {tbname}{i} values({ts+j},{cols});'
tdSql.execute(sql) tdSql.execute(sql)
...@@ -284,10 +281,10 @@ class TDTestCase: ...@@ -284,10 +281,10 @@ class TDTestCase:
# var # var
stable = "meters" stable = "meters"
tbname = "d" tbname = "d"
count = 100 count = 10
# do # do
self.create_table(stable, tbname, count) self.create_table(stable, tbname, count)
self.insert_data(tbname, 1000) self.insert_data(tbname, 100)
# scalar # scalar
self.create_scalar_udfpy() self.create_scalar_udfpy()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册