diff --git a/include/util/taoserror.h b/include/util/taoserror.h index d16a599811..086de593d0 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -577,6 +577,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802) #define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803) #define TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2804) +#define TSDB_CODE_FUNC_DUP_TIMESTAMP TAOS_DEF_ERROR_CODE(0, 0x2805) //udf #define TSDB_CODE_UDF_STOPPING TAOS_DEF_ERROR_CODE(0, 0x2901) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index c9e345f49f..c48fa7f059 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5398,8 +5398,8 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { int32_t i = pInput->startRowIndex; if (pCtx->start.key != INT64_MIN) { - ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) || - (pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC)); + //ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) || + // (pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC)); ASSERT(last->key == INT64_MIN); for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) { @@ -5447,6 +5447,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5462,6 +5466,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5476,6 +5484,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5490,6 +5502,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5504,6 +5520,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5518,6 +5538,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5532,6 +5556,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5546,6 +5574,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5560,6 +5592,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } @@ -5574,6 +5610,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); + if (pInfo->p.key == st.key) { + return TSDB_CODE_FUNC_DUP_TIMESTAMP; + } + pInfo->dOutput += twa_get_area(pInfo->p, st); pInfo->p = st; } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 044cdc86b4..ab0771d218 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -579,6 +579,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_NUM, "Invalid function par TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_TYPE, "Invalid function para type") TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_VALUE, "Invalid function para value") TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION, "Not buildin function") +TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_DUP_TIMESTAMP, "Duplicate timestamps not allowed in function") //udf TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping") diff --git a/tests/system-test/2-query/max_partition.py b/tests/system-test/2-query/max_partition.py index 01c2677242..08bb7675ad 100644 --- a/tests/system-test/2-query/max_partition.py +++ b/tests/system-test/2-query/max_partition.py @@ -181,7 +181,7 @@ class TDTestCase: # bug need fix tdSql.checkData(0,1,None) - tdSql.query(f"select c1 , twa(c1) from {dbname}.stb partition by c1 order by c1") + tdSql.query(f"select c1 , twa(c1) from {dbname}.sub_stb_1 partition by c1 order by c1") tdSql.checkRows(11) tdSql.checkData(0,1,None) diff --git a/tests/system-test/2-query/twa.py b/tests/system-test/2-query/twa.py index 62940477cf..4c163da485 100644 --- a/tests/system-test/2-query/twa.py +++ b/tests/system-test/2-query/twa.py @@ -124,7 +124,7 @@ class TDTestCase: tdSql.checkData(0,1,4.500000000) # mixup with other functions - tdSql.query(f"select twa(c1),twa(c2),max(c1),elapsed(ts) from {dbname}.stb1 ") + tdSql.query(f"select twa(c1),twa(c2),max(c1),elapsed(ts) from {dbname}.ct1 ") tdSql.checkData(0,0,1.000000000) tdSql.checkData(0,1,11111.000000000) tdSql.checkData(0,2,1)