Merge branch '3.0' into merge/mainto3.0

This commit is contained in:
Simon Guan 2025-03-12 14:20:43 +08:00
commit 81e6f49399
70 changed files with 5134 additions and 205 deletions

51
.github/workflows/tdgpt-ci.yml vendored Normal file
View File

@ -0,0 +1,51 @@
name: TDgpt CI
on:
pull_request:
branches:
- '3.0'
paths:
- 'tools/tdgpt/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
defaults:
run:
working-directory: ${{ github.workspace }}/tools/tdgpt
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pylint
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Checking the code with pylint
run: |
pylint $(git ls-files '*.py') --exit-zero
- name: Checking the code with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run test cases with pytest
run: |
pytest

View File

@ -0,0 +1,41 @@
name: TDgpt Update Service
on:
schedule:
- cron: '30 00 * * *'
env:
WKC: "/root/TDengine"
jobs:
update-service:
runs-on:
group: CI
labels: [self-hosted, Linux, X64, tdgpt-anode-service]
steps:
- name: Update TDengine codes
run: |
set -euo pipefail
cd ${{ env.WKC }}
git checkout 3.0
- name: Package the TDGpt Anode Service
run: |
set -euo pipefail
cd ${{ env.WKC }}/tools/tdgpt/script && ./release.sh
- name: Reinstall and restart the TDGpt Anode Service
run: |
set -euo pipefail
cd ${{ env.WKC }}/tools/tdgpt/release
if [[ -f "TDengine-enterprise-anode-1.0.1.tar.gz" ]]; then
tar -xzf TDengine-enterprise-anode-1.0.1.tar.gz
cd TDengine-enterprise-anode-1.0.1
./install.sh
fi
systemctl restart taosanoded
- name: Clean up
if: always()
run: |
if [[ -f ${{ env.WKC }}/tools/tdgpt/release/TDengine-enterprise-anode-1.0.1 ]] then rm -rf ${{ env.WKC }}/tools/tdgpt/release/TDengine-enterprise-anode-1.0.1; fi

View File

@ -44,6 +44,7 @@ The TDengine client driver provides all the APIs needed for application programm
|enableQueryHb | |Supported, effective immediately |Internal parameter, whether to send query heartbeat messages|
|minSlidingTime | |Supported, effective immediately |Internal parameter, minimum allowable value for sliding|
|minIntervalTime | |Supported, effective immediately |Internal parameter, minimum allowable value for interval|
|compareAsStrInGreatest | v3.3.6.0 |Supported, effective immediately |When the greatest and least functions have both numeric and string types as parameters, the comparison type conversion rules are as follows: Integer; 1: uniformly converted to string comparison, 0: uniformly converted to numeric type comparison.|
### Writing Related

View File

@ -124,7 +124,39 @@ FLOOR(expr)
```
**Function Description**: Gets the floor of the specified field.
Other usage notes see CEIL function description.
Other usage notes see [CEIL](#ceil) function description.
#### GREATEST
```sql
GREATEST(expr1, expr2[, expr]...)
```
**Function Description**: Get the maximum value of all input parameters. The minimum number of parameters for this function is 2.
**Version**ver-3.3.6.0
**Return Type**Refer to the comparison rules. The comparison type is the final return type.
**Applicable Data Types**:
- Numeric types: timestamp, bool, integer and floating point types
- Strings types: nchar and varchar types.
**Comparison rules**: The following rules describe the conversion method of the comparison operation:
- If any parameter is NULL, the comparison result is NULL.
- If all parameters in the comparison operation are string types, compare them as string types
- If all parameters are numeric types, compare them as numeric types.
- If there are both string types and numeric types in the parameters, according to the `compareAsStrInGreatest` configuration item, they are uniformly compared as strings or numeric values. By default, they are compared as strings.
- In all cases, when different types are compared, the comparison type will choose the type with a larger range for comparison. For example, when comparing integer types, if there is a BIGINT type, BIGINT will definitely be selected as the comparison type.
**Related configuration items**: Client configuration, compareAsStrInGreatest is 1, which means that both string types and numeric types are converted to string comparisons, and 0 means that they are converted to numeric types. The default is 1.
#### LEAST
```sql
LEAST(expr1, expr2[, expr]...)
```
**Function Description**Get the minimum value of all input parameters. The rest of the description is the same as the [GREATEST](#greatest) function.
#### LOG

View File

@ -221,6 +221,12 @@ TDengine 客户端驱动提供了应用编程所需要的全部 API并且在
- 动态修改:不支持
- 支持版本:从 v3.0.0.0 版本开始引入
#### compareAsStrInGreatest
- 说明:用于决定 greatest、least 函数的参数既有数值类型又有字符串类型时,比较类型的转换规则。
- 类型整数1统一转为字符串比较0统一转为数值类型比较。
- 动态修改:支持通过 SQL 修改,立即生效
- 支持版本:从 v3.3.6.0 版本开始引入
### 写入相关
#### smlChildTableName

View File

@ -186,7 +186,38 @@ FLOOR(expr)
```
**功能说明**:获得指定字段的向下取整数的结果。
其他使用说明参见 CEIL 函数描述。
其他使用说明参见 [CEIL](#ceil) 函数描述。
#### GREATEST
```sql
GREATEST(expr1, expr2[, expr]...)
```
**功能说明**:获得输入的所有参数中的最大值。该函数最小参数个数为 2 个。
**使用说明**ver-3.3.6.0
**返回结果类型**:参考比较规则,比较类型即为最终返回类型。
**适用数据类型**
- 数值类型:包括 bool 型,整型和浮点型
- 字符串类型:包括 nchar 和 varchar 类型。
**比较规则**:以下规则描述了比较操作的转换方式:
- 如果有任何一个参数为 NULL则比较结果为 NULL。
- 如果比较操作中的所有参数都是字符串类型,按照字符串类型比较
- 如果所有参数都是数值类型,则将它们作为数值类型进行比较。
- 如果参数中既有字符串类型,也有数值类型,根据 compareAsStrInGreatest 配置项,统一作为字符串或者数值进行比较。默认按照字符串比较。
- 在所有情况下,不同类型比较,比较类型会选择范围更大的类型进行比较,例如作为整数类型比较时,如果存在 BIGINT 类型,必定会选择 BIGINT 作为比较类型。
**相关配置项**客户端配置compareAsStrInGreatest 为 1 表示同时存在字符串类型和数值类型统一转为字符串比较,为 0 表示统一转为数值类型比较。默认为 1。
#### LEAST
```sql
LEAST(expr1, expr2[, expr]...)
```
**功能说明**:获得输入的所有参数中的最小值。其余部分说明同 [GREATEST](#greatest) 函数。
#### LN

View File

@ -299,6 +299,7 @@ extern bool tsStreamCoverage;
extern int8_t tsS3EpNum;
extern int32_t tsStreamNotifyMessageSize;
extern int32_t tsStreamNotifyFrameSize;
extern bool tsCompareAsStrInGreatest;
extern bool tsExperimental;
// #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)

View File

@ -40,6 +40,7 @@ typedef enum {
ARB_QUEUE,
STREAM_CTRL_QUEUE,
STREAM_LONG_EXEC_QUEUE,
STREAM_CHKPT_QUEUE,
QUEUE_MAX,
} EQueueType;

View File

@ -355,6 +355,7 @@
TD_DEF_MSG_TYPE(TDMT_STREAM_DROP, "stream-drop", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_STREAM_RETRIEVE_TRIGGER, "stream-retri-trigger", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_STREAM_CONSEN_CHKPT, "stream-consen-chkpt", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_STREAM_CHKPT_EXEC, "stream-exec-chkpt", NULL, NULL)
TD_CLOSE_MSG_SEG(TDMT_STREAM_MSG)
TD_NEW_MSG_SEG(TDMT_MON_MSG) //5 << 8

View File

@ -276,6 +276,9 @@ typedef struct {
#define IS_STR_DATA_TYPE(t) \
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define IS_COMPARE_STR_DATA_TYPE(t) \
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define IS_VALID_TINYINT(_t) ((_t) >= INT8_MIN && (_t) <= INT8_MAX)
#define IS_VALID_SMALLINT(_t) ((_t) >= INT16_MIN && (_t) <= INT16_MAX)
#define IS_VALID_INT(_t) ((_t) >= INT32_MIN && (_t) <= INT32_MAX)

View File

@ -90,6 +90,8 @@ typedef enum EFunctionType {
FUNCTION_TYPE_DEGREES,
FUNCTION_TYPE_RADIANS,
FUNCTION_TYPE_TRUNCATE,
FUNCTION_TYPE_GREATEST,
FUNCTION_TYPE_LEAST,
// string function
FUNCTION_TYPE_LENGTH = 1500,

View File

@ -66,6 +66,8 @@ int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode *
SNode **pOtherCond);
int32_t filterIsMultiTableColsCond(SNode *pCond, bool *res);
EConditionType filterClassifyCondition(SNode *pNode);
int32_t filterGetCompFunc(__compar_fn_t *func, int32_t type, int32_t optr);
bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right);
#ifdef __cplusplus
}

View File

@ -44,6 +44,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type, int8_
int32_t vectorGetConvertType(int32_t type1, int32_t type2);
int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow, int32_t startIndex, int32_t numOfRows);
int32_t vectorConvertSingleCol(SScalarParam *input, SScalarParam *output, int32_t type, int32_t startIndex, int32_t numOfRows);
/* Math functions */
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
@ -71,6 +72,8 @@ int32_t signFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t degreesFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t radiansFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t randFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t greatestFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t leastFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
/* String functions */
int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);

View File

@ -702,8 +702,8 @@ int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t clearRelHalt);
int32_t streamExecTask(SStreamTask* pTask);
int32_t streamResumeTask(SStreamTask* pTask);
int32_t streamTrySchedExec(SStreamTask* pTask);
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType);
int32_t streamTrySchedExec(SStreamTask* pTask, bool chkptExec);
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType, bool chkptExec);
void streamTaskResumeInFuture(SStreamTask* pTask);
void streamTaskClearSchedIdleInfo(SStreamTask* pTask);
void streamTaskSetIdleInfo(SStreamTask* pTask, int32_t idleTime);

View File

@ -116,9 +116,9 @@ bool tsMndSkipGrant = false;
bool tsEnableWhiteList = false; // ip white list cfg
// arbitrator
int32_t tsArbHeartBeatIntervalSec = 5;
int32_t tsArbCheckSyncIntervalSec = 10;
int32_t tsArbSetAssignedTimeoutSec = 30;
int32_t tsArbHeartBeatIntervalSec = 2;
int32_t tsArbCheckSyncIntervalSec = 3;
int32_t tsArbSetAssignedTimeoutSec = 6;
// dnode
int64_t tsDndStart = 0;
@ -130,6 +130,8 @@ uint32_t tsEncryptionKeyChksum = 0;
int8_t tsEncryptionKeyStat = ENCRYPT_KEY_STAT_UNSET;
int8_t tsGrant = 1;
bool tsCompareAsStrInGreatest = true;
// monitor
bool tsEnableMonitor = true;
int32_t tsMonitorInterval = 30;
@ -746,6 +748,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(
cfgAddBool(pCfg, "streamCoverage", tsStreamCoverage, CFG_DYN_CLIENT, CFG_DYN_CLIENT, CFG_CATEGORY_LOCAL));
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "compareAsStrInGreatest", tsCompareAsStrInGreatest, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT,CFG_CATEGORY_LOCAL));
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -1480,6 +1484,9 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "streamCoverage");
tsStreamCoverage = pItem->bval;
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compareAsStrInGreatest");
tsCompareAsStrInGreatest = pItem->bval;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -2783,7 +2790,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
{"numOfRpcSessions", &tsNumOfRpcSessions},
{"bypassFlag", &tsBypassFlag},
{"safetyCheckLevel", &tsSafetyCheckLevel},
{"streamCoverage", &tsStreamCoverage}};
{"streamCoverage", &tsStreamCoverage},
{"compareAsStrInGreatest", &tsCompareAsStrInGreatest}};
if ((code = taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true)) != TSDB_CODE_SUCCESS) {
code = taosCfgSetOption(options, tListLen(options), pItem, false);

View File

@ -47,7 +47,7 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pMsg);
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
void sndEnqueueStreamDispatch(SSnode *pSnode, SRpcMsg *pMsg);
int32_t smPutNodeMsgToChkptQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
#ifdef __cplusplus
}

View File

