From fd754eaa08a13f548b18e4e8e720dee4a4a5a605 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Sun, 25 Jun 2023 11:31:33 +0800 Subject: [PATCH 01/15] fix: udfd can not connect to taosd since authentification failure --- include/libs/function/tudf.h | 6 ++++++ source/dnode/mnode/impl/src/mndProfile.c | 10 +++++++++- source/libs/function/src/tudf.c | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/libs/function/tudf.h b/include/libs/function/tudf.h index b71d50d43c..6b15833917 100644 --- a/include/libs/function/tudf.h +++ b/include/libs/function/tudf.h @@ -111,6 +111,12 @@ int32_t udfStartUdfd(int32_t startDnodeId); */ int32_t udfStopUdfd(); +/** + * get udfd pid + * + */ + int32_t udfGetUdfdPid(int32_t* pUdfdPid); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 0bfab227c4..f51cf614bd 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -25,6 +25,7 @@ #include "mndUser.h" #include "tglobal.h" #include "tversion.h" +#include "tudf.h" typedef struct { uint32_t id; @@ -232,7 +233,6 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { } code = -1; - taosIp2String(pReq->info.conn.clientIp, ip); if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT) != 0) { mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, terrstr()); @@ -245,6 +245,13 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { goto _OVER; } + int32_t udfdPid = -1; + udfGetUdfdPid(&udfdPid); + // if connection is from udfd, no user/password/db check + if (udfdPid == connReq.pid) { + goto _CONNECT; + } + if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0) { mGError("user:%s, failed to login from %s since invalid pass, input:%s", pReq->info.conn.user, ip, connReq.passwd); code = TSDB_CODE_MND_AUTH_FAILURE; @@ -270,6 +277,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { } } +_CONNECT: pConn = mndCreateConn(pMnode, pReq->info.conn.user, connReq.connType, pReq->info.conn.clientIp, pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime); if (pConn == NULL) { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 31a7dfdbc5..5b9f44c812 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -255,6 +255,18 @@ int32_t udfStopUdfd() { return 0; } +int32_t udfGetUdfdPid(int32_t* pUdfdPid) { + SUdfdData *pData = &udfdGlobal; + if (pData->spawnErr) { + return pData->spawnErr; + } + uv_pid_t pid = uv_process_get_pid(&pData->process); + if (pUdfdPid) { + *pUdfdPid = (int32_t)pid; + } + return TSDB_CODE_SUCCESS; +} + //============================================================================================== /* Copyright (c) 2013, Ben Noordhuis * The QUEUE is copied from queue.h under libuv From 1805d30e1026d8918f25e90c92f3c3c0fa8dd5e5 Mon Sep 17 00:00:00 2001 From: slzhou Date: Sun, 25 Jun 2023 11:36:41 +0800 Subject: [PATCH 02/15] fix: add test case --- tests/script/tsim/query/udf.sim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index e539f11531..522d3e1b51 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -11,6 +11,7 @@ sql connect print ======== step1 udf system sh/compile_udf.sh +sql alter user root pass 'taosdata2' sql create database udf vgroups 3; sql use udf; sql select * from information_schema.ins_databases; From 6de507d3925989078c7d414c6625a78b046a2d7d Mon Sep 17 00:00:00 2001 From: slzhou Date: Sun, 25 Jun 2023 11:44:01 +0800 Subject: [PATCH 03/15] fix: modify test case --- source/libs/function/src/udfd.c | 1 + tests/script/tsim/query/udf.sim | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 3b827a2f99..c10895139b 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -970,6 +970,7 @@ int32_t udfdConnectToMnode() { connReq.connType = CONN_TYPE__UDFD; tstrncpy(connReq.app, "udfd", sizeof(connReq.app)); tstrncpy(connReq.user, TSDB_DEFAULT_USER, sizeof(connReq.user)); + // just use default password. this password is not checked by mnode since connection is from udfd char pass[TSDB_PASSWORD_LEN + 1] = {0}; taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass); tstrncpy(connReq.passwd, pass, sizeof(connReq.passwd)); diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index 522d3e1b51..fbf9d50c25 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -8,10 +8,12 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c udf -v 1 system sh/exec.sh -n dnode1 -s start sql connect +sql alter user root pass 'taosdata2' +system sh/exec.sh -n dnode1 -s stop +system sh/exec.sh -n dnode1 -s start print ======== step1 udf system sh/compile_udf.sh -sql alter user root pass 'taosdata2' sql create database udf vgroups 3; sql use udf; sql select * from information_schema.ins_databases; From 2f9c8417b63a7eab336862befaa77e582631e76b Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Mon, 26 Jun 2023 07:53:00 +0800 Subject: [PATCH 04/15] fix: use appname to see whether it is udfd --- source/dnode/mnode/impl/src/mndProfile.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index f51cf614bd..b1c19098a5 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -25,7 +25,6 @@ #include "mndUser.h" #include "tglobal.h" #include "tversion.h" -#include "tudf.h" typedef struct { uint32_t id; @@ -245,10 +244,8 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { goto _OVER; } - int32_t udfdPid = -1; - udfGetUdfdPid(&udfdPid); // if connection is from udfd, no user/password/db check - if (udfdPid == connReq.pid) { + if (strcmp(connReq.app, "udfd") == 0) { goto _CONNECT; } From 7ebbe0603b6c0c5749c367eeac516f3c9e23bfa8 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 26 Jun 2023 18:26:10 +0800 Subject: [PATCH 05/15] fix:coverity scan error --- source/client/src/clientSml.c | 3 +++ source/client/src/clientStmt.c | 2 -- source/client/src/clientTmq.c | 46 ++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 503120fe85..13dc019feb 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -749,6 +749,9 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, pReq.suid = pTableMeta->uid; pReq.source = TD_REQ_FROM_TAOX; pSql = (action == SCHEMA_ACTION_ADD_COLUMN) ? "sml_add_column" : "sml_modify_column_size"; + } else{ + uError("SML:0x%" PRIx64 " invalid action:%d", info->id, action); + goto end; } code = buildRequest(info->taos->id, pSql, strlen(pSql), NULL, false, &pRequest, 0); diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 975b304bf4..8ac9550aca 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -939,8 +939,6 @@ int stmtClose(TAOS_STMT* stmt) { stmtCleanSQLInfo(pStmt); taosMemoryFree(stmt); - STMT_DLOG_E("stmt freed"); - return TSDB_CODE_SUCCESS; } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index e1b2b9c48b..765ff2e0ed 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -651,7 +651,7 @@ static void asyncCommitOffset(tmq_t* tmq, const TAOS_RES* pRes, int32_t type, tm int32_t j = 0; int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs); for (j = 0; j < numOfVgroups; j++) { - SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); + SMqClientVg* pVg = (SMqClientVg*)taosArrayGet(pTopic->vgs, j); if (pVg->vgId == vgId) { break; } @@ -665,7 +665,7 @@ static void asyncCommitOffset(tmq_t* tmq, const TAOS_RES* pRes, int32_t type, tm return; } - SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); + SMqClientVg* pVg = (SMqClientVg*)taosArrayGet(pTopic->vgs, j); if (pVg->offsetInfo.currentOffset.type > 0 && !tOffsetEqual(&pVg->offsetInfo.currentOffset, &pVg->offsetInfo.committedOffset)) { code = doSendCommitMsg(tmq, pVg, pTopic->topicName, pParamSet, j, numOfVgroups, type); @@ -741,13 +741,15 @@ static void asyncCommitAllOffsets(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* us static void generateTimedTask(int64_t refId, int32_t type) { tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId); - if (tmq != NULL) { - int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0); - *pTaskType = type; - taosWriteQitem(tmq->delayedTask, pTaskType); - tsem_post(&tmq->rspSem); - taosReleaseRef(tmqMgmt.rsetId, refId); - } + if(tmq == NULL) return; + + int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0); + if(pTaskType == NULL) return; + + *pTaskType = type; + taosWriteQitem(tmq->delayedTask, pTaskType); + tsem_post(&tmq->rspSem); + taosReleaseRef(tmqMgmt.rsetId, refId); } void tmqAssignAskEpTask(void* param, void* tmrId) { @@ -762,19 +764,19 @@ void tmqAssignDelayedCommitTask(void* param, void* tmrId) { taosMemoryFree(param); } -void tmqAssignDelayedReportTask(void* param, void* tmrId) { - int64_t refId = *(int64_t*)param; - tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId); - if (tmq != NULL) { - int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0); - *pTaskType = TMQ_DELAYED_TASK__REPORT; - taosWriteQitem(tmq->delayedTask, pTaskType); - tsem_post(&tmq->rspSem); - } - - taosReleaseRef(tmqMgmt.rsetId, refId); - taosMemoryFree(param); -} +//void tmqAssignDelayedReportTask(void* param, void* tmrId) { +// int64_t refId = *(int64_t*)param; +// tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId); +// if (tmq != NULL) { +// int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0); +// *pTaskType = TMQ_DELAYED_TASK__REPORT; +// taosWriteQitem(tmq->delayedTask, pTaskType); +// tsem_post(&tmq->rspSem); +// } +// +// taosReleaseRef(tmqMgmt.rsetId, refId); +// taosMemoryFree(param); +//} int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) { if (pMsg) { From aa33384a41c285005bb9b728b224a7c6d54fdfef Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 10:07:52 +0800 Subject: [PATCH 06/15] fix coverity issue --- source/libs/function/src/tpercentile.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 3ec802a7ce..8101b342a4 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -39,6 +39,7 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx) if (p != NULL) { pIdList = *(SArray **)p; } else { + taosMemoryFree(buffer); return NULL; } @@ -48,6 +49,7 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx) SFilePage *pg = getBufPage(pMemBucket->pBuffer, *pageId); if (pg == NULL) { + taosMemoryFree(buffer); return NULL; } From 2be7b7f00444b3350e195e56fdffec631ddf262a Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 10:20:54 +0800 Subject: [PATCH 07/15] fix coverity issue --- source/common/src/ttime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index d8c43747f7..7a5581efbe 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -969,7 +969,7 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) default: fractionLen = 0; - ASSERT(false); + return; } if (taosLocalTime(", &ptm, buf) == NULL) { From 421e75d03b53c7d8c3b407bc2209a23d1b0ee79d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 10:20:54 +0800 Subject: [PATCH 08/15] fix coverity issue --- source/libs/function/src/thistogram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index e7d631f638..b56691f35d 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -474,8 +474,8 @@ double* tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num) { } ASSERTS(total <= numOfElem && total + pHisto->elems[j + 1].num > numOfElem, - "tHistogramUniform Error, total:%d, numOfElem:%d, elems[%d].num:%d", - total, numOfElem, j + 1, pHisto->elems[j + 1].num); + "tHistogramUniform Error, total:%ld, numOfElem:%ld, elems[%d].num:%ld", + total, (int64_t)numOfElem, j + 1, pHisto->elems[j + 1].num); double delta = numOfElem - total; if (fabs(delta) < FLT_EPSILON) { From 5bb7d2650180dce0f52679f3e1d39590e48e343b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 11:12:10 +0800 Subject: [PATCH 09/15] fix coverity scan issue --- source/libs/scalar/src/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index bbefcc6b3a..c0213c8861 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3741,10 +3741,10 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange *colRange, SColumnDataAg taosArrayPush(points, &startPt); taosArrayPush(points, &endPt); } - SFltSclDatum min; + SFltSclDatum min = {0}; fltSclBuildDatumFromBlockSmaValue(&min, colRange->colNode->node.resType.type, pAgg->min); SFltSclPoint minPt = {.excl = false, .start = true, .val = min}; - SFltSclDatum max; + SFltSclDatum max = {0}; fltSclBuildDatumFromBlockSmaValue(&max, colRange->colNode->node.resType.type, pAgg->max); SFltSclPoint maxPt = {.excl = false, .start = false, .val = max}; taosArrayPush(points, &minPt); From fc3fe9dff83df9e04b7d6a492e327e8fa0b1cedb Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 28 Jun 2023 13:49:13 +0800 Subject: [PATCH 10/15] fix: remove connect to mnode --- source/dnode/mnode/impl/src/mndProfile.c | 5 --- source/libs/function/src/udfd.c | 55 ------------------------ 2 files changed, 60 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index b1c19098a5..ced52058e1 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -243,11 +243,6 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, terrstr()); goto _OVER; } - - // if connection is from udfd, no user/password/db check - if (strcmp(connReq.app, "udfd") == 0) { - goto _CONNECT; - } if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0) { mGError("user:%s, failed to login from %s since invalid pass, input:%s", pReq->info.conn.user, ip, connReq.passwd); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index c10895139b..93259924d5 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -965,41 +965,6 @@ int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) { return code; } -int32_t udfdConnectToMnode() { - SConnectReq connReq = {0}; - connReq.connType = CONN_TYPE__UDFD; - tstrncpy(connReq.app, "udfd", sizeof(connReq.app)); - tstrncpy(connReq.user, TSDB_DEFAULT_USER, sizeof(connReq.user)); - // just use default password. this password is not checked by mnode since connection is from udfd - char pass[TSDB_PASSWORD_LEN + 1] = {0}; - taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass); - tstrncpy(connReq.passwd, pass, sizeof(connReq.passwd)); - connReq.pid = taosGetPId(); - connReq.startTime = taosGetTimestampMs(); - strcpy(connReq.sVer, version); - - int32_t contLen = tSerializeSConnectReq(NULL, 0, &connReq); - void *pReq = rpcMallocCont(contLen); - tSerializeSConnectReq(pReq, contLen, &connReq); - - SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo)); - msgInfo->rpcType = UDFD_RPC_MNODE_CONNECT; - uv_sem_init(&msgInfo->resultSem, 0); - - SRpcMsg rpcMsg = {0}; - rpcMsg.msgType = TDMT_MND_CONNECT; - rpcMsg.pCont = pReq; - rpcMsg.contLen = contLen; - rpcMsg.info.ahandle = msgInfo; - rpcSendRequest(global.clientRpc, &global.mgmtEp.epSet, &rpcMsg, NULL); - - uv_sem_wait(&msgInfo->resultSem); - int32_t code = msgInfo->code; - uv_sem_destroy(&msgInfo->resultSem); - taosMemoryFree(msgInfo); - return code; -} - static bool udfdRpcRfp(int32_t code, tmsg_t msgType) { if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED || code == TSDB_CODE_SYN_RESTORING || @@ -1379,23 +1344,6 @@ static int32_t udfdRun() { return 0; } -void udfdConnectMnodeThreadFunc(void *args) { - int32_t retryMnodeTimes = 0; - int32_t code = 0; - while (retryMnodeTimes++ <= TSDB_MAX_REPLICA) { - uv_sleep(100 * (1 << retryMnodeTimes)); - code = udfdConnectToMnode(); - if (code == 0) { - break; - } - fnError("udfd can not connect to mnode, code: %s. retry", tstrerror(code)); - } - - if (code != 0) { - fnError("udfd can not connect to mnode"); - } -} - int32_t udfdInitResidentFuncs() { if (strlen(tsUdfdResFuncs) == 0) { return TSDB_CODE_SUCCESS; @@ -1498,9 +1446,6 @@ int main(int argc, char *argv[]) { udfdInitResidentFuncs(); - uv_thread_t mnodeConnectThread; - uv_thread_create(&mnodeConnectThread, udfdConnectMnodeThreadFunc, NULL); - udfdRun(); removeListeningPipe(); From 1a6511fee065955332775e7dffc693e44d49090c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 15:09:42 +0800 Subject: [PATCH 11/15] fix unique document --- docs/en/12-taos-sql/10-function.md | 4 ++-- docs/zh/12-taos-sql/10-function.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index 6b62950ecc..d46e01da41 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -1054,11 +1054,11 @@ TOP(expr, k) UNIQUE(expr) ``` -**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword, but it can also be used to match tags or timestamp. The first occurrence of a timestamp or tag is used. +**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword, but it can also be used to match tags or timestamp which correspond to first occurrence of the record. **Return value type**:Same as the data type of the column being operated upon -**Applicable column types**: Any data types except for timestamp +**Applicable column types**: Any data types **Applicable table types**: table, STable diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index b4785dc5e6..e9ab75c135 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -1046,11 +1046,11 @@ TOP(expr, k) UNIQUE(expr) ``` -**功能说明**:返回该列的数值首次出现的值。该函数功能与 distinct 相似,但是可以匹配标签和时间戳信息。可以针对除时间列以外的字段进行查询,可以匹配标签和时间戳,其中的标签和时间戳是第一次出现时刻的标签和时间戳。 +**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似,可以匹配标签和时间戳,对应数据第一次出现时刻的标签和时间戳。 **返回数据类型**:同应用的字段。 -**适用数据类型**:适合于除时间类型以外的字段。 +**适用数据类型**:全部类型字段。 **适用于**: 表和超级表。 From 4f613220d102d64ddccfe3de31ae1a0aeabcae3f Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 28 Jun 2023 15:13:35 +0800 Subject: [PATCH 12/15] fix sample docs --- docs/en/12-taos-sql/10-function.md | 8 ++------ docs/zh/12-taos-sql/10-function.md | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index d46e01da41..fa1890cc27 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -998,18 +998,14 @@ SAMPLE(expr, k) **Description**: _k_ sampling values of a specific column. The applicable range of _k_ is [1,1000]. -**Return value type**: Same as the column being operated plus the associated timestamp +**Return value type**: Same as the column being operated -**Applicable data types**: Any data type except for tags of STable +**Applicable data types**: Any data type **Applicable nested query**: Inner query and Outer query **Applicable table types**: standard tables and supertables -**More explanations**: - -- This function cannot be used in expression calculation. - ### TAIL diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index e9ab75c135..d25292e8b8 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -990,18 +990,14 @@ SAMPLE(expr, k) **功能说明**: 获取数据的 k 个采样值。参数 k 的合法输入范围是 1≤ k ≤ 1000。 -**返回结果类型**: 同原始数据类型, 返回结果中带有该行记录的时间戳。 +**返回结果类型**: 同原始数据类型。 -**适用数据类型**: 在超级表查询中使用时,不能应用在标签之上。 +**适用数据类型**: 全部类型字段。 **嵌套子查询支持**: 适用于内层查询和外层查询。 **适用于**:表和超级表。 -**使用说明**: - -- 不能参与表达式计算;该函数可以应用在普通表和超级表上; - ### TAIL From 1d314b9ac205ca4d603dd4318f5cfce1d47dbd72 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao <36554565+glzhao89@users.noreply.github.com> Date: Wed, 28 Jun 2023 16:10:04 +0800 Subject: [PATCH 13/15] Update 10-function.md --- docs/en/12-taos-sql/10-function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index fa1890cc27..081d5a8d8a 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -1050,7 +1050,7 @@ TOP(expr, k) UNIQUE(expr) ``` -**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword, but it can also be used to match tags or timestamp which correspond to first occurrence of the record. +**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword. **Return value type**:Same as the data type of the column being operated upon From 1d1d35ea79ba7a2750bfb9b9dc063bd4bf79b111 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao <36554565+glzhao89@users.noreply.github.com> Date: Wed, 28 Jun 2023 16:11:13 +0800 Subject: [PATCH 14/15] Update 10-function.md --- docs/zh/12-taos-sql/10-function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index d25292e8b8..4820eb4674 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -1042,7 +1042,7 @@ TOP(expr, k) UNIQUE(expr) ``` -**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似,可以匹配标签和时间戳,对应数据第一次出现时刻的标签和时间戳。 +**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似。 **返回数据类型**:同应用的字段。 From 91a6b891aacb6cfa6fb45190a0f945633860b48e Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 28 Jun 2023 17:32:15 +0800 Subject: [PATCH 15/15] fix: restore current database while restoring connection --- tools/shell/src/shellWebsocket.c | 52 +++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tools/shell/src/shellWebsocket.c b/tools/shell/src/shellWebsocket.c index d8920cb4c3..af7f13c69c 100644 --- a/tools/shell/src/shellWebsocket.c +++ b/tools/shell/src/shellWebsocket.c @@ -17,6 +17,9 @@ #include #include +// save current database name +char curDBName[128] = ""; // TDB_MAX_DBNAME_LEN is 24, put large + int shell_conn_ws_server(bool first) { char cuttedDsn[SHELL_WS_DSN_BUFF] = {0}; int dsnLen = strlen(shell.args.dsn); @@ -59,6 +62,14 @@ int shell_conn_ws_server(bool first) { fprintf(stdout, "successfully connected to cloud service\n"); } fflush(stdout); + + // switch to current database if have + if(curDBName[0] !=0) { + char command[256]; + sprintf(command, "use %s;", curDBName); + shellRunSingleCommandWebsocketImp(command); + } + return 0; } @@ -290,7 +301,46 @@ void shellRunSingleCommandWebsocketImp(char *command) { if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { - fprintf(stdout, "Database changed.\r\n\r\n"); + + // copy dbname to curDBName + char *p = command; + bool firstStart = false; + bool firstEnd = false; + int i = 0; + while (*p != 0) { + if (*p != ' ') { + // not blank + if (!firstStart) { + firstStart = true; + } else if (firstEnd) { + if(*p == ';' && *p != '\\') { + break; + } + // database name + curDBName[i++] = *p; + if(i + 4 > sizeof(curDBName)) { + // DBName is too long, reset zero and break + i = 0; + break; + } + } + } else { + // blank + if(firstStart == true && firstEnd == false){ + firstEnd = true; + } + if(firstStart && firstEnd && i > 0){ + // blank after database name + break; + } + } + // move next + p++; + } + // append end + curDBName[i] = 0; + + fprintf(stdout, "Database changed to %s.\r\n\r\n", curDBName); fflush(stdout); ws_free_result(res); return;