Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
416e6354
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
416e6354
编写于
11月 22, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
274d115a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
121 addition
and
89 deletion
+121
-89
include/common/trow.h
include/common/trow.h
+44
-15
include/common/tschema.h
include/common/tschema.h
+41
-7
source/common/src/trow.c
source/common/src/trow.c
+9
-67
source/common/test/trowTest.cpp
source/common/test/trowTest.cpp
+21
-0
source/common/test/tschemaTest.cpp
source/common/test/tschemaTest.cpp
+6
-0
未找到文件。
include/common/trow.h
浏览文件 @
416e6354
...
...
@@ -19,18 +19,18 @@
#include "os.h"
#include "tbuffer.h"
#include "tdef.h"
#include "tschema.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define TD_OR_ROW 0
#define TD_KV_ROW 1
typedef
uint16_t
col_id_t
;
#define TD_UNDECIDED_ROW 0
#define TD_OR_ROW 1
#define TD_KV_ROW 2
typedef
struct
{
TSKEY
ts
;
// TODO
}
SOrRow
;
typedef
struct
{
...
...
@@ -48,21 +48,30 @@ typedef struct {
/// union field for encode and decode
uint64_t
info
;
struct
{
/// is deleted row
uint64_t
del
:
1
;
/// row type
uint64_t
type
:
2
;
uint64_t
type
:
3
;
/// row schema version
uint64_t
sver
:
16
;
/// row total length
uint64_t
len
:
46
;
uint64_t
len
:
32
;
/// reserved for back compatibility
uint64_t
reserve
:
12
;
};
};
/// row version
uint64_t
ver
;
/// timestamp
of the row
TSKEY
ts
;
char
content
[];
/// timestamp
TSKEY
ts
;
char
content
[];
}
SRow
;
typedef
struct
{
uint32_t
nRows
;
char
rows
[];
}
SRowBatch
;
typedef
enum
{
/// ordinary row builder
TD_OR_ROW_BUILDER
=
0
,
...
...
@@ -82,12 +91,32 @@ typedef struct {
}
SRowBuilder
;
typedef
struct
{
/* TODO */
}
SRowBatchBuilder
;
SSchema
*
pSchema
;
SRow
*
pRow
;
}
SRowReader
;
typedef
struct
{
uint32_t
it
;
SRowBatch
*
pRowBatch
;
}
SRowBatchIter
;
// SRowBuilder
#define trbInit(rt, allocator, endian, target, size) \
{ .type = (rt), .bw = tbufInitWriter(allocator, endian), .pRow = (target) }
void
trbSetRowInfo
(
SRowBuilder
*
pRB
,
bool
del
,
uint16_t
sver
);
void
trbSetRowVersion
(
SRowBuilder
*
pRB
,
uint64_t
ver
);
void
trbSetRowTS
(
SRowBuilder
*
pRB
,
TSKEY
ts
);
int
trbWriteCol
(
SRowBuilder
*
pRB
,
void
*
pData
,
col_id_t
cid
);
// SRowReader
#define tRowReaderInit(schema, row) \
{ .schema = (schema), .row = (row) }
int
tRowReaderRead
(
SRowReader
*
pRowReader
,
col_id_t
cid
,
void
*
target
,
uint64_t
size
);
#define tRBInit(type, allocator, endian) \
{ .type = (type), tbufInitWriter(allocator, endian), NULL }
void
tRBClear
(
SRowBuilder
*
pRB
);
// SRowBatchIter
#define tRowBatchIterInit(pRB) \
{ .it = 0, .pRowBatch = (pRB) }
const
SRow
*
tRowBatchIterNext
(
SRowBatchIter
*
pRowBatchIter
);
#ifdef __cplusplus
}
...
...
include/common/tschema.h
浏览文件 @
416e6354
...
...
@@ -17,27 +17,61 @@
#define _TD_COMMON_SCHEMA_H_
#include "os.h"
#include "tarray.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
SColAttr
{
/* data */
}
SColAttr
;
typedef
uint16_t
col_id_t
;
typedef
struct
SColumn
{
uint8_t
type
;
uint16_t
cid
;
uint16_t
bytes
;
/// column name
char
*
cname
;
union
{
/// for encode purpose
uint64_t
info
;
struct
{
uint64_t
sma
:
1
;
/// column data type
uint64_t
type
:
7
;
/// column id
uint64_t
cid
:
16
;
/// max bytes of the column
uint64_t
bytes
:
32
;
/// reserved
uint64_t
reserve
:
8
;
};
};
/// comment about the column
char
*
comment
;
}
SColumn
;
typedef
struct
SSchema
{
/// schema version
uint16_t
sver
;
/* data */
/// number of columns
uint16_t
ncols
;
/// sma attributes
struct
{
bool
sma
;
SArray
*
smaArray
;
};
/// column info
SColumn
cols
[];
}
SSchema
;
typedef
struct
{
uint64_t
size
;
SSchema
*
pSchema
;
}
SShemaBuilder
;
#define tSchemaBuilderInit(target, capacity) \
{ .size = (capacity), .pSchema = (target) }
void
tSchemaBuilderSetSver
(
SShemaBuilder
*
pSchemaBuilder
,
uint16_t
sver
);
void
tSchemaBuilderSetSMA
(
bool
sma
,
SArray
*
smaArray
);
int
tSchemaBuilderPutColumn
(
char
*
cname
,
bool
sma
,
uint8_t
type
,
col_id_t
cid
,
uint32_t
bytes
,
char
*
comment
);
#ifdef __cplusplus
}
#endif
...
...
source/common/src/trow.c
浏览文件 @
416e6354
...
...
@@ -15,77 +15,19 @@
#include "trow.h"
#if 0
/* ------------ Structures ---------- */
struct SRowBatch {
int32_t compress : 1; // if batch row is compressed
int32_t nrows : 31; // number of rows
int32_t tlen; // total length (including `nrows` and `tlen`)
char rows[];
};
struct SRowBuilder {
void
trbSetRowInfo
(
SRowBuilder
*
pRB
,
bool
del
,
uint16_t
sver
)
{
// TODO
};
struct SRowBatchIter {
int32_t counter; // row counter
SRowBatch *rb; // row batch to iter
SRow nrow; // next row
};
struct SRowBatchBuilder {
// TODO
};
/* ------------ Methods ---------- */
// SRowBuilder
SRowBuilder *rowBuilderCreate() {
SRowBuilder *pRowBuilder = NULL;
// TODO
return pRowBuilder;
}
void rowBuilderDestroy(SRowBuilder *pRowBuilder) {
if (pRowBuilder) {
free(pRowBuilder);
}
}
// SRowBatchIter
SRowBatchIter *rowBatchIterCreate(SRowBatch *pRowBatch) {
SRowBatchIter *pRowBatchIter = (SRowBatchIter *)malloc(sizeof(*pRowBatchIter));
if (pRowBatchIter == NULL) {
return NULL;
}
pRowBatchIter->counter = 0;
pRowBatchIter->rb = pRowBatch;
pRowBatchIter->nrow = pRowBatch->rows;
return pRowBatchIter;
};
void rowBatchIterDestroy(SRowBatchIter *pRowBatchIter) {
if (pRowBatchIter) {
free(pRowBatchIter);
}
void
trbSetRowVersion
(
SRowBuilder
*
pRB
,
uint64_t
ver
)
{
// TODO
}
const SRow rowBatchIterNext(SRowBatchIter *pRowBatchIter) {
SRow r = NULL;
if (pRowBatchIter->counter < pRowBatchIter->rb->nrows) {
r = pRowBatchIter->nrow;
pRowBatchIter->counter += 1;
pRowBatchIter->nrow = (SRow)POINTER_SHIFT(r, rowLen(r));
}
return r;
void
trbSetRowTS
(
SRowBuilder
*
pRB
,
TSKEY
ts
)
{
// TODO
}
// SRowBatchBuilder
SRowBatchBuilder *rowBatchBuilderCreate();
void rowBatchBuilderDestroy(SRowBatchBuilder *);
#endif
\ No newline at end of file
int
trbWriteCol
(
SRowBuilder
*
pRB
,
void
*
pData
,
col_id_t
cid
)
{
// TODO
return
0
;
}
\ No newline at end of file
source/common/test/trowTest.cpp
0 → 100644
浏览文件 @
416e6354
#include <gtest/gtest.h>
#include "trow.h"
TEST
(
td_row_test
,
build_row_to_target
)
{
char
dst
[
1024
];
SRow
*
pRow
=
(
SRow
*
)
dst
;
int
ncols
=
10
;
col_id_t
cid
;
void
*
pData
;
SRowBuilder
rb
=
trbInit
(
TD_OR_ROW_BUILDER
,
NULL
,
0
,
pRow
,
1024
);
trbSetRowInfo
(
&
rb
,
false
,
0
);
trbSetRowTS
(
&
rb
,
1637550210000
);
for
(
int
c
=
0
;
c
<
ncols
;
c
++
)
{
cid
=
c
;
if
(
trbWriteCol
(
&
rb
,
pData
,
cid
)
<
0
)
{
// TODO
}
}
}
\ No newline at end of file
source/common/test/tschemaTest.cpp
0 → 100644
浏览文件 @
416e6354
#include <gtest/gtest.h>
#include "tschema.h"
TEST
(
td_schema_test
,
build_schema_test
)
{
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录