refactor(query): do some internal refactor.
This commit is contained in:
parent
c52ca4cce8
commit
3d931faa5b
|
@ -78,6 +78,8 @@ typedef struct SDiffInfo {
|
||||||
int64_t i64;
|
int64_t i64;
|
||||||
double d64;
|
double d64;
|
||||||
} prev;
|
} prev;
|
||||||
|
|
||||||
|
int64_t prevTs;
|
||||||
} SDiffInfo;
|
} SDiffInfo;
|
||||||
|
|
||||||
typedef struct SSpreadInfo {
|
typedef struct SSpreadInfo {
|
||||||
|
@ -1196,8 +1198,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||||
bool isFirstBlock = (pDiffInfo->hasPrev == false);
|
bool isFirstBlock = (pDiffInfo->hasPrev == false);
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
// int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
||||||
// int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1;
|
// int32_t start = (pCtx->order == TSDB_ORDER_ASC) ? pInput->startRowIndex : pInput->numOfRows + pInput->startRowIndex - 1;
|
||||||
|
|
||||||
SColumnInfoData* pTsOutput = pCtx->pTsOutput;
|
SColumnInfoData* pTsOutput = pCtx->pTsOutput;
|
||||||
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
||||||
|
@ -1206,44 +1208,100 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||||
switch (pInputCol->info.type) {
|
switch (pInputCol->info.type) {
|
||||||
case TSDB_DATA_TYPE_INT: {
|
case TSDB_DATA_TYPE_INT: {
|
||||||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) {
|
if (pCtx->order == TSDB_ORDER_ASC) {
|
||||||
int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems);
|
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems);
|
||||||
if (pDiffInfo->includeNull) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
if (pDiffInfo->includeNull) {
|
||||||
if (tsList != NULL) {
|
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
if (tsList != NULL) {
|
||||||
|
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElems += 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||||
|
if (pDiffInfo->hasPrev) {
|
||||||
|
int32_t delta = (int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
|
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||||
|
} else {
|
||||||
|
colDataAppendInt32(pOutput, pos, &delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfElems += 1;
|
if (pTsOutput != NULL) {
|
||||||
|
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
pDiffInfo->prev.i64 = v;
|
||||||
if (pDiffInfo->hasPrev) {
|
pDiffInfo->hasPrev = true;
|
||||||
int32_t delta = (int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null
|
numOfElems++;
|
||||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
}
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
} else {
|
||||||
} else {
|
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||||
|
int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||||
|
int32_t pos = startOffset + numOfElems;
|
||||||
|
|
||||||
|
if (pDiffInfo->hasPrev) {
|
||||||
|
int32_t delta = -(int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
|
colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||||
|
} else {
|
||||||
|
colDataAppendInt32(pOutput, pos, &delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pTsOutput != NULL) {
|
||||||
|
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||||
|
}
|
||||||
|
pDiffInfo->hasPrev = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < pInput->numOfRows + pInput->startRowIndex - 1) {
|
||||||
|
int32_t next = *(int32_t*)colDataGetData(pInputCol, i + 1);
|
||||||
|
|
||||||
|
int32_t delta = v - next; // direct previous may be null
|
||||||
colDataAppendInt32(pOutput, pos, &delta);
|
colDataAppendInt32(pOutput, pos, &delta);
|
||||||
}
|
|
||||||
|
|
||||||
if (pTsOutput != NULL) {
|
if (pTsOutput != NULL) {
|
||||||
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pDiffInfo->prev.i64 = v;
|
||||||
|
if (pTsOutput != NULL) {
|
||||||
|
pDiffInfo->prevTs = tsList[i];
|
||||||
|
}
|
||||||
|
pDiffInfo->hasPrev = true;
|
||||||
}
|
}
|
||||||
|
// if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
|
// if (pDiffInfo->includeNull) {
|
||||||
|
// colDataSetNull_f(pOutput->nullbitmap, pos);
|
||||||
|
// if (tsList != NULL) {
|
||||||
|
// colDataAppendInt64(pTsOutput, pos, &tsList[i]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// numOfElems += 1;
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int32_t v = *(int32_t*)colDataGetData(pInputCol, i);
|
||||||
|
|
||||||
|
// pDiffInfo->prev.i64 = v;
|
||||||
|
// pDiffInfo->hasPrev = true;
|
||||||
|
numOfElems++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDiffInfo->prev.i64 = v;
|
|
||||||
pDiffInfo->hasPrev = true;
|
|
||||||
numOfElems++;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BIGINT: {
|
case TSDB_DATA_TYPE_BIGINT: {
|
||||||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) {
|
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue