From 85b4896fa45a8173972db16778bfc73fa6077f1e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 11 Jul 2022 12:48:16 +0000 Subject: [PATCH] more row refact --- include/common/tdataformat.h | 10 ---------- include/common/trow.h | 2 +- source/common/src/tdataformat.c | 14 +++++++------- source/common/test/dataformatTest.cpp | 4 ++-- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 6d1a4b46aa..87b0cae175 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -230,16 +230,6 @@ struct STag { memcpy(varDataVal(x), (str), (_size)); \ } while (0); -// ----------------- TSDB SCHEMA DEFINITION - -#define schemaNCols(s) ((s)->numOfCols) -#define schemaVersion(s) ((s)->version) -#define schemaTLen(s) ((s)->tlen) -#define schemaFLen(s) ((s)->flen) -#define schemaVLen(s) ((s)->vlen) -#define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) taosMemoryFreeClear((s)) - // ----------------- SCHEMA BUILDER DEFINITION typedef struct { int32_t tCols; diff --git a/include/common/trow.h b/include/common/trow.h index bd9dc82b0e..807a4c0f0a 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -168,7 +168,7 @@ typedef struct { // N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and // (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined. -#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN) +#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) ((s)->tlen + TD_ROW_HEAD_LEN) #define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i)) #define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index d9a70172c8..8eeab77a15 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -1137,17 +1137,17 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder) { STSchema *pSchema = (STSchema *)taosMemoryMalloc(tlen); if (pSchema == NULL) return NULL; - schemaVersion(pSchema) = pBuilder->version; - schemaNCols(pSchema) = pBuilder->nCols; - schemaTLen(pSchema) = pBuilder->tlen; - schemaFLen(pSchema) = pBuilder->flen; - schemaVLen(pSchema) = pBuilder->vlen; + pSchema->version = pBuilder->version; + pSchema->numOfCols = pBuilder->nCols; + pSchema->tlen = pBuilder->tlen; + pSchema->flen = pBuilder->flen; + pSchema->vlen = pBuilder->vlen; #ifdef TD_SUPPORT_BITMAP - schemaTLen(pSchema) += (int)TD_BITMAP_BYTES(schemaNCols(pSchema)); + pSchema->tlen += (int)TD_BITMAP_BYTES(pSchema->numOfCols); #endif - memcpy(schemaColAt(pSchema, 0), pBuilder->columns, sizeof(STColumn) * pBuilder->nCols); + memcpy(&pSchema->columns[0], pBuilder->columns, sizeof(STColumn) * pBuilder->nCols); return pSchema; } diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index a52bb6b516..d17f2a0ac6 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -286,7 +286,7 @@ int32_t debugPrintSColVal(SColVal *cv, int8_t type) { void debugPrintTSRow(STSRow2 *row, STSchema *pTSchema, const char *tags, int32_t ln) { printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData); - for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + for (int16_t i = 0; i < pTSchema->numOfCols; ++i) { SColVal cv = {0}; tTSRowGet(row, pTSchema, i, &cv); debugPrintSColVal(&cv, pTSchema->columns[i].type); @@ -393,7 +393,7 @@ static int32_t checkSColVal(const char *rawVal, SColVal *cv, int8_t type) { } static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) { - for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + for (int16_t i = 0; i < pTSchema->numOfCols; ++i) { SColVal cv = {0}; tTSRowGet(row, pTSchema, i, &cv); checkSColVal(data[i], &cv, pTSchema->columns[i].type);