From 6345952f8829b9219f785d95458c987c9d0661c2 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 22 Mar 2023 20:30:25 +0800 Subject: [PATCH] test: debug python file --- tests/pytest/util/cases.py | 2 + .../0-others/udfpy/sf_multi_args.py | 4 +- tests/system-test/0-others/udfpy/sf_null.py | 4 +- tests/system-test/0-others/udfpy/sf_origin.py | 4 +- tests/system-test/0-others/udfpy_main.py | 45 +++++++++---------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/tests/pytest/util/cases.py b/tests/pytest/util/cases.py index 4830d2f8b0..536b8f30d3 100644 --- a/tests/pytest/util/cases.py +++ b/tests/pytest/util/cases.py @@ -17,6 +17,7 @@ import time import datetime import inspect import importlib +import traceback from util.log import * @@ -75,6 +76,7 @@ class TDCases: case.run() except Exception as e: tdLog.notice(repr(e)) + traceback.print_exc() tdLog.exit("%s failed" % (fileName)) case.stop() runNum += 1 diff --git a/tests/system-test/0-others/udfpy/sf_multi_args.py b/tests/system-test/0-others/udfpy/sf_multi_args.py index 5d8194b3ad..f5585b4e87 100644 --- a/tests/system-test/0-others/udfpy/sf_multi_args.py +++ b/tests/system-test/0-others/udfpy/sf_multi_args.py @@ -2,8 +2,8 @@ def init(): pass -# destory -def destory(): +# destroy +def destroy(): pass # return origin column one value diff --git a/tests/system-test/0-others/udfpy/sf_null.py b/tests/system-test/0-others/udfpy/sf_null.py index a82b147d01..c22ca95b19 100644 --- a/tests/system-test/0-others/udfpy/sf_null.py +++ b/tests/system-test/0-others/udfpy/sf_null.py @@ -3,8 +3,8 @@ def init(): pass -# destory -def destory(): +# destroy +def destroy(): pass # return origin column one value diff --git a/tests/system-test/0-others/udfpy/sf_origin.py b/tests/system-test/0-others/udfpy/sf_origin.py index 7588d0402d..9158e044d2 100644 --- a/tests/system-test/0-others/udfpy/sf_origin.py +++ b/tests/system-test/0-others/udfpy/sf_origin.py @@ -2,8 +2,8 @@ def init(): pass -# destory -def destory(): +# destroy +def destroy(): pass # return origin column one value diff --git a/tests/system-test/0-others/udfpy_main.py b/tests/system-test/0-others/udfpy_main.py index 0de48269e9..07fd64d983 100644 --- a/tests/system-test/0-others/udfpy_main.py +++ b/tests/system-test/0-others/udfpy_main.py @@ -98,21 +98,15 @@ class TDTestCase: tdLog.info(f" create {count} child tables ok.") - def create_udfpy_impl(self, funs, filename): - for name, outtype in funs.items(): - sql = f' create function {name} as "{self.udf_path}/{filename} {outtype} " language "Python" ' + # create with dicts + def create_sf_dicts(self, dicts, filename): + 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) - - - def create_udfpy_dicts(self, dicts, filename): - for k,v in dicts: - self.create_udfpy_impl(k, v, filename) + tdLog.info(sql) # create_udfpy_function - def create_udfpy_function(self): - # function - - + def create_scalar_udfpy(self): # scalar funciton self.scalar_funs = { 'sf1': 'tinyint', @@ -149,18 +143,19 @@ class TDTestCase: } # 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_udfpy_function(self.agg_funs, None) - + # fun_name == fun_name.py 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) + tdLog.info(sql) 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) + tdLog.info(sql) # sql1 query result eual with sql2 @@ -174,7 +169,7 @@ class TDTestCase: tdSql.checkData(i, j, result1[i][j]) # same value like select col1, udf_fun1(col1) from st - def verfiy_same_value(sql): + def verify_same_value(sql): tdSql.query(sql) nrows = tdSql.getRows() for i in range(nrows): @@ -205,11 +200,13 @@ class TDTestCase: # query_udfpy def query_scalar_udfpy(self): # col - for col_name, col_type in self.column_dict: - for fun_name, out_type in self.scalar_funs: + for col_name, col_type in self.column_dict.items(): + for fun_name, out_type in self.scalar_funs.items(): sql = f'select {col_name}, {fun_name}({col_name}) from {self.stbname}' + tdLog.info(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' + tdLog.info(sql) self.verify_same_value(sql) @@ -262,8 +259,8 @@ class TDTestCase: ts = 1670000000000 for i in range(self.child_count): for j in range(rows): - ti = j % 128 - cols = f'{ti},{ti},{i},{i},{ti},{ti},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' + tj = j % 128 + 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});' tdSql.execute(sql) @@ -284,10 +281,10 @@ class TDTestCase: # var stable = "meters" tbname = "d" - count = 100 + count = 10 # do self.create_table(stable, tbname, count) - self.insert_data(tbname, 1000) + self.insert_data(tbname, 100) # scalar self.create_scalar_udfpy() -- GitLab