From c597c8ad587f8926c42eee99bf3b2923475a5bdb Mon Sep 17 00:00:00 2001 From: localvar Date: Sat, 25 Apr 2020 10:02:16 +0800 Subject: [PATCH] TD-97: fix bug and update testcases --- src/client/src/tscSQLParser.c | 2 +- src/client/src/tscServer.c | 2 +- src/query/src/qast.c | 3 ++- src/query/src/queryExecutor.c | 20 +++++++++++--------- src/tsdb/src/tsdbRead.c | 15 +++++++-------- tests/pytest/{select => query}/__init__.py | 0 tests/pytest/{select => query}/tbname.py | 17 ++++++++++------- 7 files changed, 32 insertions(+), 27 deletions(-) rename tests/pytest/{select => query}/__init__.py (100%) rename tests/pytest/{select => query}/tbname.py (90%) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index df47afd0dc..0e23236b16 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3545,7 +3545,7 @@ static int32_t setTableCondForSTableQuery(SQueryInfo* pQueryInfo, const char* ac return TSDB_CODE_SUCCESS; } - SStringBuilder sb1; + SStringBuilder sb1 = { 0 }; taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); char db[TSDB_TABLE_ID_LEN] = {0}; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index aeb137189b..b8c0274dd9 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1855,7 +1855,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->msgType = TSDB_MSG_TYPE_CM_HEARTBEAT; assert(msgLen + minMsgSize() <= size); - return msgLen; + return TSDB_CODE_SUCCESS; } int tscProcessTableMetaRsp(SSqlObj *pSql) { diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 70e4dbd803..b262429e5d 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -816,7 +816,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, if (pQueryInfo->optr == TSDB_RELATION_IN) { addToResult = pQueryInfo->compare(table->name, pQueryInfo->q.arr); } else if(pQueryInfo->optr == TSDB_RELATION_LIKE) { - addToResult = pQueryInfo->compare(table->name, pQueryInfo->q.pz); + addToResult = !pQueryInfo->compare(table->name, pQueryInfo->q.pz); } } else { // TODO: other columns @@ -1188,6 +1188,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { // TODO: } memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len); + pVal->nLen = (int32_t)len; } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { right->nodeType = TSQL_NODE_VALUE; diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index b9b304cfc1..cdc7b3328c 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -5430,13 +5430,6 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, pMsg += sizeof(int64_t) * pQueryMsg->numOfOutput; } - // the tag query condition expression string is located at the end of query msg - if (pQueryMsg->tagCondLen > 0) { - *tagCond = calloc(1, pQueryMsg->tagCondLen); - memcpy(*tagCond, pMsg, pQueryMsg->tagCondLen); - pMsg += pQueryMsg->tagCondLen; - } - if (pQueryMsg->numOfTags > 0) { (*tagCols) = calloc(1, sizeof(SColumnInfo) * pQueryMsg->numOfTags); for (int32_t i = 0; i < pQueryMsg->numOfTags; ++i) { @@ -5448,13 +5441,22 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, pTagCol->numOfFilters = 0; (*tagCols)[i] = *pTagCol; + pMsg += sizeof(SColumnInfo); } } + // the tag query condition expression string is located at the end of query msg + if (pQueryMsg->tagCondLen > 0) { + *tagCond = calloc(1, pQueryMsg->tagCondLen); + memcpy(*tagCond, pMsg, pQueryMsg->tagCondLen); + pMsg += pQueryMsg->tagCondLen; + } + if (*pMsg != 0) { - size_t len = strlen(pMsg); - *tbnameCond = malloc(len + 1); + size_t len = strlen(pMsg) + 1; + *tbnameCond = malloc(len); strcpy(*tbnameCond, pMsg); + pMsg += len; } qTrace("qmsg:%p query on %d table(s), qrange:%" PRId64 "-%" PRId64 diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0449f42eb5..eb35be5383 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1448,7 +1448,7 @@ int32_t tsdbQueryByTagsCond( size_t len, int16_t tagNameRelType, const char* tbnameCond, - STableGroupInfo *pGroupList, + STableGroupInfo *pGroupInfo, SColIndex *pColIndex, int32_t numOfCols ) { @@ -1465,16 +1465,15 @@ int32_t tsdbQueryByTagsCond( if (tbnameCond == NULL && (pTagCond == NULL || len == 0)) { int32_t ret = getAllTableIdList(tsdb, uid, res); if (ret == TSDB_CODE_SUCCESS) { - pGroupList->numOfTables = taosArrayGetSize(res); - pGroupList->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); + pGroupInfo->numOfTables = taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); } - - pGroupInfo->numOfTables = taosArrayGetSize(res); - pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); taosArrayDestroy(res); return ret; } + int32_t ret = TSDB_CODE_SUCCESS; + tExprNode* expr = exprTreeFromTableName(tbnameCond); tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); if (tagExpr != NULL) { @@ -1491,8 +1490,8 @@ int32_t tsdbQueryByTagsCond( } doQueryTableList(pSTable, res, expr); - pGroupList->numOfTables = taosArrayGetSize(res); - pGroupList->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); + pGroupInfo->numOfTables = taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols); taosArrayDestroy(res); return ret; diff --git a/tests/pytest/select/__init__.py b/tests/pytest/query/__init__.py similarity index 100% rename from tests/pytest/select/__init__.py rename to tests/pytest/query/__init__.py diff --git a/tests/pytest/select/tbname.py b/tests/pytest/query/tbname.py similarity index 90% rename from tests/pytest/select/tbname.py rename to tests/pytest/query/tbname.py index f088f9e63a..d2799efa25 100644 --- a/tests/pytest/select/tbname.py +++ b/tests/pytest/query/tbname.py @@ -39,29 +39,32 @@ class TDTestCase: tdSql.query("select * from cars where tbname in ('carzero', 'cartwo')") tdSql.checkRows(1) - tdSql.query("select * from cars where id=1 or tbname in ('carzero0', 'cartwo')") + tdSql.query("select * from cars where id=1 or tbname in ('carzero', 'cartwo')") tdSql.checkRows(2) - tdSql.query("select * from cars where id=1 and tbname in ('carzero0', 'cartwo')") + tdSql.query("select * from cars where id=1 and tbname in ('carzero', 'cartwo')") tdSql.checkRows(0) - tdSql.query("select * from cars where id=0 and tbname in ('carzero0', 'cartwo')") + tdSql.query("select * from cars where id=0 and tbname in ('carzero', 'cartwo')") tdSql.checkRows(1) - tdSql.query("select * from cars where tbname like 'car%') + """ + tdSql.query("select * from cars where tbname like 'car%'") tdSql.checkRows(2) - tdSql.query("select * from cars where tbname like '%%o') + tdSql.cursor.execute("use db") + tdSql.query("select * from cars where tbname like '%o'") tdSql.checkRows(1) tdSql.query("select * from cars where id=1 and tbname like 'car%') tdSql.checkRows(1) - tdSql.query("select * from cars where id = 1 and tbname like '%%o') + tdSql.query("select * from cars where id = 1 and tbname like '%o') tdSql.checkRows(0) - tdSql.query("select * from cars where id = 1 or tbname like '%%o') + tdSql.query("select * from cars where id = 1 or tbname like '%o') tdSql.checkRows(2) + """ def stop(self): tdSql.close() -- GitLab