Merge pull request #15181 from taosdata/fix/TD-17511
fix(query): twa function handling null constant or all null column
This commit is contained in:
commit
5a0668dadd
|
@ -165,6 +165,7 @@ typedef struct SElapsedInfo {
|
||||||
|
|
||||||
typedef struct STwaInfo {
|
typedef struct STwaInfo {
|
||||||
double dOutput;
|
double dOutput;
|
||||||
|
bool isNull;
|
||||||
SPoint1 p;
|
SPoint1 p;
|
||||||
STimeWindow win;
|
STimeWindow win;
|
||||||
} STwaInfo;
|
} STwaInfo;
|
||||||
|
@ -5181,6 +5182,7 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STwaInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
STwaInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
pInfo->isNull = false;
|
||||||
pInfo->p.key = INT64_MIN;
|
pInfo->p.key = INT64_MIN;
|
||||||
pInfo->win = TSWINDOW_INITIALIZER;
|
pInfo->win = TSWINDOW_INITIALIZER;
|
||||||
return true;
|
return true;
|
||||||
|
@ -5208,12 +5210,22 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
SPoint1* last = &pInfo->p;
|
SPoint1* last = &pInfo->p;
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
|
||||||
|
if (IS_NULL_TYPE(pInputCol->info.type)) {
|
||||||
|
pInfo->isNull = true;
|
||||||
|
goto _twa_over;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t i = pInput->startRowIndex;
|
int32_t i = pInput->startRowIndex;
|
||||||
if (pCtx->start.key != INT64_MIN) {
|
if (pCtx->start.key != INT64_MIN) {
|
||||||
ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) ||
|
ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) ||
|
||||||
(pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC));
|
(pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC));
|
||||||
|
|
||||||
ASSERT(last->key == INT64_MIN);
|
ASSERT(last->key == INT64_MIN);
|
||||||
|
for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
last->key = tsList[i];
|
last->key = tsList[i];
|
||||||
|
|
||||||
GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
|
GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
|
||||||
|
@ -5222,13 +5234,23 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
pInfo->win.skey = pCtx->start.key;
|
pInfo->win.skey = pCtx->start.key;
|
||||||
numOfElems++;
|
numOfElems++;
|
||||||
i += 1;
|
i += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (pInfo->p.key == INT64_MIN) {
|
} else if (pInfo->p.key == INT64_MIN) {
|
||||||
|
for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
last->key = tsList[i];
|
last->key = tsList[i];
|
||||||
|
|
||||||
GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
|
GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
|
||||||
|
|
||||||
pInfo->win.skey = last->key;
|
pInfo->win.skey = last->key;
|
||||||
numOfElems++;
|
numOfElems++;
|
||||||
i += 1;
|
i += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SPoint1 st = {0};
|
SPoint1 st = {0};
|
||||||
|
@ -5241,6 +5263,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5255,6 +5278,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5268,6 +5292,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5281,6 +5306,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5294,6 +5320,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5307,6 +5334,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5320,6 +5348,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5333,6 +5362,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5346,6 +5376,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5359,6 +5390,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
numOfElems++;
|
||||||
|
|
||||||
INIT_INTP_POINT(st, tsList[i], val[i]);
|
INIT_INTP_POINT(st, tsList[i], val[i]);
|
||||||
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
|
@ -5379,7 +5411,12 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
pInfo->win.ekey = pInfo->p.key;
|
pInfo->win.ekey = pInfo->p.key;
|
||||||
|
|
||||||
SET_VAL(pResInfo, numOfElems, 1);
|
_twa_over:
|
||||||
|
if (numOfElems == 0) {
|
||||||
|
pInfo->isNull = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SET_VAL(pResInfo, 1, 1);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5400,8 +5437,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
|
||||||
STwaInfo* pInfo = (STwaInfo*)GET_ROWCELL_INTERBUF(pResInfo);
|
STwaInfo* pInfo = (STwaInfo*)GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
if (pResInfo->numOfRes == 0) {
|
if (pInfo->isNull == true) {
|
||||||
pResInfo->isNullRes = 1;
|
pResInfo->numOfRes = 0;
|
||||||
} else {
|
} else {
|
||||||
if (pInfo->win.ekey == pInfo->win.skey) {
|
if (pInfo->win.ekey == pInfo->win.skey) {
|
||||||
pInfo->dOutput = pInfo->p.val;
|
pInfo->dOutput = pInfo->p.val;
|
||||||
|
|
|
@ -184,7 +184,7 @@ class TDTestCase:
|
||||||
|
|
||||||
tdSql.query("select c1 , twa(c1) from stb partition by c1 order by c1")
|
tdSql.query("select c1 , twa(c1) from stb partition by c1 order by c1")
|
||||||
tdSql.checkRows(11)
|
tdSql.checkRows(11)
|
||||||
tdSql.checkData(0,1,0.000000000)
|
tdSql.checkData(0,1,None)
|
||||||
|
|
||||||
tdSql.query("select c1 , irate(c1) from stb partition by c1 order by c1")
|
tdSql.query("select c1 , irate(c1) from stb partition by c1 order by c1")
|
||||||
tdSql.checkRows(11)
|
tdSql.checkRows(11)
|
||||||
|
|
Loading…
Reference in New Issue