This commit is contained in:
wangjiaming0909 2024-04-16 10:44:38 +08:00
parent 1978a06e6e
commit 92e91c2032
3 changed files with 18 additions and 10 deletions

View File

@ -1486,7 +1486,7 @@ static void mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
f.bytes = pExprNode->resType.bytes; f.bytes = pExprNode->resType.bytes;
f.type = pExprNode->resType.type; f.type = pExprNode->resType.type;
f.flags = COL_SMA_ON; f.flags = COL_SMA_ON;
strcpy(f.name, pExprNode->aliasName); strcpy(f.name, pExprNode->userAlias);
taosArrayPush(pCxt->pCreateStreamReq->pCols, &f); taosArrayPush(pCxt->pCreateStreamReq->pCols, &f);
} }
} }

View File

@ -7640,7 +7640,7 @@ static int32_t addWdurationToSampleProjects(SNodeList* pProjectionList) {
return nodesListAppend(pProjectionList, (SNode*)pFunc); return nodesListAppend(pProjectionList, (SNode*)pFunc);
} }
static int32_t buildProjectsForSampleAst(SSampleAstInfo* pInfo, SNodeList** pList) { static int32_t buildProjectsForSampleAst(SSampleAstInfo* pInfo, SNodeList** pList, int32_t *pProjectionTotalLen) {
SNodeList* pProjectionList = pInfo->pFuncs; SNodeList* pProjectionList = pInfo->pFuncs;
pInfo->pFuncs = NULL; pInfo->pFuncs = NULL;
@ -7654,7 +7654,11 @@ static int32_t buildProjectsForSampleAst(SSampleAstInfo* pInfo, SNodeList** pLis
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
SNode* pProject = NULL; SNode* pProject = NULL;
FOREACH(pProject, pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#%p", pProject); } if (pProjectionTotalLen) *pProjectionTotalLen = 0;
FOREACH(pProject, pProjectionList) {
sprintf(((SExprNode*)pProject)->aliasName, "#%p", pProject);
if (pProjectionTotalLen) *pProjectionTotalLen += ((SExprNode*)pProject)->resType.bytes;
}
*pList = pProjectionList; *pList = pProjectionList;
} else { } else {
nodesDestroyList(pProjectionList); nodesDestroyList(pProjectionList);
@ -7682,7 +7686,7 @@ static int32_t buildIntervalForSampleAst(SSampleAstInfo* pInfo, SNode** pOutput)
} }
static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, char** pAst, int32_t* pLen, char** pExpr, static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, char** pAst, int32_t* pLen, char** pExpr,
int32_t* pExprLen) { int32_t* pExprLen, int32_t* pProjectionTotalLen) {
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == pSelect) { if (NULL == pSelect) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
@ -7691,7 +7695,7 @@ static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, ch
int32_t code = buildTableForSampleAst(pInfo, &pSelect->pFromTable); int32_t code = buildTableForSampleAst(pInfo, &pSelect->pFromTable);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildProjectsForSampleAst(pInfo, &pSelect->pProjectionList); code = buildProjectsForSampleAst(pInfo, &pSelect->pProjectionList, pProjectionTotalLen);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
TSWAP(pInfo->pSubTable, pSelect->pSubtable); TSWAP(pInfo->pSubTable, pSelect->pSubtable);
@ -7843,7 +7847,7 @@ static int32_t getRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, SR
SSampleAstInfo info = {0}; SSampleAstInfo info = {0};
int32_t code = buildSampleAstInfoByTable(pCxt, pStmt, pRetension, precision, &info); int32_t code = buildSampleAstInfoByTable(pCxt, pStmt, pRetension, precision, &info);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildSampleAst(pCxt, &info, pAst, pLen, NULL, NULL); code = buildSampleAst(pCxt, &info, pAst, pLen, NULL, NULL, NULL);
} }
clearSampleAstInfo(&info); clearSampleAstInfo(&info);
return code; return code;
@ -8377,7 +8381,7 @@ static int32_t getSmaIndexAst(STranslateContext* pCxt, SCreateIndexStmt* pStmt,
SSampleAstInfo info = {0}; SSampleAstInfo info = {0};
int32_t code = buildSampleAstInfoByIndex(pCxt, pStmt, &info); int32_t code = buildSampleAstInfoByIndex(pCxt, pStmt, &info);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildSampleAst(pCxt, &info, pAst, pLen, pExpr, pExprLen); code = buildSampleAst(pCxt, &info, pAst, pLen, pExpr, pExprLen, NULL);
} }
clearSampleAstInfo(&info); clearSampleAstInfo(&info);
return code; return code;
@ -10676,7 +10680,11 @@ static int32_t buildTSMAAst(STranslateContext* pCxt, SCreateTSMAStmt* pStmt, SMC
code = fmCreateStateFuncs(info.pFuncs); code = fmCreateStateFuncs(info.pFuncs);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = buildSampleAst(pCxt, &info, &pReq->ast, &pReq->astLen, &pReq->expr, &pReq->exprLen); int32_t pProjectionTotalLen = 0;
code = buildSampleAst(pCxt, &info, &pReq->ast, &pReq->astLen, &pReq->expr, &pReq->exprLen, &pProjectionTotalLen);
if (code == TSDB_CODE_SUCCESS && pProjectionTotalLen > TSDB_MAX_BYTES_PER_ROW) {
code = TSDB_CODE_PAR_INVALID_ROW_LENGTH;
}
} }
clearSampleAstInfo(&info); clearSampleAstInfo(&info);
return code; return code;

View File

@ -1260,7 +1260,7 @@ class TDTestCase:
'avg(c1)', 'avg(c2)'], '5m') 'avg(c1)', 'avg(c2)'], '5m')
self.create_recursive_tsma('tsma1', 'tsma2', 'nsdb', '10m', 'meters') self.create_recursive_tsma('tsma1', 'tsma2', 'nsdb', '10m', 'meters')
tdSql.query('select avg(c1) from nsdb.meters', queryTimes=1) tdSql.query('select avg(c1) from nsdb.meters', queryTimes=1)
tdSql.execute('drop database nsdb', queryTimes=1) tdSql.execute('drop database nsdb')
def test_tb_ddl_with_created_tsma(self): def test_tb_ddl_with_created_tsma(self):
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
@ -1472,7 +1472,7 @@ class TDTestCase:
def generate_tsma_function_list_columns(self,max_column: int =4093): def generate_tsma_function_list_columns(self,max_column: int =4093):
columns = [] columns = []
self.tsma_support_func = ["avg", "max", "min", "count", "sum", "first", "last", "spread", "stddev", "hyperloglog"] self.tsma_support_func = ["max", "min", "count", "sum"]
num_items = len(self.tsma_support_func) num_items = len(self.tsma_support_func)
for i in range(max_column): for i in range(max_column):
random_index = secrets.randbelow(num_items) random_index = secrets.randbelow(num_items)