Merge branch '3.0' into fix/TD-31320-3.0a

This commit is contained in:
kailixu 2024-08-14 09:06:56 +08:00
commit b47c127c56
8 changed files with 267 additions and 177 deletions

View File

@ -35,6 +35,13 @@ TARGET_INCLUDE_DIRECTORIES(
PRIVATE "${TD_SOURCE_DIR}/source/client/inc" PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
) )
IF(${TD_LINUX})
add_test(
NAME clientTest
COMMAND clientTest
)
ENDIF ()
TARGET_INCLUDE_DIRECTORIES( TARGET_INCLUDE_DIRECTORIES(
tmqTest tmqTest
PUBLIC "${TD_SOURCE_DIR}/include/client/" PUBLIC "${TD_SOURCE_DIR}/include/client/"

View File

@ -16,6 +16,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
#include "clientInt.h" #include "clientInt.h"
#include "osSemaphore.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "thash.h" #include "thash.h"
@ -126,6 +127,9 @@ void queryCallback(void* param, void* res, int32_t code) {
} }
(void)printf("start to fetch data\n"); (void)printf("start to fetch data\n");
taos_fetch_raw_block_a(res, fetchCallback, param); taos_fetch_raw_block_a(res, fetchCallback, param);
taos_free_result(res);
tsem_t *sem = (tsem_t *)param;
tsem_post(sem);
} }
void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t startTs, const char* pVarchar) { void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t startTs, const char* pVarchar) {
@ -189,7 +193,7 @@ void* queryThread(void* arg) {
int64_t el = 0; int64_t el = 0;
for (int32_t i = 0; i < 5000000; ++i) { for (int32_t i = 0; i < 5; ++i) {
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
TAOS_RES* pRes = taos_query(pConn, TAOS_RES* pRes = taos_query(pConn,
"SELECT _wstart as ts,max(usage_user) FROM benchmarkcpu.host_49 WHERE ts >= " "SELECT _wstart as ts,max(usage_user) FROM benchmarkcpu.host_49 WHERE ts >= "
@ -320,6 +324,13 @@ TEST(clientCase, connect_Test) {
if (pConn == NULL) { if (pConn == NULL) {
(void)printf("failed to connect to server, reason:%s\n", taos_errstr(NULL)); (void)printf("failed to connect to server, reason:%s\n", taos_errstr(NULL));
} }
TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
if (taos_errno(pRes) != 0) {
(void)printf("error in drop db, reason:%s\n", taos_errstr(pRes));
}
taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
@ -412,7 +423,7 @@ TEST(clientCase, show_db_Test) {
int32_t code = taos_print_row(str, pRow, pFields, numOfFields); int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
(void)printf("%s\n", str); (void)printf("%s\n", str);
} }
taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
@ -437,6 +448,7 @@ TEST(clientCase, create_db_Test) {
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
(void)printf("error in create db, reason:%s\n", taos_errstr(pRes)); (void)printf("error in create db, reason:%s\n", taos_errstr(pRes));
} }
taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
@ -473,6 +485,7 @@ TEST(clientCase, drop_dnode_Test) {
int32_t numOfFields = taos_num_fields(pRes); int32_t numOfFields = taos_num_fields(pRes);
ASSERT_EQ(numOfFields, 0); ASSERT_EQ(numOfFields, 0);
taos_free_result(pRes);
pRes = taos_query(pConn, "drop dnode 4"); pRes = taos_query(pConn, "drop dnode 4");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
@ -498,31 +511,10 @@ TEST(clientCase, use_db_test) {
int32_t numOfFields = taos_num_fields(pRes); int32_t numOfFields = taos_num_fields(pRes);
ASSERT_EQ(numOfFields, 0); ASSERT_EQ(numOfFields, 0);
taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
// TEST(clientCase, drop_db_test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// showDB(pConn);
//
// TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// showDB(pConn);
//
// pRes = taos_query(pConn, "create database abc1");
// if (taos_errno(pRes) != 0) {
// (void)printf("create to drop db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
// taos_close(pConn);
//}
TEST(clientCase, create_stable_Test) { TEST(clientCase, create_stable_Test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
assert(pConn != NULL); assert(pConn != NULL);
@ -534,6 +526,7 @@ TEST(clientCase, create_stable_Test) {
taos_free_result(pRes); taos_free_result(pRes);
pRes = taos_query(pConn, "use abc1"); pRes = taos_query(pConn, "use abc1");
taos_free_result(pRes);
pRes = taos_query(pConn, "create table if not exists abc1.st1(ts timestamp, k int) tags(a int)"); pRes = taos_query(pConn, "create table if not exists abc1.st1(ts timestamp, k int) tags(a int)");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
@ -547,18 +540,6 @@ TEST(clientCase, create_stable_Test) {
ASSERT_EQ(numOfFields, 0); ASSERT_EQ(numOfFields, 0);
taos_free_result(pRes); taos_free_result(pRes);
// pRes = taos_query(pConn, "create stable if not exists abc1.`123_$^)` (ts timestamp, `abc` int) tags(a int)");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes));
// }
//
// pRes = taos_query(pConn, "use abc1");
// taos_free_result(pRes);
// pRes = taos_query(pConn, "drop stable `123_$^)`");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to drop super table 123_$^), reason:%s\n", taos_errstr(pRes));
// }
taos_close(pConn); taos_close(pConn);
} }
@ -743,7 +724,8 @@ TEST(clientCase, show_table_Test) {
} }
taos_free_result(pRes); taos_free_result(pRes);
(void)taos_query(pConn, "use abc1"); pRes = taos_query(pConn, "use abc1");
taos_free_result(pRes);
pRes = taos_query(pConn, "show tables"); pRes = taos_query(pConn, "show tables");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
@ -760,38 +742,15 @@ TEST(clientCase, show_table_Test) {
while ((pRow = taos_fetch_row(pRes)) != NULL) { while ((pRow = taos_fetch_row(pRes)) != NULL) {
int32_t code = taos_print_row(str, pRow, pFields, numOfFields); int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
if(code > 0) {
(void)printf("%d: %s\n", ++count, str); (void)printf("%d: %s\n", ++count, str);
} }
}
taos_free_result(pRes); taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
// TEST(clientCase, drop_stable_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != nullptr);
//
// TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1");
// if (taos_errno(pRes) != 0) {
// (void)printf("error in creating db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "use abc1");
// if (taos_errno(pRes) != 0) {
// (void)printf("error in using db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "drop stable st1");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
// }
TEST(clientCase, generated_request_id_test) { TEST(clientCase, generated_request_id_test) {
SHashObj* phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); SHashObj* phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
@ -832,11 +791,6 @@ TEST(clientCase, projection_query_tables) {
TAOS_RES* pRes = NULL; TAOS_RES* pRes = NULL;
// TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1");
// if (taos_errno(pRes) != 0) {
// (void)printf("error in create db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
pRes= taos_query(pConn, "use abc1"); pRes= taos_query(pConn, "use abc1");
taos_free_result(pRes); taos_free_result(pRes);
@ -846,6 +800,12 @@ TEST(clientCase, projection_query_tables) {
} }
taos_free_result(pRes); taos_free_result(pRes);
pRes = taos_query(pConn, "create table st2 (ts timestamp, v1 int) tags(t1 int)");
if (taos_errno(pRes) != 0) {
(void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
}
taos_free_result(pRes);
int64_t start = 1685959190000; int64_t start = 1685959190000;
const char* pstr = const char* pstr =
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh" "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh"
@ -861,7 +821,7 @@ TEST(clientCase, projection_query_tables) {
TAOS_RES* px = taos_query(pConn, str); TAOS_RES* px = taos_query(pConn, str);
if (taos_errno(px) != 0) { if (taos_errno(px) != 0) {
(void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); (void)printf("failed to create table tu, reason:%s\n", taos_errstr(px));
} }
taos_free_result(px); taos_free_result(px);
} }
@ -869,7 +829,7 @@ TEST(clientCase, projection_query_tables) {
for(int32_t j = 0; j < 1; ++j) { for(int32_t j = 0; j < 1; ++j) {
start += 20; start += 20;
for (int32_t i = 0; i < 1; ++i) { for (int32_t i = 0; i < 1; ++i) {
createNewTable(pConn, i, 100000, 0, pstr); createNewTable(pConn, i, 10000, 0, pstr);
} }
} }
@ -886,8 +846,8 @@ TEST(clientCase, projection_query_tables) {
char str[512] = {0}; char str[512] = {0};
while ((pRow = taos_fetch_row(pRes)) != NULL) { while ((pRow = taos_fetch_row(pRes)) != NULL) {
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); // int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// (void)printf("%s\n", str); // (void)printf("%s\n", str);
} }
taos_free_result(pRes); taos_free_result(pRes);
@ -900,7 +860,9 @@ TEST(clientCase, tsbs_perf_test) {
for (int32_t i = 0; i < numOfThreads; ++i) { for (int32_t i = 0; i < numOfThreads; ++i) {
(void)taosThreadCreate(&qid[i], NULL, queryThread, NULL); (void)taosThreadCreate(&qid[i], NULL, queryThread, NULL);
} }
getchar(); for (int32_t i = 0; i < numOfThreads; ++i) {
(void)taosThreadJoin(qid[i], NULL);
}
} }
TEST(clientCase, projection_query_stables) { TEST(clientCase, projection_query_stables) {
@ -908,14 +870,6 @@ TEST(clientCase, projection_query_stables) {
ASSERT_NE(pConn, nullptr); ASSERT_NE(pConn, nullptr);
TAOS_RES* pRes = taos_query(pConn, "explain select * from dbvg.st where tbname='ct1'"); TAOS_RES* pRes = taos_query(pConn, "explain select * from dbvg.st where tbname='ct1'");
// taos_free_result(pRes);
// pRes = taos_query(pConn, "select * from st2");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
// taos_free_result(pRes);
// ASSERT_TRUE(false);
// }
TAOS_ROW pRow = NULL; TAOS_ROW pRow = NULL;
TAOS_FIELD* pFields = taos_fetch_fields(pRes); TAOS_FIELD* pFields = taos_fetch_fields(pRes);
@ -939,12 +893,6 @@ TEST(clientCase, projection_query_stables) {
} }
//(void)printf("%d\n", i); //(void)printf("%d\n", i);
} }
// while ((pRow = taos_fetch_row(pRes)) != NULL) {
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// if (i++ % 100000 == 0) {
// (void)printf("%d\n", i);
// }
// }
taos_free_result(pRes); taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
@ -971,55 +919,41 @@ TEST(clientCase, agg_query_tables) {
pRes = taos_query(pConn, s); pRes = taos_query(pConn, s);
int32_t ret = taos_errno(pRes); int32_t ret = taos_errno(pRes);
if (ret != 0) {
(void)printf("failed to insert into table, reason:%s\n", taos_errstr(pRes));
}
taos_free_result(pRes); taos_free_result(pRes);
if (ret == 0) {
break; break;
} }
} }
// while (1) {
// sprintf(s, "insert into t2 values(%ld, %d)", st + i, i);
// pRes = taos_query(pConn, s);
// int32_t ret = taos_errno(pRes);
//
// taos_free_result(pRes);
// if (ret == 0) {
// break;
// }
// }
}
// pRes = taos_query(pConn, "show table distributed tup");
// if (taos_errno(pRes) != 0) {
// (void)printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
// taos_free_result(pRes);
// ASSERT_TRUE(false);
// }
printResult(pRes);
taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
/* // --- copy the following script in the shell to setup the environment ---
--- copy the following script in the shell to setup the environment --- //
// create database test;
// use test;
// create table m1(ts timestamp, k int) tags(a int);
// create table tm0 using m1 tags(1);
// create table tm1 using m1 tags(2);
// insert into tm0 values('2021-1-1 1:1:1.120', 1) ('2021-1-1 1:1:2.9', 2) tm1 values('2021-1-1 1:1:1.120', 11) ('2021-1-1
// 1:1:2.99', 22);
create database test;
use test;
create table m1(ts timestamp, k int) tags(a int);
create table tm0 using m1 tags(1);
create table tm1 using m1 tags(2);
insert into tm0 values('2021-1-1 1:1:1.120', 1) ('2021-1-1 1:1:2.9', 2) tm1 values('2021-1-1 1:1:1.120', 11) ('2021-1-1
1:1:2.99', 22);
*/
TEST(clientCase, async_api_test) { TEST(clientCase, async_api_test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr); ASSERT_NE(pConn, nullptr);
(void)taos_query(pConn, "use abc1"); TAOS_RES* pRes = taos_query(pConn, "use abc1");
if (taos_errno(pRes) != 0) {
(void)printf("failed to use db, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes);
taos_close(pConn);
return;
}
taos_free_result(pRes);
TAOS_RES* pRes = taos_query(pConn, "insert into tu(ts) values('2022-02-27 12:12:61')"); pRes = taos_query(pConn, "insert into tu(ts) values('2022-02-27 12:12:61')");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
(void)printf("failed, reason:%s\n", taos_errstr(pRes)); (void)printf("failed, reason:%s\n", taos_errstr(pRes));
} }
@ -1041,9 +975,12 @@ TEST(clientCase, async_api_test) {
(void)printf("%s\n", str); (void)printf("%s\n", str);
(void)memset(str, 0, sizeof(str)); (void)memset(str, 0, sizeof(str));
} }
taos_free_result(pRes);
taos_query_a(pConn, "select count(*) from tu", queryCallback, pConn); tsem_t sem;
(void)getchar(); (void)tsem_init(&sem, 0, 0);
taos_query_a(pConn, "select count(*) from tu", queryCallback, &sem);
tsem_wait(&sem);
tsem_destroy(&sem);
taos_close(pConn); taos_close(pConn);
} }
@ -1055,6 +992,7 @@ TEST(clientCase, update_test) {
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
(void)printf("failed to create database, code:%s", taos_errstr(pRes)); (void)printf("failed to create database, code:%s", taos_errstr(pRes));
taos_free_result(pRes); taos_free_result(pRes);
taos_close(pConn);
return; return;
} }
@ -1064,6 +1002,7 @@ TEST(clientCase, update_test) {
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
(void)printf("failed to use db, code:%s", taos_errstr(pRes)); (void)printf("failed to use db, code:%s", taos_errstr(pRes));
taos_free_result(pRes); taos_free_result(pRes);
taos_close(pConn);
return; return;
} }
taos_free_result(pRes); taos_free_result(pRes);
@ -1076,11 +1015,12 @@ TEST(clientCase, update_test) {
taos_free_result(pRes); taos_free_result(pRes);
char s[256] = {0}; char s[256] = {0};
for (int32_t i = 0; i < 17000; ++i) { for (int32_t i = 0; i < 10; ++i) {
(void)sprintf(s, "insert into tup values(now+%da, %d)", i, i); (void)sprintf(s, "insert into tup values(now+%da, %d)", i, i);
pRes = taos_query(pConn, s); pRes = taos_query(pConn, s);
taos_free_result(pRes); taos_free_result(pRes);
} }
taos_close(pConn);
} }
TEST(clientCase, sub_db_test) { TEST(clientCase, sub_db_test) {
@ -1158,10 +1098,13 @@ TEST(clientCase, sub_db_test) {
(void)printf("precision: %d, row content: %s\n", precision, buf); (void)printf("precision: %d, row content: %s\n", precision, buf);
} }
taos_free_result(pRes); taos_free_result(pRes);
} else {
break;
} }
} }
(void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows);
taos_close(pConn);
} }
TEST(clientCase, tmq_commit) { TEST(clientCase, tmq_commit) {
@ -1550,38 +1493,125 @@ TEST(clientCase, sub_tb_mt_test) {
} }
} }
//static void concatStrings(SArray *list, char* buf, int size){ TEST(clientCase, timezone_Test) {
// int len = 0; {
// for(int i = 0; i < taosArrayGetSize(list); i++){ // taos_options( TSDB_OPTION_TIMEZONE, "UTC-8");
// char* db = (char*)taosArrayGet(list, i); int code = taos_options(TSDB_OPTION_TIMEZONE, "UTC-8");
// char* dot = strchr(db, '.'); ASSERT_TRUE(code == 0);
// if (dot != NULL) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// db = dot + 1; ASSERT_NE(pConn, nullptr);
// }
// if (i != 0){ TAOS_RES* pRes = taos_query(pConn, "drop database if exists db1");
// strcat(buf, ","); ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
// len += 1; taos_free_result(pRes);
// }
// int ret = snprintf(buf + len, size - len, "%s", db); pRes = taos_query(pConn, "create database db1");
// if (ret < 0) { ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
// (void)printf("snprintf failed, buf:%s, ret:%d", buf, ret); taos_free_result(pRes);
// break;
// } pRes = taos_query(pConn, "create table db1.t1 (ts timestamp, v int)");
// len += ret; ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
// if (len >= size){ taos_free_result(pRes);
// (void)printf("dbList is truncated, buf:%s, len:%d", buf, len);
// break; char sql[256] = {0};
// } (void)sprintf(sql, "insert into db1.t1 values('2023-09-16 17:00:00', 1)");
// } pRes = taos_query(pConn, sql);
//} ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
// taos_free_result(pRes);
//TEST(clientCase, concat_string_test) {
// SArray* list = taosArrayInit(10, TSDB_DB_FNAME_LEN); pRes = taos_query(pConn, "select * from db1.t1 where ts == '2023-09-16 17:00:00'");
// taosArrayPush(list, "1.db1"); ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
// taosArrayPush(list, "2.db2");
// TAOS_ROW pRow = NULL;
// char buf[32] = {0}; TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// concatStrings(list, buf, sizeof(buf) - 1); int32_t numOfFields = taos_num_fields(pRes);
//}
char str[512] = {0};
int rows = 0;
while ((pRow = taos_fetch_row(pRes)) != NULL) {
rows++;
}
ASSERT_TRUE(rows == 1);
taos_free_result(pRes);
taos_close(pConn);
}
{
// taos_options( TSDB_OPTION_TIMEZONE, "UTC+8");
int code = taos_options(TSDB_OPTION_TIMEZONE, "UTC+8");
ASSERT_TRUE(code == 0);
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
TAOS_RES* pRes = taos_query(pConn, "select * from db1.t1 where ts == '2023-09-16 01:00:00'");
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
TAOS_ROW pRow = NULL;
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
int32_t numOfFields = taos_num_fields(pRes);
int rows = 0;
char str[512] = {0};
while ((pRow = taos_fetch_row(pRes)) != NULL) {
rows++;
}
ASSERT_TRUE(rows == 1);
taos_free_result(pRes);
char sql[256] = {0};
(void)sprintf(sql, "insert into db1.t1 values('2023-09-16 17:00:01', 1)");
pRes = taos_query(pConn, sql);
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
taos_free_result(pRes);
taos_close(pConn);
}
{
// taos_options( TSDB_OPTION_TIMEZONE, "UTC+0");
int code = taos_options(TSDB_OPTION_TIMEZONE, "UTC+0");
ASSERT_TRUE(code == 0);
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
TAOS_RES* pRes = taos_query(pConn, "select * from db1.t1 where ts == '2023-09-16 09:00:00'");
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
TAOS_ROW pRow = NULL;
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
int32_t numOfFields = taos_num_fields(pRes);
int rows = 0;
char str[512] = {0};
while ((pRow = taos_fetch_row(pRes)) != NULL) {
rows++;
}
ASSERT_TRUE(rows == 1);
taos_free_result(pRes);
{
TAOS_RES* pRes = taos_query(pConn, "select * from db1.t1 where ts == '2023-09-17 01:00:01'");
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
TAOS_ROW pRow = NULL;
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
int32_t numOfFields = taos_num_fields(pRes);
int rows = 0;
char str[512] = {0};
while ((pRow = taos_fetch_row(pRes)) != NULL) {
rows++;
}
ASSERT_TRUE(rows == 1);
taos_free_result(pRes);
}
taos_close(pConn);
}
}
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -5187,6 +5187,7 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) {
resetAllDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->info.window.ekey, step); resetAllDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->info.window.ekey, step);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
(void) tsdbReleaseReader(pReader);
return code; return code;
} }
@ -5213,6 +5214,7 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) {
code = doOpenReaderImpl(pReader->innerReader[1]); code = doOpenReaderImpl(pReader->innerReader[1]);
resetAllDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->info.window.ekey, step); resetAllDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->info.window.ekey, step);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
(void) tsdbReleaseReader(pReader);
return code; return code;
} }
@ -5493,6 +5495,7 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) {
code = initFilesetIterator(&pStatus->fileIter, pReader->pReadSnap->pfSetArray, pReader); code = initFilesetIterator(&pStatus->fileIter, pReader->pReadSnap->pfSetArray, pReader);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
(void) tsdbReleaseReader(pReader);
return code; return code;
} }
@ -5826,9 +5829,12 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
pSnap->pIMem = pTsdb->imem; pSnap->pIMem = pTsdb->imem;
pSnap->pINode = taosMemoryMalloc(sizeof(*pSnap->pINode)); pSnap->pINode = taosMemoryMalloc(sizeof(*pSnap->pINode));
if (pSnap->pINode == NULL) { if (pSnap->pINode == NULL) {
(void) tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem
code = terrno; code = terrno;
if (pTsdb->mem && pSnap->pNode) {
(void) tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem
}
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
goto _exit; goto _exit;
} }

