From a3f36045ab3a448721a84bfa7ef1e123a317aea5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 1 Jun 2020 06:56:47 +0000 Subject: [PATCH] resolve more conflict --- src/common/inc/tdataformat.h | 16 ++++++++++++++++ src/tsdb/src/tsdbMeta.c | 29 ++++++++++++----------------- src/tsdb/src/tsdbRWHelper.c | 2 +- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 706fdeff98..1d3319e61d 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -87,6 +87,22 @@ int tdGetSchemaEncodeSize(STSchema *pSchema); void * tdEncodeSchema(void *dst, STSchema *pSchema); STSchema *tdDecodeSchema(void **psrc); +static FORCE_INLINE int comparColId(const void *key1, const void *key2) { + if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { + return 1; + } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { + return -1; + } else { + return 0; + } +} + +static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { + void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId); + if (ptr == NULL) return NULL; + return (STColumn *)ptr; +} + // ----------------- Data row structure /* A data row, the format is like below: diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 32ad30598b..f057dcb96e 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -250,29 +250,24 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) { int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t* type, int16_t* bytes, char** val) { STsdbMeta* pMeta = tsdbGetMeta(repo); STable* pTable = tsdbGetTableByUid(pMeta, id->uid); + + STSchema *pSchema = tsdbGetTableTagSchema(pMeta, pTable); + STColumn *pCol = tdGetColOfID(pSchema, colId); + if (pCol == NULL) { + return -1; // No matched tag volumn + } - *val = tdQueryTagByID(pTable->tagVal, colId, type); + *val = tdGetKVRowValOfCol(pTable->tagVal, colId); + *type = pCol->type; if (*val != NULL) { - switch(*type) { - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: *bytes = varDataLen(*val); break; - case TSDB_DATA_TYPE_NULL: *bytes = 0; break; - default: - *bytes = tDataTypeDesc[*type].nSize;break; + if (IS_VAR_DATA_TYPE(*type)) { + *bytes = varDataLen(*val); + } else { + *bytes = TYPE_BYTES[*type]; } } - if (pCol == NULL) { - return -1; // No matched tags. Maybe the modification of tags has not been done yet. - } - - char* d = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId); - //ASSERT((int8_t)tagtype == pCol->type) - *val = d; - *type = pCol->type; - *bytes = pCol->bytes; - return TSDB_CODE_SUCCESS; } diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 8c7f8309ec..5bdf37c81e 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -453,7 +453,7 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer)*2); } buf = POINTER_SHIFT(pHelper->pBuffer, drift); - buf = taosEncodeVariant32(buf, i); + buf = taosEncodeVariantU32(buf, i); buf = tsdbEncodeSCompIdx(buf, pCompIdx); } } -- GitLab