未验证 提交 888616f3 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #17876 from taosdata/fix/TD-20140

fix(query): fix countAlwaysReturnValue param not taking effect for count and hyperloglog
......@@ -181,6 +181,7 @@ typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinT
typedef struct SHLLFuncInfo {
uint64_t result;
uint64_t totalCount;
uint8_t buckets[HLL_BUCKETS];
} SHLLInfo;
......@@ -551,7 +552,7 @@ int32_t countFunction(SqlFunctionCtx* pCtx) {
if (tsCountAlwaysReturnValue) {
pResInfo->numOfRes = 1;
} else {
SET_VAL(pResInfo, 1, 1);
SET_VAL(pResInfo, *((int64_t*)buf), 1);
}
return TSDB_CODE_SUCCESS;
......@@ -4605,7 +4606,14 @@ int32_t hllFunction(SqlFunctionCtx* pCtx) {
}
}
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
pInfo->totalCount += numOfElems;
if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) {
SET_VAL(GET_RES_INFO(pCtx), 0, 1);
} else {
SET_VAL(GET_RES_INFO(pCtx), 1, 1);
}
return TSDB_CODE_SUCCESS;
}
......@@ -4615,6 +4623,7 @@ static void hllTransferInfo(SHLLInfo* pInput, SHLLInfo* pOutput) {
pOutput->buckets[k] = pInput->buckets[k];
}
}
pOutput->totalCount += pInput->totalCount;
}
int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) {
......@@ -4632,7 +4641,12 @@ int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) {
hllTransferInfo(pInputInfo, pInfo);
}
if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) {
SET_VAL(GET_RES_INFO(pCtx), 0, 1);
} else {
SET_VAL(GET_RES_INFO(pCtx), 1, 1);
}
return TSDB_CODE_SUCCESS;
}
......
......@@ -241,7 +241,11 @@ bool fmIsNotNullOutputFunc(int32_t funcId) {
FUNCTION_TYPE_LAST_MERGE == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_FIRST == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_FIRST_PARTIAL == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type;
FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_COUNT == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_HYPERLOGLOG == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_HYPERLOGLOG_PARTIAL == funcMgtBuiltins[funcId].type ||
FUNCTION_TYPE_HYPERLOGLOG_MERGE == funcMgtBuiltins[funcId].type;
}
bool fmIsSelectValueFunc(int32_t funcId) {
......
import taos
import sys
import datetime
import inspect
from util.log import *
from util.sql import *
from util.cases import *
import random
class TDTestCase:
updatecfgDict = {"countAlwaysReturnValue":0}
def init(self, conn, logSql, replicaVar=1):
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(), False)
def prepare_data(self, dbname="db"):
tdSql.execute(
f"create database if not exists {dbname} keep 3650 duration 1000")
tdSql.execute(f"use {dbname} ")
tdSql.execute(
f"create table {dbname}.tb (ts timestamp, c0 int)"
)
tdSql.execute(
f"create table {dbname}.stb (ts timestamp, c0 int) tags (t0 int)"
)
tdSql.execute(
f"create table {dbname}.ctb1 using {dbname}.stb tags (1)"
)
tdSql.execute(
f"create table {dbname}.ctb2 using {dbname}.stb tags (2)"
)
tdSql.execute(
f"insert into {dbname}.tb values (now(), NULL)")
tdSql.execute(
f"insert into {dbname}.ctb1 values (now(), NULL)")
tdSql.execute(
f"insert into {dbname}.ctb2 values (now() + 1s, NULL)")
def test_results(self, dbname="db"):
# count
tdSql.query(f"select count(c0) from {dbname}.tb")
tdSql.checkRows(0)
tdSql.query(f"select count(NULL) from {dbname}.tb")
tdSql.checkRows(0)
tdSql.query(f"select c0,count(c0) from {dbname}.tb group by c0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query(f"select count(c0) from {dbname}.stb")
tdSql.checkRows(0)
tdSql.query(f"select count(NULL) from {dbname}.stb")
tdSql.checkRows(0)
tdSql.query(f"select c0,count(c0) from {dbname}.stb group by c0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query(f"select count(NULL)")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 0)
# hyperloglog
tdSql.query(f"select hyperloglog(c0) from {dbname}.tb")
tdSql.checkRows(0)
tdSql.query(f"select hyperloglog(NULL) from {dbname}.tb")
tdSql.checkRows(0)
tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.tb group by c0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query(f"select hyperloglog(c0) from {dbname}.stb")
tdSql.checkRows(0)
tdSql.query(f"select hyperloglog(NULL) from {dbname}.stb")
tdSql.checkRows(0)
tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.stb group by c0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
tdSql.query(f"select hyperloglog(NULL)")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 0)
def run(self):
tdSql.prepare()
tdLog.printNoPrefix("==========step1:prepare data ==============")
self.prepare_data()
tdLog.printNoPrefix("==========step2:test results ==============")
self.test_results()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())
......@@ -76,6 +76,8 @@ python3 ./test.py -f 2-query/count_partition.py
python3 ./test.py -f 2-query/count_partition.py -R
python3 ./test.py -f 2-query/count.py
python3 ./test.py -f 2-query/count.py -R
python3 ./test.py -f 2-query/countAlwaysReturnValue.py
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -R
python3 ./test.py -f 2-query/db.py
python3 ./test.py -f 2-query/db.py -R
python3 ./test.py -f 2-query/diff.py
......@@ -385,6 +387,7 @@ python3 ./test.py -f 2-query/Today.py -Q 2
python3 ./test.py -f 2-query/max.py -Q 2
python3 ./test.py -f 2-query/min.py -Q 2
python3 ./test.py -f 2-query/count.py -Q 2
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2
python3 ./test.py -f 2-query/last.py -Q 2
python3 ./test.py -f 2-query/first.py -Q 2
python3 ./test.py -f 2-query/To_iso8601.py -Q 2
......@@ -480,6 +483,7 @@ python3 ./test.py -f 2-query/Today.py -Q 3
python3 ./test.py -f 2-query/max.py -Q 3
python3 ./test.py -f 2-query/min.py -Q 3
python3 ./test.py -f 2-query/count.py -Q 3
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3
python3 ./test.py -f 2-query/last.py -Q 3
python3 ./test.py -f 2-query/first.py -Q 3
python3 ./test.py -f 2-query/To_iso8601.py -Q 3
......@@ -577,6 +581,7 @@ python3 ./test.py -f 2-query/Today.py -Q 4
python3 ./test.py -f 2-query/max.py -Q 4
python3 ./test.py -f 2-query/min.py -Q 4
python3 ./test.py -f 2-query/count.py -Q 4
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4
python3 ./test.py -f 2-query/last.py -Q 4
python3 ./test.py -f 2-query/first.py -Q 4
python3 ./test.py -f 2-query/To_iso8601.py -Q 4
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册