提交 3f62f8a3 编写于 作者: S shenglian zhou

sync home and office

上级 6f5f6896
...@@ -22,6 +22,8 @@ extern "C" { ...@@ -22,6 +22,8 @@ extern "C" {
//====================================================================================== //======================================================================================
//begin API to taosd and qworker //begin API to taosd and qworker
#define TSDB_UDF_MAX_COLUMNS 4
enum { enum {
UDFC_CODE_STOPPING = -1, UDFC_CODE_STOPPING = -1,
UDFC_CODE_RESTARTING = -2, UDFC_CODE_RESTARTING = -2,
...@@ -49,15 +51,22 @@ enum { ...@@ -49,15 +51,22 @@ enum {
TSDB_UDF_SCRIPT_LUA = 1, TSDB_UDF_SCRIPT_LUA = 1,
}; };
typedef struct SUdfColumnMeta {
int16_t type;
int32_t bytes; // <0 var length, others fixed length bytes
uint8_t precision;
uint8_t scale;
} SUdfColumnMeta;
typedef struct SUdfInfo { typedef struct SUdfInfo {
char *udfName; // function name char *udfName; // function name
int32_t udfType; // scalar function or aggregate function int32_t udfType; // scalar function or aggregate function
int8_t scriptType; int8_t scriptType;
char *path; char *path;
int8_t resType; // result type // known info between qworker and udf
int16_t resBytes; // result byte // struct SUdfColumnMeta resultMeta;
int32_t bufSize; //interbuf size // int32_t bufSize; //interbuf size
} SUdfInfo; } SUdfInfo;
...@@ -72,33 +81,50 @@ typedef void *UdfHandle; ...@@ -72,33 +81,50 @@ typedef void *UdfHandle;
int32_t setupUdf(SUdfInfo* udf, UdfHandle *handle); int32_t setupUdf(SUdfInfo* udf, UdfHandle *handle);
enum { typedef struct SUdfColumnData {
TSDB_UDF_STEP_NORMAL = 0, int32_t numOfRows;
TSDB_UDF_STEP_MERGE, bool varLengthColumn;
TSDb_UDF_STEP_FINALIZE, union {
TSDB_UDF_STEP_MAX_NUM int32_t nullBitmapLen;
}; char* nullBitmap;
/** int32_t dataLen;
* call udf char* data;
* @param handle udf handle };
* @param step
* @param state union {
* @param stateSize int32_t varOffsetsLen;
* @param input char* varOffsets;
* @param newstate int32_t payloadLen;
* @param newStateSize char* payload;
* @param output };
* @return error code } SUdfColumnData;
*/
typedef struct SUdfColumn {
SUdfColumnMeta colMeta;
SUdfColumnData colData;
} SUdfColumn;
//TODO: must change the following after metadata flow and data flow between qworker and udfd is well defined
typedef struct SUdfDataBlock { typedef struct SUdfDataBlock {
char* data; int32_t numOfRows;
int32_t size; int32_t numOfCols;
SUdfColumn udfCols[TSDB_UDF_MAX_COLUMNS];
} SUdfDataBlock; } SUdfDataBlock;
int32_t callUdf(UdfHandle handle, int8_t step, char *state, int32_t stateSize, SUdfDataBlock input, char **newstate, typedef struct SUdfInterBuf {
int32_t *newStateSize, SUdfDataBlock *output); int32_t bufLen;
char* buf;
} SUdfInterBuf;
// input: block, initFirst
// output: interbuf
int32_t callUdfAggProcess(SUdfDataBlock block, SUdfInterBuf *interBuf, bool initFirst);
// input: interBuf
// output: resultData
int32_t callUdfAggFinalize(SUdfInterBuf interBuf, SUdfColumnData* resultData);
// input: block
// output: resultData
int32_t callUdfScalaProcess(SUdfDataBlock block, SUdfColumnData* resultData);
/** /**
* tearn down udf * tearn down udf
...@@ -109,30 +135,16 @@ int32_t teardownUdf(UdfHandle handle); ...@@ -109,30 +135,16 @@ int32_t teardownUdf(UdfHandle handle);
// end API to taosd and qworker // end API to taosd and qworker
//============================================================================================================================= //=============================================================================================================================
// TODO: Must change
// begin API to UDF writer. // begin API to UDF writer.
// script // dynamic lib init and destroy
//typedef int32_t (*scriptInitFunc)(void* pCtx);
//typedef void (*scriptNormalFunc)(void* pCtx, char* data, int16_t iType, int16_t iBytes, int32_t numOfRows,
// int64_t* ptList, int64_t key, char* dataOutput, char* tsOutput, int32_t* numOfOutput,
// int16_t oType, int16_t oBytes);
//typedef void (*scriptFinalizeFunc)(void* pCtx, int64_t key, char* dataOutput, int32_t* numOfOutput);
//typedef void (*scriptMergeFunc)(void* pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput);
//typedef void (*scriptDestroyFunc)(void* pCtx);
// dynamic lib
typedef int32_t (*TUdfInitFunc)(); typedef int32_t (*TUdfInitFunc)();
typedef void (*TUdfDestroyFunc)(); typedef int32_t (*TUdfDestroyFunc)();
typedef void (*TUdfFunc)(int8_t step,
char *state, int32_t stateSize, SUdfDataBlock input,
char **newstate, int32_t *newStateSize, SUdfDataBlock *output);
//typedef void (*udfMergeFunc)(char *data, int32_t numOfRows, char *dataOutput, int32_t* numOfOutput);
//typedef void (*udfFinalizeFunc)(char* state, int32_t stateSize, SUdfDataBlock *output);
typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock block, SUdfColumnData *resultData);
typedef int32_t (*TUdfAggInit)(SUdfInterBuf *buf);
typedef int32_t (*TUdfAggProcess)(SUdfDataBlock block, SUdfInterBuf *interBuf);
typedef int32_t (*TUdfAggFinalize)(SUdfInterBuf buf, SUdfColumnData *resultData);
// end API to UDF writer // end API to UDF writer
//======================================================================================================================= //=======================================================================================================================
......
...@@ -30,6 +30,12 @@ enum { ...@@ -30,6 +30,12 @@ enum {
}; };
enum {
TSDB_UDF_CALL_AGG_PROC = 0,
TSDb_UDF_CALL_AGG_FIN,
TSDB_UDF_CALL_SCALA_PROC,
};
typedef struct SUdfSetupRequest { typedef struct SUdfSetupRequest {
char udfName[16]; // char udfName[16]; //
int8_t scriptType; // 0:c, 1: lua, 2:js int8_t scriptType; // 0:c, 1: lua, 2:js
...@@ -42,24 +48,18 @@ typedef struct SUdfSetupResponse { ...@@ -42,24 +48,18 @@ typedef struct SUdfSetupResponse {
int64_t udfHandle; int64_t udfHandle;
} SUdfSetupResponse; } SUdfSetupResponse;
typedef struct SUdfCallRequest { typedef struct SUdfCallRequest {
int64_t udfHandle; int64_t udfHandle;
int8_t step; int8_t callType;
int32_t inputBytes; SUdfDataBlock block;
char *input; SUdfInterBuf interBuf;
bool initFirst;
int32_t stateBytes;
char *state;
} SUdfCallRequest; } SUdfCallRequest;
typedef struct SUdfCallResponse { typedef struct SUdfCallResponse {
int32_t outputBytes; SUdfColumnData resultData;
char *output; SUdfInterBuf interBuf;
int32_t newStateBytes;
char *newState;
} SUdfCallResponse; } SUdfCallResponse;
...@@ -76,7 +76,11 @@ typedef struct SUdfRequest { ...@@ -76,7 +76,11 @@ typedef struct SUdfRequest {
int64_t seqNum; int64_t seqNum;
int8_t type; int8_t type;
void *subReq; union {
SUdfSetupRequest setup;
SUdfCallRequest call;
SUdfTeardownRequest teardown;
};
} SUdfRequest; } SUdfRequest;
typedef struct SUdfResponse { typedef struct SUdfResponse {
...@@ -85,13 +89,17 @@ typedef struct SUdfResponse { ...@@ -85,13 +89,17 @@ typedef struct SUdfResponse {
int8_t type; int8_t type;
int32_t code; int32_t code;
void *subRsp; union {
SUdfSetupResponse setupRsp;
SUdfCallResponse callRsp;
SUdfTeardownResponse teardownRsp;
};
} SUdfResponse; } SUdfResponse;
int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest **pRequest); int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest *pRequest);
int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response);
int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request); int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request);
int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse **pResponse); int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse *pResponse);
int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
此差异已折叠。
...@@ -44,7 +44,7 @@ typedef struct SUdf { ...@@ -44,7 +44,7 @@ typedef struct SUdf {
int8_t type; int8_t type;
uv_lib_t lib; uv_lib_t lib;
TUdfFunc normalFunc; TUdfScalarProcFunc normalFunc;
} SUdf; } SUdf;
//TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix //TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册