Merge pull request #27093 from taosdata/fix/3.0/TD-31274-TD-31280

1. fix interval query with month interval day slidng returning wrong …
This commit is contained in:
Haojun Liao 2024-08-09 13:50:34 +08:00 committed by GitHub
commit 45c6d42851
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 8 deletions

View File

@ -815,6 +815,12 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
if (IS_CALENDAR_TIME_DURATION(pInterval->intervalUnit)) {
int64_t news = (ts / pInterval->sliding) * pInterval->sliding;
ASSERT(news <= ts);
if (pInterval->slidingUnit == 'd' || pInterval->slidingUnit == 'w') {
#if defined(WINDOWS) && _MSC_VER >= 1900
int64_t timezone = _timezone;
#endif
news += (int64_t)(timezone * TSDB_TICK_PER_SECOND(precision));
}
if (news <= ts) {
int64_t prev = news;

View File

@ -11864,7 +11864,7 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm
if (checkRecursiveTsmaInterval(pRecursiveTsma->interval, pRecursiveTsma->unit, pInterval->datum.i,
pInterval->unit, pDbInfo.precision, true)) {
} else {
code = TSDB_CODE_TSMA_INVALID_PARA;
code = TSDB_CODE_TSMA_INVALID_INTERVAL;
}
}
}

View File

@ -754,7 +754,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_STAT, "Invalid tsma state"
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_PTR, "Invalid tsma pointer")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_PARA, "Invalid tsma parameters")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_TB, "Invalid table to create tsma, only stable or normal table allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_INTERVAL, "Invalid tsma interval, 1m ~ 1h is allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_INTERVAL, "Invalid tsma interval, 1m ~ 1y is allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_INVALID_FUNC_PARAM, "Invalid tsma func param, only one non-tag column allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_UNSUPPORTED_FUNC, "Tsma func not supported")
TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_MUST_BE_DROPPED, "Tsma must be dropped first")

View File

@ -1476,18 +1476,18 @@ class TDTestCase:
tdSql.error(sql, -2147473920) # syntax error
sql = 'create recursive tsma tsma2 on test.tsma1 interval(1m)'
tdSql.error(sql, -2147471099) # invalid tsma parameter
tdSql.error(sql, -2147471097) # invalid tsma interval
sql = 'create recursive tsma tsma2 on test.tsma1 interval(7m)'
tdSql.error(sql, -2147471099) # invalid tsma parameter
tdSql.error(sql, -2147471097) # invalid tsma interval
sql = 'create recursive tsma tsma2 on test.tsma1 interval(11m)'
tdSql.error(sql, -2147471099) # invalid tsma parameter
tdSql.error(sql, -2147471097) # invalid tsma interval
self.create_recursive_tsma('tsma1', 'tsma2', 'test', '20m', 'meters')
sql = 'create recursive tsma tsma3 on test.tsma2 interval(30m)'
tdSql.error(sql, -2147471099) # invalid tsma parameter
tdSql.error(sql, -2147471097) # invalid tsma interval
self.create_recursive_tsma('tsma2', 'tsma3', 'test', '40m', 'meters')

View File

@ -830,11 +830,21 @@ class TDTestCase:
).ignore_res_order(sql_generator.can_ignore_res_order()).get_qc())
return ctxs
def test_query_interval(self):
sql = 'select count(*), _wstart, _wend from db.meters interval(1n) sliding(1d) limit 1'
tdSql.query(sql)
tdSql.checkData(0, 1, '2017-06-15 00:00:00')
sql = 'select /*+skip_tsma()*/count(*), _wstart, _wend from db.meters interval(1n) sliding(1d) limit 1'
tdSql.query(sql)
tdSql.checkData(0, 1, '2017-06-15 00:00:00')
def test_bigger_tsma_interval(self):
db = 'db'
tb = 'meters'
func = ['max(c1)', 'min(c1)', 'min(c2)', 'max(c2)', 'avg(c1)', 'count(ts)']
self.init_data(db,10, 10000, 1500000000000, 11000000)
self.test_query_interval()
examples = [
('10m', '1h', True), ('10m','1d',True), ('1m', '120s', True), ('1h','1d',True),
('12h', '1y', False), ('1h', '1n', True), ('1h', '1y', True),
@ -842,7 +852,7 @@ class TDTestCase:
]
tdSql.execute('use db')
for (i, ri, ret) in examples:
self.test_create_recursive_tsma_interval(db, tb, func, i, ri, ret, -2147471099)
self.test_create_recursive_tsma_interval(db, tb, func, i, ri, ret, -2147471097)
self.create_tsma('tsma1', db, tb, func, '1h')
self.create_recursive_tsma('tsma1', 'tsma2', db, '1n', tb, func)
@ -898,7 +908,7 @@ class TDTestCase:
.get_qc())
self.check(ctxs)
tdSql.execute('drop database db')
def stop(self):
tdSql.close()