forbid tsma agg funcs with tag columns

This commit is contained in:
wangjiaming0909 2024-04-08 15:52:24 +08:00
parent 1b37ef03fb
commit 039939196a
5 changed files with 29 additions and 13 deletions

View File

@ -557,6 +557,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
if (cfgAddBool(pCfg, "multiResultFunctionStarReturnTags", tsMultiResultFunctionStarReturnTags, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) != 0) return -1; if (cfgAddBool(pCfg, "multiResultFunctionStarReturnTags", tsMultiResultFunctionStarReturnTags, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) != 0) return -1;
if (cfgAddInt32(pCfg, "countAlwaysReturnValue", tsCountAlwaysReturnValue, 0, 1, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) if (cfgAddInt32(pCfg, "countAlwaysReturnValue", tsCountAlwaysReturnValue, 0, 1, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0)
return -1; return -1;
if (cfgAddInt32(pCfg, "maxTsmaCalcDelay", tsMaxTsmaCalcDelay, 600, 86400, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) !=
0)
return -1;
return 0; return 0;
} }
@ -734,7 +737,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddInt32(pCfg, "tmqRowSize", tmqRowSize, 1, 1000000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != 0) if (cfgAddInt32(pCfg, "tmqRowSize", tmqRowSize, 1, 1000000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != 0)
return -1; return -1;
if (cfgAddInt32(pCfg, "tsMaxTsmaNum", tsMaxTsmaNum, 0, 12, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "maxTsmaNum", tsMaxTsmaNum, 0, 12, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) !=
0) 0)
return -1; return -1;
@ -1206,7 +1209,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tmqMaxTopicNum = cfgGetItem(pCfg, "tmqMaxTopicNum")->i32; tmqMaxTopicNum = cfgGetItem(pCfg, "tmqMaxTopicNum")->i32;
tmqRowSize = cfgGetItem(pCfg, "tmqRowSize")->i32; tmqRowSize = cfgGetItem(pCfg, "tmqRowSize")->i32;
tsMaxTsmaNum = cfgGetItem(pCfg, "tsMaxTsmaNum")->i32; tsMaxTsmaNum = cfgGetItem(pCfg, "maxTsmaNum")->i32;
tsMaxTsmaCalcDelay = cfgGetItem(pCfg, "maxTsmaCalcDelay")->i32;
tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32; tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32;
tsCompactPullupInterval = cfgGetItem(pCfg, "compactPullupInterval")->i32; tsCompactPullupInterval = cfgGetItem(pCfg, "compactPullupInterval")->i32;
@ -1771,7 +1775,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, char *name) {
{"slowLogThreshold", &tsSlowLogThreshold}, {"slowLogThreshold", &tsSlowLogThreshold},
{"useAdapter", &tsUseAdapter}, {"useAdapter", &tsUseAdapter},
{"experimental", &tsExperimental}, {"experimental", &tsExperimental},
{"multiResultFunctionStarReturnTags", &tsMultiResultFunctionStarReturnTags} }; {"multiResultFunctionStarReturnTags", &tsMultiResultFunctionStarReturnTags},
{"maxTsmaCalcDelay", &tsMaxTsmaCalcDelay}};
if (taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true) != 0) { if (taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true) != 0) {
taosCfgSetOption(options, tListLen(options), pItem, false); taosCfgSetOption(options, tListLen(options), pItem, false);

View File

@ -1684,7 +1684,7 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) {
pStream = mndAcquireStream(pMnode, streamName); pStream = mndAcquireStream(pMnode, streamName);
if (pStream != NULL) { if (pStream != NULL) {
mError("tsma:%s, failed to create since stream:%s already exist", createReq.name, streamName); mError("tsma:%s, failed to create since stream:%s already exist", createReq.name, streamName);
terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST; terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST;
goto _OVER; goto _OVER;
} }
@ -1959,9 +1959,9 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
// create sql // create sql
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
char buf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0}; char buf[TSDB_MAX_SAVED_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
len = snprintf(buf + VARSTR_HEADER_SIZE, TSDB_SHOW_SQL_LEN, "%s", pSma->sql); len = snprintf(buf + VARSTR_HEADER_SIZE, TSDB_MAX_SAVED_SQL_LEN, "%s", pSma->sql);
varDataSetLen(buf, TMIN(len, TSDB_SHOW_SQL_LEN)); varDataSetLen(buf, TMIN(len, TSDB_MAX_SAVED_SQL_LEN));
colDataSetVal(pColInfo, numOfRows, buf, false); colDataSetVal(pColInfo, numOfRows, buf, false);
// func list // func list
@ -1974,10 +1974,10 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
if (nodeType(pFunc) == QUERY_NODE_FUNCTION) { if (nodeType(pFunc) == QUERY_NODE_FUNCTION) {
SFunctionNode *pFuncNode = (SFunctionNode *)pFunc; SFunctionNode *pFuncNode = (SFunctionNode *)pFunc;
if (!fmIsTSMASupportedFunc(pFuncNode->funcId)) continue; if (!fmIsTSMASupportedFunc(pFuncNode->funcId)) continue;
len += snprintf(start, TSDB_SHOW_SQL_LEN - len, "%s%s", start != buf + VARSTR_HEADER_SIZE ? "," : "", len += snprintf(start, TSDB_MAX_SAVED_SQL_LEN - len, "%s%s", start != buf + VARSTR_HEADER_SIZE ? "," : "",
((SExprNode *)pFunc)->userAlias); ((SExprNode *)pFunc)->userAlias);
if (len >= TSDB_SHOW_SQL_LEN) { if (len >= TSDB_MAX_SAVED_SQL_LEN) {
len = TSDB_SHOW_SQL_LEN; len = TSDB_MAX_SAVED_SQL_LEN;
break; break;
} }
start = buf + VARSTR_HEADER_SIZE + len; start = buf + VARSTR_HEADER_SIZE + len;

View File

@ -10730,13 +10730,19 @@ static int32_t rewriteTSMAFuncs(STranslateContext* pCxt, SCreateTSMAStmt* pStmt,
break; break;
} }
SColumnNode* pCol = (SColumnNode*)pFunc->pParameterList->pHead->pNode; SColumnNode* pCol = (SColumnNode*)pFunc->pParameterList->pHead->pNode;
for (int32_t i = 0; i < columnNum; ++i) { int32_t i = 0;
for (; i < columnNum; ++i) {
if (strcmp(pCols[i].name, pCol->colName) == 0) { if (strcmp(pCols[i].name, pCol->colName) == 0) {
pCol->colId = pCols[i].colId; pCol->colId = pCols[i].colId;
pCol->node.resType.type = pCols[i].type; pCol->node.resType.type = pCols[i].type;
pCol->node.resType.bytes = pCols[i].bytes; pCol->node.resType.bytes = pCols[i].bytes;
break;
} }
} }
if (i == columnNum) {
code = TSDB_CODE_TSMA_INVALID_FUNC_PARAM;
break;
}
code = fmGetFuncInfo(pFunc, NULL, 0); code = fmGetFuncInfo(pFunc, NULL, 0);
if (TSDB_CODE_SUCCESS != code) break; if (TSDB_CODE_SUCCESS != code) break;
if (!fmIsTSMASupportedFunc(pFunc->funcId)) { if (!fmIsTSMASupportedFunc(pFunc->funcId)) {

View File

@ -691,7 +691,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_PTR, "Invalid tsma pointe
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_PARA, "Invalid tsma parameters") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_PARA, "Invalid tsma parameters")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_TB, "Invalid table to create tsma, only stable or normal table allowed") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_TB, "Invalid table to create tsma, only stable or normal table allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_INTERVAL, "Invalid tsma interval, 1ms ~ 1h is allowed") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_INTERVAL, "Invalid tsma interval, 1ms ~ 1h is allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_FUNC_PARAM, "Invalid tsma func param, only one column allowed") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_FUNC_PARAM, "Invalid tsma func param, only one non-tag column allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_UNSUPPORTED_FUNC, "Tsma func not supported") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_UNSUPPORTED_FUNC, "Tsma func not supported")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_MUST_BE_DROPPED, "Tsma must be dropped first") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_MUST_BE_DROPPED, "Tsma must be dropped first")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_NAME_TOO_LONG, "Tsma name too long") TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_NAME_TOO_LONG, "Tsma name too long")

