fix(query): update the sim.

This commit is contained in:
Haojun Liao 2022-07-20 17:24:49 +08:00
parent df58a9bb30
commit fc7887e6b7
4 changed files with 7 additions and 31 deletions

View File

@ -73,7 +73,6 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) {
} }
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision);
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);

View File

@ -712,32 +712,6 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction); return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction);
} }
int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) {
if (duration == 0) {
return t;
}
if (unit != 'n' && unit != 'y') {
return t - duration;
}
// The following code handles the y/n time duration
int64_t numOfMonth = duration;
if (unit == 'y') {
numOfMonth *= 12;
}
struct tm tm;
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
taosLocalTime(&tt, &tm);
int32_t mon = tm.tm_year * 12 + tm.tm_mon - (int32_t)numOfMonth;
tm.tm_year = mon / 12;
tm.tm_mon = mon % 12;
return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision));
}
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) {
if (ekey < skey) { if (ekey < skey) {
int64_t tmp = ekey; int64_t tmp = ekey;

View File

@ -1195,7 +1195,7 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR
colDataAppendNULL(pOutputCol, i); colDataAppendNULL(pOutputCol, i);
continue; // TODO set null or ignore continue; // TODO set null or ignore
} }
*output = taosTimeSub(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0),
pRightCol->info.scale, pRightCol->info.precision); pRightCol->info.scale, pRightCol->info.precision);
} }

View File

@ -43,7 +43,8 @@ sql select cast(1 as timestamp)+1n;
if $rows != 1 then if $rows != 1 then
return -1 return -1
endi endi
if $data00 != @70-02-01 08:00:00.000@ then if $data00 != @70-02-01 08:00:00.001@ then
print expect 70-02-01 08:00:00.001, actual: $data00
return -1 return -1
endi endi
@ -52,11 +53,13 @@ if $rows != 1 then
return -1 return -1
endi endi
sql select cast(1 as timestamp)-1y; # there is an *bug* in print timestamp that smaller than 0, so let's try value that is greater than 0.
sql select cast(1 as timestamp)+1y;
if $rows != 1 then if $rows != 1 then
return -1 return -1
endi endi
if $data00 != @69-01-01 08:00:00.000@ then if $data00 != @71-01-01 08:00:00.001@ then
print expect 71-01-01 08:00:00.001 , actual: $data00
return -1 return -1
endi endi