提交 9fccdce0 编写于 作者: S shenglian zhou

feat: add user tags to information schema

上级 fcc87f09
...@@ -155,11 +155,10 @@ static const SSysDbTableSchema userTblsSchema[] = { ...@@ -155,11 +155,10 @@ static const SSysDbTableSchema userTblsSchema[] = {
static const SSysDbTableSchema userTagsSchema[] = { static const SSysDbTableSchema userTagsSchema[] = {
{.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "tag_name", .bytes = TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "tag_name", .bytes = TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BIGINT},
{.name = "tag_type", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "tag_type", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
{.name = "tag_value", .bytes = TSDB_MAX_TAGS_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "tag_value", .bytes = TSDB_MAX_TAGS_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
}; };
......
...@@ -1742,14 +1742,14 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { ...@@ -1742,14 +1742,14 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) {
return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes;
} }
static SSDataBlock* buildSysTableMetaBlock() { static SSDataBlock* buildInfoSchemaTableMetaBlock(char* tableName) {
size_t size = 0; size_t size = 0;
const SSysTableMeta* pMeta = NULL; const SSysTableMeta* pMeta = NULL;
getInfosDbMeta(&pMeta, &size); getInfosDbMeta(&pMeta, &size);
int32_t index = 0; int32_t index = 0;
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
if (strcmp(pMeta[i].name, TSDB_INS_TABLE_USER_TABLES) == 0) { if (strcmp(pMeta[i].name, tableName) == 0) {
index = i; index = i;
break; break;
} }
...@@ -1768,7 +1768,6 @@ static SSDataBlock* buildSysTableMetaBlock() { ...@@ -1768,7 +1768,6 @@ static SSDataBlock* buildSysTableMetaBlock() {
static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SSysTableScanInfo* pInfo = pOperator->info; SSysTableScanInfo* pInfo = pOperator->info;
const char* name = tNameGetTableName(&pInfo->name);
if (pOperator->status == OP_EXEC_DONE) { if (pOperator->status == OP_EXEC_DONE) {
return NULL; return NULL;
} }
...@@ -1791,123 +1790,85 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { ...@@ -1791,123 +1790,85 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
tNameGetDbName(&sn, varDataVal(dbname)); tNameGetDbName(&sn, varDataVal(dbname));
varDataSetLen(dbname, strlen(varDataVal(dbname))); varDataSetLen(dbname, strlen(varDataVal(dbname)));
SSDataBlock* p = buildSysTableMetaBlock(); SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_USER_TAGS);
blockDataEnsureCapacity(p, pOperator->resultInfo.capacity); blockDataEnsureCapacity(p, pOperator->resultInfo.capacity);
char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
int32_t ret = 0; int32_t ret = 0;
while ((ret = metaTbCursorNext(pInfo->pCur)) == 0) { while ((ret = metaTbCursorNext(pInfo->pCur)) == 0) {
STR_TO_VARSTR(n, pInfo->pCur->mr.me.name); if (pInfo->pCur->mr.me.type != TSDB_CHILD_TABLE) {
continue;
// table name }
SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0);
colDataAppend(pColInfoData, numOfRows, n, false);
// database name
pColInfoData = taosArrayGet(p->pDataBlock, 1);
colDataAppend(pColInfoData, numOfRows, dbname, false);
// vgId
pColInfoData = taosArrayGet(p->pDataBlock, 6);
colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false);
int32_t tableType = pInfo->pCur->mr.me.type; char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
if (tableType == TSDB_CHILD_TABLE) { STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
// create time
int64_t ts = pInfo->pCur->mr.me.ctbEntry.ctime;
pColInfoData = taosArrayGet(p->pDataBlock, 2);
colDataAppend(pColInfoData, numOfRows, (char*)&ts, false);
SMetaReader mr = {0}; SMetaReader smr = {0};
metaReaderInit(&mr, pInfo->readHandle.meta, 0); metaReaderInit(&smr, pInfo->readHandle.meta, 0);
uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid;
int32_t code = metaGetTableEntryByUid(&mr, suid); int32_t code = metaGetTableEntryByUid(&smr, suid);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno), qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno),
GET_TASKID(pTaskInfo)); GET_TASKID(pTaskInfo));
metaReaderClear(&mr); metaReaderClear(&smr);
metaCloseTbCursor(pInfo->pCur); metaCloseTbCursor(pInfo->pCur);
pInfo->pCur = NULL; pInfo->pCur = NULL;
longjmp(pTaskInfo->env, terrno); longjmp(pTaskInfo->env, terrno);
} }
// number of columns char stableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
pColInfoData = taosArrayGet(p->pDataBlock, 3); STR_TO_VARSTR(stableName, smr.me.name);
colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false);
// super table name int32_t numOfTags = smr.me.stbEntry.schemaTag.nCols;
STR_TO_VARSTR(n, mr.me.name); for (int32_t i = 0; i < numOfTags; ++i) {
pColInfoData = taosArrayGet(p->pDataBlock, 4); SColumnInfoData* pColInfoData = NULL;
colDataAppend(pColInfoData, numOfRows, n, false);
metaReaderClear(&mr);
// table comment // table name
pColInfoData = taosArrayGet(p->pDataBlock, 8); pColInfoData = taosArrayGet(p->pDataBlock, 0);
if (pInfo->pCur->mr.me.ctbEntry.commentLen > 0) { colDataAppend(pColInfoData, numOfRows, tableName, false);
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment);
colDataAppend(pColInfoData, numOfRows, comment, false);
} else if (pInfo->pCur->mr.me.ctbEntry.commentLen == 0) {
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, "");
colDataAppend(pColInfoData, numOfRows, comment, false);
} else {
colDataAppendNULL(pColInfoData, numOfRows);
}
// uid
pColInfoData = taosArrayGet(p->pDataBlock, 5);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false);
// ttl // database name
pColInfoData = taosArrayGet(p->pDataBlock, 7); pColInfoData = taosArrayGet(p->pDataBlock, 1);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); colDataAppend(pColInfoData, numOfRows, dbname, false);
STR_TO_VARSTR(n, "CHILD_TABLE"); // super table name
} else if (tableType == TSDB_NORMAL_TABLE) {
// create time
pColInfoData = taosArrayGet(p->pDataBlock, 2); pColInfoData = taosArrayGet(p->pDataBlock, 2);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ctime, false); colDataAppend(pColInfoData, numOfRows, stableName, false);
// number of columns char tagName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(tagName, smr.me.stbEntry.schemaTag.pSchema[i].name);
pColInfoData = taosArrayGet(p->pDataBlock, 3); pColInfoData = taosArrayGet(p->pDataBlock, 3);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.schemaRow.nCols, false); colDataAppend(pColInfoData, numOfRows, tagName, false);
// super table name int8_t tagType = smr.me.stbEntry.schemaTag.pSchema[i].type;
pColInfoData = taosArrayGet(p->pDataBlock, 4); pColInfoData = taosArrayGet(p->pDataBlock, 4);
colDataAppendNULL(pColInfoData, numOfRows); colDataAppend(pColInfoData, numOfRows, (char*)&tagType, false);
// table comment STagVal tagVal = {0};
pColInfoData = taosArrayGet(p->pDataBlock, 8); tagVal.cid = smr.me.stbEntry.schemaTag.pSchema[i].colId;
if (pInfo->pCur->mr.me.ntbEntry.commentLen > 0) { const char* pVal = metaGetTableTagVal(&pInfo->pCur->mr.me, tagType, &tagVal);
char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment); char* tagData = NULL;
colDataAppend(pColInfoData, numOfRows, comment, false); if (tagType != TSDB_DATA_TYPE_JSON && p != NULL) {
} else if (pInfo->pCur->mr.me.ntbEntry.commentLen == 0) { tagData = tTagValToData((const STagVal*)pVal, false);
char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0};
STR_TO_VARSTR(comment, "");
colDataAppend(pColInfoData, numOfRows, comment, false);
} else { } else {
colDataAppendNULL(pColInfoData, numOfRows); tagData = (char*)pVal;
} }
// uid
pColInfoData = taosArrayGet(p->pDataBlock, 5); pColInfoData = taosArrayGet(p->pDataBlock, 5);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); colDataAppend(pColInfoData, numOfRows, tagData,
(tagData == NULL) || (tagType == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(tagData)));
// ttl
pColInfoData = taosArrayGet(p->pDataBlock, 7);
colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false);
STR_TO_VARSTR(n, "NORMAL_TABLE"); if (tagType != TSDB_DATA_TYPE_JSON && p != NULL && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
tagData != NULL) {
taosMemoryFree(tagData);
} }
pColInfoData = taosArrayGet(p->pDataBlock, 9); ++numOfRows;
colDataAppend(pColInfoData, numOfRows, n, false); }
metaReaderClear(&smr);
if (++numOfRows >= pOperator->resultInfo.capacity) { if (numOfRows >= pOperator->resultInfo.capacity) {
break; break;
} }
} }
...@@ -1931,14 +1892,9 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { ...@@ -1931,14 +1892,9 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
} }
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) {
// build message and send to mnode to fetch the content of system tables.
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SSysTableScanInfo* pInfo = pOperator->info; SSysTableScanInfo* pInfo = pOperator->info;
// retrieve local table list info from vnode
const char* name = tNameGetTableName(&pInfo->name);
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) {
if (pOperator->status == OP_EXEC_DONE) { if (pOperator->status == OP_EXEC_DONE) {
return NULL; return NULL;
} }
...@@ -1971,7 +1927,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { ...@@ -1971,7 +1927,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
tNameGetDbName(&sn, varDataVal(dbname)); tNameGetDbName(&sn, varDataVal(dbname));
varDataSetLen(dbname, strlen(varDataVal(dbname))); varDataSetLen(dbname, strlen(varDataVal(dbname)));
SSDataBlock* p = buildSysTableMetaBlock(); SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_USER_TABLES);
blockDataEnsureCapacity(p, pOperator->resultInfo.capacity); blockDataEnsureCapacity(p, pOperator->resultInfo.capacity);
char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
...@@ -2110,6 +2066,19 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { ...@@ -2110,6 +2066,19 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; pInfo->loadInfo.totalRows += pInfo->pRes->info.rows;
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
} }
}
static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
// build message and send to mnode to fetch the content of system tables.
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SSysTableScanInfo* pInfo = pOperator->info;
const char* name = tNameGetTableName(&pInfo->name);
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) {
return sysTableScanUserTables(pOperator);
} else if (strncasecmp(name, TSDB_INS_TABLE_USER_TAGS, TSDB_TABLE_FNAME_LEN) == 0) {
return sysTableScanUserTags(pOperator);
} else { // load the meta from mnode of the given epset } else { // load the meta from mnode of the given epset
if (pOperator->status == OP_EXEC_DONE) { if (pOperator->status == OP_EXEC_DONE) {
return NULL; return NULL;
...@@ -2189,7 +2158,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { ...@@ -2189,7 +2158,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
} }
int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) { int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
SSDataBlock* p = buildSysTableMetaBlock(); SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_USER_TABLES);
blockDataEnsureCapacity(p, capacity); blockDataEnsureCapacity(p, capacity);
size_t size = 0; size_t size = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册