add NULL logic for _group_key

This commit is contained in:
Ganlin Zhao 2022-06-24 20:26:46 +08:00
parent f8bb36ce2c
commit 5c3fae340e
3 changed files with 29 additions and 7 deletions

View File

@ -204,6 +204,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t groupKeyFunction(SqlFunctionCtx* pCtx); int32_t groupKeyFunction(SqlFunctionCtx* pCtx);
int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -2518,7 +2518,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.getEnvFunc = getGroupKeyFuncEnv, .getEnvFunc = getGroupKeyFuncEnv,
.initFunc = functionSetup, .initFunc = functionSetup,
.processFunc = groupKeyFunction, .processFunc = groupKeyFunction,
.finalizeFunc = functionFinalize, .finalizeFunc = groupKeyFinalize,
}, },
}; };
// clang-format on // clang-format on

View File

@ -262,6 +262,12 @@ typedef struct SRateInfo {
int8_t hasResult; // flag to denote has value int8_t hasResult; // flag to denote has value
} SRateInfo; } SRateInfo;
typedef struct SGroupKeyInfo{
bool hasResult;
char data[];
} SGroupKeyInfo;
#define SET_VAL(_info, numOfElem, res) \ #define SET_VAL(_info, numOfElem, res) \
do { \ do { \
if ((numOfElem) <= 0) { \ if ((numOfElem) <= 0) { \
@ -2404,7 +2410,7 @@ bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0); SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
pEnv->calcMemSize = pNode->node.resType.bytes; pEnv->calcMemSize = sizeof(SGroupKeyInfo) + pNode->node.resType.bytes;
return true; return true;
} }
@ -5357,7 +5363,7 @@ int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t groupKeyFunction(SqlFunctionCtx* pCtx) { int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
char* buf = GET_ROWCELL_INTERBUF(pResInfo); SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
SInputColumnInfoData* pInput = &pCtx->input; SInputColumnInfoData* pInput = &pCtx->input;
SColumnInfoData* pInputCol = pInput->pData[0]; SColumnInfoData* pInputCol = pInput->pData[0];
@ -5366,17 +5372,32 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
int32_t startIndex = pInput->startRowIndex; int32_t startIndex = pInput->startRowIndex;
if (colDataIsNull_s(pInputCol, startIndex)) { if (colDataIsNull_s(pInputCol, startIndex)) {
pResInfo->numOfRes = 0; pInfo->hasResult = false;
return TSDB_CODE_SUCCESS; goto _group_key_over;
} }
pInfo->hasResult = true;
char* data = colDataGetData(pInputCol, startIndex); char* data = colDataGetData(pInputCol, startIndex);
memcpy(buf, data, bytes); memcpy(pInfo->data, data, bytes);
SET_VAL(pResInfo, 1, 1);
_group_key_over:
SET_VAL(pResInfo, 1, 1);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
colDataAppend(pCol, pBlock->info.rows, pInfo->data, pInfo->hasResult ? false : true);
return pResInfo->numOfRes;
}
int32_t interpFunction(SqlFunctionCtx* pCtx) { int32_t interpFunction(SqlFunctionCtx* pCtx) {
#if 0 #if 0
int32_t fillType = (int32_t) pCtx->param[2].i64; int32_t fillType = (int32_t) pCtx->param[2].i64;