Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6aef8613
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
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看板
未验证
提交
6aef8613
编写于
8月 27, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
8月 27, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16453 from taosdata/szhou/fixbugs
fix: interval operator interpolation for different partition
上级
8c69f698
a574ef5c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
26 deletion
+65
-26
include/libs/function/taosudf.h
include/libs/function/taosudf.h
+3
-2
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+2
-2
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+41
-21
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+19
-1
未找到文件。
include/libs/function/taosudf.h
浏览文件 @
6aef8613
...
...
@@ -256,8 +256,9 @@ static FORCE_INLINE int32_t udfColDataSet(SUdfColumn* pColumn, uint32_t currentR
typedef
int32_t
(
*
TUdfScalarProcFunc
)(
SUdfDataBlock
*
block
,
SUdfColumn
*
resultCol
);
typedef
int32_t
(
*
TUdfAggStartFunc
)(
SUdfInterBuf
*
buf
);
typedef
int32_t
(
*
TUdfAggProcessFunc
)(
SUdfDataBlock
*
block
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
newInterBuf
);
typedef
int32_t
(
*
TUdfAggFinishFunc
)(
SUdfInterBuf
*
buf
,
SUdfInterBuf
*
resultData
);
typedef
int32_t
(
*
TUdfAggProcessFunc
)(
SUdfDataBlock
*
block
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
newInterBuf
);
typedef
int32_t
(
*
TUdfAggMergeFunc
)(
SUdfInterBuf
*
inputBuf1
,
SUdfInterBuf
*
inputBuf2
,
SUdfInterBuf
*
outputBuf
);
typedef
int32_t
(
*
TUdfAggFinishFunc
)(
SUdfInterBuf
*
buf
,
SUdfInterBuf
*
resultData
);
#ifdef __cplusplus
}
...
...
source/common/src/tdatablock.c
浏览文件 @
6aef8613
...
...
@@ -1706,8 +1706,8 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
}
void
blockDebugShowDataBlock
(
SSDataBlock
*
pBlock
,
const
char
*
flag
)
{
SArray
*
dataBlocks
=
taosArrayInit
(
1
,
sizeof
(
SSDataBlock
));
taosArrayPush
(
dataBlocks
,
pBlock
);
SArray
*
dataBlocks
=
taosArrayInit
(
1
,
sizeof
(
SSDataBlock
*
));
taosArrayPush
(
dataBlocks
,
&
pBlock
);
blockDebugShowDataBlocks
(
dataBlocks
,
flag
);
taosArrayDestroy
(
dataBlocks
);
}
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
6aef8613
...
...
@@ -33,11 +33,16 @@ typedef struct SPullWindowInfo {
uint64_t
groupId
;
}
SPullWindowInfo
;
typedef
struct
SOpenWindowInfo
{
SResultRowPosition
pos
;
uint64_t
groupId
;
}
SOpenWindowInfo
;
static
SSDataBlock
*
doStreamSessionAgg
(
SOperatorInfo
*
pOperator
);
static
int64_t
*
extractTsCol
(
SSDataBlock
*
pBlock
,
const
SIntervalAggOperatorInfo
*
pInfo
);
static
SResultRowPosition
addToOpenWindowList
(
SResultRowInfo
*
pResultRowInfo
,
const
SResultRow
*
pResult
);
static
SResultRowPosition
addToOpenWindowList
(
SResultRowInfo
*
pResultRowInfo
,
const
SResultRow
*
pResult
,
uint64_t
groupId
);
static
void
doCloseWindow
(
SResultRowInfo
*
pResultRowInfo
,
const
SIntervalAggOperatorInfo
*
pInfo
,
SResultRow
*
pResult
);
///*
...
...
@@ -598,14 +603,14 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
int32_t
startPos
=
0
;
int32_t
numOfOutput
=
pSup
->
numOfExprs
;
uint64_t
groupId
=
pBlock
->
info
.
groupId
;
SResultRow
*
pResult
=
NULL
;
while
(
1
)
{
SListNode
*
pn
=
tdListGetHead
(
pResultRowInfo
->
openWindow
);
SResultRowPosition
*
p1
=
(
SResultRowPosition
*
)
pn
->
data
;
SOpenWindowInfo
*
pOpenWin
=
(
SOpenWindowInfo
*
)
pn
->
data
;
uint64_t
groupId
=
pOpenWin
->
groupId
;
SResultRowPosition
*
p1
=
&
pOpenWin
->
pos
;
if
(
p
->
pageId
==
p1
->
pageId
&&
p
->
offset
==
p1
->
offset
)
{
break
;
}
...
...
@@ -631,12 +636,15 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
SGroupKeys
*
pTsKey
=
taosArrayGet
(
pInfo
->
pPrevValues
,
0
);
int64_t
prevTs
=
*
(
int64_t
*
)
pTsKey
->
pData
;
doTimeWindowInterpolation
(
pInfo
->
pPrevValues
,
pBlock
->
pDataBlock
,
prevTs
,
-
1
,
tsCols
[
startPos
],
startPos
,
w
.
ekey
,
RESULT_ROW_END_INTERP
,
pSup
);
if
(
groupId
==
pBlock
->
info
.
groupId
)
{
doTimeWindowInterpolation
(
pInfo
->
pPrevValues
,
pBlock
->
pDataBlock
,
prevTs
,
-
1
,
tsCols
[
startPos
],
startPos
,
w
.
ekey
,
RESULT_ROW_END_INTERP
,
pSup
);
}
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pSup
->
pCtx
,
numOfExprs
,
RESULT_ROW_START_INTERP
);
updateTimeWindowInfo
(
&
pInfo
->
twAggSup
.
timeWindowData
,
&
w
,
true
);
doApplyFunctions
(
pTaskInfo
,
pSup
->
pCtx
,
&
pInfo
->
twAggSup
.
timeWindowData
,
startPos
,
0
,
pBlock
->
info
.
rows
,
numOfExprs
);
...
...
@@ -965,7 +973,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
// prev time window not interpolation yet.
if
(
pInfo
->
timeWindowInterpo
)
{
SResultRowPosition
pos
=
addToOpenWindowList
(
pResultRowInfo
,
pResult
);
SResultRowPosition
pos
=
addToOpenWindowList
(
pResultRowInfo
,
pResult
,
tableGroupId
);
doInterpUnclosedTimeWindow
(
pOperatorInfo
,
numOfOutput
,
pResultRowInfo
,
pBlock
,
scanFlag
,
tsCols
,
&
pos
);
// restore current time window
...
...
@@ -1017,10 +1025,18 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
ekey
=
ascScan
?
nextWin
.
ekey
:
nextWin
.
skey
;
forwardRows
=
getNumOfRowsInTimeWindow
(
&
pBlock
->
info
,
tsCols
,
startPos
,
ekey
,
binarySearchForKey
,
NULL
,
pInfo
->
inputOrder
);
// window start(end) key interpolation
doWindowBorderInterpolation
(
pInfo
,
pBlock
,
pResult
,
&
nextWin
,
startPos
,
forwardRows
,
pSup
);
//TODO: add to open window? how to close the open windows after input blocks exhausted?
#if 0
if ((ascScan && ekey <= pBlock->info.window.ekey) ||
(!ascScan && ekey >= pBlock->info.window.skey)) {
// window start(end) key interpolation
doWindowBorderInterpolation(pInfo, pBlock, pResult, &nextWin, startPos, forwardRows, pSup);
} else if (pInfo->timeWindowInterpo) {
addToOpenWindowList(pResultRowInfo, pResult, tableGroupId);
}
#endif
updateTimeWindowInfo
(
&
pInfo
->
twAggSup
.
timeWindowData
,
&
nextWin
,
true
);
doApplyFunctions
(
pTaskInfo
,
pSup
->
pCtx
,
&
pInfo
->
twAggSup
.
timeWindowData
,
startPos
,
forwardRows
,
pBlock
->
info
.
rows
,
numOfOutput
);
...
...
@@ -1040,20 +1056,23 @@ void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOperatorInf
}
}
SResultRowPosition
addToOpenWindowList
(
SResultRowInfo
*
pResultRowInfo
,
const
SResultRow
*
pResult
)
{
SResultRowPosition
pos
=
(
SResultRowPosition
){.
pageId
=
pResult
->
pageId
,
.
offset
=
pResult
->
offset
};
SResultRowPosition
addToOpenWindowList
(
SResultRowInfo
*
pResultRowInfo
,
const
SResultRow
*
pResult
,
uint64_t
groupId
)
{
SOpenWindowInfo
openWin
=
{
0
};
openWin
.
pos
.
pageId
=
pResult
->
pageId
;
openWin
.
pos
.
offset
=
pResult
->
offset
;
openWin
.
groupId
=
groupId
;
SListNode
*
pn
=
tdListGetTail
(
pResultRowInfo
->
openWindow
);
if
(
pn
==
NULL
)
{
tdListAppend
(
pResultRowInfo
->
openWindow
,
&
pos
);
return
pos
;
tdListAppend
(
pResultRowInfo
->
openWindow
,
&
openWin
);
return
openWin
.
pos
;
}
S
ResultRowPosition
*
px
=
(
SResultRowPosition
*
)
pn
->
data
;
if
(
px
->
p
ageId
!=
pos
.
pageId
||
px
->
offset
!=
pos
.
offset
)
{
tdListAppend
(
pResultRowInfo
->
openWindow
,
&
pos
);
S
OpenWindowInfo
*
px
=
(
SOpenWindowInfo
*
)
pn
->
data
;
if
(
px
->
p
os
.
pageId
!=
openWin
.
pos
.
pageId
||
px
->
pos
.
offset
!=
openWin
.
pos
.
offset
||
px
->
groupId
!=
openWin
.
groupId
)
{
tdListAppend
(
pResultRowInfo
->
openWindow
,
&
openWin
);
}
return
pos
;
return
openWin
.
pos
;
}
int64_t
*
extractTsCol
(
SSDataBlock
*
pBlock
,
const
SIntervalAggOperatorInfo
*
pInfo
)
{
...
...
@@ -1884,7 +1903,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
pInfo
->
timeWindowInterpo
=
timeWindowinterpNeeded
(
pSup
->
pCtx
,
numOfCols
,
pInfo
);
if
(
pInfo
->
timeWindowInterpo
)
{
pInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
ResultRowPosition
));
pInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
OpenWindowInfo
));
if
(
pInfo
->
binfo
.
resultRowInfo
.
openWindow
==
NULL
)
{
goto
_error
;
}
...
...
@@ -5157,7 +5176,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream,
iaInfo
->
timeWindowInterpo
=
timeWindowinterpNeeded
(
pSup
->
pCtx
,
num
,
iaInfo
);
if
(
iaInfo
->
timeWindowInterpo
)
{
iaInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
ResultRowPosition
));
iaInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
OpenWindowInfo
));
}
initResultRowInfo
(
&
iaInfo
->
binfo
.
resultRowInfo
);
...
...
@@ -5292,7 +5311,7 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo*
// prev time window not interpolation yet.
if
(
iaInfo
->
timeWindowInterpo
)
{
SResultRowPosition
pos
=
addToOpenWindowList
(
pResultRowInfo
,
pResult
);
SResultRowPosition
pos
=
addToOpenWindowList
(
pResultRowInfo
,
pResult
,
tableGroupId
);
doInterpUnclosedTimeWindow
(
pOperatorInfo
,
numOfOutput
,
pResultRowInfo
,
pBlock
,
scanFlag
,
tsCols
,
&
pos
);
// restore current time window
...
...
@@ -5467,9 +5486,10 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMerge
initBasicInfo
(
&
pIntervalInfo
->
binfo
,
pResBlock
);
initExecTimeWindowInfo
(
&
pIntervalInfo
->
twAggSup
.
timeWindowData
,
&
pIntervalInfo
->
win
);
pIntervalInfo
->
timeWindowInterpo
=
timeWindowinterpNeeded
(
pExprSupp
->
pCtx
,
num
,
pIntervalInfo
);
if
(
pIntervalInfo
->
timeWindowInterpo
)
{
pIntervalInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
ResultRowPosition
));
pIntervalInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
S
OpenWindowInfo
));
if
(
pIntervalInfo
->
binfo
.
resultRowInfo
.
openWindow
==
NULL
)
{
goto
_error
;
}
...
...
source/libs/function/src/udfd.c
浏览文件 @
6aef8613
...
...
@@ -84,6 +84,7 @@ typedef struct SUdf {
TUdfAggStartFunc
aggStartFunc
;
TUdfAggProcessFunc
aggProcFunc
;
TUdfAggFinishFunc
aggFinishFunc
;
TUdfAggMergeFunc
aggMergeFunc
;
TUdfInitFunc
initFunc
;
TUdfDestroyFunc
destroyFunc
;
...
...
@@ -271,6 +272,15 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
break
;
}
case
TSDB_UDF_CALL_AGG_MERGE
:
{
SUdfInterBuf
outBuf
=
{.
buf
=
taosMemoryMalloc
(
udf
->
bufSize
),
.
bufLen
=
udf
->
bufSize
,
.
numOfResult
=
0
};
code
=
udf
->
aggMergeFunc
(
&
call
->
interBuf
,
&
call
->
interBuf2
,
&
outBuf
);
freeUdfInterBuf
(
&
call
->
interBuf
);
freeUdfInterBuf
(
&
call
->
interBuf2
);
subRsp
->
resultBuf
=
outBuf
;
break
;
}
case
TSDB_UDF_CALL_AGG_FIN
:
{
SUdfInterBuf
outBuf
=
{.
buf
=
taosMemoryMalloc
(
udf
->
bufSize
),
.
bufLen
=
udf
->
bufSize
,
.
numOfResult
=
0
};
code
=
udf
->
aggFinishFunc
(
&
call
->
interBuf
,
&
outBuf
);
...
...
@@ -309,6 +319,10 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
freeUdfInterBuf
(
&
subRsp
->
resultBuf
);
break
;
}
case
TSDB_UDF_CALL_AGG_MERGE
:
{
freeUdfInterBuf
(
&
subRsp
->
resultBuf
);
break
;
}
case
TSDB_UDF_CALL_AGG_FIN
:
{
freeUdfInterBuf
(
&
subRsp
->
resultBuf
);
break
;
...
...
@@ -560,7 +574,11 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
strncpy
(
finishFuncName
,
processFuncName
,
strlen
(
processFuncName
));
strncat
(
finishFuncName
,
finishSuffix
,
strlen
(
finishSuffix
));
uv_dlsym
(
&
udf
->
lib
,
finishFuncName
,
(
void
**
)(
&
udf
->
aggFinishFunc
));
// TODO: merge
char
mergeFuncName
[
TSDB_FUNC_NAME_LEN
+
6
]
=
{
0
};
char
*
mergeSuffix
=
"_merge"
;
strncpy
(
finishFuncName
,
processFuncName
,
strlen
(
processFuncName
));
strncat
(
finishFuncName
,
mergeSuffix
,
strlen
(
mergeSuffix
));
uv_dlsym
(
&
udf
->
lib
,
finishFuncName
,
(
void
**
)(
&
udf
->
aggMergeFunc
));
}
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录