提交 7d50bfcb 编写于 作者: H Hongze Cheng

more code

上级 36fbf6d7
...@@ -61,15 +61,17 @@ typedef struct { ...@@ -61,15 +61,17 @@ typedef struct {
uint64_t suid; uint64_t suid;
} STableListInfo; } STableListInfo;
#pragma pack(push, 1)
typedef struct SColumnDataAgg { typedef struct SColumnDataAgg {
int16_t colId; int16_t colId;
int16_t maxIndex;
int16_t minIndex; int16_t minIndex;
int16_t maxIndex;
int16_t numOfNull; int16_t numOfNull;
int64_t sum; int64_t sum;
int64_t max; int64_t max;
int64_t min; int64_t min;
} SColumnDataAgg; } SColumnDataAgg;
#pragma pack(pop)
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
...@@ -114,7 +116,7 @@ typedef struct SQueryTableDataCond { ...@@ -114,7 +116,7 @@ typedef struct SQueryTableDataCond {
int32_t order; // desc|asc order to iterate the data block int32_t order; // desc|asc order to iterate the data block
int32_t numOfCols; int32_t numOfCols;
SColumnInfo* colList; SColumnInfo* colList;
int32_t type; // data block load type: int32_t type; // data block load type:
int32_t numOfTWindows; int32_t numOfTWindows;
STimeWindow* twindows; STimeWindow* twindows;
int64_t startVersion; int64_t startVersion;
......
...@@ -119,10 +119,7 @@ int32_t tPutBlockCol(uint8_t *p, void *ph); ...@@ -119,10 +119,7 @@ int32_t tPutBlockCol(uint8_t *p, void *ph);
int32_t tGetBlockCol(uint8_t *p, void *ph); int32_t tGetBlockCol(uint8_t *p, void *ph);
int32_t tBlockColCmprFn(const void *p1, const void *p2); int32_t tBlockColCmprFn(const void *p1, const void *p2);
// SBlock // SBlock
#define tBlockInit() ((SBlock){0})
void tBlockReset(SBlock *pBlock); void tBlockReset(SBlock *pBlock);
void tBlockClear(SBlock *pBlock);
int32_t tBlockCopy(SBlock *pBlockSrc, SBlock *pBlockDest);
int32_t tPutBlock(uint8_t *p, void *ph); int32_t tPutBlock(uint8_t *p, void *ph);
int32_t tGetBlock(uint8_t *p, void *ph); int32_t tGetBlock(uint8_t *p, void *ph);
int32_t tBlockCmprFn(const void *p1, const void *p2); int32_t tBlockCmprFn(const void *p1, const void *p2);
...@@ -134,11 +131,11 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph); ...@@ -134,11 +131,11 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph);
int32_t tCmprBlockIdx(void const *lhs, void const *rhs); int32_t tCmprBlockIdx(void const *lhs, void const *rhs);
// SColdata // SColdata
#define tColDataInit() ((SColData){0}) #define tColDataInit() ((SColData){0})
void tColDataReset(SColData *pColData, int16_t cid, int8_t type); void tColDataReset(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn);
void tColDataClear(void *ph); void tColDataClear(void *ph);
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal); int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest);
int32_t tColDataGetValue(SColData *pColData, int32_t iRow, SColVal *pColVal); int32_t tColDataGetValue(SColData *pColData, int32_t iRow, SColVal *pColVal);
int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest);
// SBlockData // SBlockData
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0) #define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1) #define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
...@@ -166,9 +163,8 @@ void tsdbFree(uint8_t *pBuf); ...@@ -166,9 +163,8 @@ void tsdbFree(uint8_t *pBuf);
#define tMapDataInit() ((SMapData){0}) #define tMapDataInit() ((SMapData){0})
void tMapDataReset(SMapData *pMapData); void tMapDataReset(SMapData *pMapData);
void tMapDataClear(SMapData *pMapData); void tMapDataClear(SMapData *pMapData);
int32_t tMapDataCopy(SMapData *pMapDataSrc, SMapData *pMapDataDest);
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *)); int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
int32_t tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)); void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *));
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *), int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem); int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
int32_t tPutMapData(uint8_t *p, SMapData *pMapData); int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
...@@ -223,7 +219,6 @@ int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx, uint8_t **pp ...@@ -223,7 +219,6 @@ int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx, uint8_t **pp
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, uint8_t **ppBuf, SBlockIdx *pBlockIdx); int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, uint8_t **ppBuf, SBlockIdx *pBlockIdx);
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2, int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2,
SBlockIdx *pBlockIdx, SBlock *pBlock, int8_t cmprAlg); SBlockIdx *pBlockIdx, SBlock *pBlock, int8_t cmprAlg);
int32_t tsdbWriteBlockSMA(SDataFWriter *pWriter, SBlockSMA *pBlockSMA, int64_t *rOffset, int64_t *rSize);
SDFileSet *tsdbDataFWriterGetWSet(SDataFWriter *pWriter); SDFileSet *tsdbDataFWriterGetWSet(SDataFWriter *pWriter);
// SDataFReader // SDataFReader
...@@ -373,31 +368,32 @@ struct SBlockIdx { ...@@ -373,31 +368,32 @@ struct SBlockIdx {
struct SMapData { struct SMapData {
int32_t nItem; int32_t nItem;
uint8_t flag; int32_t *aOffset;
uint8_t *pOfst; int32_t nData;
uint32_t nData;
uint8_t *pData; uint8_t *pData;
uint8_t *pBuf;
}; };
typedef struct { typedef struct {
int16_t cid; int16_t cid;
int8_t type; int8_t type;
int8_t flag; // HAS_NONE|HAS_NULL|HAS_VALUE int8_t flag; // HAS_NONE|HAS_NULL|HAS_VALUE
int64_t offset; int32_t offset;
int64_t bsize; // bitmap size int32_t szBitmap; // bitmap size
int64_t csize; // compressed column value size int32_t szOffset; // size of offset, only for variant-length data type
int64_t osize; // original column value size (only save for variant data type) int32_t szValue; // compressed column value size
int32_t szOrigin; // original column value size (only save for variant data type)
} SBlockCol; } SBlockCol;
typedef struct { typedef struct {
int64_t nRow; int32_t nRow;
int8_t cmprAlg; int8_t cmprAlg;
int64_t offset; int64_t offset; // block data offset
int64_t szVersion; // VERSION size int32_t szBlockCol; // SBlockCol size
int64_t szTSKEY; // TSKEY size int32_t szVersion; // VERSION size
int64_t szBlock; // total block size int32_t szTSKEY; // TSKEY size
SMapData mBlockCol; // SMapData<SBlockCol> int32_t szBlock; // total block size
int64_t sOffset; // sma offset
int32_t nSma; // sma size
} SSubBlock; } SSubBlock;
struct SBlock { struct SBlock {
...@@ -425,7 +421,7 @@ struct SAggrBlkCol { ...@@ -425,7 +421,7 @@ struct SAggrBlkCol {
struct SColData { struct SColData {
int16_t cid; int16_t cid;
int8_t type; int8_t type;
int8_t offsetValid; int8_t smaOn;
int32_t nVal; int32_t nVal;
uint8_t flag; uint8_t flag;
uint8_t *pBitMap; uint8_t *pBitMap;
......
...@@ -33,12 +33,10 @@ typedef struct { ...@@ -33,12 +33,10 @@ typedef struct {
SDataFReader *pReader; SDataFReader *pReader;
SArray *aBlockIdx; // SArray<SBlockIdx> SArray *aBlockIdx; // SArray<SBlockIdx>
SMapData oBlockMap; // SMapData<SBlock>, read from reader SMapData oBlockMap; // SMapData<SBlock>, read from reader
SBlock oBlock;
SBlockData oBlockData; SBlockData oBlockData;
SDataFWriter *pWriter; SDataFWriter *pWriter;
SArray *aBlockIdxN; // SArray<SBlockIdx> SArray *aBlockIdxN; // SArray<SBlockIdx>
SMapData nBlockMap; // SMapData<SBlock> SMapData nBlockMap; // SMapData<SBlock>
SBlock nBlock;
SBlockData nBlockData; SBlockData nBlockData;
int64_t suid; int64_t suid;
int64_t uid; int64_t uid;
...@@ -260,7 +258,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) { ...@@ -260,7 +258,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
// old // old
taosArrayClear(pCommitter->aBlockIdx); taosArrayClear(pCommitter->aBlockIdx);
tMapDataReset(&pCommitter->oBlockMap); tMapDataReset(&pCommitter->oBlockMap);
tBlockReset(&pCommitter->oBlock);
tBlockDataReset(&pCommitter->oBlockData); tBlockDataReset(&pCommitter->oBlockData);
pRSet = tsdbFSStateGetDFileSet(pTsdb->fs->nState, pCommitter->commitFid); pRSet = tsdbFSStateGetDFileSet(pTsdb->fs->nState, pCommitter->commitFid);
if (pRSet) { if (pRSet) {
...@@ -274,7 +271,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) { ...@@ -274,7 +271,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
// new // new
taosArrayClear(pCommitter->aBlockIdxN); taosArrayClear(pCommitter->aBlockIdxN);
tMapDataReset(&pCommitter->nBlockMap); tMapDataReset(&pCommitter->nBlockMap);
tBlockReset(&pCommitter->nBlock);
tBlockDataReset(&pCommitter->nBlockData); tBlockDataReset(&pCommitter->nBlockData);
if (pRSet) { if (pRSet) {
wSet = (SDFileSet){.diskId = pRSet->diskId, wSet = (SDFileSet){.diskId = pRSet->diskId,
...@@ -351,11 +347,6 @@ static int32_t tsdbCommitBlockData(SCommitter *pCommitter, SBlockData *pBlockDat ...@@ -351,11 +347,6 @@ static int32_t tsdbCommitBlockData(SCommitter *pCommitter, SBlockData *pBlockDat
code = tsdbWriteBlockData(pCommitter->pWriter, pBlockData, NULL, NULL, pBlockIdx, pBlock, pCommitter->cmprAlg); code = tsdbWriteBlockData(pCommitter->pWriter, pBlockData, NULL, NULL, pBlockIdx, pBlock, pCommitter->cmprAlg);
if (code) goto _err; if (code) goto _err;
#if 0
code = tsdbWriteBlockSMA(pCommitter, pBlockData, pBlock);
if (code) goto _err;
#endif
code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock); code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock);
if (code) goto _err; if (code) goto _err;
...@@ -371,7 +362,8 @@ static int32_t tsdbMergeTableData(SCommitter *pCommitter, STbDataIter *pIter, SB ...@@ -371,7 +362,8 @@ static int32_t tsdbMergeTableData(SCommitter *pCommitter, STbDataIter *pIter, SB
SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid}; SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid};
SBlockData *pBlockDataMerge = &pCommitter->oBlockData; SBlockData *pBlockDataMerge = &pCommitter->oBlockData;
SBlockData *pBlockData = &pCommitter->nBlockData; SBlockData *pBlockData = &pCommitter->nBlockData;
SBlock *pBlock = &pCommitter->nBlock; SBlock block;
SBlock *pBlock = &block;
TSDBROW *pRow1; TSDBROW *pRow1;
TSDBROW row2; TSDBROW row2;
TSDBROW *pRow2 = &row2; TSDBROW *pRow2 = &row2;
...@@ -469,7 +461,8 @@ _err: ...@@ -469,7 +461,8 @@ _err:
static int32_t tsdbCommitTableMemData(SCommitter *pCommitter, STbDataIter *pIter, TSDBKEY toKey, int8_t toDataOnly) { static int32_t tsdbCommitTableMemData(SCommitter *pCommitter, STbDataIter *pIter, TSDBKEY toKey, int8_t toDataOnly) {
int32_t code = 0; int32_t code = 0;
TSDBROW *pRow; TSDBROW *pRow;
SBlock *pBlock = &pCommitter->nBlock; SBlock block;
SBlock *pBlock = &block;
SBlockData *pBlockData = &pCommitter->nBlockData; SBlockData *pBlockData = &pCommitter->nBlockData;
int64_t suid = pIter->pTbData->suid; int64_t suid = pIter->pTbData->suid;
int64_t uid = pIter->pTbData->uid; int64_t uid = pIter->pTbData->uid;
...@@ -519,13 +512,14 @@ _err: ...@@ -519,13 +512,14 @@ _err:
static int32_t tsdbCommitTableDiskData(SCommitter *pCommitter, SBlock *pBlock, SBlockIdx *pBlockIdx) { static int32_t tsdbCommitTableDiskData(SCommitter *pCommitter, SBlock *pBlock, SBlockIdx *pBlockIdx) {
int32_t code = 0; int32_t code = 0;
SBlock block;
if (pBlock->last) { if (pBlock->last) {
code = tsdbReadBlockData(pCommitter->pReader, pBlockIdx, pBlock, &pCommitter->oBlockData, NULL, NULL); code = tsdbReadBlockData(pCommitter->pReader, pBlockIdx, pBlock, &pCommitter->oBlockData, NULL, NULL);
if (code) goto _err; if (code) goto _err;
tBlockReset(&pCommitter->nBlock); tBlockReset(&block);
code = tsdbCommitBlockData(pCommitter, &pCommitter->oBlockData, &pCommitter->nBlock, pBlockIdx, 0); code = tsdbCommitBlockData(pCommitter, &pCommitter->oBlockData, &block, pBlockIdx, 0);
if (code) goto _err; if (code) goto _err;
} else { } else {
code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock); code = tMapDataPutItem(&pCommitter->nBlockMap, pBlock, tPutBlock);
...@@ -590,6 +584,7 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S ...@@ -590,6 +584,7 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S
int32_t code = 0; int32_t code = 0;
SBlockData *pBlockData = &pCommitter->nBlockData; SBlockData *pBlockData = &pCommitter->nBlockData;
SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid}; SBlockIdx *pBlockIdx = &(SBlockIdx){.suid = pIter->pTbData->suid, .uid = pIter->pTbData->uid};
SBlock block;
TSDBROW *pRow; TSDBROW *pRow;
tBlockDataReset(pBlockData); tBlockDataReset(pBlockData);
...@@ -617,11 +612,8 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S ...@@ -617,11 +612,8 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S
} }
} }
// write as a subblock block = *pBlock;
code = tBlockCopy(pBlock, &pCommitter->nBlock); code = tsdbCommitBlockData(pCommitter, pBlockData, &block, pBlockIdx, 0);
if (code) goto _err;
code = tsdbCommitBlockData(pCommitter, pBlockData, &pCommitter->nBlock, pBlockIdx, 0);
if (code) goto _err; if (code) goto _err;
return code; return code;
...@@ -670,7 +662,8 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBl ...@@ -670,7 +662,8 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBl
// start =========== // start ===========
tMapDataReset(&pCommitter->nBlockMap); tMapDataReset(&pCommitter->nBlockMap);
SBlock *pBlock = &pCommitter->oBlock; SBlock block;
SBlock *pBlock = &block;
iBlock = 0; iBlock = 0;
if (iBlock < nBlock) { if (iBlock < nBlock) {
...@@ -895,6 +888,8 @@ static int32_t tsdbCommitFileData(SCommitter *pCommitter) { ...@@ -895,6 +888,8 @@ static int32_t tsdbCommitFileData(SCommitter *pCommitter) {
_err: _err:
tsdbError("vgId:%d commit file data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); tsdbError("vgId:%d commit file data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
tsdbDataFReaderClose(&pCommitter->pReader);
tsdbDataFWriterClose(&pCommitter->pWriter, 0);
return code; return code;
} }
...@@ -931,21 +926,23 @@ _err: ...@@ -931,21 +926,23 @@ _err:
static int32_t tsdbCommitDataStart(SCommitter *pCommitter) { static int32_t tsdbCommitDataStart(SCommitter *pCommitter) {
int32_t code = 0; int32_t code = 0;
pCommitter->pReader = NULL;
pCommitter->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); pCommitter->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx));
pCommitter->oBlockMap = tMapDataInit(); if (pCommitter->aBlockIdx == NULL) {
pCommitter->oBlock = tBlockInit(); code = TSDB_CODE_OUT_OF_MEMORY;
pCommitter->pWriter = NULL; goto _exit;
}
pCommitter->aBlockIdxN = taosArrayInit(0, sizeof(SBlockIdx)); pCommitter->aBlockIdxN = taosArrayInit(0, sizeof(SBlockIdx));
pCommitter->nBlockMap = tMapDataInit(); if (pCommitter->aBlockIdxN == NULL) {
pCommitter->nBlock = tBlockInit(); code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
code = tBlockDataInit(&pCommitter->oBlockData); code = tBlockDataInit(&pCommitter->oBlockData);
if (code) goto _exit; if (code) goto _exit;
code = tBlockDataInit(&pCommitter->nBlockData); code = tBlockDataInit(&pCommitter->nBlockData);
if (code) { if (code) goto _exit;
tBlockDataClear(&pCommitter->oBlockData);
goto _exit;
}
_exit: _exit:
return code; return code;
...@@ -953,13 +950,11 @@ _exit: ...@@ -953,13 +950,11 @@ _exit:
static void tsdbCommitDataEnd(SCommitter *pCommitter) { static void tsdbCommitDataEnd(SCommitter *pCommitter) {
taosArrayDestroy(pCommitter->aBlockIdx); taosArrayDestroy(pCommitter->aBlockIdx);
// tMapDataClear(&pCommitter->oBlockMap); tMapDataClear(&pCommitter->oBlockMap);
// tBlockClear(&pCommitter->oBlock); tBlockDataClear(&pCommitter->oBlockData);
// tBlockDataClear(&pCommitter->oBlockData);
taosArrayDestroy(pCommitter->aBlockIdxN); taosArrayDestroy(pCommitter->aBlockIdxN);
// tMapDataClear(&pCommitter->nBlockMap); tMapDataClear(&pCommitter->nBlockMap);
// tBlockClear(&pCommitter->nBlock); tBlockDataClear(&pCommitter->nBlockData);
// tBlockDataClear(&pCommitter->nBlockData);
} }
static int32_t tsdbCommitData(SCommitter *pCommitter) { static int32_t tsdbCommitData(SCommitter *pCommitter) {
......
...@@ -807,10 +807,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, uint32_ ...@@ -807,10 +807,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, uint32_
for (int32_t j = 0; j < mapData.nItem; ++j) { for (int32_t j = 0; j < mapData.nItem; ++j) {
SBlock block = {0}; SBlock block = {0};
int32_t code = tMapDataGetItemByIdx(&mapData, j, &block, tGetBlock); tMapDataGetItemByIdx(&mapData, j, &block, tGetBlock);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
// 1. time range check // 1. time range check
if (block.minKey.ts > pReader->window.ekey || block.maxKey.ts < pReader->window.skey) { if (block.minKey.ts > pReader->window.ekey || block.maxKey.ts < pReader->window.skey) {
......
...@@ -15,57 +15,15 @@ ...@@ -15,57 +15,15 @@
#include "tsdb.h" #include "tsdb.h"
#define TSDB_OFFSET_I32 ((uint8_t)0)
#define TSDB_OFFSET_I16 ((uint8_t)1)
#define TSDB_OFFSET_I8 ((uint8_t)2)
// SMapData ======================================================================= // SMapData =======================================================================
void tMapDataReset(SMapData *pMapData) { void tMapDataReset(SMapData *pMapData) {
pMapData->flag = TSDB_OFFSET_I32;
pMapData->nItem = 0; pMapData->nItem = 0;
pMapData->nData = 0; pMapData->nData = 0;
} }
void tMapDataClear(SMapData *pMapData) { void tMapDataClear(SMapData *pMapData) {
if (pMapData->pBuf) { tsdbFree((uint8_t *)pMapData->aOffset);
tsdbFree(pMapData->pBuf); tsdbFree(pMapData->pData);
} else {
tsdbFree(pMapData->pOfst);
tsdbFree(pMapData->pData);
}
}
int32_t tMapDataCopy(SMapData *pMapDataSrc, SMapData *pMapDataDest) {
int32_t code = 0;
int32_t size;
pMapDataDest->nItem = pMapDataSrc->nItem;
pMapDataDest->flag = pMapDataSrc->flag;
switch (pMapDataDest->flag) {
case TSDB_OFFSET_I32:
size = sizeof(int32_t) * pMapDataDest->nItem;
break;
case TSDB_OFFSET_I16:
size = sizeof(int16_t) * pMapDataDest->nItem;
break;
case TSDB_OFFSET_I8:
size = sizeof(int8_t) * pMapDataDest->nItem;
break;
default:
ASSERT(0);
}
code = tsdbRealloc(&pMapDataDest->pOfst, size);
if (code) goto _exit;
memcpy(pMapDataDest->pOfst, pMapDataSrc->pOfst, size);
pMapDataDest->nData = pMapDataSrc->nData;
code = tsdbRealloc(&pMapDataDest->pData, pMapDataDest->nData);
if (code) goto _exit;
memcpy(pMapDataDest->pData, pMapDataSrc->pData, pMapDataDest->nData);
_exit:
return code;
} }
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *)) { int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *)) {
...@@ -77,35 +35,19 @@ int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(u ...@@ -77,35 +35,19 @@ int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(u
pMapData->nData += tPutItemFn(NULL, pItem); pMapData->nData += tPutItemFn(NULL, pItem);
// alloc // alloc
code = tsdbRealloc(&pMapData->pOfst, sizeof(int32_t) * pMapData->nItem); code = tsdbRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem);
if (code) goto _err; if (code) goto _err;
code = tsdbRealloc(&pMapData->pData, pMapData->nData); code = tsdbRealloc(&pMapData->pData, pMapData->nData);
if (code) goto _err; if (code) goto _err;
// put // put
ASSERT(pMapData->flag == TSDB_OFFSET_I32); pMapData->aOffset[nItem] = offset;
((int32_t *)pMapData->pOfst)[nItem] = offset;
tPutItemFn(pMapData->pData + offset, pItem); tPutItemFn(pMapData->pData + offset, pItem);
_err: _err:
return code; return code;
} }
static FORCE_INLINE int32_t tMapDataGetOffset(SMapData *pMapData, int32_t idx) {
switch (pMapData->flag) {
case TSDB_OFFSET_I8:
return ((int8_t *)pMapData->pOfst)[idx];
break;
case TSDB_OFFSET_I16:
return ((int16_t *)pMapData->pOfst)[idx];
break;
case TSDB_OFFSET_I32:
return ((int32_t *)pMapData->pOfst)[idx];
break;
default:
ASSERT(0);
}
}
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *), int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem) { int32_t (*tItemCmprFn)(const void *, const void *), void *pItem) {
int32_t code = 0; int32_t code = 0;
...@@ -135,58 +77,25 @@ _exit: ...@@ -135,58 +77,25 @@ _exit:
return code; return code;
} }
int32_t tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) {
int32_t code = 0; ASSERT(idx >= 0 && idx < pMapData->nItem);
tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem);
if (idx < 0 || idx >= pMapData->nItem) {
code = TSDB_CODE_NOT_FOUND;
goto _exit;
}
tGetItemFn(pMapData->pData + tMapDataGetOffset(pMapData, idx), pItem);
_exit:
return code;
} }
int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
int32_t n = 0; int32_t n = 0;
ASSERT(pMapData->flag == TSDB_OFFSET_I32);
n += tPutI32v(p ? p + n : p, pMapData->nItem); n += tPutI32v(p ? p + n : p, pMapData->nItem);
if (pMapData->nItem) { if (pMapData->nItem) {
int32_t maxOffset = tMapDataGetOffset(pMapData, pMapData->nItem - 1); for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
n += tPutI32v(p ? p + n : p, pMapData->aOffset[iItem]);
if (maxOffset <= INT8_MAX) {
n += tPutU8(p ? p + n : p, TSDB_OFFSET_I8);
if (p) {
for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
n += tPutI8(p + n, (int8_t)tMapDataGetOffset(pMapData, iItem));
}
} else {
n = n + sizeof(int8_t) * pMapData->nItem;
}
} else if (maxOffset <= INT16_MAX) {
n += tPutU8(p ? p + n : p, TSDB_OFFSET_I16);
if (p) {
for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
n += tPutI16(p + n, (int16_t)tMapDataGetOffset(pMapData, iItem));
}
} else {
n = n + sizeof(int16_t) * pMapData->nItem;
}
} else {
n += tPutU8(p ? p + n : p, TSDB_OFFSET_I32);
if (p) {
for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
n += tPutI32(p + n, tMapDataGetOffset(pMapData, iItem));
}
} else {
n = n + sizeof(int32_t) * pMapData->nItem;
}
} }
n += tPutBinary(p ? p + n : p, pMapData->pData, pMapData->nData);
n += tPutI32v(p ? p + n : p, pMapData->nData);
if (p) {
memcpy(p + n, pMapData->pData, pMapData->nData);
}
n += pMapData->nData;
} }
return n; return n;
...@@ -194,26 +103,22 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { ...@@ -194,26 +103,22 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
int32_t tGetMapData(uint8_t *p, SMapData *pMapData) { int32_t tGetMapData(uint8_t *p, SMapData *pMapData) {
int32_t n = 0; int32_t n = 0;
int32_t offset;
tMapDataReset(pMapData);
n += tGetI32v(p + n, &pMapData->nItem); n += tGetI32v(p + n, &pMapData->nItem);
if (pMapData->nItem) { if (pMapData->nItem) {
n += tGetU8(p + n, &pMapData->flag); if (tsdbRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) return -1;
pMapData->pOfst = p + n;
switch (pMapData->flag) { for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) {
case TSDB_OFFSET_I8: n += tGetI32v(p + n, &pMapData->aOffset[iItem]);
n = n + sizeof(int8_t) * pMapData->nItem;
break;
case TSDB_OFFSET_I16:
n = n + sizeof(int16_t) * pMapData->nItem;
break;
case TSDB_OFFSET_I32:
n = n + sizeof(int32_t) * pMapData->nItem;
break;
default:
ASSERT(0);
} }
n += tGetBinary(p + n, &pMapData->pData, &pMapData->nData);
n += tGetI32v(p + n, &pMapData->nData);
if (tsdbRealloc(&pMapData->pData, pMapData->nData)) return -1;
memcpy(pMapData->pData, p + n, pMapData->nData);
n += pMapData->nData;
} }
return n; return n;
...@@ -377,55 +282,8 @@ int32_t tCmprBlockIdx(void const *lhs, void const *rhs) { ...@@ -377,55 +282,8 @@ int32_t tCmprBlockIdx(void const *lhs, void const *rhs) {
// SBlock ====================================================== // SBlock ======================================================
void tBlockReset(SBlock *pBlock) { void tBlockReset(SBlock *pBlock) {
pBlock->minKey = TSDBKEY_MAX; *pBlock =
pBlock->maxKey = TSDBKEY_MIN; (SBlock){.minKey = TSDBKEY_MAX, .maxKey = TSDBKEY_MIN, .minVersion = VERSION_MAX, .maxVersion = VERSION_MIN};
pBlock->minVersion = VERSION_MAX;
pBlock->maxVersion = VERSION_MIN;
pBlock->nRow = 0;
pBlock->last = -1;
pBlock->hasDup = 0;
for (int8_t iSubBlock = 0; iSubBlock < TSDB_MAX_SUBBLOCKS; iSubBlock++) {
pBlock->aSubBlock[iSubBlock].nRow = 0;
pBlock->aSubBlock[iSubBlock].cmprAlg = -1;
pBlock->aSubBlock[iSubBlock].offset = -1;
pBlock->aSubBlock[iSubBlock].szVersion = -1;
pBlock->aSubBlock[iSubBlock].szTSKEY = -1;
pBlock->aSubBlock[iSubBlock].szBlock = -1;
tMapDataReset(&pBlock->aSubBlock->mBlockCol);
}
pBlock->nSubBlock = 0;
}
void tBlockClear(SBlock *pBlock) {
for (int8_t iSubBlock = 0; iSubBlock < TSDB_MAX_SUBBLOCKS; iSubBlock++) {
tMapDataClear(&pBlock->aSubBlock->mBlockCol);
}
}
int32_t tBlockCopy(SBlock *pBlockSrc, SBlock *pBlockDest) {
int32_t code = 0;
pBlockDest->minKey = pBlockSrc->minKey;
pBlockDest->maxKey = pBlockSrc->maxKey;
pBlockDest->minVersion = pBlockSrc->minVersion;
pBlockDest->maxVersion = pBlockSrc->maxVersion;
pBlockDest->nRow = pBlockSrc->nRow;
pBlockDest->last = pBlockSrc->last;
pBlockDest->hasDup = pBlockSrc->hasDup;
pBlockDest->nSubBlock = pBlockSrc->nSubBlock;
for (int32_t iSubBlock = 0; iSubBlock < pBlockSrc->nSubBlock; iSubBlock++) {
pBlockDest->aSubBlock[iSubBlock].nRow = pBlockSrc->aSubBlock[iSubBlock].nRow;
pBlockDest->aSubBlock[iSubBlock].cmprAlg = pBlockSrc->aSubBlock[iSubBlock].cmprAlg;
pBlockDest->aSubBlock[iSubBlock].offset = pBlockSrc->aSubBlock[iSubBlock].offset;
pBlockDest->aSubBlock[iSubBlock].szVersion = pBlockSrc->aSubBlock[iSubBlock].szVersion;
pBlockDest->aSubBlock[iSubBlock].szTSKEY = pBlockSrc->aSubBlock[iSubBlock].szTSKEY;
pBlockDest->aSubBlock[iSubBlock].szBlock = pBlockSrc->aSubBlock[iSubBlock].szBlock;
code = tMapDataCopy(&pBlockSrc->aSubBlock[iSubBlock].mBlockCol, &pBlockDest->aSubBlock[iSubBlock].mBlockCol);
if (code) goto _exit;
}
_exit:
return code;
} }
int32_t tPutBlock(uint8_t *p, void *ph) { int32_t tPutBlock(uint8_t *p, void *ph) {
...@@ -441,13 +299,15 @@ int32_t tPutBlock(uint8_t *p, void *ph) { ...@@ -441,13 +299,15 @@ int32_t tPutBlock(uint8_t *p, void *ph) {
n += tPutI8(p ? p + n : p, pBlock->hasDup); n += tPutI8(p ? p + n : p, pBlock->hasDup);
n += tPutI8(p ? p + n : p, pBlock->nSubBlock); n += tPutI8(p ? p + n : p, pBlock->nSubBlock);
for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) { for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) {
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].nRow); n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].nRow);
n += tPutI8(p ? p + n : p, pBlock->aSubBlock[iSubBlock].cmprAlg); n += tPutI8(p ? p + n : p, pBlock->aSubBlock[iSubBlock].cmprAlg);
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].offset); n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].offset);
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szVersion); n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlockCol);
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szTSKEY); n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szVersion);
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlock); n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szTSKEY);
n += tPutMapData(p ? p + n : p, &pBlock->aSubBlock[iSubBlock].mBlockCol); n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlock);
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].sOffset);
n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].nSma);
} }
return n; return n;
...@@ -466,20 +326,21 @@ int32_t tGetBlock(uint8_t *p, void *ph) { ...@@ -466,20 +326,21 @@ int32_t tGetBlock(uint8_t *p, void *ph) {
n += tGetI8(p + n, &pBlock->hasDup); n += tGetI8(p + n, &pBlock->hasDup);
n += tGetI8(p + n, &pBlock->nSubBlock); n += tGetI8(p + n, &pBlock->nSubBlock);
for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) { for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) {
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].nRow); n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].nRow);
n += tGetI8(p + n, &pBlock->aSubBlock[iSubBlock].cmprAlg); n += tGetI8(p + n, &pBlock->aSubBlock[iSubBlock].cmprAlg);
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].offset); n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].offset);
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].szVersion); n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szBlockCol);
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].szTSKEY); n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szVersion);
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].szBlock); n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szTSKEY);
n += tGetMapData(p + n, &pBlock->aSubBlock[iSubBlock].mBlockCol); n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szBlock);
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].sOffset);
n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].nSma);
} }
return n; return n;
} }
int32_t tBlockCmprFn(const void *p1, const void *p2) { int32_t tBlockCmprFn(const void *p1, const void *p2) {
int32_t c;
SBlock *pBlock1 = (SBlock *)p1; SBlock *pBlock1 = (SBlock *)p1;
SBlock *pBlock2 = (SBlock *)p2; SBlock *pBlock2 = (SBlock *)p2;
...@@ -504,14 +365,11 @@ int32_t tPutBlockCol(uint8_t *p, void *ph) { ...@@ -504,14 +365,11 @@ int32_t tPutBlockCol(uint8_t *p, void *ph) {
n += tPutI8(p ? p + n : p, pBlockCol->flag); n += tPutI8(p ? p + n : p, pBlockCol->flag);
if (pBlockCol->flag != HAS_NULL) { if (pBlockCol->flag != HAS_NULL) {
n += tPutI64v(p ? p + n : p, pBlockCol->offset); n += tPutI32v(p ? p + n : p, pBlockCol->offset);
if (pBlockCol->flag != HAS_VALUE) { n += tPutI32v(p ? p + n : p, pBlockCol->szBitmap);
n += tPutI64v(p ? p + n : p, pBlockCol->bsize); n += tPutI32v(p ? p + n : p, pBlockCol->szOffset);
} n += tPutI32v(p ? p + n : p, pBlockCol->szValue);
n += tPutI64v(p ? p + n : p, pBlockCol->csize); n += tPutI32v(p ? p + n : p, pBlockCol->szOrigin);
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
n += tPutI64v(p ? p + n : p, pBlockCol->osize);
}
} }
return n; return n;
...@@ -528,18 +386,11 @@ int32_t tGetBlockCol(uint8_t *p, void *ph) { ...@@ -528,18 +386,11 @@ int32_t tGetBlockCol(uint8_t *p, void *ph) {
ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE)); ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE));
if (pBlockCol->flag != HAS_NULL) { if (pBlockCol->flag != HAS_NULL) {
n += tGetI64v(p + n, &pBlockCol->offset); n += tGetI32v(p + n, &pBlockCol->offset);
if (pBlockCol->flag != HAS_VALUE) { n += tGetI32v(p + n, &pBlockCol->szBitmap);
n += tGetI64v(p + n, &pBlockCol->bsize); n += tGetI32v(p + n, &pBlockCol->szOffset);
} else { n += tGetI32v(p + n, &pBlockCol->szValue);
pBlockCol->bsize = 0; n += tGetI32v(p + n, &pBlockCol->szOrigin);
}
n += tGetI64v(p + n, &pBlockCol->csize);
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
n += tGetI64v(p + n, &pBlockCol->osize);
} else {
pBlockCol->osize = -1;
}
} }
return n; return n;
...@@ -942,12 +793,12 @@ int32_t tGetKEYINFO(uint8_t *p, KEYINFO *pKeyInfo) { ...@@ -942,12 +793,12 @@ int32_t tGetKEYINFO(uint8_t *p, KEYINFO *pKeyInfo) {
} }
// SColData ======================================== // SColData ========================================
void tColDataReset(SColData *pColData, int16_t cid, int8_t type) { void tColDataReset(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn) {
pColData->cid = cid; pColData->cid = cid;
pColData->type = type; pColData->type = type;
pColData->smaOn = smaOn;
pColData->nVal = 0; pColData->nVal = 0;
pColData->flag = 0; pColData->flag = 0;
pColData->offsetValid = 0;
pColData->nData = 0; pColData->nData = 0;
} }
...@@ -977,26 +828,35 @@ int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) { ...@@ -977,26 +828,35 @@ int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) {
if (pColVal->isNone) { if (pColVal->isNone) {
pColData->flag |= HAS_NONE; pColData->flag |= HAS_NONE;
SET_BIT2(pColData->pBitMap, pColData->nVal, 0); SET_BIT2(pColData->pBitMap, pColData->nVal, 0);
if (IS_VAR_DATA_TYPE(pColData->type)) pValue = NULL;
} else if (pColVal->isNull) { } else if (pColVal->isNull) {
pColData->flag |= HAS_NULL; pColData->flag |= HAS_NULL;
SET_BIT2(pColData->pBitMap, pColData->nVal, 1); SET_BIT2(pColData->pBitMap, pColData->nVal, 1);
if (IS_VAR_DATA_TYPE(pColData->type)) pValue = NULL;
} else { } else {
pColData->flag |= HAS_VALUE; pColData->flag |= HAS_VALUE;
SET_BIT2(pColData->pBitMap, pColData->nVal, 2); SET_BIT2(pColData->pBitMap, pColData->nVal, 2);
pValue = &pColVal->value; pValue = &pColVal->value;
} }
if (pValue) { if (IS_VAR_DATA_TYPE(pColData->type)) {
code = tsdbRealloc(&pColData->pData, pColData->nData + tPutValue(NULL, &pColVal->value, pColVal->type)); // offset
code = tsdbRealloc((uint8_t **)&pColData->aOffset, sizeof(int32_t) * (pColData->nVal + 1));
if (code) goto _exit; if (code) goto _exit;
pColData->aOffset[pColData->nVal] = pColData->nData;
pColData->nData += tPutValue(pColData->pData + pColData->nData, &pColVal->value, pColVal->type); // value
if ((!pColVal->isNone) && (!pColVal->isNull)) {
code = tsdbRealloc(&pColData->pData, pColData->nData + pColVal->value.nData);
if (code) goto _exit;
memcpy(pColData->pData + pColData->nData, pColVal->value.pData, pColVal->value.nData);
pColData->nData += pColVal->value.nData;
}
} else {
code = tsdbRealloc(&pColData->pData, pColData->nData + tPutValue(NULL, pValue, pColVal->type));
if (code) goto _exit;
pColData->nData += tPutValue(pColData->pData + pColData->nData, pValue, pColVal->type);
} }
pColData->nVal++; pColData->nVal++;
pColData->offsetValid = 0;
_exit: _exit:
return code; return code;
...@@ -1004,57 +864,33 @@ _exit: ...@@ -1004,57 +864,33 @@ _exit:
int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest) { int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest) {
int32_t code = 0; int32_t code = 0;
int32_t size;
pColDataDest->cid = pColDataDest->cid; pColDataDest->cid = pColDataSrc->cid;
pColDataDest->type = pColDataDest->type; pColDataDest->type = pColDataSrc->type;
pColDataDest->offsetValid = 0; pColDataDest->smaOn = pColDataSrc->smaOn;
pColDataDest->nVal = pColDataSrc->nVal; pColDataDest->nVal = pColDataSrc->nVal;
pColDataDest->flag = pColDataSrc->flag; pColDataDest->flag = pColDataSrc->flag;
if (pColDataSrc->flag != HAS_NONE && pColDataSrc->flag != HAS_NULL && pColDataSrc->flag != HAS_VALUE) {
code = tsdbRealloc(&pColDataDest->pBitMap, BIT2_SIZE(pColDataDest->nVal));
if (code) goto _exit;
memcpy(pColDataDest->pBitMap, pColDataSrc->pBitMap, BIT2_SIZE(pColDataSrc->nVal)); size = BIT2_SIZE(pColDataSrc->nVal);
} code = tsdbRealloc(&pColDataDest->pBitMap, size);
pColDataDest->nData = pColDataSrc->nData;
code = tsdbRealloc(&pColDataDest->pData, pColDataSrc->nData);
if (code) goto _exit; if (code) goto _exit;
memcpy(pColDataDest->pData, pColDataSrc->pData, pColDataSrc->nData); memcpy(pColDataDest->pBitMap, pColDataSrc->pBitMap, size);
_exit: if (IS_VAR_DATA_TYPE(pColDataDest->type)) {
return code; size = sizeof(int32_t) * pColDataSrc->nVal;
}
static int32_t tColDataUpdateOffset(SColData *pColData) { code = tsdbRealloc((uint8_t **)&pColDataDest->aOffset, size);
int32_t code = 0;
SValue value;
ASSERT(pColData->nVal > 0);
ASSERT(pColData->flag);
ASSERT(IS_VAR_DATA_TYPE(pColData->type));
if ((pColData->flag & HAS_VALUE)) {
code = tsdbRealloc((uint8_t **)&pColData->aOffset, sizeof(int32_t) * pColData->nVal);
if (code) goto _exit; if (code) goto _exit;
int32_t offset = 0; memcpy(pColDataDest->aOffset, pColDataSrc->aOffset, size);
for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) {
if (pColData->flag != HAS_VALUE) {
uint8_t v = GET_BIT2(pColData->pBitMap, iVal);
if (v == 0 || v == 1) {
pColData->aOffset[iVal] = -1;
continue;
}
}
pColData->aOffset[iVal] = offset;
offset += tGetValue(pColData->pData + offset, &value, pColData->type);
}
ASSERT(offset == pColData->nData);
pColData->offsetValid = 1;
} }
code = tsdbRealloc(&pColDataDest->pData, pColDataSrc->nData);
if (code) goto _exit;
pColDataDest->nData = pColDataSrc->nData;
memcpy(pColDataDest->pData, pColDataSrc->pData, pColDataDest->nData);
_exit: _exit:
return code; return code;
} }
...@@ -1085,11 +921,13 @@ int32_t tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) { ...@@ -1085,11 +921,13 @@ int32_t tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) {
// get value // get value
SValue value; SValue value;
if (IS_VAR_DATA_TYPE(pColData->type)) { if (IS_VAR_DATA_TYPE(pColData->type)) {
if (!pColData->offsetValid) { if (iVal + 1 < pColData->nVal) {
code = tColDataUpdateOffset(pColData); value.nData = pColData->aOffset[iVal + 1] - pColData->aOffset[iVal];
if (code) goto _exit; } else {
value.nData = pColData->nData - pColData->aOffset[iVal];
} }
tGetValue(pColData->pData + pColData->aOffset[iVal], &value, pColData->type);
value.pData = pColData->pData + pColData->aOffset[iVal];
} else { } else {
tGetValue(pColData->pData + tDataTypes[pColData->type].bytes * iVal, &value, pColData->type); tGetValue(pColData->pData + tDataTypes[pColData->type].bytes * iVal, &value, pColData->type);
} }
...@@ -1210,7 +1048,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS ...@@ -1210,7 +1048,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
if (code) goto _err; if (code) goto _err;
// append a NONE // append a NONE
tColDataReset(pColData, pColVal->cid, pColVal->type); tColDataReset(pColData, pColVal->cid, pColVal->type, 0);
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) { for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColVal->cid, pColVal->type)); code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColVal->cid, pColVal->type));
if (code) goto _err; if (code) goto _err;
...@@ -1240,7 +1078,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS ...@@ -1240,7 +1078,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
code = tBlockDataAddColData(pBlockData, iColData, &pColData); code = tBlockDataAddColData(pBlockData, iColData, &pColData);
if (code) goto _err; if (code) goto _err;
tColDataReset(pColData, pColVal->cid, pColVal->type); tColDataReset(pColData, pColVal->cid, pColVal->type, 0);
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) { for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColVal->cid, pColVal->type)); code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColVal->cid, pColVal->type));
if (code) goto _err; if (code) goto _err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册