提交 db3999ea 编写于 作者: S Shengliang Guan

minor changes

上级 5891779f
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tdataformat.h" #include "tdataformat.h"
#include "tcoding.h" #include "tcoding.h"
#include "tlog.h" #include "tlog.h"
static void dataColSetNEleNull(SDataCol *pCol, int nEle); static void dataColSetNEleNull(SDataCol *pCol, int nEle);
...@@ -25,7 +25,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i ...@@ -25,7 +25,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
#endif #endif
int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
int spaceNeeded = pCol->bytes * maxPoints; int spaceNeeded = pCol->bytes * maxPoints;
if(IS_VAR_DATA_TYPE(pCol->type)) { if (IS_VAR_DATA_TYPE(pCol->type)) {
spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; spaceNeeded += sizeof(VarDataOffsetT) * maxPoints;
} }
#ifdef TD_SUPPORT_BITMAP #ifdef TD_SUPPORT_BITMAP
...@@ -36,11 +36,10 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { ...@@ -36,11 +36,10 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
spaceNeeded += TYPE_BYTES[pCol->type]; spaceNeeded += TYPE_BYTES[pCol->type];
#endif #endif
if(pCol->spaceSize < spaceNeeded) { if (pCol->spaceSize < spaceNeeded) {
void* ptr = realloc(pCol->pData, spaceNeeded); void *ptr = realloc(pCol->pData, spaceNeeded);
if(ptr == NULL) { if (ptr == NULL) {
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded, uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded, strerror(errno));
strerror(errno));
return -1; return -1;
} else { } else {
pCol->pData = ptr; pCol->pData = ptr;
...@@ -66,8 +65,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { ...@@ -66,8 +65,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
* Duplicate the schema and return a new object * Duplicate the schema and return a new object
*/ */
STSchema *tdDupSchema(const STSchema *pSchema) { STSchema *tdDupSchema(const STSchema *pSchema) {
int tlen = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema);
int tlen = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema);
STSchema *tSchema = (STSchema *)malloc(tlen); STSchema *tSchema = (STSchema *)malloc(tlen);
if (tSchema == NULL) return NULL; if (tSchema == NULL) return NULL;
...@@ -98,8 +96,8 @@ int tdEncodeSchema(void **buf, STSchema *pSchema) { ...@@ -98,8 +96,8 @@ int tdEncodeSchema(void **buf, STSchema *pSchema) {
* Decode a schema from a binary. * Decode a schema from a binary.
*/ */
void *tdDecodeSchema(void *buf, STSchema **pRSchema) { void *tdDecodeSchema(void *buf, STSchema **pRSchema) {
int version = 0; int version = 0;
int numOfCols = 0; int numOfCols = 0;
STSchemaBuilder schemaBuilder; STSchemaBuilder schemaBuilder;
buf = taosDecodeFixedI32(buf, &version); buf = taosDecodeFixedI32(buf, &version);
...@@ -155,7 +153,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1 ...@@ -155,7 +153,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1
if (pBuilder->nCols >= pBuilder->tCols) { if (pBuilder->nCols >= pBuilder->tCols) {
pBuilder->tCols *= 2; pBuilder->tCols *= 2;
STColumn* columns = (STColumn *)realloc(pBuilder->columns, sizeof(STColumn) * pBuilder->tCols); STColumn *columns = (STColumn *)realloc(pBuilder->columns, sizeof(STColumn) * pBuilder->tCols);
if (columns == NULL) return -1; if (columns == NULL) return -1;
pBuilder->columns = columns; pBuilder->columns = columns;
} }
...@@ -166,7 +164,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1 ...@@ -166,7 +164,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1
if (pBuilder->nCols == 0) { if (pBuilder->nCols == 0) {
colSetOffset(pCol, 0); colSetOffset(pCol, 0);
} else { } else {
STColumn *pTCol = &(pBuilder->columns[pBuilder->nCols-1]); STColumn *pTCol = &(pBuilder->columns[pBuilder->nCols - 1]);
colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]);
} }
...@@ -258,7 +256,7 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) { ...@@ -258,7 +256,7 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
pDataCol->type = colType(pCol); pDataCol->type = colType(pCol);
pDataCol->colId = colColId(pCol); pDataCol->colId = colColId(pCol);
pDataCol->bytes = colBytes(pCol); pDataCol->bytes = colBytes(pCol);
pDataCol->offset = colOffset(pCol) + 0; //TD_DATA_ROW_HEAD_SIZE; pDataCol->offset = colOffset(pCol) + 0; // TD_DATA_ROW_HEAD_SIZE;
pDataCol->len = 0; pDataCol->len = 0;
} }
...@@ -272,7 +270,7 @@ int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPo ...@@ -272,7 +270,7 @@ int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPo
return 0; return 0;
} }
if(tdAllocMemForCol(pCol, maxPoints) < 0) return -1; if (tdAllocMemForCol(pCol, maxPoints) < 0) return -1;
if (numOfRows > 0) { if (numOfRows > 0) {
// Find the first not null value, fill all previouse values as NULL // Find the first not null value, fill all previouse values as NULL
dataColSetNEleNull(pCol, numOfRows); dataColSetNEleNull(pCol, numOfRows);
...@@ -303,7 +301,7 @@ static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row) ...@@ -303,7 +301,7 @@ static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row)
} }
bool isNEleNull(SDataCol *pCol, int nEle) { bool isNEleNull(SDataCol *pCol, int nEle) {
if(isAllRowsNull(pCol)) return true; if (isAllRowsNull(pCol)) return true;
for (int i = 0; i < nEle; i++) { for (int i = 0; i < nEle; i++) {
if (!isNull(tdGetColDataOfRowUnsafe(pCol, i), pCol->type)) return false; if (!isNull(tdGetColDataOfRowUnsafe(pCol, i), pCol->type)) return false;
} }
...@@ -370,7 +368,7 @@ SDataCols *tdNewDataCols(int maxCols, int maxRows) { ...@@ -370,7 +368,7 @@ SDataCols *tdNewDataCols(int maxCols, int maxRows) {
return NULL; return NULL;
} }
int i; int i;
for(i = 0; i < maxCols; i++) { for (i = 0; i < maxCols; i++) {
pCols->cols[i].spaceSize = 0; pCols->cols[i].spaceSize = 0;
pCols->cols[i].len = 0; pCols->cols[i].len = 0;
pCols->cols[i].pData = NULL; pCols->cols[i].pData = NULL;
...@@ -386,10 +384,10 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { ...@@ -386,10 +384,10 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
int oldMaxCols = pCols->maxCols; int oldMaxCols = pCols->maxCols;
if (schemaNCols(pSchema) > oldMaxCols) { if (schemaNCols(pSchema) > oldMaxCols) {
pCols->maxCols = schemaNCols(pSchema); pCols->maxCols = schemaNCols(pSchema);
void* ptr = (SDataCol *)realloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols); void *ptr = (SDataCol *)realloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols);
if (ptr == NULL) return -1; if (ptr == NULL) return -1;
pCols->cols = ptr; pCols->cols = ptr;
for(i = oldMaxCols; i < pCols->maxCols; i++) { for (i = oldMaxCols; i < pCols->maxCols; i++) {
pCols->cols[i].pData = NULL; pCols->cols[i].pData = NULL;
pCols->cols[i].dataOff = NULL; pCols->cols[i].dataOff = NULL;
pCols->cols[i].spaceSize = 0; pCols->cols[i].spaceSize = 0;
...@@ -402,16 +400,16 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { ...@@ -402,16 +400,16 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
for (i = 0; i < schemaNCols(pSchema); i++) { for (i = 0; i < schemaNCols(pSchema); i++) {
dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints); dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints);
} }
return 0; return 0;
} }
SDataCols *tdFreeDataCols(SDataCols *pCols) { SDataCols *tdFreeDataCols(SDataCols *pCols) {
int i; int i;
if (pCols) { if (pCols) {
if(pCols->cols) { if (pCols->cols) {
int maxCols = pCols->maxCols; int maxCols = pCols->maxCols;
for(i = 0; i < maxCols; i++) { for (i = 0; i < maxCols; i++) {
SDataCol *pCol = &pCols->cols[i]; SDataCol *pCol = &pCols->cols[i];
tfree(pCol->pData); tfree(pCol->pData);
} }
...@@ -439,7 +437,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { ...@@ -439,7 +437,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
if (keepData) { if (keepData) {
if (pDataCols->cols[i].len > 0) { if (pDataCols->cols[i].len > 0) {
if(tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) { if (tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) {
tdFreeDataCols(pRet); tdFreeDataCols(pRet);
return NULL; return NULL;
} }
...@@ -647,9 +645,9 @@ SKVRow tdKVRowDup(SKVRow row) { ...@@ -647,9 +645,9 @@ SKVRow tdKVRowDup(SKVRow row) {
return trow; return trow;
} }
static int compareColIdx(const void* a, const void* b) { static int compareColIdx(const void *a, const void *b) {
const SColIdx* x = (const SColIdx*)a; const SColIdx *x = (const SColIdx *)a;
const SColIdx* y = (const SColIdx*)b; const SColIdx *y = (const SColIdx *)b;
if (x->colId > y->colId) { if (x->colId > y->colId) {
return 1; return 1;
} }
...@@ -659,15 +657,13 @@ static int compareColIdx(const void* a, const void* b) { ...@@ -659,15 +657,13 @@ static int compareColIdx(const void* a, const void* b) {
return 0; return 0;
} }
void tdSortKVRowByColIdx(SKVRow row) { void tdSortKVRowByColIdx(SKVRow row) { qsort(kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), compareColIdx); }
qsort(kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), compareColIdx);
}
int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
SColIdx *pColIdx = NULL; SColIdx *pColIdx = NULL;
SKVRow row = *orow; SKVRow row = *orow;
SKVRow nrow = NULL; SKVRow nrow = NULL;
void * ptr = taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_GE); void *ptr = taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(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 diff = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type]; int diff = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type];
...@@ -699,7 +695,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { ...@@ -699,7 +695,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
void *pOldVal = kvRowColVal(row, (SColIdx *)ptr); void *pOldVal = kvRowColVal(row, (SColIdx *)ptr);
if (varDataTLen(value) == varDataTLen(pOldVal)) { // just update the column value in place if (varDataTLen(value) == varDataTLen(pOldVal)) { // just update the column value in place
memcpy(pOldVal, value, varDataTLen(value)); memcpy(pOldVal, value, varDataTLen(value));
} else { // need to reallocate the memory } else { // need to reallocate the memory
int16_t nlen = kvRowLen(row) + (varDataTLen(value) - varDataTLen(pOldVal)); int16_t nlen = kvRowLen(row) + (varDataTLen(value) - varDataTLen(pOldVal));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册