From b6d80466b74960495013b87cc2a442d073fee23b Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Fri, 5 Mar 2021 18:51:14 +0800 Subject: [PATCH 1/6] inc code coverage --- tests/pytest/functions/function_operations.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py index e703147b67..4bcb9a58a3 100644 --- a/tests/pytest/functions/function_operations.py +++ b/tests/pytest/functions/function_operations.py @@ -95,11 +95,12 @@ class TDTestCase: for i in col_list : for j in col_list : for k in op_list : - sql = " select %s %s %s from test1 " % ( i , k , j ) - if i in err_list or j in err_list: - tdSql.error(sql) - else: - tdSql.query(sql) + for l in [' order by ts' , ' order by ts desc' ]: + sql = " select %s %s %s from test1 %s" % ( i , k , j , l ) + if i in err_list or j in err_list: + tdSql.error(sql) + else: + tdSql.query(sql) def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From 8fb6934a8fe1d0d7294f57b73afb4143fdb632f1 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 8 Mar 2021 11:24:46 +0800 Subject: [PATCH 2/6] [TD-3181]add testcase for TD-3170 --- tests/pytest/query/queryGroupbySort.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/pytest/query/queryGroupbySort.py b/tests/pytest/query/queryGroupbySort.py index c2649a86db..063db93608 100644 --- a/tests/pytest/query/queryGroupbySort.py +++ b/tests/pytest/query/queryGroupbySort.py @@ -28,12 +28,13 @@ class TDTestCase: def run(self): tdSql.prepare() - tdSql.execute("CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int)") - tdSql.execute("CREATE TABLE D1001 USING meters TAGS ('Beijing.Chaoyang', 2)") - tdSql.execute("CREATE TABLE D1002 USING meters TAGS ('Beijing.Chaoyang', 3)") + tdSql.execute("CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int, t3 float, t4 double)") + tdSql.execute("CREATE TABLE D1001 USING meters TAGS ('Beijing.Chaoyang', 2 , NULL, NULL)") + tdSql.execute("CREATE TABLE D1002 USING meters TAGS ('Beijing.Chaoyang', 3 , NULL , 1.7)") + tdSql.execute("CREATE TABLE D1003 USING meters TAGS ('Beijing.Chaoyang', 3 , 1.1 , 1.7)") tdSql.execute("INSERT INTO D1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) (1538548696800, 12.3, 221, 0.31)") tdSql.execute("INSERT INTO D1002 VALUES (1538548685001, 10.5, 220, 0.28) (1538548696800, 12.3, 221, 0.31)") - + tdSql.execute("INSERT INTO D1003 VALUES (1538548685001, 10.5, 220, 0.28) (1538548696800, 12.3, 221, 0.31)") tdSql.query("SELECT SUM(current), AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by ts DESC") tdSql.checkRows(3) tdSql.checkData(0, 0, "2018-10-03 14:38:16") @@ -49,6 +50,12 @@ class TDTestCase: tdSql.error("SELECT SUM(current) as s, AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by s ASC") tdSql.error("SELECT SUM(current) as s, AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by s DESC") + + #add for TD-3170 + tdSql.query("select avg(current) from meters group by t3;") + tdSql.checkData(0, 0, 11.6) + tdSql.query("select avg(current) from meters group by t4;") + tdSql.query("select avg(current) from meters group by t3,t4;") def stop(self): tdSql.close() From f2e8fcb820dbca2621aea3519ff124e95001bd4c Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 8 Mar 2021 11:47:32 +0800 Subject: [PATCH 3/6] revert --- tests/pytest/functions/function_operations.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py index 4bcb9a58a3..8b385844de 100644 --- a/tests/pytest/functions/function_operations.py +++ b/tests/pytest/functions/function_operations.py @@ -95,8 +95,7 @@ class TDTestCase: for i in col_list : for j in col_list : for k in op_list : - for l in [' order by ts' , ' order by ts desc' ]: - sql = " select %s %s %s from test1 %s" % ( i , k , j , l ) + sql = " select %s %s %s from test1" % ( i , k , j ) if i in err_list or j in err_list: tdSql.error(sql) else: From 0e1545866ddae538654963aa0279666b8052793a Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 8 Mar 2021 11:49:46 +0800 Subject: [PATCH 4/6] change format --- tests/pytest/functions/function_operations.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py index 8b385844de..e703147b67 100644 --- a/tests/pytest/functions/function_operations.py +++ b/tests/pytest/functions/function_operations.py @@ -95,11 +95,11 @@ class TDTestCase: for i in col_list : for j in col_list : for k in op_list : - sql = " select %s %s %s from test1" % ( i , k , j ) - if i in err_list or j in err_list: - tdSql.error(sql) - else: - tdSql.query(sql) + sql = " select %s %s %s from test1 " % ( i , k , j ) + if i in err_list or j in err_list: + tdSql.error(sql) + else: + tdSql.query(sql) def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From 7bcca63ea6b8cb61e192873a23bca22756dad226 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Mar 2021 12:02:26 +0800 Subject: [PATCH 5/6] [TD-3197] : fix taosdump and taosdemo coverity scan issue. --- src/kit/taosdemo/taosdemo.c | 35 ++++++++++++++++++++--------------- src/kit/taosdump/taosdump.c | 2 ++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 0353fcabd3..4a9038c71e 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -56,6 +56,7 @@ #include "cJSON.h" #include "taos.h" +#include "taoserror.h" #include "tutil.h" #define REQ_EXTRA_BUF_LEN 1024 @@ -838,7 +839,8 @@ static void getResult(TAOS_RES *res, char* resultFileName) { char* databuf = (char*) calloc(1, 100*1024*1024); if (databuf == NULL) { fprintf(stderr, "failed to malloc, warning: save result to file slowly!\n"); - fclose(fp); + if (fp) + fclose(fp); return ; } @@ -1669,6 +1671,7 @@ int postProceSql(char* host, uint16_t port, char* sqlstr) ERROR_EXIT("ERROR storing complete response from socket"); } + response_buf[RESP_BUF_LEN - 1] = '\0'; printf("Response:\n%s\n", response_buf); free(request_buf); @@ -2290,6 +2293,8 @@ int startMultiThreadCreateChildTable( g_Dbs.port); if (t_info->taos == NULL) { fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); + free(pids); + free(infos); return -1; } t_info->start_table_id = last; @@ -2342,8 +2347,8 @@ static void createChildTables() { } else { // normal table len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); - for (int i = 0; i < MAX_COLUMN_COUNT; i++) { - if (g_args.datatype[i]) { + int i = 0; + while (g_args.datatype[i]) { if ((strncasecmp(g_args.datatype[i], "BINARY", strlen("BINARY")) == 0) || (strncasecmp(g_args.datatype[i], "NCHAR", strlen("NCHAR")) == 0)) { len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", i, g_args.datatype[i]); @@ -2351,15 +2356,13 @@ static void createChildTables() { len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", i, g_args.datatype[i]); } len = strlen(tblColsBuf); - } else { - len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ")"); - break; } - } + + len = snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); debugPrint("DEBUG - %s() LN%d: %s\n", __func__, __LINE__, tblColsBuf); - startMultiThreadCreateChildTable( + startMultiThreadCreateChildTable( tblColsBuf, g_Dbs.threadCountByCreateTbl, g_args.num_of_DPT, @@ -4073,11 +4076,10 @@ static void* syncWrite(void *sarg) { int len_of_binary = g_args.len_of_binary; int ncols_per_record = 1; // count first col ts - for (int i = 0; i < MAX_COLUMN_COUNT; i ++) { - if (NULL == g_args.datatype[i]) - break; - else - ncols_per_record ++; + int i = 0; + while(g_args.datatype[i]) { + i ++; + ncols_per_record ++; } srand((uint32_t)time(NULL)); @@ -4558,11 +4560,14 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { start_time = taosGetTimestamp(timePrec); } else { - taosParseTime( + if (TSDB_CODE_SUCCESS != taosParseTime( superTblInfo->startTimestamp, &start_time, strlen(superTblInfo->startTimestamp), - timePrec, 0); + timePrec, 0)) { + printf("ERROR to parse time!\n"); + exit(-1); + } } } else { start_time = 1500000000000; diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index e2105ad18b..3cee5f1b1d 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -769,6 +769,7 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu } sprintf(tmpBuf, ".select-tbname.tmp"); (void)remove(tmpBuf); + free(tblBuf); close(fd); return -1; } @@ -1523,6 +1524,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao } sprintf(tmpBuf, ".show-tables.tmp"); (void)remove(tmpBuf); + free(tblBuf); close(fd); return -1; } From 4a0648306e0a6b53e0f077438cdb5cebeac9a42c Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 8 Mar 2021 18:12:20 +0800 Subject: [PATCH 6/6] [TD-3202] : fix incorrect number of table issue. --- src/kit/taosdemo/taosdemo.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 4a9038c71e..67397d1826 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -998,7 +998,7 @@ static int printfInsertMeta() { printf("database count: \033[33m%d\033[0m\n", g_Dbs.dbCount); for (int i = 0; i < g_Dbs.dbCount; i++) { printf("database[\033[33m%d\033[0m]:\n", i); - printf(" database name: \033[33m%s\033[0m\n", g_Dbs.db[i].dbName); + printf(" database[%d] name: \033[33m%s\033[0m\n", i, g_Dbs.db[i].dbName); if (0 == g_Dbs.db[i].drop) { printf(" drop: \033[33mno\033[0m\n"); }else { @@ -1147,7 +1147,7 @@ static void printfInsertMetaToFile(FILE* fp) { fprintf(fp, "database count: %d\n", g_Dbs.dbCount); for (int i = 0; i < g_Dbs.dbCount; i++) { fprintf(fp, "database[%d]:\n", i); - fprintf(fp, " database name: %s\n", g_Dbs.db[i].dbName); + fprintf(fp, " database[%d] name: %s\n", i, g_Dbs.db[i].dbName); if (0 == g_Dbs.db[i].drop) { fprintf(fp, " drop: no\n"); }else { @@ -2140,7 +2140,7 @@ static int createDatabases() { } printf("\ncreate database %s success!\n\n", g_Dbs.db[i].dbName); - debugPrint("DEBUG %s() %d count:%d\n", __func__, __LINE__, g_Dbs.db[i].superTblCount); + debugPrint("DEBUG %s() %d supertbl count:%d\n", __func__, __LINE__, g_Dbs.db[i].superTblCount); for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { // describe super table, if exists sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, g_Dbs.db[i].superTbls[j].sTblName); @@ -2285,6 +2285,7 @@ int startMultiThreadCreateChildTable( t_info->threadID = i; tstrncpy(t_info->db_name, db_name, MAX_DB_NAME_SIZE); t_info->superTblInfo = superTblInfo; + debugPrint("DEBUG %s() %d db_name: %s\n", __func__, __LINE__, db_name); t_info->taos = taos_connect( g_Dbs.host, g_Dbs.user, @@ -2347,25 +2348,26 @@ static void createChildTables() { } else { // normal table len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); - int i = 0; - while (g_args.datatype[i]) { - if ((strncasecmp(g_args.datatype[i], "BINARY", strlen("BINARY")) == 0) - || (strncasecmp(g_args.datatype[i], "NCHAR", strlen("NCHAR")) == 0)) { - len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", i, g_args.datatype[i]); + int j = 0; + while (g_args.datatype[j]) { + if ((strncasecmp(g_args.datatype[j], "BINARY", strlen("BINARY")) == 0) + || (strncasecmp(g_args.datatype[j], "NCHAR", strlen("NCHAR")) == 0)) { + len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", j, g_args.datatype[j]); } else { - len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", i, g_args.datatype[i]); + len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", j, g_args.datatype[j]); } len = strlen(tblColsBuf); + j++; } len = snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")"); - debugPrint("DEBUG - %s() LN%d: %s\n", __func__, __LINE__, - tblColsBuf); + debugPrint("DEBUG - %s() LN%d: dbName: %s num of tb: %d schema: %s\n", __func__, __LINE__, + g_Dbs.db[i].dbName, g_args.num_of_tables, tblColsBuf); startMultiThreadCreateChildTable( tblColsBuf, g_Dbs.threadCountByCreateTbl, - g_args.num_of_DPT, + g_args.num_of_tables, g_Dbs.db[i].dbName, NULL); }