tscript.h 2.4 KB
Newer Older
Y
yihaoDeng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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

19
#if 0
Y
yihaoDeng 已提交
20
#include <lauxlib.h>
H
Hongze Cheng 已提交
21
#include <lua.h>
Y
yihaoDeng 已提交
22 23 24 25
#include <lualib.h>

#include "hash.h"
#include "tlist.h"
26
#include "tudf.h"
H
Hongze Cheng 已提交
27
#include "tutil.h"
Y
yihaoDeng 已提交
28 29 30

#define MAX_FUNC_NAME 64

H
Hongze Cheng 已提交
31
#define USER_FUNC_NAME       "funcName"
Y
yihaoDeng 已提交
32 33
#define USER_FUNC_NAME_LIMIT 48

Y
yihaoDeng 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47
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 {
Y
yihaoDeng 已提交
48
  char        funcName[USER_FUNC_NAME_LIMIT]; 
Y
yihaoDeng 已提交
49 50 51 52 53
  int8_t      state; 
  ScriptEnv  *pEnv;
  int8_t      isAgg; // agg function or not
  
  // init value of udf script
Y
yihaoDeng 已提交
54 55 56
  int8_t      resType;
  int16_t     resBytes; 

Y
yihaoDeng 已提交
57 58 59 60 61
  int32_t     numOfOutput; 
  int32_t     offset;
  
} ScriptCtx;

Y
yihaoDeng 已提交
62 63
int taosLoadScriptInit(void *pInit);
void taosLoadScriptNormal(void *pInit, char *pInput, int16_t iType, int16_t iBytes, int32_t numOfRows, 
Y
yihaoDeng 已提交
64 65 66
    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);
Y
yihaoDeng 已提交
67
void taosLoadScriptDestroy(void *pInit);
Y
yihaoDeng 已提交
68 69 70 71 72

typedef struct {
  SList     *scriptEnvs; //  
  int32_t   mSize;  // pool limit
  int32_t   cSize;  // current available size
wafwerar's avatar
wafwerar 已提交
73
  TdThreadMutex mutex;
Y
yihaoDeng 已提交
74 75
} ScriptEnvPool;

Y
yihaoDeng 已提交
76
ScriptCtx* createScriptCtx(char *str, int8_t resType, int16_t resBytes);
Y
yihaoDeng 已提交
77 78 79 80
void       destroyScriptCtx(void *pScriptCtx);

int32_t scriptEnvPoolInit();
void    scriptEnvPoolCleanup();
Y
yihaoDeng 已提交
81
bool    isValidScript(char *script, int32_t len);
82
#endif
Y
yihaoDeng 已提交
83

H
Hongze Cheng 已提交
84
#endif  // TDENGINE_QSCRIPT_H