From a97f80070a1751eeb85043fb8cfb911c21c6b288 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 5 Jul 2021 09:50:23 +0800 Subject: [PATCH] add udf case --- tests/script/sh/abs_max.c | 87 ++++++++++++++++++++++++++++++++++ tests/script/sh/prepare_udf.sh | 1 + 2 files changed, 88 insertions(+) create mode 100644 tests/script/sh/abs_max.c diff --git a/tests/script/sh/abs_max.c b/tests/script/sh/abs_max.c new file mode 100644 index 0000000000..430f364c51 --- /dev/null +++ b/tests/script/sh/abs_max.c @@ -0,0 +1,87 @@ +#include +#include +#include + +typedef struct SUdfInit{ + int maybe_null; /* 1 if function can return NULL */ + int decimals; /* for real functions */ + long long length; /* For string functions */ + char *ptr; /* free pointer for function data */ + int const_item; /* 0 if result is independent of arguments */ +} SUdfInit; + +#define TSDB_DATA_INT_NULL 0x80000000L + + +void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* 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); + if (itype == 4) { + r=*(int *)dataOutput; + *numOfOutput=0; + + for(i=0;i r) { + r = v; + } + } + + *(int *)dataOutput=r; + + printf("abs_max out, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); + } +} + + + +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); + *numOfOutput=1; + printf("abs_max finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + +void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { + int r = 0; + + if (numOfRows > 0) { + r = *((int*)data); + } + 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 - %d\n", i, *((int*)data + i)); + if (*((int*)data + i) > r) { + r= *((int*)data + i); + } + } + + *(int*)dataOutput=r; + if (numOfRows > 0) { + *numOfOutput=1; + } else { + *numOfOutput=0; + } + + printf("abs_max_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); +} + + +int abs_max_init(SUdfInit* buf) { + printf("abs_max init\n"); + return 0; +} + + +void abs_max_destroy(SUdfInit* buf) { + printf("abs_max destroy\n"); +} + diff --git a/tests/script/sh/prepare_udf.sh b/tests/script/sh/prepare_udf.sh index a4619dc2e1..ecfc53660e 100644 --- a/tests/script/sh/prepare_udf.sh +++ b/tests/script/sh/prepare_udf.sh @@ -9,3 +9,4 @@ rm -rf /tmp/sum_double.so /tmp/add_one.so gcc -g -O0 -fPIC -shared sh/sum_double.c -o /tmp/sum_double.so gcc -g -O0 -fPIC -shared sh/add_one.c -o /tmp/add_one.so gcc -g -O0 -fPIC -shared sh/demo.c -o /tmp/demo.so +gcc -g -O0 -fPIC -shared sh/abs_max.c -o /tmp/abs_max.so -- GitLab