From 521e5163a7c47678c1a6a542f9b831966e75d445 Mon Sep 17 00:00:00 2001 From: slzhou Date: Fri, 5 Aug 2022 09:18:03 +0800 Subject: [PATCH] fix: add sample udf cases and compile outside of tdengine --- tests/script/sh/bit_and.c | 4 ++++ tests/script/sh/compile_udf.sh | 4 ++-- tests/script/sh/sqr_sum.c | 2 +- tests/script/tsim/query/udf.sim | 15 +++++++++------ 4 files changed, 16 insertions(+), 9 deletions(-) mode change 100644 => 100755 tests/script/sh/compile_udf.sh diff --git a/tests/script/sh/bit_and.c b/tests/script/sh/bit_and.c index 6aeeaf2530..2f2e48fdb0 100644 --- a/tests/script/sh/bit_and.c +++ b/tests/script/sh/bit_and.c @@ -37,6 +37,10 @@ DLL_EXPORT int32_t bit_and(SUdfDataBlock* block, SUdfColumn *resultCol) { resultData->numOfRows = block->numOfRows; for (int32_t i = 0; i < resultData->numOfRows; ++i) { + if (udfColDataIsNull(block->udfCols[0], i)) { + udfColDataSetNull(resultCol, i); + continue; + } int32_t result = *(int32_t*)udfColDataGetData(block->udfCols[0], i); int j = 1; for (; j < block->numOfCols; ++j) { diff --git a/tests/script/sh/compile_udf.sh b/tests/script/sh/compile_udf.sh old mode 100644 new mode 100755 index 7cfd387c6d..12e922b2df --- a/tests/script/sh/compile_udf.sh +++ b/tests/script/sh/compile_udf.sh @@ -3,8 +3,8 @@ set +e rm -rf /tmp/udf/libbitand.so /tmp/udf/libsqrsum.so mkdir -p /tmp/udf echo "compile udf bit_and and sqr_sum" -gcc -fPIC -shared bit_and.c -o /tmp/udf/libbitand.so -gcc -fPIC -shared sqr_sum.c -o /tmp/udf/libsqrsum.so +gcc -fPIC -shared sh/bit_and.c -o /tmp/udf/libbitand.so +gcc -fPIC -shared sh/sqr_sum.c -o /tmp/udf/libsqrsum.so echo "debug show /tmp/udf/*.so" ls /tmp/udf/*.so diff --git a/tests/script/sh/sqr_sum.c b/tests/script/sh/sqr_sum.c index 0386d38993..af57f377ab 100644 --- a/tests/script/sh/sqr_sum.c +++ b/tests/script/sh/sqr_sum.c @@ -67,7 +67,7 @@ DLL_EXPORT int32_t sqr_sum(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInt return 0; } -DLL_EXPORT int32_t sqr_finish(SUdfInterBuf* buf, SUdfInterBuf *resultData) { +DLL_EXPORT int32_t sqr_sum_finish(SUdfInterBuf* buf, SUdfInterBuf *resultData) { if (buf->numOfResult == 0) { resultData->numOfResult = 0; return 0; diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index d1858f0efe..7259b1e779 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -122,22 +122,25 @@ print $rows , $data00 , $data01 if $rows != 1 then return -1 endi -if $data00 != 176.000000000 then +if $data00 != 1.414213562 then return -1 endi -if $data01 != 152.420471066 then +if $data01 != 1.414213562 then return -1 endi -sql select sqr_sum(f2) from udf.t2 group by 1-bit_and(f1); -print $rows , $data00 , $data10 -if $rows != 2 then +sql select sqr_sum(f2) from udf.t2 group by 1-bit_and(f1, f2) order by 1-bit_and(f1,f2); +print $rows , $data00 , $data10 , $data20 +if $rows != 3 then return -1 endi if $data00 != 2.000000000 then return -1 endi -if $data10 != 12.083045974 then +if $data10 != 9.055385138 then + return -1 +endi +if $data20 != 8.000000000 then return -1 endi