提交 3d931faa 编写于 作者: H Haojun Liao

refactor(query): do some internal refactor.

上级 c52ca4cc
...@@ -78,6 +78,8 @@ typedef struct SDiffInfo { ...@@ -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) { ...@@ -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,7 +1208,8 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) { ...@@ -1206,7 +1208,8 @@ 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) {
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems); int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems);
if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
if (pDiffInfo->includeNull) { if (pDiffInfo->includeNull) {
...@@ -1238,12 +1241,67 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) { ...@@ -1238,12 +1241,67 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
pDiffInfo->hasPrev = true; pDiffInfo->hasPrev = true;
numOfElems++; numOfElems++;
} }
} 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);
if (pTsOutput != NULL) {
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++;
}
}
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;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册