From 68bd0ccd5ce369c04c17ab085893c5581bb51580 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Fri, 20 Dec 2024 16:35:24 +0800 Subject: [PATCH 1/4] refactor SValue --- include/common/tdataformat.h | 22 ++++ source/common/src/msg/tmsg.c | 6 +- source/common/src/tdatablock.c | 27 +++-- source/common/src/tdataformat.c | 120 ++++++++++++------- source/common/src/trow.c | 4 +- source/dnode/vnode/src/tq/tqRead.c | 2 +- source/dnode/vnode/src/tq/tqSink.c | 2 +- source/dnode/vnode/src/tsdb/tsdbCache.c | 34 +++--- source/dnode/vnode/src/tsdb/tsdbCacheRead.c | 8 +- source/dnode/vnode/src/tsdb/tsdbRead2.c | 23 ++-- source/dnode/vnode/src/tsdb/tsdbReadUtil.c | 30 ++--- source/dnode/vnode/src/tsdb/tsdbUtil.c | 17 +-- source/dnode/vnode/src/vnd/vnodeSvr.c | 6 +- source/libs/executor/src/dataInserter.c | 2 +- source/libs/executor/src/scanoperator.c | 7 +- source/libs/executor/src/timesliceoperator.c | 4 +- source/libs/function/src/builtinsimpl.c | 8 +- source/libs/parser/src/parInsertSml.c | 6 +- source/libs/parser/src/parInsertSql.c | 57 +++++---- 19 files changed, 232 insertions(+), 153 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 0b34e882c80c..9dfb5f469922 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -242,6 +242,8 @@ typedef struct { uint32_t offset; } SPrimaryKeyIndex; +#define DATUM_MAX_SIZE 16 + struct SValue { int8_t type; union { @@ -253,6 +255,26 @@ struct SValue { }; }; +// TODO wjm remove type parameter maybe +#define VALUE_GET_DATUM(pVal, type) \ + IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL ? (pVal)->pData : (void*)&(pVal)->val + +#define VALUE_GET_TRIVIAL_DATUM(pVal) ((pVal)->val) +#define VALUE_SET_TRIVIAL_DATUM(pVal, v) (pVal)->val = v + +void valueSetDatum(SValue *pVal, int8_t type, const void *pDatum, uint32_t len); +void valueCloneDatum(SValue *pDst, const SValue *pSrc, int8_t type); +void valueClearDatum(SValue *pVal, int8_t type); + +//uint8_t* valueGetVarDatum(const SValue *pVal); +//uint32_t valueGetVarNDatum(const SValue *pVal); +//void valueSetVarDatum(SValue *pVal, uint8_t *pData, uint32_t nData); + +//DecimalWord* valueGetDecimalDatum(const SValue *pVal); +//uint32_t valueGetDecimalWordNum(const SValue *pVal); +//void valueSetDecimalDatum(SValue *pVal, DecimalWord *words, int32_t wordNum); + + #define TD_MAX_PK_COLS 2 struct SRowKey { TSKEY ts; diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index 2193c7983f77..ff72581924b3 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -11041,7 +11041,7 @@ int32_t tEncodeSTqOffsetVal(SEncoder *pEncoder, const STqOffsetVal *pOffsetVal) if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) { TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pOffsetVal->primaryKey.pData, pOffsetVal->primaryKey.nData)); } else { - TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pOffsetVal->primaryKey.val)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, VALUE_GET_TRIVIAL_DATUM(&pOffsetVal->primaryKey))); } } else if (pOffsetVal->type == TMQ_OFFSET__LOG) { @@ -11072,7 +11072,7 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) { TAOS_CHECK_EXIT( tDecodeBinaryAlloc32(pDecoder, (void **)&pOffsetVal->primaryKey.pData, &pOffsetVal->primaryKey.nData)); } else { - TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->primaryKey.val)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &VALUE_GET_TRIVIAL_DATUM(&pOffsetVal->primaryKey))); } } } else if (pOffsetVal->type == TMQ_OFFSET__LOG) { @@ -11103,7 +11103,7 @@ void tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { taosMemoryFree(tmp); } else { (void)snprintf(buf, maxLen, "tsdb:%" PRId64 "|%" PRId64 ",pk type:%d,val:%" PRId64, pVal->uid, pVal->ts, - pVal->primaryKey.type, pVal->primaryKey.val); + pVal->primaryKey.type, VALUE_GET_TRIVIAL_DATUM(&pVal->primaryKey)); } } } diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index bd18c9ceb94b..b7d1f10e2c27 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -676,10 +676,13 @@ int32_t blockDataUpdatePkRange(SSDataBlock* pDataBlock, int32_t pkColumnIndex, b void* skey = colDataGetData(pColInfoData, 0); void* ekey = colDataGetData(pColInfoData, (pInfo->rows - 1)); + int64_t val = 0; if (asc) { if (IS_NUMERIC_TYPE(pColInfoData->info.type)) { - GET_TYPED_DATA(pInfo->pks[0].val, int64_t, pColInfoData->info.type, skey); - GET_TYPED_DATA(pInfo->pks[1].val, int64_t, pColInfoData->info.type, ekey); + GET_TYPED_DATA(val, int64_t, pColInfoData->info.type, skey); + VALUE_SET_TRIVIAL_DATUM(&pInfo->pks[0], val); + GET_TYPED_DATA(val, int64_t, pColInfoData->info.type, ekey); + VALUE_SET_TRIVIAL_DATUM(&pInfo->pks[1], val); } else { // todo refactor memcpy(pInfo->pks[0].pData, varDataVal(skey), varDataLen(skey)); pInfo->pks[0].nData = varDataLen(skey); @@ -689,8 +692,10 @@ int32_t blockDataUpdatePkRange(SSDataBlock* pDataBlock, int32_t pkColumnIndex, b } } else { if (IS_NUMERIC_TYPE(pColInfoData->info.type)) { - GET_TYPED_DATA(pInfo->pks[0].val, int64_t, pColInfoData->info.type, ekey); - GET_TYPED_DATA(pInfo->pks[1].val, int64_t, pColInfoData->info.type, skey); + GET_TYPED_DATA(val, int64_t, pColInfoData->info.type, ekey); + VALUE_SET_TRIVIAL_DATUM(&pInfo->pks[0], val); + GET_TYPED_DATA(val, int64_t, pColInfoData->info.type, skey); + VALUE_SET_TRIVIAL_DATUM(&pInfo->pks[1], val); } else { // todo refactor memcpy(pInfo->pks[0].pData, varDataVal(ekey), varDataLen(ekey)); pInfo->pks[0].nData = varDataLen(ekey); @@ -2754,7 +2759,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; return terrno; } - SColVal cv = COL_VAL_VALUE(pCol->colId, ((SValue){.type = pCol->type, .val = *(TSKEY*)var})); + SValue val = {.type = pCol->type}; + VALUE_SET_TRIVIAL_DATUM(&val, *(TSKEY*)var); + SColVal cv = COL_VAL_VALUE(pCol->colId, val); void* px = taosArrayPush(pVals, &cv); if (px == NULL) { return terrno; @@ -2767,7 +2774,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat return terrno; } } else { - SColVal cv = COL_VAL_VALUE(pCol->colId, ((SValue){.type = pCol->type, .val = *(int64_t*)var})); + SValue val = {.type = pCol->type}; + VALUE_SET_TRIVIAL_DATUM(&val, *(int64_t*)var); + SColVal cv = COL_VAL_VALUE(pCol->colId, val); void* px = taosArrayPush(pVals, &cv); if (px == NULL) { return terrno; @@ -2820,13 +2829,13 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat } else { SValue sv = {.type = pCol->type}; if (pCol->type == pColInfoData->info.type) { - memcpy(&sv.val, var, tDataTypes[pCol->type].bytes); + valueSetDatum(&sv, sv.type, var, tDataTypes[pCol->type].bytes); } else { /** * 1. sum/avg would convert to int64_t/uint64_t/double during aggregation * 2. below conversion may lead to overflow or loss, the app should select the right data type. */ - char tv[8] = {0}; + char tv[DATUM_MAX_SIZE] = {0}; if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) { float v = 0; GET_TYPED_DATA(v, float, pColInfoData->info.type, var); @@ -2844,7 +2853,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var); SET_TYPED_DATA(&tv, pCol->type, v); } - memcpy(&sv.val, tv, tDataTypes[pCol->type].bytes); + valueSetDatum(&sv, sv.type, tv, tDataTypes[pCol->type].bytes); } SColVal cv = COL_VAL_VALUE(pCol->colId, sv); void* px = taosArrayPush(pVals, &cv); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f1aacfed158a..5530ffe6afdf 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -277,7 +277,7 @@ static int32_t tRowBuildTupleRow(SArray *aColVal, const SRowBuildScanInfo *sinfo (*ppRow)->numOfPKs = sinfo->numOfPKs; (*ppRow)->sver = schema->version; (*ppRow)->len = sinfo->tupleRowSize; - (*ppRow)->ts = colValArray[0].value.val; + (*ppRow)->ts = VALUE_GET_TRIVIAL_DATUM(&colValArray[0].value); if (sinfo->tupleFlag == HAS_NONE || sinfo->tupleFlag == HAS_NULL) { return 0; @@ -315,7 +315,8 @@ static int32_t tRowBuildTupleRow(SArray *aColVal, const SRowBuildScanInfo *sinfo varlen += colValArray[colValIndex].value.nData; } } else { - (void)memcpy(fixed + schema->columns[i].offset, &colValArray[colValIndex].value.val, + (void)memcpy(fixed + schema->columns[i].offset, + VALUE_GET_DATUM(&colValArray[colValIndex].value, schema->columns[i].type), tDataTypes[schema->columns[i].type].bytes); } } else if (COL_VAL_IS_NULL(&colValArray[colValIndex])) { // NULL @@ -360,7 +361,7 @@ static int32_t tRowBuildKVRow(SArray *aColVal, const SRowBuildScanInfo *sinfo, c (*ppRow)->numOfPKs = sinfo->numOfPKs; (*ppRow)->sver = schema->version; (*ppRow)->len = sinfo->kvRowSize; - (*ppRow)->ts = colValArray[0].value.val; + (*ppRow)->ts = VALUE_GET_TRIVIAL_DATUM(&colValArray[0].value); if (!(sinfo->flag != HAS_NONE && sinfo->flag != HAS_NULL)) { return TSDB_CODE_INVALID_PARA; @@ -397,7 +398,7 @@ static int32_t tRowBuildKVRow(SArray *aColVal, const SRowBuildScanInfo *sinfo, c payloadSize += colValArray[colValIndex].value.nData; } else { payloadSize += tPutI16v(payload + payloadSize, colValArray[colValIndex].cid); - (void)memcpy(payload + payloadSize, &colValArray[colValIndex].value.val, + (void)memcpy(payload + payloadSize, VALUE_GET_DATUM(&colValArray[colValIndex].value, schema->columns[i].type), tDataTypes[schema->columns[i].type].bytes); payloadSize += tDataTypes[schema->columns[i].type].bytes; } @@ -490,8 +491,9 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, } value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; } else { - (void)memcpy(&value.val, (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow, - infos[iInfo].bind->buffer_length); + valueSetDatum(&value, infos[iInfo].type, + (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow, + infos[iInfo].bind->buffer_length); } colVal = COL_VAL_VALUE(infos[iInfo].columnId, value); } @@ -543,7 +545,7 @@ int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) pColVal->cid = pTColumn->colId; pColVal->value.type = pTColumn->type; pColVal->flag = CV_FLAG_VALUE; - (void)memcpy(&pColVal->value.val, &pRow->ts, sizeof(TSKEY)); + VALUE_SET_TRIVIAL_DATUM(&pColVal->value, pRow->ts); return 0; } @@ -607,7 +609,7 @@ int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) pColVal->value.pData = NULL; } } else { - (void)memcpy(&pColVal->value.val, pData, pTColumn->bytes); + valueSetDatum(&pColVal->value, pTColumn->type, pData, pTColumn->bytes); } } return 0; @@ -658,7 +660,7 @@ int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) pColVal->value.pData = varlen + *(int32_t *)(fixed + pTColumn->offset); pColVal->value.pData += tGetU32v(pColVal->value.pData, &pColVal->value.nData); } else { - (void)memcpy(&pColVal->value.val, fixed + pTColumn->offset, TYPE_BYTES[pTColumn->type]); + valueSetDatum(&pColVal->value, pTColumn->type, fixed + pTColumn->offset, TYPE_BYTES[pTColumn->type]); } } @@ -902,7 +904,7 @@ SColVal *tRowIterNext(SRowIter *pIter) { pIter->cv.cid = pTColumn->colId; pIter->cv.value.type = pTColumn->type; pIter->cv.flag = CV_FLAG_VALUE; - (void)memcpy(&pIter->cv.value.val, &pIter->pRow->ts, sizeof(TSKEY)); + VALUE_SET_TRIVIAL_DATUM(&pIter->cv.value, pIter->pRow->ts); goto _exit; } @@ -947,7 +949,7 @@ SColVal *tRowIterNext(SRowIter *pIter) { pIter->cv.value.pData = NULL; } } else { - (void)memcpy(&pIter->cv.value.val, pData, pTColumn->bytes); + valueSetDatum(&pIter->cv.value, pTColumn->type, pData, pTColumn->bytes); } } @@ -1006,7 +1008,7 @@ SColVal *tRowIterNext(SRowIter *pIter) { pIter->cv.value.pData = NULL; } } else { - (void)memcpy(&pIter->cv.value.val, pIter->pf + pTColumn->offset, TYPE_BYTES[pTColumn->type]); + valueSetDatum(&pIter->cv.value, pTColumn->type, pIter->pf + pTColumn->offset, TYPE_BYTES[pTColumn->type]); } goto _exit; } @@ -1326,7 +1328,7 @@ void tRowGetPrimaryKey(SRow *row, SRowKey *key) { key->pks[i].pData = tdata; key->pks[i].pData += tGetU32v(key->pks[i].pData, &key->pks[i].nData); } else { - (void)memcpy(&key->pks[i].val, tdata, tDataTypes[indices[i].type].bytes); + valueSetDatum(key->pks + i, indices[i].type, tdata, tDataTypes[indices[i].type].bytes); } } } @@ -1346,26 +1348,26 @@ int32_t tValueCompare(const SValue *tv1, const SValue *tv2) { switch (tv1->type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: - T_COMPARE_SCALAR_VALUE(int8_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(int8_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_SMALLINT: - T_COMPARE_SCALAR_VALUE(int16_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(int16_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_INT: - T_COMPARE_SCALAR_VALUE(int32_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(int32_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - T_COMPARE_SCALAR_VALUE(int64_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(int64_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_FLOAT: - T_COMPARE_SCALAR_VALUE(float, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(float, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_DOUBLE: - T_COMPARE_SCALAR_VALUE(double, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(double, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_UTINYINT: - T_COMPARE_SCALAR_VALUE(uint8_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(uint8_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_USMALLINT: - T_COMPARE_SCALAR_VALUE(uint16_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(uint16_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_UINT: - T_COMPARE_SCALAR_VALUE(uint32_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(uint32_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_UBIGINT: - T_COMPARE_SCALAR_VALUE(uint64_t, &tv1->val, &tv2->val); + T_COMPARE_SCALAR_VALUE(uint64_t, &VALUE_GET_TRIVIAL_DATUM(tv1), &VALUE_GET_TRIVIAL_DATUM(tv2)); case TSDB_DATA_TYPE_GEOMETRY: case TSDB_DATA_TYPE_BINARY: { int32_t ret = strncmp((const char *)tv1->pData, (const char *)tv2->pData, TMIN(tv1->nData, tv2->nData)); @@ -1420,12 +1422,7 @@ void tRowKeyAssign(SRowKey *pDst, SRowKey *pSrc) { SValue *pVal = &pDst->pks[i]; pVal->type = pSrc->pks[i].type; - if (IS_NUMERIC_TYPE(pVal->type)) { - pVal->val = pSrc->pks[i].val; - } else { - pVal->nData = pSrc->pks[i].nData; - (void)memcpy(pVal->pData, pSrc->pks[i].pData, pVal->nData); - } + valueCloneDatum(pVal, pSrc->pks + i, pVal->type); } } } @@ -2267,8 +2264,7 @@ int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) { return TSDB_CODE_INVALID_PARA; } return tColDataAppendValueImpl[pColData->flag][pColVal->flag]( - pColData, IS_VAR_DATA_TYPE(pColData->type) ? pColVal->value.pData : (uint8_t *)&pColVal->value.val, - pColVal->value.nData); + pColData, VALUE_GET_DATUM(&pColVal->value, pColData->type), pColVal->value.nData); } static FORCE_INLINE int32_t tColDataUpdateValue10(SColData *pColData, uint8_t *pData, uint32_t nData, bool forward) { @@ -2581,8 +2577,7 @@ int32_t tColDataUpdateValue(SColData *pColData, SColVal *pColVal, bool forward) if (tColDataUpdateValueImpl[pColData->flag][pColVal->flag] == NULL) return 0; return tColDataUpdateValueImpl[pColData->flag][pColVal->flag]( - pColData, IS_VAR_DATA_TYPE(pColData->type) ? pColVal->value.pData : (uint8_t *)&pColVal->value.val, - pColVal->value.nData, forward); + pColData, VALUE_GET_DATUM(&pColVal->value, pColData->type), pColVal->value.nData, forward); } static FORCE_INLINE void tColDataGetValue1(SColData *pColData, int32_t iVal, SColVal *pColVal) { // HAS_NONE @@ -2614,8 +2609,8 @@ static FORCE_INLINE void tColDataGetValue4(SColData *pColData, int32_t iVal, SCo } value.pData = pColData->pData + pColData->aOffset[iVal]; } else { - (void)memcpy(&value.val, pColData->pData + tDataTypes[pColData->type].bytes * iVal, - tDataTypes[pColData->type].bytes); + valueSetDatum(&value, pColData->type, pColData->pData + tDataTypes[pColData->type].bytes * iVal, + tDataTypes[pColData->type].bytes); } *pColVal = COL_VAL_VALUE(pColData->cid, value); } @@ -3318,9 +3313,7 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte if (TSDB_DATA_TYPE_BOOL == value.type && *val > 1) { *val = 1; } - (void)memcpy(&value.val, val, - /*(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,*/ - infos[iInfo].bytes /*bind->buffer_length*/); + valueSetDatum(&value, infos[iInfo].type, val, infos[iInfo].bytes); } colVal = COL_VAL_VALUE(infos[iInfo].columnId, value); } @@ -4245,7 +4238,7 @@ int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value) { return code; } } else { - code = tBufferPut(&valCol->data, &value->val, tDataTypes[value->type].bytes); + code = tBufferPut(&valCol->data, VALUE_GET_DATUM(value, value->type), tDataTypes[value->type].bytes); if (code) return code; } valCol->numOfValues++; @@ -4278,7 +4271,7 @@ int32_t tValueColumnUpdate(SValueColumn *valCol, int32_t idx, const SValue *valu } return tBufferPutAt(&valCol->data, offsets[idx], value->pData, value->nData); } else { - return tBufferPutAt(&valCol->data, idx * tDataTypes[valCol->type].bytes, &value->val, + return tBufferPutAt(&valCol->data, idx * tDataTypes[valCol->type].bytes, VALUE_GET_DATUM(value, valCol->type), tDataTypes[valCol->type].bytes); } return 0; @@ -4304,7 +4297,7 @@ int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value) { value->pData = (uint8_t *)tBufferGetDataAt(&valCol->data, offset); } else { SBufferReader reader = BUFFER_READER_INITIALIZER(idx * tDataTypes[value->type].bytes, &valCol->data); - TAOS_CHECK_RETURN(tBufferGet(&reader, tDataTypes[value->type].bytes, &value->val)); + TAOS_CHECK_RETURN(tBufferGet(&reader, tDataTypes[value->type].bytes, VALUE_GET_DATUM(value, value->type))); } return 0; } @@ -4638,3 +4631,48 @@ int32_t tDecompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *outpu output->size += info->originalSize; return 0; } + +// handle all types, including var data +void valueSetDatum(SValue *pVal, int8_t type, const void *pDatum, uint32_t len) { + assert(type == pVal->type); + if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) { + memcpy(pVal->pData, pDatum, len); + pVal->nData = len; + } else { + switch (len) { + case sizeof(char): + pVal->val = *(char *)pDatum; + break; + case sizeof(int16_t): + pVal->val = *(int16_t *)pDatum; + break; + case sizeof(int32_t): + pVal->val = *(int32_t *)pDatum; + break; + case sizeof(int64_t): + pVal->val = *(int64_t *)pDatum; + break; + default: + // TODO wjm log some thing??? + break; + } + } +} + +void valueCloneDatum(SValue *pDst, const SValue *pSrc, int8_t type) { + if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) { + // we assume that pDst->pData not NULL + memcpy(pDst->pData, pSrc->pData, pSrc->nData); + pDst->nData = pSrc->nData; + } else { + pDst->val = pSrc->val; + } +} +void valueClearDatum(SValue *pVal, int8_t type) { + if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) { + pVal->pData = NULL; + pVal->nData = 0; + } else { + pVal->val = 0; + } +} \ No newline at end of file diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 2b95e9613050..ee82a13584f6 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -517,7 +517,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r val = varBuf; ++iBound; } else { - val = (const void *)&pColVal->value.val; + val = VALUE_GET_DATUM(&pColVal->value, pTColumn->type); ++iBound; } } else { @@ -972,7 +972,7 @@ int32_t tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pC pColVal->value.nData = varDataLen(cv.val); pColVal->value.pData = varDataVal(cv.val); } else { - (void)memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes); + valueSetDatum(&pColVal->value, pTColumn->type, cv.val, tDataTypes[pTColumn->type].bytes); } } return 0; diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index c0c4c4a5a3d9..4829e7b4cd4a 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -699,7 +699,7 @@ static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SCol colDataSetNULL(pColumnInfoData, rowIndex); } } else { - code = colDataSetVal(pColumnInfoData, rowIndex, (void*)&pColVal->value.val, !COL_VAL_IS_VALUE(pColVal)); + code = colDataSetVal(pColumnInfoData, rowIndex, VALUE_GET_DATUM(&pColVal->value, pColVal->value.type), !COL_VAL_IS_VALUE(pColVal)); } return code; diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index 5405ace89b18..5f1718142ca0 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -825,7 +825,7 @@ int32_t doConvertRows(SSubmitTbData* pTableData, const STSchema* pTSchema, SSDat } } else { SValue sv = {.type = pCol->type}; - memcpy(&sv.val, colData, tDataTypes[pCol->type].bytes); + valueSetDatum(&sv, pCol->type, colData, tDataTypes[pCol->type].bytes); SColVal cv = COL_VAL_VALUE(pCol->colId, sv); void* p = taosArrayPush(pVals, &cv); if (p == NULL) { diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 2047b6810182..7ea505fc0cc4 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -293,15 +293,8 @@ typedef struct { int8_t dirty; struct { int16_t cid; - int8_t type; int8_t flag; - union { - int64_t val; - struct { - uint32_t nData; - uint8_t *pData; - }; - } value; + SValue value; } colVal; } SLastColV0; @@ -313,7 +306,7 @@ static int32_t tsdbCacheDeserializeV0(char const *value, SLastCol *pLastCol) { pLastCol->dirty = pLastColV0->dirty; pLastCol->colVal.cid = pLastColV0->colVal.cid; pLastCol->colVal.flag = pLastColV0->colVal.flag; - pLastCol->colVal.value.type = pLastColV0->colVal.type; + pLastCol->colVal.value.type = pLastColV0->colVal.value.type; pLastCol->cacheStatus = TSDB_LAST_CACHE_VALID; @@ -325,7 +318,7 @@ static int32_t tsdbCacheDeserializeV0(char const *value, SLastCol *pLastCol) { } return sizeof(SLastColV0) + pLastColV0->colVal.value.nData; } else { - pLastCol->colVal.value.val = pLastColV0->colVal.value.val; + valueCloneDatum(&pLastCol->colVal.value, &pLastColV0->colVal.value, pLastColV0->colVal.value.type); return sizeof(SLastColV0); } } @@ -409,7 +402,7 @@ static int32_t tsdbCacheSerializeV0(char const *value, SLastCol *pLastCol) { pLastColV0->dirty = pLastCol->dirty; pLastColV0->colVal.cid = pLastCol->colVal.cid; pLastColV0->colVal.flag = pLastCol->colVal.flag; - pLastColV0->colVal.type = pLastCol->colVal.value.type; + pLastColV0->colVal.value.type = pLastCol->colVal.value.type; if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) { pLastColV0->colVal.value.nData = pLastCol->colVal.value.nData; if (pLastCol->colVal.value.nData > 0) { @@ -417,7 +410,7 @@ static int32_t tsdbCacheSerializeV0(char const *value, SLastCol *pLastCol) { } return sizeof(SLastColV0) + pLastCol->colVal.value.nData; } else { - pLastColV0->colVal.value.val = pLastCol->colVal.value.val; + valueCloneDatum(&pLastColV0->colVal.value, &pLastCol->colVal.value, pLastCol->colVal.value.type); return sizeof(SLastColV0); } @@ -1327,7 +1320,7 @@ static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus ca taosMemoryFreeClear(pPKValue->pData); pPKValue->nData = 0; } else { - pPKValue->val = 0; + valueClearDatum(pPKValue, pPKValue->type); } } pLastCol->rowKey.numOfPKs = 0; @@ -1337,7 +1330,7 @@ static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus ca taosMemoryFreeClear(pLastCol->colVal.value.pData); pLastCol->colVal.value.nData = 0; } else { - pLastCol->colVal.value.val = 0; + valueClearDatum(&pLastCol->colVal.value, pLastCol->colVal.value.type); } pLastCol->colVal = COL_VAL_NONE(pLastCol->colVal.cid, pLastCol->colVal.value.type); @@ -1691,11 +1684,12 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo tsdbRowGetKey(&lRow, &tsdbRowKey); { + SValue tsVal = {.type = TSDB_DATA_TYPE_TIMESTAMP}; + VALUE_SET_TRIVIAL_DATUM(&tsVal, lRow.pBlockData->aTSKEY[lRow.iRow]); SLastUpdateCtx updateCtx = { .lflag = LFLAG_LAST, .tsdbRowKey = tsdbRowKey, - .colVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, - .val = lRow.pBlockData->aTSKEY[lRow.iRow]}))}; + .colVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, tsVal)}; if (!taosArrayPush(ctxArray, &updateCtx)) { TAOS_CHECK_GOTO(terrno, &lino, _exit); } @@ -3837,7 +3831,9 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC } if (slotIds[iCol] == 0) { STColumn *pTColumn = &pTSchema->columns[0]; - *pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts})); + SValue val = {.type = pTColumn->type}; + VALUE_SET_TRIVIAL_DATUM(&val, rowKey.key.ts); + *pColVal = COL_VAL_VALUE(pTColumn->colId, val); SLastCol colTmp = {.rowKey = rowKey.key, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID}; TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&colTmp, NULL), &lino, _err); @@ -4005,7 +4001,9 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, } if (slotIds[iCol] == 0) { STColumn *pTColumn = &pTSchema->columns[0]; - *pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts})); + SValue val = {.type = pTColumn->type}; + VALUE_SET_TRIVIAL_DATUM(&val, rowKey.key.ts); + *pColVal = COL_VAL_VALUE(pTColumn->colId, val); SLastCol colTmp = {.rowKey = rowKey.key, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID}; TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&colTmp, NULL), &lino, _err); diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index f5aeb609d525..180dcd721b2e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -77,7 +77,8 @@ static int32_t saveOneRowForLastRaw(SLastCol* pColVal, SCacheRowsReader* pReader TSDB_CHECK_CODE(code, lino, _end); } } else { - code = colDataSetVal(pColInfoData, numOfRows, (const char*)&pVal->value.val, !COL_VAL_IS_VALUE(pVal)); + code = colDataSetVal(pColInfoData, numOfRows, VALUE_GET_DATUM(&pVal->value, pColVal->colVal.value.type), + !COL_VAL_IS_VALUE(pVal)); TSDB_CHECK_CODE(code, lino, _end); } @@ -166,7 +167,8 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p memcpy(varDataVal(p->buf), pColVal->colVal.value.pData, pColVal->colVal.value.nData); p->bytes = pColVal->colVal.value.nData + VARSTR_HEADER_SIZE; // binary needs to plus the header size } else { - memcpy(p->buf, &pColVal->colVal.value.val, pReader->pSchema->columns[slotId].bytes); + memcpy(p->buf, VALUE_GET_DATUM(&pColVal->colVal.value, pColVal->colVal.value.type), + pReader->pSchema->columns[slotId].bytes); p->bytes = pReader->pSchema->columns[slotId].bytes; } } @@ -601,7 +603,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 memcpy(p->rowKey.pks[j].pData, pColVal->rowKey.pks[j].pData, pColVal->rowKey.pks[j].nData); p->rowKey.pks[j].nData = pColVal->rowKey.pks[j].nData; } else { - p->rowKey.pks[j].val = pColVal->rowKey.pks[j].val; + valueCloneDatum(p->rowKey.pks + j, pColVal->rowKey.pks + j, p->rowKey.pks[j].type); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 05ae4be74b20..5b394e86ed88 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -129,7 +129,7 @@ static int32_t tColRowGetPriamyKeyDeepCopy(SBlockData* pBlock, int32_t irow, int pKey->pks[0].type = cv.value.type; if (IS_NUMERIC_TYPE(cv.value.type)) { - pKey->pks[0].val = cv.value.val; + valueCloneDatum(pKey->pks, &cv.value, cv.value.type); } else { pKey->pks[0].nData = cv.value.nData; TAOS_MEMCPY(pKey->pks[0].pData, cv.value.pData, cv.value.nData); @@ -181,7 +181,7 @@ static int32_t tRowGetPrimaryKeyDeepCopy(SRow* pRow, SRowKey* pKey) { tdata += tGetU32v(tdata, &pKey->pks[i].nData); TAOS_MEMCPY(pKey->pks[i].pData, tdata, pKey->pks[i].nData); } else { - TAOS_MEMCPY(&pKey->pks[i].val, data + indices[i].offset, tDataTypes[pKey->pks[i].type].bytes); + valueSetDatum(pKey->pks + i, indices[i].type, data + indices[i].offset, tDataTypes[pKey->pks[i].type].bytes); } } @@ -1078,7 +1078,7 @@ static int32_t updateLastKeyInfo(SRowKey* pKey, SFileDataBlockInfo* pBlockInfo, TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); if (IS_NUMERIC_TYPE(pKey->pks[0].type)) { - pKey->pks[0].val = asc ? pBlockInfo->lastPk.val : pBlockInfo->firstPk.val; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, asc ? pBlockInfo->lastPk.val : pBlockInfo->firstPk.val); } else { uint8_t* p = asc ? pBlockInfo->lastPk.pData : pBlockInfo->firstPk.pData; pKey->pks[0].nData = asc ? varDataLen(pBlockInfo->lastPk.pData) : varDataLen(pBlockInfo->firstPk.pData); @@ -1121,7 +1121,8 @@ static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int TSDB_CHECK_CODE(code, lino, _end); } } else { - code = colDataSetVal(pColInfoData, rowIndex, (const char*)&pColVal->value.val, !COL_VAL_IS_VALUE(pColVal)); + code = colDataSetVal(pColInfoData, rowIndex, VALUE_GET_DATUM(&pColVal->value, pColVal->value.type), + !COL_VAL_IS_VALUE(pColVal)); TSDB_CHECK_CODE(code, lino, _end); } @@ -1437,8 +1438,8 @@ static void blockInfoToRecord(SBrinRecord* record, SFileDataBlockInfo* pBlockInf pLast->pData = (uint8_t*)varDataVal(pBlockInfo->lastPk.pData); pLast->nData = varDataLen(pBlockInfo->lastPk.pData); } else { - pFirst->val = pBlockInfo->firstPk.val; - pLast->val = pBlockInfo->lastPk.val; + VALUE_SET_TRIVIAL_DATUM(pFirst, pBlockInfo->firstPk.val); + VALUE_SET_TRIVIAL_DATUM(pLast, pBlockInfo->lastPk.val); } } @@ -1892,7 +1893,7 @@ static bool overlapWithNeighborBlock2(SFileDataBlockInfo* pBlock, SBrinRecord* p if (IS_VAR_DATA_TYPE(pkType)) { v1.pData = (uint8_t*)varDataVal(pBlock->lastPk.pData), v1.nData = varDataLen(pBlock->lastPk.pData); } else { - v1.val = pBlock->lastPk.val; + VALUE_SET_TRIVIAL_DATUM(&v1, pBlock->lastPk.val); } return (tValueCompare(&v1, &pRec->firstKey.key.pks[0]) == 0); } else { // no pk @@ -1908,7 +1909,7 @@ static bool overlapWithNeighborBlock2(SFileDataBlockInfo* pBlock, SBrinRecord* p if (IS_VAR_DATA_TYPE(pkType)) { v1.pData = (uint8_t*)varDataVal(pBlock->firstPk.pData), v1.nData = varDataLen(pBlock->firstPk.pData); } else { - v1.val = pBlock->firstPk.val; + VALUE_SET_TRIVIAL_DATUM(&v1, pBlock->firstPk.val); } return (tValueCompare(&v1, &pRec->lastKey.key.pks[0]) == 0); } else { // no pk @@ -2185,7 +2186,7 @@ static int32_t nextRowFromSttBlocks(SSttBlockReader* pSttBlockReader, STableBloc pNextProc->ts += step; if (pSttBlockReader->numOfPks > 0) { if (IS_NUMERIC_TYPE(pNextProc->pks[0].type)) { - pNextProc->pks[0].val = INT64_MIN; + VALUE_SET_TRIVIAL_DATUM(pNextProc->pks, INT64_MAX); } else { memset(pNextProc->pks[0].pData, 0, pNextProc->pks[0].nData); } @@ -3752,8 +3753,8 @@ static int32_t buildCleanBlockFromDataFiles(STsdbReader* pReader, STableBlockSca if (pReader->suppInfo.numOfPks > 0) { if (IS_NUMERIC_TYPE(pReader->suppInfo.pk.type)) { - pInfo->pks[0].val = pBlockInfo->firstPk.val; - pInfo->pks[1].val = pBlockInfo->lastPk.val; + VALUE_SET_TRIVIAL_DATUM(pInfo->pks, pBlockInfo->firstPk.val); + VALUE_SET_TRIVIAL_DATUM(pInfo->pks + 1, pBlockInfo->lastPk.val); } else { (void)memcpy(pInfo->pks[0].pData, varDataVal(pBlockInfo->firstPk.pData), varDataLen(pBlockInfo->firstPk.pData)); (void)memcpy(pInfo->pks[1].pData, varDataVal(pBlockInfo->lastPk.pData), varDataLen(pBlockInfo->lastPk.pData)); diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c index df2279d3fea9..184693b5c1b9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c @@ -221,29 +221,29 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in if (asc) { switch (type) { case TSDB_DATA_TYPE_BIGINT: { - pKey->pks[0].val = INT64_MIN; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, INT64_MIN); break; } case TSDB_DATA_TYPE_INT: { int32_t min = INT32_MIN; - (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); + valueSetDatum(pKey->pks, type, &min, tDataTypes[type].bytes); break; } case TSDB_DATA_TYPE_SMALLINT: { int16_t min = INT16_MIN; - (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); + valueSetDatum(pKey->pks, type, &min, tDataTypes[type].bytes); break; } case TSDB_DATA_TYPE_TINYINT: { int8_t min = INT8_MIN; - (void)memcpy(&pKey->pks[0].val, &min, tDataTypes[type].bytes); + valueSetDatum(pKey->pks, type, &min, tDataTypes[type].bytes); break; } case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: { - pKey->pks[0].val = 0; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, 0); break; } default: @@ -253,28 +253,28 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in } else { switch (type) { case TSDB_DATA_TYPE_BIGINT: - pKey->pks[0].val = INT64_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, INT64_MAX); break; case TSDB_DATA_TYPE_INT: - pKey->pks[0].val = INT32_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, INT32_MAX); break; case TSDB_DATA_TYPE_SMALLINT: - pKey->pks[0].val = INT16_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, INT16_MAX); break; case TSDB_DATA_TYPE_TINYINT: - pKey->pks[0].val = INT8_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, INT8_MAX); break; case TSDB_DATA_TYPE_UBIGINT: - pKey->pks[0].val = UINT64_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, UINT64_MAX); break; case TSDB_DATA_TYPE_UINT: - pKey->pks[0].val = UINT32_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, UINT32_MAX); break; case TSDB_DATA_TYPE_USMALLINT: - pKey->pks[0].val = UINT16_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, UINT16_MAX); break; case TSDB_DATA_TYPE_UTINYINT: - pKey->pks[0].val = UINT8_MAX; + VALUE_SET_TRIVIAL_DATUM(pKey->pks, UINT8_MAX); break; default: code = TSDB_CODE_INVALID_PARA; @@ -722,8 +722,8 @@ int32_t recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record) { TSDB_CHECK_CONDITION((pFirstKey->numOfPKs == pLastKey->numOfPKs), code, lino, _end, TSDB_CODE_INVALID_PARA); if (pFirstKey->numOfPKs > 0) { if (IS_NUMERIC_TYPE(pFirstKey->pks[0].type)) { - pBlockInfo->firstPk.val = pFirstKey->pks[0].val; - pBlockInfo->lastPk.val = pLastKey->pks[0].val; + pBlockInfo->firstPk.val = VALUE_GET_TRIVIAL_DATUM(pFirstKey->pks); + pBlockInfo->lastPk.val = VALUE_GET_TRIVIAL_DATUM(pLastKey->pks); } else { int32_t keyLen = pFirstKey->pks[0].nData; char* p = taosMemoryMalloc(keyLen + VARSTR_HEADER_SIZE); diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index f807ecf2d6c2..de14c090fa4a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -615,9 +615,9 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal * } } else if (pRow->type == TSDBROW_COL_FMT) { if (iCol == 0) { - *pColVal = - COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, - ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, .val = pRow->pBlockData->aTSKEY[pRow->iRow]})); + SValue val = {.type = TSDB_DATA_TYPE_TIMESTAMP}; + VALUE_SET_TRIVIAL_DATUM(&val, pRow->pBlockData->aTSKEY[pRow->iRow]); + *pColVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, val); } else { SColData *pColData = tBlockDataGetColData(pRow->pBlockData, pTColumn->colId); @@ -709,9 +709,9 @@ SColVal *tsdbRowIterNext(STSDBRowIter *pIter) { return tRowIterNext(pIter->pIter); } else if (pIter->pRow->type == TSDBROW_COL_FMT) { if (pIter->iColData == 0) { - pIter->cv = COL_VAL_VALUE( - PRIMARYKEY_TIMESTAMP_COL_ID, - ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, .val = pIter->pRow->pBlockData->aTSKEY[pIter->pRow->iRow]})); + SValue val = {.type = TSDB_DATA_TYPE_TIMESTAMP}; + VALUE_SET_TRIVIAL_DATUM(&val, pIter->pRow->pBlockData->aTSKEY[pIter->pRow->iRow]); + pIter->cv = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, val); ++pIter->iColData; return &pIter->cv; } @@ -745,8 +745,9 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) // ts jCol = 0; pTColumn = &pTSchema->columns[jCol++]; - - *pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = key.ts})); + SValue val = {.type = pTColumn->type}; + VALUE_SET_TRIVIAL_DATUM(&val, key.ts); + *pColVal = COL_VAL_VALUE(pTColumn->colId, val); if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { code = terrno; return code; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index e82209e03f35..2080490cb4dd 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -1699,11 +1699,11 @@ static int32_t vnodeCellValConvertToColVal(STColumn *pCol, SCellVal *pCellVal, S pColVal->value.pData = (uint8_t *)varDataVal(pCellVal->val); } else if (TSDB_DATA_TYPE_FLOAT == pCol->type) { float f = GET_FLOAT_VAL(pCellVal->val); - memcpy(&pColVal->value.val, &f, sizeof(f)); + valueSetDatum(&pColVal->value, pCol->type, &f, sizeof(f)); } else if (TSDB_DATA_TYPE_DOUBLE == pCol->type) { - pColVal->value.val = *(int64_t *)pCellVal->val; + VALUE_SET_TRIVIAL_DATUM(&pColVal->value, *(int64_t*)pCellVal->val); } else { - GET_TYPED_DATA(pColVal->value.val, int64_t, pCol->type, pCellVal->val); + valueSetDatum(&pColVal->value, pCol->type, pCellVal->val, tDataTypes[pCol->type].bytes); } pColVal->flag = CV_FLAG_VALUE; diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index ec041cba708c..3bc7ea731d12 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -295,7 +295,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp } SValue sv = {.type = pCol->type}; - TAOS_MEMCPY(&sv.val, var, tDataTypes[pCol->type].bytes); + valueSetDatum(&sv, sv.type, var, tDataTypes[pCol->type].bytes); SColVal cv = COL_VAL_VALUE(pCol->colId, sv); if (NULL == taosArrayPush(pVals, &cv)) { goto _end; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 1060cbcffe52..f4e2a6056050 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -2868,7 +2868,8 @@ static int32_t doBlockDataPrimaryKeyFilter(SSDataBlock* pBlock, STqOffsetVal* of SColumnInfoData* pColTs = taosArrayGet(pBlock->pDataBlock, 0); SColumnInfoData* pColPk = taosArrayGet(pBlock->pDataBlock, 1); - qDebug("doBlockDataWindowFilter primary key, ts:%" PRId64 " %" PRId64, offset->ts, offset->primaryKey.val); + qDebug("doBlockDataWindowFilter primary key, ts:%" PRId64 " %" PRId64, offset->ts, + VALUE_GET_TRIVIAL_DATUM(&offset->primaryKey)); QUERY_CHECK_CONDITION((pColPk->info.type == offset->primaryKey.type), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); @@ -2885,7 +2886,7 @@ static int32_t doBlockDataPrimaryKeyFilter(SSDataBlock* pBlock, STqOffsetVal* of p[i] = (*ts > offset->ts) || (func(data, tmq) > 0); taosMemoryFree(tmq); } else { - p[i] = (*ts > offset->ts) || (func(data, &offset->primaryKey.val) > 0); + p[i] = (*ts > offset->ts) || (func(data, VALUE_GET_DATUM(&offset->primaryKey, pColPk->info.type)) > 0); } if (!p[i]) { @@ -3124,7 +3125,7 @@ static int32_t processPrimaryKey(SSDataBlock* pBlock, bool hasPrimaryKey, STqOff val.nData = varDataLen(tmp); memcpy(val.pData, varDataVal(tmp), varDataLen(tmp)); } else { - memcpy(&val.val, tmp, pColPk->info.bytes); + valueSetDatum(&val, pColPk->info.type, tmp, pColPk->info.bytes); } } tqOffsetResetToData(offset, pBlock->info.id.uid, pBlock->info.window.ekey, val); diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c index 3a639772c801..d38d4f9d5343 100644 --- a/source/libs/executor/src/timesliceoperator.c +++ b/source/libs/executor/src/timesliceoperator.c @@ -193,7 +193,7 @@ static void tRowGetKeyFromColData(int64_t ts, SColumnInfoData* pPkCol, int32_t r pKey->pks[0].type = t; if (IS_NUMERIC_TYPE(t)) { - GET_TYPED_DATA(pKey->pks[0].val, int64_t, t, colDataGetNumData(pPkCol, rowIndex)); + valueSetDatum(pKey->pks, t, colDataGetData(pPkCol, rowIndex), tDataTypes[t].bytes); } else { char* p = colDataGetVarData(pPkCol, rowIndex); pKey->pks[0].pData = (uint8_t*)varDataVal(p); @@ -215,7 +215,7 @@ static bool checkDuplicateTimestamps(STimeSliceOperatorInfo* pSliceInfo, SColumn if (IS_VAR_DATA_TYPE(pPkCol->info.type)) { cur.pks[0].pData = (uint8_t*)colDataGetVarData(pPkCol, curIndex); } else { - memcpy(&cur.pks[0].val, colDataGetData(pPkCol, curIndex), pPkCol->info.bytes); + valueSetDatum(cur.pks, pPkCol->info.type, colDataGetData(pPkCol, curIndex), pPkCol->info.bytes); } } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 1c77d12fb2b0..410e9afb3ae8 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2285,16 +2285,16 @@ static int32_t comparePkDataWithSValue(int8_t pkType, char* pkData, SValue* pVal char numVal[8] = {0}; switch (pkType) { case TSDB_DATA_TYPE_INT: - *(int32_t*)numVal = (int32_t)pVal->val; + *(int32_t*)numVal = (int32_t)VALUE_GET_TRIVIAL_DATUM(pVal); break; case TSDB_DATA_TYPE_UINT: - *(uint32_t*)numVal = (uint32_t)pVal->val; + *(uint32_t*)numVal = (uint32_t)VALUE_GET_TRIVIAL_DATUM(pVal); break; case TSDB_DATA_TYPE_BIGINT: - *(int64_t*)numVal = (int64_t)pVal->val; + *(int64_t*)numVal = (int64_t)VALUE_GET_TRIVIAL_DATUM(pVal); break; case TSDB_DATA_TYPE_UBIGINT: - *(uint64_t*)numVal = (uint64_t)pVal->val; + *(uint64_t*)numVal = (uint64_t)VALUE_GET_TRIVIAL_DATUM(pVal); break; default: break; diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index 22d1f7eddab0..252b5ac302b0 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -202,7 +202,7 @@ void clearColValArraySml(SArray* pCols) { taosMemoryFreeClear(pCol->value.pData); } pCol->flag = CV_FLAG_NONE; - pCol->value.val = 0; + valueClearDatum(&pCol->value, pCol->value.type); } } @@ -281,7 +281,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 } (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length); } else { - (void)memcpy(&pVal->value.val, &(kv->value), kv->length); + valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length); } pVal->flag = CV_FLAG_VALUE; @@ -436,7 +436,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc } (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length); } else { - (void)memcpy(&pVal->value.val, &(kv->value), kv->length); + valueSetDatum(&pVal->value, kv->type, &(kv->value), kv->length); } pVal->flag = CV_FLAG_VALUE; } diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index e2069deefcd2..a1811a0a7327 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1488,89 +1488,95 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, case TSDB_DATA_TYPE_BOOL: { if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) { if (IS_TRUE_STR(pToken->z, pToken->n)) { - pVal->value.val = TRUE_VALUE; + VALUE_SET_TRIVIAL_DATUM(&pVal->value, TRUE_VALUE); } else if (IS_FALSE_STR(pToken->z, pToken->n)) { - pVal->value.val = FALSE_VALUE; - } else if (TSDB_CODE_SUCCESS == toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&pVal->value.val)) { - *(int8_t*)(&pVal->value.val) = (*(double*)&pVal->value.val == 0 ? FALSE_VALUE : TRUE_VALUE); + VALUE_SET_TRIVIAL_DATUM(&pVal->value, FALSE_VALUE); + } else if (TSDB_CODE_SUCCESS == + toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value))) { + int8_t v = (*(double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value) == 0 ? FALSE_VALUE : TRUE_VALUE); + valueSetDatum(&pVal->value, TSDB_DATA_TYPE_BOOL, &v, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); } else { return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); } } else if (pToken->type == TK_NK_INTEGER) { - pVal->value.val = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE); + int8_t v = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE); + VALUE_SET_TRIVIAL_DATUM(&pVal->value, v); } else if (pToken->type == TK_NK_FLOAT) { - pVal->value.val = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE); + int8_t v = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE); + VALUE_SET_TRIVIAL_DATUM(&pVal->value, v); } else if ((pToken->type == TK_NK_HEX || pToken->type == TK_NK_BIN) && - (TSDB_CODE_SUCCESS == toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&pVal->value.val))) { - *(int8_t*)(&pVal->value.val) = (*(double*)&pVal->value.val == 0 ? FALSE_VALUE : TRUE_VALUE); + (TSDB_CODE_SUCCESS == + toDoubleEx(pToken->z, pToken->n, pToken->type, (double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value)))) { // TODO wjm use valueGetDatum instead + int8_t v = *(double*)&VALUE_GET_TRIVIAL_DATUM(&pVal->value) == 0 ? FALSE_VALUE : TRUE_VALUE; + valueSetDatum(&pVal->value, TSDB_DATA_TYPE_BOOL, &v, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); } else { return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); } break; } case TSDB_DATA_TYPE_TINYINT: { - int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid tinyint data", pToken->z); - } else if (!IS_VALID_TINYINT(pVal->value.val)) { + } else if (!IS_VALID_TINYINT(VALUE_GET_TRIVIAL_DATUM(&pVal->value))) { return buildSyntaxErrMsg(&pCxt->msg, "tinyint data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_UTINYINT: { - int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned tinyint data", pToken->z); - } else if (pVal->value.val > UINT8_MAX) { + } else if (VALUE_GET_TRIVIAL_DATUM(&pVal->value) > UINT8_MAX) { return buildSyntaxErrMsg(&pCxt->msg, "unsigned tinyint data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_SMALLINT: { - int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid smallint data", pToken->z); - } else if (!IS_VALID_SMALLINT(pVal->value.val)) { + } else if (!IS_VALID_SMALLINT(VALUE_GET_TRIVIAL_DATUM(&pVal->value))) { return buildSyntaxErrMsg(&pCxt->msg, "smallint data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_USMALLINT: { - int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned smallint data", pToken->z); - } else if (pVal->value.val > UINT16_MAX) { + } else if (VALUE_GET_TRIVIAL_DATUM(&pVal->value) > UINT16_MAX) { return buildSyntaxErrMsg(&pCxt->msg, "unsigned smallint data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_INT: { - int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid int data", pToken->z); - } else if (!IS_VALID_INT(pVal->value.val)) { + } else if (!IS_VALID_INT(VALUE_GET_TRIVIAL_DATUM(&pVal->value))) { return buildSyntaxErrMsg(&pCxt->msg, "int data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_UINT: { - int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned int data", pToken->z); - } else if (pVal->value.val > UINT32_MAX) { + } else if (VALUE_GET_TRIVIAL_DATUM(&pVal->value) > UINT32_MAX) { return buildSyntaxErrMsg(&pCxt->msg, "unsigned int data overflow", pToken->z); } break; } case TSDB_DATA_TYPE_BIGINT: { - int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid bigint data", pToken->z); } break; } case TSDB_DATA_TYPE_UBIGINT: { - int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &pVal->value.val); + int32_t code = toUIntegerEx(pToken->z, pToken->n, pToken->type, &VALUE_GET_TRIVIAL_DATUM(&pVal->value)); if (TSDB_CODE_SUCCESS != code) { return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned bigint data", pToken->z); } @@ -1586,7 +1592,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z); } float f = dv; - memcpy(&pVal->value.val, &f, sizeof(f)); + valueSetDatum(&pVal->value, TSDB_DATA_TYPE_FLOAT, &f, sizeof(f)); break; } case TSDB_DATA_TYPE_DOUBLE: { @@ -1598,7 +1604,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, if (isinf(dv) || isnan(dv)) { return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z); } - pVal->value.val = *(int64_t*)&dv; + VALUE_SET_TRIVIAL_DATUM(&pVal->value, (*(int64_t*)&dv)); break; } case TSDB_DATA_TYPE_BINARY: { @@ -1685,7 +1691,8 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, break; } case TSDB_DATA_TYPE_TIMESTAMP: { - if (parseTime(pSql, pToken, timePrec, &pVal->value.val, &pCxt->msg, pCxt->pComCxt->timezone) != TSDB_CODE_SUCCESS) { + if (parseTime(pSql, pToken, timePrec, &VALUE_GET_TRIVIAL_DATUM(&pVal->value), &pCxt->msg, + pCxt->pComCxt->timezone) != TSDB_CODE_SUCCESS) { return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp", pToken->z); } break; From 7a2f09a76fbe264829985b5305a64bc5295bba45 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Fri, 20 Dec 2024 17:21:23 +0800 Subject: [PATCH 2/4] remote assert --- source/common/src/tdataformat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 5530ffe6afdf..074c5ff005d9 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -4634,7 +4634,6 @@ int32_t tDecompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *outpu // handle all types, including var data void valueSetDatum(SValue *pVal, int8_t type, const void *pDatum, uint32_t len) { - assert(type == pVal->type); if (IS_VAR_DATA_TYPE(type) || type == TSDB_DATA_TYPE_DECIMAL) { memcpy(pVal->pData, pDatum, len); pVal->nData = len; @@ -4675,4 +4674,4 @@ void valueClearDatum(SValue *pVal, int8_t type) { } else { pVal->val = 0; } -} \ No newline at end of file +} From 25e89c645550779e2fd4b553b019a0866b7217fb Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Mon, 23 Dec 2024 10:21:02 +0800 Subject: [PATCH 3/4] fix dataformat test --- source/common/src/tdataformat.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 074c5ff005d9..9f3e15d56f51 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -4639,17 +4639,17 @@ void valueSetDatum(SValue *pVal, int8_t type, const void *pDatum, uint32_t len) pVal->nData = len; } else { switch (len) { - case sizeof(char): - pVal->val = *(char *)pDatum; + case sizeof(uint8_t): + pVal->val = *(uint8_t *)pDatum; break; - case sizeof(int16_t): - pVal->val = *(int16_t *)pDatum; + case sizeof(uint16_t): + pVal->val = *(uint16_t *)pDatum; break; - case sizeof(int32_t): - pVal->val = *(int32_t *)pDatum; + case sizeof(uint32_t): + pVal->val = *(uint32_t *)pDatum; break; - case sizeof(int64_t): - pVal->val = *(int64_t *)pDatum; + case sizeof(uint64_t): + pVal->val = *(uint64_t *)pDatum; break; default: // TODO wjm log some thing??? From 178a0fd6141da4b005627d6d8112510dd8ce2d96 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Mon, 23 Dec 2024 17:12:10 +0800 Subject: [PATCH 4/4] fix compatibility test case --- source/dnode/vnode/src/tsdb/tsdbCache.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 7ea505fc0cc4..8e8372cf7de3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -293,8 +293,15 @@ typedef struct { int8_t dirty; struct { int16_t cid; + int8_t type; int8_t flag; - SValue value; + union { + int64_t val; + struct { + int32_t nData; + uint8_t *pData; + }; + } value; } colVal; } SLastColV0; @@ -306,7 +313,7 @@ static int32_t tsdbCacheDeserializeV0(char const *value, SLastCol *pLastCol) { pLastCol->dirty = pLastColV0->dirty; pLastCol->colVal.cid = pLastColV0->colVal.cid; pLastCol->colVal.flag = pLastColV0->colVal.flag; - pLastCol->colVal.value.type = pLastColV0->colVal.value.type; + pLastCol->colVal.value.type = pLastColV0->colVal.type; pLastCol->cacheStatus = TSDB_LAST_CACHE_VALID; @@ -318,7 +325,8 @@ static int32_t tsdbCacheDeserializeV0(char const *value, SLastCol *pLastCol) { } return sizeof(SLastColV0) + pLastColV0->colVal.value.nData; } else { - valueCloneDatum(&pLastCol->colVal.value, &pLastColV0->colVal.value, pLastColV0->colVal.value.type); + // TODO wjm what if the type is decimal?? + VALUE_SET_TRIVIAL_DATUM(&pLastCol->colVal.value, pLastColV0->colVal.value.val); return sizeof(SLastColV0); } } @@ -402,7 +410,7 @@ static int32_t tsdbCacheSerializeV0(char const *value, SLastCol *pLastCol) { pLastColV0->dirty = pLastCol->dirty; pLastColV0->colVal.cid = pLastCol->colVal.cid; pLastColV0->colVal.flag = pLastCol->colVal.flag; - pLastColV0->colVal.value.type = pLastCol->colVal.value.type; + pLastColV0->colVal.type = pLastCol->colVal.value.type; if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) { pLastColV0->colVal.value.nData = pLastCol->colVal.value.nData; if (pLastCol->colVal.value.nData > 0) { @@ -410,7 +418,8 @@ static int32_t tsdbCacheSerializeV0(char const *value, SLastCol *pLastCol) { } return sizeof(SLastColV0) + pLastCol->colVal.value.nData; } else { - valueCloneDatum(&pLastColV0->colVal.value, &pLastCol->colVal.value, pLastCol->colVal.value.type); + // TODO wjm what if the type is decimal?? + VALUE_SET_TRIVIAL_DATUM(&pLastColV0->colVal.value, pLastCol->colVal.value.val); return sizeof(SLastColV0); }