@ -102,6 +102,8 @@ SArray *smGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_MND_STREAM_REQ_CHKPT_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_STREAM_CHKPT_REPORT_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_CHKPT_EXEC, smPutNodeMsgToStreamQueue, 0) == NULL) goto _OVER;
code = 0;
_OVER:
if (code != 0) {

View File

@ -162,6 +162,9 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
case WRITE_QUEUE:
code = smPutNodeMsgToWriteQueue(pMgmt, pMsg);
break;
case STREAM_CHKPT_QUEUE:
code = smPutNodeMsgToStreamQueue(pMgmt, pMsg);
break;
default:
code = TSDB_CODE_INVALID_PARA;
rpcFreeCont(pMsg->pCont);
@ -172,7 +175,6 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
}
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
int32_t code = 0;
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
if (pWorker == NULL) {
return TSDB_CODE_INVALID_MSG;
@ -198,3 +200,10 @@ int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
return taosWriteQitem(pWorker->queue, pMsg);
}
//int32_t smPutNodeMsgToChkptQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
// SSingleWorker *pWorker = &pMgmt->chkptWorker;
//
// dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
// return taosWriteQitem(pWorker->queue, pMsg);
//}

View File

@ -34,6 +34,7 @@ typedef struct SVnodeMgmt {
SAutoQWorkerPool streamPool;
SAutoQWorkerPool streamLongExecPool;
SWWorkerPool streamCtrlPool;
SWWorkerPool streamChkPool;
SWWorkerPool fetchPool;
SSingleWorker mgmtWorker;
SSingleWorker mgmtMultiWorker;
@ -77,6 +78,7 @@ typedef struct {
STaosQueue *pStreamQ;
STaosQueue *pStreamCtrlQ;
STaosQueue *pStreamLongExecQ;
STaosQueue *pStreamChkQ;
STaosQueue *pFetchQ;
STaosQueue *pMultiMgmQ;
} SVnodeObj;
@ -141,6 +143,7 @@ int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToStreamLongExecQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToStreamChkQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);

View File

@ -1022,6 +1022,7 @@ SArray *vmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_MND_STREAM_CHKPT_REPORT_RSP, vmPutMsgToStreamCtrlQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_SCAN_HISTORY, vmPutMsgToStreamLongExecQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_CHKPT_EXEC, vmPutMsgToStreamChkQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_VND_GET_STREAM_PROGRESS, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;

View File

@ -407,6 +407,9 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal,
pVnode->pStreamLongExecQ, taosQueueItemSize(pVnode->pStreamLongExecQ));
while (!taosQueueEmpty(pVnode->pStreamLongExecQ)) taosMsleep(50);
dInfo("vgId:%d, wait for vnode stream chkpt queue:%p is empty", pVnode->vgId, pVnode->pStreamChkQ);
while (!taosQueueEmpty(pVnode->pStreamChkQ)) taosMsleep(10);
dInfo("vgId:%d, all vnode queues is empty", pVnode->vgId);
dInfo("vgId:%d, post close", pVnode->vgId);

View File

@ -165,6 +165,34 @@ static void vmProcessStreamCtrlQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_
}
}
static void vmProcessStreamChkptQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
SVnodeObj *pVnode = pInfo->ahandle;
void *pItem = NULL;
int32_t code = 0;
while (1) {
if (taosGetQitem(pQall, &pItem) == 0) {
break;
}
SRpcMsg *pMsg = pItem;
const STraceId *trace = &pMsg->info.traceId;
dGTrace("vgId:%d, msg:%p get from vnode-stream-chkpt queue", pVnode->vgId, pMsg);
code = vnodeProcessStreamChkptMsg(pVnode->pImpl, pMsg, pInfo);
if (code != 0) {
terrno = code;
dGError("vgId:%d, msg:%p failed to process stream chkpt msg %s since %s", pVnode->vgId, pMsg,
TMSG_INFO(pMsg->msgType), tstrerror(code));
vmSendRsp(pMsg, code);
}
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
}
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SVnodeObj *pVnode = pInfo->ahandle;
const STraceId *trace = &pMsg->info.traceId;
@ -301,6 +329,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
break;
case STREAM_CHKPT_QUEUE:
dGTrace("vgId:%d, msg:%p put into vnode-stream-chkpt queue", pVnode->vgId, pMsg);
code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
break;
case FETCH_QUEUE:
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
code = taosWriteQitem(pVnode->pFetchQ, pMsg);
@ -361,6 +393,8 @@ int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmP
int32_t vmPutMsgToStreamLongExecQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_LONG_EXEC_QUEUE); }
int32_t vmPutMsgToStreamChkQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CHKPT_QUEUE); }
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
const STraceId *trace = &pMsg->info.traceId;
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
@ -439,6 +473,8 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
case STREAM_LONG_EXEC_QUEUE:
size = taosQueueItemSize(pVnode->pStreamLongExecQ);
break;
case STREAM_CHKPT_QUEUE:
size = taosQueueItemSize(pVnode->pStreamChkQ);
default:
break;
}
@ -487,10 +523,11 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue, 2);
pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
pVnode->pStreamLongExecQ = tAutoQWorkerAllocQueue(&pMgmt->streamLongExecPool, pVnode, (FItem)vmProcessStreamLongExecQueue, 1);
pVnode->pStreamChkQ = tWWorkerAllocQueue(&pMgmt->streamChkPool, pVnode, (FItems)vmProcessStreamChkptQueue);
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
|| pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL) {
|| pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
@ -509,6 +546,8 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
taosQueueGetThreadId(pVnode->pStreamCtrlQ));
dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
taosQueueGetThreadId(pVnode->pStreamChkQ));
return 0;
}
@ -517,6 +556,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
tAutoQWorkerFreeQueue(&pMgmt->streamLongExecPool, pVnode->pStreamLongExecQ);
tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
tWWorkerFreeQueue(&pMgmt->streamChkPool, pVnode->pStreamChkQ);
tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
pVnode->pQueryQ = NULL;
pVnode->pFetchQ = NULL;
@ -525,6 +565,8 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
pVnode->pStreamCtrlQ = NULL;
pVnode->pStreamLongExecQ = NULL;
pVnode->pStreamChkQ = NULL;
pVnode->pFetchQ = NULL;
dDebug("vgId:%d, queue is freed", pVnode->vgId);
}
@ -554,6 +596,11 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
pStreamCtrlPool->max = 1;
if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
pStreamChkPool->name = "vnode-stream-chkpt";
pStreamChkPool->max = 1;
if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
SWWorkerPool *pFPool = &pMgmt->fetchPool;
pFPool->name = "vnode-fetch";
pFPool->max = tsNumOfVnodeFetchThreads;
@ -587,6 +634,7 @@ void vmStopWorker(SVnodeMgmt *pMgmt) {
tAutoQWorkerCleanup(&pMgmt->streamPool);
tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
tWWorkerCleanup(&pMgmt->streamCtrlPool);
tWWorkerCleanup(&pMgmt->streamChkPool);
tWWorkerCleanup(&pMgmt->fetchPool);
dDebug("vnode workers are closed");
}

View File

@ -92,7 +92,7 @@ FAIL:
}
int32_t sndInit(SSnode *pSnode) {
if (streamTaskSchedTask(&pSnode->msgCb, pSnode->pMeta->vgId, 0, 0, STREAM_EXEC_T_START_ALL_TASKS) != 0) {
if (streamTaskSchedTask(&pSnode->msgCb, pSnode->pMeta->vgId, 0, 0, STREAM_EXEC_T_START_ALL_TASKS, false) != 0) {
sndError("failed to start all tasks");
}
return 0;
@ -138,6 +138,8 @@ int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) {
return tqStreamTaskProcessRetrieveTriggerReq(pSnode->pMeta, pMsg);
case TDMT_STREAM_RETRIEVE_TRIGGER_RSP:
return tqStreamTaskProcessRetrieveTriggerRsp(pSnode->pMeta, pMsg);
case TDMT_STREAM_CHKPT_EXEC:
return tqStreamTaskProcessRunReq(pSnode->pMeta, pMsg, true);
default:
sndError("invalid snode msg:%d", pMsg->msgType);
return TSDB_CODE_INVALID_MSG;

View File

@ -114,6 +114,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
int32_t vnodeProcessStreamCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
int32_t vnodeProcessStreamLongExecMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
int32_t vnodeProcessStreamChkptMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
void vnodeProposeCommitOnNeed(SVnode *pVnode, bool atExit);

View File

@ -14,10 +14,19 @@
*/
#include "meta.h"
#include "vnd.h"
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) {
SVBufPool *pool = (SVBufPool *)pPool;
SVnode *pVnode = pool->pVnode;
if (pVnode->inUse && pVnode->inUse->size > pVnode->inUse->node.size) {
return NULL;
}
return vnodeBufPoolMallocAligned((SVBufPool *)pPool, size);
}
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
// begin a meta txn

View File

@ -165,7 +165,7 @@ static void doStartScanWal(void* param, void* tmrId) {
taosMsleep(10000);
#endif
code = streamTaskSchedTask(&pParam->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA);
code = streamTaskSchedTask(&pParam->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA, false);
if (code) {
tqError("vgId:%d failed sched task to scan wal, code:%s", vgId, tstrerror(code));
}
@ -216,7 +216,7 @@ void tqScanWalAsync(STQ* pTq) {
}
int32_t tqStopStreamAllTasksAsync(SStreamMeta* pMeta, SMsgCb* pMsgCb) {
return streamTaskSchedTask(pMsgCb, pMeta->vgId, 0, 0, STREAM_EXEC_T_STOP_ALL_TASKS);
return streamTaskSchedTask(pMsgCb, pMeta->vgId, 0, 0, STREAM_EXEC_T_STOP_ALL_TASKS, false);
}
int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId) {
@ -322,7 +322,7 @@ bool taskReadyForDataFromWal(SStreamTask* pTask) {
// check whether input queue is full or not
if (streamQueueIsFull(pTask->inputq.queue)) {
tqTrace("s-task:%s input queue is full, launch task without scanning wal", pTask->id.idStr);
int32_t code = streamTrySchedExec(pTask);
int32_t code = streamTrySchedExec(pTask, false);
if (code) {
tqError("s-task:%s failed to start task while inputQ is full", pTask->id.idStr);
}
@ -461,7 +461,7 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, int32_t* pNumOfTasks) {
streamMutexUnlock(&pTask->lock);
if ((numOfItems > 0) || hasNewData) {
code = streamTrySchedExec(pTask);
code = streamTrySchedExec(pTask, false);
if (code != TSDB_CODE_SUCCESS) {
streamMetaReleaseTask(pStreamMeta, pTask);
taosArrayDestroy(pTaskList);

View File

@ -131,7 +131,7 @@ int32_t tqStreamTaskStartAsync(SStreamMeta* pMeta, SMsgCb* cb, bool restart) {
tqDebug("vgId:%d start all %d stream task(s) async", vgId, numOfTasks);
int32_t type = restart ? STREAM_EXEC_T_RESTART_ALL_TASKS : STREAM_EXEC_T_START_ALL_TASKS;
return streamTaskSchedTask(cb, vgId, 0, 0, type);
return streamTaskSchedTask(cb, vgId, 0, 0, type, false);
}
int32_t tqStreamStartOneTaskAsync(SStreamMeta* pMeta, SMsgCb* cb, int64_t streamId, int32_t taskId) {
@ -143,7 +143,7 @@ int32_t tqStreamStartOneTaskAsync(SStreamMeta* pMeta, SMsgCb* cb, int64_t stream
}
tqDebug("vgId:%d start task:0x%x async", vgId, taskId);
return streamTaskSchedTask(cb, vgId, streamId, taskId, STREAM_EXEC_T_START_ONE_TASK);
return streamTaskSchedTask(cb, vgId, streamId, taskId, STREAM_EXEC_T_START_ONE_TASK, false);
}
// this is to process request from transaction, always return true.
@ -1222,7 +1222,7 @@ static int32_t tqProcessTaskResumeImpl(void* handle, SStreamTask* pTask, int64_t
} else if (level == TASK_LEVEL__SOURCE && (streamQueueGetNumOfItems(pTask->inputq.queue) == 0)) {
// code = tqScanWalAsync((STQ*)handle, false);
} else {
code = streamTrySchedExec(pTask);
code = streamTrySchedExec(pTask, false);
}
}

View File

@ -940,6 +940,8 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace("vgId:%d, msg:%p in stream queue is processing", pVnode->config.vgId, pMsg);
// todo: NOTE: some command needs to run on follower, such as, stop_all_tasks
if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
pMsg->msgType == TDMT_VND_BATCH_META) &&
!syncIsReadyForRead(pVnode->sync)) {
@ -1016,6 +1018,24 @@ int32_t vnodeProcessStreamLongExecMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo
}
}
int32_t vnodeProcessStreamChkptMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace("vgId:%d, msg:%p in stream chkpt queue is processing", pVnode->config.vgId, pMsg);
if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
pMsg->msgType == TDMT_VND_BATCH_META) &&
!syncIsReadyForRead(pVnode->sync)) {
vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
return 0;
}
switch (pMsg->msgType) {
case TDMT_STREAM_CHKPT_EXEC:
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
default:
vError("unknown msg type:%d in stream chkpt queue", pMsg->msgType);
return TSDB_CODE_APP_ERROR;
}
}
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
if (code) {

View File

@ -597,7 +597,7 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx)
streamMetaWUnLock(pMeta);
tqInfo("vgId:%d stream task already loaded, start them", vgId);
int32_t code = streamTaskSchedTask(&pVnode->msgCb, TD_VID(pVnode), 0, 0, STREAM_EXEC_T_START_ALL_TASKS);
int32_t code = streamTaskSchedTask(&pVnode->msgCb, TD_VID(pVnode), 0, 0, STREAM_EXEC_T_START_ALL_TASKS, false);
if (code != 0) {
tqError("vgId:%d failed to sched stream task, code:%s", vgId, tstrerror(code));
}

