提交 760b66e5 编写于 作者: H Hongze Cheng

refactor and rename

上级 c1e9959b
...@@ -27,19 +27,24 @@ ...@@ -27,19 +27,24 @@
extern "C" { extern "C" {
#endif #endif
#define STR_TO_VARSTR(x, str) do {VarDataLenT __len = strlen(str); \ #define STR_TO_VARSTR(x, str) \
*(VarDataLenT*)(x) = __len; \ do { \
strncpy(varDataVal(x), (str), __len);} while(0); VarDataLenT __len = strlen(str); \
*(VarDataLenT *)(x) = __len; \
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) do {\ strncpy(varDataVal(x), (str), __len); \
char* _e = stpncpy(varDataVal(x), (str), (_maxs));\ } while (0);
varDataSetLen(x, (_e - (x) - VARSTR_HEADER_SIZE));\
} while(0) #define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
do { \
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) do {\ char *_e = stpncpy(varDataVal(x), (str), (_maxs)); \
*(VarDataLenT*)(x) = (_size); \ varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE)); \
strncpy(varDataVal(x), (str), (_size));\ } while (0)
} 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 // ----------------- TSDB COLUMN DEFINITION
typedef struct { typedef struct {
...@@ -73,9 +78,9 @@ typedef struct { ...@@ -73,9 +78,9 @@ typedef struct {
#define schemaTLen(s) ((s)->tlen) #define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen) #define schemaFLen(s) ((s)->flen)
#define schemaColAt(s, i) ((s)->columns + i) #define schemaColAt(s, i) ((s)->columns + i)
#define tdFreeSchema(s) tfree((s))
STSchema *tdNewSchema(int32_t nCols); STSchema *tdNewSchema(int32_t nCols);
#define tdFreeSchema(s) tfree((s))
int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes); int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes);
STSchema *tdDupSchema(STSchema *pSchema); STSchema *tdDupSchema(STSchema *pSchema);
int tdGetSchemaEncodeSize(STSchema *pSchema); int tdGetSchemaEncodeSize(STSchema *pSchema);
...@@ -189,7 +194,6 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) { ...@@ -189,7 +194,6 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
} }
} }
typedef struct { typedef struct {
int maxRowSize; int maxRowSize;
int maxCols; // max number of columns int maxCols; // max number of columns
...@@ -218,7 +222,6 @@ void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop); //!!!! ...@@ -218,7 +222,6 @@ void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop); //!!!!
int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge); int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge);
void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCols *src2, int *iter2, int tRows); void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCols *src2, int *iter2, int tRows);
// ----------------- K-V data row structure // ----------------- K-V data row structure
/* /*
* +----------+----------+---------------------------------+---------------------------------+ * +----------+----------+---------------------------------+---------------------------------+
...@@ -227,29 +230,29 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SD ...@@ -227,29 +230,29 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SD
* | len | ncols | cols index | data part | * | len | ncols | cols index | data part |
* +----------+----------+---------------------------------+---------------------------------+ * +----------+----------+---------------------------------+---------------------------------+
*/ */
typedef void *SKVDataRow; typedef void *SKVRow;
typedef struct { typedef struct {
int16_t colId; int16_t colId;
int16_t offset; int16_t offset;
} SColIdx; } SColIdx;
#define TD_KV_DATA_ROW_HEAD_SIZE 2*sizeof(int16_t) #define TD_KV_ROW_HEAD_SIZE 2 * sizeof(int16_t)
#define kvDataRowLen(r) (*(int16_t *)(r)) #define kvRowLen(r) (*(int16_t *)(r))
#define kvDataRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t))) #define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)))
#define kvDataRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_DATA_ROW_HEAD_SIZE) #define kvRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE)
#define kvDataRowValues(r) POINTER_SHIFT(r, TD_KV_DATA_ROW_HEAD_SIZE + sizeof(SColIdx) * kvDataRowNCols(r)) #define kvRowValues(r) POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * kvRowNCols(r))
#define kvDataRowCpy(dst, r) memcpy((dst), (r), kvDataRowLen(r)) #define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r))
#define kvDataRowColVal(r, colIdx) POINTER_SHIFT(kvDataRowValues(r), (colIdx)->offset) #define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset)
#define kvDataRowSetLen(r, len) kvDataRowLen(r) = (len) #define kvRowSetLen(r, len) kvRowLen(r) = (len)
#define kvDataRowSetNCols(r, n) kvDataRowNCols(r) = (n) #define kvRowSetNCols(r, n) kvRowNCols(r) = (n)
#define kvDataRowColIdxAt(r, i) (kvDataRowColIdx(r) + (i)) #define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i))
SKVDataRow tdKVDataRowDup(SKVDataRow row); SKVRow tdKVRowDup(SKVRow row);
SKVDataRow tdSetKVRowDataOfCol(SKVDataRow row, int16_t colId, int8_t type, void *value); SKVRow tdSetKVRowDataOfCol(SKVRow row, int16_t colId, int8_t type, void *value);
void * tdEncodeKVDataRow(void *buf, SKVDataRow row); void * tdEncodeKVRow(void *buf, SKVRow row);
void * tdDecodeKVDataRow(void *buf, SKVDataRow *row); void * tdDecodeKVRow(void *buf, SKVRow *row);
static FORCE_INLINE int comparTagId(const void *key1, const void *key2) { static FORCE_INLINE int comparTagId(const void *key1, const void *key2) {
if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) { if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) {
...@@ -261,10 +264,10 @@ static FORCE_INLINE int comparTagId(const void *key1, const void *key2) { ...@@ -261,10 +264,10 @@ static FORCE_INLINE int comparTagId(const void *key1, const void *key2) {
} }
} }
static FORCE_INLINE void *tdGetKVRowDataOfCol(SKVDataRow row, int16_t colId) { static FORCE_INLINE void *tdGetKVRowDataOfCol(SKVRow row, int16_t colId) {
void *ret = taosbsearch(&colId, kvDataRowColIdx(row), kvDataRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ); void *ret = taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ);
if (ret == NULL) return NULL; if (ret == NULL) return NULL;
return kvDataRowColVal(row, (SColIdx *)ret); return kvRowColVal(row, (SColIdx *)ret);
} }
// ----------------- K-V data row builder // ----------------- K-V data row builder
...@@ -275,13 +278,13 @@ typedef struct { ...@@ -275,13 +278,13 @@ typedef struct {
int16_t alloc; int16_t alloc;
int16_t size; int16_t size;
void * buf; void * buf;
} SKVDataRowBuilder; } SKVRowBuilder;
int tdInitKVDataRowBuilder(SKVDataRowBuilder *pBuilder); int tdInitKVRowBuilder(SKVRowBuilder *pBuilder);
void tdDestroyKVDataRowBuilder(SKVDataRowBuilder *pBuilder); void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
void tdResetKVDataRowBuilder(SKVDataRowBuilder *pBuilder); void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
SKVDataRow tdGetKVDataRowFromBuilder(SKVDataRowBuilder *pBuilder); SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
int tdAddColToKVDataRow(SKVDataRowBuilder *pBuilder, int16_t colId, int8_t type, void *value); int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value);
// ----------------- Tag row structure // ----------------- Tag row structure
...@@ -297,7 +300,6 @@ pData ...@@ -297,7 +300,6 @@ pData
*/ */
#define TD_TAG_ROW_HEAD_SIZE sizeof(int16_t) #define TD_TAG_ROW_HEAD_SIZE sizeof(int16_t)
#define tagRowNum(r) (*(int16_t *)(r)) #define tagRowNum(r) (*(int16_t *)(r))
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tdataformat.h" #include "tdataformat.h"
#include "wchar.h"
#include "talgo.h" #include "talgo.h"
#include "wchar.h"
/** /**
* Create a SSchema object with nCols columns * Create a SSchema object with nCols columns
...@@ -51,7 +51,7 @@ int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes) ...@@ -51,7 +51,7 @@ int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes)
if (schemaNCols(pSchema) == 0) { if (schemaNCols(pSchema) == 0) {
colSetOffset(pCol, 0); colSetOffset(pCol, 0);
} else { } else {
STColumn *pTCol = schemaColAt(pSchema, schemaNCols(pSchema)-1); STColumn *pTCol = schemaColAt(pSchema, schemaNCols(pSchema) - 1);
colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]);
} }
switch (type) { switch (type) {
...@@ -152,15 +152,16 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) { ...@@ -152,15 +152,16 @@ SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
return row; 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); ASSERT(((STagRow *)row)->pData != NULL);
//STagCol * stCol = tdQueryTagColByID() // STagCol * stCol = tdQueryTagColByID()
return 0; return 0;
}; };
int tdDeleteTagCol(SDataRow row, int16_t colId){ // delete tag value and update all the information int tdDeleteTagCol(SDataRow row, int16_t colId) { // delete tag value and update all the information
//todo // todo
return 0; return 0;
}; };
...@@ -177,37 +178,37 @@ static int compTagId(const void *key1, const void *key2) { ...@@ -177,37 +178,37 @@ static int compTagId(const void *key1, const void *key2) {
/** /**
* Find tag structure by colId, if find, return tag structure, else return NULL; * 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); ASSERT(((STagRow *)row)->pData != NULL);
STagCol *pBase = ((STagRow *)row)->tagCols; STagCol *pBase = ((STagRow *)row)->tagCols;
int16_t nCols = ((STagRow *)row)->ncols; int16_t nCols = ((STagRow *)row)->ncols;
STagCol key = {colId,0,0}; STagCol key = {colId, 0, 0};
STagCol * stCol = taosbsearch(&key, pBase, nCols, sizeof(STagCol), compTagId, flags); STagCol *stCol = taosbsearch(&key, pBase, nCols, sizeof(STagCol), compTagId, flags);
return stCol; return stCol;
}; };
/** /**
* Find tag value by colId, if find, return tag value, else return NULL; * Find tag value by colId, if find, return tag value, else return NULL;
*/ */
void * tdQueryTagByID(SDataRow row, int16_t colId, int16_t *type) { void *tdQueryTagByID(SDataRow row, int16_t colId, int16_t *type) {
ASSERT(((STagRow *)row)->pData != NULL); ASSERT(((STagRow *)row)->pData != NULL);
STagCol *pBase = ((STagRow *)row)->tagCols; STagCol *pBase = ((STagRow *)row)->tagCols;
int16_t nCols = ((STagRow *)row)->ncols; int16_t nCols = ((STagRow *)row)->ncols;
STagCol key = {colId,0,0}; STagCol key = {colId, 0, 0};
STagCol * stCol = taosbsearch(&key, pBase, nCols, sizeof(STagCol), compTagId, TD_EQ); STagCol *stCol = taosbsearch(&key, pBase, nCols, sizeof(STagCol), compTagId, TD_EQ);
if (NULL == stCol) { if (NULL == stCol) {
return NULL; return NULL;
} }
void * pData = ((STagRow *)row)->pData; void *pData = ((STagRow *)row)->pData;
*type = stCol->colType; *type = stCol->colType;
return pData + stCol->offset; 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(value != NULL);
//ASSERT(bytes-2 == varDataTLen(value)); // ASSERT(bytes-2 == varDataTLen(value));
ASSERT(row != NULL); ASSERT(row != NULL);
STagRow *pTagrow = row; STagRow *pTagrow = row;
pTagrow->tagCols[pTagrow->ncols].colId = colId; pTagrow->tagCols[pTagrow->ncols].colId = colId;
...@@ -231,7 +232,7 @@ int tdAppendTagColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int ...@@ -231,7 +232,7 @@ int tdAppendTagColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int
return 0; return 0;
}; };
void * tdNewTagRowFromSchema(STSchema *pSchema, int16_t numofTags) { void *tdNewTagRowFromSchema(STSchema *pSchema, int16_t numofTags) {
int32_t size = sizeof(STagRow) + numofTags * sizeof(STagCol); int32_t size = sizeof(STagRow) + numofTags * sizeof(STagCol);
STagRow *row = malloc(size); STagRow *row = malloc(size);
...@@ -284,7 +285,7 @@ SDataRow tdTagRowDecode(SDataRow row) { ...@@ -284,7 +285,7 @@ SDataRow tdTagRowDecode(SDataRow row) {
free(trow); free(trow);
return NULL; return NULL;
} }
char * pData = (char *)row + dataRowLen(row); char *pData = (char *)row + dataRowLen(row);
memcpy(trow->pData, pData, trow->dataLen); memcpy(trow->pData, pData, trow->dataLen);
return trow; return trow;
} }
...@@ -293,7 +294,7 @@ int tdTagRowCpy(SDataRow dst, SDataRow src) { ...@@ -293,7 +294,7 @@ int tdTagRowCpy(SDataRow dst, SDataRow src) {
if (src == NULL) return -1; if (src == NULL) return -1;
dataRowCpy(dst, src); dataRowCpy(dst, src);
void * pData = dst + dataRowLen(src); void *pData = dst + dataRowLen(src);
memcpy(pData, ((STagRow *)src)->pData, ((STagRow *)src)->dataLen); memcpy(pData, ((STagRow *)src)->pData, ((STagRow *)src)->dataLen);
return 0; return 0;
} }
...@@ -330,7 +331,6 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints) ...@@ -330,7 +331,6 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints)
pDataCol->pData = *pBuf; pDataCol->pData = *pBuf;
*pBuf = POINTER_SHIFT(*pBuf, pDataCol->spaceSize); *pBuf = POINTER_SHIFT(*pBuf, pDataCol->spaceSize);
} }
} }
void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints) { void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints) {
...@@ -414,7 +414,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) { ...@@ -414,7 +414,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
void dataColSetOffset(SDataCol *pCol, int nEle) { void dataColSetOffset(SDataCol *pCol, int nEle) {
ASSERT(((pCol->type == TSDB_DATA_TYPE_BINARY) || (pCol->type == TSDB_DATA_TYPE_NCHAR))); 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); // char *tptr = (char *)(pCol->pData);
VarDataOffsetT offset = 0; VarDataOffsetT offset = 0;
...@@ -596,26 +596,25 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCol ...@@ -596,26 +596,25 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, SDataCol
} }
} }
SKVDataRow tdKVDataRowDup(SKVDataRow row) { SKVRow tdKVRowDup(SKVRow row) {
SKVDataRow trow = malloc(kvDataRowLen(row)); SKVRow trow = malloc(kvRowLen(row));
if (trow == NULL) return NULL; if (trow == NULL) return NULL;
kvDataRowCpy(trow, row); kvRowCpy(trow, row);
return trow; return trow;
} }
SKVDataRow tdSetKVRowDataOfCol(SKVDataRow row, int16_t colId, int8_t type, void *value) { SKVRow tdSetKVRowDataOfCol(SKVRow row, int16_t colId, int8_t type, void *value) {
// TODO // TODO
return NULL; return NULL;
// SColIdx *pColIdx = NULL; // SColIdx *pColIdx = NULL;
// SKVDataRow rrow = row; // SKVRow rrow = row;
// SKVDataRow nrow = NULL; // SKVRow nrow = NULL;
// void *ptr = taosbsearch(&colId, kvDataRowColIdx(row), kvDataRowNCols(row), sizeof(SColIdx), comparTagId, TD_GE); // 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 // 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]); // int tlen = kvDataRowLen(row) + sizeof(SColIdx) + (IS_VAR_DATA_TYPE(type) ? varDataTLen(value) :
// nrow = malloc(tlen); // TYPE_BYTES[type]); nrow = malloc(tlen); if (nrow == NULL) return NULL;
// if (nrow == NULL) return NULL;
// kvDataRowSetNCols(nrow, kvDataRowNCols(row)+1); // kvDataRowSetNCols(nrow, kvDataRowNCols(row)+1);
// kvDataRowSetLen(nrow, tlen); // kvDataRowSetLen(nrow, tlen);
...@@ -670,18 +669,18 @@ SKVDataRow tdSetKVRowDataOfCol(SKVDataRow row, int16_t colId, int8_t type, void ...@@ -670,18 +669,18 @@ SKVDataRow tdSetKVRowDataOfCol(SKVDataRow row, int16_t colId, int8_t type, void
// return rrow; // return rrow;
} }
void *tdEncodeKVDataRow(void *buf, SKVDataRow row) { void *tdEncodeKVRow(void *buf, SKVRow row) {
// May change the encode purpose // May change the encode purpose
kvDataRowCpy(buf, row); kvRowCpy(buf, row);
return POINTER_SHIFT(buf, kvDataRowLen(row)); return POINTER_SHIFT(buf, kvRowLen(row));
} }
void *tdDecodeKVDataRow(void *buf, SKVDataRow *row) { void *tdDecodeKVRow(void *buf, SKVRow *row) {
*row = tdKVDataRowDup(buf); *row = tdKVRowDup(buf);
return POINTER_SHIFT(buf, kvDataRowLen(*row)); return POINTER_SHIFT(buf, kvRowLen(*row));
} }
int tdInitKVDataRowBuilder(SKVDataRowBuilder *pBuilder) { int tdInitKVRowBuilder(SKVRowBuilder *pBuilder) {
pBuilder->tCols = 128; pBuilder->tCols = 128;
pBuilder->nCols = 0; pBuilder->nCols = 0;
pBuilder->pColIdx = (SColIdx *)malloc(sizeof(SColIdx) * pBuilder->tCols); pBuilder->pColIdx = (SColIdx *)malloc(sizeof(SColIdx) * pBuilder->tCols);
...@@ -696,33 +695,33 @@ int tdInitKVDataRowBuilder(SKVDataRowBuilder *pBuilder) { ...@@ -696,33 +695,33 @@ int tdInitKVDataRowBuilder(SKVDataRowBuilder *pBuilder) {
return 0; return 0;
} }
void tdDestroyKVDataRowBuilder(SKVDataRowBuilder *pBuilder) { void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder) {
tfree(pBuilder->pColIdx); tfree(pBuilder->pColIdx);
tfree(pBuilder->buf); tfree(pBuilder->buf);
} }
void tdResetKVDataRowBuilder(SKVDataRowBuilder *pBuilder) { void tdResetKVRowBuilder(SKVRowBuilder *pBuilder) {
pBuilder->nCols = 0; pBuilder->nCols = 0;
pBuilder->size = 0; pBuilder->size = 0;
} }
SKVDataRow tdGetKVDataRowFromBuilder(SKVDataRowBuilder *pBuilder) { SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
int tlen = sizeof(SColIdx) * pBuilder->nCols + pBuilder->size; int tlen = sizeof(SColIdx) * pBuilder->nCols + pBuilder->size;
if (tlen == 0) return NULL; if (tlen == 0) return NULL;
SKVDataRow row = malloc(TD_KV_DATA_ROW_HEAD_SIZE + tlen); SKVRow row = malloc(TD_KV_ROW_HEAD_SIZE + tlen);
if (row == NULL) return NULL; if (row == NULL) return NULL;
kvDataRowSetNCols(row, pBuilder->nCols); kvRowSetNCols(row, pBuilder->nCols);
kvDataRowSetLen(row, TD_KV_DATA_ROW_HEAD_SIZE + tlen); kvRowSetLen(row, TD_KV_ROW_HEAD_SIZE + tlen);
memcpy(kvDataRowColIdx(row), pBuilder->pColIdx, sizeof(SColIdx) * pBuilder->nCols); memcpy(kvRowColIdx(row), pBuilder->pColIdx, sizeof(SColIdx) * pBuilder->nCols);
memcpy(kvDataRowValues(row), pBuilder->buf, pBuilder->size); memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size);
return row; return row;
} }
int tdAddColToKVDataRow(SKVDataRowBuilder *pBuilder, int16_t colId, int8_t type, void *value) { int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value) {
ASSERT(pBuilder->nCols == 0 || colId > pBuilder->pColIdx[pBuilder->nCols - 1].colId); ASSERT(pBuilder->nCols == 0 || colId > pBuilder->pColIdx[pBuilder->nCols - 1].colId);
if (pBuilder->nCols >= pBuilder->tCols) { if (pBuilder->nCols >= pBuilder->tCols) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册