diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9b18453d7b134c998c3aec6c19f6379b366f895d..03fb89d36872f58dfbd7b027bfafa625921f76a1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3637,6 +3637,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool int32_t prjNum = 0; int32_t aggNum = 0; int32_t scalNum = 0; + int32_t countTbname = 0; size_t numOfExpr = tscNumOfExprs(pQueryInfo); assert(numOfExpr > 0); @@ -3691,9 +3692,13 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool if (functionId == TSDB_FUNC_LAST_ROW && (joinQuery || twQuery || !groupbyTagsOrNull(pQueryInfo))) { return false; } + + if (functionId == TSDB_FUNC_COUNT && (pExpr1->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX || TSDB_COL_IS_TAG(pExpr1->base.colInfo.flag))) { + ++countTbname; + } } - aggNum = (int32_t)size - prjNum - scalNum - aggUdf - scalarUdf; + aggNum = (int32_t)size - prjNum - scalNum - aggUdf - scalarUdf - countTbname; assert(aggNum >= 0); @@ -3709,6 +3714,10 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool return false; } + if (countTbname && (prjNum > 0 || aggNum > 0 || scalarUdf > 0 || aggUdf > 0)) { + return false; + } + return true; } diff --git a/tests/pytest/query/queryCnameDisplay.py b/tests/pytest/query/queryCnameDisplay.py index 66a7f85120fe13293996d1bd3153b6fe9b1d6a72..186b3bfe1d1d06c4210c950fff097cb37a73d5df 100644 --- a/tests/pytest/query/queryCnameDisplay.py +++ b/tests/pytest/query/queryCnameDisplay.py @@ -79,16 +79,22 @@ class TDTestCase: tdSql.execute('insert into st1 values (now, 1, 2, 1.1, 2.2, "a", 1, 1, false, "bb");') # select as cname with cname_list - sql_seq = f'select count(ts) as {cname_list[0]}, sum(pi1) as {cname_list[1]}, avg(pi2) as {cname_list[2]}, count(pf1) as {cname_list[3]}, count(pf2) as {cname_list[4]}, count(ps1) as {cname_list[5]}, min(pi3) as {cname_list[6]}, max(pi4) as {cname_list[7]}, count(pb1) as {cname_list[8]}, count(ps2) as {cname_list[9]}, count(si1) as {cname_list[10]}, count(si2) as {cname_list[11]}, count(sf1) as {cname_list[12]}, count(sf2) as {cname_list[13]}, count(ss1) as {cname_list[14]}, count(si3) as {cname_list[15]}, count(si4) as {cname_list[16]}, count(sb1) as {cname_list[17]}, count(ss2) as {cname_list[18]} from super_table_cname_check' - sql_seq_no_as = sql_seq.replace(' as ', ' ') - res = tdSql.getColNameList(sql_seq) - res_no_as = tdSql.getColNameList(sql_seq_no_as) + sql_seq1 = f'select count(ts) as {cname_list[0]}, sum(pi1) as {cname_list[1]}, avg(pi2) as {cname_list[2]}, count(pf1) as {cname_list[3]}, count(pf2) as {cname_list[4]}, count(ps1) as {cname_list[5]}, min(pi3) as {cname_list[6]}, max(pi4) as {cname_list[7]}, count(pb1) as {cname_list[8]}, count(ps2) as {cname_list[9]} from super_table_cname_check' + sql_seq2 = f'select count(si1) as {cname_list[10]}, count(si2) as {cname_list[11]}, count(sf1) as {cname_list[12]}, count(sf2) as {cname_list[13]}, count(ss1) as {cname_list[14]}, count(si3) as {cname_list[15]}, count(si4) as {cname_list[16]}, count(sb1) as {cname_list[17]}, count(ss2) as {cname_list[18]} from super_table_cname_check' + sql_seq_no_as1 = sql_seq1.replace(' as ', ' ') + sql_seq_no_as2 = sql_seq2.replace(' as ', ' ') + res1 = tdSql.getColNameList(sql_seq1) + res2 = tdSql.getColNameList(sql_seq2) + res_no_as1 = tdSql.getColNameList(sql_seq_no_as1) + res_no_as2 = tdSql.getColNameList(sql_seq_no_as2) # cname[1] > 64, it is expected to be equal to 64 cname_list_1_expected = cname_list[1][:-1] cname_list[1] = cname_list_1_expected - checkColNameList = tdSql.checkColNameList(res, cname_list) - checkColNameList = tdSql.checkColNameList(res_no_as, cname_list) + tdSql.checkColNameList(res1, cname_list[:10]) + tdSql.checkColNameList(res2, cname_list[10:]) + tdSql.checkColNameList(res_no_as1, cname_list[:10]) + tdSql.checkColNameList(res_no_as2, cname_list[10:]) def run(self): tdSql.prepare()