Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8954035a
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,发现更多精彩内容 >>
提交
8954035a
编写于
5月 05, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): update the unit test cases.
上级
02c7fcc2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
142 addition
and
3 deletion
+142
-3
source/libs/executor/src/sortoperator.c
source/libs/executor/src/sortoperator.c
+139
-0
source/libs/executor/test/sortTests.cpp
source/libs/executor/test/sortTests.cpp
+3
-3
未找到文件。
source/libs/executor/src/sortoperator.c
0 → 100644
浏览文件 @
8954035a
#include "tdatablock.h"
#include "executorimpl.h"
static
SSDataBlock
*
doSort
(
SOperatorInfo
*
pOperator
);
static
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
);
SOperatorInfo
*
createSortOperatorInfo
(
SOperatorInfo
*
downstream
,
SSDataBlock
*
pResBlock
,
SArray
*
pSortInfo
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SArray
*
pIndexMap
,
SExecTaskInfo
*
pTaskInfo
)
{
SSortOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SSortOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
int32_t
rowSize
=
pResBlock
->
info
.
rowSize
;
if
(
pInfo
==
NULL
||
pOperator
==
NULL
||
rowSize
>
100
*
1024
*
1024
)
{
goto
_error
;
}
pOperator
->
pExpr
=
pExprInfo
;
pOperator
->
numOfExprs
=
numOfCols
;
pInfo
->
binfo
.
pCtx
=
createSqlFunctionCtx
(
pExprInfo
,
numOfCols
,
&
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
pRes
=
pResBlock
;
initResultSizeInfo
(
pOperator
,
1024
);
pInfo
->
bufPageSize
=
rowSize
<
1024
?
1024
*
2
:
rowSize
*
2
;
// there are headers, so pageSize = rowSize + header
pInfo
->
sortBufSize
=
pInfo
->
bufPageSize
*
16
;
// TODO dynamic set the available sort buffer
pInfo
->
pSortInfo
=
pSortInfo
;
pInfo
->
inputSlotMap
=
pIndexMap
;
pOperator
->
name
=
"SortOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_SORT
;
pOperator
->
blocking
=
true
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doSort
,
NULL
,
NULL
,
destroyOrderOperatorInfo
,
NULL
,
NULL
,
NULL
);
int32_t
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
return
pOperator
;
_error:
pTaskInfo
->
code
=
TSDB_CODE_OUT_OF_MEMORY
;
taosMemoryFree
(
pInfo
);
taosMemoryFree
(
pOperator
);
return
NULL
;
}
// TODO merge aggregate super table
void
appendOneRowToDataBlock
(
SSDataBlock
*
pBlock
,
STupleHandle
*
pTupleHandle
)
{
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
bool
isNull
=
tsortIsNullVal
(
pTupleHandle
,
i
);
if
(
isNull
)
{
colDataAppend
(
pColInfo
,
pBlock
->
info
.
rows
,
NULL
,
true
);
}
else
{
char
*
pData
=
tsortGetValue
(
pTupleHandle
,
i
);
colDataAppend
(
pColInfo
,
pBlock
->
info
.
rows
,
pData
,
false
);
}
}
pBlock
->
info
.
rows
+=
1
;
}
SSDataBlock
*
getSortedBlockData
(
SSortHandle
*
pHandle
,
SSDataBlock
*
pDataBlock
,
int32_t
capacity
)
{
blockDataCleanup
(
pDataBlock
);
blockDataEnsureCapacity
(
pDataBlock
,
capacity
);
blockDataEnsureCapacity
(
pDataBlock
,
capacity
);
while
(
1
)
{
STupleHandle
*
pTupleHandle
=
tsortNextTuple
(
pHandle
);
if
(
pTupleHandle
==
NULL
)
{
break
;
}
appendOneRowToDataBlock
(
pDataBlock
,
pTupleHandle
);
if
(
pDataBlock
->
info
.
rows
>=
capacity
)
{
return
pDataBlock
;
}
}
return
(
pDataBlock
->
info
.
rows
>
0
)
?
pDataBlock
:
NULL
;
}
SSDataBlock
*
loadNextDataBlock
(
void
*
param
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
return
pOperator
->
fpSet
.
getNextFn
(
pOperator
);
}
// todo refactor: merged with fetch fp
void
applyScalarFunction
(
SSDataBlock
*
pBlock
,
void
*
param
)
{
SOperatorInfo
*
pOperator
=
param
;
SSortOperatorInfo
*
pSort
=
pOperator
->
info
;
if
(
pOperator
->
pExpr
!=
NULL
)
{
projectApplyFunctions
(
pOperator
->
pExpr
,
pBlock
,
pBlock
,
pSort
->
binfo
.
pCtx
,
pOperator
->
numOfExprs
,
NULL
);
}
}
SSDataBlock
*
doSort
(
SOperatorInfo
*
pOperator
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
}
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSortOperatorInfo
*
pInfo
=
pOperator
->
info
;
if
(
pOperator
->
status
==
OP_RES_TO_RETURN
)
{
return
getSortedBlockData
(
pInfo
->
pSortHandle
,
pInfo
->
binfo
.
pRes
,
pOperator
->
resultInfo
.
capacity
);
}
int32_t
numOfBufPage
=
pInfo
->
sortBufSize
/
pInfo
->
bufPageSize
;
pInfo
->
pSortHandle
=
tsortCreateSortHandle
(
pInfo
->
pSortInfo
,
pInfo
->
inputSlotMap
,
SORT_SINGLESOURCE_SORT
,
pInfo
->
bufPageSize
,
numOfBufPage
,
pInfo
->
binfo
.
pRes
,
pTaskInfo
->
id
.
str
);
tsortSetFetchRawDataFp
(
pInfo
->
pSortHandle
,
loadNextDataBlock
,
applyScalarFunction
,
pOperator
);
SSortSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SSortSource
));
ps
->
param
=
pOperator
->
pDownstream
[
0
];
tsortAddSource
(
pInfo
->
pSortHandle
,
ps
);
int32_t
code
=
tsortOpen
(
pInfo
->
pSortHandle
);
taosMemoryFreeClear
(
ps
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
terrno
);
}
pOperator
->
status
=
OP_RES_TO_RETURN
;
return
getSortedBlockData
(
pInfo
->
pSortHandle
,
pInfo
->
binfo
.
pRes
,
pOperator
->
resultInfo
.
capacity
);
}
void
destroyOrderOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SSortOperatorInfo
*
pInfo
=
(
SSortOperatorInfo
*
)
param
;
pInfo
->
binfo
.
pRes
=
blockDataDestroy
(
pInfo
->
binfo
.
pRes
);
taosArrayDestroy
(
pInfo
->
pSortInfo
);
taosArrayDestroy
(
pInfo
->
inputSlotMap
);
}
source/libs/executor/test/sortTests.cpp
浏览文件 @
8954035a
...
...
@@ -210,7 +210,7 @@ TEST(testCase, inMem_sort_Test) {
taosArrayPush
(
orderInfo
,
&
oi
);
SSortHandle
*
phandle
=
tsortCreateSortHandle
(
orderInfo
,
NULL
,
SORT_SINGLESOURCE_SORT
,
1024
,
5
,
NULL
,
"test_abc"
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
,
NULL
,
NULL
);
_info
*
pInfo
=
(
_info
*
)
taosMemoryCalloc
(
1
,
sizeof
(
_info
));
pInfo
->
startVal
=
0
;
...
...
@@ -299,7 +299,7 @@ TEST(testCase, external_mem_sort_Test) {
taosArrayPush
(
orderInfo
,
&
oi
);
SSortHandle
*
phandle
=
tsortCreateSortHandle
(
orderInfo
,
NULL
,
SORT_SINGLESOURCE_SORT
,
128
,
3
,
NULL
,
"test_abc"
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
,
NULL
,
NULL
);
SSortSource
*
ps
=
static_cast
<
SSortSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SSortSource
)));
ps
->
param
=
&
pInfo
[
i
];
...
...
@@ -366,7 +366,7 @@ TEST(testCase, ordered_merge_sort_Test) {
}
SSortHandle
*
phandle
=
tsortCreateSortHandle
(
orderInfo
,
NULL
,
SORT_MULTISOURCE_MERGE
,
1024
,
5
,
pBlock
,
"test_abc"
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
,
NULL
,
NULL
);
tsortSetComparFp
(
phandle
,
docomp
);
SSortSource
*
p
[
10
]
=
{
0
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录