Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
89e324c8
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
89e324c8
编写于
11月 02, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-10564]fix compiler error.
上级
f69a885d
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
245 addition
and
267 deletion
+245
-267
include/libs/function/function.h
include/libs/function/function.h
+32
-16
include/util/tdef.h
include/util/tdef.h
+0
-4
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+12
-141
source/libs/function/src/taggfunction.c
source/libs/function/src/taggfunction.c
+101
-101
source/libs/function/src/tfunction.c
source/libs/function/src/tfunction.c
+24
-0
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+76
-5
未找到文件。
include/libs/function/function.h
浏览文件 @
89e324c8
...
...
@@ -26,8 +26,8 @@ extern "C" {
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
#define FUNCTION_SCALAR 1
#define FUNCTION_AGG 2
#define FUNCTION_
TYPE_
SCALAR 1
#define FUNCTION_
TYPE_
AGG 2
#define TOP_BOTTOM_QUERY_LIMIT 100
#define FUNCTIONS_NAME_MAX_LENGTH 16
...
...
@@ -108,8 +108,23 @@ typedef struct SExtTagsInfo {
struct
SQLFunctionCtx
**
pTagCtxList
;
}
SExtTagsInfo
;
typedef
struct
SResultDataInfo
{
int16_t
type
;
int16_t
bytes
;
int32_t
intermediateBytes
;
}
SResultDataInfo
;
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
typedef
struct
SFunctionFpSet
{
bool
(
*
init
)(
struct
SQLFunctionCtx
*
pCtx
,
struct
SResultRowEntryInfo
*
pResultCellInfo
);
// setup the execute environment
void
(
*
addInput
)(
struct
SQLFunctionCtx
*
pCtx
);
// finalizer must be called after all exec has been executed to generated final result.
void
(
*
finalize
)(
struct
SQLFunctionCtx
*
pCtx
);
void
(
*
combine
)(
struct
SQLFunctionCtx
*
pCtx
);
}
SFunctionFpSet
;
// sql function runtime context
typedef
struct
SQLFunctionCtx
{
int32_t
size
;
// number of rows
...
...
@@ -118,9 +133,7 @@ typedef struct SQLFunctionCtx {
int16_t
inputType
;
int16_t
inputBytes
;
int16_t
outputType
;
int16_t
outputBytes
;
// size of results, determined by function and input column data type
int32_t
interBufBytes
;
// internal buffer size
SResultDataInfo
resDataInfo
;
bool
hasNull
;
// null value exist in current block
bool
requireNull
;
// require null in some function
bool
stableQuery
;
...
...
@@ -135,11 +148,13 @@ typedef struct SQLFunctionCtx {
SVariant
tag
;
bool
isAggSet
;
SColumnDataAgg
agg
;
SColumnDataAgg
agg
;
struct
SResultRowEntryInfo
*
resultInfo
;
SExtTagsInfo
tagInfo
;
SPoint1
start
;
SPoint1
end
;
SFunctionFpSet
*
fpSet
;
}
SQLFunctionCtx
;
enum
{
...
...
@@ -179,11 +194,11 @@ typedef struct SAggFunctionInfo {
uint16_t
status
;
bool
(
*
init
)(
SQLFunctionCtx
*
pCtx
,
struct
SResultRowEntryInfo
*
pResultCellInfo
);
// setup the execute environment
void
(
*
exec
)(
SQLFunctionCtx
*
pCtx
);
void
(
*
addInput
)(
SQLFunctionCtx
*
pCtx
);
// finalizer must be called after all exec has been executed to generated final result.
void
(
*
xF
inalize
)(
SQLFunctionCtx
*
pCtx
);
void
(
*
mergeFunc
)(
SQLFunctionCtx
*
pCtx
);
void
(
*
f
inalize
)(
SQLFunctionCtx
*
pCtx
);
void
(
*
combine
)(
SQLFunctionCtx
*
pCtx
);
int32_t
(
*
dataReqFunc
)(
SQLFunctionCtx
*
pCtx
,
STimeWindow
*
w
,
int32_t
colId
);
}
SAggFunctionInfo
;
...
...
@@ -194,15 +209,9 @@ typedef struct SScalarFunctionInfo {
uint8_t
functionId
;
// index of scalar function
bool
(
*
init
)(
SQLFunctionCtx
*
pCtx
,
struct
SResultRowEntryInfo
*
pResultCellInfo
);
// setup the execute environment
void
(
*
exec
)(
SQLFunctionCtx
*
pCtx
);
void
(
*
addInput
)(
SQLFunctionCtx
*
pCtx
);
}
SScalarFunctionInfo
;
typedef
struct
SResultDataInfo
{
int16_t
type
;
int16_t
bytes
;
int32_t
intermediateBytes
;
}
SResultDataInfo
;
typedef
struct
SMultiFunctionsDesc
{
bool
stableQuery
;
bool
groupbyColumn
;
...
...
@@ -280,6 +289,13 @@ int64_t getFillInfoStart(struct SFillInfo *pFillInfo);
int32_t
taosGetLinearInterpolationVal
(
SPoint
*
point
,
int32_t
outputType
,
SPoint
*
point1
,
SPoint
*
point2
,
int32_t
inputType
);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// udf api
struct
SUdfInfo
;
void
qAddUdfInfo
(
uint64_t
id
,
struct
SUdfInfo
*
pUdfInfo
);
void
qRemoveUdfInfo
(
uint64_t
id
,
struct
SUdfInfo
*
pUdfInfo
);
#ifdef __cplusplus
}
#endif
...
...
include/util/tdef.h
浏览文件 @
89e324c8
...
...
@@ -318,10 +318,6 @@ do { \
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
#define TSDB_UDF_TYPE_SCALAR 1
#define TSDB_UDF_TYPE_AGGREGATE 2
/*
* 1. ordinary sub query for select * from super_table
* 2. all sqlobj generated by createSubqueryObj with this flag
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
89e324c8
...
...
@@ -24,7 +24,6 @@
#include "function.h"
#include "tcompare.h"
#include "tcompression.h"
#include "tlosertree.h"
#include "ttypes.h"
#define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN)
...
...
@@ -356,39 +355,6 @@ void* destroyOutputBuf(SSDataBlock* pBlock) {
return
NULL
;
}
//int32_t getNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx* pCtx, int32_t numOfOutput) {
// SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr;
// bool hasMainFunction = hasMainOutput(pQueryAttr);
//
// int32_t maxOutput = 0;
// for (int32_t j = 0; j < numOfOutput; ++j) {
// int32_t id = pCtx[j].functionId;
//
// /*
// * ts, tag, tagprj function can not decide the output number of current query
// * the number of output result is decided by main output
// */
// if (hasMainFunction && (id == FUNCTION_TS || id == FUNCTION_TAG || id == FUNCTION_TAGPRJ)) {
// continue;
// }
//
// SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[j]);
// if (pResInfo != NULL && maxOutput < pResInfo->numOfRes) {
// maxOutput = pResInfo->numOfRes;
// }
// }
//
// assert(maxOutput >= 0);
// return maxOutput;
//}
//
//static void clearNumOfRes(SQLFunctionCtx* pCtx, int32_t numOfOutput) {
// for (int32_t j = 0; j < numOfOutput; ++j) {
// SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[j]);
// pResInfo->numOfRes = 0;
// }
//}
static
bool
isSelectivityWithTagsQuery
(
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
return
true
;
// bool hasTags = false;
...
...
@@ -848,8 +814,6 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey,
pResultRowInfo
->
curPos
=
i
+
1
;
// current not closed result object
}
}
//pResultRowInfo->prevSKey = pResultRowInfo->pResult[pResultRowInfo->curIndex]->win.skey;
}
static
void
updateResultRowInfoActiveIndex
(
SResultRowInfo
*
pResultRowInfo
,
SQueryAttr
*
pQueryAttr
,
TSKEY
lastKey
)
{
...
...
@@ -903,80 +867,6 @@ static int32_t getNumOfRowsInTimeWindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc
return
num
;
}
void
doInvokeUdf
(
struct
SUdfInfo
*
pUdfInfo
,
SQLFunctionCtx
*
pCtx
,
int32_t
idx
,
int32_t
type
)
{
#if 0
int32_t output = 0;
if (pUdfInfo == NULL || pUdfInfo->funcs[type] == NULL) {
//qError("empty udf function, type:%d", type);
return;
}
// //qDebug("invoke udf function:%s,%p", pUdfInfo->name, pUdfInfo->funcs[type]);
switch (type) {
case TSDB_UDF_FUNC_NORMAL:
if (pUdfInfo->isScript) {
(*(scriptNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])(pUdfInfo->pScriptCtx,
(char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList, pCtx->startTs, pCtx->pOutput,
(char *)pCtx->ptsOutputBuf, &output, pCtx->outputType, pCtx->outputBytes);
} else {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo);
(*(udfNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])((char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList,
pCtx->pOutput, interBuf, (char *)pCtx->ptsOutputBuf, &output, pCtx->outputType, pCtx->outputBytes, &pUdfInfo->init);
}
if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) {
pCtx->resultInfo->numOfRes = output;
} else {
pCtx->resultInfo->numOfRes += output;
}
if (pCtx->resultInfo->numOfRes > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
case TSDB_UDF_FUNC_MERGE:
if (pUdfInfo->isScript) {
(*(scriptMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pUdfInfo->pScriptCtx, pCtx->pInput, pCtx->size, pCtx->pOutput, &output);
} else {
(*(udfMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pCtx->pInput, pCtx->size, pCtx->pOutput, &output, &pUdfInfo->init);
}
// set the output value exist
pCtx->resultInfo->numOfRes = output;
if (output > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
case TSDB_UDF_FUNC_FINALIZE: {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo);
if (pUdfInfo->isScript) {
(*(scriptFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pUdfInfo->pScriptCtx, pCtx->startTs, pCtx->pOutput, &output);
} else {
(*(udfFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pCtx->pOutput, interBuf, &output, &pUdfInfo->init);
}
// set the output value exist
pCtx->resultInfo->numOfRes = output;
if (output > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
}
}
#endif
}
static
void
doApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
STimeWindow
*
pWin
,
int32_t
offset
,
int32_t
forwardStep
,
TSKEY
*
tsCol
,
int32_t
numOfTotal
,
int32_t
numOfOutput
)
{
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
...
...
@@ -1004,14 +894,8 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
pCtx
[
k
].
isAggSet
=
false
;
}
int32_t
functionId
=
pCtx
[
k
].
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
]))
{
// if (functionId < 0) { // load the script and exec, pRuntimeEnv->pUdfInfo
// SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
// doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL);
// } else {
// aAggs[functionId].xFunction(&pCtx[k]);
// }
pCtx
[
k
].
fpSet
->
addInput
(
&
pCtx
[
k
]);
}
// restore it
...
...
@@ -1020,9 +904,8 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
}
}
static
int32_t
getNextQualifiedWindow
(
SQueryAttr
*
pQueryAttr
,
STimeWindow
*
pNext
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
primaryKeys
,
__block_search_fn_t
searchFn
,
int32_t
prevPosition
)
{
static
int32_t
getNextQualifiedWindow
(
SQueryAttr
*
pQueryAttr
,
STimeWindow
*
pNext
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
primaryKeys
,
__block_search_fn_t
searchFn
,
int32_t
prevPosition
)
{
getNextTimeWindow
(
pQueryAttr
,
pNext
);
// next time window is not in current block
...
...
@@ -1244,14 +1127,7 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SQLFunction
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfOutput
;
++
k
)
{
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
]))
{
pCtx
[
k
].
startTs
=
startTs
;
// this can be set during create the struct
int32_t
functionId
=
pCtx
[
k
].
functionId
;
// if (functionId < 0) {
// SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo;
// doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL);
// } else {
// aAggs[functionId].xFunction(&pCtx[k]);
// }
pCtx
[
k
].
fpSet
->
addInput
(
&
pCtx
[
k
]);
}
}
}
...
...
@@ -1940,7 +1816,7 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
FUNCTION_TAG_DUMMY
||
functionId
==
FUNCTION_TS_DUMMY
)
{
tagLen
+=
pCtx
[
i
].
outputB
ytes
;
tagLen
+=
pCtx
[
i
].
resDataInfo
.
b
ytes
;
pTagCtx
[
num
++
]
=
&
pCtx
[
i
];
}
else
if
(
1
/*(aAggs[functionId].status & FUNCSTATE_SELECTIVITY) != 0*/
)
{
p
=
&
pCtx
[
i
];
...
...
@@ -1996,13 +1872,13 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
pCtx
->
ptsOutputBuf
=
NULL
;
pCtx
->
outputB
ytes
=
pSqlExpr
->
resSchema
.
bytes
;
pCtx
->
outputT
ype
=
pSqlExpr
->
resSchema
.
type
;
pCtx
->
resDataInfo
.
b
ytes
=
pSqlExpr
->
resSchema
.
bytes
;
pCtx
->
resDataInfo
.
t
ype
=
pSqlExpr
->
resSchema
.
type
;
pCtx
->
order
=
pQueryAttr
->
order
.
order
;
// pCtx->functionId = pSqlExpr->functionId;
pCtx
->
stableQuery
=
pQueryAttr
->
stableQuery
;
pCtx
->
interBuf
Bytes
=
pSqlExpr
->
interBytes
;
pCtx
->
resDataInfo
.
intermediate
Bytes
=
pSqlExpr
->
interBytes
;
pCtx
->
start
.
key
=
INT64_MIN
;
pCtx
->
end
.
key
=
INT64_MIN
;
...
...
@@ -3577,11 +3453,7 @@ void initCtxOutputBuffer(SQLFunctionCtx* pCtx, int32_t size) {
continue
;
}
// if (pCtx[j].functionId < 0) { // todo udf initialization
// continue;
// } else {
// aAggs[pCtx[j].functionId].init(&pCtx[j], pCtx[j].resultInfo);
// }
pCtx
[
j
].
fpSet
->
init
(
&
pCtx
[
j
],
pCtx
[
j
].
resultInfo
);
}
}
...
...
@@ -3737,12 +3609,12 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
struct
SResultRowEntryInfo
*
pResInfo
=
pCtx
[
i
].
resultInfo
;
if
(
isRowEntryCompleted
(
pResInfo
)
&&
isRowEntryInitialized
(
pResInfo
))
{
offset
+=
pCtx
[
i
].
outputB
ytes
;
offset
+=
pCtx
[
i
].
resDataInfo
.
b
ytes
;
continue
;
}
pCtx
[
i
].
pOutput
=
getPosInResultPage
(
pRuntimeEnv
->
pQueryAttr
,
bufPage
,
pResult
->
offset
,
offset
);
offset
+=
pCtx
[
i
].
outputB
ytes
;
offset
+=
pCtx
[
i
].
resDataInfo
.
b
ytes
;
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
<
0
)
{
...
...
@@ -3807,7 +3679,7 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
int16_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
pCtx
[
i
].
pOutput
=
getPosInResultPage
(
pRuntimeEnv
->
pQueryAttr
,
page
,
pResult
->
offset
,
offset
);
offset
+=
pCtx
[
i
].
outputB
ytes
;
offset
+=
pCtx
[
i
].
resDataInfo
.
b
ytes
;
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
FUNCTION_TOP
||
functionId
==
FUNCTION_BOTTOM
||
functionId
==
FUNCTION_DIFF
||
functionId
==
FUNCTION_DERIVATIVE
)
{
...
...
@@ -6881,7 +6753,6 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
}
SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv;
int32_t maxNumOfTables = (int32_t)pRuntimeEnv->resultInfo.capacity;
STagScanInfo *pInfo = pOperator->info;
...
...
source/libs/function/src/taggfunction.c
浏览文件 @
89e324c8
此差异已折叠。
点击以展开。
source/libs/function/src/tfunction.c
浏览文件 @
89e324c8
...
...
@@ -6,6 +6,7 @@
#include "tscalarfunction.h"
static
SHashObj
*
functionHashTable
=
NULL
;
static
SHashObj
*
udfHashTable
=
NULL
;
static
void
doInitFunctionHashTable
()
{
int
numOfEntries
=
tListLen
(
aggFunc
);
...
...
@@ -23,6 +24,8 @@ static void doInitFunctionHashTable() {
SScalarFunctionInfo
*
ptr
=
&
scalarFunc
[
i
];
taosHashPut
(
functionHashTable
,
scalarFunc
[
i
].
name
,
len
,
(
void
*
)
&
ptr
,
POINTER_BYTES
);
}
udfHashTable
=
taosHashInit
(
numOfEntries
,
MurmurHash3_32
,
true
,
true
);
}
static
pthread_once_t
functionHashTableInit
=
PTHREAD_ONCE_INIT
;
...
...
@@ -46,6 +49,27 @@ const char* qGetFunctionName(int32_t functionId) {
}
SAggFunctionInfo
*
qGetFunctionInfo
(
const
char
*
name
,
int32_t
len
)
{
pthread_once
(
&
functionHashTableInit
,
doInitFunctionHashTable
);
SAggFunctionInfo
**
pInfo
=
taosHashGet
(
functionHashTable
,
name
,
len
);
if
(
pInfo
!=
NULL
)
{
return
(
*
pInfo
);
}
else
{
return
NULL
;
}
}
void
qAddUdfInfo
(
uint64_t
id
,
SUdfInfo
*
pUdfInfo
)
{
int32_t
len
=
(
uint32_t
)
strlen
(
pUdfInfo
->
name
);
taosHashPut
(
udfHashTable
,
pUdfInfo
->
name
,
len
,
(
void
*
)
&
pUdfInfo
,
POINTER_BYTES
);
}
void
qRemoveUdfInfo
(
uint64_t
id
,
SUdfInfo
*
pUdfInfo
)
{
int32_t
len
=
(
uint32_t
)
strlen
(
pUdfInfo
->
name
);
taosHashRemove
(
udfHashTable
,
pUdfInfo
->
name
,
len
);
}
bool
isTagsQuery
(
SArray
*
pFunctionIdList
)
{
int32_t
num
=
(
int32_t
)
taosArrayGetSize
(
pFunctionIdList
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
source/libs/function/src/tudf.c
浏览文件 @
89e324c8
#include "tudf.h"
#if 0
static
char
*
getUdfFuncName
(
char
*
funcname
,
char
*
name
,
int
type
)
{
switch
(
type
)
{
case
TSDB_UDF_FUNC_NORMAL
:
...
...
@@ -26,6 +25,7 @@ static char* getUdfFuncName(char* funcname, char* name, int type) {
return
funcname
;
}
#if 0
int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
if (pUdfInfo == NULL) {
return TSDB_CODE_SUCCESS;
...
...
@@ -47,7 +47,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL] = taosLoadScriptNormal;
if (pUdfInfo->funcType ==
TSDB_UDF_TYPE_AGGREGATE
) {
if (pUdfInfo->funcType ==
FUNCTION_TYPE_AGG
) {
pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE] = taosLoadScriptFinalize;
pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE] = taosLoadScriptMerge;
}
...
...
@@ -55,7 +55,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
} else {
char path[PATH_MAX] = {0};
taosGetTmpfilePath("script", path);
taosGetTmpfilePath("script", path
, tsTempDir
);
FILE* file = fopen(path, "w+");
...
...
@@ -72,7 +72,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
return TSDB_CODE_QRY_SYS_ERROR;
}
char funcname[
TSDB_
FUNCTIONS_NAME_MAX_LENGTH + 10] = {0};
char funcname[FUNCTIONS_NAME_MAX_LENGTH + 10] = {0};
pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(funcname, pUdfInfo->name, TSDB_UDF_FUNC_NORMAL));
if (NULL == pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL]) {
return TSDB_CODE_QRY_SYS_ERROR;
...
...
@@ -80,7 +80,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
pUdfInfo->funcs[TSDB_UDF_FUNC_INIT] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(funcname, pUdfInfo->name, TSDB_UDF_FUNC_INIT));
if (pUdfInfo->funcType ==
TSDB_UDF_TYPE_AGGREGATE
) {
if (pUdfInfo->funcType ==
FUNCTION_TYPE_AGG
) {
pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(funcname, pUdfInfo->name, TSDB_UDF_FUNC_FINALIZE));
pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE] = taosLoadSym(pUdfInfo->handle, getUdfFuncName(funcname, pUdfInfo->name, TSDB_UDF_FUNC_MERGE));
}
...
...
@@ -121,4 +121,75 @@ void destroyUdfInfo(SUdfInfo* pUdfInfo) {
tfree(pUdfInfo);
}
void doInvokeUdf(struct SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, int32_t type) {
int32_t output = 0;
if (pUdfInfo == NULL || pUdfInfo->funcs[type] == NULL) {
//qError("empty udf function, type:%d", type);
return;
}
// //qDebug("invoke udf function:%s,%p", pUdfInfo->name, pUdfInfo->funcs[type]);
switch (type) {
case TSDB_UDF_FUNC_NORMAL:
if (pUdfInfo->isScript) {
(*(scriptNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])(pUdfInfo->pScriptCtx,
(char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList, pCtx->startTs, pCtx->pOutput,
(char *)pCtx->ptsOutputBuf, &output, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
} else {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo);
(*(udfNormalFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_NORMAL])((char *)pCtx->pInput + idx * pCtx->inputType, pCtx->inputType, pCtx->inputBytes, pCtx->size, pCtx->ptsList,
pCtx->pOutput, interBuf, (char *)pCtx->ptsOutputBuf, &output, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes, &pUdfInfo->init);
}
if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) {
pCtx->resultInfo->numOfRes = output;
} else {
pCtx->resultInfo->numOfRes += output;
}
if (pCtx->resultInfo->numOfRes > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
case TSDB_UDF_FUNC_MERGE:
if (pUdfInfo->isScript) {
(*(scriptMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pUdfInfo->pScriptCtx, pCtx->pInput, pCtx->size, pCtx->pOutput, &output);
} else {
(*(udfMergeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_MERGE])(pCtx->pInput, pCtx->size, pCtx->pOutput, &output, &pUdfInfo->init);
}
// set the output value exist
pCtx->resultInfo->numOfRes = output;
if (output > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
case TSDB_UDF_FUNC_FINALIZE: {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
void *interBuf = (void *)GET_ROWCELL_INTERBUF(pResInfo);
if (pUdfInfo->isScript) {
(*(scriptFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pUdfInfo->pScriptCtx, pCtx->startTs, pCtx->pOutput, &output);
} else {
(*(udfFinalizeFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_FINALIZE])(pCtx->pOutput, interBuf, &output, &pUdfInfo->init);
}
// set the output value exist
pCtx->resultInfo->numOfRes = output;
if (output > 0) {
pCtx->resultInfo->hasResult = DATA_SET_FLAG;
}
break;
}
}
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录