Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
afe99b1f
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看板
未验证
提交
afe99b1f
编写于
3月 24, 2022
作者:
H
Haojun Liao
提交者:
GitHub
3月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10980 from taosdata/feature/TD-14222-new
add encode/decode resultRow function
上级
1204a21e
0649e662
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
111 addition
and
0 deletion
+111
-0
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+4
-0
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+107
-0
未找到文件。
source/libs/executor/inc/executorimpl.h
浏览文件 @
afe99b1f
...
...
@@ -243,6 +243,8 @@ typedef struct STaskAttr {
struct
SOperatorInfo
;
typedef
void
(
*
__optr_encode_fn_t
)(
struct
SOperatorInfo
*
pOperator
,
char
**
result
,
int32_t
*
length
);
typedef
bool
(
*
__optr_decode_fn_t
)(
struct
SOperatorInfo
*
pOperator
,
char
*
result
,
int32_t
length
);
typedef
int32_t
(
*
__optr_open_fn_t
)(
struct
SOperatorInfo
*
param
);
typedef
SSDataBlock
*
(
*
__optr_fn_t
)(
struct
SOperatorInfo
*
param
,
bool
*
newgroup
);
typedef
void
(
*
__optr_close_fn_t
)(
void
*
param
,
int32_t
num
);
...
...
@@ -332,6 +334,8 @@ typedef struct SOperatorInfo {
__optr_fn_t
cleanupFn
;
__optr_close_fn_t
closeFn
;
__optr_open_fn_t
_openFn
;
// DO NOT invoke this function directly
__optr_encode_fn_t
encodeResultRow
;
//
__optr_decode_fn_t
decodeResultRow
;
}
SOperatorInfo
;
typedef
struct
{
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
afe99b1f
...
...
@@ -6391,6 +6391,111 @@ static SSDataBlock* getAggregateResult(SOperatorInfo *pOperator, bool* newgroup)
return
(
blockDataGetNumOfRows
(
pInfo
->
pRes
)
!=
0
)
?
pInfo
->
pRes
:
NULL
;
}
static
void
aggEncodeResultRow
(
SOperatorInfo
*
pOperator
,
char
**
result
,
int32_t
*
length
)
{
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SAggSupporter
*
pSup
=
&
pAggInfo
->
aggSup
;
int32_t
size
=
taosHashGetSize
(
pSup
->
pResultRowHashTable
);
size_t
keyLen
=
POINTER_BYTES
;
// estimate the key length
int32_t
totalSize
=
sizeof
(
int32_t
)
+
size
*
(
sizeof
(
int32_t
)
+
keyLen
+
sizeof
(
int32_t
)
+
pSup
->
resultRowSize
);
*
result
=
calloc
(
1
,
totalSize
);
if
(
*
result
==
NULL
){
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
;
}
*
(
int32_t
*
)(
*
result
)
=
size
;
int32_t
offset
=
sizeof
(
int32_t
);
void
*
pIter
=
taosHashIterate
(
pSup
->
pResultRowHashTable
,
NULL
);
while
(
pIter
)
{
void
*
key
=
taosHashGetKey
(
pIter
,
&
keyLen
);
SResultRow
**
p1
=
(
SResultRow
**
)
pIter
;
// recalculate the result size
int32_t
realTotalSize
=
offset
+
sizeof
(
int32_t
)
+
keyLen
+
sizeof
(
int32_t
)
+
pSup
->
resultRowSize
;
if
(
realTotalSize
>
totalSize
){
char
*
tmp
=
realloc
(
*
result
,
realTotalSize
);
if
(
tmp
==
NULL
){
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
free
(
*
result
);
*
result
=
NULL
;
return
;
}
else
{
*
result
=
tmp
;
}
}
// save key
*
(
int32_t
*
)(
*
result
+
offset
)
=
keyLen
;
offset
+=
sizeof
(
int32_t
);
memcpy
(
*
result
+
offset
,
key
,
keyLen
);
offset
+=
keyLen
;
// save value
*
(
int32_t
*
)(
*
result
+
offset
)
=
pSup
->
resultRowSize
;
offset
+=
sizeof
(
int32_t
);
memcpy
(
*
result
+
offset
,
*
p1
,
pSup
->
resultRowSize
);
offset
+=
pSup
->
resultRowSize
;
pIter
=
taosHashIterate
(
pSup
->
pResultRowHashTable
,
pIter
);
}
if
(
length
)
{
*
length
=
offset
;
}
return
;
}
static
bool
aggDecodeResultRow
(
SOperatorInfo
*
pOperator
,
char
*
result
,
int32_t
length
)
{
if
(
!
result
||
length
<=
0
){
return
false
;
}
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SAggSupporter
*
pSup
=
&
pAggInfo
->
aggSup
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
// int32_t size = taosHashGetSize(pSup->pResultRowHashTable);
int32_t
count
=
*
(
int32_t
*
)(
result
);
int32_t
offset
=
sizeof
(
int32_t
);
while
(
count
--
>
0
&&
length
>
offset
){
int32_t
keyLen
=
*
(
int32_t
*
)(
result
+
offset
);
offset
+=
sizeof
(
int32_t
);
uint64_t
tableGroupId
=
*
(
uint64_t
*
)(
result
+
offset
);
SResultRow
*
resultRow
=
getNewResultRow_rv
(
pSup
->
pResultBuf
,
tableGroupId
,
pSup
->
resultRowSize
);
if
(
!
resultRow
){
terrno
=
TSDB_CODE_TSC_INVALID_INPUT
;
return
false
;
}
// add a new result set for a new group
taosHashPut
(
pSup
->
pResultRowHashTable
,
result
+
offset
,
keyLen
,
&
resultRow
,
POINTER_BYTES
);
offset
+=
keyLen
;
int32_t
valueLen
=
*
(
int32_t
*
)(
result
+
offset
);
if
(
valueLen
!=
pSup
->
resultRowSize
){
terrno
=
TSDB_CODE_TSC_INVALID_INPUT
;
return
false
;
}
offset
+=
sizeof
(
int32_t
);
int32_t
pageId
=
resultRow
->
pageId
;
int32_t
pOffset
=
resultRow
->
offset
;
memcpy
(
resultRow
,
result
+
offset
,
valueLen
);
resultRow
->
pageId
=
pageId
;
resultRow
->
offset
=
pOffset
;
offset
+=
valueLen
;
initResultRow
(
resultRow
);
pInfo
->
resultRowInfo
.
pPosition
[
pInfo
->
resultRowInfo
.
size
++
]
=
(
SResultRowPosition
)
{.
pageId
=
resultRow
->
pageId
,
.
offset
=
resultRow
->
offset
};
}
if
(
offset
!=
length
){
terrno
=
TSDB_CODE_TSC_INVALID_INPUT
;
return
false
;
}
return
true
;
}
static
SSDataBlock
*
doMultiTableAggregate
(
SOperatorInfo
*
pOperator
,
bool
*
newgroup
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
...
...
@@ -7312,6 +7417,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
pOperator
->
_openFn
=
doOpenAggregateOptr
;
pOperator
->
getNextFn
=
getAggregateResult
;
pOperator
->
closeFn
=
destroyAggOperatorInfo
;
pOperator
->
encodeResultRow
=
aggEncodeResultRow
;
pOperator
->
decodeResultRow
=
aggDecodeResultRow
;
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录