未验证 提交 59e91409 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #16806 from taosdata/fix/TD-18224

fix(query): twa function report error if input has overlap timestamps
...@@ -577,6 +577,7 @@ int32_t* taosGetErrno(); ...@@ -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_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803) #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_NOT_BUILTIN_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2804)
#define TSDB_CODE_FUNC_DUP_TIMESTAMP TAOS_DEF_ERROR_CODE(0, 0x2805)
//udf //udf
#define TSDB_CODE_UDF_STOPPING TAOS_DEF_ERROR_CODE(0, 0x2901) #define TSDB_CODE_UDF_STOPPING TAOS_DEF_ERROR_CODE(0, 0x2901)
......
...@@ -5398,8 +5398,8 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5398,8 +5398,8 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
int32_t i = pInput->startRowIndex; int32_t i = pInput->startRowIndex;
if (pCtx->start.key != INT64_MIN) { if (pCtx->start.key != INT64_MIN) {
ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) || //ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) ||
(pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC)); // (pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC));
ASSERT(last->key == INT64_MIN); ASSERT(last->key == INT64_MIN);
for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) { for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) {
...@@ -5447,6 +5447,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5447,6 +5447,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5462,6 +5466,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5462,6 +5466,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5476,6 +5484,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5476,6 +5484,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5490,6 +5502,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5490,6 +5502,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5504,6 +5520,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5504,6 +5520,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5518,6 +5538,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5518,6 +5538,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5532,6 +5556,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5532,6 +5556,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5546,6 +5574,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5546,6 +5574,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5560,6 +5592,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5560,6 +5592,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
...@@ -5574,6 +5610,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { ...@@ -5574,6 +5610,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) {
numOfElems++; numOfElems++;
INIT_INTP_POINT(st, tsList[i], val[i]); 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->dOutput += twa_get_area(pInfo->p, st);
pInfo->p = st; pInfo->p = st;
} }
......
...@@ -579,6 +579,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_NUM, "Invalid function par ...@@ -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_TYPE, "Invalid function para type")
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_VALUE, "Invalid function para value") 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_NOT_BUILTIN_FUNTION, "Not buildin function")
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_DUP_TIMESTAMP, "Duplicate timestamps not allowed in function")
//udf //udf
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping") TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping")
......
...@@ -181,7 +181,7 @@ class TDTestCase: ...@@ -181,7 +181,7 @@ class TDTestCase:
# bug need fix # bug need fix
tdSql.checkData(0,1,None) 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.checkRows(11)
tdSql.checkData(0,1,None) tdSql.checkData(0,1,None)
......
...@@ -124,7 +124,7 @@ class TDTestCase: ...@@ -124,7 +124,7 @@ class TDTestCase:
tdSql.checkData(0,1,4.500000000) tdSql.checkData(0,1,4.500000000)
# mixup with other functions # 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,0,1.000000000)
tdSql.checkData(0,1,11111.000000000) tdSql.checkData(0,1,11111.000000000)
tdSql.checkData(0,2,1) tdSql.checkData(0,2,1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册