Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
38932585
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看板
提交
38932585
编写于
5月 11, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact more
上级
8f4a2e0b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
89 addition
and
23 deletion
+89
-23
include/common/tdataformat.h
include/common/tdataformat.h
+6
-7
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+83
-16
未找到文件。
include/common/tdataformat.h
浏览文件 @
38932585
...
...
@@ -33,9 +33,6 @@ typedef struct STSRow2 STSRow2;
typedef
struct
STSRowBuilder
STSRowBuilder
;
typedef
struct
SKVIdx
SKVIdx
;
#define TD_TP_ROW 0x0U
#define TD_KV_ROW 0x1U
// STSchema
// STSRow2
...
...
@@ -48,8 +45,8 @@ void tTSchemaDestroy(STSchema *pTSchema);
// STSRowBuilder
int32_t
tTSRowBuilderInit
(
STSRowBuilder
*
pBuilder
,
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
nCols
);
int32_t
tTSRowBuilderClear
(
STSRowBuilder
*
pBuilder
);
int32_t
tTSRowBuilderReset
(
STSRowBuilder
*
pBuilder
);
void
tTSRowBuilderClear
(
STSRowBuilder
*
pBuilder
);
void
tTSRowBuilderReset
(
STSRowBuilder
*
pBuilder
);
int32_t
tTSRowBuilderPut
(
STSRowBuilder
*
pBuilder
,
int32_t
cid
,
const
uint8_t
*
pData
,
uint32_t
nData
);
int32_t
tTSRowBuilderGetRow
(
STSRowBuilder
*
pBuilder
,
const
STSRow2
**
ppRow
);
...
...
@@ -85,11 +82,13 @@ struct STSRow2 {
struct
STSRowBuilder
{
STColumn
*
pTColumn
;
STSchema
*
pTSchema
;
int32_t
szKVBuf
;
uint8_t
*
pKVBuf
;
int32_t
szTPBuf
;
uint8_t
*
pTPBuf
;
int32_t
nCols
;
int32_t
kvVLen
;
uint8_t
*
pKV
;
int32_t
tpVLen
;
uint8_t
*
pTuple
;
STSRow2
row
;
};
...
...
source/common/src/tdataformat.c
浏览文件 @
38932585
...
...
@@ -19,6 +19,8 @@
#include "tdatablock.h"
#include "tlog.h"
#define TD_KV_ROW 0x1U
struct
SKVIdx
{
int32_t
cid
;
int32_t
offset
;
...
...
@@ -86,16 +88,46 @@ int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t ncols, STSchema *
void
tTSchemaDestroy
(
STSchema
*
pTSchema
)
{
taosMemoryFree
(
pTSchema
);
}
int32_t
tTSRowBuilderInit
(
STSRowBuilder
*
pBuilder
,
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
nCols
)
{
// TODO
int32_t
kvBufLen
;
int32_t
tpBufLen
;
uint8_t
*
p
;
if
(
tTSchemaCreate
(
sver
,
pSchema
,
nCols
,
&
pBuilder
->
pTSchema
)
<
0
)
return
-
1
;
kvBufLen
=
sizeof
(
SKVIdx
)
*
nCols
+
pBuilder
->
pTSchema
->
flen
+
pBuilder
->
pTSchema
->
vlen
;
tpBufLen
=
pBuilder
->
pTSchema
->
flen
+
pBuilder
->
pTSchema
->
vlen
;
if
(
pBuilder
->
szKVBuf
<
kvBufLen
)
{
p
=
taosMemoryRealloc
(
pBuilder
->
pKVBuf
,
kvBufLen
);
if
(
p
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pBuilder
->
pKVBuf
=
p
;
pBuilder
->
szKVBuf
=
kvBufLen
;
}
if
(
pBuilder
->
szTPBuf
<
tpBufLen
)
{
p
=
taosMemoryRealloc
(
pBuilder
->
pTPBuf
,
tpBufLen
);
if
(
p
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pBuilder
->
pTPBuf
=
p
;
pBuilder
->
szTPBuf
=
tpBufLen
;
}
tTSRowBuilderReset
(
pBuilder
);
return
0
;
}
int32_t
tTSRowBuilderClear
(
STSRowBuilder
*
pBuilder
)
{
// TODO
return
0
;
void
tTSRowBuilderClear
(
STSRowBuilder
*
pBuilder
)
{
taosMemoryFree
(
pBuilder
->
pKVBuf
);
taosMemoryFree
(
pBuilder
->
pTPBuf
)
;
}
int32_t
tTSRowBuilderReset
(
STSRowBuilder
*
pBuilder
)
{
void
tTSRowBuilderReset
(
STSRowBuilder
*
pBuilder
)
{
for
(
int32_t
iCol
=
pBuilder
->
pTSchema
->
numOfCols
-
1
;
iCol
>=
0
;
iCol
--
)
{
pBuilder
->
pTColumn
=
&
pBuilder
->
pTSchema
->
columns
[
iCol
];
...
...
@@ -106,19 +138,29 @@ int32_t tTSRowBuilderReset(STSRowBuilder *pBuilder) {
pBuilder
->
kvVLen
=
0
;
pBuilder
->
tpVLen
=
0
;
pBuilder
->
row
.
flags
=
0
;
return
0
;
}
int32_t
tTSRowBuilderPut
(
STSRowBuilder
*
pBuilder
,
int32_t
cid
,
const
uint8_t
*
pData
,
uint32_t
nData
)
{
int32_t
iCol
;
uint8_t
*
p
;
// search column
if
(
pBuilder
->
pTColumn
->
colId
<
cid
)
{
// right search
iCol
=
(
pBuilder
->
pTColumn
-
pBuilder
->
pTSchema
->
columns
)
/
sizeof
(
STColumn
)
+
1
;
for
(;
iCol
<
pBuilder
->
pTSchema
->
numOfCols
;
iCol
++
)
{
pBuilder
->
pTColumn
=
&
pBuilder
->
pTSchema
->
columns
[
iCol
];
if
(
pBuilder
->
pTColumn
->
colId
==
cid
)
break
;
}
}
else
if
(
pBuilder
->
pTColumn
->
colId
>
cid
)
{
// left search
iCol
=
(
pBuilder
->
pTColumn
-
pBuilder
->
pTSchema
->
columns
)
/
sizeof
(
STColumn
)
-
1
;
for
(;
iCol
>=
0
;
iCol
--
)
{
pBuilder
->
pTColumn
=
&
pBuilder
->
pTSchema
->
columns
[
iCol
];
if
(
pBuilder
->
pTColumn
->
colId
==
cid
)
break
;
}
}
// check
if val is set already
if
(
pBuilder
->
pTColumn
->
flags
&
COL_VAL_SET
)
{
// check
if
(
pBuilder
->
pTColumn
->
colId
!=
cid
||
pBuilder
->
pTColumn
->
flags
&
COL_VAL_SET
)
{
return
-
1
;
}
...
...
@@ -128,7 +170,32 @@ int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, const uint8_t *pD
pBuilder
->
row
.
ts
=
*
(
TSKEY
*
)
pData
;
}
else
{
if
(
pData
)
{
// set val
// ASSERT(!IS_NULL(pData));
// set tuple data
p
=
pBuilder
->
pTPBuf
+
pBuilder
->
pTColumn
->
offset
;
if
(
IS_VAR_DATA_TYPE
(
pBuilder
->
pTColumn
->
type
))
{
*
(
int32_t
*
)
p
=
pBuilder
->
tpVLen
;
// encode the variant-length data
p
=
pBuilder
->
pTPBuf
+
pBuilder
->
pTSchema
->
flen
+
pBuilder
->
tpVLen
;
pBuilder
->
tpVLen
+=
tPutBinary
(
p
,
pData
,
nData
);
}
else
{
memcpy
(
p
,
pData
,
nData
);
}
// set kv data
p
=
pBuilder
->
pKVBuf
+
sizeof
(
SKVIdx
)
*
pBuilder
->
nCols
;
((
SKVIdx
*
)
p
)
->
cid
=
cid
;
((
SKVIdx
*
)
p
)
->
offset
=
pBuilder
->
kvVLen
;
p
=
pBuilder
->
pKVBuf
+
sizeof
(
SKVIdx
)
*
pBuilder
->
pTSchema
->
numOfCols
+
pBuilder
->
kvVLen
;
if
(
IS_VAR_DATA_TYPE
(
pBuilder
->
pTColumn
->
type
))
{
pBuilder
->
kvVLen
+=
tPutBinary
(
p
,
pData
,
nData
);
}
else
{
memcpy
(
p
,
pData
,
nData
);
pBuilder
->
kvVLen
+=
nData
;
}
}
else
{
// set NULL val
}
...
...
@@ -149,18 +216,18 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) {
pBuilder
->
row
.
flags
|=
TD_KV_ROW
;
pBuilder
->
row
.
ncols
=
pBuilder
->
nCols
;
pBuilder
->
row
.
nData
=
pBuilder
->
nCols
*
sizeof
(
SKVIdx
)
+
pBuilder
->
kvVLen
;
pBuilder
->
row
.
pData
=
pBuilder
->
pKV
;
pBuilder
->
row
.
pData
=
pBuilder
->
pKV
Buf
;
if
(
pBuilder
->
nCols
<
pBuilder
->
pTSchema
->
numOfCols
)
{
memmove
(
pBuilder
->
pKV
+
sizeof
(
SKVIdx
)
*
pBuilder
->
nCols
,
pBuilder
->
pKV
+
sizeof
(
SKVIdx
)
*
pBuilder
->
pTSchema
->
numOfCols
,
pBuilder
->
kvVLen
);
memmove
(
pBuilder
->
pKV
Buf
+
sizeof
(
SKVIdx
)
*
pBuilder
->
nCols
,
pBuilder
->
pKV
Buf
+
sizeof
(
SKVIdx
)
*
pBuilder
->
pTSchema
->
numOfCols
,
pBuilder
->
kvVLen
);
}
}
else
{
// encode as TD_TUPLE_ROW
pBuilder
->
row
.
flags
&=
(
~
TD_KV_ROW
);
pBuilder
->
row
.
sver
=
pBuilder
->
pTSchema
->
version
;
pBuilder
->
row
.
nData
=
pBuilder
->
pTSchema
->
flen
+
pBuilder
->
tpVLen
;
pBuilder
->
row
.
pData
=
pBuilder
->
pT
uple
;
pBuilder
->
row
.
pData
=
pBuilder
->
pT
PBuf
;
if
(
pBuilder
->
nCols
<
pBuilder
->
pTSchema
->
numOfCols
)
{
// set non-set cols as None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录