fix: merge join timetruncate issue
This commit is contained in:
parent
e17518e07f
commit
f13c9d2ca4
|
@ -798,7 +798,7 @@ static int32_t mJoinInitPrimExprCtx(SNode* pNode, SMJoinPrimExprCtx* pCtx, SMJoi
|
|||
SValueNode* pTimeZone = (5 == pFunc->pParameterList->length) ? (SValueNode*)nodesListGetNode(pFunc->pParameterList, 4) : (SValueNode*)nodesListGetNode(pFunc->pParameterList, 3);
|
||||
|
||||
pCtx->truncateUnit = pUnit->typeData;
|
||||
if (NULL != pCurrTz && 0 == pCurrTz->typeData) {
|
||||
if ((NULL == pCurrTz || 1 == pCurrTz->typeData) && pCtx->truncateUnit >= (86400 * TSDB_TICK_PER_SECOND(pFunc->node.resType.precision))) {
|
||||
pCtx->timezoneUnit = offsetFromTz(pTimeZone->datum.p, TSDB_TICK_PER_SECOND(pFunc->node.resType.precision));
|
||||
}
|
||||
|
||||
|
@ -905,7 +905,7 @@ int32_t mJoinLaunchPrimExpr(SSDataBlock* pBlock, SMJoinTableCtx* pTable) {
|
|||
SColumnInfoData* pPrimOut = taosArrayGet(pBlock->pDataBlock, pTable->primCtx.targetSlotId);
|
||||
if (0 != pCtx->timezoneUnit) {
|
||||
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
||||
((int64_t*)pPrimOut->pData)[i] = (((int64_t*)pPrimIn->pData)[i] - pCtx->timezoneUnit) / pCtx->truncateUnit * pCtx->truncateUnit;
|
||||
((int64_t*)pPrimOut->pData)[i] = ((int64_t*)pPrimIn->pData)[i] / pCtx->truncateUnit * pCtx->truncateUnit - pCtx->timezoneUnit;
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
||||
|
|
|
@ -197,6 +197,7 @@ typedef struct {
|
|||
bool filter;
|
||||
bool asc;
|
||||
bool grpJoin;
|
||||
bool timetruncate;
|
||||
SExecTaskInfo* pTask;
|
||||
} SJoinTestParam;
|
||||
|
||||
|
|
|
@ -23,17 +23,17 @@ sql drop database if exists testa
|
|||
sql create database testa vgroups 3;
|
||||
sql use testa;
|
||||
|
||||
sql create table sta1(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into cta11 using sta1 tags(1) values('2023-10-16 09:10:11', 100111, 1001110);
|
||||
sql insert into cta12 using sta1 tags(2) values('2023-10-16 09:10:12', 100112, 1001120);
|
||||
sql insert into cta13 using sta1 tags(3) values('2023-10-16 09:10:13', 100113, 1001130);
|
||||
sql insert into cta14 using sta1 tags(4) values('2023-10-16 09:10:14', 100114, 1001140);
|
||||
sql create table sta1(ts timestamp, f int, g bigint) tags (t int);
|
||||
sql insert into cta11 using sta1 tags(1) values('2023-10-16 09:10:11.001', 100111, 1001110);
|
||||
sql insert into cta12 using sta1 tags(2) values('2023-10-16 09:10:12.001', 100112, 1001120);
|
||||
sql insert into cta13 using sta1 tags(3) values('2023-10-16 09:10:13.001', 100113, 1001130);
|
||||
sql insert into cta14 using sta1 tags(4) values('2023-10-16 09:10:14.001', 100114, 1001140);
|
||||
|
||||
sql create table st2(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into cta21 using st2 tags(1) values('2023-10-16 09:10:11', 100221, 1002210);
|
||||
sql insert into cta22 using st2 tags(2) values('2023-10-16 09:10:12', 100222, 1002220);
|
||||
sql insert into cta23 using st2 tags(3) values('2023-10-16 09:10:13', 100223, 1002230);
|
||||
sql insert into cta24 using st2 tags(4) values('2023-10-16 09:10:14', 100224, 1002240);
|
||||
sql create table sta2(ts timestamp, f int, g bigint) tags (t int);
|
||||
sql insert into cta21 using sta2 tags(1) values('2023-10-16 09:10:11.002', 100221, 1002210);
|
||||
sql insert into cta22 using sta2 tags(2) values('2023-10-16 09:10:12.002', 100222, 1002220);
|
||||
sql insert into cta23 using sta2 tags(3) values('2023-10-16 09:10:13.002', 100223, 1002230);
|
||||
sql insert into cta24 using sta2 tags(4) values('2023-10-16 09:10:14.002', 100224, 1002240);
|
||||
|
||||
sql create table stt(ts timestamp, f int, g int) tags (t int);
|
||||
sql create table tt using stt tags(99);
|
||||
|
|
|
@ -77,5 +77,164 @@ sql_error select a.ts, b.col1 from sta a left join sta b on timetruncate(b.ts, 1
|
|||
sql_error select a.ts, b.col1 from sta a left join sta b on timetruncate(b.ts, 1h) = a.ts + 1;
|
||||
sql_error select a.ts, b.col1 from sta a left join sta b on b.ts + 1 = a.ts + 1;
|
||||
|
||||
sql use testa;
|
||||
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1a) = timetruncate(sta2.ts, 1a);
|
||||
if $rows != 8 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:11.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != NULL then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != NULL then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1a) = timetruncate(sta2.ts, 1a) and sta1.ts=sta2.ts;
|
||||
if $rows != 8 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1s) = timetruncate(sta2.ts, 1s);
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1m) = timetruncate(sta2.ts, 1m);
|
||||
if $rows != 16 then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1h) = timetruncate(sta2.ts, 1h) order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 16 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1h) = timetruncate(sta2.ts, 1h, 0) order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 16 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts, sta2.ts from sta1 full join sta2 on timetruncate(sta1.ts, 1d) = timetruncate(sta2.ts, 1d, 0) order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 8 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != NULL then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts,timetruncate(sta1.ts, 1d), sta2.ts, timetruncate(sta2.ts, 1d, 0) from sta1 left asof join sta2 on timetruncate(sta1.ts, 1d) >= timetruncate(sta2.ts, 1d, 0) order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != NULL then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != @23-10-16 09:10:13.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data12 != NULL then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts,timetruncate(sta1.ts, 1d, 0), sta2.ts, timetruncate(sta2.ts, 1d, 1) from sta1 left asof join sta2 on timetruncate(sta1.ts, 1d, 0) >= timetruncate(sta2.ts, 1d, 1) jlimit 4 order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 16 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data12 != @23-10-16 09:10:12.002@ then
|
||||
return -1
|
||||
endi
|
||||
sql select sta1.ts, sta2.ts from sta1 left asof join sta2 on timetruncate(sta1.ts, 1s, 0) > timetruncate(sta2.ts, 1s, 1) jlimit 4 order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 7 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != @23-10-16 09:10:12.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data20 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != @23-10-16 09:10:13.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data30 != @23-10-16 09:10:13.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data31 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data40 != @23-10-16 09:10:13.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data41 != @23-10-16 09:10:12.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data50 != @23-10-16 09:10:12.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data51 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data60 != @23-10-16 09:10:11.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data61 != NULL then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select sta1.ts,timetruncate(sta1.ts, 1w, 0), sta2.ts,timetruncate(sta2.ts, 1w, 1) from sta1 left asof join sta2 on timetruncate(sta1.ts, 1w, 0) > timetruncate(sta2.ts, 1w, 1) jlimit 4 order by timetruncate(sta1.ts, 1s) desc, timetruncate(sta2.ts, 1s);
|
||||
if $rows != 16 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != @23-10-16 09:10:11.002@ then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != @23-10-16 09:10:14.001@ then
|
||||
return -1
|
||||
endi
|
||||
if $data12 != @23-10-16 09:10:12.002@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql_error select count(*) from sta1 left window join sta2 on timetruncate(sta1.ts, 1h) = timetruncate(sta2.ts, 1h) window_offset(-1s, 1s);
|
||||
|
|
Loading…
Reference in New Issue