View File

@ -22,6 +22,9 @@
#include "tanalytics.h"
#include "taoserror.h"
#include "ttime.h"
#include "functionMgt.h"
#include "ttypes.h"
#include "tglobal.h"
static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) {
va_list vArgList;
@ -1745,6 +1748,62 @@ static int32_t translateHistogramPartial(SFunctionNode* pFunc, char* pErrBuf, in
return TSDB_CODE_SUCCESS;
}
#define NUMERIC_TO_STRINGS_LEN 25
static int32_t translateGreatestleast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
bool mixTypeToStrings = tsCompareAsStrInGreatest;
SDataType res = {.type = 0};
bool resInit = false;
for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); i++) {
SDataType* para = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, i));
if (IS_NULL_TYPE(para->type)) {
res.type = TSDB_DATA_TYPE_NULL;
res.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
break;
}
if (!resInit) {
res.type = para->type;
res.bytes = para->bytes;
resInit = true;
continue;
}
if (IS_MATHABLE_TYPE(para->type)) {
if (res.type == para->type) {
continue;
} else if (IS_MATHABLE_TYPE(res.type) || !mixTypeToStrings) {
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = tDataTypes[res.type].bytes;
} else {
// last res is strings, para is numeric and mixTypeToStrings is true
res.bytes = TMAX(res.bytes, NUMERIC_TO_STRINGS_LEN);
}
} else {
if (IS_COMPARE_STR_DATA_TYPE(res.type)) {
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = TMAX(res.bytes, para->bytes);
} else if (mixTypeToStrings) {
// last res is numeric, para is string, and mixTypeToStrings is true
res.type = para->type;
res.bytes = TMAX(para->bytes, NUMERIC_TO_STRINGS_LEN);
} else {
// last res is numeric, para is string, and mixTypeToStrings is false
int32_t resType = vectorGetConvertType(res.type, para->type);
res.type = resType == 0 ? res.type : resType;
res.bytes = tDataTypes[resType].bytes;
}
}
}
pFunc->node.resType = res;
return TSDB_CODE_SUCCESS;
}
// clang-format off
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
@ -5656,6 +5715,48 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.name = "cols",
.translateFunc = invalidColsFunction,
},
{
.name = "greatest",
.type = FUNCTION_TYPE_GREATEST,
.classification = FUNC_MGT_SCALAR_FUNC,
.parameters = {.minParamNum = 2,
.maxParamNum = -1,
.paramInfoPattern = 1,
.inputParaInfo[0][0] = {.isLastParam = true,
.startParam = 1,
.endParam = -1,
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE | FUNC_PARAM_SUPPORT_BOOL_TYPE | FUNC_PARAM_SUPPORT_TIMESTAMP_TYPE | FUNC_PARAM_SUPPORT_VARCHAR_TYPE | FUNC_PARAM_SUPPORT_NCHAR_TYPE,
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateGreatestleast,
.getEnvFunc = NULL,
.initFunc = NULL,
.sprocessFunc = greatestFunction,
.finalizeFunc = NULL
},
{
.name = "least",
.type = FUNCTION_TYPE_LEAST,
.classification = FUNC_MGT_SCALAR_FUNC,
.parameters = {.minParamNum = 2,
.maxParamNum = -1,
.paramInfoPattern = 1,
.inputParaInfo[0][0] = {.isLastParam = true,
.startParam = 1,
.endParam = -1,
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE | FUNC_PARAM_SUPPORT_BOOL_TYPE | FUNC_PARAM_SUPPORT_TIMESTAMP_TYPE | FUNC_PARAM_SUPPORT_VARCHAR_TYPE | FUNC_PARAM_SUPPORT_NCHAR_TYPE,
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateGreatestleast,
.getEnvFunc = NULL,
.initFunc = NULL,
.sprocessFunc = leastFunction,
.finalizeFunc = NULL
},
};
// clang-format on

View File

@ -1,11 +1,14 @@
#include <stdint.h>
#include "cJSON.h"
#include "function.h"
#include "scalar.h"
#include "sclInt.h"
#include "sclvector.h"
#include "tdatablock.h"
#include "tdef.h"
#include "tjson.h"
#include "ttime.h"
#include "filter.h"
typedef float (*_float_fn)(float);
typedef float (*_float_fn_2)(float, float);
@ -4403,3 +4406,136 @@ int32_t modeScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
return selectScalarFunction(pInput, inputNum, pOutput);
}
typedef struct SCovertScarlarParam {
SScalarParam covertParam;
SScalarParam *param;
bool converted;
} SCovertScarlarParam;
void freeSCovertScarlarParams(SCovertScarlarParam *pCovertParams, int32_t num) {
if (pCovertParams == NULL) {
return;
}
for (int32_t i = 0; i < num; i++) {
if (pCovertParams[i].converted) {
sclFreeParam(pCovertParams[i].param);
}
}
taosMemoryFree(pCovertParams);
}
static int32_t vectorCompareAndSelect(SCovertScarlarParam *pParams, int32_t numOfRows, int numOfCols,
int32_t *resultColIndex, EOperatorType optr) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t type = GET_PARAM_TYPE(pParams[0].param);
__compar_fn_t fp = NULL;
code = filterGetCompFunc(&fp, type, optr);
if(code != TSDB_CODE_SUCCESS) {
qError("failed to get compare function, func:%s type:%d, optr:%d", __FUNCTION__, type, optr);
return code;
}
for (int32_t i = 0; i < numOfRows; i++) {
int selectIndex = 0;
if (colDataIsNull_s(pParams[selectIndex].param->columnData, i)) {
resultColIndex[i] = -1;
continue;
}
for (int32_t j = 1; j < numOfCols; j++) {
if (colDataIsNull_s(pParams[j].param->columnData, i)) {
resultColIndex[i] = -1;
break;
} else {
int32_t leftRowNo = pParams[selectIndex].param->numOfRows == 1 ? 0 : i;
int32_t rightRowNo = pParams[j].param->numOfRows == 1 ? 0 : i;
char *pLeftData = colDataGetData(pParams[selectIndex].param->columnData, leftRowNo);
char *pRightData = colDataGetData(pParams[j].param->columnData, rightRowNo);
bool pRes = filterDoCompare(fp, optr, pLeftData, pRightData);
if (!pRes) {
selectIndex = j;
}
}
resultColIndex[i] = selectIndex;
}
}
return code;
}
static int32_t greatestLeastImpl(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, EOperatorType order) {
int32_t code = TSDB_CODE_SUCCESS;
SColumnInfoData *pOutputData = pOutput[0].columnData;
int16_t outputType = GET_PARAM_TYPE(&pOutput[0]);
int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]);
SCovertScarlarParam *pCovertParams = NULL;
int32_t *resultColIndex = NULL;
int32_t numOfRows = 0;
bool IsNullType = outputType == TSDB_DATA_TYPE_NULL ? true : false;
// If any column is NULL type, the output is NULL type
for (int32_t i = 0; i < inputNum; i++) {
if (IsNullType) {
break;
}
if (numOfRows != 0 && numOfRows != pInput[i].numOfRows && pInput[i].numOfRows != 1 && numOfRows != 1) {
qError("input rows not match, func:%s, rows:%d, %d", __FUNCTION__, numOfRows, pInput[i].numOfRows);
code = TSDB_CODE_TSC_INTERNAL_ERROR;
goto _return;
}
numOfRows = TMAX(numOfRows, pInput[i].numOfRows);
IsNullType |= IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]));
}
if (IsNullType) {
colDataSetNNULL(pOutputData, 0, numOfRows);
pOutput->numOfRows = numOfRows;
return TSDB_CODE_SUCCESS;
}
pCovertParams = taosMemoryMalloc(inputNum * sizeof(SCovertScarlarParam));
for (int32_t j = 0; j < inputNum; j++) {
SScalarParam *pParam = &pInput[j];
int16_t oldType = GET_PARAM_TYPE(&pInput[j]);
if (oldType != outputType) {
pCovertParams[j].covertParam = (SScalarParam){0};
setTzCharset(&pCovertParams[j].covertParam, pParam->tz, pParam->charsetCxt);
SCL_ERR_JRET(vectorConvertSingleCol(pParam, &pCovertParams[j].covertParam, outputType, 0, pParam->numOfRows));
pCovertParams[j].param = &pCovertParams[j].covertParam;
pCovertParams[j].converted = true;
} else {
pCovertParams[j].param = pParam;
pCovertParams[j].converted = false;
}
}
resultColIndex = taosMemoryCalloc(numOfRows, sizeof(int32_t));
SCL_ERR_JRET(vectorCompareAndSelect(pCovertParams, numOfRows, inputNum, resultColIndex, order));
for (int32_t i = 0; i < numOfRows; i++) {
int32_t index = resultColIndex[i];
if (index == -1) {
colDataSetNULL(pOutputData, i);
continue;
}
int32_t rowNo = pCovertParams[index].param->numOfRows == 1 ? 0 : i;
char *data = colDataGetData(pCovertParams[index].param->columnData, rowNo);
SCL_ERR_JRET(colDataSetVal(pOutputData, i, data, false));
}
pOutput->numOfRows = numOfRows;
_return:
freeSCovertScarlarParams(pCovertParams, inputNum);
taosMemoryFree(resultColIndex);
return code;
}
int32_t greatestFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return greatestLeastImpl(pInput, inputNum, pOutput, OP_TYPE_GREATER_THAN);
}
int32_t leastFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return greatestLeastImpl(pInput, inputNum, pOutput, OP_TYPE_LOWER_THAN);
}

View File

