Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KASAKI11
TDengine
提交
760b66e5
T
TDengine
项目概览
KASAKI11
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
760b66e5
编写于
6月 01, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor and rename
上级
c1e9959b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
117 deletion
+118
-117
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+49
-47
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+69
-70
未找到文件。
src/common/inc/tdataformat.h
浏览文件 @
760b66e5
...
...
@@ -27,19 +27,24 @@
extern
"C"
{
#endif
#define STR_TO_VARSTR(x, str) do {VarDataLenT __len = strlen(str); \
*(VarDataLenT*)(x) = __len; \
strncpy(varDataVal(x), (str), __len);} while(0);
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) do {\
char* _e = stpncpy(varDataVal(x), (str), (_maxs));\
varDataSetLen(x, (_e - (x) - VARSTR_HEADER_SIZE));\
} while(0)
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) do {\
*(VarDataLenT*)(x) = (_size); \
strncpy(varDataVal(x), (str), (_size));\
} while(0);
#define STR_TO_VARSTR(x, str) \
do { \
VarDataLenT __len = strlen(str); \
*(VarDataLenT *)(x) = __len; \
strncpy(varDataVal(x), (str), __len); \
} while (0);
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
do { \
char *_e = stpncpy(varDataVal(x), (str), (_maxs)); \
varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE)); \
} while (0)
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \
do { \
*(VarDataLenT *)(x) = (_size); \
strncpy(varDataVal(x), (str), (_size)); \
} while (0);
// ----------------- TSDB COLUMN DEFINITION
typedef
struct
{
...
...
@@ -73,9 +78,9 @@ typedef struct {
#define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen)
#define schemaColAt(s, i) ((s)->columns + i)
#define tdFreeSchema(s) tfree((s))
STSchema
*
tdNewSchema
(
int32_t
nCols
);
#define tdFreeSchema(s) tfree((s))
int
tdSchemaAddCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
);
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
int
tdGetSchemaEncodeSize
(
STSchema
*
pSchema
);
...
...
@@ -189,12 +194,11 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
}
}
typedef
struct
{
int
maxRowSize
;
int
maxCols
;
// max number of columns
int
maxPoints
;
// max number of points
int
bufSize
;
int
maxRowSize
;
int
maxCols
;
// max number of columns
int
maxPoints
;
// max number of points
int
bufSize
;
int
numOfRows
;
int
numOfCols
;
// Total number of cols
...
...
@@ -214,11 +218,10 @@ void tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
SDataCols
*
tdDupDataCols
(
SDataCols
*
pCols
,
bool
keepData
);
void
tdFreeDataCols
(
SDataCols
*
pCols
);
void
tdAppendDataRowToDataCol
(
SDataRow
row
,
SDataCols
*
pCols
);
void
tdPopDataColsPoints
(
SDataCols
*
pCols
,
int
pointsToPop
);
//!!!!
void
tdPopDataColsPoints
(
SDataCols
*
pCols
,
int
pointsToPop
);
//!!!!
int
tdMergeDataCols
(
SDataCols
*
target
,
SDataCols
*
src
,
int
rowsToMerge
);
void
tdMergeTwoDataCols
(
SDataCols
*
target
,
SDataCols
*
src1
,
int
*
iter1
,
SDataCols
*
src2
,
int
*
iter2
,
int
tRows
);
// ----------------- K-V data row structure
/*
* +----------+----------+---------------------------------+---------------------------------+
...
...
@@ -227,29 +230,29 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SD
* | len | ncols | cols index | data part |
* +----------+----------+---------------------------------+---------------------------------+
*/
typedef
void
*
SKV
Data
Row
;
typedef
void
*
SKVRow
;
typedef
struct
{
int16_t
colId
;
int16_t
offset
;
}
SColIdx
;
#define TD_KV_
DATA_ROW_HEAD_SIZE 2*
sizeof(int16_t)
#define TD_KV_
ROW_HEAD_SIZE 2 *
sizeof(int16_t)
#define kv
Data
RowLen(r) (*(int16_t *)(r))
#define kv
Data
RowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)))
#define kv
DataRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_DATA
_ROW_HEAD_SIZE)
#define kv
DataRowValues(r) POINTER_SHIFT(r, TD_KV_DATA_ROW_HEAD_SIZE + sizeof(SColIdx) * kvData
RowNCols(r))
#define kv
DataRowCpy(dst, r) memcpy((dst), (r), kvData
RowLen(r))
#define kv
DataRowColVal(r, colIdx) POINTER_SHIFT(kvData
RowValues(r), (colIdx)->offset)
#define kv
DataRowSetLen(r, len) kvData
RowLen(r) = (len)
#define kv
DataRowSetNCols(r, n) kvData
RowNCols(r) = (n)
#define kv
DataRowColIdxAt(r, i) (kvData
RowColIdx(r) + (i))
#define kvRowLen(r) (*(int16_t *)(r))
#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)))
#define kv
RowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV
_ROW_HEAD_SIZE)
#define kv
RowValues(r) POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * kv
RowNCols(r))
#define kv
RowCpy(dst, r) memcpy((dst), (r), kv
RowLen(r))
#define kv
RowColVal(r, colIdx) POINTER_SHIFT(kv
RowValues(r), (colIdx)->offset)
#define kv
RowSetLen(r, len) kv
RowLen(r) = (len)
#define kv
RowSetNCols(r, n) kv
RowNCols(r) = (n)
#define kv
RowColIdxAt(r, i) (kv
RowColIdx(r) + (i))
SKV
DataRow
tdKVDataRowDup
(
SKVData
Row
row
);
SKV
DataRow
tdSetKVRowDataOfCol
(
SKVData
Row
row
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
void
*
tdEncodeKVDataRow
(
void
*
buf
,
SKVData
Row
row
);
void
*
tdDecodeKVDataRow
(
void
*
buf
,
SKVData
Row
*
row
);
SKV
Row
tdKVRowDup
(
SKV
Row
row
);
SKV
Row
tdSetKVRowDataOfCol
(
SKV
Row
row
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
void
*
tdEncodeKVRow
(
void
*
buf
,
SKV
Row
row
);
void
*
tdDecodeKVRow
(
void
*
buf
,
SKV
Row
*
row
);
static
FORCE_INLINE
int
comparTagId
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
int16_t
*
)
key1
>
((
SColIdx
*
)
key2
)
->
colId
)
{
...
...
@@ -261,10 +264,10 @@ static FORCE_INLINE int comparTagId(const void *key1, const void *key2) {
}
}
static
FORCE_INLINE
void
*
tdGetKVRowDataOfCol
(
SKV
Data
Row
row
,
int16_t
colId
)
{
void
*
ret
=
taosbsearch
(
&
colId
,
kv
DataRowColIdx
(
row
),
kvData
RowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_EQ
);
static
FORCE_INLINE
void
*
tdGetKVRowDataOfCol
(
SKVRow
row
,
int16_t
colId
)
{
void
*
ret
=
taosbsearch
(
&
colId
,
kv
RowColIdx
(
row
),
kv
RowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_EQ
);
if
(
ret
==
NULL
)
return
NULL
;
return
kv
Data
RowColVal
(
row
,
(
SColIdx
*
)
ret
);
return
kvRowColVal
(
row
,
(
SColIdx
*
)
ret
);
}
// ----------------- K-V data row builder
...
...
@@ -275,19 +278,19 @@ typedef struct {
int16_t
alloc
;
int16_t
size
;
void
*
buf
;
}
SKV
Data
RowBuilder
;
}
SKVRowBuilder
;
int
tdInitKVDataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
);
void
tdDestroyKVDataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
);
void
tdResetKVDataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
);
SKV
DataRow
tdGetKVDataRowFromBuilder
(
SKVData
RowBuilder
*
pBuilder
);
int
tdAddColToKVDataRow
(
SKVData
RowBuilder
*
pBuilder
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
int
tdInitKVRowBuilder
(
SKV
RowBuilder
*
pBuilder
);
void
tdDestroyKVRowBuilder
(
SKV
RowBuilder
*
pBuilder
);
void
tdResetKVRowBuilder
(
SKV
RowBuilder
*
pBuilder
);
SKV
Row
tdGetKVRowFromBuilder
(
SKV
RowBuilder
*
pBuilder
);
int
tdAddColToKVRow
(
SKV
RowBuilder
*
pBuilder
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
// ----------------- Tag row structure
/* A tag row, the format is like below:
+----------+----------------------------------------------------------------+
| STagRow | STagCol | STagCol | STagCol | STagCol | ...| STagCol | STagCol |
| STagRow | STagCol | STagCol | STagCol | STagCol | ...| STagCol | STagCol |
+----------+----------------------------------------------------------------+
pData
...
...
@@ -297,7 +300,6 @@ pData
*/
#define TD_TAG_ROW_HEAD_SIZE sizeof(int16_t)
#define tagRowNum(r) (*(int16_t *)(r))
...
...
src/common/src/tdataformat.c
浏览文件 @
760b66e5
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdataformat.h"
#include "wchar.h"
#include "talgo.h"
#include "wchar.h"
/**
* Create a SSchema object with nCols columns
...
...
@@ -51,13 +51,13 @@ int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes)
if
(
schemaNCols
(
pSchema
)
==
0
)
{
colSetOffset
(
pCol
,
0
);
}
else
{
STColumn
*
pTCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
)
-
1
);
STColumn
*
pTCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
)
-
1
);
colSetOffset
(
pCol
,
pTCol
->
offset
+
TYPE_BYTES
[
pTCol
->
type
]);
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
colSetBytes
(
pCol
,
bytes
);
// Set as maximum bytes
colSetBytes
(
pCol
,
bytes
);
// Set as maximum bytes
pSchema
->
tlen
+=
(
TYPE_BYTES
[
type
]
+
sizeof
(
VarDataLenT
)
+
bytes
);
break
;
default:
...
...
@@ -152,17 +152,18 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
return
row
;
}
int
tdSetTagCol
(
SDataRow
row
,
void
*
value
,
int16_t
len
,
int8_t
type
,
int16_t
colId
){
//insert/update tag value and update all the information
int
tdSetTagCol
(
SDataRow
row
,
void
*
value
,
int16_t
len
,
int8_t
type
,
int16_t
colId
)
{
// insert/update tag value and update all the information
ASSERT
(((
STagRow
*
)
row
)
->
pData
!=
NULL
);
//STagCol * stCol = tdQueryTagColByID()
//
STagCol * stCol = tdQueryTagColByID()
return
0
;
};
};
int
tdDeleteTagCol
(
SDataRow
row
,
int16_t
colId
)
{
// delete tag value and update all the information
//todo
int
tdDeleteTagCol
(
SDataRow
row
,
int16_t
colId
)
{
// delete tag value and update all the information
//
todo
return
0
;
};
};
static
int
compTagId
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(((
STagCol
*
)
key1
)
->
colId
>
((
STagCol
*
)
key2
)
->
colId
)
{
...
...
@@ -177,43 +178,43 @@ static int compTagId(const void *key1, const void *key2) {
/**
* Find tag structure by colId, if find, return tag structure, else return NULL;
*/
STagCol
*
tdQueryTagColByID
(
SDataRow
row
,
int16_t
colId
,
int
flags
)
{
//if find tag, 0, else return -1;
STagCol
*
tdQueryTagColByID
(
SDataRow
row
,
int16_t
colId
,
int
flags
)
{
// if find tag, 0, else return -1;
ASSERT
(((
STagRow
*
)
row
)
->
pData
!=
NULL
);
STagCol
*
pBase
=
((
STagRow
*
)
row
)
->
tagCols
;
int16_t
nCols
=
((
STagRow
*
)
row
)
->
ncols
;
STagCol
key
=
{
colId
,
0
,
0
};
STagCol
*
stCol
=
taosbsearch
(
&
key
,
pBase
,
nCols
,
sizeof
(
STagCol
),
compTagId
,
flags
);
int16_t
nCols
=
((
STagRow
*
)
row
)
->
ncols
;
STagCol
key
=
{
colId
,
0
,
0
};
STagCol
*
stCol
=
taosbsearch
(
&
key
,
pBase
,
nCols
,
sizeof
(
STagCol
),
compTagId
,
flags
);
return
stCol
;
};
};
/**
* Find tag value by colId, if find, return tag value, else return NULL;
*/
void
*
tdQueryTagByID
(
SDataRow
row
,
int16_t
colId
,
int16_t
*
type
)
{
* Find tag value by colId, if find, return tag value, else return NULL;
*/
void
*
tdQueryTagByID
(
SDataRow
row
,
int16_t
colId
,
int16_t
*
type
)
{
ASSERT
(((
STagRow
*
)
row
)
->
pData
!=
NULL
);
STagCol
*
pBase
=
((
STagRow
*
)
row
)
->
tagCols
;
int16_t
nCols
=
((
STagRow
*
)
row
)
->
ncols
;
STagCol
key
=
{
colId
,
0
,
0
};
STagCol
*
stCol
=
taosbsearch
(
&
key
,
pBase
,
nCols
,
sizeof
(
STagCol
),
compTagId
,
TD_EQ
);
int16_t
nCols
=
((
STagRow
*
)
row
)
->
ncols
;
STagCol
key
=
{
colId
,
0
,
0
};
STagCol
*
stCol
=
taosbsearch
(
&
key
,
pBase
,
nCols
,
sizeof
(
STagCol
),
compTagId
,
TD_EQ
);
if
(
NULL
==
stCol
)
{
return
NULL
;
}
void
*
pData
=
((
STagRow
*
)
row
)
->
pData
;
void
*
pData
=
((
STagRow
*
)
row
)
->
pData
;
*
type
=
stCol
->
colType
;
return
pData
+
stCol
->
offset
;
};
};
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int16_t
colId
){
int
tdAppendTagColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int16_t
colId
)
{
ASSERT
(
value
!=
NULL
);
//ASSERT(bytes-2 == varDataTLen(value));
//
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
:
...
...
@@ -224,14 +225,14 @@ int tdAppendTagColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int
memcpy
((
char
*
)
pTagrow
->
pData
+
pTagrow
->
dataLen
,
value
,
TYPE_BYTES
[
type
]);
pTagrow
->
dataLen
+=
TYPE_BYTES
[
type
];
break
;
}
pTagrow
->
ncols
++
;
}
pTagrow
->
ncols
++
;
return
0
;
};
};
void
*
tdNewTagRowFromSchema
(
STSchema
*
pSchema
,
int16_t
numofTags
)
{
void
*
tdNewTagRowFromSchema
(
STSchema
*
pSchema
,
int16_t
numofTags
)
{
int32_t
size
=
sizeof
(
STagRow
)
+
numofTags
*
sizeof
(
STagCol
);
STagRow
*
row
=
malloc
(
size
);
...
...
@@ -245,25 +246,25 @@ void * tdNewTagRowFromSchema(STSchema *pSchema, int16_t numofTags) {
}
row
->
len
=
size
;
row
->
dataLen
=
0
;
row
->
ncols
=
0
;
return
row
;
row
->
dataLen
=
0
;
row
->
ncols
=
0
;
return
row
;
}
/**
* free tag 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
)
{
...
...
@@ -277,23 +278,23 @@ SDataRow tdTagRowDup(SDataRow row) {
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
);
char
*
pData
=
(
char
*
)
row
+
dataRowLen
(
row
);
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
);
void
*
pData
=
dst
+
dataRowLen
(
src
);
memcpy
(
pData
,
((
STagRow
*
)
src
)
->
pData
,
((
STagRow
*
)
src
)
->
dataLen
);
return
0
;
}
...
...
@@ -330,7 +331,6 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints)
pDataCol
->
pData
=
*
pBuf
;
*
pBuf
=
POINTER_SHIFT
(
*
pBuf
,
pDataCol
->
spaceSize
);
}
}
void
dataColAppendVal
(
SDataCol
*
pCol
,
void
*
value
,
int
numOfRows
,
int
maxPoints
)
{
...
...
@@ -414,7 +414,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
void
dataColSetOffset
(
SDataCol
*
pCol
,
int
nEle
)
{
ASSERT
(((
pCol
->
type
==
TSDB_DATA_TYPE_BINARY
)
||
(
pCol
->
type
==
TSDB_DATA_TYPE_NCHAR
)));
void
*
tptr
=
pCol
->
pData
;
void
*
tptr
=
pCol
->
pData
;
// char *tptr = (char *)(pCol->pData);
VarDataOffsetT
offset
=
0
;
...
...
@@ -596,26 +596,25 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCol
}
}
SKV
DataRow
tdKVDataRowDup
(
SKVData
Row
row
)
{
SKV
DataRow
trow
=
malloc
(
kvData
RowLen
(
row
));
SKV
Row
tdKVRowDup
(
SKV
Row
row
)
{
SKV
Row
trow
=
malloc
(
kv
RowLen
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
kv
Data
RowCpy
(
trow
,
row
);
kvRowCpy
(
trow
,
row
);
return
trow
;
}
SKV
DataRow
tdSetKVRowDataOfCol
(
SKVData
Row
row
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
SKV
Row
tdSetKVRowDataOfCol
(
SKV
Row
row
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
// TODO
return
NULL
;
// SColIdx *pColIdx = NULL;
// SKV
Data
Row rrow = row;
// SKV
Data
Row nrow = NULL;
// SKVRow rrow = row;
// SKVRow nrow = NULL;
// void *ptr = taosbsearch(&colId, kvDataRowColIdx(row), kvDataRowNCols(row), sizeof(SColIdx), comparTagId, TD_GE);
// if (ptr == NULL || ((SColIdx *)ptr)->colId < colId) { // need to add a column value to the row
// int tlen = kvDataRowLen(row) + sizeof(SColIdx) + (IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type]);
// nrow = malloc(tlen);
// if (nrow == NULL) return NULL;
// int tlen = kvDataRowLen(row) + sizeof(SColIdx) + (IS_VAR_DATA_TYPE(type) ? varDataTLen(value) :
// TYPE_BYTES[type]); nrow = malloc(tlen); if (nrow == NULL) return NULL;
// kvDataRowSetNCols(nrow, kvDataRowNCols(row)+1);
// kvDataRowSetLen(nrow, tlen);
...
...
@@ -670,18 +669,18 @@ SKVDataRow tdSetKVRowDataOfCol(SKVDataRow row, int16_t colId, int8_t type, void
// return rrow;
}
void
*
tdEncodeKV
DataRow
(
void
*
buf
,
SKVData
Row
row
)
{
void
*
tdEncodeKV
Row
(
void
*
buf
,
SKV
Row
row
)
{
// May change the encode purpose
kv
Data
RowCpy
(
buf
,
row
);
return
POINTER_SHIFT
(
buf
,
kv
Data
RowLen
(
row
));
kvRowCpy
(
buf
,
row
);
return
POINTER_SHIFT
(
buf
,
kvRowLen
(
row
));
}
void
*
tdDecodeKV
DataRow
(
void
*
buf
,
SKVData
Row
*
row
)
{
*
row
=
tdKV
Data
RowDup
(
buf
);
return
POINTER_SHIFT
(
buf
,
kv
Data
RowLen
(
*
row
));
void
*
tdDecodeKV
Row
(
void
*
buf
,
SKV
Row
*
row
)
{
*
row
=
tdKVRowDup
(
buf
);
return
POINTER_SHIFT
(
buf
,
kvRowLen
(
*
row
));
}
int
tdInitKV
DataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
)
{
int
tdInitKV
RowBuilder
(
SKV
RowBuilder
*
pBuilder
)
{
pBuilder
->
tCols
=
128
;
pBuilder
->
nCols
=
0
;
pBuilder
->
pColIdx
=
(
SColIdx
*
)
malloc
(
sizeof
(
SColIdx
)
*
pBuilder
->
tCols
);
...
...
@@ -696,33 +695,33 @@ int tdInitKVDataRowBuilder(SKVDataRowBuilder *pBuilder) {
return
0
;
}
void
tdDestroyKV
DataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
)
{
void
tdDestroyKV
RowBuilder
(
SKV
RowBuilder
*
pBuilder
)
{
tfree
(
pBuilder
->
pColIdx
);
tfree
(
pBuilder
->
buf
);
}
void
tdResetKV
DataRowBuilder
(
SKVData
RowBuilder
*
pBuilder
)
{
void
tdResetKV
RowBuilder
(
SKV
RowBuilder
*
pBuilder
)
{
pBuilder
->
nCols
=
0
;
pBuilder
->
size
=
0
;
}
SKV
DataRow
tdGetKVDataRowFromBuilder
(
SKVData
RowBuilder
*
pBuilder
)
{
SKV
Row
tdGetKVRowFromBuilder
(
SKV
RowBuilder
*
pBuilder
)
{
int
tlen
=
sizeof
(
SColIdx
)
*
pBuilder
->
nCols
+
pBuilder
->
size
;
if
(
tlen
==
0
)
return
NULL
;
SKV
DataRow
row
=
malloc
(
TD_KV_DATA
_ROW_HEAD_SIZE
+
tlen
);
SKV
Row
row
=
malloc
(
TD_KV
_ROW_HEAD_SIZE
+
tlen
);
if
(
row
==
NULL
)
return
NULL
;
kv
Data
RowSetNCols
(
row
,
pBuilder
->
nCols
);
kv
DataRowSetLen
(
row
,
TD_KV_DATA
_ROW_HEAD_SIZE
+
tlen
);
kvRowSetNCols
(
row
,
pBuilder
->
nCols
);
kv
RowSetLen
(
row
,
TD_KV
_ROW_HEAD_SIZE
+
tlen
);
memcpy
(
kv
Data
RowColIdx
(
row
),
pBuilder
->
pColIdx
,
sizeof
(
SColIdx
)
*
pBuilder
->
nCols
);
memcpy
(
kv
Data
RowValues
(
row
),
pBuilder
->
buf
,
pBuilder
->
size
);
memcpy
(
kvRowColIdx
(
row
),
pBuilder
->
pColIdx
,
sizeof
(
SColIdx
)
*
pBuilder
->
nCols
);
memcpy
(
kvRowValues
(
row
),
pBuilder
->
buf
,
pBuilder
->
size
);
return
row
;
}
int
tdAddColToKV
DataRow
(
SKVData
RowBuilder
*
pBuilder
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
int
tdAddColToKV
Row
(
SKV
RowBuilder
*
pBuilder
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
ASSERT
(
pBuilder
->
nCols
==
0
||
colId
>
pBuilder
->
pColIdx
[
pBuilder
->
nCols
-
1
].
colId
);
if
(
pBuilder
->
nCols
>=
pBuilder
->
tCols
)
{
...
...
@@ -733,7 +732,7 @@ int tdAddColToKVDataRow(SKVDataRowBuilder *pBuilder, int16_t colId, int8_t type,
pBuilder
->
pColIdx
[
pBuilder
->
nCols
].
colId
=
colId
;
pBuilder
->
pColIdx
[
pBuilder
->
nCols
].
offset
=
pBuilder
->
size
;
pBuilder
->
nCols
++
;
int
tlen
=
IS_VAR_DATA_TYPE
(
type
)
?
varDataTLen
(
value
)
:
TYPE_BYTES
[
type
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录