Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
14bbe488
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
14bbe488
编写于
3月 12, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more
上级
a614570c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
57 addition
and
84 deletion
+57
-84
src/common/inc/dataformat.h
src/common/inc/dataformat.h
+6
-4
src/common/src/dataformat.c
src/common/src/dataformat.c
+29
-2
src/vnode/tsdb/CMakeLists.txt
src/vnode/tsdb/CMakeLists.txt
+1
-1
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+1
-1
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+20
-76
未找到文件。
src/common/inc/dataformat.h
浏览文件 @
14bbe488
...
...
@@ -51,18 +51,20 @@ void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes);
// ----------------- TSDB SCHEMA DEFINITION
typedef
struct
{
int
32_t
numOfCols
;
int
32_t
padding
;
// TODO: replace the padding for useful variable
int
numOfCols
;
// Number of columns appended
int
totalCols
;
// Total columns allocated
STColumn
columns
[];
}
STSchema
;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaTCols(s) ((s)->totalCols)
#define schemaColAt(s, i) ((s)->columns + i)
STSchema
*
tdNewSchema
(
int32_t
nCols
);
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int16_t
bytes
);
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
void
tdFreeSchema
(
STSchema
*
pSchema
);
void
tdUpdateSchema
(
STSchema
*
pSchema
);
void
tdFreeSchema
(
STSchema
*
pSchema
);
void
tdUpdateSchema
(
STSchema
*
pSchema
);
// ----------------- Data row structure
...
...
src/common/src/dataformat.c
浏览文件 @
14bbe488
...
...
@@ -89,13 +89,40 @@ void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes) {
STSchema
*
tdNewSchema
(
int32_t
nCols
)
{
int32_t
size
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
nCols
;
STSchema
*
pSchema
=
(
STSchema
*
)
calloc
(
1
,
size
);
STSchema
*
pSchema
=
(
STSchema
*
)
malloc
(
size
);
if
(
pSchema
==
NULL
)
return
NULL
;
pSchema
->
numOfCols
=
nCols
;
pSchema
->
numOfCols
=
0
;
pSchema
->
totalCols
=
nCols
;
return
pSchema
;
}
/**
* Append a column to the schema
*/
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int16_t
bytes
)
{
if
(
pSchema
->
numOfCols
>=
pSchema
->
totalCols
)
return
-
1
;
if
(
!
isValidDataType
(
type
,
0
))
return
-
1
;
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
));
colSetType
(
pCol
,
type
);
colSetColId
(
pCol
,
colId
);
colSetOffset
(
pCol
,
-
1
);
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
colSetBytes
(
pCol
,
bytes
);
break
;
default:
colSetBytes
(
pCol
,
TYPE_BYTES
[
type
]);
break
;
}
pSchema
->
numOfCols
++
;
return
0
;
}
/**
* Duplicate the schema and return a new object
*/
...
...
src/vnode/tsdb/CMakeLists.txt
浏览文件 @
14bbe488
...
...
@@ -15,5 +15,5 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
TARGET_LINK_LIBRARIES
(
tsdb common tutil
)
# Someone has no gtest directory, so comment it
#
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY
(
tests
)
ENDIF
()
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
14bbe488
...
...
@@ -347,7 +347,7 @@ int tsdbInitTableCfg(STableCfg *config, TSDB_TABLE_TYPE type, int64_t uid, int32
config
->
superUid
=
TSDB_INVALID_SUPER_TABLE_ID
;
config
->
tableId
.
uid
=
uid
;
config
->
tableId
.
tid
=
tid
;
return
-
1
;
return
0
;
}
/**
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
14bbe488
...
...
@@ -3,92 +3,36 @@
#include "tsdb.h"
#include "dataformat.h"
#include "tsdbMeta.h"
TEST
(
TsdbTest
,
createRepo
)
{
STsdbCfg
config
;
// Create a tsdb repository
//
1.
Create a tsdb repository
tsdbSetDefaultCfg
(
&
config
);
tsdb_repo_t
*
pRepo
=
tsdbCreateRepo
(
"/home/ubuntu/work/ttest/vnode0"
,
&
config
,
NULL
);
ASSERT_NE
(
pRepo
,
nullptr
);
// // create a normal table in this repository
// STableCfg config;
// config.tableId.tid = 0;
// config.tableId.uid = 98868728187539L;
// config.numOfCols = 5;
// config.schema = tdNewSchema(config.numOfCols);
// STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
// tdColCpy(schemaColAt(config.schema, 0), pCol);
// tdFreeCol(pCol);
// for (int i = 1; i < schemaNCols(config.schema); i++) {
// pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
// tdColCpy(schemaColAt(config.schema, i), pCol);
// tdFreeCol(pCol);
// }
// tsdbCreateTable(pRepo, &config);
// Write some data
// int32_t size = sizeof(SSubmitMsg) + sizeof(SSubmitBlock) + tdMaxRowDataBytes(config.schema) * 10 + sizeof(int32_t);
// tdUpdateSchema(config.schema);
// SSubmitMsg *pMsg = (SSubmitMsg *)malloc(size);
// pMsg->numOfTables = 1; // TODO: use api
// SSubmitBlock *pBlock = (SSubmitBlock *)pMsg->data;
// pBlock->tableId = {.uid = 98868728187539L, .tid = 0};
// pBlock->sversion = 0;
// pBlock->len = sizeof(SSubmitBlock);
// SDataRows rows = pBlock->data;
// dataRowsInit(rows);
// SDataRow row = tdNewDataRow(tdMaxRowDataBytes(config.schema));
// int64_t ttime = 1583508800000;
// for (int i = 0; i < 10; i++) { // loop over rows
// ttime += (10000 * i);
// tdDataRowReset(row);
// for (int j = 0; j < schemaNCols(config.schema); j++) {
// if (j == 0) { // set time stamp
// tdAppendColVal(row, (void *)(&ttime), schemaColAt(config.schema, j), 40);
// } else { // set other fields
// int32_t val = 10;
// tdAppendColVal(row, (void *)(&val), schemaColAt(config.schema, j), 40);
// }
// }
// tdDataRowsAppendRow(rows, row);
// }
// 2. Create a normal table
STableCfg
tCfg
;
ASSERT_EQ
(
tsdbInitTableCfg
(
&
tCfg
,
TSDB_SUPER_TABLE
,
987607499877672L
,
0
),
-
1
);
ASSERT_EQ
(
tsdbInitTableCfg
(
&
tCfg
,
TSDB_NTABLE
,
987607499877672L
,
0
),
0
);
int
nCols
=
5
;
STSchema
*
schema
=
tdNewSchema
(
nCols
);
for
(
int
i
=
0
;
i
<
nCols
;
i
++
)
{
if
(
i
==
0
)
{
tdSchemaAppendCol
(
schema
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
-
1
);
}
else
{
tdSchemaAppendCol
(
schema
,
TSDB_DATA_TYPE_INT
,
i
,
-
1
);
}
}
// tsdbInsertData(pRepo, pMsg
);
tsdbTableSetSchema
(
&
tCfg
,
schema
,
true
);
// tdFreeDataRow(row
);
tsdbCreateTable
(
pRepo
,
&
tCfg
);
// tdFreeSchema(config.schema);
// tsdbDropRepo(pRepo);
// 3. Loop to write some simple data
}
TEST
(
TsdbTest
,
DISABLED_createTable
)
{
STsdbMeta
*
pMeta
=
tsdbInitMeta
(
100
);
ASSERT_NE
(
pMeta
,
nullptr
);
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
98868728187539L
;
config
.
numOfCols
=
5
;
config
.
schema
=
tdNewSchema
(
config
.
numOfCols
);
for
(
int
i
=
0
;
i
<
schemaNCols
(
config
.
schema
);
i
++
)
{
STColumn
*
pCol
=
tdNewCol
(
TSDB_DATA_TYPE_BIGINT
,
i
,
0
);
tdColCpy
(
schemaColAt
(
config
.
schema
,
i
),
pCol
);
tdFreeCol
(
pCol
);
}
config
.
tagValues
=
nullptr
;
tsdbCreateTableImpl
(
pMeta
,
&
config
);
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
config
.
tableId
.
uid
);
ASSERT_NE
(
pTable
,
nullptr
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录