@ -996,7 +996,7 @@ int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut,
}
int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 5, 9, 5, 11, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 5, 9, 5, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
@ -1021,7 +1021,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
};
int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/* NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN 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, 20,
/*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1,
/*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1,

View File

@ -717,7 +717,7 @@ void handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList) {
// The restart of all tasks requires that all tasks should not have active timer for now. Therefore, the execution
// of restart in timer thread will result in a deadlock.
int32_t addDownstreamFailedStatusResultAsync(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId) {
return streamTaskSchedTask(pMsgCb, vgId, streamId, taskId, STREAM_EXEC_T_ADD_FAILED_TASK);
return streamTaskSchedTask(pMsgCb, vgId, streamId, taskId, STREAM_EXEC_T_ADD_FAILED_TASK, false);
}
static void doCleanup(SStreamTask* pTask, SArray* pNotReadyList, SArray* pTimeoutList, void* param) {

View File

@ -93,7 +93,7 @@ int32_t appendCheckpointIntoInputQ(SStreamTask* pTask, int32_t checkpointType, i
return TSDB_CODE_OUT_OF_MEMORY;
}
return streamTrySchedExec(pTask);
return streamTrySchedExec(pTask, true);
}
int32_t streamProcessCheckpointSourceReq(SStreamTask* pTask, SStreamCheckpointSourceReq* pReq) {

View File

@ -1834,6 +1834,7 @@ int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, S
int32_t status = 0;
SStreamMeta* pMeta = pTask->pMeta;
const char* id = pTask->id.idStr;
bool chkptMsg = false;
stDebug("s-task:%s receive dispatch msg from taskId:0x%x(vgId:%d), msgLen:%" PRId64 ", msgId:%d", id,
pReq->upstreamTaskId, pReq->upstreamNodeId, pReq->totalLen, pReq->msgId);
@ -1863,6 +1864,7 @@ int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, S
// blocked. Note that there is no race condition here.
if (pReq->type == STREAM_INPUT__CHECKPOINT_TRIGGER) {
streamTaskCloseUpstreamInput(pTask, pReq->upstreamTaskId);
chkptMsg = true;
stDebug("s-task:%s close inputQ for upstream:0x%x, msgId:%d", id, pReq->upstreamTaskId, pReq->msgId);
} else if (pReq->type == STREAM_INPUT__TRANS_STATE) {
stDebug("s-task:%s recv trans-state msgId:%d from upstream:0x%x", id, pReq->msgId, pReq->upstreamTaskId);
@ -1890,5 +1892,5 @@ int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, S
tmsgSendRsp(pRsp);
}
return streamTrySchedExec(pTask);
return streamTrySchedExec(pTask, chkptMsg);
}

View File

@ -144,11 +144,20 @@ void streamQueueNextItemInSourceQ(SStreamQueue* pQueue, SStreamQueueItem** pItem
// let's try the ordinary input q
pQueue->qItem = NULL;
int32_t num = taosGetQitem(pQueue->qall, &pQueue->qItem);
int32_t code = taosGetQitem(pQueue->qall, &pQueue->qItem);
if (code) {
stError("s-task:%s failed to extract data from inputQ, code:%s", id, tstrerror(code));
}
if (pQueue->qItem == NULL) {
num = taosReadAllQitems(pQueue->pQueue, pQueue->qall);
num = taosGetQitem(pQueue->qall, &pQueue->qItem);
code = taosReadAllQitems(pQueue->pQueue, pQueue->qall);
if (code) {
stError("s-task:%s failed to read qitem into qall, code:%s", id, tstrerror(code));
}
code = taosGetQitem(pQueue->qall, &pQueue->qItem);
if (code) {
stError("s-task:%s failed to extract data from inputQ(qall), code:%s", id, tstrerror(code));
}
}
*pItem = streamQueueCurItem(pQueue);

View File

@ -93,17 +93,21 @@ void streamSetupScheduleTrigger(SStreamTask* pTask) {
}
}
int32_t streamTrySchedExec(SStreamTask* pTask) {
int32_t streamTrySchedExec(SStreamTask* pTask, bool chkptQueue) {
if (streamTaskSetSchedStatusWait(pTask)) {
return streamTaskSchedTask(pTask->pMsgCb, pTask->info.nodeId, pTask->id.streamId, pTask->id.taskId, 0);
return streamTaskSchedTask(pTask->pMsgCb, pTask->info.nodeId, pTask->id.streamId, pTask->id.taskId, 0, chkptQueue);
} else {
stTrace("s-task:%s not launch task since sched status:%d", pTask->id.idStr, pTask->status.schedStatus);
if (chkptQueue) {
stWarn("s-task:%s not launch task in chkpt queue, may delay checkpoint procedure", pTask->id.idStr);
} else {
stTrace("s-task:%s not launch task since sched status:%d", pTask->id.idStr, pTask->status.schedStatus);
}
}
return 0;
}
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType) {
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType, bool chkptExec) {
int32_t code = 0;
int32_t tlen = 0;
@ -142,10 +146,18 @@ int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int3
stDebug("vgId:%d create msg to exec, type:%d, %s", vgId, execType, streamTaskGetExecType(execType));
}
SRpcMsg msg = {.msgType = TDMT_STREAM_TASK_RUN, .pCont = buf, .contLen = tlen + sizeof(SMsgHead)};
code = tmsgPutToQueue(pMsgCb, STREAM_QUEUE, &msg);
if (code) {
stError("vgId:%d failed to put msg into stream queue, code:%s, %x", vgId, tstrerror(code), taskId);
if (chkptExec) {
SRpcMsg msg = {.msgType = TDMT_STREAM_CHKPT_EXEC, .pCont = buf, .contLen = tlen + sizeof(SMsgHead)};
code = tmsgPutToQueue(pMsgCb, STREAM_CHKPT_QUEUE, &msg);
if (code) {
stError("vgId:%d failed to put msg into stream chkpt queue, code:%s, %x", vgId, tstrerror(code), taskId);
}
} else {
SRpcMsg msg = {.msgType = TDMT_STREAM_TASK_RUN, .pCont = buf, .contLen = tlen + sizeof(SMsgHead)};
code = tmsgPutToQueue(pMsgCb, STREAM_QUEUE, &msg);
if (code) {
stError("vgId:%d failed to put msg into stream queue, code:%s, %x", vgId, tstrerror(code), taskId);
}
}
return code;
}
@ -191,12 +203,17 @@ void streamTaskResumeHelper(void* param, void* tmrId) {
return;
}
code = streamTaskSchedTask(pTask->pMsgCb, pTask->info.nodeId, pId->streamId, pId->taskId, STREAM_EXEC_T_RESUME_TASK);
code = streamTaskSchedTask(pTask->pMsgCb, pTask->info.nodeId, pId->streamId, pId->taskId, STREAM_EXEC_T_RESUME_TASK,
(p.state == TASK_STATUS__CK));
if (code) {
stError("s-task:%s sched task failed, code:%s", pId->idStr, tstrerror(code));
} else {
stDebug("trigger to resume s-task:%s after idled for %dms", pId->idStr, pTask->status.schedIdleTime);
if (p.state == TASK_STATUS__CK) {
stDebug("trigger to resume s-task:%s in stream chkpt queue after idled for %dms", pId->idStr,
pTask->status.schedIdleTime);
} else {
stDebug("trigger to resume s-task:%s after idled for %dms", pId->idStr, pTask->status.schedIdleTime);
}
// release the task ref count
streamTaskClearSchedIdleInfo(pTask);
}
@ -339,7 +356,7 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
}
}
code = streamTrySchedExec(pTask);
code = streamTrySchedExec(pTask, false);
if (code != TSDB_CODE_SUCCESS) {
stError("s-task:%s failed to sched to run, wait for next time", pTask->id.idStr);
}

View File

@ -1194,7 +1194,7 @@ int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
if (code != 0) {
return code;
}
return streamTrySchedExec(pTask);
return streamTrySchedExec(pTask, false);
}
void streamTaskSetRemoveBackendFiles(SStreamTask* pTask) { pTask->status.removeBackendFiles = true; }

View File

@ -345,7 +345,9 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
if (!pPage && pTxn->xMalloc != NULL) {
ret = tdbPageCreate(pCache->szPage, &pPage, pTxn->xMalloc, pTxn->xArg);
if (ret < 0 || pPage == NULL) {
tdbError("tdb/pcache: ret: %" PRId32 " pPage: %p, page create failed.", ret, pPage);
// when allocating from bufpool failed, it's time to flush cache.
// tdbError("tdb/pcache: ret: %" PRId32 " pPage: %p, page create failed.", ret, pPage);
terrno = ret;
return NULL;
}
@ -551,5 +553,4 @@ static void tdbPCacheCloseImpl(SPCache *pCache) {
tdbOsFree(pCache->pgHash);
tdbPCacheDestroyLock(pCache);
return ;
}

View File

@ -104,7 +104,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
}
#endif
/*
if (rollback) {
ret = tdbPagerRestoreJournals(pPager);
if (ret < 0) {
@ -118,6 +118,13 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
return ret;
}
}
*/
// Always restore journal files with page flushing
ret = tdbPagerRestoreJournals(pPager);
if (ret < 0) {
tdbOsFree(pTb);
return ret;
}
// pTb->pBt
ret = tdbBtreeOpen(keyLen, valLen, pPager, tbname, pgno, keyCmprFn, pEnv, &(pTb->pBt));

View File

@ -18,3 +18,6 @@ target_link_libraries(tdbPageDefragmentTest tdb gtest gtest_main)
add_executable(tdbPageRecycleTest "tdbPageRecycleTest.cpp")
target_link_libraries(tdbPageRecycleTest tdb gtest gtest_main)
# page flush testing
add_executable(tdbPageFlushTest "tdbPageFlushTest.cpp")
target_link_libraries(tdbPageFlushTest tdb gtest gtest_main)

View File

