show create table tbname

This commit is contained in:
factosea 2024-03-13 11:39:07 +08:00
parent 066a22443d
commit b10deacd63
8 changed files with 65 additions and 26 deletions

View File

@ -76,6 +76,7 @@ uint8_t columnLevelVal(const char* level);
uint8_t columnEncodeVal(const char* encode); uint8_t columnEncodeVal(const char* encode);
uint16_t columnCompressVal(const char* compress); uint16_t columnCompressVal(const char* compress);
bool useCompress(uint8_t tableType);
bool checkColumnEncode(char encode[TSDB_CL_COMPRESS_OPTION_LEN]); bool checkColumnEncode(char encode[TSDB_CL_COMPRESS_OPTION_LEN]);
bool checkColumnEncodeOrSetDefault(uint8_t type, 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]); bool checkColumnCompress(char compress[TSDB_CL_COMPRESS_OPTION_LEN]);

View File

@ -1199,6 +1199,7 @@ typedef struct {
SSchema* pSchemas; SSchema* pSchemas;
int32_t tagsLen; int32_t tagsLen;
char* pTags; char* pTags;
SSchemaExt* pSchemaExt;
} STableCfg; } STableCfg;
typedef STableCfg STableCfgRsp; typedef STableCfg STableCfgRsp;

View File

@ -295,3 +295,7 @@ void setColCompressByOption(uint32_t* compress, uint8_t encode, uint16_t compres
setColLevel(compress, level); setColLevel(compress, level);
return; return;
} }
bool useCompress(uint8_t tableType) {
return TSDB_SUPER_TABLE == tableType || TSDB_NORMAL_TABLE == tableType;
}

View File

@ -2904,6 +2904,11 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) {
if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1;
if (tEncodeBinary(&encoder, pRsp->pTags, 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); tEndEncode(&encoder);
int32_t tlen = encoder.pos; 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 (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1;
if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 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); tEndDecode(&decoder);
tDecoderClear(&decoder); tDecoderClear(&decoder);
@ -2975,6 +2995,7 @@ void tFreeSTableCfgRsp(STableCfgRsp *pRsp) {
taosMemoryFreeClear(pRsp->pComment); taosMemoryFreeClear(pRsp->pComment);
taosMemoryFreeClear(pRsp->pSchemas); taosMemoryFreeClear(pRsp->pSchemas);
taosMemoryFreeClear(pRsp->pSchemaExt);
taosMemoryFreeClear(pRsp->pTags); taosMemoryFreeClear(pRsp->pTags);
taosArrayDestroy(pRsp->pFuncs); taosArrayDestroy(pRsp->pFuncs);

View File

@ -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 ctgFreeQnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
static void* ctgCloneTableCfg(void* pSrc) { // static void* ctgCloneTableCfg(void* pSrc) {
STableCfg* pDst = taosMemoryMalloc(sizeof(STableCfg)); // STableCfg* pDst = taosMemoryMalloc(sizeof(STableCfg));
if (NULL == pDst) { // if (NULL == pDst) {
return NULL; // return NULL;
} // }
memcpy(pDst, pSrc, sizeof(STableCfg)); // memcpy(pDst, pSrc, sizeof(STableCfg));
return pDst; // return pDst;
} // }
static void ctgFreeTableCfg(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void ctgFreeTableCfg(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); }

View File

@ -521,7 +521,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) { for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
SSchema* pSchema = pCfg->pSchemas + 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); 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) { 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)); 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)); 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); *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
} }
} }

View File

@ -683,6 +683,7 @@ static void destroyTableCfg(STableCfg* pCfg) {
taosArrayDestroy(pCfg->pFuncs); taosArrayDestroy(pCfg->pFuncs);
taosMemoryFree(pCfg->pComment); taosMemoryFree(pCfg->pComment);
taosMemoryFree(pCfg->pSchemas); taosMemoryFree(pCfg->pSchemas);
taosMemoryFree(pCfg->pSchemaExt);
taosMemoryFree(pCfg->pTags); taosMemoryFree(pCfg->pTags);
taosMemoryFree(pCfg); taosMemoryFree(pCfg);
} }

View File

@ -1146,7 +1146,12 @@ STableCfg* tableCfgDup(STableCfg* pCfg) {
SSchema* pSchema = taosMemoryMalloc(schemaSize); SSchema* pSchema = taosMemoryMalloc(schemaSize);
memcpy(pSchema, pCfg->pSchemas, 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->pSchemas = pSchema;
pNew->pSchemaExt = pSchemaExt;
return pNew; return pNew;
} }