Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
75ede63c
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
75ede63c
编写于
2月 17, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/qnode
上级
de41059d
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
1107 addition
and
52 deletion
+1107
-52
include/common/tcompare.h
include/common/tcompare.h
+7
-3
include/common/ttypes.h
include/common/ttypes.h
+13
-2
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+9
-1
include/nodes/querynodes.h
include/nodes/querynodes.h
+5
-1
include/util/compare.h
include/util/compare.h
+13
-5
include/util/tdef.h
include/util/tdef.h
+12
-10
include/util/types.h
include/util/types.h
+1
-0
source/common/src/tcompare.c
source/common/src/tcompare.c
+50
-11
source/libs/executor/src/tfilter.c
source/libs/executor/src/tfilter.c
+35
-2
source/libs/function/inc/tscalar.h
source/libs/function/inc/tscalar.h
+3
-0
source/libs/function/src/tbinoperator.c
source/libs/function/src/tbinoperator.c
+676
-0
source/libs/function/src/tscalar.c
source/libs/function/src/tscalar.c
+253
-9
source/util/src/compare.c
source/util/src/compare.c
+30
-8
未找到文件。
include/common/tcompare.h
浏览文件 @
75ede63c
...
...
@@ -23,8 +23,12 @@
extern
"C"
{
#endif
int32_t
compareStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrPatternNotMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrPatternNotMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
);
__compar_fn_t
getKeyComparFunc
(
int32_t
keyType
,
int32_t
order
);
int32_t
doCompare
(
const
char
*
a
,
const
char
*
b
,
int32_t
type
,
size_t
size
);
...
...
@@ -33,4 +37,4 @@ int32_t doCompare(const char* a, const char* b, int32_t type, size_t size)
}
#endif
#endif
/*_TD_TCOMPARE_H_*/
\ No newline at end of file
#endif
/*_TD_TCOMPARE_H_*/
include/common/ttypes.h
浏览文件 @
75ede63c
...
...
@@ -78,9 +78,12 @@ typedef struct {
case TSDB_DATA_TYPE_UINT: \
(_v) = (_finalType)GET_UINT32_VAL(_data); \
break; \
default:
\
case TSDB_DATA_TYPE_INT:
\
(_v) = (_finalType)GET_INT32_VAL(_data); \
break; \
default: \
(_v) = (_finalType)varDataLen(_data); \
break; \
} \
} while (0)
...
...
@@ -115,9 +118,13 @@ typedef struct {
case TSDB_DATA_TYPE_UINT: \
*(uint32_t *)(_v) = (uint32_t)(_data); \
break; \
default:
\
case TSDB_DATA_TYPE_INT:
\
*(int32_t *)(_v) = (int32_t)(_data); \
break; \
default: \
(void *)(_v) = (void *)(_data); \
(void *)(_data) = NULL; \
break; \
} \
} while (0)
...
...
@@ -138,6 +145,9 @@ typedef struct {
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
#define IS_CONVERT_AS_SIGNED(_t) (IS_SIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
#define IS_CONVERT_AS_UNSIGNED(_t) (IS_UNSIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL))
static
FORCE_INLINE
bool
isNull
(
const
void
*
val
,
int32_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
...
...
@@ -205,6 +215,7 @@ void* getDataMax(int32_t type);
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
#define SET_BIGINT_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_BIGINT_NULL)
#ifdef __cplusplus
}
...
...
include/libs/function/functionMgt.h
浏览文件 @
75ede63c
...
...
@@ -118,6 +118,13 @@ typedef struct SFuncExecFuncs {
FExecFinalize
finalize
;
}
SFuncExecFuncs
;
typedef
int32_t
(
*
FScalarExecProcess
)(
SScalarFuncParam
*
pInput
,
int32_t
inputNum
,
SScalarFuncParam
*
pOutput
);
typedef
struct
SScalarFuncExecFuncs
{
FScalarExecProcess
process
;
}
SScalarFuncExecFuncs
;
int32_t
fmFuncMgtInit
();
int32_t
fmGetHandle
(
FuncMgtHandle
*
pHandle
);
...
...
@@ -136,7 +143,8 @@ bool fmIsTimeorderFunc(int32_t funcId);
int32_t
fmFuncScanType
(
int32_t
funcId
);
int32_t
fmGetFuncExecFuncs
(
FuncMgtHandle
handle
,
int32_t
funcId
,
SFuncExecFuncs
*
pFpSet
);
int32_t
fmGetFuncExecFuncs
(
int32_t
funcId
,
SFuncExecFuncs
*
pFpSet
);
int32_t
fmGetScalarFuncExecFuncs
(
int32_t
funcId
,
SScalarFuncExecFuncs
*
pFpSet
);
#ifdef __cplusplus
}
...
...
include/nodes/querynodes.h
浏览文件 @
75ede63c
...
...
@@ -93,6 +93,10 @@ typedef enum EOperatorType {
OP_TYPE_NOT_LIKE
,
OP_TYPE_MATCH
,
OP_TYPE_NMATCH
,
OP_TYPE_ISNULL
,
OP_TYPE_NOTNULL
,
OP_TYPE_BIT_AND
,
OP_TYPE_BIT_OR
,
// json operator
OP_TYPE_JSON_GET_VALUE
,
...
...
@@ -277,4 +281,4 @@ bool nodesIsTimelineQuery(const SNode* pQuery);
}
#endif
#endif
/*_TD_QUERY_NODES_H_*/
\ No newline at end of file
#endif
/*_TD_QUERY_NODES_H_*/
include/util/compare.h
浏览文件 @
75ede63c
...
...
@@ -49,10 +49,19 @@ int32_t WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size,
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
);
int32_t
setCompareBytes1
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setCompareBytes2
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setCompareBytes4
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setCompareBytes8
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkInBytes1
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkInBytes2
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkInBytes4
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkInBytes8
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkNotInBytes1
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkNotInBytes2
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkNotInBytes4
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
setChkNotInBytes8
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareChkInString
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareChkNotInString
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt16Val
(
const
void
*
pLeft
,
const
void
*
pRight
);
...
...
@@ -74,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
int32_t
compareStrRegexCompMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareStrRegexCompNMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareFindItemInSet
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt8ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareInt16ValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
);
...
...
include/util/tdef.h
浏览文件 @
75ede63c
...
...
@@ -118,16 +118,18 @@ do { \
#define TSDB_RELATION_GREATER_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_LIKE 7
#define TSDB_RELATION_ISNULL 8
#define TSDB_RELATION_NOTNULL 9
#define TSDB_RELATION_IN 10
#define TSDB_RELATION_AND 11
#define TSDB_RELATION_OR 12
#define TSDB_RELATION_NOT 13
#define TSDB_RELATION_MATCH 14
#define TSDB_RELATION_NMATCH 15
#define TSDB_RELATION_NOT_LIKE 8
#define TSDB_RELATION_ISNULL 9
#define TSDB_RELATION_NOTNULL 10
#define TSDB_RELATION_IN 11
#define TSDB_RELATION_NOT_IN 12
#define TSDB_RELATION_AND 13
#define TSDB_RELATION_OR 14
#define TSDB_RELATION_NOT 15
#define TSDB_RELATION_MATCH 16
#define TSDB_RELATION_NMATCH 17
#define TSDB_BINARY_OP_ADD 4000
#define TSDB_BINARY_OP_SUBTRACT 4001
...
...
include/util/types.h
浏览文件 @
75ede63c
...
...
@@ -66,6 +66,7 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
// #else
#define GET_FLOAT_VAL(x) (*(float *)(x))
#define GET_DOUBLE_VAL(x) (*(double *)(x))
#define SET_BIGINT_VAL(x, y) { (*(int64_t *)(x)) = (int64_t)(y); }
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); }
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); }
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); }
...
...
source/common/src/tcompare.c
浏览文件 @
75ede63c
...
...
@@ -15,7 +15,7 @@
#include "tcompare.h"
int32_t
compareStrPattern
Comp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compareStrPattern
Match
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
assert
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
);
...
...
@@ -33,7 +33,11 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
int32_t
compareWStrPatternComp
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
compareStrPatternNotMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareStrPatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
int32_t
compareWStrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
SPatternCompareInfo
pInfo
=
{
'%'
,
'_'
};
assert
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
*
TSDB_NCHAR_SIZE
);
...
...
@@ -47,6 +51,10 @@ int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
}
int32_t
compareWStrPatternNotMatch
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareWStrPatternMatch
(
pLeft
,
pRight
)
?
0
:
1
;
}
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
)
{
__compar_fn_t
comparFn
=
NULL
;
...
...
@@ -55,19 +63,42 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
return
setC
ompare
Bytes1
;
return
setC
hkIn
Bytes1
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
return
setC
ompare
Bytes2
;
return
setC
hkIn
Bytes2
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_FLOAT
:
return
setC
ompare
Bytes4
;
return
setC
hkIn
Bytes4
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
setCompareBytes8
;
return
setChkInBytes8
;
default:
assert
(
0
);
}
}
if
(
optr
==
TSDB_RELATION_NOT_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
return
setChkNotInBytes1
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
return
setChkNotInBytes2
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_FLOAT
:
return
setChkNotInBytes4
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
setChkNotInBytes8
;
default:
assert
(
0
);
}
...
...
@@ -88,9 +119,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
}
else
if
(
optr
==
TSDB_RELATION_NMATCH
)
{
comparFn
=
compareStrRegexCompNMatch
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compareStrPatternComp
;
comparFn
=
compareStrPatternMatch
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compareStrPatternNotMatch
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
compareFindItemInSet
;
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_IN
)
{
comparFn
=
compareChkNotInString
;
}
else
{
/* normal relational comparFn */
comparFn
=
compareLenPrefixedStr
;
}
...
...
@@ -104,9 +139,13 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
}
else
if
(
optr
==
TSDB_RELATION_NMATCH
)
{
comparFn
=
compareStrRegexCompNMatch
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
comparFn
=
compareWStrPatternComp
;
comparFn
=
compareWStrPatternMatch
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_LIKE
)
{
comparFn
=
compareWStrPatternNotMatch
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
compareFindItemInSet
;
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_IN
)
{
comparFn
=
compareChkNotInString
;
}
else
{
comparFn
=
compareLenPrefixedWStr
;
}
...
...
@@ -218,4 +257,4 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
}
}
}
}
\ No newline at end of file
}
source/libs/executor/src/tfilter.c
浏览文件 @
75ede63c
...
...
@@ -156,9 +156,11 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
}
__compar_fn_t
gDataCompare
[]
=
{
compareInt32Val
,
compareInt8Val
,
compareInt16Val
,
compareInt64Val
,
compareFloatVal
,
compareDoubleVal
,
compareLenPrefixedStr
,
compareStrPattern
Comp
,
compareFindItemInSet
,
compareWStrPatternComp
,
compareDoubleVal
,
compareLenPrefixedStr
,
compareStrPattern
Match
,
compareChkInString
,
compareWStrPatternMatch
,
compareLenPrefixedWStr
,
compareUint8Val
,
compareUint16Val
,
compareUint32Val
,
compareUint64Val
,
setCompareBytes1
,
setCompareBytes2
,
setCompareBytes4
,
setCompareBytes8
,
compareStrRegexCompMatch
,
compareStrRegexCompNMatch
setChkInBytes1
,
setChkInBytes2
,
setChkInBytes4
,
setChkInBytes8
,
compareStrRegexCompMatch
,
compareStrRegexCompNMatch
,
setChkNotInBytes1
,
setChkNotInBytes2
,
setChkNotInBytes4
,
setChkNotInBytes8
,
compareChkNotInString
,
compareStrPatternNotMatch
,
compareWStrPatternNotMatch
};
int8_t
filterGetCompFuncIdx
(
int32_t
type
,
int32_t
optr
)
{
...
...
@@ -186,6 +188,29 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
assert
(
0
);
}
}
if
(
optr
==
TSDB_RELATION_NOT_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
return
21
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
return
22
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_FLOAT
:
return
23
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
24
;
default:
assert
(
0
);
}
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
...
...
@@ -203,8 +228,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn
=
20
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
7
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
26
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
8
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_IN
)
{
comparFn
=
25
;
}
else
{
/* normal relational comparFn */
comparFn
=
6
;
}
...
...
@@ -219,8 +248,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn
=
20
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
comparFn
=
9
;
}
else
if
(
optr
==
TSDB_RELATION_LIKE
)
{
comparFn
=
27
;
}
else
if
(
optr
==
TSDB_RELATION_IN
)
{
comparFn
=
8
;
}
else
if
(
optr
==
TSDB_RELATION_NOT_IN
)
{
comparFn
=
25
;
}
else
{
comparFn
=
10
;
}
...
...
source/libs/function/inc/tscalar.h
浏览文件 @
75ede63c
...
...
@@ -19,6 +19,9 @@
extern
"C"
{
#endif
typedef
struct
SScalarCalcContext
{
}
SScalarCalcContext
;
#define sclFatal(...) qFatal(__VA_ARGS__)
#define sclError(...) qError(__VA_ARGS__)
...
...
source/libs/function/src/tbinoperator.c
浏览文件 @
75ede63c
此差异已折叠。
点击以展开。
source/libs/function/src/tscalar.c
浏览文件 @
75ede63c
#include "nodes.h"
#include "tscalar.h"
EDealRes
sclCalculateConstants
(
SNode
**
pNode
,
void
*
pContext
)
{
int32_t
sclGetOperatorParamNum
(
EOperatorType
type
)
{
if
(
OP_TYPE_ISNULL
==
type
||
OP_TYPE_NOTNULL
==
type
)
{
return
1
;
}
return
2
;
}
int32_t
sclPrepareFunctionParams
(
SScalarFuncParam
**
pParams
,
SNodeList
*
pParameterList
)
{
*
pParams
=
calloc
(
pParameterList
->
length
,
sizeof
(
SScalarFuncParam
));
if
(
NULL
==
*
pParams
)
{
sclError
(
"calloc %d failed"
,
pParameterList
->
length
*
sizeof
(
SScalarFuncParam
));
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
SListCell
*
cell
=
pParameterList
->
pHead
;
for
(
int32_t
i
=
0
;
i
<
pParameterList
->
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
;
}
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
;
}
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
;
cell
=
cell
->
pNext
;
}
return
TSDB_CODE_SUCCESS
;
}
EDealRes
sclRewriteFunction
(
SNode
**
pNode
,
void
*
pContext
)
{
SFunctionNode
*
node
=
(
SFunctionNode
*
)
*
pNode
;
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
;
}
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
;
}
SScalarFuncParam
*
input
=
NULL
;
if
(
sclPrepareFunctionParams
(
&
input
,
node
->
pParameterList
))
{
return
DEAL_RES_ERROR
;
}
SScalarFuncParam
output
=
{
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
;
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
;
}
res
->
node
.
resType
=
node
->
node
.
resType
;
SET_TYPED_DATA
(
nodesGetValueFromNode
(
res
),
output
.
type
,
output
.
data
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
tfree
(
output
.
data
);
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
;
}
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
;
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"
);
*
(
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
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
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
;
}
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
;
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
;
}
res
->
node
.
resType
=
oper
->
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
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclConstantsRewriter
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
))
{
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
return
sclRewriteFunction
(
pNode
,
pContext
);
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pNode
))
{
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
;
}
return
sclRewriteOperator
(
pNode
,
pContext
);
}
EDealRes
sclCalculate
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
))
{
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
return
sclCalculateFunction
(
pNode
,
pContext
);
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pNode
))
{
return
sclCalculateLogic
(
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
;
...
...
@@ -13,14 +233,15 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
}
SOperatorNode
*
oper
=
(
SOperatorNode
*
)
*
pNode
;
if
(
NULL
==
oper
->
pLeft
||
NULL
==
oper
->
pRight
)
{
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
;
}
if
(
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
oper
->
pRight
))
{
sclError
(
"invalid operation node, leftType:%d, rightType:%d"
,
nodeType
(
oper
->
pLeft
),
nodeType
(
oper
->
pRight
)
);
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
;
return
DEAL_RES_ERROR
;
}
...
...
@@ -37,10 +258,12 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
SValueNode
*
leftValue
=
(
SValueNode
*
)
oper
->
pLeft
;
SValueNode
*
rightValue
=
(
SValueNode
*
)
oper
->
pRight
;
SScalarFuncParam
leftParam
=
{
0
},
rightParam
=
{
0
};
SScalarFuncParam
leftParam
=
{
0
},
rightParam
=
{
0
};
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
oper
->
opType
);
setScalarFuncParam
(
&
leftParam
,
leftValue
->
node
.
resType
,
0
,
nodesGetValueFromNode
(
leftValue
),
1
);
setScalarFuncParam
(
&
rightParam
,
rightValue
->
node
.
resType
,
0
,
nodesGetValueFromNode
(
rightValue
),
1
);
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
);
...
...
@@ -50,6 +273,8 @@ EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
int32_t
scalarCalculateConstants
(
SNode
*
pNode
,
SNode
**
pRes
)
{
if
(
NULL
==
pNode
)
{
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
...
...
@@ -57,7 +282,26 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
int32_t
code
=
0
;
nodesRewriteNodePostOrder
(
&
pNode
,
sclCalculateConstants
,
(
void
*
)
&
code
);
nodesRewriteNodePostOrder
(
&
pNode
,
sclConstantsRewriter
,
(
void
*
)
&
code
);
if
(
code
)
{
nodesDestroyNode
(
pNode
);
SCL_ERR_RET
(
code
);
}
*
pRes
=
pNode
;
SCL_RET
(
code
);
}
int32_t
scalarCalculate
(
SNode
*
pNode
,
SSDataBlock
*
pSrc
,
SSDataBlock
*
pDst
)
{
if
(
NULL
==
pNode
)
{
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
int32_t
code
=
0
;
nodesRewriteNodePostOrder
(
&
pNode
,
sclCalculate
,
(
void
*
)
&
code
);
if
(
code
)
{
nodesDestroyNode
(
pNode
);
...
...
source/util/src/compare.c
浏览文件 @
75ede63c
...
...
@@ -24,22 +24,48 @@
#include "types.h"
#include "ulog.h"
int32_t
setC
ompare
Bytes1
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
setC
hkIn
Bytes1
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
1
)
?
1
:
0
;
}
int32_t
setC
ompare
Bytes2
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
setC
hkIn
Bytes2
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
2
)
?
1
:
0
;
}
int32_t
setC
ompare
Bytes4
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
setC
hkIn
Bytes4
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
4
)
?
1
:
0
;
}
int32_t
setC
ompare
Bytes8
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
setC
hkIn
Bytes8
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
8
)
?
1
:
0
;
}
int32_t
setChkNotInBytes1
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
==
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
1
)
?
1
:
0
;
}
int32_t
setChkNotInBytes2
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
==
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
2
)
?
1
:
0
;
}
int32_t
setChkNotInBytes4
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
==
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
4
)
?
1
:
0
;
}
int32_t
setChkNotInBytes8
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
==
taosHashGet
((
SHashObj
*
)
pRight
,
pLeft
,
8
)
?
1
:
0
;
}
int32_t
compareChkInString
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
varDataVal
(
pLeft
),
varDataLen
(
pLeft
))
?
1
:
0
;
}
int32_t
compareChkNotInString
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
==
taosHashGet
((
SHashObj
*
)
pRight
,
varDataVal
(
pLeft
),
varDataLen
(
pLeft
))
?
1
:
0
;
}
int32_t
compareInt8Val
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int8_t
left
=
GET_INT8_VAL
(
pLeft
),
right
=
GET_INT8_VAL
(
pRight
);
if
(
left
>
right
)
return
1
;
...
...
@@ -392,7 +418,3 @@ int32_t taosArrayCompareString(const void* a, const void* b) {
return
compareLenPrefixedStr
(
x
,
y
);
}
int32_t
compareFindItemInSet
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pRight
,
varDataVal
(
pLeft
),
varDataLen
(
pLeft
))
?
1
:
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录