View File

@ -553,6 +553,11 @@ static void doSetNullValue(SSDataBlock* pBlock, const SExprInfo* pExpr, int32_t
} }
} }
static void freeTableCachedValObj(STableCachedVal* pVal) {
taosMemoryFree((void*)pVal->pName);
taosMemoryFree(pVal->pTags);
}
int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock, int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock,
int32_t rows, SExecTaskInfo* pTask, STableMetaCacheInfo* pCache) { int32_t rows, SExecTaskInfo* pTask, STableMetaCacheInfo* pCache) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
@ -638,6 +643,7 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int
sizeof(STableCachedVal), freeCachedMetaItem, NULL, TAOS_LRU_PRIORITY_LOW, NULL); sizeof(STableCachedVal), freeCachedMetaItem, NULL, TAOS_LRU_PRIORITY_LOW, NULL);
if (insertRet != TAOS_LRU_STATUS_OK) { if (insertRet != TAOS_LRU_STATUS_OK) {
qError("failed to put meta into lru cache, code:%d, %s", insertRet, idStr); qError("failed to put meta into lru cache, code:%d, %s", insertRet, idStr);
taosMemoryFreeClear(pVal);
} }
} else { } else {
pCache->cacheHit += 1; pCache->cacheHit += 1;
@ -713,7 +719,7 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int
_end: _end:
if (insertRet != TAOS_LRU_STATUS_OK) { if (insertRet != TAOS_LRU_STATUS_OK) {
freeTableCachedVal(&val); freeTableCachedValObj(&val);
} }
if (freeReader) { if (freeReader) {
pHandle->api.metaReaderFn.clearReader(&mr); pHandle->api.metaReaderFn.clearReader(&mr);

View File

@ -798,7 +798,7 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
memcpy(&winStr[3], pp, ppp - pp); memcpy(&winStr[3], pp, ppp - pp);
indexStr = ppp - pp + 3; indexStr = ppp - pp + 3;
} }
sprintf(&winStr[indexStr], "%c%c%c:%c%c:00", (p[0] == '+' ? '-' : '+'), p[1], p[2], p[3], p[4]); sprintf(&winStr[indexStr], "%c%c%c:%c%c:00", (p[0] == '+' ? '+' : '-'), p[1], p[2], p[3], p[4]);
*tsTimezone = -taosStr2Int32(p, NULL, 10); *tsTimezone = -taosStr2Int32(p, NULL, 10);
} else { } else {
*tsTimezone = 0; *tsTimezone = 0;

View File

@ -556,6 +556,19 @@ class TDCom:
newTdSql.init(cur, False) newTdSql.init(cur, False)
return newTdSql return newTdSql
def newcurWithTimezone(self, timezone, host='localhost', port=6030, user='root', password='taosdata'):
cfgPath = self.getClientCfgPath()
con=taos.connect(host=host, user=user, password=password, config=cfgPath, port=port, timezone=timezone)
cur=con.cursor()
# print(cur)
return cur
def newTdSqlWithTimezone(self, timezone, host='localhost',port=6030,user='root',password='taosdata'):
newTdSql = TDSql()
cur = self.newcurWithTimezone(host=host,port=port,user=user,password=password, timezone=timezone)
newTdSql.init(cur, False)
return newTdSql
################################################################################################################ ################################################################################################################
# port from the common.py of new test frame # port from the common.py of new test frame
################################################################################################################ ################################################################################################################

View File

@ -2,6 +2,7 @@ from wsgiref.headers import tspecials
from util.log import * from util.log import *
from util.cases import * from util.cases import *
from util.sql import * from util.sql import *
from util.common import tdCom
import numpy as np import numpy as np
@ -127,11 +128,38 @@ class TDTestCase:
tdSql.query(f"select * from {dbname}.stb where loc not in ('shanghai', 'shanghai', null)") tdSql.query(f"select * from {dbname}.stb where loc not in ('shanghai', 'shanghai', null)")
tdSql.checkRows(0) tdSql.checkRows(0)
def timeZoneTest(self):
dbname = self.dbname
tdsql1 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai")
tdsql1.execute(f'create table {dbname}.tzt(ts timestamp, c1 int)')
tdsql1.execute(f'insert into {dbname}.tzt values({self.ts}, 1)')
tdsql1.query(f"select * from {dbname}.tzt")
tdsql1.checkRows(1)
tdsql1.checkData(0, 0, "2018-09-17 09:00:00")
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="UTC")
tdsql2.query(f"select * from {dbname}.tzt")
tdsql2.checkRows(1)
tdsql2.checkData(0, 0, "2018-09-17 01:00:00")
tdsql2.execute(f'insert into {dbname}.tzt values({self.ts + 1000}, 2)')
tdsql2.query(f"select * from {dbname}.tzt order by ts")
tdsql2.checkRows(2)
tdsql2.checkData(0, 0, "2018-09-17 01:00:00")
tdsql2.checkData(1, 0, "2018-09-17 01:00:01")
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai")
tdsql2.query(f"select * from {dbname}.tzt order by ts")
tdsql2.checkRows(2)
tdsql2.checkData(0, 0, "2018-09-17 09:00:00")
tdsql2.checkData(1, 0, "2018-09-17 09:00:01")
def run(self): def run(self):
dbname = "db" dbname = "db"
tdSql.prepare() tdSql.prepare()
self.timeZoneTest()
self.inAndNotinTest() self.inAndNotinTest()