From a61572e432a3b95302a7004179c14efd367d3b80 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 4 Aug 2022 17:14:17 +0800 Subject: [PATCH] fix: add scalar example bitwise_and.c --- tests/script/sh/bitwise_and.c | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/script/sh/bitwise_and.c diff --git a/tests/script/sh/bitwise_and.c b/tests/script/sh/bitwise_and.c new file mode 100644 index 0000000000..496d326dce --- /dev/null +++ b/tests/script/sh/bitwise_and.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include "taosudf.h" + + +DLL_EXPORT int32_t bitwise_and_init() { + return 0; +} + +DLL_EXPORT int32_t bitwise_and_destroy() { + return 0; +} + +DLL_EXPORT int32_t bitwise_and(SUdfDataBlock* block, SUdfColumn *resultCol) { + + if (block->numOfCols < 2) { + return TSDB_CODE_UDF_INVALID_INPUT; + } + + for (int32_t i = 0; i < block->numOfCols; ++i) { + SUdfColumn* col = block->udfCols[i]; + if (!(col->colMeta.type == TSDB_DATA_TYPE_INT)) { + return TSDB_CODE_UDF_INVALID_INPUT; + } + } + + SUdfColumnMeta *meta = &resultCol->colMeta; + meta->bytes = 4; + meta->type = TSDB_DATA_TYPE_INT; + meta->scale = 0; + meta->precision = 0; + + + SUdfColumnData *resultData = &resultCol->colData; + + resultData->numOfRows = block->numOfRows; + + for (int32_t i = 0; i < resultData->numOfRows; ++i) { + int32_t result = *(int32_t*)udfColDataGetData(block->udfCols[0], i); + int j = 1; + for (; j < block->numOfCols; ++j) { + if (udfColDataIsNull(block->udfCols[j], i)) { + udfColDataSetNull(resultCol, i); + break; + } + + char* colData = udfColDataGetData(block->udfCols[j], i); + result &= *(int32_t*)colData; + } + if (j == block->numOfCols) { + udfColDataSet(resultCol, i, (char*)&result, false); + } + + } + return TSDB_CODE_SUCCESS; +}