From 2baee09b5863d399974c90d9423238479aac8c6a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 31 May 2022 03:34:38 +0000 Subject: [PATCH] more --- include/common/tdataformat.h | 1 - source/common/src/tdataformat.c | 47 +++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index ed3a911c13..c75c5b41f2 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -144,7 +144,6 @@ struct SValue { struct SColVal { int8_t isNone; int8_t isNull; - int8_t type; int16_t cid; SValue value; }; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 653381925c..cea633a8d9 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -44,7 +44,7 @@ typedef struct { static FORCE_INLINE int tSKVIdxCmprFn(const void *p1, const void *p2); // SValue -static int32_t tPutSValue(uint8_t *p, SValue *pValue, int8_t type) { +static int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -95,7 +95,7 @@ static int32_t tPutSValue(uint8_t *p, SValue *pValue, int8_t type) { return n; } -static int32_t tGetSValue(uint8_t *p, SValue *pValue, int8_t type) { +static int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { int32_t n = 0; if (IS_VAR_DATA_TYPE(type)) { @@ -146,6 +146,49 @@ static int32_t tGetSValue(uint8_t *p, SValue *pValue, int8_t type) { return n; } +// SColVal +static int32_t tPutColVal(uint8_t *p, SColVal *pColVal, int8_t type, int8_t isTuple) { + int32_t n = 0; + + ASSERT(pColVal->isNone == 0); + if (isTuple) { + ASSERT(pColVal->isNull == 0); + n += tPutValue(p ? p + n : p, &pColVal->value, type); + } else { + if (pColVal->isNull) { + // -cid means NULL + n += tPutI16v(p ? p + n : p, -pColVal->cid); + } else { + n += tPutI16v(p ? p + n : p, pColVal->cid); + n += tPutValue(p ? p + n : p, &pColVal->value, type); + } + } + + return n; +} + +static int32_t tGetColVal(uint8_t *p, SColVal *pColVal, int8_t type, int8_t isTuple) { + int32_t n = 0; + int16_t cid; + + if (isTuple) { + n += tGetValue(p + n, pColVal ? &pColVal->value : NULL, type); + } else { + n += tGetI16v(p + n, &cid); + if (cid < 0) { + if (pColVal) { + pColVal->isNull = 1; + pColVal->cid = -cid; + } + } else { + if (pColVal) pColVal->cid = cid; + n += tGetValue(p ? p + n : p, pColVal ? &pColVal->value : NULL, type); + } + } + + return n; +} + // STSRow2 ======================================================================== int32_t tTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) { int32_t code = 0;