diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index ac1894369d991a7332191803c9f374e63628d6d3..00fa1a1479e51c5120641041155b9aa8fc2ff189 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -34,7 +34,9 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) VERSION_INFO) MESSAGE(STATUS "build version ${VERSION_INFO}") SET_TARGET_PROPERTIES(taos PROPERTIES VERSION ${VERSION_INFO} SOVERSION 1) - + + ADD_SUBDIRECTORY(tests) + ELSEIF (TD_WINDOWS_64) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32) diff --git a/src/client/tests/CMakeLists.txt b/src/client/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f07af85e255eaa5e285d9a4ce0853251e0fdaa21 --- /dev/null +++ b/src/client/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(TDengine) + +FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest) +FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib) + +IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) + MESSAGE(STATUS "gTest library found, build unit test") + + INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + + ADD_EXECUTABLE(cliTest ${SOURCE_LIST}) + TARGET_LINK_LIBRARIES(cliTest taos tutil common gtest pthread) +ENDIF() \ No newline at end of file diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index ae6ffea59a60ecb3d001f166dd9d711803f66db4..ed62357c4df875cef1c76102344756d40ee74007 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -20,6 +20,7 @@ #include "tconfig.h" #include "tutil.h" +// TODO refactor to set the tz value through parameter void tsSetTimeZone() { SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); uPrint("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 5ec5aebf144d6d576824e907617572dd0950c5bc..81b703b7400422a09b7883895c0e957b8aa8596f 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -968,6 +968,17 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { return mnodeAlterDb(pMsg->pDb, pAlter, pMsg); } +static int32_t mnodeDropDbCb(SMnodeMsg *pMsg, int32_t code) { + SDbObj *pDb = pMsg->pDb; + if (code != TSDB_CODE_SUCCESS) { + mError("db:%s, failed to drop from sdb, reason:%s", pDb->name, tstrerror(code)); + } else { + mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} + static int32_t mnodeDropDb(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -978,12 +989,12 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb, - .pMsg = pMsg + .pMsg = pMsg, + .cb = mnodeDropDbCb }; int32_t code = sdbDeleteRow(&oper); if (code == TSDB_CODE_SUCCESS) { - mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 4906aeaeb09ae8fd3fca84747ab6cf925aa88c20..88ed0e90ebce2b42a0ac9f27fac3167a570056ac 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -854,13 +854,15 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; - if (pTable != NULL) { - mLPrint("app:%p:%p, stable:%s, is dropped from sdb, result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, - tstrerror(code)); + if (code != TSDB_CODE_SUCCESS) { + mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); + } else { + mLPrint("app:%p:%p, stable:%s, is dropped from sdb", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); } return code; } + static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -899,12 +901,10 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { }; int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - return code; - } else { + if (code == TSDB_CODE_SUCCESS) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } + return code; } static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ed529db92e7a03b2be966598916cfd2def79cd37..cdb56e14695d7b04d8c6a57624f7b5cf9b0c7856 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -822,7 +822,7 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas } /** - * + * todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions * @param pRuntimeEnv * @param forwardStep * @param tsCols @@ -1064,16 +1064,18 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SQuery *pQuery = pRuntimeEnv->pQuery; STableQueryInfo* item = pQuery->current; - - TSKEY *tsCols = (TSKEY*) ((SColumnInfoData *)taosArrayGet(pDataBlock, 0))->pData; - bool groupbyStateValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); + + SColumnInfoData* pColumnInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock, 0); + + TSKEY *tsCols = (pColumnInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP)? (TSKEY*) pColumnInfoData->pData:NULL; + bool groupbyColumnValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); SArithmeticSupport *sasArray = calloc((size_t)pQuery->numOfOutput, sizeof(SArithmeticSupport)); int16_t type = 0; int16_t bytes = 0; char *groupbyColumnData = NULL; - if (groupbyStateValue) { + if (groupbyColumnValue) { groupbyColumnData = getGroupbyColumnData(pQuery, &type, &bytes, pDataBlock); } @@ -1161,7 +1163,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS pWindowResInfo->curIndex = index; } else { // other queries // decide which group this rows belongs to according to current state value - if (groupbyStateValue) { + if (groupbyColumnValue) { char *val = groupbyColumnData + bytes * offset; int32_t ret = setGroupResultOutputBuf(pRuntimeEnv, val, type, bytes); @@ -1186,9 +1188,14 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } } } - - item->lastKey = tsCols[offset] + step; - + + assert(offset >= 0); + if (tsCols != NULL) { + item->lastKey = tsCols[offset] + step; + } else { + item->lastKey = (QUERY_IS_ASC_QUERY(pQuery)? pDataBlockInfo->window.ekey:pDataBlockInfo->window.skey) + step; + } + // todo refactor: extract method for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { if (pQuery->pSelectExpr[i].base.functionId != TSDB_FUNC_ARITHM) { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 6b0224cad2391c55d4e0353f83bfcc7b6339ca07..e8da25d5852da47ca95c402983317687d7aca19b 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -553,10 +553,18 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) { return 0; } -void tsdbRefTable(STable *pTable) { T_REF_INC(pTable); } +void tsdbRefTable(STable *pTable) { + int16_t ref = T_REF_INC(pTable); + tsdbTrace("ref table:%s, uid:%"PRIu64", tid:%d, ref:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid, ref); +} void tsdbUnRefTable(STable *pTable) { - if (T_REF_DEC(pTable) == 0) { + int16_t ref = T_REF_DEC(pTable); + tsdbTrace("unref table:%s, uid:%"PRIu64", tid:%d, ref:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid, ref); + + if (ref == 0) { + tsdbTrace("destroy table:%s uid:%"PRIu64", tid:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid); + if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) { tsdbUnRefTable(pTable->pSuper); } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 2394adc6f33b93aa38b4daca6990fbc163c0738c..f3c0babe6b849983e0f1cf417767dcf26e5dd85c 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -38,7 +38,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) { const uint32_t factor = 4; int32_t n = 1; - while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) { + while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { n++; } diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index dfec6320121e67dc0d0f2907f03669e50f67895f..176f9be7fbc5c7c3d1a2252d1bcfc83eb1a1b2cd 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -48,23 +48,21 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, const unsigned int day, const unsigned int hour, const unsigned int min, const unsigned int sec) { - unsigned int mon = mon0, year = year0; - - /* 1..12 -> 11,12,1..10 */ - if (0 >= (int) (mon -= 2)) { - mon += 12; /* Puts Feb last since it has leap day */ - year -= 1; - } - - //int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + - // year*365 - 719499)*24 + hour)*60 + min)*60 + sec); - int64_t res; - res = 367*((int64_t)mon)/12; - res += year/4 - year/100 + year/400 + day + year*365 - 719499; + unsigned int mon = mon0, year = year0; + + /* 1..12 -> 11,12,1..10 */ + if (0 >= (int) (mon -= 2)) { + mon += 12; /* Puts Feb last since it has leap day */ + year -= 1; + } + + int64_t res = 367*((int64_t)mon)/12; + + res += ((int64_t)(year/4 - year/100 + year/400 + day + year*365) - 719499); // this value may be less than 0 res = res*24; res = ((res + hour) * 60 + min) * 60 + sec; - return (res + timezone); + return (res + timezone); } // ==== mktime() kernel code =================// static int64_t m_deltaUtc = 0; diff --git a/tests/script/general/parser/projection_limit_offset.sim b/tests/script/general/parser/projection_limit_offset.sim index 5f006d0eb7b81c3cc3281f8a541a121acdddc914..2b89946ef850cfd8e0b105cd35c8afc6a1d3866b 100644 --- a/tests/script/general/parser/projection_limit_offset.sim +++ b/tests/script/general/parser/projection_limit_offset.sim @@ -80,6 +80,7 @@ print $rows sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 0; if $rows != 4008 then + print expect 4008, actual:$rows return -1 endi