show create table
This commit is contained in:
parent
b10deacd63
commit
9711c830fe
|
@ -23,7 +23,8 @@ extern "C" {
|
|||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#define DESCRIBE_RESULT_COLS 7
|
||||
#define DESCRIBE_RESULT_COLS 4
|
||||
#define DESCRIBE_RESULT_COLS_COMPRESS 7
|
||||
#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (16 + VARSTR_HEADER_SIZE)
|
||||
|
|
|
@ -2904,11 +2904,13 @@ 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)
|
||||
{
|
||||
if (useCompress(pRsp->tableType)) {
|
||||
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;
|
||||
|
@ -2967,8 +2969,8 @@ 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) {
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) {
|
||||
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
|
||||
if (pRsp->pSchemaExt == NULL) return -1;
|
||||
|
||||
|
@ -4454,7 +4456,7 @@ static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) {
|
|||
if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1;
|
||||
}
|
||||
|
||||
if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) {
|
||||
if (useCompress(pRsp->tableType)) {
|
||||
for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
|
||||
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
|
||||
if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1;
|
||||
|
@ -4492,10 +4494,8 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
|
|||
pRsp->pSchemas = NULL;
|
||||
}
|
||||
|
||||
// if (tDecodeIsEnd(pDecoder)) return 0;
|
||||
if (!tDecodeIsEnd(pDecoder)) {
|
||||
if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) {
|
||||
if (pRsp->numOfColumns > 0) {
|
||||
if (useCompress(pRsp->tableType) && pRsp->numOfColumns > 0) {
|
||||
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
|
||||
if (pRsp->pSchemaExt == NULL) return -1;
|
||||
|
||||
|
@ -4508,9 +4508,6 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
|
|||
} else {
|
||||
pRsp->pSchemaExt = NULL;
|
||||
}
|
||||
} else {
|
||||
pRsp->pSchemaExt = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -100,7 +100,8 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta, int8_t biMode) {
|
||||
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
|
||||
int8_t biMode) {
|
||||
int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
|
||||
blockDataEnsureCapacity(pBlock, blockCap);
|
||||
pBlock->info.rows = 0;
|
||||
|
@ -114,11 +115,17 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
// Note
|
||||
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
|
||||
// encode
|
||||
SColumnInfoData* pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
|
||||
SColumnInfoData* pCol5 = NULL;
|
||||
// compress
|
||||
SColumnInfoData* pCol6 = taosArrayGet(pBlock->pDataBlock, 5);
|
||||
SColumnInfoData* pCol6 = NULL;
|
||||
// level
|
||||
SColumnInfoData* pCol7 = taosArrayGet(pBlock->pDataBlock, 6);
|
||||
SColumnInfoData* pCol7 = NULL;
|
||||
if (useCompress(pMeta->tableType)) {
|
||||
pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
|
||||
pCol6 = taosArrayGet(pBlock->pDataBlock, 5);
|
||||
pCol7 = taosArrayGet(pBlock->pDataBlock, 6);
|
||||
}
|
||||
|
||||
char buf[DESCRIBE_RESULT_FIELD_LEN] = {0};
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) {
|
||||
|
@ -136,6 +143,7 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
STR_TO_VARSTR(buf, "VIEW COL");
|
||||
}
|
||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
||||
if (useCompress(pMeta->tableType)) {
|
||||
if (i < pMeta->tableInfo.numOfColumns) {
|
||||
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
|
||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
||||
|
@ -151,6 +159,8 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
STR_TO_VARSTR(buf, "");
|
||||
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
|
||||
}
|
||||
}
|
||||
|
||||
++(pBlock->info.rows);
|
||||
}
|
||||
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
|
||||
|
@ -181,8 +191,12 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp**
|
|||
code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (pDesc->pMeta && useCompress(pDesc->pMeta->tableType)) {
|
||||
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_COMPRESS, pRsp);
|
||||
} else {
|
||||
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
||||
}
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -9228,8 +9228,9 @@ static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
static int32_t extractDescribeResultSchema(STableMeta* pMeta, int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = DESCRIBE_RESULT_COLS;
|
||||
if (pMeta && useCompress(pMeta->tableType)) *numOfCols = DESCRIBE_RESULT_COLS_COMPRESS;
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -9251,6 +9252,7 @@ static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema
|
|||
(*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN;
|
||||
strcpy((*pSchema)[3].name, "note");
|
||||
|
||||
if (pMeta && useCompress(pMeta->tableType)) {
|
||||
(*pSchema)[4].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[4].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN;
|
||||
strcpy((*pSchema)[4].name, "encode");
|
||||
|
@ -9262,6 +9264,7 @@ static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema
|
|||
(*pSchema)[6].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[6].bytes = DESCRIBE_RESULT_COPRESS_OPTION_LEN;
|
||||
strcpy((*pSchema)[6].name, "level");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -9391,7 +9394,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
|
|||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return extractExplainResultSchema(numOfCols, pSchema);
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return extractDescribeResultSchema(numOfCols, pSchema);
|
||||
SDescribeStmt* pNode = (SDescribeStmt*)pRoot;
|
||||
return extractDescribeResultSchema(pNode->pMeta, numOfCols, pSchema);
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
return extractShowCreateDatabaseResultSchema(numOfCols, pSchema);
|
||||
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
|
||||
|
|
|
@ -282,16 +282,21 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t schemaExtSize = pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
size_t schemaExtSize = 0;
|
||||
if (useCompress(pTableMeta->tableType)) {
|
||||
schemaExtSize = pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
}
|
||||
size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
|
||||
STableMeta* p = taosMemoryMalloc(size + schemaExtSize);
|
||||
|
||||
if (NULL == p) return NULL;
|
||||
|
||||
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size);
|
||||
memcpy(p, pTableMeta, size);
|
||||
if (useCompress(pTableMeta->tableType)) {
|
||||
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size);
|
||||
p->schemaExt = pSchemaExt;
|
||||
memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -1145,10 +1150,12 @@ STableCfg* tableCfgDup(STableCfg* pCfg) {
|
|||
|
||||
SSchema* pSchema = taosMemoryMalloc(schemaSize);
|
||||
memcpy(pSchema, pCfg->pSchemas, schemaSize);
|
||||
|
||||
SSchemaExt* pSchemaExt = NULL;
|
||||
if (useCompress(pCfg->tableType)) {
|
||||
int32_t schemaExtSize = pCfg->numOfColumns * sizeof(SSchemaExt);
|
||||
SSchemaExt* pSchemaExt = taosMemoryMalloc(schemaExtSize);
|
||||
pSchemaExt = taosMemoryMalloc(schemaExtSize);
|
||||
memcpy(pSchemaExt, pCfg->pSchemaExt, schemaExtSize);
|
||||
}
|
||||
|
||||
pNew->pSchemas = pSchema;
|
||||
pNew->pSchemaExt = pSchemaExt;
|
||||
|
|
|
@ -463,14 +463,19 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
|||
}
|
||||
|
||||
int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema);
|
||||
int32_t schemaExtSize = pSrc->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
int32_t schemaExtSize = 0;
|
||||
if (useCompress(pSrc->tableType)) {
|
||||
schemaExtSize = pSrc->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
}
|
||||
*pDst = taosMemoryMalloc(metaSize + schemaExtSize);
|
||||
if (NULL == *pDst) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(*pDst, pSrc, metaSize);
|
||||
if (useCompress(pSrc->tableType)) {
|
||||
(*pDst)->schemaExt = (SSchemaExt*)((char*)*pDst + metaSize);
|
||||
memcpy((*pDst)->schemaExt, pSrc->schemaExt, schemaExtSize);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -423,7 +423,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
|
|||
pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
|
||||
|
||||
memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
|
||||
if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_NORMAL_TABLE) {
|
||||
if (useCompress(msg->tableType)) {
|
||||
pTableMeta->schemaExt = pSchemaExt;
|
||||
memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue