TDengine/source/libs/function/inc/tscript.h

85 lines
2.4 KiB
C
Raw Normal View History

2021-04-05 03:44:09 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_QSCRIPT_H
#define TDENGINE_QSCRIPT_H
#if 0
2021-04-05 03:44:09 +00:00
#include <lauxlib.h>
2022-10-13 06:15:42 +00:00
#include <lua.h>
2021-04-05 03:44:09 +00:00
#include <lualib.h>
#include "hash.h"
#include "tlist.h"
#include "tudf.h"
2022-10-13 06:15:42 +00:00
#include "tutil.h"
2021-04-05 03:44:09 +00:00
#define MAX_FUNC_NAME 64
2022-10-13 06:15:42 +00:00
#define USER_FUNC_NAME "funcName"
2021-04-22 09:08:52 +00:00
#define USER_FUNC_NAME_LIMIT 48
2021-04-05 03:44:09 +00:00
enum ScriptState {
SCRIPT_STATE_INIT,
SCRIPT_STATE_ADD,
SCRIPT_STATE_MERGE,
SCRIPT_STATE_FINALIZE
};
typedef struct {
SHashObj *funcId; //func already registed in lua_env, may be no use
lua_State *lua_state; // lua env
} ScriptEnv;
typedef struct ScriptCtx {
2021-04-22 09:08:52 +00:00
char funcName[USER_FUNC_NAME_LIMIT];
2021-04-05 03:44:09 +00:00
int8_t state;
ScriptEnv *pEnv;
int8_t isAgg; // agg function or not
// init value of udf script
2021-04-22 02:10:40 +00:00
int8_t resType;
int16_t resBytes;
2021-04-05 03:44:09 +00:00
int32_t numOfOutput;
int32_t offset;
} ScriptCtx;
2021-04-22 02:10:40 +00:00
int taosLoadScriptInit(void *pInit);
void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iBytes, int32_t numOfRows,
2021-05-08 07:22:27 +00:00
int64_t *ptsList, int64_t key, char* pOutput, char *ptsOutput, int32_t *numOfOutput, int16_t oType, int16_t oBytes);
void taosLoadScriptFinalize(void *pInit, int64_t key, char *pOutput, int32_t *output);
void taosLoadScriptMerge(void *pCtx, char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput);
2021-04-22 02:10:40 +00:00
void taosLoadScriptDestroy(void *pInit);
2021-04-05 03:44:09 +00:00
typedef struct {
SList *scriptEnvs; //
int32_t mSize; // pool limit
int32_t cSize; // current available size
2022-03-19 16:47:45 +00:00
TdThreadMutex mutex;
2021-04-05 03:44:09 +00:00
} ScriptEnvPool;
2021-04-22 02:10:40 +00:00
ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes);
2021-04-05 03:44:09 +00:00
void destroyScriptCtx(void *pScriptCtx);
int32_t scriptEnvPoolInit();
void scriptEnvPoolCleanup();
2021-04-22 02:10:40 +00:00
bool isValidScript(char *script, int32_t len);
#endif
2021-04-05 03:44:09 +00:00
2022-10-13 06:15:42 +00:00
#endif // TDENGINE_QSCRIPT_H