diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 07aa94d0b381025a6350c05dc17f18e5026eb6c4..15432e7040a90689ee44cf598fae66bf0f27bcc1 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -3658,7 +3658,7 @@ static double twa_get_area(SPoint1 s, SPoint1 e) { return (s.val + e.val) * (e.key - s.key) / 2; } - double x = (s.val - s.key) * e.key / (s.val - e.key); + double x = (s.key * e.val - e.key * s.val)/(e.val - s.val); double val = (s.val * (x - s.key) + e.val * (e.key - x)) / 2; return val; } diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 79c620f90d06f1131c45d1705dccd5e5b311585e..3505ad1a28139a85e62193eddeb050dfde0bbc0d 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -22,7 +22,7 @@ $db = $dbPrefix . $i $mt = $mtPrefix . $i sql drop database if exists $db -sql create database $db +sql create database $db keep 36500 sql use $db print =====================================> test case for twa in single block @@ -231,3 +231,16 @@ sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts< #todo add test case while column filter exists. #sql select count(*),TWA(k) from tm0 where ts>='1970-1-1 13:43:00' and ts<='1970-1-1 13:44:10' interval(9s) + +sql create table tm0 (ts timestamp, k float); +sql insert into tm0 values(100000000, 5); +sql insert into tm0 values(100003000, -9); +sql select twa(k) from tm0 where ts