Merge pull request #17235 from taosdata/feat/TD-17777-V30

feat(shell): Supported the word completed by press Tab key for 3.0
This commit is contained in:
Shengliang Guan 2022-10-09 17:01:56 +08:00 committed by GitHub
commit 1c106bfd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 873 additions and 1032 deletions

View File

@ -40,7 +40,6 @@ typedef struct StrName {
struct StrName* next; struct StrName* next;
} StrName; } StrName;
typedef struct STire { typedef struct STire {
char type; // see define TIRE_ char type; // see define TIRE_
STireNode root; STireNode root;
@ -57,7 +56,6 @@ typedef struct SMatchNode {
struct SMatchNode* next; struct SMatchNode* next;
} SMatchNode; } SMatchNode;
typedef struct SMatch { typedef struct SMatch {
SMatchNode* head; SMatchNode* head;
SMatchNode* tail; // append node to tail SMatchNode* tail; // append node to tail
@ -65,7 +63,6 @@ typedef struct SMatch {
char pre[MAX_WORD_LEN]; char pre[MAX_WORD_LEN];
} SMatch; } SMatch;
// ----------- interface ------------- // ----------- interface -------------
// create prefix search tree, return value call freeTire to free // create prefix search tree, return value call freeTire to free

View File

@ -25,7 +25,6 @@
// //
#define UNION_ALL " union all " #define UNION_ALL " union all "
// extern function // extern function
void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos); void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos);
void shellGetPrevCharSize(const char* str, int32_t pos, int32_t* size, int32_t* width); void shellGetPrevCharSize(const char* str, int32_t pos, int32_t* size, int32_t* width);
@ -33,7 +32,6 @@ void shellShowOnScreen(SShellCmd *cmd);
void shellInsertChar(SShellCmd* cmd, char* c, int size); void shellInsertChar(SShellCmd* cmd, char* c, int size);
bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* p, int32_t len); bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* p, int32_t len);
typedef struct SAutoPtr { typedef struct SAutoPtr {
STire* p; STire* p;
int ref; int ref;
@ -58,7 +56,9 @@ typedef struct {
} SWords; } SWords;
SWords shellCommands[] = { SWords shellCommands[] = {
{"alter database <db_name> <alter_db_options> <anyword> <alter_db_options> <anyword> <alter_db_options> <anyword> <alter_db_options> <anyword> <alter_db_options> <anyword> ;", 0, 0, NULL}, {"alter database <db_name> <alter_db_options> <anyword> <alter_db_options> <anyword> <alter_db_options> <anyword> "
"<alter_db_options> <anyword> <alter_db_options> <anyword> ;",
0, 0, NULL},
{"alter dnode <dnode_id> balance ", 0, 0, NULL}, {"alter dnode <dnode_id> balance ", 0, 0, NULL},
{"alter dnode <dnode_id> resetlog;", 0, 0, NULL}, {"alter dnode <dnode_id> resetlog;", 0, 0, NULL},
{"alter dnode <dnode_id> debugFlag 141;", 0, 0, NULL}, {"alter dnode <dnode_id> debugFlag 141;", 0, 0, NULL},
@ -80,7 +80,10 @@ SWords shellCommands[] = {
{"alter user <user_name> <user_actions> <anyword> ;", 0, 0, NULL}, {"alter user <user_name> <user_actions> <anyword> ;", 0, 0, NULL},
// 20 // 20
{"create table <anyword> using <stb_name> tags(", 0, 0, NULL}, {"create table <anyword> using <stb_name> tags(", 0, 0, NULL},
{"create database <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> ;", 0, 0, NULL}, {"create database <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> "
"<anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> <db_options> <anyword> "
"<db_options> <anyword> <db_options> <anyword> ;",
0, 0, NULL},
{"create dnode ", 0, 0, NULL}, {"create dnode ", 0, 0, NULL},
{"create index ", 0, 0, NULL}, {"create index ", 0, 0, NULL},
{"create mnode on dnode <dnode_id> ;", 0, 0, NULL}, {"create mnode on dnode <dnode_id> ;", 0, 0, NULL},
@ -142,11 +145,11 @@ SWords shellCommands[] = {
// 80 // 80
{"show query <anyword> ;", 0, 0, NULL}, {"show query <anyword> ;", 0, 0, NULL},
{"show qnodes;", 0, 0, NULL}, {"show qnodes;", 0, 0, NULL},
{"show snodes;", 0, 0, NULL},
{"show stables;", 0, 0, NULL}, {"show stables;", 0, 0, NULL},
{"show stables like ", 0, 0, NULL}, {"show stables like ", 0, 0, NULL},
{"show streams;", 0, 0, NULL}, {"show streams;", 0, 0, NULL},
{"show scores;", 0, 0, NULL}, {"show scores;", 0, 0, NULL},
{"show snodes;", 0, 0, NULL},
{"show subscriptions;", 0, 0, NULL}, {"show subscriptions;", 0, 0, NULL},
{"show tables;", 0, 0, NULL}, {"show tables;", 0, 0, NULL},
{"show tables like", 0, 0, NULL}, {"show tables like", 0, 0, NULL},
@ -169,126 +172,57 @@ SWords shellCommands[] = {
{"insert into <tb_name> file ", 0, 0, NULL}, {"insert into <tb_name> file ", 0, 0, NULL},
{"trim database <db_name>", 0, 0, NULL}, {"trim database <db_name>", 0, 0, NULL},
{"use <db_name>", 0, 0, NULL}, {"use <db_name>", 0, 0, NULL},
{"quit", 0, 0, NULL} {"quit", 0, 0, NULL}};
};
char* keywords[] = { char* keywords[] = {
"and ", "and ", "asc ", "desc ", "from ", "fill(", "limit ", "where ",
"asc ", "interval(", "order by ", "order by ", "offset ", "or ", "group by ", "now()",
"desc ", "session(", "sliding ", "slimit ", "soffset ", "state_window(", "today() ", "union all select ",
"from ", "partition by "};
"fill(",
"limit ",
"where ",
"interval(",
"order by ",
"order by ",
"offset ",
"or ",
"group by ",
"now()",
"session(",
"sliding ",
"slimit ",
"soffset ",
"state_window(",
"today() ",
"union all select ",
"partition by "
};
char* functions[] = { char* functions[] = {
"count(", "count(", "sum(",
"sum(", "avg(", "last(",
"avg(", "last_row(", "top(",
"last(", "interp(", "max(",
"last_row(", "min(", "now()",
"top(", "today()", "percentile(",
"interp(", "tail(", "pow(",
"max(", "abs(", "atan(",
"min(", "acos(", "asin(",
"now()", "apercentile(", "bottom(",
"today()", "cast(", "ceil(",
"percentile(", "char_length(", "cos(",
"tail(", "concat(", "concat_ws(",
"pow(", "csum(", "diff(",
"abs(", "derivative(", "elapsed(",
"atan(", "first(", "floor(",
"acos(", "hyperloglog(", "histogram(",
"asin(", "irate(", "leastsquares(",
"apercentile(", "length(", "log(",
"bottom(", "lower(", "ltrim(",
"cast(", "mavg(", "mode(",
"ceil(", "tan(", "round(",
"char_length(", "rtrim(", "sample(",
"cos(", "sin(", "spread(",
"concat(", "substr(", "statecount(",
"concat_ws(", "stateduration(", "stddev(",
"csum(", "sqrt(", "timediff(",
"diff(", "timezone(", "timetruncate(",
"derivative(", "twa(", "to_unixtimestamp(",
"elapsed(", "unique(", "upper(",
"first(",
"floor(",
"hyperloglog(",
"histogram(",
"irate(",
"leastsquares(",
"length(",
"log(",
"lower(",
"ltrim(",
"mavg(",
"mode(",
"tan(",
"round(",
"rtrim(",
"sample(",
"sin(",
"spread(",
"substr(",
"statecount(",
"stateduration(",
"stddev(",
"sqrt(",
"timediff(",
"timezone(",
"timetruncate(",
"twa(",
"to_unixtimestamp(",
"unique(",
"upper(",
}; };
char* tb_actions[] = { char* tb_actions[] = {
"add column ", "add column ", "modify column ", "drop column ", "rename column ", "add tag ",
"modify column ", "modify tag ", "drop tag ", "rename tag ", "set tag ",
"drop column ",
"rename column ",
"add tag ",
"modify tag ",
"drop tag ",
"rename tag ",
"set tag ",
}; };
char * user_actions[] = { char* user_actions[] = {"pass ", "enable ", "sysinfo "};
"pass ",
"enable ",
"sysinfo "
};
char * tb_options[] = { char* tb_options[] = {"comment ", "watermark ", "max_delay ", "ttl ", "rollup(", "sma("};
"comment ",
"watermark ",
"max_delay ",
"ttl ",
"rollup(",
"sma("
};
char * db_options[] = { char* db_options[] = {"keep ",
"keep ",
"replica ", "replica ",
"precision ", "precision ",
"strict ", "strict ",
@ -309,43 +243,22 @@ char * db_options[] = {
"wal_retention_period ", "wal_retention_period ",
"wal_roll_period ", "wal_roll_period ",
"wal_retention_size ", "wal_retention_size ",
"wal_segment_size " "wal_segment_size "};
};
char * alter_db_options[] = { char* alter_db_options[] = {"keep ", "cachemodel ", "cachesize ", "wal_fsync_period ", "wal_level "};
"keep ",
"cachemodel ",
"cachesize ",
"wal_fsync_period ",
"wal_level "
};
char * data_types[] = { char* data_types[] = {"timestamp", "int",
"timestamp", "int unsigned", "varchar(16)",
"int", "float", "double",
"int unsigned", "binary(16)", "nchar(16)",
"varchar(16)", "bigint", "bigint unsigned",
"float", "smallint", "smallint unsigned",
"double", "tinyint", "tinyint unsigned",
"binary(16)", "bool", "json"};
"nchar(16)",
"bigint",
"bigint unsigned",
"smallint",
"smallint unsigned",
"tinyint",
"tinyint unsigned",
"bool",
"json"
};
char * key_tags[] = { char* key_tags[] = {"tags("};
"tags("
};
char * key_select[] = { char* key_select[] = {"select "};
"select "
};
// //
// ------- gobal variant define --------- // ------- gobal variant define ---------
@ -356,7 +269,6 @@ int32_t curMatchIndex = -1; // current match shellCommands index
int32_t lastWordBytes = -1; // printShow last word length int32_t lastWordBytes = -1; // printShow last word length
bool waitAutoFill = false; bool waitAutoFill = false;
// //
// ----------- global var array define ----------- // ----------- global var array define -----------
// //
@ -380,7 +292,6 @@ bool waitAutoFill = false;
#define WT_VAR_USERACTION 17 #define WT_VAR_USERACTION 17
#define WT_VAR_KEYSELECT 18 #define WT_VAR_KEYSELECT 18
#define WT_VAR_CNT 19 #define WT_VAR_CNT 19
#define WT_FROM_DB_MAX 6 // max get content from db #define WT_FROM_DB_MAX 6 // max get content from db
@ -395,50 +306,23 @@ TdThreadMutex tiresMutex;
// save thread handle obtain var name from db server // save thread handle obtain var name from db server
TdThread* threads[WT_FROM_DB_CNT]; TdThread* threads[WT_FROM_DB_CNT];
// obtain var name with sql from server // obtain var name with sql from server
char varTypes[WT_VAR_CNT][64] = { char varTypes[WT_VAR_CNT][64] = {"<db_name>", "<stb_name>", "<tb_name>", "<dnode_id>", "<user_name>",
"<db_name>", "<topic_name>", "<stream_name>", "<all_table>", "<function>", "<keyword>",
"<stb_name>", "<tb_actions>", "<db_options>", "<alter_db_options>", "<data_types>", "<key_tags>",
"<tb_name>", "<anyword>", "<tb_options>", "<user_actions>", "<key_select>"};
"<dnode_id>",
"<user_name>",
"<topic_name>",
"<stream_name>",
"<all_table>",
"<function>",
"<keyword>",
"<tb_actions>",
"<db_options>",
"<alter_db_options>",
"<data_types>",
"<key_tags>",
"<anyword>",
"<tb_options>",
"<user_actions>",
"<key_select>"
};
char varSqls[WT_FROM_DB_CNT][64] = {
"show databases;",
"show stables;",
"show tables;",
"show dnodes;",
"show users;",
"show topics;",
"show streams;"
};
char varSqls[WT_FROM_DB_CNT][64] = {"show databases;", "show stables;", "show tables;", "show dnodes;",
"show users;", "show topics;", "show streams;"};
// var words current cursor, if user press any one key except tab, cursorVar can be reset to -1 // var words current cursor, if user press any one key except tab, cursorVar can be reset to -1
int cursorVar = -1; int cursorVar = -1;
bool varMode = false; // enter var names list mode bool varMode = false; // enter var names list mode
TAOS* varCon = NULL; TAOS* varCon = NULL;
SShellCmd* varCmd = NULL; SShellCmd* varCmd = NULL;
SMatch* lastMatch = NULL; // save last match result SMatch* lastMatch = NULL; // save last match result
int cntDel = 0; // delete byte count after next press tab int cntDel = 0; // delete byte count after next press tab
// show auto tab introduction // show auto tab introduction
void printfIntroduction() { void printfIntroduction() {
printf(" **************************** How To Use TAB Key ********************************\n"); printf(" **************************** How To Use TAB Key ********************************\n");
@ -459,7 +343,8 @@ void printfIntroduction() {
void showHelp() { void showHelp() {
printf("\nThe following are supported commands for TDengine Command Line:"); printf("\nThe following are supported commands for TDengine Command Line:");
printf("\n\ printf(
"\n\
----- A ----- \n\ ----- A ----- \n\
alter database <db_name> <db_options> \n\ alter database <db_name> <db_options> \n\
alter dnode <dnode_id> balance \n\ alter dnode <dnode_id> balance \n\
@ -574,7 +459,8 @@ void showHelp() {
printf("\n\n"); printf("\n\n");
// define in getDuration() function // define in getDuration() function
printf("\ printf(
"\
Timestamp expression Format:\n\ Timestamp expression Format:\n\
b - nanosecond \n\ b - nanosecond \n\
u - microsecond \n\ u - microsecond \n\
@ -600,8 +486,7 @@ void showHelp() {
SWord* atWord(SWords* command, int32_t index) { SWord* atWord(SWords* command, int32_t index) {
SWord* word = command->head; SWord* word = command->head;
for (int32_t i = 0; i < index; i++) { for (int32_t i = 0; i < index; i++) {
if (word == NULL) if (word == NULL) return NULL;
return NULL;
word = word->next; word = word->next;
} }
@ -612,8 +497,7 @@ SWord * atWord(SWords * command, int32_t index) {
int wordType(const char* p, int32_t len) { int wordType(const char* p, int32_t len) {
for (int i = 0; i < WT_VAR_CNT; i++) { for (int i = 0; i < WT_VAR_CNT; i++) {
if (strncmp(p, varTypes[i], len) == 0) if (strncmp(p, varTypes[i], len) == 0) return i;
return i;
} }
return WT_TEXT; return WT_TEXT;
} }
@ -689,14 +573,12 @@ void freeCommand(SWords * command) {
SWord* tmp = word; SWord* tmp = word;
word = word->next; word = word->next;
// if malloc need free // if malloc need free
if(tmp->free && tmp->word) if (tmp->free && tmp->word) taosMemoryFree(tmp->word);
taosMemoryFree(tmp->word);
taosMemoryFree(tmp); taosMemoryFree(tmp);
} }
// if malloc need free // if malloc need free
if(word->free && word->word) if (word->free && word->word) taosMemoryFree(word->word);
taosMemoryFree(word->word);
taosMemoryFree(word); taosMemoryFree(word);
} }
@ -715,7 +597,6 @@ void GenerateVarType(int type, char** p, int count) {
// -------------------- shell auto ---------------- // -------------------- shell auto ----------------
// //
// init shell auto funciton , shell start call once // init shell auto funciton , shell start call once
bool shellAutoInit() { bool shellAutoInit() {
// command // command
@ -747,9 +628,7 @@ bool shellAutoInit() {
} }
// set conn // set conn
void shellSetConn(TAOS* conn) { void shellSetConn(TAOS* conn) { varCon = conn; }
varCon = conn;
}
// exit shell auto funciton, shell exit call once // exit shell auto funciton, shell exit call once
void shellAutoExit() { void shellAutoExit() {
@ -790,8 +669,7 @@ void shellAutoExit() {
// ------------------- auto ptr for tires -------------------------- // ------------------- auto ptr for tires --------------------------
// //
bool setNewAuotPtr(int type, STire* pNew) { bool setNewAuotPtr(int type, STire* pNew) {
if (pNew == NULL) if (pNew == NULL) return false;
return false;
taosThreadMutexLock(&tiresMutex); taosThreadMutexLock(&tiresMutex);
STire* pOld = tires[type]; STire* pOld = tires[type];
@ -846,8 +724,6 @@ void putBackAutoPtr(int type, STire* tire) {
return; return;
} }
// //
// ------------------- var Word -------------------------- // ------------------- var Word --------------------------
// //
@ -952,8 +828,7 @@ char* matchNextPrefix(STire* tire, char* pre) {
// save to lastMatch // save to lastMatch
if (match) { if (match) {
if (lastMatch) if (lastMatch) freeMatch(lastMatch);
freeMatch(lastMatch);
lastMatch = match; lastMatch = match;
} }
} }
@ -1011,8 +886,7 @@ char* tireSearchWord(int type, char* pre) {
if (type > WT_FROM_DB_MAX) { if (type > WT_FROM_DB_MAX) {
// NOT FROM DB , tires[type] alwary not null // NOT FROM DB , tires[type] alwary not null
STire* tire = tires[type]; STire* tire = tires[type];
if (tire == NULL) if (tire == NULL) return NULL;
return NULL;
return matchNextPrefix(tire, pre); return matchNextPrefix(tire, pre);
} }
@ -1069,8 +943,7 @@ bool matchVarWord(SWord* word1, SWord* word2) {
str = tireSearchWord(WT_VAR_STABLE, pre); str = tireSearchWord(WT_VAR_STABLE, pre);
if (str == NULL) { if (str == NULL) {
str = tireSearchWord(WT_VAR_TABLE, pre); str = tireSearchWord(WT_VAR_TABLE, pre);
if(str == NULL) if (str == NULL) return false;
return false;
} }
} else { } else {
// OTHER // OTHER
@ -1098,7 +971,6 @@ bool matchVarWord(SWord* word1, SWord* word2) {
// ------------------- match words -------------------------- // ------------------- match words --------------------------
// //
// compare command cmd1 come from shellCommands , cmd2 come from user input // compare command cmd1 come from shellCommands , cmd2 come from user input
int32_t compareCommand(SWords* cmd1, SWords* cmd2) { int32_t compareCommand(SWords* cmd1, SWords* cmd2) {
SWord* word1 = cmd1->head; SWord* word1 = cmd1->head;
@ -1112,8 +984,7 @@ int32_t compareCommand(SWords * cmd1, SWords * cmd2) {
if (word1->type == WT_TEXT) { if (word1->type == WT_TEXT) {
// WT_TEXT match // WT_TEXT match
if (word1->len == word2->len) { if (word1->len == word2->len) {
if (strncasecmp(word1->word, word2->word, word1->len) != 0) if (strncasecmp(word1->word, word2->word, word1->len) != 0) return -1;
return -1;
} else if (word1->len < word2->len) { } else if (word1->len < word2->len) {
return -1; return -1;
} else { } else {
@ -1172,8 +1043,7 @@ SWords * matchCommand(SWords * input, bool continueSearch) {
// compare // compare
int32_t index = compareCommand(shellCommand, input); int32_t index = compareCommand(shellCommand, input);
if (index != -1) { if (index != -1) {
if (firstMatchIndex == -1) if (firstMatchIndex == -1) firstMatchIndex = i;
firstMatchIndex = i;
curMatchIndex = i; curMatchIndex = i;
return &shellCommands[i]; return &shellCommands[i];
} }
@ -1226,8 +1096,7 @@ void printScreen(TAOS * con, SShellCmd * cmd, SWords * match) {
lastMatchIndex = firstMatchIndex; lastMatchIndex = firstMatchIndex;
lastWordBytes = word->len; lastWordBytes = word->len;
} else { } else {
if (lastWordBytes == -1) if (lastWordBytes == -1) return;
return ;
deleteCount(cmd, lastWordBytes); deleteCount(cmd, lastWordBytes);
SWord* word = MATCH_WORD(match); SWord* word = MATCH_WORD(match);
@ -1242,7 +1111,6 @@ void printScreen(TAOS * con, SShellCmd * cmd, SWords * match) {
shellInsertChar(cmd, (char*)str, strLen); shellInsertChar(cmd, (char*)str, strLen);
} }
// main key press tab , matched return true else false // main key press tab , matched return true else false
bool firstMatchCommand(TAOS* con, SShellCmd* cmd) { bool firstMatchCommand(TAOS* con, SShellCmd* cmd) {
// parse command // parse command
@ -1319,8 +1187,7 @@ bool nextMatchCommand(TAOS * con, SShellCmd * cmd, SWords * firstMatch) {
match = matchCommand(input, false); match = matchCommand(input, false);
if (match == NULL) { if (match == NULL) {
freeCommand(input); freeCommand(input);
if (input->source) if (input->source) taosMemoryFree(input->source);
taosMemoryFree(input->source);
taosMemoryFree(input); taosMemoryFree(input);
return false; return false;
} }
@ -1367,8 +1234,7 @@ bool fillTableName(TAOS * con, SShellCmd * cmd, char* pre) {
char* str = tireSearchWord(WT_VAR_STABLE, pre); char* str = tireSearchWord(WT_VAR_STABLE, pre);
if (str == NULL) { if (str == NULL) {
str = tireSearchWord(WT_VAR_TABLE, pre); str = tireSearchWord(WT_VAR_TABLE, pre);
if(str == NULL) if (str == NULL) return false;
return false;
} }
// need insert part string // need insert part string
@ -1543,8 +1409,7 @@ int32_t searchAfterSelect(char* p, int32_t len) {
char* p1 = p + 7; char* p1 = p + 7;
while (1) { while (1) {
char* p2 = strstr(p1, "select "); char* p2 = strstr(p1, "select ");
if(p2 == NULL) if (p2 == NULL) break;
break;
p1 = p2 + 7; p1 = p2 + 7;
} }
@ -1557,13 +1422,13 @@ int32_t searchAfterSelect(char* p, int32_t len) {
} }
char* as_pos_end = strstr(p, " as select "); char* as_pos_end = strstr(p, " as select ");
if (as_pos_end == NULL) if (as_pos_end == NULL) return -1;
return -1;
as_pos_end += 11; as_pos_end += 11;
// create stream <stream_name> as select // create stream <stream_name> as select
if (strncasecmp(p, "create stream ", 14) == 0) { if (strncasecmp(p, "create stream ", 14) == 0) {
return as_pos_end - p;; return as_pos_end - p;
;
} }
// create topic <topic_name> as select // create topic <topic_name> as select
@ -1600,8 +1465,7 @@ bool matchSelectQuery(TAOS * con, SShellCmd * cmd) {
char* sql_cp = strndup(p, len); char* sql_cp = strndup(p, len);
int32_t n = searchAfterSelect(sql_cp, len); int32_t n = searchAfterSelect(sql_cp, len);
taosMemoryFree(sql_cp); taosMemoryFree(sql_cp);
if(n == -1 || n > len) if (n == -1 || n > len) return false;
return false;
p += n; p += n;
len -= n; len -= n;
@ -1711,8 +1575,7 @@ bool matchOther(TAOS * con, SShellCmd * cmd) {
} }
// too small // too small
if(len < 8) if (len < 8) return false;
return false;
// like 'from ( ' // like 'from ( '
char* sql = strndup(p, len); char* sql = strndup(p, len);
@ -1731,8 +1594,7 @@ bool matchOther(TAOS * con, SShellCmd * cmd) {
// find last ' from' // find last ' from'
while (from) { while (from) {
char* p1 = strstr(from + 5, " from"); char* p1 = strstr(from + 5, " from");
if (p1 == NULL) if (p1 == NULL) break;
break;
from = p1; from = p1;
} }
@ -1770,13 +1632,11 @@ bool matchOther(TAOS * con, SShellCmd * cmd) {
// INSERT // INSERT
taosMemoryFree(sql); taosMemoryFree(sql);
return false; return false;
} }
// main key press tab // main key press tab
void pressTabKey(SShellCmd* cmd) { void pressTabKey(SShellCmd* cmd) {
// check // check
@ -1793,8 +1653,7 @@ void pressTabKey(SShellCmd * cmd) {
// manual match like create table st( ... // manual match like create table st( ...
matched = matchCreateTable(varCon, cmd); matched = matchCreateTable(varCon, cmd);
if (matched) if (matched) return;
return ;
// shellCommands match // shellCommands match
if (firstMatchIndex == -1) { if (firstMatchIndex == -1) {
@ -1802,19 +1661,16 @@ void pressTabKey(SShellCmd * cmd) {
} else { } else {
matched = nextMatchCommand(varCon, cmd, &shellCommands[firstMatchIndex]); matched = nextMatchCommand(varCon, cmd, &shellCommands[firstMatchIndex]);
} }
if (matched) if (matched) return;
return ;
// NOT MATCHED ANYONE // NOT MATCHED ANYONE
// match other like '\G' ... // match other like '\G' ...
matched = matchOther(varCon, cmd); matched = matchOther(varCon, cmd);
if (matched) if (matched) return;
return ;
// manual match like select * from ... // manual match like select * from ...
matched = matchSelectQuery(varCon, cmd); matched = matchSelectQuery(varCon, cmd);
if (matched) if (matched) return;
return ;
return; return;
} }
@ -2006,19 +1862,16 @@ bool dealDropCommand(char * sql) {
bool del = false; bool del = false;
// del in stable // del in stable
STire* tire = tires[WT_VAR_STABLE]; STire* tire = tires[WT_VAR_STABLE];
if(tire) if (tire) del = deleteWord(tire, name);
del = deleteWord(tire, name);
// del in table // del in table
if (!del) { if (!del) {
tire = tires[WT_VAR_TABLE]; tire = tires[WT_VAR_TABLE];
if(tire) if (tire) del = deleteWord(tire, name);
del = deleteWord(tire, name);
} }
} else { } else {
// OTHER TYPE // OTHER TYPE
STire* tire = tires[type]; STire* tire = tires[type];
if(tire) if (tire) deleteWord(tire, name);
deleteWord(tire, name);
} }
taosThreadMutexUnlock(&tiresMutex); taosThreadMutexUnlock(&tiresMutex);

View File

@ -32,8 +32,7 @@ STire* createTire(char type) {
// free tire node // free tire node
void freeTireNode(STireNode* node) { void freeTireNode(STireNode* node) {
if (node == NULL) if (node == NULL) return;
return ;
// nest free sub node on array d // nest free sub node on array d
if (node->d) { if (node->d) {
@ -184,8 +183,7 @@ bool deleteFromTree(STire* tire, char* word, int len) {
} }
} }
if(nodes[m]->d == NULL) if (nodes[m]->d == NULL) break;
break;
// move to next node // move to next node
nodes = nodes[m]->d; nodes = nodes[m]->d;
} }
@ -255,8 +253,7 @@ void enumAllWords(STireNode** nodes, char* prefix, SMatch* match) {
addWordToMatch(match, word); addWordToMatch(match, word);
} }
// nested call next layer // nested call next layer
if (c->d) if (c->d) enumAllWords(c->d, word, match);
enumAllWords(c->d, word, match);
} }
} }
} }
@ -310,12 +307,10 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) {
} }
// prefix is match to end char // prefix is match to end char
if (c->d) if (c->d) enumAllWords(c->d, prefix, root);
enumAllWords(c->d, prefix, root);
} else { } else {
// move to next node continue match // move to next node continue match
if(c->d == NULL) if (c->d == NULL) break;
break;
nodes = c->d; nodes = c->d;
} }
} }
@ -348,7 +343,6 @@ SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) {
return match; return match;
} }
// get all items from tires tree // get all items from tires tree
void enumFromList(STire* tire, SMatch* match) { void enumFromList(STire* tire, SMatch* match) {
StrName* item = tire->head; StrName* item = tire->head;
@ -410,16 +404,13 @@ SMatch* enumAll(STire* tire) {
return match; return match;
} }
// free match result // free match result
void freeMatchNode(SMatchNode* node) { void freeMatchNode(SMatchNode* node) {
// first free next // first free next
if (node->next) if (node->next) freeMatchNode(node->next);
freeMatchNode(node->next);
// second free self // second free self
if (node->word) if (node->word) taosMemoryFree(node->word);
taosMemoryFree(node->word);
taosMemoryFree(node); taosMemoryFree(node);
} }