Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yiicenne
TDengine
提交
4ecdb6d5
TDengine
项目概览
yiicenne
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ecdb6d5
编写于
2月 11, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
8676d969
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
100 addition
and
17 deletion
+100
-17
src/vnode/common/inc/schema.h
src/vnode/common/inc/schema.h
+31
-16
src/vnode/common/inc/type.h
src/vnode/common/inc/type.h
+1
-1
src/vnode/common/src/schema.c
src/vnode/common/src/schema.c
+68
-0
未找到文件。
src/vnode/common/inc/schema.h
浏览文件 @
4ecdb6d5
...
...
@@ -2,6 +2,7 @@
#define _TD_SCHEMA_H_
#include <stdint.h>
#include <string.h>
#include "type.h"
...
...
@@ -30,27 +31,41 @@ typedef struct {
* | len | SSchema | SColumn | ... | SColumn | col1_name | ... | colN_name |
* +---------+---------+---------+-----+---------+-----------+-----+-----------+
*/
typedef
char
*
SISchema
// ---- operation on SColumn
#define TD_COLUMN_TYPE(pCol) ((pCol)->type)
#define TD_COLUMN_ID(pCol) ((pCol)->colId)
#define TD_COLUMN_BYTES(pCol) ((pCol)->bytes)
#define TD_COLUMN_NAME(pCol) ((pCol)->colName)
// ---- operation on SSchema
#define TD_SCHEMA_VERSION(pSchema) ((pSchema)->version)
#define TD_SCHEMA_NCOLS(pSchema) ((pSchema)->numOfCols)
#define TD_SCHEMA_NTAGS(pSchema) ((pSchema)->numOfTags)
#define TD_SCHEMA_TOTAL_COLS(pSchema) (TD_SCHEMA_NCOLS(pSchema) + TD_SCHEMA_NTAGS(pSchema))
typedef
char
*
SISchema
;
// TODO: decide if the space is allowed
#define TD_ISCHEMA_HEADER_SIZE sizeof(int32_t) + sizeof(SSchema)
// ---- operations on SColumn
#define TD_COLUMN_TYPE(pCol) ((pCol)->type) // column type
#define TD_COLUMN_ID(pCol) ((pCol)->colId) // column ID
#define TD_COLUMN_BYTES(pCol) ((pCol)->bytes) // column bytes
#define TD_COLUMN_NAME(pCol) ((pCol)->colName) // column name
#define TD_COLUMN_INLINE_SIZE(pCol) (sizeof(SColumn) + TD_COLUMN_NAME(pCol) + 1)
// ---- operations on SSchema
#define TD_SCHEMA_VERSION(pSchema) ((pSchema)->version) // schema version
#define TD_SCHEMA_NCOLS(pSchema) ((pSchema)->numOfCols) // schema number of columns
#define TD_SCHEMA_NTAGS(pSchema) ((pSchema)->numOfTags) // schema number of tags
#define TD_SCHEMA_TOTAL_COLS(pSchema) (TD_SCHEMA_NCOLS(pSchema) + TD_SCHEMA_NTAGS(pSchema)) // schema total number of SColumns (#columns + #tags)
#define TD_SCHEMA_NEXT_COLID(pSchema) ((pSchema)->colIdCounter++)
#define TD_SCHEMA_COLS(pSchema) ((pSchema)->columns)
#define TD_SCHEMA_TAGS(pSchema) (TD_SCHEMA_COLS(pSchema) + TD_SCHEMA_NCOLS(pSchema))
#define TD_SCHEMA_COLUMN_AT(pSchema, idx)
TD_SCHEMA_COLS(pSchema)[idx]
#define TD_SCHEMA_TAG_AT(pSchema, idx)
TD_SCHEMA_TAGS(pSchema)[idx]
#define TD_SCHEMA_COLUMN_AT(pSchema, idx)
(TD_SCHEMA_COLS(pSchema) + idx)
#define TD_SCHEMA_TAG_AT(pSchema, idx)
(TD_SCHEMA_TAGS(pSchema) + idx)
// ---- operation on SISchema
// ---- operation
s
on SISchema
#define TD_ISCHEMA_LEN(pISchema) *((int32_t *)(pISchema))
#define TD_ISCHEMA_SCHEMA(pISchema) ((SSchema *)((pISchema) + sizeof(int32_t)))
#define TD_ISCHEMA_COL_NAMES(pISchema) ((pISchema) + TD_ISCHEMA_HEADER_SIZE + sizeof(SColumn) * TD_SCHEMA_TOTAL_COLS(TD_ISCHEMA_SCHEMA(pISchema)))
// ----
/* Convert a schema structure to an inline schema structure
*/
SISchema
tdConvertSchemaToInline
(
SSchema
*
pSchema
);
int32_t
tdGetColumnIdxByName
(
SSchema
*
pSchema
,
char
*
colName
);
int32_t
tdGetColumnIdxById
(
SSchema
*
pSchema
,
int32_t
colId
);
// ---- TODO: operations to change schema
#endif // _TD_SCHEMA_H_
src/vnode/common/inc/type.h
浏览文件 @
4ecdb6d5
...
...
@@ -3,7 +3,7 @@
#include <stdint.h>
typedef
enum
:
uint8_t
{
typedef
enum
{
TD_DATATYPE_INVLD
=
0
,
// invalid data type
TD_DATATYPE_BOOL
,
TD_DATATYPE_TINYINT
,
...
...
src/vnode/common/src/schema.c
0 → 100644
浏览文件 @
4ecdb6d5
#include <stdlib.h>
#include "schema.h"
static
size_t
tdGetEstimatedISchemaLen
(
SSchema
*
pSchema
)
{
size_t
colNameLen
=
0
;
for
(
size_t
i
=
0
;
i
<
TD_SCHEMA_NCOLS
(
pSchema
);
i
++
)
{
colNameLen
+=
(
strlen
(
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
)))
+
1
);
}
for
(
size_t
i
=
0
;
i
<
TD_SCHEMA_NCOLS
(
pSchema
);
i
++
)
{
colNameLen
+=
(
strlen
(
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
)))
+
1
);
}
return
TD_ISCHEMA_HEADER_SIZE
+
(
size_t
)
TD_SCHEMA_TOTAL_COLS
(
pSchema
)
+
colNameLen
;
}
SISchema
tdConvertSchemaToInline
(
SSchema
*
pSchema
)
{
size_t
len
=
tdGetEstimatedISchemaLen
(
pSchema
);
int32_t
totalCols
=
TD_SCHEMA_TOTAL_COLS
(
pSchema
);
// TODO: if use pISchema is reasonable?
SISchema
pISchema
=
malloc
(
len
);
if
(
pSchema
==
NULL
)
{
// TODO: add error handling
return
NULL
;
}
TD_ISCHEMA_LEN
(
pISchema
)
=
(
int32_t
)
len
;
memcpy
((
void
*
)
TD_ISCHEMA_SCHEMA
(
pISchema
),
(
void
*
)
pSchema
,
sizeof
(
SSchema
));
TD_SCHEMA_COLS
(
TD_ISCHEMA_SCHEMA
(
pISchema
))
=
(
SColumn
*
)(
pISchema
+
TD_ISCHEMA_HEADER_SIZE
);
memcpy
((
void
*
)
TD_SCHEMA_COLS
(
TD_ISCHEMA_SCHEMA
(
pISchema
)),
(
void
*
)
TD_SCHEMA_COLS
(
pSchema
),
sizeof
(
SColumn
)
*
totalCols
);
char
*
pName
=
TD_ISCHEMA_COL_NAMES
(
pISchema
);
for
(
int32_t
i
=
0
;
i
<
totalCols
;
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
TD_ISCHEMA_SCHEMA
(
pISchema
),
i
);
char
*
colName
=
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
),
i
);
TD_COLUMN_NAME
(
pCol
)
=
pName
;
size_t
tlen
=
strlen
(
colName
)
+
1
;
memcpy
((
void
*
)
pName
,
(
void
*
)
colName
,
tlen
);
pName
+=
tlen
;
}
return
pISchema
;
}
int32_t
tdGetColumnIdxByName
(
SSchema
*
pSchema
,
char
*
colName
)
{
for
(
int32_t
i
=
0
;
i
<
TD_SCHEMA_TOTAL_COLS
(
pSchema
);
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
);
if
(
strcmp
(
colName
,
TD_COLUMN_NAME
(
pCol
))
==
0
)
{
return
i
;
}
}
return
-
1
;
}
int32_t
tdGetColumnIdxById
(
SSchema
*
pSchema
,
int32_t
colId
)
{
for
(
int32_t
i
=
0
;
i
<
TD_SCHEMA_TOTAL_COLS
(
pSchema
);
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
);
if
(
TD_COLUMN_ID
(
pCol
)
==
colId
)
{
return
i
;
}
}
return
-
1
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录