Merge remote-tracking branch 'origin/main' into enh/useSafySysFunc

This commit is contained in:
yihaoDeng 2024-12-06 10:36:09 +08:00
commit 66771b41a0
32 changed files with 652 additions and 490 deletions

View File

@ -163,7 +163,7 @@ TDengine 对于修改数据提供两种处理方式,由 IGNORE UPDATE 选项
### 写入已存在的超级表
当流计算结果需要写入已存在的超级表时,应确保 stb_name 列与 subquery 输出结果之间的对应关系正确。如果 stb_name 列与 subquery 输出结果的位置、数量完全匹配,那么不需要显式指定对应关系;如果数据类型不匹配,系统会自动将 subquery 输出结果的类型转换为对应的 stb_name 列的类型。
当流计算结果需要写入已存在的超级表时,应确保 stb_name 列与 subquery 输出结果之间的对应关系正确。如果 stb_name 列与 subquery 输出结果的位置、数量完全匹配,那么不需要显式指定对应关系;如果数据类型不匹配,系统会自动将 subquery 输出结果的类型转换为对应的 stb_name 列的类型。创建流计算时不能指定 stb_name 的列和 TAG 的数据类型,否则会报错。
对于已经存在的超级表,系统会检查列的 schema 信息,确保它们与 subquery 输出结果相匹配。以下是一些关键点。
1. 检查列的 schema 信息是否匹配,对于不匹配的,则自动进行类型转换,当前只有数据长度大于 4096 bytes 时才报错,其余场景都能进行类型转换。

View File

@ -37,7 +37,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速
关键不同点在于:
1. 使用 原生连接,需要保证客户端的驱动程序 taosc 和服务端的 TDengine 版本配套
1. 使用 原生连接,需要保证客户端的驱动程序 taosc 和服务端的 TDengine 版本保持一致
2. 使用 REST 连接,用户无需安装客户端驱动程序 taosc具有跨平台易用的优势但是无法体验数据订阅和二进制数据类型等功能。另外与 原生连接 和 WebSocket 连接相比REST连接的性能最低。REST 接口是无状态的。在使用 REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。
3. 使用 WebSocket 连接,用户也无需安装客户端驱动程序 taosc。
4. 连接云服务实例,必须使用 REST 连接 或 WebSocket 连接。

View File

@ -213,7 +213,7 @@ TDengine 对于修改数据提供两种处理方式,由 IGNORE UPDATE 选项
```sql
[field1_name,...]
```
在本页文档顶部的 [field1_name,...] 是用来指定 stb_name 的列与 subquery 输出结果的对应关系的。如果 stb_name 的列与 subquery 输出结果的位置、数量全部匹配,则不需要显示指定对应关系。如果 stb_name 的列与 subquery 输出结果的数据类型不匹配,会把 subquery 输出结果的类型转换成对应的 stb_name 的列的类型。
在本页文档顶部的 [field1_name,...] 是用来指定 stb_name 的列与 subquery 输出结果的对应关系的。如果 stb_name 的列与 subquery 输出结果的位置、数量全部匹配,则不需要显示指定对应关系。如果 stb_name 的列与 subquery 输出结果的数据类型不匹配,会把 subquery 输出结果的类型转换成对应的 stb_name 的列的类型。创建流计算时不能指定 stb_name 的列和 TAG 的数据类型,否则会报错。
对于已经存在的超级表检查列的schema信息
1. 检查列的 schema 信息是否匹配,对于不匹配的,则自动进行类型转换,当前只有数据长度大于 4096byte 时才报错,其余场景都能进行类型转换。

View File

@ -795,7 +795,7 @@ static int32_t mndGetStreamNameFromSmaName(char *streamName, char *smaName) {
if (TSDB_CODE_SUCCESS != code) {
return code;
}
sprintf(streamName, "%d.%s", n.acctId, n.tname);
snprintf(streamName, TSDB_TABLE_FNAME_LEN,"%d.%s", n.acctId, n.tname);
return TSDB_CODE_SUCCESS;
}
@ -1219,7 +1219,7 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
memcpy(rsp->dbFName, pSma->db, sizeof(pSma->db));
memcpy(rsp->tblFName, pSma->stb, sizeof(pSma->stb));
strcpy(rsp->indexType, TSDB_INDEX_TYPE_SMA);
tstrncpy(rsp->indexType, TSDB_INDEX_TYPE_SMA, TSDB_INDEX_TYPE_LEN);
SNodeList *pList = NULL;
int32_t extOffset = 0;
@ -1252,8 +1252,8 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool
return TSDB_CODE_SUCCESS;
}
strcpy(rsp->dbFName, pStb->db);
strcpy(rsp->tbName, pStb->name + strlen(pStb->db) + 1);
tstrncpy(rsp->dbFName, pStb->db, TSDB_DB_FNAME_LEN);
tstrncpy(rsp->tbName, pStb->name + strlen(pStb->db) + 1, TSDB_TABLE_NAME_LEN);
rsp->suid = pStb->uid;
rsp->version = pStb->smaVer;
mndReleaseStb(pMnode, pStb);
@ -1629,7 +1629,7 @@ static int32_t mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
f.bytes = pExprNode->resType.bytes;
f.type = pExprNode->resType.type;
f.flags = COL_SMA_ON;
strcpy(f.name, pExprNode->userAlias);
tstrncpy(f.name, pExprNode->userAlias, TSDB_COL_NAME_LEN);
if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pCols, &f)) {
code = terrno;
break;
@ -1836,8 +1836,8 @@ static int32_t mndTSMAGenerateOutputName(const char *tsmaName, char *streamName,
if (TSDB_CODE_SUCCESS != code) {
return code;
}
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname);
snprintf(targetStbName, TSDB_TABLE_FNAME_LEN, "%s" TSMA_RES_STB_POSTFIX, tsmaName);
snprintf(streamName, TSDB_TABLE_FNAME_LEN, "%d.%s", smaName.acctId, smaName.tname);
snprintf(targetStbName, TSDB_TABLE_FNAME_LEN, "%s"TSMA_RES_STB_POSTFIX, tsmaName);
return TSDB_CODE_SUCCESS;
}
@ -2487,7 +2487,7 @@ static int32_t mndGetSomeTsmas(SMnode *pMnode, STableTSMAInfoRsp *pRsp, tsmaFilt
mndReleaseStb(pMnode, pStb);
TAOS_RETURN(code);
}
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname);
snprintf(streamName, TSDB_TABLE_FNAME_LEN, "%d.%s", smaName.acctId, smaName.tname);
pStream = NULL;
code = mndAcquireStream(pMnode, streamName, &pStream);

View File