@ -0,0 +1,582 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#define ALLOW_FORBID_FUNC
#include "os.h"
#include "tdb.h"
#include <shared_mutex>
#include <string>
#include <thread>
#include <vector>
#include "tlog.h"
typedef struct SPoolMem {
int64_t size;
struct SPoolMem *prev;
struct SPoolMem *next;
} SPoolMem;
static SPoolMem *openPool() {
SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool));
pPool->prev = pPool->next = pPool;
pPool->size = 0;
return pPool;
}
static void clearPool(SPoolMem *pPool) {
SPoolMem *pMem;
do {
pMem = pPool->next;
if (pMem == pPool) break;
pMem->next->prev = pMem->prev;
pMem->prev->next = pMem->next;
pPool->size -= pMem->size;
taosMemoryFree(pMem);
} while (1);
assert(pPool->size == 0);
}
static void closePool(SPoolMem *pPool) {
clearPool(pPool);
taosMemoryFree(pPool);
}
static void *poolMalloc(void *arg, size_t size) {
void *ptr = NULL;
SPoolMem *pPool = (SPoolMem *)arg;
SPoolMem *pMem;
pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size);
if (pMem == NULL) {
assert(0);
}
pMem->size = sizeof(*pMem) + size;
pMem->next = pPool->next;
pMem->prev = pPool;
pPool->next->prev = pMem;
pPool->next = pMem;
pPool->size += pMem->size;
ptr = (void *)(&pMem[1]);
return ptr;
}
static void *poolMallocRestricted(void *arg, size_t size) {
void *ptr = NULL;
SPoolMem *pPool = (SPoolMem *)arg;
SPoolMem *pMem;
if (pPool->size > 1024 * 1024 * 10) {
return NULL;
}
pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size);
if (pMem == NULL) {
assert(0);
}
pMem->size = sizeof(*pMem) + size;
pMem->next = pPool->next;
pMem->prev = pPool;
pPool->next->prev = pMem;
pPool->next = pMem;
pPool->size += pMem->size;
ptr = (void *)(&pMem[1]);
return ptr;
}
static void poolFree(void *arg, void *ptr) {
SPoolMem *pPool = (SPoolMem *)arg;
SPoolMem *pMem;
pMem = &(((SPoolMem *)ptr)[-1]);
pMem->next->prev = pMem->prev;
pMem->prev->next = pMem->next;
pPool->size -= pMem->size;
taosMemoryFree(pMem);
}
static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) {
int mlen;
int cret;
ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL);
mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2;
cret = memcmp(pKey1, pKey2, mlen);
if (cret == 0) {
if (keyLen1 < keyLen2) {
cret = -1;
} else if (keyLen1 > keyLen2) {
cret = 1;
} else {
cret = 0;
}
}
return cret;
}
static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
int k1, k2;
std::string s1((char *)pKey1 + 3, kLen1 - 3);
std::string s2((char *)pKey2 + 3, kLen2 - 3);
k1 = stoi(s1);
k2 = stoi(s2);
if (k1 < k2) {
return -1;
} else if (k1 > k2) {
return 1;
} else {
return 0;
}
}
static TDB *openEnv(char const *envName, int const pageSize, int const pageNum) {
TDB *pEnv = NULL;
int ret = tdbOpen(envName, pageSize, pageNum, &pEnv, 0, 0, NULL);
if (ret) {
pEnv = NULL;
}
return pEnv;
}
static void clearDb(char const *db) { taosRemoveDir(db); }
static void generateBigVal(char *val, int valLen) {
for (int i = 0; i < valLen; ++i) {
char c = char(i & 0xff);
if (c == 0) {
c = 1;
}
val[i] = c;
}
}
static void insertOfp(void) {
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
char const *key = "key123456789";
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
// commit current transaction
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}
static void insertMultipleOfp(void) {
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
// char const *key = "key1";
for (int i = 0; i < 1024 * 4; ++i) {
// char const *key = "key123456789";
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
// commit current transaction
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}
// TEST(TdbPageFlushTest, DISABLED_TbRestoreTest) {
TEST(TdbPageFlushTest, TbRestoreTest) {
clearDb("tdb");
insertMultipleOfp();
}
// TEST(TdbPageFlushTest, DISABLED_TbRestoreTest2) {
TEST(TdbPageFlushTest, TbRestoreTest2) {
clearDb("tdb");
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
// char const *key = "key1";
for (int i = 0; i < 1024 * 4; ++i) {
// char const *key = "key123456789";
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
// commit current transaction
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
for (int i = 1024 * 4; i < 1024 * 8; ++i) {
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}
// TEST(TdbPageFlushTest, DISABLED_TbRestoreTest3) {
TEST(TdbPageFlushTest, TbRestoreTest3) {
clearDb("tdb");
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
// char const *key = "key1";
for (int i = 0; i < 1024 * 4; ++i) {
// char const *key = "key123456789";
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
// commit current transaction
tdbAbort(pEnv, txn);
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
for (int i = 1024 * 4; i < 1024 * 8; ++i) {
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}
// TEST(TdbPageFlushTest, DISABLED_TbRestoreTest4) {
TEST(TdbPageFlushTest, TbRestoreTest4) {
clearDb("tdb");
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
// char const *key = "key1";
for (int i = 0; i < 1024 * 4; ++i) {
// char const *key = "key123456789";
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
// commit current transaction
tdbAbort(pEnv, txn);
closePool(pPool);
tdbTbClose(pDb);
tdbClose(pEnv);
pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
pPool = openPool();
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
for (int i = 1024 * 4; i < 1024 * 8; ++i) {
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}
// TEST(TdbPageFlushTest, DISABLED_TbRestoreTest5) {
TEST(TdbPageFlushTest, TbRestoreTest5) {
clearDb("tdb");
int ret = 0;
// open Env
int const pageSize = 4096;
int const pageNum = 64;
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
// ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
SPoolMem *pPool = openPool();
// start a transaction
TXN *txn = NULL;
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
// generate value payload
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
char val[32605];
int valLen = sizeof(val) / sizeof(val[0]);
generateBigVal(val, valLen);
// insert the generated big data
// char const *key = "key1";
for (int i = 0; i < 1024 * 4; ++i) {
// char const *key = "key123456789";
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
// commit current transaction
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
tdbTbClose(pDb);
tdbClose(pEnv);
pEnv = openEnv("tdb", pageSize, pageNum);
GTEST_ASSERT_NE(pEnv, nullptr);
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
pPool = openPool();
tdbBegin(pEnv, &txn, poolMallocRestricted, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
for (int i = 1024 * 4; i < 1024 * 8; ++i) {
char key[32] = {0};
sprintf(key, "key-%d", i);
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
GTEST_ASSERT_EQ(ret, 0);
}
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
closePool(pPool);
// Close a database
tdbTbClose(pDb);
// Close Env
tdbClose(pEnv);
}

View File

@ -0,0 +1,97 @@
import taos
import sys
import os
import subprocess
import glob
import shutil
import time
from frame.log import *
from frame.cases import *
from frame.sql import *
from frame.srvCtl import *
from frame.caseBase import *
from frame import *
from frame.autogen import *
from frame import epath
# from frame.server.dnodes import *
# from frame.server.cluster import *
class TDTestCase(TBase):
def init(self, conn, logSql, replicaVar=1):
updatecfgDict = {'dDebugFlag':131}
super(TDTestCase, self).init(conn, logSql, replicaVar=1, checkColName="c1")
self.valgrind = 0
self.db = "test"
self.stb = "meters"
self.childtable_count = 10
tdSql.init(conn.cursor(), logSql)
def run(self):
tdSql.execute('CREATE DATABASE db vgroups 1 replica 2;')
time.sleep(1)
tdSql.execute("use db;")
tdSql.execute("CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);")
tdSql.execute("CREATE TABLE d0 USING meters TAGS (\"California.SanFrancisco\", 2);");
count = 0
while count < 100:
tdSql.query("show arbgroups;")
if tdSql.getData(0, 4) == True:
break
tdLog.info("wait %d seconds for is sync"%count)
time.sleep(1)
count += 1
if count == 100:
tdLog.exit("arbgroup sync failed")
return
tdSql.query("show db.vgroups;")
if(tdSql.getData(0, 4) == "follower") and (tdSql.getData(0, 7) == "leader"):
tdLog.info("stop dnode2")
sc.dnodeStop(2)
if(tdSql.getData(0, 7) == "follower") and (tdSql.getData(0, 4) == "leader"):
tdLog.info("stop dnode 3")
sc.dnodeStop(3)
count = 0
while count < 11:
tdSql.query("show db.vgroups;")
if(tdSql.getData(0, 4) == "assigned ") or (tdSql.getData(0, 7) == "assigned "):
break
tdLog.info("wait %d seconds for set assigned"%count)
time.sleep(1)
count += 1
if count == 11:
tdLog.exit("check assigned failed")
return
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -19,6 +19,7 @@ import random
import copy
import json
import frame.eos
import frame.etool
import frame.eutil
from frame.log import *
@ -427,6 +428,42 @@ class TBase:
return db, stb, child_count, insert_rows
# insert & check
def benchInsert(self, jsonFile, options = "", results = None):
# exe insert
benchmark = frame.etool.benchMarkFile()
cmd = f"{benchmark} {options} -f {jsonFile}"
rlist = frame.eos.runRetList(cmd, True, True, True)
if results != None:
for result in results:
self.checkListString(rlist, result)
# open json
with open(jsonFile, "r") as file:
data = json.load(file)
# read json
dbs = data["databases"]
for db in dbs:
dbName = db["dbinfo"]["name"]
stbs = db["super_tables"]
for stb in stbs:
stbName = stb["name"]
child_count = stb["childtable_count"]
insert_rows = stb["insert_rows"]
timestamp_step = stb["timestamp_step"]
# check result
# count
sql = f"select count(*) from {dbName}.{stbName}"
tdSql.checkAgg(sql, child_count * insert_rows)
# diff
sql = f"select * from (select diff(ts) as dif from {dbName}.{stbName} partition by tbname) where dif != {timestamp_step};"
tdSql.query(sql)
tdSql.checkRows(0)
# show
tdLog.info(f"insert check passed. db:{dbName} stb:{stbName} child_count:{child_count} insert_rows:{insert_rows}\n")
# tmq
def tmqBenchJson(self, jsonFile, options="", checkStep=False):

View File

@ -51,7 +51,7 @@ taos> select ASCII('hello') + 1 from ts_4893.meters limit 1
taos> select ASCII('hello') + ASCII('hello') from ts_4893.meters limit 1
ascii('hello') + ascii('hello') |
==================================
2.080000000000000e+02 |
208 |
taos> select ASCII(nch1) from ts_4893.meters order by ts limit 5
ascii(nch1) |

Can't render this file because it has a wrong number of fields in line 17.

View File

@ -51,7 +51,7 @@ taos> select CHAR_LENGTH('hello') + 1 from ts_4893.meters limit 1
taos> select CHAR_LENGTH('hello') + CHAR_LENGTH('hello') from ts_4893.meters limit 1
char_length('hello') + char_length('hello') |
==============================================
1.000000000000000e+01 |
10 |
taos> select CHAR_LENGTH(nch1) from ts_4893.meters order by ts limit 5
char_length(nch1) |

Can't render this file because it has a wrong number of fields in line 17.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -576,7 +576,7 @@ taos> select max(total_voltage) from (select sum(voltage) as total_voltage from
taos> select round(max(current), 2) from ts_4893.meters
round(max(current), 2) |
=========================
1.2000000e+01 |
12 |
taos> select pow(max(current), 2) from ts_4893.meters
pow(max(current), 2) |
@ -651,7 +651,7 @@ taos> select max(cast(10000000000 as bigint unsigned))
taos> select max(cast(1.1 as float))
max(cast(1.1 as float)) |
==========================
1.1000000e+00 |
1.1 |
taos> select max(cast(1.1 as double))
max(cast(1.1 as double)) |

Can't render this file because it has a wrong number of fields in line 576.

View File

@ -576,7 +576,7 @@ taos> select min(total_voltage) from (select sum(voltage) as total_voltage from
taos> select round(min(current), 2) from ts_4893.meters
round(min(current), 2) |
=========================
8.0000000e+00 |
8 |
taos> select pow(min(current), 2) from ts_4893.meters
pow(min(current), 2) |
@ -651,7 +651,7 @@ taos> select min(cast(10000000000 as bigint unsigned))
taos> select min(cast(1.1 as float))
min(cast(1.1 as float)) |
==========================
1.1000000e+00 |
1.1 |
taos> select min(cast(1.1 as double))
min(cast(1.1 as double)) |

Can't render this file because it has a wrong number of fields in line 576.

View File

@ -42,26 +42,26 @@ taos> select MOD(10.55, 1) + 1
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 |
0.123456789000002 |
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 |
0.123456791043282 |
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 |
0.123456791043282 |
1.12345679104328 |
0.123456791043282 |
1.12345679104328 |
1.12345679104328 |
3.12345679104328 |
6.12345679104328 |
1.12345679104328 |
0.123456791043282 |
1.12345679104328 |
taos> select MOD(current, id + 1) from ts_4893.meters order by ts limit 10
mod(current, id + 1) |
@ -94,16 +94,16 @@ taos> select MOD(current, 1) from ts_4893.meters order by ts limit 10
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 |
0.263433715970078 |
0.928139402177011 |
0.129696483094478 |
3.35156676819003 |
3.27200249511885 |
2.91684767751769 |
3.0977410669248 |
3.31089110258681 |
3.35052232228847 |
3.21512050990137 |
taos> select mod(10, -3)
mod(10, -3) |

1 taos> select MOD(10.55, 3)
42 mod(87654321.123456789, id + 1) |
43 ==================================
44 1.234567910432816e-01 | 0.123456791043282 |
45 1.123456791043282e+00 | 1.12345679104328 |
46 1.234567910432816e-01 | 0.123456791043282 |
47 1.123456791043282e+00 | 1.12345679104328 |
48 1.123456791043282e+00 | 1.12345679104328 |
49 3.123456791043282e+00 | 3.12345679104328 |
50 6.123456791043282e+00 | 6.12345679104328 |
51 1.123456791043282e+00 | 1.12345679104328 |
52 1.234567910432816e-01 | 0.123456791043282 |
53 1.123456791043282e+00 | 1.12345679104328 |
54 taos> select MOD(current, id + 1) from ts_4893.meters order by ts limit 10
55 mod(current, id + 1) |
56 ============================
57 0.649999618530273 |
58 0.574000358581543 |
59 0.795000076293945 |
60 3.23299980163574 |
61 0.706000328063965 |
62 2.50800037384033 |
63 2.5959997177124 |
64 2.96199989318848 |
65 2.22599983215332 |
66 0.336999893188477 |
67 taos> select MOD(current, 1) from ts_4893.meters order by ts limit 10
94 mod(10, -3) |
95 ============================
96 1 |
97 taos> select mod(10, 3)
98 mod(10, 3) |
99 ============================
100 1 |
101 taos> select mod(id, 3) from ts_4893.d0 order by ts limit 10
102 mod(id, 3) |
103 ============================
104 0 |
105 1 |
106 2 |
107 0 |
108 1 |
109 2 |

View File

@ -190,5 +190,5 @@ taos> select voltage / pi() from ts_4893.meters limit 1
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 |
0 | 3.14159265358979 |

Can't render this file because it has a wrong number of fields in line 90.

View File

@ -201,7 +201,7 @@ taos> select ABS(POSITION('aaa' IN 'aaaaaaaaa'))
taos> select POW(POSITION('aaa' IN 'aaaaaaaaa'), 2)
pow(position('aaa' in 'aaaaaaaaa'), 2) |
=========================================
1.000000000000000e+00 |
1 |
taos> select position('t' in 'taos')
position('t' in 'taos') |

Can't render this file because it has a wrong number of fields in line 22.

View File

@ -50,12 +50,12 @@ taos> select rand(-1)
taos> select rand(12345678901234567890)
rand(12345678901234567890) |
=============================
2.008294813338805e-01 |
0.20082948133388 |
taos> select rand(-12345678901234567890)
rand(-12345678901234567890) |
==============================
8.401877171547095e-01 |
0.84018771715471 |
taos> select rand(12345), rand(12345)
rand(12345) | rand(12345) |

Can't render this file because it has a wrong number of fields in line 60.

View File

@ -67,12 +67,12 @@ taos> select ROUND(10.55, 1) + 1
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 |
123 |
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 |
123000000 |
taos> select ROUND(current) from ts_4893.meters order by ts limit 20
round(current) |
@ -101,16 +101,16 @@ taos> select ROUND(current) from ts_4893.meters order by ts limit 20
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 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1235 |
87654321.12346 |
87654321.123457 |
87654321.1234568 |
87654321.1234568 |
87654321.1234568 |
taos> select ROUND(current, id) from ts_4893.meters order by ts limit 10
round(current, id) |
@ -286,7 +286,7 @@ taos> select round(voltage, -1) from ts_4893.meters limit 1
taos> select round(current * voltage, 2) from ts_4893.meters limit 1
round(current * voltage, 2) |
==============================
2.353650000000000e+03 |
2353.65 |
taos> select round(abs(voltage), 2) from ts_4893.meters limit 1
round(abs(voltage), 2) |

1 taos> select ROUND(10.55, 3)
67 11 |
68 11 |
69 9 |
70 10 |
71 11 |
72 11 |
73 10 |
74 11 |
75 9 |
76 11 |
77 8 |
78 12 |
101 8.6 |
102 9.8 |
103 11.233 |
104 10.706 |
105 8.508 |
106 9.596 |
107 10.962 |
108 11.226 |
109 10.337 |
110 taos> select ROUND(current, 1) from ts_4893.meters order by ts limit 10
111 round(current, 1) |
112 =======================
113 10.7 |
114 8.6 |
115 9.8 |
116 11.2 |
286 round(cast(5 as tinyint unsigned), 1) |
287 ========================================
288 5 |
289 taos> select round(cast(50 as smallint unsigned), 1);
290 round(cast(50 as smallint unsigned), 1) |
291 ==========================================
292 50 |

View File

@ -164,7 +164,7 @@ taos> select sign(cast(1 as bigint unsigned))
taos> select sign(cast(1 as float))
sign(cast(1 as float)) |
=========================
1.0000000e+00 |
1 |
taos> select sign(cast(1 as double))
sign(cast(1 as double)) |
@ -316,30 +316,30 @@ taos> select sign(current) from ts_4893.meters order by ts limit 10
taos> select sign(cast(current as float)) from ts_4893.d0 order by ts limit 10
sign(cast(current as float)) |
===============================
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
taos> select sign(cast(current as float)) from ts_4893.meters order by ts limit 10
sign(cast(current as float)) |
===============================
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1.0000000e+00 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
taos> select sign(null)
sign(null) |

Can't render this file because it has a wrong number of fields in line 239.

View File

@ -109,17 +109,17 @@ taos> select stddev_pop(total_voltage) from (select sum(voltage) as total_voltag
taos> select round(stddev_pop(current), 2) from ts_4893.meters
round(stddev_pop(current), 2) |
================================
1.150000000000000e+00 |
1.15 |
taos> select pow(stddev_pop(current), 2) from ts_4893.meters
pow(stddev_pop(current), 2) |
==============================
1.332500071133751e+00 |
1.33250007113375 |
taos> select log(stddev_pop(voltage) + 1) from ts_4893.meters
log(stddev_pop(voltage) + 1) |
===============================
1.354922290183882e+00 |
1.35492229018388 |
taos> select groupid, stddev_pop(voltage) from ts_4893.meters group by groupid order by groupid
groupid | stddev_pop(voltage) |

Can't render this file because it has a wrong number of fields in line 109.

View File

@ -47,40 +47,40 @@ taos> select TRUNCATE(10.55, 1) + 1
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 |
123.123 |
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 |
120000000 |
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 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1234 |
87654321.12345 |
87654321.123456 |
87654321.1234567 |
87654321.1234568 |
87654321.1234568 |
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 |
10 |
8.5 |
9.79 |
11.233 |
10.706 |
8.508 |
9.596 |
10.962 |
11.226 |
10.337 |
taos> select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10
truncate(current, 1) |
@ -144,26 +144,26 @@ taos> select TRUNC(10.55, 1) + 1
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 |
123.123 |
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 |
120000000 |
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 |
87654321 |
87654321.1 |
87654321.12 |
87654321.123 |
87654321.1234 |
87654321.12345 |
87654321.123456 |
87654321.1234567 |
87654321.1234568 |
87654321.1234568 |
taos> select TRUNC(current, id) from ts_4893.meters order by ts limit 10
trunc(current, id) |
@ -289,7 +289,7 @@ taos> select truncate(100.9876, 2)
taos> select truncate(99999999999999.9999, 2)
truncate(99999999999999.9999, 2) |
===================================
1.000000000000000e+14 |
100000000000000 |
taos> select truncate(-5.678, 2)
truncate(-5.678, 2) |
@ -314,7 +314,7 @@ taos> select truncate(phase, 3) from ts_4893.meters limit 1
taos> select truncate(voltage + current, 2) from ts_4893.meters limit 1
truncate(voltage + current, 2) |
=================================
2.316400000000000e+02 |
231.64 |
taos> select truncate(voltage, -1) from ts_4893.meters limit 1
truncate(voltage, -1) |
@ -329,7 +329,7 @@ taos> select round(truncate(voltage, 1), 2) from ts_4893.meters limit 1
taos> select truncate(abs(current), 1) from ts_4893.meters limit 1
truncate(abs(current), 1) |
============================
1.0600000e+01 |
10.6 |
taos> select truncate(exp(phase), 2) from ts_4893.meters limit 1
truncate(exp(phase), 2) |

1 taos> select TRUNCATE(10.55, 3)
47 ===================================
48 8.765432100000000e+07 | 87654321 |
49 8.765432109999999e+07 | 87654321.1 |
50 8.765432112000000e+07 | 87654321.12 |
51 8.765432112300000e+07 | 87654321.123 |
52 8.765432112340000e+07 | 87654321.1234 |
53 8.765432112345000e+07 | 87654321.12345 |
54 8.765432112345600e+07 | 87654321.123456 |
55 8.765432112345670e+07 | 87654321.1234567 |
56 8.765432112345679e+07 | 87654321.1234568 |
57 8.765432112345679e+07 | 87654321.1234568 |
58 taos> select TRUNCATE(current, id) from ts_4893.meters order by ts limit 10
59 truncate(current, id) |
60 ========================
61 1.0000000e+01 | 10 |
62 8.5000000e+00 | 8.5 |
63 9.7900000e+00 | 9.79 |
64 1.1233000e+01 | 11.233 |
65 1.0706000e+01 | 10.706 |
66 8.5080004e+00 | 8.508 |
67 9.5959997e+00 | 9.596 |
68 1.0962000e+01 | 10.962 |
69 1.1226000e+01 | 11.226 |
70 1.0337000e+01 | 10.337 |
71 taos> select TRUNCATE(current, 1) from ts_4893.meters order by ts limit 10
72 truncate(current, 1) |
73 =======================
74 10.6 |
75 8.5 |
76 9.7 |
77 11.2 |
78 10.7 |
79 8.5 |
80 9.5 |
81 10.9 |
82 11.2 |
83 10.3 |
84 taos> select TRUNC(10.55, 3)
85 trunc(10.55, 3) |
86 ============================
144 10 |
145 8.5 |
146 9.79 |
147 11.233 |
148 10.706 |
149 8.508 |
150 9.596 |
151 10.962 |
152 11.226 |
153 10.337 |
154 taos> select TRUNC(current, 1) from ts_4893.meters order by ts limit 10
155 trunc(current, 1) |
156 =======================
157 10.6 |
158 8.5 |
159 9.7 |
160 11.2 |
161 10.7 |
162 8.5 |
163 9.5 |
164 10.9 |
165 11.2 |
166 10.3 |
167 taos> select truncate(99.99, 3)
168 truncate(99.99, 3) |
169 ============================
289
290
291
292
293
294
295
314
315
316
317
318
319
320
329
330
331
332
333
334
335

View File

@ -99,7 +99,7 @@ taos> select var_pop(total_voltage) from (select sum(voltage) as total_voltage f
taos> select round(var_pop(current), 2) from ts_4893.meters
round(var_pop(current), 2) |
=============================
1.330000000000000e+00 |
1.33 |
taos> select pow(var_pop(current), 2) from ts_4893.meters
pow(var_pop(current), 2) |

Can't render this file because it has a wrong number of fields in line 99.

View File

@ -0,0 +1,232 @@
alter local 'compareAsStrInGreatest' '1';
select GREATEST(1,2,3,4,5,6,7,8,9,10);
select GREATEST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select GREATEST(1,'2',3.3,4.4,5);
select GREATEST(121,'18');
select GREATEST(18888,'18');
select GREATEST(1,2,3,4,5,'5.1');
select GREATEST('1','2','3','4',5);
select GREATEST('1','2','3','4','5');
select GREATEST(1,2,3,4,5,6,7,'a','b','一','二','三');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select GREATEST(cast(100 as tinyint), cast(101 as tinyint));
select GREATEST(cast(100 as tinyint), cast(101 as smallint));
select GREATEST(cast(100 as tinyint), cast(101 as int));
select GREATEST(cast(100 as tinyint), cast(101 as bigint));
select GREATEST(cast(100 as tinyint), cast(101 as float));
select GREATEST(cast(100 as tinyint), cast(101 as double));
select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as nchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as tinyint));
select GREATEST(cast(101 as tinyint), cast(100 as smallint));
select GREATEST(cast(101 as tinyint), cast(100 as int));
select GREATEST(cast(101 as tinyint), cast(100 as bigint));
select GREATEST(cast(101 as tinyint), cast(100 as float));
select GREATEST(cast(101 as tinyint), cast(100 as double));
select GREATEST(cast(101 as tinyint), cast(100 as varchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as nchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as smallint));
select GREATEST(cast(1000 as smallint), cast(1001 as int));
select GREATEST(cast(1000 as smallint), cast(1001 as bigint));
select GREATEST(cast(1000 as smallint), cast(1001 as float));
select GREATEST(cast(1000 as smallint), cast(1001 as double));
select GREATEST(cast(1000 as smallint), cast(1001 as varchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as nchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as smallint));
select GREATEST(cast(1001 as smallint), cast(1000 as int));
select GREATEST(cast(1001 as smallint), cast(1000 as bigint));
select GREATEST(cast(1001 as smallint), cast(1000 as float));
select GREATEST(cast(1001 as smallint), cast(1000 as double));
select GREATEST(cast(1001 as smallint), cast(1000 as varchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as nchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as int));
select GREATEST(cast(1000000 as int), cast(1000001 as bigint));
select GREATEST(cast(1000000 as int), cast(1000001 as float));
select GREATEST(cast(1000000 as int), cast(1000001 as double));
select GREATEST(cast(1000000 as int), cast(1000001 as varchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as nchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as int));
select GREATEST(cast(1000001 as int), cast(1000000 as bigint));
select GREATEST(cast(1000001 as int), cast(1000000 as float));
select GREATEST(cast(1000001 as int), cast(1000000 as double));
select GREATEST(cast(1000001 as int), cast(1000000 as varchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as nchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as float));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as double));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as float));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as double));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select GREATEST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));
select GREATEST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select GREATEST('a','b','c','d','e','f','g','h','1231','15155');
select GREATEST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select GREATEST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(221, voltage) from ts_4893.meters order by ts limit 10;
select GREATEST(5, id) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('23', 3443434343434343);
select GREATEST(co, 3443434343434343) from ts_4893.n1;
select GREATEST('23', 3443434343434343) from ts_4893.n1;
select GREATEST('23', 1443434343434343) from ts_4893.n1;
select GREATEST(current, voltage) from ts_4893.n1;
select GREATEST(current, voltage, '15') from ts_4893.n1;
alter local 'compareAsStrInGreatest' '0';
select GREATEST(1,'2',3.3,4.4,5);
select GREATEST(1,2,3,4,5,'5.1');
select GREATEST(121,'18');
select GREATEST('1','2','3','4','5');
select GREATEST(1,2,3,4,5,6,7,'a','b','一','二','三');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select GREATEST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select GREATEST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select GREATEST(cast(100 as tinyint), cast(101 as tinyint));
select GREATEST(cast(100 as tinyint), cast(101 as smallint));
select GREATEST(cast(100 as tinyint), cast(101 as int));
select GREATEST(cast(100 as tinyint), cast(101 as bigint));
select GREATEST(cast(100 as tinyint), cast(101 as float));
select GREATEST(cast(100 as tinyint), cast(101 as double));
select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as nchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as tinyint));
select GREATEST(cast(101 as tinyint), cast(100 as smallint));
select GREATEST(cast(101 as tinyint), cast(100 as int));
select GREATEST(cast(101 as tinyint), cast(100 as bigint));
select GREATEST(cast(101 as tinyint), cast(100 as float));
select GREATEST(cast(101 as tinyint), cast(100 as double));
select GREATEST(cast(101 as tinyint), cast(100 as varchar(20)));
select GREATEST(cast(101 as tinyint), cast(100 as nchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as smallint));
select GREATEST(cast(1000 as smallint), cast(1001 as int));
select GREATEST(cast(1000 as smallint), cast(1001 as bigint));
select GREATEST(cast(1000 as smallint), cast(1001 as float));
select GREATEST(cast(1000 as smallint), cast(1001 as double));
select GREATEST(cast(1000 as smallint), cast(1001 as varchar(20)));
select GREATEST(cast(1000 as smallint), cast(1001 as nchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as smallint));
select GREATEST(cast(1001 as smallint), cast(1000 as int));
select GREATEST(cast(1001 as smallint), cast(1000 as bigint));
select GREATEST(cast(1001 as smallint), cast(1000 as float));
select GREATEST(cast(1001 as smallint), cast(1000 as double));
select GREATEST(cast(1001 as smallint), cast(1000 as varchar(20)));
select GREATEST(cast(1001 as smallint), cast(1000 as nchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as int));
select GREATEST(cast(1000000 as int), cast(1000001 as bigint));
select GREATEST(cast(1000000 as int), cast(1000001 as float));
select GREATEST(cast(1000000 as int), cast(1000001 as double));
select GREATEST(cast(1000000 as int), cast(1000001 as varchar(20)));
select GREATEST(cast(1000000 as int), cast(1000001 as nchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as int));
select GREATEST(cast(1000001 as int), cast(1000000 as bigint));
select GREATEST(cast(1000001 as int), cast(1000000 as float));
select GREATEST(cast(1000001 as int), cast(1000000 as double));
select GREATEST(cast(1000001 as int), cast(1000000 as varchar(20)));
select GREATEST(cast(1000001 as int), cast(1000000 as nchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as float));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as double));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select GREATEST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as float));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as double));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select GREATEST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select GREATEST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select GREATEST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select GREATEST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select GREATEST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select GREATEST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select GREATEST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select GREATEST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select GREATEST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));
select GREATEST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));
select GREATEST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select GREATEST('a','b','c','d','e','f','g','h','1231','15155');
select GREATEST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select GREATEST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST(221, voltage) from ts_4893.meters order by ts limit 10;
select GREATEST(5, id) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select GREATEST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select GREATEST('23', 3443434343434343);
select GREATEST(co, 3443434343434343) from ts_4893.n1;
select GREATEST('23', 1443434343434343) from ts_4893.n1;
select GREATEST('23', 3443434343434343) from ts_4893.n1
select GREATEST(current, voltage) from ts_4893.n1;
select GREATEST(current, voltage, '15') from ts_4893.n1;

