Skip to content

Commit d552f2e

Browse files
authored
fix: [6719658649] Fix wrong show create virtual table output. (#34360)
1 parent 2d3494e commit d552f2e

File tree

5 files changed

+284
-4
lines changed

5 files changed

+284
-4
lines changed

source/libs/command/src/command.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ static void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
642642

643643
static void appendColRefFields(char* buf, int32_t* len, STableCfg* pCfg) {
644644
char expandName[(SHOW_CREATE_TB_RESULT_FIELD1_LEN << 1) + 1] = {0};
645+
bool firstRef = true;
645646
for (int32_t i = 1; i < pCfg->numOfColumns; ++i) {
646647
SSchema* pSchema = pCfg->pSchemas + i;
647648
SColRef* pRef = pCfg->pColRefs + i;
@@ -659,8 +660,11 @@ static void appendColRefFields(char* buf, int32_t* len, STableCfg* pCfg) {
659660
}
660661

661662
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
662-
"%s`%s` %s", ((i > 1) ? ", " : ""), expandIdentifier(pSchema->name, expandName), type);
663-
663+
"%s`%s` %s", (!firstRef ? ", " : " ("), expandIdentifier(pSchema->name, expandName), type);
664+
firstRef = false;
665+
}
666+
if (!firstRef) {
667+
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), ")");
664668
}
665669
}
666670

@@ -929,10 +933,10 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
929933
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
930934
} else if (TSDB_VIRTUAL_CHILD_TABLE == pCfg->tableType) {
931935
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
932-
"CREATE VTABLE `%s` (", expandIdentifier(tbName, buf1));
936+
"CREATE VTABLE `%s`", expandIdentifier(tbName, buf1));
933937
appendColRefFields(buf2, &len, pCfg);
934938
len += snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
935-
") USING `%s` (", expandIdentifier(pCfg->stbName, buf1));
939+
" USING `%s` (", expandIdentifier(pCfg->stbName, buf1));
936940
appendTagNameFields(buf2, &len, pCfg);
937941
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
938942
") TAGS (");

0 commit comments

Comments
 (0)