diff --git a/cmake/cmake.define b/cmake/cmake.define index 7bcd400fa6..802c36efbf 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -220,20 +220,20 @@ ELSE () IF ("${SIMD_SUPPORT}" MATCHES "true") IF (COMPILER_SUPPORT_FMA) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma") + MESSAGE(STATUS "FMA instructions is ACTIVATED") + ENDIF() + IF (COMPILER_SUPPORT_AVX) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") + MESSAGE(STATUS "AVX instructions is ACTIVATED") + ENDIF() + IF (COMPILER_SUPPORT_AVX2) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2") + MESSAGE(STATUS "AVX2 instructions is ACTIVATED") ENDIF() - MESSAGE(STATUS "FMA instructions is ACTIVATED") - ENDIF() - IF (COMPILER_SUPPORT_AVX) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") - MESSAGE(STATUS "AVX instructions is ACTIVATED") - ENDIF() - IF (COMPILER_SUPPORT_AVX2) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2") - MESSAGE(STATUS "AVX2 instructions is ACTIVATED") ENDIF() IF ("${SIMD_AVX512_SUPPORT}" MATCHES "true") diff --git a/include/common/tglobal.h b/include/common/tglobal.h index cf918c6e0d..41fb692e42 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -42,21 +42,21 @@ typedef enum { } EEncryptScope; // cluster -extern char tsFirst[]; -extern char tsSecond[]; -extern char tsLocalFqdn[]; -extern char tsLocalEp[]; -extern char tsVersionName[]; -extern uint16_t tsServerPort; -extern int32_t tsVersion; -extern int32_t tsStatusInterval; -extern int32_t tsNumOfSupportVnodes; -extern char tsEncryptAlgorithm[]; -extern char tsEncryptScope[]; -extern EEncryptAlgor tsiEncryptAlgorithm; -extern EEncryptScope tsiEncryptScope; -//extern char tsAuthCode[]; -extern char tsEncryptKey[]; +extern char tsFirst[]; +extern char tsSecond[]; +extern char tsLocalFqdn[]; +extern char tsLocalEp[]; +extern char tsVersionName[]; +extern uint16_t tsServerPort; +extern int32_t tsVersion; +extern int32_t tsStatusInterval; +extern int32_t tsNumOfSupportVnodes; +extern char tsEncryptAlgorithm[]; +extern char tsEncryptScope[]; +extern EEncryptAlgor tsiEncryptAlgorithm; +extern EEncryptScope tsiEncryptScope; +// extern char tsAuthCode[]; +extern char tsEncryptKey[]; // common extern int32_t tsMaxShellConns; @@ -71,6 +71,8 @@ extern int32_t tsTagFilterResCacheSize; // queue & threads extern int32_t tsNumOfRpcThreads; extern int32_t tsNumOfRpcSessions; +extern int32_t tsShareConnLimit; +extern int32_t tsReadTimeout; extern int32_t tsTimeToGetAvailableConn; extern int32_t tsKeepAliveIdle; extern int32_t tsNumOfCommitThreads; @@ -264,8 +266,8 @@ extern bool tsExperimental; int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); -int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, - const char *envFile, char *apolloUrl, SArray *pArgs); +int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, + SArray *pArgs); int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); void taosCleanupCfg(); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 81a1990b71..aa14759810 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -985,6 +985,7 @@ typedef struct SEpSet { SEp eps[TSDB_MAX_REPLICA]; } SEpSet; + int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp); int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp); int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp); diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 6540e7b135..2c797e39bf 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -329,6 +329,7 @@ TD_DEF_MSG_TYPE(TDMT_SCH_EXPLAIN, "explain", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SCH_TASK_NOTIFY, "task-notify", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SCH_TASK_RELEASE, "task-release", NULL, NULL) TD_CLOSE_MSG_SEG(TDMT_SCH_MSG) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 5b860cc23a..cfa3f44f7f 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -63,6 +63,10 @@ typedef struct SRpcHandleInfo { int8_t forbiddenIp; int8_t notFreeAhandle; int8_t compressed; + int64_t seqNum; // msg seq + int64_t qId; // queryId Get from client, other req's qId = -1; + int32_t refIdMgt; + int32_t msgType; } SRpcHandleInfo; typedef struct SRpcMsg { @@ -124,9 +128,13 @@ typedef struct SRpcInit { int32_t connLimitLock; int32_t timeToGetConn; int8_t supportBatch; // 0: no batch, 1. batch - int32_t batchSize; - int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait - void *parent; + int32_t shareConnLimit; + int8_t shareConn; // 0: no share, 1. share + int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait + int8_t startReadTimer; + int64_t readTimeout; // s + + void *parent; } SRpcInit; typedef struct { @@ -144,6 +152,7 @@ typedef struct { SHashObj *args; SRpcBrokenlinkVal brokenVal; void (*freeFunc)(const void *arg); + int64_t st; } SRpcCtx; int32_t rpcInit(); diff --git a/include/os/osFile.h b/include/os/osFile.h index a56c54b086..536dee268a 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -130,14 +130,15 @@ int taosSetAutoDelFile(char *path); bool lastErrorIsFileNotExist(); #ifdef BUILD_WITH_RAND_ERR -#define STUB_RAND_NETWORK_ERR(status) \ - do { \ - if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ - uint32_t r = taosRand() % tsRandErrDivisor; \ - if ((r + 1) <= tsRandErrChance) { \ - status = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ - } \ - } \ +#define STUB_RAND_NETWORK_ERR(ret) \ + do { \ + if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ + uint32_t r = taosRand() % tsRandErrDivisor; \ + if ((r + 1) <= tsRandErrChance) { \ + ret = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ + uError("random network error: %s, %s", tstrerror(ret), __func__); \ + } \ + } \ while (0) #else #define STUB_RAND_NETWORK_ERR(status) diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 1cedfc4dcd..49acf285ee 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -137,6 +137,7 @@ int32_t taosShutDownSocketRDWR(TdSocketPtr pSocket); int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer); int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on); int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen); +int32_t taosSetSockOpt2(int32_t fd); int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen); int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); @@ -159,7 +160,7 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, st int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen); int32_t taosBlockSIGPIPE(); -int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip); +int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip); int32_t taosGetFqdn(char *); void tinet_ntoa(char *ipstr, uint32_t ip); uint32_t ip2uint(const char *const ip_addr); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 4d32c0aa24..fd8970a50f 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -94,9 +94,9 @@ int32_t taosGetErrSize(); #define TSDB_CODE_HTTP_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0025) #define TSDB_CODE_RPC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0026) #define TSDB_CODE_RPC_ASYNC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0027) - - - +#define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) +#define TSDB_CODE_RPC_NO_STATE TAOS_DEF_ERROR_CODE(0, 0x0029) +#define TSDB_CODE_RPC_STATE_DROPED TAOS_DEF_ERROR_CODE(0, 0x002A) //common & util #define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) // diff --git a/include/util/tdef.h b/include/util/tdef.h index b4cb1bdd1c..a0bfdc83f5 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -506,7 +506,7 @@ typedef enum ELogicConditionType { #ifdef WINDOWS #define TSDB_MAX_RPC_THREADS 4 // windows pipe only support 4 connections. #else -#define TSDB_MAX_RPC_THREADS 50 +#define TSDB_MAX_RPC_THREADS 20 #endif #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 21f7c93036..f892575f0a 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -370,7 +370,10 @@ int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, connLimitNum = TMAX(connLimitNum, 10); connLimitNum = TMIN(connLimitNum, 1000); rpcInit.connLimitNum = connLimitNum; + rpcInit.shareConnLimit = tsShareConnLimit; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 2c67cafdf5..9131d29f30 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -410,7 +410,6 @@ int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { SAppInstInfo* pAppInfo = getAppInfo(pRequest); SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); - // int64_t transporterId = 0; int32_t code = asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg); if (code) { doRequestCallback(pRequest, code); @@ -1921,19 +1920,19 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons return NULL; } -//TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen, -// const char* db, int dbLen, uint16_t port) { -// char ipStr[TSDB_EP_LEN] = {0}; -// char dbStr[TSDB_DB_NAME_LEN] = {0}; -// char userStr[TSDB_USER_LEN] = {0}; -// char passStr[TSDB_PASSWORD_LEN] = {0}; +// TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen, +// const char* db, int dbLen, uint16_t port) { +// char ipStr[TSDB_EP_LEN] = {0}; +// char dbStr[TSDB_DB_NAME_LEN] = {0}; +// char userStr[TSDB_USER_LEN] = {0}; +// char passStr[TSDB_PASSWORD_LEN] = {0}; // -// tstrncpy(ipStr, ip, TMIN(TSDB_EP_LEN - 1, ipLen)); -// tstrncpy(userStr, user, TMIN(TSDB_USER_LEN - 1, userLen)); -// tstrncpy(passStr, pass, TMIN(TSDB_PASSWORD_LEN - 1, passLen)); -// tstrncpy(dbStr, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen)); -// return taos_connect(ipStr, userStr, passStr, dbStr, port); -//} +// tstrncpy(ipStr, ip, TMIN(TSDB_EP_LEN - 1, ipLen)); +// tstrncpy(userStr, user, TMIN(TSDB_USER_LEN - 1, userLen)); +// tstrncpy(passStr, pass, TMIN(TSDB_PASSWORD_LEN - 1, passLen)); +// tstrncpy(dbStr, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen)); +// return taos_connect(ipStr, userStr, passStr, dbStr, port); +// } void doSetOneRowPtr(SReqResultInfo* pResultInfo) { for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { @@ -2301,7 +2300,8 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%.9lf", jsonVd); varDataSetLen(dst, strlen(varDataVal(dst))); } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { - (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false"); + (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%s", + (*((char*)jsonInnerData) == 1) ? "true" : "false"); varDataSetLen(dst, strlen(varDataVal(dst))); } else { tscError("doConvertJson error: invalid type:%d", jsonInnerType); @@ -2570,6 +2570,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de connLimitNum = TMIN(connLimitNum, 500); rpcInit.connLimitNum = connLimitNum; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.readTimeout = tsReadTimeout; if (TSDB_CODE_SUCCESS != taosVersionStrToInt(version, &(rpcInit.compatibilityVer))) { tscError("faild to convert taos version from str to int, errcode:%s", terrstr()); goto _OVER; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 3c05294264..7cff5de008 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -56,6 +56,8 @@ int32_t tsShellActivityTimer = 3; // second // queue & threads int32_t tsNumOfRpcThreads = 1; int32_t tsNumOfRpcSessions = 30000; +int32_t tsShareConnLimit = 8; +int32_t tsReadTimeout = 900; int32_t tsTimeToGetAvailableConn = 500000; int32_t tsKeepAliveIdle = 60; @@ -179,12 +181,12 @@ int32_t tsRedirectFactor = 2; int32_t tsRedirectMaxPeriod = 1000; int32_t tsMaxRetryWaitTime = 10000; bool tsUseAdapter = false; -int32_t tsMetaCacheMaxSize = -1; // MB -int32_t tsSlowLogThreshold = 10; // seconds -int32_t tsSlowLogThresholdTest = INT32_MAX; // seconds -char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = ""; // seconds +int32_t tsMetaCacheMaxSize = -1; // MB +int32_t tsSlowLogThreshold = 10; // seconds +int32_t tsSlowLogThresholdTest = INT32_MAX; // seconds +char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = ""; // seconds int32_t tsSlowLogScope = SLOW_LOG_TYPE_QUERY; -char* tsSlowLogScopeString = "query"; +char *tsSlowLogScopeString = "query"; int32_t tsSlowLogMaxLen = 4096; int32_t tsTimeSeriesThreshold = 50; bool tsMultiResultFunctionStarReturnTags = false; @@ -322,7 +324,6 @@ int32_t tsMaxTsmaNum = 3; int32_t tsMaxTsmaCalcDelay = 600; int64_t tsmaDataDeleteMark = 1000 * 60 * 60 * 24; // in ms, default to 1d - #define TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, pName) \ if ((pItem = cfgGetItem(pCfg, pName)) == NULL) { \ TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); \ @@ -361,7 +362,7 @@ static int32_t taosSplitS3Cfg(SConfig *pCfg, const char *name, char gVarible[TSD TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, name); char *strDup = NULL; - if ((strDup = taosStrdup(pItem->str))== NULL){ + if ((strDup = taosStrdup(pItem->str)) == NULL) { code = terrno; goto _exit; } @@ -450,7 +451,9 @@ int32_t taosSetS3Cfg(SConfig *pCfg) { TAOS_RETURN(TSDB_CODE_SUCCESS); } -struct SConfig *taosGetCfg() { return tsCfg; } +struct SConfig *taosGetCfg() { + return tsCfg; +} static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) { @@ -572,7 +575,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "queryPolicy", tsQueryPolicy, 1, 4, CFG_SCOPE_CLIENT, CFG_DYN_ENT_CLIENT)); - TAOS_CHECK_RETURN(cfgAddBool(pCfg, "queryTableNotExistAsEmpty", tsQueryTbNotExistAsEmpty, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN( + cfgAddBool(pCfg, "queryTableNotExistAsEmpty", tsQueryTbNotExistAsEmpty, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "enableQueryHb", tsEnableQueryHb, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "enableScience", tsEnableScience, CFG_SCOPE_CLIENT, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "querySmaOptimize", tsQuerySmaOptimize, 0, 1, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); @@ -600,16 +604,23 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "metaCacheMaxSize", tsMetaCacheMaxSize, -1, INT32_MAX, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "randErrorChance", tsRandErrChance, 0, 10000, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorDivisor", tsRandErrDivisor, 1, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); + TAOS_CHECK_RETURN( + cfgAddInt64(pCfg, "randErrorDivisor", tsRandErrDivisor, 1, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorScope", tsRandErrScope, 0, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); tsNumOfRpcThreads = tsNumOfCores / 2; - tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); + tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, TSDB_MAX_RPC_THREADS); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, CFG_SCOPE_BOTH, CFG_DYN_NONE)); tsNumOfRpcSessions = TRANGE(tsNumOfRpcSessions, 100, 100000); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcSessions", tsNumOfRpcSessions, 1, 100000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 512); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 512, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600 * 7); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsReadTimeout, 64, 24 * 3600 * 7, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 10000000); TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "timeToGetAvailableConn", tsTimeToGetAvailableConn, 20, 1000000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); @@ -865,8 +876,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "numOfRpcThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfRpcThreads = numOfCores / 2; - tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); + tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, TSDB_MAX_RPC_THREADS); pItem->i32 = tsNumOfRpcThreads; pItem->stype = stype; } @@ -878,6 +888,20 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } + pItem = cfgGetItem(pCfg, "shareConnLimit"); + if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 512); + pItem->i32 = tsShareConnLimit; + pItem->stype = stype; + } + + pItem = cfgGetItem(pCfg, "readTimeout"); + if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600 * 7); + pItem->i32 = tsReadTimeout; + pItem->stype = stype; + } + pItem = cfgGetItem(pCfg, "timeToGetAvailableConn"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 1000000); @@ -1083,9 +1107,9 @@ int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope) { int32_t slowScope = 0; - char* scope = NULL; - char *tmp = NULL; - while((scope = strsep(&pScopeStr, "|")) != NULL){ + char *scope = NULL; + char *tmp = NULL; + while ((scope = strsep(&pScopeStr, "|")) != NULL) { taosMemoryFreeClear(tmp); tmp = taosStrdup(scope); if (tmp == NULL) { @@ -1142,13 +1166,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "firstEp"); - SEp firstEp = {0}; + SEp firstEp = {0}; TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? defaultFirstEp : pItem->str, &firstEp)); (void)snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); TAOS_CHECK_RETURN(cfgSetItem(pCfg, "firstEp", tsFirst, pItem->stype, true)); TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "secondEp"); - SEp secondEp = {0}; + SEp secondEp = {0}; TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? defaultFirstEp : pItem->str, &secondEp)); (void)snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port); TAOS_CHECK_RETURN(cfgSetItem(pCfg, "secondEp", tsSecond, pItem->stype, true)); @@ -1252,6 +1276,12 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); tsNumOfRpcSessions = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); + tsShareConnLimit = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "readTimeout"); + tsReadTimeout = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; @@ -1353,6 +1383,12 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); tsNumOfRpcSessions = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); + tsShareConnLimit = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "readTimeout"); + tsReadTimeout = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; @@ -1651,8 +1687,8 @@ static int32_t taosSetAllDebugFlag(SConfig *pCfg, int32_t flag); int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SConfig *pCfg = NULL; if (tsCfg == NULL) { @@ -1724,7 +1760,7 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char * TAOS_CHECK_GOTO(cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE), NULL, _exit); TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "debugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER), NULL, _exit); - TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) ,NULL, _exit); + TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER), NULL, _exit); if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { (void)printf("failed to load cfg since %s\n", tstrerror(code)); @@ -1753,7 +1789,7 @@ _exit: static int32_t taosCheckGlobalCfg() { uint32_t ipv4 = 0; - int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); + int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); if (code) { uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, tstrerror(code)); TAOS_RETURN(TSDB_CODE_RPC_FQDN_ERROR); @@ -1858,7 +1894,7 @@ typedef struct { static int32_t taosCfgSetOption(OptionNameAndVar *pOptions, int32_t optionSize, SConfigItem *pItem, bool isDebugflag) { int32_t code = TSDB_CODE_CFG_NOT_FOUND; - char *name = pItem->name; + char *name = pItem->name; for (int32_t d = 0; d < optionSize; ++d) { const char *optName = pOptions[d].optionName; if (strcasecmp(name, optName) != 0) continue; @@ -2053,8 +2089,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { } case 'f': { if (strcasecmp("fqdn", name) == 0) { - SConfigItem* pFqdnItem = cfgGetItem(pCfg, "fqdn"); - SConfigItem* pServerPortItem = cfgGetItem(pCfg, "serverPort"); + SConfigItem *pFqdnItem = cfgGetItem(pCfg, "fqdn"); + SConfigItem *pServerPortItem = cfgGetItem(pCfg, "serverPort"); SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); if (pFqdnItem == NULL || pServerPortItem == NULL || pFirstEpItem == NULL) { uError("failed to get fqdn or serverPort or firstEp from cfg"); @@ -2069,7 +2105,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SEp firstEp = {0}; + SEp firstEp = {0}; TAOS_CHECK_GOTO( taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp), &lino, _out); @@ -2109,8 +2145,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { } case 'l': { if (strcasecmp("locale", name) == 0) { - SConfigItem* pLocaleItem = cfgGetItem(pCfg, "locale"); - SConfigItem* pCharsetItem = cfgGetItem(pCfg, "charset"); + SConfigItem *pLocaleItem = cfgGetItem(pCfg, "locale"); + SConfigItem *pCharsetItem = cfgGetItem(pCfg, "charset"); if (pLocaleItem == NULL || pCharsetItem == NULL) { uError("failed to get locale or charset from cfg"); code = TSDB_CODE_CFG_NOT_FOUND; @@ -2183,7 +2219,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SEp firstEp = {0}; + SEp firstEp = {0}; TAOS_CHECK_GOTO( taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp), &lino, _out); @@ -2314,7 +2350,7 @@ int32_t taosSetGlobalDebugFlag(int32_t flag) { return taosSetAllDebugFlag(tsCfg, // NOTE: set all command does not change the tmrDebugFlag static int32_t taosSetAllDebugFlag(SConfig *pCfg, int32_t flag) { if (flag < 0) TAOS_RETURN(TSDB_CODE_INVALID_PARA); - if (flag == 0) TAOS_RETURN(TSDB_CODE_SUCCESS); // just ignore + if (flag == 0) TAOS_RETURN(TSDB_CODE_SUCCESS); // just ignore SArray *noNeedToSetVars = NULL; SConfigItem *pItem = NULL; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index af856dc869..1446faab77 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -74,7 +74,7 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_RETRIEVE_IP_WHITE, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 0, @@ -249,7 +249,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 0, @@ -322,7 +322,7 @@ void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_NOTIFY, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 1, diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 7fc9920816..7f802f3837 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -47,7 +47,6 @@ static void *dmStatusThreadFp(void *param) { return NULL; } -extern SMonVloadInfo tsVinfo; static void *dmStatusInfoThreadFp(void *param) { SDnodeMgmt *pMgmt = param; int64_t lastTime = taosGetTimestampMs(); @@ -73,19 +72,6 @@ static void *dmStatusInfoThreadFp(void *param) { } } } - dDebug("begin to lock status info when thread exit"); - if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) { - dError("failed to lock status info lock"); - return NULL; - } - if (tsVinfo.pVloads != NULL) { - taosArrayDestroy(tsVinfo.pVloads); - tsVinfo.pVloads = NULL; - } - if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) { - dError("failed to unlock status info lock"); - return NULL; - } return NULL; } diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index 5e4f7163e7..9f1c292a90 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -219,6 +219,7 @@ int32_t dmInitVars(SDnode *pDnode) { return 0; } +extern SMonVloadInfo tsVinfo; void dmClearVars(SDnode *pDnode) { for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; @@ -254,6 +255,25 @@ void dmClearVars(SDnode *pDnode) { (void)taosThreadRwlockUnlock(&pData->lock); (void)taosThreadRwlockDestroy(&pData->lock); + + dDebug("begin to lock status info when thread exit"); + if (taosThreadMutexLock(&pData->statusInfolock) != 0) { + dError("failed to lock status info lock"); + return; + } + if (tsVinfo.pVloads != NULL) { + taosArrayDestroy(tsVinfo.pVloads); + tsVinfo.pVloads = NULL; + } + if (taosThreadMutexUnlock(&pData->statusInfolock) != 0) { + dError("failed to unlock status info lock"); + return; + } + if (taosThreadMutexDestroy(&pData->statusInfolock) != 0) { + dError("failed to destroy status info lock"); + } + memset(&pData->statusInfolock, 0, sizeof(pData->statusInfolock)); + (void)taosThreadMutexDestroy(&pDnode->mutex); memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index e84d756e0a..28d6113bba 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -267,7 +267,7 @@ _OVER: } if (IsReq(pRpc)) { - SRpcMsg rsp = {.code = code, .info = pRpc->info}; + SRpcMsg rsp = {.code = code, .info = pRpc->info, .msgType = pRpc->msgType + 1}; if (code == TSDB_CODE_MNODE_NOT_FOUND) { dmBuildMnodeRedirectRsp(pDnode, &rsp); } @@ -418,9 +418,12 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = tsShareConnLimit * 2; + rpcInit.shareConn = 1; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.notWaitAvaliableConn = 0; + rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); @@ -466,8 +469,10 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = tsShareConnLimit * 2; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.startReadTimer = 0; + rpcInit.readTimeout = 0; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); @@ -514,8 +519,11 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = tsShareConnLimit * 8; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; + if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); } @@ -569,6 +577,7 @@ int32_t dmInitServer(SDnode *pDnode) { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.compressSize = tsCompressMsgSize; + rpcInit.shareConnLimit = tsShareConnLimit * 16; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 7cbbf762ef..08ebf52ec6 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -237,7 +237,7 @@ static void mndPullupGrant(SMnode *pMnode) { .pCont = pReq, .contLen = contLen, .info.notFreeAhandle = 1, - .info.ahandle = (void *)0x9527}; + .info.ahandle = 0}; // TODO check return value if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) { mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__); diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index 4816df6323..b19d0b8ad0 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -30,9 +30,9 @@ void mndPostProcessQueryMsg(SRpcMsg *pMsg) { (void)qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg); } -int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) { - int32_t code = -1; - SMnode *pMnode = pMsg->info.node; +int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo *pInfo) { + int32_t code = -1; + SMnode *pMnode = pMsg->info.node; SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb}; @@ -67,26 +67,25 @@ int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) { return code; } - -static FORCE_INLINE void mnodeFreeSBatchRspMsg(void* p) { +static FORCE_INLINE void mnodeFreeSBatchRspMsg(void *p) { if (NULL == p) { return; } - SBatchRspMsg* pRsp = (SBatchRspMsg*)p; + SBatchRspMsg *pRsp = (SBatchRspMsg *)p; rpcFreeCont(pRsp->msg); } int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { - int32_t code = 0; - int32_t rspSize = 0; - SBatchReq batchReq = {0}; - SBatchMsg req = {0}; + int32_t code = 0; + int32_t rspSize = 0; + SBatchReq batchReq = {0}; + SBatchMsg req = {0}; SBatchRspMsg rsp = {0}; - SBatchRsp batchRsp = {0}; - SRpcMsg reqMsg = *pMsg; - void *pRsp = NULL; - SMnode *pMnode = pMsg->info.node; + SBatchRsp batchRsp = {0}; + SRpcMsg reqMsg = *pMsg; + void *pRsp = NULL; + SMnode *pMnode = pMsg->info.node; if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -94,7 +93,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { goto _exit; } - int32_t msgNum = taosArrayGetSize(batchReq.pMsgs); + int32_t msgNum = taosArrayGetSize(batchReq.pMsgs); if (msgNum >= MAX_META_MSG_IN_BATCH) { code = TSDB_CODE_INVALID_MSG; mError("too many msgs %d in mnode batch meta req", msgNum); @@ -108,7 +107,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { } for (int32_t i = 0; i < msgNum; ++i) { - SBatchMsg* req = taosArrayGet(batchReq.pMsgs, i); + SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i); reqMsg.msgType = req->msgType; reqMsg.pCont = req->msg; diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 767796977c..60442c34ee 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -226,7 +226,7 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } if (TSDB_CODE_SUCCESS != pOperator->pTaskInfo->code) { - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(pOperator->pTaskInfo->code)); T_LONG_JMP(pTaskInfo->env, pOperator->pTaskInfo->code); } if (taosArrayGetSize(pExchangeInfo->pResultBlockList) == 0) { @@ -530,6 +530,16 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int32_t index = pWrapper->sourceIndex; SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); + + int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); + if (pRpcHandle != NULL) { + int32_t ret = asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + if (ret != 0) { + qDebug("failed to free rpc handle, code:%s, %p", tstrerror(ret), pExchangeInfo); + } + *pRpcHandle = -1; + } + if (!pSourceDataInfo) { return terrno; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 885afe6411..548da84d9f 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3296,8 +3296,44 @@ static int32_t rewriteIsTrue(SNode* pSrc, SNode** pIsTrue) { return TSDB_CODE_SUCCESS; } +extern int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX]; +static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) { + if (commonType->type < TSDB_DATA_TYPE_NULL || commonType->type >= TSDB_DATA_TYPE_MAX || + newType->type < TSDB_DATA_TYPE_NULL || newType->type >= TSDB_DATA_TYPE_MAX) { + return TSDB_CODE_INVALID_PARA; + } + int8_t type1 = commonType->type; + int8_t type2 = newType->type; + int8_t resultType; + if (type1 < type2) { + resultType = gDisplyTypes[type1][type2]; + } else { + resultType = gDisplyTypes[type2][type1]; + } + if (resultType == -1) { + return TSDB_CODE_SCALAR_CONVERT_ERROR; + } + if (commonType->type == newType->type) { + commonType->bytes = TMAX(commonType->bytes, newType->bytes); + return TSDB_CODE_SUCCESS; + } + if (resultType == commonType->type){ + return TSDB_CODE_SUCCESS; + } + if(resultType == newType->type) { + *commonType = *newType; + return TSDB_CODE_SUCCESS; + } + commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); + if(resultType == TSDB_DATA_TYPE_VARCHAR && (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type))) { + commonType->bytes += TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE]; + } + commonType->type = resultType; + return TSDB_CODE_SUCCESS; + +} + static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseWhen) { - bool first = true; bool allNullThen = true; SNode* pNode = NULL; FOREACH(pNode, pCaseWhen->pWhenThenList) { @@ -3316,10 +3352,18 @@ static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseW continue; } allNullThen = false; - if (first || dataTypeComp(&pCaseWhen->node.resType, &pThenExpr->resType) < 0) { - pCaseWhen->node.resType = pThenExpr->resType; + pCxt->errCode = selectCommonType(&pCaseWhen->node.resType, &pThenExpr->resType); + if(TSDB_CODE_SUCCESS != pCxt->errCode){ + return DEAL_RES_ERROR; + } + } + + SExprNode* pElseExpr = (SExprNode*)pCaseWhen->pElse; + if (NULL != pElseExpr) { + pCxt->errCode = selectCommonType(&pCaseWhen->node.resType, &pElseExpr->resType); + if(TSDB_CODE_SUCCESS != pCxt->errCode) { + return DEAL_RES_ERROR; } - first = false; } if (allNullThen) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index a086d1f367..54794b9044 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1030,6 +1030,31 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { /*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, /*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0}; +int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { + /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ + /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 8, + /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8, + /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8, + /*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8, + /*INT */ 0, 0, 0, 0, 4, 5, 8, 8, 8, 5, 10, 4, 4, 5, 8, 8, -1, -1, -1, -1, 8, + /*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8, + /*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, + /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, + /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8, + /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8, + /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, -1, -1, -1, -1, 10, + /*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8, + /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 8, -1, -1, -1, -1, 8, + /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 8, -1, -1, -1, -1, 8, + /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 8, -1, -1, -1, -1, 8, + /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, -1, -1, -1, -1, 8, + /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, -1, -1, -1, -1, + /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, + /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, + /*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, + /*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20 +}; + int32_t vectorGetConvertType(int32_t type1, int32_t type2) { if (type1 == type2) { return 0; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index a8e747ccd2..b15a6a09d3 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -504,6 +504,10 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { code); // called if drop task rsp received code (void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error + + if (pMsg->handle == NULL) { + qError("sch handle is NULL, may be already released and mem lea"); + } if (pMsg) { taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 5f73b3913f..9230c51554 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -5150,8 +5150,8 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { } char content[256] = {0}; - nBytes = tsnprintf(content, sizeof(content), META_ON_S3_FORMATE, p->pCurrent, p->curChkpId, p->pManifest, p->curChkpId, - "processVer", processId); + nBytes = tsnprintf(content, sizeof(content), META_ON_S3_FORMATE, p->pCurrent, p->curChkpId, p->pManifest, + p->curChkpId, "processVer", processId); if (nBytes <= 0 || nBytes >= sizeof(content)) { code = TSDB_CODE_OUT_OF_RANGE; stError("chkp failed to format meta file: %s, reason: invalid msg", dstDir); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 95ea6944e3..3a4f11ac81 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -114,6 +114,7 @@ typedef struct SExHandle { void* handle; int64_t refId; void* pThrd; + int8_t pThrdIdx; queue q; int8_t inited; SRWLatch latch; @@ -135,57 +136,33 @@ typedef struct SCvtAddr { bool cvt; } SCvtAddr; -typedef struct { - SEpSet epSet; // ip list provided by app - SEpSet origEpSet; - void* ahandle; // handle provided by app - tmsg_t msgType; // message type - int8_t connType; // connection type cli/srv - - STransCtx appCtx; // - STransMsg* pRsp; // for synchronous API - tsem_t* pSem; // for synchronous API - STransSyncMsg* pSyncMsg; // for syncchronous with timeout API - int64_t syncMsgRef; - SCvtAddr cvtAddr; - - int32_t retryMinInterval; - int32_t retryMaxInterval; - int32_t retryStepFactor; - int64_t retryMaxTimeout; - int64_t retryInitTimestamp; - int64_t retryNextInterval; - bool retryInit; - int32_t retryStep; - int8_t epsetRetryCnt; - int32_t retryCode; - - void* task; - int hThrdIdx; -} STransConnCtx; - #pragma pack(push, 1) +typedef struct { + int8_t inUse; + int8_t numOfEps; + SEp eps[]; +} SReqEpSet; + #define TRANS_VER 2 typedef struct { - char version : 4; // RPC version - char comp : 2; // compression algorithm, 0:no compression 1:lz4 - char noResp : 2; // noResp bits, 0: resp, 1: resp - char persist : 2; // persist handle,0: no persit, 1: persist handle - char release : 2; + char version : 4; // RPC version + char comp : 2; // compression algorithm, 0:no compression 1:lz4 + char noResp : 2; // noResp bits, 0: resp, 1: resp + char withUserInfo : 2; // 0: sent user info or not char secured : 2; char spi : 2; char hasEpSet : 2; // contain epset or not, 0(default): no epset, 1: contain epset uint64_t timestamp; - char user[TSDB_UNI_LEN]; int32_t compatibilityVer; uint32_t magicNum; STraceId traceId; - uint64_t ahandle; // ahandle assigned by client - uint32_t code; // del later + int64_t qid; + uint32_t code; // del later uint32_t msgType; int32_t msgLen; + int64_t seqNum; uint8_t content[0]; // message body starts from here } STransMsgHead; @@ -206,6 +183,35 @@ typedef struct { #pragma pack(pop) +int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); +int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); + +int32_t transValidReqEpset(SReqEpSet* pReqEpSet); + +typedef struct { + SReqEpSet* epSet; // ip list provided by app + SReqEpSet* origEpSet; + void* ahandle; // handle provided by app + tmsg_t msgType; // message type + + STransCtx userCtx; // + STransMsg* pRsp; // for synchronous API + tsem_t* pSem; // for synchronous API + STransSyncMsg* pSyncMsg; // for syncchronous with timeout API + int64_t syncMsgRef; + SCvtAddr* pCvtAddr; + + int64_t retryInitTimestamp; + int64_t retryNextInterval; + int64_t retryMaxTimeout; + int32_t retryMinInterval; + int32_t retryMaxInterval; + int32_t retryStepFactor; + int32_t retryStep; + int32_t retryCode; + int8_t retryInit; + int8_t epsetRetryCnt; +} SReqCtx; typedef enum { Normal, Quit, Release, Register, Update, FreeById } STransMsgType; typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } ConnStatus; @@ -272,24 +278,24 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); } \ } while (0) -#define ASYNC_CHECK_HANDLE(exh1, id) \ - do { \ - if (id > 0) { \ - SExHandle* exh2 = transAcquireExHandle(transGetSvrRefMgt(), id); \ - if (exh2 == NULL || id != exh2->refId) { \ - tDebug("ref:%" PRId64 " already released", id); \ - code = terrno; \ - goto _return1; \ - } \ - } else { \ - tDebug("invalid handle to release"); \ - goto _return2; \ - } \ +#define ASYNC_CHECK_HANDLE(idMgt, id, exh1) \ + do { \ + if (id > 0) { \ + SExHandle* exh2 = transAcquireExHandle(idMgt, id); \ + if (exh2 == NULL || exh1 != exh2 || (exh2 != NULL && exh2->refId != id)) { \ + tError("handle not match, exh1:%p, exh2:%p, refId:%"PRId64"", exh1, exh2, id); \ + code = TSDB_CODE_INVALID_MSG; \ + goto _return1; \ + } \ + } else { \ + tError("invalid handle to release"); \ + goto _return2; \ + } \ } while (0) int32_t transInitBuffer(SConnBuffer* buf); int32_t transClearBuffer(SConnBuffer* buf); -int32_t transDestroyBuffer(SConnBuffer* buf); +void transDestroyBuffer(SConnBuffer* buf); int32_t transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf); bool transReadComplete(SConnBuffer* connBuf); int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf); @@ -300,30 +306,31 @@ int32_t transSetConnOption(uv_tcp_t* stream, int keepalive); void transRefSrvHandle(void* handle); void transUnrefSrvHandle(void* handle); -void transRefCliHandle(void* handle); -void transUnrefCliHandle(void* handle); +void transRefCliHandle(void* handle); +int32_t transUnrefCliHandle(void* handle); +int32_t transGetRefCount(void* handle); int32_t transReleaseCliHandle(void* handle); int32_t transReleaseSrvHandle(void* handle); -int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx); -int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp); -int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp, int8_t* epUpdated, +int32_t transSendRequest(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* pCtx); +int32_t transSendRecv(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp); +int32_t transSendRecvWithTimeout(void* pInit, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs); -int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId); -int32_t transFreeConnById(void* shandle, int64_t transpointId); +int32_t transSendRequestWithId(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId); +int32_t transFreeConnById(void* pInit, int64_t transpointId); int32_t transSendResponse(const STransMsg* msg); int32_t transRegisterMsg(const STransMsg* msg); -int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn); -int32_t transSetIpWhiteList(void* shandle, void* arg, FilteFunc* func); +int32_t transSetDefaultAddr(void* pInit, const char* ip, const char* fqdn); +int32_t transSetIpWhiteList(void* pInit, void* arg, FilteFunc* func); -int32_t transSockInfo2Str(struct sockaddr* sockname, char* dst); +void transSockInfo2Str(struct sockaddr* sockname, char* dst); int32_t transAllocHandle(int64_t* refId); -void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); -void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); +void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); +void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); void transCloseClient(void* arg); void transCloseServer(void* arg); @@ -336,33 +343,29 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key); void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); // request list -typedef struct STransReq { - queue q; - uv_write_t wreq; -} STransReq; - -void transReqQueueInit(queue* q); -void* transReqQueuePush(queue* q); -void* transReqQueueRemove(void* arg); -void transReqQueueClear(queue* q); +typedef struct SWriteReq { + queue node; // req queue node + void* conn; +} SWriteReq; // queue sending msgs typedef struct { - SArray* q; - void (*freeFunc)(const void* arg); + queue node; + void (*freeFunc)(void* arg); + int32_t size; } STransQueue; /* * init queue * note: queue'size is small, default 1 */ -int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); +int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(void* arg)); /* * put arg into queue * if queue'size > 1, return false; else return true */ -bool transQueuePush(STransQueue* queue, void* arg); +void transQueuePush(STransQueue* queue, void* arg); /* * the size of queue */ @@ -375,10 +378,25 @@ void* transQueuePop(STransQueue* queue); * get ith from queue */ void* transQueueGet(STransQueue* queue, int i); +/* + * head elm from queue + */ + +void* tranQueueHead(STransQueue* q); +/* + * remove all match elm from queue + */ +void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size); /* * rm ith from queue */ + void* transQueueRm(STransQueue* queue, int i); +/* + * remove el from queue + */ + +void transQueueRemove(STransQueue* q, void* e); /* * queue empty or not */ @@ -418,9 +436,9 @@ void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)); SDelayTask* transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs); void transDQCancel(SDelayQueue* queue, SDelayTask* task); -bool transEpSetIsEqual(SEpSet* a, SEpSet* b); +bool transReqEpsetIsEqual(SReqEpSet* a, SReqEpSet* b); -bool transEpSetIsEqual2(SEpSet* a, SEpSet* b); +bool transCompareReqAndUserEpset(SReqEpSet* a, SEpSet* b); /* * init global func */ @@ -432,14 +450,14 @@ void transPrintEpSet(SEpSet* pEpSet); void transFreeMsg(void* msg); int32_t transCompressMsg(char* msg, int32_t len); -int32_t transDecompressMsg(char** msg, int32_t len); +int32_t transDecompressMsg(char** msg, int32_t* len); int32_t transOpenRefMgt(int size, void (*func)(void*)); void transCloseRefMgt(int32_t refMgt); int64_t transAddExHandle(int32_t refMgt, void* p); -int32_t transRemoveExHandle(int32_t refMgt, int64_t refId); +void transRemoveExHandle(int32_t refMgt, int64_t refId); void* transAcquireExHandle(int32_t refMgt, int64_t refId); -int32_t transReleaseExHandle(int32_t refMgt, int64_t refId); +void transReleaseExHandle(int32_t refMgt, int64_t refId); void transDestroyExHandle(void* handle); int32_t transGetRefMgt(); @@ -465,6 +483,33 @@ int32_t subnetDebugInfoToBuf(SubnetUtils* pUtils, char* buf); int32_t transUtilSIpRangeToStr(SIpV4Range* pRange, char* buf); int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); +enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; + +#if defined(WINDOWS) || defined(DARWIN) +#define BUFFER_LIMIT 1 +#define STATE_BUFFER_LIMIT 1 +#else +#define BUFFER_LIMIT 4 +#define STATE_BUFFER_LIMIT 8 +#endif + +#define HEAP_MISS_HIT_LIMIT 100000 +#define READ_TIMEOUT 100000 + +typedef struct { + queue node; // queue for write + queue q; // queue for reqs + uv_write_t wreq; + void* arg; +} SWReqsWrapper; + +int32_t initWQ(queue* wq); +void destroyWQ(queue* wq); +uv_write_t* allocWReqFromWQ(queue* wq, void* arg); + +void freeWReqToWQ(queue* wq, SWReqsWrapper* w); + +int32_t transSetReadOption(uv_handle_t* handle); #ifdef __cplusplus } #endif diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index 703a4dde3e..39afb29342 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -32,8 +32,8 @@ extern "C" { #endif -void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); -void* taosInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); +void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); +void* taosInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); void taosCloseServer(void* arg); void taosCloseClient(void* arg); @@ -70,12 +70,16 @@ typedef struct { int32_t connLimitNum; int8_t connLimitLock; // 0: no lock. 1. lock int8_t supportBatch; // 0: no batch, 1: support batch - int32_t batchSize; + int32_t shareConnLimit; + int8_t optBatchFetch; int32_t timeToGetConn; int index; void* parent; void* tcphandle; // returned handle from TCP initialization int64_t refId; + int8_t shareConn; + int8_t startReadTimer; + int64_t readTimeout; TdThreadMutex mutex; } SRpcInfo; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 9526c0ee9e..de129773a0 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -15,13 +15,13 @@ #include "transComm.h" -void* (*taosInitHandle[])(uint32_t ip, uint32_t port, char* label, int32_t numOfThreads, void* fp, void* shandle) = { +void* (*taosInitHandle[])(uint32_t ip, uint32_t port, char* label, int32_t numOfThreads, void* fp, void* pInit) = { transInitServer, transInitClient}; void (*taosCloseHandle[])(void* arg) = {transCloseServer, transCloseClient}; void (*taosRefHandle[])(void* handle) = {transRefSrvHandle, transRefCliHandle}; -void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, transUnrefCliHandle}; +void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, NULL}; int (*transReleaseHandle[])(void* handle) = {transReleaseSrvHandle, transReleaseCliHandle}; @@ -42,6 +42,8 @@ void* rpcOpen(const SRpcInit* pInit) { if (pRpc == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _end); } + + pRpc->startReadTimer = pInit->startReadTimer; if (pInit->label) { int len = strlen(pInit->label) > sizeof(pRpc->label) ? sizeof(pRpc->label) : strlen(pInit->label); memcpy(pRpc->label, pInit->label, len); @@ -77,7 +79,15 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->connLimitLock = pInit->connLimitLock; pRpc->supportBatch = pInit->supportBatch; - pRpc->batchSize = pInit->batchSize; + pRpc->shareConnLimit = pInit->shareConnLimit; + if (pRpc->shareConnLimit <= 0) { + pRpc->shareConnLimit = BUFFER_LIMIT; + } + + pRpc->readTimeout = pInit->readTimeout; + if (pRpc->readTimeout < 0) { + pRpc->readTimeout = INT64_MAX; + } pRpc->numOfThreads = pInit->numOfThreads > TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS : pInit->numOfThreads; if (pRpc->numOfThreads <= 0) { @@ -115,6 +125,8 @@ void* rpcOpen(const SRpcInit* pInit) { int64_t refId = transAddExHandle(transGetInstMgt(), pRpc); void* tmp = transAcquireExHandle(transGetInstMgt(), refId); pRpc->refId = refId; + + pRpc->shareConn = pInit->shareConn; return (void*)refId; _end: taosMemoryFree(pRpc); @@ -127,9 +139,8 @@ void rpcClose(void* arg) { if (arg == NULL) { return; } - TAOS_UNUSED(transRemoveExHandle(transGetInstMgt(), (int64_t)arg)); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)arg)); - + transRemoveExHandle(transGetInstMgt(), (int64_t)arg); + transReleaseExHandle(transGetInstMgt(), (int64_t)arg); tInfo("end to close rpc"); return; } @@ -175,29 +186,29 @@ void* rpcReallocCont(void* ptr, int64_t contLen) { return st + TRANS_MSG_OVERHEAD; } -int32_t rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid) { - return transSendRequest(shandle, pEpSet, pMsg, NULL); +int32_t rpcSendRequest(void* pInit, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid) { + return transSendRequest(pInit, pEpSet, pMsg, NULL); } -int32_t rpcSendRequestWithCtx(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { +int32_t rpcSendRequestWithCtx(void* pInit, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0 || pRid == NULL) { - return transSendRequest(shandle, pEpSet, pMsg, pCtx); + return transSendRequest(pInit, pEpSet, pMsg, pCtx); } else { - return transSendRequestWithId(shandle, pEpSet, pMsg, pRid); + return transSendRequestWithId(pInit, pEpSet, pMsg, pRid); } } -int32_t rpcSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { - return transSendRequestWithId(shandle, pEpSet, pReq, transpointId); +int32_t rpcSendRequestWithId(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { + return transSendRequestWithId(pInit, pEpSet, pReq, transpointId); } -int32_t rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) { - return transSendRecv(shandle, pEpSet, pMsg, pRsp); +int32_t rpcSendRecv(void* pInit, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) { + return transSendRecv(pInit, pEpSet, pMsg, pRsp); } -int32_t rpcSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp, int8_t* epUpdated, +int32_t rpcSendRecvWithTimeout(void* pInit, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { - return transSendRecvWithTimeout(shandle, pEpSet, pMsg, pRsp, epUpdated, timeoutMs); + return transSendRecvWithTimeout(pInit, pEpSet, pMsg, pRsp, epUpdated, timeoutMs); } -int32_t rpcFreeConnById(void* shandle, int64_t connId) { return transFreeConnById(shandle, connId); } +int32_t rpcFreeConnById(void* pInit, int64_t connId) { return transFreeConnById(pInit, connId); } int32_t rpcSendResponse(const SRpcMsg* pMsg) { return transSendResponse(pMsg); } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c3f9819119..18bedab5c7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -13,8 +13,10 @@ */ // clang-format off +#include "taoserror.h" #include "transComm.h" #include "tmisce.h" +#include "transLog.h" // clang-format on typedef struct { @@ -23,9 +25,9 @@ typedef struct { } SMsgList; typedef struct SConnList { - queue conns; - int32_t size; - SMsgList* list; + queue conns; + int32_t size; + int32_t totaSize; } SConnList; typedef struct { @@ -47,23 +49,23 @@ typedef struct { queue wq; queue listq; int32_t wLen; - int32_t batchSize; // + int32_t shareConnLimit; // int32_t batch; SCliBatchList* pList; } SCliBatch; typedef struct SCliConn { - T_REF_DECLARE() + int32_t ref; uv_connect_t connReq; uv_stream_t* stream; - queue wreqQueue; uv_timer_t* timer; // read timer, forbidden void* hostThrd; SConnBuffer readBuf; - STransQueue cliMsgs; + STransQueue reqsToSend; + STransQueue reqsSentOut; queue q; SConnList* list; @@ -76,6 +78,9 @@ typedef struct SCliConn { SDelayTask* task; + HeapNode node; // for heap + int8_t inHeap; + int32_t reqRefCnt; uint32_t clientIp; uint32_t serverIp; @@ -83,20 +88,53 @@ typedef struct SCliConn { char src[32]; char dst[32]; - int64_t refId; + char* ipStr; + int32_t port; + + int64_t seq; + + int8_t registered; + int8_t connnected; + SHashObj* pQTable; + int8_t userInited; + void* pInitUserReq; + + void* heap; // point to req conn heap + int32_t heapMissHit; + int64_t lastAddHeapTime; + int8_t forceDelFromHeap; + + uv_buf_t* buf; + int32_t bufSize; + int32_t readerStart; + + queue wq; // uv_write_t queue + + queue batchSendq; + int8_t inThreadSendq; + } SCliConn; -typedef struct SCliMsg { - STransConnCtx* ctx; - STransMsg msg; - queue q; - STransMsgType type; +typedef struct { + SCliConn* conn; + void* arg; +} SReqState; - int64_t refId; - uint64_t st; - int sent; //(0: no send, 1: alread sent) - queue seqq; -} SCliMsg; +typedef struct { + int64_t seq; + int32_t msgType; +} SFiterArg; +typedef struct SCliReq { + SReqCtx* ctx; + queue q; + STransMsgType type; + uint64_t st; + int64_t seq; + int32_t sent; //(0: no send, 1: alread sent) + STransMsg msg; + int8_t inRetry; + +} SCliReq; typedef struct SCliThrd { TdThread thread; // tid @@ -113,18 +151,28 @@ typedef struct SCliThrd { SDelayQueue* timeoutQueue; SDelayQueue* waitConnQueue; uint64_t nextTimeout; // next timeout - STrans* pTransInst; // + STrans* pInst; // - int connCount; void (*destroyAhandleFp)(void* ahandle); SHashObj* fqdn2ipCache; - SCvtAddr cvtAddr; + SCvtAddr* pCvtAddr; SHashObj* failFastCache; SHashObj* batchCache; + SHashObj* connHeapCache; - SCliMsg* stopMsg; + SCliReq* stopMsg; bool quit; + + int32_t (*initCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + int32_t (*notifyCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + int32_t (*notifyExceptCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + + SHashObj* pIdConnTable; // + + SArray* pQIdBuf; // tmp buf to avoid alloc buf; + queue batchSendSet; + int8_t thrdInited; } SCliThrd; typedef struct SCliObj { @@ -144,14 +192,22 @@ typedef struct { // conn pool // add expire timeout and capacity limit -static void* createConnPool(int size); -static void* destroyConnPool(SCliThrd* thread); -static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); -static void addConnToPool(void* pool, SCliConn* conn); -static void doCloseIdleConn(void* param); - +static void* createConnPool(int size); +static void* destroyConnPool(SCliThrd* thread); +static void addConnToPool(void* pool, SCliConn* conn); +static void doCloseIdleConn(void* param); +static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); +static void cliBatchSendCb(uv_write_t* req, int status); +void cliBatchSendImpl(SCliConn* pConn); +static int32_t cliBatchSend(SCliConn* conn, int8_t direct); +void cliConnCheckTimoutMsg(SCliConn* conn); +bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer static void cliConnTimeout(uv_timer_t* handle); + +void cliConnTimeout__checkReq(uv_timer_t* handle); // register timer for read static void cliReadTimeoutCb(uv_timer_t* handle); // register timer in each thread to clear expire conn @@ -161,70 +217,75 @@ static FORCE_INLINE void cliAllocRecvBufferCb(uv_handle_t* handle, size_t sugges // callback after recv nbytes from socket static void cliRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf); // callback after send data to socket -static void cliSendCb(uv_write_t* req, int status); +// static void cliSendCb(uv_write_t* req, int status); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); -static void cliIdleCb(uv_idle_t* handle); - -static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); -static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); -static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); +static void destroyCliConnQTable(SCliConn* conn); -static int32_t allocConnRef(SCliConn* conn, bool update); +static void cliHandleException(SCliConn* conn); -static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); +static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); +void cliResetConnTimer(SCliConn* conn); -static int32_t cliCreateConn(SCliThrd* thrd, SCliConn** pCliConn); -static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); -static void cliDestroy(uv_handle_t* handle); -static void cliSend(SCliConn* pConn); -static void cliSendBatch(SCliConn* pConn); -static void cliDestroyConnMsgs(SCliConn* conn, bool destroy); +static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); +static void cliDestroy(uv_handle_t* handle); -static void doFreeTimeoutMsg(void* param); -static int32_t cliPreCheckSessionLimitForMsg(SCliThrd* pThrd, char* addr, SCliMsg** pMsg); +static void cliDestroyConnMsgs(SCliConn* conn, bool destroy); + +static void doFreeTimeoutMsg(void* param); static void cliDestroyBatch(SCliBatch* pBatch); // cli util func -static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx); -static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr); +static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx); +static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAddr); -static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp); +static FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* thrd, SCliReq* pReq, STransMsg* resp); static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); static FORCE_INLINE void cliMayUpdateFqdnCache(SHashObj* cache, char* dst); // process data read from server, add decompress etc later -static void cliHandleResp(SCliConn* conn); // handle except about conn -static void cliHandleExcept(SCliConn* conn, int32_t code); -static void cliReleaseUnfinishedMsg(SCliConn* conn); -static void cliHandleFastFail(SCliConn* pConn, int status); -static void doNotifyApp(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code); +static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); // handle req from app -static void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd); +static void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq) { return; } -static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, +static void cliDoReq(queue* h, SCliThrd* pThrd); +static void cliDoBatchReq(queue* h, SCliThrd* pThrd); +static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDoReq, cliDoBatchReq}; + +static void (*cliAsyncHandle[])(SCliThrd* pThrd, SCliReq* pReq) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate, cliHandleFreeById}; -/// static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, -/// NULL,cliHandleUpdate}; -static FORCE_INLINE void destroyCmsg(void* cmsg); +static FORCE_INLINE void destroyReq(void* cmsg); -static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param); -static FORCE_INLINE void destroyCmsgAndAhandle(void* cmsg); -static FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst); -static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); +static FORCE_INLINE void destroyReqWrapper(void* arg, void* param); +static FORCE_INLINE void destroyReqAndAhanlde(void* cmsg); +static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); +static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); + +static int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq); +static int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead); +static int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp); +static int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq); +static int32_t cliHandleState_mayUpdateStateTime(SCliConn* pConn, SCliReq* pReq); + +int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); + +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); +static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); +static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); // thread obj static int32_t createThrdObj(void* trans, SCliThrd** pThrd); @@ -233,11 +294,49 @@ static void destroyThrdObj(SCliThrd* pThrd); int32_t cliSendQuit(SCliThrd* thrd); static void cliWalkCb(uv_handle_t* handle, void* arg); +static void cliWalkCb(uv_handle_t* handle, void* arg); + +static FORCE_INLINE int32_t destroyAllReqs(SCliConn* SCliConn); + +typedef struct SListFilterArg { + int64_t id; + STrans* pInst; +} SListFilterArg; + +static FORCE_INLINE bool filterAllReq(void* key, void* arg); +static FORCE_INLINE bool filerBySeq(void* key, void* arg); +static FORCE_INLINE bool filterByQid(void* key, void* arg); +static FORCE_INLINE bool filterToDebug_timeoutMsg(void* key, void* arg); +static FORCE_INLINE bool filterToRmTimoutReq(void* key, void* arg); +static FORCE_INLINE bool filterTimeoutReq(void* key, void* arg); + +static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn); +typedef struct { + void* p; + HeapNode node; +} SHeapNode; +typedef struct { + // void* p; + Heap* heap; + int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b); + int64_t lastUpdateTs; + int64_t lastConnFailTs; +} SHeap; + +int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); +int32_t transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); +void transHeapDestroy(SHeap* heap); +int32_t transHeapGet(SHeap* heap, SCliConn** p); +int32_t transHeapInsert(SHeap* heap, SCliConn* p); +int32_t transHeapDelete(SHeap* heap, SCliConn* p); +int32_t transHeapBalance(SHeap* heap, SCliConn* p); +int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p); + #define CLI_RELEASE_UV(loop) \ do { \ - TAOS_UNUSED(uv_walk(loop, cliWalkCb, NULL)); \ - TAOS_UNUSED(uv_run(loop, UV_RUN_DEFAULT)); \ - TAOS_UNUSED(uv_loop_close(loop)); \ + uv_walk(loop, cliWalkCb, NULL); \ + (TAOS_UNUSED(uv_run(loop, UV_RUN_DEFAULT))); \ + (TAOS_UNUSED(uv_loop_close(loop))); \ } while (0); // snprintf may cause performance problem @@ -251,54 +350,9 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); } while (0) #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) -#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label) +#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pInst))->label) -#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ - do { \ - int i = 0, sz = transQueueSize(&conn->cliMsgs); \ - for (; i < sz; i++) { \ - pMsg = transQueueGet(&conn->cliMsgs, i); \ - if (pMsg->msg.msgType != TDMT_SCH_DROP_TASK && pMsg->ctx != NULL && (uint64_t)pMsg->ctx->ahandle == ahandle) { \ - break; \ - } \ - } \ - if (i == sz) { \ - pMsg = NULL; \ - } else { \ - pMsg = transQueueRm(&conn->cliMsgs, i); \ - } \ - } while (0) - -#define CONN_GET_NEXT_SENDMSG(conn) \ - do { \ - int i = 0; \ - do { \ - pCliMsg = transQueueGet(&conn->cliMsgs, i++); \ - if (pCliMsg && 0 == pCliMsg->sent) { \ - break; \ - } \ - } while (pCliMsg != NULL); \ - if (pCliMsg == NULL) { \ - goto _RETURN; \ - } \ - } while (0) - -#define CONN_SET_PERSIST_BY_APP(conn) \ - do { \ - if (conn->status == ConnNormal) { \ - conn->status = ConnAcquire; \ - transRefCliHandle(conn); \ - } \ - } while (0) - -#define CONN_NO_PERSIST_BY_APP(conn) \ - (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) -#define CONN_RELEASE_BY_SERVER(conn) \ - (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) - -#define REQUEST_NO_RESP(msg) ((msg)->info.noResp == 1) -#define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1) -#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release) +#define REQUEST_NO_RESP(msg) ((msg)->info.noResp == 1) #define EPSET_IS_VALID(epSet) ((epSet) != NULL && (epSet)->numOfEps >= 0 && (epSet)->inUse >= 0) #define EPSET_GET_SIZE(epSet) (epSet)->numOfEps @@ -314,310 +368,428 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); static void* cliWorkThread(void* arg); -static void cliReleaseUnfinishedMsg(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; - - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* msg = transQueueGet(&conn->cliMsgs, i); - if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { - if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { - conn->ctx.freeFunc(msg->ctx->ahandle); - } else if (msg->msg.info.notFreeAhandle == 0 && msg->ctx->ahandle != NULL && pThrd->destroyAhandleFp != NULL) { - tDebug("%s conn %p destroy unfinished ahandle %p", CONN_GET_INST_LABEL(conn), conn, msg->ctx->ahandle); - pThrd->destroyAhandleFp(msg->ctx->ahandle); - } +int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { + uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; + if (timer == NULL) { + timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + if (timer == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tDebug("no available timer, create a timer %p", timer); + int ret = uv_timer_init(pThrd->loop, timer); + if (ret != 0) { + tError("conn %p failed to init timer %p since %s", pConn, timer, uv_err_name(ret)); + return TSDB_CODE_THIRDPARTY_ERROR; } - destroyCmsg(msg); } - transQueueClear(&conn->cliMsgs); - memset(&conn->ctx, 0, sizeof(conn->ctx)); + timer->data = pConn; + pConn->timer = timer; + return 0; } -void cliResetTimer(SCliThrd* pThrd, SCliConn* conn) { +void cliResetConnTimer(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; if (conn->timer) { if (uv_is_active((uv_handle_t*)conn->timer)) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); TAOS_UNUSED(uv_timer_stop(conn->timer)); } if (taosArrayPush(pThrd->timerList, &conn->timer) == NULL) { - tError("failed to push timer %p to list, reason:%s", conn->timer, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - conn->timer = NULL; - return; + tError("%s conn %p failed to push timer %p to list since %s", CONN_GET_INST_LABEL(conn), conn, conn->timer, + tstrerror(terrno)); } conn->timer->data = NULL; conn->timer = NULL; } } -bool cliMaySendCachedMsg(SCliConn* conn) { - if (!transQueueEmpty(&conn->cliMsgs)) { - SCliMsg* pCliMsg = NULL; - CONN_GET_NEXT_SENDMSG(conn); - cliSend(conn); - return true; + +void cliConnMayUpdateTimer(SCliConn* conn, int64_t timeout) { + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + if (pInst->startReadTimer == 0) { + return; + } + // reset previous timer + if (conn->timer != NULL) { + // reset previous timer + cliResetConnTimer(conn); + } + int32_t reqsSentNum = transQueueSize(&conn->reqsSentOut); + if (reqsSentNum == 0) { + // no need to set timer + return; + } + + // start a new timer + if (cliGetConnTimer(conn->hostThrd, conn) != 0) { + return; + } + int ret = uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); + if (ret != 0) { + tError("%s conn %p failed to start timer %p since %s", CONN_GET_INST_LABEL(conn), conn, conn->timer, + uv_err_name(ret)); } - return false; -_RETURN: - return false; } -bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { - if (refId == 0) return false; - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("release conn %p, refId: %" PRId64 "", conn, refId); + +void destroyCliConnQTable(SCliConn* conn) { + SCliThrd* thrd = conn->hostThrd; + int32_t code = 0; + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter != NULL) { + int64_t* qid = taosHashGetKey(pIter, NULL); + STransCtx* ctx = pIter; + transCtxCleanup(ctx); + pIter = taosHashIterate(conn->pQTable, pIter); + + TAOS_UNUSED(taosHashRemove(thrd->pIdConnTable, qid, sizeof(*qid))); + + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); + } + taosHashCleanup(conn->pQTable); + conn->pQTable = NULL; +} + +static bool filteBySeq(void* key, void* arg) { + SFiterArg* targ = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->seq == targ->seq && pReq->msg.msgType + 1 == targ->msgType) { + return true; + } else { return false; } - taosWLockLatch(&exh->latch); - if (exh->handle == NULL) exh->handle = conn; - exh->inited = 1; - exh->pThrd = conn->hostThrd; - if (!QUEUE_IS_EMPTY(&exh->q)) { - queue* h = QUEUE_HEAD(&exh->q); - QUEUE_REMOVE(h); - taosWUnLockLatch(&exh->latch); - SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); - transCtxMerge(&conn->ctx, &t->ctx->appCtx); - TAOS_UNUSED(transQueuePush(&conn->cliMsgs, t)); - tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - cliSend(conn); - return true; +} +int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** pReq) { + int32_t code = 0; + queue set; + QUEUE_INIT(&set) + + SFiterArg arg = {.seq = seq, .msgType = msgType}; + transQueueRemoveByFilter(&conn->reqsSentOut, filteBySeq, &arg, &set, 1); + + if (QUEUE_IS_EMPTY(&set)) { + return TSDB_CODE_OUT_OF_RANGE; } - taosWUnLockLatch(&exh->latch); - tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - return false; + + queue* e = QUEUE_HEAD(&set); + SCliReq* p = QUEUE_DATA(e, SCliReq, q); + + *pReq = p; + return 0; } -void cliHandleResp(SCliConn* conn) { +int8_t cliMayRecycleConn(SCliConn* conn) { + int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; + STrans* pInst = pThrd->pInst; - cliResetTimer(pThrd, conn); + tTrace("%s conn %p in-process req summary:reqsToSend:%d, reqsSentOut:%d, statusTableSize:%d", + CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), transQueueSize(&conn->reqsSentOut), + taosHashGetSize(conn->pQTable)); + + if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && + taosHashGetSize(conn->pQTable) == 0) { + cliResetConnTimer(conn); + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tstrerror(code)); + return 1; + } else { + if (code != 0) { + tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tstrerror(code)); + } + } + addConnToPool(pThrd->pool, conn); + return 1; + } else if ((transQueueSize(&conn->reqsToSend) == 0) && (transQueueSize(&conn->reqsSentOut) == 0) && + (taosHashGetSize(conn->pQTable) != 0)) { + tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn); + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } else { + SCliConn* topConn = NULL; + if (conn->heap != NULL) { + code = transHeapGet(conn->heap, &topConn); + if (code != 0) { + tDebug("%s conn %p failed to get top conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + return 0; + } + + if (topConn == conn) { + return 0; + } + int32_t topReqs = transQueueSize(&topConn->reqsSentOut) + transQueueSize(&topConn->reqsToSend); + int32_t currReqs = transQueueSize(&conn->reqsSentOut) + transQueueSize(&conn->reqsToSend); + if (topReqs <= currReqs) { + tTrace("%s conn %p not balance conn heap since top conn has less req, topConnReqs:%d, currConnReqs:%d", + CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); + return 0; + } else { + tDebug("%s conn %p do balance conn heap since top conn has more reqs, topConnReqs:%d, currConnReqs:%d", + CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } + } + } + return 0; +} + +bool filterByQid(void* key, void* arg) { + int64_t* qid = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + + if (pReq->msg.info.qId == *qid) { + return true; + } else { + return false; + } +} +int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHead) { + pResp->contLen = transContLenFromMsg(pHead->msgLen); + pResp->pCont = transContFromHead((char*)pHead); + pResp->code = pHead->code; + pResp->msgType = pHead->msgType; + if (pResp->info.ahandle == 0) { + pResp->info.ahandle = (pReq && pReq->ctx) ? pReq->ctx->ahandle : NULL; + } + pResp->info.traceId = pHead->traceId; + pResp->info.hasEpSet = pHead->hasEpSet; + pResp->info.cliVer = htonl(pHead->compatibilityVer); + pResp->info.seqNum = taosHton64(pHead->seqNum); + + int64_t qid = taosHton64(pHead->qid); + pResp->info.handle = (void*)qid; + return 0; +} +int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { + int64_t qId = taosHton64(pHead->qid); + STraceId* trace = &pHead->traceId; + int64_t seqNum = taosHton64(pHead->seqNum); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%" PRId64 ", sid:%" PRId64 "", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, + qId); + + STransCtx* p = taosHashGet(conn->pQTable, &qId, sizeof(qId)); + transCtxCleanup(p); + + code = taosHashRemove(conn->pQTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("%s conn %p failed to release req:%" PRId64 " from conn", CONN_GET_INST_LABEL(conn), conn, qId); + } + + code = taosHashRemove(pThrd->pIdConnTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("%s conn %p failed to release req:%" PRId64 " from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); + } + + tDebug("%s %p reqToSend:%d, sentOut:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), + transQueueSize(&conn->reqsSentOut)); + + queue set; + QUEUE_INIT(&set); + transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); + transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); + + transReleaseExHandle(transGetRefMgt(), qId); + transRemoveExHandle(transGetRefMgt(), qId); + + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + QUEUE_REMOVE(el); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + + STraceId* trace = &pReq->msg.info.traceId; + tGDebug("start to free msg %p", pReq); + destroyReqWrapper(pReq, pThrd); + } + taosMemoryFree(pHead); + return 1; + } + return 0; +} +int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp) { + int32_t code = 0; + int64_t qId = taosHton64(pHead->qid); + if (qId == 0) { + return 0; + } + + STransCtx* pCtx = taosHashGet(conn->pQTable, &qId, sizeof(qId)); + if (pCtx == 0) { + return TSDB_CODE_RPC_NO_STATE; + } + pCtx->st = taosGetTimestampUs(); + STraceId* trace = &pHead->traceId; + pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); + tGDebug("%s conn %p %s received from %s, local info:%s, sid:%" PRId64 ", create ahandle %p by %s", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, qId, pResp->info.ahandle, + TMSG_INFO(pHead->msgType)); + return 0; +} + +static FORCE_INLINE void cliConnClearInitUserMsg(SCliConn* conn) { + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } +} +void cliHandleResp(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + cliConnClearInitUserMsg(conn); + SCliReq* pReq = NULL; STransMsgHead* pHead = NULL; - - int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; - int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, resetBuf); - if (msgLen <= 0) { + int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); + if (msgLen < 0) { taosMemoryFree(pHead); - tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + tWarn("%s conn %p recv invalid packet", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb + code = pThrd->notifyExceptCb(pThrd, NULL, NULL); + if (code != 0) { + tError("%s conn %p failed to notify user since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } return; } - if (resetBuf == 0) { - tTrace("%s conn %p not reset read buf", transLabel(pTransInst), conn); - } - - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { + if ((code = transDecompressMsg((char**)&pHead, &msgLen)) < 0) { tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb + return; } + int64_t qId = taosHton64(pHead->qid); pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); - if (cliRecvReleaseReq(conn, pHead)) { - return; - } + int64_t seq = taosHton64(pHead->seqNum); + STransMsg resp = {0}; - STransMsg transMsg = {0}; - transMsg.contLen = transContLenFromMsg(pHead->msgLen); - transMsg.pCont = transContFromHead((char*)pHead); - transMsg.code = pHead->code; - transMsg.msgType = pHead->msgType; - transMsg.info.ahandle = NULL; - transMsg.info.traceId = pHead->traceId; - transMsg.info.hasEpSet = pHead->hasEpSet; - transMsg.info.cliVer = htonl(pHead->compatibilityVer); - - SCliMsg* pMsg = NULL; - STransConnCtx* pCtx = NULL; - if (CONN_NO_PERSIST_BY_APP(conn)) { - pMsg = transQueuePop(&conn->cliMsgs); - - pCtx = pMsg ? pMsg->ctx : NULL; - transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; - tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); - } else { - uint64_t ahandle = (uint64_t)pHead->ahandle; - CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); - if (pMsg == NULL) { - transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType); - tDebug("%s conn %p construct ahandle %p by %s, persist: 1", CONN_GET_INST_LABEL(conn), conn, - transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); - if (!CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { - transMsg.code = TSDB_CODE_RPC_BROKEN_LINK; - transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType)); - tDebug("%s conn %p construct ahandle %p due brokenlink, persist: 1", CONN_GET_INST_LABEL(conn), conn, - transMsg.info.ahandle); - } - } else { - pCtx = pMsg->ctx; - transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; - tDebug("%s conn %p get ahandle %p, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); - } - } - // buf's mem alread translated to transMsg.pCont - if (!CONN_NO_PERSIST_BY_APP(conn)) { - transMsg.info.handle = (void*)conn->refId; - transMsg.info.refId = (int64_t)(void*)conn->refId; - tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); - } - - STraceId* trace = &transMsg.info.traceId; - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, code str:%s", CONN_GET_INST_LABEL(conn), conn, - TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, tstrerror(transMsg.code)); - - if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) { - tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); - transFreeMsg(transMsg.pCont); - return; - } - if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { - tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); - transFreeMsg(transMsg.pCont); - return; - } - - if (pMsg == NULL || (pMsg && pMsg->type != Release)) { - if (cliAppCb(conn, &transMsg, pMsg) != 0) { + if (cliHandleState_mayHandleReleaseResp(conn, pHead)) { + if (cliMayRecycleConn(conn)) { return; } - } - int64_t refId = (pMsg == NULL ? 0 : (int64_t)(pMsg->msg.info.handle)); - tDebug("conn %p msg refId: %" PRId64 "", conn, refId); - destroyCmsg(pMsg); - - if (cliConnSendSeqMsg(refId, conn)) { return; } - - if (cliMaySendCachedMsg(conn) == true) { - return; - } - - if (CONN_NO_PERSIST_BY_APP(conn)) { - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh != NULL) { - exh->handle = NULL; - } - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - - return addConnToPool(pThrd->pool, conn); - } - - TAOS_UNUSED(uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb)); -} -static void cliDestroyMsgInExhandle(int64_t refId) { - if (refId == 0) return; - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh) { - taosWLockLatch(&exh->latch); - while (!QUEUE_IS_EMPTY(&exh->q)) { - queue* h = QUEUE_HEAD(&exh->q); - QUEUE_REMOVE(h); - SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); - destroyCmsg(t); - } - taosWUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - } -} - -void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { - if (transQueueEmpty(&pConn->cliMsgs)) { - if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { - tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); - transUnrefCliHandle(pConn); + code = cliGetReqBySeq(conn, seq, pHead->msgType, &pReq); + if (code == TSDB_CODE_OUT_OF_RANGE) { + code = cliHandleState_mayCreateAhandle(conn, pHead, &resp); + if (code == 0) { + code = cliBuildRespFromCont(NULL, &resp, pHead); + code = cliNotifyCb(conn, NULL, &resp); return; } - } - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - bool once = false; - do { - SCliMsg* pMsg = transQueuePop(&pConn->cliMsgs); - - if (pMsg == NULL && once) { - break; - } - - if (pMsg != NULL && REQUEST_NO_RESP(&pMsg->msg)) { - destroyCmsg(pMsg); - break; - } - - STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; - - STransMsg transMsg = {0}; - transMsg.code = code == -1 ? (pConn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; - transMsg.info.ahandle = NULL; - transMsg.info.cliVer = pTransInst->compatibilityVer; - - if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { - transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, - TMSG_INFO(transMsg.msgType)); - if (transMsg.info.ahandle == NULL) { - int32_t msgType = 0; - transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType); - transMsg.msgType = msgType; - tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, - transMsg.info.ahandle); - } - } else { - transMsg.info.ahandle = (pMsg != NULL && pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL; - } - - if (pCtx == NULL || pCtx->pSem == NULL) { - if (transMsg.info.ahandle == NULL) { - if (pMsg == NULL || REQUEST_NO_RESP(&pMsg->msg) || pMsg->type == Release) { - destroyCmsg(pMsg); - once = true; - continue; - } - } - } - - if (pMsg == NULL || (pMsg && pMsg->type != Release)) { - int64_t refId = (pMsg == NULL ? 0 : (int64_t)(pMsg->msg.info.handle)); - cliDestroyMsgInExhandle(refId); - if (cliAppCb(pConn, &transMsg, pMsg) != 0) { + if (code != 0) { + tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", sid:%" PRId64 + ", the sever may sends repeated response since %s", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); + // TODO: notify cb + taosMemoryFree(pHead); + if (cliMayRecycleConn(conn)) { return; } + return; + } + } else { + code = cliHandleState_mayUpdateStateTime(conn, pReq); + if (code != 0) { + tDebug("%s conn %p failed to update state time sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, + tstrerror(code)); } - destroyCmsg(pMsg); - tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); - } while (!transQueueEmpty(&pConn->cliMsgs)); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); - transUnrefCliHandle(pConn); -} -void cliHandleExcept(SCliConn* conn, int32_t code) { - tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - if (code != TSDB_CODE_RPC_FQDN_ERROR) { - code = -1; } - cliHandleExceptImpl(conn, -1); + + code = cliBuildRespFromCont(pReq, &resp, pHead); + STraceId* trace = &resp.info.traceId; + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%" PRId64 ", sid:%" PRId64 "", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); + + code = cliNotifyCb(conn, pReq, &resp); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + tGWarn("%s msg need retry", CONN_GET_INST_LABEL(conn)); + } else { + destroyReq(pReq); + } + if (cliMayRecycleConn(conn)) { + return; + } + // cliConnCheckTimoutMsg(conn); + + cliConnMayUpdateTimer(conn, pInst->readTimeout * 1000); } void cliConnTimeout(uv_timer_t* handle) { SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + cliResetConnTimer(conn); + return; + } - tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - - TAOS_UNUSED(uv_timer_stop(handle)); - handle->data = NULL; - - cliResetTimer(pThrd, conn); - - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, UV_ECANCELED); + tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn), conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); } -void cliReadTimeoutCb(uv_timer_t* handle) { - // set up timeout cb + +bool filterToRmTimoutReq(void* key, void* arg) { + SListFilterArg* filterArg = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); + if (filterArg && (elapse >= filterArg->pInst->readTimeout)) { + return false; + } else { + return false; + } + } + return false; +} + +bool filterToDebug_timeoutMsg(void* key, void* arg) { + SListFilterArg* filterArg = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); + if (filterArg && elapse >= filterArg->pInst->readTimeout) { + tWarn("req %s timeout, elapse:%" PRId64 "ms", TMSG_INFO(pReq->msg.msgType), elapse); + return false; + } + return false; + } + return false; +} + +void cliConnCheckTimoutMsg(SCliConn* conn) { + int32_t code = 0; + queue set; + QUEUE_INIT(&set); + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + // transQueueRemoveByFilter(&conn->reqsSentOut, filterToDebug_timeoutMsg, NULL, &set, -1); + + if (pInst->startReadTimer == 0) { + return; + } + + if (transQueueSize(&conn->reqsSentOut) == 0) { + return; + } + code = cliConnRemoveTimeoutMsg(conn); + if (code != 0) { + tDebug("%s conn %p do remove timeout msg", CONN_GET_INST_LABEL(conn), conn); + if (!cliMayRecycleConn(conn)) { + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } + } else { + TAOS_UNUSED(cliMayRecycleConn(conn)); + } +} +void cliConnTimeout__checkReq(uv_timer_t* handle) { SCliConn* conn = handle->data; - tTrace("%s conn %p timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - TAOS_UNUSED(uv_read_stop(conn->stream)); - cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); + cliConnCheckTimoutMsg(conn); } void* createConnPool(int size) { @@ -633,25 +805,11 @@ void* destroyConnPool(SCliThrd* pThrd) { SConnList* connList = taosHashIterate((SHashObj*)pool, NULL); while (connList != NULL) { while (!QUEUE_IS_EMPTY(&connList->conns)) { - queue* h = QUEUE_HEAD(&connList->conns); + queue* h = QUEUE_HEAD(&connList->conns); + QUEUE_REMOVE(h); SCliConn* c = QUEUE_DATA(h, SCliConn, q); cliDestroyConn(c, true); } - - SMsgList* msglist = connList->list; - while (!QUEUE_IS_EMPTY(&msglist->msgQ)) { - queue* h = QUEUE_HEAD(&msglist->msgQ); - QUEUE_REMOVE(h); - - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - - transDQCancel(pThrd->waitConnQueue, pMsg->ctx->task); - pMsg->ctx->task = NULL; - - doNotifyApp(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); - } - taosMemoryFree(msglist); - connList = taosHashIterate((SHashObj*)pool, connList); } taosHashCleanup(pool); @@ -659,289 +817,117 @@ void* destroyConnPool(SCliThrd* pThrd) { return NULL; } -static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { +static int32_t getOrCreateConnList(SCliThrd* pThrd, const char* key, SConnList** ppList) { int32_t code = 0; void* pool = pThrd->pool; - STrans* pTranInst = pThrd->pTransInst; size_t klen = strlen(key); SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); if (plist == NULL) { SConnList list = {0}; - if ((code = taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list))) != 0) { - return NULL; + QUEUE_INIT(&list.conns); + code = taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); + if (code != 0) { + return code; } + plist = taosHashGet(pool, key, klen); - - SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); - if (nList == NULL) { - tError("failed to alloc memory for msg list, reason:%s", tstrerror(terrno)); - return NULL; + if (plist == NULL) { + return TSDB_CODE_INVALID_PTR; } - QUEUE_INIT(&nList->msgQ); - nList->numOfConn++; - QUEUE_INIT(&plist->conns); - plist->list = nList; + *ppList = plist; + tDebug("create conn list %p for key %s", plist, key); + } else { + *ppList = plist; + } + return 0; +} +static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** ppConn) { + int32_t code = 0; + void* pool = pThrd->pool; + STrans* pInst = pThrd->pInst; + + SConnList* plist = NULL; + code = getOrCreateConnList(pThrd, key, &plist); + if (code != 0) { + return code; } if (QUEUE_IS_EMPTY(&plist->conns)) { - if (plist->list->numOfConn >= pTranInst->connLimitNum) { - *exceed = true; - return NULL; + if (plist->size >= pInst->connLimitNum) { + return TSDB_CODE_RPC_MAX_SESSIONS; } - plist->list->numOfConn++; - return NULL; + plist->totaSize += 1; + return TSDB_CODE_RPC_NETWORK_BUSY; } - queue* h = QUEUE_TAIL(&plist->conns); - QUEUE_REMOVE(h); + queue* h = QUEUE_HEAD(&plist->conns); plist->size -= 1; + QUEUE_REMOVE(h); SCliConn* conn = QUEUE_DATA(h, SCliConn, q); conn->status = ConnNormal; QUEUE_INIT(&conn->q); - tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); + conn->list = plist; if (conn->task != NULL) { - transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); + SDelayTask* task = conn->task; conn->task = NULL; + transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, task); } - return conn; + + tDebug("conn %p get from pool, pool size:%d, dst:%s", conn, conn->list->size, conn->dstAddr); + + *ppConn = conn; + return 0; } -static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { - int32_t code = 0; - void* pool = pThrd->pool; - STrans* pTransInst = pThrd->pTransInst; - size_t klen = strlen(key); - SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); - if (plist == NULL) { - SConnList list = {0}; - if ((code = taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list))) != 0) { - tError("failed to put key %s to pool, reason:%s", key, tstrerror(code)); - return NULL; - } - plist = taosHashGet(pool, key, klen); +// code +static int32_t cliGetOrCreateConn(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { + // impl later + char* fqdn = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + uint16_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); - SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); - if (nList == NULL) { - tError("failed to alloc memory for msg list, reason:%s", tstrerror(terrno)); - return NULL; - } - - QUEUE_INIT(&nList->msgQ); - nList->numOfConn++; - - QUEUE_INIT(&plist->conns); - plist->list = nList; + int32_t code = cliGetConnFromPool(pThrd, addr, pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + return code; + } else if (code == TSDB_CODE_RPC_NETWORK_BUSY) { + code = cliCreateConn2(pThrd, pReq, pConn); + } else { } - - STraceId* trace = &(*pMsg)->msg.info.traceId; - // no avaliable conn in pool - if (QUEUE_IS_EMPTY(&plist->conns)) { - SMsgList* list = plist->list; - if ((list)->numOfConn >= pTransInst->connLimitNum) { - STraceId* trace = &(*pMsg)->msg.info.traceId; - if (pTransInst->notWaitAvaliableConn || - (pTransInst->noDelayFp != NULL && pTransInst->noDelayFp((*pMsg)->msg.msgType))) { - tDebug("%s msg %s not to send, reason: %s", pTransInst->label, TMSG_INFO((*pMsg)->msg.msgType), - tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); - *pMsg = NULL; - return NULL; - } - - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - if (arg == NULL) { - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; - return NULL; - } - arg->param1 = *pMsg; - arg->param2 = pThrd; - - SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); - if (task == NULL) { - taosMemoryFree(arg); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; - return NULL; - } - (*pMsg)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pTransInst->label, TMSG_INFO((*pMsg)->msg.msgType)); - QUEUE_PUSH(&(list)->msgQ, &(*pMsg)->q); - *pMsg = NULL; - } else { - // send msg in delay queue - if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - if (arg == NULL) { - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; - return NULL; - } - arg->param1 = *pMsg; - arg->param2 = pThrd; - - SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); - if (task == NULL) { - taosMemoryFree(arg); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; - return NULL; - } - - (*pMsg)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pTransInst->label, - TMSG_INFO((*pMsg)->msg.msgType)); - - QUEUE_PUSH(&(list)->msgQ, &(*pMsg)->q); - queue* h = QUEUE_HEAD(&(list)->msgQ); - QUEUE_REMOVE(h); - SCliMsg* ans = QUEUE_DATA(h, SCliMsg, q); - - *pMsg = ans; - - trace = &(*pMsg)->msg.info.traceId; - tGTrace("%s msg %s pop from delay queue, start to send", pTransInst->label, TMSG_INFO((*pMsg)->msg.msgType)); - transDQCancel(pThrd->waitConnQueue, ans->ctx->task); - } - list->numOfConn++; - } - tDebug("%s numOfConn: %d, limit: %d, dst:%s", pTransInst->label, list->numOfConn, pTransInst->connLimitNum, key); - return NULL; - } - - queue* h = QUEUE_TAIL(&plist->conns); - plist->size -= 1; - QUEUE_REMOVE(h); - - SCliConn* conn = QUEUE_DATA(h, SCliConn, q); - conn->status = ConnNormal; - QUEUE_INIT(&conn->q); - tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - - if (conn->task != NULL) { - transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); - conn->task = NULL; - } - return conn; + return code; } static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } - int32_t code = allocConnRef(conn, true); - if (code != 0) { - cliDestroyConn(conn, true); - return; - } SCliThrd* thrd = conn->hostThrd; - cliResetTimer(thrd, conn); - - if (T_REF_VAL_GET(conn) > 1) { - transUnrefCliHandle(conn); - } - - cliDestroyConnMsgs(conn, false); - - if (conn->list == NULL) { + cliResetConnTimer(conn); + if (conn->list == NULL && conn->dstAddr != NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); } - SConnList* pList = conn->list; - SMsgList* msgList = pList->list; - if (!QUEUE_IS_EMPTY(&msgList->msgQ)) { - queue* h = QUEUE_HEAD(&(msgList)->msgQ); - QUEUE_REMOVE(h); - - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - - transDQCancel(thrd->waitConnQueue, pMsg->ctx->task); - pMsg->ctx->task = NULL; - - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); - - conn->status = ConnNormal; - cliSend(conn); - return; - } - conn->status = ConnInPool; + QUEUE_INIT(&conn->q); QUEUE_PUSH(&conn->list->conns, &conn->q); conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - if (conn->list->size >= 10) { + conn->heapMissHit = 0; + + if (conn->list->size >= 5) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; arg->param1 = conn; arg->param2 = thrd; - STrans* pTransInst = thrd->pTransInst; - conn->task = transDQSched(thrd->timeoutQueue, doCloseIdleConn, arg, 10 * CONN_PERSIST_TIME(pTransInst->idleTime)); + STrans* pInst = thrd->pInst; + conn->task = transDQSched(thrd->timeoutQueue, doCloseIdleConn, arg, (10 * CONN_PERSIST_TIME(pInst->idleTime) / 3)); } } -static int32_t allocConnRef(SCliConn* conn, bool update) { - if (update) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); - conn->refId = -1; - } - - SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); - if (exh == NULL) { - return terrno; - } - - exh->refId = transAddExHandle(transGetRefMgt(), exh); - if (exh->refId < 0) { - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - QUEUE_INIT(&exh->q); - taosInitRWLatch(&exh->latch); - exh->handle = conn; - exh->pThrd = conn->hostThrd; - - SExHandle* self = transAcquireExHandle(transGetRefMgt(), exh->refId); - if (self != exh) { - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - conn->refId = exh->refId; - if (conn->refId < 0) { - taosMemoryFree(exh); - } - return 0; -} - -static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { - if (update) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); - conn->refId = -1; - } - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); - if (exh == NULL) { - return -1; - } - taosWLockLatch(&exh->latch); - exh->handle = conn; - exh->pThrd = conn->hostThrd; - taosWUnLockLatch(&exh->latch); - - conn->refId = exh->refId; - - tDebug("conn %p specified by %" PRId64 "", conn, handle); - - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); - return 0; -} static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SCliConn* conn = handle->data; @@ -952,20 +938,28 @@ static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_ } } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; STUB_RAND_NETWORK_ERR(nread); if (handle->data == NULL) { return; } - SCliConn* conn = handle->data; + SCliConn* conn = handle->data; + code = transSetReadOption((uv_handle_t*)handle); + if (code != 0) { + tWarn("%s conn %p failed to set recv opt since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } + SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { pBuf->len += nread; while (transReadComplete(pBuf)) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { - cliHandleExcept(conn, -1); + conn->broken = true; + TAOS_UNUSED(transUnrefCliHandle(conn)); + return; break; } else { cliHandleResp(conn); @@ -983,19 +977,81 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } if (nread < 0) { tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), - T_REF_VAL_GET(conn)); + transGetRefCount(conn)); conn->broken = true; - cliHandleExcept(conn, -1); + TAOS_UNUSED(transUnrefCliHandle(conn)); } } -static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { +static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { int32_t code = 0; + SCliConn* pConn = NULL; + char* ip = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); + + TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); + + code = cliHandleState_mayUpdateState(pConn, pReq); + + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + // code = 0, succ + // code = TSDB_CODE_RPC_NETWORK_UNAVALI, fail fast, and not insert into conn heap + if (code != 0 && code != TSDB_CODE_RPC_NETWORK_UNAVAIL) { + TAOS_CHECK_GOTO(code, NULL, _exception); + } + transQueuePush(&pConn->reqsToSend, &pReq->q); + return cliDoConn(pThrd, pConn); +_exception: + // free conn + return code; +} +void cliDestroyMsg(void* arg) { + queue* e = arg; + SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); + if (pReq->msg.info.notFreeAhandle == 0 && pReq->ctx->ahandle != 0) { + // taosMemoryFree(pReq->ctx->ahandle); + } + destroyReq(pReq); +} +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int32_t port) { + int32_t code = 0; + int32_t lino = 0; + + STrans* pInst = pThrd->pInst; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { - return terrno; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); } + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + conn->hostThrd = pThrd; + conn->dstAddr = taosStrdup(addr); + conn->ipStr = taosStrdup(ip); + conn->port = port; + if (conn->dstAddr == NULL || conn->ipStr == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); + } + + conn->status = ConnNormal; + conn->broken = false; + QUEUE_INIT(&conn->q); + + TAOS_CHECK_GOTO(transQueueInit(&conn->reqsToSend, cliDestroyMsg), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqsSentOut, cliDestroyMsg), NULL, _failed); + + TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); + + conn->hostThrd = pThrd; + conn->seq = 0; + + conn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (conn->pQTable == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _failed); + } + + TAOS_CHECK_GOTO(cliGetConnTimer(pThrd, conn), &lino, _failed); + // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (conn->stream == NULL) { @@ -1009,353 +1065,437 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_CHECK_GOTO(code, NULL, _failed); } - conn->stream->data = conn; - uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; - if (timer == NULL) { - timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - if (timer == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _failed); - } - - tDebug("no available timer, create a timer %p", timer); - TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); + conn->bufSize = pInst->shareConnLimit; + conn->buf = (uv_buf_t*)taosMemoryCalloc(1, pInst->shareConnLimit * sizeof(uv_buf_t)); + if (conn->buf == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _failed); } - timer->data = conn; - conn->timer = timer; + TAOS_CHECK_GOTO(initWQ(&conn->wq), NULL, _failed); + + QUEUE_INIT(&conn->batchSendq); + + conn->stream->data = conn; conn->connReq.data = conn; - transReqQueueInit(&conn->wreqQueue); - - TAOS_CHECK_GOTO(transQueueInit(&conn->cliMsgs, NULL), NULL, _failed); - - TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); - - QUEUE_INIT(&conn->q); - conn->hostThrd = pThrd; - conn->status = ConnNormal; - conn->broken = false; - transRefCliHandle(conn); - - TAOS_UNUSED(atomic_add_fetch_32(&pThrd->connCount, 1)); - - TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); *pCliConn = conn; + return code; _failed: if (conn) { + taosMemoryFree(conn->buf); taosMemoryFree(conn->stream); - transReqQueueClear(&conn->wreqQueue); - TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); - transQueueDestroy(&conn->cliMsgs); + destroyCliConnQTable(conn); + taosHashCleanup(conn->pQTable); + transDestroyBuffer(&conn->readBuf); + transQueueDestroy(&conn->reqsToSend); + transQueueDestroy(&conn->reqsSentOut); + taosMemoryFree(conn->dstAddr); } + tError("failed to create conn, code:%d", code); taosMemoryFree(conn); return code; } -static void cliDestroyConn(SCliConn* conn, bool clear) { + +static void cliDestroyAllQidFromThrd(SCliConn* conn) { + int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); - conn->broken = true; - QUEUE_REMOVE(&conn->q); - QUEUE_INIT(&conn->q); - conn->broken = true; - if (conn->list == NULL) { - conn->list = taosHashGet((SHashObj*)pThrd->pool, conn->dstAddr, strlen(conn->dstAddr)); - } + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter != NULL) { + int64_t* qid = taosHashGetKey(pIter, NULL); - if (conn->list) { - SConnList* list = conn->list; - list->list->numOfConn--; - if (conn->status == ConnInPool) { - list->size--; + code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + if (code != 0) { + tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, + tstrerror(code)); + } else { + tDebug("%s conn %p destroy sid::%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); } - } - conn->list = NULL; - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); - conn->refId = -1; + STransCtx* ctx = pIter; + transCtxCleanup(ctx); - if (conn->task != NULL) { - transDQCancel(pThrd->timeoutQueue, conn->task); - conn->task = NULL; - } - cliResetTimer(pThrd, conn); + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); - if (clear) { - if (!uv_is_closing((uv_handle_t*)conn->stream)) { - TAOS_UNUSED(uv_read_stop(conn->stream)); - uv_close((uv_handle_t*)conn->stream, cliDestroy); - } + pIter = taosHashIterate(conn->pQTable, pIter); } + taosHashCleanup(conn->pQTable); + conn->pQTable = NULL; } +static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleException(conn); } static void cliDestroy(uv_handle_t* handle) { + int32_t code = 0; if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; } SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; - cliResetTimer(pThrd, conn); + cliResetConnTimer(conn); - TAOS_UNUSED(atomic_sub_fetch_32(&pThrd->connCount, 1)); + tDebug("%s conn %p try to destroy", CONN_GET_INST_LABEL(conn), conn); - if (conn->refId > 0) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); + code = destroyAllReqs(conn); + if (code != 0) { + tDebug("%s conn %p failed to all reqs since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } + + conn->forceDelFromHeap = 1; + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tDebug("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } + taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); + taosMemoryFree(conn->ipStr); + cliDestroyAllQidFromThrd(conn); - cliDestroyConnMsgs(conn, true); + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } + + taosMemoryFree(conn->buf); + destroyWQ(&conn->wq); + transDestroyBuffer(&conn->readBuf); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); - transReqQueueClear(&conn->wreqQueue); - TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); taosMemoryFree(conn); } -static bool cliHandleNoResp(SCliConn* conn) { - bool res = false; - if (!transQueueEmpty(&conn->cliMsgs)) { - SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0); - if (REQUEST_NO_RESP(&pMsg->msg)) { - TAOS_UNUSED(transQueuePop(&conn->cliMsgs)); - destroyCmsg(pMsg); - res = true; - } - if (res == true) { - if (cliMaySendCachedMsg(conn) == false) { - SCliThrd* thrd = conn->hostThrd; - addConnToPool(thrd->pool, conn); - res = false; - } else { - res = true; - } - } - } - return res; -} -static void cliSendCb(uv_write_t* req, int status) { - STUB_RAND_NETWORK_ERR(status); - SCliConn* pConn = transReqQueueRemove(req); - if (pConn == NULL) return; +static FORCE_INLINE bool filterAllReq(void* e, void* arg) { return 1; } - SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); - if (pMsg != NULL) { - int64_t cost = taosGetTimestampUs() - pMsg->st; - if (cost > 1000 * 50) { - tTrace("%s conn %p send cost:%dus ", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); - } - } - if (pMsg != NULL && pMsg->msg.contLen == 0 && pMsg->msg.pCont != 0) { - rpcFreeCont(pMsg->msg.pCont); - pMsg->msg.pCont = 0; +static void notifyAndDestroyReq(SCliConn* pConn, SCliReq* pReq, int32_t code) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + STransMsg resp = {0}; + resp.code = (pConn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); + if (code != 0) { + resp.code = code; } - if (status == 0) { - tDebug("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); + resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; + resp.info.cliVer = pInst->compatibilityVer; + resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + resp.info.handle = pReq->msg.info.handle; + if (pReq) { + resp.info.traceId = pReq->msg.info.traceId; + } + + STraceId* trace = &resp.info.traceId; + tDebug("%s conn %p notify user and destroy msg %s since %s", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msg.msgType), tstrerror(resp.code)); + + // handle noresp and inter manage msg + if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { + tDebug("%s conn %p destroy %s msg directly since %s", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msg.msgType), tstrerror(resp.code)); + destroyReq(pReq); + return; + } + + pReq->seq = 0; + code = cliNotifyCb(pConn, pReq, &resp); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + return; } else { - if (!uv_is_closing((uv_handle_t*)&pConn->stream)) { - tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); - cliHandleExcept(pConn, -1); - } - return; + // already notify user + destroyReq(pReq); } - if (cliHandleNoResp(pConn) == true) { - tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); - return; - } - TAOS_UNUSED(uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb)); } -void cliSendBatch(SCliConn* pConn) { + +static FORCE_INLINE void destroyReqInQueue(SCliConn* conn, queue* set, int32_t code) { + while (!QUEUE_IS_EMPTY(set)) { + queue* el = QUEUE_HEAD(set); + QUEUE_REMOVE(el); + + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + notifyAndDestroyReq(conn, pReq, code); + } +} +static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + queue set; + QUEUE_INIT(&set); + // TODO + // 1. from qId from thread table + // 2. not itera to all reqs + transQueueRemoveByFilter(&conn->reqsSentOut, filterAllReq, NULL, &set, -1); + transQueueRemoveByFilter(&conn->reqsToSend, filterAllReq, NULL, &set, -1); + + destroyReqInQueue(conn, &set, 0); + return 0; +} +static void cliHandleException(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + cliResetConnTimer(conn); + code = destroyAllReqs(conn); + if (code != 0) { + tError("%s conn %p failed to destroy all reqs on conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } + + cliDestroyAllQidFromThrd(conn); + QUEUE_REMOVE(&conn->q); + if (conn->list) { + conn->list->totaSize -= 1; + conn->list = NULL; + } + + if (conn->task != NULL) { + transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); + conn->task = NULL; + } + conn->forceDelFromHeap = 1; + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tError("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } + + if (conn->registered) { + int8_t ref = transGetRefCount(conn); + if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { + uv_close((uv_handle_t*)conn->stream, cliDestroy); + } + } +} + +bool filterToRmReq(void* h, void* arg) { + queue* el = h; + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { + return true; + } + return false; +} +static void cliConnRmReqs(SCliConn* conn) { + queue set; + QUEUE_INIT(&set); + + transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmReq, NULL, &set, -1); + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + QUEUE_REMOVE(el); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + destroyReq(pReq); + } + return; +} + +static void cliBatchSendCb(uv_write_t* req, int status) { + int32_t code = 0; + SWReqsWrapper* wrapper = (SWReqsWrapper*)req->data; + SCliConn* conn = wrapper->arg; + + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + freeWReqToWQ(&conn->wq, wrapper); + + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + return; + } + cliConnRmReqs(conn); + if (status != 0) { + tDebug("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + return; + } + + cliConnMayUpdateTimer(conn, pInst->readTimeout * 1000); + if (conn->readerStart == 0) { + code = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + if (code != 0) { + tDebug("%s conn %p failed to start read since%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + return; + } + conn->readerStart = 1; + } + + if (!cliMayRecycleConn(conn)) { + code = cliBatchSend(conn, 1); + if (code != 0) { + tDebug("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + } + } +} +bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + if (pConn->userInited == 1) { + return false; + } + STransMsgHead* pHead = *ppHead; + STransMsgHead* tHead = taosMemoryCalloc(1, *msgLen + sizeof(pInst->user)); + memcpy((char*)tHead, (char*)pHead, TRANS_MSG_OVERHEAD); + memcpy((char*)tHead + TRANS_MSG_OVERHEAD, pInst->user, sizeof(pInst->user)); + + memcpy((char*)tHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), (char*)pHead + TRANS_MSG_OVERHEAD, + *msgLen - TRANS_MSG_OVERHEAD); + + tHead->withUserInfo = 1; + *ppHead = tHead; + *msgLen += sizeof(pInst->user); + + pConn->pInitUserReq = tHead; + pConn->userInited = 1; + return true; +} +int32_t cliBatchSend(SCliConn* pConn, int8_t direct) { int32_t code = 0; SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; + STrans* pInst = pThrd->pInst; - SCliBatch* pBatch = pConn->pBatch; - int32_t wLen = pBatch->wLen; - - pBatch->pList->connCnt += 1; - - uv_buf_t* wb = taosMemoryCalloc(wLen, sizeof(uv_buf_t)); - if (wb == NULL) { - code = terrno; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; + if (pConn->broken) { + return 0; } - int i = 0; - queue* h = NULL; - QUEUE_FOREACH(h, &pBatch->wq) { - SCliMsg* pCliMsg = QUEUE_DATA(h, SCliMsg, q); + if (pConn->connnected != 1) { + return 0; + } - STransConnCtx* pCtx = pCliMsg->ctx; + if (!direct) { + if (pConn->inThreadSendq) { + return 0; + } + QUEUE_PUSH(&pThrd->batchSendSet, &pConn->batchSendq); + pConn->inThreadSendq = 1; + tDebug("%s conn %p batch send later", pInst->label, pConn); + return 0; + } - STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); - if (pMsg->pCont == 0) { - pMsg->pCont = (void*)rpcMallocCont(0); - if (pMsg->pCont == NULL) { - code = TSDB_CODE_OUT_OF_BUFFER; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; + int32_t size = transQueueSize(&pConn->reqsToSend); + + int32_t totalLen = 0; + if (size == 0) { + tDebug("%s conn %p not msg to send", pInst->label, pConn); + return 0; + } + uv_buf_t* wb = NULL; + if (pConn->bufSize < size) { + uv_buf_t* twb = (uv_buf_t*)taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + if (twb == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pConn->buf = twb; + pConn->bufSize = size; + } + + wb = pConn->buf; + + int j = 0; + int32_t batchLimit = 64; + while (!transQueueEmpty(&pConn->reqsToSend)) { + queue* h = transQueuePop(&pConn->reqsToSend); + SCliReq* pCliMsg = QUEUE_DATA(h, SCliReq, q); + SReqCtx* pCtx = pCliMsg->ctx; + pConn->seq++; + + STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); + if (pReq->pCont == 0) { + pReq->pCont = (void*)rpcMallocCont(0); + if (pReq->pCont == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; } - pMsg->contLen = 0; + pReq->contLen = 0; } - int msgLen = transMsgLenFromCont(pMsg->contLen); - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + int32_t msgLen = transMsgLenFromCont(pReq->contLen); + STransMsgHead* pHead = transHeadFromCont(pReq->pCont); + + char* content = pReq->pCont; + int32_t contLen = pReq->contLen; + if (cliConnMayAddUserInfo(pConn, &pHead, &msgLen)) { + content = transContFromHead(pHead); + contLen = transContLenFromMsg(msgLen); + } if (pHead->comp == 0) { - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; - pHead->msgType = pMsg->msgType; + pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; + pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; - memcpy(pHead->user, pTransInst->user, strlen(pTransInst->user)); - pHead->traceId = pMsg->info.traceId; + pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; - pHead->compatibilityVer = htonl(pTransInst->compatibilityVer); + pHead->compatibilityVer = htonl(pInst->compatibilityVer); } - pHead->timestamp = taosHton64(taosGetTimestampUs()); + pHead->timestamp = taosHton64(pCliMsg->st); + pHead->seqNum = taosHton64(pConn->seq); + pHead->qid = taosHton64(pReq->info.qId); - if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pTransInst->compressSize != -1 && pTransInst->compressSize < pMsg->contLen) { - msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); + if (pHead->comp == 0) { + if (pInst->compressSize != -1 && pInst->compressSize < contLen) { + msgLen = transCompressMsg(content, contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); } } else { msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); } - wb[i++] = uv_buf_init((char*)pHead, msgLen); - } + wb[j++] = uv_buf_init((char*)pHead, msgLen); + totalLen += msgLen; - uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + pCliMsg->sent = 1; + pCliMsg->seq = pConn->seq; + + STraceId* trace = &pCliMsg->msg.info.traceId; + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", sid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), + pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); + transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); + if (j >= batchLimit) { + break; + } + } + transRefCliHandle(pConn); + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); if (req == NULL) { - code = terrno; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; - } - req->data = pConn; - tDebug("%s conn %p start to send batch msg, batch size:%d, msgLen:%d", CONN_GET_INST_LABEL(pConn), pConn, - pBatch->wLen, pBatch->batchSize); - - code = uv_write(req, (uv_stream_t*)pConn->stream, wb, wLen, cliSendBatchCb); - if (code != 0) { - tDebug("%s conn %p failed to to send batch msg since %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(code)); - goto _exception; + tError("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(terrno)); + transRefCliHandle(pConn); + return terrno; } - taosMemoryFree(wb); - return; + tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, j, totalLen); -_exception: - cliDestroyBatch(pBatch); - taosMemoryFree(wb); - pConn->pBatch = NULL; - return; + int32_t ret = uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); + if (ret != 0) { + tError("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); + freeWReqToWQ(&pConn->wq, req->data); + code = TSDB_CODE_THIRDPARTY_ERROR; + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } + + return code; } -void cliSend(SCliConn* pConn) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - if (transQueueEmpty(&pConn->cliMsgs)) { - tError("%s conn %p not msg to send", pTransInst->label, pConn); - cliHandleExcept(pConn, -1); - return; +int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { + transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + + return cliBatchSend(pConn, pCliMsg->inRetry); +} +int32_t cliSendReqPrepare(SCliConn* pConn, SCliReq* pCliMsg) { + transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + + if (pConn->broken) { + return 0; } - SCliMsg* pCliMsg = NULL; - CONN_GET_NEXT_SENDMSG(pConn); - pCliMsg->sent = 1; - - STransConnCtx* pCtx = pCliMsg->ctx; - - STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); - if (pMsg->pCont == 0) { - pMsg->pCont = (void*)rpcMallocCont(0); - tDebug("malloc memory: %p", pMsg->pCont); - pMsg->contLen = 0; + if (pConn->connnected != 1) { + return 0; } - - int msgLen = transMsgLenFromCont(pMsg->contLen); - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); - - if (pHead->comp == 0) { - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; - pHead->msgType = pMsg->msgType; - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; - memcpy(pHead->user, pTransInst->user, strlen(pTransInst->user)); - pHead->traceId = pMsg->info.traceId; - pHead->magicNum = htonl(TRANS_MAGIC_NUM); - pHead->version = TRANS_VER; - pHead->compatibilityVer = htonl(pTransInst->compatibilityVer); - } - pHead->timestamp = taosHton64(taosGetTimestampUs()); - - if (pHead->persist == 1) { - CONN_SET_PERSIST_BY_APP(pConn); - } - - STraceId* trace = &pMsg->info.traceId; - - if (pTransInst->startTimer != NULL && pTransInst->startTimer(0, pMsg->msgType)) { - uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; - if (timer == NULL) { - timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - if (timer == NULL) { - tError("failed to alloc timer since %s", tstrerror(terrno)); - } - tDebug("no available timer, create a timer %p", timer); - TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); - } - if (timer != NULL) { - timer->data = pConn; - pConn->timer = timer; - } - - tGTrace("%s conn %p start timer for msg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType)); - TAOS_UNUSED(uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0)); - } - - if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pTransInst->compressSize != -1 && pTransInst->compressSize < pMsg->contLen) { - msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - } - } else { - msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); - } - - tGDebug("%s conn %p %s is sent to %s, local info %s, len:%d", CONN_GET_INST_LABEL(pConn), pConn, - TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, msgLen); - - uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); - if (req == NULL) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - cliHandleExcept(pConn, -1); - } - - int status = uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); - if (status != 0) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType), - uv_err_name(status)); - cliHandleExcept(pConn, -1); - } - return; -_RETURN: - return; + // return cliBatchSend(pConn); + return 0; } static void cliDestroyBatch(SCliBatch* pBatch) { @@ -1364,215 +1504,96 @@ static void cliDestroyBatch(SCliBatch* pBatch) { queue* h = QUEUE_HEAD(&pBatch->wq); QUEUE_REMOVE(h); - SCliMsg* p = QUEUE_DATA(h, SCliMsg, q); - destroyCmsg(p); + SCliReq* p = QUEUE_DATA(h, SCliReq, q); + destroyReq(p); } SCliBatchList* p = pBatch->pList; p->sending -= 1; taosMemoryFree(pBatch); } -static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { - int32_t code = 0; - if (pThrd->quit == true) { - cliDestroyBatch(pBatch); - return; + +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { + int32_t lino = 0; + STrans* pInst = pThrd->pInst; + + uint32_t ipaddr; + int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, conn->ipStr, &ipaddr); + if (code != 0) { + TAOS_CHECK_GOTO(code, &lino, _exception1); } - if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { - return; - } - STrans* pTransInst = pThrd->pTransInst; - SCliBatchList* pList = pBatch->pList; + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = ipaddr; + addr.sin_port = (uint16_t)htons(conn->port); - char key[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(key, pList->ip, pList->port); + tTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); - bool exceed = false; - SCliConn* conn = getConnFromPool(pThrd, key, &exceed); - - if (conn == NULL && exceed) { - tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d", pTransInst->label, pBatch->wLen, - pBatch->batchSize, pTransInst->connLimitNum); - cliDestroyBatch(pBatch); - return; - } - if (conn == NULL) { - code = cliCreateConn(pThrd, &conn); - if (code != 0) { - tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pTransInst->label, - pBatch->wLen, pBatch->batchSize, pTransInst->connLimitNum, tstrerror(code)); - cliDestroyBatch(pBatch); - return; - } - - conn->pBatch = pBatch; - conn->dstAddr = taosStrdup(pList->dst); - if (conn->dstAddr == NULL) { - tError("%s conn %p failed to send batch msg, reason:%s", transLabel(pTransInst), conn, - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - cliHandleFastFail(conn, -1); - return; - } - - uint32_t ipaddr = 0; - if ((code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip, &ipaddr)) != 0) { - cliResetTimer(pThrd, conn); - cliHandleFastFail(conn, code); - return; - } - - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ipaddr; - addr.sin_port = (uint16_t)htons(pList->port); - - tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst); - int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - if (fd == -1) { - tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno)); - cliHandleFastFail(conn, -1); - return; - } - int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); - if (ret != 0) { - tError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; - } - ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); - if (ret != 0) { - tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; - } - - ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); - if (ret != 0) { - cliResetTimer(pThrd, conn); - - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, -1); - return; - } - TAOS_UNUSED(uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0)); - return; + int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); + if (fd < 0) { + TAOS_CHECK_GOTO(terrno, &lino, _exception1); } - conn->pBatch = pBatch; - cliSendBatch(conn); -} -static void cliSendBatchCb(uv_write_t* req, int status) { - STUB_RAND_NETWORK_ERR(status); - SCliConn* conn = req->data; - SCliThrd* thrd = conn->hostThrd; - SCliBatch* p = conn->pBatch; - - SCliBatchList* pBatchList = p->pList; - SCliBatch* nxtBatch = cliGetHeadFromList(pBatchList); - pBatchList->connCnt -= 1; - - conn->pBatch = NULL; - - if (status != 0) { - tDebug("%s conn %p failed to send batch msg, batch size:%d, msgLen:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, - p->wLen, p->batchSize, uv_err_name(status)); - - if (!uv_is_closing((uv_handle_t*)&conn->stream)) cliHandleExcept(conn, -1); - - cliHandleBatchReq(nxtBatch, thrd); - } else { - tDebug("%s conn %p succ to send batch msg, batch size:%d, msgLen:%d", CONN_GET_INST_LABEL(conn), conn, p->wLen, - p->batchSize); - if (!uv_is_closing((uv_handle_t*)&conn->stream) && conn->broken == false) { - if (nxtBatch != NULL) { - conn->pBatch = nxtBatch; - cliSendBatch(conn); - } else { - addConnToPool(thrd->pool, conn); - } - } else { - cliDestroyBatch(nxtBatch); - // conn release by other callback - } + int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); + if (ret != 0) { + tError("%s conn %p failed to set stream since %s", transLabel(pInst), conn, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); + } + ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); + if (ret != 0) { + tError("%s conn %p failed to set socket opt since %s", transLabel(pInst), conn, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); + return code; } - cliDestroyBatch(p); - taosMemoryFree(req); -} -static void cliHandleFastFail(SCliConn* pConn, int status) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; + transRefCliHandle(conn); + ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); + if (ret != 0) { + tError("failed connect to %s since %s", conn->dstAddr, uv_err_name(ret)); - if (status == -1) status = UV_EADDRNOTAVAIL; - - if (pConn->pBatch == NULL) { - SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); - - STraceId* trace = &pMsg->msg.info.traceId; - tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - TMSG_INFO(pMsg->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); - - if (pMsg != NULL && REQUEST_NO_RESP(&pMsg->msg) && - (pTransInst->failFastFp != NULL && pTransInst->failFastFp(pMsg->msg.msgType))) { - SFailFastItem* item = taosHashGet(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr)); - int64_t cTimestamp = taosGetTimestampMs(); - if (item != NULL) { - int32_t elapse = cTimestamp - item->timestamp; - if (elapse >= 0 && elapse <= pTransInst->failFastInterval) { - item->count++; - } else { - item->count = 1; - item->timestamp = cTimestamp; - } - } else { - SFailFastItem item = {.count = 1, .timestamp = cTimestamp}; - int32_t code = - taosHashPut(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr), &item, sizeof(SFailFastItem)); - if (code != 0) { - tError("failed to put fail-fast item to cache, reason:%s", tstrerror(code)); - } - } - } - } else { - tError("%s batch msg failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - pConn, pConn->dstAddr, uv_strerror(status)); - cliDestroyBatch(pConn->pBatch); - pConn->pBatch = NULL; + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } - cliHandleExcept(pConn, status); + + conn->registered = 1; + transRefCliHandle(conn); + ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + if (ret != 0) { + tError("%s conn %p failed to start timer since %s", transLabel(pInst), conn, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); + } + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + +_exception1: + tError("%s conn %p failed to do connect since %s", transLabel(pInst), conn, tstrerror(code)); + cliDestroyConn(conn, true); + return code; + +_exception2: + TAOS_UNUSED(transUnrefCliHandle(conn)); + tError("%s conn %p failed to do connect since %s", transLabel(pInst), conn, tstrerror(code)); + return code; } -void cliConnCb(uv_connect_t* req, int status) { - SCliConn* pConn = req->data; - SCliThrd* pThrd = pConn->hostThrd; - bool timeout = false; - - if (pConn->timer == NULL) { - timeout = true; - } else { - cliResetTimer(pThrd, pConn); - } - - STUB_RAND_NETWORK_ERR(status); - - if (status != 0) { - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); - if (timeout == false) { - cliHandleFastFail(pConn, status); - } else if (timeout == true) { - // already deal by timeout - } - return; - } - +int32_t cliConnSetSockInfo(SCliConn* pConn) { struct sockaddr peername, sockname; int addrlen = sizeof(peername); - TAOS_UNUSED(uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen)); - TAOS_UNUSED(transSockInfo2Str(&peername, pConn->dst)); + + int32_t code = uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); + if (code != 0) { + tWarn("failed to get perrname since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + return code; + } + transSockInfo2Str(&peername, pConn->dst); addrlen = sizeof(sockname); - TAOS_UNUSED(uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen)); - TAOS_UNUSED(transSockInfo2Str(&sockname, pConn->src)); + code = uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen); + if (code != 0) { + tWarn("failed to get sock name since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + return code; + } + transSockInfo2Str(&sockname, pConn->src); struct sockaddr_in addr = *(struct sockaddr_in*)&sockname; struct sockaddr_in saddr = *(struct sockaddr_in*)&peername; @@ -1580,182 +1601,164 @@ void cliConnCb(uv_connect_t* req, int status) { pConn->clientIp = addr.sin_addr.s_addr; pConn->serverIp = saddr.sin_addr.s_addr; - tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - if (pConn->pBatch != NULL) { - cliSendBatch(pConn); + return 0; +}; + +// static int32_t cliBuildExeceptMsg(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { +// SCliThrd* pThrd = pConn->hostThrd; +// STrans* pInst = pThrd->pInst; +// memset(pResp, 0, sizeof(STransMsg)); +// STransMsg resp = {0}; +// resp.contLen = 0; +// resp.pCont = NULL; +// resp.msgType = pReq->msg.msgType + 1; +// resp.info.ahandle = pReq->ctx->ahandle; +// resp.info.traceId = pReq->msg.info.traceId; +// resp.info.hasEpSet = false; +// resp.info.cliVer = pInst->compatibilityVer; +// return 0; +// } + +bool filteGetAll(void* q, void* arg) { return true; } +void cliConnCb(uv_connect_t* req, int status) { + int32_t code = 0; + SCliConn* pConn = req->data; + SCliThrd* pThrd = pConn->hostThrd; + bool timeout = false; + + int32_t ref = transUnrefCliHandle(pConn); + if (ref <= 0) { + return; + } + if (pConn->timer == NULL) { + timeout = true; + return; } else { - cliSend(pConn); + cliResetConnTimer(pConn); + } + + STUB_RAND_NETWORK_ERR(status); + + if (status != 0) { + tDebug("%s conn %p failed to connect to %s since %s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, + uv_strerror(status)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + return; + } + pConn->connnected = 1; + code = cliConnSetSockInfo(pConn); + if (code != 0) { + tDebug("%s conn %p failed to get sock info since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } + tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); + + code = cliBatchSend(pConn, 1); + if (code != 0) { + tDebug("%s conn %p failed to get sock info since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); } } -static void doNotifyApp(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { - STransConnCtx* pCtx = pMsg->ctx; - STrans* pTransInst = pThrd->pTransInst; +static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { + SReqCtx* pCtx = pReq->ctx; + STrans* pInst = pThrd->pInst; - STransMsg transMsg = {0}; - transMsg.contLen = 0; - transMsg.pCont = NULL; - transMsg.code = code; - transMsg.msgType = pMsg->msg.msgType + 1; - transMsg.info.ahandle = pMsg->ctx->ahandle; - transMsg.info.traceId = pMsg->msg.info.traceId; - transMsg.info.hasEpSet = false; - transMsg.info.cliVer = pTransInst->compatibilityVer; + STransMsg resp = {0}; + resp.contLen = 0; + resp.pCont = NULL; + resp.code = code; + resp.msgType = pReq->msg.msgType + 1; + resp.info.ahandle = pReq->ctx->ahandle; + resp.info.traceId = pReq->msg.info.traceId; + resp.info.hasEpSet = false; + resp.info.cliVer = pInst->compatibilityVer; if (pCtx->pSem != NULL) { if (pCtx->pRsp == NULL) { } else { - memcpy((char*)pCtx->pRsp, (char*)&transMsg, sizeof(transMsg)); + memcpy((char*)pCtx->pRsp, (char*)&resp, sizeof(resp)); } } else { - pTransInst->cfp(pTransInst->parent, &transMsg, NULL); + pInst->cfp(pInst->parent, &resp, NULL); } - destroyCmsg(pMsg); + destroyReq(pReq); } -static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) { +static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { if (!transAsyncPoolIsEmpty(pThrd->asyncPool)) { - pThrd->stopMsg = pMsg; + pThrd->stopMsg = pReq; return; } pThrd->stopMsg = NULL; pThrd->quit = true; + tDebug("cli work thread %p start to quit", pThrd); - destroyCmsg(pMsg); + destroyReq(pReq); TAOS_UNUSED(destroyConnPool(pThrd)); TAOS_UNUSED(uv_walk(pThrd->loop, cliWalkCb, NULL)); } -static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { - int64_t refId = (int64_t)(pMsg->msg.info.handle); - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("%" PRId64 " already released", refId); - destroyCmsg(pMsg); - return; +static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { return; } +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; + if (pThrd->pCvtAddr != NULL) { + taosMemoryFreeClear(pThrd->pCvtAddr); } - - taosRLockLatch(&exh->latch); - SCliConn* conn = exh->handle; - taosRUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); - - if (T_REF_VAL_GET(conn) == 2) { - transUnrefCliHandle(conn); - if (!transQueuePush(&conn->cliMsgs, pMsg)) { - return; - } - cliSend(conn); - } else { - tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); - destroyCmsg(pMsg); - } -} -static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd) { - STransConnCtx* pCtx = pMsg->ctx; - pThrd->cvtAddr = pCtx->cvtAddr; - destroyCmsg(pMsg); -} -static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { - int32_t code = 0; - int64_t refId = (int64_t)(pMsg->msg.info.handle); - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("refId %" PRId64 " already released", refId); - destroyCmsg(pMsg); - return; - } - - taosRLockLatch(&exh->latch); - SCliConn* conn = exh->handle; - taosRUnLockLatch(&exh->latch); - - if (conn == NULL || conn->refId != refId) { - TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); - } - tDebug("do free conn %p by refId %" PRId64 "", conn, refId); - - int32_t size = transQueueSize(&conn->cliMsgs); - if (size == 0) { - // already recv, and notify upper layer - TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); - } else { - destroyCmsg(pMsg); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - - while (T_REF_VAL_GET(conn) >= 1) { - transUnrefCliHandle(conn); - } - return; - } -_exception: - tDebug("already free conn %p by id %" PRId64 "", conn, refId); - - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), refId)); - destroyCmsg(pMsg); + pThrd->pCvtAddr = pCtx->pCvtAddr; + destroyReq(pReq); + return; } -SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) { - STransConnCtx* pCtx = (*pMsg)->ctx; - SCliConn* conn = NULL; - - int64_t refId = (int64_t)((*pMsg)->msg.info.handle); - if (refId != 0) { - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tError("failed to get conn, refId: %" PRId64 "", refId); - *ignore = true; - return NULL; - } else { - taosRLockLatch(&exh->latch); - conn = exh->handle; - taosRUnLockLatch(&exh->latch); - if (conn == NULL) { - conn = getConnFromPool2(pThrd, addr, pMsg); - if (conn != NULL) specifyConnRef(conn, true, refId); - } - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); - } - return conn; - }; - - conn = getConnFromPool2(pThrd, addr, pMsg); - if (conn != NULL) { - tTrace("%s conn %p get from conn pool:%p", CONN_GET_INST_LABEL(conn), conn, pThrd->pool); - } else { - tTrace("%s not found conn in conn pool:%p, dst:%s", ((STrans*)pThrd->pTransInst)->label, pThrd->pool, addr); +FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAddr) { + if (pEpSet == NULL || pCvtAddr == NULL) { + return 0; } - return conn; -} -FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr) { if (pCvtAddr->cvt == false) { - return; + if (EPSET_IS_VALID(pEpSet)) { + return 0; + } else { + return TSDB_CODE_RPC_FQDN_ERROR; + } } + if (pEpSet->numOfEps == 1 && strncmp(pEpSet->eps[0].fqdn, pCvtAddr->fqdn, TSDB_FQDN_LEN) == 0) { memset(pEpSet->eps[0].fqdn, 0, TSDB_FQDN_LEN); memcpy(pEpSet->eps[0].fqdn, pCvtAddr->ip, TSDB_FQDN_LEN); } + if (EPSET_IS_VALID(pEpSet)) { + return 0; + } + return TSDB_CODE_RPC_FQDN_ERROR; } -FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { +FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx) { if (code != 0) return false; - // if (pCtx->retryCnt == 0) return false; - if (transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet)) return false; - return true; + + return transReqEpsetIsEqual(pCtx->epSet, pCtx->origEpSet) ? false : true; } -FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { - if (pMsg == NULL) return -1; - // memset(pResp, 0, sizeof(STransMsg)); +FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* pThrd, SCliReq* pReq, STransMsg* pResp) { + if (pReq == NULL) return -1; + STrans* pInst = pThrd->pInst; + + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + STransMsg resp = {0}; + // resp.code = (conn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); + pResp->msgType = pReq ? pReq->msg.msgType + 1 : 0; + pResp->info.cliVer = pInst->compatibilityVer; + pResp->info.ahandle = pCtx ? pCtx->ahandle : 0; + if (pReq) { + pResp->info.traceId = pReq->msg.info.traceId; + } + + // handle noresp and inter manage msg + if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { + return TSDB_CODE_RPC_NO_STATE; + } if (pResp->code == 0) { pResp->code = TSDB_CODE_RPC_BROKEN_LINK; } - pResp->msgType = pMsg->msg.msgType + 1; - pResp->info.ahandle = pMsg->ctx ? pMsg->ctx->ahandle : NULL; - pResp->info.traceId = pMsg->msg.info.traceId; return 0; } @@ -1818,149 +1821,196 @@ static void cliMayUpdateFqdnCache(SHashObj* cache, char* dst) { static void doFreeTimeoutMsg(void* param) { STaskArg* arg = param; - SCliMsg* pMsg = arg->param1; + SCliReq* pReq = arg->param1; SCliThrd* pThrd = arg->param2; - STrans* pTransInst = pThrd->pTransInst; - int32_t code = TSDB_CODE_RPC_MAX_SESSIONS; - QUEUE_REMOVE(&pMsg->q); - STraceId* trace = &pMsg->msg.info.traceId; - tGTrace("%s msg %s cannot get available conn after timeout", pTransInst->label, TMSG_INFO(pMsg->msg.msgType)); - doNotifyApp(pMsg, pThrd, code); + STrans* pInst = pThrd->pInst; + + QUEUE_REMOVE(&pReq->q); + STraceId* trace = &pReq->msg.info.traceId; + + tGTrace("%s msg %s cannot get available conn after timeout", pInst->label, TMSG_INFO(pReq->msg.msgType)); + doNotifyCb(pReq, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + taosMemoryFree(arg); } -void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { - int32_t code = 0; - STrans* pTransInst = pThrd->pTransInst; - - cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); - if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { - destroyCmsg(pMsg); - return; - } - - char* fqdn = EPSET_GET_INUSE_IP(&pMsg->ctx->epSet); - uint16_t port = EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet); - char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); - - bool ignore = false; - SCliConn* conn = cliGetConn(&pMsg, pThrd, &ignore, addr); - if (ignore == true) { - // persist conn already release by server - STransMsg resp = {0}; - TAOS_UNUSED(cliBuildExceptResp(pMsg, &resp)); - // refactorr later - resp.info.cliVer = pTransInst->compatibilityVer; - - if (pMsg->type != Release) { - pTransInst->cfp(pTransInst->parent, &resp, NULL); +int32_t cliHandleState_mayUpdateStateTime(SCliConn* pConn, SCliReq* pReq) { + int64_t qid = pReq->msg.info.qId; + if (qid > 0) { + STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (pUserCtx != NULL) { + pUserCtx->st = taosGetTimestampUs(); } - destroyCmsg(pMsg); - return; } - if (conn == NULL && pMsg == NULL) { - return; + return 0; +} +int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + SReqCtx* pCtx = pReq->ctx; + SCliThrd* pThrd = pConn->hostThrd; + if (pCtx == NULL) { + tDebug("%s conn %p not need to update statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + return 0; } - STraceId* trace = &pMsg->msg.info.traceId; - if (conn != NULL) { - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); - cliSend(conn); + STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (pUserCtx == NULL) { + pCtx->userCtx.st = taosGetTimestampUs(); + code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); + tDebug("%s conn %p succ to add statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { - code = cliCreateConn(pThrd, &conn); - if (code != 0) { - tError("%s failed to create conn, reason:%s", pTransInst->label, tstrerror(code)); - STransMsg resp = {.code = code}; - TAOS_UNUSED(cliBuildExceptResp(pMsg, &resp)); - - resp.info.cliVer = pTransInst->compatibilityVer; - if (pMsg->type != Release) { - pTransInst->cfp(pTransInst->parent, &resp, NULL); - } - destroyCmsg(pMsg); - return; - } - - int64_t refId = (int64_t)pMsg->msg.info.handle; - if (refId != 0) specifyConnRef(conn, true, refId); - - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); - - conn->dstAddr = taosStrdup(addr); - if (conn->dstAddr == NULL) { - tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno)); - cliHandleExcept(conn, -1); - } - - uint32_t ipaddr; - int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); - if (code != 0) { - cliResetTimer(pThrd, conn); - cliHandleExcept(conn, code); - return; - } - - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ipaddr; - addr.sin_port = (uint16_t)htons(port); - - tGTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr); - int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - if (fd == -1) { - tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno)); - cliHandleExcept(conn, -1); - terrno = 0; - return; - } - - int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); - if (ret != 0) { - tGError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleExcept(conn, -1); - return; - } - - ret = transSetConnOption((uv_tcp_t*)conn->stream, tsKeepAliveIdle); - if (ret != 0) { - tGError("%s conn %p failed to set socket opt, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleExcept(conn, -1); - return; - } - - ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); - if (ret != 0) { - cliResetTimer(pThrd, conn); - - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, ret); - return; - } - TAOS_UNUSED(uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0)); + transCtxMerge(pUserCtx, &pCtx->userCtx); + pUserCtx->st = taosGetTimestampUs(); + tDebug("%s conn %p succ to update statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } - tGTrace("%s conn %p ready", pTransInst->label, conn); + return 0; } -static void cliNoBatchDealReq(queue* wq, SCliThrd* pThrd) { +int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + if (qid == 0) { + return TSDB_CODE_RPC_NO_STATE; + } else { + SExHandle* exh = transAcquireExHandle(transGetRefMgt(), qid); + if (exh == NULL) { + return TSDB_CODE_RPC_STATE_DROPED; + } + + SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); + + if (pState == NULL) { + if (pReq->ctx == NULL) { + transReleaseExHandle(transGetRefMgt(), qid); + return TSDB_CODE_RPC_STATE_DROPED; + } + tDebug("%s conn %p failed to get statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + transReleaseExHandle(transGetRefMgt(), qid); + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } else { + *pConn = pState->conn; + tDebug("%s conn %p succ to get conn of statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + } + transReleaseExHandle(transGetRefMgt(), qid); + return 0; + } +} + +int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq) { + SCliThrd* pThrd = pConn->hostThrd; + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + if (qid == 0) { + return TSDB_CODE_RPC_NO_STATE; + } + + SReqState state = {.conn = pConn, .arg = NULL}; + code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); + if (code != 0) { + tDebug("%s conn %p failed to statue, sid:%" PRId64 " since %s", transLabel(pThrd->pInst), pConn, qid, + tstrerror(code)); + } else { + tDebug("%s conn %p succ to add statue, sid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); + } + + TAOS_UNUSED(cliHandleState_mayUpdateStateCtx(pConn, pReq)); + return code; +} +void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { + int32_t lino = 0; + STransMsg resp = {0}; + int32_t code = (pThrd->initCb)(pThrd, pReq, NULL); + TAOS_CHECK_GOTO(code, &lino, _exception); + + STrans* pInst = pThrd->pInst; + SCliConn* pConn = NULL; + code = cliMayGetStateByQid(pThrd, pReq, &pConn); + if (code == 0) { + TAOS_UNUSED(cliHandleState_mayUpdateStateCtx(pConn, pReq)); + } else if (code == TSDB_CODE_RPC_STATE_DROPED) { + TAOS_CHECK_GOTO(code, &lino, _exception); + return; + } else if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + char addr[TSDB_FQDN_LEN + 64] = {0}; + char* ip = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + + pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + if (pConn == NULL) { + code = cliGetOrCreateConn(pThrd, pReq, &pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + TAOS_CHECK_GOTO(code, &lino, _exception); + } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + // do nothing, notiy + return; + } else if (code == 0) { + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + if (code != 0) { + tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, pConn, tstrerror(code)); + } + } else { + // TAOS_CHECK_GOTO(code, &lino, _exception); + return; + } + } + code = cliHandleState_mayUpdateState(pConn, pReq); + } + code = cliSendReq(pConn, pReq); + if (code != 0) { + tWarn("%s conn %p failed to send req since %s", pInst->label, pConn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } + + tTrace("%s conn %p ready", pInst->label, pConn); + return; + +_exception: + resp.code = code; + STraceId* trace = &pReq->msg.info.traceId; + tGWarn("%s failed to process req since %s", pInst->label, tstrerror(code)); + + code = (pThrd->notifyExceptCb)(pThrd, pReq, &resp); + if (code != 0) { + tWarn("%s failed to notify user since %s", pInst->label, tstrerror(code)); + } + return; +} + +void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { return cliHandleBatchReq(pThrd, pReq); } + +static void cliDoReq(queue* wq, SCliThrd* pThrd) { int count = 0; + QUEUE_INIT(&pThrd->batchSendSet); while (!QUEUE_IS_EMPTY(wq)) { queue* h = QUEUE_HEAD(wq); QUEUE_REMOVE(h); - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - - if (pMsg->type == Quit) { - pThrd->stopMsg = pMsg; + SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); + if (pReq->type == Quit) { + pThrd->stopMsg = pReq; continue; } - (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); - + (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } + int32_t code = 0; + while (!QUEUE_IS_EMPTY(&pThrd->batchSendSet)) { + queue* el = QUEUE_HEAD(&pThrd->batchSendSet); + QUEUE_REMOVE(el); + + SCliConn* conn = QUEUE_DATA(el, SCliConn, batchSendq); + conn->inThreadSendq = 0; + QUEUE_INIT(&conn->batchSendq); + code = cliBatchSend(conn, 1); + if (code != 0) { + tWarn("%s conn %p failed to send req since %s", pThrd->pInst->label, conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + } + } + QUEUE_INIT(&pThrd->batchSendSet); if (count >= 2) { tTrace("cli process batch size:%d", count); } @@ -1978,11 +2028,74 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) { SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq); return batch; } +static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* pReq); +static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port); + +static void destroyBatchList(SCliBatchList* pList); +static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { + int32_t code = 0; + STrans* pInst = pThrd->pInst; + SReqCtx* pCtx = pReq->ctx; + + char* ip = EPSET_GET_INUSE_IP(pCtx->epSet); + uint32_t port = EPSET_GET_INUSE_PORT(pCtx->epSet); + char key[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(key, ip, port); + size_t klen = strlen(key); + SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); + if (ppBatchList == NULL || *ppBatchList == NULL) { + SCliBatchList* pBatchList = NULL; + code = createBatchList(&pBatchList, key, ip, port); + if (code != 0) { + destroyReq(pReq); + return; + } + + pBatchList->batchLenLimit = pInst->shareConnLimit; + + SCliBatch* pBatch = NULL; + code = createBatch(&pBatch, pBatchList, pReq); + if (code != 0) { + destroyBatchList(pBatchList); + destroyReq(pReq); + return; + } + + code = taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); + if (code != 0) { + destroyBatchList(pBatchList); + } + } else { + if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { + SCliBatch* pBatch = NULL; + code = createBatch(&pBatch, *ppBatchList, pReq); + if (code != 0) { + destroyReq(pReq); + cliDestroyBatch(pBatch); + } + } else { + queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); + SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); + if ((pBatch->shareConnLimit + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { + QUEUE_PUSH(&pBatch->wq, h); + pBatch->shareConnLimit += pReq->msg.contLen; + pBatch->wLen += 1; + } else { + SCliBatch* tBatch = NULL; + code = createBatch(&tBatch, *ppBatchList, pReq); + if (code != 0) { + destroyReq(pReq); + } + } + } + } + return; +} static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port) { SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); if (pBatchList == NULL) { - tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch list since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } QUEUE_INIT(&pBatchList->wq); @@ -1998,7 +2111,7 @@ static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, taosMemoryFree(pBatchList->ip); taosMemoryFree(pBatchList->dst); taosMemoryFree(pBatchList); - tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch list since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } *ppBatchList = pBatchList; @@ -2019,19 +2132,19 @@ static void destroyBatchList(SCliBatchList* pList) { taosMemoryFree(pList->dst); taosMemoryFree(pList); } -static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* pMsg) { +static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* pReq) { SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); if (pBatch == NULL) { - tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } QUEUE_INIT(&pBatch->wq); QUEUE_INIT(&pBatch->listq); - QUEUE_PUSH(&pBatch->wq, &pMsg->q); + QUEUE_PUSH(&pBatch->wq, &pReq->q); pBatch->wLen += 1; - pBatch->batchSize = pMsg->msg.contLen; + pBatch->shareConnLimit = pReq->msg.contLen; pBatch->pList = pList; QUEUE_PUSH(&pList->wq, &pBatch->listq); @@ -2040,184 +2153,64 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* p *ppBatch = pBatch; return 0; } -static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { - STrans* pInst = pThrd->pTransInst; - int32_t code = 0; - - int count = 0; - while (!QUEUE_IS_EMPTY(wq)) { - queue* h = QUEUE_HEAD(wq); - QUEUE_REMOVE(h); - - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - - if (pMsg->type == Quit) { - pThrd->stopMsg = pMsg; - continue; - } - - if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { - STransConnCtx* pCtx = pMsg->ctx; - - char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); - uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); - char key[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(key, ip, port); - size_t klen = strlen(key); - SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); - if (ppBatchList == NULL || *ppBatchList == NULL) { - SCliBatchList* pBatchList = NULL; - code = createBatchList(&pBatchList, key, ip, port); - if (code != 0) { - destroyCmsg(pMsg); - continue; - } - pBatchList->batchLenLimit = pInst->batchSize; - - SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, pBatchList, pMsg); - if (code != 0) { - destroyBatchList(pBatchList); - destroyCmsg(pMsg); - continue; - } - - code = taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); - if (code != 0) { - destroyBatchList(pBatchList); - } - } else { - if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { - SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, *ppBatchList, pMsg); - if (code != 0) { - destroyCmsg(pMsg); - cliDestroyBatch(pBatch); - } - } else { - queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); - SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); - if ((pBatch->batchSize + pMsg->msg.contLen) < (*ppBatchList)->batchLenLimit) { - QUEUE_PUSH(&pBatch->wq, h); - pBatch->batchSize += pMsg->msg.contLen; - pBatch->wLen += 1; - } else { - SCliBatch* tBatch = NULL; - code = createBatch(&tBatch, *ppBatchList, pMsg); - if (code != 0) { - destroyCmsg(pMsg); - } - } - } - } - continue; - } - (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); - count++; - } - - void** pIter = taosHashIterate(pThrd->batchCache, NULL); - while (pIter != NULL) { - SCliBatchList* batchList = (SCliBatchList*)(*pIter); - SCliBatch* batch = cliGetHeadFromList(batchList); - if (batch != NULL) { - cliHandleBatchReq(batch, pThrd); - } - pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); - } - - if (count >= 2) { - tTrace("cli process batch size:%d", count); - } -} +static void cliDoBatchReq(queue* wq, SCliThrd* pThrd) { return cliDoReq(wq, pThrd); } static void cliAsyncCb(uv_async_t* handle) { SAsyncItem* item = handle->data; SCliThrd* pThrd = item->pThrd; - STrans* pTransInst = pThrd->pTransInst; + STrans* pInst = pThrd->pInst; // batch process to avoid to lock/unlock frequently queue wq; if (taosThreadMutexLock(&item->mtx) != 0) { - tError("failed to lock mutex, reason:%s", tstrerror(terrno)); + tError("failed to lock mutex since %s", tstrerror(terrno)); } QUEUE_MOVE(&item->qmsg, &wq); if (taosThreadMutexUnlock(&item->mtx) != 0) { - tError("failed to unlock mutex, reason:%s", tstrerror(terrno)); + tError("failed to unlock mutex since %s", tstrerror(terrno)); } - int8_t supportBatch = pTransInst->supportBatch; - if (supportBatch == 0) { - cliNoBatchDealReq(&wq, pThrd); - } else if (supportBatch == 1) { - cliBatchDealReq(&wq, pThrd); - } + cliDealFunc[pInst->supportBatch](&wq, pThrd); - if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); + if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd, pThrd->stopMsg); } -void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { - transCtxCleanup(&conn->ctx); - cliReleaseUnfinishedMsg(conn); - if (destroy == 1) { - transQueueDestroy(&conn->cliMsgs); - } else { - transQueueClear(&conn->cliMsgs); +static FORCE_INLINE void destroyReq(void* arg) { + SCliReq* pReq = arg; + if (pReq == NULL) { + return; } + STraceId* trace = &pReq->msg.info.traceId; + tGDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); + + if (pReq->ctx) { + destroyReqCtx(pReq->ctx); + } + transFreeMsg(pReq->msg.pCont); + taosMemoryFree(pReq); } +static FORCE_INLINE void destroyReqWrapper(void* arg, void* param) { + if (arg == NULL) return; -void cliConnFreeMsgs(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; + SCliReq* pReq = arg; + SCliThrd* pThrd = param; - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* cmsg = transQueueGet(&conn->cliMsgs, i); - if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { - continue; + if (pReq->ctx != NULL && pReq->ctx->ahandle != NULL) { + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + (*pThrd->destroyAhandleFp)(pReq->ctx->ahandle); } - - STransMsg resp = {0}; - if (-1 == cliBuildExceptResp(cmsg, &resp)) { - continue; - } - resp.info.cliVer = pTransInst->compatibilityVer; - pTransInst->cfp(pTransInst->parent, &resp, NULL); - - cmsg->ctx->ahandle = NULL; } + destroyReq(pReq); } -bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { - if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - uint64_t ahandle = pHead->ahandle; - SCliMsg* pMsg = NULL; - CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); - tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, - conn->refId); +static FORCE_INLINE void destroyReqAndAhanlde(void* param) { + if (param == NULL) return; - TAOS_UNUSED(transClearBuffer(&conn->readBuf)); - transFreeMsg(transContFromHead((char*)pHead)); - - for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* cliMsg = transQueueGet(&conn->cliMsgs, i); - if (cliMsg->type == Release) { - tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, - conn->refId); - cliDestroyConn(conn, true); - return true; - } - } - - cliConnFreeMsgs(conn); - - tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); - destroyCmsg(pMsg); - - addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); - return true; - } - return false; + STaskArg* arg = param; + SCliReq* pReq = arg->param1; + SCliThrd* pThrd = arg->param2; + destroyReqWrapper(pReq, pThrd); } static void* cliWorkThread(void* arg) { @@ -2226,23 +2219,24 @@ static void* cliWorkThread(void* arg) { SCliThrd* pThrd = (SCliThrd*)arg; pThrd->pid = taosGetSelfPthreadId(); - TAOS_UNUSED(strtolower(threadName, pThrd->pTransInst->label)); + tsEnableRandErr = true; + TAOS_UNUSED(strtolower(threadName, pThrd->pInst->label)); setThreadName(threadName); TAOS_UNUSED(uv_run(pThrd->loop, UV_RUN_DEFAULT)); - tDebug("thread quit-thread:%08" PRId64, pThrd->pid); + tDebug("thread quit-thread:%08" PRId64 "", pThrd->pid); return NULL; } -void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { +void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInstRef) { int32_t code = 0; SCliObj* cli = taosMemoryCalloc(1, sizeof(SCliObj)); if (cli == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _err); } - STrans* pTransInst = shandle; + STrans* pInst = pInstRef; memcpy(cli->label, label, TSDB_LABEL_LEN); cli->numOfThreads = numOfThreads; @@ -2253,18 +2247,20 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, for (int i = 0; i < cli->numOfThreads; i++) { SCliThrd* pThrd = NULL; - code = createThrdObj(shandle, &pThrd); + code = createThrdObj(pInstRef, &pThrd); if (code != 0) { goto _err; } int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd)); if (err != 0) { + destroyThrdObj(pThrd); code = TAOS_SYSTEM_ERROR(errno); TAOS_CHECK_GOTO(code, NULL, _err); } else { tDebug("success to create tranport-cli thread:%d", i); } + pThrd->thrdInited = 1; cli->pThreadObj[i] = pThrd; } return cli; @@ -2283,52 +2279,37 @@ _err: terrno = code; return NULL; } - -static FORCE_INLINE void destroyCmsg(void* arg) { - SCliMsg* pMsg = arg; - if (pMsg == NULL) { - return; +int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = thrd; + if (pReq->ctx == NULL || pReq->ctx->epSet == NULL) { + return 0; } - tDebug("free memory:%p, free ctx: %p", pMsg, pMsg->ctx); - - transDestroyConnCtx(pMsg->ctx); - transFreeMsg(pMsg->msg.pCont); - taosMemoryFree(pMsg); + return cliMayCvtFqdnToIp(pReq->ctx->epSet, pThrd->pCvtAddr); } -static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param) { - if (arg == NULL) return; - - SCliMsg* pMsg = arg; - SCliThrd* pThrd = param; - if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL) { - if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pMsg->msg.info.ahandle); +int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = thrd; + STrans* pInst = pThrd->pInst; + int32_t code = cliBuildExceptResp(pThrd, pReq, pResp); + if (code != 0) { + destroyReq(pReq); + return code; } - destroyCmsg(pMsg); + pInst->cfp(pInst->parent, pResp, NULL); + destroyReq(pReq); + return code; } -static FORCE_INLINE void destroyCmsgAndAhandle(void* param) { - if (param == NULL) return; - STaskArg* arg = param; - SCliMsg* pMsg = arg->param1; - SCliThrd* pThrd = arg->param2; +int32_t notfiyCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + // impl later + SCliThrd* pThrd = thrd; + STrans* pInst = pThrd->pInst; - if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pMsg->ctx->ahandle); - } - - if (pMsg->msg.info.handle != 0) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle)); - } - - transDestroyConnCtx(pMsg->ctx); - transFreeMsg(pMsg->msg.pCont); - taosMemoryFree(pMsg); + return 0; } static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { int32_t code = 0; - STrans* pTransInst = trans; + STrans* pInst = trans; SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd)); if (pThrd == NULL) { @@ -2347,17 +2328,40 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { code = uv_loop_init(pThrd->loop); if (code != 0) { - tError("failed to init uv_loop, reason:%s", uv_err_name(code)); + tError("failed to init uv_loop since %s", uv_err_name(code)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); } - int32_t nSync = pTransInst->supportBatch ? 4 : 8; + int32_t nSync = 2; // pInst->supportBatch ? 4 : 8; code = transAsyncPoolCreate(pThrd->loop, nSync, pThrd, cliAsyncCb, &pThrd->asyncPool); if (code != 0) { tError("failed to init async pool since:%s", tstrerror(code)); TAOS_CHECK_GOTO(code, NULL, _end); } + int32_t timerSize = 64; + pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); + if (pThrd->timerList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + + for (int i = 0; i < timerSize; i++) { + uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + if (timer == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _end); + } + code = uv_timer_init(pThrd->loop, timer); + if (code != 0) { + tError("failed to init timer since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + TAOS_CHECK_GOTO(code, NULL, _end); + } + if (taosArrayPush(pThrd->timerList, &timer) == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _end); + } + } + pThrd->pool = createConnPool(4); if (pThrd->pool == NULL) { code = terrno; @@ -2375,40 +2379,39 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(code, NULL, _end); } - pThrd->destroyAhandleFp = pTransInst->destroyFp; - pThrd->fqdn2ipCache = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + pThrd->destroyAhandleFp = pInst->destroyFp; + + pThrd->fqdn2ipCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pThrd->fqdn2ipCache == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _end); } - pThrd->failFastCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - if (pThrd->failFastCache == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); - } pThrd->batchCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pThrd->batchCache == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _end); } - int32_t timerSize = 64; - pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); - if (pThrd->timerList == NULL) { - code = terrno; - TAOS_CHECK_GOTO(terrno, NULL, _end); + pThrd->connHeapCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (pThrd->connHeapCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } - for (int i = 0; i < timerSize; i++) { - uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - if (timer == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); - } - TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); - if (taosArrayPush(pThrd->timerList, &timer) == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); - } + pThrd->pIdConnTable = taosHashInit(512, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (pThrd->connHeapCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } - pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); - pThrd->pTransInst = trans; + + pThrd->pQIdBuf = taosArrayInit(8, sizeof(int64_t)); + if (pThrd->pQIdBuf == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + + pThrd->initCb = initCb; + pThrd->notifyCb = notfiyCb; + pThrd->notifyExceptCb = notifyExceptCb; + + pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pInst->idleTime); + pThrd->pInst = trans; pThrd->quit = false; *ppThrd = pThrd; @@ -2420,6 +2423,7 @@ _end: TAOS_UNUSED(uv_loop_close(pThrd->loop)); taosMemoryFree(pThrd->loop); + TAOS_UNUSED((taosThreadMutexDestroy(&pThrd->msgMtx))); transAsyncPoolDestroy(pThrd->asyncPool); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); @@ -2435,6 +2439,8 @@ _end: taosHashCleanup(pThrd->fqdn2ipCache); taosHashCleanup(pThrd->failFastCache); taosHashCleanup(pThrd->batchCache); + taosHashCleanup(pThrd->pIdConnTable); + taosArrayDestroy(pThrd->pQIdBuf); taosMemoryFree(pThrd); } @@ -2445,16 +2451,16 @@ static void destroyThrdObj(SCliThrd* pThrd) { return; } - if (taosThreadJoin(pThrd->thread, NULL) != 0) { - tTrace("failed to join thread, reason:%s", tstrerror(terrno)); + if (pThrd->thrdInited && taosThreadJoin(pThrd->thread, NULL) != 0) { + tTrace("failed to join thread since %s", tstrerror(terrno)); } CLI_RELEASE_UV(pThrd->loop); TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx)); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsgWrapper, (void*)pThrd); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliReq, destroyReqWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); - transDQDestroy(pThrd->delayQueue, destroyCmsgAndAhandle); + transDQDestroy(pThrd->delayQueue, destroyReqAndAhanlde); transDQDestroy(pThrd->timeoutQueue, NULL); transDQDestroy(pThrd->waitConnQueue, NULL); @@ -2467,7 +2473,6 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosArrayDestroy(pThrd->timerList); taosMemoryFree(pThrd->loop); taosHashCleanup(pThrd->fqdn2ipCache); - taosHashCleanup(pThrd->failFastCache); void** pIter = taosHashIterate(pThrd->batchCache, NULL); while (pIter != NULL) { @@ -2486,18 +2491,35 @@ static void destroyThrdObj(SCliThrd* pThrd) { pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); } taosHashCleanup(pThrd->batchCache); + + void* pIter2 = taosHashIterate(pThrd->connHeapCache, NULL); + while (pIter2 != NULL) { + SHeap* heap = (SHeap*)(pIter2); + transHeapDestroy(heap); + pIter2 = (void*)taosHashIterate(pThrd->connHeapCache, pIter2); + } + taosHashCleanup(pThrd->connHeapCache); + + taosHashCleanup(pThrd->pIdConnTable); + + taosMemoryFree(pThrd->pCvtAddr); + taosArrayDestroy(pThrd->pQIdBuf); + taosMemoryFree(pThrd); } -static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx) { - // - taosMemoryFree(ctx); +static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx) { + if (ctx) { + taosMemoryFree(ctx->epSet); + taosMemoryFree(ctx->origEpSet); + taosMemoryFree(ctx); + } } int32_t cliSendQuit(SCliThrd* thrd) { // cli can stop gracefully int32_t code = 0; - SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* msg = taosMemoryCalloc(1, sizeof(SCliReq)); if (msg == NULL) { return terrno; } @@ -2523,77 +2545,124 @@ void cliWalkCb(uv_handle_t* handle, void* arg) { } } -FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst) { - int32_t index = pTransInst->index; - if (pTransInst->numOfThreads == 0) { +FORCE_INLINE int cliRBChoseIdx(STrans* pInst) { + int32_t index = pInst->index; + if (pInst->numOfThreads == 0) { return -1; } /* - * no lock, and to avoid CPU load imbalance, set limit pTransInst->numOfThreads * 2000; + * no lock, and to avoid CPU load imbalance, set limit pInst->numOfThreads * 2000; */ - if (pTransInst->index++ >= pTransInst->numOfThreads * 2000) { - pTransInst->index = 0; + if (pInst->index++ >= pInst->numOfThreads * 2000) { + pInst->index = 0; } - return index % pTransInst->numOfThreads; + return index % pInst->numOfThreads; } static FORCE_INLINE void doDelayTask(void* param) { STaskArg* arg = param; - cliHandleReq((SCliMsg*)arg->param1, (SCliThrd*)arg->param2); + + if (arg && arg->param1) { + SCliReq* pReq = arg->param1; + pReq->inRetry = 1; + } + cliHandleReq((SCliThrd*)arg->param2, (SCliReq*)arg->param1); taosMemoryFree(arg); } -static void doCloseIdleConn(void* param) { +static FORCE_INLINE void doCloseIdleConn(void* param) { STaskArg* arg = param; SCliConn* conn = arg->param1; tDebug("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); conn->task = NULL; - cliDestroyConn(conn, true); taosMemoryFree(arg); + + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + return; + } } -static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { +static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { + int32_t code = 0; if (!(rpcDebugFlag & DEBUG_DEBUG)) { return; } - STransConnCtx* pCtx = pMsg->ctx; - STraceId* trace = &pMsg->msg.info.traceId; - char tbuf[512] = {0}; - TAOS_UNUSED(epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf))); + SReqCtx* pCtx = pReq->ctx; + STraceId* trace = &pReq->msg.info.traceId; + char tbuf[512] = {0}; + + code = epsetToStr((SEpSet*)pCtx->epSet, tbuf, tListLen(tbuf)); + if (code != 0) { + tWarn("failed to debug epset since %s", tstrerror(code)); + return; + } + tGDebug("%s retry on next node,use:%s, step: %d,timeout:%" PRId64 "", label, tbuf, pCtx->retryStep, pCtx->retryNextInterval); return; } +static FORCE_INLINE void cliPerfLog_epset(SCliConn* pConn, SCliReq* pReq) { + int32_t code = 0; + if (!(rpcDebugFlag & DEBUG_TRACE)) { + return; + } + SReqCtx* pCtx = pReq->ctx; -static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { - STrans* pTransInst = pThrd->pTransInst; - STransConnCtx* pCtx = pMsg->ctx; - cliSchedMsgToDebug(pMsg, transLabel(pThrd->pTransInst)); + char tbuf[512] = {0}; + + code = epsetToStr((SEpSet*)pCtx->epSet, tbuf, tListLen(tbuf)); + if (code != 0) { + tWarn("failed to debug epset since %s", tstrerror(code)); + return; + } + tTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); + return; +} + +static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliReq* pReq, SCliThrd* pThrd) { + STrans* pInst = pThrd->pInst; + SReqCtx* pCtx = pReq->ctx; + cliPerfLog_schedMsg(pReq, transLabel(pThrd->pInst)); STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { - tError("failed to malloc memory, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return; + return TSDB_CODE_OUT_OF_MEMORY; } - arg->param1 = pMsg; + arg->param1 = pReq; arg->param2 = pThrd; - TAOS_UNUSED(transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval)); + SDelayTask* pTask = transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + if (pTask == NULL) { + taosMemoryFree(arg); + return TSDB_CODE_OUT_OF_MEMORY; + } + return 0; } -FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { +FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { + int32_t code = 0; + SReqCtx* ctx = pReq->ctx; + if ((pResp == NULL || pResp->info.hasEpSet == 0)) { return false; } // rebuild resp msg SEpSet epset; - if (tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epset) < 0) { + if ((code = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epset)) < 0) { + tError("failed to deserialize epset, code:%d", code); return false; } - int32_t tlen = tSerializeSEpSet(NULL, 0, dst); + SEpSet tepset; + int32_t tlen = tSerializeSEpSet(NULL, 0, &tepset); char* buf = NULL; int32_t len = pResp->contLen - tlen; if (len != 0) { buf = rpcMallocCont(len); + if (buf == NULL) { + pResp->code = TSDB_CODE_OUT_OF_MEMORY; + return false; + } + // TODO: check buf memcpy(buf, (char*)pResp->pCont + tlen, len); } rpcFreeCont(pResp->pCont); @@ -2601,41 +2670,49 @@ FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { pResp->pCont = buf; pResp->contLen = len; - epsetAssign(dst, &epset); + pResp->info.hasEpSet = 1; + + if (transCreateReqEpsetFromUserEpset(&epset, &ctx->epSet) != 0) { + return false; + } return true; } -bool cliResetEpset(STransConnCtx* pCtx, STransMsg* pResp, bool hasEpSet) { + +bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { bool noDelay = true; if (hasEpSet == false) { if (pResp->contLen == 0) { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else if (pResp->contLen != 0) { SEpSet epSet; int32_t valid = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epSet); if (valid < 0) { tDebug("get invalid epset, epset equal, continue"); - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else { - if (!transEpSetIsEqual2(&pCtx->epSet, &epSet)) { + if (!transCompareReqAndUserEpset(pCtx->epSet, &epSet)) { tDebug("epset not equal, retry new epset1"); - transPrintEpSet(&pCtx->epSet); + transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - epsetAssign(&pCtx->epSet, &epSet); + + if (transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet) != 0) { + tDebug("failed to create req epset from user epset"); + } noDelay = false; } else { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { tDebug("epset equal, continue"); - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } } @@ -2645,97 +2722,63 @@ bool cliResetEpset(STransConnCtx* pCtx, STransMsg* pResp, bool hasEpSet) { int32_t valid = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epSet); if (valid < 0) { tDebug("get invalid epset, epset equal, continue"); - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else { - if (!transEpSetIsEqual2(&pCtx->epSet, &epSet)) { + if (!transCompareReqAndUserEpset(pCtx->epSet, &epSet)) { tDebug("epset not equal, retry new epset2"); - transPrintEpSet(&pCtx->epSet); + transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - epsetAssign(&pCtx->epSet, &epSet); + if (transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet) != 0) { + tError("failed to create req epset from user epset"); + } noDelay = false; } else { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { tDebug("epset equal, continue"); - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } } } return noDelay; } -bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - - STransConnCtx* pCtx = pMsg->ctx; - int32_t code = pResp->code; - - bool retry = pTransInst->retry != NULL ? pTransInst->retry(code, pResp->msgType - 1) : false; - if (retry == false) { - return false; - } +void cliRetryMayInitCtx(STrans* pInst, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; if (!pCtx->retryInit) { - pCtx->retryMinInterval = pTransInst->retryMinInterval; - pCtx->retryMaxInterval = pTransInst->retryMaxInterval; - pCtx->retryStepFactor = pTransInst->retryStepFactor; - pCtx->retryMaxTimeout = pTransInst->retryMaxTimeout; + pCtx->retryMinInterval = pInst->retryMinInterval; + pCtx->retryMaxInterval = pInst->retryMaxInterval; + pCtx->retryStepFactor = pInst->retryStepFactor; + pCtx->retryMaxTimeout = pInst->retryMaxTimeout; pCtx->retryInitTimestamp = taosGetTimestampMs(); pCtx->retryNextInterval = pCtx->retryMinInterval; pCtx->retryStep = 0; - pCtx->retryInit = true; + pCtx->retryInit = 1; pCtx->retryCode = TSDB_CODE_SUCCESS; - - // already retry, not use handle specified by app; - pMsg->msg.info.handle = 0; + pReq->msg.info.handle = 0; } +} - if (-1 != pCtx->retryMaxTimeout && taosGetTimestampMs() - pCtx->retryInitTimestamp >= pCtx->retryMaxTimeout) { - return false; +int32_t cliRetryIsTimeout(STrans* pInst, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; + if (pCtx->retryMaxTimeout != -1 && taosGetTimestampMs() - pCtx->retryInitTimestamp >= pCtx->retryMaxTimeout) { + return 1; } + return 0; +} - // code, msgType - - // A: epset, leader, not self - // B: epset, not know leader - // C: no epset, leader but not serivce - - bool noDelay = false; - if (code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { - tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); - noDelay = cliResetEpset(pCtx, pResp, false); - transFreeMsg(pResp->pCont); - transUnrefCliHandle(pConn); - } else if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_INTERNAL_ERROR || - code == TSDB_CODE_SYN_PROPOSE_NOT_READY || code == TSDB_CODE_VND_STOPPED || - code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING || - code == TSDB_CODE_APP_IS_STOPPING || code == TSDB_CODE_VND_STOPPED) { - tTrace("code str %s, contlen:%d 1", tstrerror(code), pResp->contLen); - noDelay = cliResetEpset(pCtx, pResp, true); - transFreeMsg(pResp->pCont); - addConnToPool(pThrd->pool, pConn); - } else if (code == TSDB_CODE_SYN_RESTORING) { - tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); - noDelay = cliResetEpset(pCtx, pResp, true); - addConnToPool(pThrd->pool, pConn); - transFreeMsg(pResp->pCont); - } else { - tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); - noDelay = cliResetEpset(pCtx, pResp, false); - addConnToPool(pThrd->pool, pConn); - transFreeMsg(pResp->pCont); - } - if (code != TSDB_CODE_RPC_BROKEN_LINK && code != TSDB_CODE_RPC_NETWORK_UNAVAIL && code != TSDB_CODE_SUCCESS) { - // save one internal code - pCtx->retryCode = code; - } +int8_t cliRetryShouldRetry(STrans* pInst, STransMsg* pResp) { + bool retry = pInst->retry != NULL ? pInst->retry(pResp->code, pResp->msgType - 1) : false; + return retry == false ? 0 : 1; +} +void cliRetryUpdateRule(SReqCtx* pCtx, int8_t noDelay) { if (noDelay == false) { pCtx->epsetRetryCnt = 1; pCtx->retryStep++; @@ -2749,28 +2792,85 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pCtx->retryNextInterval = 0; pCtx->epsetRetryCnt++; } +} - pMsg->sent = 0; - cliSchedMsgToNextNode(pMsg, pThrd); +int32_t cliRetryDoSched(SCliReq* pReq, SCliThrd* pThrd) { + int32_t code = cliSchedMsgToNextNode(pReq, pThrd); + if (code != 0) { + tError("failed to sched msg to next node since %s", tstrerror(code)); + return code; + } + return 0; +} + +bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + SReqCtx* pCtx = pReq->ctx; + int32_t code = pResp->code; + + if (pReq && pReq->msg.info.qId != 0) { + return false; + } + + cliRetryMayInitCtx(pInst, pReq); + + if (!cliRetryShouldRetry(pInst, pResp)) { + return false; + } + + if (cliRetryIsTimeout(pInst, pReq)) { + return false; + } + + // code, msgType + // A: epset,leader, not self + // B: epset,not know leader + // C: noepset,leader but not serivce + + bool noDelay = false; + if (code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { + tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); + noDelay = cliResetEpset(pCtx, pResp, false); + transFreeMsg(pResp->pCont); + } else if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_INTERNAL_ERROR || + code == TSDB_CODE_SYN_PROPOSE_NOT_READY || code == TSDB_CODE_VND_STOPPED || + code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING || + code == TSDB_CODE_APP_IS_STOPPING || code == TSDB_CODE_VND_STOPPED) { + tTrace("code str %s, contlen:%d 1", tstrerror(code), pResp->contLen); + noDelay = cliResetEpset(pCtx, pResp, true); + transFreeMsg(pResp->pCont); + } else if (code == TSDB_CODE_SYN_RESTORING) { + tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); + noDelay = cliResetEpset(pCtx, pResp, true); + transFreeMsg(pResp->pCont); + } else { + tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); + noDelay = cliResetEpset(pCtx, pResp, false); + transFreeMsg(pResp->pCont); + } + if (code != TSDB_CODE_RPC_BROKEN_LINK && code != TSDB_CODE_RPC_NETWORK_UNAVAIL && code != TSDB_CODE_SUCCESS) { + // save one internal code + pCtx->retryCode = code; + } + + cliRetryUpdateRule(pCtx, noDelay); + + pReq->sent = 0; + pReq->seq = 0; + + code = cliRetryDoSched(pReq, pThrd); + if (code != 0) { + pResp->code = code; + tError("failed to sched msg to next node since %s", tstrerror(code)); + return false; + } return true; } -int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - - if (pMsg == NULL || pMsg->ctx == NULL) { - tTrace("%s conn %p handle resp", pTransInst->label, pConn); - pTransInst->cfp(pTransInst->parent, pResp, NULL); - return 0; - } - - STransConnCtx* pCtx = pMsg->ctx; - - bool retry = cliGenRetryRule(pConn, pResp, pMsg); - if (retry == true) { - return -1; - } +void cliMayResetRespCode(SCliReq* pReq, STransMsg* pResp) { + SReqCtx* pCtx = pReq->ctx; if (pCtx->retryCode != TSDB_CODE_SUCCESS) { int32_t code = pResp->code; // return internal code app @@ -2781,22 +2881,24 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } // check whole vnodes is offline on this vgroup - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps || pCtx->retryStep > 0) { + if (((pCtx->epSet != NULL) && pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) || pCtx->retryStep > 0) { if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { pResp->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED; } else if (pResp->code == TSDB_CODE_RPC_BROKEN_LINK) { pResp->code = TSDB_CODE_RPC_SOMENODE_BROKEN_LINK; } } +} +int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STraceId* trace = &pResp->info.traceId; - bool hasEpSet = cliTryExtractEpSet(pResp, &pCtx->epSet); - if (hasEpSet) { - if (rpcDebugFlag & DEBUG_TRACE) { - char tbuf[512] = {0}; - TAOS_UNUSED(epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf))); - tGTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); - } + + if (pCtx == NULL) { + pInst->cfp(pInst->parent, pResp, NULL); + return 0; } if (pCtx->pSem || pCtx->syncMsgRef != 0) { tGTrace("%s conn %p(sync) handle resp", CONN_GET_INST_LABEL(pConn), pConn); @@ -2814,7 +2916,12 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { memcpy(pSyncMsg->pRsp, (char*)pResp, sizeof(*pResp)); if (cliIsEpsetUpdated(pResp->code, pCtx)) { pSyncMsg->hasEpSet = 1; - epsetAssign(&pSyncMsg->epSet, &pCtx->epSet); + + SEpSet epset = {0}; + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } + epsetAssign(&pSyncMsg->epSet, &epset); } TAOS_UNUSED(tsem2_post(pSyncMsg->pSem)); TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef)); @@ -2824,18 +2931,43 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } } else { tGTrace("%s conn %p handle resp", CONN_GET_INST_LABEL(pConn), pConn); - if (retry == false && hasEpSet == true) { - pTransInst->cfp(pTransInst->parent, pResp, &pCtx->epSet); + if (pResp->info.hasEpSet == 1) { + SEpSet epset = {0}; + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } + pInst->cfp(pInst->parent, pResp, &epset); } else { if (!cliIsEpsetUpdated(pResp->code, pCtx)) { - pTransInst->cfp(pTransInst->parent, pResp, NULL); + pInst->cfp(pInst->parent, pResp, NULL); } else { - pTransInst->cfp(pTransInst->parent, pResp, &pCtx->epSet); + SEpSet epset = {0}; + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } + pInst->cfp(pInst->parent, pResp, &epset); } } } return 0; } +int32_t cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + if (pReq != NULL) { + if (cliMayRetry(pConn, pReq, pResp)) { + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } + + cliMayResetRespCode(pReq, pResp); + + if (cliTryUpdateEpset(pReq, pResp)) { + cliPerfLog_epset(pConn, pReq); + } + } + return cliNotifyImplCb(pConn, pReq, pResp); +} void transCloseClient(void* arg) { int32_t code = 0; @@ -2843,7 +2975,7 @@ void transCloseClient(void* arg) { for (int i = 0; i < cli->numOfThreads; i++) { code = cliSendQuit(cli->pThreadObj[i]); if (code != 0) { - tError("failed to send quit to thread:%d, reason:%s", i, tstrerror(code)); + tError("failed to send quit to thread:%d since %s", i, tstrerror(code)); } destroyThrdObj(cli->pThreadObj[i]); @@ -2852,30 +2984,43 @@ void transCloseClient(void* arg) { taosMemoryFree(cli); } void transRefCliHandle(void* handle) { + int32_t ref = 0; if (handle == NULL) { return; } - int ref = T_REF_INC((SCliConn*)handle); - tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref); - UNUSED(ref); + SCliConn* conn = (SCliConn*)handle; + conn->ref++; + + tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL(conn), conn, conn->ref); } -void transUnrefCliHandle(void* handle) { +int32_t transUnrefCliHandle(void* handle) { if (handle == NULL) { - return; + return 0; } - int ref = T_REF_DEC((SCliConn*)handle); - tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref); - if (ref == 0) { - cliDestroyConn((SCliConn*)handle, true); + int32_t ref = 0; + SCliConn* conn = (SCliConn*)handle; + conn->ref--; + ref = conn->ref; + + tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL(conn), conn, conn->ref); + if (conn->ref == 0) { + cliDestroyConn(conn, true); } + return ref; +} + +int32_t transGetRefCount(void* handle) { + if (handle == NULL) { + return 0; + } + SCliConn* conn = (SCliConn*)handle; + return conn->ref; } static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t handle) { SCliThrd* pThrd = NULL; SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); if (exh == NULL) { return NULL; - } else { - tDebug("conn %p got", exh->handle); } taosWLockLatch(&exh->latch); if (exh->pThrd == NULL && trans != NULL) { @@ -2886,7 +3031,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t pThrd = exh->pThrd; taosWUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); + transReleaseExHandle(transGetRefMgt(), handle); return pThrd; } @@ -2906,145 +3051,141 @@ int32_t transReleaseCliHandle(void* handle) { return TSDB_CODE_RPC_BROKEN_LINK; } - STransMsg tmsg = {.info.handle = handle, .info.ahandle = (void*)0x9527}; + STransMsg tmsg = { + .msgType = TDMT_SCH_TASK_RELEASE, .info.handle = handle, .info.ahandle = (void*)0, .info.qId = (int64_t)handle}; + TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { return terrno; } - pCtx->ahandle = tmsg.info.ahandle; + SCliReq* cmsg = taosMemoryCalloc(1, sizeof(SCliReq)); - SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cmsg == NULL) { taosMemoryFree(pCtx); return terrno; } cmsg->msg = tmsg; cmsg->st = taosGetTimestampUs(); - cmsg->type = Release; + cmsg->type = Normal; cmsg->ctx = pCtx; STraceId* trace = &tmsg.info.traceId; tGDebug("send release request at thread:%08" PRId64 ", malloc memory:%p", pThrd->pid, cmsg); if ((code = transAsyncSend(pThrd->asyncPool, &cmsg->q)) != 0) { - destroyCmsg(cmsg); + destroyReq(cmsg); return code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code; } return code; } -static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliMsg** pCliMsg) { - if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); +static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliReq** pCliMsg) { + int32_t code = 0; + TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); + + SCliReq* pCliReq = NULL; + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _exception); } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + TAOS_CHECK_GOTO(code, NULL, _exception); + } + + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + TAOS_CHECK_GOTO(code, NULL, _exception); + } pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; - if (ctx != NULL) pCtx->appCtx = *ctx; + if (ctx != NULL) pCtx->userCtx = *ctx; - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); - if (cliMsg == NULL) { - taosMemoryFree(pCtx); - return terrno; + pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _exception); } - cliMsg->ctx = pCtx; - cliMsg->msg = *pReq; - cliMsg->st = taosGetTimestampUs(); - cliMsg->type = Normal; - cliMsg->refId = (int64_t)shandle; - QUEUE_INIT(&cliMsg->seqq); + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; - *pCliMsg = cliMsg; - - return 0; + *pCliMsg = pCliReq; + return code; +_exception: + if (pCtx != NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } + taosMemoryFree(pCliReq); + return code; } -int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { +int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; return TSDB_CODE_RPC_MODULE_QUIT; } int32_t code = 0; int64_t handle = (int64_t)pReq->info.handle; - SCliThrd* pThrd = transGetWorkThrd(pTransInst, handle); + SCliThrd* pThrd = transGetWorkThrd(pInst, handle); if (pThrd == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception;); + TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception); } - if (handle != 0) { - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); - if (exh != NULL) { - taosWLockLatch(&exh->latch); - if (exh->handle == NULL && exh->inited != 0) { - SCliMsg* pCliMsg = NULL; - code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); - if (code != 0) { - taosWUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); - TAOS_CHECK_GOTO(code, NULL, _exception); - } + pReq->info.qId = handle; - QUEUE_PUSH(&exh->q, &pCliMsg->seqq); - taosWUnLockLatch(&exh->latch); - - tDebug("msg refId: %" PRId64 "", handle); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); - return 0; - } else { - exh->inited = 1; - taosWUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); - } - } - } - - SCliMsg* pCliMsg = NULL; - TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); + SCliReq* pCliMsg = NULL; + TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; - tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, + tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { - destroyCmsg(pCliMsg); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + destroyReq(pCliMsg); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + + // if (pReq->msgType == TDMT_SCH_DROP_TASK) { + // TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); + // } + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (code != 0) { + tError("failed to send request since %s", tstrerror(code)); + } return code; } -int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { +int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { if (transpointId == NULL) { return TSDB_CODE_INVALID_PARA; } int32_t code = 0; - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_RPC_MODULE_QUIT, NULL, _exception); } TAOS_CHECK_GOTO(transAllocHandle(transpointId), NULL, _exception); - SCliThrd* pThrd = transGetWorkThrd(pTransInst, *transpointId); + SCliThrd* pThrd = transGetWorkThrd(pInst, *transpointId); if (pThrd == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception); } @@ -3055,43 +3196,53 @@ int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* p } pReq->info.handle = (void*)(*transpointId); + pReq->info.qId = *transpointId; - SCliMsg* pCliMsg = NULL; - TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); + SCliReq* pCliMsg = NULL; + TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; - tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, + tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { - destroyCmsg(pCliMsg); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + destroyReq(pCliMsg); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + + // if (pReq->msgType == TDMT_SCH_DROP_TASK) { + // TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); + // } + transReleaseExHandle(transGetRefMgt(), *transpointId); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + + tError("failed to send request since %s", tstrerror(code)); return code; } -int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) { - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { +int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; return TSDB_CODE_RPC_MODULE_QUIT; } - int32_t code = 0; + int32_t code = 0; + SCliReq* pCliReq = NULL; + SReqCtx* pCtx = NULL; STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg)); if (pTransRsp == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } - SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); + SCliThrd* pThrd = transGetWorkThrd(pInst, (int64_t)pReq->info.handle); if (pThrd == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _RETURN1); } @@ -3109,41 +3260,51 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { TAOS_UNUSED(tsem_destroy(sem)); taosMemoryFree(sem); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + (TAOS_UNUSED(tsem_destroy(sem))); + taosMemoryFree(sem); + TAOS_CHECK_GOTO(code, NULL, _RETURN1); + } + + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + (TAOS_UNUSED(tsem_destroy(sem))); + taosMemoryFree(sem); + TAOS_CHECK_GOTO(code, NULL, _RETURN1); + } + pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; pCtx->pSem = sem; pCtx->pRsp = pTransRsp; - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); - if (cliMsg == NULL) { - TAOS_UNUSED(tsem_destroy(sem)); + pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pCliReq == NULL) { + (TAOS_UNUSED(tsem_destroy(sem))); taosMemoryFree(sem); - taosMemoryFree(pCtx); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } - cliMsg->ctx = pCtx; - cliMsg->msg = *pReq; - cliMsg->st = taosGetTimestampUs(); - cliMsg->type = Normal; - cliMsg->refId = (int64_t)shandle; + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; STraceId* trace = &pReq->info.traceId; - tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, - EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); + tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, + EPSET_GET_INUSE_IP(pCtx->epSet), EPSET_GET_INUSE_PORT(pCtx->epSet), pReq->info.ahandle); - code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(cliMsg); + destroyReq(pReq); TAOS_CHECK_GOTO((code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code), NULL, _RETURN); } TAOS_UNUSED(tsem_wait(sem)); @@ -3153,16 +3314,22 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra _RETURN: tsem_destroy(sem); taosMemoryFree(sem); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); return code; _RETURN1: - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); taosMemoryFree(pReq->pCont); pReq->pCont = NULL; + if (pCtx != NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } return code; } + int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { int32_t code = 0; tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t)); @@ -3199,11 +3366,12 @@ _EXIT: taosMemoryFree(pSyncMsg); return code; } -int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, + +int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { int32_t code = 0; - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; return TSDB_CODE_RPC_MODULE_QUIT; @@ -3214,20 +3382,28 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } - SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); + SCliThrd* pThrd = transGetWorkThrd(pInst, (int64_t)pReq->info.handle); if (pThrd == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _RETURN2); } if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + taosMemoryFreeClear(pCtx->epSet); + TAOS_CHECK_GOTO(code, NULL, _RETURN2); + } + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + taosMemoryFreeClear(pCtx->epSet); + TAOS_CHECK_GOTO(code, NULL, _RETURN2); + } pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; @@ -3243,25 +3419,24 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _RETURN2); } - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); - if (cliMsg == NULL) { + SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == NULL) { taosMemoryFree(pCtx); TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } - cliMsg->ctx = pCtx; - cliMsg->msg = *pReq; - cliMsg->st = taosGetTimestampUs(); - cliMsg->type = Normal; - cliMsg->refId = (int64_t)shandle; + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; STraceId* trace = &pReq->info.traceId; - tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, - EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); + tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, + EPSET_GET_INUSE_IP(pCtx->epSet), EPSET_GET_INUSE_PORT(pCtx->epSet), pReq->info.ahandle); - code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(cliMsg); + destroyReq(pReq); TAOS_CHECK_GOTO(code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code, NULL, _RETURN); goto _RETURN; } @@ -3278,25 +3453,31 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, } } _RETURN: - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), ref)); TAOS_UNUSED(taosRemoveRef(transGetSyncMsgMgt(), ref)); return code; _RETURN2: transFreeMsg(pReq->pCont); + + if (pCtx != NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } pReq->pCont = NULL; taosMemoryFree(pTransMsg); - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } /* * **/ -int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { +int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { if (ip == NULL || fqdn == NULL) return TSDB_CODE_INVALID_PARA; - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } @@ -3306,31 +3487,39 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { cvtAddr.cvt = true; int32_t code = 0; - for (int8_t i = 0; i < pTransInst->numOfThreads; i++) { - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + for (int8_t i = 0; i < pInst->numOfThreads; i++) { + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { code = terrno; break; } - pCtx->cvtAddr = cvtAddr; - - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); - if (cliMsg == NULL) { + pCtx->pCvtAddr = (SCvtAddr*)taosMemoryCalloc(1, sizeof(SCvtAddr)); + if (pCtx->pCvtAddr == NULL) { taosMemoryFree(pCtx); code = terrno; break; } - cliMsg->ctx = pCtx; - cliMsg->type = Update; - cliMsg->refId = (int64_t)shandle; + memcpy(pCtx->pCvtAddr, &cvtAddr, sizeof(SCvtAddr)); - SCliThrd* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i]; - tDebug("%s update epset at thread:%08" PRId64, pTransInst->label, thrd->pid); + SCliReq* pReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == NULL) { + taosMemoryFree(pCtx->pCvtAddr); + taosMemoryFree(pCtx); + code = terrno; + break; + } - if ((code = transAsyncSend(thrd->asyncPool, &(cliMsg->q))) != 0) { - destroyCmsg(cliMsg); + pReq->ctx = pCtx; + pReq->type = Update; + + SCliThrd* thrd = ((SCliObj*)pInst->tcphandle)->pThreadObj[i]; + tDebug("%s update epset at thread:%08" PRId64, pInst->label, thrd->pid); + + if ((code = transAsyncSend(thrd->asyncPool, &(pReq->q))) != 0) { + taosMemoryFree(pCtx->pCvtAddr); + destroyReq(pReq); if (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT) { code = TSDB_CODE_RPC_MODULE_QUIT; } @@ -3338,7 +3527,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { } } - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } @@ -3362,15 +3551,14 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("pre alloc refId %" PRId64 ", alloc exhandle %p", exh->refId, exh); + tDebug("trans alloc sid:%" PRId64 ", malloc:%p", exh->refId, exh); *refId = exh->refId; return 0; } -int32_t transFreeConnById(void* shandle, int64_t transpointId) { - int32_t code = 0; - SCliMsg* pCli = NULL; - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - if (pTransInst == NULL) { +int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { + int32_t code = 0; + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (pInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } if (transpointId == 0) { @@ -3378,22 +3566,25 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { TAOS_CHECK_GOTO(0, NULL, _exception); } - SCliThrd* pThrd = transGetWorkThrdFromHandle(pTransInst, transpointId); + SCliThrd* pThrd = transGetWorkThrdFromHandle(pInst, transpointId); if (pThrd == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } - pCli = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* pCli = taosMemoryCalloc(1, sizeof(SCliReq)); if (pCli == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _exception); } - pCli->type = FreeById; + pCli->type = Normal; - tDebug("release conn id %" PRId64 "", transpointId); - - STransMsg msg = {.info.handle = (void*)transpointId}; + STransMsg msg = {.msgType = TDMT_SCH_TASK_RELEASE, .info.handle = (void*)transpointId}; + TRACE_SET_MSGID(&msg.info.traceId, tGenIdPI64()); + msg.info.qId = transpointId; pCli->msg = msg; + STraceId* trace = &pCli->msg.info.traceId; + tGDebug("%s start to free conn sid:%" PRId64 "", pInst->label, transpointId); + code = transAsyncSend(pThrd->asyncPool, &pCli->q); if (code != 0) { taosMemoryFreeClear(pCli); @@ -3401,14 +3592,363 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { } _exception: - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); - if (code != 0) { - if (transpointId != 0) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), transpointId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), transpointId)); - } - taosMemoryFree(pCli); - } - + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } + +static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHeap) { + int32_t code = 0; + size_t klen = strlen(key); + + SHeap* p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + SHeap heap = {0}; + code = transHeapInit(&heap, compareHeapNode); + if (code != 0) { + tError("failed to init heap cache for key:%s since %s", key, tstrerror(code)); + return code; + } + + code = taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); + if (code != 0) { + transHeapDestroy(&heap); + tError("failed to put heap to cache for key:%s since %s", key, tstrerror(code)); + return code; + } + p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + code = TSDB_CODE_INVALID_PARA; + } + } + *pHeap = p; + return code; +} + +bool filterTimeoutReq(void* key, void* arg) { + SListFilterArg* listArg = arg; + if (listArg == NULL) { + return false; + } + + int64_t st = listArg->id; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { + int64_t elapse = ((st - pReq->st) / 1000000); + if (listArg && elapse >= listArg->pInst->readTimeout) { + return true; + } else { + return false; + } + } + return false; +} + +static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) { + int32_t code = 0; + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + SArray* pQIdBuf = pThrd->pQIdBuf; + void* pIter = taosHashIterate(pConn->pQTable, NULL); + while (pIter) { + STransCtx* pCtx = (STransCtx*)pIter; + int64_t* qid = taosHashGetKey(pIter, NULL); + + if (((*st - pCtx->st) / 1000000) >= pInst->readTimeout) { + code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + if (code != 0) { + tError("%s conn %p failed to remove state sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); + } + + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); + + if (taosArrayPush(pQIdBuf, qid) == NULL) { + code = terrno; + tError("%s conn %p failed to add sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); + break; + } + tWarn("%s conn %p remove timeout msg sid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, *qid); + } + pIter = taosHashIterate(pConn->pQTable, pIter); + } + + for (int32_t i = 0; i < taosArrayGetSize(pQIdBuf); i++) { + int64_t* qid = taosArrayGet(pQIdBuf, i); + transQueueRemoveByFilter(&pConn->reqsSentOut, filterByQid, qid, set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterByQid, qid, set, -1); + + STransCtx* p = taosHashGet(pConn->pQTable, qid, sizeof(*qid)); + transCtxCleanup(p); + code = taosHashRemove(pConn->pQTable, qid, sizeof(*qid)); + if (code != 0) { + tError("%s conn %p failed to drop ctx of sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); + } + } + + taosArrayClear(pQIdBuf); +} + +static void cliConnRemoveTimeoutNoQidMsg(SCliConn* pConn, int64_t* st, queue* set) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + SListFilterArg arg = {.id = *st, .pInst = pInst}; + transQueueRemoveByFilter(&pConn->reqsSentOut, filterTimeoutReq, &arg, set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, &arg, set, -1); + return; +} + +static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + queue set; + QUEUE_INIT(&set); + + int64_t now = taosGetTimestampUs(); + + cliConnRemoveTimoutQidMsg(pConn, &now, &set); + cliConnRemoveTimeoutNoQidMsg(pConn, &now, &set); + + if (QUEUE_IS_EMPTY(&set)) { + return 0; + } + tWarn("%s conn %p do remove timeout msg", pInst->label, pConn); + destroyReqInQueue(pConn, &set, TSDB_CODE_RPC_TIMEOUT); + return 1; +} +static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); + int32_t reqsNum = transQueueSize(&pConn->reqsToSend); + int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); + int32_t stateNum = taosHashGetSize(pConn->pQTable); + int32_t totalReqs = reqsNum + reqsSentOut; + + if (totalReqs >= pInst->shareConnLimit) { + if (pConn->list == NULL && pConn->dstAddr != NULL) { + pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); + if (pConn->list != NULL) { + tTrace("conn %p get list %p from pool for key:%s", pConn, pConn->list, key); + } + } + if (pConn->list && pConn->list->totaSize >= pInst->connLimitNum / 4) { + tWarn("%s conn %p try to remove timeout msg since too many conn created", transLabel(pInst), pConn); + + if (cliConnRemoveTimeoutMsg(pConn)) { + tWarn("%s conn %p succ to remove timeout msg", transLabel(pInst), pConn); + } + return 1; + } + // check req timeout or not + return 1; + } + + return 0; +} + +static FORCE_INLINE bool filterToDebug(void* e, void* arg) { + SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); + STraceId* trace = &pReq->msg.info.traceId; + tGWarn("%s is sent to, and no resp from server", TMSG_INFO(pReq->msg.msgType)); + return false; +} +static FORCE_INLINE void logConnMissHit(SCliConn* pConn) { + // queue set; + // QUEUE_INIT(&set); + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + pConn->heapMissHit++; + tDebug("conn %p has %d reqs, %d sentout and %d status in process, total limit:%d, switch to other conn", pConn, + transQueueSize(&pConn->reqsToSend), transQueueSize(&pConn->reqsSentOut), taosHashGetSize(pConn->pQTable), + pInst->shareConnLimit); + // if (transQueueSize(&pConn->reqsSentOut) >= pInst->shareConnLimit) { + // transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); + // } +} +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { + int code = 0; + SHeap* pHeap = NULL; + SCliConn* pConn = NULL; + code = getOrCreateHeap(pConnHeapCache, key, &pHeap); + if (code != 0) { + tTrace("failed to get conn heap from cache for key:%s", key); + return NULL; + } + code = transHeapGet(pHeap, &pConn); + if (code != 0) { + tTrace("failed to get conn from heap cache for key:%s", key); + return NULL; + } else { + tTrace("conn %p get conn from heap cache for key:%s", pConn, key); + if (shouldSWitchToOtherConn(pConn, key)) { + code = balanceConnHeapCache(pConnHeapCache, pConn); + if (code != 0) { + tTrace("failed to balance conn heap cache for key:%s", key); + } + logConnMissHit(pConn); + return NULL; + } + } + + return pConn; +} +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { + SHeap* p = NULL; + int32_t code = 0; + + if (pConn->heap != NULL) { + p = pConn->heap; + tTrace("conn %p add to heap cache for key:%s,status:%d, refCnt:%d, add direct", pConn, pConn->dstAddr, + pConn->inHeap, pConn->reqRefCnt); + } else { + code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); + if (code != 0) { + return code; + } + if (pConn->connnected == 0) { + int64_t now = taosGetTimestampMs(); + if (now - p->lastConnFailTs < 3000) { + return TSDB_CODE_RPC_NETWORK_UNAVAIL; + } + } + } + + code = transHeapInsert(p, pConn); + tTrace("conn %p add to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, + pConn->reqRefCnt); + return code; +} + +static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + if (pConn->heap != NULL) { + tTrace("conn %p try to delete from heap cache direct", pConn); + return transHeapDelete(pConn->heap, pConn); + } + + SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); + if (p == NULL) { + tTrace("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); + return 0; + } + int32_t code = transHeapDelete(p, pConn); + if (code != 0) { + tTrace("conn %p failed delete from heap cache since %s", pConn, tstrerror(code)); + } + return code; +} + +static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + if (pConn->heap != NULL && pConn->inHeap != 0) { + SHeap* heap = pConn->heap; + tTrace("conn %p'heap may should do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); + int64_t now = taosGetTimestampMs(); + if (((now - heap->lastUpdateTs) / 1000) > 30) { + heap->lastUpdateTs = now; + tTrace("conn %p'heap do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); + return transHeapBalance(pConn->heap, pConn); + } + } + return 0; +} +// conn heap +int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { + SCliConn* args1 = container_of(a, SCliConn, node); + SCliConn* args2 = container_of(b, SCliConn, node); + + int32_t totalReq1 = transQueueSize(&args1->reqsToSend) + transQueueSize(&args1->reqsSentOut); + int32_t totalReq2 = transQueueSize(&args2->reqsToSend) + transQueueSize(&args2->reqsSentOut); + if (totalReq1 > totalReq2) { + return 0; + } + return 1; +} +int32_t transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)) { + heap->heap = heapCreate(cmpFunc); + if (heap->heap == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + heap->cmpFunc = cmpFunc; + return 0; +} +void transHeapDestroy(SHeap* heap) { + if (heap != NULL) { + heapDestroy(heap->heap); + } +} +int32_t transHeapGet(SHeap* heap, SCliConn** p) { + if (heapSize(heap->heap) == 0) { + *p = NULL; + return -1; + } + HeapNode* minNode = heapMin(heap->heap); + if (minNode == NULL) { + *p = NULL; + return -1; + } + *p = container_of(minNode, SCliConn, node); + return 0; +} +int32_t transHeapInsert(SHeap* heap, SCliConn* p) { + // impl later + p->reqRefCnt++; + if (p->inHeap == 1) { + tTrace("failed to insert conn %p since already in heap", p); + return TSDB_CODE_DUP_KEY; + } + + heapInsert(heap->heap, &p->node); + p->inHeap = 1; + p->lastAddHeapTime = taosGetTimestampMs(); + p->heap = heap; + return 0; +} +int32_t transHeapDelete(SHeap* heap, SCliConn* p) { + // impl later + if (p->connnected == 0) { + TAOS_UNUSED(transHeapUpdateFailTs(heap, p)); + } + + if (p->inHeap == 0) { + tTrace("failed to del conn %p since not in heap", p); + return 0; + } else { + int64_t now = taosGetTimestampMs(); + if (p->forceDelFromHeap == 0 && now - p->lastAddHeapTime < 10000) { + tTrace("conn %p not added/delete to heap frequently", p); + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } + } + + p->inHeap = 0; + p->reqRefCnt--; + if (p->reqRefCnt == 0) { + heapRemove(heap->heap, &p->node); + tTrace("conn %p delete from heap", p); + } else if (p->reqRefCnt < 0) { + tTrace("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); + } else { + tTrace("conn %p has %d reqs, not delete from heap", p, p->reqRefCnt); + } + return 0; +} + +int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p) { + heap->lastConnFailTs = taosGetTimestampMs(); + return 0; +} + +int32_t transHeapBalance(SHeap* heap, SCliConn* p) { + if (p->inHeap == 0 || heap == NULL || heap->heap == NULL) { + return 0; + } + heapRemove(heap->heap, &p->node); + heapInsert(heap->heap, &p->node); + return 0; +} diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index d3a79f330c..35ca6678b8 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -15,7 +15,7 @@ #include "transComm.h" -#define BUFFER_CAP 4096 +#define BUFFER_CAP 8 * 1024 static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT; @@ -59,7 +59,7 @@ int32_t transCompressMsg(char* msg, int32_t len) { taosMemoryFree(buf); return ret; } -int32_t transDecompressMsg(char** msg, int32_t len) { +int32_t transDecompressMsg(char** msg, int32_t* len) { STransMsgHead* pHead = (STransMsgHead*)(*msg); if (pHead->comp == 0) return 0; @@ -68,16 +68,18 @@ int32_t transDecompressMsg(char** msg, int32_t len) { STransCompMsg* pComp = (STransCompMsg*)pCont; int32_t oriLen = htonl(pComp->contLen); - char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); + int32_t tlen = *len; + char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); if (buf == NULL) { return terrno; } STransMsgHead* pNewHead = (STransMsgHead*)buf; int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content, - len - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); + tlen - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); memcpy((char*)pNewHead, (char*)pHead, sizeof(STransMsgHead)); + *len = oriLen + sizeof(STransMsgHead); pNewHead->msgLen = htonl(oriLen + sizeof(STransMsgHead)); taosMemoryFree(pHead); @@ -95,13 +97,12 @@ void transFreeMsg(void* msg) { tTrace("rpc free cont:%p", (char*)msg - TRANS_MSG_OVERHEAD); taosMemoryFree((char*)msg - sizeof(STransMsgHead)); } -int transSockInfo2Str(struct sockaddr* sockname, char* dst) { +void transSockInfo2Str(struct sockaddr* sockname, char* dst) { struct sockaddr_in addr = *(struct sockaddr_in*)sockname; char buf[20] = {0}; int r = uv_ip4_name(&addr, (char*)buf, sizeof(buf)); sprintf(dst, "%s:%d", buf, ntohs(addr.sin_port)); - return r; } int32_t transInitBuffer(SConnBuffer* buf) { buf->buf = taosMemoryCalloc(1, BUFFER_CAP); @@ -116,10 +117,9 @@ int32_t transInitBuffer(SConnBuffer* buf) { buf->invalid = 0; return 0; } -int32_t transDestroyBuffer(SConnBuffer* p) { +void transDestroyBuffer(SConnBuffer* p) { taosMemoryFree(p->buf); p->buf = NULL; - return 0; } int32_t transClearBuffer(SConnBuffer* buf) { @@ -184,7 +184,7 @@ int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { } } } else { - tError("failed to reset buffer, total:%d, len:%d, reason:%s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG)); + tError("failed to reset buffer, total:%d, len:%d since %s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG)); return TSDB_CODE_INVALID_MSG; } return 0; @@ -281,7 +281,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs async->data = item; err = uv_async_init(loop, async, cb); if (err != 0) { - tError("failed to init async, reason:%s", uv_err_name(err)); + tError("failed to init async since %s", uv_err_name(err)); code = TSDB_CODE_THIRDPARTY_ERROR; break; } @@ -333,14 +333,16 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { SAsyncItem* item = async->data; if (taosThreadMutexLock(&item->mtx) != 0) { - tError("failed to lock mutex"); + tError("failed to lock mutex since %s", tstrerror(terrno)); + return terrno; } QUEUE_PUSH(&item->qmsg, q); TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); + int ret = uv_async_send(async); if (ret != 0) { - tError("failed to send async,reason:%s", uv_err_name(ret)); + tError("failed to send async since %s", uv_err_name(ret)); return TSDB_CODE_THIRDPARTY_ERROR; } return 0; @@ -348,15 +350,17 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { void transCtxInit(STransCtx* ctx) { // init transCtx - ctx->args = taosHashInit(2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UINT), true, HASH_NO_LOCK); + ctx->args = taosHashInit(2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); } void transCtxCleanup(STransCtx* ctx) { - if (ctx->args == NULL) { + if (ctx == NULL || ctx->args == NULL) { return; } STransCtxVal* iter = taosHashIterate(ctx->args, NULL); while (iter) { + int32_t* type = taosHashGetKey(iter, NULL); + tDebug("free msg type %s dump func", TMSG_INFO(*type)); ctx->freeFunc(iter->val); iter = taosHashIterate(ctx->args, iter); } @@ -385,7 +389,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { int32_t code = taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); if (code != 0) { - tError("failed to put val to hash, reason:%s", tstrerror(code)); + tError("failed to put val to hash since %s", tstrerror(code)); } iter = taosHashIterate(src->args, iter); } @@ -415,120 +419,93 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { return ret; } -void transReqQueueInit(queue* q) { - // init req queue - QUEUE_INIT(q); -} -void* transReqQueuePush(queue* q) { - STransReq* req = taosMemoryCalloc(1, sizeof(STransReq)); - if (req == NULL) { - return NULL; - } - req->wreq.data = req; - QUEUE_PUSH(q, &req->q); - return &req->wreq; -} -void* transReqQueueRemove(void* arg) { - void* ret = NULL; - uv_write_t* wreq = arg; - - STransReq* req = wreq ? wreq->data : NULL; - if (req == NULL) return NULL; - QUEUE_REMOVE(&req->q); - - ret = wreq && wreq->handle ? wreq->handle->data : NULL; - taosMemoryFree(req); - - return ret; -} -void transReqQueueClear(queue* q) { - while (!QUEUE_IS_EMPTY(q)) { - queue* h = QUEUE_HEAD(q); - QUEUE_REMOVE(h); - STransReq* req = QUEUE_DATA(h, STransReq, q); - taosMemoryFree(req); - } -} - -int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { - queue->q = taosArrayInit(2, sizeof(void*)); - if (queue->q == NULL) { - return terrno; - } - queue->freeFunc = (void (*)(const void*))freeFunc; - +int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { + QUEUE_INIT(&wq->node); + wq->freeFunc = (void (*)(void*))freeFunc; + wq->size = 0; return 0; } -bool transQueuePush(STransQueue* queue, void* arg) { - if (queue->q == NULL) { - return true; - } - if (taosArrayPush(queue->q, &arg) == NULL) { - return false; - } - if (taosArrayGetSize(queue->q) > 1) { - return false; - } - return true; +void transQueuePush(STransQueue* q, void* arg) { + queue* node = arg; + QUEUE_PUSH(&q->node, node); + q->size++; } -void* transQueuePop(STransQueue* queue) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - void* ptr = taosArrayGetP(queue->q, 0); - taosArrayRemove(queue->q, 0); - return ptr; -} -int32_t transQueueSize(STransQueue* queue) { - if (queue->q == NULL) { - return 0; - } - return taosArrayGetSize(queue->q); -} -void* transQueueGet(STransQueue* queue, int i) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - if (i >= taosArrayGetSize(queue->q)) { - return NULL; - } +void* transQueuePop(STransQueue* q) { + if (q->size == 0) return NULL; - void* ptr = taosArrayGetP(queue->q, i); - return ptr; + queue* head = QUEUE_HEAD(&q->node); + QUEUE_REMOVE(head); + q->size--; + return head; +} +int32_t transQueueSize(STransQueue* q) { return q->size; } + +void* transQueueGet(STransQueue* q, int idx) { + if (q->size == 0) return NULL; + + while (idx-- > 0) { + queue* node = QUEUE_NEXT(&q->node); + if (node == &q->node) return NULL; + } + return NULL; } -void* transQueueRm(STransQueue* queue, int i) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - if (i >= taosArrayGetSize(queue->q)) { - return NULL; - } - void* ptr = taosArrayGetP(queue->q, i); - taosArrayRemove(queue->q, i); - return ptr; -} - -bool transQueueEmpty(STransQueue* queue) { - if (queue->q == NULL) { - return true; - } - return taosArrayGetSize(queue->q) == 0; -} -void transQueueClear(STransQueue* queue) { - if (queue->freeFunc != NULL) { - for (int i = 0; i < taosArrayGetSize(queue->q); i++) { - void* p = taosArrayGetP(queue->q, i); - queue->freeFunc(p); +void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size) { + queue* d = dst; + queue* node = QUEUE_NEXT(&q->node); + while (node != &q->node) { + queue* next = QUEUE_NEXT(node); + if (filter && filter(node, arg)) { + QUEUE_REMOVE(node); + q->size--; + QUEUE_PUSH(d, node); + if (--size == 0) { + break; + } } + node = next; } - taosArrayClear(queue->q); } -void transQueueDestroy(STransQueue* queue) { - transQueueClear(queue); - taosArrayDestroy(queue->q); + +void* tranQueueHead(STransQueue* q) { + if (q->size == 0) return NULL; + + queue* head = QUEUE_HEAD(&q->node); + return head; } +void* transQueueRm(STransQueue* q, int i) { + // if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { + // return NULL; + // } + // if (i >= taosArrayGetSize(queue->q)) { + // return NULL; + // } + // void* ptr = taosArrayGetP(queue->q, i); + // taosArrayRemove(queue->q, i); + // return ptr; + return NULL; +} + +void transQueueRemove(STransQueue* q, void* e) { + if (q->size == 0) return; + queue* node = e; + QUEUE_REMOVE(node); + q->size--; +} + +bool transQueueEmpty(STransQueue* q) { return q->size == 0 ? true : false; } + +void transQueueClear(STransQueue* q) { + while (!QUEUE_IS_EMPTY(&q->node)) { + queue* h = QUEUE_HEAD(&q->node); + QUEUE_REMOVE(h); + if (q->freeFunc != NULL) (q->freeFunc)(h); + q->size--; + } +} +void transQueueDestroy(STransQueue* q) { transQueueClear(q); } + static FORCE_INLINE int32_t timeCompare(const HeapNode* a, const HeapNode* b) { SDelayTask* arg1 = container_of(a, SDelayTask, node); SDelayTask* arg2 = container_of(b, SDelayTask, node); @@ -690,7 +667,13 @@ void transPrintEpSet(SEpSet* pEpSet) { len += tsnprintf(buf + len, sizeof(buf) - len, "}"); tTrace("%s, inUse:%d", buf, pEpSet->inUse); } -bool transEpSetIsEqual(SEpSet* a, SEpSet* b) { +bool transReqEpsetIsEqual(SReqEpSet* a, SReqEpSet* b) { + if (a == NULL && b == NULL) { + return true; + } else if (a == NULL || b == NULL) { + return false; + } + if (a->numOfEps != b->numOfEps || a->inUse != b->inUse) { return false; } @@ -701,7 +684,7 @@ bool transEpSetIsEqual(SEpSet* a, SEpSet* b) { } return true; } -bool transEpSetIsEqual2(SEpSet* a, SEpSet* b) { +bool transCompareReqAndUserEpset(SReqEpSet* a, SEpSet* b) { if (a->numOfEps != b->numOfEps) { return false; } @@ -757,28 +740,31 @@ int64_t transAddExHandle(int32_t refMgt, void* p) { // acquire extern handle return taosAddRef(refMgt, p); } -int32_t transRemoveExHandle(int32_t refMgt, int64_t refId) { +void transRemoveExHandle(int32_t refMgt, int64_t refId) { // acquire extern handle - return taosRemoveRef(refMgt, refId); + int32_t code = taosRemoveRef(refMgt, refId); + if (code != 0) { + tTrace("failed to remove %" PRId64 " from resetId:%d", refId, refMgt); + } } void* transAcquireExHandle(int32_t refMgt, int64_t refId) { // acquire extern handle return (void*)taosAcquireRef(refMgt, refId); } -int32_t transReleaseExHandle(int32_t refMgt, int64_t refId) { +void transReleaseExHandle(int32_t refMgt, int64_t refId) { // release extern handle - return taosReleaseRef(refMgt, refId); + int32_t code = taosReleaseRef(refMgt, refId); + if (code != 0) { + tTrace("failed to release %" PRId64 " from resetId:%d", refId, refMgt); + } } void transDestroyExHandle(void* handle) { if (handle == NULL) { return; } SExHandle* eh = handle; - if (!QUEUE_IS_EMPTY(&eh->q)) { - tDebug("handle %p mem leak", handle); - } - tDebug("free exhandle %p", handle); + tDebug("trans destroy sid:%" PRId64 ", memory %p", eh->refId, handle); taosMemoryFree(handle); } @@ -841,7 +827,7 @@ int32_t transUtilSIpRangeToStr(SIpV4Range* pRange, char* buf) { int32_t err = uv_inet_ntop(AF_INET, &addr, buf, 32); if (err != 0) { - tError("failed to convert ip to string, reason:%s", uv_strerror(err)); + tError("failed to convert ip to string since %s", uv_strerror(err)); return TSDB_CODE_THIRDPARTY_ERROR; } @@ -890,3 +876,113 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { // STUB_RAND_NETWORK_ERR(status) // return status; // } + +int32_t initWQ(queue* wq) { + int32_t code = 0; + QUEUE_INIT(wq); + for (int i = 0; i < 4; i++) { + SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + if (w == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _exception); + } + w->wreq.data = w; + w->arg = NULL; + QUEUE_INIT(&w->node); + QUEUE_PUSH(wq, &w->q); + } + return 0; +_exception: + destroyWQ(wq); + return code; +} +void destroyWQ(queue* wq) { + while (!QUEUE_IS_EMPTY(wq)) { + queue* h = QUEUE_HEAD(wq); + QUEUE_REMOVE(h); + SWReqsWrapper* w = QUEUE_DATA(h, SWReqsWrapper, q); + taosMemoryFree(w); + } +} + +uv_write_t* allocWReqFromWQ(queue* wq, void* arg) { + if (!QUEUE_IS_EMPTY(wq)) { + queue* node = QUEUE_HEAD(wq); + QUEUE_REMOVE(node); + SWReqsWrapper* w = QUEUE_DATA(node, SWReqsWrapper, q); + w->arg = arg; + QUEUE_INIT(&w->node); + + return &w->wreq; + } else { + SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + if (w == NULL) { + return NULL; + } + w->wreq.data = w; + w->arg = arg; + QUEUE_INIT(&w->node); + return &w->wreq; + } +} + +void freeWReqToWQ(queue* wq, SWReqsWrapper* w) { + QUEUE_INIT(&w->node); + QUEUE_PUSH(wq, &w->q); +} + +int32_t transSetReadOption(uv_handle_t* handle) { + int32_t code = 0; + int32_t fd; + int ret = uv_fileno((uv_handle_t*)handle, &fd); + if (ret != 0) { + tWarn("failed to get fd since %s", uv_err_name(ret)); + return TSDB_CODE_THIRDPARTY_ERROR; + } + code = taosSetSockOpt2(fd); + return code; +} + +int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet) { + if (pEpset == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + int32_t size = sizeof(SReqEpSet) + sizeof(SEp) * pEpset->numOfEps; + SReqEpSet* pReq = (SReqEpSet*)taosMemoryCalloc(1, size); + if (pReq == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + memcpy((char*)pReq, (char*)pEpset, size); + // clear previous + taosMemoryFree(*pReqEpSet); + + if (transValidReqEpset(pReq) != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + return TSDB_CODE_INVALID_PARA; + } + + *pReqEpSet = pReq; + return TSDB_CODE_SUCCESS; +} + +int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet) { + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + memcpy((char*)pEpSet, (char*)pReqEpSet, sizeof(SReqEpSet) + sizeof(SEp) * pReqEpSet->numOfEps); + return TSDB_CODE_SUCCESS; +} + +int32_t transValidReqEpset(SReqEpSet* pReqEpSet) { + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + if (pReqEpSet->numOfEps == 0 || pReqEpSet->numOfEps > TSDB_MAX_EP_NUM || pReqEpSet->inUse >= TSDB_MAX_EP_NUM) { + return TSDB_CODE_INVALID_PARA; + } + return TSDB_CODE_SUCCESS; +} \ No newline at end of file diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index d8737ef30f..a7c24f3fae 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -25,21 +25,20 @@ typedef struct { } SSvrRegArg; typedef struct SSvrConn { - T_REF_DECLARE() + int32_t ref; uv_tcp_t* pTcp; - queue wreqQueue; uv_timer_t pTimer; queue queue; SConnBuffer readBuf; // read buf, int inType; - void* pTransInst; // rpc init - void* ahandle; // + void* pInst; // rpc init + void* ahandle; // void* hostThrd; - STransQueue srvMsgs; + STransQueue resps; - SSvrRegArg regArg; - bool broken; // conn broken; + // SSvrRegArg regArg; + bool broken; // conn broken; ConnStatus status; @@ -54,22 +53,30 @@ typedef struct SSvrConn { int spi; char info[64]; char user[TSDB_UNI_LEN]; // user ID for the link + int8_t userInited; char secret[TSDB_PASSWORD_LEN]; char ckey[TSDB_PASSWORD_LEN]; // ciphering key int64_t whiteListVer; + + // state req dict + SHashObj* pQTable; + uv_buf_t* buf; + int32_t bufSize; + queue wq; // uv_write_t queue } SSvrConn; -typedef struct SSvrMsg { +typedef struct SSvrRespMsg { SSvrConn* pConn; STransMsg msg; queue q; STransMsgType type; + int64_t seqNum; + void* arg; + FilteFunc func; + int8_t sent; - void* arg; - FilteFunc func; - -} SSvrMsg; +} SSvrRespMsg; typedef struct { int64_t ver; @@ -91,13 +98,16 @@ typedef struct SWorkThrd { queue msg; queue conn; - void* pTransInst; + void* pInst; bool quit; SIpWhiteListTab* pWhiteList; int64_t whiteListVer; int8_t enableIpWhiteList; - int8_t inited; + + int32_t connRefMgt; + + int8_t inited; } SWorkThrd; typedef struct SServerObj { @@ -140,8 +150,6 @@ static void uvWorkerAsyncCb(uv_async_t* handle); static void uvAcceptAsyncCb(uv_async_t* handle); static void uvShutDownCb(uv_shutdown_t* req, int status); -static bool uvRecvReleaseReq(SSvrConn* conn, STransMsgHead* pHead); - /* * time-consuming task throwed into BG work thread */ @@ -151,27 +159,26 @@ static void uvWorkAfterTask(uv_work_t* req, int status); static void uvWalkCb(uv_handle_t* handle, void* arg); static void uvFreeCb(uv_handle_t* handle); -static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg); +static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg); -static int uvPrepareSendData(SSvrMsg* msg, uv_buf_t* wb); -static void uvStartSendResp(SSvrMsg* msg); +static int32_t uvPrepareSendData(SSvrRespMsg* msg, uv_buf_t* wb); +static void uvStartSendResp(SSvrRespMsg* msg); static void uvNotifyLinkBrokenToApp(SSvrConn* conn); -static FORCE_INLINE void destroySmsg(SSvrMsg* smsg); +static FORCE_INLINE void destroySmsg(SSvrRespMsg* smsg); static FORCE_INLINE SSvrConn* createConn(void* hThrd); static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear /*clear handle or not*/); -static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn); -static int32_t reallocConnRef(SSvrConn* conn); +int32_t uvGetConnRefOfThrd(SWorkThrd* thrd) { return thrd ? thrd->connRefMgt : -1; } -static void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleUpdate(SSvrMsg* pMsg, SWorkThrd* thrd); -static void (*transAsyncHandle[])(SSvrMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease, - uvHandleRegister, uvHandleUpdate}; +static void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleRegister(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleUpdate(SSvrRespMsg* pMsg, SWorkThrd* thrd); +static void (*transAsyncHandle[])(SSvrRespMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease, + uvHandleRegister, uvHandleUpdate}; static void uvDestroyConn(uv_handle_t* handle); @@ -373,32 +380,178 @@ void uvWhiteListSetConnVer(SIpWhiteListTab* pWhite, SSvrConn* pConn) { pConn->whiteListVer = pWhite->ver; } +static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* pTransMsg) { + if (!(rpcDebugFlag & DEBUG_DEBUG)) { + return; + } + + STrans* pInst = pConn->pInst; + STraceId* trace = &pHead->traceId; + + int64_t cost = taosGetTimestampUs() - taosNtoh64(pHead->timestamp); + static int64_t EXCEPTION_LIMIT_US = 100 * 1000; + + if (pConn->status == ConnNormal && pHead->noResp == 0) { + if (cost >= EXCEPTION_LIMIT_US) { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%" PRId64 + ", sid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%" PRId64 ", sid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); + } + } else { + if (cost >= EXCEPTION_LIMIT_US) { + tGDebug( + "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception, " + "seqNum:%" PRId64 ", sid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%" PRId64 + ", " + "sid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); + } + } + tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pInst), pTransMsg->info.handle, pConn, + pConn->refId); +} + +static int8_t uvValidConn(SSvrConn* pConn) { + STrans* pInst = pConn->pInst; + SWorkThrd* pThrd = pConn->hostThrd; + int8_t forbiddenIp = 0; + if (pThrd->enableIpWhiteList) { + forbiddenIp = !uvWhiteListCheckConn(pThrd->pWhiteList, pConn) ? 1 : 0; + if (forbiddenIp == 0) { + uvWhiteListSetConnVer(pThrd->pWhiteList, pConn); + } + } + return forbiddenIp; +} + +static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { + int32_t code = 0; + STrans* pInst = pConn->pInst; + if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { + int64_t qId = taosHton64(pHead->qid); + if (qId <= 0) { + tError("conn %p recv release, but invalid sid:%" PRId64 "", pConn, qId); + code = TSDB_CODE_RPC_NO_STATE; + } else { + void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); + if (p == NULL) { + code = TSDB_CODE_RPC_NO_STATE; + tTrace("conn %p recv release, and releady release by server sid:%" PRId64 "", pConn, qId); + } else { + SSvrRegArg* arg = p; + (pInst->cfp)(pInst->parent, &(arg->msg), NULL); + tTrace("conn %p recv release, notify server app, sid:%" PRId64 "", pConn, qId); + + code = taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("conn %p failed to remove sid:%" PRId64 "", pConn, qId); + } + tTrace("conn %p clear state,sid:%" PRId64 "", pConn, qId); + } + } + + STransMsg tmsg = {.code = code, + .msgType = pHead->msgType + 1, + .info.qId = qId, + .info.traceId = pHead->traceId, + .info.seqNum = taosHton64(pHead->seqNum)}; + + SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); + if (srvMsg == NULL) { + tError("conn %p recv release, failed to send release-resp since %s", pConn, tstrerror(terrno)); + taosMemoryFree(pHead); + return terrno; + } + srvMsg->msg = tmsg; + srvMsg->type = Normal; + srvMsg->pConn = pConn; + + transQueuePush(&pConn->resps, &srvMsg->q); + + uvStartSendRespImpl(srvMsg); + taosMemoryFree(pHead); + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } + return 0; +} + +bool uvConnMayGetUserInfo(SSvrConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { + if (pConn->userInited) { + return false; + } + + STrans* pInst = pConn->pInst; + STransMsgHead* pHead = *ppHead; + int32_t len = *msgLen; + if (pHead->withUserInfo) { + STransMsgHead* tHead = taosMemoryCalloc(1, len - sizeof(pInst->user)); + if (tHead == NULL) { + tError("conn %p failed to get user info since %s", pConn, tstrerror(terrno)); + return false; + } + memcpy((char*)tHead, (char*)pHead, TRANS_MSG_OVERHEAD); + memcpy((char*)tHead + TRANS_MSG_OVERHEAD, (char*)pHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), + len - sizeof(STransMsgHead) - sizeof(pInst->user)); + tHead->msgLen = htonl(htonl(pHead->msgLen) - sizeof(pInst->user)); + + memcpy(pConn->user, (char*)pHead + TRANS_MSG_OVERHEAD, sizeof(pConn->user)); + pConn->userInited = 1; + + taosMemoryFree(pHead); + *ppHead = tHead; + *msgLen = len - sizeof(pInst->user); + return true; + } + return false; +} static bool uvHandleReq(SSvrConn* pConn) { - STrans* pTransInst = pConn->pTransInst; + STrans* pInst = pConn->pInst; SWorkThrd* pThrd = pConn->hostThrd; int8_t acquire = 0; STransMsgHead* pHead = NULL; - int8_t resetBuf = pConn->status == ConnAcquire ? 0 : 1; - int msgLen = transDumpFromBuffer(&pConn->readBuf, (char**)&pHead, resetBuf); + int8_t resetBuf = 0; + int msgLen = transDumpFromBuffer(&pConn->readBuf, (char**)&pHead, 0); if (msgLen <= 0) { - tError("%s conn %p read invalid packet", transLabel(pTransInst), pConn); + tError("%s conn %p read invalid packet", transLabel(pInst), pConn); return false; } - if (resetBuf == 0) { - tTrace("%s conn %p not reset read buf", transLabel(pTransInst), pConn); + if (transDecompressMsg((char**)&pHead, &msgLen) < 0) { + tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); + taosMemoryFree(pHead); + return false; } - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { - tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pTransInst), pConn); - return false; + if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { + tDebug("%s conn %p get user info", transLabel(pInst), pConn); + } else { + if (pConn->userInited == 0) { + taosMemoryFree(pHead); + tDebug("%s conn %p failed get user info since %s", transLabel(pInst), pConn, tstrerror(terrno)); + return false; + } + tDebug("%s conn %p no need get user info", transLabel(pInst), pConn); } + + if (resetBuf == 0) { + tTrace("%s conn %p not reset read buf", transLabel(pInst), pConn); + } + pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); pConn->inType = pHead->msgType; - memcpy(pConn->user, pHead->user, strlen(pHead->user)); int8_t forbiddenIp = 0; if (pThrd->enableIpWhiteList && tsEnableWhiteList) { @@ -408,85 +561,39 @@ static bool uvHandleReq(SSvrConn* pConn) { } } - if (uvRecvReleaseReq(pConn, pHead)) { + if (uvMayHandleReleaseReq(pConn, pHead)) { return true; } - // TODO(dengyihao): time-consuming task throwed into BG Thread - // uv_work_t* wreq = taosMemoryMalloc(sizeof(uv_work_t)); - // wreq->data = pConn; - // uv_read_stop((uv_stream_t*)pConn->pTcp); - // transRefSrvHandle(pConn); - // uv_queue_work(((SWorkThrd*)pConn->hostThrd)->loop, wreq, uvWorkDoTask, uvWorkAfterTask); - - STransMsg transMsg; - memset(&transMsg, 0, sizeof(transMsg)); + STransMsg transMsg = {0}; transMsg.contLen = transContLenFromMsg(pHead->msgLen); transMsg.pCont = pHead->content; transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - if (pConn->status == ConnNormal) { - if (pHead->persist == 1) { - pConn->status = ConnAcquire; - transRefSrvHandle(pConn); - tDebug("conn %p acquired by server app", pConn); - } + if (pHead->seqNum == 0) { + STraceId* trace = &pHead->traceId; + tGError("%s conn %p received invalid seqNum, msgType:%s", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType)); + return false; } - STraceId* trace = &pHead->traceId; - int64_t cost = taosGetTimestampUs() - taosNtoh64(pHead->timestamp); - static int64_t EXCEPTION_LIMIT_US = 100 * 1000; - - if (pConn->status == ConnNormal && pHead->noResp == 0) { - transRefSrvHandle(pConn); - if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", - transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, (int)cost); - } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus", transLabel(pTransInst), pConn, - TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, (int)cost); - } - } else { - if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception", - transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, (int)(cost)); - } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus", - transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, (int)(cost)); - } - } + transMsg.info.handle = (void*)transAcquireExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); + transMsg.info.refIdMgt = pThrd->connRefMgt; // pHead->noResp = 1, // 1. server application should not send resp on handle // 2. once send out data, cli conn released to conn pool immediately // 3. not mixed with persist - transMsg.info.ahandle = (void*)pHead->ahandle; - - if (pHead->noResp == 1) { - transMsg.info.handle = NULL; - } else { - transMsg.info.handle = (void*)transAcquireExHandle(transGetSvrRefMgt(), pConn->refId); - acquire = 1; - } - transMsg.info.refId = pConn->refId; + transMsg.info.refId = pHead->noResp == 1 ? -1 : pConn->refId; transMsg.info.traceId = pHead->traceId; transMsg.info.cliVer = htonl(pHead->compatibilityVer); transMsg.info.forbiddenIp = forbiddenIp; transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; + transMsg.info.seqNum = taosHton64(pHead->seqNum); + transMsg.info.qId = taosHton64(pHead->qid); + transMsg.info.msgType = pHead->msgType; - tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, - pConn->refId); - // if (transMsg.info.handle == NULL) { - // tError("%s handle %p conn:%p handle failed to init" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn); - // return false; - // } - - if (pHead->noResp == 1) { - transMsg.info.refId = -1; - } + uvPerfLog_receive(pConn, pHead, &transMsg); // set up conn info SRpcConnInfo* pConnInfo = &(transMsg.info.conn); @@ -494,14 +601,16 @@ static bool uvHandleReq(SSvrConn* pConn) { pConnInfo->clientPort = pConn->port; tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user)); - if (acquire) transReleaseExHandle(transGetSvrRefMgt(), pConn->refId); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); - (*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL); + (*pInst->cfp)(pInst->parent, &transMsg, NULL); return true; } void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; SSvrConn* conn = cli->data; + STrans* pInst = conn->pInst; SWorkThrd* pThrd = conn->hostThrd; STUB_RAND_NETWORK_ERR(nread); @@ -511,7 +620,11 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { destroyConn(conn, true); return; } - STrans* pTransInst = conn->pTransInst; + + code = transSetReadOption((uv_handle_t*)cli); + if (code != 0) { + tWarn("%s conn %p failed to set recv opt since %s", transLabel(pInst), conn, tstrerror(code)); + } SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -519,17 +632,18 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { if (pBuf->len <= TRANS_PACKET_LIMIT) { while (transReadComplete(pBuf)) { if (true == pBuf->invalid || false == uvHandleReq(conn)) { - tError("%s conn %p read invalid packet, received from %s, local info:%s", transLabel(pTransInst), conn, - conn->dst, conn->src); - destroyConn(conn, true); + tError("%s conn %p read invalid packet, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, + conn->src); + conn->broken = true; + transUnrefSrvHandle(conn); return; } } return; } else { - tError("%s conn %p read invalid packet, exceed limit, received from %s, local info:%s", transLabel(pTransInst), - conn, conn->dst, conn->src); - destroyConn(conn, true); + tError("%s conn %p read invalid packet, exceed limit, received from %s, local info:%s", transLabel(pInst), conn, + conn->dst, conn->src); + transUnrefSrvHandle(conn); return; } } @@ -537,18 +651,10 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { return; } - tDebug("%s conn %p read error:%s", transLabel(pTransInst), conn, uv_err_name(nread)); + tDebug("%s conn %p read error:%s", transLabel(pInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; - if (conn->status == ConnAcquire) { - if (conn->regArg.init) { - tTrace("%s conn %p broken, notify server app", transLabel(pTransInst), conn); - STrans* pTransInst = conn->pTransInst; - (*pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - } - destroyConn(conn, true); + transUnrefSrvHandle(conn); } } void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { @@ -567,60 +673,51 @@ void uvOnTimeoutCb(uv_timer_t* handle) { void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - SSvrConn* conn = transReqQueueRemove(req); - if (conn == NULL) return; + SWReqsWrapper* wrapper = req->data; + SSvrConn* conn = wrapper->arg; + + queue src; + QUEUE_INIT(&src); + QUEUE_MOVE(&wrapper->node, &src); + + freeWReqToWQ(&conn->wq, wrapper); + + tDebug("%s conn %p send data out ", transLabel(conn->pInst), conn); if (status == 0) { - tTrace("conn %p data already was written on stream", conn); - if (!transQueueEmpty(&conn->srvMsgs)) { - SSvrMsg* msg = transQueuePop(&conn->srvMsgs); - STraceId* trace = &msg->msg.info.traceId; - tGDebug("conn %p write data out", conn); + while (!QUEUE_IS_EMPTY(&src)) { + queue* head = QUEUE_HEAD(&src); + QUEUE_REMOVE(head); - destroySmsg(msg); - // send cached data - if (!transQueueEmpty(&conn->srvMsgs)) { - msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); - if (msg->type == Register && conn->status == ConnAcquire) { - if (conn->regArg.init) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } - conn->regArg.notifyCount = 0; - conn->regArg.init = 1; - conn->regArg.msg = msg->msg; - if (conn->broken) { - STrans* pTransInst = conn->pTransInst; - (pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - TAOS_UNUSED(transQueuePop(&conn->srvMsgs)); - taosMemoryFree(msg); - - msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); - if (msg != NULL) { - uvStartSendRespImpl(msg); - } - } else { - uvStartSendRespImpl(msg); - } - } + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + STraceId* trace = &smsg->msg.info.traceId; + tGDebug("%s conn %p msg already send out, seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(conn->pInst), conn, + smsg->msg.info.seqNum, smsg->msg.info.qId); + destroySmsg(smsg); } - transUnrefSrvHandle(conn); } else { - if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { - tError("conn %p failed to write data, %s", conn, uv_err_name(status)); - conn->broken = true; - transUnrefSrvHandle(conn); + while (!QUEUE_IS_EMPTY(&src)) { + queue* head = QUEUE_HEAD(&src); + QUEUE_REMOVE(head); + + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + STraceId* trace = &smsg->msg.info.traceId; + tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", sid:%" PRId64 " since %s", transLabel(conn->pInst), conn, + smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); + destroySmsg(smsg); } + + conn->broken = true; + transUnrefSrvHandle(conn); } + transUnrefSrvHandle(conn); } static void uvOnPipeWriteCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); if (status == 0) { tTrace("success to dispatch conn to work thread"); } else { - tError("fail to dispatch conn to work thread, reason:%s", uv_strerror(status)); + tError("fail to dispatch conn to work thread since %s", uv_strerror(status)); } if (!uv_is_closing((uv_handle_t*)req->data)) { uv_close((uv_handle_t*)req->data, uvFreeCb); @@ -630,7 +727,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { taosMemoryFree(req); } -static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { +static int32_t uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { SSvrConn* pConn = smsg->pConn; STransMsg* pMsg = &smsg->msg; if (pMsg->pCont == 0) { @@ -638,109 +735,181 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { if (pMsg->pCont == NULL) { return terrno; } - pMsg->contLen = 0; } STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); - pHead->ahandle = (uint64_t)pMsg->info.ahandle; pHead->traceId = pMsg->info.traceId; pHead->hasEpSet = pMsg->info.hasEpSet; pHead->magicNum = htonl(TRANS_MAGIC_NUM); - pHead->compatibilityVer = htonl(((STrans*)pConn->pTransInst)->compatibilityVer); + pHead->compatibilityVer = htonl(((STrans*)pConn->pInst)->compatibilityVer); pHead->version = TRANS_VER; + pHead->seqNum = taosHton64(pMsg->info.seqNum); + pHead->qid = taosHton64(pMsg->info.qId); + pHead->withUserInfo = pConn->userInited == 0 ? 1 : 0; // handle invalid drop_task resp, TD-20098 - if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - TAOS_UNUSED(transQueuePop(&pConn->srvMsgs)); - destroySmsg(smsg); - return TSDB_CODE_INVALID_MSG; - } + // if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { + // // return TSDB_CODE_INVALID_MSG; + // return 0; + // } - if (pConn->status == ConnNormal) { - pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - if (smsg->type == Release) pHead->msgType = 0; - } else { - if (smsg->type == Release) { - pHead->msgType = 0; - pConn->status = ConnNormal; - destroyConnRegArg(pConn); - transUnrefSrvHandle(pConn); - } else { - // set up resp msg type - pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - } - } - - pHead->release = smsg->type == Release ? 1 : 0; + pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); + // pHead->msgType = pMsg->msgType; + // pHead->release = smsg->type == Release ? 1 : 0; pHead->code = htonl(pMsg->code); pHead->msgLen = htonl(pMsg->contLen + sizeof(STransMsgHead)); char* msg = (char*)pHead; int32_t len = transMsgLenFromCont(pMsg->contLen); - STrans* pTransInst = pConn->pTransInst; - if (pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp && pTransInst->compressSize != -1 && - pTransInst->compressSize < pMsg->contLen) { + STrans* pInst = pConn->pInst; + if (pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp && pInst->compressSize != -1 && + pInst->compressSize < pMsg->contLen) { len = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)len); } STraceId* trace = &pMsg->info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d", transLabel(pTransInst), pConn, - TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len); + tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(pInst), + pConn, TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); wb->base = (char*)pHead; wb->len = len; return 0; } +static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum, queue* toSendQ) { + int32_t code = 0; + int32_t size = transQueueSize(&pConn->resps); + tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); + if (size == 0) { + return 0; + } -static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { + if (pConn->bufSize < size) { + pConn->buf = taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + if (pConn->buf == NULL) { + return terrno; + } + pConn->bufSize = size; + } + uv_buf_t* pWb = pConn->buf; + + int32_t count = 0; + + while (transQueueSize(&pConn->resps) > 0) { + queue* el = transQueuePop(&pConn->resps); + SSvrRespMsg* pMsg = QUEUE_DATA(el, SSvrRespMsg, q); + uv_buf_t wb; + code = uvPrepareSendData(pMsg, &wb); + if (code != 0) { + return code; + } + pWb[count] = wb; + pMsg->sent = 1; + QUEUE_PUSH(toSendQ, &pMsg->q); + count++; + } + + if (count == 0) { + return 0; + } + + *bufNum = count; + *ppBuf = pWb; + + return 0; +} + +static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { + int32_t code = 0; SSvrConn* pConn = smsg->pConn; if (pConn->broken) { return; } + int32_t size = transQueueSize(&pConn->resps); + if (size == 0) { + tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); + return; + } - uv_buf_t wb; - if (uvPrepareSendData(smsg, &wb) < 0) { + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); + if (req == NULL) { + uError("%s conn %p failed to alloc write req since %s", transLabel(pConn->pInst), pConn, tstrerror(terrno)); + transUnrefSrvHandle(pConn); + return; + } + SWReqsWrapper* pWreq = req->data; + + uv_buf_t* pBuf = NULL; + int32_t bufNum = 0; + code = uvBuildToSendData(pConn, &pBuf, &bufNum, &pWreq->node); + if (code != 0) { + tError("%s conn %p failed to send data", transLabel(pConn->pInst), pConn); + return; + } + if (bufNum == 0) { + tDebug("%s conn %p no data to send", transLabel(pConn->pInst), pConn); return; } transRefSrvHandle(pConn); - uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); - if (req == NULL) { - tError("failed to send resp since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return; + + int32_t ret = uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); + if (ret != 0) { + tError("conn %p failed to write data since %s", pConn, uv_err_name(ret)); + pConn->broken = true; + while (!QUEUE_IS_EMPTY(&pWreq->node)) { + queue* head = QUEUE_HEAD(&pWreq->node); + QUEUE_REMOVE(head); + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + destroySmsg(smsg); + } + freeWReqToWQ(&pConn->wq, req->data); + + transUnrefSrvHandle(pConn); } - TAOS_UNUSED(uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb)); } -static void uvStartSendResp(SSvrMsg* smsg) { +int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { + int32_t code = 0; + SSvrConn* pConn = pMsg->pConn; + int64_t qid = pMsg->msg.info.qId; + if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { + SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (p == NULL) { + tError("%s conn %p already release sid:%" PRId64 "", transLabel(pConn->pInst), pConn, qid); + return TSDB_CODE_RPC_NO_STATE; + } else { + transFreeMsg(p->msg.pCont); + code = taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); + if (code != 0) { + tError("%s conn %p failed to release sid:%" PRId64 " since %s", transLabel(pConn->pInst), pConn, qid, + tstrerror(code)); + } + } + } + return 0; +} +static void uvStartSendResp(SSvrRespMsg* smsg) { // impl SSvrConn* pConn = smsg->pConn; - if (pConn->broken == true) { - // persist by + if (uvMayHandleReleaseResp(smsg) == TSDB_CODE_RPC_NO_STATE) { destroySmsg(smsg); - transUnrefSrvHandle(pConn); return; } - if (pConn->status == ConnNormal) { - transUnrefSrvHandle(pConn); - } - if (!transQueuePush(&pConn->srvMsgs, smsg)) { - return; - } + transQueuePush(&pConn->resps, &smsg->q); uvStartSendRespImpl(smsg); return; } -static FORCE_INLINE void destroySmsg(SSvrMsg* smsg) { +static FORCE_INLINE void destroySmsg(SSvrRespMsg* smsg) { if (smsg == NULL) { return; } transFreeMsg(smsg->msg.pCont); taosMemoryFree(smsg); } -static FORCE_INLINE void destroySmsgWrapper(void* smsg, void* param) { destroySmsg((SSvrMsg*)smsg); } +static FORCE_INLINE void destroySmsgWrapper(void* smsg, void* param) { destroySmsg((SSvrRespMsg*)smsg); } static void destroyAllConn(SWorkThrd* pThrd) { tTrace("thread %p destroy all conn ", pThrd); @@ -750,7 +919,7 @@ static void destroyAllConn(SWorkThrd* pThrd) { QUEUE_INIT(h); SSvrConn* c = QUEUE_DATA(h, SSvrConn, queue); - while (T_REF_VAL_GET(c) >= 2) { + while (c->ref >= 2) { transUnrefSrvHandle(c); } transUnrefSrvHandle(c); @@ -777,7 +946,7 @@ void uvWorkerAsyncCb(uv_async_t* handle) { queue* head = QUEUE_HEAD(&wq); QUEUE_REMOVE(head); - SSvrMsg* msg = QUEUE_DATA(head, SSvrMsg, q); + SSvrRespMsg* msg = QUEUE_DATA(head, SSvrRespMsg, q); if (msg == NULL) { tError("unexcept occurred, continue"); continue; @@ -791,15 +960,17 @@ void uvWorkerAsyncCb(uv_async_t* handle) { SExHandle* exh1 = transMsg.info.handle; int64_t refId = transMsg.info.refId; - SExHandle* exh2 = transAcquireExHandle(transGetSvrRefMgt(), refId); + msg->seqNum = transMsg.info.seqNum; + + SExHandle* exh2 = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -827,47 +998,6 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { uv_close((uv_handle_t*)req->handle, uvDestroyConn); taosMemoryFree(req); } -static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { - if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - int32_t code = reallocConnRef(pConn); - if (code != 0) { - destroyConn(pConn, true); - return true; - } - tTrace("conn %p received release request", pConn); - - STraceId traceId = pHead->traceId; - TAOS_UNUSED(transClearBuffer(&pConn->readBuf)); - transFreeMsg(transContFromHead((char*)pHead)); - if (pConn->status != ConnAcquire) { - return true; - } - pConn->status = ConnRelease; - - STransMsg tmsg = {.code = 0, .info.handle = (void*)pConn, .info.traceId = traceId, .info.ahandle = (void*)0x9527}; - SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); - if (srvMsg == NULL) { - tError("failed to alloc buf to send release resp since %s", tstrerror(terrno)); - return true; - } - srvMsg->msg = tmsg; - srvMsg->type = Release; - srvMsg->pConn = pConn; - if (!transQueuePush(&pConn->srvMsgs, srvMsg)) { - return true; - } - if (pConn->regArg.init) { - tTrace("conn %p release, notify server app", pConn); - STrans* pTransInst = pConn->pTransInst; - (*pTransInst->cfp)(pTransInst->parent, &(pConn->regArg.msg), NULL); - memset(&pConn->regArg, 0, sizeof(pConn->regArg)); - } - uvStartSendRespImpl(srvMsg); - return true; - } - return false; -} - static void uvWorkDoTask(uv_work_t* req) { // doing time-consumeing task // only auth conn currently, add more func later @@ -938,13 +1068,14 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { } } void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; STUB_RAND_NETWORK_ERR(nread); if (nread < 0) { if (nread != UV_EOF) { tError("read error %s", uv_err_name(nread)); } // TODO(log other failure reason) - tWarn("failed to create connect:%p, reason: %s", q, uv_err_name(nread)); + tWarn("failed to create connect:%p since %s", q, uv_err_name(nread)); taosMemoryFree(buf->base); uv_close((uv_handle_t*)q, NULL); return; @@ -962,33 +1093,22 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { uv_pipe_t* pipe = (uv_pipe_t*)q; if (!uv_pipe_pending_count(pipe)) { - tError("no pending count, unexpected error"); - uv_close((uv_handle_t*)q, NULL); + tError("No pending count"); + // uv_close((uv_handle_t*)q, NULL); return; } if (pThrd->quit) { tWarn("thread already received quit msg, ignore incoming conn"); - - uv_close((uv_handle_t*)q, NULL); + // uv_close((uv_handle_t*)q, NULL); return; } SSvrConn* pConn = createConn(pThrd); if (pConn == NULL) { - uv_close((uv_handle_t*)q, NULL); + // uv_close((uv_handle_t*)q, NULL); return; } - // pConn->pTransInst = pThrd->pTransInst; - // /* init conn timer*/ - // // uv_timer_init(pThrd->loop, &pConn->pTimer); - // // pConn->pTimer.data = pConn; - // pConn->hostThrd = pThrd; - // // init client handle - // pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); - // uv_tcp_init(pThrd->loop, pConn->pTcp); - // pConn->pTcp->data = pConn; - if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { uv_os_fd_t fd; TAOS_UNUSED(uv_fileno((const uv_handle_t*)pConn->pTcp, &fd)); @@ -1018,8 +1138,16 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { pConn->serverIp = saddr.sin_addr.s_addr; pConn->port = ntohs(addr.sin_port); - TAOS_UNUSED(uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb)); - + code = transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); + if (code != 0) { + tWarn("failed to set tcp option since %s", tstrerror(code)); + } + code = uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); + if (code != 0) { + tWarn("conn %p failed to start to read since %s", pConn, uv_err_name(code)); + transUnrefSrvHandle(pConn); + return; + } } else { tDebug("failed to create new connection"); transUnrefSrvHandle(pConn); @@ -1142,91 +1270,114 @@ static int32_t addHandleToAcceptloop(void* arg) { } void* transWorkerThread(void* arg) { + int32_t code = 0; setThreadName("trans-svr-work"); SWorkThrd* pThrd = (SWorkThrd*)arg; - TAOS_UNUSED(uv_run(pThrd->loop, UV_RUN_DEFAULT)); + tsEnableRandErr = true; + code = uv_run(pThrd->loop, UV_RUN_DEFAULT); + if (code != 0) { + tWarn("failed to start to worker thread since %s", uv_err_name(code)); + } return NULL; } - +void uvDestroyResp(void* e) { + SSvrRespMsg* pMsg = QUEUE_DATA(e, SSvrRespMsg, q); + destroySmsg(pMsg); +} static FORCE_INLINE SSvrConn* createConn(void* hThrd) { int32_t code = 0; SWorkThrd* pThrd = hThrd; + int32_t lino; SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); if (pConn == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } - transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); - QUEUE_PUSH(&pThrd->conn, &pConn->queue); - if ((code = transQueueInit(&pConn->srvMsgs, NULL)) != 0) { - TAOS_CHECK_GOTO(code, NULL, _end); + if ((code = transQueueInit(&pConn->resps, uvDestroyResp)) != 0) { + TAOS_CHECK_GOTO(code, &lino, _end); } if ((code = transInitBuffer(&pConn->readBuf)) != 0) { - TAOS_CHECK_GOTO(code, NULL, _end); + TAOS_CHECK_GOTO(code, &lino, _end); } - memset(&pConn->regArg, 0, sizeof(pConn->regArg)); pConn->broken = false; pConn->status = ConnNormal; SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); if (exh == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } exh->handle = pConn; exh->pThrd = pThrd; - exh->refId = transAddExHandle(transGetSvrRefMgt(), exh); + exh->refId = transAddExHandle(uvGetConnRefOfThrd(pThrd), exh); if (exh->refId < 0) { - TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, &lino, _end); } QUEUE_INIT(&exh->q); - SExHandle* pSelf = transAcquireExHandle(transGetSvrRefMgt(), exh->refId); + SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), exh->refId); if (pSelf != exh) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); } - STrans* pTransInst = pThrd->pTransInst; + STrans* pInst = pThrd->pInst; pConn->refId = exh->refId; - QUEUE_INIT(&exh->q); - transRefSrvHandle(pConn); - tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pTransInst), exh, pConn, pConn->refId); - pConn->pTransInst = pThrd->pTransInst; - /* init conn timer*/ - // uv_timer_init(pThrd->loop, &pConn->pTimer); - // pConn->pTimer.data = pConn; - pConn->hostThrd = pThrd; + QUEUE_INIT(&exh->q); + tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pInst), exh, pConn, pConn->refId); + + pConn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (pConn->pQTable == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); + } + + code = initWQ(&pConn->wq); + TAOS_CHECK_GOTO(code, &lino, _end); + // init client handle pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (pConn->pTcp == NULL) { - TAOS_CHECK_GOTO(terrno, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); + } + + pConn->bufSize = pInst->shareConnLimit; + pConn->buf = taosMemoryCalloc(1, pInst->shareConnLimit * sizeof(uv_buf_t)); + if (pConn->buf == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } code = uv_tcp_init(pThrd->loop, pConn->pTcp); if (code != 0) { - tError("%s failed to create conn since %s" PRId64, transLabel(pTransInst), uv_strerror(code)); + tError("%s failed to create conn since %s" PRId64, transLabel(pInst), uv_strerror(code)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); } pConn->pTcp->data = pConn; + QUEUE_PUSH(&pThrd->conn, &pConn->queue); + pConn->pInst = pThrd->pInst; + pConn->hostThrd = pThrd; + + transRefSrvHandle(pConn); return pConn; _end: if (pConn) { - transQueueDestroy(&pConn->srvMsgs); - TAOS_UNUSED(transDestroyBuffer(&pConn->readBuf)); + transQueueDestroy(&pConn->resps); + transDestroyBuffer(&pConn->readBuf); + taosHashCleanup(pConn->pQTable); taosMemoryFree(pConn->pTcp); + destroyWQ(&pConn->wq); + taosMemoryFree(pConn->buf); taosMemoryFree(pConn); pConn = NULL; } - tError("%s failed to create conn since %s" PRId64, transLabel(pTransInst), tstrerror(code)); + tError("%s failed to create conn since %s" PRId64, transLabel(pInst), tstrerror(code)); return NULL; } @@ -1242,42 +1393,24 @@ static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear) { } } } -static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { - if (conn->regArg.init == 1) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } -} -static int32_t reallocConnRef(SSvrConn* conn) { - if (conn->refId > 0) { - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetSvrRefMgt(), conn->refId)); - } - // avoid app continue to send msg on invalid handle - SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); - if (exh == NULL) { - return terrno; + +void uvConnDestroyAllState(SSvrConn* p) { + STrans* pInst = p->pInst; + SHashObj* pQTable = p->pQTable; + if (pQTable == NULL) return; + + void* pIter = taosHashIterate(pQTable, NULL); + while (pIter) { + SSvrRegArg* arg = pIter; + int64_t* qid = taosHashGetKey(pIter, NULL); + (pInst->cfp)(pInst->parent, &(arg->msg), NULL); + tTrace("conn %p broken, notify server app, sid:%" PRId64 "", p, *qid); + pIter = taosHashIterate(pQTable, pIter); } - exh->handle = conn; - exh->pThrd = conn->hostThrd; - exh->refId = transAddExHandle(transGetSvrRefMgt(), exh); - if (exh->refId < 0) { - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - QUEUE_INIT(&exh->q); - SExHandle* pSelf = transAcquireExHandle(transGetSvrRefMgt(), exh->refId); - if (pSelf != exh) { - tError("conn %p failed to acquire handle", conn); - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - conn->refId = exh->refId; - - return 0; + taosHashCleanup(pQTable); + pQTable = NULL; + return; } static void uvDestroyConn(uv_handle_t* handle) { SSvrConn* conn = handle->data; @@ -1287,23 +1420,24 @@ static void uvDestroyConn(uv_handle_t* handle) { } SWorkThrd* thrd = conn->hostThrd; - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetSvrRefMgt(), conn->refId)); + transReleaseExHandle(uvGetConnRefOfThrd(thrd), conn->refId); + transRemoveExHandle(uvGetConnRefOfThrd(thrd), conn->refId); - STrans* pTransInst = thrd->pTransInst; - tDebug("%s conn %p destroy", transLabel(pTransInst), conn); + STrans* pInst = thrd->pInst; + tDebug("%s conn %p destroy", transLabel(pInst), conn); - for (int i = 0; i < transQueueSize(&conn->srvMsgs); i++) { - SSvrMsg* msg = transQueueGet(&conn->srvMsgs, i); - destroySmsg(msg); - } - transQueueDestroy(&conn->srvMsgs); - transReqQueueClear(&conn->wreqQueue); + transQueueDestroy(&conn->resps); QUEUE_REMOVE(&conn->queue); + taosMemoryFree(conn->pTcp); - destroyConnRegArg(conn); - TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); + + uvConnDestroyAllState(conn); + + transDestroyBuffer(&conn->readBuf); + + destroyWQ(&conn->wq); + taosMemoryFree(conn->buf); taosMemoryFree(conn); if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) { @@ -1350,7 +1484,7 @@ static void uvPipeListenCb(uv_stream_t* handle, int status) { srv->numOfWorkerReady++; } -void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { +void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit) { int32_t code = 0; SServerObj* srv = taosMemoryCalloc(1, sizeof(SServerObj)); @@ -1382,7 +1516,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == taosValidIpAndPort(srv->ip, srv->port)) { code = TAOS_SYSTEM_ERROR(errno); - tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); + tError("invalid ip/port, %d:%d since %s", srv->ip, srv->port, terrstr()); goto End; } char pipeName[PATH_MAX]; @@ -1414,19 +1548,20 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, for (int i = 0; i < srv->numOfThreads; i++) { SWorkThrd* thrd = (SWorkThrd*)taosMemoryCalloc(1, sizeof(SWorkThrd)); - if (thrd == NULL) { - code = terrno; - goto End; - } - thrd->pTransInst = shandle; + thrd->pInst = pInit; thrd->quit = false; - thrd->pTransInst = shandle; + thrd->pInst = pInit; thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { destroyWorkThrdObj(thrd); code = terrno; goto End; } + thrd->connRefMgt = transOpenRefMgt(50000, transDestroyExHandle); + if (thrd->connRefMgt < 0) { + code = thrd->connRefMgt; + goto End; + } srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { @@ -1460,11 +1595,10 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, code = terrno; goto End; } - srv->pThreadObj[i] = thrd; - thrd->pTransInst = shandle; + thrd->pInst = pInit; thrd->quit = false; - thrd->pTransInst = shandle; + thrd->pInst = pInit; thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { destroyWorkThrdObj(thrd); @@ -1472,6 +1606,12 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } + thrd->connRefMgt = transOpenRefMgt(50000, transDestroyExHandle); + if (thrd->connRefMgt < 0) { + code = thrd->connRefMgt; + goto End; + } + srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { code = terrno; @@ -1501,7 +1641,9 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, thrd->pipe = &(srv->pipe[i][1]); // init read thrd->fd = fds[0]; + srv->pThreadObj[i] = thrd; + thrd->inited = 1; if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) { goto End; } @@ -1514,7 +1656,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, tError("failed to create worker-thread:%d", i); goto End; } - thrd->inited = 1; } #endif @@ -1547,7 +1688,7 @@ End: return NULL; } -void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd) { thrd->quit = true; if (QUEUE_IS_EMPTY(&thrd->conn)) { uv_walk(thrd->loop, uvWalkCb, NULL); @@ -1556,57 +1697,38 @@ void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) { } taosMemoryFree(msg); } -void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { - int32_t code = 0; - SSvrConn* conn = msg->pConn; - if (conn->status == ConnAcquire) { - code = reallocConnRef(conn); - if (code != 0) { - destroyConn(conn, true); - return; - } - if (!transQueuePush(&conn->srvMsgs, msg)) { - return; - } - uvStartSendRespImpl(msg); - return; - } else if (conn->status == ConnRelease || conn->status == ConnNormal) { - tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pTransInst), conn); - } - destroySmsg(msg); -} -void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd) { return; } + +void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd) { // send msg to client - tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pTransInst), msg->pConn); + tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pInst), msg->pConn); uvStartSendResp(msg); } -void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { + +int32_t uvHandleStateReq(SSvrRespMsg* msg) { + int32_t code = 0; SSvrConn* conn = msg->pConn; - tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pTransInst), conn); - if (conn->status == ConnAcquire) { - if (!transQueuePush(&conn->srvMsgs, msg)) { - return; - } - TAOS_UNUSED(transQueuePop(&conn->srvMsgs)); + int64_t qid = msg->msg.info.qId; + tDebug("%s conn %p start to register brokenlink callback, sid:%" PRId64 "", transLabel(conn->pInst), conn, qid); - if (conn->regArg.init) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } - conn->regArg.notifyCount = 0; - conn->regArg.init = 1; - conn->regArg.msg = msg->msg; - tDebug("conn %p register brokenlink callback succ", conn); - - if (conn->broken) { - STrans* pTransInst = conn->pTransInst; - (*pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - taosMemoryFree(msg); + SSvrRegArg arg = {.notifyCount = 0, .init = 1, .msg = msg->msg}; + SSvrRegArg* p = taosHashGet(conn->pQTable, &qid, sizeof(qid)); + if (p != NULL) { + transFreeMsg(p->msg.pCont); } + + code = taosHashPut(conn->pQTable, &qid, sizeof(qid), &arg, sizeof(arg)); + if (code == 0) tDebug("conn %p register brokenlink callback succ", conn); + return code; } -void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleRegister(SSvrRespMsg* msg, SWorkThrd* thrd) { + SSvrConn* conn = msg->pConn; + tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pInst), conn); + int32_t code = uvHandleStateReq(msg); + taosMemoryFree(msg); +} + +void uvHandleUpdate(SSvrRespMsg* msg, SWorkThrd* thrd) { SUpdateIpWhite* req = msg->arg; if (req == NULL) { tDebug("ip-white-list disable on trans"); @@ -1651,6 +1773,7 @@ void destroyWorkThrdObj(SWorkThrd* pThrd) { } transAsyncPoolDestroy(pThrd->asyncPool); uvWhiteListDestroy(pThrd->pWhiteList); + taosCloseRef(pThrd->connRefMgt); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } @@ -1665,12 +1788,12 @@ void destroyWorkThrd(SWorkThrd* pThrd) { } SRV_RELEASE_UV(pThrd->loop); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrRespMsg, destroySmsgWrapper, NULL); } destroyWorkThrdObj(pThrd); } void sendQuitToWorkThrd(SWorkThrd* pThrd) { - SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* msg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (msg == NULL) { tError("failed to send quit msg to work thread since %s", tstrerror(terrno)); return; @@ -1717,17 +1840,19 @@ void transRefSrvHandle(void* handle) { if (handle == NULL) { return; } - int ref = T_REF_INC((SSvrConn*)handle); - tTrace("conn %p ref count:%d", handle, ref); + SSvrConn* pConn = handle; + pConn->ref++; + tTrace("conn %p ref count:%d", pConn, pConn->ref); } void transUnrefSrvHandle(void* handle) { if (handle == NULL) { return; } - int ref = T_REF_DEC((SSvrConn*)handle); - tTrace("conn %p ref count:%d", handle, ref); - if (ref == 0) { + SSvrConn* pConn = handle; + pConn->ref--; + tTrace("conn %p ref count:%d", pConn, pConn->ref); + if (pConn->ref == 0) { destroyConn((SSvrConn*)handle, true); } } @@ -1736,36 +1861,44 @@ int32_t transReleaseSrvHandle(void* handle) { int32_t code = 0; SRpcHandleInfo* info = handle; SExHandle* exh = info->handle; + int64_t qId = info->qId; int64_t refId = info->refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(info->refIdMgt, refId, exh); SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - STransMsg tmsg = {.code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId}; + STransMsg tmsg = {.msgType = TDMT_SCH_TASK_RELEASE, + .code = 0, + .info.handle = exh, + .info.ahandle = NULL, + .info.refId = refId, + .info.qId = qId, + .info.traceId = info->traceId}; - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = terrno; goto _return1; } m->msg = tmsg; - m->type = Release; + m->type = Normal; - tDebug("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle); + tDebug("%s conn %p start to send %s, sid:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), + qId); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(info->refIdMgt, refId); return code; } - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(info->refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send to release handle", exh); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(info->refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send to release handle", exh); @@ -1787,38 +1920,41 @@ int32_t transSendResponse(const STransMsg* msg) { return 0; } int64_t refId = msg->info.refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(msg->info.refIdMgt, refId, exh); STransMsg tmsg = *msg; tmsg.info.refId = refId; + if (tmsg.info.qId == 0) { + tmsg.msgType = msg->info.msgType + 1; + } SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = terrno; goto _return1; } - m->msg = tmsg; + m->type = Normal; STraceId* trace = (STraceId*)&msg->info.traceId; tGDebug("conn %p start to send resp (1/2)", exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send resp", exh); @@ -1830,17 +1966,20 @@ int32_t transRegisterMsg(const STransMsg* msg) { SExHandle* exh = msg->info.handle; int64_t refId = msg->info.refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(msg->info.refIdMgt, refId, exh); STransMsg tmsg = *msg; tmsg.info.noResp = 1; + tmsg.info.qId = msg->info.qId; + tmsg.info.seqNum = msg->info.seqNum; tmsg.info.refId = refId; + tmsg.info.refIdMgt = msg->info.refIdMgt; SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = terrno; goto _return1; @@ -1849,21 +1988,21 @@ int32_t transRegisterMsg(const STransMsg* msg) { m->msg = tmsg; m->type = Register; - STrans* pTransInst = pThrd->pTransInst; - tDebug("%s conn %p start to register brokenlink callback", transLabel(pTransInst), exh->handle); + STrans* pInst = pThrd->pInst; + tDebug("%s conn %p start to register brokenlink callback", transLabel(pInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to register brokenlink", exh); @@ -1872,19 +2011,19 @@ _return2: } int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)thandle); - if (pTransInst == NULL) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)thandle); + if (pInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } int32_t code = 0; tDebug("ip-white-list update on rpc"); - SServerObj* svrObj = pTransInst->tcphandle; + SServerObj* svrObj = pInst->tcphandle; for (int i = 0; i < svrObj->numOfThreads; i++) { SWorkThrd* pThrd = svrObj->pThreadObj[i]; - SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* msg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (msg == NULL) { code = terrno; break; @@ -1908,12 +2047,10 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { break; } } - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)thandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); if (code != 0) { tError("ip-white-list update failed since %s", tstrerror(code)); } return code; } - -int32_t transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; } diff --git a/source/libs/transport/test/cliBench.c b/source/libs/transport/test/cliBench.c index 134c911401..e73c209d55 100644 --- a/source/libs/transport/test/cliBench.c +++ b/source/libs/transport/test/cliBench.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) { rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.connLimitNum = 10; rpcInit.connLimitLock = 1; - rpcInit.batchSize = 16 * 1024; + rpcInit.shareConnLimit = 16 * 1024; rpcInit.supportBatch = 1; rpcDebugFlag = 135; diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 46cca99e5f..2f18c6e697 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -395,10 +395,11 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { SetFilePointer(h, 0, NULL, FILE_END); } if (h == INVALID_HANDLE_VALUE) { - DWORD dwError = GetLastError(); + DWORD dwError = GetLastError(); terrno = TAOS_SYSTEM_WINAPI_ERROR(dwError); // LPVOID lpMsgBuf; - // FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, + // FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, + // 0, // NULL); // printf("CreateFile failed with error %d: %s", dwError, (char *)lpMsgBuf); // LocalFree(lpMsgBuf); @@ -915,7 +916,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { } struct stat fileStat; - int32_t code = fstat(pFile->fd, &fileStat); + int32_t code = fstat(pFile->fd, &fileStat); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; @@ -983,7 +984,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } #ifdef _TD_DARWIN_64 - if(lseek(pFileIn->fd, (int32_t)(*offset), 0) < 0) { + if (lseek(pFileIn->fd, (int32_t)(*offset), 0) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -1015,7 +1016,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } return writeLen; -#else // for linux +#else // for linux int64_t leftbytes = size; int64_t sentbytes; @@ -1126,7 +1127,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { if ((*ppFile)->hFile != NULL) { // FlushFileBuffers((*ppFile)->hFile); if (!CloseHandle((*ppFile)->hFile)) { - terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); code = -1; } (*ppFile)->hFile = NULL; @@ -1469,7 +1470,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { while (!feof(pSrcFile->fp)) { len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp); if (len > 0) { - if(gzwrite(dstFp, data, len) == 0) { + if (gzwrite(dstFp, data, len) == 0) { terrno = TAOS_SYSTEM_ERROR(errno); ret = terrno; goto cmp_end; @@ -1564,4 +1565,4 @@ int taosSetAutoDelFile(char *path) { } return 0; #endif -} +} \ No newline at end of file diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index c084b76485..f4aa966d2b 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -308,6 +308,7 @@ void *taosMemoryCalloc(int64_t num, int64_t size) { uint32_t r = taosRand() % tsRandErrDivisor; if ((r + 1) <= tsRandErrChance) { terrno = TSDB_CODE_OUT_OF_MEMORY; + uError("random memory error: %s, %s", tstrerror(terrno), __func__); return NULL; } } diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index cc3a13a818..538d5bf63e 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -74,7 +74,7 @@ int32_t taosGetAppName(char* name, int32_t* len) { int32_t tsem_wait(tsem_t* sem) { DWORD ret = WaitForSingleObject(*sem, INFINITE); - if(ret == WAIT_OBJECT_0) { + if (ret == WAIT_OBJECT_0) { return 0; } else { return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); @@ -140,7 +140,7 @@ int32_t tsem_wait(tsem_t *psem) { int32_t tsem_timewait(tsem_t *psem, int64_t milis) { if (psem == NULL || *psem == NULL) return -1; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); - if(dispatch_semaphore_wait(*psem, time) == 0) { + if (dispatch_semaphore_wait(*psem, time) == 0) { return 0; } else { return TSDB_CODE_TIMEOUT_ERROR; @@ -218,7 +218,7 @@ int32_t taosGetAppName(char* name, int32_t* len) { } else { ++end; } - + tstrncpy(name, end, TSDB_APP_NAME_LEN); if (len != NULL) { @@ -228,8 +228,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { return 0; } -int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { - if(sem_init(psem, flags, count) == 0) { +int32_t tsem_init(tsem_t* psem, int flags, unsigned int count) { + if (sem_init(psem, flags, count) == 0) { return 0; } else { return terrno = TAOS_SYSTEM_ERROR(errno); @@ -251,9 +251,9 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { ts.tv_nsec %= 1000000000; while ((ret = sem_timedwait(sem, &ts)) == -1) { - if(errno == EINTR) { + if (errno == EINTR) { continue; - } else if(errno == ETIMEDOUT) { + } else if (errno == ETIMEDOUT) { return TSDB_CODE_TIMEOUT_ERROR; } else { terrno = TAOS_SYSTEM_ERROR(errno); @@ -274,27 +274,27 @@ int32_t tsem_wait(tsem_t* sem) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - + return ret; } int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { int ret = taosThreadMutexInit(&sem->mutex, NULL); if (ret != 0) return ret; - + ret = taosThreadCondAttrInit(&sem->attr); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); return ret; } - + ret = taosThreadCondAttrSetclock(&sem->attr, CLOCK_MONOTONIC); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondAttrDestroy(&sem->attr); return ret; } - + ret = taosThreadCondInit(&sem->cond, &sem->attr); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); @@ -303,7 +303,7 @@ int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { } sem->count = value; - + return 0; } @@ -315,7 +315,7 @@ int32_t tsem_post(tsem_t* psem) { } } -int32_t tsem_destroy(tsem_t *sem) { +int32_t tsem_destroy(tsem_t* sem) { if (sem_destroy(sem) == 0) { return 0; } else { @@ -323,7 +323,7 @@ int32_t tsem_destroy(tsem_t *sem) { } } -int tsem2_post(tsem2_t *sem) { +int tsem2_post(tsem2_t* sem) { int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -347,7 +347,7 @@ int tsem2_destroy(tsem2_t* sem) { (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondDestroy(&sem->cond); (void)taosThreadCondAttrDestroy(&sem->attr); - + return 0; } @@ -367,7 +367,7 @@ int32_t tsem2_wait(tsem2_t* sem) { } } sem->count--; - + code = taosThreadMutexUnlock(&sem->mutex); if (code) { return code; @@ -383,7 +383,7 @@ int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { if (code) { return code; } - + if (sem->count <= 0) { struct timespec ts = {0}; if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index d17cc9b239..5f983d5480 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -482,3 +482,18 @@ uint64_t taosNtoh64(uint64_t val) { } #endif } + +int32_t taosSetSockOpt2(int32_t fd) { +#if defined(WINDOWS) || defined(DARWIN) + return 0; +#else + int32_t ret = setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } else { + return 0; + } +#endif + return 0; +} diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 8d74267905..9b85e82184 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -55,10 +55,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TIMEOUT, "Conn read timeout") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED, "some vnode/qnode/mnode(s) out of service") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, "rpc open too many session") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_ERROR, "rpc network error") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_BUSY, "rpc network busy") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_MODULE_QUIT, "http-report already quit") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MODULE_QUIT, "rpc module already quit") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_MODULE_QUIT, "rpc async module already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_BUSY, "rpc network busy") +TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_MODULE_QUIT, "http-report already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MODULE_QUIT, "rpc module already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_MODULE_QUIT, "rpc async module already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NO_STATE, "rpc no state") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_STATE_DROPED, "rpc state already dropped") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") diff --git a/source/util/src/theap.c b/source/util/src/theap.c index e906d1f55b..600bc2b998 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -225,7 +225,8 @@ void destroyPriorityQueue(PriorityQueue* pq) { static size_t pqParent(size_t i) { return (--i) >> 1; /* (i - 1) / 2 */ } static size_t pqLeft(size_t i) { return (i << 1) | 1; /* i * 2 + 1 */ } static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */ } -static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { + +static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { void* tmp = a->data; a->data = b->data; b->data = tmp; diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 9360bd8b0e..f3597b5586 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -19,7 +19,7 @@ #include "tlog.h" #include "tutil.h" -#define TSDB_REF_OBJECTS 50 +#define TSDB_REF_OBJECTS 100 #define TSDB_REF_STATE_EMPTY 0 #define TSDB_REF_STATE_ACTIVE 1 #define TSDB_REF_STATE_DELETED 2 @@ -56,7 +56,7 @@ static void taosLockList(int64_t *lockedBy); static void taosUnlockList(int64_t *lockedBy); static void taosIncRsetCount(SRefSet *pSet); static void taosDecRsetCount(SRefSet *pSet); -static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t* isReleased); +static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased); int32_t taosOpenRef(int32_t max, RefFp fp) { SRefNode **nodeList; @@ -254,7 +254,9 @@ void *taosAcquireRef(int32_t rsetId, int64_t rid) { } int32_t taosReleaseRef(int32_t rsetId, int64_t rid) { return taosDecRefCount(rsetId, rid, 0, NULL); } -int32_t taosReleaseRefEx(int32_t rsetId, int64_t rid, int32_t* isReleased) { return taosDecRefCount(rsetId, rid, 0, isReleased); } +int32_t taosReleaseRefEx(int32_t rsetId, int64_t rid, int32_t *isReleased) { + return taosDecRefCount(rsetId, rid, 0, isReleased); +} // if rid is 0, return the first p in hash list, otherwise, return the next after current rid void *taosIterateRef(int32_t rsetId, int64_t rid) { @@ -387,7 +389,7 @@ int32_t taosListRef() { return num; } -static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t* isReleased) { +static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased) { int32_t hash; SRefSet *pSet; SRefNode *pNode; diff --git a/source/util/test/heapTest.cpp b/source/util/test/heapTest.cpp new file mode 100644 index 0000000000..51eeb26ed3 --- /dev/null +++ b/source/util/test/heapTest.cpp @@ -0,0 +1,55 @@ +#include + +#include "taoserror.h" +#include "theap.h" + +using namespace std; + +typedef struct TNode { + int32_t data; + HeapNode node; +} TNodeMem; + +#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member))) +int32_t heapCompare(const HeapNode* a, const HeapNode* b) { + TNodeMem *ta = container_of(a, TNodeMem, node); + TNodeMem *tb = container_of(b, TNodeMem, node); + if (ta->data > tb->data) { + return 0; + } + return 1; +} + +TEST(TD_UTIL_HEAP_TEST, heapTest) { + Heap* heap = heapCreate(heapCompare); + ASSERT_TRUE(heap != NULL); + ASSERT_EQ(0, heapSize(heap)); + + + int32_t limit = 10; + + TNodeMem **pArr = (TNodeMem **)taosMemoryCalloc(100, sizeof(TNodeMem *)); + for (int i = 0; i < 100; i++) { + TNodeMem *a = (TNodeMem *)taosMemoryCalloc(1, sizeof(TNodeMem)); + a->data = i%limit; + + heapInsert(heap, &a->node); + + pArr[i] = a; + TNodeMem *b = (TNodeMem *)taosMemoryCalloc(1, sizeof(TNodeMem)); + b->data = (limit - i)%limit; + heapInsert(heap, &b->node); + } + for (int i = 98; i < 100; i++) { + TNodeMem *p = pArr[i]; + p->data = -100000; + } + HeapNode *node = heapMin(heap); + while (node != NULL) { + TNodeMem *data = container_of(node, TNodeMem, node); + heapRemove(heap, node); + printf("%d\t", data->data); + node = heapMin(heap); + } + heapDestroy(heap); +} diff --git a/tests/army/query/function/ans/ascii.csv b/tests/army/query/function/ans/ascii.csv index cc1529367b..3f1e6b8c5b 100644 --- a/tests/army/query/function/ans/ascii.csv +++ b/tests/army/query/function/ans/ascii.csv @@ -1,112 +1,302 @@ -104 -104 -104 -104 -229 -105.000000000000000 -103.000000000000000 -104 -104 -104 -104 -104 -105.000000000000000 -2.080000000000000e+02 -110 -228 -117 -112 -110 -110 -112 -110 -112 -228 -110 -228 -117 -112 -110 -110 -228 -117 -112 -110 -12100.000000000000000 -51984.000000000000000 -13689.000000000000000 -12544.000000000000000 -12100.000000000000000 -10.488088481701515 -15.099668870541500 -10.816653826391969 -10.583005244258363 -10.488088481701515 -110 -228 -117 -112 -110 -116 -116 -39 -108 -120 -108 -120 -108 -116 -104 -116 -116 -104 -108 -120 -108 -120 -108 -116 -104 -116 -116 -104 -110 -228 -117 -112 -110 -110 -97 -228 -110 -97 -110 -228 -117 -112 -110 -110 -97 -228 -110 -97 -110 -112 -110 -112 -228 -117 -112 -112 -112 -112 -110 -112 -110 -112 -228 -117 -112 -112 -112 -112 + +taos> select ASCII('hello') + ascii('hello') | +================= + 104 | + +taos> select ASCII('hello world') + ascii('hello world') | +======================= + 104 | + +taos> select ASCII('hello world!') + ascii('hello world!') | +======================== + 104 | + +taos> select ASCII('hello,world.你好,世界。') + ascii('hello,world.你好,世界。') | +========================================== + 104 | + +taos> select ASCII('北京涛思数据科技有限公司') + ascii('北京涛思数据科技有限公司') | +================================================ + 229 | + +taos> select ASCII('hello') + 1 + ascii('hello') + 1 | +============================ + 105.000000000000000 | + +taos> select ASCII('hello') - 1 + ascii('hello') - 1 | +============================ + 103.000000000000000 | + +taos> select ASCII('hello') from ts_4893.meters limit 5 + ascii('hello') | +================= + 104 | + 104 | + 104 | + 104 | + 104 | + +taos> select ASCII('hello') + 1 from ts_4893.meters limit 1 + ascii('hello') + 1 | +============================ + 105.000000000000000 | + +taos> select ASCII('hello') + ASCII('hello') from ts_4893.meters limit 1 + ascii('hello') + ascii('hello') | +================================== + 2.080000000000000e+02 | + +taos> select ASCII(nch1) from ts_4893.meters order by ts limit 5 + ascii(nch1) | +============== + 110 | + 228 | + 117 | + 112 | + 110 | + +taos> select ASCII(var1) from ts_4893.meters order by ts limit 5 + ascii(var1) | +============== + 110 | + 112 | + 110 | + 112 | + 228 | + +taos> select ASCII(concat(nch1,var1)) from ts_4893.meters order by ts limit 5 + ascii(concat(nch1,var1)) | +=========================== + 110 | + 228 | + 117 | + 112 | + 110 | + +taos> select ASCII(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5 + ascii(cast(nch1 as varchar)) | +=============================== + 110 | + 228 | + 117 | + 112 | + 110 | + +taos> select pow(ASCII(nch1), 2) from ts_4893.meters order by ts limit 5 + pow(ascii(nch1), 2) | +============================ + 12100.000000000000000 | + 51984.000000000000000 | + 13689.000000000000000 | + 12544.000000000000000 | + 12100.000000000000000 | + +taos> select sqrt(ASCII(nch1)) from ts_4893.meters order by ts limit 5 + sqrt(ascii(nch1)) | +============================ + 10.488088481701515 | + 15.099668870541500 | + 10.816653826391969 | + 10.583005244258363 | + 10.488088481701515 | + +taos> select cast(ASCII(nch1) as int) from ts_4893.meters order by ts limit 5 + cast(ascii(nch1) as int) | +=========================== + 110 | + 228 | + 117 | + 112 | + 110 | + +taos> select ascii('taos') + ascii('taos') | +================ + 116 | + +taos> select ascii('t') + ascii('t') | +============= + 116 | + +taos> select ascii('\'') + ascii('\'') | +============== + 39 | + +taos> select ascii(name) from ts_4893.d0 order by ts limit 10 + ascii(name) | +============== + 108 | + 120 | + 108 | + 120 | + 108 | + 116 | + 104 | + 116 | + 116 | + 104 | + +taos> select ascii(name) from ts_4893.meters order by ts limit 10 + ascii(name) | +============== + 108 | + 120 | + 108 | + 120 | + 108 | + 116 | + 104 | + 116 | + 116 | + 104 | + +taos> select ascii(nch1) from ts_4893.d0 order by ts limit 10 + ascii(nch1) | +============== + 110 | + 228 | + 117 | + 112 | + 110 | + 110 | + 97 | + 228 | + 110 | + 97 | + +taos> select ascii(nch1) from ts_4893.meters order by ts limit 10 + ascii(nch1) | +============== + 110 | + 228 | + 117 | + 112 | + 110 | + 110 | + 97 | + 228 | + 110 | + 97 | + +taos> select ascii(var1) from ts_4893.d0 order by ts limit 10 + ascii(var1) | +============== + 110 | + 112 | + 110 | + 112 | + 228 | + 117 | + 112 | + 112 | + 112 | + 112 | + +taos> select ascii(var1) from ts_4893.meters order by ts limit 10 + ascii(var1) | +============== + 110 | + 112 | + 110 | + 112 | + 228 | + 117 | + 112 | + 112 | + 112 | + 112 | + +taos> select ascii(null) + ascii(null) | +============== + NULL | + +taos> select ascii('0') + ascii('0') | +============= + 48 | + +taos> select ascii(' ') + ascii(' ') | +============= + 32 | + +taos> select ascii('~') + ascii('~') | +============= + 126 | + +taos> select ascii('中') + ascii('中') | +=============== + 228 | + +taos> select ascii('é') + ascii('é') | +============== + 195 | + +taos> select ascii('!@#') + ascii('!@#') | +=============== + 33 | + +taos> select ascii('Hello') + ascii('Hello') | +================= + 72 | + +taos> select ascii('123abc') + ascii('123abc') | +================== + 49 | + +taos> select ascii(concat('A', 'B')) + ascii(concat('A', 'B')) | +========================== + 65 | + +taos> select ascii(char(65)) + ascii(char(65)) | +================== + 65 | + +taos> select ascii(upper('b')) + ascii(upper('b')) | +==================== + 66 | + +taos> select ascii(trim(' A ')) + ascii(trim(' A ')) | +===================== + 65 | + +taos> select name, ascii(name) from ts_4893.meters limit 1 + name | ascii(name) | +=============================================== + lili | 108 | + +taos> select name, ascii(substring(name, 1, 1)) from ts_4893.meters limit 1 + name | ascii(substring(name, 1, 1)) | +================================================================ + lili | 108 | + +taos> select nch1, ascii(nch1) from ts_4893.meters limit 1 + nch1 | ascii(nch1) | +=============================================== + novel | 110 | + +taos> select var1, ascii(var1) from ts_4893.meters limit 1 + var1 | ascii(var1) | +=============================================== + novel | 110 | + diff --git a/tests/army/query/function/ans/char.csv b/tests/army/query/function/ans/char.csv index 7488ac31b8..6aa17a3726 100644 --- a/tests/army/query/function/ans/char.csv +++ b/tests/army/query/function/ans/char.csv @@ -1,43 +1,129 @@ -M -M -d -M -M -M -M -M -MNOPQ -MNOPQ -MNOPQ -MNOPQ -MNOPQ -MM -MM -MM -MM -MM -MN -MN -MN -MN -MN -1 -M -N -O -P -Q -MMM -NNN -OOO -PPP -QQQ -MMMMM -NNNNN -OOOOO -PPPPP -QQQQQ -M -MM -{ -M{ + +taos> select CHAR(77) + char(77) | +=========== + M | + +taos> select CHAR(77.5) + char(77.5) | +============= + M | + +taos> select CHAR(100) + char(100) | +============ + d | + +taos> select CHAR(77) from ts_4893.meters limit 5 + char(77) | +=========== + M | + M | + M | + M | + M | + +taos> select CHAR(77,78,79,80,81) from ts_4893.meters limit 5 + char(77,78,79,80,81) | +========================= + MNOPQ | + MNOPQ | + MNOPQ | + MNOPQ | + MNOPQ | + +taos> select CHAR(77*256+77) from ts_4893.meters limit 5 + char(77*256+77) | +================== + MM | + MM | + MM | + MM | + MM | + +taos> select concat(CHAR(77),CHAR(78)) from ts_4893.meters limit 5 + concat(char(77),char(78)) | +============================ + MN | + MN | + MN | + MN | + MN | + +taos> select cast(CHAR(49) as int) + cast(char(49) as int) | +======================== + 1 | + +taos> select CHAR(id + 77) from ts_4893.meters order by ts limit 5; + char(id + 77) | +================ + M | + N | + O | + P | + Q | + +taos> select CONCAT(CHAR(id + 77),CHAR(id + 77),CHAR(id + 77)) from ts_4893.meters limit 5 + concat(char(id + 77),char(id + 77),char(id + 77)) | +==================================================== + MMM | + NNN | + OOO | + PPP | + QQQ | + +taos> select CHAR(id+77, id+77, id+77, id+77, id+77) from ts_4893.meters limit 5 + char(id+77, id+77, id+77, id+77, id+77) | +========================================== + MMMMM | + NNNNN | + OOOOO | + PPPPP | + QQQQQ | + +taos> select char(77) + char(77) | +=========== + M | + +taos> select char(77 * 256 + 77) + char(77 * 256 + 77) | +====================== + MM | + +taos> select char('123') + char('123') | +============== + { | + +taos> select char(77, NULL, '123') + char(77, null, '123') | +======================== + M{ | + +taos> select char(null) + char(null) | +============= + | + +taos> select char('ustc') + char('ustc') | +=============== + | + +taos> select char(65.99) + char(65.99) | +============== + A | + +taos> select char(65, 66, 67) + char(65, 66, 67) | +=================== + ABC | + +taos> select char(72, 101, 108, 108, 111) + char(72, 101, 108, 108, 111) | +=============================== + Hello | + diff --git a/tests/army/query/function/ans/char_length.csv b/tests/army/query/function/ans/char_length.csv index 1a4c328fef..a872e8cd88 100644 --- a/tests/army/query/function/ans/char_length.csv +++ b/tests/army/query/function/ans/char_length.csv @@ -1,93 +1,259 @@ -5 -11 -12 -18 -12 -6.000000000000000 -4.000000000000000 -5 -5 -5 -5 -5 -6.000000000000000 -1.000000000000000e+01 -5 -10 -6 -7 -5 -5 -6 -5 -5 -10 -10 -16 -11 -12 -15 -5 -10 -6 -7 -5 -25.000000000000000 -100.000000000000000 -36.000000000000000 -49.000000000000000 -25.000000000000000 -2.236067977499790 -3.162277660168380 -2.449489742783178 -2.645751311064591 -2.236067977499790 -5 -10 -6 -7 -5 -4 -2 -6 -5 -5 -10 -6 -7 -5 -5 -5 -10 -5 -5 -5 -10 -6 -7 -5 -5 -5 -10 -5 -5 -5 -6 -5 -5 -10 -6 -7 -6 -7 -5 -5 -6 -5 -5 -10 -6 -7 -6 -7 -5 + +taos> select CHAR_LENGTH('hello') + char_length('hello') | +======================== + 5 | + +taos> select CHAR_LENGTH('hello world') + char_length('hello world') | +============================= + 11 | + +taos> select CHAR_LENGTH('hello world!') + char_length('hello world!') | +============================== + 12 | + +taos> select CHAR_LENGTH('hello,world.你好,世界。') + char_length('hello,world.你好,世界。') | +================================================ + 18 | + +taos> select CHAR_LENGTH('北京涛思数据科技有限公司') + char_length('北京涛思数据科技有限公司') | +====================================================== + 12 | + +taos> select CHAR_LENGTH('hello') + 1 + char_length('hello') + 1 | +============================ + 6.000000000000000 | + +taos> select CHAR_LENGTH('hello') - 1 + char_length('hello') - 1 | +============================ + 4.000000000000000 | + +taos> select CHAR_LENGTH('hello') from ts_4893.meters limit 5 + char_length('hello') | +======================== + 5 | + 5 | + 5 | + 5 | + 5 | + +taos> select CHAR_LENGTH('hello') + 1 from ts_4893.meters limit 1 + char_length('hello') + 1 | +============================ + 6.000000000000000 | + +taos> select CHAR_LENGTH('hello') + CHAR_LENGTH('hello') from ts_4893.meters limit 1 + char_length('hello') + char_length('hello') | +============================================== + 1.000000000000000e+01 | + +taos> select CHAR_LENGTH(nch1) from ts_4893.meters order by ts limit 5 + char_length(nch1) | +======================== + 5 | + 10 | + 6 | + 7 | + 5 | + +taos> select CHAR_LENGTH(var1) from ts_4893.meters order by ts limit 5 + char_length(var1) | +======================== + 5 | + 6 | + 5 | + 5 | + 10 | + +taos> select CHAR_LENGTH(concat(nch1,var1)) from ts_4893.meters order by ts limit 5 + char_length(concat(nch1,var1)) | +================================= + 10 | + 16 | + 11 | + 12 | + 15 | + +taos> select CHAR_LENGTH(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5 + char_length(cast(nch1 as varchar)) | +===================================== + 5 | + 10 | + 6 | + 7 | + 5 | + +taos> select pow(CHAR_LENGTH(nch1), 2) from ts_4893.meters order by ts limit 5 + pow(char_length(nch1), 2) | +============================ + 25.000000000000000 | + 100.000000000000000 | + 36.000000000000000 | + 49.000000000000000 | + 25.000000000000000 | + +taos> select sqrt(CHAR_LENGTH(nch1)) from ts_4893.meters order by ts limit 5 + sqrt(char_length(nch1)) | +============================ + 2.236067977499790 | + 3.162277660168380 | + 2.449489742783178 | + 2.645751311064591 | + 2.236067977499790 | + +taos> select cast(CHAR_LENGTH(nch1) as int) from ts_4893.meters order by ts limit 5 + cast(char_length(nch1) as int) | +================================= + 5 | + 10 | + 6 | + 7 | + 5 | + +taos> select char_length('taos') + char_length('taos') | +======================== + 4 | + +taos> select char_length('涛思') + char_length('涛思') | +======================== + 2 | + +taos> select char_length('涛思taos') + char_length('涛思taos') | +============================ + 6 | + +taos> select char_length('tao\'s') + char_length('tao\'s') | +======================== + 5 | + +taos> select char_length(nch1) from ts_4893.d0 limit 10 + char_length(nch1) | +======================== + 5 | + 10 | + 6 | + 7 | + 5 | + 5 | + 5 | + 10 | + 5 | + 5 | + +taos> select char_length(nch1) from ts_4893.meters limit 10 + char_length(nch1) | +======================== + 5 | + 10 | + 6 | + 7 | + 5 | + 5 | + 5 | + 10 | + 5 | + 5 | + +taos> select char_length(var1) from ts_4893.d0 limit 10 + char_length(var1) | +======================== + 5 | + 6 | + 5 | + 5 | + 10 | + 6 | + 7 | + 6 | + 7 | + 5 | + +taos> select char_length(var1) from ts_4893.meters limit 10 + char_length(var1) | +======================== + 5 | + 6 | + 5 | + 5 | + 10 | + 6 | + 7 | + 6 | + 7 | + 5 | + +taos> select char_length(null) + char_length(null) | +======================== + NULL | + +taos> select char_length('') + char_length('') | +======================== + 0 | + +taos> select char_length('あいうえお') + char_length('あいうえお') | +================================= + 5 | + +taos> select min(char_length(name)) from ts_4893.meters + min(char_length(name)) | +========================= + 1 | + +taos> select max(char_length(name)) from ts_4893.meters + max(char_length(name)) | +========================= + 4 | + +taos> select trim(name), char_length(trim(name)) from ts_4893.meters limit 1 + trim(name) | char_length(trim(name)) | +=========================================================== + lili | 4 | + +taos> select upper(name), char_length(upper(name)) from ts_4893.meters limit 1 + upper(name) | char_length(upper(name)) | +============================================================ + LILI | 4 | + +taos> select concat(name, ' - ', location), char_length(concat(name, ' - ', location)) from ts_4893.meters limit 1 + concat(name, ' - ', location) | char_length(concat(name, ' - ', location)) | +============================================================================== + lili - beijing | 14 | + +taos> select substring(name, 1, 5), char_length(substring(name, 1, 5)) from ts_4893.meters limit 1 + substring(name, 1, 5) | char_length(substring(name, 1, 5)) | +====================================================================== + lili | 4 | + +taos> select name, char_length(name) from ts_4893.meters limit 1 + name | char_length(name) | +========================================================= + lili | 4 | + +taos> select nch1, char_length(nch1) from ts_4893.meters limit 1 + nch1 | char_length(nch1) | +========================================================= + novel | 5 | + +taos> select groupid, max(char_length(name)) from ts_4893.meters group by groupid order by ts + groupid | max(char_length(name)) | +=================================== + 1 | 4 | + +taos> select location, avg(char_length(name)) from ts_4893.meters group by location order by location + location | avg(char_length(name)) | +================================================= + beijing | 3.244600000000000 | + diff --git a/tests/army/query/function/ans/dayofweek.csv b/tests/army/query/function/ans/dayofweek.csv index 93af60dc7d..ff80e7aa80 100644 --- a/tests/army/query/function/ans/dayofweek.csv +++ b/tests/army/query/function/ans/dayofweek.csv @@ -1,99 +1,262 @@ -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -4 -4 -2 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 + +taos> select DAYOFWEEK('2020-01-01 00:00:00') + dayofweek('2020-01-01 00:00:00') | +=================================== + 4 | + +taos> select DAYOFWEEK('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + dayofweek('2020-01-01 00:00:00') | +=================================== + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select DAYOFWEEK('2021-01-01 00:00:00') + dayofweek('2021-01-01 00:00:00') | +=================================== + 6 | + +taos> select DAYOFWEEK('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + dayofweek('2021-01-01 00:00:00') | +=================================== + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + +taos> select DAYOFWEEK('1998-01-01 00:00:00') + dayofweek('1998-01-01 00:00:00') | +=================================== + 5 | + +taos> select DAYOFWEEK('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + dayofweek('1998-01-01 00:00:00') | +=================================== + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + +taos> select DAYOFWEEK('1998-12-31 00:00:00') + dayofweek('1998-12-31 00:00:00') | +=================================== + 5 | + +taos> select DAYOFWEEK('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 + dayofweek('1998-12-31 00:00:00') | +=================================== + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + +taos> select DAYOFWEEK('2000-01-06 00:00:00') + dayofweek('2000-01-06 00:00:00') | +=================================== + 5 | + +taos> select DAYOFWEEK('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 + dayofweek('2000-01-06 00:00:00') | +=================================== + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + 5 | + +taos> select DAYOFWEEK(1725095657) + dayofweek(1725095657) | +======================== + 4 | + +taos> select DAYOFWEEK(1725095657) from ts_4893.meters order by ts limit 10 + dayofweek(1725095657) | +======================== + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select DAYOFWEEK(ts) from ts_4893.meters order by ts limit 10 + dayofweek(ts) | +======================== + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + +taos> select dayofweek(null) + dayofweek(null) | +======================== + NULL | + +taos> select dayofweek('1721020591') + dayofweek('1721020591') | +========================== + NULL | + +taos> select dayofweek('1721020666229') + dayofweek('1721020666229') | +============================= + NULL | + +taos> select dayofweek('abc') + dayofweek('abc') | +======================== + NULL | + +taos> select dayofweek('01/01/2020') + dayofweek('01/01/2020') | +========================== + NULL | + +taos> select dayofweek('20200101') + dayofweek('20200101') | +======================== + NULL | + +taos> select dayofweek('20/01/01') + dayofweek('20/01/01') | +======================== + NULL | + +taos> select dayofweek('11/01/31') + dayofweek('11/01/31') | +======================== + NULL | + +taos> select dayofweek('01-JAN-20') + dayofweek('01-JAN-20') | +========================= + NULL | + +taos> select dayofweek('2020-01-01') + dayofweek('2020-01-01') | +========================== + 4 | + +taos> select dayofweek(1721020666) + dayofweek(1721020666) | +======================== + 4 | + +taos> select dayofweek(1721020666229) + dayofweek(1721020666229) | +=========================== + 2 | + +taos> select dayofweek(ts) from ts_4893.d0 order by ts limit 10 + dayofweek(ts) | +======================== + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + +taos> select dayofweek(ts) from ts_4893.meters order by ts limit 10 + dayofweek(ts) | +======================== + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + 6 | + +taos> select dayofweek('2024-02-29') + dayofweek('2024-02-29') | +========================== + 5 | + +taos> select dayofweek('2024-01-01') + dayofweek('2024-01-01') | +========================== + 2 | + +taos> select dayofweek('2024-12-31') + dayofweek('2024-12-31') | +========================== + 3 | + +taos> select dayofweek('9999-12-31') + dayofweek('9999-12-31') | +========================== + 6 | + +taos> select dayofweek(ts) from ts_4893.meters limit 1 + dayofweek(ts) | +======================== + 6 | + +taos> select dayofweek(name) from ts_4893.meters limit 1 + dayofweek(name) | +======================== + NULL | + +taos> select dayofweek(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 + dayofweek(timediff(ts, '2024-10-10 09:36:50.172')) | +===================================================== + 6 | + +taos> select id, dayofweek(ts) from ts_4893.meters where id = 1 limit 1 + id | dayofweek(ts) | +====================================== + 1 | 6 | + +taos> select groupid, sum(dayofweek(ts)) from ts_4893.meters group by groupid order by groupid + groupid | sum(dayofweek(ts)) | +================================== + 1 | 400012 | + diff --git a/tests/army/query/function/ans/degrees.csv b/tests/army/query/function/ans/degrees.csv index 4da868ff42..9c68c92a9c 100644 --- a/tests/army/query/function/ans/degrees.csv +++ b/tests/army/query/function/ans/degrees.csv @@ -1,66 +1,270 @@ -0.000000000000000 -57.295779513082323 -85.943669269623484 -5729.577951308232514 --57.295779513082323 --85.943669269623484 --5729.577951308232514 -58.295779513082323 -56.295779513082323 -57.295779513082323 -57.295779513082323 -57.295779513082323 -57.295779513082323 -57.295779513082323 -57.295779513082323 -57.295779513082323 -58.295779513082323 -56.295779513082323 -114.591559026164646 -28.647889756541161 -171.887338539246969 -57.295779513082323 -6565.612700023488287 -2.000000000000000 -57.295779513082323 -58.295779513082323 -59.295779513082323 -60.295779513082323 -61.295779513082323 -0.000000000000000 -58.295779513082323 -116.591559026164646 -174.887338539246969 -233.183118052329291 -572.957795130823229 -180.000000000000000 -572.957795130823229 -328280.635001174407080 -23.936536824085962 -572 -0.000000000000000 -57.295779513082323 -81.028468454139556 -99.239201175922574 -114.591559026164646 -180 -610.200029957721426 -491.254034090376820 -561.212164701962479 -643.603479905018958 -613.408634263739941 -487.472513516777667 -549.810284033650078 -628.076328902558998 -643.202411196955836 -592.266466706882511 -610.200029957721426 -491.254034090376820 -561.212164701962479 -643.603479905018958 -613.408634263739941 -487.472513516777667 -549.810284033650078 -628.076328902558998 -643.202411196955836 -592.266466706882511 + +taos> select DEGREES(0) + degrees(0) | +============================ + 0.000000000000000 | + +taos> select DEGREES(1) + degrees(1) | +============================ + 57.295779513082323 | + +taos> select DEGREES(1.5) + degrees(1.5) | +============================ + 85.943669269623484 | + +taos> select DEGREES(100) + degrees(100) | +============================ + 5729.577951308232514 | + +taos> select DEGREES(-1) + degrees(-1) | +============================ + -57.295779513082323 | + +taos> select DEGREES(-1.5) + degrees(-1.5) | +============================ + -85.943669269623484 | + +taos> select DEGREES(-100) + degrees(-100) | +============================ + -5729.577951308232514 | + +taos> select DEGREES(1) + 1 + degrees(1) + 1 | +============================ + 58.295779513082323 | + +taos> select DEGREES(1) - 1 + degrees(1) - 1 | +============================ + 56.295779513082323 | + +taos> select DEGREES(1) * 1 + degrees(1) * 1 | +============================ + 57.295779513082323 | + +taos> select DEGREES(1) / 1 + degrees(1) / 1 | +============================ + 57.295779513082323 | + +taos> select DEGREES(1) from ts_4893.meters limit 5 + degrees(1) | +============================ + 57.295779513082323 | + 57.295779513082323 | + 57.295779513082323 | + 57.295779513082323 | + 57.295779513082323 | + +taos> select DEGREES(1) + 1 from ts_4893.meters limit 1 + degrees(1) + 1 | +============================ + 58.295779513082323 | + +taos> select DEGREES(1) - 1 from ts_4893.meters limit 1 + degrees(1) - 1 | +============================ + 56.295779513082323 | + +taos> select DEGREES(1) * 2 from ts_4893.meters limit 1 + degrees(1) * 2 | +============================ + 114.591559026164646 | + +taos> select DEGREES(1) / 2 from ts_4893.meters limit 1 + degrees(1) / 2 | +============================ + 28.647889756541161 | + +taos> select DEGREES(2) + DEGREES(1) from ts_4893.meters limit 1 + degrees(2) + degrees(1) | +============================ + 171.887338539246969 | + +taos> select DEGREES(2) - DEGREES(1) from ts_4893.meters limit 1 + degrees(2) - degrees(1) | +============================ + 57.295779513082323 | + +taos> select DEGREES(2) * DEGREES(1) from ts_4893.meters limit 1 + degrees(2) * degrees(1) | +============================ + 6565.612700023488287 | + +taos> select DEGREES(2) / DEGREES(1) from ts_4893.meters limit 1 + degrees(2) / degrees(1) | +============================ + 2.000000000000000 | + +taos> select DEGREES(1) + id from ts_4893.meters order by ts limit 5 + degrees(1) + id | +============================ + 57.295779513082323 | + 58.295779513082323 | + 59.295779513082323 | + 60.295779513082323 | + 61.295779513082323 | + +taos> select DEGREES(id) + id from ts_4893.meters order by ts limit 5 + degrees(id) + id | +============================ + 0.000000000000000 | + 58.295779513082323 | + 116.591559026164646 | + 174.887338539246969 | + 233.183118052329291 | + +taos> select DEGREES(abs(10)) + degrees(abs(10)) | +============================ + 572.957795130823229 | + +taos> select DEGREES(PI()) + degrees(pi()) | +============================ + 180.000000000000000 | + +taos> select abs(DEGREES(10)) + abs(degrees(10)) | +============================ + 572.957795130823229 | + +taos> select pow(DEGREES(10), 2) + pow(degrees(10), 2) | +============================ + 328280.635001174407080 | + +taos> select sqrt(DEGREES(10)) + sqrt(degrees(10)) | +============================ + 23.936536824085962 | + +taos> select cast(DEGREES(10) as int) + cast(degrees(10) as int) | +=========================== + 572 | + +taos> select DEGREES(sqrt(id)) from ts_4893.meters order by ts limit 5 + degrees(sqrt(id)) | +============================ + 0.000000000000000 | + 57.295779513082323 | + 81.028468454139556 | + 99.239201175922574 | + 114.591559026164646 | + +taos> select degrees(pi()) + degrees(pi()) | +============================ + 180.000000000000000 | + +taos> select degrees(current) from ts_4893.d0 order by ts limit 10 + degrees(current) | +============================ + 610.200029957721426 | + 491.254034090376820 | + 561.212164701962479 | + 643.603479905018958 | + 613.408634263739941 | + 487.472513516777667 | + 549.810284033650078 | + 628.076328902558998 | + 643.202411196955836 | + 592.266466706882511 | + +taos> select degrees(current) from ts_4893.meters order by ts limit 10 + degrees(current) | +============================ + 610.200029957721426 | + 491.254034090376820 | + 561.212164701962479 | + 643.603479905018958 | + 613.408634263739941 | + 487.472513516777667 | + 549.810284033650078 | + 628.076328902558998 | + 643.202411196955836 | + 592.266466706882511 | + +taos> select degrees(null) + degrees(null) | +============================ + NULL | + +taos> select degrees(-5) + degrees(-5) | +============================ + -286.478897565411614 | + +taos> select degrees(3.14) + degrees(3.14) | +============================ + 179.908747671078515 | + +taos> select degrees(2*pi()) + degrees(2*pi()) | +============================ + 360.000000000000000 | + +taos> select degrees(pi()/2) + degrees(pi()/2) | +============================ + 90.000000000000000 | + +taos> select degrees(-pi()/2) + degrees(-pi()/2) | +============================ + -90.000000000000000 | + +taos> select degrees(1000000) + degrees(1000000) | +============================ + 57295779.513082325458527 | + +taos> select degrees(sin(1)) + degrees(sin(1)) | +============================ + 48.212736012209490 | + +taos> select degrees(cos(1)) + degrees(cos(1)) | +============================ + 30.957041787430903 | + +taos> select degrees(tan(1)) + degrees(tan(1)) | +============================ + 89.232889603798512 | + +taos> select degrees(radians(90)) + degrees(radians(90)) | +============================ + 90.000000000000000 | + +taos> select degrees(atan(1)) + degrees(atan(1)) | +============================ + 45.000000000000000 | + +taos> select degrees(phase) from ts_4893.meters limit 1 + degrees(phase) | +============================ + 29.157708736569255 | + +taos> select degrees(current) from ts_4893.meters limit 1 + degrees(current) | +============================ + 610.200029957721426 | + +taos> select degrees(voltage) from ts_4893.meters limit 1 + degrees(voltage) | +============================ + 12662.367272391193183 | + diff --git a/tests/army/query/function/ans/exp.csv b/tests/army/query/function/ans/exp.csv old mode 100755 new mode 100644 index 37a6204848..c30efe4f55 --- a/tests/army/query/function/ans/exp.csv +++ b/tests/army/query/function/ans/exp.csv @@ -1,66 +1,260 @@ -1.000000000000000 -2.718281828459045 -4.481689070338065 -2.688117141816136e+43 -0.367879441171442 -0.223130160148430 -0.000000000000000 -3.718281828459045 -1.718281828459045 -2.718281828459045 -2.718281828459045 -2.718281828459045 -2.718281828459045 -2.718281828459045 -2.718281828459045 -2.718281828459045 -3.718281828459045 -1.718281828459045 -5.436563656918090 -1.359140914229523 -10.107337927389695 -4.670774270471606 -20.085536923187668 -2.718281828459046 -2.718281828459045 -3.718281828459045 -4.718281828459045 -5.718281828459045 -6.718281828459045 -1.000000000000000 -3.718281828459045 -9.389056098930650 -23.085536923187668 -58.598150033144236 -22026.465794806717895 -485165195.409790337085724 -148.413159102576600 -22026 -1.000000000000000 -2.718281828459045 -4.113250378782928 -5.652233674034091 -7.389056098930650 -3814279.104760214220732 -7.38905609893065 -1.6487212707001282 -42192.578453635847836 -5292.258432380726845 -17943.802618770550907 -75583.992598717435612 -44622.804904812772293 -4954.246535954979663 -14705.836248958077704 -57641.604897186582093 -75056.754435561466380 -30853.327779395312973 -42192.578453635847836 -5292.258432380726845 -17943.802618770550907 -75583.992598717435612 -44622.804904812772293 -4954.246535954979663 -14705.836248958077704 -57641.604897186582093 -75056.754435561466380 -30853.327779395312973 + +taos> select EXP(0) + exp(0) | +============================ + 1.000000000000000 | + +taos> select EXP(1) + exp(1) | +============================ + 2.718281828459045 | + +taos> select EXP(1.5) + exp(1.5) | +============================ + 4.481689070338065 | + +taos> select EXP(100) + exp(100) | +============================ + 2.688117141816136e+43 | + +taos> select EXP(-1) + exp(-1) | +============================ + 0.367879441171442 | + +taos> select EXP(-1.5) + exp(-1.5) | +============================ + 0.223130160148430 | + +taos> select EXP(-100) + exp(-100) | +============================ + 0.000000000000000 | + +taos> select EXP(1) + 1 + exp(1) + 1 | +============================ + 3.718281828459045 | + +taos> select EXP(1) - 1 + exp(1) - 1 | +============================ + 1.718281828459045 | + +taos> select EXP(1) * 1 + exp(1) * 1 | +============================ + 2.718281828459045 | + +taos> select EXP(1) / 1 + exp(1) / 1 | +============================ + 2.718281828459045 | + +taos> select exp(1) from ts_4893.meters limit 5 + exp(1) | +============================ + 2.718281828459045 | + 2.718281828459045 | + 2.718281828459045 | + 2.718281828459045 | + 2.718281828459045 | + +taos> select exp(1) + 1 from ts_4893.meters limit 1 + exp(1) + 1 | +============================ + 3.718281828459045 | + +taos> select exp(1) - 1 from ts_4893.meters limit 1 + exp(1) - 1 | +============================ + 1.718281828459045 | + +taos> select exp(1) * 2 from ts_4893.meters limit 1 + exp(1) * 2 | +============================ + 5.436563656918090 | + +taos> select exp(1) / 2 from ts_4893.meters limit 1 + exp(1) / 2 | +============================ + 1.359140914229523 | + +taos> select exp(2) + exp(1) from ts_4893.meters limit 1 + exp(2) + exp(1) | +============================ + 10.107337927389695 | + +taos> select exp(2) - exp(1) from ts_4893.meters limit 1 + exp(2) - exp(1) | +============================ + 4.670774270471606 | + +taos> select exp(2) * exp(1) from ts_4893.meters limit 1 + exp(2) * exp(1) | +============================ + 20.085536923187668 | + +taos> select exp(2) / exp(1) from ts_4893.meters limit 1 + exp(2) / exp(1) | +============================ + 2.718281828459046 | + +taos> select exp(1) + id from ts_4893.meters order by ts limit 5 + exp(1) + id | +============================ + 2.718281828459045 | + 3.718281828459045 | + 4.718281828459045 | + 5.718281828459045 | + 6.718281828459045 | + +taos> select exp(id) + id from ts_4893.meters order by ts limit 5 + exp(id) + id | +============================ + 1.000000000000000 | + 3.718281828459045 | + 9.389056098930650 | + 23.085536923187668 | + 58.598150033144236 | + +taos> select abs(EXP(10)) + abs(exp(10)) | +============================ + 22026.465794806717895 | + +taos> select pow(EXP(10), 2) + pow(exp(10), 2) | +============================ + 485165195.409790337085724 | + +taos> select sqrt(EXP(10)) + sqrt(exp(10)) | +============================ + 148.413159102576600 | + +taos> select cast(EXP(10) as int) + cast(exp(10) as int) | +======================= + 22026 | + +taos> select EXP(sqrt(id)) from ts_4893.meters order by ts limit 5 + exp(sqrt(id)) | +============================ + 1.000000000000000 | + 2.718281828459045 | + 4.113250378782928 | + 5.652233674034091 | + 7.389056098930650 | + +taos> select EXP(EXP(EXP(EXP(0)))) + exp(exp(exp(exp(0)))) | +============================ + 3814279.104760214220732 | + +taos> select exp(2) + exp(2) | +============================ + 7.389056098930650 | + +taos> select exp(0.5) + exp(0.5) | +============================ + 1.648721270700128 | + +taos> select exp(current) from ts_4893.d0 order by ts limit 10 + exp(current) | +============================ + 42192.578453635847836 | + 5292.258432380726845 | + 17943.802618770550907 | + 75583.992598717435612 | + 44622.804904812772293 | + 4954.246535954979663 | + 14705.836248958077704 | + 57641.604897186582093 | + 75056.754435561466380 | + 30853.327779395312973 | + +taos> select exp(current) from ts_4893.meters order by ts limit 10 + exp(current) | +============================ + 42192.578453635847836 | + 5292.258432380726845 | + 17943.802618770550907 | + 75583.992598717435612 | + 44622.804904812772293 | + 4954.246535954979663 | + 14705.836248958077704 | + 57641.604897186582093 | + 75056.754435561466380 | + 30853.327779395312973 | + +taos> select exp(null) + exp(null) | +============================ + NULL | + +taos> select exp(100000) + exp(100000) | +============================ + NULL | + +taos> select exp(-1000) + exp(-1000) | +============================ + 0.000000000000000 | + +taos> select exp(-9999999999) + exp(-9999999999) | +============================ + 0.000000000000000 | + +taos> select exp(0.0001) + exp(0.0001) | +============================ + 1.000100005000167 | + +taos> select exp(pi()) + exp(pi()) | +============================ + 23.140692632779267 | + +taos> select exp(voltage) from ts_4893.meters limit 1 + exp(voltage) | +============================ + 9.529727902367202e+95 | + +taos> select exp(current) from ts_4893.meters limit 1 + exp(current) | +============================ + 42192.578453635847836 | + +taos> select exp(phase) from ts_4893.meters limit 1 + exp(phase) | +============================ + 1.663457087766762 | + +taos> select exp(voltage + current) from ts_4893.meters limit 1 + exp(voltage + current) | +============================ + 4.020837921624308e+100 | + +taos> select exp(abs(current)) from ts_4893.meters limit 1 + exp(abs(current)) | +============================ + 42192.578453635847836 | + +taos> select exp(log(voltage)) from ts_4893.meters limit 1 + exp(log(voltage)) | +============================ + 220.999999999999915 | + +taos> select round(exp(voltage), 2) from ts_4893.meters limit 1 + round(exp(voltage), 2) | +============================ + 9.529727902367202e+95 | + diff --git a/tests/army/query/function/ans/ln.csv b/tests/army/query/function/ans/ln.csv old mode 100755 new mode 100644 index ef8db86bbf..5d6443ab79 --- a/tests/army/query/function/ans/ln.csv +++ b/tests/army/query/function/ans/ln.csv @@ -1,63 +1,265 @@ -4.605170185988092 -0.405465108108164 -4.605170185988092 -5.605170185988092 -3.605170185988092 -4.605170185988092 -4.605170185988092 -4.605170185988092 -4.605170185988092 -4.605170185988092 -4.605170185988092 -4.605170185988092 -5.605170185988092 -3.605170185988092 -9.210340371976184 -2.302585092994046 -5.298317366548037 --3.912023005428146 -3.192060730416365 -0.150514997831991 -4.605170185988092 -5.605170185988092 -6.605170185988092 -7.605170185988092 -8.605170185988092 -0.000000000000000 -1.693147180559945 -3.098612288668110 -4.386294361119891 -5.609437912434101 -2.302585092994046 -5.301898110478399 -1.517427129385146 -2 -0.000000000000000 -0.693147180559945 -0.881373587019543 -1.005052538742381 -1.098612288668110 --0.226079864157595 -2.000000000000000 -2.302585092994046 -1.144729885849400 -2.365559856336680 -2.148734409997751 -2.281872059185575 -2.418855857000369 -2.370804362614190 -2.141006941277850 -2.261346315560232 -2.394434736880126 -2.418232501568406 -2.335729681253415 -2.365559856336680 -2.148734409997751 -2.281872059185575 -2.418855857000369 -2.370804362614190 -2.141006941277850 -2.261346315560232 -2.394434736880126 -2.418232501568406 -2.335729681253415 + +taos> select LN(100) + ln(100) | +============================ + 4.605170185988092 | + +taos> select LN(1.5) + ln(1.5) | +============================ + 0.405465108108164 | + +taos> select LN(100) + ln(100) | +============================ + 4.605170185988092 | + +taos> select LN(100) + 1 + ln(100) + 1 | +============================ + 5.605170185988092 | + +taos> select LN(100) - 1 + ln(100) - 1 | +============================ + 3.605170185988092 | + +taos> select LN(100) * 1 + ln(100) * 1 | +============================ + 4.605170185988092 | + +taos> select LN(100) / 1 + ln(100) / 1 | +============================ + 4.605170185988092 | + +taos> select LN(100) from ts_4893.meters limit 5 + ln(100) | +============================ + 4.605170185988092 | + 4.605170185988092 | + 4.605170185988092 | + 4.605170185988092 | + 4.605170185988092 | + +taos> select LN(100) + 1 from ts_4893.meters limit 1 + ln(100) + 1 | +============================ + 5.605170185988092 | + +taos> select LN(100) - 1 from ts_4893.meters limit 1 + ln(100) - 1 | +============================ + 3.605170185988092 | + +taos> select LN(100) * 2 from ts_4893.meters limit 1 + ln(100) * 2 | +============================ + 9.210340371976184 | + +taos> select LN(100) / 2 from ts_4893.meters limit 1 + ln(100) / 2 | +============================ + 2.302585092994046 | + +taos> select LN(2) + LN(100) from ts_4893.meters limit 1 + ln(2) + ln(100) | +============================ + 5.298317366548037 | + +taos> select LN(2) - LN(100) from ts_4893.meters limit 1 + ln(2) - ln(100) | +============================ + -3.912023005428146 | + +taos> select LN(2) * LN(100) from ts_4893.meters limit 1 + ln(2) * ln(100) | +============================ + 3.192060730416365 | + +taos> select LN(2) / LN(100) from ts_4893.meters limit 1 + ln(2) / ln(100) | +============================ + 0.150514997831991 | + +taos> select LN(100) + id from ts_4893.meters order by ts limit 5 + ln(100) + id | +============================ + 4.605170185988092 | + 5.605170185988092 | + 6.605170185988092 | + 7.605170185988092 | + 8.605170185988092 | + +taos> select LN(id + 1) + id from ts_4893.meters order by ts limit 5 + ln(id + 1) + id | +============================ + 0.000000000000000 | + 1.693147180559945 | + 3.098612288668110 | + 4.386294361119891 | + 5.609437912434101 | + +taos> select ln(null) + ln(null) | +============================ + NULL | + +taos> select ln(0) + ln(0) | +============================ + NULL | + +taos> select ln(-5) + ln(-5) | +============================ + NULL | + +taos> select abs(LN(10)) + abs(ln(10)) | +============================ + 2.302585092994046 | + +taos> select pow(LN(10), 2) + pow(ln(10), 2) | +============================ + 5.301898110478399 | + +taos> select sqrt(LN(10)) + sqrt(ln(10)) | +============================ + 1.517427129385146 | + +taos> select cast(LN(10) as int) + cast(ln(10) as int) | +====================== + 2 | + +taos> select LN(sqrt(id) + 1) from ts_4893.meters order by ts limit 5 + ln(sqrt(id) + 1) | +============================ + 0.000000000000000 | + 0.693147180559945 | + 0.881373587019543 | + 1.005052538742381 | + 1.098612288668110 | + +taos> select LN(LN(LN(LN(10000)))) + ln(ln(ln(ln(10000)))) | +============================ + -0.226079864157595 | + +taos> select LN(EXP(2)) + ln(exp(2)) | +============================ + 2.000000000000000 | + +taos> select ln(10) + ln(10) | +============================ + 2.302585092994046 | + +taos> select ln(pi()) + ln(pi()) | +============================ + 1.144729885849400 | + +taos> select ln(current) from ts_4893.d0 order by ts limit 10 + ln(current) | +============================ + 2.365559856336680 | + 2.148734409997751 | + 2.281872059185575 | + 2.418855857000369 | + 2.370804362614190 | + 2.141006941277850 | + 2.261346315560232 | + 2.394434736880126 | + 2.418232501568406 | + 2.335729681253415 | + +taos> select ln(current) from ts_4893.meters order by ts limit 10 + ln(current) | +============================ + 2.365559856336680 | + 2.148734409997751 | + 2.281872059185575 | + 2.418855857000369 | + 2.370804362614190 | + 2.141006941277850 | + 2.261346315560232 | + 2.394434736880126 | + 2.418232501568406 | + 2.335729681253415 | + +taos> select ln(1) + ln(1) | +============================ + 0.000000000000000 | + +taos> select ln(20) + ln(20) | +============================ + 2.995732273553991 | + +taos> select ln(100) + ln(100) | +============================ + 4.605170185988092 | + +taos> select ln(99999999999999) + ln(99999999999999) | +============================ + 32.236191301916627 | + +taos> select ln(0.1) + ln(0.1) | +============================ + -2.302585092994045 | + +taos> select ln(2.718) + ln(2.718) | +============================ + 0.999896315728952 | + +taos> select ln(exp(1)) + ln(exp(1)) | +============================ + 1.000000000000000 | + +taos> select ln(voltage) from ts_4893.meters where voltage > 0 limit 1 + ln(voltage) | +============================ + 5.398162701517752 | + +taos> select ln(current) from ts_4893.meters where current > 0 limit 1 + ln(current) | +============================ + 2.365559856336680 | + +taos> select ln(phase) from ts_4893.meters where phase > 0 limit 1 + ln(phase) | +============================ + -0.675507636551043 | + +taos> select ln(exp(voltage)) from ts_4893.meters where voltage > 0 limit 1 + ln(exp(voltage)) | +============================ + 221.000000000000000 | + +taos> select ln(abs(current)) from ts_4893.meters where current != 0 limit 1 + ln(abs(current)) | +============================ + 2.365559856336680 | + +taos> select ln(sqrt(phase)) from ts_4893.meters where phase >= 0 limit 1 + ln(sqrt(phase)) | +============================ + -0.337753818275521 | + +taos> select ln(log(current)) from ts_4893.meters where current > 1 limit 1 + ln(log(current)) | +============================ + 0.861014719652538 | + diff --git a/tests/army/query/function/ans/max.csv b/tests/army/query/function/ans/max.csv index 62df7c5d53..f150ad1208 100644 --- a/tests/army/query/function/ans/max.csv +++ b/tests/army/query/function/ans/max.csv @@ -1,480 +1,605 @@ -9999 -11.9989996 -224 -x -一二三四五六七八九十 -四 -一二三四五六七八九十 -四 -1110 -2838 -4566 -6294 -8022 -9750 -9999 -3206 -4934 -6662 -8390 -9999 -1846 -3574 -5302 -7030 -8758 -9999 -2214 -3942 -5670 -7398 -9126 -9999 -2582 -4310 -6038 -7766 -9494 -9999 -2950 -4678 -6406 -8134 -9862 -9999 -3318 -5046 -6774 -8502 -9999 -1958 -3686 -5414 -7142 -8870 -9999 -2326 -4054 -5782 -7510 -9238 -9999 -2694 -4422 -6150 -7878 -9606 -9999 -11.9989996 -11.9969997 -11.9969997 -11.9989996 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9980001 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9989996 -11.9989996 -11.9989996 -11.9989996 -11.9969997 -11.9989996 -11.9989996 -11.9989996 -11.9860001 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -224 -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -一二三四五六七八九十 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 -四 + +taos> select MAX(current) from ts_4893.meters + max(current) | +======================= + 11.9989996 | + +taos> select MAX(voltage) from ts_4893.meters + max(voltage) | +=============== + 224 | + +taos> select MAX(name) from ts_4893.meters + max(name) | +================================= + x | + +taos> select MAX(nch1) from ts_4893.meters + max(nch1) | +================================= + 一二三四五六七八九十 | + +taos> select MAX(nch2) from ts_4893.meters + max(nch2) | +================================= + 四 | + +taos> select MAX(var1) from ts_4893.meters + max(var1) | +================================= + 一二三四五六七八九十 | + +taos> select MAX(var2) from ts_4893.meters + max(var2) | +================================= + 四 | + +taos> select MAX(id) from ts_4893.meters interval(60d) + max(id) | +============== + 1110 | + 2838 | + 4566 | + 6294 | + 8022 | + 9750 | + 9999 | + 3206 | + 4934 | + 6662 | + 8390 | + 9999 | + 1846 | + 3574 | + 5302 | + 7030 | + 8758 | + 9999 | + 2214 | + 3942 | + 5670 | + 7398 | + 9126 | + 9999 | + 2582 | + 4310 | + 6038 | + 7766 | + 9494 | + 9999 | + 2950 | + 4678 | + 6406 | + 8134 | + 9862 | + 9999 | + 3318 | + 5046 | + 6774 | + 8502 | + 9999 | + 1958 | + 3686 | + 5414 | + 7142 | + 8870 | + 9999 | + 2326 | + 4054 | + 5782 | + 7510 | + 9238 | + 9999 | + 2694 | + 4422 | + 6150 | + 7878 | + 9606 | + 9999 | + +taos> select MAX(current) from ts_4893.meters interval(60d) + max(current) | +======================= + 11.9989996 | + 11.9969997 | + 11.9969997 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9980001 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9969997 | + 11.9989996 | + 11.9989996 | + 11.9989996 | + 11.9860001 | + +taos> select MAX(voltage) from ts_4893.meters interval(60d) + max(voltage) | +=============== + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + 224 | + +taos> select MAX(name) from ts_4893.meters interval(60d) + max(name) | +================================= + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + x | + +taos> select MAX(nch1) from ts_4893.meters interval(60d) + max(nch1) | +================================= + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + +taos> select MAX(nch2) from ts_4893.meters interval(60d) + max(nch2) | +================================= + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + +taos> select MAX(var1) from ts_4893.meters interval(60d) + max(var1) | +================================= + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + 一二三四五六七八九十 | + +taos> select MAX(var2) from ts_4893.meters interval(60d) + max(var2) | +================================= + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + 四 | + +taos> select max(null) from ts_4893.meters + max(null) | +======================== + NULL | + +taos> select max(id) from ts_4893.meters + max(id) | +============== + 9999 | + +taos> select max(id) from ts_4893.meters where id > 0 + max(id) | +============== + 9999 | + +taos> select max(id) from ts_4893.meters where id <= 0 + max(id) | +============== + 0 | + +taos> select max(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' + max(phase) | +======================= + 0.9999660 | + +taos> select max(voltage) from ts_4893.meters where voltage is not null + max(voltage) | +=============== + 224 | + +taos> select max(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) + max(total_voltage) | +======================== + 21948660 | + +taos> select round(max(current), 2) from ts_4893.meters + round(max(current), 2) | +========================= + 1.2000000e+01 | + +taos> select pow(max(current), 2) from ts_4893.meters + pow(max(current), 2) | +============================ + 143.975991296219036 | + +taos> select log(max(voltage) + 1) from ts_4893.meters + log(max(voltage) + 1) | +============================ + 5.416100402204420 | + +taos> select groupid, max(voltage) from ts_4893.meters group by groupid order by groupid + groupid | max(voltage) | +========================= + 1 | 224 | + +taos> select location, max(id) from ts_4893.meters group by location order by location + location | max(id) | +=================================== + beijing | 9999 | + +taos> select location, max(current) from ts_4893.meters group by location order by location + location | max(current) | +============================================ + beijing | 11.9989996 | + diff --git a/tests/army/query/function/ans/min.csv b/tests/army/query/function/ans/min.csv index d87f2264d7..9a8ba15287 100644 --- a/tests/army/query/function/ans/min.csv +++ b/tests/army/query/function/ans/min.csv @@ -1,480 +1,605 @@ -0 -8.0000000 -215 -haha -abc一二三abc一二三abc -a -abc一二三abc一二三abc -a -0 -1111 -2839 -4567 -6295 -8023 -0 -1479 -3207 -4935 -6663 -0 -119 -1847 -3575 -5303 -7031 -0 -487 -2215 -3943 -5671 -7399 -0 -855 -2583 -4311 -6039 -7767 -0 -1223 -2951 -4679 -6407 -8135 -0 -1591 -3319 -5047 -6775 -0 -231 -1959 -3687 -5415 -7143 -0 -599 -2327 -4055 -5783 -7511 -0 -967 -2695 -4423 -6151 -7879 -9607 -8.0000000 -8.0000000 -8.0000000 -8.0010004 -8.0010004 -8.0000000 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0030003 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0030003 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0000000 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0000000 -8.0000000 -8.0000000 -8.0010004 -8.0089998 -8.0000000 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0030003 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0019999 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0000000 -8.0000000 -8.0000000 -8.0019999 -8.0010004 -8.0000000 -8.0050001 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -215 -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -haha -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a + +taos> select MIN(id) from ts_4893.meters + min(id) | +============== + 0 | + +taos> select MIN(current) from ts_4893.meters + min(current) | +======================= + 8.0000000 | + +taos> select MIN(voltage) from ts_4893.meters + min(voltage) | +=============== + 215 | + +taos> select MIN(name) from ts_4893.meters + min(name) | +================================= + haha | + +taos> select MIN(nch1) from ts_4893.meters + min(nch1) | +================================= + abc一二三abc一二三abc | + +taos> select MIN(nch2) from ts_4893.meters + min(nch2) | +================================= + a | + +taos> select MIN(var1) from ts_4893.meters + min(var1) | +================================= + abc一二三abc一二三abc | + +taos> select MIN(var2) from ts_4893.meters + min(var2) | +================================= + a | + +taos> select MIN(id) from ts_4893.meters interval(60d) + min(id) | +============== + 0 | + 1111 | + 2839 | + 4567 | + 6295 | + 8023 | + 0 | + 1479 | + 3207 | + 4935 | + 6663 | + 0 | + 119 | + 1847 | + 3575 | + 5303 | + 7031 | + 0 | + 487 | + 2215 | + 3943 | + 5671 | + 7399 | + 0 | + 855 | + 2583 | + 4311 | + 6039 | + 7767 | + 0 | + 1223 | + 2951 | + 4679 | + 6407 | + 8135 | + 0 | + 1591 | + 3319 | + 5047 | + 6775 | + 0 | + 231 | + 1959 | + 3687 | + 5415 | + 7143 | + 0 | + 599 | + 2327 | + 4055 | + 5783 | + 7511 | + 0 | + 967 | + 2695 | + 4423 | + 6151 | + 7879 | + 9607 | + +taos> select MIN(current) from ts_4893.meters interval(60d) + min(current) | +======================= + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0010004 | + 8.0010004 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0030003 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0030003 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0010004 | + 8.0089998 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0030003 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0019999 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0000000 | + 8.0019999 | + 8.0010004 | + 8.0000000 | + 8.0050001 | + +taos> select MIN(voltage) from ts_4893.meters interval(60d) + min(voltage) | +=============== + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + 215 | + +taos> select MIN(name) from ts_4893.meters interval(60d) + min(name) | +================================= + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + haha | + +taos> select MIN(nch1) from ts_4893.meters interval(60d) + min(nch1) | +================================= + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + +taos> select MIN(nch2) from ts_4893.meters interval(60d) + min(nch2) | +================================= + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + +taos> select MIN(var1) from ts_4893.meters interval(60d) + min(var1) | +================================= + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + +taos> select MIN(var2) from ts_4893.meters interval(60d) + min(var2) | +================================= + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + a | + +taos> select min(null) from ts_4893.meters + min(null) | +======================== + NULL | + +taos> select min(id) from ts_4893.meters where id > 0 + min(id) | +============== + 1 | + +taos> select min(id) from ts_4893.meters where id <= 0 + min(id) | +============== + 0 | + +taos> select min(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' + min(phase) | +======================= + 0.0001700 | + +taos> select min(voltage) from ts_4893.meters where voltage is not null + min(voltage) | +=============== + 215 | + +taos> select min(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) + min(total_voltage) | +======================== + 21948660 | + +taos> select round(min(current), 2) from ts_4893.meters + round(min(current), 2) | +========================= + 8.0000000e+00 | + +taos> select pow(min(current), 2) from ts_4893.meters + pow(min(current), 2) | +============================ + 64.000000000000000 | + +taos> select log(min(voltage) + 1) from ts_4893.meters + log(min(voltage) + 1) | +============================ + 5.375278407684165 | + +taos> select groupid, min(voltage) from ts_4893.meters group by groupid order by groupid + groupid | min(voltage) | +========================= + 1 | 215 | + +taos> select location, min(current) from ts_4893.meters group by location order by location + location | min(current) | +============================================ + beijing | 8.0000000 | + +taos> select location, min(id) from ts_4893.meters group by location order by location + location | min(id) | +=================================== + beijing | 0 | + diff --git a/tests/army/query/function/ans/mod.csv b/tests/army/query/function/ans/mod.csv index 87f776a3a9..fb0a09c14c 100644 --- a/tests/army/query/function/ans/mod.csv +++ b/tests/army/query/function/ans/mod.csv @@ -1,72 +1,235 @@ -1.550000000000001 -0.550000000000001 -0.550000000000001 -0.550000000000001 -0.550000000000001 --0.550000000000001 -0.000000000000000 -1.550000000000001 -1.234567890000022e-01 -1.234567910432816e-01 -1.234567910432816e-01 -1.123456791043282e+00 -1.234567910432816e-01 -1.123456791043282e+00 -1.123456791043282e+00 -3.123456791043282e+00 -6.123456791043282e+00 -1.123456791043282e+00 -1.234567910432816e-01 -1.123456791043282e+00 -0.649999618530273 -0.574000358581543 -0.795000076293945 -3.232999801635742 -0.706000328063965 -2.508000373840332 -2.595999717712402 -2.961999893188477 -2.225999832153320 -0.336999893188477 -0.649999618530273 -0.574000358581543 -0.795000076293945 -0.232999801635742 -0.706000328063965 -0.508000373840332 -0.595999717712402 -0.961999893188477 -0.225999832153320 -0.336999893188477 -2.634337159700784e-01 -9.281394021770111e-01 -1.296964830944782e-01 -3.351566768190027e+00 -3.272002495118848e+00 -2.916847677517688e+00 -3.097741066924800e+00 -3.310891102586806e+00 -3.350522322288470e+00 -3.215120509901375e+00 -1 -1 -0 -1 -2 -0 -1 -2 -0 -1 -2 -0 -0 -1 -2 -0 -1 -2 -0 -1 -2 -0 + +taos> select MOD(10.55, 3) + mod(10.55, 3) | +============================ + 1.550000000000001 | + +taos> select MOD(10.55, 2) + mod(10.55, 2) | +============================ + 0.550000000000001 | + +taos> select MOD(10.55, 1) + mod(10.55, 1) | +============================ + 0.550000000000001 | + +taos> select MOD(10.55, -1) + mod(10.55, -1) | +============================ + 0.550000000000001 | + +taos> select MOD(10.55, -10) + mod(10.55, -10) | +============================ + 0.550000000000001 | + +taos> select MOD(-10.55, 1) + mod(-10.55, 1) | +============================ + -0.550000000000001 | + +taos> select MOD(99, 1) + mod(99, 1) | +============================ + 0.000000000000000 | + +taos> select MOD(10.55, 1) + 1 + mod(10.55, 1) + 1 | +============================ + 1.550000000000001 | + +taos> select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123.123456789, 9), 8), 7), 6), 5), 4), 3) + mod(mod(mod(mod(mod(mod(mod(123.123456789, 9), 8), 7), 6), 5), 4 | +=================================================================== + 1.234567890000022e-01 | + +taos> select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) + mod(mod(mod(mod(mod(mod(mod(123456789.123456789, -1), -2), -3), | +=================================================================== + 1.234567910432816e-01 | + +taos> select MOD(87654321.123456789, id + 1) from ts_4893.meters order by ts limit 10 + mod(87654321.123456789, id + 1) | +================================== + 1.234567910432816e-01 | + 1.123456791043282e+00 | + 1.234567910432816e-01 | + 1.123456791043282e+00 | + 1.123456791043282e+00 | + 3.123456791043282e+00 | + 6.123456791043282e+00 | + 1.123456791043282e+00 | + 1.234567910432816e-01 | + 1.123456791043282e+00 | + +taos> select MOD(current, id + 1) from ts_4893.meters order by ts limit 10 + mod(current, id + 1) | +============================ + 0.649999618530273 | + 0.574000358581543 | + 0.795000076293945 | + 3.232999801635742 | + 0.706000328063965 | + 2.508000373840332 | + 2.595999717712402 | + 2.961999893188477 | + 2.225999832153320 | + 0.336999893188477 | + +taos> select MOD(current, 1) from ts_4893.meters order by ts limit 10 + mod(current, 1) | +============================ + 0.649999618530273 | + 0.574000358581543 | + 0.795000076293945 | + 0.232999801635742 | + 0.706000328063965 | + 0.508000373840332 | + 0.595999717712402 | + 0.961999893188477 | + 0.225999832153320 | + 0.336999893188477 | + +taos> select MOD(sqrt(current), abs(id + 1)) from ts_4893.meters order by ts limit 10 + mod(sqrt(current), abs(id + 1)) | +================================== + 2.634337159700784e-01 | + 9.281394021770111e-01 | + 1.296964830944782e-01 | + 3.351566768190027e+00 | + 3.272002495118848e+00 | + 2.916847677517688e+00 | + 3.097741066924800e+00 | + 3.310891102586806e+00 | + 3.350522322288470e+00 | + 3.215120509901375e+00 | + +taos> select mod(10, -3) + mod(10, -3) | +============================ + 1.000000000000000 | + +taos> select mod(10, 3) + mod(10, 3) | +============================ + 1.000000000000000 | + +taos> select mod(id, 3) from ts_4893.d0 order by ts limit 10 + mod(id, 3) | +============================ + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + +taos> select mod(id, 3) from ts_4893.meters order by ts limit 10 + mod(id, 3) | +============================ + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + 1.000000000000000 | + 2.000000000000000 | + 0.000000000000000 | + +taos> select mod(null, 2) + mod(null, 2) | +============================ + NULL | + +taos> select mod(10, null) + mod(10, null) | +============================ + NULL | + +taos> select mod(10, 0) + mod(10, 0) | +============================ + NULL | + +taos> select mod(-10, 0) + mod(-10, 0) | +============================ + NULL | + +taos> select mod(5, 0) + mod(5, 0) | +============================ + NULL | + +taos> select mod(0, 1) + mod(0, 1) | +============================ + 0.000000000000000 | + +taos> select mod(1, 1) + mod(1, 1) | +============================ + 0.000000000000000 | + +taos> select mod(5, 2) + mod(5, 2) | +============================ + 1.000000000000000 | + +taos> select mod(5, -3) + mod(5, -3) | +============================ + 2.000000000000000 | + +taos> select mod(15, 4) + mod(15, 4) | +============================ + 3.000000000000000 | + +taos> select mod(-5, 3) + mod(-5, 3) | +============================ + -2.000000000000000 | + +taos> select mod(voltage, 2) from ts_4893.meters limit 1 + mod(voltage, 2) | +============================ + 1.000000000000000 | + +taos> select mod(current, 10) from ts_4893.meters limit 1 + mod(current, 10) | +============================ + 0.649999618530273 | + +taos> select mod(current, log(100)) from ts_4893.meters limit 1 + mod(current, log(100)) | +============================ + 1.439659246554090 | + +taos> select mod(phase, 4) from ts_4893.meters limit 1 + mod(phase, 4) | +============================ + 0.508898019790649 | + +taos> select mod(abs(voltage), 3) from ts_4893.meters limit 1 + mod(abs(voltage), 3) | +============================ + 2.000000000000000 | + +taos> select mod(phase, sqrt(16)) from ts_4893.meters limit 1 + mod(phase, sqrt(16)) | +============================ + 0.508898019790649 | + +taos> select mod(round(voltage), 5) from ts_4893.meters limit 1 + mod(round(voltage), 5) | +============================ + 1.000000000000000 | + diff --git a/tests/army/query/function/ans/pi.csv b/tests/army/query/function/ans/pi.csv index 68dd383cb3..1afc45f953 100644 --- a/tests/army/query/function/ans/pi.csv +++ b/tests/army/query/function/ans/pi.csv @@ -1,28 +1,194 @@ -3.141592653589793 -4.141592653589793 -2.141592653589793 -6.283185307179586 -1.570796326794897 -3.141592653589793 -3.141592653589793 -3.141592653589793 -3.141592653589793 -3.141592653589793 -4.141592653589793 -2.141592653589793 -6.283185307179586 -1.570796326794897 -6.283185307179586 -0.000000000000000 -9.869604401089358 -1.000000000000000 -3.141592653589793 -4.141592653589793 -5.141592653589793 -6.141592653589793 -7.141592653589793 -3.141592653589793 -9.869604401089358 -1.772453850905516 -3 -3.141592653589793 + +taos> select pi() + pi() | +============================ + 3.141592653589793 | + +taos> select pi() + 1 + pi() + 1 | +============================ + 4.141592653589793 | + +taos> select pi() - 1 + pi() - 1 | +============================ + 2.141592653589793 | + +taos> select pi() * 2 + pi() * 2 | +============================ + 6.283185307179586 | + +taos> select pi() / 2 + pi() / 2 | +============================ + 1.570796326794897 | + +taos> select pi() from ts_4893.meters limit 5 + pi() | +============================ + 3.141592653589793 | + 3.141592653589793 | + 3.141592653589793 | + 3.141592653589793 | + 3.141592653589793 | + +taos> select pi() + 1 from ts_4893.meters limit 1 + pi() + 1 | +============================ + 4.141592653589793 | + +taos> select pi() - 1 from ts_4893.meters limit 1 + pi() - 1 | +============================ + 2.141592653589793 | + +taos> select pi() * 2 from ts_4893.meters limit 1 + pi() * 2 | +============================ + 6.283185307179586 | + +taos> select pi() / 2 from ts_4893.meters limit 1 + pi() / 2 | +============================ + 1.570796326794897 | + +taos> select pi() + pi() from ts_4893.meters limit 1 + pi() + pi() | +============================ + 6.283185307179586 | + +taos> select pi() - pi() from ts_4893.meters limit 1 + pi() - pi() | +============================ + 0.000000000000000 | + +taos> select pi() * pi() from ts_4893.meters limit 1 + pi() * pi() | +============================ + 9.869604401089358 | + +taos> select pi() / pi() from ts_4893.meters limit 1 + pi() / pi() | +============================ + 1.000000000000000 | + +taos> select pi() + id from ts_4893.meters order by ts limit 5 + pi() + id | +============================ + 3.141592653589793 | + 4.141592653589793 | + 5.141592653589793 | + 6.141592653589793 | + 7.141592653589793 | + +taos> select abs(pi()) + abs(pi()) | +============================ + 3.141592653589793 | + +taos> select pow(pi(), 2) + pow(pi(), 2) | +============================ + 9.869604401089358 | + +taos> select sqrt(pi()) + sqrt(pi()) | +============================ + 1.772453850905516 | + +taos> select cast(pi() as int) + cast(pi() as int) | +==================== + 3 | + +taos> select pi() + pi() | +============================ + 3.141592653589793 | + +taos> select substring_index(null, '.', 2) + substring_index(null, '.', 2) | +================================ + NULL | + +taos> select pi() + null + pi() + null | +============================ + NULL | + +taos> select pi() * 0 + pi() * 0 | +============================ + 0.000000000000000 | + +taos> select pi() / 0 + pi() / 0 | +============================ + NULL | + +taos> select pi() * 0.5 + pi() * 0.5 | +============================ + 1.570796326794897 | + +taos> select pi() * -1 + pi() * -1 | +============================ + -3.141592653589793 | + +taos> select pi() * name from ts_4893.meters limit 1 + pi() * name | +============================ + 0.000000000000000 | + +taos> select pi() * voltage from ts_4893.meters limit 1 + pi() * voltage | +============================ + 694.291976443344311 | + +taos> select pi() * phase * 2 from ts_4893.meters limit 1 + pi() * phase * 2 | +============================ + 3.197500560801395 | + +taos> select round(pi(), 6) + round(pi(), 6) | +============================ + 3.141593000000000 | + +taos> select round(pi() * phase, 2) from ts_4893.meters limit 1 + round(pi() * phase, 2) | +============================ + 1.600000000000000 | + +taos> select sqrt(pi() * voltage) from ts_4893.meters limit 1 + sqrt(pi() * voltage) | +============================ + 26.349420799010826 | + +taos> select sqrt(current / pi()) from ts_4893.meters limit 1 + sqrt(current / pi()) | +============================ + 1.841195309148865 | + +taos> select abs(pi() * phase) from ts_4893.meters limit 1 + abs(pi() * phase) | +============================ + 1.598750280400697 | + +taos> select log(pi() * voltage) from ts_4893.meters limit 1 + log(pi() * voltage) | +============================ + 6.542892587367153 | + +taos> select voltage / pi() from ts_4893.meters limit 1 + voltage / pi() | +============================ + 70.346484846617741 | + +taos> select id, case when voltage > 100 then pi() else pi() / 2 end from ts_4893.meters limit 1 + id | case when voltage > 100 then pi() else pi() / 2 end | +==================================================================== + 0 | 3.141592653589793e+00 | + diff --git a/tests/army/query/function/ans/pi_1.csv b/tests/army/query/function/ans/pi_1.csv deleted file mode 100644 index 6f9baf1a71..0000000000 --- a/tests/army/query/function/ans/pi_1.csv +++ /dev/null @@ -1,114 +0,0 @@ - -taos> select pi() - pi() | -============================ - 3.141592653589793 | - -taos> select pi() + 1 - pi() + 1 | -============================ - 4.141592653589793 | - -taos> select pi() - 1 - pi() - 1 | -============================ - 2.141592653589793 | - -taos> select pi() * 2 - pi() * 2 | -============================ - 6.283185307179586 | - -taos> select pi() / 2 - pi() / 2 | -============================ - 1.570796326794897 | - -taos> select pi() from ts_4893.meters limit 5 - pi() | -============================ - 3.141592653589793 | - 3.141592653589793 | - 3.141592653589793 | - 3.141592653589793 | - 3.141592653589793 | - -taos> select pi() + 1 from ts_4893.meters limit 1 - pi() + 1 | -============================ - 4.141592653589793 | - -taos> select pi() - 1 from ts_4893.meters limit 1 - pi() - 1 | -============================ - 2.141592653589793 | - -taos> select pi() * 2 from ts_4893.meters limit 1 - pi() * 2 | -============================ - 6.283185307179586 | - -taos> select pi() / 2 from ts_4893.meters limit 1 - pi() / 2 | -============================ - 1.570796326794897 | - -taos> select pi() + pi() from ts_4893.meters limit 1 - pi() + pi() | -============================ - 6.283185307179586 | - -taos> select pi() - pi() from ts_4893.meters limit 1 - pi() - pi() | -============================ - 0.000000000000000 | - -taos> select pi() * pi() from ts_4893.meters limit 1 - pi() * pi() | -============================ - 9.869604401089358 | - -taos> select pi() / pi() from ts_4893.meters limit 1 - pi() / pi() | -============================ - 1.000000000000000 | - -taos> select pi() + id from ts_4893.meters order by ts limit 5 - pi() + id | -============================ - 3.141592653589793 | - 4.141592653589793 | - 5.141592653589793 | - 6.141592653589793 | - 7.141592653589793 | - -taos> select abs(pi()) - abs(pi()) | -============================ - 3.141592653589793 | - -taos> select pow(pi(), 2) - pow(pi(), 2) | -============================ - 9.869604401089358 | - -taos> select sqrt(pi()) - sqrt(pi()) | -============================ - 1.772453850905516 | - -taos> select cast(pi() as int) - cast(pi() as int) | -==================== - 3 | - -taos> select pi() - pi() | -============================ - 3.141592653589793 | - -taos> select substring_index(null, '.', 2) - substring_index(null, '.', 2) | -================================ - NULL | - diff --git a/tests/army/query/function/ans/position.csv b/tests/army/query/function/ans/position.csv index 1f3534572e..1547564322 100644 --- a/tests/army/query/function/ans/position.csv +++ b/tests/army/query/function/ans/position.csv @@ -1,176 +1,447 @@ -1 -3 -1 -0 -14 -0 -7 -1 -1 -0 -4 -2 -5 -4 -2 -0 -0 -0 -0 -4 -4 -5 -4 -1 -3 -4 -0 -0 -5 -0 -4 -4 -1 -1 -3 -4 -0 -0 -0 -0 -3 -2 -1 -4 -3 -0 -0 -0 -0 -0 -4 -1 -1 -3 -1 -3 -4 -3 -4 -4 -1 -1 -4 -1 -1 -1 -1 -4 -1 -1 -6 -3 -5 -5 -4 -5 -5 -2 -7 -2 -4 -1 -1 -4 -1 -4 -1 -4 -4 -1 -1 -1.000000000000000e+00 -1 -0 -1 -1 -0 -0 -0 -0 -4 -0 -0 -0 -0 -0 -0 -0 -0 -0 -4 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -4 -0 -0 -0 -0 -0 -0 -0 -4 -0 -4 -0 -0 -0 -0 -0 -0 -0 -4 -0 -4 -0 -0 -5 -0 -0 -0 -0 -0 -0 -4 -0 -0 -5 -0 -0 -0 -0 -0 -0 + +taos> select POSITION('北' IN '北京涛思') + position('北' in '北京涛思') | +==================================== + 1 | + +taos> select POSITION('涛思' IN '北京涛思') + position('涛思' in '北京涛思') | +======================================= + 3 | + +taos> select POSITION('a' IN 'abcd') + position('a' in 'abcd') | +========================== + 1 | + +taos> select POSITION('e' IN 'abcd') + position('e' in 'abcd') | +========================== + 0 | + +taos> select POSITION('好,' IN 'hello,world.你好,世界。') + position('好,' in 'hello,world.你好,世界。') | +========================================================= + 14 | + +taos> select POSITION(',你' IN 'hello,world.你好,世界。') + position(',你' in 'hello,world.你好,世界。') | +========================================================= + 0 | + +taos> select POSITION('world' IN 'hello,world.你好,世界。') + position('world' in 'hello,world.你好,世界。') | +======================================================== + 7 | + +taos> select POSITION('aaa' IN 'aaaaaaaaa') + position('aaa' in 'aaaaaaaaa') | +================================= + 1 | + +taos> select POSITION(CONCAT('a','b','c') IN CONCAT('abc','def','ghi')) + position(concat('a','b','c') in concat('abc','def','ghi')) | +============================================================= + 1 | + +taos> select POSITION(CONCAT('a','b','d') IN CONCAT('abc','def','ghi')) + position(concat('a','b','d') in concat('abc','def','ghi')) | +============================================================= + 0 | + +taos> select POSITION(nch2 IN nch1) from ts_4893.meters where POSITION(nch2 IN nch1) != 0 order by ts limit 5 + position(nch2 in nch1) | +========================= + 4 | + 2 | + 5 | + 4 | + 2 | + +taos> select POSITION(nch2 IN nch1) from ts_4893.meters order by ts limit 5 + position(nch2 in nch1) | +========================= + 0 | + 0 | + 0 | + 0 | + 4 | + +taos> select POSITION(var2 IN var1) from ts_4893.meters where POSITION(var2 IN var1) != 0 order by ts limit 5 + position(var2 in var1) | +========================= + 4 | + 5 | + 4 | + 1 | + 3 | + +taos> select POSITION(var2 IN var1) from ts_4893.meters order by ts limit 5 + position(var2 in var1) | +========================= + 4 | + 0 | + 0 | + 5 | + 0 | + +taos> select POSITION(var2 IN nch1) from ts_4893.meters where POSITION(var2 IN nch1) != 0 order by ts limit 5 + position(var2 in nch1) | +========================= + 4 | + 4 | + 1 | + 1 | + 3 | + +taos> select POSITION(var2 IN nch1) from ts_4893.meters order by ts limit 5 + position(var2 in nch1) | +========================= + 4 | + 0 | + 0 | + 0 | + 0 | + +taos> select POSITION(nch2 IN var1) from ts_4893.meters where POSITION(nch2 IN var1) != 0 order by ts limit 5 + position(nch2 in var1) | +========================= + 3 | + 2 | + 1 | + 4 | + 3 | + +taos> select POSITION(nch2 IN var1) from ts_4893.meters order by ts limit 5 + position(nch2 in var1) | +========================= + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select POSITION('a' IN nch1) from ts_4893.meters where POSITION('a' IN nch1) != 0 order by ts limit 5 + position('a' in nch1) | +======================== + 4 | + 1 | + 1 | + 3 | + 1 | + +taos> select POSITION('a' IN var1) from ts_4893.meters where POSITION('a' IN var1) != 0 order by ts limit 5 + position('a' in var1) | +======================== + 3 | + 4 | + 3 | + 4 | + 4 | + +taos> select POSITION('一' IN nch1) from ts_4893.meters where POSITION('一' IN nch1) != 0 order by ts limit 5 + position('一' in nch1) | +========================== + 1 | + 1 | + 4 | + 1 | + 1 | + +taos> select POSITION('一' IN var1) from ts_4893.meters where POSITION('一' IN var1) != 0 order by ts limit 5 + position('一' in var1) | +========================== + 1 | + 1 | + 4 | + 1 | + 1 | + +taos> select POSITION(nch2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(nch2 IN 'abcdefghijklmn') != 0 order by ts limit 5 + position(nch2 in 'abcdefghijklmn') | +===================================== + 6 | + 3 | + 5 | + 5 | + 4 | + +taos> select POSITION(var2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(var2 IN 'abcdefghijklmn') != 0 order by ts limit 5 + position(var2 in 'abcdefghijklmn') | +===================================== + 5 | + 5 | + 2 | + 7 | + 2 | + +taos> select POSITION(nch2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(nch2 IN '一二三四五六七八九十') != 0 order by ts limit 5 + position(nch2 in '一二三四五六七八九十') | +===================================================== + 4 | + 1 | + 1 | + 4 | + 1 | + +taos> select POSITION(var2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(var2 IN '一二三四五六七八九十') != 0 order by ts limit 5 + position(var2 in '一二三四五六七八九十') | +===================================================== + 4 | + 1 | + 4 | + 4 | + 1 | + +taos> select ABS(POSITION('aaa' IN 'aaaaaaaaa')) + abs(position('aaa' in 'aaaaaaaaa')) | +====================================== + 1 | + +taos> select POW(POSITION('aaa' IN 'aaaaaaaaa'), 2) + pow(position('aaa' in 'aaaaaaaaa'), 2) | +========================================= + 1.000000000000000e+00 | + +taos> select position('t' in 'taos') + position('t' in 'taos') | +========================== + 1 | + +taos> select position('ustc' in 'taos') + position('ustc' in 'taos') | +============================= + 0 | + +taos> select position('' in '') + position('' in '') | +======================== + 1 | + +taos> select position('' in 'taos') + position('' in 'taos') | +========================= + 1 | + +taos> select position(nch2 in nch1) from ts_4893.d0 order by ts limit 10 + position(nch2 in nch1) | +========================= + 0 | + 0 | + 0 | + 0 | + 4 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position(nch2 in nch1) from ts_4893.meters order by ts limit 10 + position(nch2 in nch1) | +========================= + 0 | + 0 | + 0 | + 0 | + 4 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position(nch2 in var1) from ts_4893.d0 order by ts limit 10 + position(nch2 in var1) | +========================= + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position(nch2 in var1) from ts_4893.meters order by ts limit 10 + position(nch2 in var1) | +========================= + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position(var2 in nch1) from ts_4893.d0 order by ts limit 10 + position(var2 in nch1) | +========================= + 4 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 4 | + 0 | + +taos> select position(var2 in nch1) from ts_4893.meters order by ts limit 10 + position(var2 in nch1) | +========================= + 4 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 4 | + 0 | + +taos> select position(var2 in var1) from ts_4893.d0 order by ts limit 10 + position(var2 in var1) | +========================= + 4 | + 0 | + 0 | + 5 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position(var2 in var1) from ts_4893.meters order by ts limit 10 + position(var2 in var1) | +========================= + 4 | + 0 | + 0 | + 5 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select position('t' in null) + position('t' in null) | +======================== + NULL | + +taos> select position(null in 'taos') + position(null in 'taos') | +=========================== + NULL | + +taos> select position('' in 'A') + position('' in 'A') | +======================== + 1 | + +taos> select position('A' in 'A') + position('A' in 'A') | +======================== + 1 | + +taos> select position('A' in '') + position('A' in '') | +======================== + 0 | + +taos> select position('A' in null) + position('A' in null) | +======================== + NULL | + +taos> select position('Z' in 'ABC') + position('Z' in 'ABC') | +========================= + 0 | + +taos> select position('l' in 'Hello') + position('l' in 'Hello') | +=========================== + 3 | + +taos> select position('s' in 'meters') + position('s' in 'meters') | +============================ + 6 | + +taos> select position('中' in '中国') + position('中' in '中国') | +============================== + 1 | + +taos> select position('e' in 'é') + position('e' in 'é') | +======================== + 0 | + +taos> select position('W' in 'Hello World') + position('W' in 'Hello World') | +================================= + 7 | + +taos> select position('@' in '!@#') + position('@' in '!@#') | +========================= + 2 | + +taos> select position('6' in '12345') + position('6' in '12345') | +=========================== + 0 | + +taos> select position('A' in trim(' A ')) + position('A' in trim(' A ')) | +=============================== + 1 | + +taos> select position('A' in upper('abc')) + position('A' in upper('abc')) | +================================ + 1 | + +taos> select position('B' in concat('A', 'B')) + position('B' in concat('A', 'B')) | +==================================== + 2 | + +taos> select position('x' in replace('Hello', 'l', 'x')) + position('x' in replace('Hello', 'l', 'x')) | +============================================== + 3 | + +taos> select name, position('e' in name) from ts_4893.meters limit 1 + name | position('e' in name) | +========================================================= + lili | 0 | + +taos> select name, position('a' in substring(name, 2, 5)) from ts_4893.meters limit 1 + name | position('a' in substring(name, 2, 5)) | +========================================================================== + lili | 0 | + +taos> select nch1, position('n' in nch1) from ts_4893.meters limit 1 + nch1 | position('n' in nch1) | +========================================================= + novel | 1 | + +taos> select var1, position('1' in var1) from ts_4893.meters limit 1 + var1 | position('1' in var1) | +========================================================= + novel | 0 | + diff --git a/tests/army/query/function/ans/radians.csv b/tests/army/query/function/ans/radians.csv index 0f6e56c565..83814344bc 100644 --- a/tests/army/query/function/ans/radians.csv +++ b/tests/army/query/function/ans/radians.csv @@ -1,66 +1,275 @@ -0.000000000000000 -0.017453292519943 -0.026179938779915 -1.745329251994330 --0.017453292519943 --0.026179938779915 --1.745329251994330 -1.017453292519943 --0.982546707480057 -0.017453292519943 -0.017453292519943 -0.017453292519943 -0.017453292519943 -0.017453292519943 -0.017453292519943 -0.017453292519943 -1.017453292519943 --0.982546707480057 -0.034906585039887 -0.008726646259972 -0.052359877559830 -0.017453292519943 -0.000609234839573 -2.000000000000000 -0.017453292519943 -1.017453292519943 -2.017453292519943 -3.017453292519943 -4.017453292519943 -0.000000000000000 -1.017453292519943 -2.034906585039887 -3.052359877559830 -4.069813170079773 -0.174532925199433 -3.141592653589793 -0.174532925199433 -0.030461741978671 -0.417771379105167 -0 -0.000000000000000 -0.017453292519943 -0.024682682989769 -0.030229989403904 -0.034906585039887 -3.141592653589793 -0.185877558679493 -0.149644536324422 -0.170955001564425 -0.196052831414414 -0.186854955444309 -0.148492619284422 -0.167481790094528 -0.191322990739406 -0.195930658899406 -0.180414682914441 -0.185877558679493 -0.149644536324422 -0.170955001564425 -0.196052831414414 -0.186854955444309 -0.148492619284422 -0.167481790094528 -0.191322990739406 -0.195930658899406 -0.180414682914441 + +taos> select RADIANS(0) + radians(0) | +============================ + 0.000000000000000 | + +taos> select RADIANS(1) + radians(1) | +============================ + 0.017453292519943 | + +taos> select RADIANS(1.5) + radians(1.5) | +============================ + 0.026179938779915 | + +taos> select RADIANS(100) + radians(100) | +============================ + 1.745329251994330 | + +taos> select RADIANS(-1) + radians(-1) | +============================ + -0.017453292519943 | + +taos> select RADIANS(-1.5) + radians(-1.5) | +============================ + -0.026179938779915 | + +taos> select RADIANS(-100) + radians(-100) | +============================ + -1.745329251994330 | + +taos> select RADIANS(1) + 1 + radians(1) + 1 | +============================ + 1.017453292519943 | + +taos> select RADIANS(1) - 1 + radians(1) - 1 | +============================ + -0.982546707480057 | + +taos> select RADIANS(1) * 1 + radians(1) * 1 | +============================ + 0.017453292519943 | + +taos> select RADIANS(1) / 1 + radians(1) / 1 | +============================ + 0.017453292519943 | + +taos> select RADIANS(1) from ts_4893.meters limit 5 + radians(1) | +============================ + 0.017453292519943 | + 0.017453292519943 | + 0.017453292519943 | + 0.017453292519943 | + 0.017453292519943 | + +taos> select RADIANS(1) + 1 from ts_4893.meters limit 1 + radians(1) + 1 | +============================ + 1.017453292519943 | + +taos> select RADIANS(1) - 1 from ts_4893.meters limit 1 + radians(1) - 1 | +============================ + -0.982546707480057 | + +taos> select RADIANS(1) * 2 from ts_4893.meters limit 1 + radians(1) * 2 | +============================ + 0.034906585039887 | + +taos> select RADIANS(1) / 2 from ts_4893.meters limit 1 + radians(1) / 2 | +============================ + 0.008726646259972 | + +taos> select RADIANS(2) + RADIANS(1) from ts_4893.meters limit 1 + radians(2) + radians(1) | +============================ + 0.052359877559830 | + +taos> select RADIANS(2) - RADIANS(1) from ts_4893.meters limit 1 + radians(2) - radians(1) | +============================ + 0.017453292519943 | + +taos> select RADIANS(2) * RADIANS(1) from ts_4893.meters limit 1 + radians(2) * radians(1) | +============================ + 0.000609234839573 | + +taos> select RADIANS(2) / RADIANS(1) from ts_4893.meters limit 1 + radians(2) / radians(1) | +============================ + 2.000000000000000 | + +taos> select RADIANS(1) + id from ts_4893.meters order by ts limit 5 + radians(1) + id | +============================ + 0.017453292519943 | + 1.017453292519943 | + 2.017453292519943 | + 3.017453292519943 | + 4.017453292519943 | + +taos> select RADIANS(id) + id from ts_4893.meters order by ts limit 5 + radians(id) + id | +============================ + 0.000000000000000 | + 1.017453292519943 | + 2.034906585039887 | + 3.052359877559830 | + 4.069813170079773 | + +taos> select RADIANS(abs(10)) + radians(abs(10)) | +============================ + 0.174532925199433 | + +taos> select RADIANS(DEGREES(PI())) + radians(degrees(pi())) | +============================ + 3.141592653589793 | + +taos> select abs(RADIANS(10)) + abs(radians(10)) | +============================ + 0.174532925199433 | + +taos> select pow(RADIANS(10), 2) + pow(radians(10), 2) | +============================ + 0.030461741978671 | + +taos> select sqrt(RADIANS(10)) + sqrt(radians(10)) | +============================ + 0.417771379105167 | + +taos> select cast(RADIANS(10) as int) + cast(radians(10) as int) | +=========================== + 0 | + +taos> select RADIANS(sqrt(id)) from ts_4893.meters order by ts limit 5 + radians(sqrt(id)) | +============================ + 0.000000000000000 | + 0.017453292519943 | + 0.024682682989769 | + 0.030229989403904 | + 0.034906585039887 | + +taos> select radians(180) + radians(180) | +============================ + 3.141592653589793 | + +taos> select radians(current) from ts_4893.d0 order by ts limit 10 + radians(current) | +============================ + 0.185877558679493 | + 0.149644536324422 | + 0.170955001564425 | + 0.196052831414414 | + 0.186854955444309 | + 0.148492619284422 | + 0.167481790094528 | + 0.191322990739406 | + 0.195930658899406 | + 0.180414682914441 | + +taos> select radians(current) from ts_4893.meters order by ts limit 10 + radians(current) | +============================ + 0.185877558679493 | + 0.149644536324422 | + 0.170955001564425 | + 0.196052831414414 | + 0.186854955444309 | + 0.148492619284422 | + 0.167481790094528 | + 0.191322990739406 | + 0.195930658899406 | + 0.180414682914441 | + +taos> select radians(null) + radians(null) | +============================ + NULL | + +taos> select radians(0) + radians(0) | +============================ + 0.000000000000000 | + +taos> select radians(45) + radians(45) | +============================ + 0.785398163397448 | + +taos> select radians(-45) + radians(-45) | +============================ + -0.785398163397448 | + +taos> select radians(90) + radians(90) | +============================ + 1.570796326794897 | + +taos> select radians(-90) + radians(-90) | +============================ + -1.570796326794897 | + +taos> select radians(360) + radians(360) | +============================ + 6.283185307179586 | + +taos> select radians(1000000) + radians(1000000) | +============================ + 17453.292519943293883 | + +taos> select radians(sin(1)) + radians(sin(1)) | +============================ + 0.014686439244897 | + +taos> select radians(cos(1)) + radians(cos(1)) | +============================ + 0.009430054193517 | + +taos> select radians(tan(1)) + radians(tan(1)) | +============================ + 0.027181892591221 | + +taos> select radians(degrees(90)) + radians(degrees(90)) | +============================ + 89.999999999999986 | + +taos> select radians(atan(1)) + radians(atan(1)) | +============================ + 0.013707783890402 | + +taos> select radians(current) from ts_4893.meters limit 1 + radians(current) | +============================ + 0.185877558679493 | + +taos> select radians(voltage) from ts_4893.meters limit 1 + radians(voltage) | +============================ + 3.857177646907469 | + +taos> select radians(phase) from ts_4893.meters limit 1 + radians(phase) | +============================ + 0.008881946002226 | + diff --git a/tests/army/query/function/ans/rand.csv b/tests/army/query/function/ans/rand.csv index 40e20c5ba4..98a096233c 100644 --- a/tests/army/query/function/ans/rand.csv +++ b/tests/army/query/function/ans/rand.csv @@ -1,21 +1,173 @@ -0.663936012733698 -0.840187717154710 -0.840187717154710 -0.700976369297587 -0.561380175203728 -0.916457875592847 -0.274745596235034 -0.135438768721856 -0.486904139391568 -0.352760728612896 -0.206965447965528 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 -0.419929514834624 \ No newline at end of file + +taos> select RAND(1245) + rand(1245) | +============================ + 0.663936012733698 | + +taos> select RAND(id) from ts_4893.d0 limit 10 + rand(id) | +============================ + 0.840187717154710 | + 0.840187717154710 | + 0.700976369297587 | + 0.561380175203728 | + 0.916457875592847 | + 0.274745596235034 | + 0.135438768721856 | + 0.486904139391568 | + 0.352760728612896 | + 0.206965447965528 | + +taos> select RAND(id) from ts_4893.d0 order by id desc limit 10 + rand(id) | +============================ + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + 0.419929514834624 | + +taos> select rand(0) + rand(0) | +============================ + 0.840187717154710 | + +taos> select rand(1) + rand(1) | +============================ + 0.840187717154710 | + +taos> select rand(-1) + rand(-1) | +============================ + 0.118708995691831 | + +taos> select rand(12345678901234567890) + rand(12345678901234567890) | +============================= + 2.008294813338805e-01 | + +taos> select rand(-12345678901234567890) + rand(-12345678901234567890) | +============================== + 8.401877171547095e-01 | + +taos> select rand(12345), rand(12345) + rand(12345) | rand(12345) | +======================================================== + 0.178395304446293 | 0.178395304446293 | + +taos> select rand(9999999999) where rand(9999999999) >= 0 and rand(9999999999) < 1 + rand(9999999999) | +============================ + 0.321409397442550 | + +taos> select rand(id) from ts_4893.meters limit 100 + rand(id) | +============================ + 0.840187717154710 | + 0.840187717154710 | + 0.700976369297587 | + 0.561380175203728 | + 0.916457875592847 | + 0.274745596235034 | + 0.135438768721856 | + 0.486904139391568 | + 0.352760728612896 | + 0.206965447965528 | + 0.565810732341283 | + 0.926345318521534 | + 0.785600282617658 | + 0.632643183056565 | + 0.999498499557142 | + 0.354973177125199 | + 0.215437470104283 | + 0.571794000254848 | + 0.929072778173291 | + 0.290233385418650 | + 0.148812267532950 | + 0.505899571117898 | + 0.865026922367991 | + 0.727581746283724 | + 0.087714229285584 | + 0.939356191986872 | + 0.795545781867367 | + 0.659832971943465 | + 0.517155105023251 | + 0.875989373715589 | + 0.229967075041480 | + 0.592119012303706 | + 0.449675684072858 | + 0.307948935454688 | + 0.168970021497910 | + 0.524489704763745 | + 0.381259786142623 | + 0.239412393066758 | + 0.598226357529977 | + 0.957148446215851 | + 0.819422913165494 | + 0.670246056127477 | + 0.033469948001890 | + 0.392149003405193 | + 0.749737140606035 | + 0.608923980318440 | + 0.469695958061933 | + 0.825680229266025 | + 0.683865774275673 | + 0.041811583583155 | + 0.894321223206036 | + 0.760580372885140 | + 0.615916447069457 | + 0.977703406930763 | + 0.329537633959920 | + 0.193522962831670 | + 0.052021294390793 | + 0.911150676622591 | + 0.766549994129012 | + 0.126697651635249 | + 0.985316422761100 | + 0.843173408342140 | + 0.699550600116863 | + 0.557263156192965 | + 0.419794161068180 | + 0.278590486048996 | + 0.133239280028846 | + 0.488706417143674 | + 0.854142372894167 | + 0.710721029765308 | + 0.570226699379378 | + 0.424855420563768 | + 0.283543675338637 | + 0.137892492179709 | + 0.998458440880505 | + 0.356983164025928 | + 0.218767986269094 | + 0.076468908263589 | + 0.431104593179703 | + 0.293163777931204 | + 0.650123746902740 | + 0.510736836358317 | + 0.864335399057872 | + 0.725284450559544 | + 0.085677149279824 | + 0.942077809917777 | + 0.798407114482674 | + 0.163865051774245 | + 0.017995767769402 | + 0.879516513030751 | + 0.736922031145972 | + 0.589669372695344 | + 0.954449085497507 | + 0.811225361568493 | + 0.172090128609953 | + 0.525153056031630 | + 0.386470556904781 | + 0.744990266275122 | + 0.100015020510189 | + 0.460091779222755 | + diff --git a/tests/army/query/function/ans/repeat.csv b/tests/army/query/function/ans/repeat.csv index 98176c87a3..d8f8b3050f 100644 --- a/tests/army/query/function/ans/repeat.csv +++ b/tests/army/query/function/ans/repeat.csv @@ -1,161 +1,396 @@ -hello -hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello -aa -g;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddh -gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc;ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddh -aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc;ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddgh -6400 -50060 -北京taos北京taos北京taos北京taos北京taos北京taos -novelnovelnovelnovelnovelnovel -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdateupdateupdateupdate -prisionprisionprisionprisionprisionprision -novelnovelnovelnovelnovelnovel -novelnovelnovelnovelnovelnovel -personpersonpersonpersonpersonperson -novelnovelnovelnovelnovelnovel -plateplateplateplateplateplate -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -一二三四五六七八九十 -updateupdate -prisionprisionprision -novelnovelnovelnovel -novelnovelnovelnovelnovel -person -novelnovel -plateplateplate -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdateupdateupdate -nch1 -nch1nch1 -nch1nch1nch1 -nch1nch1nch1nch1 -nch1nch1nch1nch1nch1 -var1 -var1var1 -var1var1var1 -var1var1var1var1 -var1var1var1var1var1 -taos -taostaos -lililililili -xxx -lililililili -xxx -lililililili -taostaostaos -hahahahahaha -taostaostaos -taostaostaos -hahahahahaha -lililililili -xxx -lililililili -xxx -lililililili -taostaostaos -hahahahahaha -taostaostaos -taostaostaos -hahahahahaha -novelnovelnovel -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdate -prisionprisionprision -novelnovelnovel -novelnovelnovel -againagainagain -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -novelnovelnovel -againagainagain -novelnovelnovel -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdate -prisionprisionprision -novelnovelnovel -novelnovelnovel -againagainagain -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -novelnovelnovel -againagainagain -novelnovelnovel -personpersonperson -novelnovelnovel -plateplateplate -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdate -prisionprisionprision -personpersonperson -prisionprisionprision -plateplateplate -novelnovelnovel -personpersonperson -novelnovelnovel -plateplateplate -一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 -updateupdateupdate -prisionprisionprision -personpersonperson -prisionprisionprision -plateplateplate -lili -x -lili -x -lili -taos -haha -taos -taos -haha -lili -x -lili -x -lili -taos -haha -taos -taos -haha -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again + +taos> select repeat('hello', 1) + repeat('hello', 1) | +===================== + hello | + +taos> select repeat('hello', 20) + repeat('hello', 20) | +================================= + hellohellohellohellohellohe... | + +taos> SELECT REPEAT('a', 2) + repeat('a', 2) | +================= + aa | + +taos> SELECT CONCAT('g',CONCAT(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') + concat('g',concat(';',repeat('a',60), repeat('b',60), repeat('c' | +=================================================================== + g;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | + +taos> SELECT CONCAT('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') + concat('g',concat_ws(';',repeat('a',60), repeat('b',60), repeat( | +=================================================================== + gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | + +taos> SELECT CONCAT_WS('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') + concat_ws('g',concat_ws(';',repeat('a',60), repeat('b',60), repe | +=================================================================== + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;... | + +taos> select length(concat(repeat("a",3200),repeat("a",3200))) + length(concat(repeat("a",3200),repeat("a",3200))) | +==================================================== + 6400 | + +taos> select length(replace("aaaaa","a",concat(repeat("a",10000),repeat("a",12)))) + length(replace("aaaaa","a",concat(repeat("a",10000),repeat("a",1 | +=================================================================== + 50060 | + +taos> select repeat('北京taos', 6) + repeat('北京taos', 6) | +================================= + 北京taos北京taos北京taos北... | + +taos> select repeat(nch1, 6) from ts_4893.meters order by ts limit 5 + repeat(nch1, 6) | +================================= + novelnovelnovelnovelnovelnovel | + 一二三四五六七八九十一二三... | + updateupdateupdateupdateupd... | + prisionprisionprisionprisio... | + novelnovelnovelnovelnovelnovel | + +taos> select repeat(var1, 6) from ts_4893.meters order by ts limit 5 + repeat(var1, 6) | +================================= + novelnovelnovelnovelnovelnovel | + personpersonpersonpersonper... | + novelnovelnovelnovelnovelnovel | + plateplateplateplateplateplate | + 一二三四五六七八九十一二三... | + +taos> select position(nch1 in repeat(nch1,6)) from ts_4893.meters order by ts limit 5 + position(nch1 in repeat(nch1,6)) | +=================================== + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select position(var1 in repeat(var1,6)) from ts_4893.meters order by ts limit 5 + position(var1 in repeat(var1,6)) | +=================================== + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select position(nch1 in repeat(var1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5 + position(nch1 in repeat(var1,6)) | +=================================== + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select position(var1 in repeat(nch1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5 + position(var1 in repeat(nch1,6)) | +=================================== + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select repeat(nch1, id) from ts_4893.meters where id > 0 order by ts limit 5 + repeat(nch1, id) | +================================= + 一二三四五六七八九十 | + updateupdate | + prisionprisionprision | + novelnovelnovelnovel | + novelnovelnovelnovelnovel | + +taos> select repeat(var1, id) from ts_4893.meters where id > 0 order by ts limit 5 + repeat(var1, id) | +=================== + person | + novelnovel | + plateplateplate | + 一二三四五六... | + updateupdateu... | + +taos> select repeat('nch1', id) from ts_4893.meters where id > 0 order by ts limit 5 + repeat('nch1', id) | +================================= + nch1 | + nch1nch1 | + nch1nch1nch1 | + nch1nch1nch1nch1 | + nch1nch1nch1nch1nch1 | + +taos> select repeat('var1', id) from ts_4893.meters where id > 0 order by ts limit 5 + repeat('var1', id) | +================================= + var1 | + var1var1 | + var1var1var1 | + var1var1var1var1 | + var1var1var1var1var1 | + +taos> select repeat('taos', 1) + repeat('taos', 1) | +==================== + taos | + +taos> select repeat('taos', 2) + repeat('taos', 2) | +==================== + taostaos | + +taos> select repeat(name, 3) from ts_4893.d0 order by ts limit 10 + repeat(name, 3) | +================================= + lililililili | + xxx | + lililililili | + xxx | + lililililili | + taostaostaos | + hahahahahaha | + taostaostaos | + taostaostaos | + hahahahahaha | + +taos> select repeat(name, 3) from ts_4893.meters order by ts limit 10 + repeat(name, 3) | +================================= + lililililili | + xxx | + lililililili | + xxx | + lililililili | + taostaostaos | + hahahahahaha | + taostaostaos | + taostaostaos | + hahahahahaha | + +taos> select repeat(nch1, 3) from ts_4893.d0 order by ts limit 10 + repeat(nch1, 3) | +================================= + novelnovelnovel | + 一二三四五六七八九十一二三... | + updateupdateupdate | + prisionprisionprision | + novelnovelnovel | + novelnovelnovel | + againagainagain | + 一二三四五六七八九十一二三... | + novelnovelnovel | + againagainagain | + +taos> select repeat(nch1, 3) from ts_4893.meters order by ts limit 10 + repeat(nch1, 3) | +================================= + novelnovelnovel | + 一二三四五六七八九十一二三... | + updateupdateupdate | + prisionprisionprision | + novelnovelnovel | + novelnovelnovel | + againagainagain | + 一二三四五六七八九十一二三... | + novelnovelnovel | + againagainagain | + +taos> select repeat(var1, 3) from ts_4893.d0 order by ts limit 10 + repeat(var1, 3) | +================================= + novelnovelnovel | + personpersonperson | + novelnovelnovel | + plateplateplate | + 一二三四五六七八九十一二三... | + updateupdateupdate | + prisionprisionprision | + personpersonperson | + prisionprisionprision | + plateplateplate | + +taos> select repeat(var1, 3) from ts_4893.meters order by ts limit 10 + repeat(var1, 3) | +================================= + novelnovelnovel | + personpersonperson | + novelnovelnovel | + plateplateplate | + 一二三四五六七八九十一二三... | + updateupdateupdate | + prisionprisionprision | + personpersonperson | + prisionprisionprision | + plateplateplate | + +taos> select repeat(name, groupid) from ts_4893.d0 order by ts limit 10 + repeat(name, groupid) | +======================== + lili | + x | + lili | + x | + lili | + taos | + haha | + taos | + taos | + haha | + +taos> select repeat(name, groupid) from ts_4893.meters order by ts limit 10 + repeat(name, groupid) | +======================== + lili | + x | + lili | + x | + lili | + taos | + haha | + taos | + taos | + haha | + +taos> select repeat(nch1, groupid) from ts_4893.d0 order by ts limit 10 + repeat(nch1, groupid) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select repeat(nch1, groupid) from ts_4893.meters order by ts limit 10 + repeat(nch1, groupid) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select repeat(null, 3) + repeat(null, 3) | +================== + NULL | + +taos> select repeat('taos', null) + repeat('taos', null) | +======================= + NULL | + +taos> select repeat('taos', 0) + repeat('taos', 0) | +==================== + | + +taos> select repeat('', 5) + repeat('', 5) | +================ + | + +taos> select repeat('A', 0) + repeat('A', 0) | +================= + | + +taos> select repeat('A', 10) + repeat('A', 10) | +================================= + AAAAAAAAAA | + +taos> select repeat('A B', 5) + repeat('A B', 5) | +============================ + A BA BA BA BA B | + +taos> select repeat('ABC', 1) + repeat('ABC', 1) | +=================== + ABC | + +taos> select repeat('Hello', 2) + repeat('Hello', 2) | +===================== + HelloHello | + +taos> select repeat('HelloWorld', 2) + repeat('HelloWorld', 2) | +=========================== + HelloWorldHelloWorld | + +taos> select repeat('123', 5) + repeat('123', 5) | +============================ + 123123123123123 | + +taos> select repeat('12345', 3) + repeat('12345', 3) | +======================== + 123451234512345 | + +taos> select repeat('!@#', 3) + repeat('!@#', 3) | +=================== + !@#!@#!@# | + +taos> select repeat('你好', 2) + repeat('你好', 2) | +====================== + 你好你好 | + +taos> select repeat('abc', length('abc')) + repeat('abc', length('abc')) | +=============================== + abcabcabc | + +taos> select repeat(concat('A', 'B', 'C'), 3) + repeat(concat('A', 'B', 'C'), 3) | +=================================== + ABCABCABC | + +taos> select repeat(upper('abc'), 4) + repeat(upper('abc'), 4) | +========================== + ABCABCABCABC | + +taos> select repeat(trim(' Hello '), 3) + repeat(trim(' Hello '), 3) | +================================= + HelloHelloHello | + +taos> select name, repeat(name, 3) from ts_4893.meters limit 1 + name | repeat(name, 3) | +================================================================== + lili | lililililili | + +taos> select name, repeat(substring(name, 1, 5), 2) from ts_4893.meters limit 1 + name | repeat(substring(name, 1, 5), 2) | +==================================================================== + lili | lililili | + +taos> select var1, repeat(var1, 2) from ts_4893.meters limit 1 + var1 | repeat(var1, 2) | +================================================================== + novel | novelnovel | + +taos> select nch1, repeat(nch1, 4) from ts_4893.meters limit 1 + nch1 | repeat(nch1, 4) | +================================================================== + novel | novelnovelnovelnovel | + diff --git a/tests/army/query/function/ans/replace.csv b/tests/army/query/function/ans/replace.csv index 4df4e02d83..e1b7654897 100644 --- a/tests/army/query/function/ans/replace.csv +++ b/tests/army/query/function/ans/replace.csv @@ -1,476 +1,979 @@ -bbbb -bb -bbbbbbbb -aaaa -bbbb -this is a REAL test -涛思 -北京 -北京涛北京com -北京涛思.com -北京涛思 -novel -一二三四五六七八九十 -updbte -prision -novel -updbte -bgbin -bgbin -plbte -bbc一二三bbc一二三bbc -novel -一二三四五六七八九十 -prision -novel -novel -novel -一二三四五六七八九十 -upd啊te -prision -novel -upd啊te -啊g啊in -啊g啊in -pl啊te -啊bc一二三啊bc一二三啊bc -novel -一二三四五六七八九十 -prision -novel -novel -novel -壹二三四五六七八九十 -update -prision -novel -壹二三四五六七八九十 -壹二三四五六七八九十 -abc壹二三abc壹二三abc -壹壹壹壹壹||壹壹壹壹 -壹二三123321三二壹 -novel -update -prision -novel -novel -novel -1二三四五六七八九十 -update -prision -novel -1二三四五六七八九十 -1二三四五六七八九十 -abc1二三abc1二三abc -11111||1111 -1二三123321三二1 -novel -update -prision -novel -novel -novel -一二三四五六七八九十 -update -prision -novnch2l -novnch2l -anch2c一二三anch2c一二三anch2c -一二三anch2c -一二三nch2五六七八九十 -pnch2rson -novel -一二三四五六七八九十 -update -prision -novel -novvar2l -一二三四五六七八九十 -update -prision -novel -novvar2l -novvar2l -var2abc -var2123321三二一 -abvar2一二三abvar2一二三abvar2 -一二三四五六七八九十 -update -prision -novel -novel -novel -一二f四五六七八九十 -update -prision -novel -一二f四五六七八九十 -一二d四五六七八九十 -abc一二babc一二babc -一二三a123321三a二一 -一二babc -novel -update -prision -novel -novel -novel -一二三a四五六七八九十 -update -prision -novel -一二三a四五六七八九十 -一二b四五六七八九十 -abc一二fabc一二fabc -一二三a123321三a二一 -一二一二三abc -novel -update -prision -novel -novel -novel -一二三四五六七八九十 -update -prision -novbl -novbl -afc一二三afc一二三afc -一二三a一二三c -一二三三a五六七八九十 -pdrson -novel -一二三四五六七八九十 -update -prision -novel -nov四l -一二三四五六七八九十 -update -prision -novel -nov四l -novcl -babc -三a123321三二一 -abf一二三abf一二三abf -一二三四五六七八九十 -update -prision -novel -novel -novel -person -novel -plbte -一二三四五六七八九十 -plbte -updbte -plbte -updbte -一二三bbc -novel -person -novel -一二三四五六七八九十 -prision -novel -person -novel -pl啊te -一二三四五六七八九十 -pl啊te -upd啊te -pl啊te -upd啊te -一二三啊bc -novel -person -novel -一二三四五六七八九十 -prision -novel -person -novel -plate -壹二三四五六七八九十 -壹二三四五六七八九十 -壹二三abc -abc壹二三abc壹二三abc -壹二三123321三二壹 -壹壹壹壹壹||壹壹壹壹 -novel -person -novel -plate -update -novel -person -novel -plate -1二三四五六七八九十 -1二三四五六七八九十 -1二三abc -abc1二三abc1二三abc -1二三123321三二1 -11111||1111 -novel -person -novel -plate -update -novel -person -novel -plate -一二三四五六七八九十 -一二nch2bc -anch2c一二三anch2c一二三anch2c -nch2bc一二三nch2bc一二三nch2bc -novnch2l -upnch2ate -novel -person -novel -plate -一二三四五六七八九十 -novvar2l -person -novel -platvar2 -一二三四五六七八九十 -novvar2l -platvar2 -一二三var2bc -var2123321三二一 -abvar2一二三abvar2一二三abvar2 -person -novel -一二三四五六七八九十 -update -prision -novel -person -novel -plate -一二e四五六七八九十 -一二e四五六七八九十 -一二三aabc -abc一二babc一二babc -一二三a123321三a二一 -一二c四五六七八九十 -novel -person -novel -plate -update -novel -person -novel -plate -一二b四五六七八九十 -一二b四五六七八九十 -一二aabc -abc一二fabc一二fabc -一二四123321四二一 -一二b四五六七八九十 -novel -person -novel -plate -update -novel -person -novel -plate -一二三四五六七八九十 -一二abc -afc一二三afc一二三afc -四bc一二三四bc一二三四bc -novdl -up一二三ate -novel -person -novel -plate -一二三四五六七八九十 -nov四l -person -novel -plat一 -一二三四五六七八九十 -nov四l -plat一 -一二三三abc -b123321三二一 -abf一二三abf一二三abf -person -novel -一二三四五六七八九十 -update -prision -一二三nch2五六七abcdefghijk213124123 -一二三四五六七abcdench2ghijk213124123 -一二三四五六七abnch2defghijk213124123 -nch2二三四五六七abcdefghijk213124123 -一二三四五六七abcdnch2fghijk213124123 -一二三nch2五六七abcdefghijk213124123 -一二三四五六七abcdench2ghijk213124123 -一二三四五六七abnch2defghijk213124123 -nch2二三四五六七abcdefghijk213124123 -一二三四五六七abcdnch2fghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三e五六七abcdefghijk213124123 -一二三四五六七abcde三aghijk213124123 -一二三四五六七ab四defghijk213124123 -e二三四五六七abcdefghijk213124123 -一二三四五六七abcdbfghijk213124123 -一二三e五六七abcdefghijk213124123 -一二三四五六七abcde三aghijk213124123 -一二三四五六七ab四defghijk213124123 -e二三四五六七abcdefghijk213124123 -一二三四五六七abcdbfghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdvar2fghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三var2五六七abcdefghijk213124123 -一二三四五六七abcdvar2fghijk213124123 -一二三四五六七avar2cdefghijk213124123 -一二三四五六七abcdvar2fghijk213124123 -一二三var2五六七abcdefghijk213124123 -一二三四五六七abcdvar2fghijk213124123 -一二三四五六七avar2cdefghijk213124123 -一二三四五六七abcdefvar2hijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcd四fghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三c五六七abcdefghijk213124123 -一二三四五六七abcd一fghijk213124123 -一二三四五六七aecdefghijk213124123 -一二三四五六七abcd四fghijk213124123 -一二三c五六七abcdefghijk213124123 -一二三四五六七abcd一fghijk213124123 -一二三四五六七aecdefghijk213124123 -一二三四五六七abcdef一二三hijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -一二三四五六七abcdefghijk213124123 -eebbccdd -aabbccdd -南京 -北南 -南京taos -novel -一二三四五六七八九十 -update -prision -novtl -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novtl -novel -again -一二三四五六七八九十 -novel -again -novtl -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novtl -again -novtl -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novtl -again -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novtl -person -novel -platt -一二三四五六七八九十 -update -prision -person -prision -plate -novtl -person -novel -platt -一二三四五六七八九十 -update -prision -person -prision -plate -novel -一二三四五六七八九十 -update -prision -nov一二三四五六七八九十l -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -nov一二三四五六七八九十l -novel -again -一二三四五六七八九十 -novel -again + +taos> select replace('aaaa','a','b') + replace('aaaa','a','b') | +========================== + bbbb | + +taos> select replace('aaaa','aa','b') + replace('aaaa','aa','b') | +=========================== + bb | + +taos> select replace('aaaa','a','bb') + replace('aaaa','a','bb') | +=========================== + bbbbbbbb | + +taos> select replace('aaaa','','b') + replace('aaaa','','b') | +========================= + aaaa | + +taos> select replace('bbbb','a','c') + replace('bbbb','a','c') | +========================== + bbbb | + +taos> select replace(concat(lower(concat('THIS',' ','IS',' ','A',' ')),upper('false'),' ','test'),'FALSE','REAL') + replace(concat(lower(concat('THIS',' ','IS',' ','A',' ')),upper( | +=================================================================== + this is a REAL test | + +taos> select replace('北京涛思','北京', '') + replace('北京涛思','北京', '') | +======================================= + 涛思 | + +taos> select replace('北京涛思','涛思', '') + replace('北京涛思','涛思', '') | +======================================= + 北京 | + +taos> select replace('北京涛思.com','思.', '北京') + replace('北京涛思.com','思.', '北京') | +=============================================== + 北京涛北京com | + +taos> select replace('北京涛思.com','北com', '北京涛') + replace('北京涛思.com','北com', '北京涛') | +==================================================== + 北京涛思.com | + +taos> select replace('北京涛思', char(ascii('北')), 'wrongans') + replace('北京涛思', char(ascii('北')), 'wrongans') | +========================================================== + 北京涛思 | + +taos> select replace(nch1, 'a', 'b') from ts_4893.meters order by ts limit 5 + replace(nch1, 'a', 'b') | +================================= + novel | + 一二三四五六七八九十 | + updbte | + prision | + novel | + +taos> select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5 + replace(nch1, 'a', 'b') | +================================= + updbte | + bgbin | + bgbin | + plbte | + bbc一二三bbc一二三bbc | + +taos> select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5 + replace(nch1, 'a', 'b') | +================================= + novel | + 一二三四五六七八九十 | + prision | + novel | + novel | + +taos> select replace(nch1, 'a', '啊') from ts_4893.meters order by ts limit 5 + replace(nch1, 'a', '啊') | +================================= + novel | + 一二三四五六七八九十 | + upd啊te | + prision | + novel | + +taos> select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5 + replace(nch1, 'a', '啊') | +================================= + upd啊te | + 啊g啊in | + 啊g啊in | + pl啊te | + 啊bc一二三啊bc一二三啊bc | + +taos> select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5 + replace(nch1, 'a', '啊') | +================================= + novel | + 一二三四五六七八九十 | + prision | + novel | + novel | + +taos> select replace(nch1, '一', '壹') from ts_4893.meters order by ts limit 5 + replace(nch1, '一', '壹') | +================================= + novel | + 壹二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5 + replace(nch1, '一', '壹') | +================================= + 壹二三四五六七八九十 | + 壹二三四五六七八九十 | + abc壹二三abc壹二三abc | + 壹壹壹壹壹||壹壹壹壹 | + 壹二三123321三二壹 | + +taos> select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5 + replace(nch1, '一', '壹') | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select replace(nch1, '一', '1') from ts_4893.meters order by ts limit 5 + replace(nch1, '一', '1') | +================================= + novel | + 1二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5 + replace(nch1, '一', '1') | +================================= + 1二三四五六七八九十 | + 1二三四五六七八九十 | + abc1二三abc1二三abc | + 11111||1111 | + 1二三123321三二1 | + +taos> select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5 + replace(nch1, '一', '1') | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select replace(nch1, nch2, 'nch2') from ts_4893.meters order by ts limit 5 + replace(nch1, nch2, 'nch2') | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novnch2l | + +taos> select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5 + replace(nch1, nch2, 'nch2') | +================================= + novnch2l | + anch2c一二三anch2c一二三anch2c | + 一二三anch2c | + 一二三nch2五六七八九十 | + pnch2rson | + +taos> select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5 + replace(nch1, nch2, 'nch2') | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, var2, 'var2') from ts_4893.meters order by ts limit 5 + replace(nch1, var2, 'var2') | +================================= + novvar2l | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5 + replace(nch1, var2, 'var2') | +================================= + novvar2l | + novvar2l | + var2abc | + var2123321三二一 | + abvar2一二三abvar2一二三abvar2 | + +taos> select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5 + replace(nch1, var2, 'var2') | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select replace(nch1, '三', nch2) from ts_4893.meters order by ts limit 5 + replace(nch1, '三', nch2) | +================================= + novel | + 一二f四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5 + replace(nch1, '三', nch2) | +================================= + 一二f四五六七八九十 | + 一二d四五六七八九十 | + abc一二babc一二babc | + 一二三a123321三a二一 | + 一二babc | + +taos> select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5 + replace(nch1, '三', nch2) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select replace(nch1, '三', var2) from ts_4893.meters order by ts limit 5 + replace(nch1, '三', var2) | +================================= + novel | + 一二三a四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5 + replace(nch1, '三', var2) | +================================= + 一二三a四五六七八九十 | + 一二b四五六七八九十 | + abc一二fabc一二fabc | + 一二三a123321三a二一 | + 一二一二三abc | + +taos> select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5 + replace(nch1, '三', var2) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select replace(nch1, nch2, var2) from ts_4893.meters order by ts limit 5 + replace(nch1, nch2, var2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novbl | + +taos> select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5 + replace(nch1, nch2, var2) | +================================= + novbl | + afc一二三afc一二三afc | + 一二三a一二三c | + 一二三三a五六七八九十 | + pdrson | + +taos> select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5 + replace(nch1, nch2, var2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, var2, nch2) from ts_4893.meters order by ts limit 5 + replace(nch1, var2, nch2) | +================================= + nov四l | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5 + replace(nch1, var2, nch2) | +================================= + nov四l | + novcl | + babc | + 三a123321三二一 | + abf一二三abf一二三abf | + +taos> select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5 + replace(nch1, var2, nch2) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select replace(var1, 'a', 'b') from ts_4893.meters order by ts limit 5 + replace(var1, 'a', 'b') | +================================= + novel | + person | + novel | + plbte | + 一二三四五六七八九十 | + +taos> select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5 + replace(var1, 'a', 'b') | +================================= + plbte | + updbte | + plbte | + updbte | + 一二三bbc | + +taos> select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5 + replace(var1, 'a', 'b') | +================================= + novel | + person | + novel | + 一二三四五六七八九十 | + prision | + +taos> select replace(var1, 'a', '啊') from ts_4893.meters order by ts limit 5 + replace(var1, 'a', '啊') | +================================= + novel | + person | + novel | + pl啊te | + 一二三四五六七八九十 | + +taos> select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5 + replace(var1, 'a', '啊') | +================================= + pl啊te | + upd啊te | + pl啊te | + upd啊te | + 一二三啊bc | + +taos> select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5 + replace(var1, 'a', '啊') | +================================= + novel | + person | + novel | + 一二三四五六七八九十 | + prision | + +taos> select replace(var1, '一', '壹') from ts_4893.meters order by ts limit 5 + replace(var1, '一', '壹') | +================================= + novel | + person | + novel | + plate | + 壹二三四五六七八九十 | + +taos> select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5 + replace(var1, '一', '壹') | +================================= + 壹二三四五六七八九十 | + 壹二三abc | + abc壹二三abc壹二三abc | + 壹二三123321三二壹 | + 壹壹壹壹壹||壹壹壹壹 | + +taos> select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5 + replace(var1, '一', '壹') | +================================= + novel | + person | + novel | + plate | + update | + +taos> select replace(var1, '一', '1') from ts_4893.meters order by ts limit 5 + replace(var1, '一', '1') | +================================= + novel | + person | + novel | + plate | + 1二三四五六七八九十 | + +taos> select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5 + replace(var1, '一', '1') | +================================= + 1二三四五六七八九十 | + 1二三abc | + abc1二三abc1二三abc | + 1二三123321三二1 | + 11111||1111 | + +taos> select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5 + replace(var1, '一', '1') | +================================= + novel | + person | + novel | + plate | + update | + +taos> select replace(var1, nch2, 'nch2') from ts_4893.meters order by ts limit 5 + replace(var1, nch2, 'nch2') | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5 + replace(var1, nch2, 'nch2') | +================================= + 一二nch2bc | + anch2c一二三anch2c一二三anch2c | + nch2bc一二三nch2bc一二三nch2bc | + novnch2l | + upnch2ate | + +taos> select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5 + replace(var1, nch2, 'nch2') | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select replace(var1, var2, 'var2') from ts_4893.meters order by ts limit 5 + replace(var1, var2, 'var2') | +================================= + novvar2l | + person | + novel | + platvar2 | + 一二三四五六七八九十 | + +taos> select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5 + replace(var1, var2, 'var2') | +================================= + novvar2l | + platvar2 | + 一二三var2bc | + var2123321三二一 | + abvar2一二三abvar2一二三abvar2 | + +taos> select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5 + replace(var1, var2, 'var2') | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select replace(var1, '三', nch2) from ts_4893.meters order by ts limit 5 + replace(var1, '三', nch2) | +================================= + novel | + person | + novel | + plate | + 一二e四五六七八九十 | + +taos> select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5 + replace(var1, '三', nch2) | +================================= + 一二e四五六七八九十 | + 一二三aabc | + abc一二babc一二babc | + 一二三a123321三a二一 | + 一二c四五六七八九十 | + +taos> select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5 + replace(var1, '三', nch2) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select replace(var1, '三', var2) from ts_4893.meters order by ts limit 5 + replace(var1, '三', var2) | +================================= + novel | + person | + novel | + plate | + 一二b四五六七八九十 | + +taos> select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5 + replace(var1, '三', var2) | +================================= + 一二b四五六七八九十 | + 一二aabc | + abc一二fabc一二fabc | + 一二四123321四二一 | + 一二b四五六七八九十 | + +taos> select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5 + replace(var1, '三', var2) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select replace(var1, nch2, var2) from ts_4893.meters order by ts limit 5 + replace(var1, nch2, var2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5 + replace(var1, nch2, var2) | +================================= + 一二abc | + afc一二三afc一二三afc | + 四bc一二三四bc一二三四bc | + novdl | + up一二三ate | + +taos> select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5 + replace(var1, nch2, var2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select replace(var1, var2, nch2) from ts_4893.meters order by ts limit 5 + replace(var1, var2, nch2) | +================================= + nov四l | + person | + novel | + plat一 | + 一二三四五六七八九十 | + +taos> select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5 + replace(var1, var2, nch2) | +================================= + nov四l | + plat一 | + 一二三三abc | + b123321三二一 | + abf一二三abf一二三abf | + +taos> select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5 + replace(var1, var2, nch2) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2 | +=================================================================== + 一二三nch2五六七abcdefghijk213124123 | + 一二三四五六七abcdench2ghijk213124123 | + 一二三四五六七abnch2defghijk213124123 | + nch2二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdnch2fghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2 | +=================================================================== + 一二三nch2五六七abcdefghijk213124123 | + 一二三四五六七abcdench2ghijk213124123 | + 一二三四五六七abnch2defghijk213124123 | + nch2二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdnch2fghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2 | +=================================================================== + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, var2) | +=================================================================== + 一二三e五六七abcdefghijk213124123 | + 一二三四五六七abcde三aghijk213124123 | + 一二三四五六七ab四defghijk213124123 | + e二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdbfghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, var2) | +=================================================================== + 一二三e五六七abcdefghijk213124123 | + 一二三四五六七abcde三aghijk213124123 | + 一二三四五六七ab四defghijk213124123 | + e二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdbfghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', nch2, var2) | +=================================================================== + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, 'var2 | +=================================================================== + 一二三四五六七abcdvar2fghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三var2五六七abcdefghijk213124123 | + 一二三四五六七abcdvar2fghijk213124123 | + 一二三四五六七avar2cdefghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, 'var2 | +=================================================================== + 一二三四五六七abcdvar2fghijk213124123 | + 一二三var2五六七abcdefghijk213124123 | + 一二三四五六七abcdvar2fghijk213124123 | + 一二三四五六七avar2cdefghijk213124123 | + 一二三四五六七abcdefvar2hijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, 'var2 | +=================================================================== + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, nch2) | +=================================================================== + 一二三四五六七abcd四fghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三c五六七abcdefghijk213124123 | + 一二三四五六七abcd一fghijk213124123 | + 一二三四五六七aecdefghijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, nch2) | +=================================================================== + 一二三四五六七abcd四fghijk213124123 | + 一二三c五六七abcdefghijk213124123 | + 一二三四五六七abcd一fghijk213124123 | + 一二三四五六七aecdefghijk213124123 | + 一二三四五六七abcdef一二三hijk213124123 | + +taos> select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 + replace('一二三四五六七abcdefghijk213124123', var2, nch2) | +=================================================================== + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + 一二三四五六七abcdefghijk213124123 | + +taos> select replace('aabbccdd','aa', 'ee') + replace('aabbccdd','aa', 'ee') | +================================= + eebbccdd | + +taos> select replace('aabbccdd','AA', 'ee') + replace('aabbccdd','AA', 'ee') | +================================= + aabbccdd | + +taos> select replace('北京','北' , '南') + replace('北京','北' , '南') | +================================== + 南京 | + +taos> select replace('北京','京' , '南') + replace('北京','京' , '南') | +================================== + 北南 | + +taos> select replace('北京taos','北' , '南') + replace('北京taos','北' , '南') | +====================================== + 南京taos | + +taos> select replace(nch1, nch2, 't') from ts_4893.d0 order by ts limit 10 + replace(nch1, nch2, 't') | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novtl | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select replace(nch1, nch2, 't') from ts_4893.meters order by ts limit 10 + replace(nch1, nch2, 't') | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novtl | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select replace(nch1, var2, 't') from ts_4893.d0 order by ts limit 10 + replace(nch1, var2, 't') | +================================= + novtl | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novtl | + again | + +taos> select replace(nch1, var2, 't') from ts_4893.meters order by ts limit 10 + replace(nch1, var2, 't') | +================================= + novtl | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novtl | + again | + +taos> select replace(var1, nch2, 't') from ts_4893.d0 order by ts limit 10 + replace(var1, nch2, 't') | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select replace(var1, nch2, 't') from ts_4893.meters order by ts limit 10 + replace(var1, nch2, 't') | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select replace(var1, var2, 't') from ts_4893.d0 order by ts limit 10 + replace(var1, var2, 't') | +================================= + novtl | + person | + novel | + platt | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select replace(var1, var2, 't') from ts_4893.meters order by ts limit 10 + replace(var1, var2, 't') | +================================= + novtl | + person | + novel | + platt | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select replace(nch1, nch2, var1) from ts_4893.d0 order by ts limit 10 + replace(nch1, nch2, var1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + nov一二三四五六七八九十l | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select replace(nch1, nch2, var1) from ts_4893.meters order by ts limit 10 + replace(nch1, nch2, var1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + nov一二三四五六七八九十l | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select replace(null, 'aa', 'ee') + replace(null, 'aa', 'ee') | +============================ + NULL | + +taos> select replace(null, 'A', 'B') + replace(null, 'A', 'B') | +========================== + NULL | + +taos> select replace('', '', 'B') + replace('', '', 'B') | +======================= + | + +taos> select replace('', 'A', 'B') + replace('', 'A', 'B') | +======================== + | + +taos> select replace('A', 'A', '') + replace('A', 'A', '') | +======================== + | + +taos> select replace('aabbccdd', null, 'ee') + replace('aabbccdd', null, 'ee') | +================================== + NULL | + +taos> select replace('Hello', 'Z', 'X') + replace('Hello', 'Z', 'X') | +============================= + Hello | + +taos> select replace('Hello World', ' ', '_') + replace('Hello World', ' ', '_') | +=================================== + Hello_World | + +taos> select replace('Hello World', 'World', 'MySQL') + replace('Hello World', 'World', 'MySQL') | +=========================================== + Hello MySQL | + +taos> select replace('12345', '5', 'five') + replace('12345', '5', 'five') | +================================ + 1234five | + +taos> select replace('中国', '中', '国') + replace('中国', '中', '国') | +================================== + 国国 | + +taos> select replace('é', 'e', 'a') + replace('é', 'e', 'a') | +========================== + é | + +taos> select replace('!@#', '@', '#') + replace('!@#', '@', '#') | +=========================== + !## | + +taos> select replace('123456', '7', 'eight') + replace('123456', '7', 'eight') | +================================== + 123456 | + +taos> select replace(concat('A', 'B', 'C'), 'B', 'Z') + replace(concat('A', 'B', 'C'), 'B', 'Z') | +=========================================== + AZC | + +taos> select replace(upper('abc'), 'A', 'X') + replace(upper('abc'), 'A', 'X') | +================================== + XBC | + +taos> select replace(trim(' Hello '), 'l', 'L') + replace(trim(' Hello '), 'l', 'L') | +======================================= + HeLLo | + +taos> select replace(lower('HELLO'), 'h', 'H') + replace(lower('HELLO'), 'h', 'H') | +==================================== + Hello | + +taos> select name, replace(substring(name, 1, 5), 'e', 'o') from ts_4893.meters limit 1 + name | replace(substring(name, 1, 5), 'e', 'o') | +============================================================================ + lili | lili | + +taos> select name, replace(name, 'a', 'o') from ts_4893.meters limit 1 + name | replace(name, 'a', 'o') | +================================================================== + lili | lili | + +taos> select var1, replace(var1, '1', 'one') from ts_4893.meters limit 1 + var1 | replace(var1, '1', 'one') | +================================================================== + novel | novel | + +taos> select nch1, replace(nch1, 'n', 'm') from ts_4893.meters limit 1 + nch1 | replace(nch1, 'n', 'm') | +================================================================== + novel | movel | + diff --git a/tests/army/query/function/ans/round.csv b/tests/army/query/function/ans/round.csv index 75b48e51a8..1b6ed548e7 100644 --- a/tests/army/query/function/ans/round.csv +++ b/tests/army/query/function/ans/round.csv @@ -1,94 +1,310 @@ -10.550000000000001 -10.550000000000001 -10.600000000000000 -11.000000000000000 -11.000000000000000 -10.000000000000000 -0.000000000000000 --10.600000000000000 -99 -111.000000000000000 -112.000000000000000 -12.000000000000000 -11.600000000000000 -1.230000000000000e+02 -1.230000000000000e+08 -11.0000000 -9.0000000 -10.0000000 -11.0000000 -11.0000000 -9.0000000 -10.0000000 -11.0000000 -11.0000000 -10.0000000 -11.0000000 -9.0000000 -11.0000000 -8.0000000 -12.0000000 -9.0000000 -10.0000000 -10.0000000 -10.0000000 -10.0000000 -8.765432100000000e+07 -8.765432109999999e+07 -8.765432112000000e+07 -8.765432112300000e+07 -8.765432112350000e+07 -8.765432112345999e+07 -8.765432112345700e+07 -8.765432112345681e+07 -8.765432112345679e+07 -8.765432112345679e+07 -11.0000000 -8.6000004 -9.8000002 -11.2329998 -10.7060003 -8.5080004 -9.5959997 -10.9619999 -11.2259998 -10.3369999 -10.6999998 -8.6000004 -9.8000002 -11.1999998 -10.6999998 -8.5000000 -9.6000004 -11.0000000 -11.1999998 -10.3000002 -10.55 -10.55 -10.6 -11 -11 -10 -0 --10.6 -99 -11 -9 -10 -11 -11 -9 -10 -11 -11 -10 -11 -9 -10 -11 -11 -9 -10 -11 -11 -10 + +taos> select ROUND(10.55, 3) + round(10.55, 3) | +============================ + 10.550000000000001 | + +taos> select ROUND(10.55, 2) + round(10.55, 2) | +============================ + 10.550000000000001 | + +taos> select ROUND(10.55, 1) + round(10.55, 1) | +============================ + 10.600000000000000 | + +taos> select ROUND(10.55, 0) + round(10.55, 0) | +============================ + 11.000000000000000 | + +taos> select ROUND(10.55) + round(10.55) | +============================ + 11.000000000000000 | + +taos> select ROUND(10.55, -1) + round(10.55, -1) | +============================ + 10.000000000000000 | + +taos> select ROUND(10.55, -10) + round(10.55, -10) | +============================ + 0.000000000000000 | + +taos> select ROUND(-10.55, 1) + round(-10.55, 1) | +============================ + -10.600000000000000 | + +taos> select ROUND(99, 1) + round(99, 1) | +======================== + 99 | + +taos> select ROUND(111.1111) + round(111.1111) | +============================ + 111.000000000000000 | + +taos> select ROUND(111.5111) + round(111.5111) | +============================ + 112.000000000000000 | + +taos> select ROUND(10.55) + 1 + round(10.55) + 1 | +============================ + 12.000000000000000 | + +taos> select ROUND(10.55, 1) + 1 + round(10.55, 1) + 1 | +============================ + 11.600000000000000 | + +taos> select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123.123456789, 9), 8), 7), 6), 5), 4)) + round(round(round(round(round(round(round(123.123456789, 9), 8), | +=================================================================== + 1.230000000000000e+02 | + +taos> select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123456789.123456789, -1), -2), -3), -4), -5), -6)) + round(round(round(round(round(round(round(123456789.123456789, - | +=================================================================== + 1.230000000000000e+08 | + +taos> select ROUND(current) from ts_4893.meters order by ts limit 20 + round(current) | +======================= + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 10.0000000 | + 11.0000000 | + 9.0000000 | + 11.0000000 | + 8.0000000 | + 12.0000000 | + 9.0000000 | + 10.0000000 | + 10.0000000 | + 10.0000000 | + 10.0000000 | + +taos> select ROUND(87654321.123456789, id) from ts_4893.meters order by ts limit 10 + round(87654321.123456789, id) | +================================ + 8.765432100000000e+07 | + 8.765432109999999e+07 | + 8.765432112000000e+07 | + 8.765432112300000e+07 | + 8.765432112350000e+07 | + 8.765432112345999e+07 | + 8.765432112345700e+07 | + 8.765432112345681e+07 | + 8.765432112345679e+07 | + 8.765432112345679e+07 | + +taos> select ROUND(current, id) from ts_4893.meters order by ts limit 10 + round(current, id) | +======================= + 11.0000000 | + 8.6000004 | + 9.8000002 | + 11.2329998 | + 10.7060003 | + 8.5080004 | + 9.5959997 | + 10.9619999 | + 11.2259998 | + 10.3369999 | + +taos> select ROUND(current, 1) from ts_4893.meters order by ts limit 10 + round(current, 1) | +======================= + 10.6999998 | + 8.6000004 | + 9.8000002 | + 11.1999998 | + 10.6999998 | + 8.5000000 | + 9.6000004 | + 11.0000000 | + 11.1999998 | + 10.3000002 | + +taos> select round(10.55, 3) + round(10.55, 3) | +============================ + 10.550000000000001 | + +taos> select round(10.55, 2) + round(10.55, 2) | +============================ + 10.550000000000001 | + +taos> select round(10.55, 1) + round(10.55, 1) | +============================ + 10.600000000000000 | + +taos> select round(10.55, 0) + round(10.55, 0) | +============================ + 11.000000000000000 | + +taos> select round(10.55) + round(10.55) | +============================ + 11.000000000000000 | + +taos> select round(10.55, -1) + round(10.55, -1) | +============================ + 10.000000000000000 | + +taos> select round(10.55, -10) + round(10.55, -10) | +============================ + 0.000000000000000 | + +taos> select round(-10.55, 1) + round(-10.55, 1) | +============================ + -10.600000000000000 | + +taos> select round(99, 1) + round(99, 1) | +======================== + 99 | + +taos> select round(current) from ts_4893.d0 order by ts limit 10 + round(current) | +======================= + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 10.0000000 | + +taos> select round(current) from ts_4893.meters order by ts limit 10 + round(current) | +======================= + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 9.0000000 | + 10.0000000 | + 11.0000000 | + 11.0000000 | + 10.0000000 | + +taos> select round(10, null) + round(10, null) | +======================== + NULL | + +taos> select round(null, 2) + round(null, 2) | +======================== + NULL | + +taos> select round(123.456, null) + round(123.456, null) | +============================ + NULL | + +taos> select round(100) + round(100) | +======================== + 100 | + +taos> select round(0.00123, -2) + round(0.00123, -2) | +============================ + 0.000000000000000 | + +taos> select round(123.456, 0) + round(123.456, 0) | +============================ + 123.000000000000000 | + +taos> select round(123.456, -5) + round(123.456, -5) | +============================ + 0.000000000000000 | + +taos> select round(12345.6789, -2) + round(12345.6789, -2) | +============================ + 12300.000000000000000 | + +taos> select round(-123.456, 2) + round(-123.456, 2) | +============================ + -123.459999999999994 | + +taos> select round(-1234.5678, 2) + round(-1234.5678, 2) | +============================ + -1234.569999999999936 | + +taos> select round(voltage, 0) from ts_4893.meters limit 1 + round(voltage, 0) | +==================== + 221 | + +taos> select round(current, 1) from ts_4893.meters limit 1 + round(current, 1) | +======================= + 10.6999998 | + +taos> select round(phase, 3) from ts_4893.meters limit 1 + round(phase, 3) | +======================= + 0.5090000 | + +taos> select round(voltage, -1) from ts_4893.meters limit 1 + round(voltage, -1) | +===================== + 220 | + +taos> select round(current * voltage, 2) from ts_4893.meters limit 1 + round(current * voltage, 2) | +============================== + 2.353650000000000e+03 | + +taos> select round(abs(voltage), 2) from ts_4893.meters limit 1 + round(abs(voltage), 2) | +========================= + 221 | + +taos> select round(pi() * phase, 3) from ts_4893.meters limit 1 + round(pi() * phase, 3) | +============================ + 1.599000000000000 | + +taos> select round(sqrt(voltage), 2) from ts_4893.meters limit 1 + round(sqrt(voltage), 2) | +============================ + 14.869999999999999 | + +taos> select round(log(current), 2) from ts_4893.meters limit 1 + round(log(current), 2) | +============================ + 2.370000000000000 | + diff --git a/tests/army/query/function/ans/sign.csv b/tests/army/query/function/ans/sign.csv index 4338e8f40d..e15b4a74c7 100644 --- a/tests/army/query/function/ans/sign.csv +++ b/tests/army/query/function/ans/sign.csv @@ -1,70 +1,275 @@ -0 -1 -1.000000000000000 -1 --1 --1.000000000000000 --1 -2.000000000000000 -0.000000000000000 -1.000000000000000 -1.000000000000000 -1 -1 -1 -1 -1 -2.000000000000000 -0.000000000000000 -2.000000000000000 -0.500000000000000 -2.000000000000000 -0.000000000000000 -1.000000000000000 -1.000000000000000 -1.000000000000000 -2.000000000000000 -3.000000000000000 -4.000000000000000 -5.000000000000000 -0.000000000000000 -2.000000000000000 -3.000000000000000 -4.000000000000000 -5.000000000000000 -1 -1 -1 -1.000000000000000 -1.000000000000000 -1 -0.000000000000000 -1.000000000000000 -1.000000000000000 -1.000000000000000 -1.000000000000000 -0 -1 -1 --1 --1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 + +taos> select SIGN(0) + sign(0) | +======================== + 0 | + +taos> select SIGN(1) + sign(1) | +======================== + 1 | + +taos> select SIGN(1.5) + sign(1.5) | +============================ + 1.000000000000000 | + +taos> select SIGN(100) + sign(100) | +======================== + 1 | + +taos> select SIGN(-1) + sign(-1) | +======================== + -1 | + +taos> select SIGN(-1.5) + sign(-1.5) | +============================ + -1.000000000000000 | + +taos> select SIGN(-100) + sign(-100) | +======================== + -1 | + +taos> select SIGN(1) + 1 + sign(1) + 1 | +============================ + 2.000000000000000 | + +taos> select SIGN(1) - 1 + sign(1) - 1 | +============================ + 0.000000000000000 | + +taos> select SIGN(1) * 1 + sign(1) * 1 | +============================ + 1.000000000000000 | + +taos> select SIGN(1) / 1 + sign(1) / 1 | +============================ + 1.000000000000000 | + +taos> select SIGN(1) from ts_4893.meters limit 5 + sign(1) | +======================== + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select SIGN(1) + 1 from ts_4893.meters limit 1 + sign(1) + 1 | +============================ + 2.000000000000000 | + +taos> select SIGN(1) - 1 from ts_4893.meters limit 1 + sign(1) - 1 | +============================ + 0.000000000000000 | + +taos> select SIGN(1) * 2 from ts_4893.meters limit 1 + sign(1) * 2 | +============================ + 2.000000000000000 | + +taos> select SIGN(1) / 2 from ts_4893.meters limit 1 + sign(1) / 2 | +============================ + 0.500000000000000 | + +taos> select SIGN(2) + SIGN(1) from ts_4893.meters limit 1 + sign(2) + sign(1) | +============================ + 2.000000000000000 | + +taos> select SIGN(2) - SIGN(1) from ts_4893.meters limit 1 + sign(2) - sign(1) | +============================ + 0.000000000000000 | + +taos> select SIGN(2) * SIGN(1) from ts_4893.meters limit 1 + sign(2) * sign(1) | +============================ + 1.000000000000000 | + +taos> select SIGN(2) / SIGN(1) from ts_4893.meters limit 1 + sign(2) / sign(1) | +============================ + 1.000000000000000 | + +taos> select SIGN(1) + id from ts_4893.meters order by ts limit 5 + sign(1) + id | +============================ + 1.000000000000000 | + 2.000000000000000 | + 3.000000000000000 | + 4.000000000000000 | + 5.000000000000000 | + +taos> select SIGN(id) + id from ts_4893.meters order by ts limit 5 + sign(id) + id | +============================ + 0.000000000000000 | + 2.000000000000000 | + 3.000000000000000 | + 4.000000000000000 | + 5.000000000000000 | + +taos> select SIGN(abs(10)) + sign(abs(10)) | +======================== + 1 | + +taos> select SIGN(abs(-10)) + sign(abs(-10)) | +======================== + 1 | + +taos> select abs(SIGN(10)) + abs(sign(10)) | +======================== + 1 | + +taos> select pow(SIGN(10), 2) + pow(sign(10), 2) | +============================ + 1.000000000000000 | + +taos> select sqrt(SIGN(10)) + sqrt(sign(10)) | +============================ + 1.000000000000000 | + +taos> select cast(SIGN(10) as int) + cast(sign(10) as int) | +======================== + 1 | + +taos> select SIGN(sqrt(id)) from ts_4893.meters order by ts limit 5 + sign(sqrt(id)) | +============================ + 0.000000000000000 | + 1.000000000000000 | + 1.000000000000000 | + 1.000000000000000 | + 1.000000000000000 | + +taos> select SIGN(SIGN(SIGN(SIGN(0)))) + sign(sign(sign(sign(0)))) | +============================ + 0 | + +taos> select sign(1) + sign(1) | +======================== + 1 | + +taos> select sign(10) + sign(10) | +======================== + 1 | + +taos> select sign(-1) + sign(-1) | +======================== + -1 | + +taos> select sign(-10) + sign(-10) | +======================== + -1 | + +taos> select sign(current) from ts_4893.d0 order by ts limit 10 + sign(current) | +======================= + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + +taos> select sign(current) from ts_4893.meters order by ts limit 10 + sign(current) | +======================= + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + 1.0000000 | + +taos> select sign(null) + sign(null) | +======================== + NULL | + +taos> select sign(25) + sign(25) | +======================== + 1 | + +taos> select sign(-10) + sign(-10) | +======================== + -1 | + +taos> select sign(0.1) + sign(0.1) | +============================ + 1.000000000000000 | + +taos> select sign(-0.1) + sign(-0.1) | +============================ + -1.000000000000000 | + +taos> select sign(current) from ts_4893.meters limit 1 + sign(current) | +======================= + 1.0000000 | + +taos> select sign(voltage) from ts_4893.meters limit 1 + sign(voltage) | +================ + 1 | + +taos> select sign(phase) from ts_4893.meters limit 1 + sign(phase) | +======================= + 1.0000000 | + +taos> select sign(abs(voltage)) from ts_4893.meters limit 1 + sign(abs(voltage)) | +===================== + 1 | + +taos> select sign(round(current)) from ts_4893.meters limit 1 + sign(round(current)) | +======================= + 1.0000000 | + +taos> select sign(sqrt(voltage)) from ts_4893.meters limit 1 + sign(sqrt(voltage)) | +============================ + 1.000000000000000 | + +taos> select sign(log(current + 1)) from ts_4893.meters limit 1 + sign(log(current + 1)) | +============================ + 1.000000000000000 | + diff --git a/tests/army/query/function/ans/stddev.csv b/tests/army/query/function/ans/stddev.csv index 48d54ae544..95af278013 100644 --- a/tests/army/query/function/ans/stddev.csv +++ b/tests/army/query/function/ans/stddev.csv @@ -1,37 +1,138 @@ -1.154339668872968 -0.838273408289688 -0.838639277789964 -0.839707477142887 -0.839707477142887 -0.840565842326812 -0.844574982206356 -0.846680761198646 -0.847012832740021 -0.847182714923875 -0.848223610563542 -2886.751331514371941 -4.609772228646444 -8.366600265340756 -8.366600265340756 -8.366600265340756 -8.366600265340756 -8.077747210701755 -8.366600265340756 -8.366600265340756 -8.366600265340756 -8.366600265340756 -2857.595142773027419 -4.609772228646444 -5.477225575051661 -8.077747210701755 -8.077747210701755 -8.077747210701755 -8.077747210701755 -8.077747210701755 -8.077747210701755 -8.077747210701755 -8.077747210701755 -2886.751331514371941 -2886.751331514371941 -1.154339668872967 -1.154339668872967 + +taos> select STDDEV(current) from ts_4893.meters + stddev(current) | +============================ + 1.154339668872967 | + +taos> select STDDEV(current) from ts_4893.meters interval(1d) order by 1 limit 10 + stddev(current) | +============================ + 0.838273408289689 | + 0.838639277789961 | + 0.839707477142884 | + 0.839707477142884 | + 0.840565842326814 | + 0.844574982206356 | + 0.846680761198646 | + 0.847012832740024 | + 0.847182714923872 | + 0.848223610563545 | + +taos> select STDDEV(id) from ts_4893.meters + stddev(id) | +============================ + 2886.751331514371941 | + +taos> select STDDEV(id) from ts_4893.meters interval(1d) limit 10 + stddev(id) | +============================ + 4.609772228646444 | + 8.366600265340756 | + 8.366600265340756 | + 8.366600265340756 | + 8.366600265340756 | + 8.077747210701755 | + 8.366600265340756 | + 8.366600265340756 | + 8.366600265340756 | + 8.366600265340756 | + +taos> select STDDEV(id) from ts_4893.meters where id > 100 + stddev(id) | +============================ + 2857.595142773027419 | + +taos> select STDDEV(id) from ts_4893.meters interval(1d) order by 1 limit 10 + stddev(id) | +============================ + 4.609772228646444 | + 5.477225575051661 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + 8.077747210701755 | + +taos> select stddev_pop(null) from ts_4893.meters + stddev_pop(null) | +============================ + NULL | + +taos> select stddev_pop(id) from ts_4893.d0 + stddev_pop(id) | +============================ + 2886.751331514371941 | + +taos> select stddev_pop(id) from ts_4893.meters + stddev_pop(id) | +============================ + 2886.751331514371941 | + +taos> select stddev_pop(current) from ts_4893.d0 + stddev_pop(current) | +============================ + 1.154339668872967 | + +taos> select stddev_pop(current) from ts_4893.meters + stddev_pop(current) | +============================ + 1.154339668872967 | + +taos> select stddev_pop(voltage) from ts_4893.meters + stddev_pop(voltage) | +============================ + 2.876459705957324 | + +taos> select stddev_pop(voltage) from ts_4893.meters where voltage is not null + stddev_pop(voltage) | +============================ + 2.876459705957324 | + +taos> select stddev_pop(phase) from ts_4893.meters + stddev_pop(phase) | +============================ + 0.288595458155823 | + +taos> select stddev_pop(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' + stddev_pop(phase) | +============================ + 0.288075357974611 | + +taos> select stddev_pop(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) + stddev_pop(total_voltage) | +============================ + 0.000000000000000 | + +taos> select round(stddev_pop(current), 2) from ts_4893.meters + round(stddev_pop(current), 2) | +================================ + 1.150000000000000e+00 | + +taos> select pow(stddev_pop(current), 2) from ts_4893.meters + pow(stddev_pop(current), 2) | +============================== + 1.332500071133751e+00 | + +taos> select log(stddev_pop(voltage) + 1) from ts_4893.meters + log(stddev_pop(voltage) + 1) | +=============================== + 1.354922290183882e+00 | + +taos> select groupid, stddev_pop(voltage) from ts_4893.meters group by groupid order by groupid + groupid | stddev_pop(voltage) | +====================================== + 1 | 2.876459705957324 | + +taos> select location, stddev_pop(current) from ts_4893.meters group by location order by location + location | stddev_pop(current) | +================================================= + beijing | 1.154339668872967 | + +taos> select location, stddev_pop(voltage) from ts_4893.meters group by location order by location + location | stddev_pop(voltage) | +================================================= + beijing | 2.876459705957324 | + diff --git a/tests/army/query/function/ans/substr.csv b/tests/army/query/function/ans/substr.csv index 72fd79c419..f56ea44ace 100644 --- a/tests/army/query/function/ans/substr.csv +++ b/tests/army/query/function/ans/substr.csv @@ -1,495 +1,1182 @@ -Hello.World! -Hello -Hello.World! -Hello.World! -Hello -Hello.World! -World! -World -World! -World! -World -World! -北京涛思数据科技有限公司,tdengine. -北京涛思数 -北京涛思数据科技有限公司,tdengin -北京涛思数据科技有限公司,tdengine. -北京涛思数 -北京涛思数据科技有限公司,tdengin -ngine. -ngine -ngine. -ngine. -ngine -ngine. -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九 -risio -五六七八九 -risio -一二三ab -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九 -risio -五六七八九 -risio -一二三ab -五六七八九十 -rision -五六七八九十 -rision -一二三abc -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九 -risio -risio -一二三ab -321三二 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九 -risio -risio -一二三ab -321三二 -五六七八九十 -rision -rision -一二三abc -321三二一 -一 -p -一 -p -a -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一 -p -p -a -一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -二 -ris -二三四五六七八 -rision -bc一二三abc一二三a -二 -ris -二三四五六七八 -rision -bc一二三abc一二三a -二三四五 -rision -rision -bc一二三abc一二三a -二三123321三二一 -二三四五 -rision -rision -bc一二三abc一二三a -二三123321三二一 -Hello.World! -Hello -Hello.World! -Hello.World! -Hello -Hello.World! -World! -World -World! -World! -World -World! -北京涛思数据科技有限公司,tdengine. -北京涛思数 -北京涛思数据科技有限公司,tdengin -北京涛思数据科技有限公司,tdengine. -北京涛思数 -北京涛思数据科技有限公司,tdengin -ngine. -ngine -ngine. -ngine. -ngine -ngine. -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九 -risio -五六七八九 -risio -一二三ab -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九十 -rision -五六七八九十 -rision -一二三abc -五六七八九 -risio -五六七八九 -risio -一二三ab -五六七八九十 -rision -五六七八九十 -rision -一二三abc -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九 -risio -risio -一二三ab -321三二 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九十 -rision -rision -一二三abc -321三二一 -五六七八九 -risio -risio -一二三ab -321三二 -五六七八九十 -rision -rision -一二三abc -321三二一 -一 -p -一 -p -a -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一二三四五 -prisi -一二三四五 -prisi -abc一二 -一二三四五六七八九十 -prision -一二三四五六七八九十 -prision -abc一二三abc一二三abc -一 -p -p -a -一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -一二三四五 -prisi -prisi -abc一二 -一二三12 -一二三四五六七八九十 -prision -prision -abc一二三abc一二三abc -一二三123321三二一 -二 -ris -二三四五六七八 -rision -bc一二三abc一二三a -二 -ris -二三四五六七八 -rision -bc一二三abc一二三a -二三四五 -rision -rision -bc一二三abc一二三a -二三123321三二一 -二三四五 -rision -rision -bc一二三abc一二三a -二三123321三二一 -dengine -e -tde -dengine -e -中国 -中国t -novel -perso -novel -plate -一二三四五 -updat -prisi -perso -prisi -plate -novel -perso -novel -plate -一二三四五 -updat -prisi -perso -prisi -plate -novel -一二三四五 -updat -prisi -novel -novel -again -一二三四五 -novel -again -novel -一二三四五 -updat -prisi -novel -novel -again -一二三四五 -novel -again + +taos> select SUBSTRING('Hello.World!', 1) + substring('Hello.World!', 1) | +=============================== + Hello.World! | + +taos> select SUBSTRING('Hello.World!', 1, 5) + substring('Hello.World!', 1, 5) | +================================== + Hello | + +taos> select SUBSTRING('Hello.World!', 1, 20) + substring('Hello.World!', 1, 20) | +=================================== + Hello.World! | + +taos> select SUBSTRING('Hello.World!' FROM 1) + substring('Hello.World!' from 1) | +=================================== + Hello.World! | + +taos> select SUBSTRING('Hello.World!' FROM 1 FOR 5) + substring('Hello.World!' from 1 for 5) | +========================================= + Hello | + +taos> select SUBSTRING('Hello.World!' FROM 1 FOR 20) + substring('Hello.World!' from 1 for 20) | +========================================== + Hello.World! | + +taos> select SUBSTRING('Hello.World!', -6) + substring('Hello.World!', -6) | +================================ + World! | + +taos> select SUBSTRING('Hello.World!', -6, 5) + substring('Hello.World!', -6, 5) | +=================================== + World | + +taos> select SUBSTRING('Hello.World!', -6, 20) + substring('Hello.World!', -6, 20) | +==================================== + World! | + +taos> select SUBSTRING('Hello.World!' FROM -6) + substring('Hello.World!' from -6) | +==================================== + World! | + +taos> select SUBSTRING('Hello.World!' FROM -6 FOR 5) + substring('Hello.World!' from -6 for 5) | +========================================== + World | + +taos> select SUBSTRING('Hello.World!' FROM -6 FOR 20) + substring('Hello.World!' from -6 for 20) | +=========================================== + World! | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1) + substring('北京涛思数据科技有限公司,tdengine.', 1) | +=================================================================== + 北京涛思数据科技有限公司,tdengine. | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 5) + substring('北京涛思数据科技有限公司,tdengine.', 1, | +=================================================================== + 北京涛思数 | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 20) + substring('北京涛思数据科技有限公司,tdengine.', 1, | +=================================================================== + 北京涛思数据科技有限公司,tdengin | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + 北京涛思数据科技有限公司,tdengine. | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + 北京涛思数 | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + 北京涛思数据科技有限公司,tdengin | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6) + substring('北京涛思数据科技有限公司,tdengine.', -6 | +=================================================================== + ngine. | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 5) + substring('北京涛思数据科技有限公司,tdengine.', -6 | +=================================================================== + ngine | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 20) + substring('北京涛思数据科技有限公司,tdengine.', -6 | +=================================================================== + ngine. | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + ngine. | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + ngine | + +taos> select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20) + substring('北京涛思数据科技有限公司,tdengine.' fro | +=================================================================== + ngine. | + +taos> select SUBSTRING(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, 1) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, 1, 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTRING(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, 1, 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from 1) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from 1 for 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTRING(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from 1 for 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, -6) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTRING(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, -6, 5) | +================================= + 五六七八九 | + risio | + 五六七八九 | + risio | + 一二三ab | + +taos> select SUBSTRING(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, -6, 20) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTRING(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from -6) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTRING(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from -6 for 5) | +================================= + 五六七八九 | + risio | + 五六七八九 | + risio | + 一二三ab | + +taos> select SUBSTRING(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from -6 for 20) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTRING(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, 1) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, 1, 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTRING(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, 1, 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from 1) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from 1 for 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTRING(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from 1 for 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, -6) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTRING(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, -6, 5) | +================================= + 五六七八九 | + risio | + risio | + 一二三ab | + 321三二 | + +taos> select SUBSTRING(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, -6, 20) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTRING(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from -6) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTRING(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from -6 for 5) | +================================= + 五六七八九 | + risio | + risio | + 一二三ab | + 321三二 | + +taos> select SUBSTRING(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from -6 for 20) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTRING(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, sign(id), 1) | +================================= + 一 | + p | + 一 | + p | + a | + +taos> select SUBSTRING(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, sign(id), 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTRING(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, sign(id), 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from sign(id)) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from sign(id) for 5) | +====================================== + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTRING(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from sign(id) for 20) | +======================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTRING(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, sign(id), 1) | +================================= + 一 | + p | + p | + a | + 一 | + +taos> select SUBSTRING(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, sign(id), 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTRING(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, sign(id), 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from sign(id)) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from sign(id) for 5) | +====================================== + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTRING(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from sign(id) for 20) | +======================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTRING(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1, 2, id) | +================================= + 二 | + ris | + 二三四五六七八 | + rision | + bc一二三abc一二三a | + +taos> select SUBSTRING(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substring(nch1 from 2 for id) | +================================= + 二 | + ris | + 二三四五六七八 | + rision | + bc一二三abc一二三a | + +taos> select SUBSTRING(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1, 2, id) | +================================= + 二三四五 | + rision | + rision | + bc一二三abc一二三a | + 二三123321三二一 | + +taos> select SUBSTRING(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substring(var1 from 2 for id) | +================================= + 二三四五 | + rision | + rision | + bc一二三abc一二三a | + 二三123321三二一 | + +taos> select SUBSTR('Hello.World!', 1) + substr('Hello.World!', 1) | +============================ + Hello.World! | + +taos> select SUBSTR('Hello.World!', 1, 5) + substr('Hello.World!', 1, 5) | +=============================== + Hello | + +taos> select SUBSTR('Hello.World!', 1, 20) + substr('Hello.World!', 1, 20) | +================================ + Hello.World! | + +taos> select SUBSTR('Hello.World!' FROM 1) + substr('Hello.World!' from 1) | +================================ + Hello.World! | + +taos> select SUBSTR('Hello.World!' FROM 1 FOR 5) + substr('Hello.World!' from 1 for 5) | +====================================== + Hello | + +taos> select SUBSTR('Hello.World!' FROM 1 FOR 20) + substr('Hello.World!' from 1 for 20) | +======================================= + Hello.World! | + +taos> select SUBSTR('Hello.World!', -6) + substr('Hello.World!', -6) | +============================= + World! | + +taos> select SUBSTR('Hello.World!', -6, 5) + substr('Hello.World!', -6, 5) | +================================ + World | + +taos> select SUBSTR('Hello.World!', -6, 20) + substr('Hello.World!', -6, 20) | +================================= + World! | + +taos> select SUBSTR('Hello.World!' FROM -6) + substr('Hello.World!' from -6) | +================================= + World! | + +taos> select SUBSTR('Hello.World!' FROM -6 FOR 5) + substr('Hello.World!' from -6 for 5) | +======================================= + World | + +taos> select SUBSTR('Hello.World!' FROM -6 FOR 20) + substr('Hello.World!' from -6 for 20) | +======================================== + World! | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1) + substr('北京涛思数据科技有限公司,tdengine.', 1) | +================================================================ + 北京涛思数据科技有限公司,tdengine. | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 5) + substr('北京涛思数据科技有限公司,tdengine.', 1, 5) | +=================================================================== + 北京涛思数 | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 20) + substr('北京涛思数据科技有限公司,tdengine.', 1, 20 | +=================================================================== + 北京涛思数据科技有限公司,tdengin | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1) + substr('北京涛思数据科技有限公司,tdengine.' from 1 | +=================================================================== + 北京涛思数据科技有限公司,tdengine. | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5) + substr('北京涛思数据科技有限公司,tdengine.' from 1 | +=================================================================== + 北京涛思数 | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20) + substr('北京涛思数据科技有限公司,tdengine.' from 1 | +=================================================================== + 北京涛思数据科技有限公司,tdengin | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6) + substr('北京涛思数据科技有限公司,tdengine.', -6) | +================================================================= + ngine. | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 5) + substr('北京涛思数据科技有限公司,tdengine.', -6, 5 | +=================================================================== + ngine | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 20) + substr('北京涛思数据科技有限公司,tdengine.', -6, 2 | +=================================================================== + ngine. | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6) + substr('北京涛思数据科技有限公司,tdengine.' from - | +=================================================================== + ngine. | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5) + substr('北京涛思数据科技有限公司,tdengine.' from - | +=================================================================== + ngine | + +taos> select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20) + substr('北京涛思数据科技有限公司,tdengine.' from - | +=================================================================== + ngine. | + +taos> select SUBSTR(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, 1) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, 1, 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTR(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, 1, 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from 1) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from 1 for 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTR(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from 1 for 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, -6) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTR(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, -6, 5) | +================================= + 五六七八九 | + risio | + 五六七八九 | + risio | + 一二三ab | + +taos> select SUBSTR(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, -6, 20) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTR(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from -6) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTR(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from -6 for 5) | +================================= + 五六七八九 | + risio | + 五六七八九 | + risio | + 一二三ab | + +taos> select SUBSTR(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from -6 for 20) | +================================= + 五六七八九十 | + rision | + 五六七八九十 | + rision | + 一二三abc | + +taos> select SUBSTR(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, 1) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, 1, 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTR(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, 1, 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from 1) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from 1 for 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTR(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from 1 for 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, -6) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTR(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, -6, 5) | +================================= + 五六七八九 | + risio | + risio | + 一二三ab | + 321三二 | + +taos> select SUBSTR(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, -6, 20) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTR(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from -6) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTR(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from -6 for 5) | +================================= + 五六七八九 | + risio | + risio | + 一二三ab | + 321三二 | + +taos> select SUBSTR(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from -6 for 20) | +================================= + 五六七八九十 | + rision | + rision | + 一二三abc | + 321三二一 | + +taos> select SUBSTR(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, sign(id), 1) | +================================= + 一 | + p | + 一 | + p | + a | + +taos> select SUBSTR(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, sign(id), 5) | +================================= + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTR(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, sign(id), 20) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from sign(id)) | +================================= + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from sign(id) for 5) | +=================================== + 一二三四五 | + prisi | + 一二三四五 | + prisi | + abc一二 | + +taos> select SUBSTR(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from sign(id) for 20) | +==================================== + 一二三四五六七八九十 | + prision | + 一二三四五六七八九十 | + prision | + abc一二三abc一二三abc | + +taos> select SUBSTR(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, sign(id), 1) | +================================= + 一 | + p | + p | + a | + 一 | + +taos> select SUBSTR(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, sign(id), 5) | +================================= + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTR(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, sign(id), 20) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from sign(id)) | +================================= + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from sign(id) for 5) | +=================================== + 一二三四五 | + prisi | + prisi | + abc一二 | + 一二三12 | + +taos> select SUBSTR(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from sign(id) for 20) | +==================================== + 一二三四五六七八九十 | + prision | + prision | + abc一二三abc一二三abc | + 一二三123321三二一 | + +taos> select SUBSTR(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1, 2, id) | +================================= + 二 | + ris | + 二三四五六七八 | + rision | + bc一二三abc一二三a | + +taos> select SUBSTR(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 + substr(nch1 from 2 for id) | +================================= + 二 | + ris | + 二三四五六七八 | + rision | + bc一二三abc一二三a | + +taos> select SUBSTR(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1, 2, id) | +================================= + 二三四五 | + rision | + rision | + bc一二三abc一二三a | + 二三123321三二一 | + +taos> select SUBSTR(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 + substr(var1 from 2 for id) | +================================= + 二三四五 | + rision | + rision | + bc一二三abc一二三a | + 二三123321三二一 | + +taos> select substring('tdengine', 2) + substring('tdengine', 2) | +=========================== + dengine | + +taos> select substring('tdengine', 8) + substring('tdengine', 8) | +=========================== + e | + +taos> select substring('tdengine', 1, 3) + substring('tdengine', 1, 3) | +============================== + tde | + +taos> select substring('tdengine', 2, 99) + substring('tdengine', 2, 99) | +=============================== + dengine | + +taos> select substring('tdengine', -1, 10) + substring('tdengine', -1, 10) | +================================ + e | + +taos> select substring('中国', 1, 3) + substring('中国', 1, 3) | +============================ + 中国 | + +taos> select substring('中国tdengine', 1, 3) + substring('中国tdengine', 1, 3) | +==================================== + 中国t | + +taos> select substring(var1, 1, 5) from ts_4893.d0 order by ts limit 10 + substring(var1, 1, 5) | +================================= + novel | + perso | + novel | + plate | + 一二三四五 | + updat | + prisi | + perso | + prisi | + plate | + +taos> select substring(var1, 1, 5) from ts_4893.meters order by ts limit 10 + substring(var1, 1, 5) | +================================= + novel | + perso | + novel | + plate | + 一二三四五 | + updat | + prisi | + perso | + prisi | + plate | + +taos> select substring(nch1, 1, 5) from ts_4893.d0 order by ts limit 10 + substring(nch1, 1, 5) | +================================= + novel | + 一二三四五 | + updat | + prisi | + novel | + novel | + again | + 一二三四五 | + novel | + again | + +taos> select substring(nch1, 1, 5) from ts_4893.meters order by ts limit 10 + substring(nch1, 1, 5) | +================================= + novel | + 一二三四五 | + updat | + prisi | + novel | + novel | + again | + 一二三四五 | + novel | + again | + +taos> select substring(null, 1, 3) + substring(null, 1, 3) | +======================== + NULL | + +taos> select substring('tdengine', null, 3) + substring('tdengine', null, 3) | +================================= + NULL | + +taos> select substring('tdengine', 0) + substring('tdengine', 0) | +=========================== + | + +taos> select substring('tdengine', 10) + substring('tdengine', 10) | +============================ + | + +taos> select substring('tdengine', 1, null) + substring('tdengine', 1, null) | +================================= + NULL | + +taos> select substring('tdengine', 1, 0) + substring('tdengine', 1, 0) | +============================== + | + +taos> select substring('tdengine', 1, -1) + substring('tdengine', 1, -1) | +=============================== + | + +taos> select substr(null, 1, 3) + substr(null, 1, 3) | +===================== + NULL | + +taos> select substr('Hello', 1, 3) + substr('Hello', 1, 3) | +======================== + Hel | + +taos> select substr('', 1, 5) + substr('', 1, 5) | +=================== + | + +taos> select substr('ABCDE', 0, 3) + substr('ABCDE', 0, 3) | +======================== + | + +taos> select substr('ABCDEFG', -3, 2) + substr('ABCDEFG', -3, 2) | +=========================== + EF | + +taos> select substr('HelloWorld', 2, 5) + substr('HelloWorld', 2, 5) | +============================= + elloW | + +taos> select substr('1234567890', -5, 5) + substr('1234567890', -5, 5) | +============================== + 67890 | + +taos> select substr('!@#$%^&*()', 2, 4) + substr('!@#$%^&*()', 2, 4) | +============================= + @#$% | + +taos> select substr('你好世界', 3, 2) + substr('你好世界', 3, 2) | +=============================== + 世界 | + +taos> select substr('ABCDEFG', 10, 5) + substr('ABCDEFG', 10, 5) | +=========================== + | + +taos> select substr('ABCDEFG', -1, 3) + substr('ABCDEFG', -1, 3) | +=========================== + G | + +taos> select substr('1234567890', -15, 5) + substr('1234567890', -15, 5) | +=============================== + 12345 | + +taos> select substr(concat('Hello', 'World'), 1, 5) + substr(concat('Hello', 'World'), 1, 5) | +========================================= + Hello | + +taos> select substr('HelloWorld', 1, length('Hello')) + substr('HelloWorld', 1, length('Hello')) | +=========================================== + Hello | + +taos> select substr(upper('helloworld'), 2, 4) + substr(upper('helloworld'), 2, 4) | +==================================== + ELLO | + +taos> select substr(trim(' HelloWorld '), 1, 5) + substr(trim(' HelloWorld '), 1, 5) | +======================================= + Hello | + +taos> select name, substr(name, 1, 3) from ts_4893.meters limit 1 + name | substr(name, 1, 3) | +================================================================== + lili | lil | + +taos> select var1, substr(var1, 1, 6) from ts_4893.meters limit 1 + var1 | substr(var1, 1, 6) | +================================================================== + novel | novel | + +taos> select nch1, substr(nch1, 2, 4) from ts_4893.meters limit 1 + nch1 | substr(nch1, 2, 4) | +================================================================== + novel | ovel | + diff --git a/tests/army/query/function/ans/substr_idx.csv b/tests/army/query/function/ans/substr_idx.csv index ff64b770c4..ac0a1ef274 100644 --- a/tests/army/query/function/ans/substr_idx.csv +++ b/tests/army/query/function/ans/substr_idx.csv @@ -1,295 +1,798 @@ -1abcd;2abcd -3abcd;4abcd -www. -data.com -www -com -taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -www.taosdata.com -taosdata.com -.taosdata.com -aa -aaaa -aaaaaa -aaaaaaaaa1 -aaa -aaaaaa -aaaaaaaaa1 -aaaa -aaaaaaaaa -1 -1 -aa1 -aaaa1 -aaaaaa1 -aaaaaaaaa1 -1 -aaa1 -aaaaaa1 -aaaaaaaaa1 -the hill - the hill - the hill -hill - the hill -hill -the hill - the hill -the the hill -of the the hill -.the hill -the.the hill - hill -"the king of " -"the king of the " -nov -a -一二三a -一二三 -p -novel -一二三四五六七八九十 -update -prision -novel -novel -c一二三abc -一二三abc -一二三四五六七八九十 -person -novel -一二三四五六七八九十 -update -prision -novel -nov -plat -一二三 -ab -一二三a -person -novel -一二三四五六七八九十 -update -prision -novel -plate -一二三abc -一二三123321三二一 -一二三abc -person -novel -一二三四五六七八九十 -update -prision -nov -nov -ab -g -一二三 -一二三四五六七八九十 -update -prision -novel -novel -novel -novel -一二三abc -一二三123321三二一 -一二三abc -一二三四五六七八九十 -update -prision -novel -novel -一二 -a -nov -up -p -novel -person -novel -plate -一二三四五六七八九十 -一二三abc -c一二三abc -bc一二三abc -novel -update -novel -person -novel -plate -一二三四五六七八九十 -a一二三a一二三bbc -a一二三a一二三bb -a -a -a一二三a一二三bb -p -fp -二三bbcfp -bbcfp -fp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二 -a一二三a一二三 -a一二三a一二三 -a一二三a一二三 -a -一二三bbcfp -cfp -cfp -cfp -二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -a一二三a一二三bbcfp -一二三 -一二三 -一二三 -一二三 -一二三 -321三二一 -321三二一 -321三二一 -321三二一 -321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -一二三 -一二三 -一二三 -一二三 -一二三 -321三二一 -321三二一 -321三二一 -321三二一 -321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -一二三123321三二一 -www.taosdata -taosdata.com -中国.科学 -北京。涛思 -novel -一二三四五六七八九十 -update -prision -novel -novel -ag -一二三四五六七八九十 -novel -ag -novel -一二三四五六七八九十 -update -prision -novel -novel -ag -一二三四五六七八九十 -novel -ag -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate + +taos> select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) + substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) | +===================================================== + 1abcd;2abcd | + +taos> select substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2) + substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2) | +====================================================== + 3abcd;4abcd | + +taos> select substring_index('www.taosdata.com','taos',1) + substring_index('www.taosdata.com','taos',1) | +=============================================== + www. | + +taos> select substring_index('www.taosdata.com','taos',-1) + substring_index('www.taosdata.com','taos',-1) | +================================================ + data.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 1) + substring_index('www.taosdata.com', '.', 1) | +============================================== + www | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -1) + substring_index('www.taosdata.com', '.', -1) | +=============================================== + com | + +taos> select substring_index('www.taosdata.com','.',-2) + substring_index('www.taosdata.com','.',-2) | +============================================= + taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 100) + substring_index('www.taosdata.com', '.', 100) | +================================================ + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -100) + substring_index('www.taosdata.com', '.', -100) | +================================================= + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483647) + substring_index('www.taosdata.com', '.', 2147483647) | +======================================================= + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483647) + substring_index('www.taosdata.com', '.', -2147483647) | +======================================================== + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483648) + substring_index('www.taosdata.com', '.', 2147483648) | +======================================================= + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483648) + substring_index('www.taosdata.com', '.', -2147483648) | +======================================================== + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483649) + substring_index('www.taosdata.com', '.', 2147483649) | +======================================================= + www.taosdata.com | + +taos> SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483649) + substring_index('www.taosdata.com', '.', -2147483649) | +======================================================== + www.taosdata.com | + +taos> select substring_index('.taosdata.com','.',-2) + substring_index('.taosdata.com','.',-2) | +========================================== + taosdata.com | + +taos> select substring_index('.taosdata.com','.tcx',-1) + substring_index('.taosdata.com','.tcx',-1) | +============================================= + .taosdata.com | + +taos> select substring_index('aaaaaaaaa1','aa',2) + substring_index('aaaaaaaaa1','aa',2) | +======================================= + aa | + +taos> select substring_index('aaaaaaaaa1','aa',3) + substring_index('aaaaaaaaa1','aa',3) | +======================================= + aaaa | + +taos> select substring_index('aaaaaaaaa1','aa',4) + substring_index('aaaaaaaaa1','aa',4) | +======================================= + aaaaaa | + +taos> select substring_index('aaaaaaaaa1','aa',5) + substring_index('aaaaaaaaa1','aa',5) | +======================================= + aaaaaaaaa1 | + +taos> select substring_index('aaaaaaaaa1','aaa',2) + substring_index('aaaaaaaaa1','aaa',2) | +======================================== + aaa | + +taos> select substring_index('aaaaaaaaa1','aaa',3) + substring_index('aaaaaaaaa1','aaa',3) | +======================================== + aaaaaa | + +taos> select substring_index('aaaaaaaaa1','aaa',4) + substring_index('aaaaaaaaa1','aaa',4) | +======================================== + aaaaaaaaa1 | + +taos> select substring_index('aaaaaaaaa1','aaaa',2) + substring_index('aaaaaaaaa1','aaaa',2) | +========================================= + aaaa | + +taos> select substring_index('aaaaaaaaa1','1',1) + substring_index('aaaaaaaaa1','1',1) | +====================================== + aaaaaaaaa | + +taos> select substring_index('aaaaaaaaa1','a',-1) + substring_index('aaaaaaaaa1','a',-1) | +======================================= + 1 | + +taos> select substring_index('aaaaaaaaa1','aa',-1) + substring_index('aaaaaaaaa1','aa',-1) | +======================================== + 1 | + +taos> select substring_index('aaaaaaaaa1','aa',-2) + substring_index('aaaaaaaaa1','aa',-2) | +======================================== + aa1 | + +taos> select substring_index('aaaaaaaaa1','aa',-3) + substring_index('aaaaaaaaa1','aa',-3) | +======================================== + aaaa1 | + +taos> select substring_index('aaaaaaaaa1','aa',-4) + substring_index('aaaaaaaaa1','aa',-4) | +======================================== + aaaaaa1 | + +taos> select substring_index('aaaaaaaaa1','aa',-5) + substring_index('aaaaaaaaa1','aa',-5) | +======================================== + aaaaaaaaa1 | + +taos> select substring_index('aaaaaaaaa1','aaa',-1) + substring_index('aaaaaaaaa1','aaa',-1) | +========================================= + 1 | + +taos> select substring_index('aaaaaaaaa1','aaa',-2) + substring_index('aaaaaaaaa1','aaa',-2) | +========================================= + aaa1 | + +taos> select substring_index('aaaaaaaaa1','aaa',-3) + substring_index('aaaaaaaaa1','aaa',-3) | +========================================= + aaaaaa1 | + +taos> select substring_index('aaaaaaaaa1','aaa',-4) + substring_index('aaaaaaaaa1','aaa',-4) | +========================================= + aaaaaaaaa1 | + +taos> select substring_index('the king of thethe hill','the',-2) + substring_index('the king of thethe hill','the',-2) | +====================================================== + the hill | + +taos> select substring_index('the king of the the hill','the',-2) + substring_index('the king of the the hill','the',-2) | +======================================================= + the hill | + +taos> select substring_index('the king of the the hill','the',-2) + substring_index('the king of the the hill','the',-2) | +======================================================== + the hill | + +taos> select substring_index('the king of the the hill',' the ',-1) + substring_index('the king of the the hill',' the ',-1) | +========================================================== + hill | + +taos> select substring_index('the king of the the hill',' the ',-2) + substring_index('the king of the the hill',' the ',-2) | +========================================================== + the hill | + +taos> select substring_index('the king of the the hill',' ',-1) + substring_index('the king of the the hill',' ',-1) | +====================================================== + hill | + +taos> select substring_index('the king of the the hill',' ',-2) + substring_index('the king of the the hill',' ',-2) | +====================================================== + the hill | + +taos> select substring_index('the king of the the hill',' ',-3) + substring_index('the king of the the hill',' ',-3) | +====================================================== + the hill | + +taos> select substring_index('the king of the the hill',' ',-4) + substring_index('the king of the the hill',' ',-4) | +====================================================== + the the hill | + +taos> select substring_index('the king of the the hill',' ',-5) + substring_index('the king of the the hill',' ',-5) | +====================================================== + of the the hill | + +taos> select substring_index('the king of the.the hill','the',-2) + substring_index('the king of the.the hill','the',-2) | +======================================================= + .the hill | + +taos> select substring_index('the king of thethethe.the hill','the',-3) + substring_index('the king of thethethe.the hill','the',-3) | +============================================================= + the.the hill | + +taos> select substring_index('the king of thethethe.the hill','the',-1) + substring_index('the king of thethethe.the hill','the',-1) | +============================================================= + hill | + +taos> select substring_index('the king of the the hill','the',2) + substring_index('the king of the the hill','the',2) | +====================================================== + the king of | + +taos> select substring_index('the king of the the hill','the',3) + substring_index('the king of the the hill','the',3) | +====================================================== + the king of the | + +taos> select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) > 1 order by ts limit 5 + substring_index(nch1, nch2, 1) | +================================= + nov | + a | + 一二三a | + 一二三 | + p | + +taos> select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + substring_index(nch1, nch2, 1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 + substring_index(nch1, nch2, -2) | +================================== + novel | + c一二三abc | + 一二三abc | + 一二三四五六七八九十 | + person | + +taos> select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + substring_index(nch1, nch2, -2) | +================================== + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) > 1 order by ts limit 5 + substring_index(var1, var2, 1) | +================================= + nov | + plat | + 一二三 | + ab | + 一二三a | + +taos> select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + substring_index(var1, var2, 1) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 + substring_index(var1, var2, -2) | +================================== + novel | + plate | + 一二三abc | + 一二三123321三二一 | + 一二三abc | + +taos> select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + substring_index(var1, var2, -2) | +================================== + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) > 1 order by ts limit 5 + substring_index(nch1, var2, 1) | +================================= + nov | + nov | + ab | + g | + 一二三 | + +taos> select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + substring_index(nch1, var2, 1) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 + substring_index(nch1, var2, -2) | +================================== + novel | + novel | + 一二三abc | + 一二三123321三二一 | + 一二三abc | + +taos> select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + substring_index(nch1, var2, -2) | +================================== + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) > 1 order by ts limit 5 + substring_index(var1, nch2, 1) | +================================= + 一二 | + a | + nov | + up | + p | + +taos> select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + substring_index(var1, nch2, 1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 + substring_index(var1, nch2, -2) | +================================== + 一二三abc | + c一二三abc | + bc一二三abc | + novel | + update | + +taos> select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + substring_index(var1, nch2, -2) | +================================== + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select substring_index('a一二三a一二三bbcfp', nch2, 1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', nch2, 1) | +======================================================== + a一二三a一二三bbc | + a一二三a一二三bb | + a | + a | + a一二三a一二三bb | + +taos> select substring_index('a一二三a一二三bbcfp', nch2, -1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', nch2, -1) | +========================================================= + p | + fp | + 二三bbcfp | + bbcfp | + fp | + +taos> select substring_index('a一二三a一二三bbcfp', nch2, cast(id + 1 as int)) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', nch2, cast(id + 1 a | +=================================================================== + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + +taos> select substring_index('a一二三a一二三bbcfp', var2, 1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', var2, 1) | +======================================================== + a一二 | + a一二三a一二三 | + a一二三a一二三 | + a一二三a一二三 | + a | + +taos> select substring_index('a一二三a一二三bbcfp', var2, -1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', var2, -1) | +========================================================= + 一二三bbcfp | + cfp | + cfp | + cfp | + 二三bbcfp | + +taos> select substring_index('a一二三a一二三bbcfp', var2, cast(id + 1 as int)) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5 + substring_index('a一二三a一二三bbcfp', var2, cast(id + 1 a | +=================================================================== + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + a一二三a一二三bbcfp | + +taos> select substring_index(nch1, '123', 1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 + substring_index(nch1, '123', 1) | +================================== + 一二三 | + 一二三 | + 一二三 | + 一二三 | + 一二三 | + +taos> select substring_index(nch1, '123', -1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 + substring_index(nch1, '123', -1) | +=================================== + 321三二一 | + 321三二一 | + 321三二一 | + 321三二一 | + 321三二一 | + +taos> select substring_index(nch1, '123', id) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 + substring_index(nch1, '123', id) | +=================================== + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + +taos> select substring_index(var1, '123', 1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 + substring_index(var1, '123', 1) | +================================== + 一二三 | + 一二三 | + 一二三 | + 一二三 | + 一二三 | + +taos> select substring_index(var1, '123', -1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 + substring_index(var1, '123', -1) | +=================================== + 321三二一 | + 321三二一 | + 321三二一 | + 321三二一 | + 321三二一 | + +taos> select substring_index(var1, '123', id) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 + substring_index(var1, '123', id) | +=================================== + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + 一二三123321三二一 | + +taos> select substring_index('www.taosdata.com', '.', 2) + substring_index('www.taosdata.com', '.', 2) | +============================================== + www.taosdata | + +taos> select substring_index('www.taosdata.com', '.', -2) + substring_index('www.taosdata.com', '.', -2) | +=============================================== + taosdata.com | + +taos> select substring_index('中国.科学.www.taosdata.com', '.', 2) + substring_index('中国.科学.www.taosdata.com', '.', 2) | +============================================================ + 中国.科学 | + +taos> select substring_index('北京。涛思。数据。科技', '。', 2) + substring_index('北京。涛思。数据。科技', '。', 2) | +================================================================= + 北京。涛思 | + +taos> select substring_index(nch1, 'a', 2) from ts_4893.d0 order by ts limit 10 + substring_index(nch1, 'a', 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + ag | + 一二三四五六七八九十 | + novel | + ag | + +taos> select substring_index(nch1, 'a', 2) from ts_4893.meters order by ts limit 10 + substring_index(nch1, 'a', 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + ag | + 一二三四五六七八九十 | + novel | + ag | + +taos> select substring_index(nch1, nch2, 2) from ts_4893.d0 order by ts limit 10 + substring_index(nch1, nch2, 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select substring_index(nch1, nch2, 2) from ts_4893.meters order by ts limit 10 + substring_index(nch1, nch2, 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select substring_index(nch1, var2, 2) from ts_4893.d0 order by ts limit 10 + substring_index(nch1, var2, 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select substring_index(nch1, var2, 2) from ts_4893.meters order by ts limit 10 + substring_index(nch1, var2, 2) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select substring_index(var1, nch2, 2) from ts_4893.d0 order by ts limit 10 + substring_index(var1, nch2, 2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select substring_index(var1, nch2, 2) from ts_4893.meters order by ts limit 10 + substring_index(var1, nch2, 2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select substring_index(var1, var2, 2) from ts_4893.d0 order by ts limit 10 + substring_index(var1, var2, 2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select substring_index(var1, var2, 2) from ts_4893.meters order by ts limit 10 + substring_index(var1, var2, 2) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select substring_index(null, '.', 2) + substring_index(null, '.', 2) | +================================ + NULL | + +taos> select substring_index('www.taosdata.com', null, 2) + substring_index('www.taosdata.com', null, 2) | +=============================================== + NULL | + +taos> select substring_index('www.taosdata.com', '.', 0) + substring_index('www.taosdata.com', '.', 0) | +============================================== + | + +taos> select substring_index('www.taosdata.com', '.', null) + substring_index('www.taosdata.com', '.', null) | +================================================= + NULL | + +taos> select substring_index('a.b.c', '.', 1) + substring_index('a.b.c', '.', 1) | +=================================== + a | + +taos> select substring_index('a.b.c', '.', 2) + substring_index('a.b.c', '.', 2) | +=================================== + a.b | + +taos> select substring_index('a.b.c', '.', -1) + substring_index('a.b.c', '.', -1) | +==================================== + c | + +taos> select substring_index('', '.', 1) + substring_index('', '.', 1) | +============================== + | + +taos> select substring_index('apple.orange.banana', '.', 2) + substring_index('apple.orange.banana', '.', 2) | +================================================= + apple.orange | + +taos> select substring_index('192.168.1.1', '.', 3) + substring_index('192.168.1.1', '.', 3) | +========================================= + 192.168.1 | + +taos> select substring_index('abc@xyz.com', '.', 5) + substring_index('abc@xyz.com', '.', 5) | +========================================= + abc@xyz.com | + +taos> select substring_index('123456789', '.', 1) + substring_index('123456789', '.', 1) | +======================================= + 123456789 | + +taos> select substring_index('abcdef', ' ', 2) + substring_index('abcdef', ' ', 2) | +==================================== + abcdef | + +taos> select substring_index('ABCDEFG', '-', -1) + substring_index('ABCDEFG', '-', -1) | +====================================== + ABCDEFG | + +taos> select substring_index('apple', '.', -3) + substring_index('apple', '.', -3) | +==================================== + apple | + +taos> select substring_index(concat('apple', '.', 'orange', '.', 'banana'), '.', 2) + substring_index(concat('apple', '.', 'orange', '.', 'banana'), ' | +=================================================================== + apple.orange | + +taos> select substring_index('apple.orange.banana', '.', length('apple')) + substring_index('apple.orange.banana', '.', length('apple')) | +=============================================================== + apple.orange.banana | + +taos> select substring_index(upper('apple.orange.banana'), '.', 2) + substring_index(upper('apple.orange.banana'), '.', 2) | +======================================================== + APPLE.ORANGE | + +taos> select substring_index(trim(' apple.orange.banana '), '.', 2) + substring_index(trim(' apple.orange.banana '), '.', 2) | +=========================================================== + apple.orange | + +taos> select substring_index(concat('apple', '.', 'orange', '.', 'banana'), '.', 2) + substring_index(concat('apple', '.', 'orange', '.', 'banana'), ' | +=================================================================== + apple.orange | + +taos> select substring_index('apple.orange.banana', '.', length('apple')) + substring_index('apple.orange.banana', '.', length('apple')) | +=============================================================== + apple.orange.banana | + +taos> select substring_index(upper('apple.orange.banana'), '.', 2) + substring_index(upper('apple.orange.banana'), '.', 2) | +======================================================== + APPLE.ORANGE | + +taos> select substring_index(trim(' apple.orange.banana '), '.', 2) + substring_index(trim(' apple.orange.banana '), '.', 2) | +=========================================================== + apple.orange | + +taos> select name, substring_index(name, ' ', 1) from ts_4893.meters limit 1 + name | substring_index(name, ' ', 1) | +================================================================== + lili | lili | + +taos> select var1, substring_index(var1, '-', -1) from ts_4893.meters limit 1 + var1 | substring_index(var1, '-', -1) | +================================================================== + novel | novel | + +taos> select nch1, substring_index(nch1, ',', 3) from ts_4893.meters limit 1 + nch1 | substring_index(nch1, ',', 3) | +================================================================== + novel | novel | + diff --git a/tests/army/query/function/ans/timediff.csv b/tests/army/query/function/ans/timediff.csv index c819be1411..39de484454 100644 --- a/tests/army/query/function/ans/timediff.csv +++ b/tests/army/query/function/ans/timediff.csv @@ -1,334 +1,785 @@ --1000 -1000 --1 -1 --166666 -166666 --2777 -2777 --115 -115 --16 -16 --691207000 -691207000 --691207 -691207 --11520 -11520 --192 -192 --8 -8 --1 -1 --691200000 -691200000 --691200 -691200 --11520 -11520 --192 -192 --8 -8 --1 -1 --691200000 -691200000 --691200 -691200 --11520 -11520 --192 -192 --8 -8 --1 -1 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 --225095657000 --225092657000 --225089657000 --225086657000 --225083657000 --225080657000 --225077657000 --225074657000 --225071657000 --225068657000 -225095657000 -225092657000 -225089657000 -225086657000 -225083657000 -225080657000 -225077657000 -225074657000 -225071657000 -225068657000 --225095657 --225092657 --225089657 --225086657 --225083657 --225080657 --225077657 --225074657 --225071657 --225068657 -225095657 -225092657 -225089657 -225086657 -225083657 -225080657 -225077657 -225074657 -225071657 -225068657 --3751594 --3751544 --3751494 --3751444 --3751394 --3751344 --3751294 --3751244 --3751194 --3751144 -3751594 -3751544 -3751494 -3751444 -3751394 -3751344 -3751294 -3751244 -3751194 -3751144 --62526 --62525 --62524 --62524 --62523 --62522 --62521 --62520 --62519 --62519 -62526 -62525 -62524 -62524 -62523 -62522 -62521 -62520 -62519 -62519 --2605 --2605 --2605 --2605 --2605 --2605 --2605 --2605 --2604 --2604 -2605 -2605 -2605 -2605 -2605 -2605 -2605 -2605 -2604 -2604 --372 --372 --372 --372 --372 --372 --372 --372 --372 --372 -372 -372 -372 -372 -372 -372 -372 -372 -372 -372 --225095657000 --225092657000 --225089657000 --225086657000 --225083657000 --225080657000 --225077657000 --225074657000 --225071657000 --225068657000 -225095657000 -225092657000 -225089657000 -225086657000 -225083657000 -225080657000 -225077657000 -225074657000 -225071657000 -225068657000 --225095657 --225092657 --225089657 --225086657 --225083657 --225080657 --225077657 --225074657 --225071657 --225068657 -225095657 -225092657 -225089657 -225086657 -225083657 -225080657 -225077657 -225074657 -225071657 -225068657 --3751594 --3751544 --3751494 --3751444 --3751394 --3751344 --3751294 --3751244 --3751194 --3751144 -3751594 -3751544 -3751494 -3751444 -3751394 -3751344 -3751294 -3751244 -3751194 -3751144 --62526 --62525 --62524 --62524 --62523 --62522 --62521 --62520 --62519 --62519 -62526 -62525 -62524 -62524 -62523 -62522 -62521 -62520 -62519 -62519 --2605 --2605 --2605 --2605 --2605 --2605 --2605 --2605 --2604 --2604 -2605 -2605 -2605 -2605 -2605 -2605 -2605 -2605 -2604 -2604 --372 --372 --372 --372 --372 --372 --372 --372 --372 --372 -372 -372 -372 -372 -372 -372 -372 -372 -372 -372 --10 -31536000 -3000 -43200 -720 -30 -4 -2592000000 -2592000 -2592000 -60 -60 -79774389 --79774389 -79774389 --79774389 --220769589123 --220766589123 --220763589123 --220760589123 --220757589123 --220754589123 --220751589123 --220748589123 --220745589123 --220742589123 --220769589123 --220766589123 --220763589123 --220760589123 --220757589123 --220754589123 --220751589123 --220748589123 --220745589123 --220742589123 + +taos> select TIMEDIFF(1,2) + timediff(1,2) | +======================== + -1000 | + +taos> select TIMEDIFF(2,1) + timediff(2,1) | +======================== + 1000 | + +taos> select TIMEDIFF(1,2,1s) + timediff(1,2,1s) | +======================== + -1 | + +taos> select TIMEDIFF(2,1,1s) + timediff(2,1,1s) | +======================== + 1 | + +taos> select TIMEDIFF(1,10000000,1m) + timediff(1,10000000,1m) | +========================== + -166666 | + +taos> select TIMEDIFF(10000000,1,1m) + timediff(10000000,1,1m) | +========================== + 166666 | + +taos> select TIMEDIFF(1,10000000,1h) + timediff(1,10000000,1h) | +========================== + -2777 | + +taos> select TIMEDIFF(10000000,1,1h) + timediff(10000000,1,1h) | +========================== + 2777 | + +taos> select TIMEDIFF(1,10000000,1d) + timediff(1,10000000,1d) | +========================== + -115 | + +taos> select TIMEDIFF(10000000,1,1d) + timediff(10000000,1,1d) | +========================== + 115 | + +taos> select TIMEDIFF(1,10000000,1w) + timediff(1,10000000,1w) | +========================== + -16 | + +taos> select TIMEDIFF(10000000,1,1w) + timediff(10000000,1,1w) | +========================== + 16 | + +taos> select TIMEDIFF(1724404450,1725095657) + timediff(1724404450,1725095657) | +================================== + -691207000 | + +taos> select TIMEDIFF(1725095657,1724404450) + timediff(1725095657,1724404450) | +================================== + 691207000 | + +taos> select TIMEDIFF(1724404450,1725095657,1s) + timediff(1724404450,1725095657,1s) | +===================================== + -691207 | + +taos> select TIMEDIFF(1725095657,1724404450,1s) + timediff(1725095657,1724404450,1s) | +===================================== + 691207 | + +taos> select TIMEDIFF(1724404450,1725095657,1m) + timediff(1724404450,1725095657,1m) | +===================================== + -11520 | + +taos> select TIMEDIFF(1725095657,1724404450,1m) + timediff(1725095657,1724404450,1m) | +===================================== + 11520 | + +taos> select TIMEDIFF(1724404450,1725095657,1h) + timediff(1724404450,1725095657,1h) | +===================================== + -192 | + +taos> select TIMEDIFF(1725095657,1724404450,1h) + timediff(1725095657,1724404450,1h) | +===================================== + 192 | + +taos> select TIMEDIFF(1724404450,1725095657,1d) + timediff(1724404450,1725095657,1d) | +===================================== + -8 | + +taos> select TIMEDIFF(1725095657,1724404450,1d) + timediff(1725095657,1724404450,1d) | +===================================== + 8 | + +taos> select TIMEDIFF(1724404450,1725095657,1w) + timediff(1724404450,1725095657,1w) | +===================================== + -1 | + +taos> select TIMEDIFF(1725095657,1724404450,1w) + timediff(1725095657,1724404450,1w) | +===================================== + 1 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17') + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17') | +========================================================= + -691200000 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17') + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17') | +========================================================= + 691200000 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1s) + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1s) | +============================================================= + -691200 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1s) + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1s) | +============================================================= + 691200 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1m) + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1m) | +============================================================= + -11520 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1m) + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1m) | +============================================================= + 11520 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1h) + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1h) | +============================================================= + -192 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1h) + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1h) | +============================================================= + 192 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1d) + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1d) | +============================================================= + -8 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1d) + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1d) | +============================================================= + 8 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1w) + timediff('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1w) | +============================================================= + -1 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1w) + timediff('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1w) | +============================================================= + 1 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657) + timediff('2024-08-23 17:14:17', 1725095657) | +============================================== + -691200000 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17') + timediff(1725095657, '2024-08-23 17:14:17') | +============================================== + 691200000 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1s) + timediff('2024-08-23 17:14:17', 1725095657, 1s) | +================================================== + -691200 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1s) + timediff(1725095657, '2024-08-23 17:14:17', 1s) | +================================================== + 691200 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1m) + timediff('2024-08-23 17:14:17', 1725095657, 1m) | +================================================== + -11520 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1m) + timediff(1725095657, '2024-08-23 17:14:17', 1m) | +================================================== + 11520 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1h) + timediff('2024-08-23 17:14:17', 1725095657, 1h) | +================================================== + -192 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1h) + timediff(1725095657, '2024-08-23 17:14:17', 1h) | +================================================== + 192 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1d) + timediff('2024-08-23 17:14:17', 1725095657, 1d) | +================================================== + -8 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1d) + timediff(1725095657, '2024-08-23 17:14:17', 1d) | +================================================== + 8 | + +taos> select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1w) + timediff('2024-08-23 17:14:17', 1725095657, 1w) | +================================================== + -1 | + +taos> select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1w) + timediff(1725095657, '2024-08-23 17:14:17', 1w) | +================================================== + 1 | + +taos> select TIMEDIFF(ts, ts) from ts_4893.meters order by ts limit 10 + timediff(ts, ts) | +======================== + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + 0 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17') from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17') | +====================================== + -225095657000 | + -225092657000 | + -225089657000 | + -225086657000 | + -225083657000 | + -225080657000 | + -225077657000 | + -225074657000 | + -225071657000 | + -225068657000 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts) | +====================================== + 225095657000 | + 225092657000 | + 225089657000 | + 225086657000 | + 225083657000 | + 225080657000 | + 225077657000 | + 225074657000 | + 225071657000 | + 225068657000 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17', 1s) from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17', 1s) | +========================================== + -225095657 | + -225092657 | + -225089657 | + -225086657 | + -225083657 | + -225080657 | + -225077657 | + -225074657 | + -225071657 | + -225068657 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts, 1s) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts, 1s) | +========================================== + 225095657 | + 225092657 | + 225089657 | + 225086657 | + 225083657 | + 225080657 | + 225077657 | + 225074657 | + 225071657 | + 225068657 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17', 1m) from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17', 1m) | +========================================== + -3751594 | + -3751544 | + -3751494 | + -3751444 | + -3751394 | + -3751344 | + -3751294 | + -3751244 | + -3751194 | + -3751144 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts, 1m) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts, 1m) | +========================================== + 3751594 | + 3751544 | + 3751494 | + 3751444 | + 3751394 | + 3751344 | + 3751294 | + 3751244 | + 3751194 | + 3751144 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17', 1h) from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17', 1h) | +========================================== + -62526 | + -62525 | + -62524 | + -62524 | + -62523 | + -62522 | + -62521 | + -62520 | + -62519 | + -62519 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts, 1h) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts, 1h) | +========================================== + 62526 | + 62525 | + 62524 | + 62524 | + 62523 | + 62522 | + 62521 | + 62520 | + 62519 | + 62519 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17', 1d) from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17', 1d) | +========================================== + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2604 | + -2604 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts, 1d) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts, 1d) | +========================================== + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2604 | + 2604 | + +taos> select TIMEDIFF(ts, '2024-08-31 17:14:17', 1w) from ts_4893.meters order by ts limit 10 + timediff(ts, '2024-08-31 17:14:17', 1w) | +========================================== + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + +taos> select TIMEDIFF('2024-08-31 17:14:17', ts, 1w) from ts_4893.meters order by ts limit 10 + timediff('2024-08-31 17:14:17', ts, 1w) | +========================================== + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + +taos> select TIMEDIFF(ts, 1725095657) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657) | +=========================== + -225095657000 | + -225092657000 | + -225089657000 | + -225086657000 | + -225083657000 | + -225080657000 | + -225077657000 | + -225074657000 | + -225071657000 | + -225068657000 | + +taos> select TIMEDIFF(1725095657, ts) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts) | +=========================== + 225095657000 | + 225092657000 | + 225089657000 | + 225086657000 | + 225083657000 | + 225080657000 | + 225077657000 | + 225074657000 | + 225071657000 | + 225068657000 | + +taos> select TIMEDIFF(ts, 1725095657, 1s) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657, 1s) | +=============================== + -225095657 | + -225092657 | + -225089657 | + -225086657 | + -225083657 | + -225080657 | + -225077657 | + -225074657 | + -225071657 | + -225068657 | + +taos> select TIMEDIFF(1725095657, ts, 1s) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts, 1s) | +=============================== + 225095657 | + 225092657 | + 225089657 | + 225086657 | + 225083657 | + 225080657 | + 225077657 | + 225074657 | + 225071657 | + 225068657 | + +taos> select TIMEDIFF(ts, 1725095657, 1m) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657, 1m) | +=============================== + -3751594 | + -3751544 | + -3751494 | + -3751444 | + -3751394 | + -3751344 | + -3751294 | + -3751244 | + -3751194 | + -3751144 | + +taos> select TIMEDIFF(1725095657, ts, 1m) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts, 1m) | +=============================== + 3751594 | + 3751544 | + 3751494 | + 3751444 | + 3751394 | + 3751344 | + 3751294 | + 3751244 | + 3751194 | + 3751144 | + +taos> select TIMEDIFF(ts, 1725095657, 1h) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657, 1h) | +=============================== + -62526 | + -62525 | + -62524 | + -62524 | + -62523 | + -62522 | + -62521 | + -62520 | + -62519 | + -62519 | + +taos> select TIMEDIFF(1725095657, ts, 1h) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts, 1h) | +=============================== + 62526 | + 62525 | + 62524 | + 62524 | + 62523 | + 62522 | + 62521 | + 62520 | + 62519 | + 62519 | + +taos> select TIMEDIFF(ts, 1725095657, 1d) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657, 1d) | +=============================== + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2605 | + -2604 | + -2604 | + +taos> select TIMEDIFF(1725095657, ts, 1d) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts, 1d) | +=============================== + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2605 | + 2604 | + 2604 | + +taos> select TIMEDIFF(ts, 1725095657, 1w) from ts_4893.meters order by ts limit 10 + timediff(ts, 1725095657, 1w) | +=============================== + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + -372 | + +taos> select TIMEDIFF(1725095657, ts, 1w) from ts_4893.meters order by ts limit 10 + timediff(1725095657, ts, 1w) | +=============================== + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + 372 | + +taos> select timediff('2022-01-01 08:00:00', '2022-01-01 08:00:10',1s) + timediff('2022-01-01 08:00:00', '2022-01-01 08:00:10',1s) | +============================================================ + -10 | + +taos> select timediff('2023-01-01 08:00:00', '2022-01-01 08:00:00',1s) + timediff('2023-01-01 08:00:00', '2022-01-01 08:00:00',1s) | +============================================================ + 31536000 | + +taos> select timediff('2022-01-01 08:00:03', '2022-01-01 08:00:00',1a) + timediff('2022-01-01 08:00:03', '2022-01-01 08:00:00',1a) | +============================================================ + 3000 | + +taos> select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1m) + timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1m) | +============================================================ + 43200 | + +taos> select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1h) + timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1h) | +============================================================ + 720 | + +taos> select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1d) + timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1d) | +============================================================ + 30 | + +taos> select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1w) + timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1w) | +============================================================ + 4 | + +taos> select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00') + timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00') | +========================================================= + 2592000000 | + +taos> select timediff('2022-01-31 08:00:0', '2022-01-01 08:00:00',1s) + timediff('2022-01-31 08:00:0', '2022-01-01 08:00:00',1s) | +=========================================================== + 2592000 | + +taos> select timediff('2022-01-31', '2022-01-01',1s) + timediff('2022-01-31', '2022-01-01',1s) | +========================================== + 2592000 | + +taos> select timediff(1720769589, 1720769529, 1s) + timediff(1720769589, 1720769529, 1s) | +======================================= + 60 | + +taos> select timediff(1720769589, '2022-01-01 08:00:00', 1s) + timediff(1720769589, '2022-01-01 08:00:00', 1s) | +================================================== + 79774389 | + +taos> select timediff(1720769589123, 1720769529123, 1s) + timediff(1720769589123, 1720769529123, 1s) | +============================================= + 60 | + +taos> select timediff(1720769589231, '2022-01-01 08:00:00', 1s) + timediff(1720769589231, '2022-01-01 08:00:00', 1s) | +===================================================== + 79774389 | + +taos> select timediff('2022-01-01 08:00:00', 1720769589, 1s) + timediff('2022-01-01 08:00:00', 1720769589, 1s) | +================================================== + -79774389 | + +taos> select timediff('2022-01-01 08:00:00', 1720769589123, 1s) + timediff('2022-01-01 08:00:00', 1720769589123, 1s) | +===================================================== + -79774389 | + +taos> select timediff(ts, 1720769589123, 1a) from ts_4893.d0 order by ts limit 10 + timediff(ts, 1720769589123, 1a) | +================================== + -220769589123 | + -220766589123 | + -220763589123 | + -220760589123 | + -220757589123 | + -220754589123 | + -220751589123 | + -220748589123 | + -220745589123 | + -220742589123 | + +taos> select timediff(ts, 1720769589123, 1a) from ts_4893.meters order by ts limit 10 + timediff(ts, 1720769589123, 1a) | +================================== + -220769589123 | + -220766589123 | + -220763589123 | + -220760589123 | + -220757589123 | + -220754589123 | + -220751589123 | + -220748589123 | + -220745589123 | + -220742589123 | + +taos> select timediff(null, '2022-01-01 08:00:01', 1s) + timediff(null, '2022-01-01 08:00:01', 1s) | +============================================ + NULL | + +taos> select timediff('20220131', '20220101', 1s) + timediff('20220131', '20220101', 1s) | +======================================= + NULL | + +taos> select timediff('01/31/22', '01/01/22', 1s) + timediff('01/31/22', '01/01/22', 1s) | +======================================= + NULL | + +taos> select timediff('22/01/31', '22/01/01') + timediff('22/01/31', '22/01/01') | +=================================== + NULL | + +taos> select timediff('22/01/31', '22/01/01', 1s) + timediff('22/01/31', '22/01/01', 1s) | +======================================= + NULL | + +taos> select timediff('31-JAN-22', '01-JAN-22', 1s) + timediff('31-JAN-22', '01-JAN-22', 1s) | +========================================= + NULL | + +taos> select timediff('2022/01/31', '2022/01/01', 1s) + timediff('2022/01/31', '2022/01/01', 1s) | +=========================================== + NULL | + +taos> select timediff('2022-01-01 08:00:00', null, 1s) + timediff('2022-01-01 08:00:00', null, 1s) | +============================================ + NULL | + +taos> select timediff('www', 'ttt') + timediff('www', 'ttt') | +========================= + NULL | + +taos> select timediff(ts, ts) from ts_4893.meters limit 1 + timediff(ts, ts) | +======================== + 0 | + +taos> select timediff(ts, ts - 1d) from ts_4893.meters limit 1 + timediff(ts, ts - 1d) | +======================== + 86400000 | + +taos> select timediff(ts, '00:00:00') from ts_4893.meters limit 1 + timediff(ts, '00:00:00') | +=========================== + NULL | + +taos> select timediff(ts, null) from ts_4893.meters limit 1 + timediff(ts, null) | +======================== + NULL | + +taos> select timediff('25:61:61', ts) from ts_4893.meters limit 1 + timediff('25:61:61', ts) | +=========================== + NULL | + +taos> select timediff('invalid_format', ts) from ts_4893.meters limit 1 + timediff('invalid_format', ts) | +================================= + NULL | + +taos> select timediff(name, ts) from ts_4893.meters limit 2 + timediff(name, ts) | +======================== + NULL | + NULL | + +taos> select timediff('string_value', 'another_string') from ts_4893.meters limit 1 + timediff('string_value', 'another_string') | +============================================= + NULL | + diff --git a/tests/army/query/function/ans/trim.csv b/tests/army/query/function/ans/trim.csv index 01ed8a62c9..6e2efbda51 100644 --- a/tests/army/query/function/ans/trim.csv +++ b/tests/army/query/function/ans/trim.csv @@ -1,453 +1,1049 @@ -foo -bar -foobar -barfoo -bar -blank -bla nk -bla nk - bla nk -blank -aæa -中文测试 -中文测试 -中文测试 - 中文测试 -中文测试 -二中文测试 -二中文测试 -二中文测试一 -一二中文测试 -中文andEnglish测试Test -中文andEnglish测试Test -中文andEnglish测试Test - 中文andEnglish测试Test -中文andEngTes -中文andEngTes -中文andEngTes空格空格 -空格中文andEngTes -中文andEnglish测试Tes -中文andEnglish测试Tes -中文andEnglish测试Tesblankblankblank -blankblank中文andEnglish测试Tes -空格中Tes空格blank空 -空格中Tes空格blank空 -空格中Tes空格blank空 -空格blank空格中Tes空格blank空 -novel -abc一二三abc一二三abc -一二三abc -一二三四五六七八九十 -person -novel -abc一二三abc一二三abc -一二三abc -一二三四五六七八九十 -person -novel -abc一二三abc一二三abc -一二三abc -一二三四五六七八九十 -person -novel -abc一二三abc一二三abc -一二三abc -一二三四五六七八九十 -person -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -novel -abc -123321三二一 -abc一二三abc一二三ab -novel -novel -abc -123321三二一 -abc一二三abc一二三ab -novel -novel -abc -123321三二一 -abc一二三abc一二三abc -novel -novel -一二三abc -一二三123321三二一 -abc一二三abc一二三ab -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三四五六七八九十 -update -prision -novel -novel -一二三abc -abc一二三abc一二三abc -bc一二三abc一二三abc -novel -update -一二三abc -abc一二三abc一二三abc -bc一二三abc一二三abc -novel -update -一二三abc -abc一二三abc一二三abc -bc一二三abc一二三abc -novel -update -一二三abc -abc一二三abc一二三abc -abc一二三abc一二三abc -novel -update -novel -person -novel -plate -一二三四五六七八九十 -novel -person -novel -plate -一二三四五六七八九十 -novel -person -novel -plate -一二三四五六七八九十 -novel -person -novel -plate -一二三四五六七八九十 -novel -plat -一二三abc -123321三二一 -abc一二三abc一二三ab -novel -plat -一二三abc -123321三二一 -abc一二三abc一二三ab -novel -plate -一二三abc -123321三二一 -abc一二三abc一二三abc -novel -plat -一二三abc -一二三123321三二一 -abc一二三abc一二三ab -person -novel -一二三四五六七八九十 -update -prision -person -novel -一二三四五六七八九十 -update -prision -person -novel -一二三四五六七八九十 -update -prision -person -novel -一二三四五六七八九十 -update -prision -二三四五六七八九十 -二三四五六七八九十 -abc一二三abc一二三abc -|| -二三123321三二 -二三四五六七八九十 -二三四五六七八九十 -abc一二三abc一二三abc -|| -二三123321三二 -二三四五六七八九十 -二三四五六七八九十 -abc一二三abc一二三abc -||一一一一 -二三123321三二一 -一二三四五六七八九十 -一二三四五六七八九十 -abc一二三abc一二三abc -一一一一一|| -一二三123321三二 -novel -update -prision -novel -novel -novel -update -prision -novel -novel -novel -update -prision -novel -novel -novel -update -prision -novel -novel -二三四五六七八九十 -二三abc -abc一二三abc一二三abc -二三123321三二 -|| -二三四五六七八九十 -二三abc -abc一二三abc一二三abc -二三123321三二 -|| -二三四五六七八九十 -二三abc -abc一二三abc一二三abc -二三123321三二一 -||一一一一 -一二三四五六七八九十 -一二三abc -abc一二三abc一二三abc -一二三123321三二 -一一一一一|| -novel -person -novel -plate -update -novel -person -novel -plate -update -novel -person -novel -plate -update -novel -person -novel -plate -update -三abbcfp三a -三abbcfp三a -三abbcfp三a -bbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -bbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -bbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -bbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三 -bbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三 -bbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三 -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -三abbcfp三a -A -涛思 -b bbb -aaa - aaa abab aaaa - abab aaaa -京涛思数据科技有限公司北 -bei京涛思数据科技有限公司北 - aaa abab aaaa -aaa abab - aaa abab -北京涛思数据科技有限公司 -北京涛思数据科技有限公司bei -aaa abab aaaa - aaa abab aaaa - abab -京涛思数据科技有限公司 -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plate -一二三四五六七八九十 -update -prision -person -prision -plate -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -一二三四五六七八九十 -update -prision -novel -novel -again -一二三四五六七八九十 -novel -again -novel -person -novel -plat -一二三四五六七八九十 -update -prision -person -prision -plate -novel -person -novel -plat -一二三四五六七八九十 -update -prision -person -prision -plate + +taos> select trim('foo') + trim('foo') | +============== + foo | + +taos> select trim('foo' from 'foobarfoo') + trim('foo' from 'foobarfoo') | +=============================== + bar | + +taos> select trim(trailing 'foo' from 'foobarfoo') + trim(trailing 'foo' from 'foobarfoo') | +======================================== + foobar | + +taos> select trim(leading 'foo' from 'foobarfoo') + trim(leading 'foo' from 'foobarfoo') | +======================================= + barfoo | + +taos> select trim(both 'foo' from 'foobarfoo') + trim(both 'foo' from 'foobarfoo') | +==================================== + bar | + +taos> select trim(' blank ') + trim(' blank ') | +======================== + blank | + +taos> select trim(both ' ' from ' bla nk ') + trim(both ' ' from ' bla nk ') | +======================================== + bla nk | + +taos> select trim(leading ' ' from ' bla nk') + trim(leading ' ' from ' bla nk') | +====================================== + bla nk | + +taos> select trim(trailing ' ' from ' bla nk ') + trim(trailing ' ' from ' bla nk ') | +============================================ + bla nk | + +taos> select trim(' ' from ' blank ') + trim(' ' from ' blank ') | +================================= + blank | + +taos> select TRIM(BOTH 'å' FROM 'aæaå') + trim(both 'å' from 'aæaå') | +================================ + aæa | + +taos> select trim(' 中文测试 ') + trim(' 中文测试 ') | +=========================== + 中文测试 | + +taos> select trim(both ' ' from ' 中文测试 ') + trim(both ' ' from ' 中文测试 ') | +========================================= + 中文测试 | + +taos> select trim(leading ' ' from ' 中文测试') + trim(leading ' ' from ' 中文测试') | +========================================== + 中文测试 | + +taos> select trim(trailing ' ' from ' 中文测试 ') + trim(trailing ' ' from ' 中文测试 ') | +============================================= + 中文测试 | + +taos> select trim(' ' from ' 中文测试 ') + trim(' ' from ' 中文测试 ') | +==================================== + 中文测试 | + +taos> select trim('一' from '一二中文测试一') + trim('一' from '一二中文测试一') | +=========================================== + 二中文测试 | + +taos> select trim(both '一' from '一二中文测试一') + trim(both '一' from '一二中文测试一') | +================================================ + 二中文测试 | + +taos> select trim(leading '一' from '一二中文测试一') + trim(leading '一' from '一二中文测试一') | +=================================================== + 二中文测试一 | + +taos> select trim(trailing '一' from '一二中文测试一') + trim(trailing '一' from '一二中文测试一') | +==================================================== + 一二中文测试 | + +taos> select trim(' 中文andEnglish测试Test ') + trim(' 中文andEnglish测试Test ') | +=========================================== + 中文andEnglish测试Test | + +taos> select trim(both ' ' from ' 中文andEnglish测试Test ') + trim(both ' ' from ' 中文andEnglish测试Test ') | +========================================================= + 中文andEnglish测试Test | + +taos> select trim(leading ' ' from ' 中文andEnglish测试Test') + trim(leading ' ' from ' 中文andEnglish测试Test') | +========================================================= + 中文andEnglish测试Test | + +taos> select trim(trailing ' ' from ' 中文andEnglish测试Test ') + trim(trailing ' ' from ' 中文andEnglish测试Test ') | +============================================================= + 中文andEnglish测试Test | + +taos> select trim('空格' from '空格中文andEngTes空格空格') + trim('空格' from '空格中文andEngTes空格空格') | +========================================================== + 中文andEngTes | + +taos> select trim(both '空格' from '空格中文andEngTes空格空格') + trim(both '空格' from '空格中文andEngTes空格空格') | +=============================================================== + 中文andEngTes | + +taos> select trim(leading '空格' from '空格中文andEngTes空格空格') + trim(leading '空格' from '空格中文andEngTes空格空格') | +================================================================== + 中文andEngTes空格空格 | + +taos> select trim(trailing '空格' from '空格中文andEngTes空格空格') + trim(trailing '空格' from '空格中文andEngTes空格空格') | +=================================================================== + 空格中文andEngTes | + +taos> select trim('blank' from 'blankblank中文andEnglish测试Tesblankblankblank') + trim('blank' from 'blankblank中文andEnglish测试Tesblankblank | +=================================================================== + 中文andEnglish测试Tes | + +taos> select trim(both 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') + trim(both 'blank' from 'blankblank中文andEnglish测试Tesblank | +=================================================================== + 中文andEnglish测试Tes | + +taos> select trim(leading 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') + trim(leading 'blank' from 'blankblank中文andEnglish测试Tesbl | +=================================================================== + 中文andEnglish测试Tesblankblankblank | + +taos> select trim(trailing 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') + trim(trailing 'blank' from 'blankblank中文andEnglish测试Tesb | +=================================================================== + blankblank中文andEnglish测试Tes | + +taos> select trim('空格blank' from '空格blank空格中Tes空格blank空') + trim('空格blank' from '空格blank空格中Tes空格blank空') | +=================================================================== + 空格中Tes空格blank空 | + +taos> select trim(both '空格blank' from '空格blank空格中Tes空格blank空') + trim(both '空格blank' from '空格blank空格中Tes空格blank | +=================================================================== + 空格中Tes空格blank空 | + +taos> select trim(leading '空格blank' from '空格blank空格中Tes空格blank空') + trim(leading '空格blank' from '空格blank空格中Tes空格bl | +=================================================================== + 空格中Tes空格blank空 | + +taos> select trim(trailing '空格blank' from '空格blank空格中Tes空格blank空') + trim(trailing '空格blank' from '空格blank空格中Tes空格b | +=================================================================== + 空格blank空格中Tes空格blank空 | + +taos> select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 + trim(nch2 from nch1) | +================================= + novel | + abc一二三abc一二三abc | + 一二三abc | + 一二三四五六七八九十 | + person | + +taos> select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 + trim(both nch2 from nch1) | +================================= + novel | + abc一二三abc一二三abc | + 一二三abc | + 一二三四五六七八九十 | + person | + +taos> select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 + trim(leading nch2 from nch1) | +================================= + novel | + abc一二三abc一二三abc | + 一二三abc | + 一二三四五六七八九十 | + person | + +taos> select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 + trim(trailing nch2 from nch1) | +================================= + novel | + abc一二三abc一二三abc | + 一二三abc | + 一二三四五六七八九十 | + person | + +taos> select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + trim(nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + trim(both nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + trim(leading nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 + trim(trailing nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + +taos> select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 + trim(var2 from nch1) | +================================= + novel | + novel | + abc | + 123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 + trim(both var2 from nch1) | +================================= + novel | + novel | + abc | + 123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 + trim(leading var2 from nch1) | +================================= + novel | + novel | + abc | + 123321三二一 | + abc一二三abc一二三abc | + +taos> select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 + trim(trailing var2 from nch1) | +================================= + novel | + novel | + 一二三abc | + 一二三123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + trim(var2 from nch1) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + trim(both var2 from nch1) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + trim(leading var2 from nch1) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 + trim(trailing var2 from nch1) | +================================= + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + +taos> select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 + trim(nch2 from var1) | +================================= + 一二三abc | + abc一二三abc一二三abc | + bc一二三abc一二三abc | + novel | + update | + +taos> select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 + trim(both nch2 from var1) | +================================= + 一二三abc | + abc一二三abc一二三abc | + bc一二三abc一二三abc | + novel | + update | + +taos> select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 + trim(leading nch2 from var1) | +================================= + 一二三abc | + abc一二三abc一二三abc | + bc一二三abc一二三abc | + novel | + update | + +taos> select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 + trim(trailing nch2 from var1) | +================================= + 一二三abc | + abc一二三abc一二三abc | + abc一二三abc一二三abc | + novel | + update | + +taos> select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + trim(nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + trim(both nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + trim(leading nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 + trim(trailing nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + +taos> select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 + trim(var2 from var1) | +================================= + novel | + plat | + 一二三abc | + 123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 + trim(both var2 from var1) | +================================= + novel | + plat | + 一二三abc | + 123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 + trim(leading var2 from var1) | +================================= + novel | + plate | + 一二三abc | + 123321三二一 | + abc一二三abc一二三abc | + +taos> select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 + trim(trailing var2 from var1) | +================================= + novel | + plat | + 一二三abc | + 一二三123321三二一 | + abc一二三abc一二三ab | + +taos> select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + trim(var2 from var1) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + trim(both var2 from var1) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + trim(leading var2 from var1) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 + trim(trailing var2 from var1) | +================================= + person | + novel | + 一二三四五六七八九十 | + update | + prision | + +taos> select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 + trim('一' from nch1) | +================================= + 二三四五六七八九十 | + 二三四五六七八九十 | + abc一二三abc一二三abc | + || | + 二三123321三二 | + +taos> select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 + trim(both '一' from nch1) | +================================= + 二三四五六七八九十 | + 二三四五六七八九十 | + abc一二三abc一二三abc | + || | + 二三123321三二 | + +taos> select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 + trim(leading '一' from nch1) | +================================= + 二三四五六七八九十 | + 二三四五六七八九十 | + abc一二三abc一二三abc | + ||一一一一 | + 二三123321三二一 | + +taos> select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 + trim(trailing '一' from nch1) | +================================= + 一二三四五六七八九十 | + 一二三四五六七八九十 | + abc一二三abc一二三abc | + 一一一一一|| | + 一二三123321三二 | + +taos> select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 + trim('一' from nch1) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 + trim(both '一' from nch1) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 + trim(leading '一' from nch1) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 + trim(trailing '一' from nch1) | +================================= + novel | + update | + prision | + novel | + novel | + +taos> select trim('一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 + trim('一' from var1) | +================================= + 二三四五六七八九十 | + 二三abc | + abc一二三abc一二三abc | + 二三123321三二 | + || | + +taos> select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 + trim(both '一' from var1) | +================================= + 二三四五六七八九十 | + 二三abc | + abc一二三abc一二三abc | + 二三123321三二 | + || | + +taos> select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 + trim(leading '一' from var1) | +================================= + 二三四五六七八九十 | + 二三abc | + abc一二三abc一二三abc | + 二三123321三二一 | + ||一一一一 | + +taos> select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 + trim(trailing '一' from var1) | +================================= + 一二三四五六七八九十 | + 一二三abc | + abc一二三abc一二三abc | + 一二三123321三二 | + 一一一一一|| | + +taos> select trim('一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 + trim('一' from var1) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 + trim(both '一' from var1) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 + trim(leading '一' from var1) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 + trim(trailing '一' from var1) | +================================= + novel | + person | + novel | + plate | + update | + +taos> select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(nch2 from '三abbcfp三a') | +================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + bbcfp | + 三abbcfp三a | + +taos> select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(both nch2 from '三abbcfp三a') | +======================================= + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + bbcfp | + 三abbcfp三a | + +taos> select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(leading nch2 from '三abbcfp三a') | +========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + bbcfp三a | + 三abbcfp三a | + +taos> select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(trailing nch2 from '三abbcfp三a') | +=========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp | + 三abbcfp三a | + +taos> select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(nch2 from '三abbcfp三a') | +================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(both nch2 from '三abbcfp三a') | +======================================= + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(leading nch2 from '三abbcfp三a') | +========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(trailing nch2 from '三abbcfp三a') | +=========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(var2 from '三abbcfp三a') | +================================== + bbcfp | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三 | + +taos> select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(both var2 from '三abbcfp三a') | +======================================= + bbcfp | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三 | + +taos> select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(leading var2 from '三abbcfp三a') | +========================================== + bbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 + trim(trailing var2 from '三abbcfp三a') | +=========================================== + 三abbcfp | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三 | + +taos> select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(var2 from '三abbcfp三a') | +================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(both var2 from '三abbcfp三a') | +======================================= + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(leading var2 from '三abbcfp三a') | +========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 + trim(trailing var2 from '三abbcfp三a') | +=========================================== + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + 三abbcfp三a | + +taos> select trim(' A ') + trim(' A ') | +======================= + A | + +taos> select trim(' 涛思 ') + trim(' 涛思 ') | +============================ + 涛思 | + +taos> select trim('a' FROM 'aaab bbba') + trim('a' from 'aaab bbba') | +================================== + b bbb | + +taos> select trim(LEADING FROM ' aaa ') + trim(leading from ' aaa ') | +======================================= + aaa | + +taos> select trim(LEADING 'a' FROM ' aaa abab aaaa ') + trim(leading 'a' from ' aaa abab aaaa ') | +==================================================== + aaa abab aaaa | + +taos> select trim(LEADING 'a' FROM 'aaa abab aaaa ') + trim(leading 'a' from 'aaa abab aaaa ') | +================================================= + abab aaaa | + +taos> select trim(LEADING '北' FROM '北京涛思数据科技有限公司北') + trim(leading '北' from '北京涛思数据科技有限公司北 | +=================================================================== + 京涛思数据科技有限公司北 | + +taos> select trim(LEADING '北' FROM '北bei京涛思数据科技有限公司北') + trim(leading '北' from '北bei京涛思数据科技有限公司 | +=================================================================== + bei京涛思数据科技有限公司北 | + +taos> select trim(TRAILING FROM ' aaa abab aaaa ') + trim(trailing from ' aaa abab aaaa ') | +================================================= + aaa abab aaaa | + +taos> select trim(TRAILING 'a' FROM 'aaa abab aaaa') + trim(trailing 'a' from 'aaa abab aaaa') | +=============================================== + aaa abab | + +taos> select trim(TRAILING 'a' FROM ' aaa abab aaaa') + trim(trailing 'a' from ' aaa abab aaaa') | +================================================== + aaa abab | + +taos> select trim(TRAILING '北' FROM '北京涛思数据科技有限公司北') as sub + sub | +================================= + 北京涛思数据科技有限公司 | + +taos> select trim(TRAILING '北' FROM '北京涛思数据科技有限公司bei北') + trim(trailing '北' from '北京涛思数据科技有限公司be | +=================================================================== + 北京涛思数据科技有限公司bei | + +taos> select trim(BOTH FROM ' aaa abab aaaa ') + trim(both from ' aaa abab aaaa ') | +============================================= + aaa abab aaaa | + +taos> select trim(BOTH 'a' FROM ' aaa abab aaaa ') + trim(both 'a' from ' aaa abab aaaa ') | +================================================== + aaa abab aaaa | + +taos> select trim(BOTH 'a' FROM 'aaa abab aaaa') + trim(both 'a' from 'aaa abab aaaa') | +=========================================== + abab | + +taos> select trim(BOTH '北' FROM '北京涛思数据科技有限公司北') + trim(both '北' from '北京涛思数据科技有限公司北') | +================================================================== + 京涛思数据科技有限公司 | + +taos> select trim(nch2 from nch1) from ts_4893.d0 order by ts limit 10 + trim(nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select trim(nch2 from nch1) from ts_4893.meters order by ts limit 10 + trim(nch2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select trim(nch2 from var1) from ts_4893.d0 order by ts limit 10 + trim(nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select trim(nch2 from var1) from ts_4893.meters order by ts limit 10 + trim(nch2 from var1) | +================================= + novel | + person | + novel | + plate | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select trim(var2 from nch1) from ts_4893.d0 order by ts limit 10 + trim(var2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select trim(var2 from nch1) from ts_4893.meters order by ts limit 10 + trim(var2 from nch1) | +================================= + novel | + 一二三四五六七八九十 | + update | + prision | + novel | + novel | + again | + 一二三四五六七八九十 | + novel | + again | + +taos> select trim(var2 from var1) from ts_4893.d0 order by ts limit 10 + trim(var2 from var1) | +================================= + novel | + person | + novel | + plat | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select trim(var2 from var1) from ts_4893.meters order by ts limit 10 + trim(var2 from var1) | +================================= + novel | + person | + novel | + plat | + 一二三四五六七八九十 | + update | + prision | + person | + prision | + plate | + +taos> select trim(null) + trim(null) | +============= + NULL | + +taos> select trim('') + trim('') | +=========== + | + +taos> select trim(leading ' ' from ' hello') + trim(leading ' ' from ' hello') | +==================================== + hello | + +taos> select trim(trailing ' ' from 'hello ') + trim(trailing ' ' from 'hello ') | +===================================== + hello | + +taos> select trim('0' from '000123000') + trim('0' from '000123000') | +============================= + 123 | + +taos> select trim(' hello ') + trim(' hello ') | +==================== + hello | + +taos> select trim(' apple banana ') + trim(' apple banana ') | +============================= + apple banana | + +taos> select var2, trim('*' from var2) from ts_4893.meters limit 1 + var2 | trim('*' from var2) | +================================================================== + e | e | + +taos> select trim('x' from 'hello') + trim('x' from 'hello') | +========================= + hello | + +taos> select trim('longer' from 'short') + trim('longer' from 'short') | +============================== + short | + +taos> select trim('hello') + trim('hello') | +================ + hello | + +taos> select trim(' 12345 ') + trim(' 12345 ') | +====================== + 12345 | + +taos> select trim(concat(' hello', ' world ')) + trim(concat(' hello', ' world ')) | +========================================== + hello world | + +taos> select trim(upper(' hello world ')) + trim(upper(' hello world ')) | +================================= + HELLO WORLD | + +taos> select trim(substring(' hello world ', 4)) + trim(substring(' hello world ', 4)) | +========================================== + hello world | + +taos> select trim(replace(' hello world ', ' ', '-')) + trim(replace(' hello world ', ' ', '-')) | +=============================================== + ---hello-world--- | + +taos> select name, trim(name) from ts_4893.meters limit 1 + name | trim(name) | +================================================================== + lili | lili | + +taos> select var1, trim(trailing '!' from var1) from ts_4893.meters limit 1 + var1 | trim(trailing '!' from var1) | +================================================================== + novel | novel | + +taos> select nch1, trim(leading '-' from nch1) from ts_4893.meters limit 1 + nch1 | trim(leading '-' from nch1) | +================================================================== + novel | novel | + diff --git a/tests/army/query/function/ans/trunc.csv b/tests/army/query/function/ans/trunc.csv old mode 100755 new mode 100644 index ea735c1c7e..e553f3acb5 --- a/tests/army/query/function/ans/trunc.csv +++ b/tests/army/query/function/ans/trunc.csv @@ -1,129 +1,343 @@ -10.550000000000001 -10.550000000000001 -10.500000000000000 -10.000000000000000 -10.000000000000000 -0.000000000000000 --10.500000000000000 -99 -11.500000000000000 -1.231230000000000e+02 -1.200000000000000e+08 -8.765432100000000e+07 -8.765432109999999e+07 -8.765432112000000e+07 -8.765432112300000e+07 -8.765432112340000e+07 -8.765432112345000e+07 -8.765432112345600e+07 -8.765432112345670e+07 -8.765432112345679e+07 -8.765432112345679e+07 -10.0000000 -8.5000000 -9.7900000 -11.2329998 -10.7060003 -8.5080004 -9.5959997 -10.9619999 -11.2259998 -10.3369999 -10.6000004 -8.5000000 -9.6999998 -11.1999998 -10.6999998 -8.5000000 -9.5000000 -10.8999996 -11.1999998 -10.3000002 -10.550000000000001 -10.550000000000001 -10.500000000000000 -10.000000000000000 -10.000000000000000 -0.000000000000000 --10.500000000000000 -99 -11.500000000000000 -1.231230000000000e+02 -1.200000000000000e+08 -8.765432100000000e+07 -8.765432109999999e+07 -8.765432112000000e+07 -8.765432112300000e+07 -8.765432112340000e+07 -8.765432112345000e+07 -8.765432112345600e+07 -8.765432112345670e+07 -8.765432112345679e+07 -8.765432112345679e+07 -10.0000000 -8.5000000 -9.7900000 -11.2329998 -10.7060003 -8.5080004 -9.5959997 -10.9619999 -11.2259998 -10.3369999 -10.6000004 -8.5000000 -9.6999998 -11.1999998 -10.6999998 -8.5000000 -9.5000000 -10.8999996 -11.1999998 -10.3000002 -99.99 -99.99 -99.9 -99 -90 -0 -99 -10.6 -8.5 -9.7 -11.2 -10.7 -8.5 -9.5 -10.9 -11.2 -10.3 -10.6 -8.5 -9.7 -11.2 -10.7 -8.5 -9.5 -10.9 -11.2 -10.3 -10.6 -8.5 -9.7 -11.2 -10.7 -8.5 -9.5 -10.9 -11.2 -10.3 -10.6 -8.5 -9.7 -11.2 -10.7 -8.5 -9.5 -10.9 -11.2 -10.3 + +taos> select TRUNCATE(10.55, 3) + truncate(10.55, 3) | +============================ + 10.550000000000001 | + +taos> select TRUNCATE(10.55, 2) + truncate(10.55, 2) | +============================ + 10.550000000000001 | + +taos> select TRUNCATE(10.55, 1) + truncate(10.55, 1) | +============================ + 10.500000000000000 | + +taos> select TRUNCATE(10.55, 0) + truncate(10.55, 0) | +============================ + 10.000000000000000 | + +taos> select TRUNCATE(10.55, -1) + truncate(10.55, -1) | +============================ + 10.000000000000000 | + +taos> select TRUNCATE(10.55, -10) + truncate(10.55, -10) | +============================ + 0.000000000000000 | + +taos> select TRUNCATE(-10.55, 1) + truncate(-10.55, 1) | +============================ + -10.500000000000000 | + +taos> select TRUNCATE(99, 1) + truncate(99, 1) | +======================== + 99 | + +taos> select TRUNCATE(10.55, 1) + 1 + truncate(10.55, 1) + 1 | +============================ + 11.500000000000000 | + +taos> select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123.123456789, 9), 8), 7), 6), 5), 4), 3) + truncate(truncate(truncate(truncate(truncate(truncate(truncate(1 | +=================================================================== + 1.231230000000000e+02 | + +taos> select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) + truncate(truncate(truncate(truncate(truncate(truncate(truncate(1 | +=================================================================== + 1.200000000000000e+08 | + +taos> select TRUNCATE(87654321.123456789, id) from ts_4893.meters order by ts limit 10 + truncate(87654321.123456789, id) | +=================================== + 8.765432100000000e+07 | + 8.765432109999999e+07 | + 8.765432112000000e+07 | + 8.765432112300000e+07 | + 8.765432112340000e+07 | + 8.765432112345000e+07 | + 8.765432112345600e+07 | + 8.765432112345670e+07 | + 8.765432112345679e+07 | + 8.765432112345679e+07 | + +taos> select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10 + truncate(current, id) | +======================== + 1.0000000e+01 | + 8.5000000e+00 | + 9.7900000e+00 | + 1.1233000e+01 | + 1.0706000e+01 | + 8.5080004e+00 | + 9.5959997e+00 | + 1.0962000e+01 | + 1.1226000e+01 | + 1.0337000e+01 | + +taos> select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10 + truncate(current, 1) | +======================= + 10.6000004 | + 8.5000000 | + 9.6999998 | + 11.1999998 | + 10.6999998 | + 8.5000000 | + 9.5000000 | + 10.8999996 | + 11.1999998 | + 10.3000002 | + +taos> select TRUNC(10.55, 3) + trunc(10.55, 3) | +============================ + 10.550000000000001 | + +taos> select TRUNC(10.55, 2) + trunc(10.55, 2) | +============================ + 10.550000000000001 | + +taos> select TRUNC(10.55, 1) + trunc(10.55, 1) | +============================ + 10.500000000000000 | + +taos> select TRUNC(10.55, 0) + trunc(10.55, 0) | +============================ + 10.000000000000000 | + +taos> select TRUNC(10.55, -1) + trunc(10.55, -1) | +============================ + 10.000000000000000 | + +taos> select TRUNC(10.55, -10) + trunc(10.55, -10) | +============================ + 0.000000000000000 | + +taos> select TRUNC(-10.55, 1) + trunc(-10.55, 1) | +============================ + -10.500000000000000 | + +taos> select TRUNC(99, 1) + trunc(99, 1) | +======================== + 99 | + +taos> select TRUNC(10.55, 1) + 1 + trunc(10.55, 1) + 1 | +============================ + 11.500000000000000 | + +taos> select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123.123456789, 9), 8), 7), 6), 5), 4), 3) + trunc(trunc(trunc(trunc(trunc(trunc(trunc(123.123456789, 9), 8), | +=================================================================== + 1.231230000000000e+02 | + +taos> select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) + trunc(trunc(trunc(trunc(trunc(trunc(trunc(123456789.123456789, - | +=================================================================== + 1.200000000000000e+08 | + +taos> select TRUNC(87654321.123456789, id) from ts_4893.meters order by ts limit 10 + trunc(87654321.123456789, id) | +================================ + 8.765432100000000e+07 | + 8.765432109999999e+07 | + 8.765432112000000e+07 | + 8.765432112300000e+07 | + 8.765432112340000e+07 | + 8.765432112345000e+07 | + 8.765432112345600e+07 | + 8.765432112345670e+07 | + 8.765432112345679e+07 | + 8.765432112345679e+07 | + +taos> select TRUNC(current, id) from ts_4893.meters order by ts limit 10 + trunc(current, id) | +======================= + 10.0000000 | + 8.5000000 | + 9.7900000 | + 11.2329998 | + 10.7060003 | + 8.5080004 | + 9.5959997 | + 10.9619999 | + 11.2259998 | + 10.3369999 | + +taos> select TRUNC(current, 1) from ts_4893.meters order by ts limit 10 + trunc(current, 1) | +======================= + 10.6000004 | + 8.5000000 | + 9.6999998 | + 11.1999998 | + 10.6999998 | + 8.5000000 | + 9.5000000 | + 10.8999996 | + 11.1999998 | + 10.3000002 | + +taos> select truncate(99.99, 3) + truncate(99.99, 3) | +============================ + 99.989999999999995 | + +taos> select truncate(99.99, 2) + truncate(99.99, 2) | +============================ + 99.989999999999995 | + +taos> select truncate(99.99, 1) + truncate(99.99, 1) | +============================ + 99.900000000000006 | + +taos> select truncate(99.99, 0) + truncate(99.99, 0) | +============================ + 99.000000000000000 | + +taos> select truncate(99.99, -1) + truncate(99.99, -1) | +============================ + 90.000000000000000 | + +taos> select truncate(99.99, -10) + truncate(99.99, -10) | +============================ + 0.000000000000000 | + +taos> select truncate(99, 1) + truncate(99, 1) | +======================== + 99 | + +taos> select truncate(current, 1) from ts_4893.d0 order by ts limit 10 + truncate(current, 1) | +======================= + 10.6000004 | + 8.5000000 | + 9.6999998 | + 11.1999998 | + 10.6999998 | + 8.5000000 | + 9.5000000 | + 10.8999996 | + 11.1999998 | + 10.3000002 | + +taos> select truncate(current, 1) from ts_4893.meters order by ts limit 10 + truncate(current, 1) | +======================= + 10.6000004 | + 8.5000000 | + 9.6999998 | + 11.1999998 | + 10.6999998 | + 8.5000000 | + 9.5000000 | + 10.8999996 | + 11.1999998 | + 10.3000002 | + +taos> select truncate(99.99, null) + truncate(99.99, null) | +============================ + NULL | + +taos> select truncate(null, 3) + truncate(null, 3) | +==================== + NULL | + +taos> select truncate(1.0001, 3) + truncate(1.0001, 3) | +============================ + 1.000000000000000 | + +taos> select truncate(2.71828, 4) + truncate(2.71828, 4) | +============================ + 2.718200000000000 | + +taos> select truncate(3.14159, 2) + truncate(3.14159, 2) | +============================ + 3.140000000000000 | + +taos> select truncate(100.9876, 2) + truncate(100.9876, 2) | +============================ + 100.980000000000004 | + +taos> select truncate(99999999999999.9999, 2) + truncate(99999999999999.9999, 2) | +=================================== + 1.000000000000000e+14 | + +taos> select truncate(-5.678, 2) + truncate(-5.678, 2) | +============================ + -5.670000000000000 | + +taos> select truncate(voltage, 2) from ts_4893.meters limit 1 + truncate(voltage, 2) | +======================= + 221 | + +taos> select truncate(current, 1) from ts_4893.meters limit 1 + truncate(current, 1) | +======================= + 10.6000004 | + +taos> select truncate(phase, 3) from ts_4893.meters limit 1 + truncate(phase, 3) | +======================= + 0.5080000 | + +taos> select truncate(voltage + current, 2) from ts_4893.meters limit 1 + truncate(voltage + current, 2) | +================================= + 2.316400000000000e+02 | + +taos> select truncate(voltage, -1) from ts_4893.meters limit 1 + truncate(voltage, -1) | +======================== + 220 | + +taos> select round(truncate(voltage, 1), 2) from ts_4893.meters limit 1 + round(truncate(voltage, 1), 2) | +================================= + 221 | + +taos> select truncate(abs(current), 1) from ts_4893.meters limit 1 + truncate(abs(current), 1) | +============================ + 1.0600000e+01 | + +taos> select truncate(exp(phase), 2) from ts_4893.meters limit 1 + truncate(exp(phase), 2) | +============================ + 1.660000000000000 | + +taos> select truncate(log(current), 1) from ts_4893.meters limit 1 + truncate(log(current), 1) | +============================ + 2.300000000000000 | + diff --git a/tests/army/query/function/ans/varpop.csv b/tests/army/query/function/ans/varpop.csv index d621d013fd..7cfb67dbea 100644 --- a/tests/army/query/function/ans/varpop.csv +++ b/tests/army/query/function/ans/varpop.csv @@ -1,37 +1,128 @@ -1.332500071133753 -0.702702307045610 -0.703315838252072 -0.705108647169672 -0.705108647169672 -0.706550935286583 -0.713306900568867 -0.716868311383919 -0.717430738826275 -0.717718552465788 -0.719483293517451 -8333333.250000000000000 -21.250000000000000 -70.000000000000000 -70.000000000000000 -70.000000000000000 -70.000000000000000 -65.250000000000000 -70.000000000000000 -70.000000000000000 -70.000000000000000 -70.000000000000000 -8165850.000000000000000 -21.250000000000000 -30.000000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -65.250000000000000 -8333333.250000000000000 -8333333.250000000000000 -1.332500071133751 -1.332500071133751 + +taos> select VAR_POP(current) from ts_4893.meters + var_pop(current) | +============================ + 1.332500071133751 | + +taos> select VAR_POP(current) from ts_4893.meters interval(1d) order by 1 limit 10 + var_pop(current) | +============================ + 0.702702307045612 | + 0.703315838252067 | + 0.705108647169666 | + 0.705108647169666 | + 0.706550935286586 | + 0.713306900568867 | + 0.716868311383919 | + 0.717430738826280 | + 0.717718552465783 | + 0.719483293517456 | + +taos> select VAR_POP(id) from ts_4893.meters + var_pop(id) | +============================ + 8333333.250000000000000 | + +taos> select VAR_POP(id) from ts_4893.meters interval(1d) limit 10 + var_pop(id) | +============================ + 21.250000000000000 | + 70.000000000000000 | + 70.000000000000000 | + 70.000000000000000 | + 70.000000000000000 | + 65.250000000000000 | + 70.000000000000000 | + 70.000000000000000 | + 70.000000000000000 | + 70.000000000000000 | + +taos> select VAR_POP(id) from ts_4893.meters where id > 100 + var_pop(id) | +============================ + 8165850.000000000000000 | + +taos> select VAR_POP(id) from ts_4893.meters interval(1d) order by 1 limit 10 + var_pop(id) | +============================ + 21.250000000000000 | + 30.000000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + 65.250000000000000 | + +taos> select var_pop(null) from ts_4893.meters + var_pop(null) | +============================ + NULL | + +taos> select var_pop(id) from ts_4893.d0 + var_pop(id) | +============================ + 8333333.250000000000000 | + +taos> select var_pop(current) from ts_4893.d0 + var_pop(current) | +============================ + 1.332500071133751 | + +taos> select var_pop(voltage) from ts_4893.meters + var_pop(voltage) | +============================ + 8.274020439996093 | + +taos> select var_pop(voltage) from ts_4893.meters where voltage is not null + var_pop(voltage) | +============================ + 8.274020439996093 | + +taos> select var_pop(phase) from ts_4893.meters + var_pop(phase) | +============================ + 0.083287338468169 | + +taos> select var_pop(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' + var_pop(phase) | +============================ + 0.082987411872200 | + +taos> select var_pop(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) + var_pop(total_voltage) | +============================ + 0.000000000000000 | + +taos> select round(var_pop(current), 2) from ts_4893.meters + round(var_pop(current), 2) | +============================= + 1.330000000000000e+00 | + +taos> select pow(var_pop(current), 2) from ts_4893.meters + pow(var_pop(current), 2) | +============================ + 1.775556439571451 | + +taos> select log(var_pop(voltage) + 1) from ts_4893.meters + log(var_pop(voltage) + 1) | +============================ + 2.227216989977633 | + +taos> select groupid, var_pop(voltage) from ts_4893.meters group by groupid order by groupid + groupid | var_pop(voltage) | +====================================== + 1 | 8.274020439996093 | + +taos> select location, var_pop(current) from ts_4893.meters group by location order by location + location | var_pop(current) | +================================================= + beijing | 1.332500071133751 | + +taos> select location, var_pop(voltage) from ts_4893.meters group by location order by location + location | var_pop(voltage) | +================================================= + beijing | 8.274020439996093 | + diff --git a/tests/army/query/function/ans/week.csv b/tests/army/query/function/ans/week.csv index 3a127f2feb..650d4aacfc 100644 --- a/tests/army/query/function/ans/week.csv +++ b/tests/army/query/function/ans/week.csv @@ -1,174 +1,565 @@ -0 -0 -1 -52 -1 -1 -0 -1 -52 -0 -0 -0 -52 -53 -0 -0 -53 -52 -0 -0 -1 -52 -1 -0 -0 -53 -52 -52 -52 -53 -52 -53 -52 -52 -52 -52 -1 -1 -1 -1 -1 -1 -1 -1 -1 -3 -3 -4 -3 -4 -3 -3 -3 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -0 -0 -0 -52 -52 -0 -0 -52 -52 -3 -52 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 + +taos> select WEEK('2020-01-01 00:00:00') + week('2020-01-01 00:00:00') | +============================== + 0 | + +taos> select WEEK('2020-01-01 00:00:00', 0) + week('2020-01-01 00:00:00', 0) | +================================= + 0 | + +taos> select WEEK('2020-01-01 00:00:00', 1) + week('2020-01-01 00:00:00', 1) | +================================= + 1 | + +taos> select WEEK('2020-01-01 00:00:00', 2) + week('2020-01-01 00:00:00', 2) | +================================= + 52 | + +taos> select WEEK('2020-01-01 00:00:00', 3) + week('2020-01-01 00:00:00', 3) | +================================= + 1 | + +taos> select WEEK('2020-01-01 00:00:00', 4) + week('2020-01-01 00:00:00', 4) | +================================= + 1 | + +taos> select WEEK('2020-01-01 00:00:00', 5) + week('2020-01-01 00:00:00', 5) | +================================= + 0 | + +taos> select WEEK('2020-01-01 00:00:00', 6) + week('2020-01-01 00:00:00', 6) | +================================= + 1 | + +taos> select WEEK('2020-01-01 00:00:00', 7) + week('2020-01-01 00:00:00', 7) | +================================= + 52 | + +taos> select WEEK('2021-01-01 00:00:00') + week('2021-01-01 00:00:00') | +============================== + 0 | + +taos> select WEEK('2021-01-01 00:00:00', 0) + week('2021-01-01 00:00:00', 0) | +================================= + 0 | + +taos> select WEEK('2021-01-01 00:00:00', 1) + week('2021-01-01 00:00:00', 1) | +================================= + 0 | + +taos> select WEEK('2021-01-01 00:00:00', 2) + week('2021-01-01 00:00:00', 2) | +================================= + 52 | + +taos> select WEEK('2021-01-01 00:00:00', 3) + week('2021-01-01 00:00:00', 3) | +================================= + 53 | + +taos> select WEEK('2021-01-01 00:00:00', 4) + week('2021-01-01 00:00:00', 4) | +================================= + 0 | + +taos> select WEEK('2021-01-01 00:00:00', 5) + week('2021-01-01 00:00:00', 5) | +================================= + 0 | + +taos> select WEEK('2021-01-01 00:00:00', 6) + week('2021-01-01 00:00:00', 6) | +================================= + 53 | + +taos> select WEEK('2021-01-01 00:00:00', 7) + week('2021-01-01 00:00:00', 7) | +================================= + 52 | + +taos> select WEEK('1998-01-01 00:00:00') + week('1998-01-01 00:00:00') | +============================== + 0 | + +taos> select WEEK('1998-01-01 00:00:00', 0) + week('1998-01-01 00:00:00', 0) | +================================= + 0 | + +taos> select WEEK('1998-01-01 00:00:00', 1) + week('1998-01-01 00:00:00', 1) | +================================= + 1 | + +taos> select WEEK('1998-01-01 00:00:00', 2) + week('1998-01-01 00:00:00', 2) | +================================= + 52 | + +taos> select WEEK('1998-01-01 00:00:00', 3) + week('1998-01-01 00:00:00', 3) | +================================= + 1 | + +taos> select WEEK('1998-01-01 00:00:00', 4) + week('1998-01-01 00:00:00', 4) | +================================= + 0 | + +taos> select WEEK('1998-01-01 00:00:00', 5) + week('1998-01-01 00:00:00', 5) | +================================= + 0 | + +taos> select WEEK('1998-01-01 00:00:00', 6) + week('1998-01-01 00:00:00', 6) | +================================= + 53 | + +taos> select WEEK('1998-01-01 00:00:00', 7) + week('1998-01-01 00:00:00', 7) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00') + week('1998-12-31 00:00:00') | +============================== + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 0) + week('1998-12-31 00:00:00', 0) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 1) + week('1998-12-31 00:00:00', 1) | +================================= + 53 | + +taos> select WEEK('1998-12-31 00:00:00', 2) + week('1998-12-31 00:00:00', 2) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 3) + week('1998-12-31 00:00:00', 3) | +================================= + 53 | + +taos> select WEEK('1998-12-31 00:00:00', 4) + week('1998-12-31 00:00:00', 4) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 5) + week('1998-12-31 00:00:00', 5) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 6) + week('1998-12-31 00:00:00', 6) | +================================= + 52 | + +taos> select WEEK('1998-12-31 00:00:00', 7) + week('1998-12-31 00:00:00', 7) | +================================= + 52 | + +taos> select WEEK('2000-01-06 00:00:00') + week('2000-01-06 00:00:00') | +============================== + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 0) + week('2000-01-06 00:00:00', 0) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 1) + week('2000-01-06 00:00:00', 1) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 2) + week('2000-01-06 00:00:00', 2) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 3) + week('2000-01-06 00:00:00', 3) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 4) + week('2000-01-06 00:00:00', 4) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 5) + week('2000-01-06 00:00:00', 5) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 6) + week('2000-01-06 00:00:00', 6) | +================================= + 1 | + +taos> select WEEK('2000-01-06 00:00:00', 7) + week('2000-01-06 00:00:00', 7) | +================================= + 1 | + +taos> select WEEK(1725095657) + week(1725095657) | +======================== + 3 | + +taos> select WEEK(1725095657, 0) + week(1725095657, 0) | +======================== + 3 | + +taos> select WEEK(1725095657, 1) + week(1725095657, 1) | +======================== + 4 | + +taos> select WEEK(1725095657, 2) + week(1725095657, 2) | +======================== + 3 | + +taos> select WEEK(1725095657, 3) + week(1725095657, 3) | +======================== + 4 | + +taos> select WEEK(1725095657, 4) + week(1725095657, 4) | +======================== + 3 | + +taos> select WEEK(1725095657, 5) + week(1725095657, 5) | +======================== + 3 | + +taos> select WEEK(1725095657, 6) + week(1725095657, 6) | +======================== + 3 | + +taos> select WEEK(ts) from ts_4893.meters order by ts limit 10 + week(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 0) from ts_4893.meters order by ts limit 10 + week(ts, 0) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 1) from ts_4893.meters order by ts limit 10 + week(ts, 1) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 2) from ts_4893.meters order by ts limit 10 + week(ts, 2) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 3) from ts_4893.meters order by ts limit 10 + week(ts, 3) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 4) from ts_4893.meters order by ts limit 10 + week(ts, 4) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 5) from ts_4893.meters order by ts limit 10 + week(ts, 5) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 6) from ts_4893.meters order by ts limit 10 + week(ts, 6) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select WEEK(ts, 7) from ts_4893.meters order by ts limit 10 + week(ts, 7) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select week(123) + week(123) | +======================== + 0 | + +taos> select week('2000-01-01',0) + week('2000-01-01',0) | +======================== + 0 | + +taos> select week('2000-01-01',1) + week('2000-01-01',1) | +======================== + 0 | + +taos> select week('2000-01-01',2) + week('2000-01-01',2) | +======================== + 52 | + +taos> select week('2000-01-01',3) + week('2000-01-01',3) | +======================== + 52 | + +taos> select week('2000-01-01',4) + week('2000-01-01',4) | +======================== + 0 | + +taos> select week('2000-01-01',5) + week('2000-01-01',5) | +======================== + 0 | + +taos> select week('2000-01-01',6) + week('2000-01-01',6) | +======================== + 52 | + +taos> select week('2000-01-01',7) + week('2000-01-01',7) | +======================== + 52 | + +taos> select week(1721020591,0) + week(1721020591,0) | +======================== + 3 | + +taos> select week('2020-01-01 00:00:00', 2) + week('2020-01-01 00:00:00', 2) | +================================= + 52 | + +taos> select week(ts) from ts_4893.d0 order by ts limit 10 + week(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select week(ts) from ts_4893.meters order by ts limit 10 + week(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select week(null, 0) + week(null, 0) | +======================== + NULL | + +taos> select week('abc') + week('abc') | +======================== + NULL | + +taos> select week('1721020591', 0) + week('1721020591', 0) | +======================== + NULL | + +taos> select week('1721020666229', 0) + week('1721020666229', 0) | +=========================== + NULL | + +taos> select week('20200101', 2) + week('20200101', 2) | +======================== + NULL | + +taos> select week('11/01/31', 2) + week('11/01/31', 2) | +======================== + NULL | + +taos> select week('20/01/01', 2) + week('20/01/01', 2) | +======================== + NULL | + +taos> select week('01/01/2020', 2) + week('01/01/2020', 2) | +======================== + NULL | + +taos> select week('01-JAN-20', 2) + week('01-JAN-20', 2) | +======================== + NULL | + +taos> select week('2023-09-25') + week('2023-09-25') | +======================== + 39 | + +taos> select week('9999-12-31') + week('9999-12-31') | +======================== + 52 | + +taos> select week('2024-02-29 00:00:00') + week('2024-02-29 00:00:00') | +============================== + 8 | + +taos> select week(ts) from ts_4893.meters limit 1 + week(ts) | +======================== + 28 | + +taos> select week(name) from ts_4893.meters limit 1 + week(name) | +======================== + NULL | + +taos> select week(ts), dayofweek(ts) from ts_4893.meters limit 1 + week(ts) | dayofweek(ts) | +================================================ + 28 | 6 | + +taos> select week(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 + week(timediff(ts, '2024-10-10 09:36:50.172')) | +================================================ + 39 | + +taos> select id, week(ts) from ts_4893.meters where id = 1 limit 1 + id | week(ts) | +====================================== + 1 | 28 | + +taos> select groupid, sum(week(ts)) from ts_4893.meters group by groupid order by groupid + groupid | sum(week(ts)) | +================================== + 1 | 2669490 | + diff --git a/tests/army/query/function/ans/weekday.csv b/tests/army/query/function/ans/weekday.csv index 39bec5315b..5b3dddebf6 100644 --- a/tests/army/query/function/ans/weekday.csv +++ b/tests/army/query/function/ans/weekday.csv @@ -1,100 +1,272 @@ -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -2 -2 -0 -2 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 + +taos> select WEEKDAY('2020-01-01 00:00:00') + weekday('2020-01-01 00:00:00') | +================================= + 2 | + +taos> select WEEKDAY('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekday('2020-01-01 00:00:00') | +================================= + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + +taos> select WEEKDAY('2021-01-01 00:00:00') + weekday('2021-01-01 00:00:00') | +================================= + 4 | + +taos> select WEEKDAY('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekday('2021-01-01 00:00:00') | +================================= + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select WEEKDAY('1998-01-01 00:00:00') + weekday('1998-01-01 00:00:00') | +================================= + 3 | + +taos> select WEEKDAY('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekday('1998-01-01 00:00:00') | +================================= + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + +taos> select WEEKDAY('1998-12-31 00:00:00') + weekday('1998-12-31 00:00:00') | +================================= + 3 | + +taos> select WEEKDAY('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 + weekday('1998-12-31 00:00:00') | +================================= + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + +taos> select WEEKDAY('2000-01-06 00:00:00') + weekday('2000-01-06 00:00:00') | +================================= + 3 | + +taos> select WEEKDAY('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 + weekday('2000-01-06 00:00:00') | +================================= + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + 3 | + +taos> select WEEKDAY(1725095657) + weekday(1725095657) | +======================== + 2 | + +taos> select WEEKDAY(1725095657) from ts_4893.meters order by ts limit 10 + weekday(1725095657) | +======================== + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + 2 | + +taos> select WEEKDAY(ts) from ts_4893.meters order by ts limit 10 + weekday(ts) | +======================== + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select weekday('2020-01-01') + weekday('2020-01-01') | +======================== + 2 | + +taos> select weekday(1721020591) + weekday(1721020591) | +======================== + 2 | + +taos> select weekday(1721020666229) + weekday(1721020666229) | +========================= + 0 | + +taos> select weekday('2020-01-01 00:00:00') + weekday('2020-01-01 00:00:00') | +================================= + 2 | + +taos> select weekday(ts) from ts_4893.d0 order by ts limit 10 + weekday(ts) | +======================== + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select weekday(ts) from ts_4893.meters order by ts limit 10 + weekday(ts) | +======================== + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select weekday(null) + weekday(null) | +======================== + NULL | + +taos> select weekday('abc') + weekday('abc') | +======================== + NULL | + +taos> select weekday('1721020591') + weekday('1721020591') | +======================== + NULL | + +taos> select weekday('1721020666229') + weekday('1721020666229') | +=========================== + NULL | + +taos> select weekday('01/01/2020') + weekday('01/01/2020') | +======================== + NULL | + +taos> select weekday('20200101') + weekday('20200101') | +======================== + NULL | + +taos> select weekday('20/01/01') + weekday('20/01/01') | +======================== + NULL | + +taos> select weekday('11/01/32') + weekday('11/01/32') | +======================== + NULL | + +taos> select weekday('01-JAN-20') + weekday('01-JAN-20') | +======================== + NULL | + +taos> select weekday('2024-02-29') + weekday('2024-02-29') | +======================== + 3 | + +taos> select weekday('2023-09-24') + weekday('2023-09-24') | +======================== + 6 | + +taos> select weekday('2023-09-25') + weekday('2023-09-25') | +======================== + 0 | + +taos> select weekday('9999-12-31') + weekday('9999-12-31') | +======================== + 4 | + +taos> select weekday(name) from ts_4893.meters limit 1 + weekday(name) | +======================== + NULL | + +taos> select weekday(ts), dayofweek(ts) from ts_4893.meters limit 1 + weekday(ts) | dayofweek(ts) | +================================================ + 4 | 6 | + +taos> select weekday(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 + weekday(timediff(ts, '2024-10-10 09:36:50.172')) | +=================================================== + 4 | + +taos> select weekday(ts) from ts_4893.meters limit 1 + weekday(ts) | +======================== + 4 | + +taos> select id, weekday(ts) from ts_4893.meters where id = 1 limit 1 + id | weekday(ts) | +====================================== + 1 | 4 | + +taos> select groupid, sum(weekday(ts)) from ts_4893.meters group by groupid order by groupid + groupid | sum(weekday(ts)) | +================================== + 1 | 300007 | + diff --git a/tests/army/query/function/ans/weekofyear.csv b/tests/army/query/function/ans/weekofyear.csv index 09c865e8b2..2d9697a4c5 100644 --- a/tests/army/query/function/ans/weekofyear.csv +++ b/tests/army/query/function/ans/weekofyear.csv @@ -1,99 +1,267 @@ -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -53 -53 -53 -53 -53 -53 -53 -53 -53 -53 -53 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -53 -53 -53 -53 -53 -53 -53 -53 -53 -53 -53 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -1 -4 -29 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 -28 + +taos> select WEEKOFYEAR('2020-01-01 00:00:00') + weekofyear('2020-01-01 00:00:00') | +==================================== + 1 | + +taos> select WEEKOFYEAR('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekofyear('2020-01-01 00:00:00') | +==================================== + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select WEEKOFYEAR('2021-01-01 00:00:00') + weekofyear('2021-01-01 00:00:00') | +==================================== + 53 | + +taos> select WEEKOFYEAR('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekofyear('2021-01-01 00:00:00') | +==================================== + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + +taos> select WEEKOFYEAR('1998-01-01 00:00:00') + weekofyear('1998-01-01 00:00:00') | +==================================== + 1 | + +taos> select WEEKOFYEAR('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 + weekofyear('1998-01-01 00:00:00') | +==================================== + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select WEEKOFYEAR('1998-12-31 00:00:00') + weekofyear('1998-12-31 00:00:00') | +==================================== + 53 | + +taos> select WEEKOFYEAR('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 + weekofyear('1998-12-31 00:00:00') | +==================================== + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + 53 | + +taos> select WEEKOFYEAR('2000-01-06 00:00:00') + weekofyear('2000-01-06 00:00:00') | +==================================== + 1 | + +taos> select WEEKOFYEAR('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 + weekofyear('2000-01-06 00:00:00') | +==================================== + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + 1 | + +taos> select WEEKOFYEAR(1725095657) + weekofyear(1725095657) | +========================= + 4 | + +taos> select WEEKOFYEAR(1725095657) from ts_4893.meters order by ts limit 10 + weekofyear(1725095657) | +========================= + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + 4 | + +taos> select WEEKOFYEAR(ts) from ts_4893.meters order by ts limit 10 + weekofyear(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select weekofyear('2020-01-01') + weekofyear('2020-01-01') | +=========================== + 1 | + +taos> select weekofyear(1721020666) + weekofyear(1721020666) | +========================= + 4 | + +taos> select weekofyear(1721020666229) + weekofyear(1721020666229) | +============================ + 29 | + +taos> select weekofyear(ts) from ts_4893.d0 order by ts limit 10 + weekofyear(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select weekofyear(ts) from ts_4893.meters order by ts limit 10 + weekofyear(ts) | +======================== + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + 28 | + +taos> select weekofyear(null) + weekofyear(null) | +======================== + NULL | + +taos> select weekofyear('1721020591') + weekofyear('1721020591') | +=========================== + NULL | + +taos> select weekofyear('1721020666229') + weekofyear('1721020666229') | +============================== + NULL | + +taos> select weekofyear('abc') + weekofyear('abc') | +======================== + NULL | + +taos> select weekofyear('01/01/2020') + weekofyear('01/01/2020') | +=========================== + NULL | + +taos> select weekofyear('20200101') + weekofyear('20200101') | +========================= + NULL | + +taos> select weekofyear('20/01/01') + weekofyear('20/01/01') | +========================= + NULL | + +taos> select weekofyear('11/01/31') + weekofyear('11/01/31') | +========================= + NULL | + +taos> select weekofyear('01-JAN-20') + weekofyear('01-JAN-20') | +========================== + NULL | + +taos> select weekofyear('2024-02-29') + weekofyear('2024-02-29') | +=========================== + 9 | + +taos> select weekofyear('2024-01-01') + weekofyear('2024-01-01') | +=========================== + 1 | + +taos> select weekofyear('2024-12-31') + weekofyear('2024-12-31') | +=========================== + 1 | + +taos> select weekofyear('9999-12-31') + weekofyear('9999-12-31') | +=========================== + 52 | + +taos> select weekofyear(name) from ts_4893.meters limit 1 + weekofyear(name) | +======================== + NULL | + +taos> select weekofyear(ts) from ts_4893.meters limit 1 + weekofyear(ts) | +======================== + 28 | + +taos> select weekofyear(ts), dayofweek(ts) from ts_4893.meters limit 1 + weekofyear(ts) | dayofweek(ts) | +================================================ + 28 | 6 | + +taos> select weekofyear(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 + weekofyear(timediff(ts, '2024-10-10 09:36:50.172')) | +====================================================== + 40 | + +taos> select id, weekofyear(ts) from ts_4893.meters where id = 1 limit 1 + id | weekofyear(ts) | +====================================== + 1 | 28 | + +taos> select groupid, sum(weekofyear(ts)) from ts_4893.meters group by groupid order by groupid + groupid | sum(weekofyear(ts)) | +================================== + 1 | 2720120 | + diff --git a/tests/army/query/function/in/ascii.in b/tests/army/query/function/in/ascii.in index 638fcd8d7c..dc4c229bd3 100644 --- a/tests/army/query/function/in/ascii.in +++ b/tests/army/query/function/in/ascii.in @@ -1,26 +1,43 @@ -select ASCII('hello'); -select ASCII('hello world'); -select ASCII('hello world!'); -select ASCII('hello,world.你好,世界。'); -select ASCII('北京涛思数据科技有限公司'); -select ASCII('hello') + 1; -select ASCII('hello') - 1; -select ASCII('hello') from ts_4893.meters limit 5; -select ASCII('hello') + 1 from ts_4893.meters limit 1; -select ASCII('hello') + ASCII('hello') from ts_4893.meters limit 1; -select ASCII(nch1) from ts_4893.meters order by ts limit 5; -select ASCII(var1) from ts_4893.meters order by ts limit 5; -select ASCII(concat(nch1,var1)) from ts_4893.meters order by ts limit 5; -select ASCII(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5; -select pow(ASCII(nch1), 2) from ts_4893.meters order by ts limit 5; -select sqrt(ASCII(nch1)) from ts_4893.meters order by ts limit 5; -select cast(ASCII(nch1) as int) from ts_4893.meters order by ts limit 5; -select ascii('taos'); -select ascii('t'); -select ascii('\''); -select ascii(name) from ts_4893.d0 order by ts limit 10; -select ascii(name) from ts_4893.meters order by ts limit 10; -select ascii(nch1) from ts_4893.d0 order by ts limit 10; -select ascii(nch1) from ts_4893.meters order by ts limit 10; -select ascii(var1) from ts_4893.d0 order by ts limit 10; -select ascii(var1) from ts_4893.meters order by ts limit 10; +select ASCII('hello') +select ASCII('hello world') +select ASCII('hello world!') +select ASCII('hello,world.你好,世界。') +select ASCII('北京涛思数据科技有限公司') +select ASCII('hello') + 1 +select ASCII('hello') - 1 +select ASCII('hello') from ts_4893.meters limit 5 +select ASCII('hello') + 1 from ts_4893.meters limit 1 +select ASCII('hello') + ASCII('hello') from ts_4893.meters limit 1 +select ASCII(nch1) from ts_4893.meters order by ts limit 5 +select ASCII(var1) from ts_4893.meters order by ts limit 5 +select ASCII(concat(nch1,var1)) from ts_4893.meters order by ts limit 5 +select ASCII(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5 +select pow(ASCII(nch1), 2) from ts_4893.meters order by ts limit 5 +select sqrt(ASCII(nch1)) from ts_4893.meters order by ts limit 5 +select cast(ASCII(nch1) as int) from ts_4893.meters order by ts limit 5 +select ascii('taos') +select ascii('t') +select ascii('\'') +select ascii(name) from ts_4893.d0 order by ts limit 10 +select ascii(name) from ts_4893.meters order by ts limit 10 +select ascii(nch1) from ts_4893.d0 order by ts limit 10 +select ascii(nch1) from ts_4893.meters order by ts limit 10 +select ascii(var1) from ts_4893.d0 order by ts limit 10 +select ascii(var1) from ts_4893.meters order by ts limit 10 +select ascii(null) +select ascii('0') +select ascii(' ') +select ascii('~') +select ascii('中') +select ascii('é') +select ascii('!@#') +select ascii('Hello') +select ascii('123abc') +select ascii(concat('A', 'B')) +select ascii(char(65)) +select ascii(upper('b')) +select ascii(trim(' A ')) +select name, ascii(name) from ts_4893.meters limit 1 +select name, ascii(substring(name, 1, 1)) from ts_4893.meters limit 1 +select nch1, ascii(nch1) from ts_4893.meters limit 1 +select var1, ascii(var1) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/char.in b/tests/army/query/function/in/char.in index eb1d1b954e..9a0b2a284d 100644 --- a/tests/army/query/function/in/char.in +++ b/tests/army/query/function/in/char.in @@ -1,15 +1,20 @@ -select CHAR(77); -select CHAR(77.5); -select CHAR(100); -select CHAR(77) from ts_4893.meters limit 5; -select CHAR(77,78,79,80,81) from ts_4893.meters limit 5; -select CHAR(77*256+77) from ts_4893.meters limit 5; -select concat(CHAR(77),CHAR(78)) from ts_4893.meters limit 5; -select cast(CHAR(49) as int); -select CHAR(id + 77) from ts_4893.meters order by ts limit 5;; -select CONCAT(CHAR(id + 77),CHAR(id + 77),CHAR(id + 77)) from ts_4893.meters limit 5; -select CHAR(id+77, id+77, id+77, id+77, id+77) from ts_4893.meters limit 5; -select char(77); -select char(77 * 256 + 77); -select char('123'); -select char(77, NULL, '123'); +select CHAR(77) +select CHAR(77.5) +select CHAR(100) +select CHAR(77) from ts_4893.meters limit 5 +select CHAR(77,78,79,80,81) from ts_4893.meters limit 5 +select CHAR(77*256+77) from ts_4893.meters limit 5 +select concat(CHAR(77),CHAR(78)) from ts_4893.meters limit 5 +select cast(CHAR(49) as int) +select CHAR(id + 77) from ts_4893.meters order by ts limit 5; +select CONCAT(CHAR(id + 77),CHAR(id + 77),CHAR(id + 77)) from ts_4893.meters limit 5 +select CHAR(id+77, id+77, id+77, id+77, id+77) from ts_4893.meters limit 5 +select char(77) +select char(77 * 256 + 77) +select char('123') +select char(77, NULL, '123') +select char(null) +select char('ustc') +select char(65.99) +select char(65, 66, 67) +select char(72, 101, 108, 108, 111) diff --git a/tests/army/query/function/in/char_length.in b/tests/army/query/function/in/char_length.in index eb0e7424fc..31aafaea07 100644 --- a/tests/army/query/function/in/char_length.in +++ b/tests/army/query/function/in/char_length.in @@ -1,25 +1,38 @@ -select CHAR_LENGTH('hello'); -select CHAR_LENGTH('hello world'); -select CHAR_LENGTH('hello world!'); -select CHAR_LENGTH('hello,world.你好,世界。'); -select CHAR_LENGTH('北京涛思数据科技有限公司'); -select CHAR_LENGTH('hello') + 1; -select CHAR_LENGTH('hello') - 1; -select CHAR_LENGTH('hello') from ts_4893.meters limit 5; -select CHAR_LENGTH('hello') + 1 from ts_4893.meters limit 1; -select CHAR_LENGTH('hello') + CHAR_LENGTH('hello') from ts_4893.meters limit 1; -select CHAR_LENGTH(nch1) from ts_4893.meters order by ts limit 5; -select CHAR_LENGTH(var1) from ts_4893.meters order by ts limit 5; -select CHAR_LENGTH(concat(nch1,var1)) from ts_4893.meters order by ts limit 5; -select CHAR_LENGTH(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5; -select pow(CHAR_LENGTH(nch1), 2) from ts_4893.meters order by ts limit 5; -select sqrt(CHAR_LENGTH(nch1)) from ts_4893.meters order by ts limit 5; -select cast(CHAR_LENGTH(nch1) as int) from ts_4893.meters order by ts limit 5; -select char_length('taos'); -select char_length('涛思'); -select char_length('涛思taos'); -select char_length('tao\'s'); -select char_length(nch1) from ts_4893.d0 limit 10; -select char_length(nch1) from ts_4893.meters limit 10; -select char_length(var1) from ts_4893.d0 limit 10; -select char_length(var1) from ts_4893.meters limit 10; +select CHAR_LENGTH('hello') +select CHAR_LENGTH('hello world') +select CHAR_LENGTH('hello world!') +select CHAR_LENGTH('hello,world.你好,世界。') +select CHAR_LENGTH('北京涛思数据科技有限公司') +select CHAR_LENGTH('hello') + 1 +select CHAR_LENGTH('hello') - 1 +select CHAR_LENGTH('hello') from ts_4893.meters limit 5 +select CHAR_LENGTH('hello') + 1 from ts_4893.meters limit 1 +select CHAR_LENGTH('hello') + CHAR_LENGTH('hello') from ts_4893.meters limit 1 +select CHAR_LENGTH(nch1) from ts_4893.meters order by ts limit 5 +select CHAR_LENGTH(var1) from ts_4893.meters order by ts limit 5 +select CHAR_LENGTH(concat(nch1,var1)) from ts_4893.meters order by ts limit 5 +select CHAR_LENGTH(cast(nch1 as varchar)) from ts_4893.meters order by ts limit 5 +select pow(CHAR_LENGTH(nch1), 2) from ts_4893.meters order by ts limit 5 +select sqrt(CHAR_LENGTH(nch1)) from ts_4893.meters order by ts limit 5 +select cast(CHAR_LENGTH(nch1) as int) from ts_4893.meters order by ts limit 5 +select char_length('taos') +select char_length('涛思') +select char_length('涛思taos') +select char_length('tao\'s') +select char_length(nch1) from ts_4893.d0 limit 10 +select char_length(nch1) from ts_4893.meters limit 10 +select char_length(var1) from ts_4893.d0 limit 10 +select char_length(var1) from ts_4893.meters limit 10 +select char_length(null) +select char_length('') +select char_length('あいうえお') +select min(char_length(name)) from ts_4893.meters +select max(char_length(name)) from ts_4893.meters +select trim(name), char_length(trim(name)) from ts_4893.meters limit 1 +select upper(name), char_length(upper(name)) from ts_4893.meters limit 1 +select concat(name, ' - ', location), char_length(concat(name, ' - ', location)) from ts_4893.meters limit 1 +select substring(name, 1, 5), char_length(substring(name, 1, 5)) from ts_4893.meters limit 1 +select name, char_length(name) from ts_4893.meters limit 1 +select nch1, char_length(nch1) from ts_4893.meters limit 1 +select groupid, max(char_length(name)) from ts_4893.meters group by groupid order by ts +select location, avg(char_length(name)) from ts_4893.meters group by location order by location diff --git a/tests/army/query/function/in/dayofweek.in b/tests/army/query/function/in/dayofweek.in index 66d6599963..49be283860 100644 --- a/tests/army/query/function/in/dayofweek.in +++ b/tests/army/query/function/in/dayofweek.in @@ -1,18 +1,36 @@ -select DAYOFWEEK('2020-01-01 00:00:00'); -select DAYOFWEEK('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select DAYOFWEEK('2021-01-01 00:00:00'); -select DAYOFWEEK('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select DAYOFWEEK('1998-01-01 00:00:00'); -select DAYOFWEEK('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select DAYOFWEEK('1998-12-31 00:00:00'); -select DAYOFWEEK('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10; -select DAYOFWEEK('2000-01-06 00:00:00'); -select DAYOFWEEK('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10; -select DAYOFWEEK(1725095657); -select DAYOFWEEK(1725095657) from ts_4893.meters order by ts limit 10; -select DAYOFWEEK(ts) from ts_4893.meters order by ts limit 10; -select dayofweek('2020-01-01'); -select dayofweek(1721020666); -select dayofweek(1721020666229); -select dayofweek(ts) from ts_4893.d0 order by ts limit 10; -select dayofweek(ts) from ts_4893.meters order by ts limit 10; +select DAYOFWEEK('2020-01-01 00:00:00') +select DAYOFWEEK('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select DAYOFWEEK('2021-01-01 00:00:00') +select DAYOFWEEK('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select DAYOFWEEK('1998-01-01 00:00:00') +select DAYOFWEEK('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select DAYOFWEEK('1998-12-31 00:00:00') +select DAYOFWEEK('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 +select DAYOFWEEK('2000-01-06 00:00:00') +select DAYOFWEEK('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 +select DAYOFWEEK(1725095657) +select DAYOFWEEK(1725095657) from ts_4893.meters order by ts limit 10 +select DAYOFWEEK(ts) from ts_4893.meters order by ts limit 10 +select dayofweek(null) +select dayofweek('1721020591') +select dayofweek('1721020666229') +select dayofweek('abc') +select dayofweek('01/01/2020') +select dayofweek('20200101') +select dayofweek('20/01/01') +select dayofweek('11/01/31') +select dayofweek('01-JAN-20') +select dayofweek('2020-01-01') +select dayofweek(1721020666) +select dayofweek(1721020666229) +select dayofweek(ts) from ts_4893.d0 order by ts limit 10 +select dayofweek(ts) from ts_4893.meters order by ts limit 10 +select dayofweek('2024-02-29') +select dayofweek('2024-01-01') +select dayofweek('2024-12-31') +select dayofweek('9999-12-31') +select dayofweek(ts) from ts_4893.meters limit 1 +select dayofweek(name) from ts_4893.meters limit 1 +select dayofweek(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 +select id, dayofweek(ts) from ts_4893.meters where id = 1 limit 1 +select groupid, sum(dayofweek(ts)) from ts_4893.meters group by groupid order by groupid diff --git a/tests/army/query/function/in/degrees.in b/tests/army/query/function/in/degrees.in index 54672c0722..14c7d7eeb1 100644 --- a/tests/army/query/function/in/degrees.in +++ b/tests/army/query/function/in/degrees.in @@ -1,32 +1,47 @@ -select DEGREES(0); -select DEGREES(1); -select DEGREES(1.5); -select DEGREES(100); -select DEGREES(-1); -select DEGREES(-1.5); -select DEGREES(-100); -select DEGREES(1) + 1; -select DEGREES(1) - 1; -select DEGREES(1) * 1; -select DEGREES(1) / 1; -select DEGREES(1) from ts_4893.meters limit 5; -select DEGREES(1) + 1 from ts_4893.meters limit 1; -select DEGREES(1) - 1 from ts_4893.meters limit 1; -select DEGREES(1) * 2 from ts_4893.meters limit 1; -select DEGREES(1) / 2 from ts_4893.meters limit 1; -select DEGREES(2) + DEGREES(1) from ts_4893.meters limit 1; -select DEGREES(2) - DEGREES(1) from ts_4893.meters limit 1; -select DEGREES(2) * DEGREES(1) from ts_4893.meters limit 1; -select DEGREES(2) / DEGREES(1) from ts_4893.meters limit 1; -select DEGREES(1) + id from ts_4893.meters order by ts limit 5; -select DEGREES(id) + id from ts_4893.meters order by ts limit 5; -select DEGREES(abs(10)); -select DEGREES(PI()); -select abs(DEGREES(10)); -select pow(DEGREES(10), 2); -select sqrt(DEGREES(10)); -select cast(DEGREES(10) as int); -select DEGREES(sqrt(id)) from ts_4893.meters order by ts limit 5; -select degrees(pi()); -select degrees(current) from ts_4893.d0 order by ts limit 10; -select degrees(current) from ts_4893.meters order by ts limit 10; +select DEGREES(0) +select DEGREES(1) +select DEGREES(1.5) +select DEGREES(100) +select DEGREES(-1) +select DEGREES(-1.5) +select DEGREES(-100) +select DEGREES(1) + 1 +select DEGREES(1) - 1 +select DEGREES(1) * 1 +select DEGREES(1) / 1 +select DEGREES(1) from ts_4893.meters limit 5 +select DEGREES(1) + 1 from ts_4893.meters limit 1 +select DEGREES(1) - 1 from ts_4893.meters limit 1 +select DEGREES(1) * 2 from ts_4893.meters limit 1 +select DEGREES(1) / 2 from ts_4893.meters limit 1 +select DEGREES(2) + DEGREES(1) from ts_4893.meters limit 1 +select DEGREES(2) - DEGREES(1) from ts_4893.meters limit 1 +select DEGREES(2) * DEGREES(1) from ts_4893.meters limit 1 +select DEGREES(2) / DEGREES(1) from ts_4893.meters limit 1 +select DEGREES(1) + id from ts_4893.meters order by ts limit 5 +select DEGREES(id) + id from ts_4893.meters order by ts limit 5 +select DEGREES(abs(10)) +select DEGREES(PI()) +select abs(DEGREES(10)) +select pow(DEGREES(10), 2) +select sqrt(DEGREES(10)) +select cast(DEGREES(10) as int) +select DEGREES(sqrt(id)) from ts_4893.meters order by ts limit 5 +select degrees(pi()) +select degrees(current) from ts_4893.d0 order by ts limit 10 +select degrees(current) from ts_4893.meters order by ts limit 10 +select degrees(null) +select degrees(-5) +select degrees(3.14) +select degrees(2*pi()) +select degrees(pi()/2) +select degrees(-pi()/2) +select degrees(1000000) +select degrees(sin(1)) +select degrees(cos(1)) +select degrees(tan(1)) +select degrees(radians(90)) +select degrees(atan(1)) +select degrees(phase) from ts_4893.meters limit 1 +select degrees(current) from ts_4893.meters limit 1 +select degrees(voltage) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/exp.in b/tests/army/query/function/in/exp.in index 1af149d9cc..e89e13fcb2 100755 --- a/tests/army/query/function/in/exp.in +++ b/tests/army/query/function/in/exp.in @@ -1,32 +1,45 @@ -select EXP(0); -select EXP(1); -select EXP(1.5); -select EXP(100); -select EXP(-1); -select EXP(-1.5); -select EXP(-100); -select EXP(1) + 1; -select EXP(1) - 1; -select EXP(1) * 1; -select EXP(1) / 1; -select exp(1) from ts_4893.meters limit 5; -select exp(1) + 1 from ts_4893.meters limit 1; -select exp(1) - 1 from ts_4893.meters limit 1; -select exp(1) * 2 from ts_4893.meters limit 1; -select exp(1) / 2 from ts_4893.meters limit 1; -select exp(2) + exp(1) from ts_4893.meters limit 1; -select exp(2) - exp(1) from ts_4893.meters limit 1; -select exp(2) * exp(1) from ts_4893.meters limit 1; -select exp(2) / exp(1) from ts_4893.meters limit 1; -select exp(1) + id from ts_4893.meters order by ts limit 5; -select exp(id) + id from ts_4893.meters order by ts limit 5; -select abs(EXP(10)); -select pow(EXP(10), 2); -select sqrt(EXP(10)); -select cast(EXP(10) as int); -select EXP(sqrt(id)) from ts_4893.meters order by ts limit 5; -select EXP(EXP(EXP(EXP(0)))); -select exp(2); -select exp(0.5); -select exp(current) from ts_4893.d0 order by ts limit 10; -select exp(current) from ts_4893.meters order by ts limit 10; +select EXP(0) +select EXP(1) +select EXP(1.5) +select EXP(100) +select EXP(-1) +select EXP(-1.5) +select EXP(-100) +select EXP(1) + 1 +select EXP(1) - 1 +select EXP(1) * 1 +select EXP(1) / 1 +select exp(1) from ts_4893.meters limit 5 +select exp(1) + 1 from ts_4893.meters limit 1 +select exp(1) - 1 from ts_4893.meters limit 1 +select exp(1) * 2 from ts_4893.meters limit 1 +select exp(1) / 2 from ts_4893.meters limit 1 +select exp(2) + exp(1) from ts_4893.meters limit 1 +select exp(2) - exp(1) from ts_4893.meters limit 1 +select exp(2) * exp(1) from ts_4893.meters limit 1 +select exp(2) / exp(1) from ts_4893.meters limit 1 +select exp(1) + id from ts_4893.meters order by ts limit 5 +select exp(id) + id from ts_4893.meters order by ts limit 5 +select abs(EXP(10)) +select pow(EXP(10), 2) +select sqrt(EXP(10)) +select cast(EXP(10) as int) +select EXP(sqrt(id)) from ts_4893.meters order by ts limit 5 +select EXP(EXP(EXP(EXP(0)))) +select exp(2) +select exp(0.5) +select exp(current) from ts_4893.d0 order by ts limit 10 +select exp(current) from ts_4893.meters order by ts limit 10 +select exp(null) +select exp(100000) +select exp(-1000) +select exp(-9999999999) +select exp(0.0001) +select exp(pi()) +select exp(voltage) from ts_4893.meters limit 1 +select exp(current) from ts_4893.meters limit 1 +select exp(phase) from ts_4893.meters limit 1 +select exp(voltage + current) from ts_4893.meters limit 1 +select exp(abs(current)) from ts_4893.meters limit 1 +select exp(log(voltage)) from ts_4893.meters limit 1 +select round(exp(voltage), 2) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/ln.in b/tests/army/query/function/in/ln.in index eb3f3281d5..d0c5cc0744 100755 --- a/tests/army/query/function/in/ln.in +++ b/tests/army/query/function/in/ln.in @@ -1,29 +1,46 @@ -select LN(100); -select LN(1.5); -select LN(100); -select LN(100) + 1; -select LN(100) - 1; -select LN(100) * 1; -select LN(100) / 1; -select LN(100) from ts_4893.meters limit 5; -select LN(100) + 1 from ts_4893.meters limit 1; -select LN(100) - 1 from ts_4893.meters limit 1; -select LN(100) * 2 from ts_4893.meters limit 1; -select LN(100) / 2 from ts_4893.meters limit 1; -select LN(2) + LN(100) from ts_4893.meters limit 1; -select LN(2) - LN(100) from ts_4893.meters limit 1; -select LN(2) * LN(100) from ts_4893.meters limit 1; -select LN(2) / LN(100) from ts_4893.meters limit 1; -select LN(100) + id from ts_4893.meters order by ts limit 5; -select LN(id + 1) + id from ts_4893.meters order by ts limit 5; -select abs(LN(10)); -select pow(LN(10), 2); -select sqrt(LN(10)); -select cast(LN(10) as int); -select LN(sqrt(id) + 1) from ts_4893.meters order by ts limit 5; -select LN(LN(LN(LN(10000)))); -select LN(EXP(2)); -select ln(10); -select ln(pi()); -select ln(current) from ts_4893.d0 order by ts limit 10; -select ln(current) from ts_4893.meters order by ts limit 10; +select LN(100) +select LN(1.5) +select LN(100) +select LN(100) + 1 +select LN(100) - 1 +select LN(100) * 1 +select LN(100) / 1 +select LN(100) from ts_4893.meters limit 5 +select LN(100) + 1 from ts_4893.meters limit 1 +select LN(100) - 1 from ts_4893.meters limit 1 +select LN(100) * 2 from ts_4893.meters limit 1 +select LN(100) / 2 from ts_4893.meters limit 1 +select LN(2) + LN(100) from ts_4893.meters limit 1 +select LN(2) - LN(100) from ts_4893.meters limit 1 +select LN(2) * LN(100) from ts_4893.meters limit 1 +select LN(2) / LN(100) from ts_4893.meters limit 1 +select LN(100) + id from ts_4893.meters order by ts limit 5 +select LN(id + 1) + id from ts_4893.meters order by ts limit 5 +select ln(null) +select ln(0) +select ln(-5) +select abs(LN(10)) +select pow(LN(10), 2) +select sqrt(LN(10)) +select cast(LN(10) as int) +select LN(sqrt(id) + 1) from ts_4893.meters order by ts limit 5 +select LN(LN(LN(LN(10000)))) +select LN(EXP(2)) +select ln(10) +select ln(pi()) +select ln(current) from ts_4893.d0 order by ts limit 10 +select ln(current) from ts_4893.meters order by ts limit 10 +select ln(1) +select ln(20) +select ln(100) +select ln(99999999999999) +select ln(0.1) +select ln(2.718) +select ln(exp(1)) +select ln(voltage) from ts_4893.meters where voltage > 0 limit 1 +select ln(current) from ts_4893.meters where current > 0 limit 1 +select ln(phase) from ts_4893.meters where phase > 0 limit 1 +select ln(exp(voltage)) from ts_4893.meters where voltage > 0 limit 1 +select ln(abs(current)) from ts_4893.meters where current != 0 limit 1 +select ln(sqrt(phase)) from ts_4893.meters where phase >= 0 limit 1 +select ln(log(current)) from ts_4893.meters where current > 1 limit 1 diff --git a/tests/army/query/function/in/max.in b/tests/army/query/function/in/max.in index 8415983989..efd4620f7b 100644 --- a/tests/army/query/function/in/max.in +++ b/tests/army/query/function/in/max.in @@ -1,16 +1,28 @@ -select MAX(id) from ts_4893.meters; -select MAX(current) from ts_4893.meters; -select MAX(voltage) from ts_4893.meters; -select MAX(name) from ts_4893.meters; -select MAX(nch1) from ts_4893.meters; -select MAX(nch2) from ts_4893.meters; -select MAX(var1) from ts_4893.meters; -select MAX(var2) from ts_4893.meters; -select MAX(id) from ts_4893.meters interval(60d); -select MAX(current) from ts_4893.meters interval(60d); -select MAX(voltage) from ts_4893.meters interval(60d); -select MAX(name) from ts_4893.meters interval(60d); -select MAX(nch1) from ts_4893.meters interval(60d); -select MAX(nch2) from ts_4893.meters interval(60d); -select MAX(var1) from ts_4893.meters interval(60d); -select MAX(var2) from ts_4893.meters interval(60d); \ No newline at end of file +select MAX(current) from ts_4893.meters +select MAX(voltage) from ts_4893.meters +select MAX(name) from ts_4893.meters +select MAX(nch1) from ts_4893.meters +select MAX(nch2) from ts_4893.meters +select MAX(var1) from ts_4893.meters +select MAX(var2) from ts_4893.meters +select MAX(id) from ts_4893.meters interval(60d) +select MAX(current) from ts_4893.meters interval(60d) +select MAX(voltage) from ts_4893.meters interval(60d) +select MAX(name) from ts_4893.meters interval(60d) +select MAX(nch1) from ts_4893.meters interval(60d) +select MAX(nch2) from ts_4893.meters interval(60d) +select MAX(var1) from ts_4893.meters interval(60d) +select MAX(var2) from ts_4893.meters interval(60d) +select max(null) from ts_4893.meters +select max(id) from ts_4893.meters +select max(id) from ts_4893.meters where id > 0 +select max(id) from ts_4893.meters where id <= 0 +select max(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' +select max(voltage) from ts_4893.meters where voltage is not null +select max(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) +select round(max(current), 2) from ts_4893.meters +select pow(max(current), 2) from ts_4893.meters +select log(max(voltage) + 1) from ts_4893.meters +select groupid, max(voltage) from ts_4893.meters group by groupid order by groupid +select location, max(id) from ts_4893.meters group by location order by location +select location, max(current) from ts_4893.meters group by location order by location diff --git a/tests/army/query/function/in/min.in b/tests/army/query/function/in/min.in index 5f6c516bd7..910b8cc7bd 100644 --- a/tests/army/query/function/in/min.in +++ b/tests/army/query/function/in/min.in @@ -1,16 +1,28 @@ -select MIN(id) from ts_4893.meters; -select MIN(current) from ts_4893.meters; -select MIN(voltage) from ts_4893.meters; -select MIN(name) from ts_4893.meters; -select MIN(nch1) from ts_4893.meters; -select MIN(nch2) from ts_4893.meters; -select MIN(var1) from ts_4893.meters; -select MIN(var2) from ts_4893.meters; -select MIN(id) from ts_4893.meters interval(60d); -select MIN(current) from ts_4893.meters interval(60d); -select MIN(voltage) from ts_4893.meters interval(60d); -select MIN(name) from ts_4893.meters interval(60d); -select MIN(nch1) from ts_4893.meters interval(60d); -select MIN(nch2) from ts_4893.meters interval(60d); -select MIN(var1) from ts_4893.meters interval(60d); -select MIN(var2) from ts_4893.meters interval(60d); \ No newline at end of file +select MIN(id) from ts_4893.meters +select MIN(current) from ts_4893.meters +select MIN(voltage) from ts_4893.meters +select MIN(name) from ts_4893.meters +select MIN(nch1) from ts_4893.meters +select MIN(nch2) from ts_4893.meters +select MIN(var1) from ts_4893.meters +select MIN(var2) from ts_4893.meters +select MIN(id) from ts_4893.meters interval(60d) +select MIN(current) from ts_4893.meters interval(60d) +select MIN(voltage) from ts_4893.meters interval(60d) +select MIN(name) from ts_4893.meters interval(60d) +select MIN(nch1) from ts_4893.meters interval(60d) +select MIN(nch2) from ts_4893.meters interval(60d) +select MIN(var1) from ts_4893.meters interval(60d) +select MIN(var2) from ts_4893.meters interval(60d) +select min(null) from ts_4893.meters +select min(id) from ts_4893.meters where id > 0 +select min(id) from ts_4893.meters where id <= 0 +select min(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' +select min(voltage) from ts_4893.meters where voltage is not null +select min(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) +select round(min(current), 2) from ts_4893.meters +select pow(min(current), 2) from ts_4893.meters +select log(min(voltage) + 1) from ts_4893.meters +select groupid, min(voltage) from ts_4893.meters group by groupid order by groupid +select location, min(current) from ts_4893.meters group by location order by location +select location, min(id) from ts_4893.meters group by location order by location diff --git a/tests/army/query/function/in/mod.in b/tests/army/query/function/in/mod.in index d335573cf4..331940a46f 100755 --- a/tests/army/query/function/in/mod.in +++ b/tests/army/query/function/in/mod.in @@ -1,18 +1,36 @@ -select MOD(10.55, 3); -select MOD(10.55, 2); -select MOD(10.55, 1); -select MOD(10.55, -1); -select MOD(10.55, -10); -select MOD(-10.55, 1); -select MOD(99, 1); -select MOD(10.55, 1) + 1; -select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123.123456789, 9), 8), 7), 6), 5), 4), 3); -select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123456789.123456789, -1), -2), -3), -4), -5), -6), -7); -select MOD(87654321.123456789, id + 1) from ts_4893.meters order by ts limit 10; -select MOD(current, id + 1) from ts_4893.meters order by ts limit 10; -select MOD(current, 1) from ts_4893.meters order by ts limit 10; -select MOD(sqrt(current), abs(id + 1)) from ts_4893.meters order by ts limit 10; -select mod(10, -3); -select mod(10, 3); -select mod(id, 3) from ts_4893.d0 order by ts limit 10; -select mod(id, 3) from ts_4893.meters order by ts limit 10; +select MOD(10.55, 3) +select MOD(10.55, 2) +select MOD(10.55, 1) +select MOD(10.55, -1) +select MOD(10.55, -10) +select MOD(-10.55, 1) +select MOD(99, 1) +select MOD(10.55, 1) + 1 +select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123.123456789, 9), 8), 7), 6), 5), 4), 3) +select MOD(MOD(MOD(MOD(MOD(MOD(MOD(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) +select MOD(87654321.123456789, id + 1) from ts_4893.meters order by ts limit 10 +select MOD(current, id + 1) from ts_4893.meters order by ts limit 10 +select MOD(current, 1) from ts_4893.meters order by ts limit 10 +select MOD(sqrt(current), abs(id + 1)) from ts_4893.meters order by ts limit 10 +select mod(10, -3) +select mod(10, 3) +select mod(id, 3) from ts_4893.d0 order by ts limit 10 +select mod(id, 3) from ts_4893.meters order by ts limit 10 +select mod(null, 2) +select mod(10, null) +select mod(10, 0) +select mod(-10, 0) +select mod(5, 0) +select mod(0, 1) +select mod(1, 1) +select mod(5, 2) +select mod(5, -3) +select mod(15, 4) +select mod(-5, 3) +select mod(voltage, 2) from ts_4893.meters limit 1 +select mod(current, 10) from ts_4893.meters limit 1 +select mod(current, log(100)) from ts_4893.meters limit 1 +select mod(phase, 4) from ts_4893.meters limit 1 +select mod(abs(voltage), 3) from ts_4893.meters limit 1 +select mod(phase, sqrt(16)) from ts_4893.meters limit 1 +select mod(round(voltage), 5) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/pi.in b/tests/army/query/function/in/pi.in index dc5d24b655..fd1e3953c6 100644 --- a/tests/army/query/function/in/pi.in +++ b/tests/army/query/function/in/pi.in @@ -19,3 +19,19 @@ select sqrt(pi()) select cast(pi() as int) select pi() select substring_index(null, '.', 2) +select pi() + null +select pi() * 0 +select pi() / 0 +select pi() * 0.5 +select pi() * -1 +select pi() * name from ts_4893.meters limit 1 +select pi() * voltage from ts_4893.meters limit 1 +select pi() * phase * 2 from ts_4893.meters limit 1 +select round(pi(), 6) +select round(pi() * phase, 2) from ts_4893.meters limit 1 +select sqrt(pi() * voltage) from ts_4893.meters limit 1 +select sqrt(current / pi()) from ts_4893.meters limit 1 +select abs(pi() * phase) from ts_4893.meters limit 1 +select log(pi() * voltage) from ts_4893.meters limit 1 +select voltage / pi() from ts_4893.meters limit 1 +select id, case when voltage > 100 then pi() else pi() / 2 end from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/position.in b/tests/army/query/function/in/position.in index 7c682c5c80..088cf6b24c 100644 --- a/tests/army/query/function/in/position.in +++ b/tests/army/query/function/in/position.in @@ -1,40 +1,62 @@ -select POSITION('北' IN '北京涛思'); -select POSITION('涛思' IN '北京涛思'); -select POSITION('a' IN 'abcd'); -select POSITION('e' IN 'abcd'); -select POSITION('好,' IN 'hello,world.你好,世界。'); -select POSITION(',你' IN 'hello,world.你好,世界。'); -select POSITION('world' IN 'hello,world.你好,世界。'); -select POSITION('aaa' IN 'aaaaaaaaa'); -select POSITION(CONCAT('a','b','c') IN CONCAT('abc','def','ghi')); -select POSITION(CONCAT('a','b','d') IN CONCAT('abc','def','ghi')); -select POSITION(nch2 IN nch1) from ts_4893.meters where POSITION(nch2 IN nch1) != 0 order by ts limit 5; -select POSITION(nch2 IN nch1) from ts_4893.meters order by ts limit 5; -select POSITION(var2 IN var1) from ts_4893.meters where POSITION(var2 IN var1) != 0 order by ts limit 5; -select POSITION(var2 IN var1) from ts_4893.meters order by ts limit 5; -select POSITION(var2 IN nch1) from ts_4893.meters where POSITION(var2 IN nch1) != 0 order by ts limit 5; -select POSITION(var2 IN nch1) from ts_4893.meters order by ts limit 5; -select POSITION(nch2 IN var1) from ts_4893.meters where POSITION(nch2 IN var1) != 0 order by ts limit 5; -select POSITION(nch2 IN var1) from ts_4893.meters order by ts limit 5; -select POSITION('a' IN nch1) from ts_4893.meters where POSITION('a' IN nch1) != 0 order by ts limit 5; -select POSITION('a' IN var1) from ts_4893.meters where POSITION('a' IN var1) != 0 order by ts limit 5; -select POSITION('一' IN nch1) from ts_4893.meters where POSITION('一' IN nch1) != 0 order by ts limit 5; -select POSITION('一' IN var1) from ts_4893.meters where POSITION('一' IN var1) != 0 order by ts limit 5; -select POSITION(nch2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(nch2 IN 'abcdefghijklmn') != 0 order by ts limit 5; -select POSITION(var2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(var2 IN 'abcdefghijklmn') != 0 order by ts limit 5; -select POSITION(nch2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(nch2 IN '一二三四五六七八九十') != 0 order by ts limit 5; -select POSITION(var2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(var2 IN '一二三四五六七八九十') != 0 order by ts limit 5; -select ABS(POSITION('aaa' IN 'aaaaaaaaa')); -select POW(POSITION('aaa' IN 'aaaaaaaaa'), 2); -select position('t' in 'taos'); -select position('ustc' in 'taos'); -select position('' in ''); -select position('' in 'taos'); -select position(nch2 in nch1) from ts_4893.d0 order by ts limit 10; -select position(nch2 in nch1) from ts_4893.meters order by ts limit 10; -select position(nch2 in var1) from ts_4893.d0 order by ts limit 10; -select position(nch2 in var1) from ts_4893.meters order by ts limit 10; -select position(var2 in nch1) from ts_4893.d0 order by ts limit 10; -select position(var2 in nch1) from ts_4893.meters order by ts limit 10; -select position(var2 in var1) from ts_4893.d0 order by ts limit 10; -select position(var2 in var1) from ts_4893.meters order by ts limit 10; +select POSITION('北' IN '北京涛思') +select POSITION('涛思' IN '北京涛思') +select POSITION('a' IN 'abcd') +select POSITION('e' IN 'abcd') +select POSITION('好,' IN 'hello,world.你好,世界。') +select POSITION(',你' IN 'hello,world.你好,世界。') +select POSITION('world' IN 'hello,world.你好,世界。') +select POSITION('aaa' IN 'aaaaaaaaa') +select POSITION(CONCAT('a','b','c') IN CONCAT('abc','def','ghi')) +select POSITION(CONCAT('a','b','d') IN CONCAT('abc','def','ghi')) +select POSITION(nch2 IN nch1) from ts_4893.meters where POSITION(nch2 IN nch1) != 0 order by ts limit 5 +select POSITION(nch2 IN nch1) from ts_4893.meters order by ts limit 5 +select POSITION(var2 IN var1) from ts_4893.meters where POSITION(var2 IN var1) != 0 order by ts limit 5 +select POSITION(var2 IN var1) from ts_4893.meters order by ts limit 5 +select POSITION(var2 IN nch1) from ts_4893.meters where POSITION(var2 IN nch1) != 0 order by ts limit 5 +select POSITION(var2 IN nch1) from ts_4893.meters order by ts limit 5 +select POSITION(nch2 IN var1) from ts_4893.meters where POSITION(nch2 IN var1) != 0 order by ts limit 5 +select POSITION(nch2 IN var1) from ts_4893.meters order by ts limit 5 +select POSITION('a' IN nch1) from ts_4893.meters where POSITION('a' IN nch1) != 0 order by ts limit 5 +select POSITION('a' IN var1) from ts_4893.meters where POSITION('a' IN var1) != 0 order by ts limit 5 +select POSITION('一' IN nch1) from ts_4893.meters where POSITION('一' IN nch1) != 0 order by ts limit 5 +select POSITION('一' IN var1) from ts_4893.meters where POSITION('一' IN var1) != 0 order by ts limit 5 +select POSITION(nch2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(nch2 IN 'abcdefghijklmn') != 0 order by ts limit 5 +select POSITION(var2 IN 'abcdefghijklmn') from ts_4893.meters where POSITION(var2 IN 'abcdefghijklmn') != 0 order by ts limit 5 +select POSITION(nch2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(nch2 IN '一二三四五六七八九十') != 0 order by ts limit 5 +select POSITION(var2 IN '一二三四五六七八九十') from ts_4893.meters where POSITION(var2 IN '一二三四五六七八九十') != 0 order by ts limit 5 +select ABS(POSITION('aaa' IN 'aaaaaaaaa')) +select POW(POSITION('aaa' IN 'aaaaaaaaa'), 2) +select position('t' in 'taos') +select position('ustc' in 'taos') +select position('' in '') +select position('' in 'taos') +select position(nch2 in nch1) from ts_4893.d0 order by ts limit 10 +select position(nch2 in nch1) from ts_4893.meters order by ts limit 10 +select position(nch2 in var1) from ts_4893.d0 order by ts limit 10 +select position(nch2 in var1) from ts_4893.meters order by ts limit 10 +select position(var2 in nch1) from ts_4893.d0 order by ts limit 10 +select position(var2 in nch1) from ts_4893.meters order by ts limit 10 +select position(var2 in var1) from ts_4893.d0 order by ts limit 10 +select position(var2 in var1) from ts_4893.meters order by ts limit 10 +select position('t' in null) +select position(null in 'taos') +select position('' in 'A') +select position('A' in 'A') +select position('A' in '') +select position('A' in null) +select position('Z' in 'ABC') +select position('l' in 'Hello') +select position('s' in 'meters') +select position('中' in '中国') +select position('e' in 'é') +select position('W' in 'Hello World') +select position('@' in '!@#') +select position('6' in '12345') +select position('A' in trim(' A ')) +select position('A' in upper('abc')) +select position('B' in concat('A', 'B')) +select position('x' in replace('Hello', 'l', 'x')) +select name, position('e' in name) from ts_4893.meters limit 1 +select name, position('a' in substring(name, 2, 5)) from ts_4893.meters limit 1 +select nch1, position('n' in nch1) from ts_4893.meters limit 1 +select var1, position('1' in var1) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/radians.in b/tests/army/query/function/in/radians.in index 45ef75f0d2..0e41cce64b 100644 --- a/tests/army/query/function/in/radians.in +++ b/tests/army/query/function/in/radians.in @@ -1,32 +1,48 @@ -select RADIANS(0); -select RADIANS(1); -select RADIANS(1.5); -select RADIANS(100); -select RADIANS(-1); -select RADIANS(-1.5); -select RADIANS(-100); -select RADIANS(1) + 1; -select RADIANS(1) - 1; -select RADIANS(1) * 1; -select RADIANS(1) / 1; -select RADIANS(1) from ts_4893.meters limit 5; -select RADIANS(1) + 1 from ts_4893.meters limit 1; -select RADIANS(1) - 1 from ts_4893.meters limit 1; -select RADIANS(1) * 2 from ts_4893.meters limit 1; -select RADIANS(1) / 2 from ts_4893.meters limit 1; -select RADIANS(2) + RADIANS(1) from ts_4893.meters limit 1; -select RADIANS(2) - RADIANS(1) from ts_4893.meters limit 1; -select RADIANS(2) * RADIANS(1) from ts_4893.meters limit 1; -select RADIANS(2) / RADIANS(1) from ts_4893.meters limit 1; -select RADIANS(1) + id from ts_4893.meters order by ts limit 5; -select RADIANS(id) + id from ts_4893.meters order by ts limit 5; -select RADIANS(abs(10)); -select RADIANS(DEGREES(PI())); -select abs(RADIANS(10)); -select pow(RADIANS(10), 2); -select sqrt(RADIANS(10)); -select cast(RADIANS(10) as int); -select RADIANS(sqrt(id)) from ts_4893.meters order by ts limit 5; -select radians(180); -select radians(current) from ts_4893.d0 order by ts limit 10; -select radians(current) from ts_4893.meters order by ts limit 10; +select RADIANS(0) +select RADIANS(1) +select RADIANS(1.5) +select RADIANS(100) +select RADIANS(-1) +select RADIANS(-1.5) +select RADIANS(-100) +select RADIANS(1) + 1 +select RADIANS(1) - 1 +select RADIANS(1) * 1 +select RADIANS(1) / 1 +select RADIANS(1) from ts_4893.meters limit 5 +select RADIANS(1) + 1 from ts_4893.meters limit 1 +select RADIANS(1) - 1 from ts_4893.meters limit 1 +select RADIANS(1) * 2 from ts_4893.meters limit 1 +select RADIANS(1) / 2 from ts_4893.meters limit 1 +select RADIANS(2) + RADIANS(1) from ts_4893.meters limit 1 +select RADIANS(2) - RADIANS(1) from ts_4893.meters limit 1 +select RADIANS(2) * RADIANS(1) from ts_4893.meters limit 1 +select RADIANS(2) / RADIANS(1) from ts_4893.meters limit 1 +select RADIANS(1) + id from ts_4893.meters order by ts limit 5 +select RADIANS(id) + id from ts_4893.meters order by ts limit 5 +select RADIANS(abs(10)) +select RADIANS(DEGREES(PI())) +select abs(RADIANS(10)) +select pow(RADIANS(10), 2) +select sqrt(RADIANS(10)) +select cast(RADIANS(10) as int) +select RADIANS(sqrt(id)) from ts_4893.meters order by ts limit 5 +select radians(180) +select radians(current) from ts_4893.d0 order by ts limit 10 +select radians(current) from ts_4893.meters order by ts limit 10 +select radians(null) +select radians(0) +select radians(45) +select radians(-45) +select radians(90) +select radians(-90) +select radians(360) +select radians(1000000) +select radians(sin(1)) +select radians(cos(1)) +select radians(tan(1)) +select radians(degrees(90)) +select radians(atan(1)) +select radians(current) from ts_4893.meters limit 1 +select radians(voltage) from ts_4893.meters limit 1 +select radians(phase) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/rand.in b/tests/army/query/function/in/rand.in index 185a76d6f9..42075c8067 100644 --- a/tests/army/query/function/in/rand.in +++ b/tests/army/query/function/in/rand.in @@ -1,3 +1,11 @@ -select RAND(1245); -select RAND(id) from ts_4893.d0 limit 10; -select RAND(id) from ts_4893.d0 order by id desc limit 10; \ No newline at end of file +select RAND(1245) +select RAND(id) from ts_4893.d0 limit 10 +select RAND(id) from ts_4893.d0 order by id desc limit 10 +select rand(0) +select rand(1) +select rand(-1) +select rand(12345678901234567890) +select rand(-12345678901234567890) +select rand(12345), rand(12345) +select rand(9999999999) where rand(9999999999) >= 0 and rand(9999999999) < 1 +select rand(id) from ts_4893.meters limit 100 diff --git a/tests/army/query/function/in/repeat.in b/tests/army/query/function/in/repeat.in index a0a74a96cc..4cc99e61be 100644 --- a/tests/army/query/function/in/repeat.in +++ b/tests/army/query/function/in/repeat.in @@ -1,31 +1,53 @@ -select repeat('hello', 1); -select repeat('hello', 20); -SELECT REPEAT('a', 2); -SELECT CONCAT('g',CONCAT(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h'); -SELECT CONCAT('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h'); -SELECT CONCAT_WS('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h'); -select length(concat(repeat("a",3200),repeat("a",3200))); -select length(replace("aaaaa","a",concat(repeat("a",10000),repeat("a",12)))); -select repeat('北京taos', 6); -select repeat(nch1, 6) from ts_4893.meters order by ts limit 5; -select repeat(var1, 6) from ts_4893.meters order by ts limit 5; -select position(nch1 in repeat(nch1,6)) from ts_4893.meters order by ts limit 5; -select position(var1 in repeat(var1,6)) from ts_4893.meters order by ts limit 5; -select position(nch1 in repeat(var1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5; -select position(var1 in repeat(nch1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5; -select repeat(nch1, id) from ts_4893.meters where id > 0 order by ts limit 5; -select repeat(var1, id) from ts_4893.meters where id > 0 order by ts limit 5; -select repeat('nch1', id) from ts_4893.meters where id > 0 order by ts limit 5; -select repeat('var1', id) from ts_4893.meters where id > 0 order by ts limit 5; -select repeat('taos', 1); -select repeat('taos', 2); -select repeat(name, 3) from ts_4893.d0 order by ts limit 10; -select repeat(name, 3) from ts_4893.meters order by ts limit 10; -select repeat(nch1, 3) from ts_4893.d0 order by ts limit 10; -select repeat(nch1, 3) from ts_4893.meters order by ts limit 10; -select repeat(var1, 3) from ts_4893.d0 order by ts limit 10; -select repeat(var1, 3) from ts_4893.meters order by ts limit 10; -select repeat(name, groupid) from ts_4893.d0 order by ts limit 10; -select repeat(name, groupid) from ts_4893.meters order by ts limit 10; -select repeat(nch1, groupid) from ts_4893.d0 order by ts limit 10; -select repeat(nch1, groupid) from ts_4893.meters order by ts limit 10; +select repeat('hello', 1) +select repeat('hello', 20) +SELECT REPEAT('a', 2) +SELECT CONCAT('g',CONCAT(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') +SELECT CONCAT('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') +SELECT CONCAT_WS('g',CONCAT_WS(';',repeat('a',60), repeat('b',60), repeat('c',60), repeat ('d',100)),'h') +select length(concat(repeat("a",3200),repeat("a",3200))) +select length(replace("aaaaa","a",concat(repeat("a",10000),repeat("a",12)))) +select repeat('北京taos', 6) +select repeat(nch1, 6) from ts_4893.meters order by ts limit 5 +select repeat(var1, 6) from ts_4893.meters order by ts limit 5 +select position(nch1 in repeat(nch1,6)) from ts_4893.meters order by ts limit 5 +select position(var1 in repeat(var1,6)) from ts_4893.meters order by ts limit 5 +select position(nch1 in repeat(var1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5 +select position(var1 in repeat(nch1,6)) from ts_4893.meters where nch1 = var1 order by ts limit 5 +select repeat(nch1, id) from ts_4893.meters where id > 0 order by ts limit 5 +select repeat(var1, id) from ts_4893.meters where id > 0 order by ts limit 5 +select repeat('nch1', id) from ts_4893.meters where id > 0 order by ts limit 5 +select repeat('var1', id) from ts_4893.meters where id > 0 order by ts limit 5 +select repeat('taos', 1) +select repeat('taos', 2) +select repeat(name, 3) from ts_4893.d0 order by ts limit 10 +select repeat(name, 3) from ts_4893.meters order by ts limit 10 +select repeat(nch1, 3) from ts_4893.d0 order by ts limit 10 +select repeat(nch1, 3) from ts_4893.meters order by ts limit 10 +select repeat(var1, 3) from ts_4893.d0 order by ts limit 10 +select repeat(var1, 3) from ts_4893.meters order by ts limit 10 +select repeat(name, groupid) from ts_4893.d0 order by ts limit 10 +select repeat(name, groupid) from ts_4893.meters order by ts limit 10 +select repeat(nch1, groupid) from ts_4893.d0 order by ts limit 10 +select repeat(nch1, groupid) from ts_4893.meters order by ts limit 10 +select repeat(null, 3) +select repeat('taos', null) +select repeat('taos', 0) +select repeat('', 5) +select repeat('A', 0) +select repeat('A', 10) +select repeat('A B', 5) +select repeat('ABC', 1) +select repeat('Hello', 2) +select repeat('HelloWorld', 2) +select repeat('123', 5) +select repeat('12345', 3) +select repeat('!@#', 3) +select repeat('你好', 2) +select repeat('abc', length('abc')) +select repeat(concat('A', 'B', 'C'), 3) +select repeat(upper('abc'), 4) +select repeat(trim(' Hello '), 3) +select name, repeat(name, 3) from ts_4893.meters limit 1 +select name, repeat(substring(name, 1, 5), 2) from ts_4893.meters limit 1 +select var1, repeat(var1, 2) from ts_4893.meters limit 1 +select nch1, repeat(nch1, 4) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/replace.in b/tests/army/query/function/in/replace.in index 619b10ced0..1a1b3ed02c 100644 --- a/tests/army/query/function/in/replace.in +++ b/tests/army/query/function/in/replace.in @@ -1,98 +1,120 @@ -select replace('aaaa','a','b'); -select replace('aaaa','aa','b'); -select replace('aaaa','a','bb'); -select replace('aaaa','','b'); -select replace('bbbb','a','c'); -select replace(concat(lower(concat('THIS',' ','IS',' ','A',' ')),upper('false'),' ','test'),'FALSE','REAL') ; -select replace('北京涛思','北京', ''); -select replace('北京涛思','涛思', ''); -select replace('北京涛思.com','思.', '北京'); -select replace('北京涛思.com','北com', '北京涛'); -select replace('北京涛思', char(ascii('北')), 'wrongans'); -select replace(nch1, 'a', 'b') from ts_4893.meters order by ts limit 5; -select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5; -select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5; -select replace(nch1, 'a', '啊') from ts_4893.meters order by ts limit 5; -select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5; -select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5; -select replace(nch1, '一', '壹') from ts_4893.meters order by ts limit 5; -select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5; -select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5; -select replace(nch1, '一', '1') from ts_4893.meters order by ts limit 5; -select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5; -select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5; -select replace(nch1, nch2, 'nch2') from ts_4893.meters order by ts limit 5; -select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5; -select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5; -select replace(nch1, var2, 'var2') from ts_4893.meters order by ts limit 5; -select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5; -select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5; -select replace(nch1, '三', nch2) from ts_4893.meters order by ts limit 5; -select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5; -select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5; -select replace(nch1, '三', var2) from ts_4893.meters order by ts limit 5; -select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5; -select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5; -select replace(nch1, nch2, var2) from ts_4893.meters order by ts limit 5; -select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5; -select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5; -select replace(nch1, var2, nch2) from ts_4893.meters order by ts limit 5; -select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5; -select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5; -select replace(var1, 'a', 'b') from ts_4893.meters order by ts limit 5; -select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5; -select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5; -select replace(var1, 'a', '啊') from ts_4893.meters order by ts limit 5; -select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5; -select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5; -select replace(var1, '一', '壹') from ts_4893.meters order by ts limit 5; -select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5; -select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5; -select replace(var1, '一', '1') from ts_4893.meters order by ts limit 5; -select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5; -select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5; -select replace(var1, nch2, 'nch2') from ts_4893.meters order by ts limit 5; -select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5; -select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5; -select replace(var1, var2, 'var2') from ts_4893.meters order by ts limit 5; -select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5; -select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5; -select replace(var1, '三', nch2) from ts_4893.meters order by ts limit 5; -select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5; -select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5; -select replace(var1, '三', var2) from ts_4893.meters order by ts limit 5; -select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5; -select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5; -select replace(var1, nch2, var2) from ts_4893.meters order by ts limit 5; -select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5; -select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5; -select replace(var1, var2, nch2) from ts_4893.meters order by ts limit 5; -select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5; -select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5; -select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5; -select replace('aabbccdd','aa', 'ee'); -select replace('aabbccdd','AA', 'ee'); -select replace('北京','北' , '南'); -select replace('北京','京' , '南'); -select replace('北京taos','北' , '南'); -select replace(nch1, nch2, 't') from ts_4893.d0 order by ts limit 10; -select replace(nch1, nch2, 't') from ts_4893.meters order by ts limit 10; -select replace(nch1, var2, 't') from ts_4893.d0 order by ts limit 10; -select replace(nch1, var2, 't') from ts_4893.meters order by ts limit 10; -select replace(var1, nch2, 't') from ts_4893.d0 order by ts limit 10; -select replace(var1, nch2, 't') from ts_4893.meters order by ts limit 10; -select replace(var1, var2, 't') from ts_4893.d0 order by ts limit 10; -select replace(var1, var2, 't') from ts_4893.meters order by ts limit 10; -select replace(nch1, nch2, var1) from ts_4893.d0 order by ts limit 10; -select replace(nch1, nch2, var1) from ts_4893.meters order by ts limit 10; +select replace('aaaa','a','b') +select replace('aaaa','aa','b') +select replace('aaaa','a','bb') +select replace('aaaa','','b') +select replace('bbbb','a','c') +select replace(concat(lower(concat('THIS',' ','IS',' ','A',' ')),upper('false'),' ','test'),'FALSE','REAL') +select replace('北京涛思','北京', '') +select replace('北京涛思','涛思', '') +select replace('北京涛思.com','思.', '北京') +select replace('北京涛思.com','北com', '北京涛') +select replace('北京涛思', char(ascii('北')), 'wrongans') +select replace(nch1, 'a', 'b') from ts_4893.meters order by ts limit 5 +select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5 +select replace(nch1, 'a', 'b') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5 +select replace(nch1, 'a', '啊') from ts_4893.meters order by ts limit 5 +select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) != 0 order by ts limit 5 +select replace(nch1, 'a', '啊') from ts_4893.meters where position('a' IN nch1) = 0 order by ts limit 5 +select replace(nch1, '一', '壹') from ts_4893.meters order by ts limit 5 +select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5 +select replace(nch1, '一', '壹') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5 +select replace(nch1, '一', '1') from ts_4893.meters order by ts limit 5 +select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) != 0 order by ts limit 5 +select replace(nch1, '一', '1') from ts_4893.meters where position('一' IN nch1) = 0 order by ts limit 5 +select replace(nch1, nch2, 'nch2') from ts_4893.meters order by ts limit 5 +select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5 +select replace(nch1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5 +select replace(nch1, var2, 'var2') from ts_4893.meters order by ts limit 5 +select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5 +select replace(nch1, var2, 'var2') from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5 +select replace(nch1, '三', nch2) from ts_4893.meters order by ts limit 5 +select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5 +select replace(nch1, '三', nch2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5 +select replace(nch1, '三', var2) from ts_4893.meters order by ts limit 5 +select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) != 0 order by ts limit 5 +select replace(nch1, '三', var2) from ts_4893.meters where position('三' IN nch1) = 0 order by ts limit 5 +select replace(nch1, nch2, var2) from ts_4893.meters order by ts limit 5 +select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) != 0 order by ts limit 5 +select replace(nch1, nch2, var2) from ts_4893.meters where position(nch2 IN nch1) = 0 order by ts limit 5 +select replace(nch1, var2, nch2) from ts_4893.meters order by ts limit 5 +select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) != 0 order by ts limit 5 +select replace(nch1, var2, nch2) from ts_4893.meters where position(var2 IN nch1) = 0 order by ts limit 5 +select replace(var1, 'a', 'b') from ts_4893.meters order by ts limit 5 +select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5 +select replace(var1, 'a', 'b') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5 +select replace(var1, 'a', '啊') from ts_4893.meters order by ts limit 5 +select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) != 0 order by ts limit 5 +select replace(var1, 'a', '啊') from ts_4893.meters where position('a' IN var1) = 0 order by ts limit 5 +select replace(var1, '一', '壹') from ts_4893.meters order by ts limit 5 +select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5 +select replace(var1, '一', '壹') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5 +select replace(var1, '一', '1') from ts_4893.meters order by ts limit 5 +select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) != 0 order by ts limit 5 +select replace(var1, '一', '1') from ts_4893.meters where position('一' IN var1) = 0 order by ts limit 5 +select replace(var1, nch2, 'nch2') from ts_4893.meters order by ts limit 5 +select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5 +select replace(var1, nch2, 'nch2') from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5 +select replace(var1, var2, 'var2') from ts_4893.meters order by ts limit 5 +select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5 +select replace(var1, var2, 'var2') from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5 +select replace(var1, '三', nch2) from ts_4893.meters order by ts limit 5 +select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5 +select replace(var1, '三', nch2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5 +select replace(var1, '三', var2) from ts_4893.meters order by ts limit 5 +select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) != 0 order by ts limit 5 +select replace(var1, '三', var2) from ts_4893.meters where position('三' IN var1) = 0 order by ts limit 5 +select replace(var1, nch2, var2) from ts_4893.meters order by ts limit 5 +select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) != 0 order by ts limit 5 +select replace(var1, nch2, var2) from ts_4893.meters where position(nch2 IN var1) = 0 order by ts limit 5 +select replace(var1, var2, nch2) from ts_4893.meters order by ts limit 5 +select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) != 0 order by ts limit 5 +select replace(var1, var2, nch2) from ts_4893.meters where position(var2 IN var1) = 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, 'nch2') from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', nch2, var2) from ts_4893.meters where position(nch2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, 'var2') from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') != 0 order by ts limit 5 +select replace('一二三四五六七abcdefghijk213124123', var2, nch2) from ts_4893.meters where position(var2 IN '一二三四五六七abcdefghijk213124123') = 0 order by ts limit 5 +select replace('aabbccdd','aa', 'ee') +select replace('aabbccdd','AA', 'ee') +select replace('北京','北' , '南') +select replace('北京','京' , '南') +select replace('北京taos','北' , '南') +select replace(nch1, nch2, 't') from ts_4893.d0 order by ts limit 10 +select replace(nch1, nch2, 't') from ts_4893.meters order by ts limit 10 +select replace(nch1, var2, 't') from ts_4893.d0 order by ts limit 10 +select replace(nch1, var2, 't') from ts_4893.meters order by ts limit 10 +select replace(var1, nch2, 't') from ts_4893.d0 order by ts limit 10 +select replace(var1, nch2, 't') from ts_4893.meters order by ts limit 10 +select replace(var1, var2, 't') from ts_4893.d0 order by ts limit 10 +select replace(var1, var2, 't') from ts_4893.meters order by ts limit 10 +select replace(nch1, nch2, var1) from ts_4893.d0 order by ts limit 10 +select replace(nch1, nch2, var1) from ts_4893.meters order by ts limit 10 +select replace(null, 'aa', 'ee') +select replace(null, 'A', 'B') +select replace('', '', 'B') +select replace('', 'A', 'B') +select replace('A', 'A', '') +select replace('aabbccdd', null, 'ee') +select replace('Hello', 'Z', 'X') +select replace('Hello World', ' ', '_') +select replace('Hello World', 'World', 'MySQL') +select replace('12345', '5', 'five') +select replace('中国', '中', '国') +select replace('é', 'e', 'a') +select replace('!@#', '@', '#') +select replace('123456', '7', 'eight') +select replace(concat('A', 'B', 'C'), 'B', 'Z') +select replace(upper('abc'), 'A', 'X') +select replace(trim(' Hello '), 'l', 'L') +select replace(lower('HELLO'), 'h', 'H') +select name, replace(substring(name, 1, 5), 'e', 'o') from ts_4893.meters limit 1 +select name, replace(name, 'a', 'o') from ts_4893.meters limit 1 +select var1, replace(var1, '1', 'one') from ts_4893.meters limit 1 +select nch1, replace(nch1, 'n', 'm') from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/round.in b/tests/army/query/function/in/round.in index f9be21ef04..bca293fc72 100644 --- a/tests/army/query/function/in/round.in +++ b/tests/army/query/function/in/round.in @@ -1,30 +1,49 @@ -select ROUND(10.55, 3); -select ROUND(10.55, 2); -select ROUND(10.55, 1); -select ROUND(10.55, 0); -select ROUND(10.55); -select ROUND(10.55, -1); -select ROUND(10.55, -10); -select ROUND(-10.55, 1); -select ROUND(99, 1); -select ROUND(111.1111); -select ROUND(111.5111); -select ROUND(10.55) + 1; -select ROUND(10.55, 1) + 1; -select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123.123456789, 9), 8), 7), 6), 5), 4)); -select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123456789.123456789, -1), -2), -3), -4), -5), -6)); -select ROUND(current) from ts_4893.meters order by ts limit 20; -select ROUND(87654321.123456789, id) from ts_4893.meters order by ts limit 10; -select ROUND(current, id) from ts_4893.meters order by ts limit 10; -select ROUND(current, 1) from ts_4893.meters order by ts limit 10; -select round(10.55, 3); -select round(10.55, 2); -select round(10.55, 1); -select round(10.55, 0); -select round(10.55); -select round(10.55, -1); -select round(10.55, -10); -select round(-10.55, 1); -select round(99, 1); -select round(current) from ts_4893.d0 order by ts limit 10; -select round(current) from ts_4893.meters order by ts limit 10; +select ROUND(10.55, 3) +select ROUND(10.55, 2) +select ROUND(10.55, 1) +select ROUND(10.55, 0) +select ROUND(10.55) +select ROUND(10.55, -1) +select ROUND(10.55, -10) +select ROUND(-10.55, 1) +select ROUND(99, 1) +select ROUND(111.1111) +select ROUND(111.5111) +select ROUND(10.55) + 1 +select ROUND(10.55, 1) + 1 +select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123.123456789, 9), 8), 7), 6), 5), 4)) +select ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(123456789.123456789, -1), -2), -3), -4), -5), -6)) +select ROUND(current) from ts_4893.meters order by ts limit 20 +select ROUND(87654321.123456789, id) from ts_4893.meters order by ts limit 10 +select ROUND(current, id) from ts_4893.meters order by ts limit 10 +select ROUND(current, 1) from ts_4893.meters order by ts limit 10 +select round(10.55, 3) +select round(10.55, 2) +select round(10.55, 1) +select round(10.55, 0) +select round(10.55) +select round(10.55, -1) +select round(10.55, -10) +select round(-10.55, 1) +select round(99, 1) +select round(current) from ts_4893.d0 order by ts limit 10 +select round(current) from ts_4893.meters order by ts limit 10 +select round(10, null) +select round(null, 2) +select round(123.456, null) +select round(100) +select round(0.00123, -2) +select round(123.456, 0) +select round(123.456, -5) +select round(12345.6789, -2) +select round(-123.456, 2) +select round(-1234.5678, 2) +select round(voltage, 0) from ts_4893.meters limit 1 +select round(current, 1) from ts_4893.meters limit 1 +select round(phase, 3) from ts_4893.meters limit 1 +select round(voltage, -1) from ts_4893.meters limit 1 +select round(current * voltage, 2) from ts_4893.meters limit 1 +select round(abs(voltage), 2) from ts_4893.meters limit 1 +select round(pi() * phase, 3) from ts_4893.meters limit 1 +select round(sqrt(voltage), 2) from ts_4893.meters limit 1 +select round(log(current), 2) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/sign.in b/tests/army/query/function/in/sign.in index 1be6a3610c..436c884d36 100644 --- a/tests/army/query/function/in/sign.in +++ b/tests/army/query/function/in/sign.in @@ -1,36 +1,48 @@ -select SIGN(0); -select SIGN(1); -select SIGN(1.5); -select SIGN(100); -select SIGN(-1); -select SIGN(-1.5); -select SIGN(-100); -select SIGN(1) + 1; -select SIGN(1) - 1; -select SIGN(1) * 1; -select SIGN(1) / 1; -select SIGN(1) from ts_4893.meters limit 5; -select SIGN(1) + 1 from ts_4893.meters limit 1; -select SIGN(1) - 1 from ts_4893.meters limit 1; -select SIGN(1) * 2 from ts_4893.meters limit 1; -select SIGN(1) / 2 from ts_4893.meters limit 1; -select SIGN(2) + SIGN(1) from ts_4893.meters limit 1; -select SIGN(2) - SIGN(1) from ts_4893.meters limit 1; -select SIGN(2) * SIGN(1) from ts_4893.meters limit 1; -select SIGN(2) / SIGN(1) from ts_4893.meters limit 1; -select SIGN(1) + id from ts_4893.meters order by ts limit 5; -select SIGN(id) + id from ts_4893.meters order by ts limit 5; -select SIGN(abs(10)); -select SIGN(abs(-10)); -select abs(SIGN(10)); -select pow(SIGN(10), 2); -select sqrt(SIGN(10)); -select cast(SIGN(10) as int); -select SIGN(sqrt(id)) from ts_4893.meters order by ts limit 5; -select SIGN(SIGN(SIGN(SIGN(0)))); -select sign(1); -select sign(10); -select sign(-1); -select sign(-10); -select sign(current) from ts_4893.d0 order by ts limit 10; -select sign(current) from ts_4893.meters order by ts limit 10; +select SIGN(0) +select SIGN(1) +select SIGN(1.5) +select SIGN(100) +select SIGN(-1) +select SIGN(-1.5) +select SIGN(-100) +select SIGN(1) + 1 +select SIGN(1) - 1 +select SIGN(1) * 1 +select SIGN(1) / 1 +select SIGN(1) from ts_4893.meters limit 5 +select SIGN(1) + 1 from ts_4893.meters limit 1 +select SIGN(1) - 1 from ts_4893.meters limit 1 +select SIGN(1) * 2 from ts_4893.meters limit 1 +select SIGN(1) / 2 from ts_4893.meters limit 1 +select SIGN(2) + SIGN(1) from ts_4893.meters limit 1 +select SIGN(2) - SIGN(1) from ts_4893.meters limit 1 +select SIGN(2) * SIGN(1) from ts_4893.meters limit 1 +select SIGN(2) / SIGN(1) from ts_4893.meters limit 1 +select SIGN(1) + id from ts_4893.meters order by ts limit 5 +select SIGN(id) + id from ts_4893.meters order by ts limit 5 +select SIGN(abs(10)) +select SIGN(abs(-10)) +select abs(SIGN(10)) +select pow(SIGN(10), 2) +select sqrt(SIGN(10)) +select cast(SIGN(10) as int) +select SIGN(sqrt(id)) from ts_4893.meters order by ts limit 5 +select SIGN(SIGN(SIGN(SIGN(0)))) +select sign(1) +select sign(10) +select sign(-1) +select sign(-10) +select sign(current) from ts_4893.d0 order by ts limit 10 +select sign(current) from ts_4893.meters order by ts limit 10 +select sign(null) +select sign(25) +select sign(-10) +select sign(0.1) +select sign(-0.1) +select sign(current) from ts_4893.meters limit 1 +select sign(voltage) from ts_4893.meters limit 1 +select sign(phase) from ts_4893.meters limit 1 +select sign(abs(voltage)) from ts_4893.meters limit 1 +select sign(round(current)) from ts_4893.meters limit 1 +select sign(sqrt(voltage)) from ts_4893.meters limit 1 +select sign(log(current + 1)) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/stddev.in b/tests/army/query/function/in/stddev.in index ef36a7da41..d3db1bb56b 100644 --- a/tests/army/query/function/in/stddev.in +++ b/tests/army/query/function/in/stddev.in @@ -1,10 +1,22 @@ -select STDDEV(current) from ts_4893.meters; -select STDDEV(current) from ts_4893.meters interval(1d) order by 1 limit 10; -select STDDEV(id) from ts_4893.meters; -select STDDEV(id) from ts_4893.meters interval(1d) limit 10; -select STDDEV(id) from ts_4893.meters where id > 100; -select STDDEV(id) from ts_4893.meters interval(1d) order by 1 limit 10; -select stddev_pop(id) from ts_4893.d0; -select stddev_pop(id) from ts_4893.meters; -select stddev_pop(current) from ts_4893.d0; -select stddev_pop(current) from ts_4893.meters; +select STDDEV(current) from ts_4893.meters +select STDDEV(current) from ts_4893.meters interval(1d) order by 1 limit 10 +select STDDEV(id) from ts_4893.meters +select STDDEV(id) from ts_4893.meters interval(1d) limit 10 +select STDDEV(id) from ts_4893.meters where id > 100 +select STDDEV(id) from ts_4893.meters interval(1d) order by 1 limit 10 +select stddev_pop(null) from ts_4893.meters +select stddev_pop(id) from ts_4893.d0 +select stddev_pop(id) from ts_4893.meters +select stddev_pop(current) from ts_4893.d0 +select stddev_pop(current) from ts_4893.meters +select stddev_pop(voltage) from ts_4893.meters +select stddev_pop(voltage) from ts_4893.meters where voltage is not null +select stddev_pop(phase) from ts_4893.meters +select stddev_pop(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' +select stddev_pop(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) +select round(stddev_pop(current), 2) from ts_4893.meters +select pow(stddev_pop(current), 2) from ts_4893.meters +select log(stddev_pop(voltage) + 1) from ts_4893.meters +select groupid, stddev_pop(voltage) from ts_4893.meters group by groupid order by groupid +select location, stddev_pop(current) from ts_4893.meters group by location order by location +select location, stddev_pop(voltage) from ts_4893.meters group by location order by location diff --git a/tests/army/query/function/in/substr.in b/tests/army/query/function/in/substr.in index e5a1ea0754..8975e360c9 100644 --- a/tests/army/query/function/in/substr.in +++ b/tests/army/query/function/in/substr.in @@ -1,139 +1,165 @@ -select SUBSTRING('Hello.World!', 1); -select SUBSTRING('Hello.World!', 1, 5); -select SUBSTRING('Hello.World!', 1, 20); -select SUBSTRING('Hello.World!' FROM 1); -select SUBSTRING('Hello.World!' FROM 1 FOR 5); -select SUBSTRING('Hello.World!' FROM 1 FOR 20); -select SUBSTRING('Hello.World!', -6); -select SUBSTRING('Hello.World!', -6, 5); -select SUBSTRING('Hello.World!', -6, 20); -select SUBSTRING('Hello.World!' FROM -6); -select SUBSTRING('Hello.World!' FROM -6 FOR 5); -select SUBSTRING('Hello.World!' FROM -6 FOR 20); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 5); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 20); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 5); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 20); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5); -select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20); -select SUBSTRING(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTRING(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTRING(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR('Hello.World!', 1); -select SUBSTR('Hello.World!', 1, 5); -select SUBSTR('Hello.World!', 1, 20); -select SUBSTR('Hello.World!' FROM 1); -select SUBSTR('Hello.World!' FROM 1 FOR 5); -select SUBSTR('Hello.World!' FROM 1 FOR 20); -select SUBSTR('Hello.World!', -6); -select SUBSTR('Hello.World!', -6, 5); -select SUBSTR('Hello.World!', -6, 20); -select SUBSTR('Hello.World!' FROM -6); -select SUBSTR('Hello.World!' FROM -6 FOR 5); -select SUBSTR('Hello.World!' FROM -6 FOR 20); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 5); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 20); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 5); -select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 20); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5); -select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20); -select SUBSTR(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5; -select SUBSTR(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select SUBSTR(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5; -select substring('tdengine', 2); -select substring('tdengine', 8); -select substring('tdengine', 1, 3); -select substring('tdengine', 2, 99); -select substring('tdengine', -1, 10); -select substring('中国', 1, 3); -select substring('中国tdengine', 1, 3); -select substring(var1, 1, 5) from ts_4893.d0 order by ts limit 10; -select substring(var1, 1, 5) from ts_4893.meters order by ts limit 10; -select substring(nch1, 1, 5) from ts_4893.d0 order by ts limit 10; -select substring(nch1, 1, 5) from ts_4893.meters order by ts limit 10; +select SUBSTRING('Hello.World!', 1) +select SUBSTRING('Hello.World!', 1, 5) +select SUBSTRING('Hello.World!', 1, 20) +select SUBSTRING('Hello.World!' FROM 1) +select SUBSTRING('Hello.World!' FROM 1 FOR 5) +select SUBSTRING('Hello.World!' FROM 1 FOR 20) +select SUBSTRING('Hello.World!', -6) +select SUBSTRING('Hello.World!', -6, 5) +select SUBSTRING('Hello.World!', -6, 20) +select SUBSTRING('Hello.World!' FROM -6) +select SUBSTRING('Hello.World!' FROM -6 FOR 5) +select SUBSTRING('Hello.World!' FROM -6 FOR 20) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 5) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', 1, 20) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 5) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.', -6, 20) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5) +select SUBSTRING('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20) +select SUBSTRING(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTRING(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTRING(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR('Hello.World!', 1) +select SUBSTR('Hello.World!', 1, 5) +select SUBSTR('Hello.World!', 1, 20) +select SUBSTR('Hello.World!' FROM 1) +select SUBSTR('Hello.World!' FROM 1 FOR 5) +select SUBSTR('Hello.World!' FROM 1 FOR 20) +select SUBSTR('Hello.World!', -6) +select SUBSTR('Hello.World!', -6, 5) +select SUBSTR('Hello.World!', -6, 20) +select SUBSTR('Hello.World!' FROM -6) +select SUBSTR('Hello.World!' FROM -6 FOR 5) +select SUBSTR('Hello.World!' FROM -6 FOR 20) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 5) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', 1, 20) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 5) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM 1 FOR 20) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 5) +select SUBSTR('北京涛思数据科技有限公司,tdengine.', -6, 20) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 5) +select SUBSTR('北京涛思数据科技有限公司,tdengine.' FROM -6 FOR 20) +select SUBSTR(nch1, 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, 1, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, 1, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM 1 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM 1 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, -6, 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, -6, 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM -6) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM -6 FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM -6 FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(var1, 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, 1, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, 1, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM 1 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM 1 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, -6, 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, -6, 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM -6) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM -6 FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM -6 FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(nch1, sign(id), 1) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, sign(id), 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1, sign(id), 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM sign(id)) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(var1, sign(id), 1) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, sign(id), 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1, sign(id), 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM sign(id)) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM sign(id) FOR 5) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM sign(id) FOR 20) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(nch1, 2, id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(nch1 FROM 2 FOR id) from ts_4893.meters where char_length(nch1) > 6 order by ts limit 5 +select SUBSTR(var1, 2, id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select SUBSTR(var1 FROM 2 FOR id) from ts_4893.meters where char_length(var1) > 6 order by ts limit 5 +select substring('tdengine', 2) +select substring('tdengine', 8) +select substring('tdengine', 1, 3) +select substring('tdengine', 2, 99) +select substring('tdengine', -1, 10) +select substring('中国', 1, 3) +select substring('中国tdengine', 1, 3) +select substring(var1, 1, 5) from ts_4893.d0 order by ts limit 10 +select substring(var1, 1, 5) from ts_4893.meters order by ts limit 10 +select substring(nch1, 1, 5) from ts_4893.d0 order by ts limit 10 +select substring(nch1, 1, 5) from ts_4893.meters order by ts limit 10 +select substring(null, 1, 3) +select substring('tdengine', null, 3) +select substring('tdengine', 0) +select substring('tdengine', 10) +select substring('tdengine', 1, null) +select substring('tdengine', 1, 0) +select substring('tdengine', 1, -1) +select substr(null, 1, 3) +select substr('Hello', 1, 3) +select substr('', 1, 5) +select substr('ABCDE', 0, 3) +select substr('ABCDEFG', -3, 2) +select substr('HelloWorld', 2, 5) +select substr('1234567890', -5, 5) +select substr('!@#$%^&*()', 2, 4) +select substr('你好世界', 3, 2) +select substr('ABCDEFG', 10, 5) +select substr('ABCDEFG', -1, 3) +select substr('1234567890', -15, 5) +select substr(concat('Hello', 'World'), 1, 5) +select substr('HelloWorld', 1, length('Hello')) +select substr(upper('helloworld'), 2, 4) +select substr(trim(' HelloWorld '), 1, 5) +select name, substr(name, 1, 3) from ts_4893.meters limit 1 +select var1, substr(var1, 1, 6) from ts_4893.meters limit 1 +select nch1, substr(nch1, 2, 4) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/substr_idx.in b/tests/army/query/function/in/substr_idx.in index ae278f0a7a..c38171ee50 100644 --- a/tests/army/query/function/in/substr_idx.in +++ b/tests/army/query/function/in/substr_idx.in @@ -1,93 +1,119 @@ -select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2); -select substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2); -select substring_index('www.taosdata.com','taos',1); -select substring_index('www.taosdata.com','taos',-1); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 1); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -1); -select substring_index('www.taosdata.com','.',-2); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 100); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -100); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483647); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483647); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483648); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483648); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483649); -SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483649); -select substring_index('.taosdata.com','.',-2); -select substring_index('.taosdata.com','.tcx',-1); -select substring_index('aaaaaaaaa1','aa',2); -select substring_index('aaaaaaaaa1','aa',3); -select substring_index('aaaaaaaaa1','aa',4); -select substring_index('aaaaaaaaa1','aa',5); -select substring_index('aaaaaaaaa1','aaa',2); -select substring_index('aaaaaaaaa1','aaa',3); -select substring_index('aaaaaaaaa1','aaa',4); -select substring_index('aaaaaaaaa1','aaaa',2); -select substring_index('aaaaaaaaa1','1',1); -select substring_index('aaaaaaaaa1','a',-1); -select substring_index('aaaaaaaaa1','aa',-1); -select substring_index('aaaaaaaaa1','aa',-2); -select substring_index('aaaaaaaaa1','aa',-3); -select substring_index('aaaaaaaaa1','aa',-4); -select substring_index('aaaaaaaaa1','aa',-5); -select substring_index('aaaaaaaaa1','aaa',-1); -select substring_index('aaaaaaaaa1','aaa',-2); -select substring_index('aaaaaaaaa1','aaa',-3); -select substring_index('aaaaaaaaa1','aaa',-4); -select substring_index('the king of thethe hill','the',-2); -select substring_index('the king of the the hill','the',-2); -select substring_index('the king of the the hill','the',-2); -select substring_index('the king of the the hill',' the ',-1); -select substring_index('the king of the the hill',' the ',-2); -select substring_index('the king of the the hill',' ',-1); -select substring_index('the king of the the hill',' ',-2); -select substring_index('the king of the the hill',' ',-3); -select substring_index('the king of the the hill',' ',-4); -select substring_index('the king of the the hill',' ',-5); -select substring_index('the king of the.the hill','the',-2); -select substring_index('the king of thethethe.the hill','the',-3); -select substring_index('the king of thethethe.the hill','the',-1); -select substring_index('the king of the the hill','the',2); -select substring_index('the king of the the hill','the',3); -select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) > 1 order by ts limit 5; -select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5; -select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) > 1 order by ts limit 5; -select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5; -select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) > 1 order by ts limit 5; -select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5; -select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) > 1 order by ts limit 5; -select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5; -select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', nch2, 1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', nch2, -1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', nch2, cast(id + 1 as int)) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', var2, 1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', var2, -1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5; -select substring_index('a一二三a一二三bbcfp', var2, cast(id + 1 as int)) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5; -select substring_index(nch1, '123', 1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5; -select substring_index(nch1, '123', -1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5; -select substring_index(nch1, '123', id) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5; -select substring_index(var1, '123', 1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5; -select substring_index(var1, '123', -1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5; -select substring_index(var1, '123', id) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5; -select substring_index('www.taosdata.com', '.', 2); -select substring_index('www.taosdata.com', '.', -2); -select substring_index('中国.科学.www.taosdata.com', '.', 2); -select substring_index('北京。涛思。数据。科技', '。', 2); -select substring_index(nch1, 'a', 2) from ts_4893.d0 order by ts limit 10; -select substring_index(nch1, 'a', 2) from ts_4893.meters order by ts limit 10; -select substring_index(nch1, nch2, 2) from ts_4893.d0 order by ts limit 10; -select substring_index(nch1, nch2, 2) from ts_4893.meters order by ts limit 10; -select substring_index(nch1, var2, 2) from ts_4893.d0 order by ts limit 10; -select substring_index(nch1, var2, 2) from ts_4893.meters order by ts limit 10; -select substring_index(var1, nch2, 2) from ts_4893.d0 order by ts limit 10; -select substring_index(var1, nch2, 2) from ts_4893.meters order by ts limit 10; -select substring_index(var1, var2, 2) from ts_4893.d0 order by ts limit 10; -select substring_index(var1, var2, 2) from ts_4893.meters order by ts limit 10; +select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) +select substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2) +select substring_index('www.taosdata.com','taos',1) +select substring_index('www.taosdata.com','taos',-1) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 1) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -1) +select substring_index('www.taosdata.com','.',-2) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 100) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -100) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483647) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483647) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483648) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483648) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', 2147483649) +SELECT SUBSTRING_INDEX('www.taosdata.com', '.', -2147483649) +select substring_index('.taosdata.com','.',-2) +select substring_index('.taosdata.com','.tcx',-1) +select substring_index('aaaaaaaaa1','aa',2) +select substring_index('aaaaaaaaa1','aa',3) +select substring_index('aaaaaaaaa1','aa',4) +select substring_index('aaaaaaaaa1','aa',5) +select substring_index('aaaaaaaaa1','aaa',2) +select substring_index('aaaaaaaaa1','aaa',3) +select substring_index('aaaaaaaaa1','aaa',4) +select substring_index('aaaaaaaaa1','aaaa',2) +select substring_index('aaaaaaaaa1','1',1) +select substring_index('aaaaaaaaa1','a',-1) +select substring_index('aaaaaaaaa1','aa',-1) +select substring_index('aaaaaaaaa1','aa',-2) +select substring_index('aaaaaaaaa1','aa',-3) +select substring_index('aaaaaaaaa1','aa',-4) +select substring_index('aaaaaaaaa1','aa',-5) +select substring_index('aaaaaaaaa1','aaa',-1) +select substring_index('aaaaaaaaa1','aaa',-2) +select substring_index('aaaaaaaaa1','aaa',-3) +select substring_index('aaaaaaaaa1','aaa',-4) +select substring_index('the king of thethe hill','the',-2) +select substring_index('the king of the the hill','the',-2) +select substring_index('the king of the the hill','the',-2) +select substring_index('the king of the the hill',' the ',-1) +select substring_index('the king of the the hill',' the ',-2) +select substring_index('the king of the the hill',' ',-1) +select substring_index('the king of the the hill',' ',-2) +select substring_index('the king of the the hill',' ',-3) +select substring_index('the king of the the hill',' ',-4) +select substring_index('the king of the the hill',' ',-5) +select substring_index('the king of the.the hill','the',-2) +select substring_index('the king of thethethe.the hill','the',-3) +select substring_index('the king of thethethe.the hill','the',-1) +select substring_index('the king of the the hill','the',2) +select substring_index('the king of the the hill','the',3) +select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) > 1 order by ts limit 5 +select substring_index(nch1, nch2, 1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 +select substring_index(nch1, nch2, -2) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) > 1 order by ts limit 5 +select substring_index(var1, var2, 1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 +select substring_index(var1, var2, -2) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) > 1 order by ts limit 5 +select substring_index(nch1, var2, 1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 +select substring_index(nch1, var2, -2) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) > 1 order by ts limit 5 +select substring_index(var1, nch2, 1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 +select substring_index(var1, nch2, -2) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', nch2, 1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', nch2, -1) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', nch2, cast(id + 1 as int)) from ts_4893.meters where position(nch2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', var2, 1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', var2, -1) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') > 1 order by ts limit 5 +select substring_index('a一二三a一二三bbcfp', var2, cast(id + 1 as int)) from ts_4893.meters where position(var2 in 'a一二三a一二三bbcfp') = 0 order by ts limit 5 +select substring_index(nch1, '123', 1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 +select substring_index(nch1, '123', -1) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 +select substring_index(nch1, '123', id) from ts_4893.meters where position('123' in nch1) > 1 order by ts limit 5 +select substring_index(var1, '123', 1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 +select substring_index(var1, '123', -1) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 +select substring_index(var1, '123', id) from ts_4893.meters where position('123' in var1) > 1 order by ts limit 5 +select substring_index('www.taosdata.com', '.', 2) +select substring_index('www.taosdata.com', '.', -2) +select substring_index('中国.科学.www.taosdata.com', '.', 2) +select substring_index('北京。涛思。数据。科技', '。', 2) +select substring_index(nch1, 'a', 2) from ts_4893.d0 order by ts limit 10 +select substring_index(nch1, 'a', 2) from ts_4893.meters order by ts limit 10 +select substring_index(nch1, nch2, 2) from ts_4893.d0 order by ts limit 10 +select substring_index(nch1, nch2, 2) from ts_4893.meters order by ts limit 10 +select substring_index(nch1, var2, 2) from ts_4893.d0 order by ts limit 10 +select substring_index(nch1, var2, 2) from ts_4893.meters order by ts limit 10 +select substring_index(var1, nch2, 2) from ts_4893.d0 order by ts limit 10 +select substring_index(var1, nch2, 2) from ts_4893.meters order by ts limit 10 +select substring_index(var1, var2, 2) from ts_4893.d0 order by ts limit 10 +select substring_index(var1, var2, 2) from ts_4893.meters order by ts limit 10 +select substring_index(null, '.', 2) +select substring_index('www.taosdata.com', null, 2) +select substring_index('www.taosdata.com', '.', 0) +select substring_index('www.taosdata.com', '.', null) +select substring_index('a.b.c', '.', 1) +select substring_index('a.b.c', '.', 2) +select substring_index('a.b.c', '.', -1) +select substring_index('', '.', 1) +select substring_index('apple.orange.banana', '.', 2) +select substring_index('192.168.1.1', '.', 3) +select substring_index('abc@xyz.com', '.', 5) +select substring_index('123456789', '.', 1) +select substring_index('abcdef', ' ', 2) +select substring_index('ABCDEFG', '-', -1) +select substring_index('apple', '.', -3) +select substring_index(concat('apple', '.', 'orange', '.', 'banana'), '.', 2) +select substring_index('apple.orange.banana', '.', length('apple')) +select substring_index(upper('apple.orange.banana'), '.', 2) +select substring_index(trim(' apple.orange.banana '), '.', 2) +select substring_index(concat('apple', '.', 'orange', '.', 'banana'), '.', 2) +select substring_index('apple.orange.banana', '.', length('apple')) +select substring_index(upper('apple.orange.banana'), '.', 2) +select substring_index(trim(' apple.orange.banana '), '.', 2) +select name, substring_index(name, ' ', 1) from ts_4893.meters limit 1 +select var1, substring_index(var1, '-', -1) from ts_4893.meters limit 1 +select nch1, substring_index(nch1, ',', 3) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/timediff.in b/tests/army/query/function/in/timediff.in index 0367d94a1a..d365980e45 100644 --- a/tests/army/query/function/in/timediff.in +++ b/tests/army/query/function/in/timediff.in @@ -1,91 +1,108 @@ -select TIMEDIFF(1,2); -select TIMEDIFF(2,1); -select TIMEDIFF(1,2,1s); -select TIMEDIFF(2,1,1s); -select TIMEDIFF(1,10000000,1m); -select TIMEDIFF(10000000,1,1m); -select TIMEDIFF(1,10000000,1h); -select TIMEDIFF(10000000,1,1h); -select TIMEDIFF(1,10000000,1d); -select TIMEDIFF(10000000,1,1d); -select TIMEDIFF(1,10000000,1w); -select TIMEDIFF(10000000,1,1w); -select TIMEDIFF(1724404450,1725095657); -select TIMEDIFF(1725095657,1724404450); -select TIMEDIFF(1724404450,1725095657,1s); -select TIMEDIFF(1725095657,1724404450,1s); -select TIMEDIFF(1724404450,1725095657,1m); -select TIMEDIFF(1725095657,1724404450,1m); -select TIMEDIFF(1724404450,1725095657,1h); -select TIMEDIFF(1725095657,1724404450,1h); -select TIMEDIFF(1724404450,1725095657,1d); -select TIMEDIFF(1725095657,1724404450,1d); -select TIMEDIFF(1724404450,1725095657,1w); -select TIMEDIFF(1725095657,1724404450,1w); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17'); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17'); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1s); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1s); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1m); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1m); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1h); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1h); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1d); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1d); -select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1w); -select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1w); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17'); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1s); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1s); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1m); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1m); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1h); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1h); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1d); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1d); -select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1w); -select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1w); -select TIMEDIFF(ts, ts) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17') from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17', 1s) from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts, 1s) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17', 1m) from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts, 1m) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17', 1h) from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts, 1h) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17', 1d) from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts, 1d) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, '2024-08-31 17:14:17', 1w) from ts_4893.meters order by ts limit 10; -select TIMEDIFF('2024-08-31 17:14:17', ts, 1w) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657, 1s) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts, 1s) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657, 1m) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts, 1m) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657, 1h) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts, 1h) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657, 1d) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts, 1d) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(ts, 1725095657, 1w) from ts_4893.meters order by ts limit 10; -select TIMEDIFF(1725095657, ts, 1w) from ts_4893.meters order by ts limit 10; -select timediff('2022-01-01 08:00:00', '2022-01-01 08:00:10',1s); -select timediff('2023-01-01 08:00:00', '2022-01-01 08:00:00',1s); -select timediff('2022-01-01 08:00:03', '2022-01-01 08:00:00',1a); -select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1m); -select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1h); -select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1d); -select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1w); -select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00'); -select timediff('2022-01-31 08:00:0', '2022-01-01 08:00:00',1s); -select timediff('2022-01-31', '2022-01-01',1s); -select timediff(1720769589, 1720769529, 1s); -select timediff(1720769589123, 1720769529123, 1s); -select timediff(1720769589, '2022-01-01 08:00:00', 1s); -select timediff('2022-01-01 08:00:00', 1720769589, 1s); -select timediff(1720769589231, '2022-01-01 08:00:00', 1s); -select timediff('2022-01-01 08:00:00', 1720769589123, 1s); -select timediff(ts, 1720769589123, 1a) from ts_4893.d0 order by ts limit 10; -select timediff(ts, 1720769589123, 1a) from ts_4893.meters order by ts limit 10; +select TIMEDIFF(1,2) +select TIMEDIFF(2,1) +select TIMEDIFF(1,2,1s) +select TIMEDIFF(2,1,1s) +select TIMEDIFF(1,10000000,1m) +select TIMEDIFF(10000000,1,1m) +select TIMEDIFF(1,10000000,1h) +select TIMEDIFF(10000000,1,1h) +select TIMEDIFF(1,10000000,1d) +select TIMEDIFF(10000000,1,1d) +select TIMEDIFF(1,10000000,1w) +select TIMEDIFF(10000000,1,1w) +select TIMEDIFF(1724404450,1725095657) +select TIMEDIFF(1725095657,1724404450) +select TIMEDIFF(1724404450,1725095657,1s) +select TIMEDIFF(1725095657,1724404450,1s) +select TIMEDIFF(1724404450,1725095657,1m) +select TIMEDIFF(1725095657,1724404450,1m) +select TIMEDIFF(1724404450,1725095657,1h) +select TIMEDIFF(1725095657,1724404450,1h) +select TIMEDIFF(1724404450,1725095657,1d) +select TIMEDIFF(1725095657,1724404450,1d) +select TIMEDIFF(1724404450,1725095657,1w) +select TIMEDIFF(1725095657,1724404450,1w) +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17') +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17') +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1s) +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1s) +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1m) +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1m) +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1h) +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1h) +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1d) +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1d) +select TIMEDIFF('2024-08-23 17:14:17', '2024-08-31 17:14:17', 1w) +select TIMEDIFF('2024-08-31 17:14:17', '2024-08-23 17:14:17', 1w) +select TIMEDIFF('2024-08-23 17:14:17', 1725095657) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17') +select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1s) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1s) +select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1m) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1m) +select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1h) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1h) +select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1d) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1d) +select TIMEDIFF('2024-08-23 17:14:17', 1725095657, 1w) +select TIMEDIFF(1725095657, '2024-08-23 17:14:17', 1w) +select TIMEDIFF(ts, ts) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17') from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17', 1s) from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts, 1s) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17', 1m) from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts, 1m) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17', 1h) from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts, 1h) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17', 1d) from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts, 1d) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, '2024-08-31 17:14:17', 1w) from ts_4893.meters order by ts limit 10 +select TIMEDIFF('2024-08-31 17:14:17', ts, 1w) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657, 1s) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts, 1s) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657, 1m) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts, 1m) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657, 1h) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts, 1h) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657, 1d) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts, 1d) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(ts, 1725095657, 1w) from ts_4893.meters order by ts limit 10 +select TIMEDIFF(1725095657, ts, 1w) from ts_4893.meters order by ts limit 10 +select timediff('2022-01-01 08:00:00', '2022-01-01 08:00:10',1s) +select timediff('2023-01-01 08:00:00', '2022-01-01 08:00:00',1s) +select timediff('2022-01-01 08:00:03', '2022-01-01 08:00:00',1a) +select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1m) +select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1h) +select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1d) +select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00',1w) +select timediff('2022-01-31 08:00:00', '2022-01-01 08:00:00') +select timediff('2022-01-31 08:00:0', '2022-01-01 08:00:00',1s) +select timediff('2022-01-31', '2022-01-01',1s) +select timediff(1720769589, 1720769529, 1s) +select timediff(1720769589, '2022-01-01 08:00:00', 1s) +select timediff(1720769589123, 1720769529123, 1s) +select timediff(1720769589231, '2022-01-01 08:00:00', 1s) +select timediff('2022-01-01 08:00:00', 1720769589, 1s) +select timediff('2022-01-01 08:00:00', 1720769589123, 1s) +select timediff(ts, 1720769589123, 1a) from ts_4893.d0 order by ts limit 10 +select timediff(ts, 1720769589123, 1a) from ts_4893.meters order by ts limit 10 +select timediff(null, '2022-01-01 08:00:01', 1s) +select timediff('20220131', '20220101', 1s) +select timediff('01/31/22', '01/01/22', 1s) +select timediff('22/01/31', '22/01/01') +select timediff('22/01/31', '22/01/01', 1s) +select timediff('31-JAN-22', '01-JAN-22', 1s) +select timediff('2022/01/31', '2022/01/01', 1s) +select timediff('2022-01-01 08:00:00', null, 1s) +select timediff('www', 'ttt') +select timediff(ts, ts) from ts_4893.meters limit 1 +select timediff(ts, ts - 1d) from ts_4893.meters limit 1 +select timediff(ts, '00:00:00') from ts_4893.meters limit 1 +select timediff(ts, null) from ts_4893.meters limit 1 +select timediff('25:61:61', ts) from ts_4893.meters limit 1 +select timediff('invalid_format', ts) from ts_4893.meters limit 1 +select timediff(name, ts) from ts_4893.meters limit 2 +select timediff('string_value', 'another_string') from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/trim.in b/tests/army/query/function/in/trim.in index 6706dfd98a..a0ad54dd7c 100644 --- a/tests/army/query/function/in/trim.in +++ b/tests/army/query/function/in/trim.in @@ -1,125 +1,144 @@ -select trim('foo'); -select trim('foo' from 'foobarfoo'); -select trim(trailing 'foo' from 'foobarfoo'); -select trim(leading 'foo' from 'foobarfoo'); -select trim(both 'foo' from 'foobarfoo'); -select trim(' blank '); -select trim(both ' ' from ' bla nk '); -select trim(leading ' ' from ' bla nk'); -select trim(trailing ' ' from ' bla nk '); -select trim(' ' from ' blank '); -select TRIM(BOTH 'å' FROM 'aæaå'); -select trim(' 中文测试 '); -select trim(both ' ' from ' 中文测试 '); -select trim(leading ' ' from ' 中文测试'); -select trim(trailing ' ' from ' 中文测试 '); -select trim(' ' from ' 中文测试 '); -select trim('一' from '一二中文测试一'); -select trim(both '一' from '一二中文测试一'); -select trim(leading '一' from '一二中文测试一'); -select trim(trailing '一' from '一二中文测试一'); -select trim(' 中文andEnglish测试Test '); -select trim(both ' ' from ' 中文andEnglish测试Test '); -select trim(leading ' ' from ' 中文andEnglish测试Test'); -select trim(trailing ' ' from ' 中文andEnglish测试Test '); -select trim('空格' from '空格中文andEngTes空格空格'); -select trim(both '空格' from '空格中文andEngTes空格空格'); -select trim(leading '空格' from '空格中文andEngTes空格空格'); -select trim(trailing '空格' from '空格中文andEngTes空格空格'); -select trim('blank' from 'blankblank中文andEnglish测试Tesblankblankblank'); -select trim(both 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank'); -select trim(leading 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank'); -select trim(trailing 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank'); -select trim('空格blank' from '空格blank空格中Tes空格blank空'); -select trim(both '空格blank' from '空格blank空格中Tes空格blank空'); -select trim(leading '空格blank' from '空格blank空格中Tes空格blank空'); -select trim(trailing '空格blank' from '空格blank空格中Tes空格blank空'); -select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5; -select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5; -select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5; -select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5; -select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5; -select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5; -select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5; -select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5; -select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5; -select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5; -select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5; -select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5; -select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5; -select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5; -select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5; -select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5; -select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5; -select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5; -select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5; -select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5; -select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5; -select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5; -select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5; -select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5; -select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5; -select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5; -select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5; -select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5; -select trim('一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5; -select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5; -select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5; -select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5; -select trim('一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5; -select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5; -select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5; -select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5; -select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5; -select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5; -select trim(' A '); -select trim(' 涛思 '); -select trim('a' FROM 'aaab bbba'); -select trim(LEADING FROM ' aaa '); -select trim(LEADING 'a' FROM ' aaa abab aaaa '); -select trim(LEADING 'a' FROM 'aaa abab aaaa '); -select trim(LEADING '北' FROM '北京涛思数据科技有限公司北'); -select trim(LEADING '北' FROM '北bei京涛思数据科技有限公司北'); -select trim(TRAILING FROM ' aaa abab aaaa '); -select trim(TRAILING 'a' FROM 'aaa abab aaaa'); -select trim(TRAILING 'a' FROM ' aaa abab aaaa'); -select trim(TRAILING '北' FROM '北京涛思数据科技有限公司北') as sub; -select trim(TRAILING '北' FROM '北京涛思数据科技有限公司bei北'); -select trim(BOTH FROM ' aaa abab aaaa '); -select trim(BOTH 'a' FROM ' aaa abab aaaa '); -select trim(BOTH 'a' FROM 'aaa abab aaaa'); -select trim(BOTH '北' FROM '北京涛思数据科技有限公司北'); -select trim(nch2 from nch1) from ts_4893.d0 order by ts limit 10; -select trim(nch2 from nch1) from ts_4893.meters order by ts limit 10; -select trim(nch2 from var1) from ts_4893.d0 order by ts limit 10; -select trim(nch2 from var1) from ts_4893.meters order by ts limit 10; -select trim(var2 from nch1) from ts_4893.d0 order by ts limit 10; -select trim(var2 from nch1) from ts_4893.meters order by ts limit 10; -select trim(var2 from var1) from ts_4893.d0 order by ts limit 10; -select trim(var2 from var1) from ts_4893.meters order by ts limit 10; +select trim('foo') +select trim('foo' from 'foobarfoo') +select trim(trailing 'foo' from 'foobarfoo') +select trim(leading 'foo' from 'foobarfoo') +select trim(both 'foo' from 'foobarfoo') +select trim(' blank ') +select trim(both ' ' from ' bla nk ') +select trim(leading ' ' from ' bla nk') +select trim(trailing ' ' from ' bla nk ') +select trim(' ' from ' blank ') +select TRIM(BOTH 'å' FROM 'aæaå') +select trim(' 中文测试 ') +select trim(both ' ' from ' 中文测试 ') +select trim(leading ' ' from ' 中文测试') +select trim(trailing ' ' from ' 中文测试 ') +select trim(' ' from ' 中文测试 ') +select trim('一' from '一二中文测试一') +select trim(both '一' from '一二中文测试一') +select trim(leading '一' from '一二中文测试一') +select trim(trailing '一' from '一二中文测试一') +select trim(' 中文andEnglish测试Test ') +select trim(both ' ' from ' 中文andEnglish测试Test ') +select trim(leading ' ' from ' 中文andEnglish测试Test') +select trim(trailing ' ' from ' 中文andEnglish测试Test ') +select trim('空格' from '空格中文andEngTes空格空格') +select trim(both '空格' from '空格中文andEngTes空格空格') +select trim(leading '空格' from '空格中文andEngTes空格空格') +select trim(trailing '空格' from '空格中文andEngTes空格空格') +select trim('blank' from 'blankblank中文andEnglish测试Tesblankblankblank') +select trim(both 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') +select trim(leading 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') +select trim(trailing 'blank' from 'blankblank中文andEnglish测试Tesblankblankblank') +select trim('空格blank' from '空格blank空格中Tes空格blank空') +select trim(both '空格blank' from '空格blank空格中Tes空格blank空') +select trim(leading '空格blank' from '空格blank空格中Tes空格blank空') +select trim(trailing '空格blank' from '空格blank空格中Tes空格blank空') +select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 +select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 +select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 +select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) != 0 order by ts limit 5 +select trim(nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select trim(both nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select trim(leading nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select trim(trailing nch2 from nch1) from ts_4893.meters where position(nch2 in nch1) = 0 order by ts limit 5 +select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 +select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 +select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 +select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) != 0 order by ts limit 5 +select trim(var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select trim(both var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select trim(leading var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select trim(trailing var2 from nch1) from ts_4893.meters where position(var2 in nch1) = 0 order by ts limit 5 +select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 +select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 +select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 +select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) != 0 order by ts limit 5 +select trim(nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select trim(both nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select trim(leading nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select trim(trailing nch2 from var1) from ts_4893.meters where position(nch2 in var1) = 0 order by ts limit 5 +select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 +select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 +select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 +select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) != 0 order by ts limit 5 +select trim(var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select trim(both var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select trim(leading var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select trim(trailing var2 from var1) from ts_4893.meters where position(var2 in var1) = 0 order by ts limit 5 +select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 +select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 +select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 +select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) != 0 order by ts limit 5 +select trim('一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 +select trim(both '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 +select trim(leading '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 +select trim(trailing '一' from nch1) from ts_4893.meters where position('一' in nch1) = 0 order by ts limit 5 +select trim('一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 +select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 +select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 +select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) != 0 order by ts limit 5 +select trim('一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 +select trim(both '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 +select trim(leading '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 +select trim(trailing '一' from var1) from ts_4893.meters where position('一' in var1) = 0 order by ts limit 5 +select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(both nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(leading nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(trailing nch2 from '三abbcfp三a') from ts_4893.meters where position(nch2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') != 0 order by ts limit 5 +select trim(var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(both var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(leading var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(trailing var2 from '三abbcfp三a') from ts_4893.meters where position(var2 in '三abbcfp三a') = 0 order by ts limit 5 +select trim(' A ') +select trim(' 涛思 ') +select trim('a' FROM 'aaab bbba') +select trim(LEADING FROM ' aaa ') +select trim(LEADING 'a' FROM ' aaa abab aaaa ') +select trim(LEADING 'a' FROM 'aaa abab aaaa ') +select trim(LEADING '北' FROM '北京涛思数据科技有限公司北') +select trim(LEADING '北' FROM '北bei京涛思数据科技有限公司北') +select trim(TRAILING FROM ' aaa abab aaaa ') +select trim(TRAILING 'a' FROM 'aaa abab aaaa') +select trim(TRAILING 'a' FROM ' aaa abab aaaa') +select trim(TRAILING '北' FROM '北京涛思数据科技有限公司北') as sub +select trim(TRAILING '北' FROM '北京涛思数据科技有限公司bei北') +select trim(BOTH FROM ' aaa abab aaaa ') +select trim(BOTH 'a' FROM ' aaa abab aaaa ') +select trim(BOTH 'a' FROM 'aaa abab aaaa') +select trim(BOTH '北' FROM '北京涛思数据科技有限公司北') +select trim(nch2 from nch1) from ts_4893.d0 order by ts limit 10 +select trim(nch2 from nch1) from ts_4893.meters order by ts limit 10 +select trim(nch2 from var1) from ts_4893.d0 order by ts limit 10 +select trim(nch2 from var1) from ts_4893.meters order by ts limit 10 +select trim(var2 from nch1) from ts_4893.d0 order by ts limit 10 +select trim(var2 from nch1) from ts_4893.meters order by ts limit 10 +select trim(var2 from var1) from ts_4893.d0 order by ts limit 10 +select trim(var2 from var1) from ts_4893.meters order by ts limit 10 +select trim(null) +select trim('') +select trim(leading ' ' from ' hello') +select trim(trailing ' ' from 'hello ') +select trim('0' from '000123000') +select trim(' hello ') +select trim(' apple banana ') +select var2, trim('*' from var2) from ts_4893.meters limit 1 +select trim('x' from 'hello') +select trim('longer' from 'short') +select trim('hello') +select trim(' 12345 ') +select trim(concat(' hello', ' world ')) +select trim(upper(' hello world ')) +select trim(substring(' hello world ', 4)) +select trim(replace(' hello world ', ' ', '-')) +select name, trim(name) from ts_4893.meters limit 1 +select var1, trim(trailing '!' from var1) from ts_4893.meters limit 1 +select nch1, trim(leading '-' from nch1) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/trunc.in b/tests/army/query/function/in/trunc.in index a341cde4b5..5d4da23a28 100755 --- a/tests/army/query/function/in/trunc.in +++ b/tests/army/query/function/in/trunc.in @@ -1,37 +1,54 @@ -select TRUNCATE(10.55, 3); -select TRUNCATE(10.55, 2); -select TRUNCATE(10.55, 1); -select TRUNCATE(10.55, 0); -select TRUNCATE(10.55, -1); -select TRUNCATE(10.55, -10); -select TRUNCATE(-10.55, 1); -select TRUNCATE(99, 1); -select TRUNCATE(10.55, 1) + 1; -select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123.123456789, 9), 8), 7), 6), 5), 4), 3); -select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123456789.123456789, -1), -2), -3), -4), -5), -6), -7); -select TRUNCATE(87654321.123456789, id) from ts_4893.meters order by ts limit 10; -select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10; -select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10; -select TRUNC(10.55, 3); -select TRUNC(10.55, 2); -select TRUNC(10.55, 1); -select TRUNC(10.55, 0); -select TRUNC(10.55, -1); -select TRUNC(10.55, -10); -select TRUNC(-10.55, 1); -select TRUNC(99, 1); -select TRUNC(10.55, 1) + 1; -select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123.123456789, 9), 8), 7), 6), 5), 4), 3); -select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123456789.123456789, -1), -2), -3), -4), -5), -6), -7); -select TRUNC(87654321.123456789, id) from ts_4893.meters order by ts limit 10; -select TRUNC(current, id) from ts_4893.meters order by ts limit 10; -select TRUNC(current, 1) from ts_4893.meters order by ts limit 10; -select truncate(99.99, 3); -select truncate(99.99, 2); -select truncate(99.99, 1); -select truncate(99.99, 0); -select truncate(99.99, -1); -select truncate(99.99, -10); -select truncate(99, 1); -select truncate(current, 1) from ts_4893.d0 order by ts limit 10; -select truncate(current, 1) from ts_4893.meters order by ts limit 10; +select TRUNCATE(10.55, 3) +select TRUNCATE(10.55, 2) +select TRUNCATE(10.55, 1) +select TRUNCATE(10.55, 0) +select TRUNCATE(10.55, -1) +select TRUNCATE(10.55, -10) +select TRUNCATE(-10.55, 1) +select TRUNCATE(99, 1) +select TRUNCATE(10.55, 1) + 1 +select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123.123456789, 9), 8), 7), 6), 5), 4), 3) +select TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(TRUNCATE(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) +select TRUNCATE(87654321.123456789, id) from ts_4893.meters order by ts limit 10 +select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10 +select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10 +select TRUNC(10.55, 3) +select TRUNC(10.55, 2) +select TRUNC(10.55, 1) +select TRUNC(10.55, 0) +select TRUNC(10.55, -1) +select TRUNC(10.55, -10) +select TRUNC(-10.55, 1) +select TRUNC(99, 1) +select TRUNC(10.55, 1) + 1 +select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123.123456789, 9), 8), 7), 6), 5), 4), 3) +select TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(TRUNC(123456789.123456789, -1), -2), -3), -4), -5), -6), -7) +select TRUNC(87654321.123456789, id) from ts_4893.meters order by ts limit 10 +select TRUNC(current, id) from ts_4893.meters order by ts limit 10 +select TRUNC(current, 1) from ts_4893.meters order by ts limit 10 +select truncate(99.99, 3) +select truncate(99.99, 2) +select truncate(99.99, 1) +select truncate(99.99, 0) +select truncate(99.99, -1) +select truncate(99.99, -10) +select truncate(99, 1) +select truncate(current, 1) from ts_4893.d0 order by ts limit 10 +select truncate(current, 1) from ts_4893.meters order by ts limit 10 +select truncate(99.99, null) +select truncate(null, 3) +select truncate(1.0001, 3) +select truncate(2.71828, 4) +select truncate(3.14159, 2) +select truncate(100.9876, 2) +select truncate(99999999999999.9999, 2) +select truncate(-5.678, 2) +select truncate(voltage, 2) from ts_4893.meters limit 1 +select truncate(current, 1) from ts_4893.meters limit 1 +select truncate(phase, 3) from ts_4893.meters limit 1 +select truncate(voltage + current, 2) from ts_4893.meters limit 1 +select truncate(voltage, -1) from ts_4893.meters limit 1 +select round(truncate(voltage, 1), 2) from ts_4893.meters limit 1 +select truncate(abs(current), 1) from ts_4893.meters limit 1 +select truncate(exp(phase), 2) from ts_4893.meters limit 1 +select truncate(log(current), 1) from ts_4893.meters limit 1 diff --git a/tests/army/query/function/in/varpop.in b/tests/army/query/function/in/varpop.in index 1a8f5e6149..d828f268a3 100644 --- a/tests/army/query/function/in/varpop.in +++ b/tests/army/query/function/in/varpop.in @@ -1,10 +1,20 @@ -select VAR_POP(current) from ts_4893.meters; -select VAR_POP(current) from ts_4893.meters interval(1d) order by 1 limit 10; -select VAR_POP(id) from ts_4893.meters; -select VAR_POP(id) from ts_4893.meters interval(1d) limit 10; -select VAR_POP(id) from ts_4893.meters where id > 100; -select VAR_POP(id) from ts_4893.meters interval(1d) order by 1 limit 10; -select var_pop(id) from ts_4893.d0; -select var_pop(id) from ts_4893.meters; -select var_pop(current) from ts_4893.d0; -select var_pop(current) from ts_4893.meters; +select VAR_POP(current) from ts_4893.meters +select VAR_POP(current) from ts_4893.meters interval(1d) order by 1 limit 10 +select VAR_POP(id) from ts_4893.meters +select VAR_POP(id) from ts_4893.meters interval(1d) limit 10 +select VAR_POP(id) from ts_4893.meters where id > 100 +select VAR_POP(id) from ts_4893.meters interval(1d) order by 1 limit 10 +select var_pop(null) from ts_4893.meters +select var_pop(id) from ts_4893.d0 +select var_pop(current) from ts_4893.d0 +select var_pop(voltage) from ts_4893.meters +select var_pop(voltage) from ts_4893.meters where voltage is not null +select var_pop(phase) from ts_4893.meters +select var_pop(phase) from ts_4893.meters where ts between '2023-01-01 00:00:00' and '2023-12-31 23:59:59' +select var_pop(total_voltage) from (select sum(voltage) as total_voltage from ts_4893.meters group by location) +select round(var_pop(current), 2) from ts_4893.meters +select pow(var_pop(current), 2) from ts_4893.meters +select log(var_pop(voltage) + 1) from ts_4893.meters +select groupid, var_pop(voltage) from ts_4893.meters group by groupid order by groupid +select location, var_pop(current) from ts_4893.meters group by location order by location +select location, var_pop(voltage) from ts_4893.meters group by location order by location diff --git a/tests/army/query/function/in/week.in b/tests/army/query/function/in/week.in index a6b2bf161a..d449bf1e89 100644 --- a/tests/army/query/function/in/week.in +++ b/tests/army/query/function/in/week.in @@ -1,75 +1,93 @@ -select WEEK('2020-01-01 00:00:00'); -select WEEK('2020-01-01 00:00:00', 0); -select WEEK('2020-01-01 00:00:00', 1); -select WEEK('2020-01-01 00:00:00', 2); -select WEEK('2020-01-01 00:00:00', 3); -select WEEK('2020-01-01 00:00:00', 4); -select WEEK('2020-01-01 00:00:00', 5); -select WEEK('2020-01-01 00:00:00', 6); -select WEEK('2020-01-01 00:00:00', 7); -select WEEK('2021-01-01 00:00:00'); -select WEEK('2021-01-01 00:00:00', 0); -select WEEK('2021-01-01 00:00:00', 1); -select WEEK('2021-01-01 00:00:00', 2); -select WEEK('2021-01-01 00:00:00', 3); -select WEEK('2021-01-01 00:00:00', 4); -select WEEK('2021-01-01 00:00:00', 5); -select WEEK('2021-01-01 00:00:00', 6); -select WEEK('2021-01-01 00:00:00', 7); -select WEEK('1998-01-01 00:00:00'); -select WEEK('1998-01-01 00:00:00', 0); -select WEEK('1998-01-01 00:00:00', 1); -select WEEK('1998-01-01 00:00:00', 2); -select WEEK('1998-01-01 00:00:00', 3); -select WEEK('1998-01-01 00:00:00', 4); -select WEEK('1998-01-01 00:00:00', 5); -select WEEK('1998-01-01 00:00:00', 6); -select WEEK('1998-01-01 00:00:00', 7); -select WEEK('1998-12-31 00:00:00'); -select WEEK('1998-12-31 00:00:00', 0); -select WEEK('1998-12-31 00:00:00', 1); -select WEEK('1998-12-31 00:00:00', 2); -select WEEK('1998-12-31 00:00:00', 3); -select WEEK('1998-12-31 00:00:00', 4); -select WEEK('1998-12-31 00:00:00', 5); -select WEEK('1998-12-31 00:00:00', 6); -select WEEK('1998-12-31 00:00:00', 7); -select WEEK('2000-01-06 00:00:00'); -select WEEK('2000-01-06 00:00:00', 0); -select WEEK('2000-01-06 00:00:00', 1); -select WEEK('2000-01-06 00:00:00', 2); -select WEEK('2000-01-06 00:00:00', 3); -select WEEK('2000-01-06 00:00:00', 4); -select WEEK('2000-01-06 00:00:00', 5); -select WEEK('2000-01-06 00:00:00', 6); -select WEEK('2000-01-06 00:00:00', 7); -select WEEK(1725095657); -select WEEK(1725095657, 0); -select WEEK(1725095657, 1); -select WEEK(1725095657, 2); -select WEEK(1725095657, 3); -select WEEK(1725095657, 4); -select WEEK(1725095657, 5); -select WEEK(1725095657, 6); -select WEEK(ts) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 0) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 1) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 2) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 3) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 4) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 5) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 6) from ts_4893.meters order by ts limit 10; -select WEEK(ts, 7) from ts_4893.meters order by ts limit 10; -select week(123); -select week('2000-01-01',0); -select week('2000-01-01',1); -select week('2000-01-01',2); -select week('2000-01-01',3); -select week('2000-01-01',4); -select week('2000-01-01',5); -select week('2000-01-01',6); -select week('2000-01-01',7); -select week(1721020591,0); -select week('2020-01-01 00:00:00', 2); -select week(ts) from ts_4893.d0 order by ts limit 10; -select week(ts) from ts_4893.meters order by ts limit 10; +select WEEK('2020-01-01 00:00:00') +select WEEK('2020-01-01 00:00:00', 0) +select WEEK('2020-01-01 00:00:00', 1) +select WEEK('2020-01-01 00:00:00', 2) +select WEEK('2020-01-01 00:00:00', 3) +select WEEK('2020-01-01 00:00:00', 4) +select WEEK('2020-01-01 00:00:00', 5) +select WEEK('2020-01-01 00:00:00', 6) +select WEEK('2020-01-01 00:00:00', 7) +select WEEK('2021-01-01 00:00:00') +select WEEK('2021-01-01 00:00:00', 0) +select WEEK('2021-01-01 00:00:00', 1) +select WEEK('2021-01-01 00:00:00', 2) +select WEEK('2021-01-01 00:00:00', 3) +select WEEK('2021-01-01 00:00:00', 4) +select WEEK('2021-01-01 00:00:00', 5) +select WEEK('2021-01-01 00:00:00', 6) +select WEEK('2021-01-01 00:00:00', 7) +select WEEK('1998-01-01 00:00:00') +select WEEK('1998-01-01 00:00:00', 0) +select WEEK('1998-01-01 00:00:00', 1) +select WEEK('1998-01-01 00:00:00', 2) +select WEEK('1998-01-01 00:00:00', 3) +select WEEK('1998-01-01 00:00:00', 4) +select WEEK('1998-01-01 00:00:00', 5) +select WEEK('1998-01-01 00:00:00', 6) +select WEEK('1998-01-01 00:00:00', 7) +select WEEK('1998-12-31 00:00:00') +select WEEK('1998-12-31 00:00:00', 0) +select WEEK('1998-12-31 00:00:00', 1) +select WEEK('1998-12-31 00:00:00', 2) +select WEEK('1998-12-31 00:00:00', 3) +select WEEK('1998-12-31 00:00:00', 4) +select WEEK('1998-12-31 00:00:00', 5) +select WEEK('1998-12-31 00:00:00', 6) +select WEEK('1998-12-31 00:00:00', 7) +select WEEK('2000-01-06 00:00:00') +select WEEK('2000-01-06 00:00:00', 0) +select WEEK('2000-01-06 00:00:00', 1) +select WEEK('2000-01-06 00:00:00', 2) +select WEEK('2000-01-06 00:00:00', 3) +select WEEK('2000-01-06 00:00:00', 4) +select WEEK('2000-01-06 00:00:00', 5) +select WEEK('2000-01-06 00:00:00', 6) +select WEEK('2000-01-06 00:00:00', 7) +select WEEK(1725095657) +select WEEK(1725095657, 0) +select WEEK(1725095657, 1) +select WEEK(1725095657, 2) +select WEEK(1725095657, 3) +select WEEK(1725095657, 4) +select WEEK(1725095657, 5) +select WEEK(1725095657, 6) +select WEEK(ts) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 0) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 1) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 2) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 3) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 4) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 5) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 6) from ts_4893.meters order by ts limit 10 +select WEEK(ts, 7) from ts_4893.meters order by ts limit 10 +select week(123) +select week('2000-01-01',0) +select week('2000-01-01',1) +select week('2000-01-01',2) +select week('2000-01-01',3) +select week('2000-01-01',4) +select week('2000-01-01',5) +select week('2000-01-01',6) +select week('2000-01-01',7) +select week(1721020591,0) +select week('2020-01-01 00:00:00', 2) +select week(ts) from ts_4893.d0 order by ts limit 10 +select week(ts) from ts_4893.meters order by ts limit 10 +select week(null, 0) +select week('abc') +select week('1721020591', 0) +select week('1721020666229', 0) +select week('20200101', 2) +select week('11/01/31', 2) +select week('20/01/01', 2) +select week('01/01/2020', 2) +select week('01-JAN-20', 2) +select week('2023-09-25') +select week('9999-12-31') +select week('2024-02-29 00:00:00') +select week(ts) from ts_4893.meters limit 1 +select week(name) from ts_4893.meters limit 1 +select week(ts), dayofweek(ts) from ts_4893.meters limit 1 +select week(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 +select id, week(ts) from ts_4893.meters where id = 1 limit 1 +select groupid, sum(week(ts)) from ts_4893.meters group by groupid order by groupid diff --git a/tests/army/query/function/in/weekday.in b/tests/army/query/function/in/weekday.in index 7e73967047..b421fa3930 100644 --- a/tests/army/query/function/in/weekday.in +++ b/tests/army/query/function/in/weekday.in @@ -1,19 +1,38 @@ -select WEEKDAY('2020-01-01 00:00:00'); -select WEEKDAY('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKDAY('2021-01-01 00:00:00'); -select WEEKDAY('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKDAY('1998-01-01 00:00:00'); -select WEEKDAY('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKDAY('1998-12-31 00:00:00'); -select WEEKDAY('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKDAY('2000-01-06 00:00:00'); -select WEEKDAY('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKDAY(1725095657); -select WEEKDAY(1725095657) from ts_4893.meters order by ts limit 10; -select WEEKDAY(ts) from ts_4893.meters order by ts limit 10; -select weekday('2020-01-01'); -select weekday(1721020591); -select weekday(1721020666229); -select weekday('2020-01-01 00:00:00'); -select weekday(ts) from ts_4893.d0 order by ts limit 10; -select weekday(ts) from ts_4893.meters order by ts limit 10; +select WEEKDAY('2020-01-01 00:00:00') +select WEEKDAY('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKDAY('2021-01-01 00:00:00') +select WEEKDAY('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKDAY('1998-01-01 00:00:00') +select WEEKDAY('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKDAY('1998-12-31 00:00:00') +select WEEKDAY('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKDAY('2000-01-06 00:00:00') +select WEEKDAY('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKDAY(1725095657) +select WEEKDAY(1725095657) from ts_4893.meters order by ts limit 10 +select WEEKDAY(ts) from ts_4893.meters order by ts limit 10 +select weekday('2020-01-01') +select weekday(1721020591) +select weekday(1721020666229) +select weekday('2020-01-01 00:00:00') +select weekday(ts) from ts_4893.d0 order by ts limit 10 +select weekday(ts) from ts_4893.meters order by ts limit 10 +select weekday(null) +select weekday('abc') +select weekday('1721020591') +select weekday('1721020666229') +select weekday('01/01/2020') +select weekday('20200101') +select weekday('20/01/01') +select weekday('11/01/32') +select weekday('01-JAN-20') +select weekday('2024-02-29') +select weekday('2023-09-24') +select weekday('2023-09-25') +select weekday('9999-12-31') +select weekday(name) from ts_4893.meters limit 1 +select weekday(ts), dayofweek(ts) from ts_4893.meters limit 1 +select weekday(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 +select weekday(ts) from ts_4893.meters limit 1 +select id, weekday(ts) from ts_4893.meters where id = 1 limit 1 +select groupid, sum(weekday(ts)) from ts_4893.meters group by groupid order by groupid diff --git a/tests/army/query/function/in/weekofyear.in b/tests/army/query/function/in/weekofyear.in index 8ac1b745ab..ac201c37c6 100644 --- a/tests/army/query/function/in/weekofyear.in +++ b/tests/army/query/function/in/weekofyear.in @@ -1,18 +1,37 @@ -select WEEKOFYEAR('2020-01-01 00:00:00'); -select WEEKOFYEAR('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR('2021-01-01 00:00:00'); -select WEEKOFYEAR('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR('1998-01-01 00:00:00'); -select WEEKOFYEAR('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR('1998-12-31 00:00:00'); -select WEEKOFYEAR('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR('2000-01-06 00:00:00'); -select WEEKOFYEAR('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR(1725095657); -select WEEKOFYEAR(1725095657) from ts_4893.meters order by ts limit 10; -select WEEKOFYEAR(ts) from ts_4893.meters order by ts limit 10; -select weekofyear('2020-01-01'); -select weekofyear(1721020666); -select weekofyear(1721020666229); -select weekofyear(ts) from ts_4893.d0 order by ts limit 10; -select weekofyear(ts) from ts_4893.meters order by ts limit 10; +select WEEKOFYEAR('2020-01-01 00:00:00') +select WEEKOFYEAR('2020-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR('2021-01-01 00:00:00') +select WEEKOFYEAR('2021-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR('1998-01-01 00:00:00') +select WEEKOFYEAR('1998-01-01 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR('1998-12-31 00:00:00') +select WEEKOFYEAR('1998-12-31 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR('2000-01-06 00:00:00') +select WEEKOFYEAR('2000-01-06 00:00:00') from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR(1725095657) +select WEEKOFYEAR(1725095657) from ts_4893.meters order by ts limit 10 +select WEEKOFYEAR(ts) from ts_4893.meters order by ts limit 10 +select weekofyear('2020-01-01') +select weekofyear(1721020666) +select weekofyear(1721020666229) +select weekofyear(ts) from ts_4893.d0 order by ts limit 10 +select weekofyear(ts) from ts_4893.meters order by ts limit 10 +select weekofyear(null) +select weekofyear('1721020591') +select weekofyear('1721020666229') +select weekofyear('abc') +select weekofyear('01/01/2020') +select weekofyear('20200101') +select weekofyear('20/01/01') +select weekofyear('11/01/31') +select weekofyear('01-JAN-20') +select weekofyear('2024-02-29') +select weekofyear('2024-01-01') +select weekofyear('2024-12-31') +select weekofyear('9999-12-31') +select weekofyear(name) from ts_4893.meters limit 1 +select weekofyear(ts) from ts_4893.meters limit 1 +select weekofyear(ts), dayofweek(ts) from ts_4893.meters limit 1 +select weekofyear(timediff(ts, '2024-10-10 09:36:50.172')) from ts_4893.meters limit 1 +select id, weekofyear(ts) from ts_4893.meters where id = 1 limit 1 +select groupid, sum(weekofyear(ts)) from ts_4893.meters group by groupid order by groupid diff --git a/tests/army/query/function/test_function.py b/tests/army/query/function/test_function.py index aae0cf6eee..bf7cf49290 100644 --- a/tests/army/query/function/test_function.py +++ b/tests/army/query/function/test_function.py @@ -11,20 +11,12 @@ # -*- coding: utf-8 -*- -import sys -import time -import random - -import taos -import frame - +from frame import etool from frame.etool import * from frame.log import * from frame.cases import * from frame.sql import * from frame.caseBase import * - -from frame import etool from frame.common import * class TDTestCase(TBase): @@ -36,17 +28,16 @@ class TDTestCase(TBase): "queryBufferSize": 10240 } - def insertData(self): + def insert_data(self): tdLog.info(f"insert data.") - # taosBenchmark run datafile = etool.curFile(__file__, "data/d1001.data") tdSql.execute("create database ts_4893;") - tdSql.execute(f"use ts_4893;") + tdSql.execute("use ts_4893;") tdSql.execute("select database();") tdSql.execute("CREATE STABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT, " - "`id` INT, `name` VARCHAR(64), `nch1` NCHAR(50), `nch2` NCHAR(50), `var1` VARCHAR(50), " - "`var2` VARCHAR(50)) TAGS (`groupid` TINYINT, `location` VARCHAR(16));") + "`id` INT, `name` VARCHAR(64), `nch1` NCHAR(50), `nch2` NCHAR(50), `var1` VARCHAR(50), " + "`var2` VARCHAR(50)) TAGS (`groupid` TINYINT, `location` VARCHAR(16));") tdSql.execute("CREATE table d0 using meters tags(1, 'beijing')") tdSql.execute("insert into d0 file '%s'" % datafile) @@ -63,12 +54,9 @@ class TDTestCase(TBase): continue sql_statement += line.strip() - if sql_statement.endswith(';'): - # 去掉末尾的分号 sql_statement = sql_statement.rstrip(';') tdSql.checkDataCsvByLine(sql_statement, ansFile) - # 清空 sql_statement 以便处理下一条语句 sql_statement = '' err_file_path = etool.curFile(__file__, f"in/{testCase}.err") if not os.path.isfile(err_file_path): @@ -80,16 +68,15 @@ class TDTestCase(TBase): continue err_statement += line.strip() - if err_statement.endswith(';'): tdSql.error(err_statement) err_statement = '' def test_normal_query_new(self, testCase): # read sql from .sql file and execute - tdLog.info(f"test normal query.") + tdLog.info("test normal query.") self.sqlFile = etool.curFile(__file__, f"in/{testCase}.in") - self.ansFile = etool.curFile(__file__, f"ans/{testCase}_1.csv") + self.ansFile = etool.curFile(__file__, f"ans/{testCase}.csv") tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase) @@ -97,531 +84,230 @@ class TDTestCase(TBase): self.test_normal_query_new("pi") def test_round(self): - self.test_normal_query("round") + self.test_normal_query_new("round") - tdSql.query("select round(10, null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select round(null, 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select round(name, 2) from ts_4893.meters limit 1;") def test_exp(self): - self.test_normal_query("exp") + self.test_normal_query_new("exp") - tdSql.query("select exp(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + def test_truncate(self): + self.test_normal_query_new("trunc") - def test_trunc(self): - self.test_normal_query("trunc") - - tdSql.query("select truncate(99.99, null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select truncate(null, 3);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select truncate(0.999);") + tdSql.error("select truncate(-1.999);") + tdSql.error("select truncate(null);") + tdSql.error("select truncate(name, 1) from ts_4893.meters limit 1;") def test_ln(self): - self.test_normal_query("ln") + self.test_normal_query_new("ln") - tdSql.query("select ln(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select ln(name) from ts_4893.meters limit 1;") def test_mod(self): - self.test_normal_query("mod") + self.test_normal_query_new("mod") - tdSql.query("select mod(null, 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select mod(10, null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select mod(10, 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select mod(name, 2) from ts_4893.meters limit 1;") def test_sign(self): - self.test_normal_query("sign") + self.test_normal_query_new("sign") - tdSql.query("select sign(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select sign('');") + tdSql.error("select sign('abc');") + tdSql.error("select sign('123');") + tdSql.error("select sign('-456');") def test_degrees(self): - self.test_normal_query("degrees") + self.test_normal_query_new("degrees") - tdSql.query("select degrees(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select degrees('');") + tdSql.error("select degrees('abc');") + tdSql.error("select degrees('1.57');") def test_radians(self): - self.test_normal_query("radians") + self.test_normal_query_new("radians") - tdSql.query("select radians(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select radians('');") + tdSql.error("select radians('abc');") + tdSql.error("select radians('45');") def test_char_length(self): - self.test_normal_query("char_length") + self.test_normal_query_new("char_length") - tdSql.query("select char_length(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select char_length(12345);") + tdSql.error("select char_length(true);") + tdSql.error("select char_length(repeat('a', 1000000));") + tdSql.error("select char_length(id) from ts_4893.meters;") def test_char(self): - self.test_normal_query("char") + self.test_normal_query_new("char") - tdSql.query("select char(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') + res = [[chr(0)], [chr(1)], [chr(2)], [chr(3)], [chr(4)], [chr(5)], [chr(6)], [chr(7)], [chr(8)], [chr(9)]] + tdSql.checkDataMem("select char(id) from ts_4893.d0 limit 10;", res) + tdSql.checkDataMem("select char(id) from ts_4893.meters limit 10;", res) - tdSql.query("select char('ustc');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, chr(0)) - - result1 = [[chr(0)], [chr(1)], [chr(2)], [chr(3)], [chr(4)], [chr(5)], [chr(6)], [chr(7)], [chr(8)], [chr(9)]] - tdSql.checkDataMem("select char(id) from ts_4893.d0 limit 10;", result1) - tdSql.checkDataMem("select char(id) from ts_4893.meters limit 10;", result1) - - result2 = [[chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)]] - tdSql.checkDataMem("select char(nch1) from ts_4893.d0 limit 10;", result2) - tdSql.checkDataMem("select char(nch1) from ts_4893.meters limit 10;", result2) - - tdSql.checkDataMem("select char(var1) from ts_4893.d0 limit 10;", result2) - tdSql.checkDataMem("select char(var1) from ts_4893.meters limit 10;", result2) + res = [[chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)], [chr(0)]] + tdSql.checkDataMem("select char(nch1) from ts_4893.d0 limit 10;", res) + tdSql.checkDataMem("select char(nch1) from ts_4893.meters limit 10;", res) + tdSql.checkDataMem("select char(var1) from ts_4893.d0 limit 10;", res) + tdSql.checkDataMem("select char(var1) from ts_4893.meters limit 10;", res) def test_ascii(self): - self.test_normal_query("ascii") + self.test_normal_query_new("ascii") - tdSql.query("select ascii(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select ascii(123);") def test_position(self): - self.test_normal_query("position") - - tdSql.query("select position('t' in null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select position(null in 'taos');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + self.test_normal_query_new("position") def test_replace(self): - self.test_normal_query("replace") - - tdSql.query("select replace(null, 'aa', 'ee');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select replace('aabbccdd', null, 'ee');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + self.test_normal_query_new("replace") def test_repeat(self): - self.test_normal_query("repeat") - - tdSql.query("select repeat('taos', null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select repeat(null, 3);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select repeat('taos', 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') + self.test_normal_query_new("repeat") def test_substr(self): - self.test_normal_query("substr") - - tdSql.query("select substring('tdengine', null, 3);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring(null, 1, 3);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring('tdengine', 1, null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring('tdengine', 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') - - tdSql.query("select substring('tdengine', 10);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') - - tdSql.query("select substring('tdengine', 1, 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') - - tdSql.query("select substring('tdengine', 1, -1);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') + self.test_normal_query_new("substr") def test_substr_idx(self): - self.test_normal_query("substr_idx") - - tdSql.query("select substring_index(null, '.', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring_index('www.taosdata.com', null, 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring_index('www.taosdata.com', '.', null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select substring_index('www.taosdata.com', '.', 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, '') + self.test_normal_query_new("substr_idx") def test_trim(self): - self.test_normal_query("trim") - - tdSql.query("select trim(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + self.test_normal_query_new("trim") def test_timediff(self): - self.test_normal_query("timediff") + self.test_normal_query_new("timediff") - tdSql.query("select timediff(null, '2022-01-01 08:00:01',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('2022-01-01 08:00:00', null,1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('2022/01/31', '2022/01/01',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('20220131', '20220101',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('22/01/31', '22/01/01',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('01/31/22', '01/01/22',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('31-JAN-22', '01-JAN-22',1s);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('22/01/31', '22/01/01');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select timediff('www', 'ttt');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select timediff(min(ts), '2023-01-01 00:00:00') from ts_4893.meters limit 1;") + tdSql.error("select timediff(max(ts), '2023-12-31 23:59:59') from ts_4893.meters limit 1;") + tdSql.error("select (select timediff(ts, (select max(ts) from ts_4893.meters)) from ts_4893.meters where id = m.id) from ts_4893.meters m;") def test_week(self): - self.test_normal_query("week") - - tdSql.query("select week(null, 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('abc');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('1721020591', 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('1721020666229', 0);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('01/01/2020', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('20200101', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('20/01/01', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('11/01/31', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select week('01-JAN-20', 2);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + self.test_normal_query_new("week") def test_weekday(self): - self.test_normal_query("weekday") + self.test_normal_query_new("weekday") - tdSql.query("select weekday(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('1721020591');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('1721020666229');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('abc');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('01/01/2020');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('20200101');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('20/01/01');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('11/01/32');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekday('01-JAN-20');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select weekday(hello) from ts_4893.meters limit 1;") def test_weekofyear(self): - self.test_normal_query("weekofyear") - - tdSql.query("select weekofyear(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('1721020591');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('1721020666229');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('abc');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('01/01/2020');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('20200101');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('20/01/01');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('11/01/31');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select weekofyear('01-JAN-20');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + self.test_normal_query_new("weekofyear") def test_dayofweek(self): - self.test_normal_query("dayofweek") + self.test_normal_query_new("dayofweek") - tdSql.query("select dayofweek(null);") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + def test_stddev_pop(self): + self.test_normal_query_new("stddev") - tdSql.query("select dayofweek('1721020591');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('1721020666229');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('abc');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('01/01/2020');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('20200101');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('20/01/01');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('11/01/31');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select dayofweek('01-JAN-20');") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - def test_stddev(self): - self.test_normal_query("stddev") - - tdSql.query("select stddev_pop(null) from ts_4893.d0;") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select stddev_pop(null) from ts_4893.meters;") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) + tdSql.error("select stddev_pop(var1) from ts_4893.meters;") + tdSql.error("select stddev_pop(current) from empty_ts_4893.meters;") + tdSql.error("select stddev_pop(name) from ts_4893.meters;") + tdSql.error("select stddev_pop(nonexistent_column) from ts_4893.meters;") def test_varpop(self): - self.test_normal_query("varpop") + self.test_normal_query_new("varpop") - tdSql.query("select var_pop(null) from ts_4893.d0;") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - - tdSql.query("select var_pop(null) from ts_4893.meters;") - tdSql.checkRows(1) - tdSql.checkData(0, 0, None) - def test_error(self): - tdSql.error( - "select * from (select to_iso8601(ts, timezone()), timezone() from meters order by ts desc) limit 1000;", - expectErrInfo="Not supported timzone format") # TS-5340 + tdSql.error("select var_pop(var1) from ts_4893.meters;") + tdSql.error("select var_pop(current) from empty_ts_4893.meters;") + tdSql.error("select var_pop(name) from ts_4893.meters;") + tdSql.error("select var_pop(nonexistent_column) from ts_4893.meters;") def test_rand(self): - self.test_normal_query("rand") + self.test_normal_query_new("rand") tdSql.query("select rand();") tdSql.checkRows(1) tdSql.checkCols(1) - self.check_result_in_range(0, 0) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) tdSql.query("select rand(null);") tdSql.checkRows(1) tdSql.checkCols(1) - self.check_result_in_range(0, 0) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) + + tdSql.query("select rand() where rand() >= 0;") + tdSql.checkRows(1) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) + + tdSql.query("select rand() where rand() < 1;") + tdSql.checkRows(1) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) + + tdSql.query("select rand() where rand() >= 0 and rand() < 1;") + tdSql.checkRows(1) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) tdSql.query("select rand() from (select 1) t limit 1;") tdSql.checkRows(1) tdSql.checkCols(1) - self.check_result_in_range(0, 0) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) - tdSql.query("select rand(id) from ts_4893.d0 limit 100;") - tdSql.checkRows(100) + tdSql.query("select round(rand(), 3)") + tdSql.checkRows(1) tdSql.checkCols(1) - for i in range(len(tdSql.res)): - self.check_result_in_range(i, 0) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) - tdSql.query("select rand(id) from ts_4893.meters limit 100;") - tdSql.checkRows(100) + tdSql.query("select pow(rand(), 2)") + tdSql.checkRows(1) tdSql.checkCols(1) - for i in range(len(tdSql.res)): - self.check_result_in_range(i, 0) + res = tdSql.getData(0, 0) + self.check_rand_data_range(res, 0) - tdSql.query("select rand(123), rand(123);") + tdSql.query("select rand(12345), rand(12345);") tdSql.checkRows(1) tdSql.checkCols(2) - if tdSql.res[0][0] != tdSql.res[0][1]: + res0 = tdSql.getData(0, 0) + res1 = tdSql.getData(0, 1) + if res0 != res1: caller = inspect.getframeinfo(inspect.stack()[1][0]) - args = (caller.filename, caller.lineno, tdSql.sql, tdSql.res[0][0], tdSql.res[0][1]) - tdLog.exit("%s(%d) failed: sql:%s data1:%s ne data2:%s" % args) + args = (caller.filename, caller.lineno, self.sql, 1, self.queryRows) + tdLog.exit("%s(%d) failed: sql:%s, row:%d is larger than queryRows:%d" % args) - def check_result_in_range(self, row, col): - res = tdSql.res[row][col] - if res < 0 or res >= 1: + tdSql.error("select rand(3.14);") + tdSql.error("select rand(-3.14);") + tdSql.error("select rand('');") + tdSql.error("select rand('hello');") + + def check_rand_data_range(self, data, row): + if data < 0 or data >= 1: caller = inspect.getframeinfo(inspect.stack()[1][0]) - args = (caller.filename, caller.lineno, tdSql.sql, row, col, res) - tdLog.exit("%s(%d) failed: sql:%s row:%s col:%s data:%s lt 0 or ge 1" % args) + args = (caller.filename, caller.lineno, self.sql, row+1, self.queryRows) + tdLog.exit("%s(%d) failed: sql:%s, row:%d is larger than queryRows:%d" % args) def test_max(self): - self.test_normal_query("max") + self.test_normal_query_new("max") - tdSql.query("select max(null) from ts_4893.meters;") - tdSql.checkRows(1) - tdSql.checkCols(1) - tdSql.checkData(0, 0, 'None') - - tdSql.query("select max(id) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select max(name) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select max(current) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select max(nch1) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select max(var1) from ts_4893.meters;") - tdSql.checkRows(1) + tdSql.error("select max(nonexistent_column) from ts_4893.meters;") def test_min(self): - self.test_normal_query("min") + self.test_normal_query_new("min") - tdSql.query("select min(null) from ts_4893.meters;") - tdSql.checkRows(1) - tdSql.checkCols(1) - tdSql.checkData(0, 0, 'None') + tdSql.error("select min(nonexistent_column) from ts_4893.meters;") - tdSql.query("select min(id) from ts_4893.meters;") - tdSql.checkRows(1) + def test_error(self): + tdSql.error("select * from (select to_iso8601(ts, timezone()), timezone() from ts_4893.meters \ + order by ts desc) limit 1000;", expectErrInfo="Not supported timzone format") # TS-5340 - tdSql.query("select min(name) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select min(current) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select min(nch1) from ts_4893.meters;") - tdSql.checkRows(1) - - tdSql.query("select min(var1) from ts_4893.meters;") - tdSql.checkRows(1) - - # run def run(self): tdLog.debug(f"start to excute {__file__}") - # insert data - self.insertData() + self.insert_data() # math function self.test_pi() self.test_round() self.test_exp() - self.test_trunc() + self.test_truncate() self.test_ln() self.test_mod() self.test_sign() @@ -648,7 +334,7 @@ class TDTestCase(TBase): self.test_dayofweek() # agg function - self.test_stddev() + self.test_stddev_pop() self.test_varpop() # select function diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim index c10413f23c..67c8ac3673 100644 --- a/tests/script/tsim/scalar/caseWhen.sim +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -397,7 +397,7 @@ sql select case when f1 then f1 when f1 + 1 then f1 + 1 else f1 is null end from if $rows != 4 then return -1 endi -if $data00 != 1 then +if $data00 != 1.000000 then return -1 endi if $data10 != 1 then @@ -406,26 +406,26 @@ endi if $data20 != 5 then return -1 endi -if $data30 != 1 then +if $data30 != true then return -1 endi sql select case when f1 then 3 when ts then ts end from tba1; -if $rows != 4 then + if $rows != 4 then + return -1 + endi + if $data00 != 1664176501000 then return -1 -endi -if $data00 != 1664176501000 then - return -1 -endi -if $data10 != 3 then - return -1 -endi -if $data20 != 3 then - return -1 -endi -if $data30 != 1664176504000 then - return -1 -endi + endi + if $data10 != 3 then + return -1 + endi + if $data20 != 3 then + return -1 + endi + if $data30 != 1664176504000 then + return -1 + endi sql select case when 3 then f1 end from tba1; if $rows != 4 then @@ -601,7 +601,6 @@ endi if $data30 != 1.000000000 then return -1 endi - sql select sum(case f1 when f1 then f1 + 1 else f1 is null end + 1) from tba1; if $rows != 1 then return -1 @@ -660,10 +659,10 @@ endi if $data00 != 0 then return -1 endi -if $data10 != 10 then +if $data10 != 10.000000 then return -1 endi -if $data20 != 50 then +if $data20 != 50.000000 then return -1 endi if $data30 != -1 then @@ -890,19 +889,19 @@ endi if $data10 != 0 then return -1 endi -if $data11 != -99.000000000 then +if $data11 != -99.000000 then return -1 endi if $data20 != 1 then return -1 endi -if $data21 != 100.000000000 then +if $data21 != 100.000000 then return -1 endi if $data30 != 5 then return -1 endi -if $data31 != -94.000000000 then +if $data31 != -94.000000 then return -1 endi @@ -1029,13 +1028,13 @@ endi if $data00 != NULL then return -1 endi -if $data10 != -99.000000000 then +if $data10 != -99.000000 then return -1 endi -if $data20 != 1.000000000 then +if $data20 != 1 then return -1 endi -if $data30 != 5.000000000 then +if $data30 != 5 then return -1 endi @@ -1052,13 +1051,117 @@ endi if $data21 != NULL then return -1 endi -if $data31 != 101 then +if $data31 != 101.000000 then return -1 endi -if $data41 != 103 then +if $data41 != 103.000000 then return -1 endi sql_error select case when sum(f1) then sum(f1)-abs(f1) end from tba1; +sql drop database if exists test_db; +sql create database test_db vgroups 5; +sql use test_db; +sql create stable test_stable (ts TIMESTAMP,c_int INT,c_uint INT UNSIGNED, c_bigint BIGINT, c_ubigint BIGINT UNSIGNED, c_float FLOAT, c_double DOUBLE, c_binary BINARY(20), c_smallint SMALLINT, c_usmallint SMALLINT UNSIGNED, c_tinyint TINYINT,c_utinyint TINYINT UNSIGNED,c_bool BOOL,c_nchar NCHAR(20), c_varchar VARCHAR(20), c_varbinary VARBINARY(20), c_geometry GEOMETRY(50)) tags(tag_id JSON); +sql create table t_test using test_stable tags('{\"tag1\":5}'); +sql insert into t_test values ('2022-09-30 15:15:01',123,456,1234567890,9876543210,123.45,678.90,'binary_val',32767,65535,127,255,true,'涛思数据','varchar_val', '1101', 'point(10 10)'); + +sql select case when c_int > 100 then c_float else c_int end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 123.449997 then + return -1 +endi + +sql select case when c_bigint > 100000 then c_double else c_bigint end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 678.900000 then + return -1 +endi + +sql select case when c_bool then c_bool else c_utinyint end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 1 then + return -1 +endi + +sql select case when c_smallint > 30000 then c_usmallint else c_smallint end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 65535 then + return -1 +endi + +sql select case when c_binary = 'binary_val' then c_nchar else c_binary end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 涛思数据 then + return -1 +endi + +sql select case when c_bool then c_int else c_bool end as result from t_test; +if $rows != 1 then + return -1 +endi +if $data00 != 123 then + return -1 +endi + +sql select case when ts > '2022-01-01 00:00:00' then c_bool else ts end as result from t_test; +if $data00 != 1 then + return -1 +endi + +sql select case when c_double > 100 then c_nchar else c_double end as result from t_test; +if $data00 != 涛思数据 then + return -1 +endi + +sql select case when c_double > 100 then c_varchar else c_double end as result from t_test; +if $data00 != varchar_val then + return -1 +endi + +sql select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test; +if $data00 != varchar_val then + return -1 +endi + +sql select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test; +if $data00 != true then + return -1 +endi + +sql select case when 0 then tag_id else c_geometry end as result from t_test; +if $data00 != 16842773 then + return -1 +endi + +sql select case when 0 then tag_id else c_nchar end as result from t_test; +if $data00 != 涛思数据 then + return -1 +endi + +sql select case when 0 then tag_id else c_int end as result from t_test; +if $data00 != 123 then + return -1 +endi + +sql select case when 0 then tag_id else c_float end as result from t_test; +if $data00 != 123.449997 then + return -1 +endi + +sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test; +sql_error select case when c_bool then c_double else c_varbinary end as result from t_test; +sql_error select case when c_bool then c_varbinary else c_varchar end as result from t_test; + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tagindex/sma_and_tag_index.sim b/tests/script/tsim/tagindex/sma_and_tag_index.sim index 77cc9f53f9..4a6a948e21 100644 --- a/tests/script/tsim/tagindex/sma_and_tag_index.sim +++ b/tests/script/tsim/tagindex/sma_and_tag_index.sim @@ -96,6 +96,7 @@ while $i < 5 sql drop index $sma endw +#sleep 5000 sql drop stable $mtPrefix sql select * from information_schema.ins_indexes if $rows != 0 then diff --git a/tests/system-test/2-query/case_when.py b/tests/system-test/2-query/case_when.py index 1ccd2b5076..85fe43b487 100755 --- a/tests/system-test/2-query/case_when.py +++ b/tests/system-test/2-query/case_when.py @@ -231,12 +231,12 @@ class TDTestCase: 'first case when \'%d\' then \'b\' when null then %d end last' %(a1,a2) , #'first case when \'2\' then \'b\' when null then 0 end last' , 'first case when \'%d\' then \'b\' else null end last' %(a1), #'first case when \'0\' then \'b\' else null end last', 'first case when \'%d\' then \'b\' else %d end last' %(a1,a2), #'first case when \'0\' then \'b\' else 2 end last', - 'first case when q_int then q_int when q_int + (%d) then q_int + (%d) else q_int is null end last' %(a1,a2) , #'first case when q_int then q_int when q_int + 1 then q_int + 1 else q_int is null end last' , - 'first case when q_int then %d when ts then ts end last' %(a1), #'first case when q_int then 3 when ts then ts end last' , + 'first case when q_int then q_int when q_int + (%d) then cast(q_int + (%d) as int) else q_int is null end last' %(a1,a2) , #'first case when q_int then q_int when q_int + 1 then q_int + 1 else q_int is null end last' , + 'first case when q_int then %d when ts then cast(ts as int) end last' %(a1), #'first case when q_int then 3 when ts then ts end last' , 'first case when %d then q_int end last' %(a1), #'first case when 3 then q_int end last' , 'first case when q_int then %d when %d then %d end last' %(a1,a1,a3), #'first case when q_int then 3 when 1 then 2 end last' , 'first case when q_int < %d then %d when q_int >= %d then %d else %d end last' %(a1,a2,a1,a2,a3), #'first case when q_int < 3 then 1 when q_int >= 3 then 2 else 3 end last' , - 'first case when q_int is not null then case when q_int <= %d then q_int else q_int * (%d) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , + 'first case when q_int is not null then case when q_int <= %d then q_int else cast(q_int * (%d) as int) end else -(%d) end last' %(a1,a1,a3), #'first case when q_int is not null then case when q_int <= 0 then q_int else q_int * 10 end else -1 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 3 then 4 end last' , 'first case %d when %d then %d end last' %(a1,a2,a3), # 'first case 3 when 1 then 4 end last' , 'first case %d when %d then %d else %d end last' %(a1,a1,a2,a3), # 'first case 3 when 1 then 4 else 2 end last' , @@ -250,15 +250,15 @@ class TDTestCase: 'first case when \'a\' then \'b\' when null then %d end last' %(a1), # 'first case when \'a\' then \'b\' when null then 0 end last' , 'first case when \'%d\' then \'b\' when null then %d end last' %(a1,a2), # 'first case when \'2\' then \'b\' when null then 0 end last' , 'first case when %d then \'b\' else null end last' %(a1), # 'first case when 0 then \'b\' else null end last' , - 'first case when %d then \'b\' else %d+abs(%d) end last' %(a1,a2,a3), # 'first case when 0 then \'b\' else 2+abs(-2) end last' , + 'first case when %d then \'b\' else cast(%d+abs(%d) as int) end last' %(a1,a2,a3), # 'first case when 0 then \'b\' else 2+abs(-2) end last' , 'first case when %d then %d end last' %(a1,a2), # 'first case when 3 then 4 end last' , 'first case when %d then %d end last' %(a1,a2), # 'first case when 0 then 4 end last' , 'first case when null then %d end last' %(a1), # 'first case when null then 4 end last' , - #'first case when %d then %d+(%d) end last' %(a1,a2,a3), # 'first case when 1 then 4+1 end last' , + 'first case when %d then cast(%d+(%d) as int) end last' %(a1,a2,a3), # 'first case when 1 then 4+1 end last' , 'first case when %d-(%d) then %d end last' %(a1,a2,a3), # 'first case when 1-1 then 0 end last' , 'first case when %d+(%d) then %d end last' %(a1,a2,a3), # 'first case when 1+1 then 0 end last' , 'first case when abs(%d) then abs(%d) end last' %(a1,a2), # 'first case when abs(3) then abs(-1) end last' , - #'first case when abs(%d+(%d)) then abs(%d)+abs(%d) end last' %(a1,a2,a3,a1), # 'first case when abs(1+1) then abs(-1)+abs(3) end last' , + 'first case when abs(%d+(%d)) then cast(abs(%d)+abs(%d) as int) end last' %(a1,a2,a3,a1), # 'first case when abs(1+1) then abs(-1)+abs(3) end last' , 'first case when %d then %d else %d end last' %(a1,a2,a3), # 'first case when 0 then 1 else 3 end last' , 'first case when %d then %d when %d then %d else %d end last' %(a1,a2,a3,a1,a2), # 'first case when 0 then 1 when 1 then 0 else 3 end last' , 'first case when %d then %d when %d then %d when %d then %d end last' %(a1,a2,a3,a1,a2,a3), # 'first case when 0 then 1 when 1 then 0 when 2 then 3 end last' ,