Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
43a3f513
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
43a3f513
编写于
12月 01, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2129]
上级
c3c7643f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
277 addition
and
47 deletion
+277
-47
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+49
-47
tests/script/general/parser/function.sim
tests/script/general/parser/function.sim
+228
-0
未找到文件。
src/query/src/qExecutor.c
浏览文件 @
43a3f513
...
...
@@ -1074,12 +1074,12 @@ static bool setTimeWindowInterpolationStartTs(SQueryRuntimeEnv* pRuntimeEnv, int
// start exactly from this point, no need to do interpolation
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
win
->
skey
:
win
->
ekey
;
if
(
key
==
curTs
)
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Cols
,
RESULT_ROW_START_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Output
,
RESULT_ROW_START_INTERP
);
return
true
;
}
if
(
lastTs
==
INT64_MIN
&&
((
pos
==
0
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
pos
==
(
numOfRows
-
1
)
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
))))
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Cols
,
RESULT_ROW_START_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Output
,
RESULT_ROW_START_INTERP
);
return
true
;
}
...
...
@@ -1099,13 +1099,13 @@ static bool setTimeWindowInterpolationEndTs(SQueryRuntimeEnv* pRuntimeEnv, int32
// not ended in current data block, do not invoke interpolation
if
((
key
>
blockEkey
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
key
<
blockEkey
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)))
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Cols
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Output
,
RESULT_ROW_END_INTERP
);
return
false
;
}
// there is actual end point of current time window, no interpolation need
if
(
key
==
actualEndKey
)
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Cols
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOf
Output
,
RESULT_ROW_END_INTERP
);
return
true
;
}
...
...
@@ -1535,6 +1535,43 @@ void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArray* pDa
}
}
static
void
setTimeWindowSKeyInterp
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SArray
*
pDataBlock
,
TSKEY
prevTs
,
int32_t
prevRowIndex
,
TSKEY
ts
,
int32_t
offset
,
SResultRow
*
pResult
,
STimeWindow
*
win
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
done
)
{
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
win
->
skey
:
win
->
ekey
;
if
(
key
==
ts
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
else
if
(
prevTs
!=
INT64_MIN
&&
((
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
prevTs
<
key
)
||
(
!
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
prevTs
>
key
)))
{
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
key
,
RESULT_ROW_START_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
}
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_END_INTERP
);
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
pRuntimeEnv
->
pCtx
[
k
].
size
=
1
;
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
}
}
static
void
setTimeWindowEKeyInterp
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SArray
*
pDataBlock
,
TSKEY
prevTs
,
int32_t
prevRowIndex
,
TSKEY
ts
,
int32_t
offset
,
SResultRow
*
pResult
,
STimeWindow
*
win
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
win
->
ekey
:
win
->
skey
;
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
key
,
RESULT_ROW_END_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
pRuntimeEnv
->
pCtx
[
i
].
size
=
0
;
}
}
static
void
rowwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
SWindowResInfo
*
pWindowResInfo
,
SArray
*
pDataBlock
)
{
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
...
...
@@ -1585,7 +1622,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
int32_t
offset
=
-
1
;
TSKEY
prevTs
=
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
];
TSKEY
prevTs
=
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
];
int32_t
prevRowIndex
=
-
1
;
for
(
int32_t
j
=
0
;
j
<
pDataBlockInfo
->
rows
;
++
j
)
{
...
...
@@ -1609,8 +1646,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
// interval window query, decide the time window according to the primary timestamp
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
int32_t
prevWindowIndex
=
curTimeWindowIndex
(
pWindowResInfo
);
int64_t
ts
=
tsCols
[
offset
];
int64_t
ts
=
tsCols
[
offset
];
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
bool
hasTimeWindow
=
false
;
...
...
@@ -1631,21 +1668,14 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
if
(
prevWindowIndex
!=
-
1
&&
prevWindowIndex
<
curIndex
)
{
for
(
int32_t
k
=
prevWindowIndex
;
k
<
curIndex
;
++
k
)
{
SResultRow
*
pRes
=
pWindowResInfo
->
pResult
[
k
];
STimeWindow
w
=
pRes
->
win
;
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
w
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
pRes
->
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
assert
(
ret
==
TSDB_CODE_SUCCESS
&&
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
w
.
ekey
:
w
.
skey
;
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
key
,
RESULT_ROW_END_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_START_INTERP
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
pRuntimeEnv
->
pCtx
[
i
].
size
=
0
;
}
setTimeWindowEKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
pRes
->
win
);
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
w
,
offset
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
pRes
->
win
,
offset
);
}
// restore current time window
...
...
@@ -1656,23 +1686,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
}
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
done
)
{
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
win
.
skey
:
win
.
ekey
;
if
(
prevTs
!=
INT64_MIN
&&
ts
!=
key
)
{
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
key
,
RESULT_ROW_START_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_START_INTERP
);
}
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_END_INTERP
);
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
pRuntimeEnv
->
pCtx
[
k
].
size
=
1
;
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_START_INTERP
);
}
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
win
);
}
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
...
...
@@ -1699,19 +1713,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
if
(
hasTimeWindow
)
{
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
done
)
{
if
(
prevTs
!=
INT64_MIN
&&
((
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
(
prevTs
<
nextWin
.
skey
))
||
(
!
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
prevTs
>
nextWin
.
ekey
)))
{
TSKEY
key
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
nextWin
.
skey
:
nextWin
.
ekey
;
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
key
,
RESULT_ROW_START_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_START_INTERP
);
}
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfCols
,
RESULT_ROW_END_INTERP
);
}
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
nextWin
);
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
offset
);
}
...
...
tests/script/general/parser/function.sim
0 → 100644
浏览文件 @
43a3f513
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/cfg.sh -n dnode1 -c tableMetaKeepTimer -v 3
system sh/exec.sh -n dnode1 -s start
sleep 500
sql connect
$dbPrefix = m_func_db
$tbPrefix = m_func_tb
$mtPrefix = m_func_mt
$tbNum = 10
$rowNum = 5
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== alter.sim
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database if exists $db
sql create database $db
sql use $db
print =====================================> test case for twa in single block
sql create table t1 (ts timestamp, k float);
sql insert into t1 values('2015-08-18 00:00:00', 2.064);
sql insert into t1 values('2015-08-18 00:06:00', 2.116);
sql insert into t1 values('2015-08-18 00:12:00', 2.028);
sql insert into t1 values('2015-08-18 00:18:00', 2.126);
sql insert into t1 values('2015-08-18 00:24:00', 2.041);
sql insert into t1 values('2015-08-18 00:30:00', 2.051);
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:05:00'
if $rows != 1 then
return -1
endi
if $data00 != 2.063999891 then
return -1
endi
if $data01 != 2.063999891 then
return -1
endi
if $data02 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00'
if $rows != 1 then
return -1
endi
if $data00 != 2.089999914 then
return -1
endi
if $data01 != 2.089999914 then
return -1
endi
if $data02 != 2 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts asc
if $rows != 2 then
return -1
endi
if $data00 != @15-08-18 00:00:00.000@ then
return -1
endi
if $data01 != 2.068333156 then
return -1
endi
if $data02 != 2.063999891 then
return -1
endi
if $data03 != 1 then
return -1
endi
if $data10 != @15-08-18 00:06:00.000@ then
return -1
endi
if $data11 != 2.115999937 then
return -1
endi
if $data12 != 2.115999937 then
return -1
endi
if $data13 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts desc;
if $rows != 2 then
return -1
endi
if $data00 != @15-08-18 00:06:00.00@ then
return -1
endi
if $data01 != 2.115999937 then
return -1
endi
if $data02 != 2.115999937 then
return -1
endi
if $data03 != 1 then
return -1
endi
if $data11 != 2.068333156 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts asc
if $rows != 3 then
return -1
endi
if $data01 != 2.088666666 then
return -1
endi
if $data02 != 2.089999914 then
return -1
endi
if $data03 != 2 then
return -1
endi
if $data11 != 2.077099980 then
return -1
endi
if $data12 != 2.077000022 then
return -1
endi
if $data13 != 2 then
return -1
endi
if $data21 != 2.069333235 then
return -1
endi
if $data22 != 2.040999889 then
return -1
endi
if $data23 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts desc
if $rows != 3 then
return -1
endi
if $data01 != 2.069333235 then
return -1
endi
if $data11 != 2.077099980 then
return -1
endi
if $data21 != 2.088666666 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' order by ts asc
if $data00 != 2.073699975 then
return -1
endi
if $data01 != 2.070999980 then
return -1
endi
if $data02 != 6 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' order by ts desc
if $rows != 1 then
return -1
endi
if $data00 != 2.073699975 then
return -1
endi
if $data01 != 2.070999980 then
return -1
endi
if $data02 != 6 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts asc
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts desc
#todo add test case while column filte exists.
select count(*),TWA(k) from tm0 where ts>='1970-1-1 13:43:00' and ts<='1970-1-1 13:44:10' interval(9s)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录