diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index ba77885f02dddf6af6ee6ee7478d1087299a563b..ec442f42a64b30611137a66b6993fd7309ea0cab 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -424,29 +424,44 @@ int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrec } } //end switch fromPrecision end_: - if (tempResult > (double)INT64_MAX) return INT64_MAX; - if (tempResult < (double)INT64_MIN) return INT64_MIN + 1; // INT64_MIN means NULL + if (tempResult >= (double)INT64_MAX) return INT64_MAX; + if (tempResult <= (double)INT64_MIN) return INT64_MIN + 1; // INT64_MIN means NULL return time; } static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { switch (unit) { - case 's': + case 's':{ + double temp = ((double)val) * MILLISECOND_PER_SECOND; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'm': + } + case 'm':{ + double temp = ((double)val) * MILLISECOND_PER_MINUTE; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_MINUTE, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'h': + } + case 'h':{ + double temp = ((double)val) * MILLISECOND_PER_HOUR; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_HOUR, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'd': + } + case 'd': { + double temp = ((double)val) * MILLISECOND_PER_DAY; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_DAY, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'w': + } + case 'w': { + double temp = ((double)val) * MILLISECOND_PER_WEEK; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_WEEK, TSDB_TIME_PRECISION_MILLI, timePrecision); break; + } case 'a': (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_MILLI, timePrecision); break; diff --git a/tests/pytest/functions/function_derivative.py b/tests/pytest/functions/function_derivative.py index e90a7671197ae9abe7c4463308b480849769f2fe..db9fc04be2a4467fe47c3251d88a6781ccc31b67 100644 --- a/tests/pytest/functions/function_derivative.py +++ b/tests/pytest/functions/function_derivative.py @@ -29,7 +29,6 @@ class TDTestCase: def insertAndCheckData(self): types = ["tinyint", "tinyint unsigned", "smallint", "smallint unsigned", "int", "int unsigned", "bigint", "bigint unsigned", "float", "double", "bool", "binary(20)", "nchar(20)"] - for type in types: print("============== create table using %s type ================" % type) tdSql.execute("drop table if exists stb") @@ -68,9 +67,9 @@ class TDTestCase: tdSql.checkData(0, 0, "2018-09-17 09:00:10.000") tdSql.checkData(0, 1, "2018-09-17 09:00:10.000") tdSql.checkData(0, 3, "2018-09-17 09:00:10.000") - tdSql.checkData(1, 0, "2018-09-17 09:00:20.009") - tdSql.checkData(1, 1, "2018-09-17 09:00:20.009") - tdSql.checkData(1, 3, "2018-09-17 09:00:20.009") + tdSql.checkData(1, 0, "2018-09-17 09:00:20.000") + tdSql.checkData(1, 1, "2018-09-17 09:00:20.000") + tdSql.checkData(1, 3, "2018-09-17 09:00:20.000") tdSql.query("select ts from(select ts,derivative(col, 10s, 0) from stb group by tbname)")