[td-2895] refactor.
This commit is contained in:
parent
75a45e3f5a
commit
a260707c46
|
@ -4092,17 +4092,49 @@ static void interp_function_impl(SQLFunctionCtx *pCtx) {
|
||||||
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
|
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
|
||||||
} else {
|
} else {
|
||||||
if (pCtx->start.key != INT64_MIN && pCtx->start.key < pCtx->startTs && pCtx->end.key > pCtx->startTs) {
|
if (pCtx->start.key != INT64_MIN && pCtx->start.key < pCtx->startTs && pCtx->end.key > pCtx->startTs) {
|
||||||
// the value of prev/next/linear interpolation is placed in pCtx->start
|
if (type == TSDB_FILL_PREV) {
|
||||||
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
|
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
|
||||||
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val);
|
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val);
|
||||||
} else {
|
} else {
|
||||||
assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType);
|
assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType);
|
||||||
}
|
}
|
||||||
|
} else if (type == TSDB_FILL_NEXT) {
|
||||||
|
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
|
||||||
|
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->end.val);
|
||||||
} else {
|
} else {
|
||||||
|
assignVal(pCtx->pOutput, pCtx->end.ptr, pCtx->outputBytes, pCtx->inputType);
|
||||||
|
}
|
||||||
|
} else if (type == TSDB_FILL_LINEAR) {
|
||||||
|
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val};
|
||||||
|
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val};
|
||||||
|
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
|
||||||
|
|
||||||
|
int32_t srcType = pCtx->inputType;
|
||||||
|
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data?
|
||||||
|
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
|
||||||
|
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
|
||||||
|
} else {
|
||||||
|
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no data generated yet
|
||||||
|
if (pCtx->size == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check the timestamp in input buffer
|
// check the timestamp in input buffer
|
||||||
TSKEY skey = GET_TS_DATA(pCtx, 0);
|
TSKEY skey = GET_TS_DATA(pCtx, 0);
|
||||||
TSKEY ekey = GET_TS_DATA(pCtx, 1);
|
TSKEY ekey = GET_TS_DATA(pCtx, 1);
|
||||||
|
|
||||||
|
// no data generated yet
|
||||||
|
if (!(skey < pCtx->startTs && ekey > pCtx->startTs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(pCtx->start.key == INT64_MIN && skey < pCtx->startTs && ekey > pCtx->startTs);
|
assert(pCtx->start.key == INT64_MIN && skey < pCtx->startTs && ekey > pCtx->startTs);
|
||||||
|
|
||||||
if (type == TSDB_FILL_PREV) {
|
if (type == TSDB_FILL_PREV) {
|
||||||
|
@ -4114,8 +4146,6 @@ static void interp_function_impl(SQLFunctionCtx *pCtx) {
|
||||||
char *start = GET_INPUT_DATA(pCtx, 0);
|
char *start = GET_INPUT_DATA(pCtx, 0);
|
||||||
char *end = GET_INPUT_DATA(pCtx, 1);
|
char *end = GET_INPUT_DATA(pCtx, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SPoint point1 = {.key = skey, .val = start};
|
SPoint point1 = {.key = skey, .val = start};
|
||||||
SPoint point2 = {.key = ekey, .val = end};
|
SPoint point2 = {.key = ekey, .val = end};
|
||||||
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
|
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
|
||||||
|
|
|
@ -1894,8 +1894,7 @@ _clean:
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doFreeQueryHandle(SQInfo* pQInfo) {
|
static void doFreeQueryHandle(SQueryRuntimeEnv* pRuntimeEnv) {
|
||||||
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
|
|
||||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||||
|
|
||||||
tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
|
tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle);
|
||||||
|
@ -1923,7 +1922,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
pRuntimeEnv->pFillInfo = taosDestroyFillInfo(pRuntimeEnv->pFillInfo);
|
pRuntimeEnv->pFillInfo = taosDestroyFillInfo(pRuntimeEnv->pFillInfo);
|
||||||
|
|
||||||
destroyResultBuf(pRuntimeEnv->pResultBuf);
|
destroyResultBuf(pRuntimeEnv->pResultBuf);
|
||||||
doFreeQueryHandle(pQInfo);
|
doFreeQueryHandle(pRuntimeEnv);
|
||||||
|
|
||||||
pRuntimeEnv->pTsBuf = tsBufDestroy(pRuntimeEnv->pTsBuf);
|
pRuntimeEnv->pTsBuf = tsBufDestroy(pRuntimeEnv->pTsBuf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue