From c9c3834449a5ceb2bad79503c1590aa3ed517094 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 2 Jul 2020 23:02:09 +0800 Subject: [PATCH] [td-225] refactor code --- src/client/inc/tscUtil.h | 2 -- src/client/inc/tsclient.h | 2 +- src/client/src/tscServer.c | 2 +- src/client/src/tscUtil.c | 25 --------------------- src/common/inc/{qsqltype.h => tcmdtype.h} | 6 ++--- src/common/inc/tname.h | 2 ++ src/common/src/sqlcmdstr.c | 2 +- src/common/src/tname.c | 27 ++++++++++++++++++++++- src/query/inc/qExecutor.h | 16 ++++---------- src/query/src/qExecutor.c | 5 ++--- src/query/src/qparserImpl.c | 6 ++--- src/query/src/sql.c | 10 ++++----- 12 files changed, 48 insertions(+), 57 deletions(-) rename src/common/inc/{qsqltype.h => tcmdtype.h} (97%) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index b99a8a46d0..f687d7f244 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -176,8 +176,6 @@ SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex); SArray* tscColumnListClone(const SArray* src, int16_t tableIndex); void tscColumnListDestroy(SArray* pColList); -SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters); - int32_t tscValidateName(SSQLToken* pToken); void tscIncStreamExecutionCount(void* pStream); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 6ce94d5aa4..75ca4b6240 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -32,8 +32,8 @@ extern "C" { #include "qExecutor.h" #include "qsqlparser.h" -#include "qsqltype.h" #include "qtsbuf.h" +#include "tcmdtype.h" // forward declaration struct SSqlInfo; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e85ade60e5..1b2334b998 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -14,8 +14,8 @@ */ #include "os.h" -#include "qsqltype.h" #include "tcache.h" +#include "tcmdtype.h" #include "trpc.h" #include "tscLocalMerge.h" #include "tscLog.h" diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 26a81c597f..9b6eff7123 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1115,31 +1115,6 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { return taosArrayGetP(pColumnList, i); } -SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters) { - if (numOfFilters == 0) { - assert(src == NULL); - return NULL; - } - - SColumnFilterInfo* pFilter = calloc(1, numOfFilters * sizeof(SColumnFilterInfo)); - - memcpy(pFilter, src, sizeof(SColumnFilterInfo) * numOfFilters); - for (int32_t j = 0; j < numOfFilters; ++j) { - - if (pFilter[j].filterstr) { - size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE; - pFilter[j].pz = (int64_t) calloc(1, len); - - memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len); - } - } - - assert(src->filterstr == 0 || src->filterstr == 1); - assert(!(src->lowerRelOptr == TSDB_RELATION_INVALID && src->upperRelOptr == TSDB_RELATION_INVALID)); - - return pFilter; -} - static void destroyFilterInfo(SColumnFilterInfo* pFilterInfo, int32_t numOfFilters) { for(int32_t i = 0; i < numOfFilters; ++i) { if (pFilterInfo[i].filterstr) { diff --git a/src/common/inc/qsqltype.h b/src/common/inc/tcmdtype.h similarity index 97% rename from src/common/inc/qsqltype.h rename to src/common/inc/tcmdtype.h index 6f6493d17c..90fb5bf478 100644 --- a/src/common/inc/qsqltype.h +++ b/src/common/inc/tcmdtype.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_QSQLCMD_H -#define TDENGINE_QSQLCMD_H +#ifndef TDENGINE_TSQLMSGTYPE_H +#define TDENGINE_TSQLMSGTYPE_H #ifdef __cplusplus extern "C" { @@ -109,4 +109,4 @@ extern char *sqlCmd[]; } #endif -#endif // TDENGINE_QSQLCMD_H +#endif // TDENGINE_TSQLMSGTYPE_H diff --git a/src/common/inc/tname.h b/src/common/inc/tname.h index d2008c9ff8..10d725db32 100644 --- a/src/common/inc/tname.h +++ b/src/common/inc/tname.h @@ -27,4 +27,6 @@ SSchema tGetTableNameColumnSchema(); bool tscValidateTableNameLength(size_t len); +SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters); + #endif // TDENGINE_NAME_H diff --git a/src/common/src/sqlcmdstr.c b/src/common/src/sqlcmdstr.c index 8584ba7976..672106523e 100644 --- a/src/common/src/sqlcmdstr.c +++ b/src/common/src/sqlcmdstr.c @@ -15,4 +15,4 @@ #define TSDB_SQL_C -#include "qsqltype.h" +#include "tcmdtype.h" diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 2514ed26e5..295015d466 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -49,4 +49,29 @@ SSchema tGetTableNameColumnSchema() { bool tscValidateTableNameLength(size_t len) { return len < TSDB_TABLE_NAME_LEN; -} \ No newline at end of file +} + +SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters) { + if (numOfFilters == 0) { + assert(src == NULL); + return NULL; + } + + SColumnFilterInfo* pFilter = calloc(1, numOfFilters * sizeof(SColumnFilterInfo)); + + memcpy(pFilter, src, sizeof(SColumnFilterInfo) * numOfFilters); + for (int32_t j = 0; j < numOfFilters; ++j) { + + if (pFilter[j].filterstr) { + size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE; + pFilter[j].pz = (int64_t) calloc(1, len); + + memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len); + } + } + + assert(src->filterstr == 0 || src->filterstr == 1); + assert(!(src->lowerRelOptr == TSDB_RELATION_INVALID && src->upperRelOptr == TSDB_RELATION_INVALID)); + + return pFilter; +} diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index d7d59230b6..f29bd01736 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -95,16 +95,13 @@ typedef struct SSingleColumnFilterInfo { } SSingleColumnFilterInfo; typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct - int32_t tableIndex; - int32_t groupIndex; // group id in table list TSKEY lastKey; - int32_t numOfRes; + int32_t groupIndex; // group id in table list int16_t queryRangeSet; // denote if the query range is set, only available for interval query int64_t tag; STimeWindow win; STSCursor cur; - void* pTable; // for retrieve the page id list - + void* pTable; // for retrieve the page id list SWindowResInfo windowResInfo; } STableQueryInfo; @@ -127,11 +124,6 @@ typedef struct SQueryCostInfo { uint64_t computTime; } SQueryCostInfo; -//typedef struct SGroupItem { -// void *pTable; -// STableQueryInfo *info; -//} SGroupItem; - typedef struct SQuery { int16_t numOfCols; int16_t numOfTags; @@ -173,12 +165,12 @@ typedef struct SQueryRuntimeEnv { STSBuf* pTSBuf; STSCursor cur; SQueryCostInfo summary; - bool stableQuery; // super table query or not void* pQueryHandle; void* pSecQueryHandle; // another thread for - SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file + bool stableQuery; // super table query or not bool topBotQuery; // false int32_t prevGroupId; // previous executed group id + SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file } SQueryRuntimeEnv; typedef struct SQInfo { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index f33d739ba1..5e3a7b2abd 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ #include "os.h" +#include "taosmsg.h" #include "qfill.h" #include "hash.h" @@ -22,9 +23,8 @@ #include "qresultBuf.h" #include "query.h" #include "queryLog.h" -#include "taosmsg.h" #include "tlosertree.h" -#include "tscUtil.h" // todo move the function to common module +#include "exception.h" #include "tscompression.h" #include "ttime.h" @@ -5656,7 +5656,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, STableQueryInfo* item = createTableQueryInfo(&pQInfo->runtimeEnv, pTable, window); item->groupIndex = i; - item->tableIndex = tableIndex++; taosArrayPush(p1, &item); taosHashPut(pQInfo->tableqinfoGroupInfo.map, &id.tid, sizeof(id.tid), &item, POINTER_BYTES); } diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index 928b9eb873..d4ac540d2f 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -15,16 +15,16 @@ #include "os.h" #include "qsqlparser.h" +#include "queryLog.h" #include "taosdef.h" #include "taosmsg.h" +#include "tcmdtype.h" #include "tglobal.h" #include "tstoken.h" +#include "tstrbuild.h" #include "ttime.h" #include "ttokendef.h" #include "tutil.h" -#include "qsqltype.h" -#include "tstrbuild.h" -#include "queryLog.h" SSqlInfo qSQLParse(const char *pStr) { void *pParser = ParseAlloc(malloc); diff --git a/src/query/src/sql.c b/src/query/src/sql.c index e75802a98f..eafb052593 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -25,17 +25,17 @@ #include /************ Begin %include sections from the grammar ************************/ +#include +#include #include #include #include -#include -#include -#include "tutil.h" #include "qsqlparser.h" +#include "tcmdtype.h" #include "tstoken.h" -#include "tvariant.h" #include "ttokendef.h" -#include "qsqltype.h" +#include "tutil.h" +#include "tvariant.h" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless -- GitLab