From c2e15394d632530e8dc0a0b710a5dda26f979672 Mon Sep 17 00:00:00 2001 From: Jing Sima Date: Wed, 22 Jan 2025 11:33:56 +0800 Subject: [PATCH] fix:[TS-5941] fix interpolate varchar/nchar data error --- source/libs/executor/src/timesliceoperator.c | 4 +- tests/army/query/function/ans/interp.csv | 105 +++++++++++++++++++ tests/army/query/function/in/interp.in | 5 + tests/army/query/function/test_interp.py | 6 ++ 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c index 3a639772c8..49fd557fe3 100644 --- a/source/libs/executor/src/timesliceoperator.c +++ b/source/libs/executor/src/timesliceoperator.c @@ -63,7 +63,7 @@ static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock pkey->isNull = false; char* val = colDataGetData(pColInfoData, rowIndex); if (IS_VAR_DATA_TYPE(pkey->type)) { - memcpy(pkey->pData, val, varDataLen(val)); + memcpy(pkey->pData, val, varDataTLen(val)); } else { memcpy(pkey->pData, val, pkey->bytes); } @@ -87,7 +87,7 @@ static void doKeepNextRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock if (!IS_VAR_DATA_TYPE(pkey->type)) { memcpy(pkey->pData, val, pkey->bytes); } else { - memcpy(pkey->pData, val, varDataLen(val)); + memcpy(pkey->pData, val, varDataTLen(val)); } } else { pkey->isNull = true; diff --git a/tests/army/query/function/ans/interp.csv b/tests/army/query/function/ans/interp.csv index 3eaccd887a..1d4e2b0a38 100644 --- a/tests/army/query/function/ans/interp.csv +++ b/tests/army/query/function/ans/interp.csv @@ -1015,3 +1015,108 @@ taos> select _irowts, _isfilled, interp(c1) from test.td32861 where ts between ' taos> select _irowts, _isfilled, interp(c1) from test.td32861 where ts between '2020-01-01 00:00:22' and '2020-01-01 00:00:30' range('2020-01-01 00:00:00', '2020-01-01 00:00:21') every(1s) fill(linear); +taos> select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(prev); + _irowts | interp(c1) | t1 | +=========================================================================== + 2020-02-01 00:00:05.000 | 5 | testts5941 | + 2020-02-01 00:00:06.000 | 5 | testts5941 | + 2020-02-01 00:00:07.000 | 5 | testts5941 | + 2020-02-01 00:00:08.000 | 5 | testts5941 | + 2020-02-01 00:00:09.000 | 5 | testts5941 | + 2020-02-01 00:00:10.000 | 10 | testts5941 | + 2020-02-01 00:00:11.000 | 10 | testts5941 | + 2020-02-01 00:00:12.000 | 10 | testts5941 | + 2020-02-01 00:00:13.000 | 10 | testts5941 | + 2020-02-01 00:00:14.000 | 10 | testts5941 | + 2020-02-01 00:00:15.000 | 15 | testts5941 | + 2020-02-01 00:00:16.000 | 15 | testts5941 | + 2020-02-01 00:00:17.000 | 15 | testts5941 | + 2020-02-01 00:00:18.000 | 15 | testts5941 | + 2020-02-01 00:00:19.000 | 15 | testts5941 | + 2020-02-01 00:00:20.000 | 15 | testts5941 | + +taos> select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(next); + _irowts | interp(c1) | t1 | +=========================================================================== + 2020-02-01 00:00:00.000 | 5 | testts5941 | + 2020-02-01 00:00:01.000 | 5 | testts5941 | + 2020-02-01 00:00:02.000 | 5 | testts5941 | + 2020-02-01 00:00:03.000 | 5 | testts5941 | + 2020-02-01 00:00:04.000 | 5 | testts5941 | + 2020-02-01 00:00:05.000 | 5 | testts5941 | + 2020-02-01 00:00:06.000 | 10 | testts5941 | + 2020-02-01 00:00:07.000 | 10 | testts5941 | + 2020-02-01 00:00:08.000 | 10 | testts5941 | + 2020-02-01 00:00:09.000 | 10 | testts5941 | + 2020-02-01 00:00:10.000 | 10 | testts5941 | + 2020-02-01 00:00:11.000 | 15 | testts5941 | + 2020-02-01 00:00:12.000 | 15 | testts5941 | + 2020-02-01 00:00:13.000 | 15 | testts5941 | + 2020-02-01 00:00:14.000 | 15 | testts5941 | + 2020-02-01 00:00:15.000 | 15 | testts5941 | + +taos> select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(linear); + _irowts | interp(c1) | t1 | +=========================================================================== + 2020-02-01 00:00:05.000 | 5 | testts5941 | + 2020-02-01 00:00:06.000 | 6 | testts5941 | + 2020-02-01 00:00:07.000 | 7 | testts5941 | + 2020-02-01 00:00:08.000 | 8 | testts5941 | + 2020-02-01 00:00:09.000 | 9 | testts5941 | + 2020-02-01 00:00:10.000 | 10 | testts5941 | + 2020-02-01 00:00:11.000 | 11 | testts5941 | + 2020-02-01 00:00:12.000 | 12 | testts5941 | + 2020-02-01 00:00:13.000 | 13 | testts5941 | + 2020-02-01 00:00:14.000 | 14 | testts5941 | + 2020-02-01 00:00:15.000 | 15 | testts5941 | + +taos> select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(null); + _irowts | interp(c1) | t1 | +=========================================================================== + 2020-02-01 00:00:00.000 | NULL | testts5941 | + 2020-02-01 00:00:01.000 | NULL | testts5941 | + 2020-02-01 00:00:02.000 | NULL | testts5941 | + 2020-02-01 00:00:03.000 | NULL | testts5941 | + 2020-02-01 00:00:04.000 | NULL | testts5941 | + 2020-02-01 00:00:05.000 | 5 | testts5941 | + 2020-02-01 00:00:06.000 | NULL | testts5941 | + 2020-02-01 00:00:07.000 | NULL | testts5941 | + 2020-02-01 00:00:08.000 | NULL | testts5941 | + 2020-02-01 00:00:09.000 | NULL | testts5941 | + 2020-02-01 00:00:10.000 | 10 | testts5941 | + 2020-02-01 00:00:11.000 | NULL | testts5941 | + 2020-02-01 00:00:12.000 | NULL | testts5941 | + 2020-02-01 00:00:13.000 | NULL | testts5941 | + 2020-02-01 00:00:14.000 | NULL | testts5941 | + 2020-02-01 00:00:15.000 | 15 | testts5941 | + 2020-02-01 00:00:16.000 | NULL | testts5941 | + 2020-02-01 00:00:17.000 | NULL | testts5941 | + 2020-02-01 00:00:18.000 | NULL | testts5941 | + 2020-02-01 00:00:19.000 | NULL | testts5941 | + 2020-02-01 00:00:20.000 | NULL | testts5941 | + +taos> select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(value, 1); + _irowts | interp(c1) | t1 | +=========================================================================== + 2020-02-01 00:00:00.000 | 1 | testts5941 | + 2020-02-01 00:00:01.000 | 1 | testts5941 | + 2020-02-01 00:00:02.000 | 1 | testts5941 | + 2020-02-01 00:00:03.000 | 1 | testts5941 | + 2020-02-01 00:00:04.000 | 1 | testts5941 | + 2020-02-01 00:00:05.000 | 5 | testts5941 | + 2020-02-01 00:00:06.000 | 1 | testts5941 | + 2020-02-01 00:00:07.000 | 1 | testts5941 | + 2020-02-01 00:00:08.000 | 1 | testts5941 | + 2020-02-01 00:00:09.000 | 1 | testts5941 | + 2020-02-01 00:00:10.000 | 10 | testts5941 | + 2020-02-01 00:00:11.000 | 1 | testts5941 | + 2020-02-01 00:00:12.000 | 1 | testts5941 | + 2020-02-01 00:00:13.000 | 1 | testts5941 | + 2020-02-01 00:00:14.000 | 1 | testts5941 | + 2020-02-01 00:00:15.000 | 15 | testts5941 | + 2020-02-01 00:00:16.000 | 1 | testts5941 | + 2020-02-01 00:00:17.000 | 1 | testts5941 | + 2020-02-01 00:00:18.000 | 1 | testts5941 | + 2020-02-01 00:00:19.000 | 1 | testts5941 | + 2020-02-01 00:00:20.000 | 1 | testts5941 | + diff --git a/tests/army/query/function/in/interp.in b/tests/army/query/function/in/interp.in index 97a9936b8d..1ba768e6e3 100644 --- a/tests/army/query/function/in/interp.in +++ b/tests/army/query/function/in/interp.in @@ -63,3 +63,8 @@ select _irowts, _isfilled, interp(c1) from test.td32861 where ts between '2020-0 select _irowts, _isfilled, interp(c1) from test.td32861 where ts between '2020-01-01 00:00:22' and '2020-01-01 00:00:30' range('2020-01-01 00:00:00', '2020-01-01 00:00:21') every(1s) fill(prev); select _irowts, _isfilled, interp(c1) from test.td32861 where ts between '2020-01-01 00:00:22' and '2020-01-01 00:00:30' range('2020-01-01 00:00:00', '2020-01-01 00:00:21') every(1s) fill(next); select _irowts, _isfilled, interp(c1) from test.td32861 where ts between '2020-01-01 00:00:22' and '2020-01-01 00:00:30' range('2020-01-01 00:00:00', '2020-01-01 00:00:21') every(1s) fill(linear); +select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(prev); +select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(next); +select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(linear); +select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(null); +select _irowts, interp(c1), t1 from test.ts5941_child range('2020-02-01 00:00:00', '2020-02-01 00:00:20') every(1s) fill(value, 1); diff --git a/tests/army/query/function/test_interp.py b/tests/army/query/function/test_interp.py index 106ef1e58e..e543d81363 100644 --- a/tests/army/query/function/test_interp.py +++ b/tests/army/query/function/test_interp.py @@ -40,6 +40,9 @@ class TDTestCase(TBase): ) tdSql.execute("create table if not exists test.td32861(ts timestamp, c1 int);") + tdSql.execute("create stable if not exists test.ts5941(ts timestamp, c1 int, c2 int) tags (t1 varchar(30));") + tdSql.execute("create table if not exists test.ts5941_child using test.ts5941 tags ('testts5941');") + tdLog.printNoPrefix("==========step2:insert data") tdSql.execute(f"insert into test.td32727 values ('2020-02-01 00:00:05', 5, 5, 5, 5, 5.0, 5.0, true, 'varchar', 'nchar', 5, 5, 5, 5)") @@ -56,6 +59,9 @@ class TDTestCase(TBase): ('2020-01-01 00:00:15', 15), ('2020-01-01 00:00:21', 21);""" ) + tdSql.execute(f"insert into test.ts5941_child values ('2020-02-01 00:00:05', 5, 5)") + tdSql.execute(f"insert into test.ts5941_child values ('2020-02-01 00:00:10', 10, 10)") + tdSql.execute(f"insert into test.ts5941_child values ('2020-02-01 00:00:15', 15, 15)") def test_normal_query_new(self, testCase): # read sql from .sql file and execute