diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 6a73d3d67839bde8c63c0710170602e2ddfa8ad1..9ce39e7966a918dbca5190aa453408db2993fd4f 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -42,7 +42,9 @@ int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema * void tTSchemaDestroy(STSchema *pTSchema); // SValue -int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type); +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); +int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); // STSRow2 #define COL_VAL_NONE(CID) ((SColVal){.cid = (CID), .isNone = 1}) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1ddb606ccfa2f721e5de4b704a2c63ff2fd4fe6e..d2206735b450adc3da97156742d0a231579eda6f 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -37,7 +37,7 @@ typedef struct { #define GET_BIT2(p, i) (((p)[(i) / 4] >> ((i) % 4)) & ((uint8_t)3)) // SValue -static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -88,7 +88,7 @@ static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { return n; } -static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { +int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -421,7 +421,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_none: if ((flags & 0xf0) == 0) { setBitMap(pb, 0, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -434,7 +434,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S _set_null: if ((flags & 0xf0) == 0) { setBitMap(pb, 1, iColumn - 1, flags); - if (flags & TSROW_HAS_VAL) { // set 0 + if (flags & TSROW_HAS_VAL) { // set 0 if (IS_VAR_DATA_TYPE(pTColumn->type)) { *(VarDataOffsetT *)(pf + pTColumn->offset) = 0; } else { @@ -1109,9 +1109,9 @@ _err: #if 1 // =================================================================================================================== static void dataColSetNEleNull(SDataCol *pCol, int nEle); int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { - int spaceNeeded = pCol->bytes * maxPoints; - if (IS_VAR_DATA_TYPE(pCol->type)) { - spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; + int spaceNeeded = pCol->bytes * maxPoints; + if (IS_VAR_DATA_TYPE(pCol->type)) { + spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; } #ifdef TD_SUPPORT_BITMAP int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(maxPoints); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index d3e66dc3df756221e740ba828a540d000f6ec183..cb4c04eec59747868d30a052ca089454a384d9b7 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -31,22 +31,23 @@ extern "C" { #define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -typedef struct TSDBROW TSDBROW; -typedef struct TSDBKEY TSDBKEY; -typedef struct TABLEID TABLEID; -typedef struct SDelOp SDelOp; -typedef struct SDelDataItem SDelDataItem; -typedef struct SDelData SDelData; -typedef struct SDelIdxItem SDelIdxItem; -typedef struct SDelIdx SDelIdx; -typedef struct STbData STbData; -typedef struct SMemTable SMemTable; -typedef struct STbDataIter STbDataIter; -typedef struct SMergeInfo SMergeInfo; -typedef struct STable STable; -typedef struct SOffset SOffset; -typedef struct SMapData SMapData; -typedef struct SVDataCols SVDataCols; +typedef struct TSDBROW TSDBROW; +typedef struct TSDBKEY TSDBKEY; +typedef struct TABLEID TABLEID; +typedef struct SDelOp SDelOp; +typedef struct SDelDataItem SDelDataItem; +typedef struct SDelData SDelData; +typedef struct SDelIdxItem SDelIdxItem; +typedef struct SDelIdx SDelIdx; +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct SMergeInfo SMergeInfo; +typedef struct STable STable; +typedef struct SOffset SOffset; +typedef struct SMapData SMapData; +typedef struct SColData SColData; +typedef struct SColDataBlock SColDataBlock; // tsdbMemTable ============================================================================================== @@ -270,8 +271,16 @@ int tsdbLockRepo(STsdb *pTsdb); int tsdbUnlockRepo(STsdb *pTsdb); struct TSDBROW { - int64_t version; - STSRow *pTSRow; + union { + struct { + int64_t version; + STSRow *pTSRow; + }; + struct { + SColDataBlock *pColDataBlock; + int32_t iRow; + }; + }; }; struct SBlockIdxItem { @@ -449,8 +458,19 @@ struct SMapData { uint8_t *pData; }; -struct SVDataCols { - int64_t *aVersion; +struct SColData { + int16_t cid; + uint8_t flags; + uint32_t nData; + uint8_t *pData; +}; + +struct SColDataBlock { + int32_t nRow; + int64_t *aVersion; + TSKEY *aTSKey; + int32_t nColData; + SColData *aColData; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 1655f222ac0c487b4bf92d600c6a92473d9f736e..8aabd6dcd876cb0e4c4be025dc53df48001f5aaf 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -40,8 +40,8 @@ struct SCommitter { SBlockIdx *pBlockIdx; SMapData oBlock; SMapData nBlock; - SColDataBatch oBatch; - SColDataBatch nBatch; + SColDataBlock oColDataBlock; + SColDataBlock nColDataBlock; /* commit del */ SDelFReader *pDelFReader; SDelFWriter *pDelFWriter; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 950b1fbd113d8beaaec3b021917c0772679bcf29..15782256f835cac1403ca116ef0ce712b7521a4d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -726,4 +726,41 @@ int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision) { } } -// SColDataBlock ====================================================== \ No newline at end of file +// TSDBROW ====================================================== +void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { + // TODO +} + +// SColDataBlock ====================================================== +int32_t tsdbColDataBlockAppend(SColDataBlock *pColDataBlock, TSDBROW *pRow, STSchema *pTSchema) { + int32_t code = 0; + int32_t nRow = pColDataBlock->nRow; + STColumn *pTColumn; + SColData *pColData; + SColVal colVal; + + pColDataBlock->nRow++; + + // version + pColDataBlock->aVersion[nRow] = pRow->version; // TODO + + // ts + pColDataBlock->aTSKey[nRow] = pRow->pTSRow->ts; // TODO + + // other rows + for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) { + pTColumn = &pTSchema->columns[iCol]; + + tsdbRowGetColVal(pRow, pTSchema, iCol, &colVal); + + if (colVal.isNone) { + // TODO + } else if (colVal.isNull) { + // TODO + } else { + pColData->nData += tPutValue(pColData->pData + pColData->nData, &colVal.value, pTColumn->type); + } + } + + return code; +} \ No newline at end of file