[td-11818] Refactor.

This commit is contained in:
Haojun Liao 2022-01-19 18:22:25 +08:00
parent 8dc69569ec
commit 0399125bb8
3 changed files with 70 additions and 79 deletions

View File

@ -521,29 +521,29 @@ TEST(testCase, connect_Test) {
// taosHashCleanup(phash); // taosHashCleanup(phash);
//} //}
// //
//TEST(testCase, create_topic_Test) { TEST(testCase, create_topic_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);
//
// TAOS_RES* pRes = taos_query(pConn, "use abc1"); TAOS_RES* pRes = taos_query(pConn, "use abc1");
// if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
// printf("error in use db, reason:%s\n", taos_errstr(pRes)); printf("error in use db, reason:%s\n", taos_errstr(pRes));
// } }
// taos_free_result(pRes); taos_free_result(pRes);
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes); TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// ASSERT_TRUE(pFields == nullptr); ASSERT_TRUE(pFields == nullptr);
//
// 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_free_result(pRes);
//
// char* sql = "select * from tu"; char* sql = "select * from tu";
// pRes = taos_create_topic(pConn, "test_topic_1", sql, strlen(sql)); pRes = taos_create_topic(pConn, "test_topic_1", sql, strlen(sql));
// taos_free_result(pRes); taos_free_result(pRes);
// taos_close(pConn); taos_close(pConn);
//} }
//TEST(testCase, insert_test) { //TEST(testCase, insert_test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
@ -614,30 +614,30 @@ TEST(testCase, connect_Test) {
// taos_close(pConn); // taos_close(pConn);
//} //}
TEST(testCase, projection_query_stables) { //TEST(testCase, projection_query_stables) {
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);
//
TAOS_RES* pRes = taos_query(pConn, "use abc1"); // TAOS_RES* pRes = taos_query(pConn, "use abc1");
taos_free_result(pRes); // taos_free_result(pRes);
//
pRes = taos_query(pConn, "select ts from m1"); // pRes = taos_query(pConn, "select ts from m1");
if (taos_errno(pRes) != 0) { // if (taos_errno(pRes) != 0) {
printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); // printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes); // taos_free_result(pRes);
ASSERT_TRUE(false); // 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);
int32_t numOfFields = taos_num_fields(pRes); // int32_t numOfFields = taos_num_fields(pRes);
//
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);
printf("%s\n", str); // printf("%s\n", str);
} // }
//
taos_free_result(pRes); // taos_free_result(pRes);
taos_close(pConn); // taos_close(pConn);
} //}

View File