@ -987,7 +987,14 @@ _end:
}
void resetStreamFillSup(SStreamFillSupporter* pFillSup) {
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
SSHashObj* pNewMap = tSimpleHashInit(16, hashFn);
if (pNewMap != NULL) {
tSimpleHashCleanup(pFillSup->pResMap);
pFillSup->pResMap = pNewMap;
} else {
tSimpleHashClear(pFillSup->pResMap);
}
pFillSup->hasDelete = false;
}
void resetStreamFillInfo(SStreamFillOperatorInfo* pInfo) {
@ -1406,6 +1413,7 @@ static int32_t doStreamForceFillNext(SOperatorInfo* pOperator, SSDataBlock** ppR
}
pInfo->stateStore.streamStateClearExpiredState(pInfo->pState);
resetStreamFillInfo(pInfo);
setStreamOperatorCompleted(pOperator);
(*ppRes) = NULL;
goto _end;
@ -1477,6 +1485,7 @@ static int32_t doStreamForceFillNext(SOperatorInfo* pOperator, SSDataBlock** ppR
if ((*ppRes) == NULL) {
pInfo->stateStore.streamStateClearExpiredState(pInfo->pState);
resetStreamFillInfo(pInfo);
setStreamOperatorCompleted(pOperator);
}

View File

@ -120,6 +120,36 @@ void initIntervalSlicePoint(SStreamAggSupporter* pAggSup, STimeWindow* pTWin, in
pPoint->pLastRow = POINTER_SHIFT(pPoint->pFinished, sizeof(bool));
}
int32_t getIntervalSlicePrevStateBuf(SStreamAggSupporter* pAggSup, SInterval* pInterval, SWinKey* pCurKey,
SInervalSlicePoint* pPrevPoint) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SWinKey prevKey = {.groupId = pCurKey->groupId};
SET_WIN_KEY_INVALID(prevKey.ts);
int32_t prevVLen = 0;
int32_t prevWinCode = TSDB_CODE_SUCCESS;
code = pAggSup->stateStore.streamStateGetPrev(pAggSup->pState, pCurKey, &prevKey, (void**)&pPrevPoint->pResPos,
&prevVLen, &prevWinCode);
QUERY_CHECK_CODE(code, lino, _end);
if (prevWinCode == TSDB_CODE_SUCCESS) {
STimeWindow prevSTW = {.skey = prevKey.ts};
prevSTW.ekey = taosTimeGetIntervalEnd(prevSTW.skey, pInterval);
initIntervalSlicePoint(pAggSup, &prevSTW, pCurKey->groupId, pPrevPoint);
qDebug("===stream=== set stream twa prev point buf.ts:%" PRId64 ", groupId:%" PRIu64 ", res:%d",
pPrevPoint->winKey.win.skey, pPrevPoint->winKey.groupId, prevWinCode);
} else {
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.skey);
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.ekey);
}
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
return code;
}
static int32_t getIntervalSliceCurStateBuf(SStreamAggSupporter* pAggSup, SInterval* pInterval, bool needPrev, STimeWindow* pTWin, int64_t groupId,
SInervalSlicePoint* pCurPoint, SInervalSlicePoint* pPrevPoint, int32_t* pWinCode) {
int32_t code = TSDB_CODE_SUCCESS;
@ -136,24 +166,8 @@ static int32_t getIntervalSliceCurStateBuf(SStreamAggSupporter* pAggSup, SInterv
initIntervalSlicePoint(pAggSup, pTWin, groupId, pCurPoint);
if (needPrev) {
SWinKey prevKey = {.groupId = groupId};
SET_WIN_KEY_INVALID(prevKey.ts);
int32_t prevVLen = 0;
int32_t prevWinCode = TSDB_CODE_SUCCESS;
code = pAggSup->stateStore.streamStateGetPrev(pAggSup->pState, &curKey, &prevKey, (void**)&pPrevPoint->pResPos,
&prevVLen, &prevWinCode);
code = getIntervalSlicePrevStateBuf(pAggSup, pInterval, &curKey, pPrevPoint);
QUERY_CHECK_CODE(code, lino, _end);
if (prevWinCode == TSDB_CODE_SUCCESS) {
STimeWindow prevSTW = {.skey = prevKey.ts};
prevSTW.ekey = taosTimeGetIntervalEnd(prevSTW.skey, pInterval);
initIntervalSlicePoint(pAggSup, &prevSTW, groupId, pPrevPoint);
qDebug("===stream=== set stream twa prev point buf.ts:%" PRId64 ", groupId:%" PRIu64 ", res:%d", pPrevPoint->winKey.win.skey,
pPrevPoint->winKey.groupId, prevWinCode);
} else {
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.skey);
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.ekey);
}
}
_end:
@ -265,13 +279,15 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
STimeWindow curWin =
getActiveTimeWindow(NULL, pResultRowInfo, curTs, &pInfo->interval, TSDB_ORDER_ASC);
while (1) {
if (curTs > pInfo->endTs) {
break;
}
int32_t winCode = TSDB_CODE_SUCCESS;
if (curTs <= pInfo->endTs) {
code = getIntervalSliceCurStateBuf(&pInfo->streamAggSup, &pInfo->interval, pInfo->hasInterpoFunc, &curWin, groupId, &curPoint, &prevPoint, &winCode);
QUERY_CHECK_CODE(code, lino, _end);
} else if (pInfo->hasInterpoFunc) {
SWinKey curKey = {.ts = curWin.skey, .groupId = groupId};
code = getIntervalSlicePrevStateBuf(&pInfo->streamAggSup, &pInfo->interval, &curKey, &prevPoint);
QUERY_CHECK_CODE(code, lino, _end);
}
if (pInfo->hasInterpoFunc && IS_VALID_WIN_KEY(prevPoint.winKey.win.skey) && isInterpoWindowFinished(&prevPoint) == false) {
code = setIntervalSliceOutputBuf(&prevPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
@ -288,6 +304,12 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
code = saveWinResult(&prevKey, prevPoint.pResPos, pInfo->pUpdatedMap);
QUERY_CHECK_CODE(code, lino, _end);
setInterpoWindowFinished(&prevPoint);
} else if (IS_VALID_WIN_KEY(prevPoint.winKey.win.skey)) {
releaseOutputBuf(pInfo->streamAggSup.pState, prevPoint.pResPos, &pInfo->streamAggSup.stateStore);
}
if (curTs > pInfo->endTs) {
break;
}
code = setIntervalSliceOutputBuf(&curPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
@ -300,7 +322,7 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
forwardRows = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, curWin.ekey, binarySearchForKey, NULL,
TSDB_ORDER_ASC);
int32_t prevEndPos = (forwardRows - 1) + startPos;
if (pInfo->hasInterpoFunc && winCode != TSDB_CODE_SUCCESS) {
if (pInfo->hasInterpoFunc) {
int32_t endRowId = getQualifiedRowNumDesc(pSup, pBlock, tsCols, prevEndPos, false);
TSKEY endRowTs = tsCols[endRowId];
transBlockToSliceResultRow(pBlock, endRowId, endRowTs, curPoint.pLastRow, 0, NULL, NULL, pInfo->pOffsetInfo);

View File

@ -4944,7 +4944,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.paramInfoPattern = 0,
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateSelectValue,
.getEnvFunc = getSelectivityFuncEnv,
.getEnvFunc = getGroupKeyFuncEnv,
.initFunc = functionSetup,
.processFunc = groupConstValueFunction,
.finalizeFunc = groupConstValueFinalize,

View File

@ -28,7 +28,7 @@
#define COPY_CHAR_ARRAY_FIELD(fldname) \
do { \
strcpy((pDst)->fldname, (pSrc)->fldname); \
tstrncpy((pDst)->fldname, (pSrc)->fldname, sizeof((pDst)->fldname)); \
} while (0)
#define COPY_OBJECT_FIELD(fldname, size) \

View File

@ -2339,7 +2339,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL;
}
sprintf(buf, "%s", pNode->datum.b ? "true" : "false");
snprintf(buf, MAX_NUM_STR_SIZE, "%s", pNode->datum.b ? "true" : "false");
return buf;
}
case TSDB_DATA_TYPE_TINYINT:
@ -2352,7 +2352,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL;
}
sprintf(buf, "%" PRId64, pNode->datum.i);
snprintf(buf, MAX_NUM_STR_SIZE, "%" PRId64, pNode->datum.i);
return buf;
}
case TSDB_DATA_TYPE_UTINYINT:
@ -2364,7 +2364,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL;
}
sprintf(buf, "%" PRIu64, pNode->datum.u);
snprintf(buf, MAX_NUM_STR_SIZE, "%" PRIu64, pNode->datum.u);
return buf;
}
case TSDB_DATA_TYPE_FLOAT:
@ -2374,7 +2374,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL;
}
sprintf(buf, "%e", pNode->datum.d);
snprintf(buf, MAX_NUM_STR_SIZE, "%e", pNode->datum.d);
return buf;
}
case TSDB_DATA_TYPE_NCHAR:
@ -2530,7 +2530,7 @@ static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pN
}
if (pCol->projRefIdx > 0) {
len = taosHashBinary(name, strlen(name));
len += sprintf(name + len, "_%d", pCol->projRefIdx);
len += tsnprintf(name + len, TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN - len, "_%d", pCol->projRefIdx);
}
SNode** pNodeFound = taosHashGet(pCxt->pColHash, name, len);
if (pNodeFound == NULL) {

View File

@ -142,13 +142,13 @@ static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* p
(void)strdequote(ep);
(void)strtrim(ep);
if (NULL == pPort) {
strcpy(pFqdn, ep);
tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
return TSDB_CODE_SUCCESS;
}
char* pColon = strchr(ep, ':');
if (NULL == pColon) {
*pPort = tsServerPort;
strcpy(pFqdn, ep);
tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
return TSDB_CODE_SUCCESS;
}
strncpy(pFqdn, ep, pColon - ep);
@ -320,12 +320,12 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
if (nodesIsExprNode(pRealizedExpr)) {
SExprNode* pExpr = (SExprNode*)pRealizedExpr;
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pExpr->aliasName, ((SColumnNode*)pExpr)->colName);
strcpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName);
tstrncpy(pExpr->aliasName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
tstrncpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else if (pRawExpr->isPseudoColumn) {
// all pseudo column are translate to function with same name
strcpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName);
strcpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName);
tstrncpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
tstrncpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
} else {
int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n);
@ -333,9 +333,9 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
// Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN].
// If aliasName is truncated, hash value of aliasName could be the same.
uint64_t hashVal = MurmurHash3_64(pRawExpr->p, pRawExpr->n);
sprintf(pExpr->aliasName, "%" PRIu64, hashVal);
snprintf(pExpr->aliasName, TSDB_COL_NAME_LEN, "%" PRIu64, hashVal);
strncpy(pExpr->userAlias, pRawExpr->p, len);
pExpr->userAlias[len] = '\0';
pExpr->userAlias[len] = 0;
}
}
pRawExpr->pNode = NULL;
@ -946,11 +946,11 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
goto _err;
}
if ('+' == pVal->literal[0]) {
sprintf(pNewLiteral, "-%s", pVal->literal + 1);
snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal + 1);
} else if ('-' == pVal->literal[0]) {
sprintf(pNewLiteral, "%s", pVal->literal + 1);
snprintf(pNewLiteral, strlen(pVal->literal) + 2, "%s", pVal->literal + 1);
} else {
sprintf(pNewLiteral, "-%s", pVal->literal);
snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal);
}
taosMemoryFree(pVal->literal);
pVal->literal = pNewLiteral;
@ -1021,7 +1021,7 @@ static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt, const SToken* pFuncNa
CHECK_MAKE_NODE(pCol);
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
if (NULL == pFuncName) {
strcpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME);
tstrncpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME, TSDB_COL_NAME_LEN);
} else {
strncpy(pCol->colName, pFuncName->z, pFuncName->n);
}
@ -1052,7 +1052,7 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "cast");
tstrncpy(func->functionName, "cast", TSDB_FUNC_NAME_LEN);
func->node.resType = dt;
if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type || TSDB_DATA_TYPE_VARBINARY == dt.type) {
func->node.resType.bytes = func->node.resType.bytes + VARSTR_HEADER_SIZE;
@ -1073,7 +1073,7 @@ SNode* createPositionFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode*
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "position");
tstrncpy(func->functionName, "position", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1091,7 +1091,7 @@ SNode* createTrimFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, ETrimType t
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "trim");
tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
func->trimType = type;
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt);
@ -1107,7 +1107,7 @@ SNode* createTrimFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode* p
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "trim");
tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
func->trimType = type;
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt);
@ -1126,7 +1126,7 @@ SNode* createSubstrFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode* pE
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "substr");
tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1144,7 +1144,7 @@ SNode* createSubstrFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode*
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func);
strcpy(func->functionName, "substr");
tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1228,10 +1228,10 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, SToken* pT
taosRandStr(tempTable->table.tableAlias, 8);
}
if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) {
strcpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias);
tstrncpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
((SSelectStmt*)pSubquery)->isSubquery = true;
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pSubquery)) {
strcpy(((SSetOperator*)pSubquery)->stmtName, tempTable->table.tableAlias);
tstrncpy(((SSetOperator*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
}
return (SNode*)tempTable;
_err:
@ -1434,7 +1434,7 @@ SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
fill->pWStartTs = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&(fill->pWStartTs));
CHECK_MAKE_NODE(fill->pWStartTs);
strcpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart");
tstrncpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
return (SNode*)fill;
_err:
nodesDestroyNode((SNode*)fill);
@ -1764,7 +1764,7 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
setSubquery(setOp->pLeft);
setOp->pRight = pRight;
setSubquery(setOp->pRight);
sprintf(setOp->stmtName, "%p", setOp);
snprintf(setOp->stmtName, TSDB_TABLE_NAME_LEN, "%p", setOp);
return (SNode*)setOp;
_err:
nodesDestroyNode(pLeft);
@ -2322,8 +2322,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode*
SCreateTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists;
pStmt->pCols = pCols;
pStmt->pTags = pTags;
@ -2344,10 +2344,10 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN
SCreateSubTableClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
strcpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName);
strcpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists;
pStmt->pSpecificTags = pSpecificTags;
pStmt->pValsOfTags = pValsOfTags;
@ -2370,8 +2370,8 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx
SCreateSubTableFromFileClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName);
strcpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName);
tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists;
pStmt->pSpecificTags = pSpecificTags;
if (TK_NK_STRING == pFilePath->type) {
@ -2405,8 +2405,8 @@ SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNod
SDropTableClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreNotExists = ignoreNotExists;
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
@ -2433,8 +2433,8 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool igno
SDropSuperTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreNotExists = ignoreNotExists;
pStmt->withOpt = withOpt;
nodesDestroyNode(pRealTable);
@ -2445,8 +2445,8 @@ _err:
}
static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* pStmt) {
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
}
@ -2765,8 +2765,8 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
SShowCreateTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:
@ -2779,8 +2779,8 @@ SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
SShowCreateViewStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:
@ -2793,8 +2793,8 @@ SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable
SShowTableDistributedStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:
@ -2953,7 +2953,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_USER_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
strcpy(pStmt->password, password);
tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
pStmt->sysinfo = sysinfo;
pStmt->createDb = createDb;
pStmt->isImport = is_import;
@ -2975,7 +2975,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al
char password[TSDB_USET_PASSWORD_LEN] = {0};
SToken* pVal = pAlterInfo;
CHECK_NAME(checkPassword(pCxt, pVal, password));
strcpy(pStmt->password, password);
tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
break;
}
case TSDB_ALTER_USER_ENABLE: {
@ -3285,8 +3285,8 @@ SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists,
pStmt->withMeta = withMeta;
pStmt->pWhere = pWhere;
strcpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:
@ -3399,8 +3399,8 @@ SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
SDescribeStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
_err:
@ -3480,8 +3480,8 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
}
pStmt->pQuerySql = tstrdup(pAs->z + i);
CHECK_OUT_OF_MEM(pStmt->pQuerySql);
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName);
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName);
tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
nodesDestroyNode(pView);
pStmt->orReplace = orReplace;
pStmt->pQuery = pQuery;
@ -3499,8 +3499,8 @@ SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode*
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_VIEW_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
pStmt->ignoreNotExists = ignoreNotExists;
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName);
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName);
tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
nodesDestroyNode(pView);
return (SNode*)pStmt;
_err:
@ -3585,8 +3585,8 @@ SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
strcpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName);
tstrncpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable);
pStmt->ignoreExists = ignoreExists;
pStmt->pOptions = (SStreamOptions*)pOptions;
@ -3840,9 +3840,9 @@ SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols
pStmt->pCols = pCols;
pStmt->pQuery = pQuery;
if (QUERY_NODE_SELECT_STMT == nodeType(pQuery)) {
strcpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias);
tstrncpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pQuery)) {
strcpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias);
tstrncpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
}
return (SNode*)pStmt;
_err:

