[TD-2610]<fix>: fix twa bug in case of all data is NULL.

This commit is contained in:
Haojun Liao 2020-12-29 18:57:52 +08:00
parent fe15fc8a84
commit b64c30cfdb
1 changed files with 6 additions and 2 deletions

View File

@ -3810,11 +3810,15 @@ static void twa_function(SQLFunctionCtx *pCtx) {
// skip null value
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
int32_t i = (pCtx->order == TSDB_ORDER_ASC)? 0:(pCtx->size - 1);
while (pCtx->hasNull && i < pCtx->size && isNull((char *)data + pCtx->inputBytes * i, pCtx->inputType)) {
while (pCtx->hasNull && i < pCtx->size && i >= 0 && isNull((char *)data + pCtx->inputBytes * i, pCtx->inputType)) {
i += step;
}
int32_t notNullElems = twa_function_impl(pCtx, pCtx->startOffset, i, pCtx->size);
int32_t notNullElems = 0;
if (i >= 0 && i < pCtx->size) {
notNullElems = twa_function_impl(pCtx, pCtx->startOffset, i, pCtx->size);
}
SET_VAL(pCtx, notNullElems, 1);
if (notNullElems > 0) {