View File

@ -0,0 +1,228 @@
alter local 'compareAsStrInGreatest' '1';
select LEAST(1,2,3,4,5,6,7,8,9,10);
select LEAST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select LEAST(1,'2',3.3,4.4,5);
select LEAST(1,2,3,4,5,'5.1');
select LEAST('1','2','3','4',5);
select LEAST('1','2','3','4','5');
select LEAST(1,2,3,4,5,6,7,'a','b','一','二','三');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select LEAST(cast(100 as tinyint), cast(101 as tinyint));
select LEAST(cast(100 as tinyint), cast(101 as smallint));
select LEAST(cast(100 as tinyint), cast(101 as int));
select LEAST(cast(100 as tinyint), cast(101 as bigint));
select LEAST(cast(100 as tinyint), cast(101 as float));
select LEAST(cast(100 as tinyint), cast(101 as double));
select LEAST(cast(100 as tinyint), cast(101 as varchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as nchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as tinyint));
select LEAST(cast(101 as tinyint), cast(100 as smallint));
select LEAST(cast(101 as tinyint), cast(100 as int));
select LEAST(cast(101 as tinyint), cast(100 as bigint));
select LEAST(cast(101 as tinyint), cast(100 as float));
select LEAST(cast(101 as tinyint), cast(100 as double));
select LEAST(cast(101 as tinyint), cast(100 as varchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as nchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as smallint));
select LEAST(cast(1000 as smallint), cast(1001 as int));
select LEAST(cast(1000 as smallint), cast(1001 as bigint));
select LEAST(cast(1000 as smallint), cast(1001 as float));
select LEAST(cast(1000 as smallint), cast(1001 as double));
select LEAST(cast(1000 as smallint), cast(1001 as varchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as nchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as smallint));
select LEAST(cast(1001 as smallint), cast(1000 as int));
select LEAST(cast(1001 as smallint), cast(1000 as bigint));
select LEAST(cast(1001 as smallint), cast(1000 as float));
select LEAST(cast(1001 as smallint), cast(1000 as double));
select LEAST(cast(1001 as smallint), cast(1000 as varchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as nchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as int));
select LEAST(cast(1000000 as int), cast(1000001 as bigint));
select LEAST(cast(1000000 as int), cast(1000001 as float));
select LEAST(cast(1000000 as int), cast(1000001 as double));
select LEAST(cast(1000000 as int), cast(1000001 as varchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as nchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as int));
select LEAST(cast(1000001 as int), cast(1000000 as bigint));
select LEAST(cast(1000001 as int), cast(1000000 as float));
select LEAST(cast(1000001 as int), cast(1000000 as double));
select LEAST(cast(1000001 as int), cast(1000000 as varchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as nchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as float));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as double));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as float));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as double));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select LEAST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select LEAST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select LEAST('a','b','c','d','e','f','g','h','1231','15155');
select LEAST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select LEAST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(221, voltage) from ts_4893.meters order by ts limit 10;
select LEAST(5, id) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('23', 3443434343434343);
select LEAST(co, 3443434343434343) from ts_4893.n1;
select LEAST('23', 3443434343434343) from ts_4893.n1;
select LEAST('23', 1443434343434343) from ts_4893.n1;
select LEAST(current, voltage) from ts_4893.n1;
select LEAST(current, voltage, '15') from ts_4893.n1;
alter local 'compareAsStrInGreatest' '0';
select LEAST(1,2,3,4,5,6,7,8,9,10);
select LEAST(1,1.1,2.23,3.4444,5.66666666,6.21241241,7.999999999999);
select LEAST(1,'2',3.3,4.4,5);
select LEAST(1,2,3,4,5,'5.1');
select LEAST('1','2','3','4',5);
select LEAST('1','2','3','4','5');
select LEAST(1,2,3,4,5,6,7,'a','b','一','二','三');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213');
select LEAST(1,2,3,4,5,6,7,'a','b','c','1','2','1231213','1231213.123123');
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)));
select LEAST(cast(0 as bool), cast(1 as tinyint), cast(2 as smallint), cast(3 as int), cast(4 as bigint), cast(5 as float), cast(6 as double), cast(8 as varchar(20)), cast(9 as nchar(20)), cast(0 as bool), cast(1 as tinyint unsigned), cast(2 as smallint unsigned), cast(3 as int unsigned), cast(4 as bigint unsigned), cast(5 as float), cast(6 as double));
select LEAST(cast(100 as tinyint), cast(101 as tinyint));
select LEAST(cast(100 as tinyint), cast(101 as smallint));
select LEAST(cast(100 as tinyint), cast(101 as int));
select LEAST(cast(100 as tinyint), cast(101 as bigint));
select LEAST(cast(100 as tinyint), cast(101 as float));
select LEAST(cast(100 as tinyint), cast(101 as double));
select LEAST(cast(100 as tinyint), cast(101 as varchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as nchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as tinyint));
select LEAST(cast(101 as tinyint), cast(100 as smallint));
select LEAST(cast(101 as tinyint), cast(100 as int));
select LEAST(cast(101 as tinyint), cast(100 as bigint));
select LEAST(cast(101 as tinyint), cast(100 as float));
select LEAST(cast(101 as tinyint), cast(100 as double));
select LEAST(cast(101 as tinyint), cast(100 as varchar(20)));
select LEAST(cast(101 as tinyint), cast(100 as nchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as smallint));
select LEAST(cast(1000 as smallint), cast(1001 as int));
select LEAST(cast(1000 as smallint), cast(1001 as bigint));
select LEAST(cast(1000 as smallint), cast(1001 as float));
select LEAST(cast(1000 as smallint), cast(1001 as double));
select LEAST(cast(1000 as smallint), cast(1001 as varchar(20)));
select LEAST(cast(1000 as smallint), cast(1001 as nchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as smallint));
select LEAST(cast(1001 as smallint), cast(1000 as int));
select LEAST(cast(1001 as smallint), cast(1000 as bigint));
select LEAST(cast(1001 as smallint), cast(1000 as float));
select LEAST(cast(1001 as smallint), cast(1000 as double));
select LEAST(cast(1001 as smallint), cast(1000 as varchar(20)));
select LEAST(cast(1001 as smallint), cast(1000 as nchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as int));
select LEAST(cast(1000000 as int), cast(1000001 as bigint));
select LEAST(cast(1000000 as int), cast(1000001 as float));
select LEAST(cast(1000000 as int), cast(1000001 as double));
select LEAST(cast(1000000 as int), cast(1000001 as varchar(20)));
select LEAST(cast(1000000 as int), cast(1000001 as nchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as int));
select LEAST(cast(1000001 as int), cast(1000000 as bigint));
select LEAST(cast(1000001 as int), cast(1000000 as float));
select LEAST(cast(1000001 as int), cast(1000000 as double));
select LEAST(cast(1000001 as int), cast(1000000 as varchar(20)));
select LEAST(cast(1000001 as int), cast(1000000 as nchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as bigint));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as float));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as double));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as varchar(20)));
select LEAST(cast(1000000000 as bigint), cast(1000000001 as nchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as bigint));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as float));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as double));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as varchar(20)));
select LEAST(cast(1000000001 as bigint), cast(1000000000 as nchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as float));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as float), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as float));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as float), cast(100000.1111111 as nchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as double));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as timestamp));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as varchar(20)));
select LEAST(cast(100000.1111111 as double), cast(100001.1111111 as nchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as double));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as timestamp));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as varchar(20)));
select LEAST(cast(100001.1111111 as double), cast(100000.1111111 as nchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as varchar(20)));
select LEAST(cast('中文测试' as varchar(20)), cast('中文测试一' as nchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as varchar(20)));
select LEAST(cast('中文测试一' as varchar(20)), cast('中文测试' as nchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as varchar(20)));
select LEAST(cast('abc123abc' as varchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as varchar(20)));
select LEAST(cast('abc124abc' as varchar(20)), cast('abc123abc' as nchar(20)));
select LEAST(cast('abc123abc' as nchar(20)), cast('abc124abc' as nchar(20)));
select LEAST(cast(100 as tinyint), cast(101 as float), cast(102 as varchar(20)));
select LEAST(cast(100 as varchar(20)), cast(101 as float), cast(102 as tinyint));
select LEAST('a','b','c','d','e','f','g','h','1231','15155');
select LEAST(current, voltage, phase, id, nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(current, voltage, phase, id) from ts_4893.meters order by ts limit 10;
select LEAST(nch1, nch2, var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST(221, voltage) from ts_4893.meters order by ts limit 10;
select LEAST(5, id) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('r', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1) from ts_4893.meters order by ts limit 10;
select LEAST('r', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', nch1, nch2) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1) from ts_4893.meters order by ts limit 10;
select LEAST('二中文测试', var1, var2) from ts_4893.meters order by ts limit 10;
select LEAST('23', 3443434343434343);
select LEAST(co, 3443434343434343) from ts_4893.n1;
select LEAST('23', 3443434343434343) from ts_4893.n1;
select LEAST('23', 1443434343434343) from ts_4893.n1;
select LEAST(current, voltage) from ts_4893.n1;
select LEAST(current, voltage, '15') from ts_4893.n1;

View File

@ -40,37 +40,10 @@ class TDTestCase(TBase):
"`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)
def test_normal_query(self, testCase):
# read sql from .sql file and execute
tdLog.info(f"test normal query.")
sqlFile = etool.curFile(__file__, f"in/{testCase}.in")
ansFile = etool.curFile(__file__, f"ans/{testCase}.csv")
with open(sqlFile, 'r') as sql_file:
sql_statement = ''
tdSql.csvLine = 0
for line in sql_file:
if not line.strip() or line.strip().startswith('--'):
continue
sql_statement += line.strip()
if sql_statement.endswith(';'):
sql_statement = sql_statement.rstrip(';')
tdSql.checkDataCsvByLine(sql_statement, ansFile)
sql_statement = ''
err_file_path = etool.curFile(__file__, f"in/{testCase}.err")
if not os.path.isfile(err_file_path):
return None
with open(err_file_path, 'r') as err_file:
err_statement = ''
for line in err_file:
if not line.strip() or line.strip().startswith('--'):
continue
err_statement += line.strip()
if err_statement.endswith(';'):
tdSql.error(err_statement)
err_statement = ''
tdSql.execute("CREATE TABLE `n1` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, co NCHAR(10))")
tdSql.execute("insert into n1 values(now, 1, null, '23')")
tdSql.execute("insert into n1 values(now, null, 3, '23')")
tdSql.execute("insert into n1 values(now, 5, 3, '23')")
def test_normal_query_new(self, testCase):
# read sql from .sql file and execute
@ -310,6 +283,223 @@ class TDTestCase(TBase):
tdSql.error("select * from (select to_iso8601(ts, timezone()), timezone() from ts_4893.meters \
order by ts desc) limit 1000;", expectErrInfo="Invalid parameter data type : to_iso8601") # TS-5340
def test_greatest(self):
self.test_normal_query_new("greatest")
tdSql.execute("alter local 'compareAsStrInGreatest' '1';")
tdSql.query("select GREATEST(NULL, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(1, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(id, NULL, 1) from ts_4893.meters order by ts limit 10;")
tdSql.checkRows(10)
tdSql.checkData(0, 0, None)
tdSql.query("select GREATEST(cast(100 as tinyint), cast(101 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.101")
tdSql.query("select GREATEST(cast(101 as tinyint), cast(100 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.101")
tdSql.query("select GREATEST(cast(1000 as smallint), cast(1001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.001")
tdSql.query("select GREATEST(cast(1001 as smallint), cast(1000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.001")
tdSql.query("select GREATEST(cast(1000000 as int), cast(1000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.001")
tdSql.query("select GREATEST(cast(1000001 as int), cast(1000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.001")
tdSql.query("select GREATEST(cast(1000000000 as bigint), cast(1000000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.001")
tdSql.query("select GREATEST(cast(1000000001 as bigint), cast(1000000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.001")
tdSql.query("select GREATEST(cast(1725506504000 as timestamp), cast(1725506510000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:50")
tdSql.query("select GREATEST(cast(1725506510000 as timestamp), cast(1725506504000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:50")
tdSql.query("select GREATEST(cast(100 as tinyint), cast(101 as varchar(20)), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "102.000000")
tdSql.query("select GREATEST(cast(100 as varchar(20)), cast(101 as tinyint), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "102.000000")
tdSql.query("select GREATEST(now, 1);")
tdSql.query("select GREATEST(now, 1.0);")
tdSql.query("select GREATEST(now, '1');")
tdSql.error("select GREATEST(1)")
tdSql.error("select GREATEST(cast('a' as varbinary), cast('b' as varbinary), 'c', 'd');")
tdSql.error("select GREATEST(6, cast('f' as varbinary), cast('b' as varbinary), 'c', 'd');")
def test_least(self):
self.test_normal_query_new("least")
tdSql.execute("alter local 'compareAsStrInGreatest' '1';")
tdSql.query("select LEAST(NULL, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(1, NULL, NULL, NULL);")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(id, NULL, 1) from ts_4893.meters order by ts limit 10;")
tdSql.checkRows(10)
tdSql.checkData(0, 0, None)
tdSql.query("select LEAST(cast(100 as tinyint), cast(101 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.100")
tdSql.query("select LEAST(cast(101 as tinyint), cast(100 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.100")
tdSql.query("select LEAST(cast(1000 as smallint), cast(1001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.000")
tdSql.query("select LEAST(cast(1001 as smallint), cast(1000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:01.000")
tdSql.query("select LEAST(cast(1000000 as int), cast(1000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.000")
tdSql.query("select LEAST(cast(1000001 as int), cast(1000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-01 08:16:40.000")
tdSql.query("select LEAST(cast(1000000000 as bigint), cast(1000000001 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.000")
tdSql.query("select LEAST(cast(1000000001 as bigint), cast(1000000000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "1970-01-12 21:46:40.000")
tdSql.query("select LEAST(cast(1725506504000 as timestamp), cast(1725506510000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:44")
tdSql.query("select LEAST(cast(1725506510000 as timestamp), cast(1725506504000 as timestamp));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "2024-09-05 11:21:44")
tdSql.query("select LEAST(cast(100 as tinyint), cast(101 as varchar(20)), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100")
tdSql.query("select LEAST(cast(100 as varchar(20)), cast(101 as tinyint), cast(102 as float));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100")
tdSql.query("select LEAST(cast(100 as float), cast(101 as tinyint), cast(102 as varchar(20)));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100.000000")
tdSql.query("select LEAST(cast(100 as float), cast(101 as varchar(20)), cast(102 as tinyint));")
tdSql.checkRows(1)
tdSql.checkData(0, 0, "100.000000")
tdSql.query("select LEAST(now, 1);")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, "1970-01-01 08:00:00.001")
tdSql.query("select LEAST(now, 1.0);")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, 1)
tdSql.query("select LEAST(now, '1');")
tdSql.checkRows(1)
tdSql.checkCols(1)
tdSql.checkData(0, 0, "1")
tdSql.error("select LEAST(cast('a' as varbinary), cast('b' as varbinary), 'c', 'd');")
tdSql.error("select LEAST(cast('f' as varbinary), cast('b' as varbinary), 'c', 'd');")
def test_greatest_large_table(self):
tdLog.info("test greatest large table.")
ts = 1741341251000
create_table_sql = "CREATE TABLE `large_table` (`ts` TIMESTAMP"
for i in range(1, 1001):
if i % 5 == 1:
create_table_sql += f", `col{i}` INT"
elif i % 5 == 2:
create_table_sql += f", `col{i}` FLOAT"
elif i % 5 == 3:
create_table_sql += f", `col{i}` DOUBLE"
elif i % 5 == 4:
create_table_sql += f", `col{i}` VARCHAR(64)"
else:
create_table_sql += f", `col{i}` NCHAR(50)"
create_table_sql += ");"
tdSql.execute(create_table_sql)
for j in range(1000):
insert_sql = f"INSERT INTO `large_table` VALUES ({ts +j}"
for i in range(1, 1001):
if i % 5 == 1:
insert_sql += f", {j + i}"
elif i % 5 == 2:
insert_sql += f", {j + i}.1"
elif i % 5 == 3:
insert_sql += f", {j + i}.2"
elif i % 5 == 4:
insert_sql += f", '{j + i}'"
else:
insert_sql += f", '{j + i}'"
insert_sql += ");"
tdSql.execute(insert_sql)
greatest_query = "SELECT GREATEST("
for i in range(1, 1001):
greatest_query += f"`col{i}`"
if i < 1000:
greatest_query += ", "
greatest_query += ") FROM `large_table` LIMIT 1;"
tdLog.info(f"greatest_query: {greatest_query}")
tdSql.execute(greatest_query)
greatest_query = "SELECT "
for i in range(1, 1001):
greatest_query += f"`col{i}` > `col5`"
if i < 1000:
greatest_query += ", "
greatest_query += " FROM `large_table` LIMIT 1;"
tdLog.info(f"greatest_query: {greatest_query}")
tdSql.execute(greatest_query)
def run(self):
tdLog.debug(f"start to excute {__file__}")
@ -326,7 +516,10 @@ class TDTestCase(TBase):
self.test_degrees()
self.test_radians()
self.test_rand()
self.test_greatest()
self.test_least()
self.test_greatest_large_table()
# char function
self.test_char_length()
self.test_char()

View File

@ -13,6 +13,7 @@
import os
import json
import frame
import frame.eos
import frame.etool
from frame.log import *
from frame.cases import *
@ -109,7 +110,6 @@ class TDTestCase(TBase):
tdLog.info(f" vgroups real={tdSql.getData(0,0)} expect={vgroups}")
tdSql.checkData(0, 0, vgroups, True)
# bugs ts
def checkVGroups(self, benchmark):
# vgroups with command line set
@ -117,12 +117,19 @@ class TDTestCase(TBase):
# vgroups with json file
self.testBenchmarkJson(benchmark, "./tools/benchmark/basic/json/insertBasic.json", "", True)
def checkInsertManyStb(self):
# many stb
self.benchInsert("./tools/benchmark/basic/json/insertManyStb.json")
def run(self):
benchmark = etool.benchMarkFile()
benchmark = frame.etool.benchMarkFile()
# vgroups
self.checkVGroups(benchmark)
# check many stable
self.checkInsertManyStb()
def stop(self):
tdSql.close()

View File

@ -0,0 +1,151 @@
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"num_of_records_per_req": 3000,
"thread_count": 2,
"confirm_parameter_prompt": "no",
"databases": [
{
"dbinfo": {
"name": "test1",
"drop": "yes",
"precision": "us",
"vgroups": 1
},
"super_tables": [
{
"name": "meters1",
"child_table_exists": "no",
"childtable_count": 2,
"insert_rows": 1000,
"childtable_prefix": "da",
"insert_mode": "stmt",
"timestamp_step": 15,
"start_timestamp":1700000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
},
{
"name": "meters2",
"child_table_exists": "no",
"childtable_count": 3,
"insert_rows": 100,
"childtable_prefix": "db",
"insert_mode": "stmt",
"timestamp_step": 20,
"interlace_rows": 1,
"start_timestamp":1700000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
},
{
"name": "meters3",
"child_table_exists": "no",
"childtable_count": 5,
"insert_rows": 100,
"childtable_prefix": "dc",
"insert_mode": "stmt2",
"timestamp_step": 20,
"interlace_rows": 1,
"start_timestamp":1700000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
},
{
"name": "meters4",
"child_table_exists": "no",
"childtable_count": 2,
"insert_rows": 70,
"childtable_prefix": "dd",
"insert_mode": "stmt2",
"timestamp_step": 50,
"interlace_rows": 0,
"start_timestamp":1700000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
}
]
},
{
"dbinfo": {
"name": "test2",
"drop": "yes",
"precision": "ns",
"vgroups": 2
},
"super_tables": [
{
"name": "meters1",
"child_table_exists": "no",
"childtable_count": 3,
"insert_rows": 120,
"childtable_prefix": "de",
"insert_mode": "taosc",
"timestamp_step": 15,
"start_timestamp":1700000000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
},
{
"name": "meters2",
"child_table_exists": "no",
"childtable_count": 2,
"insert_rows": 200,
"childtable_prefix": "df",
"insert_mode": "taosc",
"timestamp_step": 2,
"interlace_rows": 4,
"start_timestamp":1700000000000000000,
"columns": [
{ "type": "double", "name": "dc", "max": 10, "min": 0 },
{ "type": "tinyint", "name": "ti", "max": 100, "min": -100 },
{ "type": "binary", "name": "bin", "len": 4}
],
"tags": [
{ "type": "usmallint", "name": "tusi", "max": 100, "min": 0 },
{ "type": "uint", "name": "tui", "max": 1000, "min": 0 }
]
}
]
}
]
}

View File

@ -22,6 +22,8 @@ from util.cluster import *
# should be used by -N option
class TDTestCase:
updatecfgDict = {'checkpointInterval': 60 ,
'vdebugflag':143,
'ddebugflag':143
}
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)

View File

@ -668,28 +668,22 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
printf("%*" PRIu64, width, *((uint64_t *)val));
break;
case TSDB_DATA_TYPE_FLOAT:
width = width >= LENGTH ? LENGTH - 1 : width;
if (tsEnableScience) {
printf("%*.7e", width, GET_FLOAT_VAL(val));
} else {
n = snprintf(buf, LENGTH, "%*.*g", width, FLT_DIG, GET_FLOAT_VAL(val));
if (n > SHELL_FLOAT_WIDTH) {
printf("%*.7e", width, GET_FLOAT_VAL(val));
} else {
printf("%s", buf);
}
snprintf(buf, LENGTH, "%*.*g", width, FLT_DIG, GET_FLOAT_VAL(val));
printf("%s", buf);
}
break;
case TSDB_DATA_TYPE_DOUBLE:
width = width >= LENGTH ? LENGTH - 1 : width;
if (tsEnableScience) {
snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val));
printf("%s", buf);
} else {
n = snprintf(buf, LENGTH, "%*.*g", width, DBL_DIG, GET_DOUBLE_VAL(val));
if (n > SHELL_DOUBLE_WIDTH) {
printf("%*.15e", width, GET_DOUBLE_VAL(val));
} else {
printf("%*s", width, buf);
}
snprintf(buf, LENGTH, "%*.*g", width, DBL_DIG, GET_DOUBLE_VAL(val));
printf("%*s", width, buf);
}
break;
case TSDB_DATA_TYPE_VARBINARY: {

View File

@ -1928,7 +1928,7 @@ static void *syncWriteInterlace(void *sarg) {
bindv = createBindV(nBatchTable, tagCnt, stbInfo->cols->size + 1);
}
bool oldInitStmt = stbInfo->autoTblCreating || database->superTbls->size > 1;
bool oldInitStmt = stbInfo->autoTblCreating;
// not auto create table call once
if(stbInfo->iface == STMT_IFACE && !oldInitStmt) {
debugPrint("call prepareStmt for stable:%s\n", stbInfo->stbName);
@ -2900,7 +2900,7 @@ void *syncWriteProgressive(void *sarg) {
tagData = benchCalloc(TAG_BATCH_COUNT, stbInfo->lenOfTags, false);
}
bool oldInitStmt = stbInfo->autoTblCreating || database->superTbls->size > 1;
bool oldInitStmt = stbInfo->autoTblCreating;
// stmt. not auto table create call on stmt
if (stbInfo->iface == STMT_IFACE && !oldInitStmt) {
if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w)) {
@ -3909,11 +3909,8 @@ int32_t initInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr
if (NULL == pThreadInfo->conn) {
goto END;
}
// single always true for benchmark
bool single = true;
if (database->superTbls->size > 1) {
single = false;
}
if (stbInfo->iface == STMT2_IFACE) {
// stmt2 init
if (pThreadInfo->conn->stmt2)

View File

@ -0,0 +1,54 @@
absl-py==2.1.0
blinker==1.8.2
click==8.1.7
contourpy==1.3.0
cycler==0.12.1
Cython==3.0.11
filelock==3.13.1
Flask==3.0.3
fonttools==4.54.1
fsspec==2024.2.0
h5py==3.12.1
itsdangerous==2.2.0
Jinja2==3.1.4
joblib==1.4.2
keras==3.6.0
kiwisolver==1.4.7
markdown-it-py==3.0.0
MarkupSafe==3.0.1
matplotlib==3.9.2
mdurl==0.1.2
ml_dtypes==0.5.0
mpmath==1.3.0
namex==0.0.8
networkx==3.2.1
numpy==1.26.4
optree==0.13.0
outlier-utils==0.0.5
packaging==24.1
pandas==1.5.0
patsy==0.5.6
pillow==10.4.0
pmdarima==2.0.4
pyculiarity==0.0.7
Pygments==2.18.0
pyparsing==3.1.4
python-dateutil==2.9.0.post0
pytz==2024.2
rich==13.9.2
rstl==0.1.3
scikit-learn==1.5.2
scipy==1.14.1
six==1.16.0
statsmodels==0.14.4
sympy==1.12
threadpoolctl==3.5.0
--find-links https://download.pytorch.org/whl/torch/
torch==2.4.1+cpu
typing_extensions==4.9.0
urllib3==2.2.3
uWSGI==2.0.27
Werkzeug==3.0.4
Flask-Testing==0.8.1
xlsxwriter==3.2.1
taospy==2.7.16

View File

@ -8,8 +8,8 @@ import numpy as np
import pandas as pd
from taosanalytics.conf import app_logger, conf
from taosanalytics.misc.train_model import create_sequences
from taosanalytics.service import AbstractAnomalyDetectionService
from taosanalytics.util import create_sequences
class _AutoEncoderDetectionService(AbstractAnomalyDetectionService):

View File

@ -160,4 +160,4 @@ def handle_forecast_req():
if __name__ == '__main__':
app.run()
app.run(port=6090)