提交 4817f54a 编写于 作者: S shenglian zhou

SSDataBlock and SUdfInterBuf message passing between taosd/udfd

上级 3526c0d4
......@@ -20,6 +20,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "tmsg.h"
#include "tcommon.h"
#ifdef __cplusplus
extern "C" {
......@@ -97,18 +98,20 @@ typedef struct SUdfInterBuf {
char* buf;
} SUdfInterBuf;
//TODO: translate these calls to callUdf
int32_t callUdfAggInit(SUdfInterBuf *interBuf);
// input: block, initFirst
// output: interbuf
int32_t callUdfAggProcess(SUdfDataBlock *block, SUdfInterBuf *interBuf, bool initFirst);
int32_t callUdfAggProcess(SSDataBlock *block, SUdfInterBuf *interBuf);
// input: interBuf
// output: resultData
int32_t callUdfAggFinalize(SUdfInterBuf *interBuf, SUdfColumnData *resultData);
int32_t callUdfAggFinalize(SUdfInterBuf *interBuf, SSDataBlock *resultData);
// input: interbuf1, interbuf2
// output: resultBuf
int32_t callUdfAggMerge(SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, SUdfInterBuf *resultBuf);
// input: block
// output: resultData
int32_t callUdfScalaProcess(SUdfDataBlock *block, SUdfColumnData *resultData);
int32_t callUdfScalaProcess(SSDataBlock *block, SSDataBlock *resultData);
/**
* tearn down udf
......@@ -125,6 +128,7 @@ int32_t teardownUdf(UdfHandle handle);
typedef int32_t (*TUdfSetupFunc)();
typedef int32_t (*TUdfTeardownFunc)();
//TODO: add API to check function arguments type, number etc.
//TODO: another way to manage memory is provide api for UDF to add data to SUdfColumnData and UDF framework will allocate memory.
// then UDF framework will free the memory
//typedef int32_t addFixedLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t colBytes, char* data);
......
......@@ -30,9 +30,10 @@ enum {
};
enum {
TSDB_UDF_CALL_AGG_PROC = 0,
TSDB_UDF_CALL_AGG_INIT = 0,
TSDB_UDF_CALL_AGG_PROC,
TSDB_UDF_CALL_AGG_MERGE,
TSDb_UDF_CALL_AGG_FIN,
TSDB_UDF_CALL_AGG_FIN,
TSDB_UDF_CALL_SCALA_PROC,
};
......@@ -49,14 +50,15 @@ typedef struct SUdfCallRequest {
int64_t udfHandle;
int8_t callType;
SUdfDataBlock block;
SSDataBlock block;
SUdfInterBuf interBuf;
SUdfInterBuf interBuf2;
bool initFirst;
int8_t initFirst;
} SUdfCallRequest;
typedef struct SUdfCallResponse {
SUdfColumnData resultData;
int8_t callType;
SSDataBlock resultData;
SUdfInterBuf interBuf;
} SUdfCallResponse;
......@@ -94,10 +96,11 @@ typedef struct SUdfResponse {
};
} SUdfResponse;
int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest *pRequest);
int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request);
int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse *pResponse);
int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response);
int32_t encodeUdfRequest(void **buf, const SUdfRequest* request);
void* decodeUdfRequest(const void *buf, SUdfRequest* request);
int32_t encodeUdfResponse(void **buf, const SUdfResponse *response);
void* decodeUdfResponse(const void* buf, SUdfResponse *response);
void freeUdfColumnData(SUdfColumnData *data);
void freeUdfColumn(SUdfColumn* col);
......
此差异已折叠。
......@@ -62,7 +62,7 @@ typedef struct SUdfHandle {
void udfdProcessRequest(uv_work_t *req) {
SUvUdfWork *uvUdf = (SUvUdfWork *) (req->data);
SUdfRequest request = {0};
decodeRequest(uvUdf->input.base, uvUdf->input.len, &request);
decodeUdfRequest(uvUdf->input.base, &request);
switch (request.type) {
case UDF_TASK_SETUP: {
......@@ -94,9 +94,10 @@ void udfdProcessRequest(uv_work_t *req) {
rsp.type = request.type;
rsp.code = 0;
rsp.setupRsp.udfHandle = (int64_t) (handle);
char *buf;
int32_t len;
encodeResponse(&buf, &len, &rsp);
int32_t len = encodeUdfResponse(NULL, &rsp);
rsp.msgLen = len;
void *buf = taosMemoryMalloc(len);
encodeUdfResponse(&buf, &rsp);
uvUdf->output = uv_buf_init(buf, len);
......@@ -110,7 +111,8 @@ void udfdProcessRequest(uv_work_t *req) {
SUdfHandle *handle = (SUdfHandle *) (call->udfHandle);
SUdf *udf = handle->udf;
SUdfDataBlock input = call->block;
SUdfDataBlock input = {0};
//TODO: convertSDataBlockToUdfDataBlock(call->block, &input);
SUdfColumnData output;
//TODO: call different functions according to call type, for now just calar
if (call->callType == TSDB_UDF_CALL_SCALA_PROC) {
......@@ -124,12 +126,13 @@ void udfdProcessRequest(uv_work_t *req) {
rsp->type = request.type;
rsp->code = 0;
SUdfCallResponse *subRsp = &rsp->callRsp;
subRsp->resultData = output;
//TODO: convertSUdfColumnDataToSSDataBlock(output, &subRsp->resultData);
}
char *buf;
int32_t len;
encodeResponse(&buf, &len, rsp);
int32_t len = encodeUdfResponse(NULL, rsp);
rsp->msgLen = len;
void *buf = taosMemoryMalloc(len);
encodeUdfResponse(&buf, rsp);
uvUdf->output = uv_buf_init(buf, len);
//TODO: free
......@@ -158,9 +161,10 @@ void udfdProcessRequest(uv_work_t *req) {
rsp->type = request.type;
rsp->code = 0;
SUdfTeardownResponse *subRsp = &response.teardownRsp;
char *buf;
int32_t len;
encodeResponse(&buf, &len, rsp);
int32_t len = encodeUdfResponse(NULL, rsp);
void *buf = taosMemoryMalloc(len);
rsp->msgLen = len;
encodeUdfResponse(&buf, rsp);
uvUdf->output = uv_buf_init(buf, len);
taosMemoryFree(uvUdf->input.base);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册