提交 9b073353 编写于 作者: H Haojun Liao

[td-225] fix bug found by regression test.

上级 678cc06f
...@@ -2161,7 +2161,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2161,7 +2161,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_STDDEV: case TSDB_FUNC_STDDEV:
case TSDB_FUNC_LEASTSQR: { case TSDB_FUNC_LEASTSQR: {
// 1. valid the number of parameters // 1. valid the number of parameters
int32_t numOfParams = taosArrayGetSize(pItem->pNode->pParam); int32_t numOfParams = (pItem->pNode->pParam == NULL)? 0: taosArrayGetSize(pItem->pNode->pParam);
if (pItem->pNode->pParam == NULL || if (pItem->pNode->pParam == NULL ||
(functionId != TSDB_FUNC_LEASTSQR && functionId != TSDB_FUNC_DERIVATIVE && numOfParams != 1) || (functionId != TSDB_FUNC_LEASTSQR && functionId != TSDB_FUNC_DERIVATIVE && numOfParams != 1) ||
((functionId == TSDB_FUNC_LEASTSQR || functionId == TSDB_FUNC_DERIVATIVE) && numOfParams != 3)) { ((functionId == TSDB_FUNC_LEASTSQR || functionId == TSDB_FUNC_DERIVATIVE) && numOfParams != 3)) {
......
...@@ -234,7 +234,6 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI ...@@ -234,7 +234,6 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
//TODO twa function definit error.
if (isSuperTable) { if (isSuperTable) {
if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) {
*type = TSDB_DATA_TYPE_BINARY; *type = TSDB_DATA_TYPE_BINARY;
...@@ -3420,18 +3419,6 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx) { ...@@ -3420,18 +3419,6 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx) {
return false; return false;
} }
#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);
static bool deriv_function_setup(SQLFunctionCtx *pCtx) { static bool deriv_function_setup(SQLFunctionCtx *pCtx) {
if (!function_setup(pCtx)) { if (!function_setup(pCtx)) {
return false; return false;
...@@ -3480,7 +3467,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3480,7 +3467,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
if (pDerivInfo->ignoreNegative && *pOutput < 0) { if (pDerivInfo->ignoreNegative && *pOutput < 0) {
} else { } else {
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3508,7 +3494,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3508,7 +3494,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
if (pDerivInfo->ignoreNegative && *pOutput < 0) { if (pDerivInfo->ignoreNegative && *pOutput < 0) {
} else { } else {
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3535,7 +3520,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3535,7 +3520,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
if (pDerivInfo->ignoreNegative && *pOutput < 0) { if (pDerivInfo->ignoreNegative && *pOutput < 0) {
} else { } else {
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3563,7 +3547,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3563,7 +3547,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
if (pDerivInfo->ignoreNegative && *pOutput < 0) { if (pDerivInfo->ignoreNegative && *pOutput < 0) {
} else { } else {
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3590,7 +3573,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3590,7 +3573,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
if (pDerivInfo->ignoreNegative && *pOutput < 0) { if (pDerivInfo->ignoreNegative && *pOutput < 0) {
} else { } else {
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3646,18 +3628,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) { ...@@ -3646,18 +3628,6 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
} }
} }
#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);
#define DIFF_IMPL(ctx, d, type) \ #define DIFF_IMPL(ctx, d, type) \
do { \ do { \
if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \ if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \
...@@ -3693,20 +3663,10 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3693,20 +3663,10 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].i64 = pData[i];
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = (int32_t)(pData[i] - pCtx->param[1].i64);
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1;
pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3725,20 +3685,10 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3725,20 +3685,10 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].i64 = pData[i]; *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = pData[i] - pCtx->param[1].i64;
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = pData[i] - pCtx->param[1].i64;
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1;
pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3757,22 +3707,14 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3757,22 +3707,14 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].dKey = pData[i]; *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = pData[i] - pCtx->param[1].dKey;
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = pData[i] - pCtx->param[1].dKey;
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1; pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
pCtx->param[1].dKey = pData[i]; pCtx->param[1].i64 = pData[i];
pCtx->param[1].nType = pCtx->inputType; pCtx->param[1].nType = pCtx->inputType;
notNullElems++; notNullElems++;
} }
...@@ -3787,25 +3729,14 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3787,25 +3729,14 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].dKey = pData[i]; *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = (float)(pData[i] - pCtx->param[1].dKey);
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = (float)(pData[i] - pCtx->param[1].dKey);
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1;
pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
// keep the last value, the remain may be all null pCtx->param[1].i64 = pData[i];
pCtx->param[1].dKey = pData[i];
pCtx->param[1].nType = pCtx->inputType; pCtx->param[1].nType = pCtx->inputType;
notNullElems++; notNullElems++;
} }
...@@ -3820,19 +3751,10 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3820,19 +3751,10 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].i64 = pData[i]; *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = (int16_t)(pData[i] - pCtx->param[1].i64);
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = (int16_t)(pData[i] - pCtx->param[1].i64);
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1;
pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3851,20 +3773,10 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3851,20 +3773,10 @@ static void diff_function(SQLFunctionCtx *pCtx) {
continue; continue;
} }
if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
pCtx->param[1].i64 = pData[i]; *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
pCtx->param[1].nType = pCtx->inputType;
} else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) {
*pOutput = (int8_t)(pData[i] - pCtx->param[1].i64);
*pTimestamp = tsList[i];
pOutput += 1;
pTimestamp += 1;
} else {
*pOutput = (int8_t)(pData[i] - pCtx->param[1].i64);
*pTimestamp = tsList[i]; *pTimestamp = tsList[i];
pOutput += 1;
pOutput += 1;
pTimestamp += 1; pTimestamp += 1;
} }
...@@ -3892,18 +3804,6 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3892,18 +3804,6 @@ static void diff_function(SQLFunctionCtx *pCtx) {
} }
} }
#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);
static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) {
char *pData = GET_INPUT_DATA(pCtx, index); char *pData = GET_INPUT_DATA(pCtx, index);
if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { if (pCtx->hasNull && isNull(pData, pCtx->inputType)) {
......
...@@ -9,7 +9,7 @@ sql connect ...@@ -9,7 +9,7 @@ sql connect
print ======================== dnode1 start print ======================== dnode1 start
$db = testdb $db = testdb
sql drop database if exists $db
sql create database $db cachelast 2 sql create database $db cachelast 2
sql use $db sql use $db
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册