From 02b81258f5e9448346b80154fab1abda8920bb39 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Jun 2022 12:44:23 +0000 Subject: [PATCH] more --- include/common/tdataformat.h | 7 - source/common/src/tdataformat.c | 260 +------------------------------- 2 files changed, 1 insertion(+), 266 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 2d740c1af7..539587b47a 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -55,13 +55,6 @@ int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow); int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow); // STSRowBuilder -#if 0 -int32_t tTSRowBuilderInit(STSRowBuilder *pBuilder, int32_t sver, int32_t nCols, SSchema *pSchema); -void tTSRowBuilderClear(STSRowBuilder *pBuilder); -void tTSRowBuilderReset(STSRowBuilder *pBuilder); -int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, uint8_t *pData, uint32_t nData); -int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow); -#endif // STag int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index c53a22b408..1f6f0a896e 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -626,266 +626,8 @@ void tTSchemaDestroy(STSchema *pTSchema) { } // STSRowBuilder -#if 0 -int32_t tTSRowBuilderInit(STSRowBuilder *pBuilder, int32_t sver, int32_t nCols, SSchema *pSchema) { - if (tTSchemaCreate(sver, pSchema, nCols, &pBuilder->pTSchema) < 0) return -1; - - pBuilder->szBitMap1 = BIT1_SIZE(nCols - 1); - pBuilder->szBitMap2 = BIT2_SIZE(nCols - 1); - pBuilder->szKVBuf = - sizeof(STSKVRow) + sizeof(SKVIdx) * (nCols - 1) + pBuilder->pTSchema->flen + pBuilder->pTSchema->vlen; - pBuilder->szTPBuf = pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->pTSchema->vlen; - pBuilder->pKVBuf = taosMemoryMalloc(pBuilder->szKVBuf); - if (pBuilder->pKVBuf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - tTSchemaDestroy(pBuilder->pTSchema); - return -1; - } - pBuilder->pTPBuf = taosMemoryMalloc(pBuilder->szTPBuf); - if (pBuilder->pTPBuf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - taosMemoryFree(pBuilder->pKVBuf); - tTSchemaDestroy(pBuilder->pTSchema); - return -1; - } - - return 0; -} - -void tTSRowBuilderClear(STSRowBuilder *pBuilder) { - if (pBuilder->pTPBuf) { - taosMemoryFree(pBuilder->pTPBuf); - pBuilder->pTPBuf = NULL; - } - if (pBuilder->pKVBuf) { - taosMemoryFree(pBuilder->pKVBuf); - pBuilder->pKVBuf = NULL; - } - tTSchemaDestroy(pBuilder->pTSchema); - pBuilder->pTSchema = NULL; -} - -void tTSRowBuilderReset(STSRowBuilder *pBuilder) { - for (int32_t iCol = pBuilder->pTSchema->numOfCols - 1; iCol >= 0; iCol--) { - STColumn *pTColumn = &pBuilder->pTSchema->columns[iCol]; - COL_CLR_SET(pTColumn->flags); - } - - pBuilder->iCol = 0; - ((STSKVRow *)pBuilder->pKVBuf)->nCols = 0; - pBuilder->vlenKV = 0; - pBuilder->vlenTP = 0; - pBuilder->row.flags = 0; -} - -int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, uint8_t *pData, uint32_t nData) { - STColumn *pTColumn = &pBuilder->pTSchema->columns[pBuilder->iCol]; - uint8_t *p; - int32_t iCol; - STSKVRow *pTSKVRow = (STSKVRow *)pBuilder->pKVBuf; - - // use interp search - if (pTColumn->colId < cid) { // right search - for (iCol = pBuilder->iCol + 1; iCol < pBuilder->pTSchema->numOfCols; iCol++) { - pTColumn = &pBuilder->pTSchema->columns[iCol]; - if (pTColumn->colId >= cid) break; - } - } else if (pTColumn->colId > cid) { // left search - for (iCol = pBuilder->iCol - 1; iCol >= 0; iCol--) { - pTColumn = &pBuilder->pTSchema->columns[iCol]; - if (pTColumn->colId <= cid) break; - } - } - - if (pTColumn->colId != cid || COL_IS_SET(pTColumn->flags)) { - return -1; - } - - pBuilder->iCol = iCol; - - // set value - if (cid == 0) { - ASSERT(pData && nData == sizeof(TSKEY) && iCol == 0); - pBuilder->row.ts = *(TSKEY *)pData; - pTColumn->flags |= COL_SET_VAL; - } else { - if (pData) { - // set VAL - - pBuilder->row.flags |= TSROW_HAS_VAL; - pTColumn->flags |= COL_SET_VAL; - - /* KV */ - if (1) { // avoid KV at some threshold (todo) - pTSKVRow->idx[pTSKVRow->nCols].cid = cid; - pTSKVRow->idx[pTSKVRow->nCols].offset = pBuilder->vlenKV; - - p = pBuilder->pKVBuf + sizeof(STSKVRow) + sizeof(SKVIdx) * (pBuilder->pTSchema->numOfCols - 1) + - pBuilder->vlenKV; - if (IS_VAR_DATA_TYPE(pTColumn->type)) { - ASSERT(nData <= pTColumn->bytes); - pBuilder->vlenKV += tPutBinary(p, pData, nData); - } else { - ASSERT(nData == pTColumn->bytes); - memcpy(p, pData, nData); - pBuilder->vlenKV += nData; - } - } - - /* TUPLE */ - p = pBuilder->pTPBuf + pBuilder->szBitMap2 + pTColumn->offset; - if (IS_VAR_DATA_TYPE(pTColumn->type)) { - ASSERT(nData <= pTColumn->bytes); - *(int32_t *)p = pBuilder->vlenTP; - - p = pBuilder->pTPBuf + pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->vlenTP; - pBuilder->vlenTP += tPutBinary(p, pData, nData); - } else { - ASSERT(nData == pTColumn->bytes); - memcpy(p, pData, nData); - } - } else { - // set NULL - - pBuilder->row.flags |= TSROW_HAS_NULL; - pTColumn->flags |= COL_SET_NULL; - - pTSKVRow->idx[pTSKVRow->nCols].cid = cid; - pTSKVRow->idx[pTSKVRow->nCols].offset = -1; - } - - pTSKVRow->nCols++; - } - - return 0; -} - -static FORCE_INLINE int tSKVIdxCmprFn(const void *p1, const void *p2) { - SKVIdx *pKVIdx1 = (SKVIdx *)p1; - SKVIdx *pKVIdx2 = (SKVIdx *)p2; - if (pKVIdx1->cid > pKVIdx2->cid) { - return 1; - } else if (pKVIdx1->cid < pKVIdx2->cid) { - return -1; - } - return 0; -} -static void setBitMap(uint8_t *p, STSchema *pTSchema, uint8_t flags) { - int32_t bidx; - STColumn *pTColumn; - - for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) { - pTColumn = &pTSchema->columns[iCol]; - bidx = iCol - 1; - - switch (flags) { - case TSROW_HAS_NULL | TSROW_HAS_NONE: - if (pTColumn->flags & COL_SET_NULL) { - SET_BIT1(p, bidx, (uint8_t)1); - } else { - SET_BIT1(p, bidx, (uint8_t)0); - } - break; - case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE: - if (pTColumn->flags & COL_SET_NULL) { - SET_BIT2(p, bidx, (uint8_t)1); - } else if (pTColumn->flags & COL_SET_VAL) { - SET_BIT2(p, bidx, (uint8_t)2); - } else { - SET_BIT2(p, bidx, (uint8_t)0); - } - break; - default: - if (pTColumn->flags & COL_SET_VAL) { - SET_BIT1(p, bidx, (uint8_t)1); - } else { - SET_BIT1(p, bidx, (uint8_t)0); - } - - break; - } - } -} -int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) { - int32_t nDataTP, nDataKV; - STSKVRow *pTSKVRow = (STSKVRow *)pBuilder->pKVBuf; - int32_t nCols = pBuilder->pTSchema->numOfCols; - - // error not set ts - if (!COL_IS_SET(pBuilder->pTSchema->columns->flags)) { - return -1; - } - - ASSERT(pTSKVRow->nCols < nCols); - if (pTSKVRow->nCols < nCols - 1) { - pBuilder->row.flags |= TSROW_HAS_NONE; - } - - ASSERT((pBuilder->row.flags & 0xf) != 0); - *(ppRow) = &pBuilder->row; - switch (pBuilder->row.flags & 0xf) { - case TSROW_HAS_NONE: - case TSROW_HAS_NULL: - pBuilder->row.nData = 0; - pBuilder->row.pData = NULL; - return 0; - case TSROW_HAS_NULL | TSROW_HAS_NONE: - nDataTP = pBuilder->szBitMap1; - break; - case TSROW_HAS_VAL: - nDataTP = pBuilder->pTSchema->flen + pBuilder->vlenTP; - break; - case TSROW_HAS_VAL | TSROW_HAS_NONE: - case TSROW_HAS_VAL | TSROW_HAS_NULL: - nDataTP = pBuilder->szBitMap1 + pBuilder->pTSchema->flen + pBuilder->vlenTP; - break; - case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE: - nDataTP = pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->vlenTP; - break; - default: - ASSERT(0); - } - - nDataKV = sizeof(STSKVRow) + sizeof(SKVIdx) * pTSKVRow->nCols + pBuilder->vlenKV; - pBuilder->row.sver = pBuilder->pTSchema->version; - if (nDataKV < nDataTP) { - // generate KV row - - ASSERT((pBuilder->row.flags & 0xf) != TSROW_HAS_VAL); - - pBuilder->row.flags |= TSROW_KV_ROW; - pBuilder->row.nData = nDataKV; - pBuilder->row.pData = pBuilder->pKVBuf; - - qsort(pTSKVRow->idx, pTSKVRow->nCols, sizeof(SKVIdx), tSKVIdxCmprFn); - if (pTSKVRow->nCols < nCols - 1) { - memmove(&pTSKVRow->idx[pTSKVRow->nCols], &pTSKVRow->idx[nCols - 1], pBuilder->vlenKV); - } - } else { - // generate TUPLE row - - pBuilder->row.nData = nDataTP; - - uint8_t *p; - uint8_t flags = (pBuilder->row.flags & 0xf); - - if (flags == TSROW_HAS_VAL) { - pBuilder->row.pData = pBuilder->pTPBuf + pBuilder->szBitMap2; - } else { - if (flags == (TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE)) { - pBuilder->row.pData = pBuilder->pTPBuf; - } else { - pBuilder->row.pData = pBuilder->pTPBuf + pBuilder->szBitMap2 - pBuilder->szBitMap1; - } - - setBitMap(pBuilder->row.pData, pBuilder->pTSchema, flags); - } - } - - return 0; -} -#endif +// STag static int tTagValCmprFn(const void *p1, const void *p2) { if (((STagVal *)p1)->cid < ((STagVal *)p2)->cid) { return -1;