View File

@ -601,7 +601,7 @@ class TSMATestSQLGenerator:
class TDTestCase: class TDTestCase:
updatecfgDict = {'debugFlag': 143, 'asynclog': 0, 'ttlUnit': 1, 'ttlPushInterval': 5, 'ratioOfVnodeStreamThrea': 4} updatecfgDict = {'debugFlag': 143, 'asynclog': 0, 'ttlUnit': 1, 'ttlPushInterval': 5, 'ratioOfVnodeStreamThrea': 4, 'maxTsmaNum': 8}
def __init__(self): def __init__(self):
self.vgroups = 4 self.vgroups = 4
@ -1323,6 +1323,9 @@ class TDTestCase:
tdSql.error( tdSql.error(
'create tsma tsma1 on meters function(avg(c1), avg(c2)) interval(10m)', -2147482496) 'create tsma tsma1 on meters function(avg(c1), avg(c2)) interval(10m)', -2147482496)
# tsma already exists: test.tsma1
tdSql.error('create tsma tsma1 on nsdb.meters function(avg(c1)) interval(10m)', -2147482496)
# max tsma num 8 # max tsma num 8
self.create_tsma('tsma2', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '10s') self.create_tsma('tsma2', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '10s')
self.create_tsma('tsma3', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '100s') self.create_tsma('tsma3', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '100s')
@ -1344,6 +1347,8 @@ class TDTestCase:
tdSql.error( tdSql.error(
'create tsma tsma1 on test.meters function(avg(c1), avg(c2)) interval(2h)', -2147471097) 'create tsma tsma1 on test.meters function(avg(c1), avg(c2)) interval(2h)', -2147471097)
# only non-tag columns are allowed
tdSql.error('create tsma tsma1 on test.meters function(avg(c1), avg(t6)) interval(10m)', -2147471096)
tdSql.execute('drop database nsdb') tdSql.execute('drop database nsdb')
def test_create_tsma_on_norm_table(self): def test_create_tsma_on_norm_table(self):