td-1099: fix bug & compile error / add test cases
This commit is contained in:
parent
b3840db93e
commit
1afed4c067
|
@ -586,7 +586,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
|
||||||
}
|
}
|
||||||
|
|
||||||
// interval is not null
|
// interval is not null
|
||||||
SSQLToken* t = &pQuerySql->interval;
|
SStrToken* t = &pQuerySql->interval;
|
||||||
if (parseDuration(t->z, t->n, &pQueryInfo->intervalTime, &pQueryInfo->intervalTimeUnit) != TSDB_CODE_SUCCESS) {
|
if (parseDuration(t->z, t->n, &pQueryInfo->intervalTime, &pQueryInfo->intervalTimeUnit) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
@ -672,7 +672,7 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
SSQLToken* pSliding = &pQuerySql->sliding;
|
SStrToken* pSliding = &pQuerySql->sliding;
|
||||||
if (pSliding->n == 0) {
|
if (pSliding->n == 0) {
|
||||||
pQueryInfo->slidingTimeUnit = pQueryInfo->intervalTimeUnit;
|
pQueryInfo->slidingTimeUnit = pQueryInfo->intervalTimeUnit;
|
||||||
pQueryInfo->slidingTime = pQueryInfo->intervalTime;
|
pQueryInfo->slidingTime = pQueryInfo->intervalTime;
|
||||||
|
|
|
@ -172,28 +172,24 @@ static void getNextTimeWindow(SQuery* pQuery, STimeWindow* tw) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t key = tw->skey;
|
int64_t key = tw->skey / 1000, interval = pQuery->intervalTime;
|
||||||
key /= 1000;
|
|
||||||
if (pQuery->precision == TSDB_TIME_PRECISION_MICRO) {
|
if (pQuery->precision == TSDB_TIME_PRECISION_MICRO) {
|
||||||
key /= 1000;
|
key /= 1000;
|
||||||
}
|
}
|
||||||
|
if (pQuery->intervalTimeUnit == 'y') {
|
||||||
|
interval *= 12;
|
||||||
|
}
|
||||||
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t t = (time_t)key;
|
time_t t = (time_t)key;
|
||||||
localtime_r(&t, &tm);
|
localtime_r(&t, &tm);
|
||||||
|
|
||||||
if (pQuery->intervalTimeUnit == 'y') {
|
int mon = tm.tm_year * 12 + tm.tm_mon + interval * factor;
|
||||||
factor *= 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mon = tm.tm_year * 12 + tm.tm_mon;
|
|
||||||
mon += pQuery->intervalTime * factor;
|
|
||||||
tm.tm_year = mon / 12;
|
tm.tm_year = mon / 12;
|
||||||
tm.tm_mon = mon % 12;
|
tm.tm_mon = mon % 12;
|
||||||
|
|
||||||
tw->skey = mktime(&tm) * 1000L;
|
tw->skey = mktime(&tm) * 1000L;
|
||||||
|
|
||||||
mon += pQuery->intervalTime * factor;
|
mon += interval;
|
||||||
tm.tm_year = mon / 12;
|
tm.tm_year = mon / 12;
|
||||||
tm.tm_mon = mon % 12;
|
tm.tm_mon = mon % 12;
|
||||||
tw->ekey = mktime(&tm) * 1000L;
|
tw->ekey = mktime(&tm) * 1000L;
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2020 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import taos
|
||||||
|
from util.log import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.sql import *
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor())
|
||||||
|
|
||||||
|
def singleTable(self):
|
||||||
|
tdSql.execute("create table car(ts timestamp, s int)")
|
||||||
|
tdSql.execute("insert into car values('2019-01-01 00:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2019-05-13 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2019-12-31 23:59:59', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-03 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-04 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-05 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-01-31 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-02-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-02-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-02-29 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-03-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-03-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-03-15 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-03-31 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car values('2020-05-01 12:00:00', 1)")
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(1n)")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.checkData(1, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 6)
|
||||||
|
tdSql.checkData(4, 1, 3)
|
||||||
|
tdSql.checkData(5, 1, 4)
|
||||||
|
tdSql.checkData(6, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(1n) order by ts desc")
|
||||||
|
tdSql.checkData(6, 1, 1)
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
tdSql.checkData(4, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 6)
|
||||||
|
tdSql.checkData(2, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(2n)")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.checkData(1, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 9)
|
||||||
|
tdSql.checkData(4, 1, 4)
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(2n) order by ts desc")
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
tdSql.checkData(4, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 9)
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(1y)")
|
||||||
|
tdSql.checkData(0, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 14)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from car interval(2y)")
|
||||||
|
tdSql.checkData(0, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 14)
|
||||||
|
|
||||||
|
|
||||||
|
def superTable(self):
|
||||||
|
tdSql.execute("create table cars(ts timestamp, s int) tags(id int)")
|
||||||
|
tdSql.execute("create table car0 using cars tags(0)")
|
||||||
|
tdSql.execute("create table car1 using cars tags(0)")
|
||||||
|
tdSql.execute("create table car2 using cars tags(0)")
|
||||||
|
tdSql.execute("create table car3 using cars tags(0)")
|
||||||
|
tdSql.execute("create table car4 using cars tags(0)")
|
||||||
|
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2019-05-13 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car2 values('2019-12-31 23:59:59', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-03 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-04 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-05 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-01-31 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2020-02-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car2 values('2020-02-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car2 values('2020-02-29 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car3 values('2020-03-01 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car3 values('2020-03-02 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car3 values('2020-03-15 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car4 values('2020-03-31 12:00:00', 1)")
|
||||||
|
tdSql.execute("insert into car3 values('2020-05-01 12:00:00', 1)")
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(1n)")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.checkData(1, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 6)
|
||||||
|
tdSql.checkData(4, 1, 3)
|
||||||
|
tdSql.checkData(5, 1, 4)
|
||||||
|
tdSql.checkData(6, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(1n) order by ts desc")
|
||||||
|
tdSql.checkData(6, 1, 1)
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
tdSql.checkData(4, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 6)
|
||||||
|
tdSql.checkData(2, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(2n)")
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
tdSql.checkData(1, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 9)
|
||||||
|
tdSql.checkData(4, 1, 4)
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(2n) order by ts desc")
|
||||||
|
tdSql.checkData(5, 1, 1)
|
||||||
|
tdSql.checkData(4, 1, 1)
|
||||||
|
tdSql.checkData(3, 1, 1)
|
||||||
|
tdSql.checkData(2, 1, 9)
|
||||||
|
tdSql.checkData(1, 1, 4)
|
||||||
|
tdSql.checkData(0, 1, 1)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(1y)")
|
||||||
|
tdSql.checkData(0, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 14)
|
||||||
|
|
||||||
|
tdSql.query("select count(*) from cars interval(2y)")
|
||||||
|
tdSql.checkData(0, 1, 3)
|
||||||
|
tdSql.checkData(1, 1, 14)
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
self.singleTable()
|
||||||
|
self.superTable()
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
Loading…
Reference in New Issue