From 736149daeae74f38510ec4ab2e84026ac3e24316 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 24 Oct 2024 17:41:37 +0800 Subject: [PATCH 01/22] feat: from 3.3.1.0~ 3.3.3.0 new key add --- tools/shell/src/shellAuto.c | 155 ++++++++++++++++++++++++++++-------- 1 file changed, 121 insertions(+), 34 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 65ae9fad54..9e6b0fe79e 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -99,6 +99,8 @@ SWords shellCommands[] = { {"create qnode on dnode ;", 0, 0, NULL}, {"create stream into as select", 0, 0, NULL}, // 26 append sub sql {"create topic as select", 0, 0, NULL}, // 27 append sub sql + {"create tsma on function", 0, 0, NULL}, + {"create recursive tsma on interval(", 0, 0, NULL}, {"create function as outputtype language ", 0, 0, NULL}, {"create or replace as outputtype language ", 0, 0, NULL}, {"create aggregate function as outputtype bufsize language ", 0, 0, NULL}, @@ -123,6 +125,7 @@ SWords shellCommands[] = { {"drop consumer group on ", 0, 0, NULL}, {"drop topic ;", 0, 0, NULL}, {"drop stream ;", 0, 0, NULL}, + {"drop tsma ;", 0, 0, NULL}, {"explain select", 0, 0, NULL}, // 44 append sub sql {"flush database ;", 0, 0, NULL}, {"help;", 0, 0, NULL}, @@ -163,12 +166,14 @@ SWords shellCommands[] = { {"show create database \\G;", 0, 0, NULL}, {"show create stable \\G;", 0, 0, NULL}, {"show create table \\G;", 0, 0, NULL}, + {"show create tsma \\G;", 0, 0, NULL}, #ifdef TD_ENTERPRISE {"show create view \\G;", 0, 0, NULL}, -#endif - {"show connections;", 0, 0, NULL}, {"show compact", 0, 0, NULL}, {"show compacts;", 0, 0, NULL}, + +#endif + {"show connections;", 0, 0, NULL}, {"show cluster;", 0, 0, NULL}, {"show cluster alive;", 0, 0, NULL}, {"show cluster machines;", 0, 0, NULL}, @@ -196,10 +201,12 @@ SWords shellCommands[] = { {"show table tags from ", 0, 0, NULL}, {"show topics;", 0, 0, NULL}, {"show transactions;", 0, 0, NULL}, + {"show tsmas;", 0, 0, NULL}, {"show users;", 0, 0, NULL}, {"show variables;", 0, 0, NULL}, {"show local variables;", 0, 0, NULL}, - {"show vnodes ", 0, 0, NULL}, + {"show vnodes;", 0, 0, NULL}, + {"show vnodes on dnode ;", 0, 0, NULL}, {"show vgroups;", 0, 0, NULL}, {"show consumers;", 0, 0, NULL}, {"show grants;", 0, 0, NULL}, @@ -207,22 +214,26 @@ SWords shellCommands[] = { {"show grants logs;", 0, 0, NULL}, #ifdef TD_ENTERPRISE {"show views;", 0, 0, NULL}, + {"show arbgroups;", 0, 0, NULL}, {"split vgroup ", 0, 0, NULL}, + {"s3migrate database ", 0, 0, NULL}, #endif {"insert into values(", 0, 0, NULL}, {"insert into using tags(", 0, 0, NULL}, {"insert into using values(", 0, 0, NULL}, {"insert into file ", 0, 0, NULL}, {"trim database ", 0, 0, NULL}, - {"s3migrate database ", 0, 0, NULL}, {"use ", 0, 0, NULL}, {"quit", 0, 0, NULL}}; +// where keyword char* keywords[] = { "and ", "asc ", "desc ", "from ", "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 "}; + "partition by ", "match", "nmatch ", "between ", "like ", "is null ", "is not null ", + "state_window(", "event_window ", "count_window(" +}; char* functions[] = { "count(", "sum(", @@ -255,6 +266,20 @@ char* functions[] = { "timezone(", "timetruncate(", "twa(", "to_unixtimestamp(", "unique(", "upper(", + "pi(", "round(", + "truncate(", "exp(", + "ln(", "mod(", + "rand(", "sign(", + "degrees(", "radians(", + "greatest(", "least(", + "char_length(", "char(", + "ascii(", "position(", + "trim(", "replace(", + "repeat(", "substring(", + "substring_index(","timediff(", + "week(", "weekday(", + "weekofyear(", "dayofweek(", + "stddev_pop(", "var_pop(" }; char* tb_actions[] = { @@ -275,7 +300,7 @@ char* db_options[] = {"keep ", "cachesize ", "comp ", "duration ", - "wal_fsync_period", + "wal_fsync_period ", "maxrows ", "minrows ", "pages ", @@ -284,17 +309,22 @@ char* db_options[] = {"keep ", "wal_level ", "vgroups ", "single_stable ", - "s3_chunksize ", - "s3_keeplocal ", - "s3_compact ", + "s3_chunksize ", + "s3_keeplocal ", + "s3_compact ", "wal_retention_period ", "wal_roll_period ", "wal_retention_size ", - "wal_segment_size "}; +#ifdef TD_ENTERPRISE + "encrypt_algorithm " +#endif + "keep_time_offset ", + "wal_segment_size " +}; char* alter_db_options[] = {"cachemodel ", "replica ", "keep ", "stt_trigger ", "wal_retention_period ", "wal_retention_size ", "cachesize ", - "s3_keeplocal ", "s3_compact ", + "s3_keeplocal ", "s3_compact ", "wal_fsync_period ", "buffer ", "pages " ,"wal_level "}; char* data_types[] = {"timestamp", "int", @@ -304,6 +334,7 @@ char* data_types[] = {"timestamp", "int", "bigint", "bigint unsigned", "smallint", "smallint unsigned", "tinyint", "tinyint unsigned", + "geometry", "varbinary(16)", "bool", "json"}; char* key_tags[] = {"tags("}; @@ -319,6 +350,15 @@ char* key_systable[] = { char* udf_language[] = {"\'Python\'", "\'C\'"}; +char* field_options[] = { + "encode ", "compress ", "level ", + "lz4 ", "zlib ", "zstd ", "xz ", "tsz ", "disabled ", // compress + "simple8b ", "delta-i ", "delta-d ", "bit-packing ", + "high ", "medium ", "low ", + "comment ", + "primary key " +}; + // global keys can tips on anywhere char* global_keys[] = { "tbname", @@ -354,27 +394,29 @@ bool waitAutoFill = false; #define WT_VAR_STREAM 6 #define WT_VAR_UDFNAME 7 #define WT_VAR_VGROUPID 8 +#define WT_VAR_TSMA 9 -#define WT_FROM_DB_MAX 8 // max get content from db +#define WT_FROM_DB_MAX 9 // max get content from db #define WT_FROM_DB_CNT (WT_FROM_DB_MAX + 1) -#define WT_VAR_ALLTABLE 9 -#define WT_VAR_FUNC 10 -#define WT_VAR_KEYWORD 11 -#define WT_VAR_TBACTION 12 -#define WT_VAR_DBOPTION 13 -#define WT_VAR_ALTER_DBOPTION 14 -#define WT_VAR_DATATYPE 15 -#define WT_VAR_KEYTAGS 16 -#define WT_VAR_ANYWORD 17 -#define WT_VAR_TBOPTION 18 -#define WT_VAR_USERACTION 19 -#define WT_VAR_KEYSELECT 20 -#define WT_VAR_SYSTABLE 21 -#define WT_VAR_LANGUAGE 22 -#define WT_VAR_GLOBALKEYS 23 +#define WT_VAR_ALLTABLE 10 +#define WT_VAR_FUNC 11 +#define WT_VAR_KEYWORD 12 +#define WT_VAR_TBACTION 13 +#define WT_VAR_DBOPTION 14 +#define WT_VAR_ALTER_DBOPTION 15 +#define WT_VAR_DATATYPE 16 +#define WT_VAR_KEYTAGS 17 +#define WT_VAR_ANYWORD 18 +#define WT_VAR_TBOPTION 19 +#define WT_VAR_USERACTION 20 +#define WT_VAR_KEYSELECT 21 +#define WT_VAR_SYSTABLE 22 +#define WT_VAR_LANGUAGE 23 +#define WT_VAR_GLOBALKEYS 24 +#define WT_VAR_FIELD_OPTIONS 25 -#define WT_VAR_CNT 24 +#define WT_VAR_CNT 26 #define WT_TEXT 0xFF @@ -387,12 +429,17 @@ TdThreadMutex tiresMutex; TdThread* threads[WT_FROM_DB_CNT]; // obtain var name with sql from server char varTypes[WT_VAR_CNT][64] = { + // get from db "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", ""}; + "", "", "", + // get from code + "", "", "", "", "", "", + "", "", "", "", "", "", "", + "", "", ""}; char varSqls[WT_FROM_DB_CNT][64] = {"show databases;", "show stables;", "show tables;", "show dnodes;", - "show users;", "show topics;", "show streams;", "show functions;", "show vgroups;"}; + "show users;", "show topics;", "show streams;", "show functions;", + "show vgroups;", "show tsmas;"}; // var words current cursor, if user press any one key except tab, cursorVar can be reset to -1 int cursorVar = -1; @@ -567,7 +614,8 @@ void showHelp() { show users;\n\ show variables;\n\ show local variables;\n\ - show vnodes \n\ + show vnodes;\n\ + show vnodes on dnode ;\n\ show vgroups;\n\ show consumers;\n\ show grants;\n\ @@ -588,8 +636,10 @@ void showHelp() { create view as select ...\n\ redistribute vgroup dnode ;\n\ split vgroup ;\n\ + s3migrate database ;\n\ show compacts;\n\ show compact \n\ + show arbgroups;\n\ show views;\n\ show create view ;"); #endif @@ -756,6 +806,7 @@ bool shellAutoInit() { GenerateVarType(WT_VAR_SYSTABLE, key_systable, sizeof(key_systable) / sizeof(char*)); GenerateVarType(WT_VAR_LANGUAGE, udf_language, sizeof(udf_language) / sizeof(char*)); GenerateVarType(WT_VAR_GLOBALKEYS, global_keys, sizeof(global_keys) / sizeof(char*)); + GenerateVarType(WT_VAR_FIELD_OPTIONS, field_options, sizeof(field_options) / sizeof(char*)); return true; } @@ -1648,6 +1699,36 @@ bool matchSelectQuery(TAOS* con, SShellCmd* cmd) { return appendAfterSelect(con, cmd, p, len); } +// is fields option area +bool fieldOptionsArea(char* p) { + char* p1 = strrchr(p, '('); + char* p2 = strrchr(p, ','); + if (p1 == NULL && p2 == NULL) { + return false; + } + + if(p2 == NULL) { + // first field area + p2 = p1; + } + + // find blank count + int32_t cnt = 0; + while(p2) { + p2 = strchr(p2, ' '); + if(p2) { + cnt ++; + while (p2[1] != 0 && p2[1] == ' ') { + // move next if blank again + p2 += 1; + } + } + } + + // like create table st(ts timestamp TAB-KEY or st(ts timestamp , age int TAB-KEY + return cnt >= 2; +} + // if is input create fields or tags area, return true bool isCreateFieldsArea(char* p) { // put to while, support like create table st(ts timestamp, bin1 binary(16), bin2 + blank + TAB @@ -1717,8 +1798,14 @@ bool matchCreateTable(TAOS* con, SShellCmd* cmd) { char* last = lastWord(ps); // check in create fields or tags input area - if (isCreateFieldsArea(ps)) { - ret = fillWithType(con, cmd, last, WT_VAR_DATATYPE); + if (isCreateFieldsArea(ps)) { + if (fieldOptionsArea(ps)) { + // fill field options + ret = fillWithType(con, cmd, last, WT_VAR_FIELD_OPTIONS); + } else { + // fill field + ret = fillWithType(con, cmd, last, WT_VAR_DATATYPE); + } } // tags From b5e6c557497669a611a5803c0e9a33074ca2fd2c Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 24 Oct 2024 19:55:26 +0800 Subject: [PATCH 02/22] feat: auto append end char ; to command --- tools/shell/src/shellAuto.c | 119 ++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 52 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 9e6b0fe79e..a12efb7e96 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -46,6 +46,7 @@ typedef struct SWord { int32_t len; struct SWord* next; bool free; // if true need free + bool end; // if true is last keyword } SWord; typedef struct { @@ -95,62 +96,62 @@ SWords shellCommands[] = { " ;", 0, 0, NULL}, {"create dnode ", 0, 0, NULL}, {"create index on ()", 0, 0, NULL}, - {"create mnode on dnode ;", 0, 0, NULL}, - {"create qnode on dnode ;", 0, 0, NULL}, + {"create mnode on dnode ;", 0, 0, NULL}, + {"create qnode on dnode ;", 0, 0, NULL}, {"create stream into as select", 0, 0, NULL}, // 26 append sub sql {"create topic as select", 0, 0, NULL}, // 27 append sub sql {"create tsma on function", 0, 0, NULL}, {"create recursive tsma on interval(", 0, 0, NULL}, - {"create function as outputtype language ", 0, 0, NULL}, - {"create or replace as outputtype language ", 0, 0, NULL}, - {"create aggregate function as outputtype bufsize language ", 0, 0, NULL}, - {"create or replace aggregate function as outputtype bufsize language ", 0, 0, NULL}, + {"create function as outputtype language ;", 0, 0, NULL}, + {"create or replace as outputtype language ;", 0, 0, NULL}, + {"create aggregate function as outputtype bufsize language ;", 0, 0, NULL}, + {"create or replace aggregate function as outputtype bufsize language ;", 0, 0, NULL}, {"create user pass sysinfo 0;", 0, 0, NULL}, {"create user pass sysinfo 1;", 0, 0, NULL}, #ifdef TD_ENTERPRISE {"create view as select", 0, 0, NULL}, {"compact database ", 0, 0, NULL}, #endif - {"describe ", 0, 0, NULL}, + {"describe ;", 0, 0, NULL}, {"delete from where ", 0, 0, NULL}, - {"drop database ", 0, 0, NULL}, - {"drop index ", 0, 0, NULL}, - {"drop table ", 0, 0, NULL}, - {"drop dnode ", 0, 0, NULL}, - {"drop mnode on dnode ;", 0, 0, NULL}, - {"drop qnode on dnode ;", 0, 0, NULL}, - {"drop user ;", 0, 0, NULL}, + {"drop database ;", 0, 0, NULL}, + {"drop index ;", 0, 0, NULL}, + {"drop table ;", 0, 0, NULL}, + {"drop dnode ;", 0, 0, NULL}, + {"drop mnode on dnode ;", 0, 0, NULL}, + {"drop qnode on dnode ;", 0, 0, NULL}, + {"drop user ;", 0, 0, NULL}, // 40 - {"drop function ;", 0, 0, NULL}, + {"drop function ;", 0, 0, NULL}, {"drop consumer group on ", 0, 0, NULL}, - {"drop topic ;", 0, 0, NULL}, - {"drop stream ;", 0, 0, NULL}, - {"drop tsma ;", 0, 0, NULL}, - {"explain select", 0, 0, NULL}, // 44 append sub sql - {"flush database ;", 0, 0, NULL}, + {"drop topic ;", 0, 0, NULL}, + {"drop stream ;", 0, 0, NULL}, + {"drop tsma ;", 0, 0, NULL}, + {"explain select ", 0, 0, NULL}, // 44 append sub sql + {"flush database ;", 0, 0, NULL}, {"help;", 0, 0, NULL}, - {"grant all on to ;", 0, 0, NULL}, - {"grant read on to ;", 0, 0, NULL}, - {"grant write on to ;", 0, 0, NULL}, - {"kill connection ;", 0, 0, NULL}, + {"grant all on to ;", 0, 0, NULL}, + {"grant read on to ;", 0, 0, NULL}, + {"grant write on to ;", 0, 0, NULL}, + {"kill connection ;", 0, 0, NULL}, {"kill query ", 0, 0, NULL}, {"kill transaction ", 0, 0, NULL}, #ifdef TD_ENTERPRISE - {"merge vgroup ", 0, 0, NULL}, + {"merge vgroup ;", 0, 0, NULL}, #endif - {"pause stream ;", 0, 0, NULL}, + {"pause stream ;", 0, 0, NULL}, #ifdef TD_ENTERPRISE - {"redistribute vgroup dnode ;", 0, 0, NULL}, + {"redistribute vgroup dnode ;", 0, 0, NULL}, #endif - {"resume stream ;", 0, 0, NULL}, + {"resume stream ;", 0, 0, NULL}, {"reset query cache;", 0, 0, NULL}, - {"restore dnode ;", 0, 0, NULL}, - {"restore vnode on dnode ;", 0, 0, NULL}, - {"restore mnode on dnode ;", 0, 0, NULL}, - {"restore qnode on dnode ;", 0, 0, NULL}, - {"revoke all on from ;", 0, 0, NULL}, - {"revoke read on from ;", 0, 0, NULL}, - {"revoke write on from ;", 0, 0, NULL}, + {"restore dnode ;", 0, 0, NULL}, + {"restore vnode on dnode ;", 0, 0, NULL}, + {"restore mnode on dnode ;", 0, 0, NULL}, + {"restore qnode on dnode ;", 0, 0, NULL}, + {"revoke all on from ;", 0, 0, NULL}, + {"revoke read on from ;", 0, 0, NULL}, + {"revoke write on from ;", 0, 0, NULL}, {"select * from ", 0, 0, NULL}, {"select client_version();", 0, 0, NULL}, // 60 @@ -163,6 +164,7 @@ SWords shellCommands[] = { {"select timezone();", 0, 0, NULL}, {"set max_binary_display_width ", 0, 0, NULL}, {"show apps;", 0, 0, NULL}, + {"show alive;", 0, 0, NULL}, {"show create database \\G;", 0, 0, NULL}, {"show create stable \\G;", 0, 0, NULL}, {"show create table \\G;", 0, 0, NULL}, @@ -195,10 +197,9 @@ SWords shellCommands[] = { {"show subscriptions;", 0, 0, NULL}, {"show tables;", 0, 0, NULL}, {"show tables like", 0, 0, NULL}, - {"show table distributed ", 0, 0, NULL}, - {"show tags from ", 0, 0, NULL}, - {"show tags from ", 0, 0, NULL}, - {"show table tags from ", 0, 0, NULL}, + {"show table distributed ;", 0, 0, NULL}, + {"show tags from ;", 0, 0, NULL}, + {"show table tags from ;", 0, 0, NULL}, {"show topics;", 0, 0, NULL}, {"show transactions;", 0, 0, NULL}, {"show tsmas;", 0, 0, NULL}, @@ -206,7 +207,7 @@ SWords shellCommands[] = { {"show variables;", 0, 0, NULL}, {"show local variables;", 0, 0, NULL}, {"show vnodes;", 0, 0, NULL}, - {"show vnodes on dnode ;", 0, 0, NULL}, + {"show vnodes on dnode ;", 0, 0, NULL}, {"show vgroups;", 0, 0, NULL}, {"show consumers;", 0, 0, NULL}, {"show grants;", 0, 0, NULL}, @@ -215,15 +216,15 @@ SWords shellCommands[] = { #ifdef TD_ENTERPRISE {"show views;", 0, 0, NULL}, {"show arbgroups;", 0, 0, NULL}, - {"split vgroup ", 0, 0, NULL}, - {"s3migrate database ", 0, 0, NULL}, + {"split vgroup ;", 0, 0, NULL}, + {"s3migrate database ;", 0, 0, NULL}, #endif {"insert into values(", 0, 0, NULL}, {"insert into using tags(", 0, 0, NULL}, {"insert into using values(", 0, 0, NULL}, {"insert into file ", 0, 0, NULL}, - {"trim database ", 0, 0, NULL}, - {"use ", 0, 0, NULL}, + {"trim database ;", 0, 0, NULL}, + {"use ;", 0, 0, NULL}, {"quit", 0, 0, NULL}}; // where keyword @@ -362,7 +363,8 @@ char* field_options[] = { // global keys can tips on anywhere char* global_keys[] = { "tbname", - "now", + "now", + "vgroups", "_wstart", "_wend", "_wduration", @@ -581,6 +583,7 @@ void showHelp() { select timezone();\n\ set max_binary_display_width ...\n\ show apps;\n\ + show alive;\n\ show create database ;\n\ show create stable ;\n\ show create table ;\n\ @@ -698,7 +701,12 @@ SWord* addWord(const char* p, int32_t len, bool pattern) { // check format if (pattern && len > 0) { - word->type = wordType(p, len); + if (p[len-1] == ';') { + word->type = wordType(p, len - 1); + word->end = true; + } else { + word->type = wordType(p, len); + } } else { word->type = WT_TEXT; } @@ -1304,10 +1312,10 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { // first tab press const char* str = NULL; int strLen = 0; - + + SWord* word = MATCH_WORD(match); if (firstMatchIndex == curMatchIndex && lastWordBytes == -1) { // first press tab - SWord* word = MATCH_WORD(match); str = word->word + match->matchLen; strLen = word->len - match->matchLen; lastMatchIndex = firstMatchIndex; @@ -1315,8 +1323,6 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { } else { if (lastWordBytes == -1) return; deleteCount(cmd, lastWordBytes); - - SWord* word = MATCH_WORD(match); str = word->word; strLen = word->len; // set current to last @@ -1324,8 +1330,17 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { lastWordBytes = word->len; } - // insert new - shellInsertStr(cmd, (char*)str, strLen); + if (word->end) { + // append end ';' + char *p = taosMemoryMalloc(strLen + 8); + strcpy(p, str); + strcat(p, ";"); + shellInsertStr(cmd, (char *)p, strLen + 1); + taosMemoryFree(p); + } else { + // insert new + shellInsertStr(cmd, (char *)str, strLen); + } } // main key press tab , matched return true else false From de31de5d11940a3b9cae0e9b96607bda67177241 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 09:59:30 +0800 Subject: [PATCH 03/22] fix: parse blank count error --- tools/shell/src/shellAuto.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index a12efb7e96..05a996dafc 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1731,13 +1731,19 @@ bool fieldOptionsArea(char* p) { int32_t cnt = 0; while(p2) { p2 = strchr(p2, ' '); - if(p2) { - cnt ++; + if (p2) { + if ((p2 - 1)[0] != ',') { + // blank if before comma, not calc count. like st(ts timestamp, age int + BLANK + TAB only two blank + cnt ++; + } + + // continue blank is one blank while (p2[1] != 0 && p2[1] == ' ') { // move next if blank again p2 += 1; } - } + p2 += 1; + } } // like create table st(ts timestamp TAB-KEY or st(ts timestamp , age int TAB-KEY From 48444f2aca16f9efd778f6e2c29595c0ce933866 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 10:16:10 +0800 Subject: [PATCH 04/22] fix: compress and encode algo add single quotes --- tools/shell/src/shellAuto.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 05a996dafc..b8d346f34f 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -353,9 +353,9 @@ char* udf_language[] = {"\'Python\'", "\'C\'"}; char* field_options[] = { "encode ", "compress ", "level ", - "lz4 ", "zlib ", "zstd ", "xz ", "tsz ", "disabled ", // compress - "simple8b ", "delta-i ", "delta-d ", "bit-packing ", - "high ", "medium ", "low ", + "\'lz4\' ", "\'zlib\' ", "\'zstd\' ", "\'xz\' ", "\'tsz\' ", "\'disabled\' ", // compress + "\'simple8b\' ", "\'delta-i\' ", "\'delta-d\' ", "\'bit-packing\' ", + "\'high\' ", "\'medium\' ", "\'low\' ", "comment ", "primary key " }; From 1b2ac1e5376c0b1512a890f2e1df6f1f7642a690 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 10:44:23 +0800 Subject: [PATCH 05/22] fix: create talbe fields area support blank on left bracket --- tools/shell/src/shellAuto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index b8d346f34f..89d882d52b 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1732,7 +1732,9 @@ bool fieldOptionsArea(char* p) { while(p2) { p2 = strchr(p2, ' '); if (p2) { - if ((p2 - 1)[0] != ',') { + // get prev char + char prec = *(p2 - 1); + if (prec != ',' && prec != '(') { // blank if before comma, not calc count. like st(ts timestamp, age int + BLANK + TAB only two blank cnt ++; } From 86dbba5c8cf2e39feaeb41e8eafd5e95c3568698 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 10:58:25 +0800 Subject: [PATCH 06/22] fix: create table tags area --- tools/shell/src/shellAuto.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 89d882d52b..defbf1cb82 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1722,6 +1722,11 @@ bool fieldOptionsArea(char* p) { return false; } + // find tags + if(strstr(p, " tags") != NULL) { + return false; + } + if(p2 == NULL) { // first field area p2 = p1; From a10e6457bf173d8ed0587c6574547f4d39d3c269 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 14:00:32 +0800 Subject: [PATCH 07/22] fix: blank and double quotes --- tools/shell/src/shellAuto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index defbf1cb82..2b203953dd 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -229,7 +229,7 @@ SWords shellCommands[] = { // where keyword char* keywords[] = { - "and ", "asc ", "desc ", "from ", "fill(", "limit ", "where ", + "where ", "and ", "asc ", "desc ", "from ", "fill(", "limit ", "interval(", "order by ", "order by ", "offset ", "or ", "group by ", "now()", "session(", "sliding ", "slimit ", "soffset ", "state_window(", "today() ", "union all select ", "partition by ", "match", "nmatch ", "between ", "like ", "is null ", "is not null ", @@ -1330,7 +1330,7 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { lastWordBytes = word->len; } - if (word->end) { + if (word->end && str[strLen - 1] != ';') { // append end ';' char *p = taosMemoryMalloc(strLen + 8); strcpy(p, str); From 9dce56d552c4f99b7bbf45f4ff9c35e7c2110e6e Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 16:49:45 +0800 Subject: [PATCH 08/22] fix: fields area left right quotes change total method --- tools/shell/src/shellAuto.c | 45 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 2b203953dd..81021965a2 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -168,7 +168,6 @@ SWords shellCommands[] = { {"show create database \\G;", 0, 0, NULL}, {"show create stable \\G;", 0, 0, NULL}, {"show create table \\G;", 0, 0, NULL}, - {"show create tsma \\G;", 0, 0, NULL}, #ifdef TD_ENTERPRISE {"show create view \\G;", 0, 0, NULL}, {"show compact", 0, 0, NULL}, @@ -290,7 +289,7 @@ char* tb_actions[] = { char* user_actions[] = {"pass ", "enable ", "sysinfo "}; -char* tb_options[] = {"comment ", "watermark ", "max_delay ", "ttl ", "rollup(", "sma("}; +char* tb_options[] = {"tags(", "comment ", "watermark ", "max_delay ", "ttl ", "rollup(", "sma("}; char* db_options[] = {"keep ", "replica ", @@ -335,7 +334,7 @@ char* data_types[] = {"timestamp", "int", "bigint", "bigint unsigned", "smallint", "smallint unsigned", "tinyint", "tinyint unsigned", - "geometry", "varbinary(16)", + "geometry(64)", "varbinary(16)", "bool", "json"}; char* key_tags[] = {"tags("}; @@ -1759,36 +1758,24 @@ bool fieldOptionsArea(char* p) { // if is input create fields or tags area, return true bool isCreateFieldsArea(char* p) { - // put to while, support like create table st(ts timestamp, bin1 binary(16), bin2 + blank + TAB - char* p1 = taosStrdup(p); - bool ret = false; - while (1) { - char* left = strrchr(p1, '('); - if (left == NULL) { - // like 'create table st' - ret = false; + int32_t n = 0; // count + char *p1 = p; + while (*p1 != 0) { + switch (*p1) { + case '(': + ++ n; + break; + case ')': + -- n; + break; + default: break; } - - char* right = strrchr(p1, ')'); - if (right == NULL) { - // like 'create table st( ' - ret = true; - break; - } - - if (left > right) { - // like 'create table st( ts timestamp, age int) tags(area ' - ret = true; - break; - } - - // set string end by small for next strrchr search - *left = 0; + // move next + ++p1; } - taosMemoryFree(p1); - return ret; + return n > 0; } bool matchCreateTable(TAOS* con, SShellCmd* cmd) { From fca6e89dc576d4a424f87339f692fa6dc0c57058 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 17:03:01 +0800 Subject: [PATCH 09/22] fix: fill tags is passed --- tools/shell/src/shellAuto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 81021965a2..18b9bb8860 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -289,7 +289,7 @@ char* tb_actions[] = { char* user_actions[] = {"pass ", "enable ", "sysinfo "}; -char* tb_options[] = {"tags(", "comment ", "watermark ", "max_delay ", "ttl ", "rollup(", "sma("}; +char* tb_options[] = {"comment ", "watermark ", "max_delay ", "ttl ", "rollup(", "sma("}; char* db_options[] = {"keep ", "replica ", From dffab4422ff714aad58ce67e05865cbc7799ec7e Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 25 Oct 2024 17:05:33 +0800 Subject: [PATCH 10/22] fix: fill tags is passed1 --- tools/shell/src/shellAuto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 18b9bb8860..f0d61e4a54 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1828,7 +1828,7 @@ bool matchCreateTable(TAOS* con, SShellCmd* cmd) { // find only one ')' , can insert tags char* p1 = strchr(ps, ')'); if (p1) { - if (strchr(p1 + 1, ')') == NULL && strstr(p1 + 1, "tags") == NULL) { + if (strstr(p1 + 1, "tags") == NULL) { // can insert tags keyword ret = fillWithType(con, cmd, last, WT_VAR_KEYTAGS); } From 4df8aeded9024c47df2cfb1bfb6e065fbe19129e Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 11:25:51 +0800 Subject: [PATCH 11/22] fix: repeat double state_window( keyword --- tools/shell/src/shellAuto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index f0d61e4a54..201389f20b 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -232,7 +232,7 @@ char* keywords[] = { "interval(", "order by ", "order by ", "offset ", "or ", "group by ", "now()", "session(", "sliding ", "slimit ", "soffset ", "state_window(", "today() ", "union all select ", "partition by ", "match", "nmatch ", "between ", "like ", "is null ", "is not null ", - "state_window(", "event_window ", "count_window(" + "event_window ", "count_window(" }; char* functions[] = { From 651a652376a28f39a46472b4488b6334624783d8 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 18:04:21 +0800 Subject: [PATCH 12/22] feat: add unit test to shell --- tools/shell/CMakeLists.txt | 50 +++++++++++++ tools/shell/inc/shellAuto.h | 8 +++ tools/shell/src/shellEngine.c | 2 + tools/shell/src/shellMain.c | 3 +- tools/shell/test/shellTest.cpp | 128 +++++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 tools/shell/test/shellTest.cpp diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index fd46870ac5..9fdc0e98f4 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -14,14 +14,17 @@ IF(TD_LINUX AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include -ltaosws) SET(LINK_WEBSOCKET "-L${CMAKE_BINARY_DIR}/build/lib -ltaosws") ADD_DEPENDENCIES(shell taosws-rs) + ADD_DEPENDENCIES(shell_ut taosws-rs) ELSEIF(TD_DARWIN AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/libtaosws.dylib") ADD_DEPENDENCIES(shell taosws-rs) + ADD_DEPENDENCIES(shell_ut taosws-rs) ELSEIF(TD_WINDOWS AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/taosws.lib") ADD_DEPENDENCIES(shell taosws-rs) + ADD_DEPENDENCIES(shell_ut taosws-rs) ELSE() SET(LINK_WEBSOCKET "") ENDIF() @@ -49,3 +52,50 @@ target_include_directories( ) SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) + +# +# generator library shell_ut for uint test +# + +# include +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellMain.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellAuto.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellTire.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellArguments.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellCommand.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellEngine.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellUtil.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellNettest.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellWebsocket.c) + + + +# shell_ut library +add_library(shell_ut STATIC ${SHELL_UT_SRC}) + +# link public +if(TD_WINDOWS) + target_link_libraries(shell_ut PUBLIC taos_static ${LINK_WEBSOCKET}) +else() + target_link_libraries(shell_ut PUBLIC taos ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) +endif() + +# link private +target_link_libraries( + shell_ut + PRIVATE os common transport geometry util +) + +# util depends +target_link_directories( + shell_ut + PUBLIC "${TD_SOURCE_DIR}/contrib/lzma2" + PUBLIC "${TD_SOURCE_DIR}/contrib/pcre2" +) + +# unit test +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/tools/shell/inc/shellAuto.h b/tools/shell/inc/shellAuto.h index bcf500fefc..7fe249251b 100644 --- a/tools/shell/inc/shellAuto.h +++ b/tools/shell/inc/shellAuto.h @@ -47,4 +47,12 @@ void showAD(bool end); // show all commands help void showHelp(); + +// +// for unit test +// +bool fieldOptionsArea(char* p); +bool isCreateFieldsArea(char* p); + + #endif diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 2a583f948e..50a7fe8119 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -22,6 +22,8 @@ #include "shellAuto.h" #include "shellInt.h" +SShellObj shell = {0}; + typedef struct { const char *sql; bool vertical; diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index 71acf23e41..fc6ba0f7d8 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -17,8 +17,7 @@ #include "shellInt.h" #include "shellAuto.h" -SShellObj shell = {0}; - +extern SShellObj shell; void shellCrashHandler(int signum, void *sigInfo, void *context) { taosIgnSignal(SIGTERM); diff --git a/tools/shell/test/shellTest.cpp b/tools/shell/test/shellTest.cpp new file mode 100644 index 0000000000..1f3f1b1b2a --- /dev/null +++ b/tools/shell/test/shellTest.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "shellAuto.h" + + +TEST(fieldOptionsArea, autoTabTest) { + printf("hellow world SHELL tab test\n"); + + // str false + const char *s0 [] = { + "create table st(ts ", + "create table st(ts timestamp, age ", + "create table st(ts timestamp, age", + "create table st(ts timestamp, age int , name ", + "create table st(ts timestamp, age int , name binary(16)", + "create table st(ts timestamp, age int , name binary(16) ) tags( ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary", + "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32)", + "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr", + "create table st (ts timestamp , age int, name binary(16) , area int,", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' , no i", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high', no in", + }; + + // str true + const char *s1 [] = { + "create table st(ts timestamp ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) , addr varbinary( 32 ) ", + "create table st(ts timestamp, age int , name binary(16) ,area int, addr varbinary(32) ", + "create table st(ts timestamp, age int , name binary(16), area int,addr varbinary(32) ", + "create table st(ts timestamp, age int, name binary(16) , area int,addr varbinary(32) ", + "create table st( ts timestamp, age int, name binary(16) ,area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16), area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) compress 'zlib' ", + "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) level 'high' ", + "create table st (ts timestamp , age int, name binary(16) , area int , addr varbinary(32) encode 'simple8b' level 'high' ", + }; + + // s0 is false + for(int32_t i = 0; i < sizeof(s0)/sizeof(char*) ; i++) { + printf("s0 i=%d fieldOptionsArea %s expect false \n", i, s0[i]); + ASSERT (fieldOptionsArea((char *)s0[i]) == false); + } + + // s1 is true + for(int32_t i = 0; i < sizeof(s1)/sizeof(char*) ; i++) { + printf("s1 i=%d fieldOptionsArea %s expect true \n", i, s1[i]); + ASSERT (fieldOptionsArea((char *)s1[i]) == true); + } +} + +TEST(isCreateFieldsArea, autoTabTest) { + printf("hellow world SHELL tab test\n"); + + // str false + const char *s0 [] = { + "create table st(ts )", + "create table st(ts timestamp, age) ", + "create table st(ts timestamp, age)", + "create table st(ts timestamp, age int , name binary(16) )", + "create table st(ts timestamp, age int , name binary(16))", + "create table st(ts timestamp, age int , name binary(16) ) tags( )", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr )", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary)", + "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32))", + "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr int)", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int,addr varbinary(32) )", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary(14))", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' )", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ) ", + }; + + // str true + const char *s1 [] = { + "create table st(ts timestamp ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int ,", + "create table st(ts timestamp, age int , name binary(16), ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr varbinary(32) ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary(32)", + "create table st(ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", + "create table st( ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int, addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) compress 'zlib' ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ", + }; + + // s0 is false + for(int32_t i = 0; i < sizeof(s0)/sizeof(char*) ; i++) { + printf("s0 i=%d isCreateFieldsArea %s expect false. \n", i, s0[i]); + ASSERT (isCreateFieldsArea((char *)s0[i]) == false); + } + + // s1 is true + for(int32_t i = 0; i < sizeof(s1)/sizeof(char*) ; i++) { + printf("s1 i=%d isCreateFieldsArea %s expect true. \n", i, s1[i]); + ASSERT (isCreateFieldsArea((char *)s1[i]) == true); + } +} + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file From efa6db21502f7162aea6143f8d4b408e146f41aa Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 18:12:33 +0800 Subject: [PATCH 13/22] fix: websocket build --- tools/shell/CMakeLists.txt | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 9fdc0e98f4..3c9ae1d962 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -2,6 +2,22 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) +# include +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellMain.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellAuto.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellTire.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellArguments.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellCommand.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellEngine.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellUtil.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellNettest.c) +LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellWebsocket.c) + +# shell_ut library +add_library(shell_ut STATIC ${SHELL_UT_SRC}) + IF(TD_LINUX_64 AND JEMALLOC_ENABLED) ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") @@ -57,24 +73,6 @@ SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) # generator library shell_ut for uint test # -# include -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) - -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellMain.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellAuto.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellTire.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellArguments.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellCommand.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellEngine.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellUtil.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellNettest.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellWebsocket.c) - - - -# shell_ut library -add_library(shell_ut STATIC ${SHELL_UT_SRC}) - # link public if(TD_WINDOWS) target_link_libraries(shell_ut PUBLIC taos_static ${LINK_WEBSOCKET}) From 3ce942f5fbc23fec76900ea10eacbd5a0cffcc4c Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 18:30:36 +0800 Subject: [PATCH 14/22] fix: PR error --- tools/shell/CMakeLists.txt | 61 +++++++++++++------------------------- 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 3c9ae1d962..317fb69c62 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -2,21 +2,6 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) -# include -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) - -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellMain.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellAuto.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellTire.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellArguments.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellCommand.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellEngine.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellUtil.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellNettest.c) -LIST(APPEND SHELL_UT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/shellWebsocket.c) - -# shell_ut library -add_library(shell_ut STATIC ${SHELL_UT_SRC}) IF(TD_LINUX_64 AND JEMALLOC_ENABLED) ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) @@ -30,17 +15,13 @@ IF(TD_LINUX AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include -ltaosws) SET(LINK_WEBSOCKET "-L${CMAKE_BINARY_DIR}/build/lib -ltaosws") ADD_DEPENDENCIES(shell taosws-rs) - ADD_DEPENDENCIES(shell_ut taosws-rs) ELSEIF(TD_DARWIN AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/libtaosws.dylib") - ADD_DEPENDENCIES(shell taosws-rs) - ADD_DEPENDENCIES(shell_ut taosws-rs) ELSEIF(TD_WINDOWS AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/taosws.lib") ADD_DEPENDENCIES(shell taosws-rs) - ADD_DEPENDENCIES(shell_ut taosws-rs) ELSE() SET(LINK_WEBSOCKET "") ENDIF() @@ -73,27 +54,27 @@ SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) # generator library shell_ut for uint test # -# link public -if(TD_WINDOWS) - target_link_libraries(shell_ut PUBLIC taos_static ${LINK_WEBSOCKET}) -else() +IF(TD_LINUX) + # include + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + # shell_ut library + add_library(shell_ut STATIC ${SHELL_SRC}) + + IF(TD_WEBSOCKET) + ADD_DEPENDENCIES(shell_ut taosws-rs) + ENDIF() target_link_libraries(shell_ut PUBLIC taos ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) -endif() + target_link_libraries(shell_ut PRIVATE os common transport geometry util) -# link private -target_link_libraries( - shell_ut - PRIVATE os common transport geometry util -) + # util depends + target_link_directories( + shell_ut + PUBLIC "${TD_SOURCE_DIR}/contrib/lzma2" + PUBLIC "${TD_SOURCE_DIR}/contrib/pcre2" + ) -# util depends -target_link_directories( - shell_ut - PUBLIC "${TD_SOURCE_DIR}/contrib/lzma2" - PUBLIC "${TD_SOURCE_DIR}/contrib/pcre2" -) - -# unit test -if(${BUILD_TEST}) - ADD_SUBDIRECTORY(test) -endif(${BUILD_TEST}) \ No newline at end of file + # unit test + IF(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) + ENDIF(${BUILD_TEST}) +ENDIF() From 4876bc4fb2ab7a8ff75e9808ba1118c32ba92727 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 18:33:31 +0800 Subject: [PATCH 15/22] fix: restore shell origin code --- tools/shell/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 317fb69c62..4a8e0b9d34 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -2,7 +2,6 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) - IF(TD_LINUX_64 AND JEMALLOC_ENABLED) ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") @@ -18,6 +17,7 @@ IF(TD_LINUX AND TD_WEBSOCKET) ELSEIF(TD_DARWIN AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/libtaosws.dylib") + ADD_DEPENDENCIES(shell taosws-rs) ELSEIF(TD_WINDOWS AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/taosws.lib") From db71fe49ed88342f91e161756b665519f1f11808 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 19:04:58 +0800 Subject: [PATCH 16/22] add shell-test CMakefiles --- tools/shell/test/CMakeLists.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tools/shell/test/CMakeLists.txt diff --git a/tools/shell/test/CMakeLists.txt b/tools/shell/test/CMakeLists.txt new file mode 100644 index 0000000000..31ee70c202 --- /dev/null +++ b/tools/shell/test/CMakeLists.txt @@ -0,0 +1,25 @@ + +MESSAGE(STATUS "build catalog unit test") + +IF(NOT TD_DARWIN) + # GoogleTest requires at least C++11 + SET(CMAKE_CXX_STANDARD 11) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + + ADD_EXECUTABLE(shellTest ${SOURCE_LIST}) + TARGET_LINK_LIBRARIES( + shellTest + PRIVATE shell_ut gtest os common transport geometry util + ) + + target_include_directories( + shell_ui + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + ) + + + add_test( + NAME shellTest + COMMAND shellTest + ) +ENDIF() From 0e2ccadd2fea60af4afdba79f72e0363275943a8 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 19:06:10 +0800 Subject: [PATCH 17/22] add shell-test CMakefiles --- tools/shell/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/test/CMakeLists.txt b/tools/shell/test/CMakeLists.txt index 31ee70c202..6f3b0474bd 100644 --- a/tools/shell/test/CMakeLists.txt +++ b/tools/shell/test/CMakeLists.txt @@ -1,5 +1,5 @@ -MESSAGE(STATUS "build catalog unit test") +MESSAGE(STATUS "build taos-CLI unit test") IF(NOT TD_DARWIN) # GoogleTest requires at least C++11 From 2803d51797ea190610dc405071ce66b562ff2602 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 19:15:51 +0800 Subject: [PATCH 18/22] add shell-test CMakefiles shell-ut --- tools/shell/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/test/CMakeLists.txt b/tools/shell/test/CMakeLists.txt index 6f3b0474bd..1eb6c709ab 100644 --- a/tools/shell/test/CMakeLists.txt +++ b/tools/shell/test/CMakeLists.txt @@ -13,7 +13,7 @@ IF(NOT TD_DARWIN) ) target_include_directories( - shell_ui + shell_ut PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) From 90642f4dc2ddf01a7d51c36bd46c8dd04c1a5d53 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Sun, 27 Oct 2024 19:33:58 +0800 Subject: [PATCH 19/22] fix: add extern C support c++ --- tools/shell/inc/shellAuto.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/shell/inc/shellAuto.h b/tools/shell/inc/shellAuto.h index 7fe249251b..c9d631f4b2 100644 --- a/tools/shell/inc/shellAuto.h +++ b/tools/shell/inc/shellAuto.h @@ -16,6 +16,10 @@ #ifndef __SHELL_AUTO__ #define __SHELL_AUTO__ +#ifdef __cplusplus +extern "C" { +#endif + #include "shellInt.h" #define TAB_KEY 0x09 @@ -54,5 +58,8 @@ void showHelp(); bool fieldOptionsArea(char* p); bool isCreateFieldsArea(char* p); +#ifdef __cplusplus +} +#endif #endif From 036b7ebefa0e4386fefa0e3ed370edb54086a323 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Mon, 28 Oct 2024 16:12:18 +0800 Subject: [PATCH 20/22] fix: replace unsafe str fun and check return value --- tools/shell/src/shellAuto.c | 54 ++++++------ tools/shell/test/shellTest.cpp | 145 +++++++++++++++++---------------- 2 files changed, 105 insertions(+), 94 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 201389f20b..8ad9e9072b 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -700,9 +700,9 @@ SWord* addWord(const char* p, int32_t len, bool pattern) { // check format if (pattern && len > 0) { - if (p[len-1] == ';') { + if (p[len - 1] == ';') { word->type = wordType(p, len - 1); - word->end = true; + word->end = true; } else { word->type = wordType(p, len); } @@ -1311,7 +1311,7 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { // first tab press const char* str = NULL; int strLen = 0; - + SWord* word = MATCH_WORD(match); if (firstMatchIndex == curMatchIndex && lastWordBytes == -1) { // first press tab @@ -1331,14 +1331,18 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { if (word->end && str[strLen - 1] != ';') { // append end ';' - char *p = taosMemoryMalloc(strLen + 8); - strcpy(p, str); - strcat(p, ";"); - shellInsertStr(cmd, (char *)p, strLen + 1); - taosMemoryFree(p); + char* p = taosMemoryCalloc(strLen + 8, 1); + if (p) { + tstrncpy(p, str, strLen); + tstrncpy(p + strLen, ";", 1); + shellInsertStr(cmd, (char*)p, strLen + 1); + taosMemoryFree(p); + } else { + shellInsertStr(cmd, (char*)str, strLen); + } } else { // insert new - shellInsertStr(cmd, (char *)str, strLen); + shellInsertStr(cmd, (char*)str, strLen); } } @@ -1722,27 +1726,27 @@ bool fieldOptionsArea(char* p) { } // find tags - if(strstr(p, " tags") != NULL) { + if (strstr(p, " tags") != NULL) { return false; } - if(p2 == NULL) { + if (p2 == NULL) { // first field area p2 = p1; } // find blank count int32_t cnt = 0; - while(p2) { + while (p2) { p2 = strchr(p2, ' '); if (p2) { // get prev char char prec = *(p2 - 1); if (prec != ',' && prec != '(') { // blank if before comma, not calc count. like st(ts timestamp, age int + BLANK + TAB only two blank - cnt ++; + cnt++; } - + // continue blank is one blank while (p2[1] != 0 && p2[1] == ' ') { // move next if blank again @@ -1758,18 +1762,18 @@ bool fieldOptionsArea(char* p) { // if is input create fields or tags area, return true bool isCreateFieldsArea(char* p) { - int32_t n = 0; // count - char *p1 = p; + int32_t n = 0; // count + char* p1 = p; while (*p1 != 0) { switch (*p1) { - case '(': - ++ n; - break; - case ')': - -- n; - break; - default: - break; + case '(': + ++n; + break; + case ')': + --n; + break; + default: + break; } // move next ++p1; @@ -1813,7 +1817,7 @@ bool matchCreateTable(TAOS* con, SShellCmd* cmd) { char* last = lastWord(ps); // check in create fields or tags input area - if (isCreateFieldsArea(ps)) { + if (isCreateFieldsArea(ps)) { if (fieldOptionsArea(ps)) { // fill field options ret = fillWithType(con, cmd, last, WT_VAR_FIELD_OPTIONS); diff --git a/tools/shell/test/shellTest.cpp b/tools/shell/test/shellTest.cpp index 1f3f1b1b2a..cf0ec503fe 100644 --- a/tools/shell/test/shellTest.cpp +++ b/tools/shell/test/shellTest.cpp @@ -17,56 +17,58 @@ #include #include "shellAuto.h" - TEST(fieldOptionsArea, autoTabTest) { printf("hellow world SHELL tab test\n"); // str false - const char *s0 [] = { - "create table st(ts ", - "create table st(ts timestamp, age ", - "create table st(ts timestamp, age", - "create table st(ts timestamp, age int , name ", - "create table st(ts timestamp, age int , name binary(16)", - "create table st(ts timestamp, age int , name binary(16) ) tags( ", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr ", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary", - "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32)", - "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr", - "create table st (ts timestamp , age int, name binary(16) , area int,", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' , no i", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high', no in", + const char *s0[] = { + "create table st(ts ", + "create table st(ts timestamp, age ", + "create table st(ts timestamp, age", + "create table st(ts timestamp, age int , name ", + "create table st(ts timestamp, age int , name binary(16)", + "create table st(ts timestamp, age int , name binary(16) ) tags( ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary", + "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32)", + "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr", + "create table st (ts timestamp , age int, name binary(16) , area int,", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level " + "'high' , no i", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode " + "'simple8b' level 'high', no in", }; // str true - const char *s1 [] = { - "create table st(ts timestamp ", - "create table st(ts timestamp, age int ", - "create table st(ts timestamp, age int ", - "create table st(ts timestamp, age int , name binary(16) ", - "create table st(ts timestamp, age int , name binary(16) ", - "create table st(ts timestamp, age int , name binary(16) , addr varbinary( 32 ) ", - "create table st(ts timestamp, age int , name binary(16) ,area int, addr varbinary(32) ", - "create table st(ts timestamp, age int , name binary(16), area int,addr varbinary(32) ", - "create table st(ts timestamp, age int, name binary(16) , area int,addr varbinary(32) ", - "create table st( ts timestamp, age int, name binary(16) ,area int,addr varbinary(32) ", - "create table st (ts timestamp , age int, name binary(16), area int,addr varbinary(32) ", - "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) compress 'zlib' ", - "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) level 'high' ", - "create table st (ts timestamp , age int, name binary(16) , area int , addr varbinary(32) encode 'simple8b' level 'high' ", + const char *s1[] = { + "create table st(ts timestamp ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) , addr varbinary( 32 ) ", + "create table st(ts timestamp, age int , name binary(16) ,area int, addr varbinary(32) ", + "create table st(ts timestamp, age int , name binary(16), area int,addr varbinary(32) ", + "create table st(ts timestamp, age int, name binary(16) , area int,addr varbinary(32) ", + "create table st( ts timestamp, age int, name binary(16) ,area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16), area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) compress 'zlib' ", + "create table st (ts timestamp , age int, name binary(16), area int , addr varbinary(32) level 'high' ", + "create table st (ts timestamp , age int, name binary(16) , area int , addr varbinary(32) encode 'simple8b' " + "level 'high' ", }; // s0 is false - for(int32_t i = 0; i < sizeof(s0)/sizeof(char*) ; i++) { + for (int32_t i = 0; i < sizeof(s0) / sizeof(char *); i++) { printf("s0 i=%d fieldOptionsArea %s expect false \n", i, s0[i]); - ASSERT (fieldOptionsArea((char *)s0[i]) == false); + ASSERT(fieldOptionsArea((char *)s0[i]) == false); } // s1 is true - for(int32_t i = 0; i < sizeof(s1)/sizeof(char*) ; i++) { + for (int32_t i = 0; i < sizeof(s1) / sizeof(char *); i++) { printf("s1 i=%d fieldOptionsArea %s expect true \n", i, s1[i]); - ASSERT (fieldOptionsArea((char *)s1[i]) == true); + ASSERT(fieldOptionsArea((char *)s1[i]) == true); } } @@ -74,51 +76,56 @@ TEST(isCreateFieldsArea, autoTabTest) { printf("hellow world SHELL tab test\n"); // str false - const char *s0 [] = { - "create table st(ts )", - "create table st(ts timestamp, age) ", - "create table st(ts timestamp, age)", - "create table st(ts timestamp, age int , name binary(16) )", - "create table st(ts timestamp, age int , name binary(16))", - "create table st(ts timestamp, age int , name binary(16) ) tags( )", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr )", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary)", - "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32))", - "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr int)", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int,addr varbinary(32) )", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary(14))", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' )", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ) ", + const char *s0[] = { + "create table st(ts )", + "create table st(ts timestamp, age) ", + "create table st(ts timestamp, age)", + "create table st(ts timestamp, age int , name binary(16) )", + "create table st(ts timestamp, age int , name binary(16))", + "create table st(ts timestamp, age int , name binary(16) ) tags( )", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr )", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary)", + "create table st(ts timestamp, age int, name binary(16)) tags(area int , addr varbinary(32))", + "create table st( ts timestamp, age int, name binary(16)) tags( area int, addr int)", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int,addr varbinary(32) )", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int ,addr varbinary(14))", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level " + "'high' )", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode " + "'simple8b' level 'high' ) ", }; // str true - const char *s1 [] = { - "create table st(ts timestamp ", - "create table st(ts timestamp, age int ", - "create table st(ts timestamp, age int ,", - "create table st(ts timestamp, age int , name binary(16), ", - "create table st(ts timestamp, age int , name binary(16) ", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int ", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr varbinary(32) ", - "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary(32)", - "create table st(ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", - "create table st( ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int, addr varbinary(32) ", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) compress 'zlib' ", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level 'high' ", - "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode 'simple8b' level 'high' ", + const char *s1[] = { + "create table st(ts timestamp ", + "create table st(ts timestamp, age int ", + "create table st(ts timestamp, age int ,", + "create table st(ts timestamp, age int , name binary(16), ", + "create table st(ts timestamp, age int , name binary(16) ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int, addr varbinary(32) ", + "create table st(ts timestamp, age int , name binary(16) ) tags( area int,addr varbinary(32)", + "create table st(ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", + "create table st( ts timestamp, age int, name binary(16)) tags(area int,addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int, addr varbinary(32) ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) compress " + "'zlib' ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) level " + "'high' ", + "create table st (ts timestamp , age int, name binary(16) ) tags ( area int , addr varbinary(32) encode " + "'simple8b' level 'high' ", }; // s0 is false - for(int32_t i = 0; i < sizeof(s0)/sizeof(char*) ; i++) { + for (int32_t i = 0; i < sizeof(s0) / sizeof(char *); i++) { printf("s0 i=%d isCreateFieldsArea %s expect false. \n", i, s0[i]); - ASSERT (isCreateFieldsArea((char *)s0[i]) == false); + ASSERT(isCreateFieldsArea((char *)s0[i]) == false); } // s1 is true - for(int32_t i = 0; i < sizeof(s1)/sizeof(char*) ; i++) { + for (int32_t i = 0; i < sizeof(s1) / sizeof(char *); i++) { printf("s1 i=%d isCreateFieldsArea %s expect true. \n", i, s1[i]); - ASSERT (isCreateFieldsArea((char *)s1[i]) == true); + ASSERT(isCreateFieldsArea((char *)s1[i]) == true); } } From 6b6c9c884e4856f33099e33898252cf4ef3f2c1d Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Mon, 28 Oct 2024 16:21:15 +0800 Subject: [PATCH 21/22] fix: tstrncpy len must add 1 --- tools/shell/src/shellAuto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 8ad9e9072b..a3093237cb 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1333,8 +1333,8 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { // append end ';' char* p = taosMemoryCalloc(strLen + 8, 1); if (p) { - tstrncpy(p, str, strLen); - tstrncpy(p + strLen, ";", 1); + tstrncpy(p, str, strLen + 1); + tstrncpy(p + strLen, ";", 1 + 1); shellInsertStr(cmd, (char*)p, strLen + 1); taosMemoryFree(p); } else { From 462dc3362f2c88fe5428ceb43f700dc65d905024 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Mon, 28 Oct 2024 16:27:52 +0800 Subject: [PATCH 22/22] fix: lastWordBytes need add 1 --- tools/shell/src/shellAuto.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index a3093237cb..959e2d6d62 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -1335,6 +1335,7 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { if (p) { tstrncpy(p, str, strLen + 1); tstrncpy(p + strLen, ";", 1 + 1); + lastWordBytes += 1; shellInsertStr(cmd, (char*)p, strLen + 1); taosMemoryFree(p); } else {