Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c3d702fe
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
c3d702fe
编写于
7月 10, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor.
上级
4a9e1e37
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
91 deletion
+45
-91
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-1
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+1
-1
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+43
-89
未找到文件。
source/libs/executor/inc/executorimpl.h
浏览文件 @
c3d702fe
...
...
@@ -902,7 +902,7 @@ int32_t aggDecodeResultRow(SOperatorInfo* pOperator, char* result);
int32_t
aggEncodeResultRow
(
SOperatorInfo
*
pOperator
,
char
**
result
,
int32_t
*
length
);
STimeWindow
getActiveTimeWindow
(
SDiskbasedBuf
*
pBuf
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
SInterval
*
pInterval
,
int32_t
precision
,
int32_t
order
);
int32_t
order
);
int32_t
getNumOfRowsInTimeWindow
(
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
int32_t
startPos
,
TSKEY
ekey
,
__block_search_fn_t
searchFn
,
STableQueryInfo
*
item
,
int32_t
order
);
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
c3d702fe
...
...
@@ -938,7 +938,7 @@ static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t t
setGroupId
(
pInfo
,
pSDB
,
GROUPID_COLUMN_INDEX
,
*
pRowIndex
);
(
*
pRowIndex
)
+=
updateSessionWindowInfo
(
pCurWin
,
tsCols
,
NULL
,
pSDB
->
info
.
rows
,
*
pRowIndex
,
gap
,
NULL
);
}
else
{
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
*
pRowIndex
],
&
pInfo
->
interval
,
pInfo
->
interval
.
precision
,
TSDB_ORDER_ASC
);
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
*
pRowIndex
],
&
pInfo
->
interval
,
TSDB_ORDER_ASC
);
setGroupId
(
pInfo
,
pSDB
,
GROUPID_COLUMN_INDEX
,
*
pRowIndex
);
(
*
pRowIndex
)
+=
getNumOfRowsInTimeWindow
(
&
pSDB
->
info
,
tsCols
,
*
pRowIndex
,
win
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
c3d702fe
...
...
@@ -93,99 +93,55 @@ static STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow,
return
save
;
}
static
STimeWindow
doCalculateTimeWindow
(
int64_t
ts
,
SInterval
*
pInterval
)
{
STimeWindow
w
=
{
0
};
if
(
pInterval
->
intervalUnit
==
'n'
||
pInterval
->
intervalUnit
==
'y'
)
{
w
.
skey
=
taosTimeTruncate
(
ts
,
pInterval
,
pInterval
->
precision
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
pInterval
->
precision
)
-
1
;
}
else
{
int64_t
st
=
w
.
skey
;
if
(
st
>
ts
)
{
st
-=
((
st
-
ts
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
int64_t
et
=
st
+
pInterval
->
interval
-
1
;
if
(
et
<
ts
)
{
st
+=
((
ts
-
et
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
w
.
skey
=
st
;
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
pInterval
->
precision
)
-
1
;
}
return
w
;
}
// todo do refactor
// get the correct time window according to the handled timestamp
STimeWindow
getActiveTimeWindow
(
SDiskbasedBuf
*
pBuf
,
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
SInterval
*
pInterval
,
int32_t
precision
,
int32_t
order
)
{
int32_t
order
)
{
STimeWindow
w
=
{
0
};
if
(
pResultRowInfo
->
cur
.
pageId
==
-
1
)
{
// the first window, from the previous stored value
getInitialStartTimeWindow
(
pInterval
,
p
recision
,
ts
,
&
w
,
true
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
getInitialStartTimeWindow
(
pInterval
,
p
Interval
->
precision
,
ts
,
&
w
,
(
order
==
TSDB_ORDER_ASC
)
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
p
Interval
->
p
recision
)
-
1
;
return
w
;
}
w
=
getResultRowByPos
(
pBuf
,
&
pResultRowInfo
->
cur
)
->
win
;
if
(
pInterval
->
interval
==
pInterval
->
sliding
)
{
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
if
(
pInterval
->
intervalUnit
==
'n'
||
pInterval
->
intervalUnit
==
'y'
)
{
w
.
skey
=
taosTimeTruncate
(
ts
,
pInterval
,
precision
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
}
else
{
int64_t
st
=
w
.
skey
;
if
(
st
>
ts
)
{
st
-=
((
st
-
ts
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
int64_t
et
=
st
+
pInterval
->
interval
-
1
;
if
(
et
<
ts
)
{
st
+=
((
ts
-
et
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
w
.
skey
=
st
;
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
}
}
}
else
{
// it is an sliding window query, in which sliding value is not equalled to
// interval value, and we need to find the first qualified time window for asc/desc traverse respectively.
if
(
order
==
TSDB_ORDER_ASC
)
{
if
(
w
.
skey
<=
ts
&&
w
.
ekey
>=
ts
)
{
// ts is resident in current time window, but we need to find the first
//qualified time window that cover this timestamp
w
=
getFirstQualifiedTimeWindow
(
ts
,
&
w
,
pInterval
,
order
);
}
else
{
// todo refactor:
if
(
pInterval
->
intervalUnit
==
'n'
||
pInterval
->
intervalUnit
==
'y'
)
{
w
.
skey
=
taosTimeTruncate
(
ts
,
pInterval
,
precision
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
}
else
{
int64_t
st
=
w
.
skey
;
if
(
st
>
ts
)
{
st
-=
((
st
-
ts
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
int64_t
et
=
st
+
pInterval
->
interval
-
1
;
if
(
et
<
ts
)
{
st
+=
((
ts
-
et
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
w
.
skey
=
st
;
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
w
=
getFirstQualifiedTimeWindow
(
ts
,
&
w
,
pInterval
,
order
);
}
}
}
else
{
if
(
w
.
skey
<=
ts
&&
w
.
ekey
>=
ts
)
{
w
=
getFirstQualifiedTimeWindow
(
ts
,
&
w
,
pInterval
,
order
);
}
else
{
// todo refactor:
if
(
pInterval
->
intervalUnit
==
'n'
||
pInterval
->
intervalUnit
==
'y'
)
{
w
.
skey
=
taosTimeTruncate
(
ts
,
pInterval
,
precision
);
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
}
else
{
int64_t
st
=
w
.
skey
;
if
(
st
>
ts
)
{
st
-=
((
st
-
ts
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
int64_t
et
=
st
+
pInterval
->
interval
-
1
;
if
(
et
<
ts
)
{
st
+=
((
ts
-
et
+
pInterval
->
sliding
-
1
)
/
pInterval
->
sliding
)
*
pInterval
->
sliding
;
}
w
.
skey
=
st
;
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
)
-
1
;
// in case of typical time window, we can calculate time window directly.
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
w
=
doCalculateTimeWindow
(
ts
,
pInterval
);
}
w
=
getFirstQualifiedTimeWindow
(
ts
,
&
w
,
pInterval
,
order
);
}
}
}
if
(
pInterval
->
interval
!=
pInterval
->
sliding
)
{
// it is an sliding window query, in which sliding value is not equalled to
// interval value, and we need to find the first qualified time window.
w
=
getFirstQualifiedTimeWindow
(
ts
,
&
w
,
pInterval
,
order
);
}
return
w
;
}
...
...
@@ -930,8 +886,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
TSKEY
ts
=
getStartTsKey
(
&
pBlock
->
info
.
window
,
tsCols
);
SResultRow
*
pResult
=
NULL
;
STimeWindow
win
=
getActiveTimeWindow
(
pInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
ts
,
&
pInfo
->
interval
,
pInfo
->
interval
.
precision
,
pInfo
->
order
);
STimeWindow
win
=
getActiveTimeWindow
(
pInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
ts
,
&
pInfo
->
interval
,
pInfo
->
order
);
int32_t
ret
=
TSDB_CODE_SUCCESS
;
if
(
!
pInfo
->
ignoreExpiredData
||
!
isCloseWindow
(
&
win
,
&
pInfo
->
twAggSup
))
{
ret
=
setTimeWindowOutputBuf
(
pResultRowInfo
,
&
win
,
(
scanFlag
==
MAIN_SCAN
),
&
pResult
,
tableGroupId
,
pSup
->
pCtx
,
...
...
@@ -1390,7 +1345,7 @@ void doDeleteSpecifyIntervalWindow(SAggSupporter* pAggSup, SSDataBlock* pBlock,
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
rows
;
i
++
)
{
SResultRowInfo
dumyInfo
;
dumyInfo
.
cur
.
pageId
=
-
1
;
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsStarts
[
i
],
pInterval
,
pInterval
->
precision
,
TSDB_ORDER_ASC
);
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsStarts
[
i
],
pInterval
,
TSDB_ORDER_ASC
);
doDeleteIntervalWindow
(
pAggSup
,
win
.
skey
,
groupIds
[
i
]);
if
(
pUpWins
)
{
SWinRes
winRes
=
{.
ts
=
win
.
skey
,
.
groupId
=
groupIds
[
i
]};
...
...
@@ -1412,7 +1367,7 @@ static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval*
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
rows
;
i
+=
step
)
{
SResultRowInfo
dumyInfo
;
dumyInfo
.
cur
.
pageId
=
-
1
;
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
i
],
pInterval
,
pInterval
->
precision
,
TSDB_ORDER_ASC
);
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
i
],
pInterval
,
TSDB_ORDER_ASC
);
step
=
getNumOfRowsInTimeWindow
(
&
pBlock
->
info
,
tsCols
,
i
,
win
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
uint64_t
winGpId
=
pGpDatas
?
pGpDatas
[
i
]
:
pBlock
->
info
.
groupId
;
bool
res
=
doClearWindow
(
pAggSup
,
pSup1
,
(
char
*
)
&
win
.
skey
,
sizeof
(
TKEY
),
winGpId
,
numOfOutput
);
...
...
@@ -1452,7 +1407,7 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup,
TSKEY
ts
=
*
(
int64_t
*
)((
char
*
)
key
+
sizeof
(
uint64_t
));
SResultRowInfo
dumyInfo
;
dumyInfo
.
cur
.
pageId
=
-
1
;
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
ts
,
pInterval
,
pInterval
->
precision
,
TSDB_ORDER_ASC
);
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
ts
,
pInterval
,
TSDB_ORDER_ASC
);
SWinRes
winRe
=
{
.
ts
=
win
.
skey
,
.
groupId
=
groupId
,
...
...
@@ -2547,8 +2502,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
int32_t
startPos
=
ascScan
?
0
:
(
pSDataBlock
->
info
.
rows
-
1
);
TSKEY
ts
=
getStartTsKey
(
&
pSDataBlock
->
info
.
window
,
tsCols
);
STimeWindow
nextWin
=
getActiveTimeWindow
(
pInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
ts
,
&
pInfo
->
interval
,
pInfo
->
interval
.
precision
,
pInfo
->
order
);
STimeWindow
nextWin
=
getActiveTimeWindow
(
pInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
ts
,
&
pInfo
->
interval
,
pInfo
->
order
);
while
(
1
)
{
bool
isClosed
=
isCloseWindow
(
&
nextWin
,
&
pInfo
->
twAggSup
);
if
(
pInfo
->
ignoreExpiredData
&&
isClosed
)
{
...
...
@@ -4751,7 +4705,7 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo*
SResultRow
*
pResult
=
NULL
;
STimeWindow
win
=
getActiveTimeWindow
(
iaInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
blockStartTs
,
&
iaInfo
->
interval
,
iaInfo
->
interval
.
precision
,
iaInfo
->
order
);
iaInfo
->
order
);
int32_t
ret
=
setTimeWindowOutputBuf
(
pResultRowInfo
,
&
win
,
(
scanFlag
==
MAIN_SCAN
),
&
pResult
,
tableGroupId
,
pExprSup
->
pCtx
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录