Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f6edfd75
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
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看板
未验证
提交
f6edfd75
编写于
2月 23, 2022
作者:
D
dapan1121
提交者:
GitHub
2月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10366 from taosdata/feature/qnode
Feature/qnode
上级
5fa4b1ae
3eec053e
变更
30
展开全部
显示空白变更内容
内联
并排
Showing
30 changed file
with
2734 addition
and
601 deletion
+2734
-601
include/common/ttypes.h
include/common/ttypes.h
+3
-0
include/libs/function/function.h
include/libs/function/function.h
+1
-0
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+0
-44
include/libs/scalar/filter.h
include/libs/scalar/filter.h
+19
-1
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
include/util/tdef.h
include/util/tdef.h
+45
-31
source/common/src/tname.c
source/common/src/tname.c
+1
-1
source/common/src/ttypes.c
source/common/src/ttypes.c
+1
-1
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+1
-1
source/libs/function/inc/builtins.h
source/libs/function/inc/builtins.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+8
-0
source/libs/function/src/texpr.c
source/libs/function/src/texpr.c
+6
-5
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+2
-2
source/libs/parser/src/parserUtil.c
source/libs/parser/src/parserUtil.c
+20
-20
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+1
-1
source/libs/scalar/inc/filterInt.h
source/libs/scalar/inc/filterInt.h
+4
-24
source/libs/scalar/inc/sclInt.h
source/libs/scalar/inc/sclInt.h
+2
-0
source/libs/scalar/inc/sclvector.h
source/libs/scalar/inc/sclvector.h
+0
-1
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+199
-238
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+108
-18
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+0
-3
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+493
-123
source/libs/scalar/test/CMakeLists.txt
source/libs/scalar/test/CMakeLists.txt
+3
-17
source/libs/scalar/test/filter/CMakeLists.txt
source/libs/scalar/test/filter/CMakeLists.txt
+18
-0
source/libs/scalar/test/filter/filterTests.cpp
source/libs/scalar/test/filter/filterTests.cpp
+581
-0
source/libs/scalar/test/scalar/CMakeLists.txt
source/libs/scalar/test/scalar/CMakeLists.txt
+18
-0
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+1183
-0
source/libs/scalar/test/scalarTests.cpp
source/libs/scalar/test/scalarTests.cpp
+0
-55
source/util/src/compare.c
source/util/src/compare.c
+14
-14
未找到文件。
include/common/ttypes.h
浏览文件 @
f6edfd75
...
...
@@ -91,6 +91,8 @@ typedef struct {
do { \
switch (_type) { \
case TSDB_DATA_TYPE_BOOL: \
*(bool *)(_v) = (bool)(_data); \
break; \
case TSDB_DATA_TYPE_TINYINT: \
*(int8_t *)(_v) = (int8_t)(_data); \
break; \
...
...
@@ -104,6 +106,7 @@ typedef struct {
*(uint16_t *)(_v) = (uint16_t)(_data); \
break; \
case TSDB_DATA_TYPE_BIGINT: \
case TSDB_DATA_TYPE_TIMESTAMP: \
*(int64_t *)(_v) = (int64_t)(_data); \
break; \
case TSDB_DATA_TYPE_UBIGINT: \
...
...
include/libs/function/function.h
浏览文件 @
f6edfd75
...
...
@@ -228,6 +228,7 @@ typedef struct SAggFunctionInfo {
typedef
struct
SScalarParam
{
void
*
data
;
bool
colData
;
int32_t
num
;
int32_t
type
;
int32_t
bytes
;
...
...
include/libs/nodes/querynodes.h
浏览文件 @
f6edfd75
...
...
@@ -88,45 +88,6 @@ typedef struct SValueNode {
}
datum
;
}
SValueNode
;
typedef
enum
EOperatorType
{
// arithmetic operator
OP_TYPE_ADD
=
1
,
OP_TYPE_SUB
,
OP_TYPE_MULTI
,
OP_TYPE_DIV
,
OP_TYPE_MOD
,
// bit operator
OP_TYPE_BIT_AND
,
OP_TYPE_BIT_OR
,
// comparison operator
OP_TYPE_GREATER_THAN
,
OP_TYPE_GREATER_EQUAL
,
OP_TYPE_LOWER_THAN
,
OP_TYPE_LOWER_EQUAL
,
OP_TYPE_EQUAL
,
OP_TYPE_NOT_EQUAL
,
OP_TYPE_IN
,
OP_TYPE_NOT_IN
,
OP_TYPE_LIKE
,
OP_TYPE_NOT_LIKE
,
OP_TYPE_MATCH
,
OP_TYPE_NMATCH
,
OP_TYPE_IS_NULL
,
OP_TYPE_IS_NOT_NULL
,
OP_TYPE_IS_TRUE
,
OP_TYPE_IS_FALSE
,
OP_TYPE_IS_UNKNOWN
,
OP_TYPE_IS_NOT_TRUE
,
OP_TYPE_IS_NOT_FALSE
,
OP_TYPE_IS_NOT_UNKNOWN
,
// json operator
OP_TYPE_JSON_GET_VALUE
,
OP_TYPE_JSON_CONTAINS
}
EOperatorType
;
typedef
struct
SOperatorNode
{
SExprNode
node
;
// QUERY_NODE_OPERATOR
EOperatorType
opType
;
...
...
@@ -134,11 +95,6 @@ typedef struct SOperatorNode {
SNode
*
pRight
;
}
SOperatorNode
;
typedef
enum
ELogicConditionType
{
LOGIC_COND_TYPE_AND
,
LOGIC_COND_TYPE_OR
,
LOGIC_COND_TYPE_NOT
,
}
ELogicConditionType
;
typedef
struct
SLogicConditionNode
{
SExprNode
node
;
// QUERY_NODE_LOGIC_CONDITION
...
...
include/libs/scalar/filter.h
浏览文件 @
f6edfd75
...
...
@@ -20,6 +20,14 @@ extern "C" {
#endif
typedef
struct
SFilterInfo
SFilterInfo
;
typedef
int32_t
(
*
filer_get_col_from_id
)(
void
*
,
int32_t
,
void
**
);
enum
{
FLT_OPTION_NO_REWRITE
=
1
,
FLT_OPTION_TIMESTAMP
=
2
,
FLT_OPTION_NEED_UNIQE
=
4
,
};
typedef
struct
SFilterColumnParam
{
int32_t
numOfCols
;
...
...
@@ -27,6 +35,16 @@ typedef struct SFilterColumnParam{
}
SFilterColumnParam
;
extern
int32_t
filterInitFromNode
(
SNode
*
pNode
,
SFilterInfo
**
pinfo
,
uint32_t
options
);
extern
bool
filterExecute
(
SFilterInfo
*
info
,
SSDataBlock
*
pSrc
,
int8_t
**
p
,
SColumnDataAgg
*
statis
,
int16_t
numOfCols
);
extern
int32_t
filterSetDataFromSlotId
(
SFilterInfo
*
info
,
void
*
param
,
filer_get_col_from_id
fp
);
extern
int32_t
filterSetDataFromColId
(
SFilterInfo
*
info
,
void
*
param
,
filer_get_col_from_id
fp
);
extern
int32_t
filterGetTimeRange
(
SFilterInfo
*
info
,
STimeWindow
*
win
);
extern
int32_t
filterConverNcharColumns
(
SFilterInfo
*
pFilterInfo
,
int32_t
rows
,
bool
*
gotNchar
);
extern
int32_t
filterFreeNcharColumns
(
SFilterInfo
*
pFilterInfo
);
extern
void
filterFreeInfo
(
SFilterInfo
*
info
);
extern
bool
filterRangeExecute
(
SFilterInfo
*
info
,
SColumnDataAgg
*
pDataStatis
,
int32_t
numOfCols
,
int32_t
numOfRows
);
#ifdef __cplusplus
}
#endif
...
...
include/libs/scalar/scalar.h
浏览文件 @
f6edfd75
...
...
@@ -29,6 +29,7 @@ typedef struct SFilterInfo SFilterInfo;
int32_t
scalarCalculateConstants
(
SNode
*
pNode
,
SNode
**
pRes
);
int32_t
scalarCalculate
(
SNode
*
pNode
,
SSDataBlock
*
pSrc
,
SScalarParam
*
pDst
);
int32_t
scalarGetOperatorParamNum
(
EOperatorType
type
);
int32_t
scalarGenerateSetFromList
(
void
**
data
,
void
*
pNode
,
uint32_t
type
);
int32_t
vectorGetConvertType
(
int32_t
type1
,
int32_t
type2
);
int32_t
vectorConvertImpl
(
SScalarParam
*
pIn
,
SScalarParam
*
pOut
);
...
...
include/util/tdef.h
浏览文件 @
f6edfd75
...
...
@@ -108,35 +108,52 @@ do { \
(src) = (void *)((char *)src + sizeof(type));\
} while(0)
typedef
enum
EOperatorType
{
// arithmetic operator
OP_TYPE_ADD
=
1
,
OP_TYPE_SUB
,
OP_TYPE_MULTI
,
OP_TYPE_DIV
,
OP_TYPE_MOD
,
// bit operator
OP_TYPE_BIT_AND
,
OP_TYPE_BIT_OR
,
// comparison operator
OP_TYPE_GREATER_THAN
,
OP_TYPE_GREATER_EQUAL
,
OP_TYPE_LOWER_THAN
,
OP_TYPE_LOWER_EQUAL
,
OP_TYPE_EQUAL
,
OP_TYPE_NOT_EQUAL
,
OP_TYPE_IN
,
OP_TYPE_NOT_IN
,
OP_TYPE_LIKE
,
OP_TYPE_NOT_LIKE
,
OP_TYPE_MATCH
,
OP_TYPE_NMATCH
,
OP_TYPE_IS_NULL
,
OP_TYPE_IS_NOT_NULL
,
OP_TYPE_IS_TRUE
,
OP_TYPE_IS_FALSE
,
OP_TYPE_IS_UNKNOWN
,
OP_TYPE_IS_NOT_TRUE
,
OP_TYPE_IS_NOT_FALSE
,
OP_TYPE_IS_NOT_UNKNOWN
,
// json operator
OP_TYPE_JSON_GET_VALUE
,
OP_TYPE_JSON_CONTAINS
}
EOperatorType
;
typedef
enum
ELogicConditionType
{
LOGIC_COND_TYPE_AND
,
LOGIC_COND_TYPE_OR
,
LOGIC_COND_TYPE_NOT
,
}
ELogicConditionType
;
// TODO: check if below is necessary
#define TSDB_RELATION_INVALID 0
#define TSDB_RELATION_LESS 1
#define TSDB_RELATION_GREATER 2
#define TSDB_RELATION_EQUAL 3
#define TSDB_RELATION_LESS_EQUAL 4
#define TSDB_RELATION_GREATER_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL 6
#define TSDB_RELATION_LIKE 7
#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
#define TSDB_BINARY_OP_MULTIPLY 4002
#define TSDB_BINARY_OP_DIVIDE 4003
#define TSDB_BINARY_OP_REMAINDER 4004
#define TSDB_BINARY_OP_CONCAT 4005
#define FUNCTION_CEIL 4500
#define FUNCTION_FLOOR 4501
...
...
@@ -148,9 +165,6 @@ do { \
#define FUNCTION_LTRIM 4802
#define FUNCTION_RTRIM 4803
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
#define TSDB_NAME_DELIMITER_LEN 1
#define TSDB_UNI_LEN 24
...
...
source/common/src/tname.c
浏览文件 @
f6edfd75
...
...
@@ -31,7 +31,7 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil
}
assert
(
src
->
filterstr
==
0
||
src
->
filterstr
==
1
);
assert
(
!
(
src
->
lowerRelOptr
==
TSDB_RELATION_INVALID
&&
src
->
upperRelOptr
==
TSDB_RELATION_INVALID
));
assert
(
!
(
src
->
lowerRelOptr
==
0
&&
src
->
upperRelOptr
==
0
));
return
pFilter
;
}
...
...
source/common/src/ttypes.c
浏览文件 @
f6edfd75
...
...
@@ -585,7 +585,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
}
void
operateVal
(
void
*
dst
,
void
*
s1
,
void
*
s2
,
int32_t
optr
,
int32_t
type
)
{
if
(
optr
==
TSDB_BINARY_OP
_ADD
)
{
if
(
optr
==
OP_TYPE
_ADD
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
*
((
int8_t
*
)
dst
)
=
GET_INT8_VAL
(
s1
)
+
GET_INT8_VAL
(
s2
);
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
f6edfd75
...
...
@@ -546,7 +546,7 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable
if
(
tbMeta
->
tableType
!=
TSDB_CHILD_TABLE
)
{
ctgReleaseDBCache
(
pCtg
,
dbCache
);
ctgDebug
(
"Got
tbl
from cache, type:%d, dbFName:%s, tbName:%s"
,
tbMeta
->
tableType
,
dbFName
,
pTableName
->
tname
);
ctgDebug
(
"Got
meta
from cache, type:%d, dbFName:%s, tbName:%s"
,
tbMeta
->
tableType
,
dbFName
,
pTableName
->
tname
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/function/inc/builtins.h
浏览文件 @
f6edfd75
...
...
@@ -46,6 +46,7 @@ typedef struct SBuiltinFuncDefinition {
FExecGetEnv
getEnvFunc
;
FExecInit
initFunc
;
FExecProcess
processFunc
;
FScalarExecProcess
sprocessFunc
;
FExecFinalize
finalizeFunc
;
}
SBuiltinFuncDefinition
;
...
...
source/libs/function/src/builtins.c
浏览文件 @
f6edfd75
...
...
@@ -36,7 +36,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
checkFunc
=
stubCheckAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
processFunc
=
NULL
,
.
s
processFunc
=
NULL
,
.
finalizeFunc
=
NULL
}
};
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
f6edfd75
...
...
@@ -71,6 +71,14 @@ int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
fmGetScalarFuncExecFuncs
(
int32_t
funcId
,
SScalarFuncExecFuncs
*
pFpSet
)
{
if
(
funcId
<
0
||
funcId
>=
funcMgtBuiltinsNum
)
{
return
TSDB_CODE_FAILED
;
}
pFpSet
->
process
=
funcMgtBuiltins
[
funcId
].
sprocessFunc
;
return
TSDB_CODE_SUCCESS
;
}
bool
fmIsAggFunc
(
int32_t
funcId
)
{
if
(
funcId
<
0
||
funcId
>=
funcMgtBuiltinsNum
)
{
return
false
;
...
...
source/libs/function/src/texpr.c
浏览文件 @
f6edfd75
...
...
@@ -25,6 +25,7 @@
#include "thash.h"
#include "texpr.h"
#include "tvariant.h"
#include "tdef.h"
//static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
// if (pLeft->nodeType == TEXPR_COL_NODE) {
...
...
@@ -94,7 +95,7 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp
//non-leaf nodes, recursively traverse the expression tree in the post-root order
if
(
pLeft
->
nodeType
==
TEXPR_BINARYEXPR_NODE
&&
pRight
->
nodeType
==
TEXPR_BINARYEXPR_NODE
)
{
if
(
pExpr
->
_node
.
optr
==
TSDB_RELATION
_OR
)
{
// or
if
(
pExpr
->
_node
.
optr
==
LOGIC_COND_TYPE
_OR
)
{
// or
if
(
exprTreeApplyFilter
(
pLeft
,
pItem
,
param
))
{
return
true
;
}
...
...
@@ -255,7 +256,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
)
==
0
)
{
right
->
nodeType
=
TEXPR_VALUE_NODE
;
expr
->
_node
.
optr
=
TSDB_RELATION
_LIKE
;
expr
->
_node
.
optr
=
OP_TYPE
_LIKE
;
SVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
SVariant
));
right
->
pVal
=
pVal
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_LIKE_LEN
)
+
1
;
...
...
@@ -266,7 +267,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_MATCH
,
QUERY_COND_REL_PREFIX_MATCH_LEN
)
==
0
)
{
right
->
nodeType
=
TEXPR_VALUE_NODE
;
expr
->
_node
.
optr
=
TSDB_RELATION
_MATCH
;
expr
->
_node
.
optr
=
OP_TYPE
_MATCH
;
SVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
SVariant
));
right
->
pVal
=
pVal
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_MATCH_LEN
)
+
1
;
...
...
@@ -276,7 +277,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
pVal
->
nLen
=
(
int32_t
)
len
;
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_NMATCH
,
QUERY_COND_REL_PREFIX_NMATCH_LEN
)
==
0
)
{
right
->
nodeType
=
TEXPR_VALUE_NODE
;
expr
->
_node
.
optr
=
TSDB_RELATION
_NMATCH
;
expr
->
_node
.
optr
=
OP_TYPE
_NMATCH
;
SVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
SVariant
));
right
->
pVal
=
pVal
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_NMATCH_LEN
)
+
1
;
...
...
@@ -286,7 +287,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
pVal
->
nLen
=
(
int32_t
)
len
;
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
)
==
0
)
{
right
->
nodeType
=
TEXPR_VALUE_NODE
;
expr
->
_node
.
optr
=
TSDB_RELATION
_IN
;
expr
->
_node
.
optr
=
OP_TYPE
_IN
;
SVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
SVariant
));
right
->
pVal
=
pVal
;
pVal
->
nType
=
TSDB_DATA_TYPE_POINTER_ARRAY
;
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
f6edfd75
...
...
@@ -63,6 +63,8 @@ SNode* nodesMakeNode(ENodeType type) {
return
makeNode
(
type
,
sizeof
(
SNodeListNode
));
case
QUERY_NODE_FILL
:
return
makeNode
(
type
,
sizeof
(
SFillNode
));
case
QUERY_NODE_COLUMN_REF
:
return
makeNode
(
type
,
sizeof
(
SColumnRefNode
));
case
QUERY_NODE_RAW_EXPR
:
return
makeNode
(
type
,
sizeof
(
SRawExprNode
));
case
QUERY_NODE_SET_OPERATOR
:
...
...
@@ -79,8 +81,6 @@ SNode* nodesMakeNode(ENodeType type) {
return
makeNode
(
type
,
sizeof
(
SAggLogicNode
));
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
return
makeNode
(
type
,
sizeof
(
SProjectLogicNode
));
case
QUERY_NODE_COLUMN_REF
:
return
makeNode
(
type
,
sizeof
(
SColumnRefNode
));
case
QUERY_NODE_TARGET
:
return
makeNode
(
type
,
sizeof
(
STargetNode
));
case
QUERY_NODE_TUPLE_DESC
:
...
...
source/libs/parser/src/parserUtil.c
浏览文件 @
f6edfd75
...
...
@@ -884,7 +884,7 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil
}
assert
(
src
->
filterstr
==
0
||
src
->
filterstr
==
1
);
assert
(
!
(
src
->
lowerRelOptr
==
TSDB_RELATION_INVALID
&&
src
->
upperRelOptr
==
TSDB_RELATION_INVALID
));
assert
(
!
(
src
->
lowerRelOptr
==
0
&&
src
->
upperRelOptr
==
0
));
return
pFilter
;
}
...
...
@@ -1507,45 +1507,45 @@ int32_t getTagFilterSerializeLen(SQueryStmtInfo* pQueryInfo) {
uint32_t
convertRelationalOperator
(
SToken
*
pToken
)
{
switch
(
pToken
->
type
)
{
case
TK_LT
:
return
TSDB_RELATION_LESS
;
return
OP_TYPE_LOWER_THAN
;
case
TK_LE
:
return
TSDB_RELATION_LESS
_EQUAL
;
return
OP_TYPE_LOWER
_EQUAL
;
case
TK_GT
:
return
TSDB_RELATION_GREATER
;
return
OP_TYPE_GREATER_THAN
;
case
TK_GE
:
return
TSDB_RELATION
_GREATER_EQUAL
;
return
OP_TYPE
_GREATER_EQUAL
;
case
TK_NE
:
return
TSDB_RELATION
_NOT_EQUAL
;
return
OP_TYPE
_NOT_EQUAL
;
case
TK_AND
:
return
TSDB_RELATION
_AND
;
return
LOGIC_COND_TYPE
_AND
;
case
TK_OR
:
return
TSDB_RELATION
_OR
;
return
LOGIC_COND_TYPE
_OR
;
case
TK_EQ
:
return
TSDB_RELATION
_EQUAL
;
return
OP_TYPE
_EQUAL
;
case
TK_PLUS
:
return
TSDB_BINARY_OP
_ADD
;
return
OP_TYPE
_ADD
;
case
TK_MINUS
:
return
TSDB_BINARY_OP_SUBTRACT
;
return
OP_TYPE_SUB
;
case
TK_STAR
:
return
TSDB_BINARY_OP_MULTIPLY
;
return
OP_TYPE_MULTI
;
case
TK_SLASH
:
case
TK_DIVIDE
:
return
TSDB_BINARY_OP_DIVIDE
;
return
OP_TYPE_DIV
;
case
TK_REM
:
return
TSDB_BINARY_OP_REMAINDER
;
return
OP_TYPE_MOD
;
case
TK_LIKE
:
return
TSDB_RELATION
_LIKE
;
return
OP_TYPE
_LIKE
;
case
TK_MATCH
:
return
TSDB_RELATION
_MATCH
;
return
OP_TYPE
_MATCH
;
case
TK_NMATCH
:
return
TSDB_RELATION
_NMATCH
;
return
OP_TYPE
_NMATCH
;
case
TK_ISNULL
:
return
TSDB_RELATION_IS
NULL
;
return
OP_TYPE_IS_
NULL
;
case
TK_NOTNULL
:
return
TSDB_RELATION_NOT
NULL
;
return
OP_TYPE_IS_NOT_
NULL
;
case
TK_IN
:
return
TSDB_RELATION
_IN
;
return
OP_TYPE
_IN
;
default:
{
return
0
;
}
}
}
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
f6edfd75
...
...
@@ -593,7 +593,7 @@ TEST(testCase, function_Test6) {
SExprInfo
*
p2
=
(
SExprInfo
*
)
taosArrayGetP
(
pQueryInfo
->
exprList
[
1
],
0
);
ASSERT_EQ
(
p2
->
pExpr
->
nodeType
,
TEXPR_BINARYEXPR_NODE
);
ASSERT_EQ
(
p2
->
pExpr
->
_node
.
optr
,
TSDB_BINARY_OP
_ADD
);
ASSERT_EQ
(
p2
->
pExpr
->
_node
.
optr
,
OP_TYPE
_ADD
);
ASSERT_EQ
(
p2
->
pExpr
->
_node
.
pLeft
->
nodeType
,
TEXPR_COL_NODE
);
ASSERT_EQ
(
p2
->
pExpr
->
_node
.
pRight
->
nodeType
,
TEXPR_COL_NODE
);
...
...
source/libs/scalar/inc/filterInt.h
浏览文件 @
f6edfd75
...
...
@@ -43,7 +43,6 @@ enum {
FLD_TYPE_COLUMN
=
1
,
FLD_TYPE_VALUE
=
2
,
FLD_TYPE_MAX
=
3
,
FLD_DESC_NO_FREE
=
4
,
FLD_DATA_NO_FREE
=
8
,
FLD_DATA_IS_HASH
=
16
,
};
...
...
@@ -61,11 +60,6 @@ enum {
RANGE_FLG_NULL
=
4
,
};
enum
{
FI_OPTION_NO_REWRITE
=
1
,
FI_OPTION_TIMESTAMP
=
2
,
FI_OPTION_NEED_UNIQE
=
4
,
};
enum
{
FI_STATUS_ALL
=
1
,
...
...
@@ -107,7 +101,6 @@ typedef struct SFilterRange {
typedef
bool
(
*
rangeCompFunc
)
(
const
void
*
,
const
void
*
,
const
void
*
,
const
void
*
,
__compar_fn_t
);
typedef
int32_t
(
*
filter_desc_compare_func
)(
const
void
*
,
const
void
*
);
typedef
bool
(
*
filter_exec_func
)(
void
*
,
int32_t
,
int8_t
**
,
SColumnDataAgg
*
,
int16_t
);
typedef
int32_t
(
*
filer_get_col_from_id
)(
void
*
,
int32_t
,
void
**
);
typedef
int32_t
(
*
filer_get_col_from_name
)(
void
*
,
int32_t
,
char
*
,
void
**
);
typedef
struct
SFilterRangeCompare
{
...
...
@@ -264,12 +257,12 @@ typedef struct SFilterInfo {
}
SFilterInfo
;
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON)
#define FILTER_NO_MERGE_OPTR(o) ((o) ==
TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOT
NULL || (o) == FILTER_DUMMY_EMPTY_OPTR)
#define FILTER_NO_MERGE_OPTR(o) ((o) ==
OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_
NULL || (o) == FILTER_DUMMY_EMPTY_OPTR)
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
#define SET_AND_OPTR(ctx, o) do {if (o ==
TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOT
NULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0)
#define SET_OR_OPTR(ctx,o) do {if (o ==
TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOT
NULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0)
#define SET_AND_OPTR(ctx, o) do {if (o ==
OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_
NULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0)
#define SET_OR_OPTR(ctx,o) do {if (o ==
OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_
NULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0)
#define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true)
#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true)))
...
...
@@ -351,23 +344,10 @@ typedef struct SFilterInfo {
#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL)
#define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY)
#if 0
extern int32_t filterInitFromTree(tExprNode* tree, void **pinfo, uint32_t options);
extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
extern int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from_id fp);
extern int32_t filterSetJsonColFieldData(SFilterInfo *info, void *param, filer_get_col_from_name fp);
extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win);
extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar);
extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo);
extern void filterFreeInfo(SFilterInfo *info);
extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows);
#else
//REMOVE THESE!!!!!!!!!!!!!!!!!!!!
#include "function.h"
#endif
extern
bool
filterDoCompare
(
__compar_fn_t
func
,
uint8_t
optr
,
void
*
left
,
void
*
right
);
extern
__compar_fn_t
filterGetCompFunc
(
int32_t
type
,
int32_t
optr
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/scalar/inc/sclInt.h
浏览文件 @
f6edfd75
...
...
@@ -28,6 +28,8 @@ typedef struct SScalarCtx {
SHashObj
*
pRes
;
/* element is SScalarParam */
}
SScalarCtx
;
#define SCL_DATA_TYPE_DUMMY_HASH 9000
#define SCL_DEFAULT_OP_NUM 10
#define sclFatal(...) qFatal(__VA_ARGS__)
...
...
source/libs/scalar/inc/sclvector.h
浏览文件 @
f6edfd75
...
...
@@ -24,7 +24,6 @@ extern "C" {
typedef
void
(
*
_bin_scalar_fn_t
)(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
void
*
output
,
int32_t
order
);
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binOperator
);
bool
isBinaryStringOp
(
int32_t
op
);
#ifdef __cplusplus
}
...
...
source/libs/scalar/src/filter.c
浏览文件 @
f6edfd75
此差异已折叠。
点击以展开。
source/libs/scalar/src/scalar.c
浏览文件 @
f6edfd75
...
...
@@ -7,13 +7,87 @@
#include "sclInt.h"
int32_t
scalarGetOperatorParamNum
(
EOperatorType
type
)
{
if
(
OP_TYPE_IS_NULL
==
type
||
OP_TYPE_IS_NOT_NULL
==
type
)
{
if
(
OP_TYPE_IS_NULL
==
type
||
OP_TYPE_IS_NOT_NULL
==
type
||
OP_TYPE_IS_TRUE
==
type
||
OP_TYPE_IS_NOT_TRUE
==
type
||
OP_TYPE_IS_FALSE
==
type
||
OP_TYPE_IS_NOT_FALSE
==
type
||
OP_TYPE_IS_UNKNOWN
==
type
||
OP_TYPE_IS_NOT_UNKNOWN
==
type
)
{
return
1
;
}
return
2
;
}
int32_t
scalarGenerateSetFromList
(
void
**
data
,
void
*
pNode
,
uint32_t
type
)
{
SHashObj
*
pObj
=
taosHashInit
(
256
,
taosGetDefaultHashFunction
(
type
),
true
,
false
);
if
(
NULL
==
pObj
)
{
sclError
(
"taosHashInit failed, size:%d"
,
256
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
taosHashSetEqualFp
(
pObj
,
taosGetDefaultEqualFunction
(
type
));
int32_t
code
=
0
;
SNodeListNode
*
nodeList
=
(
SNodeListNode
*
)
pNode
;
SListCell
*
cell
=
nodeList
->
pNodeList
->
pHead
;
SScalarParam
in
=
{.
num
=
1
},
out
=
{.
num
=
1
,
.
type
=
type
};
int8_t
dummy
=
0
;
int32_t
bufLen
=
60
;
out
.
data
=
malloc
(
bufLen
);
int32_t
len
=
0
;
void
*
buf
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
nodeList
->
pNodeList
->
length
;
++
i
)
{
SValueNode
*
valueNode
=
(
SValueNode
*
)
cell
->
pNode
;
if
(
valueNode
->
node
.
resType
.
type
!=
type
)
{
in
.
type
=
valueNode
->
node
.
resType
.
type
;
in
.
bytes
=
valueNode
->
node
.
resType
.
bytes
;
in
.
data
=
nodesGetValueFromNode
(
valueNode
);
code
=
vectorConvertImpl
(
&
in
,
&
out
);
if
(
code
)
{
sclError
(
"convert from %d to %d failed"
,
in
.
type
,
out
.
type
);
SCL_ERR_JRET
(
code
);
}
if
(
IS_VAR_DATA_TYPE
(
type
))
{
len
=
varDataLen
(
out
.
data
);
buf
=
varDataVal
(
out
.
data
);
}
else
{
len
=
tDataTypes
[
type
].
bytes
;
buf
=
out
.
data
;
}
}
else
{
buf
=
nodesGetValueFromNode
(
valueNode
);
if
(
IS_VAR_DATA_TYPE
(
type
))
{
len
=
varDataLen
(
buf
);
buf
=
varDataVal
(
buf
);
}
else
{
len
=
valueNode
->
node
.
resType
.
bytes
;
buf
=
out
.
data
;
}
}
if
(
taosHashPut
(
pObj
,
buf
,
(
size_t
)
len
,
&
dummy
,
sizeof
(
dummy
)))
{
sclError
(
"taosHashPut failed"
);
SCL_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
cell
=
cell
->
pNext
;
}
tfree
(
out
.
data
);
*
data
=
pObj
;
return
TSDB_CODE_SUCCESS
;
_return:
tfree
(
out
.
data
);
taosHashCleanup
(
pObj
);
SCL_RET
(
code
);
}
void
sclFreeRes
(
SHashObj
*
res
)
{
SScalarParam
*
p
=
NULL
;
void
*
pIter
=
taosHashIterate
(
res
,
NULL
);
...
...
@@ -42,12 +116,22 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
param
->
num
=
1
;
param
->
type
=
valueNode
->
node
.
resType
.
type
;
param
->
bytes
=
valueNode
->
node
.
resType
.
bytes
;
param
->
colData
=
false
;
break
;
}
case
QUERY_NODE_NODE_LIST
:
{
SNodeListNode
*
nodeList
=
(
SNodeListNode
*
)
node
;
//TODO BUILD HASH
if
(
nodeList
->
pNodeList
->
length
<=
0
)
{
sclError
(
"invalid length in nodeList, length:%d"
,
nodeList
->
pNodeList
->
length
);
SCL_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SCL_ERR_RET
(
scalarGenerateSetFromList
(
&
param
->
data
,
node
,
nodeList
->
dataType
.
type
));
param
->
num
=
1
;
param
->
type
=
SCL_DATA_TYPE_DUMMY_HASH
;
param
->
colData
=
false
;
break
;
}
case
QUERY_NODE_COLUMN_REF
:
{
...
...
@@ -63,7 +147,14 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
}
SColumnInfoData
*
columnData
=
(
SColumnInfoData
*
)
taosArrayGet
(
ctx
->
pSrc
->
pDataBlock
,
ref
->
slotId
);
if
(
IS_VAR_DATA_TYPE
(
columnData
->
info
.
type
))
{
param
->
data
=
columnData
;
param
->
colData
=
true
;
}
else
{
param
->
data
=
columnData
->
pData
;
param
->
colData
=
false
;
}
param
->
num
=
ctx
->
pSrc
->
info
.
rows
;
param
->
type
=
columnData
->
info
.
type
;
param
->
bytes
=
columnData
->
info
.
bytes
;
...
...
@@ -248,12 +339,16 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
SCL_ERR_RET
(
sclInitParamList
(
&
params
,
node
->
pParameterList
,
ctx
,
&
rowNum
));
output
->
type
=
node
->
node
.
resType
.
type
;
output
->
bytes
=
sizeof
(
bool
);
output
->
num
=
rowNum
;
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
);
}
void
*
data
=
output
->
data
;
bool
value
=
false
;
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
...
...
@@ -275,6 +370,8 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o
sclParamMoveNext
(
params
,
node
->
pParameterList
->
length
);
}
output
->
data
=
data
;
return
TSDB_CODE_SUCCESS
;
_return:
...
...
@@ -291,6 +388,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
SCL_ERR_RET
(
sclInitOperatorParams
(
&
params
,
node
,
ctx
,
&
rowNum
));
output
->
type
=
node
->
node
.
resType
.
type
;
output
->
num
=
rowNum
;
output
->
bytes
=
tDataTypes
[
output
->
type
].
bytes
;
output
->
data
=
calloc
(
rowNum
,
tDataTypes
[
output
->
type
].
bytes
);
if
(
NULL
==
output
->
data
)
{
sclError
(
"calloc %d failed"
,
(
int32_t
)
rowNum
*
tDataTypes
[
output
->
type
].
bytes
);
...
...
@@ -303,17 +402,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
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:
...
...
@@ -427,7 +517,7 @@ EDealRes sclRewriteOperator(SNode** pNode, void* pContext) {
EDealRes
sclConstantsRewriter
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
))
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
*
pNode
)
||
QUERY_NODE_NODE_LIST
==
nodeType
(
*
pNode
)
)
{
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -509,7 +599,7 @@ EDealRes sclWalkOperator(SNode* pNode, void* pContext) {
EDealRes
sclCalcWalker
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
pNode
))
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
pNode
)
||
QUERY_NODE_NODE_LIST
==
nodeType
(
pNode
)
||
QUERY_NODE_COLUMN_REF
==
nodeType
(
pNode
)
)
{
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -525,7 +615,7 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
return
sclWalkOperator
(
pNode
,
pContext
);
}
sclError
(
"invalid node type for
calculating constants
, type:%d"
,
nodeType
(
pNode
));
sclError
(
"invalid node type for
scalar calculating
, type:%d"
,
nodeType
(
pNode
));
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
f6edfd75
...
...
@@ -268,9 +268,6 @@ static void setScalarFuncParam(SScalarParam* param, int32_t type, int32_t bytes,
param
->
data
=
pInput
;
}
bool
isStringOp
(
int32_t
op
)
{
return
op
==
TSDB_BINARY_OP_CONCAT
;
}
#if 0
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
f6edfd75
此差异已折叠。
点击以展开。
source/libs/scalar/test/CMakeLists.txt
浏览文件 @
f6edfd75
enable_testing
()
MESSAGE
(
STATUS
"build scalar unit test"
)
# GoogleTest requires at least C++11
SET
(
CMAKE_CXX_STANDARD 11
)
AUX_SOURCE_DIRECTORY
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
ADD_EXECUTABLE
(
scalarTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
scalarTest
PUBLIC os util common gtest qcom function nodes
)
TARGET_INCLUDE_DIRECTORIES
(
scalarTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/scalar/"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/source/libs/scalar/inc"
)
add_subdirectory
(
filter
)
add_subdirectory
(
scalar
)
source/libs/scalar/test/filter/CMakeLists.txt
0 → 100644
浏览文件 @
f6edfd75
MESSAGE
(
STATUS
"build filter unit test"
)
# GoogleTest requires at least C++11
SET
(
CMAKE_CXX_STANDARD 11
)
AUX_SOURCE_DIRECTORY
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
ADD_EXECUTABLE
(
filterTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
filterTest
PUBLIC os util common gtest qcom function nodes scalar
)
TARGET_INCLUDE_DIRECTORIES
(
filterTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/scalar/"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/source/libs/scalar/inc"
)
source/libs/scalar/test/filter/filterTests.cpp
0 → 100644
浏览文件 @
f6edfd75
/*
* 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/>.
*/
#include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include "os.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "tep.h"
#include "stub.h"
#include "addr_any.h"
#include "scalar.h"
#include "nodes.h"
#include "tlog.h"
#include "filter.h"
namespace
{
int64_t
flttLeftV
=
21
,
flttRightV
=
10
;
double
flttLeftVd
=
21.0
,
flttRightVd
=
10.0
;
void
flttInitLogFile
()
{
const
char
*
defaultLogFileNamePrefix
=
"taoslog"
;
const
int32_t
maxLogFileNum
=
10
;
tsAsyncLog
=
0
;
qDebugFlag
=
159
;
char
temp
[
128
]
=
{
0
};
sprintf
(
temp
,
"%s/%s"
,
tsLogDir
,
defaultLogFileNamePrefix
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
maxLogFileNum
)
<
0
)
{
printf
(
"failed to open log file in directory:%s
\n
"
,
tsLogDir
);
}
}
void
flttMakeValueNode
(
SNode
**
pNode
,
int32_t
dataType
,
void
*
value
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
SValueNode
*
vnode
=
(
SValueNode
*
)
node
;
vnode
->
node
.
resType
.
type
=
dataType
;
if
(
IS_VAR_DATA_TYPE
(
dataType
))
{
vnode
->
datum
.
p
=
(
char
*
)
malloc
(
varDataTLen
(
value
));
varDataCopy
(
vnode
->
datum
.
p
,
value
);
vnode
->
node
.
resType
.
bytes
=
varDataLen
(
value
);
}
else
{
vnode
->
node
.
resType
.
bytes
=
tDataTypes
[
dataType
].
bytes
;
assignVal
((
char
*
)
nodesGetValueFromNode
(
vnode
),
(
const
char
*
)
value
,
0
,
dataType
);
}
*
pNode
=
(
SNode
*
)
vnode
;
}
void
flttMakeColRefNode
(
SNode
**
pNode
,
SSDataBlock
**
block
,
int32_t
dataType
,
int32_t
dataBytes
,
int32_t
rowNum
,
void
*
value
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_COLUMN_REF
);
SColumnRefNode
*
rnode
=
(
SColumnRefNode
*
)
node
;
rnode
->
dataType
.
type
=
dataType
;
rnode
->
dataType
.
bytes
=
dataBytes
;
rnode
->
tupleId
=
0
;
if
(
NULL
==
block
)
{
rnode
->
slotId
=
2
;
rnode
->
columnId
=
55
;
*
pNode
=
(
SNode
*
)
rnode
;
return
;
}
if
(
NULL
==
*
block
)
{
SSDataBlock
*
res
=
(
SSDataBlock
*
)
calloc
(
1
,
sizeof
(
SSDataBlock
));
res
->
info
.
numOfCols
=
3
;
res
->
info
.
rows
=
rowNum
;
res
->
pDataBlock
=
taosArrayInit
(
3
,
sizeof
(
SColumnInfoData
));
for
(
int32_t
i
=
0
;
i
<
2
;
++
i
)
{
SColumnInfoData
idata
=
{{
0
}};
idata
.
info
.
type
=
TSDB_DATA_TYPE_NULL
;
idata
.
info
.
bytes
=
10
;
idata
.
info
.
colId
=
0
;
int32_t
size
=
idata
.
info
.
bytes
*
rowNum
;
idata
.
pData
=
(
char
*
)
calloc
(
1
,
size
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
}
SColumnInfoData
idata
=
{{
0
}};
idata
.
info
.
type
=
dataType
;
idata
.
info
.
bytes
=
dataBytes
;
idata
.
info
.
colId
=
55
;
idata
.
pData
=
(
char
*
)
value
;
if
(
IS_VAR_DATA_TYPE
(
dataType
))
{
idata
.
varmeta
.
offset
=
(
int32_t
*
)
calloc
(
rowNum
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
idata
.
varmeta
.
offset
[
i
]
=
(
dataBytes
+
VARSTR_HEADER_SIZE
)
*
i
;
}
}
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
rnode
->
slotId
=
2
;
rnode
->
columnId
=
55
;
*
block
=
res
;
}
else
{
SSDataBlock
*
res
=
*
block
;
int32_t
idx
=
taosArrayGetSize
(
res
->
pDataBlock
);
SColumnInfoData
idata
=
{{
0
}};
idata
.
info
.
type
=
dataType
;
idata
.
info
.
bytes
=
dataBytes
;
idata
.
info
.
colId
=
55
+
idx
;
idata
.
pData
=
(
char
*
)
value
;
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
rnode
->
slotId
=
idx
;
rnode
->
columnId
=
55
+
idx
;
}
*
pNode
=
(
SNode
*
)
rnode
;
}
void
flttMakeOpNode
(
SNode
**
pNode
,
EOperatorType
opType
,
int32_t
resType
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
onode
=
(
SOperatorNode
*
)
node
;
onode
->
node
.
resType
.
type
=
resType
;
onode
->
node
.
resType
.
bytes
=
tDataTypes
[
resType
].
bytes
;
onode
->
opType
=
opType
;
onode
->
pLeft
=
pLeft
;
onode
->
pRight
=
pRight
;
*
pNode
=
(
SNode
*
)
onode
;
}
void
flttMakeLogicNode
(
SNode
**
pNode
,
ELogicConditionType
opType
,
SNode
**
nodeList
,
int32_t
nodeNum
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
SLogicConditionNode
*
onode
=
(
SLogicConditionNode
*
)
node
;
onode
->
condType
=
opType
;
onode
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_BOOL
;
onode
->
node
.
resType
.
bytes
=
sizeof
(
bool
);
onode
->
pParameterList
=
nodesMakeList
();
for
(
int32_t
i
=
0
;
i
<
nodeNum
;
++
i
)
{
nodesListAppend
(
onode
->
pParameterList
,
nodeList
[
i
]);
}
*
pNode
=
(
SNode
*
)
onode
;
}
void
flttMakeListNode
(
SNode
**
pNode
,
SNodeList
*
list
,
int32_t
resType
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_NODE_LIST
);
SNodeListNode
*
lnode
=
(
SNodeListNode
*
)
node
;
lnode
->
dataType
.
type
=
resType
;
lnode
->
pNodeList
=
list
;
*
pNode
=
(
SNode
*
)
lnode
;
}
}
TEST
(
timerangeTest
,
greater_and_lower
)
{
flttInitLogFile
();
SNode
*
pcol
=
NULL
,
*
pval
=
NULL
,
*
opNode1
=
NULL
,
*
opNode2
=
NULL
,
*
logicNode
=
NULL
;
bool
eRes
[
5
]
=
{
false
,
false
,
true
,
true
,
true
};
SScalarParam
res
=
{
0
};
int64_t
tsmall
=
222
,
tbig
=
333
;
flttMakeColRefNode
(
&
pcol
,
NULL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
0
,
NULL
);
flttMakeValueNode
(
&
pval
,
TSDB_DATA_TYPE_TIMESTAMP
,
&
tsmall
);
flttMakeOpNode
(
&
opNode1
,
OP_TYPE_GREATER_THAN
,
TSDB_DATA_TYPE_BOOL
,
pcol
,
pval
);
flttMakeColRefNode
(
&
pcol
,
NULL
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
0
,
NULL
);
flttMakeValueNode
(
&
pval
,
TSDB_DATA_TYPE_TIMESTAMP
,
&
tbig
);
flttMakeOpNode
(
&
opNode2
,
OP_TYPE_LOWER_THAN
,
TSDB_DATA_TYPE_BOOL
,
pcol
,
pval
);
SNode
*
list
[
2
]
=
{
0
};
list
[
0
]
=
opNode1
;
list
[
1
]
=
opNode2
;
flttMakeLogicNode
(
&
logicNode
,
LOGIC_COND_TYPE_AND
,
list
,
2
);
SFilterInfo
*
filter
=
NULL
;
int32_t
code
=
filterInitFromNode
(
logicNode
,
&
filter
,
FLT_OPTION_NO_REWRITE
|
FLT_OPTION_TIMESTAMP
);
ASSERT_EQ
(
code
,
0
);
STimeWindow
win
=
{
0
};
code
=
filterGetTimeRange
(
filter
,
&
win
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
win
.
skey
,
tsmall
);
ASSERT_EQ
(
win
.
ekey
,
tbig
);
}
#if 0
TEST(columnTest, smallint_column_greater_double_value) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {1, 2, 3, 4, 5};
double rightv= 2.5;
bool eRes[5] = {false, false, true, true, true};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(columnTest, int_column_in_double_list) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
int32_t leftv[5] = {1, 2, 3, 4, 5};
double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3;
bool eRes[5] = {true, true, true, false, false};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
SNodeList* list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
nodesListAppend(list, pRight);
flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(columnTest, binary_column_in_binary_list) {
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
bool eRes[5] = {true, true, false, false, false};
SSDataBlock *src = NULL;
SScalarParam res = {0};
char leftv[5][5]= {0};
char rightv[3][5]= {0};
for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = 'a' + i;
leftv[i][3] = 'b' + i;
leftv[i][4] = '0' + i;
varDataSetLen(leftv[i], 3);
}
for (int32_t i = 0; i < 2; ++i) {
rightv[i][2] = 'a' + i;
rightv[i][3] = 'b' + i;
rightv[i][4] = '0' + i;
varDataSetLen(rightv[i], 3);
}
for (int32_t i = 2; i < 3; ++i) {
rightv[i][2] = 'a' + i;
rightv[i][3] = 'a' + i;
rightv[i][4] = 'a' + i;
varDataSetLen(rightv[i], 3);
}
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
SNodeList* list = nodesMakeList();
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
nodesListAppend(list, pRight);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
nodesListAppend(list, pRight);
flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY);
flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(columnTest, binary_column_like_binary) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
char rightv[64] = {0};
char leftv[5][5]= {0};
SSDataBlock *src = NULL;
SScalarParam res = {0};
bool eRes[5] = {true, false, true, false, true};
for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = 'a';
leftv[i][3] = 'a';
leftv[i][4] = '0' + i % 2;
varDataSetLen(leftv[i], 3);
}
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
sprintf(&rightv[2], "%s", "__0");
varDataSetLen(rightv, strlen(&rightv[2]));
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(columnTest, binary_column_is_null) {
SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0};
SSDataBlock *src = NULL;
SScalarParam res = {0};
bool eRes[5] = {false, false, false, false, true};
for (int32_t i = 0; i < 4; ++i) {
leftv[i][2] = '0' + i % 2;
leftv[i][3] = 'a';
leftv[i][4] = '0' + i % 2;
varDataSetLen(leftv[i], 3);
}
setVardataNull(leftv[4], TSDB_DATA_TYPE_BINARY);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(columnTest, binary_column_is_not_null) {
SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0};
SSDataBlock *src = NULL;
SScalarParam res = {0};
bool eRes[5] = {true, true, true, true, false};
for (int32_t i = 0; i < 4; ++i) {
leftv[i][2] = '0' + i % 2;
leftv[i][3] = 'a';
leftv[i][4] = '0' + i % 2;
varDataSetLen(leftv[i], 3);
}
setVardataNull(leftv[4], TSDB_DATA_TYPE_BINARY);
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
TEST(logicTest, and_or_and) {
}
TEST(logicTest, or_and_or) {
}
TEST(opTest, smallint_column_greater_int_column) {
}
TEST(opTest, smallint_value_add_int_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int32_t leftv = 1;
int16_t rightv[5]= {0, -5, -4, 23, 100};
double eRes[5] = {1.0, -4, -3, 24, 101};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
flttMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
flttMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_DOUBLE);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)res.data + i), eRes[i]);
}
}
TEST(opTest, bigint_column_multi_binary_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int64_t leftv[5]= {1, 2, 3, 4, 5};
char rightv[5][5]= {0};
for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i;
varDataSetLen(rightv[i], 3);
}
double eRes[5] = {0, 2, 6, 12, 20};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
flttMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_DOUBLE);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)res.data + i), eRes[i]);
}
}
TEST(opTest, smallint_column_and_binary_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {1, 2, 3, 4, 5};
char rightv[5][5]= {0};
for (int32_t i = 0; i < 5; ++i) {
rightv[i][2] = rightv[i][3] = '0';
rightv[i][4] = '0' + i;
varDataSetLen(rightv[i], 3);
}
int64_t eRes[5] = {0, 0, 2, 0, 4};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
}
}
TEST(opTest, smallint_column_or_float_column) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {1, 2, 3, 4, 5};
float rightv[5]= {2.0, 3.0, 4.1, 5.2, 6.0};
int64_t eRes[5] = {3, 3, 7, 5, 7};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
}
}
TEST(opTest, smallint_column_or_double_value) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
int16_t leftv[5]= {1, 2, 3, 4, 5};
double rightv= 10.2;
int64_t eRes[5] = {11, 10, 11, 14, 15};
SSDataBlock *src = NULL;
SScalarParam res = {0};
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
}
}
TEST(opTest, binary_column_is_true) {
SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0};
SSDataBlock *src = NULL;
SScalarParam res = {0};
bool eRes[5] = {false, true, false, true, false};
for (int32_t i = 0; i < 5; ++i) {
leftv[i][2] = '0' + i % 2;
leftv[i][3] = 'a';
leftv[i][4] = '0' + i % 2;
varDataSetLen(leftv[i], 3);
}
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
flttMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
int32_t code = scalarCalculate(opNode, src, &res);
ASSERT_EQ(code, 0);
ASSERT_EQ(res.num, rowNum);
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
}
}
#endif
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
#pragma GCC diagnostic pop
source/libs/scalar/test/scalar/CMakeLists.txt
0 → 100644
浏览文件 @
f6edfd75
MESSAGE
(
STATUS
"build scalar unit test"
)
# GoogleTest requires at least C++11
SET
(
CMAKE_CXX_STANDARD 11
)
AUX_SOURCE_DIRECTORY
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
ADD_EXECUTABLE
(
scalarTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
scalarTest
PUBLIC os util common gtest qcom function nodes scalar
)
TARGET_INCLUDE_DIRECTORIES
(
scalarTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/scalar/"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/source/libs/scalar/inc"
)
source/libs/scalar/test/scalar/scalarTests.cpp
0 → 100644
浏览文件 @
f6edfd75
此差异已折叠。
点击以展开。
source/libs/scalar/test/scalarTests.cpp
已删除
100644 → 0
浏览文件 @
5fa4b1ae
/*
* 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/>.
*/
#include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include "os.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "tep.h"
#include "stub.h"
#include "addr_any.h"
#include "scalar.h"
namespace
{
}
TEST
(
scalarTest
,
func
)
{
}
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
#pragma GCC diagnostic pop
source/util/src/compare.c
浏览文件 @
f6edfd75
...
...
@@ -466,7 +466,7 @@ int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight) {
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
)
{
__compar_fn_t
comparFn
=
NULL
;
if
(
optr
==
TSDB_RELATION
_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
if
(
optr
==
OP_TYPE
_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
...
...
@@ -489,7 +489,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
}
}
if
(
optr
==
TSDB_RELATION
_NOT_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
if
(
optr
==
OP_TYPE
_NOT_IN
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
))
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
...
...
@@ -522,17 +522,17 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_FLOAT
:
comparFn
=
compareFloatVal
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
comparFn
=
compareDoubleVal
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
optr
==
TSDB_RELATION
_MATCH
)
{
if
(
optr
==
OP_TYPE
_MATCH
)
{
comparFn
=
compareStrRegexCompMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_NMATCH
)
{
}
else
if
(
optr
==
OP_TYPE
_NMATCH
)
{
comparFn
=
compareStrRegexCompNMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_LIKE
)
{
/* wildcard query using like operator */
}
else
if
(
optr
==
OP_TYPE
_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compareStrPatternMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_NOT_LIKE
)
{
/* wildcard query using like operator */
}
else
if
(
optr
==
OP_TYPE
_NOT_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
compareStrPatternNotMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_IN
)
{
}
else
if
(
optr
==
OP_TYPE
_IN
)
{
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
TSDB_RELATION
_NOT_IN
)
{
}
else
if
(
optr
==
OP_TYPE
_NOT_IN
)
{
comparFn
=
compareChkNotInString
;
}
else
{
/* normal relational comparFn */
comparFn
=
compareLenPrefixedStr
;
...
...
@@ -542,17 +542,17 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
optr
==
TSDB_RELATION
_MATCH
)
{
if
(
optr
==
OP_TYPE
_MATCH
)
{
comparFn
=
compareStrRegexCompMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_NMATCH
)
{
}
else
if
(
optr
==
OP_TYPE
_NMATCH
)
{
comparFn
=
compareStrRegexCompNMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE
_LIKE
)
{
comparFn
=
compareWStrPatternMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_NOT_LIKE
)
{
}
else
if
(
optr
==
OP_TYPE
_NOT_LIKE
)
{
comparFn
=
compareWStrPatternNotMatch
;
}
else
if
(
optr
==
TSDB_RELATION
_IN
)
{
}
else
if
(
optr
==
OP_TYPE
_IN
)
{
comparFn
=
compareChkInString
;
}
else
if
(
optr
==
TSDB_RELATION
_NOT_IN
)
{
}
else
if
(
optr
==
OP_TYPE
_NOT_IN
)
{
comparFn
=
compareChkNotInString
;
}
else
{
comparFn
=
compareLenPrefixedWStr
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录