refactor: do some internal refactor, add the column info in STableRetrieveRsp.
This commit is contained in:
parent
9bee5e2cee
commit
716dd2c5e4
|
@ -356,8 +356,8 @@ typedef enum ELogicConditionType {
|
||||||
|
|
||||||
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
|
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
|
||||||
|
|
||||||
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024
|
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 512
|
||||||
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN"
|
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY_PLAN"
|
||||||
|
|
||||||
#define TSDB_MAX_FIELD_LEN 16384
|
#define TSDB_MAX_FIELD_LEN 16384
|
||||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
|
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
|
||||||
|
|
|
@ -780,31 +780,28 @@ TEST(testCase, async_api_test) {
|
||||||
|
|
||||||
taos_query(pConn, "use test");
|
taos_query(pConn, "use test");
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "select * from t1");
|
TAOS_RES* pRes = taos_query(pConn, "desc abc1.tu");
|
||||||
|
|
||||||
taos_query(pConn, "alter table t1 add column b int");
|
|
||||||
pRes = taos_query(pConn, "insert into t1 values(now, 1, 2)");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed, reason:%s\n", taos_errstr(pRes));
|
printf("failed, reason:%s\n", taos_errstr(pRes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// int32_t n = 0;
|
int32_t n = 0;
|
||||||
// TAOS_ROW pRow = NULL;
|
TAOS_ROW pRow = NULL;
|
||||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
// int32_t numOfFields = taos_num_fields(pRes);
|
int32_t numOfFields = taos_num_fields(pRes);
|
||||||
//
|
|
||||||
// char str[512] = {0};
|
char str[512] = {0};
|
||||||
// while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
// int32_t* length = taos_fetch_lengths(pRes);
|
int32_t* length = taos_fetch_lengths(pRes);
|
||||||
// for(int32_t i = 0; i < numOfFields; ++i) {
|
for(int32_t i = 0; i < numOfFields; ++i) {
|
||||||
// printf("(%d):%d " , i, length[i]);
|
printf("(%d):%d " , i, length[i]);
|
||||||
// }
|
}
|
||||||
// printf("\n");
|
printf("\n");
|
||||||
//
|
|
||||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
// printf("%s\n", str);
|
printf("%s\n", str);
|
||||||
// memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
// }
|
}
|
||||||
|
|
||||||
taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn);
|
taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn);
|
||||||
getchar();
|
getchar();
|
||||||
|
|
|
@ -1902,7 +1902,7 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen
|
||||||
int32_t* colSizes = (int32_t*)data;
|
int32_t* colSizes = (int32_t*)data;
|
||||||
data += numOfCols * sizeof(int32_t);
|
data += numOfCols * sizeof(int32_t);
|
||||||
|
|
||||||
*dataLen = blockDataGetSerialMetaSize(numOfCols);;
|
*dataLen = blockDataGetSerialMetaSize(numOfCols);
|
||||||
|
|
||||||
int32_t numOfRows = pBlock->info.rows;
|
int32_t numOfRows = pBlock->info.rows;
|
||||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||||
|
|
|
@ -28,91 +28,94 @@ static int32_t getSchemaBytes(const SSchema* pSchema) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo : to convert data according to SSDatablock
|
static SSDataBlock* buildDescResultDataBlock() {
|
||||||
static void buildRspData(const STableMeta* pMeta, char* pData) {
|
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
int32_t* payloadLen = (int32_t*) pData;
|
pBlock->info.numOfCols = DESCRIBE_RESULT_COLS;
|
||||||
uint64_t* groupId = (uint64_t*)(pData + sizeof(int32_t));
|
pBlock->info.hasVarCol = true;
|
||||||
|
|
||||||
int32_t* pColSizes = (int32_t*)(pData + sizeof(int32_t) + sizeof(uint64_t));
|
pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData));
|
||||||
pData = (char*) pColSizes + DESCRIBE_RESULT_COLS * sizeof(int32_t);
|
|
||||||
|
|
||||||
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta);
|
SColumnInfoData infoData = {0};
|
||||||
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
|
infoData.info.bytes = DESCRIBE_RESULT_FIELD_LEN;
|
||||||
|
|
||||||
// Field
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
int32_t* pOffset = (int32_t*)pData;
|
|
||||||
pData += numOfRows * sizeof(int32_t);
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
|
infoData.info.bytes = DESCRIBE_RESULT_TYPE_LEN;
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
|
||||||
|
infoData.info.type = TSDB_DATA_TYPE_INT;
|
||||||
|
infoData.info.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes;;
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
|
||||||
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
|
infoData.info.bytes = DESCRIBE_RESULT_NOTE_LEN;
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
|
||||||
|
return pBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setDescResultIntoDataBlock(SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta) {
|
||||||
|
blockDataEnsureCapacity(pBlock, numOfRows);
|
||||||
|
pBlock->info.rows = numOfRows;
|
||||||
|
|
||||||
|
// field
|
||||||
|
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
|
char buf[DESCRIBE_RESULT_FIELD_LEN] = {0};
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
STR_TO_VARSTR(pData, pMeta->schema[i].name);
|
STR_TO_VARSTR(buf, pMeta->schema[i].name);
|
||||||
int16_t len = varDataTLen(pData);
|
colDataAppend(pCol1, i, buf, false);
|
||||||
pData += len;
|
|
||||||
*pOffset = pColSizes[0];
|
|
||||||
pOffset += 1;
|
|
||||||
pColSizes[0] += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type
|
// Type
|
||||||
pOffset = (int32_t*)pData;
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
pData += numOfRows * sizeof(int32_t);
|
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
STR_TO_VARSTR(pData, tDataTypes[pMeta->schema[i].type].name);
|
STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
|
||||||
int16_t len = varDataTLen(pData);
|
colDataAppend(pCol2, i, buf, false);
|
||||||
pData += len;
|
|
||||||
*pOffset = pColSizes[1];
|
|
||||||
pOffset += 1;
|
|
||||||
pColSizes[1] += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length
|
// Length
|
||||||
pData += BitmapLen(numOfRows);
|
SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2);
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
*(int32_t*)pData = getSchemaBytes(pMeta->schema + i);
|
int32_t bytes = getSchemaBytes(pMeta->schema + i);
|
||||||
pData += sizeof(int32_t);
|
colDataAppend(pCol3, i, (const char*)&bytes, false);
|
||||||
}
|
}
|
||||||
pColSizes[2] = sizeof(int32_t) * numOfRows;
|
|
||||||
|
|
||||||
// Note
|
// Note
|
||||||
pOffset = (int32_t*)pData;
|
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
|
||||||
pData += numOfRows * sizeof(int32_t);
|
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
STR_TO_VARSTR(pData, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
||||||
int16_t len = varDataTLen(pData);
|
colDataAppend(pCol4, i, buf, false);
|
||||||
pData += len;
|
|
||||||
*pOffset = pColSizes[3];
|
|
||||||
pOffset += 1;
|
|
||||||
pColSizes[3] += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < DESCRIBE_RESULT_COLS; ++i) {
|
|
||||||
pColSizes[i] = htonl(pColSizes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
*payloadLen = (int32_t)(pData - (char*)payloadLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t calcRspSize(const STableMeta* pMeta) {
|
|
||||||
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta);
|
|
||||||
return sizeof(SRetrieveTableRsp) +
|
|
||||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_FIELD_LEN) +
|
|
||||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_TYPE_LEN) +
|
|
||||||
(BitmapLen(numOfRows) + numOfRows * sizeof(int32_t)) +
|
|
||||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_NOTE_LEN) +
|
|
||||||
sizeof(int32_t) + sizeof(uint64_t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SDescribeStmt* pDesc = (SDescribeStmt*)pStmt;
|
SDescribeStmt* pDesc = (SDescribeStmt*) pStmt;
|
||||||
*pRsp = taosMemoryCalloc(1, calcRspSize(pDesc->pMeta));
|
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta);
|
||||||
|
|
||||||
|
SSDataBlock* pBlock = buildDescResultDataBlock();
|
||||||
|
setDescResultIntoDataBlock(pBlock, numOfRows, pDesc->pMeta);
|
||||||
|
|
||||||
|
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||||
|
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||||
if (NULL == *pRsp) {
|
if (NULL == *pRsp) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pRsp)->useconds = 0;
|
(*pRsp)->useconds = 0;
|
||||||
(*pRsp)->completed = 1;
|
(*pRsp)->completed = 1;
|
||||||
(*pRsp)->precision = 0;
|
(*pRsp)->precision = 0;
|
||||||
(*pRsp)->compressed = 0;
|
(*pRsp)->compressed = 0;
|
||||||
(*pRsp)->compLen = 0;
|
(*pRsp)->compLen = 0;
|
||||||
(*pRsp)->numOfRows = htonl(TABLE_TOTAL_COL_NUM(pDesc->pMeta));
|
(*pRsp)->numOfRows = htonl(numOfRows);
|
||||||
buildRspData(pDesc->pMeta, (*pRsp)->data);
|
(*pRsp)->numOfCols = htonl(DESCRIBE_RESULT_COLS);
|
||||||
|
|
||||||
|
int32_t len = 0;
|
||||||
|
blockCompressEncode(pBlock, (*pRsp)->data, &len, DESCRIBE_RESULT_COLS, false);
|
||||||
|
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||||
|
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "commandInt.h"
|
#include "commandInt.h"
|
||||||
#include "plannodes.h"
|
#include "plannodes.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
@ -916,9 +917,32 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colNum = 1;
|
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
int32_t rspSize = sizeof(SRetrieveTableRsp) + sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum +
|
SColumnInfoData infoData = {0};
|
||||||
sizeof(int32_t) * rowNum + pCtx->dataSize;
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
|
infoData.info.bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE;
|
||||||
|
|
||||||
|
pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||||
|
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
|
||||||
|
SColumnInfoData* pInfoData = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
|
pInfoData->hasNull = false;
|
||||||
|
colInfoDataEnsureCapacity(pInfoData, 0, rowNum);
|
||||||
|
|
||||||
|
char buf[1024] = {0};
|
||||||
|
for (int32_t i = 0; i < rowNum; ++i) {
|
||||||
|
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
||||||
|
varDataCopy(buf, row->buf);
|
||||||
|
ASSERT(varDataTLen(row->buf) == row->len);
|
||||||
|
colDataAppend(pInfoData, i, buf, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
pBlock->info.numOfCols = 1;
|
||||||
|
pBlock->info.rows = rowNum;
|
||||||
|
pBlock->info.hasVarCol = true;
|
||||||
|
|
||||||
|
int32_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||||
|
|
||||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
||||||
if (NULL == rsp) {
|
if (NULL == rsp) {
|
||||||
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
||||||
|
@ -928,34 +952,13 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
rsp->completed = 1;
|
rsp->completed = 1;
|
||||||
rsp->numOfRows = htonl(rowNum);
|
rsp->numOfRows = htonl(rowNum);
|
||||||
|
|
||||||
// payload length
|
int32_t len = 0;
|
||||||
*(int32_t *)rsp->data =
|
blockCompressEncode(pBlock, rsp->data, &len, pBlock->info.numOfCols, 0);
|
||||||
sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->dataSize;
|
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||||
|
|
||||||
// group id
|
rsp->compLen = htonl(len);
|
||||||
*(uint64_t *)(rsp->data + sizeof(int32_t)) = 0;
|
|
||||||
|
|
||||||
// column length
|
blockDataDestroy(pBlock);
|
||||||
int32_t *colLength = (int32_t *)(rsp->data + sizeof(int32_t) + sizeof(uint64_t));
|
|
||||||
|
|
||||||
// varchar column offset segment
|
|
||||||
int32_t *offset = (int32_t *)((char *)colLength + sizeof(int32_t));
|
|
||||||
|
|
||||||
// varchar data real payload
|
|
||||||
char *data = (char *)(offset + rowNum);
|
|
||||||
|
|
||||||
char *start = data;
|
|
||||||
for (int32_t i = 0; i < rowNum; ++i) {
|
|
||||||
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
|
||||||
offset[i] = data - start;
|
|
||||||
|
|
||||||
varDataCopy(data, row->buf);
|
|
||||||
ASSERT(varDataTLen(row->buf) == row->len);
|
|
||||||
data += row->len;
|
|
||||||
}
|
|
||||||
|
|
||||||
*colLength = htonl(data - start);
|
|
||||||
rsp->compLen = htonl(rspSize);
|
|
||||||
|
|
||||||
*pRsp = rsp;
|
*pRsp = rsp;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue