Merge pull request #17972 from taosdata/fix/TD-20246
refactor: optimize interp linear interpolation ignore NULL values during calculation
This commit is contained in:
commit
d3a75048c2
|
@ -776,7 +776,6 @@ typedef struct STimeSliceOperatorInfo {
|
||||||
SArray* pPrevRow; // SArray<SGroupValue>
|
SArray* pPrevRow; // SArray<SGroupValue>
|
||||||
SArray* pNextRow; // SArray<SGroupValue>
|
SArray* pNextRow; // SArray<SGroupValue>
|
||||||
SArray* pLinearInfo; // SArray<SFillLinearInfo>
|
SArray* pLinearInfo; // SArray<SFillLinearInfo>
|
||||||
bool fillLastPoint;
|
|
||||||
bool isPrevRowSet;
|
bool isPrevRowSet;
|
||||||
bool isNextRowSet;
|
bool isNextRowSet;
|
||||||
int32_t fillType; // fill type
|
int32_t fillType; // fill type
|
||||||
|
|
|
@ -36,7 +36,8 @@ typedef struct SFillColInfo {
|
||||||
typedef struct SFillLinearInfo {
|
typedef struct SFillLinearInfo {
|
||||||
SPoint start;
|
SPoint start;
|
||||||
SPoint end;
|
SPoint end;
|
||||||
bool hasNull;
|
bool isStartSet;
|
||||||
|
bool isEndSet;
|
||||||
int16_t type;
|
int16_t type;
|
||||||
int32_t bytes;
|
int32_t bytes;
|
||||||
} SFillLinearInfo;
|
} SFillLinearInfo;
|
||||||
|
|
|
@ -1942,10 +1942,8 @@ static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||||
|
|
||||||
// null data should not be kept since it can not be used to perform interpolation
|
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, i);
|
||||||
if (!colDataIsNull_s(pColInfoData, i)) {
|
if (!colDataIsNull_s(pColInfoData, rowIndex)) {
|
||||||
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, i);
|
|
||||||
|
|
||||||
pkey->isNull = false;
|
pkey->isNull = false;
|
||||||
char* val = colDataGetData(pColInfoData, rowIndex);
|
char* val = colDataGetData(pColInfoData, rowIndex);
|
||||||
if (!IS_VAR_DATA_TYPE(pkey->type)) {
|
if (!IS_VAR_DATA_TYPE(pkey->type)) {
|
||||||
|
@ -1953,6 +1951,8 @@ static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock
|
||||||
} else {
|
} else {
|
||||||
memcpy(pkey->pData, val, varDataLen(val));
|
memcpy(pkey->pData, val, varDataLen(val));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pkey->isNull = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1964,10 +1964,8 @@ static void doKeepNextRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||||
|
|
||||||
// null data should not be kept since it can not be used to perform interpolation
|
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pNextRow, i);
|
||||||
if (!colDataIsNull_s(pColInfoData, i)) {
|
if (!colDataIsNull_s(pColInfoData, rowIndex)) {
|
||||||
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pNextRow, i);
|
|
||||||
|
|
||||||
pkey->isNull = false;
|
pkey->isNull = false;
|
||||||
char* val = colDataGetData(pColInfoData, rowIndex);
|
char* val = colDataGetData(pColInfoData, rowIndex);
|
||||||
if (!IS_VAR_DATA_TYPE(pkey->type)) {
|
if (!IS_VAR_DATA_TYPE(pkey->type)) {
|
||||||
|
@ -1975,50 +1973,51 @@ static void doKeepNextRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock
|
||||||
} else {
|
} else {
|
||||||
memcpy(pkey->pData, val, varDataLen(val));
|
memcpy(pkey->pData, val, varDataLen(val));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pkey->isNull = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSliceInfo->isNextRowSet = true;
|
pSliceInfo->isNextRowSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doKeepLinearInfo(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock* pBlock, int32_t rowIndex,
|
static void doKeepLinearInfo(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock* pBlock, int32_t rowIndex) {
|
||||||
bool isLastRow) {
|
|
||||||
int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||||
bool fillLastPoint = pSliceInfo->fillLastPoint;
|
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||||
SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, pSliceInfo->tsCol.slotId);
|
SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, pSliceInfo->tsCol.slotId);
|
||||||
SFillLinearInfo* pLinearInfo = taosArrayGet(pSliceInfo->pLinearInfo, i);
|
SFillLinearInfo* pLinearInfo = taosArrayGet(pSliceInfo->pLinearInfo, i);
|
||||||
|
|
||||||
// null data should not be kept since it can not be used to perform interpolation
|
// null value is represented by using key = INT64_MIN for now.
|
||||||
if (!colDataIsNull_s(pColInfoData, i)) {
|
// TODO: optimize to ignore null values for linear interpolation.
|
||||||
if (isLastRow) {
|
if (!pLinearInfo->isStartSet) {
|
||||||
|
if (!colDataIsNull_s(pColInfoData, rowIndex)) {
|
||||||
pLinearInfo->start.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
pLinearInfo->start.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
||||||
memcpy(pLinearInfo->start.val, colDataGetData(pColInfoData, rowIndex), pLinearInfo->bytes);
|
memcpy(pLinearInfo->start.val, colDataGetData(pColInfoData, rowIndex), pLinearInfo->bytes);
|
||||||
} else if (fillLastPoint) {
|
}
|
||||||
|
pLinearInfo->isStartSet = true;
|
||||||
|
} else if (!pLinearInfo->isEndSet) {
|
||||||
|
if (!colDataIsNull_s(pColInfoData, rowIndex)) {
|
||||||
|
pLinearInfo->end.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
||||||
|
memcpy(pLinearInfo->end.val, colDataGetData(pColInfoData, rowIndex), pLinearInfo->bytes);
|
||||||
|
}
|
||||||
|
pLinearInfo->isEndSet = true;
|
||||||
|
} else {
|
||||||
|
pLinearInfo->start.key = pLinearInfo->end.key;
|
||||||
|
memcpy(pLinearInfo->start.val, pLinearInfo->end.val, pLinearInfo->bytes);
|
||||||
|
|
||||||
|
if (!colDataIsNull_s(pColInfoData, rowIndex)) {
|
||||||
pLinearInfo->end.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
pLinearInfo->end.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
||||||
memcpy(pLinearInfo->end.val, colDataGetData(pColInfoData, rowIndex), pLinearInfo->bytes);
|
memcpy(pLinearInfo->end.val, colDataGetData(pColInfoData, rowIndex), pLinearInfo->bytes);
|
||||||
} else {
|
} else {
|
||||||
pLinearInfo->start.key = *(int64_t*)colDataGetData(pTsCol, rowIndex);
|
pLinearInfo->end.key = INT64_MIN;
|
||||||
pLinearInfo->end.key = *(int64_t*)colDataGetData(pTsCol, rowIndex + 1);
|
|
||||||
|
|
||||||
char* val;
|
|
||||||
val = colDataGetData(pColInfoData, rowIndex);
|
|
||||||
memcpy(pLinearInfo->start.val, val, pLinearInfo->bytes);
|
|
||||||
val = colDataGetData(pColInfoData, rowIndex + 1);
|
|
||||||
memcpy(pLinearInfo->end.val, val, pLinearInfo->bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pLinearInfo->hasNull = false;
|
|
||||||
} else {
|
|
||||||
pLinearInfo->hasNull = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSliceInfo->fillLastPoint = isLastRow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp* pExprSup, SSDataBlock* pResBlock) {
|
static bool genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp* pExprSup, SSDataBlock* pResBlock, bool beforeTs) {
|
||||||
int32_t rows = pResBlock->info.rows;
|
int32_t rows = pResBlock->info.rows;
|
||||||
blockDataEnsureCapacity(pResBlock, rows + 1);
|
blockDataEnsureCapacity(pResBlock, rows + 1);
|
||||||
// todo set the correct primary timestamp column
|
// todo set the correct primary timestamp column
|
||||||
|
@ -2037,7 +2036,6 @@ static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
||||||
// SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot);
|
|
||||||
switch (pSliceInfo->fillType) {
|
switch (pSliceInfo->fillType) {
|
||||||
case TSDB_FILL_NULL: {
|
case TSDB_FILL_NULL: {
|
||||||
colDataAppendNULL(pDst, rows);
|
colDataAppendNULL(pDst, rows);
|
||||||
|
@ -2069,21 +2067,26 @@ static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
||||||
SPoint start = pLinearInfo->start;
|
SPoint start = pLinearInfo->start;
|
||||||
SPoint end = pLinearInfo->end;
|
SPoint end = pLinearInfo->end;
|
||||||
SPoint current = {.key = pSliceInfo->current};
|
SPoint current = {.key = pSliceInfo->current};
|
||||||
current.val = taosMemoryCalloc(pLinearInfo->bytes, 1);
|
|
||||||
|
|
||||||
// before interp range, do not fill
|
// do not interpolate before ts range, only increate pSliceInfo->current
|
||||||
if (start.key == INT64_MIN || end.key == INT64_MAX) {
|
if (beforeTs && !pLinearInfo->isEndSet) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pLinearInfo->isStartSet || !pLinearInfo->isEndSet) {
|
||||||
hasInterp = false;
|
hasInterp = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pLinearInfo->hasNull) {
|
if (start.key == INT64_MIN || end.key == INT64_MIN) {
|
||||||
colDataAppendNULL(pDst, rows);
|
colDataAppendNULL(pDst, rows);
|
||||||
} else {
|
break;
|
||||||
taosGetLinearInterpolationVal(¤t, pLinearInfo->type, &start, &end, pLinearInfo->type);
|
|
||||||
colDataAppend(pDst, rows, (char*)current.val, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current.val = taosMemoryCalloc(pLinearInfo->bytes, 1);
|
||||||
|
taosGetLinearInterpolationVal(¤t, pLinearInfo->type, &start, &end, pLinearInfo->type);
|
||||||
|
colDataAppend(pDst, rows, (char*)current.val, false);
|
||||||
|
|
||||||
taosMemoryFree(current.val);
|
taosMemoryFree(current.val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2094,7 +2097,11 @@ static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
||||||
}
|
}
|
||||||
|
|
||||||
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, srcSlot);
|
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, srcSlot);
|
||||||
colDataAppend(pDst, rows, pkey->pData, false);
|
if (pkey->isNull == false) {
|
||||||
|
colDataAppend(pDst, rows, pkey->pData, false);
|
||||||
|
} else {
|
||||||
|
colDataAppendNULL(pDst, rows);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2105,7 +2112,11 @@ static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
||||||
}
|
}
|
||||||
|
|
||||||
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pNextRow, srcSlot);
|
SGroupKeys* pkey = taosArrayGet(pSliceInfo->pNextRow, srcSlot);
|
||||||
colDataAppend(pDst, rows, pkey->pData, false);
|
if (pkey->isNull == false) {
|
||||||
|
colDataAppend(pDst, rows, pkey->pData, false);
|
||||||
|
} else {
|
||||||
|
colDataAppendNULL(pDst, rows);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2118,8 +2129,40 @@ static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp
|
||||||
if (hasInterp) {
|
if (hasInterp) {
|
||||||
pResBlock->info.rows += 1;
|
pResBlock->info.rows += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hasInterp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addCurrentRowToResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp* pExprSup, SSDataBlock* pResBlock,
|
||||||
|
SSDataBlock* pSrcBlock, int32_t index) {
|
||||||
|
blockDataEnsureCapacity(pResBlock, pResBlock->info.rows + 1);
|
||||||
|
for (int32_t j = 0; j < pExprSup->numOfExprs; ++j) {
|
||||||
|
SExprInfo* pExprInfo = &pExprSup->pExprInfo[j];
|
||||||
|
|
||||||
|
int32_t dstSlot = pExprInfo->base.resSchema.slotId;
|
||||||
|
SColumnInfoData* pDst = taosArrayGet(pResBlock->pDataBlock, dstSlot);
|
||||||
|
|
||||||
|
if (IS_TIMESTAMP_TYPE(pExprInfo->base.resSchema.type)) {
|
||||||
|
colDataAppend(pDst, pResBlock->info.rows, (char*)&pSliceInfo->current, false);
|
||||||
|
} else {
|
||||||
|
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
||||||
|
SColumnInfoData* pSrc = taosArrayGet(pSrcBlock->pDataBlock, srcSlot);
|
||||||
|
|
||||||
|
if (colDataIsNull_s(pSrc, index)) {
|
||||||
|
colDataAppendNULL(pDst, pResBlock->info.rows);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* v = colDataGetData(pSrc, index);
|
||||||
|
colDataAppend(pDst, pResBlock->info.rows, v, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pResBlock->info.rows += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
||||||
if (pInfo->pPrevRow != NULL) {
|
if (pInfo->pPrevRow != NULL) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2190,24 +2233,19 @@ static int32_t initFillLinearInfo(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB
|
||||||
|
|
||||||
SFillLinearInfo linearInfo = {0};
|
SFillLinearInfo linearInfo = {0};
|
||||||
linearInfo.start.key = INT64_MIN;
|
linearInfo.start.key = INT64_MIN;
|
||||||
linearInfo.end.key = INT64_MAX;
|
linearInfo.end.key = INT64_MIN;
|
||||||
linearInfo.start.val = taosMemoryCalloc(1, pColInfo->info.bytes);
|
linearInfo.start.val = taosMemoryCalloc(1, pColInfo->info.bytes);
|
||||||
linearInfo.end.val = taosMemoryCalloc(1, pColInfo->info.bytes);
|
linearInfo.end.val = taosMemoryCalloc(1, pColInfo->info.bytes);
|
||||||
linearInfo.hasNull = false;
|
linearInfo.isStartSet = false;
|
||||||
|
linearInfo.isEndSet = false;
|
||||||
linearInfo.type = pColInfo->info.type;
|
linearInfo.type = pColInfo->info.type;
|
||||||
linearInfo.bytes = pColInfo->info.bytes;
|
linearInfo.bytes = pColInfo->info.bytes;
|
||||||
taosArrayPush(pInfo->pLinearInfo, &linearInfo);
|
taosArrayPush(pInfo->pLinearInfo, &linearInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->fillLastPoint = false;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needToFillLastPoint(STimeSliceOperatorInfo* pSliceInfo) {
|
|
||||||
return (pSliceInfo->fillLastPoint == true && pSliceInfo->fillType == TSDB_FILL_LINEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t initKeeperInfo(STimeSliceOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
static int32_t initKeeperInfo(STimeSliceOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
code = initPrevRowsKeeper(pInfo, pBlock);
|
code = initPrevRowsKeeper(pInfo, pBlock);
|
||||||
|
@ -2263,195 +2301,73 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) {
|
||||||
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
||||||
int64_t ts = *(int64_t*)colDataGetData(pTsCol, i);
|
int64_t ts = *(int64_t*)colDataGetData(pTsCol, i);
|
||||||
|
|
||||||
if (i == 0 && needToFillLastPoint(pSliceInfo)) { // first row in current block
|
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, false);
|
|
||||||
while (pSliceInfo->current < ts && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
|
||||||
pSliceInfo->current =
|
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
||||||
setOperatorCompleted(pOperator);
|
setOperatorCompleted(pOperator);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts == pSliceInfo->current) {
|
if (ts == pSliceInfo->current) {
|
||||||
blockDataEnsureCapacity(pResBlock, pResBlock->info.rows + 1);
|
addCurrentRowToResult(pSliceInfo, &pOperator->exprSupp, pResBlock, pBlock, i);
|
||||||
for (int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) {
|
|
||||||
SExprInfo* pExprInfo = &pOperator->exprSupp.pExprInfo[j];
|
|
||||||
|
|
||||||
int32_t dstSlot = pExprInfo->base.resSchema.slotId;
|
|
||||||
SColumnInfoData* pDst = taosArrayGet(pResBlock->pDataBlock, dstSlot);
|
|
||||||
|
|
||||||
if (IS_TIMESTAMP_TYPE(pExprInfo->base.resSchema.type)) {
|
|
||||||
colDataAppend(pDst, pResBlock->info.rows, (char*)&pSliceInfo->current, false);
|
|
||||||
} else {
|
|
||||||
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
|
||||||
SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot);
|
|
||||||
|
|
||||||
if (colDataIsNull_s(pSrc, i)) {
|
|
||||||
colDataAppendNULL(pDst, pResBlock->info.rows);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* v = colDataGetData(pSrc, i);
|
|
||||||
colDataAppend(pDst, pResBlock->info.rows, v, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pResBlock->info.rows += 1;
|
|
||||||
doKeepPrevRows(pSliceInfo, pBlock, i);
|
doKeepPrevRows(pSliceInfo, pBlock, i);
|
||||||
|
doKeepLinearInfo(pSliceInfo, pBlock, i);
|
||||||
|
|
||||||
// for linear interpolation, always fill value between this and next points;
|
pSliceInfo->current =
|
||||||
// if its the first point in data block, also fill values between previous(if there's any) and this point;
|
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||||
// if its the last point in data block, no need to fill, but reserve this point as the start value and do
|
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
||||||
// the interpolation when processing next data block.
|
setOperatorCompleted(pOperator);
|
||||||
if (pSliceInfo->fillType == TSDB_FILL_LINEAR) {
|
break;
|
||||||
pSliceInfo->current =
|
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
|
||||||
if (i < pBlock->info.rows - 1) {
|
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, false);
|
|
||||||
int64_t nextTs = *(int64_t*)colDataGetData(pTsCol, i + 1);
|
|
||||||
if (nextTs > pSliceInfo->current) {
|
|
||||||
while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
|
||||||
pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit,
|
|
||||||
pInterval->precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
|
||||||
setOperatorCompleted(pOperator);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // it is the last row of current block
|
|
||||||
// store ts value as start, and calculate interp value when processing next block
|
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, true);
|
|
||||||
}
|
|
||||||
} else { // non-linear interpolation
|
|
||||||
pSliceInfo->current =
|
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
|
||||||
setOperatorCompleted(pOperator);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (ts < pSliceInfo->current) {
|
} else if (ts < pSliceInfo->current) {
|
||||||
// in case of interpolation window starts and ends between two datapoints, fill(prev) need to interpolate
|
// in case of interpolation window starts and ends between two datapoints, fill(prev) need to interpolate
|
||||||
doKeepPrevRows(pSliceInfo, pBlock, i);
|
doKeepPrevRows(pSliceInfo, pBlock, i);
|
||||||
|
doKeepLinearInfo(pSliceInfo, pBlock, i);
|
||||||
|
|
||||||
if (pSliceInfo->fillType == TSDB_FILL_LINEAR) {
|
if (i < pBlock->info.rows - 1) {
|
||||||
// no need to increate pSliceInfo->current here
|
// in case of interpolation window starts and ends between two datapoints, fill(next) need to interpolate
|
||||||
// pSliceInfo->current =
|
doKeepNextRows(pSliceInfo, pBlock, i + 1);
|
||||||
// taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
int64_t nextTs = *(int64_t*)colDataGetData(pTsCol, i + 1);
|
||||||
if (i < pBlock->info.rows - 1) {
|
if (nextTs > pSliceInfo->current) {
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, false);
|
while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
||||||
int64_t nextTs = *(int64_t*)colDataGetData(pTsCol, i + 1);
|
if (!genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock, false) && pSliceInfo->fillType == TSDB_FILL_LINEAR) {
|
||||||
if (nextTs > pSliceInfo->current) {
|
|
||||||
while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
|
||||||
pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit,
|
|
||||||
pInterval->precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
|
||||||
setOperatorCompleted(pOperator);
|
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
pSliceInfo->current =
|
||||||
|
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
||||||
|
setOperatorCompleted(pOperator);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// store ts value as start, and calculate interp value when processing next block
|
// ignore current row, and do nothing
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, true);
|
|
||||||
}
|
|
||||||
} else { // non-linear interpolation
|
|
||||||
if (i < pBlock->info.rows - 1) {
|
|
||||||
// in case of interpolation window starts and ends between two datapoints, fill(next) need to interpolate
|
|
||||||
doKeepNextRows(pSliceInfo, pBlock, i + 1);
|
|
||||||
int64_t nextTs = *(int64_t*)colDataGetData(pTsCol, i + 1);
|
|
||||||
if (nextTs > pSliceInfo->current) {
|
|
||||||
while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
|
||||||
pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit,
|
|
||||||
pInterval->precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
|
||||||
setOperatorCompleted(pOperator);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// ignore current row, and do nothing
|
|
||||||
}
|
|
||||||
} else { // it is the last row of current block
|
|
||||||
doKeepPrevRows(pSliceInfo, pBlock, i);
|
|
||||||
}
|
}
|
||||||
|
} else { // it is the last row of current block
|
||||||
|
doKeepPrevRows(pSliceInfo, pBlock, i);
|
||||||
}
|
}
|
||||||
} else { // ts > pSliceInfo->current
|
} else { // ts > pSliceInfo->current
|
||||||
// in case of interpolation window starts and ends between two datapoints, fill(next) need to interpolate
|
// in case of interpolation window starts and ends between two datapoints, fill(next) need to interpolate
|
||||||
doKeepNextRows(pSliceInfo, pBlock, i);
|
doKeepNextRows(pSliceInfo, pBlock, i);
|
||||||
|
doKeepLinearInfo(pSliceInfo, pBlock, i);
|
||||||
|
|
||||||
while (pSliceInfo->current < ts && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
while (pSliceInfo->current < ts && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
if (!genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock, true) && pSliceInfo->fillType == TSDB_FILL_LINEAR) {
|
||||||
pSliceInfo->current =
|
break;
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
} else {
|
||||||
|
pSliceInfo->current =
|
||||||
|
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add current row if timestamp match
|
// add current row if timestamp match
|
||||||
if (ts == pSliceInfo->current && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
if (ts == pSliceInfo->current && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
||||||
blockDataEnsureCapacity(pResBlock, pResBlock->info.rows + 1);
|
addCurrentRowToResult(pSliceInfo, &pOperator->exprSupp, pResBlock, pBlock, i);
|
||||||
for (int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) {
|
|
||||||
SExprInfo* pExprInfo = &pOperator->exprSupp.pExprInfo[j];
|
|
||||||
|
|
||||||
int32_t dstSlot = pExprInfo->base.resSchema.slotId;
|
|
||||||
SColumnInfoData* pDst = taosArrayGet(pResBlock->pDataBlock, dstSlot);
|
|
||||||
|
|
||||||
if (IS_TIMESTAMP_TYPE(pExprInfo->base.resSchema.type)) {
|
|
||||||
colDataAppend(pDst, pResBlock->info.rows, (char*)&pSliceInfo->current, false);
|
|
||||||
} else {
|
|
||||||
int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId;
|
|
||||||
SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot);
|
|
||||||
|
|
||||||
if (colDataIsNull_s(pSrc, i)) {
|
|
||||||
colDataAppendNULL(pDst, pResBlock->info.rows);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* v = colDataGetData(pSrc, i);
|
|
||||||
colDataAppend(pDst, pResBlock->info.rows, v, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pResBlock->info.rows += 1;
|
|
||||||
doKeepPrevRows(pSliceInfo, pBlock, i);
|
doKeepPrevRows(pSliceInfo, pBlock, i);
|
||||||
|
|
||||||
if (pSliceInfo->fillType == TSDB_FILL_LINEAR) {
|
pSliceInfo->current =
|
||||||
pSliceInfo->current =
|
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
|
||||||
if (i < pBlock->info.rows - 1) {
|
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, false);
|
|
||||||
int64_t nextTs = *(int64_t*)colDataGetData(pTsCol, i + 1);
|
|
||||||
if (nextTs > pSliceInfo->current) {
|
|
||||||
while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) {
|
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
|
||||||
pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit,
|
|
||||||
pInterval->precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
|
||||||
setOperatorCompleted(pOperator);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // it is the last row of current block
|
|
||||||
// store ts value as start, and calculate interp value when processing next block
|
|
||||||
doKeepLinearInfo(pSliceInfo, pBlock, i, true);
|
|
||||||
}
|
|
||||||
} else { // non-linear interpolation
|
|
||||||
pSliceInfo->current =
|
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
if (pSliceInfo->current > pSliceInfo->win.ekey) {
|
||||||
|
@ -2466,7 +2382,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) {
|
||||||
// except for fill(next), fill(linear)
|
// except for fill(next), fill(linear)
|
||||||
while (pSliceInfo->current <= pSliceInfo->win.ekey && pSliceInfo->fillType != TSDB_FILL_NEXT &&
|
while (pSliceInfo->current <= pSliceInfo->win.ekey && pSliceInfo->fillType != TSDB_FILL_NEXT &&
|
||||||
pSliceInfo->fillType != TSDB_FILL_LINEAR) {
|
pSliceInfo->fillType != TSDB_FILL_LINEAR) {
|
||||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock);
|
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock, false);
|
||||||
pSliceInfo->current =
|
pSliceInfo->current =
|
||||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue