From 7c3bc50140b3434f8883cd820e8bdcc155789ced Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 11 Dec 2020 11:11:45 +0800 Subject: [PATCH] [TD-2129] --- src/client/src/tscFunctionImpl.c | 2 +- tests/script/general/parser/function.sim | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 07aa94d0b3..15432e7040 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 79c620f90d..3505ad1a28 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