View File

@ -480,8 +480,8 @@ static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt*
static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName);
strcpy(name.tname, pStmt->tableName);
tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
#ifdef TD_ENTERPRISE
if (TSDB_CODE_SUCCESS == code) {
@ -781,8 +781,8 @@ static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SS
static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName);
strcpy(name.tname, pStmt->tableName);
tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
if (TSDB_CODE_SUCCESS == code) {
code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
@ -799,8 +799,8 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName);
strcpy(name.tname, pStmt->viewName);
tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
tstrncpy(name.tname, pStmt->viewName, TSDB_TABLE_NAME_LEN);
char dbFName[TSDB_DB_FNAME_LEN];
(void)tNameGetFullDbName(&name, dbFName);
int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->viewName, 0);
@ -841,8 +841,8 @@ static int32_t collectMetaKeyFromInsert(SCollectMetaKeyCxt* pCxt, SInsertStmt* p
static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName);
strcpy(name.tname, pStmt->tableName);
tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
if (TSDB_CODE_SUCCESS == code) {
code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ);

View File

@ -131,8 +131,8 @@ EDealRes rewriteAuthTable(SNode* pNode, void* pContext) {
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SColumnNode* pCol = (SColumnNode*)pNode;
SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext;
strcpy(pCol->tableName, pCxt->pTarget->tableName);
strcpy(pCol->tableAlias, pCxt->pTarget->tableAlias);
tstrncpy(pCol->tableName, pCxt->pTarget->tableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableAlias, pCxt->pTarget->tableAlias, TSDB_TABLE_NAME_LEN);
}
return DEAL_RES_CONTINUE;

View File

