Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
fbc50a3d
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看板
提交
fbc50a3d
编写于
5月 26, 2020
作者:
T
Tao Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-90] tag schema develop
上级
eb6b6e0c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
52 deletion
+158
-52
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+10
-7
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+118
-25
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+17
-11
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+9
-7
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+4
-2
未找到文件。
src/common/inc/tdataformat.h
浏览文件 @
fbc50a3d
...
...
@@ -226,13 +226,13 @@ pData
typedef
struct
{
int16_t
colId
;
// column ID
int16_t
colType
;
int16_t
colLen
;
// if col type is binary/Nchar, this is the length of binary/Nchar
int16_t
offset
;
//to store value for numeric col or offset for binary/Nchar
uint16_t
offset
;
//to store value for numeric col or offset for binary/Nchar
}
STagCol
;
typedef
struct
{
int32_t
len
;
int32_t
len
;
void
*
pData
;
// Space to store the tag value
uint16_t
dataLen
;
int16_t
ncols
;
// Total columns allocated
STagCol
tagCols
[];
}
STagRow
;
...
...
@@ -242,10 +242,13 @@ typedef struct {
int
tdInsertTagCol
(
SDataRow
row
,
void
*
value
,
int16_t
len
,
int8_t
type
,
int16_t
colId
);
//insert tag value and update all the information
int
tdDeleteTagCol
(
SDataRow
row
,
int16_t
colId
);
// delete tag value and update all the information
int
tdQuerTagByID
(
SDataRow
row
,
int16_t
colId
,
void
*
value
,
int16_t
*
type
,
int16_t
*
len
);
//if find tag, 0, else return -1;
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
);
SDataRow
tdNewTagRowFromSchema
(
STSchema
*
pSchema
);
void
*
tdQueryTagByID
(
SDataRow
row
,
int16_t
colId
,
int16_t
*
type
);
//if find tag, 0, else return -1;
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int16_t
colId
);
SDataRow
tdTagRowDup
(
SDataRow
row
);
void
tdFreeTagRow
(
SDataRow
row
);
SDataRow
tdTagRowDecode
(
SDataRow
row
);
int
tdTagRowCpy
(
SDataRow
dst
,
SDataRow
src
);
void
*
tdNewTagRowFromSchema
(
STSchema
*
pSchema
,
int16_t
numofTags
);
STSchema
*
tdGetSchemaFromData
(
SDataRow
*
row
);
#ifdef __cplusplus
...
...
src/common/src/tdataformat.c
浏览文件 @
fbc50a3d
...
...
@@ -14,6 +14,7 @@
*/
#include "tdataformat.h"
#include "wchar.h"
#include "talgo.h"
/**
* Create a SSchema object with nCols columns
...
...
@@ -152,25 +153,136 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
}
int
tdInsertTagCol
(
SDataRow
row
,
void
*
value
,
int16_t
len
,
int8_t
type
,
int16_t
colId
){
//insert tag value and update all the information
//todo
return
0
;
};
int
tdDeleteTagCol
(
SDataRow
row
,
int16_t
colId
){
// delete tag value and update all the information
return
o
;
//todo
return
0
;
};
int
tdQuerTagByID
(
SDataRow
row
,
int16_t
colId
,
void
*
value
,
int16_t
*
type
,
int16_t
*
len
){
//if find tag, 0, else return -1;
return
0
;
static
int
compTagVal
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
int16_t
*
)
key1
>
*
(
int16_t
*
)
key2
)
{
return
1
;
}
else
if
(
*
(
int16_t
*
)
key1
==
*
(
int16_t
*
)
key2
)
{
return
0
;
}
else
{
return
-
1
;
}
}
void
*
tdQueryTagByID
(
SDataRow
row
,
int16_t
colId
,
int16_t
*
type
)
{
//if find tag, 0, else return -1;
//todo
ASSERT
(((
STagRow
*
)
row
)
->
pData
!=
NULL
);
STagCol
*
pBase
=
((
STagRow
*
)
row
)
->
tagCols
;
int16_t
nCols
=
((
STagRow
*
)
row
)
->
ncols
;
STagCol
*
stCol
=
taosbsearch
(
&
colId
,
pBase
,
nCols
,
sizeof
(
STagCol
),
compTagVal
,
TD_EQ
);
if
(
NULL
==
stCol
)
{
return
NULL
;
}
void
*
pData
=
((
STagRow
*
)
row
)
->
pData
;
*
type
=
stCol
->
colType
;
return
pData
+
stCol
->
offset
;
};
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
){
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int16_t
colId
){
ASSERT
(
value
!=
NULL
);
//ASSERT(bytes-2 == varDataTLen(value));
ASSERT
(
row
!=
NULL
);
STagRow
*
pTagrow
=
row
;
pTagrow
->
tagCols
[
pTagrow
->
ncols
].
colId
=
colId
;
pTagrow
->
tagCols
[
pTagrow
->
ncols
].
colType
=
type
;
pTagrow
->
tagCols
[
pTagrow
->
ncols
].
offset
=
pTagrow
->
dataLen
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
memcpy
((
char
*
)
pTagrow
->
pData
+
pTagrow
->
dataLen
,
value
,
varDataTLen
(
value
));
pTagrow
->
dataLen
+=
varDataTLen
(
value
);
break
;
default:
memcpy
((
char
*
)
pTagrow
->
pData
+
pTagrow
->
dataLen
,
value
,
TYPE_BYTES
[
type
]);
pTagrow
->
dataLen
+=
TYPE_BYTES
[
type
];
break
;
}
pTagrow
->
ncols
++
;
return
0
;
};
SDataRow
tdNewTagRowFromSchema
(
STSchema
*
pSchema
)
{
//todo
void
*
tdNewTagRowFromSchema
(
STSchema
*
pSchema
,
int16_t
numofTags
)
{
int32_t
size
=
sizeof
(
STagRow
)
+
numofTags
*
sizeof
(
STagCol
);
STagRow
*
row
=
malloc
(
size
);
if
(
row
==
NULL
)
return
NULL
;
int32_t
datasize
=
pSchema
->
tlen
-
pSchema
->
flen
;
row
->
pData
=
malloc
(
datasize
);
if
(
NULL
==
row
->
pData
)
{
free
(
row
);
return
NULL
;
}
row
->
len
=
size
;
row
->
dataLen
=
0
;
row
->
ncols
=
0
;
return
row
;
}
/**
* free tag row
*/
void
tdFreeTagRow
(
SDataRow
row
)
{
if
(
row
)
{
free
(((
STagRow
*
)
row
)
->
pData
);
free
(
row
);
}
}
SDataRow
tdTagRowDup
(
SDataRow
row
)
{
STagRow
*
trow
=
malloc
(
dataRowLen
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
dataRowCpy
(
trow
,
row
);
trow
->
pData
=
malloc
(
trow
->
dataLen
);
if
(
NULL
==
trow
->
pData
)
{
free
(
trow
);
return
NULL
;
}
memcpy
(
trow
->
pData
,
((
STagRow
*
)
row
)
->
pData
,
trow
->
dataLen
);
return
trow
;
}
SDataRow
tdTagRowDecode
(
SDataRow
row
)
{
STagRow
*
trow
=
malloc
(
dataRowLen
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
dataRowCpy
(
trow
,
row
);
trow
->
pData
=
malloc
(
trow
->
dataLen
);
if
(
NULL
==
trow
->
pData
)
{
free
(
trow
);
return
NULL
;
}
char
*
pData
=
(
char
*
)
row
+
dataRowLen
(
row
)
+
sizeof
(
int32_t
);
memcpy
(
trow
->
pData
,
pData
,
trow
->
dataLen
);
return
trow
;
}
int
tdTagRowCpy
(
SDataRow
dst
,
SDataRow
src
)
{
if
(
src
==
NULL
)
return
-
1
;
dataRowCpy
(
dst
,
src
);
void
*
pData
=
dst
+
dataRowLen
(
src
);
memcpy
(
pData
,
((
STagRow
*
)
src
)
->
pData
,
((
STagRow
*
)
src
)
->
dataLen
);
return
0
;
}
/**
* Free the SDataRow object
*/
...
...
@@ -203,25 +315,6 @@ int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_
return
0
;
}
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int32_t
offset
)
{
ASSERT
(
value
!=
NULL
);
int32_t
toffset
=
offset
+
TD_DATA_ROW_HEAD_SIZE
;
char
*
ptr
=
POINTER_SHIFT
(
row
,
dataRowLen
(
row
));
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
row
,
toffset
)
=
dataRowLen
(
row
);
memcpy
(
ptr
,
value
,
varDataTLen
(
value
));
dataRowLen
(
row
)
+=
varDataTLen
(
value
);
break
;
default:
memcpy
(
POINTER_SHIFT
(
row
,
toffset
),
value
,
TYPE_BYTES
[
type
]);
break
;
}
return
0
;
}
SDataRow
tdDataRowDup
(
SDataRow
row
)
{
SDataRow
trow
=
malloc
(
dataRowLen
(
row
));
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
fbc50a3d
...
...
@@ -54,7 +54,7 @@ void *tsdbEncodeTable(STable *pTable, int *contLen) {
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
tagSchema
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
data
RowCpy
(
ptr
,
pTable
->
tagVal
);
tdTag
RowCpy
(
ptr
,
pTable
->
tagVal
);
}
else
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
}
...
...
@@ -96,7 +96,7 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
pTable
->
tagSchema
=
tdDecodeSchema
(
&
ptr
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
pTable
->
tagVal
=
td
DataRowDup
(
ptr
);
pTable
->
tagVal
=
td
TagRowDecode
(
ptr
);
}
else
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
}
...
...
@@ -114,8 +114,10 @@ static char* getTagIndexKey(const void* pData) {
SDataRow
row
=
elem
->
pTable
->
tagVal
;
STSchema
*
pSchema
=
tsdbGetTableTagSchema
(
elem
->
pMeta
,
elem
->
pTable
);
STColumn
*
pCol
=
&
pSchema
->
columns
[
DEFAULT_TAG_INDEX_COLUMN
];
return
tdGetRowDataOfCol
(
row
,
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
int16_t
type
=
0
;
void
*
res
=
tdQueryTagByID
(
row
,
pCol
->
colId
,
&
type
);
ASSERT
(
type
==
pCol
->
type
);
return
res
;
}
int
tsdbRestoreTable
(
void
*
pHandle
,
void
*
cont
,
int
contLen
)
{
...
...
@@ -255,8 +257,9 @@ int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t
}
SDataRow
row
=
(
SDataRow
)
pTable
->
tagVal
;
char
*
d
=
tdGetRowDataOfCol
(
row
,
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
int16_t
tagtype
=
0
;
char
*
d
=
tdQueryTagByID
(
row
,
pCol
->
colId
,
&
tagtype
);
//ASSERT((int8_t)tagtype == pCol->type)
*
val
=
d
;
*
type
=
pCol
->
type
;
*
bytes
=
pCol
->
bytes
;
...
...
@@ -321,7 +324,7 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) {
if
(
super
->
pIndex
==
NULL
)
{
tdFreeSchema
(
super
->
schema
);
tdFreeSchema
(
super
->
tagSchema
);
tdFree
Data
Row
(
super
->
tagVal
);
tdFree
Tag
Row
(
super
->
tagVal
);
free
(
super
);
return
-
1
;
}
...
...
@@ -346,7 +349,7 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) {
if
(
IS_CREATE_STABLE
(
pCfg
))
{
// TSDB_CHILD_TABLE
table
->
type
=
TSDB_CHILD_TABLE
;
table
->
superUid
=
pCfg
->
superUid
;
table
->
tagVal
=
td
Data
RowDup
(
pCfg
->
tagValues
);
table
->
tagVal
=
td
Tag
RowDup
(
pCfg
->
tagValues
);
}
else
{
// TSDB_NORMAL_TABLE
table
->
type
=
TSDB_NORMAL_TABLE
;
table
->
superUid
=
-
1
;
...
...
@@ -433,7 +436,7 @@ static void tsdbFreeMemTable(SMemTable *pMemTable) {
static
int
tsdbFreeTable
(
STable
*
pTable
)
{
// TODO: finish this function
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
tdFree
Data
Row
(
pTable
->
tagVal
);
tdFree
Tag
Row
(
pTable
->
tagVal
);
}
else
{
tdFreeSchema
(
pTable
->
schema
);
}
...
...
@@ -571,7 +574,9 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
STSchema
*
pSchema
=
tsdbGetTableTagSchema
(
pMeta
,
pTable
);
STColumn
*
pCol
=
&
pSchema
->
columns
[
DEFAULT_TAG_INDEX_COLUMN
];
char
*
key
=
tdGetRowDataOfCol
(
pTable
->
tagVal
,
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
int16_t
tagtype
=
0
;
char
*
key
=
tdQueryTagByID
(
pTable
->
tagVal
,
pCol
->
colId
,
&
tagtype
);
ASSERT
(
pCol
->
type
==
tagtype
);
SArray
*
res
=
tSkipListGet
(
pSTable
->
pIndex
,
key
);
size_t
size
=
taosArrayGetSize
(
res
);
...
...
@@ -602,7 +607,8 @@ static int tsdbEstimateTableEncodeSize(STable *pTable) {
size
+=
tdGetSchemaEncodeSize
(
pTable
->
schema
);
size
+=
tdGetSchemaEncodeSize
(
pTable
->
tagSchema
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
size
+=
dataRowLen
(
pTable
->
tagVal
);
STagRow
*
pTagRow
=
(
STagRow
*
)(
pTable
->
tagVal
);
size
+=
dataRowLen
(
pTable
->
tagVal
)
+
pTagRow
->
dataLen
;
}
else
{
size
+=
tdGetSchemaEncodeSize
(
pTable
->
schema
);
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
fbc50a3d
...
...
@@ -1746,9 +1746,9 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
STColumn
*
pCol
=
schemaColAt
(
pTableGroupSupp
->
pTagSchema
,
colIndex
);
bytes
=
pCol
->
bytes
;
type
=
pCol
->
type
;
f1
=
td
GetRowDataOfCol
(
pTable1
->
tagVal
,
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
f2
=
td
GetRowDataOfCol
(
pTable2
->
tagVal
,
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
int16_t
tgtype1
,
tgtype2
=
0
;
f1
=
td
QueryTagByID
(
pTable1
->
tagVal
,
pCol
->
colId
,
&
tgtype1
);
f2
=
td
QueryTagByID
(
pTable2
->
tagVal
,
pCol
->
colId
,
&
tgtype2
);
}
int32_t
ret
=
doCompare
(
f1
,
f2
,
type
,
bytes
);
...
...
@@ -1836,10 +1836,12 @@ bool indexedNodeFilterFp(const void* pNode, void* param) {
val
=
(
char
*
)
elem
->
pTable
->
name
;
type
=
TSDB_DATA_TYPE_BINARY
;
}
else
{
STSchema
*
pTSchema
=
(
STSchema
*
)
pInfo
->
param
;
// todo table schema is identical to stable schema??
int32_t
offset
=
pTSchema
->
columns
[
pInfo
->
colIndex
].
offset
;
val
=
tdGetRowDataOfCol
(
elem
->
pTable
->
tagVal
,
pInfo
->
sch
.
type
,
TD_DATA_ROW_HEAD_SIZE
+
offset
);
// STSchema* pTSchema = (STSchema*) pInfo->param; // todo table schema is identical to stable schema??
int16_t
type
;
// int32_t offset = pTSchema->columns[pInfo->colIndex].offset;
// val = tdGetRowDataOfCol(elem->pTable->tagVal, pInfo->sch.type, TD_DATA_ROW_HEAD_SIZE + offset);
val
=
tdQueryTagByID
(
elem
->
pTable
->
tagVal
,
pInfo
->
colIndex
,
&
type
);
// ASSERT(pInfo->sch.type == type);
}
int32_t
ret
=
0
;
...
...
src/vnode/src/vnodeWrite.c
浏览文件 @
fbc50a3d
...
...
@@ -139,11 +139,13 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
char
*
pTagData
=
pTable
->
data
+
totalCols
*
sizeof
(
SSchema
);
int
accumBytes
=
0
;
dataRow
=
tdNewDataRowFromSchema
(
pDestTagSchema
);
//dataRow = tdNewDataRowFromSchema(pDestTagSchema);
dataRow
=
tdNewTagRowFromSchema
(
pDestTagSchema
,
numOfTags
);
for
(
int
i
=
0
;
i
<
numOfTags
;
i
++
)
{
STColumn
*
pTCol
=
schemaColAt
(
pDestTagSchema
,
i
);
tdAppendColVal
(
dataRow
,
pTagData
+
accumBytes
,
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
offset
);
// tdAppendColVal(dataRow, pTagData + accumBytes, pTCol->type, pTCol->bytes, pTCol->offset);
tdAppendTagColVal
(
dataRow
,
pTagData
+
accumBytes
,
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
colId
);
accumBytes
+=
htons
(
pSchema
[
i
+
numOfColumns
].
bytes
);
}
tsdbTableSetTagValue
(
&
tCfg
,
dataRow
,
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录