diff --git a/include/libs/function/tudf.h b/include/libs/function/tudf.h index e3e4a83bc1809a20924f14d07b3a56af31f657f4..37fd3c8e3c654e7d454f3fa5930b5b9a01463477 100644 --- a/include/libs/function/tudf.h +++ b/include/libs/function/tudf.h @@ -137,8 +137,8 @@ typedef int32_t (*TUdfTeardownFunc)(); //typedef int32_t addVariableLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t dataLen, char * data); typedef int32_t (*TUdfFreeUdfColumnFunc)(SUdfColumn* column); - typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock block, SUdfColumn *resultCol); + typedef int32_t (*TUdfAggInitFunc)(SUdfInterBuf *buf); typedef int32_t (*TUdfAggProcessFunc)(SUdfDataBlock block, SUdfInterBuf *interBuf); typedef int32_t (*TUdfAggFinalizeFunc)(SUdfInterBuf buf, SUdfInterBuf *resultData); diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 98f1209ad921ce9e86887a6972b4246ad7483d3a..5a3363123457c51b8b9f8051a8e5c77a8f25c9e0 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -51,6 +51,21 @@ target_link_libraries( udf1 PUBLIC os ) +add_library(udf2 MODULE test/udf2.c) +target_include_directories( + udf1 + PUBLIC + "${TD_SOURCE_DIR}/include/libs/function" + "${TD_SOURCE_DIR}/include/util" + "${TD_SOURCE_DIR}/include/common" + "${TD_SOURCE_DIR}/include/client" + "${TD_SOURCE_DIR}/include/os" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + udf2 PUBLIC os +) + #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin) add_executable(udfd src/udfd.c) target_include_directories( diff --git a/source/libs/function/test/udf1.c b/source/libs/function/test/udf1.c index 94cab9fee96377c170c70d45ec9a85f29a4976e3..6a2237470d599ddcc9330ecb2c8abe4495f084c7 100644 --- a/source/libs/function/test/udf1.c +++ b/source/libs/function/test/udf1.c @@ -9,11 +9,11 @@ #undef free #define free free -int32_t udf1_setup() { +int32_t udf1_init() { return 0; } -int32_t udf1_teardown() { +int32_t udf1_destroy() { return 0; } diff --git a/source/libs/function/test/udf2.c b/source/libs/function/test/udf2.c new file mode 100644 index 0000000000000000000000000000000000000000..3169f46263ce2e4cc03080bb519c0a674b7eb1b7 --- /dev/null +++ b/source/libs/function/test/udf2.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#include "tudf.h" + +#undef malloc +#define malloc malloc +#undef free +#define free free + +int32_t udf2_init() { + return 0; +} + +int32_t udf2_destroy() { + return 0; +} + +int32_t udf2_start(SUdfInterBuf *buf) { + +} + +int32_t udf2(SUdfDataBlock block, SUdfInterBuf *interBuf) { + +} + +int32_t udf2_finish(SUdfInterBuf buf, SUdfInterBuf *resultData) { + +} + +int32_t udf2(SUdfDataBlock block, SUdfColumn *resultCol) { + SUdfColumnData *resultData = &resultCol->colData; + resultData->numOfRows = block.numOfRows; + SUdfColumnData *srcData = &block.udfCols[0]->colData; + resultData->varLengthColumn = srcData->varLengthColumn; + + if (resultData->varLengthColumn) { + resultData->varLenCol.varOffsetsLen = srcData->varLenCol.varOffsetsLen; + resultData->varLenCol.varOffsets = malloc(resultData->varLenCol.varOffsetsLen); + memcpy(resultData->varLenCol.varOffsets, srcData->varLenCol.varOffsets, srcData->varLenCol.varOffsetsLen); + + resultData->varLenCol.payloadLen = srcData->varLenCol.payloadLen; + resultData->varLenCol.payload = malloc(resultData->varLenCol.payloadLen); + memcpy(resultData->varLenCol.payload, srcData->varLenCol.payload, srcData->varLenCol.payloadLen); + } else { + resultData->fixLenCol.nullBitmapLen = srcData->fixLenCol.nullBitmapLen; + resultData->fixLenCol.nullBitmap = malloc(resultData->fixLenCol.nullBitmapLen); + memcpy(resultData->fixLenCol.nullBitmap, srcData->fixLenCol.nullBitmap, srcData->fixLenCol.nullBitmapLen); + + resultData->fixLenCol.dataLen = srcData->fixLenCol.dataLen; + resultData->fixLenCol.data = malloc(resultData->fixLenCol.dataLen); + memcpy(resultData->fixLenCol.data, srcData->fixLenCol.data, srcData->fixLenCol.dataLen); + for (int32_t i = 0; i < resultData->numOfRows; ++i) { + *(resultData->fixLenCol.data + i * sizeof(int32_t)) = 88; + } + } + + SUdfColumnMeta *meta = &resultCol->colMeta; + meta->bytes = 4; + meta->type = TSDB_DATA_TYPE_INT; + meta->scale = 0; + meta->precision = 0; + return 0; +} + +int32_t udf2_free(SUdfColumn *col) { + SUdfColumnData *data = &col->colData; + if (data->varLengthColumn) { + free(data->varLenCol.varOffsets); + data->varLenCol.varOffsets = NULL; + free(data->varLenCol.payload); + data->varLenCol.payload = NULL; + } else { + free(data->fixLenCol.nullBitmap); + data->fixLenCol.nullBitmap = NULL; + free(data->fixLenCol.data); + data->fixLenCol.data = NULL; + } + return 0; +}