@ -178,14 +178,14 @@ static EDealRes doFindAndReplaceNode(SNode** pNode, void* pContext) {
SCalcConstContext* pCxt = pContext;
if (pCxt->replaceCxt.pTarget == *pNode) {
char aliasName[TSDB_COL_NAME_LEN] = {0};
strcpy(aliasName, ((SExprNode*)*pNode)->aliasName);
tstrncpy(aliasName, ((SExprNode*)*pNode)->aliasName, TSDB_COL_NAME_LEN);
nodesDestroyNode(*pNode);
*pNode = NULL;
pCxt->code = nodesCloneNode(pCxt->replaceCxt.pNew, pNode);
if (NULL == *pNode) {
return DEAL_RES_ERROR;
}
strcpy(((SExprNode*)*pNode)->aliasName, aliasName);
tstrncpy(((SExprNode*)*pNode)->aliasName, aliasName, TSDB_COL_NAME_LEN);
pCxt->replaceCxt.replaced = true;
return DEAL_RES_END;
@ -228,14 +228,14 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d
SAssociationNode* pAssNode = taosArrayGet(pAssociation, i);
SNode** pCol = pAssNode->pPlace;
if (*pCol == pAssNode->pAssociationNode) {
strcpy(aliasName, ((SExprNode*)*pCol)->aliasName);
tstrncpy(aliasName, ((SExprNode*)*pCol)->aliasName, TSDB_COL_NAME_LEN);
SArray* pOrigAss = NULL;
TSWAP(((SExprNode*)*pCol)->pAssociation, pOrigAss);
nodesDestroyNode(*pCol);
*pCol = NULL;
code = nodesCloneNode(*pNew, pCol);
if (TSDB_CODE_SUCCESS == code) {
strcpy(((SExprNode*)*pCol)->aliasName, aliasName);
tstrncpy(((SExprNode*)*pCol)->aliasName, aliasName, TSDB_COL_NAME_LEN);
TSWAP(pOrigAss, ((SExprNode*)*pCol)->pAssociation);
}
taosArrayDestroy(pOrigAss);

View File

@ -903,7 +903,7 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc
for (int32_t i = 0; i < numOfBound; ++i) {
schema = &pSchema[boundColumns[i]];
strcpy((*fields)[i].name, schema->name);
tstrncpy((*fields)[i].name, schema->name, 65);
(*fields)[i].type = schema->type;
(*fields)[i].bytes = schema->bytes;
}

File diff suppressed because it is too large Load Diff

View File

@ -250,7 +250,7 @@ int32_t generateSyntaxErrMsgExt(SMsgBuf* pBuf, int32_t errCode, const char* pFor
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
if (pBuf->buf) {
strncpy(pBuf->buf, msg, pBuf->len);
tstrncpy(pBuf->buf, msg, pBuf->len);
}
return TSDB_CODE_TSC_INVALID_OPERATION;
@ -277,7 +277,7 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
}
char buf[64] = {0}; // only extract part of sql string
strncpy(buf, sourceStr, tListLen(buf) - 1);
tstrncpy(buf, sourceStr, tListLen(buf));
if (additionalInfo != NULL) {
snprintf(pBuf->buf, pBuf->len, msgFormat2, buf, additionalInfo);
@ -454,7 +454,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi
continue;
}
STagVal val = {0};
// strcpy(val.colName, colName);
// TSDB_DB_FNAME_LENme, colName);
val.pKey = jsonKey;
retCode = taosHashPut(keyHash, jsonKey, keyLen, &keyLen,
CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
@ -595,15 +595,15 @@ int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName)
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
char* pStr, bool isView) {
return sprintf(pStr, "%s*%d*%s*%s*%d*%d", pUser, acctId, pDb, (NULL == pTable || '\0' == pTable[0]) ? "``" : pTable,
type, isView);
return snprintf(pStr, USER_AUTH_KEY_MAX_LEN, "%s*%d*%s*%s*%d*%d", pUser, acctId, pDb,
(NULL == pTable || '\0' == pTable[0]) ? "``" : pTable, type, isView);
}
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
char* p = strchr(pStart, '*');
char buf[10] = {0};
if (NULL == p) {
strcpy(buf, pStart);
tstrncpy(buf, pStart, 10);
*pNext = NULL;
} else {
strncpy(buf, pStart, p - pStart);
@ -615,7 +615,7 @@ static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) {
char* p = strchr(pStart, '*');
if (NULL == p) {
strcpy(pStr, pStart);
tstrncpy(pStr, pStart, strlen(pStart) + 1);
*pNext = NULL;
} else {
strncpy(pStr, pStart, p - pStart);
@ -707,7 +707,7 @@ static int32_t buildTableReqFromDb(SHashObj* pDbsHash, SArray** pDbs) {
SParseTablesMetaReq* p = taosHashIterate(pDbsHash, NULL);
while (NULL != p) {
STablesReq req = {0};
strcpy(req.dbFName, p->dbFName);
tstrncpy(req.dbFName, p->dbFName, TSDB_DB_FNAME_LEN);
int32_t code = buildTableReq(p->pTables, &req.pTables);
if (TSDB_CODE_SUCCESS == code) {
if (NULL == taosArrayPush(*pDbs, &req)) {
@ -831,7 +831,7 @@ int32_t createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode*
select->isDistinct = isDistinct;
select->pProjectionList = pProjectionList;
select->pFromTable = pTable;
sprintf(select->stmtName, "%p", select);
snprintf(select->stmtName, TSDB_TABLE_NAME_LEN, "%p", select);
select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL;
select->timeLineCurMode = TIME_LINE_GLOBAL;
select->onlyHasKeepOrderFunc = true;

View File

@ -218,7 +218,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) {
static EDealRes rewriteQueryExprAliasImpl(SNode* pNode, void* pContext) {
if (nodesIsExprNode(pNode) && QUERY_NODE_COLUMN != nodeType(pNode)) {
sprintf(((SExprNode*)pNode)->aliasName, "#%d", *(int32_t*)pContext);
snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#%d", *(int32_t*)pContext);
++(*(int32_t*)pContext);
}
return DEAL_RES_CONTINUE;
@ -433,9 +433,6 @@ int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx
nodesDestroyNode(pQuery->pRoot);
pQuery->pRoot = NULL;
code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
if (NULL == pQuery->pRoot) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
rewriteExprAlias(pQuery->pRoot);
@ -525,9 +522,6 @@ int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colId
nodesDestroyNode(pQuery->pRoot);
pQuery->pRoot = NULL;
code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
if (NULL == pQuery->pRoot) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
rewriteExprAlias(pQuery->pRoot);

View File

@ -119,9 +119,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
}
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode);
pCol->node.resType = pToBeRewrittenExpr->resType;
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
strcpy(pCol->node.userAlias, ((SExprNode*)pExpr)->userAlias);
strcpy(pCol->colName, ((SExprNode*)pExpr)->aliasName);
tstrncpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.userAlias, ((SExprNode*)pExpr)->userAlias, TSDB_COL_NAME_LEN);
tstrncpy(pCol->colName, ((SExprNode*)pExpr)->aliasName, TSDB_COL_NAME_LEN);
pCol->node.projIdx = ((SExprNode*)(*pNode))->projIdx;
if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
setColumnInfo((SFunctionNode*)pExpr, pCol, pCxt->isPartitionBy);
@ -150,7 +150,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
case QUERY_NODE_LOGIC_CONDITION:
case QUERY_NODE_FUNCTION: {
if ('\0' == ((SExprNode*)pNode)->aliasName[0]) {
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%p", pNode);
snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#expr_%p", pNode);
}
return DEAL_RES_IGNORE_CHILD;
}
@ -305,12 +305,12 @@ static SNode* createFirstCol(SRealTableNode* pTable, const SSchema* pSchema) {
pCol->tableId = pTable->pMeta->uid;
pCol->colId = pSchema->colId;
pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->tableAlias, pTable->table.tableAlias);
strcpy(pCol->tableName, pTable->table.tableName);
tstrncpy(pCol->tableAlias, pTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableName, pTable->table.tableName, TSDB_TABLE_NAME_LEN);
pCol->isPk = pSchema->flags & COL_IS_KEY;
pCol->tableHasPk = hasPkInTable(pTable->pMeta);
pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs;
strcpy(pCol->colName, pSchema->name);
tstrncpy(pCol->colName, pSchema->name, TSDB_COL_NAME_LEN);
return (SNode*)pCol;
}
@ -386,8 +386,8 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT
pScan->scanRange = TSWINDOW_INITIALIZER;
pScan->tableName.type = TSDB_TABLE_NAME_T;
pScan->tableName.acctId = pCxt->pPlanCxt->acctId;
strcpy(pScan->tableName.dbname, pRealTable->table.dbName);
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
tstrncpy(pScan->tableName.dbname, pRealTable->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pScan->tableName.tname, pRealTable->table.tableName, TSDB_TABLE_NAME_LEN);
pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
pScan->ratio = pRealTable->ratio;
pScan->dataRequired = FUNC_DATA_REQUIRED_DATA_LOAD;
@ -776,12 +776,12 @@ static int32_t addWinJoinPrimKeyToAggFuncs(SSelectStmt* pSelect, SNodeList** pLi
}
SSchema* pColSchema = &pProbeTable->pMeta->schema[0];
strcpy(pCol->dbName, pProbeTable->table.dbName);
strcpy(pCol->tableAlias, pProbeTable->table.tableAlias);
strcpy(pCol->tableName, pProbeTable->table.tableName);
strcpy(pCol->colName, pColSchema->name);
strcpy(pCol->node.aliasName, pColSchema->name);
strcpy(pCol->node.userAlias, pColSchema->name);
tstrncpy(pCol->dbName, pProbeTable->table.dbName, TSDB_DB_NAME_LEN);
tstrncpy(pCol->tableAlias, pProbeTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableName, pProbeTable->table.tableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->colName, pColSchema->name, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.aliasName, pColSchema->name, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.userAlias, pColSchema->name, TSDB_COL_NAME_LEN);
pCol->tableId = pProbeTable->pMeta->uid;
pCol->tableType = pProbeTable->pMeta->tableType;
pCol->colId = pColSchema->colId;
@ -1547,9 +1547,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
if (TSDB_CODE_SUCCESS == code) {
pSort->pSortKeys = NULL;
code = nodesCloneList(pSelect->pOrderByList, &pSort->pSortKeys);
if (NULL == pSort->pSortKeys) {
code = code;
}
if (TSDB_CODE_SUCCESS == code) {
SNode* pNode = NULL;
SOrderByExprNode* firstSortKey = (SOrderByExprNode*)nodesListGetNode(pSort->pSortKeys, 0);
if (isPrimaryKeySort(pSelect->pOrderByList)) pSort->node.outputTsOrder = firstSortKey->order;
@ -1565,6 +1563,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
}
}
}
}
if (TSDB_CODE_SUCCESS == code) {
*pLogicNode = (SLogicNode*)pSort;
@ -1615,10 +1614,7 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel
pProject->pProjections = NULL;
code = nodesCloneList(pSelect->pProjectionList, &pProject->pProjections);
if (NULL == pProject->pProjections) {
code = code;
}
strcpy(pProject->stmtName, pSelect->stmtName);
tstrncpy(pProject->stmtName, pSelect->stmtName, TSDB_TABLE_NAME_LEN);
if (TSDB_CODE_SUCCESS == code) {
code = createColumnByProjections(pCxt, pSelect->stmtName, pSelect->pProjectionList, &pProject->node.pTargets);
@ -2108,7 +2104,7 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet
pModify->tableId = pRealTable->pMeta->uid;
pModify->tableType = pRealTable->pMeta->tableType;
snprintf(pModify->tableName, sizeof(pModify->tableName), "%s", pRealTable->table.tableName);
strcpy(pModify->tsColName, pRealTable->pMeta->schema->name);
tstrncpy(pModify->tsColName, pRealTable->pMeta->schema->name, TSDB_COL_NAME_LEN);
pModify->deleteTimeRange = pDelete->timeRange;
pModify->pAffectedRows = NULL;
code = nodesCloneNode(pDelete->pCountFunc, &pModify->pAffectedRows);

View File

@ -184,7 +184,7 @@ static EDealRes optRebuildTbanme(SNode** pNode, void* pContext) {
*(int32_t*)pContext = code;
return DEAL_RES_ERROR;
}
strcpy(pFunc->functionName, "tbname");
tstrncpy(pFunc->functionName, "tbname", TSDB_FUNC_NAME_LEN);
pFunc->funcType = FUNCTION_TYPE_TBNAME;
pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType;
nodesDestroyNode(*pNode);
@ -1291,9 +1291,7 @@ static int32_t pdcJoinAddPreFilterColsToTarget(SOptimizeContext* pCxt, SJoinLogi
SNodeList* pCondCols = NULL;
code = nodesMakeList(&pCondCols);
SNodeList* pTargets = NULL;
if (NULL == pCondCols) {
code = code;
} else {
if (TSDB_CODE_SUCCESS == code) {
code = nodesCollectColumnsFromNode(pJoin->pColOnCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols);
}
if (TSDB_CODE_SUCCESS == code) {
@ -2927,9 +2925,9 @@ static int32_t smaIndexOptCreateSmaCol(SNode* pFunc, uint64_t tableId, int32_t c
pCol->tableType = TSDB_SUPER_TABLE;
pCol->colId = colId;
pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->colName, ((SExprNode*)pFunc)->aliasName);
tstrncpy(pCol->colName, ((SExprNode*)pFunc)->aliasName, TSDB_COL_NAME_LEN);
pCol->node.resType = ((SExprNode*)pFunc)->resType;
strcpy(pCol->node.aliasName, ((SExprNode*)pFunc)->aliasName);
tstrncpy(pCol->node.aliasName, ((SExprNode*)pFunc)->aliasName, TSDB_COL_NAME_LEN);
*ppNode = pCol;
return code;
}
@ -2998,7 +2996,7 @@ static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNo
}
SExprNode exprNode;
exprNode.resType = ((SExprNode*)pWsNode)->resType;
sprintf(exprNode.aliasName, "#expr_%d", index + 1);
snprintf(exprNode.aliasName, TSDB_COL_NAME_LEN, "#expr_%d", index + 1);
SColumnNode* pkNode = NULL;
code = smaIndexOptCreateSmaCol((SNode*)&exprNode, tableId, PRIMARYKEY_TIMESTAMP_COL_ID, &pkNode);
if (TSDB_CODE_SUCCESS != code) {
@ -3168,7 +3166,7 @@ static void partTagsSetAlias(char* pAlias, const char* pTableAlias, const char*
int32_t len = tsnprintf(name, TSDB_COL_FNAME_LEN, "%s.%s", pTableAlias, pColName);
(void)taosHashBinary(name, len);
strncpy(pAlias, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pAlias, name, TSDB_COL_NAME_LEN);
}
static int32_t partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode, SFunctionNode** ppNode) {
@ -3186,7 +3184,7 @@ static int32_t partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode, SF
SColumnNode* pCol = (SColumnNode*)pNode;
partTagsSetAlias(pFunc->node.aliasName, pCol->tableAlias, pCol->colName);
} else {
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName);
tstrncpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
}
code = nodesCloneNode(pNode, &pNew);
if (TSDB_CODE_SUCCESS == code) {
@ -3472,7 +3470,7 @@ static EDealRes eliminateProjOptRewriteScanTableAlias(SNode* pNode, void* pConte
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SColumnNode* pCol = (SColumnNode*)pNode;
RewriteTableAliasCxt* pCtx = (RewriteTableAliasCxt*)pContext;
strncpy(pCol->tableAlias, pCtx->newTableAlias, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableAlias, pCtx->newTableAlias, TSDB_TABLE_NAME_LEN);
}
return DEAL_RES_CONTINUE;
}
@ -3727,7 +3725,7 @@ static int32_t rewriteTailOptCreateProjectExpr(SFunctionNode* pFunc, SNode** ppN
if (NULL == pExpr) {
return code;
}
strcpy(((SExprNode*)pExpr)->aliasName, pFunc->node.aliasName);
tstrncpy(((SExprNode*)pExpr)->aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
*ppNode = pExpr;
return code;
}
@ -3883,15 +3881,15 @@ static int32_t rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNod
return code;
}
strcpy(pFunc->functionName, "first");
tstrncpy(pFunc->functionName, "first", TSDB_FUNC_NAME_LEN);
if (NULL != pSelectValue) {
strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName);
tstrncpy(pFunc->node.aliasName, pSelectValue->node.aliasName, TSDB_COL_NAME_LEN);
} else {
int64_t pointer = (int64_t)pFunc;
char name[TSDB_FUNC_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pFunc->functionName, pointer);
(void)taosHashBinary(name, len);
strncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN);
}
SNode* pNew = NULL;
code = nodesCloneNode(pCol, &pNew);
@ -3989,15 +3987,15 @@ static int32_t rewriteUniqueOptCreateProjectCol(SFunctionNode* pFunc, SNode** pp
if (FUNCTION_TYPE_UNIQUE == pFunc->funcType) {
SExprNode* pExpr = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias);
strcpy(pCol->colName, ((SColumnNode*)pExpr)->colName);
tstrncpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->colName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else {
strcpy(pCol->colName, pExpr->aliasName);
tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
}
} else {
strcpy(pCol->colName, pFunc->node.aliasName);
tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
}
strcpy(pCol->node.aliasName, pFunc->node.aliasName);
tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
*ppNode = (SNode*)pCol;
return code;
}
@ -4366,7 +4364,7 @@ static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pCo
return terrno;
}
pFuncTypeParam->pCol->colId = pColNode->colId;
strcpy(pFuncTypeParam->pCol->name, pColNode->colName);
tstrncpy(pFuncTypeParam->pCol->name, pColNode->colName, TSDB_COL_NAME_LEN);
if (NULL == taosArrayPush(pScan->pFuncTypes, pFuncTypeParam)) {
taosMemoryFree(pFuncTypeParam);
return terrno;
@ -4443,15 +4441,15 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
if (TSDB_CODE_SUCCESS != code) {
break;
}
sprintf(((SColumnNode*)newColNode)->colName, "#dup_col.%p", newColNode);
sprintf(((SColumnNode*)pParamNode)->colName, "#dup_col.%p", newColNode);
snprintf(((SColumnNode*)newColNode)->colName, TSDB_COL_NAME_LEN, "#dup_col.%p", newColNode);
snprintf(((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN, "#dup_col.%p", newColNode);
if (FUNCTION_TYPE_LAST_ROW == funcType &&
((SColumnNode*)pParamNode)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
if (!adjLastRowTsColName) {
adjLastRowTsColName = true;
strncpy(tsColName, ((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN);
tstrncpy(tsColName, ((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN);
} else {
strncpy(((SColumnNode*)pParamNode)->colName, tsColName, TSDB_COL_NAME_LEN);
tstrncpy(((SColumnNode*)pParamNode)->colName, tsColName, TSDB_COL_NAME_LEN);
nodesDestroyNode(newColNode);
continue;
}
@ -4573,7 +4571,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
((cxt.pLastCols->length == 1 && nodesEqualNode((SNode*)pPKTsCol, nodesListGetNode(cxt.pLastCols, 0))) ||
(pScan->node.pTargets->length == 2 && cxt.pkBytes > 0))) {
// when select last(ts),tbname,ts from ..., we add another ts to targets
sprintf(pPKTsCol->colName, "#sel_val.%p", pPKTsCol);
snprintf(pPKTsCol->colName, TSDB_COL_NAME_LEN, "#sel_val.%p", pPKTsCol);
SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pPKTsCol, &pNew);
if (TSDB_CODE_SUCCESS == code) {
@ -4590,7 +4588,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
if (pNonPKCol && cxt.pLastCols->length == 1 &&
nodesEqualNode((SNode*)pNonPKCol, nodesListGetNode(cxt.pLastCols, 0))) {
// when select last(c1), c1 from ..., we add c1 to targets
sprintf(pNonPKCol->colName, "#sel_val.%p", pNonPKCol);
snprintf(pNonPKCol->colName, TSDB_COL_NAME_LEN, "#sel_val.%p", pNonPKCol);
SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pNonPKCol, &pNew);
if (TSDB_CODE_SUCCESS == code) {
@ -5359,10 +5357,10 @@ static bool tbCntScanOptIsEligibleLogicCond(STbCntScanOptInfo* pInfo, SLogicCond
}
if (!hasDbCond && 0 == strcmp(pCol->colName, "db_name")) {
hasDbCond = true;
strcpy(pInfo->table.dbname, pVal->literal);
tstrncpy(pInfo->table.dbname, pVal->literal, TSDB_DB_NAME_LEN);
} else if (!hasStbCond && 0 == strcmp(pCol->colName, "stable_name")) {
hasStbCond = true;
strcpy(pInfo->table.tname, pVal->literal);
tstrncpy(pInfo->table.tname, pVal->literal, TSDB_TABLE_NAME_LEN);
} else {
return false;
}
@ -5425,8 +5423,8 @@ static int32_t tbCntScanOptCreateTableCountFunc(SNode** ppNode) {
if (NULL == pFunc) {
return code;
}
strcpy(pFunc->functionName, "_table_count");
strcpy(pFunc->node.aliasName, "_table_count");
tstrncpy(pFunc->functionName, "_table_count", TSDB_FUNC_NAME_LEN);
tstrncpy(pFunc->node.aliasName, "_table_count", TSDB_COL_NAME_LEN);
code = fmGetFuncInfo(pFunc, NULL, 0);
if (TSDB_CODE_SUCCESS != code) {
nodesDestroyNode((SNode*)pFunc);
@ -5438,8 +5436,8 @@ static int32_t tbCntScanOptCreateTableCountFunc(SNode** ppNode) {
static int32_t tbCntScanOptRewriteScan(STbCntScanOptInfo* pInfo) {
pInfo->pScan->scanType = SCAN_TYPE_TABLE_COUNT;
strcpy(pInfo->pScan->tableName.dbname, pInfo->table.dbname);
strcpy(pInfo->pScan->tableName.tname, pInfo->table.tname);
tstrncpy(pInfo->pScan->tableName.dbname, pInfo->table.dbname, TSDB_DB_NAME_LEN);
tstrncpy(pInfo->pScan->tableName.tname, pInfo->table.tname, TSDB_TABLE_NAME_LEN);
NODES_DESTORY_LIST(pInfo->pScan->node.pTargets);
NODES_DESTORY_LIST(pInfo->pScan->pScanCols);
NODES_DESTORY_NODE(pInfo->pScan->node.pConditions);
@ -5489,8 +5487,8 @@ static int32_t tbCntScanOptCreateSumFunc(SFunctionNode* pCntFunc, SNode* pParam,
if (NULL == pFunc) {
return code;
}
strcpy(pFunc->functionName, "sum");
strcpy(pFunc->node.aliasName, pCntFunc->node.aliasName);
tstrncpy(pFunc->functionName, "sum", TSDB_FUNC_NAME_LEN);
tstrncpy(pFunc->node.aliasName, pCntFunc->node.aliasName, TSDB_COL_NAME_LEN);
code = createColumnByRewriteExpr(pParam, &pFunc->pParameterList);
if (TSDB_CODE_SUCCESS == code) {
code = fmGetFuncInfo(pFunc, NULL, 0);
@ -6267,29 +6265,22 @@ static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pRoot, SLogicNode* p
if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->node.pChildren = NULL;
code = nodesMakeList(&pDynCtrl->node.pChildren);
if (NULL == pDynCtrl->node.pChildren) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->stbJoin.pVgList = NULL;
code = nodesMakeList(&pDynCtrl->stbJoin.pVgList);
if (NULL == pDynCtrl->stbJoin.pVgList) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->stbJoin.pUidList = NULL;
code = nodesMakeList(&pDynCtrl->stbJoin.pUidList);
if (NULL == pDynCtrl->stbJoin.pUidList) {
code = code;
}
}
SJoinLogicNode* pHJoin = (SJoinLogicNode*)pPrev;
if (TSDB_CODE_SUCCESS == code) {
code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 0));
}
if (TSDB_CODE_SUCCESS == code) {
code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 2));
}
@ -6308,9 +6299,6 @@ static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pRoot, SLogicNode* p
if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->node.pTargets = NULL;
code = nodesCloneList(pPost->pTargets, &pDynCtrl->node.pTargets);
if (!pDynCtrl->node.pTargets) {
code = code;
}
}
}
@ -7056,10 +7044,9 @@ int32_t tsmaOptCreateTsmaScanCols(const STSMAOptUsefulTsma* pTsma, const SNodeLi
pCol->tableType = TSDB_SUPER_TABLE;
pCol->tableId = pTsma->targetTbUid;
pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->tableName, pTsma->targetTbName);
strcpy(pCol->dbName, pTsma->pTsma->targetDbFName);
strcpy(pCol->colName, pFunc->node.aliasName);
strcpy(pCol->node.aliasName, pFunc->node.aliasName);
tstrncpy(pCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
pCol->node.resType.type = TSDB_DATA_TYPE_BINARY;
code = nodesListMakeStrictAppend(&pScanCols, (SNode*)pCol);
}
@ -7083,8 +7070,8 @@ static int32_t tsmaOptRewriteTag(const STSMAOptCtx* pTsmaOptCtx, const STSMAOptU
for (int32_t i = 0; i < pTsma->pTsma->pTags->size; ++i) {
const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, i);
if (strcmp(pTagCol->colName, pSchema->name) == 0) {
strcpy(pTagCol->tableName, pTsma->targetTbName);
strcpy(pTagCol->tableAlias, pTsma->targetTbName);
tstrncpy(pTagCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
tstrncpy(pTagCol->tableAlias, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
pTagCol->tableId = pTsma->targetTbUid;
pTagCol->tableType = TSDB_SUPER_TABLE;
pTagCol->colId = pSchema->colId;
@ -7109,8 +7096,8 @@ static int32_t tsmaOptRewriteTbname(const STSMAOptCtx* pTsmaOptCtx, SNode** pTbN
nodesDestroyNode(*pTbNameNode);
SColumnNode* pCol = (SColumnNode*)pRewrittenFunc;
const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, pTsma->pTsma->pTags->size - 1);
strcpy(pCol->tableName, pTsma->targetTbName);
strcpy(pCol->tableAlias, pTsma->targetTbName);
tstrncpy(pCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableAlias, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
pCol->tableId = pTsma->targetTbUid;
pCol->tableType = TSDB_SUPER_TABLE;
pCol->colId = pSchema->colId;
@ -7234,7 +7221,7 @@ static int32_t tsmaOptRewriteScan(STSMAOptCtx* pTsmaOptCtx, SScanLogicNode* pNew
if (code == TSDB_CODE_SUCCESS) {
pNewScan->stableId = pTsma->pTsma->destTbUid;
pNewScan->tableId = pTsma->targetTbUid;
strcpy(pNewScan->tableName.tname, pTsma->targetTbName);
tstrncpy(pNewScan->tableName.tname, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
}
if (code == TSDB_CODE_SUCCESS) {
code = tsmaOptRewriteNodeList(pNewScan->pScanPseudoCols, pTsmaOptCtx, pTsma, true, true);
@ -7287,12 +7274,12 @@ static int32_t tsmaOptCreateWStart(int8_t precision, SFunctionNode** pWStartOut)
if (NULL == pWStart) {
return code;
}
strcpy(pWStart->functionName, "_wstart");
tstrncpy(pWStart->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWStart;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer);
(void)taosHashBinary(name, len);
strncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN);
pWStart->node.resType.precision = precision;
code = fmGetFuncInfo(pWStart, NULL, 0);
@ -7395,12 +7382,12 @@ static int32_t tsmaOptGeneratePlan(STSMAOptCtx* pTsmaOptCtx) {
for (int32_t j = 0; j < pTsmaOptCtx->pScan->pTsmas->size; ++j) {
if (taosArrayGetP(pTsmaOptCtx->pScan->pTsmas, j) == pTsma->pTsma) {
const STsmaTargetTbInfo* ptbInfo = taosArrayGet(pTsmaOptCtx->pScan->pTsmaTargetTbInfo, j);
strcpy(pTsma->targetTbName, ptbInfo->tableName);
tstrncpy(pTsma->targetTbName, ptbInfo->tableName, TSDB_TABLE_NAME_LEN);
pTsma->targetTbUid = ptbInfo->uid;
}
}
} else {
strcpy(pTsma->targetTbName, pTsma->pTsma->targetTb);
tstrncpy(pTsma->targetTbName, pTsma->pTsma->targetTb, TSDB_TABLE_NAME_LEN);
pTsma->targetTbUid = pTsma->pTsma->destTbUid;
}
}

View File

@ -41,9 +41,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pStmtName);
strcat(*ppKey, ".");
strcat(*ppKey, pCol->node.aliasName);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
} else {
@ -51,7 +51,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pCol->node.aliasName);
TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}
@ -61,7 +61,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pCol->colName);
TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}
@ -70,9 +70,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pCol->tableAlias);
strcat(*ppKey, ".");
strcat(*ppKey, pCol->colName);
TAOS_STRNCAT(*ppKey, pCol->tableAlias, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
} else if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
@ -85,9 +85,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pStmtName);
strcat(*ppKey, ".");
strcat(*ppKey, ((SExprNode*)pNode)->aliasName);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -95,9 +95,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pVal->literal);
strcat(*ppKey, ".");
strcat(*ppKey, ((SExprNode*)pNode)->aliasName);
TAOS_STRNCAT(*ppKey, pVal->literal, strlen(pVal->literal));
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -109,9 +109,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, pStmtName);
strcat(*ppKey, ".");
strcat(*ppKey, ((SExprNode*)pNode)->aliasName);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -120,7 +120,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strcat(*ppKey, ((SExprNode*)pNode)->aliasName);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}
@ -229,7 +229,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD
code = putSlotToHash(name, len, pDataBlockDesc->dataBlockId, slotId, pNode, pHash);
if (TSDB_CODE_SUCCESS == code) {
if (nodeType(pNode) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode)->resIdx > 0) {
sprintf(name + strlen(name), "_%d", ((SColumnNode*)pNode)->resIdx);
snprintf(name + strlen(name), 16, "_%d", ((SColumnNode*)pNode)->resIdx);
code = putSlotToHash(name, strlen(name), pDataBlockDesc->dataBlockId, slotId, pNode, pProjIdxDescHash);
}
}
@ -396,7 +396,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
}
SSlotIndex *pIndex = NULL;
if (((SColumnNode*)pNode)->projRefIdx > 0) {
sprintf(name + strlen(name), "_%d", ((SColumnNode*)pNode)->projRefIdx);
snprintf(name + strlen(name), 16, "_%d", ((SColumnNode*)pNode)->projRefIdx);
pIndex = taosHashGet(pCxt->pLeftProjIdxHash, name, strlen(name));
if (!pIndex) {
pIndex = taosHashGet(pCxt->pRightProdIdxHash, name, strlen(name));
@ -567,9 +567,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (TSDB_CODE_SUCCESS == code && NULL != pScanLogicNode->pScanPseudoCols) {
pScanPhysiNode->pScanPseudoCols = NULL;
code = nodesCloneList(pScanLogicNode->pScanPseudoCols, &pScanPhysiNode->pScanPseudoCols);
if (NULL == pScanPhysiNode->pScanPseudoCols) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
@ -589,9 +586,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (NULL != pScanLogicNode->pTagCond) {
pSubplan->pTagCond = NULL;
code = nodesCloneNode(pScanLogicNode->pTagCond, &pSubplan->pTagCond);
if (NULL == pSubplan->pTagCond) {
code = code;
}
}
}
@ -599,9 +593,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (NULL != pScanLogicNode->pTagIndexCond) {
pSubplan->pTagIndexCond = NULL;
code = nodesCloneNode(pScanLogicNode->pTagIndexCond, &pSubplan->pTagIndexCond);
if (NULL == pSubplan->pTagIndexCond) {
code = code;
}
}
}
@ -1675,11 +1666,11 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
SExprNode* pRewrittenExpr = (SExprNode*)pExpr;
pCol->node.resType = pRewrittenExpr->resType;
if ('\0' != pRewrittenExpr->aliasName[0]) {
strcpy(pCol->colName, pRewrittenExpr->aliasName);
tstrncpy(pCol->colName, pRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
} else {
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId,
pCxt->rewriteId);
strcpy(pCol->colName, pRewrittenExpr->aliasName);
tstrncpy(pCol->colName, pRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
}
nodesDestroyNode(*pNode);
*pNode = (SNode*)pCol;
@ -1700,7 +1691,7 @@ static int32_t rewriteValueToOperator(SRewritePrecalcExprsCxt* pCxt, SNode** pNo
}
SValueNode* pVal = (SValueNode*)*pNode;
pOper->node.resType = pVal->node.resType;
strcpy(pOper->node.aliasName, pVal->node.aliasName);
tstrncpy(pOper->node.aliasName, pVal->node.aliasName, TSDB_COL_NAME_LEN);
pOper->opType = OP_TYPE_ASSIGN;
pOper->pRight = *pNode;
*pNode = (SNode*)pOper;
@ -1961,9 +1952,6 @@ static int32_t createInterpFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pCh
pInterpFunc->rangeInterval = pFuncLogicNode->rangeInterval;
pInterpFunc->rangeIntervalUnit = pFuncLogicNode->rangeIntervalUnit;
code = nodesCloneNode(pFuncLogicNode->pFillValues, &pInterpFunc->pFillValues);
if (TSDB_CODE_SUCCESS != code) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
@ -2876,7 +2864,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod
pInserter->tableId = pModify->tableId;
pInserter->stableId = pModify->stableId;
pInserter->tableType = pModify->tableType;
strcpy(pInserter->tableName, pModify->tableName);
tstrncpy(pInserter->tableName, pModify->tableName, TSDB_TABLE_NAME_LEN);
pInserter->explain = (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pPlanCxt->pAstRoot) ? true : false);
if (pModify->pVgroupList) {
pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId;
@ -2888,9 +2876,6 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod
if (TSDB_CODE_SUCCESS == code) {
pInserter->sink.pInputDataBlockDesc = NULL;
code = nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc, (SNode**)&pInserter->sink.pInputDataBlockDesc);
if (NULL == pInserter->sink.pInputDataBlockDesc) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {
@ -2929,8 +2914,8 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
pDeleter->tableId = pModify->tableId;
pDeleter->tableType = pModify->tableType;
strcpy(pDeleter->tableFName, pModify->tableName);
strcpy(pDeleter->tsColName, pModify->tsColName);
tstrncpy(pDeleter->tableFName, pModify->tableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pDeleter->tsColName, pModify->tsColName, TSDB_COL_NAME_LEN);
pDeleter->deleteTimeRange = pModify->deleteTimeRange;
code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows,
@ -2944,9 +2929,6 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
if (TSDB_CODE_SUCCESS == code) {
pDeleter->sink.pInputDataBlockDesc = NULL;
code = nodesCloneNode((SNode*)pRoot->pOutputDataBlockDesc, (SNode**)&pDeleter->sink.pInputDataBlockDesc);
if (NULL == pDeleter->sink.pInputDataBlockDesc) {
code = code;
}
}
if (TSDB_CODE_SUCCESS == code) {

View File

@ -428,12 +428,12 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex, uint8_t pr
if (NULL == pWStart) {
return code;
}
strcpy(pWStart->functionName, "_wstart");
tstrncpy(pWStart->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWStart;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer);
(void)taosHashBinary(name, len);
strncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN);
pWStart->node.resType.precision = precision;
code = fmGetFuncInfo(pWStart, NULL, 0);
@ -460,12 +460,12 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) {
if (NULL == pWEnd) {
return code;
}
strcpy(pWEnd->functionName, "_wend");
tstrncpy(pWEnd->functionName, "_wend", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWEnd;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWEnd->functionName, pointer);
(void)taosHashBinary(name, len);
strncpy(pWEnd->node.aliasName, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pWEnd->node.aliasName, name, TSDB_COL_NAME_LEN);
code = fmGetFuncInfo(pWEnd, NULL, 0);
if (TSDB_CODE_SUCCESS == code) {
@ -836,9 +836,6 @@ static int32_t stbSplSplitSessionForStream(SSplitContext* pCxt, SStableSplitInfo
nodesDestroyNode(pMergeWin->pTsEnd);
pMergeWin->pTsEnd = NULL;
code = nodesCloneNode(nodesListGetNode(pPartWin->node.pTargets, index), &pMergeWin->pTsEnd);
if (NULL == pMergeWin->pTsEnd) {
code = code;
}
}
code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow);
}
@ -1137,8 +1134,8 @@ static int32_t stbSplAggNodeCreateMerge(SSplitContext* pCtx, SStableSplitInfo* p
if (!nodesEqualNode(pParam, (SNode*)pCol)) continue;
// use the colName of group_key func to make sure finding the right slot id for merge keys.
strcpy(pCol->colName, pFunc->node.aliasName);
strcpy(pCol->node.aliasName, pFunc->node.aliasName);
tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
memset(pCol->tableAlias, 0, TSDB_TABLE_NAME_LEN);
break;
}
@ -1267,15 +1264,15 @@ static int32_t stbSplCreateColumnNode(SExprNode* pExpr, SNode** ppNode) {
return code;
}
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName);
strcpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName);
strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias);
strcpy(pCol->colName, ((SColumnNode*)pExpr)->colName);
tstrncpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName, TSDB_DB_NAME_LEN);
tstrncpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->colName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else {
strcpy(pCol->colName, pExpr->aliasName);
tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
}
strcpy(pCol->node.aliasName, pExpr->aliasName);
strcpy(pCol->node.userAlias, pExpr->userAlias);
tstrncpy(pCol->node.aliasName, pExpr->aliasName, TSDB_COL_NAME_LEN);
tstrncpy(pCol->node.userAlias, pExpr->userAlias, TSDB_COL_NAME_LEN);
pCol->node.resType = pExpr->resType;
*ppNode = (SNode*)pCol;
return code;
@ -1360,9 +1357,6 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOut
int32_t code = TSDB_CODE_SUCCESS;
SSortLogicNode* pPartSort = NULL;
code = nodesCloneNode((SNode*)pSort, (SNode**)&pPartSort);
if (NULL == pPartSort) {
code = code;
}
SNodeList* pMergeKeys = NULL;
if (TSDB_CODE_SUCCESS == code) {
@ -1543,9 +1537,6 @@ static int32_t stbSplCreateMergeScanNode(SScanLogicNode* pScan, SLogicNode** pOu
int32_t code = TSDB_CODE_SUCCESS;
SScanLogicNode* pMergeScan = NULL;
code = nodesCloneNode((SNode*)pScan, (SNode**)&pMergeScan);
if (NULL == pMergeScan) {
code = code;
}
SNodeList* pMergeKeys = NULL;
if (TSDB_CODE_SUCCESS == code) {

View File

@ -68,14 +68,14 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) {
return DEAL_RES_ERROR;
}
pCol->node.resType = pExpr->resType;
strcpy(pCol->colName, pExpr->aliasName);
tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
SFunctionNode* pFunc = (SFunctionNode*)pNode;
if (pFunc->funcType == FUNCTION_TYPE_TBNAME) {
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0);
if (NULL != pVal) {
strcpy(pCol->tableAlias, pVal->literal);
strcpy(pCol->tableName, pVal->literal);
tstrncpy(pCol->tableAlias, pVal->literal, TSDB_TABLE_NAME_LEN);
tstrncpy(pCol->tableName, pVal->literal, TSDB_TABLE_NAME_LEN);
}
}
}
@ -636,9 +636,9 @@ SFunctionNode* createGroupKeyAggFunc(SColumnNode* pGroupCol) {
SFunctionNode* pFunc = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
if (pFunc) {
strcpy(pFunc->functionName, "_group_key");
strcpy(pFunc->node.aliasName, pGroupCol->node.aliasName);
strcpy(pFunc->node.userAlias, pGroupCol->node.userAlias);
tstrncpy(pFunc->functionName, "_group_key", TSDB_FUNC_NAME_LEN);
tstrncpy(pFunc->node.aliasName, pGroupCol->node.aliasName, TSDB_COL_NAME_LEN);
tstrncpy(pFunc->node.userAlias, pGroupCol->node.userAlias, TSDB_COL_NAME_LEN);
SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pGroupCol, &pNew);
if (TSDB_CODE_SUCCESS == code) {
@ -655,7 +655,7 @@ SFunctionNode* createGroupKeyAggFunc(SColumnNode* pGroupCol) {
char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%p", pFunc->functionName, pFunc);
(void)taosHashBinary(name, len);
strncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN - 1);
tstrncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN);
}
}
if (TSDB_CODE_SUCCESS != code) {

View File

@ -634,9 +634,11 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
pInfo->processedVer <= pReq->checkpointVer);
if (!valid) {
stFatal("invalid checkpoint id check, current checkpointId:%" PRId64 " checkpointVer:%" PRId64
" processedVer:%" PRId64 " req checkpointId:%" PRId64 " checkpointVer:%" PRId64,
pInfo->checkpointId, pInfo->checkpointVer, pInfo->processedVer, pReq->checkpointId, pReq->checkpointVer);
stFatal("s-task:%s invalid checkpointId update info recv, current checkpointId:%" PRId64 " checkpointVer:%" PRId64
" processedVer:%" PRId64 " req checkpointId:%" PRId64 " checkpointVer:%" PRId64 " discard it",
id, pInfo->checkpointId, pInfo->checkpointVer, pInfo->processedVer, pReq->checkpointId,
pReq->checkpointVer);
streamMutexUnlock(&pTask->lock);
return TSDB_CODE_STREAM_INTERNAL_ERROR;
}

