Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
76d5298b
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
76d5298b
编写于
2月 17, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/qnode
上级
bffdb7a8
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
449 addition
and
199 deletion
+449
-199
include/libs/function/function.h
include/libs/function/function.h
+2
-2
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-1
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+0
-2
source/libs/function/inc/tbinoperator.h
source/libs/function/inc/tbinoperator.h
+1
-1
source/libs/function/inc/tscalar.h
source/libs/function/inc/tscalar.h
+6
-2
source/libs/function/inc/tscalarfunction.h
source/libs/function/inc/tscalarfunction.h
+3
-3
source/libs/function/inc/tunaryoperator.h
source/libs/function/inc/tunaryoperator.h
+1
-1
source/libs/function/src/taggfunction.c
source/libs/function/src/taggfunction.c
+1
-1
source/libs/function/src/tbinoperator.c
source/libs/function/src/tbinoperator.c
+34
-34
source/libs/function/src/tscalar.c
source/libs/function/src/tscalar.c
+390
-142
source/libs/function/src/tscalarfunction.c
source/libs/function/src/tscalarfunction.c
+10
-10
未找到文件。
include/libs/function/function.h
浏览文件 @
76d5298b
...
...
@@ -226,13 +226,13 @@ typedef struct SAggFunctionInfo {
int32_t
(
*
dataReqFunc
)(
SqlFunctionCtx
*
pCtx
,
STimeWindow
*
w
,
int32_t
colId
);
}
SAggFunctionInfo
;
struct
SScalar
Func
Param
;
struct
SScalarParam
;
typedef
struct
SScalarFunctionInfo
{
char
name
[
FUNCTIONS_NAME_MAX_LENGTH
];
int8_t
type
;
// scalar function or aggregation function
uint32_t
functionId
;
// index of scalar function
void
(
*
process
)(
struct
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
struct
SScalarFunc
Param
*
pInput
);
void
(
*
process
)(
struct
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
struct
SScalar
Param
*
pInput
);
}
SScalarFunctionInfo
;
typedef
struct
SMultiFunctionsDesc
{
...
...
include/libs/function/functionMgt.h
浏览文件 @
76d5298b
...
...
@@ -117,7 +117,7 @@ typedef struct SFuncExecFuncs {
FExecFinalize
finalize
;
}
SFuncExecFuncs
;
typedef
int32_t
(
*
FScalarExecProcess
)(
SScalar
FuncParam
*
pInput
,
int32_t
inputNum
,
SScalarFunc
Param
*
pOutput
);
typedef
int32_t
(
*
FScalarExecProcess
)(
SScalar
Param
*
pInput
,
int32_t
inputNum
,
SScalar
Param
*
pOutput
);
typedef
struct
SScalarFuncExecFuncs
{
FScalarExecProcess
process
;
...
...
include/libs/nodes/querynodes.h
浏览文件 @
76d5298b
...
...
@@ -104,8 +104,6 @@ typedef enum EOperatorType {
OP_TYPE_NMATCH
,
OP_TYPE_IS_NULL
,
OP_TYPE_IS_NOT_NULL
,
OP_TYPE_BIT_AND
,
OP_TYPE_BIT_OR
,
// json operator
OP_TYPE_JSON_GET_VALUE
,
...
...
source/libs/function/inc/tbinoperator.h
浏览文件 @
76d5298b
...
...
@@ -22,7 +22,7 @@ extern "C" {
#include "tscalarfunction.h"
typedef
void
(
*
_bin_scalar_fn_t
)(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
output
,
int32_t
order
);
typedef
void
(
*
_bin_scalar_fn_t
)(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
output
,
int32_t
order
);
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binOperator
);
bool
isBinaryStringOp
(
int32_t
op
);
...
...
source/libs/function/inc/tscalar.h
浏览文件 @
76d5298b
...
...
@@ -19,9 +19,13 @@
extern
"C"
{
#endif
typedef
struct
SScalarCalcContext
{
typedef
struct
SScalarCtx
{
int32_t
code
;
SSDataBlock
*
pSrc
;
SHashObj
*
pRes
;
/* element is SScalarParam */
}
SScalarCtx
;
}
SScalarCalcContext
;
#define SCL_DEFAULT_OP_NUM 10
#define sclFatal(...) qFatal(__VA_ARGS__)
#define sclError(...) qError(__VA_ARGS__)
...
...
source/libs/function/inc/tscalarfunction.h
浏览文件 @
76d5298b
...
...
@@ -21,12 +21,12 @@ extern "C" {
#include "function.h"
typedef
struct
SScalar
Func
Param
{
typedef
struct
SScalarParam
{
void
*
data
;
int32_t
num
;
int32_t
type
;
int32_t
bytes
;
}
SScalar
Func
Param
;
}
SScalarParam
;
typedef
struct
SScalarFunctionSupport
{
struct
SExprInfo
*
pExprInfo
;
...
...
@@ -39,7 +39,7 @@ typedef struct SScalarFunctionSupport {
extern
struct
SScalarFunctionInfo
scalarFunc
[
8
];
int32_t
evaluateExprNodeTree
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
SScalar
Func
Param
*
pOutput
,
int32_t
evaluateExprNodeTree
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
SScalarParam
*
pOutput
,
void
*
param
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
));
...
...
source/libs/function/inc/tunaryoperator.h
浏览文件 @
76d5298b
...
...
@@ -22,7 +22,7 @@ extern "C" {
#include "tscalarfunction.h"
typedef
void
(
*
_unary_scalar_fn_t
)(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pOutput
);
typedef
void
(
*
_unary_scalar_fn_t
)(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pOutput
);
_unary_scalar_fn_t
getUnaryScalarOperatorFn
(
int32_t
binOperator
);
#ifdef __cplusplus
...
...
source/libs/function/src/taggfunction.c
浏览文件 @
76d5298b
...
...
@@ -3240,7 +3240,7 @@ static void arithmetic_function(SqlFunctionCtx *pCtx) {
GET_RES_INFO
(
pCtx
)
->
numOfRes
+=
pCtx
->
size
;
SScalarFunctionSupport
*
pSup
=
(
SScalarFunctionSupport
*
)
pCtx
->
param
[
1
].
pz
;
SScalar
Func
Param
output
=
{
0
};
SScalarParam
output
=
{
0
};
output
.
data
=
pCtx
->
pOutput
;
//evaluateExprNodeTree(pSup->pExprInfo->pExpr, pCtx->size, &output, pSup, getArithColumnData);
...
...
source/libs/function/src/tbinoperator.c
浏览文件 @
76d5298b
...
...
@@ -245,7 +245,7 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
}
int32_t
vectorConvertImpl
(
SScalar
FuncParam
*
pIn
,
SScalarFunc
Param
*
pOut
)
{
int32_t
vectorConvertImpl
(
SScalar
Param
*
pIn
,
SScalar
Param
*
pOut
)
{
int16_t
inType
=
pIn
->
type
;
int16_t
inBytes
=
pIn
->
bytes
;
char
*
input
=
pIn
->
data
;
...
...
@@ -512,13 +512,13 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
/*BLOB*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
int32_t
vectorConvert
(
SScalar
FuncParam
*
pLeft
,
SScalarFuncParam
*
pRight
,
SScalarFuncParam
*
pLeftOut
,
SScalarFunc
Param
*
pRightOut
)
{
int32_t
vectorConvert
(
SScalar
Param
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pLeftOut
,
SScalar
Param
*
pRightOut
)
{
if
(
pLeft
->
type
==
pRight
->
type
)
{
return
TSDB_CODE_SUCCESS
;
}
SScalar
Func
Param
*
param1
=
NULL
,
*
paramOut1
=
NULL
;
SScalar
Func
Param
*
param2
=
NULL
,
*
paramOut2
=
NULL
;
SScalarParam
*
param1
=
NULL
,
*
paramOut1
=
NULL
;
SScalarParam
*
param2
=
NULL
,
*
paramOut2
=
NULL
;
int32_t
code
=
0
;
if
(
pLeft
->
type
<
pRight
->
type
)
{
...
...
@@ -575,7 +575,7 @@ int32_t vectorConvert(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, SScalar
return
TSDB_CODE_SUCCESS
;
}
void
vectorAdd
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorAdd
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -614,7 +614,7 @@ void vectorAdd(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int
}
}
void
vectorSub
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorSub
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -651,7 +651,7 @@ void vectorSub(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, int
}
}
}
void
vectorMultiply
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorMultiply
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -690,7 +690,7 @@ void vectorMultiply(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out
}
}
void
vectorDivide
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorDivide
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -736,7 +736,7 @@ void vectorDivide(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
}
}
void
vectorRemainder
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorRemainder
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -808,7 +808,7 @@ void vectorRemainder(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *ou
}
}
void
vectorConcat
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorConcat
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
len
=
pLeft
->
bytes
+
pRight
->
bytes
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
...
...
@@ -859,7 +859,7 @@ void vectorConcat(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
}
void
vectorBitAnd
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorBitAnd
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -898,7 +898,7 @@ void vectorBitAnd(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
}
}
void
vectorBitOr
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorBitOr
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
...
...
@@ -938,7 +938,7 @@ void vectorBitOr(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out, i
}
void
vectorCompareImpl
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
,
int32_t
optr
)
{
void
vectorCompareImpl
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
,
int32_t
optr
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
int8_t
funcIdx
=
filterGetCompFuncIdx
(
pLeft
->
type
,
optr
);
...
...
@@ -993,14 +993,14 @@ void vectorCompareImpl(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *
}
}
void
vectorCompare
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
,
int32_t
optr
)
{
SScalar
Func
Param
pLeftOut
=
{
0
};
SScalar
Func
Param
pRightOut
=
{
0
};
void
vectorCompare
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
,
int32_t
optr
)
{
SScalarParam
pLeftOut
=
{
0
};
SScalarParam
pRightOut
=
{
0
};
vectorConvert
(
pLeft
,
pRight
,
&
pLeftOut
,
&
pRightOut
);
SScalar
Func
Param
*
param1
=
NULL
;
SScalar
Func
Param
*
param2
=
NULL
;
SScalarParam
*
param1
=
NULL
;
SScalarParam
*
param2
=
NULL
;
int32_t
type
=
0
;
if
(
pLeftOut
->
type
)
{
...
...
@@ -1018,55 +1018,55 @@ void vectorCompare(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
vectorCompareImpl
(
pLeftOut
,
pRightOut
,
out
,
_ord
,
TSDB_RELATION_GREATER
);
}
void
vectorGreater
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorGreater
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_GREATER
);
}
void
vectorGreaterEqual
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorGreaterEqual
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_GREATER_EQUAL
);
}
void
vectorLower
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorLower
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_LESS
);
}
void
vectorLowerEqual
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorLowerEqual
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_LESS_EQUAL
);
}
void
vectorEqual
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorEqual
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_EQUAL
);
}
void
vectorNotEqual
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorNotEqual
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_NOT_EQUAL
);
}
void
vectorIn
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorIn
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_IN
);
}
void
vectorNotIn
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorNotIn
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_NOT_IN
);
}
void
vectorLike
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorLike
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_LIKE
);
}
void
vectorNotLike
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorNotLike
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_NOT_LIKE
);
}
void
vectorMatch
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorMatch
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_MATCH
);
}
void
vectorNotMatch
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorNotMatch
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
vectorCompare
(
pLeft
,
pRight
,
out
,
_ord
,
TSDB_RELATION_NMATCH
);
}
void
vectorIsNull
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorIsNull
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
bool
res
=
false
;
...
...
@@ -1086,7 +1086,7 @@ void vectorIsNull(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
}
}
void
vectorNotNull
(
SScalar
FuncParam
*
pLeft
,
SScalarFunc
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
void
vectorNotNull
(
SScalar
Param
*
pLeft
,
SScalar
Param
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
bool
res
=
false
;
...
...
@@ -1143,9 +1143,9 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
return
vectorMatch
;
case
OP_TYPE_NMATCH
:
return
vectorNotMatch
;
case
OP_TYPE_ISNULL
:
case
OP_TYPE_IS
_
NULL
:
return
vectorIsNull
;
case
OP_TYPE_
NOT
NULL
:
case
OP_TYPE_
IS_NOT_
NULL
:
return
vectorNotNull
;
case
OP_TYPE_BIT_AND
:
return
vectorBitAnd
;
...
...
source/libs/function/src/tscalar.c
浏览文件 @
76d5298b
...
...
@@ -2,79 +2,326 @@
#include "tscalar.h"
int32_t
sclGetOperatorParamNum
(
EOperatorType
type
)
{
if
(
OP_TYPE_IS
NULL
==
type
||
OP_TYPE_NOT
NULL
==
type
)
{
if
(
OP_TYPE_IS
_NULL
==
type
||
OP_TYPE_IS_NOT_
NULL
==
type
)
{
return
1
;
}
return
2
;
}
int32_t
sclPrepareFunctionParams
(
SScalarFuncParam
**
pParams
,
SNodeList
*
pParameterList
)
{
*
pParams
=
calloc
(
pParameterList
->
length
,
sizeof
(
SScalarFuncParam
));
void
sclFreeRes
(
SHashObj
*
res
)
{
SScalarParam
*
p
=
NULL
;
void
*
pIter
=
taosHashIterate
(
res
,
NULL
);
while
(
pIter
)
{
p
=
(
SScalarParam
*
)
pIter
;
if
(
p
)
{
tfree
(
p
->
data
);
}
pIter
=
taosHashIterate
(
res
,
pIter
);
}
taosHashCleanup
(
res
);
}
void
sclFreeParam
(
SScalarParam
*
param
)
{
tfree
(
param
->
data
);
}
int32_t
sclInitParam
(
SNode
*
node
,
SScalarParam
*
param
,
SScalarCtx
*
ctx
,
int32_t
*
rowNum
)
{
switch
(
nodeType
(
node
))
{
case
QUERY_NODE_VALUE
:
{
SValueNode
*
valueNode
=
(
SValueNode
*
)
node
;
param
->
data
=
nodesGetValueFromNode
(
valueNode
);
param
->
num
=
1
;
param
->
type
=
valueNode
->
node
.
resType
.
type
;
param
->
bytes
=
valueNode
->
node
.
resType
.
bytes
;
break
;
}
case
QUERY_NODE_COLUMN_REF
:
{
if
(
NULL
==
ctx
)
{
sclError
(
"invalid node type for constant calculating, type:%d, ctx:%p"
,
nodeType
(
node
),
ctx
);
SCL_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
SColumnRef
*
ref
=
(
SColumnRef
*
)
node
;
if
(
ref
->
slotId
>=
taosArrayGetSize
(
ctx
->
pSrc
->
pDataBlock
))
{
sclError
(
"column ref slotId is too big, slodId:%d, dataBlockSize:%d"
,
ref
->
slotId
,
taosArrayGetSize
(
ctx
->
pSrc
->
pDataBlock
));
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SColumnInfoData
*
columnData
=
(
SColumnInfoData
*
)
taosArrayGet
(
ctx
->
pSrc
->
pDataBlock
,
ref
->
slotId
);
param
->
data
=
columnData
->
pData
;
param
->
num
=
ctx
->
pSrc
->
info
.
rows
;
param
->
type
=
columnData
->
info
.
type
;
param
->
bytes
=
columnData
->
info
.
bytes
;
break
;
}
case
QUERY_NODE_LOGIC_CONDITION
:
case
QUERY_NODE_OPERATOR
:
{
if
(
NULL
==
ctx
)
{
sclError
(
"invalid node type for constant calculating, type:%d, ctx:%p"
,
nodeType
(
node
),
ctx
);
SCL_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
SScalarParam
*
res
=
(
SScalarParam
*
)
taosHashGet
(
ctx
->
pRes
,
&
node
,
POINTER_BYTES
);
if
(
NULL
==
res
)
{
sclError
(
"no result for node, type:%d, node:%p"
,
nodeType
(
node
),
node
);
SCL_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
*
param
=
*
res
;
break
;
}
}
if
(
param
->
num
>
*
rowNum
)
{
if
(
1
!=
param
->
num
)
&&
(
1
<
*
rowNum
)
{
sclError
(
"different row nums, rowNum:%d, newRowNum:%d"
,
*
rowNum
,
param
->
num
);
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
*
rowNum
=
param
->
num
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
sclParamMoveNext
(
SScalarParam
*
params
,
int32_t
num
)
{
SScalarParam
*
param
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
param
=
params
+
i
;
if
(
1
==
param
->
num
)
{
continue
;
}
if
(
IS_VAR_DATA_TYPE
(
param
->
type
))
{
param
->
data
=
(
char
*
)(
param
->
data
)
+
varDataTLen
(
param
->
data
);
}
else
{
param
->
data
=
(
char
*
)(
param
->
data
)
+
tDataTypes
[
param
->
type
].
bytes
;
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
sclInitParamList
(
SScalarParam
**
pParams
,
SNodeList
*
pParamList
,
SScalarCtx
*
ctx
,
int32_t
*
rowNum
)
{
int32_t
code
=
0
;
*
pParams
=
calloc
(
pParamList
->
length
,
sizeof
(
SScalarParam
));
if
(
NULL
==
*
pParams
)
{
sclError
(
"calloc %d failed"
,
pParam
eterList
->
length
*
sizeof
(
SScalarFunc
Param
));
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
sclError
(
"calloc %d failed"
,
pParam
List
->
length
*
sizeof
(
SScalar
Param
));
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
)
;
}
SListCell
*
cell
=
pParam
eter
List
->
pHead
;
for
(
int32_t
i
=
0
;
i
<
pParam
eter
List
->
length
;
++
i
)
{
SListCell
*
cell
=
pParamList
->
pHead
;
for
(
int32_t
i
=
0
;
i
<
pParamList
->
length
;
++
i
)
{
if
(
NULL
==
cell
||
NULL
==
cell
->
pNode
)
{
sclError
(
"invalid cell, cell:%p, pNode:%p"
,
cell
,
cell
->
pNode
);
tfree
(
*
pParams
);
return
TSDB_CODE_QRY_INVALID_INPUT
;
SCL_ERR_JRET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
if
(
QUERY_NODE_VALUE
!=
nodeType
(
cell
->
pNode
))
{
sclError
(
"invalid node type in cell, type:%d"
,
nodeType
(
cell
->
pNode
));
tfree
(
*
pParams
);
return
TSDB_CODE_QRY_APP_ERROR
;
}
SCL_ERR_JRET
(
sclInitParam
(
cell
->
pNode
,
&
pParams
[
i
],
ctx
,
rowNum
));
cell
=
cell
->
pNext
;
}
SValueNode
*
valueNode
=
(
SValueNode
*
)
cell
->
pNode
;
pParams
[
i
].
data
=
nodesGetValueFromNode
(
valueNode
);
pParams
[
i
].
num
=
1
;
pParams
[
i
].
type
=
valueNode
->
node
.
resType
.
type
;
pParams
[
i
].
bytes
=
valueNode
->
node
.
resType
.
bytes
;
return
TSDB_CODE_SUCCESS
;
cell
=
cell
->
pNext
;
_return:
tfree
(
*
pParams
);
SCL_RET
(
code
);
}
int32_t
sclInitOperatorParams
(
SScalarParam
**
pParams
,
SOperatorNode
*
node
,
SScalarCtx
*
ctx
,
int32_t
*
rowNum
)
{
int32_t
code
=
0
;
int32_t
paramNum
=
sclGetOperatorParamNum
(
node
->
opType
);
if
(
NULL
==
node
->
pLeft
||
(
paramNum
==
2
&&
NULL
==
node
->
pRight
))
{
sclError
(
"invalid operation node, left:%p, right:%p"
,
node
->
pLeft
,
node
->
pRight
);
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
*
pParams
=
calloc
(
paramNum
,
sizeof
(
SScalarParam
));
if
(
NULL
==
*
pParams
)
{
sclError
(
"calloc %d failed"
,
paramNum
*
sizeof
(
SScalarParam
));
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
SCL_ERR_JRET
(
sclInitParam
(
node
->
pLeft
,
&
pParams
[
0
],
ctx
,
rowNum
));
if
(
paramNum
>
1
)
{
SCL_ERR_JRET
(
sclInitParam
(
node
->
pRight
,
&
pParams
[
1
],
ctx
,
rowNum
));
}
return
TSDB_CODE_SUCCESS
;
_return:
tfree
(
*
pParams
);
SCL_RET
(
code
);
}
EDealRes
sclRewriteFunction
(
SNode
**
pNode
,
void
*
pContext
)
{
SFunctionNode
*
node
=
(
SFunctionNode
*
)
*
pNode
;
int32_t
sclExecFuncion
(
SFunctionNode
*
node
,
SScalarCtx
*
ctx
,
SScalarParam
*
output
)
{
if
(
NULL
==
node
->
pParameterList
||
node
->
pParameterList
->
length
<=
0
)
{
sclError
(
"invalid function parameter list, list:%p, paramNum:%d"
,
node
->
pParameterList
,
node
->
pParameterList
?
node
->
pParameterList
->
length
:
0
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SScalarFuncExecFuncs
ffpSet
=
{
0
};
int32_t
code
=
fmGetScalarFuncExecFuncs
(
node
->
funcId
,
&
ffpSet
);
if
(
code
)
{
sclError
(
"fmGetFuncExecFuncs failed, funcId:%d, code:%s"
,
node
->
funcId
,
tstrerror
(
code
));
*
(
int32_t
*
)
pContext
=
code
;
return
DEAL_RES_ERROR
;
SCL_ERR_RET
(
code
);
}
SScalarFuncParam
*
input
=
NULL
;
if
(
sclPrepareFunctionParams
(
&
input
,
node
->
pParameterList
))
{
return
DEAL_RES_ERROR
;
SScalarParam
*
params
=
NULL
;
int32_t
rowNum
=
0
;
SCL_ERR_RET
(
sclInitParamList
(
&
params
,
node
->
pParameterList
,
ctx
,
&
rowNum
));
output
->
type
=
node
->
node
.
resType
.
type
;
output
->
data
=
calloc
(
rowNum
,
sizeof
(
tDataTypes
[
output
->
type
].
bytes
));
if
(
NULL
==
output
->
data
)
{
sclError
(
"calloc %d failed"
,
(
int32_t
)
rowNum
*
sizeof
(
tDataTypes
[
output
->
type
].
bytes
));
SCL_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
code
=
(
*
ffpSet
.
process
)(
params
,
node
->
pParameterList
->
length
,
output
);
if
(
code
)
{
sclError
(
"scalar function exec failed, funcId:%d, code:%s"
,
node
->
funcId
,
tstrerror
(
code
));
SCL_ERR_JRET
(
code
);
}
sclParamMoveNext
(
output
,
1
);
sclParamMoveNext
(
params
,
node
->
pParameterList
->
length
);
}
return
TSDB_CODE_SUCCESS
;
_return:
tfree
(
params
);
SCL_RET
(
code
);
}
int32_t
sclExecLogic
(
SLogicConditionNode
*
node
,
SScalarCtx
*
ctx
,
SScalarParam
*
output
)
{
if
(
NULL
==
node
->
pParameterList
||
node
->
pParameterList
->
length
<=
0
)
{
sclError
(
"invalid logic parameter list, list:%p, paramNum:%d"
,
node
->
pParameterList
,
node
->
pParameterList
?
node
->
pParameterList
->
length
:
0
);
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
if
(
TSDB_DATA_TYPE_BOOL
!=
node
->
node
.
resType
.
type
)
{
sclError
(
"invalid logic resType, type:%d"
,
node
->
node
.
resType
.
type
);
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SScalarFuncParam
output
=
{
0
};
if
(
LOGIC_COND_TYPE_NOT
==
node
->
condType
&&
node
->
pParameterList
->
length
>
1
)
{
sclError
(
"invalid NOT operation parameter number, paramNum:%d"
,
node
->
pParameterList
->
length
);
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SScalarParam
*
params
=
NULL
;
int32_t
rowNum
=
0
;
int32_t
code
=
0
;
code
=
(
*
ffpSet
.
process
)(
input
,
node
->
pParameterList
->
length
,
&
output
);
if
(
code
)
{
sclError
(
"scalar function exec failed, funcId:%d, code:%s"
,
node
->
funcId
,
tstrerror
(
code
));
*
(
int32_t
*
)
pContext
=
code
;
SCL_ERR_RET
(
sclInitParamList
(
&
params
,
node
->
pParameterList
,
ctx
,
&
rowNum
));
output
->
type
=
node
->
node
.
resType
.
type
;
output
->
data
=
calloc
(
rowNum
,
sizeof
(
bool
));
if
(
NULL
==
output
->
data
)
{
sclError
(
"calloc %d failed"
,
(
int32_t
)
rowNum
*
sizeof
(
bool
));
SCL_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
bool
value
=
false
;
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
for
(
int32_t
m
=
0
;
m
<
node
->
pParameterList
->
length
;
++
m
)
{
GET_TYPED_DATA
(
value
,
bool
,
params
[
m
].
type
,
params
[
m
].
data
);
if
(
LOGIC_COND_TYPE_AND
==
node
->
condType
&&
(
false
==
value
))
{
break
;
}
else
if
(
LOGIC_COND_TYPE_OR
==
node
->
condType
&&
value
)
{
break
;
}
else
if
(
LOGIC_COND_TYPE_NOT
==
node
->
condType
)
{
value
=
!
value
;
}
}
*
(
bool
*
)
output
->
data
=
value
;
sclParamMoveNext
(
output
,
1
);
sclParamMoveNext
(
params
,
node
->
pParameterList
->
length
);
}
return
TSDB_CODE_SUCCESS
;
_return:
tfree
(
params
);
CTG_RET
(
code
);
}
int32_t
sclExecOperator
(
SOperatorNode
*
node
,
SScalarCtx
*
ctx
,
SScalarParam
*
output
)
{
SScalarParam
*
params
=
NULL
;
int32_t
rowNum
=
0
;
int32_t
code
=
0
;
SCL_ERR_RET
(
sclInitOperatorParams
(
&
params
,
node
,
ctx
,
&
rowNum
));
output
->
type
=
node
->
node
.
resType
.
type
;
output
->
data
=
calloc
(
rowNum
,
sizeof
(
tDataTypes
[
output
->
type
].
bytes
));
if
(
NULL
==
output
->
data
)
{
sclError
(
"calloc %d failed"
,
(
int32_t
)
rowNum
*
sizeof
(
tDataTypes
[
output
->
type
].
bytes
));
SCL_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
node
->
opType
);
int32_t
paramNum
=
sclGetOperatorParamNum
(
node
->
opType
);
SScalarParam
*
pLeft
=
&
params
[
0
];
SScalarParam
*
pRight
=
paramNum
>
1
?
&
params
[
1
]
:
NULL
;
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
OperatorFn
(
pLeft
,
pRight
,
output
->
data
,
TSDB_ORDER_ASC
);
sclParamMoveNext
(
output
,
1
);
sclParamMoveNext
(
pLeft
,
1
);
if
(
pRight
)
{
sclParamMoveNext
(
pRight
,
1
);
}
}
return
TSDB_CODE_SUCCESS
;
_return:
tfree
(
params
);
CTG_RET
(
code
);
}
EDealRes
sclRewriteFunction
(
SNode
**
pNode
,
void
*
pContext
)
{
SFunctionNode
*
node
=
(
SFunctionNode
*
)
*
pNode
;
SScalarParam
output
=
{
0
};
*
(
int32_t
*
)
pContext
=
sclExecFuncion
(
node
,
NULL
,
&
output
);
if
(
*
(
int32_t
*
)
pContext
)
{
return
DEAL_RES_ERROR
;
}
SValueNode
*
res
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
sclError
(
"make value node failed"
);
sclFreeParam
(
&
output
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
...
...
@@ -86,107 +333,66 @@ EDealRes sclRewriteFunction(SNode** pNode, void* pContext) {
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
tfree
(
output
.
data
);
sclFreeParam
(
&
output
);
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclRewriteLogic
(
SNode
**
pNode
,
void
*
pContext
)
{
SLogicConditionNode
*
node
=
(
SLogicConditionNode
*
)
*
pNode
;
if
(
NULL
==
node
->
pParameterList
||
node
->
pParameterList
->
length
<=
0
)
{
sclError
(
"invalid logic parameter list, list:%p, paramNum:%d"
,
node
->
pParameterList
,
node
->
pParameterList
?
node
->
pParameterList
->
length
:
0
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
SScalarParam
output
=
{
0
};
if
(
LOGIC_COND_TYPE_NOT
==
node
->
condType
&&
node
->
pParameterList
->
length
>
1
)
{
sclError
(
"invalid NOT operation parameter number, paramNum:%d"
,
node
->
pParameterList
->
length
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
*
(
int32_t
*
)
pContext
=
sclExecLogic
(
node
,
NULL
,
&
output
);
if
(
*
(
int32_t
*
)
pContext
)
{
return
DEAL_RES_ERROR
;
}
bool
value
=
false
;
SListCell
*
cell
=
node
->
pParameterList
->
pHead
;
for
(
int32_t
i
=
0
;
i
<
node
->
pParameterList
->
length
;
++
i
)
{
if
(
NULL
==
cell
||
NULL
==
cell
->
pNode
)
{
sclError
(
"invalid cell, cell:%p, pNode:%p"
,
cell
,
cell
->
pNode
);
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
if
(
QUERY_NODE_VALUE
!=
nodeType
(
cell
->
pNode
))
{
sclError
(
"invalid node type in cell, type:%d"
,
nodeType
(
cell
->
pNode
));
return
TSDB_CODE_QRY_APP_ERROR
;
}
SValueNode
*
valueNode
=
(
SValueNode
*
)
cell
->
pNode
;
GET_TYPED_DATA
(
value
,
bool
,
valueNode
->
node
.
resType
.
type
,
nodesGetValueFromNode
(
valueNode
));
if
(
LOGIC_COND_TYPE_AND
==
node
->
condType
&&
(
false
==
value
))
{
break
;
}
else
if
(
LOGIC_COND_TYPE_OR
==
node
->
condType
&&
value
)
{
break
;
}
else
if
(
LOGIC_COND_TYPE_NOT
==
node
->
condType
)
{
value
=
!
value
;
}
cell
=
cell
->
pNext
;
}
SValueNode
*
res
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
sclError
(
"make value node failed"
);
sclFreeParam
(
&
output
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
res
->
node
.
resType
=
node
->
node
.
resType
;
SET_TYPED_DATA
(
nodesGetValueFromNode
(
res
),
res
->
node
.
resType
.
type
,
value
);
SET_TYPED_DATA
(
nodesGetValueFromNode
(
res
),
res
->
node
.
resType
.
type
,
output
.
data
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
sclFreeParam
(
&
output
);
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclRewriteOperator
(
SNode
**
pNode
,
void
*
pContext
)
{
SOperatorNode
*
oper
=
(
SOperatorNode
*
)
*
pNode
;
int32_t
paramNum
=
sclGetOperatorParamNum
(
oper
->
opType
);
if
(
NULL
==
oper
->
pLeft
||
(
paramNum
==
2
&&
NULL
==
oper
->
pRight
))
{
sclError
(
"invalid operation node, left:%p, right:%p"
,
oper
->
pLeft
,
oper
->
pRight
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
SOperatorNode
*
node
=
(
SOperatorNode
*
)
*
pNode
;
SScalarParam
output
=
{
0
};
if
(
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pLeft
)
||
(
paramNum
==
2
&&
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pRight
)))
{
sclError
(
"invalid operation node, leftType:%d, rightType:%d"
,
nodeType
(
oper
->
pLeft
),
oper
->
pRight
?
nodeType
(
oper
->
pRight
)
:
0
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
*
(
int32_t
*
)
pContext
=
sclExecOperator
(
node
,
NULL
,
&
output
);
if
(
*
(
int32_t
*
)
pContext
)
{
return
DEAL_RES_ERROR
;
}
SValueNode
*
res
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
sclError
(
"make value node failed"
);
sclError
(
"make value node failed"
);
sclFreeParam
(
&
output
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
res
->
node
.
resType
=
oper
->
node
.
resType
;
res
->
node
.
resType
=
node
->
node
.
resType
;
SValueNode
*
leftValue
=
(
SValueNode
*
)
oper
->
pLeft
;
SValueNode
*
rightValue
=
(
SValueNode
*
)
oper
->
pRight
;
SScalarFuncParam
leftParam
=
{
0
},
rightParam
=
{
0
};
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
oper
->
opType
);
setScalarFuncParam
(
&
leftParam
,
leftValue
->
node
.
resType
.
type
,
0
,
nodesGetValueFromNode
(
leftValue
),
1
);
if
(
2
==
paramNum
)
{
setScalarFuncParam
(
&
rightParam
,
rightValue
->
node
.
resType
.
type
,
0
,
nodesGetValueFromNode
(
rightValue
),
1
);
}
OperatorFn
(
&
leftParam
,
&
rightParam
,
nodesGetValueFromNode
(
res
),
TSDB_ORDER_ASC
);
SET_TYPED_DATA
(
nodesGetValueFromNode
(
res
),
res
->
node
.
resType
.
type
,
output
.
data
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
sclFreeParam
(
&
output
);
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -204,73 +410,99 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
return
sclRewriteLogic
(
pNode
,
pContext
);
}
if
(
QUERY_NODE_OPERATOR
!=
nodeType
(
*
pNode
))
{
sclError
(
"invalid node type for calculating constants, type:%d"
,
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
return
sclRewriteOperator
(
pNode
,
pContext
);
}
return
sclRewriteOperator
(
pNode
,
pContext
);
sclError
(
"invalid node type for calculating constants, type:%d"
,
nodeType
(
*
pNode
));
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
EDealRes
sclCalculate
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
))
{
return
DEAL_RES_CONTINUE
;
EDealRes
sclWalkFunction
(
SNode
**
pNode
,
void
*
pContext
)
{
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
SFunctionNode
*
node
=
(
SFunctionNode
*
)
*
pNode
;
SScalarParam
output
=
{
0
};
ctx
->
code
=
sclExecFuncion
(
node
,
ctx
,
&
output
);
if
(
ctx
->
code
)
{
return
DEAL_RES_ERROR
;
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
return
sclCalculateFunction
(
pNode
,
pContext
);
if
(
taosHashPut
(
ctx
->
pRes
,
pNode
,
POINTER_BYTES
,
&
output
,
sizeof
(
output
)))
{
ctx
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pNode
))
{
return
sclCalculateLogic
(
pNode
,
pContext
);
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclWalkLogic
(
SNode
**
pNode
,
void
*
pContext
)
{
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
SLogicConditionNode
*
node
=
(
SLogicConditionNode
*
)
*
pNode
;
SScalarParam
output
=
{
0
};
ctx
->
code
=
sclExecLogic
(
node
,
ctx
,
&
output
);
if
(
ctx
->
code
)
{
return
DEAL_RES_ERROR
;
}
if
(
QUERY_NODE_OPERATOR
!=
nodeType
(
*
pNode
))
{
sclError
(
"invalid node type for calculating constants, type:%d"
,
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
if
(
taosHashPut
(
ctx
->
pRes
,
pNode
,
POINTER_BYTES
,
&
output
,
sizeof
(
output
)))
{
ctx
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
}
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclWalkOperator
(
SNode
**
pNode
,
void
*
pContext
)
{
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
SOperatorNode
*
node
=
(
SOperatorNode
*
)
*
pNode
;
SScalarParam
output
=
{
0
};
SOperatorNode
*
oper
=
(
SOperatorNode
*
)
*
pNode
;
int32_t
paramNum
=
sclGetOperatorParamNum
(
oper
->
opType
);
if
(
NULL
==
oper
->
pLeft
||
(
paramNum
==
2
&&
NULL
==
oper
->
pRight
))
{
sclError
(
"invalid operation node, left:%p, right:%p"
,
oper
->
pLeft
,
oper
->
pRight
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
ctx
->
code
=
sclExecOperator
(
node
,
ctx
,
&
output
);
if
(
ctx
->
code
)
{
return
DEAL_RES_ERROR
;
}
if
(
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pLeft
)
||
(
paramNum
==
2
&&
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pRight
)))
{
sclError
(
"invalid operation node, leftType:%d, rightType:%d"
,
nodeType
(
oper
->
pLeft
),
oper
->
pRight
?
nodeType
(
oper
->
pRight
)
:
0
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_INVALID_INPUT
;
if
(
taosHashPut
(
ctx
->
pRes
,
pNode
,
POINTER_BYTES
,
&
output
,
sizeof
(
output
)))
{
ctx
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
SValueNode
*
res
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
sclError
(
"make value node failed"
);
*
(
int32_t
*
)
pContext
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclCalcWalker
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
))
{
return
DEAL_RES_CONTINUE
;
}
res
->
node
.
resType
=
oper
->
node
.
resType
;
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
return
sclWalkFunction
(
pNode
,
pContext
);
}
SValueNode
*
leftValue
=
(
SValueNode
*
)
oper
->
pLeft
;
SValueNode
*
rightValue
=
(
SValueNode
*
)
oper
->
pRight
;
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pNode
))
{
return
sclWalkLogic
(
pNode
,
pContext
);
}
SScalarFuncParam
leftParam
=
{
0
},
rightParam
=
{
0
};
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
oper
->
opType
);
setScalarFuncParam
(
&
leftParam
,
leftValue
->
node
.
resType
.
type
,
0
,
nodesGetValueFromNode
(
leftValue
),
1
);
if
(
2
==
paramNum
)
{
setScalarFuncParam
(
&
rightParam
,
rightValue
->
node
.
resType
.
type
,
0
,
nodesGetValueFromNode
(
rightValue
),
1
);
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
return
sclWalkOperator
(
pNode
,
pContext
);
}
OperatorFn
(
&
leftParam
,
&
rightParam
,
nodesGetValueFromNode
(
res
),
TSDB_ORDER_ASC
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
sclError
(
"invalid node type for calculating constants, type:%d"
,
nodeType
(
*
pNode
));
return
DEAL_RES_CONTINUE
;
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
...
...
@@ -294,23 +526,39 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
SCL_RET
(
code
);
}
int32_t
scalarCalculate
(
SNode
*
pNode
,
SSDataBlock
*
pSrc
,
SS
DataBlock
*
pDst
)
{
if
(
NULL
==
pNode
)
{
int32_t
scalarCalculate
(
SNode
*
pNode
,
SSDataBlock
*
pSrc
,
SS
calarParam
*
pDst
)
{
if
(
NULL
==
pNode
||
NULL
==
pSrc
||
NULL
==
pDst
)
{
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
int32_t
code
=
0
;
SScalarCtx
ctx
=
{.
code
=
0
,
.
pSrc
=
pSrc
};
ctx
.
pRes
=
taosHashInit
(
SCL_DEFAULT_OP_NUM
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
pRes
)
{
sclError
(
"taosHashInit failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
nodes
RewriteNodePostOrder
(
&
pNode
,
sclCalculate
,
(
void
*
)
&
code
);
nodes
WalkNodePostOrder
(
&
pNode
,
sclCalcWalker
,
(
void
*
)
&
ctx
);
if
(
code
)
{
if
(
c
tx
.
c
ode
)
{
nodesDestroyNode
(
pNode
);
SCL_ERR_RET
(
code
);
sclFreeRes
(
ctx
.
pRes
);
SCL_ERR_RET
(
ctx
.
code
);
}
*
pRes
=
pNode
;
SScalarParam
*
res
=
taosHashGet
(
ctx
.
pRes
,
&
pNode
,
POINTER_BYTES
);
if
(
NULL
==
res
)
{
sclError
(
"no res for calculating, node:%d, type:%d"
,
pNode
,
nodeType
(
pNode
));
SCL_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
*
pDst
=
*
res
;
SCL_RET
(
code
);
nodesDestroyNode
(
pNode
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/function/src/tscalarfunction.c
浏览文件 @
76d5298b
...
...
@@ -2,13 +2,13 @@
#include "tbinoperator.h"
#include "tunaryoperator.h"
static
void
assignBasicParaInfo
(
struct
SScalar
FuncParam
*
dst
,
const
struct
SScalarFunc
Param
*
src
)
{
static
void
assignBasicParaInfo
(
struct
SScalar
Param
*
dst
,
const
struct
SScalar
Param
*
src
)
{
dst
->
type
=
src
->
type
;
dst
->
bytes
=
src
->
bytes
;
dst
->
num
=
src
->
num
;
}
static
void
tceil
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tceil
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
assert
(
numOfInput
==
1
);
...
...
@@ -34,7 +34,7 @@ static void tceil(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarFun
}
}
static
void
tfloor
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tfloor
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
assert
(
numOfInput
==
1
);
...
...
@@ -62,7 +62,7 @@ static void tfloor(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarFu
}
}
static
void
_tabs
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
_tabs
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
assert
(
numOfInput
==
1
);
...
...
@@ -120,7 +120,7 @@ static void _tabs(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarFun
}
}
static
void
tround
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tround
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assignBasicParaInfo
(
pOutput
,
pLeft
);
assert
(
numOfInput
==
1
);
...
...
@@ -146,7 +146,7 @@ static void tround(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarFu
}
}
static
void
tlength
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tlength
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assert
(
numOfInput
==
1
);
int64_t
*
out
=
(
int64_t
*
)
pOutput
->
data
;
...
...
@@ -157,7 +157,7 @@ static void tlength(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarF
}
}
static
void
tconcat
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tconcat
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
assert
(
numOfInput
>
0
);
int32_t
rowLen
=
0
;
...
...
@@ -189,11 +189,11 @@ static void tconcat(SScalarFuncParam* pOutput, size_t numOfInput, const SScalarF
}
}
static
void
tltrim
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
tltrim
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
}
static
void
trtrim
(
SScalar
FuncParam
*
pOutput
,
size_t
numOfInput
,
const
SScalarFunc
Param
*
pLeft
)
{
static
void
trtrim
(
SScalar
Param
*
pOutput
,
size_t
numOfInput
,
const
SScalar
Param
*
pLeft
)
{
}
...
...
@@ -262,7 +262,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
}
}
static
void
setScalarFuncParam
(
SScalar
Func
Param
*
param
,
int32_t
type
,
int32_t
bytes
,
void
*
pInput
,
int32_t
numOfRows
)
{
static
void
setScalarFuncParam
(
SScalarParam
*
param
,
int32_t
type
,
int32_t
bytes
,
void
*
pInput
,
int32_t
numOfRows
)
{
param
->
bytes
=
bytes
;
param
->
type
=
type
;
param
->
num
=
numOfRows
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录