提交 961c4723 编写于 作者: S shenglian zhou

fix diff function error for table blocks interleave. eg. table 1 block 1,...

fix diff function error for table blocks interleave. eg. table 1 block 1, table 2 block 1, table 1 block2
上级 d65d8627
...@@ -196,6 +196,14 @@ typedef struct { ...@@ -196,6 +196,14 @@ typedef struct {
char *taglists; char *taglists;
} SSampleFuncInfo; } SSampleFuncInfo;
typedef struct {
bool valueAssigned;
union {
int64_t i64Prev;
double d64Prev;
};
} SDiffFuncInfo;
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable, SUdfInfo* pUdfInfo) { int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable, SUdfInfo* pUdfInfo) {
if (!isValidDataType(dataType)) { if (!isValidDataType(dataType)) {
...@@ -214,10 +222,13 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -214,10 +222,13 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == TSDB_FUNC_INTERP) { if (functionId == TSDB_FUNC_INTERP) {
*interBytes = sizeof(SInterpInfoDetail); *interBytes = sizeof(SInterpInfoDetail);
} else if (functionId == TSDB_FUNC_DIFF) {
*interBytes = sizeof(SDiffFunctInfo);
} else { } else {
*interBytes = 0; *interBytes = 0;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -2984,18 +2995,16 @@ static void full_copy_function(SQLFunctionCtx *pCtx) { ...@@ -2984,18 +2995,16 @@ static void full_copy_function(SQLFunctionCtx *pCtx) {
} }
} }
enum {
INITIAL_VALUE_NOT_ASSIGNED = 0,
};
static bool diff_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { static bool diff_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) {
if (!function_setup(pCtx, pResInfo)) { if (!function_setup(pCtx, pResInfo)) {
return false; return false;
} }
// diff function require the value is set to -1 SDiffFuncInfo* pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo);
pCtx->param[1].nType = INITIAL_VALUE_NOT_ASSIGNED; pDiffInfo->valueAssigned = false;
return false; pDiffInfo->i64Prev = 0;
return true;
} }
static bool deriv_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) { static bool deriv_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResultInfo) {
...@@ -3201,22 +3210,14 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3201,22 +3210,14 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO(pCtx)->numOfRes += notNullElems; GET_RES_INFO(pCtx)->numOfRes += notNullElems;
} }
#define DIFF_IMPL(ctx, d, type) \
do { \
if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \
(ctx)->param[1].nType = (ctx)->inputType; \
*(type *)&(ctx)->param[1].i64 = *(type *)(d); \
} else { \
*(type *)(ctx)->pOutput = *(type *)(d) - (*(type *)(&(ctx)->param[1].i64)); \
*(type *)(&(ctx)->param[1].i64) = *(type *)(d); \
*(int64_t *)(ctx)->ptsOutputBuf = GET_TS_DATA(ctx, index); \
} \
} while (0);
// TODO difference in date column // TODO difference in date column
static void diff_function(SQLFunctionCtx *pCtx) { static void diff_function(SQLFunctionCtx *pCtx) {
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
SDiffFuncInfo *pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo);
void *data = GET_INPUT_DATA_LIST(pCtx); void *data = GET_INPUT_DATA_LIST(pCtx);
bool isFirstBlock = (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED); bool isFirstBlock = (pDiffInfo->valueAssigned == false);
int32_t notNullElems = 0; int32_t notNullElems = 0;
...@@ -3236,15 +3237,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3236,15 +3237,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) {
*pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pOutput = (int32_t)(pData[i] - pDiffInfo->i64Prev); // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].i64 = pData[i]; pDiffInfo->i64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3258,15 +3259,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3258,15 +3259,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) {
*pOutput = pData[i] - pCtx->param[1].i64; // direct previous may be null *pOutput = pData[i] - pDiffInfo->i64Prev; // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].i64 = pData[i]; pDiffInfo->i64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3280,15 +3281,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3280,15 +3281,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) { // initial value is not set yet
SET_DOUBLE_VAL(pOutput, pData[i] - pCtx->param[1].dKey); // direct previous may be null SET_DOUBLE_VAL(pOutput, pData[i] - pCtx->param[1].dKey); // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].dKey = pData[i]; pDiffInfo->d64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3302,15 +3303,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3302,15 +3303,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) { // initial value is not set yet
*pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null *pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].dKey = pData[i]; pDiffInfo->d64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3324,15 +3325,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3324,15 +3325,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) { // initial value is not set yet
*pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].i64 = pData[i]; pDiffInfo->i64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3347,15 +3348,15 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3347,15 +3348,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pDiffInfo->valueAssigned) { // initial value is not set yet
*pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
*pTimestamp = (tsList != NULL)? tsList[i]:0; *pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].i64 = pData[i]; pDiffInfo->i64Prev = pData[i];
pCtx->param[1].nType = pCtx->inputType; pDiffInfo->valueAssigned = true;
notNullElems++; notNullElems++;
} }
break; break;
...@@ -3365,7 +3366,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3365,7 +3366,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
} }
// initial value is not set yet // initial value is not set yet
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED || notNullElems <= 0) { if (!pDiffInfo->valueAssigned || notNullElems <= 0) {
/* /*
* 1. current block and blocks before are full of null * 1. current block and blocks before are full of null
* 2. current block may be null value * 2. current block may be null value
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册