From 4aa7802e5e2b5c5d4ae6262917972d44301fb10d Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Mon, 26 Sep 2022 16:23:38 +0800 Subject: [PATCH] feat(query): select count return value if no rows --- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 11 +++++++++++ src/query/src/qAggMain.c | 6 +++--- src/util/inc/tconfig.h | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 650bb6bb4e..80cef9a893 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -219,6 +219,7 @@ extern int32_t cqDebugFlag; extern int32_t debugFlag; extern int8_t tsClientMerge; +extern int8_t tsCountAlwaysReturnValue; // probe alive connection extern int32_t tsProbeSeconds; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 6260b22c81..41419cbc4e 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -273,6 +273,7 @@ int32_t cqDebugFlag = 131; int32_t fsDebugFlag = 135; int8_t tsClientMerge = 0; +int8_t tsCountAlwaysReturnValue = 0; // probe alive connection int32_t tsProbeSeconds = 5 * 60; // start probe link alive after tsProbeSeconds from starting query @@ -1690,6 +1691,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "countAlwaysReturnValue"; + cfg.ptr = &tsCountAlwaysReturnValue; + cfg.valType = TAOS_CFG_VTYPE_INT8; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + // default JSON string type option "binary"/"nchar" cfg.option = "defaultJSONStrType"; cfg.ptr = tsDefaultJSONStrType; diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index d12bb28ab8..e8c0c8c3b8 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -936,12 +936,12 @@ static void count_function(SQLFunctionCtx *pCtx) { } } - if (numOfElem > 0) { + if (numOfElem > 0 || tsCountAlwaysReturnValue) { GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; + *((int64_t *)pCtx->pOutput) += numOfElem; + pCtx->resultInfo->numOfRes = 1; } - *((int64_t *)pCtx->pOutput) += numOfElem; - SET_VAL(pCtx, numOfElem, 1); } static void count_func_merge(SQLFunctionCtx *pCtx) { diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index a2c2937722..cd46d51de1 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define TSDB_CFG_MAX_NUM 136 +#define TSDB_CFG_MAX_NUM 137 #define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_VALUE_LEN 41 -- GitLab