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

SSDataBlock and SUdfInterBuf message passing between taosd/udfd

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