View File

@ -947,6 +947,7 @@ int32_t recoverSession(SStreamFileState* pFileState, int64_t ckId) {
}
SRowBuffPos* pPos = createSessionWinBuff(pFileState, &key, pVal, &vlen);
pPos->beUsed = false;
winRes = putSessionWinResultBuff(pFileState, pPos);
if (winRes != TSDB_CODE_SUCCESS) {
break;
@ -1008,6 +1009,7 @@ int32_t recoverSnapshot(SStreamFileState* pFileState, int64_t ckId) {
memcpy(pNewPos->pRowBuff, pVal, vlen);
taosMemoryFreeClear(pVal);
pNewPos->beFlushed = true;
pNewPos->beUsed = false;
qDebug("===stream=== read checkpoint state from disc. %s", __func__);
code = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES);
if (code != TSDB_CODE_SUCCESS) {
@ -1090,6 +1092,7 @@ int32_t recoverFillSnapshot(SStreamFileState* pFileState, int64_t ckId) {
if (vlen != pFileState->rowSize) {
qError("row size mismatch, expect:%d, actual:%d", pFileState->rowSize, vlen);
destroyRowBuffPos(pNewPos);
code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
taosMemoryFreeClear(pVal);
QUERY_CHECK_CODE(code, lino, _end);
@ -1098,6 +1101,7 @@ int32_t recoverFillSnapshot(SStreamFileState* pFileState, int64_t ckId) {
memcpy(pNewPos->pRowBuff, pVal, vlen);
taosMemoryFreeClear(pVal);
pNewPos->beFlushed = true;
pNewPos->beUsed = false;
qDebug("===stream=== read checkpoint state from disc. %s", __func__);
winRes = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES);
if (winRes != TSDB_CODE_SUCCESS) {
@ -1228,6 +1232,8 @@ void setFillInfo(SStreamFileState* pFileState) {
}
void clearExpiredState(SStreamFileState* pFileState) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SSHashObj* pSearchBuff = pFileState->searchBuff;
void* pIte = NULL;
int32_t iter = 0;
@ -1246,6 +1252,13 @@ void clearExpiredState(SStreamFileState* pFileState) {
}
taosArrayRemoveBatch(pWinStates, 0, size - 1, NULL);
}
code = clearRowBuff(pFileState);
QUERY_CHECK_CODE(code, lino, _end);
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
}
int32_t getStateSearchRowBuff(SStreamFileState* pFileState, const SWinKey* pKey, void** pVal, int32_t* pVLen,

View File

@ -80,7 +80,7 @@ else
fi
mv ${REP_REAL_PATH}/debug ${WORKDIR}/debugSan
rm -rf ${REP_REAL_PATH}/debug
date
ret=$?

View File

@ -27,7 +27,6 @@ function runCasesOneByOne () {
|| echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
if $case failed
elif [[ "$line" == *"$2"* ]]; then
if [[ "$cmd" == *"pytest.sh"* ]]; then

View File

@ -289,6 +289,64 @@ if $data51 != $query1_data51 then
goto loop3
endi
print ======step3
sql create database test3 vgroups 1;
sql use test3;
sql create stable st(ts timestamp, a int, b int , c int)tags(ta int,tb int,tc int);
sql create table t1 using st tags(1,1,1);
sql create table t2 using st tags(2,2,2);
sql create stream streams3 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt3 as select _wstart, twa(a), ta from st partition by tbname,ta interval(10s);
run tsim/stream/checkTaskStatus.sim
sql insert into t1 values(now + 3000a,1,1,1);
sql flush database test;
sql insert into t1 values(now + 3001a,10,10,10);
sql insert into t1 values(now + 13s,50,50,50);
sleep 1000
print sql select _wstart, twa(a), ta from st partition by tbname,ta interval(10s) order by 1;
sql select _wstart, twa(a), ta from st partition by tbname,ta interval(10s) order by 1;
$query_data01 = $data01
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
$loop_count = 0
loop4:
sleep 2000
$loop_count = $loop_count + 1
if $loop_count == 20 then
return -1
endi
print 2 sql select * from streamt3 order by 1;
sql select * from streamt3 order by 1;
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
if $data01 != $query_data01 then
print ======data01======$data01
print ====query_data01=$query_data01
goto loop4
endi
print end
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -515,6 +515,18 @@ class TDTestCase:
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1")
tdSql.checkRows(1)
tdSql.checkData(0,0,0)
tdSql.query(f"select * from {dbname}.stb1")
rows = tdSql.queryRows
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 or (1<2)")
tdSql.checkRows(rows)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 and (1<2)")
tdSql.checkRows(1)
tdSql.checkData(0,0,0)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 and (1>2)")
tdSql.checkRows(0)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 or (1>2)")
tdSql.checkRows(1)
tdSql.checkData(0,0,0)
tdSql.query(
f"select abs(c1+t1)*t1 from {dbname}.stb1 where abs(c1)/floor(abs(ceil(t1))) ==1")

View File

@ -452,6 +452,73 @@ class TDTestCase:
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(5)
def test_TS_5727(self):
tdSql.execute(f" use {self.dbname} ")
stableName = "test5727"
sql = f"CREATE STABLE {self.dbname}.{stableName} (`ts` TIMESTAMP, `WaterConsumption` FLOAT, \
`ElecConsumption` INT, `Status` BOOL, `status2` BOOL, `online` BOOL) \
TAGS (`ActivationTime` TIMESTAMP, `ProductId` INT, \
`ProductMac` VARCHAR(24), `location` INT)"
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d00` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124710578, 1001, "00:11:22:33:44:55", 100000)'
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d01` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124723572, 1002, "00:12:22:33:44:55", 200000)'
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d02` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124730908, 1003, "00:11:23:33:44:55", 100000)'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d00 values(now - 2s, 5, 5, true, true, false);'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d01 values(now - 1s, 6, 5, true, true, true);'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d02 values(now, 6, 7, true, true, true);'
tdSql.execute(sql)
sql = f'select `location`, tbname from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, 100000)
tdSql.checkData(1, 0, 200000)
tdSql.checkData(2, 0, 100000)
tdSql.checkData(0, 1, "d00")
tdSql.checkData(1, 1, "d01")
tdSql.checkData(2, 1, "d02")
sql = f'select tbname,last(online) as online,location from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, "d00")
tdSql.checkData(1, 0, "d01")
tdSql.checkData(2, 0, "d02")
tdSql.checkData(0, 1, False)
tdSql.checkData(1, 1, True)
tdSql.checkData(2, 1, True)
tdSql.checkData(0, 2, 100000)
tdSql.checkData(1, 2, 200000)
tdSql.checkData(2, 2, 100000)
sql = f'select location,tbname,last_row(online) as online from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, 100000)
tdSql.checkData(1, 0, 200000)
tdSql.checkData(2, 0, 100000)
tdSql.checkData(0, 1, "d00")
tdSql.checkData(1, 1, "d01")
tdSql.checkData(2, 1, "d02")
tdSql.checkData(0, 2, False)
tdSql.checkData(1, 2, True)
tdSql.checkData(2, 2, True)
def run(self):
tdSql.prepare()
self.prepare_db()
@ -494,6 +561,8 @@ class TDTestCase:
self.test_error()
self.test_TS_5727()
def stop(self):
tdSql.close()

View File

@ -64,6 +64,10 @@ class TDTestCase:
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 where c1 is null group by c1 order by c1 desc ")
tdSql.checkRows(1)
tdSql.checkData(0,0,"sub_stb_1")
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 group by c1 order by c1 desc ")
rows = tdSql.queryRows
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 where c1 is null or (1<2) group by c1 order by c1 desc ")
tdSql.checkRows(rows)
tdSql.query(f"select max(c1) ,c2 ,t2,tbname from {dbname}.stb group by abs(c1) order by abs(c1)")
tdSql.checkRows(self.row_nums+1)

View File

@ -75,6 +75,25 @@ class TDTestCase:
tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 9)
tdSql.query(f"select * from {dbname}.stb_1 order by ts")
rows = tdSql.queryRows
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) or (1<2) order by ts")
tdSql.checkRows(rows)
tdSql.query(f"select * from (select * from {dbname}.stb_1 where col1 in (1, 9, 3) or (1<2) order by ts)")
tdSql.checkRows(rows)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) and (1<2) order by ts")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 2)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 9, 3) and (1<2) order by ts")
tdSql.checkRows(3)
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 9)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 9, 3, 'xy') order by ts")
tdSql.checkRows(3)
tdSql.checkData(0, 1, 1)
@ -160,7 +179,7 @@ class TDTestCase:
tdSql.prepare()
self.timeZoneTest()
# self.inAndNotinTest()
self.inAndNotinTest()
def stop(self):

View File

@ -28,6 +28,10 @@ class TDTestCase:
for type_name in stype:
tdsql.execute(f"drop table if exists {dbname}.{stbname}")
tdsql.execute(f"create table if not exists {dbname}.{stbname} (ts timestamp, v1 {type_name}) tags(t1 {type_name})")
tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) or (1<2) order by t1")
tdsql.checkRows(0)
tdsql.execute(f"insert into {dbname}.sub_1 using {dbname}.{stbname} tags(1) values({self.ts}, 10)")
tdsql.execute(f"insert into {dbname}.sub_2 using {dbname}.{stbname} tags(2) values({self.ts + 1000}, 20)")
tdsql.execute(f"insert into {dbname}.sub_3 using {dbname}.{stbname} tags(3) values({self.ts + 2000}, 30)")
@ -36,6 +40,11 @@ class TDTestCase:
tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) order by t1")
tdsql.checkRows(1)
tdsql.checkData(0, 0, 3)
tdsql.query(f"select * from {dbname}.{stbname} where t1 not in (1, 2) or (1<2) order by t1")
tdsql.checkRows(3)
tdsql.checkData(0, 1, 10)
tdsql.checkData(1, 1, 20)
tdsql.checkData(2, 1, 30)
# Test case 2: NOT BETWEEN
tdsql.query(f"select * from {dbname}.{stbname} where v1 not between 10 and 20 order by t1")