Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
12bbecc5
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
12bbecc5
编写于
11月 25, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2220]<fix>: fix the bug in column arithmetic expression.
上级
32138695
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
153 addition
and
18 deletion
+153
-18
src/query/src/qAst.c
src/query/src/qAst.c
+96
-11
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-0
tests/script/general/parser/col_arithmetic_query.sim
tests/script/general/parser/col_arithmetic_query.sim
+56
-7
未找到文件。
src/query/src/qAst.c
浏览文件 @
12bbecc5
...
...
@@ -370,6 +370,66 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
#endif
}
static
void
reverseCopy
(
char
*
dest
,
const
char
*
src
,
int16_t
type
,
int32_t
numOfRows
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
p
=
(
int8_t
*
)
dest
;
int8_t
*
pSrc
=
(
int8_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
p
=
(
int16_t
*
)
dest
;
int16_t
*
pSrc
=
(
int16_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
p
=
(
int32_t
*
)
dest
;
int32_t
*
pSrc
=
(
int32_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
p
=
(
int64_t
*
)
dest
;
int64_t
*
pSrc
=
(
int64_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
dest
;
float
*
pSrc
=
(
float
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
dest
;
double
*
pSrc
=
(
double
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
default:
assert
(
0
);
}
}
void
tExprTreeCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
))
{
if
(
pExprs
==
NULL
)
{
...
...
@@ -387,6 +447,8 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
/* the right output has result from the right child syntax tree */
char
*
pRightOutput
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
char
*
pdata
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
tExprTreeCalcTraverse
(
pRight
,
numOfRows
,
pRightOutput
,
param
,
order
,
getSourceDataBlock
);
}
...
...
@@ -398,52 +460,75 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
* the type of returned value of one expression is always double float precious
*/
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
pLeftOutput
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
fp
(
pLeftOutput
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// exprLeft + columnRight
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
// set input buffer
char
*
pInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
fp
(
pLeftOutput
,
pInputData
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pInputData
,
pRight
->
pSchema
->
type
,
numOfRows
);
fp
(
pLeftOutput
,
pdata
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftOutput
,
pInputData
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// exprLeft + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
pLeftOutput
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
order
);
fp
(
pLeftOutput
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
// column data specified on left-hand-side
char
*
pLeftInputData
=
getSourceDataBlock
(
param
,
pLeft
->
pSchema
->
name
,
pLeft
->
pSchema
->
colId
);
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// columnLeft + expr2
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pLeftInputData
,
pLeft
->
pSchema
->
type
,
numOfRows
);
fp
(
pdata
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftInputData
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// columnLeft + columnRight
// column data specified on right-hand-side
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
pRightInputData
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
// both columns are descending order, do not reverse the source data
fp
(
pLeftInputData
,
pRightInputData
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_DESC
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// columnLeft + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pLeftInputData
,
pLeft
->
pSchema
->
type
,
numOfRows
);
fp
(
pdata
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftInputData
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
}
else
{
// column data specified on left-hand-side
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// 12 + expr2
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightOutput
,
1
,
numOfRows
,
pOutput
,
order
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightOutput
,
1
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// 12 + columnRight
// column data specified on right-hand-side
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightInputData
,
1
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pRightInputData
,
pRight
->
pSchema
->
type
,
numOfRows
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pdata
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightInputData
,
1
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// 12 + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
&
pRight
->
pVal
->
i64Key
,
1
,
1
,
pOutput
,
order
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
&
pRight
->
pVal
->
i64Key
,
1
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
...
...
src/query/src/qExecutor.c
浏览文件 @
12bbecc5
...
...
@@ -1090,6 +1090,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
pCtx
[
k
].
nStartQueryTimestamp
=
pDataBlockInfo
->
window
.
skey
;
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
}
...
...
tests/script/general/parser/col_arithmetic_query.sim
浏览文件 @
12bbecc5
...
...
@@ -62,24 +62,73 @@ if $data91 != 1.000000000 then
return -1
endi
sql select (c1 * 2) % 7.9 from $tb order by ts desc;
sql select (c1 * 2) % 7.9
, c1*1, c1*1*1, c1*c1, c1*c1*c1
from $tb order by ts desc;
if $rows != 10000 then
return -1
endi
if $data00 !=
0.1
00000000 then
print expect
0.100000000, acut
al:$data00
if $data00 !=
2.2
00000000 then
print expect
2.200000000, actu
al:$data00
return -1
endi
if $data
10 != 2.1
00000000 then
if $data
01 != 9.0
00000000 then
return -1
endi
if $data90 != 6.000000000 then
if $data02 != 9.000000000 then
return -1
endi
if $data03 != 81.000000000 then
return -1
endi
if $data04 != 729.000000000 then
return -1
endi
if $data10 != 0.200000000 then
return -1
endi
if $data11 != 8.000000000 then
return -1
endi
if $data12 != 8.000000000 then
return -1
endi
if $data13 != 64.000000000 then
return -1
endi
if $data14 != 512.000000000 then
return -1
endi
if $data90 != 0.000000000 then
return -1
endi
if $data11 != 0.000000000 then
return -1
endi
if $data12 != 0.000000000 then
return -1
endi
if $data13 != 0.000000000 then
return -1
endi
if $data14 != 0.000000000 then
return -1
endi
# [d.3]
sql select c1 * c2 /4 from $tb where ts < 1537166000000 and ts > 1537156000000
if $rows != 17 then
...
...
@@ -586,7 +635,7 @@ if $data00 != @18-09-17 09:00:00.000@ then
return -1
endi
sql select first(c7)- last(c1) from $tb interval(2y)
sql
_error
select first(c7)- last(c1) from $tb interval(2y)
# aggregation query [d.18]===============================================================
# all cases in this part are aggregation query test.
...
...
@@ -595,7 +644,7 @@ sql select first(c7)- last(c1) from $tb interval(2y)
# multiple retrieve [d.20]===============================================================
sql select c2-c2 from $tb
;
sql select c2-c2 from $tb
sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录