@ -29,6 +29,14 @@ static void copyString(const cJSON* json, const char* name, char* dst) {
strcpy(dst, cJSON_GetStringValue(cJSON_GetObjectItem(json, name))); strcpy(dst, cJSON_GetStringValue(cJSON_GetObjectItem(json, name)));
} }
static uint64_t getBigintFromString(const cJSON* json, const char* name) {
char* val = getString(json, name);
uint64_t intVal = strtoul(val, NULL, 10);
tfree(val);
return intVal;
}
static int64_t getNumber(const cJSON* json, const char* name) { static int64_t getNumber(const cJSON* json, const char* name) {
double d = cJSON_GetNumberValue(cJSON_GetObjectItem(json, name)); double d = cJSON_GetNumberValue(cJSON_GetObjectItem(json, name));
return (int64_t) d; return (int64_t) d;
@ -543,13 +551,13 @@ static const char* jkTimeWindowEndKey = "EndKey";
static bool timeWindowToJson(const void* obj, cJSON* json) { static bool timeWindowToJson(const void* obj, cJSON* json) {
const STimeWindow* win = (const STimeWindow*)obj; const STimeWindow* win = (const STimeWindow*)obj;
char tmp[32] = {0}; char tmp[40] = {0};
sprintf(tmp, "%"PRId64, win->skey); snprintf(tmp, tListLen(tmp),"%"PRId64, win->skey);
bool res = cJSON_AddStringToObject(json, jkTimeWindowStartKey, tmp); bool res = cJSON_AddStringToObject(json, jkTimeWindowStartKey, tmp);
if (res) { if (res) {
memset(tmp, 0, tListLen(tmp)); memset(tmp, 0, tListLen(tmp));
sprintf(tmp, "%"PRId64, win->ekey); snprintf(tmp, tListLen(tmp),"%"PRId64, win->ekey);
res = cJSON_AddStringToObject(json, jkTimeWindowEndKey, tmp); res = cJSON_AddStringToObject(json, jkTimeWindowEndKey, tmp);
} }
return res; return res;
@ -557,16 +565,8 @@ static bool timeWindowToJson(const void* obj, cJSON* json) {
static bool timeWindowFromJson(const cJSON* json, void* obj) { static bool timeWindowFromJson(const cJSON* json, void* obj) {
STimeWindow* win = (STimeWindow*)obj; STimeWindow* win = (STimeWindow*)obj;
win->skey = getBigintFromString(json, jkTimeWindowStartKey);
char* pStartKey = getString(json, jkTimeWindowStartKey); win->ekey = getBigintFromString(json, jkTimeWindowEndKey);
win->skey = strtoul(pStartKey, NULL, 10);
char* pEndKey = getString(json, jkTimeWindowEndKey);
win->ekey = strtoul(pEndKey, NULL, 10);
tfree(pStartKey);
tfree(pEndKey);
return true; return true;
} }
@ -605,10 +605,7 @@ static bool scanNodeToJson(const void* obj, cJSON* json) {
static bool scanNodeFromJson(const cJSON* json, void* obj) { static bool scanNodeFromJson(const cJSON* json, void* obj) {
SScanPhyNode* pNode = (SScanPhyNode*)obj; SScanPhyNode* pNode = (SScanPhyNode*)obj;
char* val = getString(json, jkScanNodeTableId); pNode->uid = getBigintFromString(json, jkScanNodeTableId);
pNode->uid = strtoull(val, NULL, 10);
tfree(val);
pNode->tableType = getNumber(json, jkScanNodeTableType); pNode->tableType = getNumber(json, jkScanNodeTableType);
pNode->count = getNumber(json, jkScanNodeTableCount); pNode->count = getNumber(json, jkScanNodeTableCount);
pNode->order = getNumber(json, jkScanNodeTableOrder); pNode->order = getNumber(json, jkScanNodeTableOrder);
@ -782,10 +779,7 @@ static bool nodeAddrFromJson(const cJSON* json, void* obj) {
SDownstreamSource* pSource = (SDownstreamSource*)obj; SDownstreamSource* pSource = (SDownstreamSource*)obj;
pSource->taskId = getNumber(json, jkNodeTaskId); pSource->taskId = getNumber(json, jkNodeTaskId);
char* pSchedId = getString(json, jkNodeTaskSchedId); pSource->schedId = getBigintFromString(json, jkNodeTaskSchedId);
pSource->schedId = strtoul(pSchedId, NULL, 10);
tfree(pSchedId);
bool res = fromObject(json, jkNodeAddr, queryNodeAddrFromJson, &pSource->addr, true); bool res = fromObject(json, jkNodeAddr, queryNodeAddrFromJson, &pSource->addr, true);
return res; return res;
} }
@ -1031,12 +1025,9 @@ static bool subplanIdToJson(const void* obj, cJSON* jId) {
static bool subplanIdFromJson(const cJSON* json, void* obj) { static bool subplanIdFromJson(const cJSON* json, void* obj) {
SSubplanId* id = (SSubplanId*)obj; SSubplanId* id = (SSubplanId*)obj;
char* queryId = getString(json, jkIdQueryId); id->queryId = getBigintFromString(json, jkIdQueryId);
id->queryId = strtoul(queryId, NULL, 0);
tfree(queryId);
id->templateId = getNumber(json, jkIdTemplateId); id->templateId = getNumber(json, jkIdTemplateId);
id->subplanId = getNumber(json, jkIdSubplanId); id->subplanId = getNumber(json, jkIdSubplanId);
return true; return true;
} }

View File

@ -65,9 +65,9 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag,
} }
if (pLogicPlan->info.type != QNODE_MODIFY) { if (pLogicPlan->info.type != QNODE_MODIFY) {
char* str = NULL; // char* str = NULL;
queryPlanToString(pLogicPlan, &str); // queryPlanToString(pLogicPlan, &str);
printf("%s\n", str); // printf("%s\n", str);
} }
code = optimizeQueryPlan(pLogicPlan); code = optimizeQueryPlan(pLogicPlan);