Merge pull request #24529 from taosdata/szhou/fix/td-28350

fix: calculate interval end with new alogrithm
This commit is contained in:
dapan1121 2024-01-23 08:41:37 +08:00 committed by GitHub
commit 66c30f861f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -1858,7 +1858,7 @@ STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowI
STimeWindow w = {0};
if (pResultRowInfo->cur.pageId == -1) { // the first window, from the previous stored value
getInitialStartTimeWindow(pInterval, ts, &w, (order == TSDB_ORDER_ASC));
w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1;
w.ekey = taosTimeGetIntervalEnd(w.skey, pInterval);
return w;
}

View File

@ -19,6 +19,7 @@
#include "thash.h"
#include "tsimplehash.h"
#include "executor.h"
#include "executorInt.h"
#include "ttime.h"
#pragma GCC diagnostic push
@ -186,4 +187,20 @@ TEST(testCase, timewindow_natural) {
ASSERT_EQ(w3.skey, w4.skey);
ASSERT_EQ(w3.ekey, w4.ekey);
}
TEST(testCase, timewindow_active) {
osSetTimezone("CST");
int32_t precision = TSDB_TIME_PRECISION_MILLI;
int64_t offset = (int64_t)2*365*24*60*60*1000;
SInterval interval = createInterval(10, 10, offset, 'y', 'y', 0, precision);
SResultRowInfo dumyInfo = {0};
dumyInfo.cur.pageId = -1;
int64_t key = (int64_t)1609430400*1000; // 2021-01-01
STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, key, &interval, TSDB_ORDER_ASC);
printTimeWindow(&win, precision, key);
printf("%ld win %ld, %ld\n", key, win.skey, win.ekey);
ASSERT_EQ(win.skey, 1325376000000);
ASSERT_EQ(win.ekey, 1640908799999);
}
#pragma GCC diagnostic pop