diff --git a/include/common/tcol.h b/include/common/tcol.h index 4ca85f2540..11b74d2a04 100644 --- a/include/common/tcol.h +++ b/include/common/tcol.h @@ -76,6 +76,7 @@ uint8_t columnLevelVal(const char* level); uint8_t columnEncodeVal(const char* encode); uint16_t columnCompressVal(const char* compress); +bool useCompress(uint8_t tableType); bool checkColumnEncode(char encode[TSDB_CL_COMPRESS_OPTION_LEN]); bool checkColumnEncodeOrSetDefault(uint8_t type, char encode[TSDB_CL_COMPRESS_OPTION_LEN]); bool checkColumnCompress(char compress[TSDB_CL_COMPRESS_OPTION_LEN]); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 062cda701e..b7180fe5da 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1182,23 +1182,24 @@ typedef struct { } STableCfgReq; typedef struct { - char tbName[TSDB_TABLE_NAME_LEN]; - char stbName[TSDB_TABLE_NAME_LEN]; - char dbFName[TSDB_DB_FNAME_LEN]; - int32_t numOfTags; - int32_t numOfColumns; - int8_t tableType; - int64_t delay1; - int64_t delay2; - int64_t watermark1; - int64_t watermark2; - int32_t ttl; - SArray* pFuncs; - int32_t commentLen; - char* pComment; - SSchema* pSchemas; - int32_t tagsLen; - char* pTags; + char tbName[TSDB_TABLE_NAME_LEN]; + char stbName[TSDB_TABLE_NAME_LEN]; + char dbFName[TSDB_DB_FNAME_LEN]; + int32_t numOfTags; + int32_t numOfColumns; + int8_t tableType; + int64_t delay1; + int64_t delay2; + int64_t watermark1; + int64_t watermark2; + int32_t ttl; + SArray* pFuncs; + int32_t commentLen; + char* pComment; + SSchema* pSchemas; + int32_t tagsLen; + char* pTags; + SSchemaExt* pSchemaExt; } STableCfg; typedef STableCfg STableCfgRsp; diff --git a/source/common/src/tcol.c b/source/common/src/tcol.c index 82ceae482e..97663d86db 100644 --- a/source/common/src/tcol.c +++ b/source/common/src/tcol.c @@ -295,3 +295,7 @@ void setColCompressByOption(uint32_t* compress, uint8_t encode, uint16_t compres setColLevel(compress, level); return; } + +bool useCompress(uint8_t tableType) { + return TSDB_SUPER_TABLE == tableType || TSDB_NORMAL_TABLE == tableType; +} diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b7a65b2bb4..a667fdd95f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2904,6 +2904,11 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1; + for (int32_t i = 0; i < pRsp->numOfColumns; ++i) + { + SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; + if (tEncodeSSchemaExt(&encoder, pSchemaExt) < 0) return -1; + } tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -2962,6 +2967,21 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) if (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1; if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1; + if (1 /*!tDecodeIsEnd(&decoder)*/) { + if (pRsp->numOfColumns > 0) { + pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); + if (pRsp->pSchemaExt == NULL) return -1; + + for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { + SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; + if (tDecodeSSchemaExt(&decoder, pSchemaExt) < 0) return -1; + pSchemaExt->colId = i; + pSchemaExt->compress = 0x02000303; + } + } else { + pRsp->pSchemaExt = NULL; + } + } tEndDecode(&decoder); tDecoderClear(&decoder); @@ -2975,6 +2995,7 @@ void tFreeSTableCfgRsp(STableCfgRsp *pRsp) { taosMemoryFreeClear(pRsp->pComment); taosMemoryFreeClear(pRsp->pSchemas); + taosMemoryFreeClear(pRsp->pSchemaExt); taosMemoryFreeClear(pRsp->pTags); taosArrayDestroy(pRsp->pFuncs); diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 4825d0f4bb..d48286dc6c 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -1630,14 +1630,14 @@ static void* ctgCloneQnodeList(void* pSrc) { return taosArrayDup((const SArray*) static void ctgFreeQnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); } -static void* ctgCloneTableCfg(void* pSrc) { - STableCfg* pDst = taosMemoryMalloc(sizeof(STableCfg)); - if (NULL == pDst) { - return NULL; - } - memcpy(pDst, pSrc, sizeof(STableCfg)); - return pDst; -} +// static void* ctgCloneTableCfg(void* pSrc) { +// STableCfg* pDst = taosMemoryMalloc(sizeof(STableCfg)); +// if (NULL == pDst) { +// return NULL; +// } +// memcpy(pDst, pSrc, sizeof(STableCfg)); +// return pDst; +// } static void ctgFreeTableCfg(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 9781262064..1ca47297bf 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -521,7 +521,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) { void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { for (int32_t i = 0; i < pCfg->numOfColumns; ++i) { SSchema* pSchema = pCfg->pSchemas + i; - char type[32]; + char type[32 + 60]; // 60 byte for compress info sprintf(type, "%s", tDataTypes[pSchema->type].name); if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type || TSDB_DATA_TYPE_GEOMETRY == pSchema->type) { sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE)); @@ -529,6 +529,12 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } + if (useCompress(pCfg->tableType)) { + sprintf(type + strlen(type), " ENCODE \'%s\'", columnEncodeStr(COMPRESS_L1_TYPE_U32(pCfg->pSchemaExt[i].compress))); + sprintf(type + strlen(type), " COMPRESS \'%s\'", columnCompressStr(COMPRESS_L2_TYPE_U32(pCfg->pSchemaExt[i].compress))); + sprintf(type + strlen(type), " LEVEL \'%s\'", columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pCfg->pSchemaExt[i].compress))); + } + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type); } } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 11ea272039..9eef62e7a8 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -683,6 +683,7 @@ static void destroyTableCfg(STableCfg* pCfg) { taosArrayDestroy(pCfg->pFuncs); taosMemoryFree(pCfg->pComment); taosMemoryFree(pCfg->pSchemas); + taosMemoryFree(pCfg->pSchemaExt); taosMemoryFree(pCfg->pTags); taosMemoryFree(pCfg); } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 7f4738938b..cffbe11c52 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -1146,7 +1146,12 @@ STableCfg* tableCfgDup(STableCfg* pCfg) { SSchema* pSchema = taosMemoryMalloc(schemaSize); memcpy(pSchema, pCfg->pSchemas, schemaSize); + int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt); + SSchemaExt* pSchemaExt = taosMemoryMalloc(schemaExtSize); + memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize); + pNew->pSchemas = pSchema; + pNew->pSchemaExt = pSchemaExt; return pNew; }