Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
29327a6d
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
29327a6d
编写于
4月 16, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): support now()/today() arithmetic operation with time duration
TD-14243
上级
e655a3cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
136 addition
and
34 deletion
+136
-34
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+12
-2
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+124
-32
未找到文件。
source/libs/parser/src/parTranslater.c
浏览文件 @
29327a6d
...
...
@@ -466,8 +466,18 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
TSDB_DATA_TYPE_BLOB
==
rdt
.
type
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_DOUBLE
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
if
(
TSDB_DATA_TYPE_TIMESTAMP
==
ldt
.
type
&&
TSDB_DATA_TYPE_TIMESTAMP
==
rdt
.
type
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
if
((
TSDB_DATA_TYPE_TIMESTAMP
==
ldt
.
type
&&
TSDB_DATA_TYPE_BIGINT
==
rdt
.
type
)
||
(
TSDB_DATA_TYPE_TIMESTAMP
==
rdt
.
type
&&
TSDB_DATA_TYPE_BIGINT
==
ldt
.
type
))
{
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
;
}
else
{
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_DOUBLE
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
}
}
else
if
(
nodesIsComparisonOp
(
pOp
))
{
if
(
TSDB_DATA_TYPE_JSON
==
ldt
.
type
||
TSDB_DATA_TYPE_BLOB
==
ldt
.
type
||
TSDB_DATA_TYPE_JSON
==
rdt
.
type
||
TSDB_DATA_TYPE_BLOB
==
rdt
.
type
)
{
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
29327a6d
...
...
@@ -79,6 +79,8 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
p
=
getVectorBigintValue_FLOAT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_DOUBLE
)
{
p
=
getVectorBigintValue_DOUBLE
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
p
=
getVectorBigintValue_BIGINT
;
}
else
{
assert
(
0
);
}
...
...
@@ -565,6 +567,25 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
}
}
static
void
vectorMathBigintAddHelper
(
SColumnInfoData
*
pLeftCol
,
SColumnInfoData
*
pRightCol
,
SColumnInfoData
*
pOutputCol
,
int32_t
numOfRows
,
int32_t
step
,
int32_t
i
)
{
_getBigintValue_fn_t
getVectorBigintValueFnLeft
=
getVectorBigintValueFn
(
pLeftCol
->
info
.
type
);
_getBigintValue_fn_t
getVectorBigintValueFnRight
=
getVectorBigintValueFn
(
pRightCol
->
info
.
type
);
int64_t
*
output
=
(
int64_t
*
)
pOutputCol
->
pData
;
if
(
colDataIsNull_f
(
pRightCol
->
nullbitmap
,
0
))
{
// Set pLeft->numOfRows NULL value
colDataAppendNNULL
(
pOutputCol
,
0
,
numOfRows
);
}
else
{
for
(;
i
>=
0
&&
i
<
numOfRows
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorBigintValueFnLeft
(
pLeftCol
->
pData
,
i
)
+
getVectorBigintValueFnRight
(
pRightCol
->
pData
,
0
);
}
pOutputCol
->
hasNull
=
pLeftCol
->
hasNull
;
if
(
pOutputCol
->
hasNull
)
{
memcpy
(
pOutputCol
->
nullbitmap
,
pLeftCol
->
nullbitmap
,
BitmapLen
(
numOfRows
));
}
}
}
static
SColumnInfoData
*
doVectorConvert
(
SScalarParam
*
pInput
,
int32_t
*
doConvert
)
{
SScalarParam
convertParam
=
{
0
};
...
...
@@ -599,27 +620,53 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
SColumnInfoData
*
pLeftCol
=
doVectorConvert
(
pLeft
,
&
leftConvert
);
SColumnInfoData
*
pRightCol
=
doVectorConvert
(
pRight
,
&
rightConvert
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeftCol
->
info
.
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRightCol
->
info
.
type
);
if
((
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_BIGINT
)
||
(
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_BIGINT
))
{
//timestamp plus duration
int64_t
*
output
=
(
int64_t
*
)
pOutputCol
->
pData
;
_getBigintValue_fn_t
getVectorBigintValueFnLeft
=
getVectorBigintValueFn
(
pLeftCol
->
info
.
type
);
_getBigintValue_fn_t
getVectorBigintValueFnRight
=
getVectorBigintValueFn
(
pRightCol
->
info
.
type
);
double
*
output
=
(
double
*
)
pOutputCol
->
pData
;
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorDoubleValueFnLeft
(
pLeftCol
->
pData
,
i
)
+
getVectorDoubleValueFnRight
(
pRightCol
->
pData
,
i
);
}
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorBigintValueFnLeft
(
pLeftCol
->
pData
,
i
)
+
getVectorBigintValueFnRight
(
pRightCol
->
pData
,
i
);
}
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
}
}
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathBigintAddHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathBigintAddHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
i
);
}
}
else
{
double
*
output
=
(
double
*
)
pOutputCol
->
pData
;
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeftCol
->
info
.
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRightCol
->
info
.
type
);
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathAddHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathAddHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
i
);
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorDoubleValueFnLeft
(
pLeftCol
->
pData
,
i
)
+
getVectorDoubleValueFnRight
(
pRightCol
->
pData
,
i
);
}
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
}
}
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathAddHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathAddHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
i
);
}
}
doReleaseVec
(
pLeftCol
,
leftConvert
);
...
...
@@ -646,6 +693,25 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
}
}
static
void
vectorMathBigintSubHelper
(
SColumnInfoData
*
pLeftCol
,
SColumnInfoData
*
pRightCol
,
SColumnInfoData
*
pOutputCol
,
int32_t
numOfRows
,
int32_t
step
,
int32_t
factor
,
int32_t
i
)
{
_getBigintValue_fn_t
getVectorBigintValueFnLeft
=
getVectorBigintValueFn
(
pLeftCol
->
info
.
type
);
_getBigintValue_fn_t
getVectorBigintValueFnRight
=
getVectorBigintValueFn
(
pRightCol
->
info
.
type
);
int64_t
*
output
=
(
int64_t
*
)
pOutputCol
->
pData
;
if
(
colDataIsNull_f
(
pRightCol
->
nullbitmap
,
0
))
{
// Set pLeft->numOfRows NULL value
colDataAppendNNULL
(
pOutputCol
,
0
,
numOfRows
);
}
else
{
for
(;
i
>=
0
&&
i
<
numOfRows
;
i
+=
step
,
output
+=
1
)
{
*
output
=
(
getVectorBigintValueFnLeft
(
pLeftCol
->
pData
,
i
)
-
getVectorBigintValueFnRight
(
pRightCol
->
pData
,
0
))
*
factor
;
}
pOutputCol
->
hasNull
=
pLeftCol
->
hasNull
;
if
(
pOutputCol
->
hasNull
)
{
memcpy
(
pOutputCol
->
nullbitmap
,
pLeftCol
->
nullbitmap
,
BitmapLen
(
numOfRows
));
}
}
}
void
vectorMathSub
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
SColumnInfoData
*
pOutputCol
=
pOut
->
columnData
;
...
...
@@ -658,27 +724,53 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
SColumnInfoData
*
pLeftCol
=
doVectorConvert
(
pLeft
,
&
leftConvert
);
SColumnInfoData
*
pRightCol
=
doVectorConvert
(
pRight
,
&
rightConvert
);
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeftCol
->
info
.
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRightCol
->
info
.
type
);
if
((
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_BIGINT
)
||
(
GET_PARAM_TYPE
(
pRight
)
==
TSDB_DATA_TYPE_TIMESTAMP
&&
GET_PARAM_TYPE
(
pLeft
)
==
TSDB_DATA_TYPE_BIGINT
))
{
//timestamp minus duration
int64_t
*
output
=
(
int64_t
*
)
pOutputCol
->
pData
;
_getBigintValue_fn_t
getVectorBigintValueFnLeft
=
getVectorBigintValueFn
(
pLeftCol
->
info
.
type
);
_getBigintValue_fn_t
getVectorBigintValueFnRight
=
getVectorBigintValueFn
(
pRightCol
->
info
.
type
);
double
*
output
=
(
double
*
)
pOutputCol
->
pData
;
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorDoubleValueFnLeft
(
pLeftCol
->
pData
,
i
)
-
getVectorDoubleValueFnRight
(
pRightCol
->
pData
,
i
);
}
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorBigintValueFnLeft
(
pLeftCol
->
pData
,
i
)
-
getVectorBigintValueFnRight
(
pRightCol
->
pData
,
i
);
}
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
}
}
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathBigintSubHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
-
1
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathBigintSubHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
1
,
i
);
}
}
else
{
double
*
output
=
(
double
*
)
pOutputCol
->
pData
;
_getDoubleValue_fn_t
getVectorDoubleValueFnLeft
=
getVectorDoubleValueFn
(
pLeftCol
->
info
.
type
);
_getDoubleValue_fn_t
getVectorDoubleValueFnRight
=
getVectorDoubleValueFn
(
pRightCol
->
info
.
type
);
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathSubHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
-
1
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathSubHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
1
,
i
);
if
(
pLeft
->
numOfRows
==
pRight
->
numOfRows
)
{
for
(;
i
<
pRight
->
numOfRows
&&
i
>=
0
;
i
+=
step
,
output
+=
1
)
{
*
output
=
getVectorDoubleValueFnLeft
(
pLeftCol
->
pData
,
i
)
-
getVectorDoubleValueFnRight
(
pRightCol
->
pData
,
i
);
}
pOutputCol
->
hasNull
=
(
pLeftCol
->
hasNull
||
pRightCol
->
hasNull
);
if
(
pOutputCol
->
hasNull
)
{
int32_t
numOfBitLen
=
BitmapLen
(
pLeft
->
numOfRows
);
for
(
int32_t
j
=
0
;
j
<
numOfBitLen
;
++
j
)
{
pOutputCol
->
nullbitmap
[
j
]
=
pLeftCol
->
nullbitmap
[
j
]
|
pRightCol
->
nullbitmap
[
j
];
}
}
}
else
if
(
pLeft
->
numOfRows
==
1
)
{
vectorMathSubHelper
(
pRightCol
,
pLeftCol
,
pOutputCol
,
pRight
->
numOfRows
,
step
,
-
1
,
i
);
}
else
if
(
pRight
->
numOfRows
==
1
)
{
vectorMathSubHelper
(
pLeftCol
,
pRightCol
,
pOutputCol
,
pLeft
->
numOfRows
,
step
,
1
,
i
);
}
}
doReleaseVec
(
pLeftCol
,
leftConvert
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录