Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/libs/executor/src/scanoperator.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ static void prepareForDescendingScan(STableScanBase* pTableScanInfo, SqlFunction

switchCtxOrder(pCtx, numOfOutput);
pTableScanInfo->cond.order = TSDB_ORDER_DESC;
STimeWindow* pTWindow = &pTableScanInfo->cond.twindows;
TSWAP(pTWindow->skey, pTWindow->ekey);
// STimeWindow* pTWindow = &pTableScanInfo->cond.twindows;
// TSWAP(pTWindow->skey, pTWindow->ekey);
}

typedef struct STableCachedVal {
Expand Down
71 changes: 71 additions & 0 deletions test/cases/22-Functions/02-Aggregate/test_agg_last.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import time
import math
import random
from new_test_framework.utils import tdLog, tdSql, tdStream, streamUtil,StreamTableType, StreamTable, cluster,tdCom
from random import randint
import os
import subprocess
import json
import random
import time
import datetime

class Test_Last:
caseName = "test_last"
currentDir = os.path.dirname(os.path.abspath(__file__))
dbname = "test"
stbname= "meters"

def setup_class(cls):
tdLog.debug(f"start to execute {__file__}")

def test_last(self):
"""Agg-basic: last

Test the LAST function

Catalog:
- Function:Aggregate

Since: v3.0.0.0

Labels: common,ci

Jira: None

History:
- 2025-9-18 Stephen Jin

"""

self.prepareHistoryData()
self.insertNowData()
self.checkResult()

def prepareHistoryData(self):
cmd = f"taosBenchmark -t 100 -n 10000 -y"
ret = os.system(cmd)
if ret != 0:
raise Exception("taosBenchmark run failed")
time.sleep(5)
tdLog.info(f"Prepare history data:taosBenchmark -t 100 -n 10000 -y")

def insertNowData(self):
tdSql.execute(f"use {self.dbname}")

tdSql.execute(f"insert into {self.dbname}.d1 values (1759194759000, 1.1, 1.1, 245)")
tdSql.execute(f"insert into {self.dbname}.d15 values (1759194759001, 1.1, 1.1, 245)")

def checkResult(self):
tdSql.query(f"select last(ts) from {self.dbname}.{self.stbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1759194759001)

tdSql.query(f"select last(ts), first(ts) from {self.dbname}.{self.stbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1759194759001)

tdSql.query(f"select first(ts), last(ts) from {self.dbname}.{self.stbname}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, 1759194759001)

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

taos> select * from test1.`s0-0-0-1-1_out` order by tag_tbname
taos> select * from test1.`s0-0-0-1-1_out` order by tag_tbname, cts
cts | cint | tag_tbname |
=========================================================================
2025-01-01 00:19:00.000 | 38 | st1_0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TestStreamSlidingTrigger:
"0-0-0-0-27": [40, None, True, [], ""], #success

"0-0-0-1-0": [3, None, True, [], ""], #success
"0-0-0-1-1": [6, None, True, [], "order by tag_tbname"], #success
"0-0-0-1-1": [6, None, True, [], "order by tag_tbname, cts"], #success
"0-0-0-1-2": [120, None, True, [], ""], #success
"0-0-0-1-4": [120, None, True, [], "order by cts, tag_tbname"], #success
"0-0-0-1-6": [3513, None, True, [], ""], #success
Expand Down
1 change: 1 addition & 0 deletions test/ci/cases.task
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
,,y,.,./ci/pytest.sh pytest cases/22-Functions/02-Aggregate/test_agg_sum.py
,,y,.,./ci/pytest.sh pytest cases/22-Functions/02-Aggregate/test_agg_gconcat.py
,,y,.,./ci/pytest.sh pytest cases/22-Functions/02-Aggregate/test_agg_smoking.py
,,y,.,./ci/pytest.sh pytest cases/22-Functions/02-Aggregate/test_agg_last.py
## 03-Selection
,,y,.,./ci/pytest.sh pytest cases/22-Functions/03-Selection/test_select_all.py
,,y,.,./ci/pytest.sh pytest cases/22-Functions/03-Selection/test_select_first_last.py
Expand Down
Loading