Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
97e7a41a
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
97e7a41a
编写于
2月 28, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/qnode
上级
cda69861
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
569 addition
and
163 deletion
+569
-163
include/common/tep.h
include/common/tep.h
+1
-0
source/common/src/tep.c
source/common/src/tep.c
+41
-26
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+3
-0
source/libs/scalar/inc/sclvector.h
source/libs/scalar/inc/sclvector.h
+3
-0
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+1
-0
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+22
-16
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+256
-15
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+242
-106
未找到文件。
include/common/tep.h
浏览文件 @
97e7a41a
...
...
@@ -101,6 +101,7 @@ size_t blockDataNumOfRowsForSerialize(const SSDataBlock* pBlock, int32_t blockSi
int32_t
blockDataSort
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
);
int32_t
blockDataSort_rv
(
SSDataBlock
*
pDataBlock
,
SArray
*
pOrderInfo
,
bool
nullFirst
);
int32_t
blockDataEnsureColumnCapacity
(
SColumnInfoData
*
pColumn
,
uint32_t
numOfRows
);
int32_t
blockDataEnsureCapacity
(
SSDataBlock
*
pDataBlock
,
uint32_t
numOfRows
);
void
blockDataClearup
(
SSDataBlock
*
pDataBlock
,
bool
hasVarCol
);
void
*
blockDataDestroy
(
SSDataBlock
*
pBlock
);
...
...
source/common/src/tep.c
浏览文件 @
97e7a41a
...
...
@@ -120,14 +120,18 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
}
else
{
char
*
p
=
pColumnInfoData
->
pData
+
pColumnInfoData
->
info
.
bytes
*
currentRow
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
*
(
bool
*
)
p
=
*
(
bool
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
{
*
(
int8_t
*
)
p
=
*
(
int8_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
{
*
(
int16_t
*
)
p
=
*
(
int16_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
{
*
(
int32_t
*
)
p
=
*
(
int32_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
*
(
int64_t
*
)
p
=
*
(
int64_t
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_FLOAT
:
{
*
(
float
*
)
p
=
*
(
float
*
)
pData
;
break
;}
case
TSDB_DATA_TYPE_DOUBLE
:
{
*
(
double
*
)
p
=
*
(
double
*
)
pData
;
break
;}
default:
assert
(
0
);
}
...
...
@@ -1040,36 +1044,47 @@ void blockDataClearup(SSDataBlock* pDataBlock, bool hasVarCol) {
}
}
int32_t
blockDataEnsureCapacity
(
SSDataBlock
*
pDataBlock
,
uint32_t
numOfRows
)
{
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
p
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
info
.
type
))
{
char
*
tmp
=
realloc
(
p
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
numOfRows
);
int32_t
blockDataEnsureColumnCapacity
(
SColumnInfoData
*
pColumn
,
uint32_t
numOfRows
)
{
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
info
.
type
))
{
char
*
tmp
=
realloc
(
pColumn
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
numOfRows
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
varmeta
.
offset
=
(
int32_t
*
)
tmp
;
memset
(
p
->
varmeta
.
offset
,
0
,
sizeof
(
int32_t
)
*
numOfRows
);
pColumn
->
varmeta
.
offset
=
(
int32_t
*
)
tmp
;
memset
(
pColumn
->
varmeta
.
offset
,
0
,
sizeof
(
int32_t
)
*
numOfRows
);
p
->
varmeta
.
length
=
0
;
p
->
varmeta
.
allocLen
=
0
;
tfree
(
p
->
pData
);
pColumn
->
varmeta
.
length
=
0
;
pColumn
->
varmeta
.
allocLen
=
0
;
tfree
(
pColumn
->
pData
);
}
else
{
char
*
tmp
=
realloc
(
p
->
nullbitmap
,
BitmapLen
(
numOfRows
));
char
*
tmp
=
realloc
(
pColumn
->
nullbitmap
,
BitmapLen
(
numOfRows
));
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
nullbitmap
=
tmp
;
memset
(
p
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
pColumn
->
nullbitmap
=
tmp
;
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
tmp
=
realloc
(
p
->
pData
,
numOfRows
*
p
->
info
.
bytes
);
tmp
=
realloc
(
pColumn
->
pData
,
numOfRows
*
pColumn
->
info
.
bytes
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
p
->
pData
=
tmp
;
pColumn
->
pData
=
tmp
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
blockDataEnsureCapacity
(
SSDataBlock
*
pDataBlock
,
uint32_t
numOfRows
)
{
int32_t
code
=
0
;
for
(
int32_t
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
p
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
code
=
blockDataEnsureColumnCapacity
(
p
,
numOfRows
);
if
(
code
)
{
return
code
;
}
}
...
...
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
97e7a41a
...
...
@@ -105,6 +105,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_RAW_EXPR
:
res
=
walkNode
(((
SRawExprNode
*
)
pNode
)
->
pNode
,
order
,
walker
,
pContext
);
break
;
case
QUERY_NODE_TARGET
:
res
=
walkNode
(((
STargetNode
*
)
pNode
)
->
pExpr
,
order
,
walker
,
pContext
);
break
;
default:
break
;
}
...
...
source/libs/scalar/inc/sclvector.h
浏览文件 @
97e7a41a
...
...
@@ -22,6 +22,9 @@ extern "C" {
#include "sclfunc.h"
typedef
double
(
*
_mathFunc
)(
double
,
double
,
bool
*
);
typedef
void
(
*
_bufConverteFunc
)(
char
*
buf
,
SScalarParam
*
pOut
,
int32_t
outType
);
typedef
void
(
*
_bin_scalar_fn_t
)(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
output
,
int32_t
order
);
_bin_scalar_fn_t
getBinScalarOperatorFn
(
int32_t
binOperator
);
...
...
source/libs/scalar/src/filter.c
浏览文件 @
97e7a41a
无法预览此类型文件
source/libs/scalar/src/scalar.c
浏览文件 @
97e7a41a
...
...
@@ -142,9 +142,13 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
case
QUERY_NODE_VALUE
:
{
SValueNode
*
valueNode
=
(
SValueNode
*
)
node
;
param
->
data
=
nodesGetValueFromNode
(
valueNode
);
param
->
orig
.
data
=
param
->
data
;
param
->
num
=
1
;
param
->
type
=
valueNode
->
node
.
resType
.
type
;
param
->
bytes
=
valueNode
->
node
.
resType
.
bytes
;
if
(
TSDB_DATA_TYPE_NULL
==
param
->
type
)
{
sclSetNull
(
param
,
0
);
}
param
->
dataInBlock
=
false
;
break
;
...
...
@@ -178,12 +182,12 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
}
SColumnNode
*
ref
=
(
SColumnNode
*
)
node
;
if
(
ref
->
tuple
Id
>=
taosArrayGetSize
(
ctx
->
pBlockList
))
{
sclError
(
"column tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
ref
->
tuple
Id
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
if
(
ref
->
dataBlock
Id
>=
taosArrayGetSize
(
ctx
->
pBlockList
))
{
sclError
(
"column tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
ref
->
dataBlock
Id
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SSDataBlock
*
block
=
*
(
SSDataBlock
**
)
taosArrayGet
(
ctx
->
pBlockList
,
ref
->
tuple
Id
);
SSDataBlock
*
block
=
*
(
SSDataBlock
**
)
taosArrayGet
(
ctx
->
pBlockList
,
ref
->
dataBlock
Id
);
if
(
NULL
==
block
||
ref
->
slotId
>=
taosArrayGetSize
(
block
->
pDataBlock
))
{
sclError
(
"column slotId is too big, slodId:%d, dataBlockSize:%d"
,
ref
->
slotId
,
(
int32_t
)
taosArrayGetSize
(
block
->
pDataBlock
));
...
...
@@ -639,15 +643,15 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) {
EDealRes
sclWalkTarget
(
SNode
*
pNode
,
SScalarCtx
*
ctx
)
{
STargetNode
*
target
=
(
STargetNode
*
)
pNode
;
if
(
target
->
tuple
Id
>=
taosArrayGetSize
(
ctx
->
pBlockList
))
{
sclError
(
"target tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
target
->
tuple
Id
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
if
(
target
->
dataBlock
Id
>=
taosArrayGetSize
(
ctx
->
pBlockList
))
{
sclError
(
"target tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
target
->
dataBlock
Id
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
SSDataBlock
*
block
=
taosArrayGet
(
ctx
->
pBlockList
,
target
->
tuple
Id
);
SSDataBlock
*
block
=
*
(
SSDataBlock
**
)
taosArrayGet
(
ctx
->
pBlockList
,
target
->
dataBlock
Id
);
if
(
target
->
slotId
>=
taosArrayGetSize
(
block
->
pDataBlock
))
{
sclError
(
"target slot not exist,
slotId:%d, dataBlockNum:%d"
,
target
->
slotId
,
(
int32_t
)
taosArrayGetSize
(
block
->
pDataBlock
));
sclError
(
"target slot not exist,
dataBlockId:%d, slotId:%d, dataBlockNum:%d"
,
target
->
dataBlockId
,
target
->
slotId
,
(
int32_t
)
taosArrayGetSize
(
block
->
pDataBlock
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
...
...
@@ -734,7 +738,7 @@ _return:
}
int32_t
scalarCalculate
(
SNode
*
pNode
,
SArray
*
pBlockList
,
SScalarParam
*
pDst
)
{
if
(
NULL
==
pNode
||
NULL
==
pBlockList
||
NULL
==
pDst
)
{
if
(
NULL
==
pNode
||
NULL
==
pBlockList
)
{
SCL_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
@@ -751,6 +755,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
SCL_ERR_JRET
(
ctx
.
code
);
if
(
pDst
)
{
SScalarParam
*
res
=
(
SScalarParam
*
)
taosHashGet
(
ctx
.
pRes
,
(
void
*
)
&
pNode
,
POINTER_BYTES
);
if
(
NULL
==
res
)
{
sclError
(
"no valid res in hash, node:%p, type:%d"
,
pNode
,
nodeType
(
pNode
));
...
...
@@ -760,6 +765,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
taosHashRemove
(
ctx
.
pRes
,
(
void
*
)
&
pNode
,
POINTER_BYTES
);
*
pDst
=
*
res
;
}
_return:
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
97e7a41a
...
...
@@ -485,6 +485,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
if
(
NULL
==
paramOut1
->
data
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
paramOut1
->
orig
.
data
=
paramOut1
->
data
;
code
=
vectorConvertImpl
(
param1
,
paramOut1
);
if
(
code
)
{
...
...
@@ -502,6 +503,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
tfree
(
paramOut1
->
data
);
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
paramOut2
->
orig
.
data
=
paramOut2
->
data
;
code
=
vectorConvertImpl
(
param2
,
paramOut2
);
if
(
code
)
{
...
...
@@ -514,10 +516,11 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
return
TSDB_CODE_SUCCESS
;
}
void
vector
Add
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
void
vector
Math
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
,
_mathFunc
func
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
num
,
pRight
->
num
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
double
leftv
=
0
,
rightv
=
0
;
bool
isNull
=
false
;
SScalarParam
leftParam
=
{.
type
=
TSDB_DATA_TYPE_DOUBLE
,
.
num
=
pLeft
->
num
,
.
dataInBlock
=
false
};
SScalarParam
rightParam
=
{.
type
=
TSDB_DATA_TYPE_DOUBLE
,
.
num
=
pRight
->
num
,
.
dataInBlock
=
false
};
if
(
IS_VAR_DATA_TYPE
(
pLeft
->
type
))
{
...
...
@@ -526,6 +529,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
sclError
(
"malloc %d failed"
,
(
int32_t
)(
leftParam
.
num
*
sizeof
(
double
)));
return
;
}
leftParam
.
orig
.
data
=
leftParam
.
data
;
if
(
vectorConvertImpl
(
pLeft
,
&
leftParam
))
{
return
;
...
...
@@ -539,6 +543,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
sclFreeParam
(
&
leftParam
);
return
;
}
rightParam
.
orig
.
data
=
rightParam
.
data
;
if
(
vectorConvertImpl
(
pRight
,
&
rightParam
))
{
sclFreeParam
(
&
leftParam
);
...
...
@@ -548,8 +553,163 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
pRight
=
&
rightParam
;
}
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeft
->
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRight
->
type
);
if
(
pLeft
->
num
==
pRight
->
num
)
{
for
(;
i
<
pRight
->
num
&&
i
>=
0
;
i
+=
step
)
{
sclMoveParamListData
(
pLeft
,
1
,
i
);
sclMoveParamListData
(
pRight
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
if
(
sclIsNull
(
pLeft
,
i
)
||
sclIsNull
(
pRight
,
i
))
{
sclSetNull
(
pOut
,
i
);
continue
;
}
GET_TYPED_DATA
(
leftv
,
double
,
pLeft
->
type
,
pLeft
->
data
);
GET_TYPED_DATA
(
rightv
,
double
,
pRight
->
type
,
pRight
->
data
);
SET_DOUBLE_VAL
(
pOut
->
data
,
(
*
func
)(
leftv
,
rightv
,
&
isNull
));
if
(
isNull
)
{
sclSetNull
(
pOut
,
i
);
isNull
=
false
;
}
}
}
else
if
(
pLeft
->
num
==
1
)
{
sclMoveParamListData
(
pLeft
,
1
,
0
);
GET_TYPED_DATA
(
leftv
,
double
,
pLeft
->
type
,
pLeft
->
data
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pRight
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
if
(
sclIsNull
(
pLeft
,
0
)
||
sclIsNull
(
pRight
,
i
))
{
sclSetNull
(
pOut
,
i
);
continue
;
}
GET_TYPED_DATA
(
rightv
,
double
,
pRight
->
type
,
pRight
->
data
);
SET_DOUBLE_VAL
(
pOut
->
data
,
(
*
func
)(
leftv
,
rightv
,
&
isNull
));
if
(
isNull
)
{
sclSetNull
(
pOut
,
i
);
isNull
=
false
;
}
}
}
else
if
(
pRight
->
num
==
1
)
{
sclMoveParamListData
(
pRight
,
1
,
0
);
GET_TYPED_DATA
(
rightv
,
double
,
pRight
->
type
,
pRight
->
data
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pLeft
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
if
(
sclIsNull
(
pLeft
,
i
)
||
sclIsNull
(
pRight
,
0
))
{
sclSetNull
(
pOut
,
i
);
continue
;
}
GET_TYPED_DATA
(
leftv
,
double
,
pLeft
->
type
,
pLeft
->
data
);
SET_DOUBLE_VAL
(
pOut
->
data
,
(
*
func
)(
leftv
,
rightv
,
&
isNull
));
if
(
isNull
)
{
sclSetNull
(
pOut
,
i
);
isNull
=
false
;
}
}
}
sclFreeParam
(
&
leftParam
);
sclFreeParam
(
&
rightParam
);
}
double
mathAdd
(
double
leftv
,
double
rightv
,
bool
*
isNull
)
{
return
leftv
+
rightv
;
}
double
mathSub
(
double
leftv
,
double
rightv
,
bool
*
isNull
)
{
return
leftv
-
rightv
;
}
double
mathMultiply
(
double
leftv
,
double
rightv
,
bool
*
isNull
)
{
return
leftv
*
rightv
;
}
double
mathDivide
(
double
leftv
,
double
rightv
,
bool
*
isNull
)
{
double
zero
=
0
;
if
(
0
==
compareDoubleVal
(
&
rightv
,
&
zero
))
{
*
isNull
=
true
;
return
zero
;
}
return
leftv
/
rightv
;
}
double
mathRemainder
(
double
leftv
,
double
rightv
,
bool
*
isNull
)
{
double
zero
=
0
;
if
(
0
==
compareDoubleVal
(
&
rightv
,
&
zero
))
{
*
isNull
=
true
;
return
zero
;
}
return
leftv
-
((
int64_t
)(
leftv
/
rightv
))
*
rightv
;
}
void
vectorAdd
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorMath
(
pLeft
,
pRight
,
pOut
,
_ord
,
mathAdd
);
}
void
vectorSub
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorMath
(
pLeft
,
pRight
,
pOut
,
_ord
,
mathSub
);
}
void
vectorMultiply
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorMath
(
pLeft
,
pRight
,
pOut
,
_ord
,
mathMultiply
);
}
void
vectorDivide
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorMath
(
pLeft
,
pRight
,
pOut
,
_ord
,
mathDivide
);
}
void
vectorRemainder
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
vectorMath
(
pLeft
,
pRight
,
pOut
,
_ord
,
mathRemainder
);
}
#if 0
void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = calloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) {
return;
}
pLeft = &leftParam;
}
if (IS_VAR_DATA_TYPE(pRight->type)) {
rightParam.data = calloc(rightParam.num, sizeof(double));
if (NULL == rightParam.data) {
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
sclFreeParam(&leftParam);
return;
}
rightParam.orig.data = rightParam.data;
if (vectorConvertImpl(pRight, &rightParam)) {
sclFreeParam(&leftParam);
sclFreeParam(&rightParam);
return;
}
pRight = &rightParam;
}
if (pLeft->num == pRight->num) {
for (; i < pRight->num && i >= 0; i += step) {
...
...
@@ -562,9 +722,15 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
continue;
}
SET_DOUBLE_VAL
(
pOut
->
data
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, leftv + rightv);
}
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
...
...
@@ -574,9 +740,14 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
continue;
}
SET_DOUBLE_VAL
(
pOut
->
data
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
0
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, leftv + rightv);
}
} else if (pRight->num == 1) {
sclMoveParamListData(pRight, 1, 0);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
for (; i >= 0 && i < pLeft->num; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pOut, 1, i);
...
...
@@ -586,7 +757,9 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
continue;
}
SET_DOUBLE_VAL
(
pOut
->
data
,
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
)
+
getVectorDoubleValueFnRight
(
pRight
->
data
,
0
));
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
SET_DOUBLE_VAL(pOut->data, leftv + rightv);
}
}
...
...
@@ -597,6 +770,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
...
...
@@ -606,6 +780,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) {
return;
...
...
@@ -619,6 +794,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
sclFreeParam(&leftParam);
return;
}
rightParam.orig.data = rightParam.data;
if (vectorConvertImpl(pRight, &rightParam)) {
sclFreeParam(&leftParam);
...
...
@@ -643,9 +819,15 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i));
}
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
...
...
@@ -677,6 +859,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in
void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
...
...
@@ -686,6 +869,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) {
return;
...
...
@@ -699,6 +883,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
sclFreeParam(&leftParam);
return;
}
rightParam.orig.data = rightParam.data;
if (vectorConvertImpl(pRight, &rightParam)) {
sclFreeParam(&leftParam);
...
...
@@ -723,9 +908,15 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i));
}
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
...
...
@@ -758,6 +949,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
...
...
@@ -767,6 +959,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) {
return;
...
...
@@ -780,6 +973,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclFreeParam(&leftParam);
return;
}
rightParam.orig.data = rightParam.data;
if (vectorConvertImpl(pRight, &rightParam)) {
sclFreeParam(&leftParam);
...
...
@@ -804,6 +998,9 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i));
}
} else if (pLeft->num == 1) {
...
...
@@ -839,6 +1036,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
...
...
@@ -848,6 +1046,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) {
return;
...
...
@@ -861,6 +1060,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
sclFreeParam(&leftParam);
return;
}
rightParam.orig.data = rightParam.data;
if (vectorConvertImpl(pRight, &rightParam)) {
sclFreeParam(&leftParam);
...
...
@@ -892,8 +1092,9 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
continue;
}
double
left
=
getVectorDoubleValueFnLeft
(
pLeft
->
data
,
i
);
double
right
=
getVectorDoubleValueFnRight
(
pRight
->
data
,
i
);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right);
}
} else if (pLeft->num == 1) {
...
...
@@ -946,6 +1147,8 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
sclFreeParam(&rightParam);
}
#endif
void
vectorConcat
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
void
*
out
,
int32_t
_ord
)
{
int32_t
len
=
pLeft
->
bytes
+
pRight
->
bytes
;
...
...
@@ -999,6 +1202,7 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
void
vectorBitAnd
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
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
;
int64_t
leftv
=
0
,
rightv
=
0
;
SScalarParam
leftParam
=
{.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
num
=
pLeft
->
num
};
SScalarParam
rightParam
=
{.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
num
=
pRight
->
num
};
...
...
@@ -1008,6 +1212,7 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclError
(
"malloc %d failed"
,
(
int32_t
)(
leftParam
.
num
*
sizeof
(
double
)));
return
;
}
leftParam
.
orig
.
data
=
leftParam
.
data
;
if
(
vectorConvertImpl
(
pLeft
,
&
leftParam
))
{
return
;
...
...
@@ -1021,6 +1226,7 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclFreeParam
(
&
leftParam
);
return
;
}
rightParam
.
orig
.
data
=
rightParam
.
data
;
if
(
vectorConvertImpl
(
pRight
,
&
rightParam
))
{
sclFreeParam
(
&
leftParam
);
...
...
@@ -1045,9 +1251,15 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
i
)
&
getVectorBigintValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
&
rightv
);
}
}
else
if
(
pLeft
->
num
==
1
)
{
sclMoveParamListData
(
pLeft
,
1
,
0
);
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pRight
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
...
...
@@ -1057,9 +1269,14 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
0
)
&
getVectorBigintValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
&
rightv
);
}
}
else
if
(
pRight
->
num
==
1
)
{
sclMoveParamListData
(
pRight
,
1
,
0
);
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pLeft
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
...
...
@@ -1069,7 +1286,9 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
i
)
&
getVectorBigintValueFnRight
(
pRight
->
data
,
0
));
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
&
rightv
);
}
}
...
...
@@ -1080,6 +1299,7 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
void
vectorBitOr
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
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
;
int64_t
leftv
=
0
,
rightv
=
0
;
SScalarParam
leftParam
=
{.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
num
=
pLeft
->
num
};
SScalarParam
rightParam
=
{.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
num
=
pRight
->
num
};
...
...
@@ -1089,6 +1309,7 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclError
(
"malloc %d failed"
,
(
int32_t
)(
leftParam
.
num
*
sizeof
(
double
)));
return
;
}
leftParam
.
orig
.
data
=
leftParam
.
data
;
if
(
vectorConvertImpl
(
pLeft
,
&
leftParam
))
{
return
;
...
...
@@ -1102,6 +1323,7 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
sclFreeParam
(
&
leftParam
);
return
;
}
rightParam
.
orig
.
data
=
rightParam
.
data
;
if
(
vectorConvertImpl
(
pRight
,
&
rightParam
))
{
sclFreeParam
(
&
leftParam
);
...
...
@@ -1125,9 +1347,15 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
i
)
|
getVectorBigintValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
|
rightv
);
}
}
else
if
(
pLeft
->
num
==
1
)
{
sclMoveParamListData
(
pLeft
,
1
,
0
);
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pRight
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
...
...
@@ -1137,9 +1365,14 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
0
)
|
getVectorBigintValueFnRight
(
pRight
->
data
,
i
));
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
|
rightv
);
}
}
else
if
(
pRight
->
num
==
1
)
{
sclMoveParamListData
(
pRight
,
1
,
0
);
GET_TYPED_DATA
(
rightv
,
int64_t
,
pRight
->
type
,
pRight
->
data
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pLeft
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
...
...
@@ -1149,7 +1382,9 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
continue
;
}
SET_BIGINT_VAL
(
pOut
->
data
,
getVectorBigintValueFnLeft
(
pLeft
->
data
,
i
)
|
getVectorBigintValueFnRight
(
pRight
->
data
,
0
));
GET_TYPED_DATA
(
leftv
,
int64_t
,
pLeft
->
type
,
pLeft
->
data
);
SET_BIGINT_VAL
(
pOut
->
data
,
leftv
|
rightv
);
}
}
...
...
@@ -1181,8 +1416,11 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
SET_TYPED_DATA
(
pOut
->
data
,
TSDB_DATA_TYPE_BOOL
,
res
);
}
}
else
if
(
pLeft
->
num
==
1
)
{
sclMoveParamListData
(
pLeft
,
1
,
0
);
for
(;
i
>=
0
&&
i
<
pRight
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pRight
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
if
(
sclIsNull
(
pLeft
,
0
)
||
sclIsNull
(
pRight
,
i
))
{
sclSetNull
(
pOut
,
i
);
...
...
@@ -1195,8 +1433,11 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
SET_TYPED_DATA
(
pOut
->
data
,
TSDB_DATA_TYPE_BOOL
,
res
);
}
}
else
if
(
pRight
->
num
==
1
)
{
sclMoveParamListData
(
pRight
,
1
,
0
);
for
(;
i
>=
0
&&
i
<
pLeft
->
num
;
i
+=
step
)
{
sclMoveParamListData
(
pLeft
,
1
,
i
);
sclMoveParamListData
(
pOut
,
1
,
i
);
if
(
sclIsNull
(
pLeft
,
i
)
||
sclIsNull
(
pRight
,
0
))
{
sclSetNull
(
pOut
,
i
);
...
...
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
97e7a41a
...
...
@@ -50,19 +50,20 @@ void scltInitLogFile() {
tsAsyncLog
=
0
;
qDebugFlag
=
159
;
strcpy
(
tsLogDir
,
"/var/log/taos"
);
if
(
taosInitLog
(
defaultLogFileNamePrefix
,
maxLogFileNum
)
<
0
)
{
printf
(
"failed to open log file in directory:%s
\n
"
,
tsLogDir
);
}
}
void
scltAppendReservedSlot
(
SArray
*
pBlockList
,
int16_t
*
tuple
Id
,
int16_t
*
slotId
,
bool
newBlock
,
int32_t
rows
,
SColumnInfo
*
colInfo
)
{
void
scltAppendReservedSlot
(
SArray
*
pBlockList
,
int16_t
*
dataBlock
Id
,
int16_t
*
slotId
,
bool
newBlock
,
int32_t
rows
,
SColumnInfo
*
colInfo
)
{
if
(
newBlock
)
{
SSDataBlock
*
res
=
(
SSDataBlock
*
)
calloc
(
1
,
sizeof
(
SSDataBlock
));
res
->
info
.
numOfCols
=
1
;
res
->
info
.
rows
=
rows
;
res
->
pDataBlock
=
taosArrayInit
(
1
,
sizeof
(
SColumnInfoData
));
SColumnInfoData
idata
=
{
{
0
}
};
SColumnInfoData
idata
=
{
0
};
idata
.
info
=
*
colInfo
;
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
...
...
@@ -70,18 +71,19 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *tupleId, int16_t *slotI
blockDataEnsureCapacity
(
res
,
rows
);
*
tuple
Id
=
taosArrayGetSize
(
pBlockList
)
-
1
;
*
dataBlock
Id
=
taosArrayGetSize
(
pBlockList
)
-
1
;
*
slotId
=
0
;
}
else
{
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
pBlockList
);
res
->
info
.
numOfCols
++
;
SColumnInfoData
idata
=
{
{
0
}
};
SColumnInfoData
idata
=
{
0
};
idata
.
info
=
*
colInfo
;
blockDataEnsureColumnCapacity
(
&
idata
,
rows
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
blockDataEnsureCapacity
(
res
,
rows
);
*
tuple
Id
=
taosArrayGetSize
(
pBlockList
)
-
1
;
*
dataBlock
Id
=
taosArrayGetSize
(
pBlockList
)
-
1
;
*
slotId
=
taosArrayGetSize
(
res
->
pDataBlock
)
-
1
;
}
}
...
...
@@ -130,14 +132,21 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
idata
.
info
.
type
=
dataType
;
idata
.
info
.
bytes
=
dataBytes
;
idata
.
info
.
colId
=
3
;
idata
.
pData
=
(
char
*
)
value
;
if
(
IS_VAR_DATA_TYPE
(
dataType
))
{
idata
.
varmeta
.
offset
=
(
int32_t
*
)
calloc
(
rowNum
,
sizeof
(
int32_t
));
int32_t
size
=
idata
.
info
.
bytes
*
rowNum
;
idata
.
pData
=
(
char
*
)
calloc
(
1
,
size
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
blockDataEnsureCapacity
(
res
,
rowNum
);
SColumnInfoData
*
pColumn
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
idata
.
varmeta
.
offset
[
i
]
=
(
dataBytes
+
VARSTR_HEADER_SIZE
)
*
i
;
colDataAppend
(
pColumn
,
i
,
(
const
char
*
)
value
,
false
);
if
(
IS_VAR_DATA_TYPE
(
dataType
))
{
value
=
(
char
*
)
value
+
varDataTLen
(
value
);
}
else
{
value
=
(
char
*
)
value
+
dataBytes
;
}
}
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
rnode
->
slotId
=
2
;
rnode
->
colId
=
3
;
...
...
@@ -151,8 +160,22 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in
idata
.
info
.
type
=
dataType
;
idata
.
info
.
bytes
=
dataBytes
;
idata
.
info
.
colId
=
1
+
idx
;
idata
.
pData
=
(
char
*
)
value
;
int32_t
size
=
idata
.
info
.
bytes
*
rowNum
;
idata
.
pData
=
(
char
*
)
calloc
(
1
,
size
);
taosArrayPush
(
res
->
pDataBlock
,
&
idata
);
res
->
info
.
numOfCols
++
;
SColumnInfoData
*
pColumn
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
blockDataEnsureColumnCapacity
(
pColumn
,
rowNum
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
colDataAppend
(
pColumn
,
i
,
(
const
char
*
)
value
,
false
);
if
(
IS_VAR_DATA_TYPE
(
dataType
))
{
value
=
(
char
*
)
value
+
varDataTLen
(
value
);
}
else
{
value
=
(
char
*
)
value
+
dataBytes
;
}
}
rnode
->
slotId
=
idx
;
rnode
->
colId
=
1
+
idx
;
...
...
@@ -200,11 +223,11 @@ void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi
*
pNode
=
(
SNode
*
)
onode
;
}
void
scltMakeTargetNode
(
SNode
**
pNode
,
int16_t
tuple
Id
,
int16_t
slotId
,
SNode
*
snode
)
{
void
scltMakeTargetNode
(
SNode
**
pNode
,
int16_t
dataBlock
Id
,
int16_t
slotId
,
SNode
*
snode
)
{
SNode
*
node
=
nodesMakeNode
(
QUERY_NODE_TARGET
);
STargetNode
*
onode
=
(
STargetNode
*
)
node
;
onode
->
pExpr
=
snode
;
onode
->
tupleId
=
tuple
Id
;
onode
->
dataBlockId
=
dataBlock
Id
;
onode
->
slotId
=
slotId
;
*
pNode
=
(
SNode
*
)
onode
;
...
...
@@ -699,7 +722,7 @@ TEST(constantTest, int_is_null1) {
TEST
(
constantTest
,
int_is_null2
)
{
SNode
*
pLeft
=
NULL
,
*
pRight
=
NULL
,
*
opNode
=
NULL
,
*
res
=
NULL
;
int32_t
leftv
=
TSDB_DATA_INT_NULL
,
rightv
=
1
;
scltMakeValueNode
(
&
pLeft
,
TSDB_DATA_TYPE_
INT
,
&
leftv
);
scltMakeValueNode
(
&
pLeft
,
TSDB_DATA_TYPE_
NULL
,
&
leftv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IS_NULL
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
pRight
);
int32_t
code
=
scalarCalculateConstants
(
opNode
,
&
res
);
...
...
@@ -728,8 +751,8 @@ TEST(constantTest, int_is_not_null1) {
TEST
(
constantTest
,
int_is_not_null2
)
{
SNode
*
pLeft
=
NULL
,
*
pRight
=
NULL
,
*
opNode
=
NULL
,
*
res
=
NULL
;
int32_t
leftv
=
TSDB_DATA_INT_NULL
,
rightv
=
1
;
scltMakeValueNode
(
&
pLeft
,
TSDB_DATA_TYPE_
INT
,
&
leftv
);
int32_t
leftv
=
1
,
rightv
=
1
;
scltMakeValueNode
(
&
pLeft
,
TSDB_DATA_TYPE_
NULL
,
&
leftv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IS_NOT_NULL
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
pRight
);
int32_t
code
=
scalarCalculateConstants
(
opNode
,
&
res
);
...
...
@@ -837,6 +860,8 @@ TEST(constantTest, greater_and_lower) {
TEST
(
columnTest
,
smallint_value_add_int_column
)
{
scltInitLogFile
();
SNode
*
pLeft
=
NULL
,
*
pRight
=
NULL
,
*
opNode
=
NULL
;
int32_t
leftv
=
1
;
int16_t
rightv
[
5
]
=
{
0
,
-
5
,
-
4
,
23
,
100
};
...
...
@@ -850,9 +875,9 @@ TEST(columnTest, smallint_value_add_int_column) {
SArray
*
blockList
=
taosArrayInit
(
2
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_DOUBLE
,
.
bytes
=
sizeof
(
double
)};
int16_t
tuple
Id
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
tuple
Id
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
tuple
Id
,
slotId
,
opNode
);
int16_t
dataBlock
Id
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlock
Id
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlock
Id
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -867,7 +892,6 @@ TEST(columnTest, smallint_value_add_int_column) {
}
}
#if 0
TEST
(
columnTest
,
bigint_column_multi_binary_column
)
{
SNode
*
pLeft
=
NULL
,
*
pRight
=
NULL
,
*
opNode
=
NULL
;
int64_t
leftv
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
...
...
@@ -879,19 +903,29 @@ TEST(columnTest, bigint_column_multi_binary_column) {
}
double
eRes
[
5
]
=
{
0
,
2
,
6
,
12
,
20
};
SSDataBlock
*
src
=
NULL
;
SScalarParam res = {0};
int32_t
rowNum
=
sizeof
(
rightv
)
/
sizeof
(
rightv
[
0
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_BIGINT
,
sizeof
(
int64_t
),
rowNum
,
leftv
);
scltMakeColumnNode
(
&
pRight
,
&
src
,
TSDB_DATA_TYPE_BINARY
,
5
,
rowNum
,
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_MULTI
,
TSDB_DATA_TYPE_DOUBLE
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_DOUBLE
,
.
bytes
=
sizeof
(
double
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((double *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
double
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -906,19 +940,28 @@ TEST(columnTest, smallint_column_and_binary_column) {
}
int64_t
eRes
[
5
]
=
{
0
,
0
,
2
,
0
,
4
};
SSDataBlock
*
src
=
NULL
;
SScalarParam res = {0};
int32_t
rowNum
=
sizeof
(
rightv
)
/
sizeof
(
rightv
[
0
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_SMALLINT
,
sizeof
(
int16_t
),
rowNum
,
leftv
);
scltMakeColumnNode
(
&
pRight
,
&
src
,
TSDB_DATA_TYPE_BINARY
,
5
,
rowNum
,
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_BIT_AND
,
TSDB_DATA_TYPE_BIGINT
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
bytes
=
sizeof
(
int64_t
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BIGINT
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((int64_t *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
int64_t
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -928,19 +971,28 @@ TEST(columnTest, smallint_column_or_float_column) {
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
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_SMALLINT
,
sizeof
(
int16_t
),
rowNum
,
leftv
);
scltMakeColumnNode
(
&
pRight
,
&
src
,
TSDB_DATA_TYPE_FLOAT
,
sizeof
(
float
),
rowNum
,
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_BIT_OR
,
TSDB_DATA_TYPE_BIGINT
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
bytes
=
sizeof
(
int64_t
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BIGINT
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((int64_t *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
int64_t
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -950,19 +1002,28 @@ TEST(columnTest, smallint_column_or_double_value) {
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
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_SMALLINT
,
sizeof
(
int16_t
),
rowNum
,
leftv
);
scltMakeValueNode
(
&
pRight
,
TSDB_DATA_TYPE_DOUBLE
,
&
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_BIT_OR
,
TSDB_DATA_TYPE_BIGINT
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
bytes
=
sizeof
(
int64_t
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BIGINT
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((int64_t *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
int64_t
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -972,19 +1033,28 @@ TEST(columnTest, smallint_column_greater_double_value) {
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
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_SMALLINT
,
sizeof
(
int16_t
),
rowNum
,
leftv
);
scltMakeValueNode
(
&
pRight
,
TSDB_DATA_TYPE_DOUBLE
,
&
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_GREATER_THAN
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -994,7 +1064,6 @@ TEST(columnTest, int_column_in_double_list) {
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
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_INT
,
sizeof
(
int32_t
),
rowNum
,
leftv
);
SNodeList
*
list
=
nodesMakeList
();
...
...
@@ -1007,13 +1076,23 @@ TEST(columnTest, int_column_in_double_list) {
scltMakeListNode
(
&
listNode
,
list
,
TSDB_DATA_TYPE_INT
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IN
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
listNode
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -1021,7 +1100,6 @@ 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
)
{
...
...
@@ -1055,13 +1133,23 @@ TEST(columnTest, binary_column_in_binary_list) {
scltMakeListNode
(
&
listNode
,
list
,
TSDB_DATA_TYPE_BINARY
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IN
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
listNode
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -1070,7 +1158,6 @@ TEST(columnTest, binary_column_like_binary) {
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
)
{
...
...
@@ -1088,21 +1175,31 @@ TEST(columnTest, binary_column_like_binary) {
scltMakeValueNode
(
&
pRight
,
TSDB_DATA_TYPE_BINARY
,
rightv
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_LIKE
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
pRight
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
TEST
(
columnTest
,
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
)
{
...
...
@@ -1117,13 +1214,23 @@ TEST(columnTest, binary_column_is_true) {
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IS_TRUE
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
NULL
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -1131,30 +1238,41 @@ 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};
bool
eRes
[
5
]
=
{
false
,
false
,
true
,
false
,
true
};
for (int32_t i = 0; i <
4
; ++i) {
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
);
}
setVardataNull(leftv[4], TSDB_DATA_TYPE_BINARY);
int32_t
rowNum
=
sizeof
(
leftv
)
/
sizeof
(
leftv
[
0
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_BINARY
,
3
,
rowNum
,
leftv
);
SColumnInfoData
*
pcolumn
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
src
->
pDataBlock
);
colDataAppend
(
pcolumn
,
2
,
NULL
,
true
);
colDataAppend
(
pcolumn
,
4
,
NULL
,
true
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IS_NULL
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
NULL
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -1162,30 +1280,40 @@ 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) {
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
);
}
setVardataNull(leftv[4], TSDB_DATA_TYPE_BINARY);
int32_t
rowNum
=
sizeof
(
leftv
)
/
sizeof
(
leftv
[
0
]);
scltMakeColumnNode
(
&
pLeft
,
&
src
,
TSDB_DATA_TYPE_BINARY
,
3
,
rowNum
,
leftv
);
SColumnInfoData
*
pcolumn
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
src
->
pDataBlock
);
colDataAppend
(
pcolumn
,
4
,
NULL
,
true
);
scltMakeOpNode
(
&
opNode
,
OP_TYPE_IS_NOT_NULL
,
TSDB_DATA_TYPE_BOOL
,
pLeft
,
NULL
);
int32_t code = scalarCalculate(opNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
...
...
@@ -1198,28 +1326,36 @@ TEST(columnTest, greater_and_lower) {
int32_t
v4
[
5
]
=
{
5
,
3
,
4
,
2
,
6
};
bool
eRes
[
5
]
=
{
false
,
true
,
false
,
false
,
false
};
SSDataBlock
*
src
=
NULL
;
SScalarParam res = {0};
int32_t
rowNum
=
sizeof
(
v1
)
/
sizeof
(
v1
[
0
]);
scltMakeColumnNode
(
&
pcol1
,
&
src
,
TSDB_DATA_TYPE_SMALLINT
,
sizeof
(
int16_t
),
rowNum
,
v1
);
scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int
16
_t), rowNum, v2);
scltMakeColumnNode
(
&
pcol2
,
&
src
,
TSDB_DATA_TYPE_INT
,
sizeof
(
int
32
_t
),
rowNum
,
v2
);
scltMakeOpNode
(
&
opNode1
,
OP_TYPE_GREATER_THAN
,
TSDB_DATA_TYPE_BOOL
,
pcol1
,
pcol2
);
scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int
16
_t), rowNum, v3);
scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int
16
_t), rowNum, v4);
scltMakeColumnNode
(
&
pcol1
,
&
src
,
TSDB_DATA_TYPE_BIGINT
,
sizeof
(
int
64
_t
),
rowNum
,
v3
);
scltMakeColumnNode
(
&
pcol2
,
&
src
,
TSDB_DATA_TYPE_INT
,
sizeof
(
int
32
_t
),
rowNum
,
v4
);
scltMakeOpNode
(
&
opNode2
,
OP_TYPE_LOWER_THAN
,
TSDB_DATA_TYPE_BOOL
,
pcol1
,
pcol2
);
list
[
0
]
=
opNode1
;
list
[
1
]
=
opNode2
;
scltMakeLogicNode
(
&
logicNode
,
LOGIC_COND_TYPE_AND
,
list
,
2
);
int32_t code = scalarCalculate(logicNode, src, &res);
SArray
*
blockList
=
taosArrayInit
(
1
,
POINTER_BYTES
);
taosArrayPush
(
blockList
,
&
src
);
SColumnInfo
colInfo
=
{.
colId
=
1
,
.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
false
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
logicNode
,
dataBlockId
,
slotId
,
logicNode
);
int32_t
code
=
scalarCalculate
(
logicNode
,
blockList
,
NULL
);
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);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
rowNum
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
ASSERT_EQ
(
column
->
info
.
type
,
TSDB_DATA_TYPE_BOOL
);
ASSERT_EQ
(
column
->
info
.
bytes
,
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
);
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
ASSERT_EQ(*((bool *)
res.data + i
), eRes[i]);
ASSERT_EQ
(
*
((
bool
*
)
colDataGet
(
column
,
i
)
),
eRes
[
i
]);
}
}
#endif
int
main
(
int
argc
,
char
**
argv
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录