2024-12-09 08:21:14 +00:00
import random
import string
from util . log import *
from util . cases import *
from util . sql import *
from util . common import *
2025-02-11 09:33:34 +00:00
from util . tserror import *
2024-12-09 08:21:14 +00:00
import numpy as np
class TDTestCase :
def init ( self , conn , logSql , replicaVar = 1 ) :
self . replicaVar = int ( replicaVar )
tdLog . debug ( " start to execute %s " % __file__ )
tdSql . init ( conn . cursor ( ) )
self . dbname = ' test '
2025-01-02 07:31:02 +00:00
def condition_check ( self , condition , row , col , expected_value ) :
if condition :
tdSql . checkData ( row , col , expected_value )
2024-12-09 08:21:14 +00:00
2024-12-29 23:56:02 +00:00
def create_test_data ( self ) :
tdSql . execute ( f ' create database if not exists { self . dbname } ; ' )
tdSql . execute ( f ' use { self . dbname } ' )
tdSql . execute ( f ' drop table if exists { self . dbname } .meters ' )
2024-12-09 08:21:14 +00:00
2024-12-29 23:56:02 +00:00
# tdLog.info("create test data")
# tdLog.info("taosBenchmark -y -t 10 -n 100 -b INT,FLOAT,NCHAR,BOOL")
# os.system("taosBenchmark -y -t 10 -n 100 -b INT,FLOAT,NCHAR,BOOL")
tdSql . execute ( f ' create table { self . dbname } .meters (ts timestamp, c0 int, c1 float, c2 nchar(30), c3 bool) tags (t1 nchar(30)) ' )
tdSql . execute ( f ' create table { self . dbname } .d0 using { self . dbname } .meters tags( " st1 " ) ' )
2025-01-01 11:17:12 +00:00
tdSql . execute ( f ' create table { self . dbname } .d1 using { self . dbname } .meters tags( " st2 " ) ' )
2025-01-02 07:31:02 +00:00
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929000, 1, 1, " c2 " , true) ' )
2024-12-29 23:56:02 +00:00
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929001, 2, 2, " bbbbbbbbb1 " , false) ' )
2025-01-02 07:31:02 +00:00
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929002, 2, 2, " bbbbbbbbb1 " , false) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929003, 3, 3, " a2 " , true) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929004, 4, 4, " bbbbbbbbb2 " , false) ' )
2024-12-29 23:56:02 +00:00
2025-01-02 07:31:02 +00:00
tdSql . execute ( f ' insert into { self . dbname } .d1 values(1734574929000, 1, 1, " c2 " , true) ' )
2025-01-01 11:17:12 +00:00
2024-12-29 23:56:02 +00:00
tdSql . execute ( f ' use { self . dbname } ' )
2024-12-09 08:21:14 +00:00
tdSql . execute ( f ' Create table { self . dbname } .normal_table (ts timestamp, c0 int, c1 float, c2 nchar(30), c3 bool) ' )
tdSql . execute ( f ' insert into { self . dbname } .normal_table (select * from { self . dbname } .d0) ' )
def one_cols_1output_test ( self ) :
tdLog . info ( " one_cols_1output_test " )
tdSql . query ( f ' select cols(last(ts), ts) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts), ts) as t1 from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts), ts as t1) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts), c0) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts), c1) from { self . dbname } .meters group by tbname ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c1 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts+1), ts) as t1 from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts+1), ts+2 as t1) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' ] )
2024-12-09 08:21:14 +00:00
tdSql . query ( f ' select cols(last(ts+1), c0+10) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0+10 ' ] )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
def one_cols_multi_output_with_group_test ( self , from_table = ' test.meters ' , isTmpTable = False ) :
select_t1 = [ " " , " , t1 " , " , t1 as tag1 " ]
for t1 in select_t1 :
tags_count = 0 if t1 == " " else 1
tdLog . info ( " one_cols_1output_test_with_group " )
tdSql . query ( f ' select cols(last(c1), ts) { t1 } from { from_table } group by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 1 + tags_count )
tdSql . query ( f ' select cols(last(c1), ts) { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . checkCols ( 1 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . query ( f ' select cols(last(c1), ts) { t1 } from { from_table } group by tbname order by ts ' )
tdSql . checkCols ( 1 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 0 , 1734574929004 )
tdSql . query ( f ' select cols(last(c1), ts), tbname { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , ' d0 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , ' d1 ' )
tdSql . query ( f ' select cols(last(c1), ts), tbname, t1 from { from_table } group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , ' d0 ' )
tdSql . checkData ( 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , ' d1 ' )
tdSql . checkData ( 1 , 2 , ' st2 ' )
tdSql . query ( f ' select cols(last(c1), ts), tbname, t1 from { from_table } group by tbname order by t1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' tbname ' , ' t1 ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , ' d0 ' )
tdSql . checkData ( 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , ' d1 ' )
tdSql . checkData ( 1 , 2 , ' st2 ' )
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) { t1 } from { from_table } group by t1 order by t1 ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 5 )
self . condition_check ( t1 != " " , 0 , 3 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 1 )
self . condition_check ( t1 != " " , 1 , 3 , ' st2 ' )
tdSql . query ( f ' select cols(last(ts), ts, c0), sum(c0) { t1 } from { from_table } group by t1 order by t1 ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 12 )
self . condition_check ( t1 != " " , 0 , 3 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 1 )
self . condition_check ( t1 != " " , 1 , 3 , ' st2 ' )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
tdSql . error ( f ' select cols(last(ts), ts, c0), count(1), t1 from { from_table } group by t1 order by tbname ' )
if t1 != " " and isTmpTable :
# Not a GROUP BY expression
tdSql . error ( f ' select cols(last(ts), ts, c0), count(1) { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . error ( f ' select cols(last(ts), ts, c0), count(1), tbname { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . error ( f ' select cols(max(c0), ts, c0), count(1), tbname { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . error ( f ' select cols(last(c1), ts), count(1) { t1 } from { from_table } group by tbname ' )
continue
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 1 )
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1), tbname { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 4 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . checkData ( 0 , 3 , ' d0 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 1 )
tdSql . checkData ( 1 , 3 , ' d1 ' )
tdSql . query ( f ' select cols(max(c0), ts, c0), count(1), tbname { t1 } from { from_table } group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 4 + tags_count )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . checkData ( 0 , 3 , ' d0 ' )
self . condition_check ( t1 != " " , 0 , 4 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1734574929000 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 1 )
tdSql . checkData ( 1 , 3 , ' d1 ' )
self . condition_check ( t1 != " " , 1 , 4 , ' st2 ' )
tdSql . query ( f ' select cols(last(c1), ts), count(1) { t1 } from { from_table } group by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
def one_cols_multi_output_test ( self , from_table = ' test.meters ' ) :
tdLog . info ( f " one_cols_1output_test { from_table } " )
tdSql . query ( f ' select cols(last(ts), ts, c0) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c0 ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(last(ts), ts as time, c0 cc) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' time ' , ' cc ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-03 02:32:18 +00:00
tdSql . query ( f ' select cols(last(ts), ts as t123456789t123456789t123456789t123456789t123456789t123456789t123456789, c0 cc) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t123456789t123456789t123456789t123456789t123456789t123456789t123 ' , ' cc ' ] )
2025-01-03 02:32:18 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(last(ts), c0, c1, c2, c3) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' c1 ' , ' c2 ' , ' c3 ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 4 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , ' bbbbbbbbb2 ' )
tdSql . checkData ( 0 , 3 , False )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(last(ts), c0, t1) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' t1 ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkData ( 0 , 0 , 4 )
tdSql . checkData ( 0 , 1 , ' st1 ' )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c0), ts) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkCols ( 1 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . query ( f ' select cols(min(c1), ts, c0) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c0 ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c0), ts, c0), count(1) from { from_table } ' )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 6 )
2025-01-01 11:17:12 +00:00
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) from { self . dbname } .d0 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 5 )
2025-01-01 11:17:12 +00:00
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) from { self . dbname } .d1 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) from { self . dbname } .normal_table ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . query ( f ' select cols(first(ts), ts, c0), count(1) from { self . dbname } .normal_table ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . query ( f ' select cols(min(c0), ts, c0), count(1) from { self . dbname } .normal_table ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c0 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 5 )
tdSql . query ( f ' select cols(last(ts), ts, c0), avg(c0) from { from_table } ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 2.1666666666666665 )
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) from { from_table } ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 6 )
tdSql . query ( f ' select cols(last(ts), ts, c0), sum(c0) from { from_table } ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 13 )
tdSql . query ( f ' select count(1), cols(last(ts), ts, c0), min(c0) from { from_table } ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 6 )
tdSql . checkData ( 0 , 1 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 2 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 3 , 1 )
tdSql . query ( f ' select count(1), cols(last_row(ts), ts, c0), min(c0) from test.meters ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 6 )
tdSql . checkData ( 0 , 1 , 1734574929004 )
tdSql . checkData ( 0 , 2 , 4 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . query ( f ' select count(1), cols(last_row(ts), ts, c0), last_row(c1), last_row(c3) from test.meters ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 6 )
tdSql . checkData ( 0 , 1 , 1734574929004 )
tdSql . checkData ( 0 , 2 , 4 )
tdSql . checkData ( 0 , 3 , 4 )
tdSql . checkData ( 0 , 4 , False )
tdSql . query ( f ' select cols(last(ts), ts, c0), count(1) from { from_table } ' )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 6 )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c0), ts, c0), count(1) from { from_table } ' )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 6 )
tdSql . query ( f ' select cols(last(ts), ts as time, c0 cc), count(1) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' time ' , ' cc ' , ' count(1) ' ] )
2025-01-01 11:17:12 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2025-01-01 11:17:12 +00:00
tdSql . checkData ( 0 , 1 , 4 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 2 , 6 )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c1), ts as time, c0 cc), count(1) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' time ' , ' cc ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 6 )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(last(ts), c0, c1, c2, c3), count(1) from { from_table } ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' c1 ' , ' c2 ' , ' c3 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 4 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , ' bbbbbbbbb2 ' )
tdSql . checkData ( 0 , 3 , False )
tdSql . checkData ( 0 , 4 , 6 )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c0), ts), count(1) from { from_table } ' )
tdSql . query ( f ' select cols(min(c1), ts, c0), count(1) from { from_table } ' )
tdSql . query ( f ' select count(1), cols(max(c0), ts) from { from_table } ' )
tdSql . query ( f ' select max(c0), cols(max(c0), ts) from { from_table } ' )
tdSql . query ( f ' select max(c1), cols(max(c0), ts) from { from_table } ' )
2024-12-09 08:21:14 +00:00
2025-01-02 07:31:02 +00:00
def multi_cols_output_test ( self , from_table = ' test.meters ' , isTmpTable = False ) :
2024-12-09 08:21:14 +00:00
tdLog . info ( " multi_cols_output_test " )
tdSql . query ( f ' select cols(last(c0), ts, c1), cols(first(c0), ts, c1), count(1) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c1 ' , ' ts ' , ' c1 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 6 )
tdSql . query ( f ' select cols(last(c0),ts lts, c1 lc1), cols(first(c0), ts fts, c1 as fc1), count(1) from test.meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' lts ' , ' lc1 ' , ' fts ' , ' fc1 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 6 )
tdSql . query ( f ' select cols(max(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), count(1) from { self . dbname } .meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 6 )
tdSql . query ( f ' select cols(max(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), count(1) from { self . dbname } .meters where c0 < 4 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929003 )
tdSql . checkData ( 0 , 1 , 3 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 5 )
2025-01-03 02:32:18 +00:00
tdSql . query ( f ' select cols(max(c0), ts as t123456789t123456789t123456789t123456789t123456789t123456789t123456789, c1 as c11), cols(first(c0), \
ts as t123456789t123456789t123456789t123456789t123456789t123456789t123456789 , c1 c21 ) , count ( 1 ) from { self . dbname } . meters ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t123456789t123456789t123456789t123456789t123456789t123456789t123 ' , ' c11 ' , \
' t123456789t123456789t123456789t123456789t123456789t123456789t123 ' , ' c21 ' , ' count(1) ' ] )
2025-01-03 02:32:18 +00:00
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 6 )
tdSql . query ( f ' select cols(max(c0), ts as t123456789t123456789t123456789t123456789t123456789t123456789t123456789, c1 as c11), cols(first(c0), \
ts as t123456789t123456789t123456789t123456789t123456789t123456789t123456789 , c1 c21 ) , count ( 1 ) from { self . dbname } . meters where c0 < 4 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929003 )
tdSql . checkData ( 0 , 1 , 3 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 5 )
2025-01-02 07:31:02 +00:00
tdSql . query ( f ' select cols(max(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), count(1) from test.meters where c0 < 4 group by tbname order by t1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929000 )
tdSql . checkData ( 1 , 3 , 1 )
tdSql . checkData ( 1 , 4 , 4 )
tdSql . query ( f ' select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), count(1) from test.meters where c0 < 4 group by tbname order by t1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929000 )
tdSql . checkData ( 1 , 3 , 1 )
tdSql . checkData ( 1 , 4 , 4 )
tdSql . query ( f ' select cols(last_row(c0), ts as t1, c1 as c11), cols(min(c0), ts as t2, c1 c21), count(1) from test.meters where c0 < 4 group by tbname order by t1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929000 )
tdSql . checkData ( 1 , 3 , 1 )
tdSql . checkData ( 1 , 4 , 4 )
tdSql . query ( f ' select cols(last_row(c0), ts as t1, c1 as c11), cols(mode(c0), ts as t2, c1 c21), count(1) from test.meters where c0 < 4 group by tbname order by t1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' count(1) ' ] )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
#tdSql.checkData(1, 2, 1734574929000) # mode(c0) is return a random ts of same c0
tdSql . checkData ( 1 , 3 , 2 )
tdSql . checkData ( 1 , 4 , 4 )
2025-01-23 11:27:32 +00:00
# fixed: has same select function outof cols func
tdSql . query ( f ' select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4 group by tbname order by t1 ' )
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' first(c0) ' ] )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929000 )
tdSql . checkData ( 1 , 3 , 1 )
tdSql . checkData ( 1 , 4 , 1 )
tdSql . query ( f ' select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0), cols(last(c0), ts, c1) from test.meters where c0 < 4 group by tbname order by t1; ' )
tdSql . checkResColNameList ( [ ' t1 ' , ' c11 ' , ' t2 ' , ' c21 ' , ' first(c0) ' , ' ts ' , ' c1 ' ] )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 7 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . checkData ( 0 , 5 , 1734574929000 )
tdSql . checkData ( 0 , 6 , 1 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929000 )
tdSql . checkData ( 1 , 3 , 1 )
tdSql . checkData ( 1 , 4 , 1 )
tdSql . checkData ( 1 , 5 , 1734574929003 )
tdSql . checkData ( 1 , 6 , 3 )
2025-02-05 07:26:03 +00:00
# sub query has cols func
tdSql . query ( f ' select c11 from (select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 1 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . query ( f ' select c11, c21 from (select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . query ( f ' select c1, c21 from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . checkData ( 0 , 1 , 1 )
2025-02-15 17:15:12 +00:00
tdSql . query ( f ' select * from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 1 , 3 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
2025-02-05 07:26:03 +00:00
tdSql . error ( f ' select c1 from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1), first(c0) from test.meters where c0 < 4) ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select c11, _rowts from (select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . query ( f ' select c11, c21, _rowts from (select cols(last_row(c0), ts as t1, c1 as c11), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . query ( f ' select c1, c21, _rowts from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 3 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . query ( f ' select *, _rowts from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1 c21), first(c0) from test.meters where c0 < 4) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 6 )
tdSql . checkData ( 0 , 1 , 3 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . error ( f ' select c1, _rowts from (select cols(last_row(c0), ts as t1, c1), cols(first(c0), ts as t2, c1), first(c0) from test.meters where c0 < 4) ' )
2025-02-05 07:26:03 +00:00
# cols on system table
tdSql . query ( f ' select cols(max(vgroup_id), uid) from information_schema.ins_tables ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 1 )
tdSql . query ( f ' select cols(max(vgroup_id), uid, `ttl`, create_time) from information_schema.ins_tables ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . query ( f ' select cols(max(vgroup_id), uid as uidname) from information_schema.ins_tables ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 1 )
tdSql . error ( f ' select cols(last(vgroup_id), uid, `ttl`, create_time) from information_schema.ins_tables ' )
tdSql . error ( f ' select cols(first(vgroup_id), uid, `ttl`, create_time) from information_schema.ins_tables ' )
2024-12-09 08:21:14 +00:00
2024-12-26 03:13:51 +00:00
def funcSupperTableTest ( self ) :
tdSql . execute ( ' create database if not exists db; ' )
tdSql . execute ( ' use db ' )
tdSql . execute ( f ' drop table if exists db.st ' )
tdSql . execute ( ' create table db.st (ts timestamp, c0 int, c1 float, c2 nchar(30), c3 bool) tags (t1 nchar(30)) ' )
tdSql . execute ( ' create table db.st_1 using db.st tags( " st1 " ) ' )
tdSql . execute ( ' create table db.st_2 using db.st tags( " st1 " ) ' )
2025-01-02 07:31:02 +00:00
tdSql . execute ( ' insert into db.st_1 values(1734574929000, 1, 1, " c2 " , true) ' )
2024-12-26 03:13:51 +00:00
tdSql . execute ( ' insert into db.st_1 values(1734574929001, 2, 2, " bbbbbbbbb1 " , false) ' )
tdSql . execute ( ' insert into db.st_1 values(1734574929002, 3, 3, " a2 " , true) ' )
2025-01-02 07:31:02 +00:00
tdSql . execute ( ' insert into db.st_1 values(1734574929004, 4, 4, " bbbbbbbbb2 " , false) ' )
2024-12-26 03:13:51 +00:00
tdSql . query ( f ' select cols(last(c0), ts, c1, c2, c3), cols(first(c0), ts, c1, c2, c3) from db.st ' )
tdSql . checkRows ( 1 )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 0 , 1734574929004 )
2024-12-27 12:08:21 +00:00
tdSql . checkData ( 0 , 1 , ' 4.0 ' )
tdSql . checkData ( 0 , 2 , ' bbbbbbbbb2 ' )
tdSql . checkData ( 0 , 3 , False )
tdSql . checkData ( 0 , 4 , 1734574929000 )
tdSql . checkData ( 0 , 5 , ' 1.0 ' )
2025-01-02 07:31:02 +00:00
tdSql . checkData ( 0 , 6 , ' c2 ' )
2024-12-27 12:08:21 +00:00
tdSql . checkData ( 0 , 7 , True )
2024-12-26 03:13:51 +00:00
2025-02-05 07:26:03 +00:00
tdSql . execute ( f ' drop table if exists db.st ' )
2024-12-26 03:13:51 +00:00
2024-12-19 02:48:40 +00:00
def funcNestTest ( self ) :
tdSql . execute ( ' create database db; ' )
tdSql . execute ( ' use db ' )
tdSql . execute ( f ' drop table if exists db.d1 ' )
tdSql . execute ( ' create table db.d1 (ts timestamp, c0 int, c1 float, c2 nchar(30), c3 bool) ' )
tdSql . execute ( ' insert into db.d1 values(1734574929000, 1, 1.1, " a " , true) ' )
tdSql . execute ( ' insert into db.d1 values(1734574930000, 2, 2.2, " bbbbbbbbb " , false) ' )
2025-01-02 07:31:02 +00:00
groupby = [ " " , " group by tbname order ts " , " group by tbname order t1 " , " group by tbname order ts " ]
2024-12-19 02:48:40 +00:00
tdSql . query ( f ' select cols(last(c0), ts, c2), cols(first(c0), ts, c2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c2 ' , ' ts ' , ' c2 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 0 , 1734574930000 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 1 , ' bbbbbbbbb ' )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 2 , 1734574929000 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 3 , ' a ' )
2024-12-19 02:48:40 +00:00
tdSql . query ( f ' select cols(last(c0), ts, c1, c2, c3), cols(first(c0), ts, c1, c2, c3) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c1 ' , ' c2 ' , ' c3 ' , ' ts ' , ' c1 ' , ' c2 ' , ' c3 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 8 )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 0 , 1734574930000 )
tdSql . checkData ( 0 , 1 , 2.2 )
tdSql . checkData ( 0 , 2 , ' bbbbbbbbb ' )
tdSql . checkData ( 0 , 3 , False )
tdSql . checkData ( 0 , 4 , 1734574929000 )
tdSql . checkData ( 0 , 5 , 1.1 )
tdSql . checkData ( 0 , 6 , ' a ' )
tdSql . checkData ( 0 , 7 , True )
tdSql . query ( f ' select cols(last(ts), c1), cols(first(ts), c1) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c1 ' , ' c1 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 2 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 0 , 2.2 )
tdSql . checkData ( 0 , 1 , 1.1 )
2024-12-19 02:48:40 +00:00
2024-12-25 00:58:07 +00:00
tdSql . query ( f ' select cols(first(ts), c0, c1), cols(first(ts), c0, c1) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' c1 ' , ' c0 ' , ' c1 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 0 , 1 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 1 , 1.1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 0 , 3 , 1.1 )
2024-12-19 02:48:40 +00:00
2024-12-25 00:58:07 +00:00
tdSql . query ( f ' select cols(first(ts), c0, c1), cols(first(ts+1), c0, c1) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' c1 ' , ' c0 ' , ' c1 ' ] )
2024-12-25 00:58:07 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1.1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 0 , 3 , 1.1 )
tdSql . query ( f ' select cols(first(ts), c0, c1), cols(first(ts), c0+1, c1+2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' c0 ' , ' c1 ' , ' c0+1 ' , ' c1+2 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 0 , 1 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 1 , 1.1 )
tdSql . checkData ( 0 , 2 , 2 )
tdSql . checkData ( 0 , 3 , 3.1 )
tdSql . query ( f ' select cols(first(c0), ts, length(c2)), cols(last(c0), ts, length(c2)) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' length(c2) ' , ' ts ' , ' length(c2) ' ] )
2024-12-25 00:58:07 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-25 00:58:07 +00:00
tdSql . checkData ( 0 , 0 , 1734574929000 )
2024-12-25 10:27:50 +00:00
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574930000 )
tdSql . checkData ( 0 , 3 , 36 )
tdSql . query ( f ' select cols(first(c0), ts, length(c2)), cols(last(c0), ts, length(c2) + 2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' length(c2) ' , ' ts ' , ' length(c2) + 2 ' ] )
2024-12-19 02:48:40 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-19 02:48:40 +00:00
tdSql . checkData ( 0 , 0 , 1734574929000 )
2024-12-25 10:27:50 +00:00
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574930000 )
tdSql . checkData ( 0 , 3 , 38 )
tdSql . query ( f ' select cols(first(c0), ts, c2), cols(last(c0), ts, length(c2) + 2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c2 ' , ' ts ' , ' length(c2) + 2 ' ] )
2024-12-25 10:27:50 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-25 10:27:50 +00:00
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , ' a ' )
tdSql . checkData ( 0 , 2 , 1734574930000 )
tdSql . checkData ( 0 , 3 , 38 )
tdSql . query ( f ' select cols(min(c0), ts, c2), cols(last(c0), ts, length(c2) + 2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c2 ' , ' ts ' , ' length(c2) + 2 ' ] )
2024-12-25 10:27:50 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-25 10:27:50 +00:00
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , ' a ' )
tdSql . checkData ( 0 , 2 , 1734574930000 )
tdSql . checkData ( 0 , 3 , 38 )
2024-12-19 02:48:40 +00:00
2024-12-25 10:27:50 +00:00
tdSql . query ( f ' select cols(min(c0), ts, c2), cols(first(c0), ts, length(c2) + 2) from db.d1 ' )
2025-01-23 07:37:21 +00:00
tdSql . checkResColNameList ( [ ' ts ' , ' c2 ' , ' ts ' , ' length(c2) + 2 ' ] )
2024-12-25 10:27:50 +00:00
tdSql . checkRows ( 1 )
2024-12-29 23:56:02 +00:00
tdSql . checkCols ( 4 )
2024-12-25 10:27:50 +00:00
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , ' a ' )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 6 )
2025-01-01 11:17:12 +00:00
2025-02-18 05:06:13 +00:00
def orderby_test ( self , from_table = ' test.meters ' , col_name = ' c0 ' , isTmpTable = False ) :
2025-01-02 07:31:02 +00:00
select_t1 = [ " " , " , t1 " , " , t1 as tag1 " ]
for t1 in select_t1 :
if t1 != " " and isTmpTable :
# Not a GROUP BY expression
2025-02-18 05:06:13 +00:00
tdSql . error ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
tdSql . error ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
tdSql . error ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
tdSql . error ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
tdSql . error ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
tdSql . error ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
tdSql . error ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
tdSql . error ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
tdSql . error ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
tdSql . error ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
tdSql . error ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
tdSql . error ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
2025-01-02 07:31:02 +00:00
continue
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tags_count = 0 if t1 == " " else 1
tdLog . debug ( f ' tags_count: { tags_count } ' )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 5 )
tdSql . checkData ( 0 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st2 ' )
2025-04-02 03:31:08 +00:00
tdSql . error ( f ' select count(1), cols(last( { col_name } ),*) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), *) ' )
#tdSql.query(f'select count(1), cols(last({col_name}),c2) {t1} from {from_table} group by tbname order by cols(last({col_name}), *)')
2025-01-02 07:31:02 +00:00
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by 1 ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by 2 ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 5 )
tdSql . checkData ( 0 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st2 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), cols(last( { col_name } ),c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 5 )
tdSql . checkData ( 0 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st2 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), last(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' bbbbbbbbb2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 5 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 1 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st2 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), c2) desc ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-02-18 05:06:13 +00:00
tdSql . query ( f ' select count(1), max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
2025-01-02 07:31:02 +00:00
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 0 , 5 )
tdSql . checkData ( 1 , 1 , ' c2 ' )
2025-02-18 05:06:13 +00:00
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
tdSql . query ( f ' select _rowts, max(c2) { t1 } from { from_table } group by tbname order by cols(last( { col_name } ), { col_name } ), cols(last( { col_name } ), c1) ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 + tags_count )
tdSql . checkData ( 0 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 0 , 2 , ' st2 ' )
tdSql . checkData ( 1 , 1 , ' c2 ' )
self . condition_check ( t1 != " " , 1 , 2 , ' st1 ' )
2025-01-02 07:31:02 +00:00
2024-12-09 08:21:14 +00:00
def parse_test ( self ) :
tdLog . info ( " parse test " )
#** error sql **#
tdSql . error ( f ' select cols(ts) from { self . dbname } .meters group by tbname ' )
tdSql . error ( f ' select cols(ts) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(ts)) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(ts, ts)) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(ts, ts), ts) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), ts as t1) as t1 from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), ts, c0) t1 from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), ts t1) tt from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), c0 cc0, c1 cc1) cc from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), c0 as cc0) as cc from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(ts) + 1 from { self . dbname } .meters group by tbname ' )
tdSql . error ( f ' select last(cols(ts)+1) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(ts+1, ts)) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(ts, ts), ts+1) from { self . dbname } .meters ' )
tdSql . error ( f ' select last(cols(last(ts+1), ts+1), ts) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), ts+1 as t1) as t1 from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts+1), ts, c0) t1 from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts), ts t1) tt from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(first(ts+1), c0+2 cc0, c1 cc1) cc from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts)+1, c0+2 as cc0) as cc from { self . dbname } .meters ' )
2024-12-30 10:21:26 +00:00
tdSql . error ( f ' select cols(ABS(c0), c1) from { self . dbname } .meters group by tbname ' )
2025-02-23 16:06:22 +00:00
tdSql . error ( f ' select cols(top(c0, 5), c1) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(tail(c0, 5),c1) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(BOTTOM(c0, 5),c1) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(tail(ts, 5),c1) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(UNIQUE(ts),c1) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(sample(ts, 5),c1) from { self . dbname } .meters ' )
2024-12-09 08:21:14 +00:00
tdSql . error ( f ' select cols(last(ts)+1, ts) from { self . dbname } .meters ' )
tdSql . error ( f ' select cols(last(ts)+10, c1+10) from { self . dbname } .meters group by tbname ' )
2024-12-19 02:48:40 +00:00
tdSql . error ( f ' select cols(cols(last(ts), c0), c0) as cc from { self . dbname } .meters ' )
2024-12-26 03:13:51 +00:00
tdSql . error ( f ' select cols(last(ts), cols(last(ts), c0), c0) as cc from { self . dbname } .meters ' )
2025-01-02 07:31:02 +00:00
# Aggregate functions do not support nesting
tdSql . error ( f ' select count(1), cols(last_row(ts), ts, first(c0)), last_row(c1) from { self . dbname } .meters ' )
2024-12-19 02:48:40 +00:00
2025-01-02 07:31:02 +00:00
# Not a GROUP BY expression
tdSql . error ( f ' select count(1), cols(last(c0),c0) from test.meters group by tbname order by c3 desc ' )
def subquery_test ( self ) :
tdSql . query ( f ' select count(1), cols(last(c0),c0) from (select * from test.d0) ' )
tdSql . query ( f ' select count(1), cols(last(c0),c0) from (select *, tbname from test.meters) group by tbname ' )
tdLog . info ( " subquery_test: orderby_test from meters " )
2025-02-18 05:06:13 +00:00
self . orderby_test ( " test.meters " , " c0 " , False )
2025-01-02 07:31:02 +00:00
tdLog . info ( " subquery_test: orderby_test from (select *, tbname from meters) " )
2025-02-18 05:06:13 +00:00
self . orderby_test ( " (select *, tbname from test.meters) " , " c0 " , True )
2025-01-02 07:31:02 +00:00
tdLog . info ( " subquery_test: one_cols_multi_output_with_group_test from meters " )
self . one_cols_multi_output_with_group_test ( " test.meters " , False )
tdLog . info ( " subquery_test: one_cols_multi_output_with_group_test from (select *, tbname from meters) " )
self . one_cols_multi_output_with_group_test ( " (select *, tbname from test.meters) " , True )
self . one_cols_multi_output_test ( " test.meters " )
self . one_cols_multi_output_test ( " (select *, tbname from test.meters) " )
2025-02-18 05:06:13 +00:00
2025-01-02 07:31:02 +00:00
def window_test ( self ) :
tdSql . query ( f ' select tbname, _wstart,_wend, max(c0), max(c1), cols( max(c0), c1) from test.meters partition \
2025-02-06 01:39:39 +00:00
by tbname count_window ( 2 ) order by tbname ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 6 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 3 , 0 , ' d1 ' )
tdSql . checkData ( 3 , 5 , 1 )
tdSql . query ( f ' select _wstart,_wend, max(c0), max(c1), cols( max(c0), c1) from test.d1 count_window(2); ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 4 , 1 )
tdSql . query ( f ' select _wstart,_wend, max(c0), max(c1), cols( max(c0), c1) from test.normal_table count_window(2); ' )
tdSql . checkRows ( 3 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 4 , 2 )
2025-02-21 08:32:39 +00:00
tdSql . query ( f ' select c0, cols(first(ts), c0, c1) from test.meters state_window(c0) order by c0 ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 1 , 0 , 2 )
tdSql . checkData ( 1 , 1 , 2 )
tdSql . checkData ( 1 , 2 , 2 )
tdSql . checkData ( 2 , 0 , 3 )
tdSql . query ( f ' select c0, cols(first(ts), c0, c1), tbname from test.meters state_window(c0) ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 0 , 3 , ' d0 ' )
tdSql . checkData ( 1 , 0 , 2 )
tdSql . checkData ( 1 , 1 , 2 )
tdSql . checkData ( 1 , 2 , 2 )
tdSql . checkData ( 2 , 0 , 3 )
tdSql . query ( f ' select c0, cols(first(ts), c0, c1), t1 from test.meters state_window(c0) ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 0 , 3 , ' st1 ' )
tdSql . checkData ( 1 , 0 , 2 )
tdSql . checkData ( 1 , 1 , 2 )
tdSql . checkData ( 1 , 2 , 2 )
tdSql . checkData ( 2 , 0 , 3 )
tdSql . error ( f ' select tbname, c0, cols(first(ts), c0, c1), cols(last(ts), c0) from test.meters state_window(c0) ' )
def window_test2 ( self ) :
tdSql . query ( f ' select cols(first(ts), c0, c1), count(1) from test.meters session(ts, 3) ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 6 )
tdSql . checkData ( 1 , 0 , 0 )
tdSql . checkData ( 1 , 1 , None )
tdSql . checkData ( 1 , 2 , 5 )
tdSql . query ( f ' select cols(max(c0), c1), count(1) from test.meters session(ts, 3) ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 4 )
tdSql . checkData ( 0 , 1 , 6 )
tdSql . checkData ( 1 , 0 , None )
tdSql . checkData ( 1 , 1 , 5 )
tdSql . query ( f ' select cols(first(ts), c0, c1), first(ts), count(1) from test.meters session(ts, 3) ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 4 )
tdSql . query ( f ' select cols(first(ts), c0, c1), first(ts), count(1) from test.meters event_window start with c3=true end with c3!=true ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . checkData ( 0 , 1 , 1 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 3 )
tdSql . checkData ( 1 , 0 , 3 )
tdSql . checkData ( 1 , 1 , 3 )
tdSql . checkData ( 1 , 2 , 1734574929003 )
tdSql . checkData ( 1 , 3 , 2 )
tdSql . query ( f ' select first(ts), count(1) from test.meters event_window start with c3=true end with c3!=true ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 1734574929000 )
tdSql . checkData ( 0 , 1 , 3 )
tdSql . checkData ( 1 , 0 , 1734574929003 )
tdSql . checkData ( 1 , 1 , 2 )
2024-12-09 08:21:14 +00:00
2025-02-06 01:39:39 +00:00
def join_test ( self ) :
tdSql . query ( f ' select cols(last(a.ts), a.c0) from test.d0 a join test.d1 b on a.ts = b.ts; ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 1 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . query ( f ' select cols(last(a.ts), a.c0) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0 = b.c0; ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 1 )
tdSql . checkData ( 0 , 0 , 1 )
tdSql . query ( f ' select cols(last(a.ts), a.c0) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0 > b.c0; ' )
tdSql . checkRows ( 0 )
tdSql . query ( f ' select tbname, ts, c0 from (select cols(last(a.ts), a.tbname, a.ts, a.c0) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0=b.c0) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . query ( f ' select tbname, ts, c0 from (select cols(first(a.ts), a.tbname, a.ts, a.c0) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0=b.c0) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . error ( f ' select tbname, ts, c0 from (select cols(first(a.ts), a.tbname, a.ts, a.c0), cols(last(a.ts), b.tbname, b.ts, b.c0) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0=b.c0) ' )
tdSql . query ( f ' select tbname, ts, c0 from (select cols(first(a.ts), a.tbname, a.ts, a.c0), cols(last(a.ts), b.tbname tbname1, b.ts ts2, b.c0 c02) from test.d0 a join test.d1 b on a.ts = b.ts and a.c0=b.c0) ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
2025-02-11 09:33:34 +00:00
tdSql . checkData ( 0 , 2 , 1 )
def stream_cols_test ( self ) :
2025-04-02 03:31:08 +00:00
tdSql . execute ( f ' CREATE STREAM last_col_s1 INTO { self . dbname } .last_col1 AS SELECT cols(last(ts), ts, c0) FROM { self . dbname } .meters PARTITION BY tbname INTERVAL(1s) SLIDING(1s); ' )
tdSql . execute ( f ' CREATE STREAM last_col_s2 INTO { self . dbname } .last_col2 AS SELECT last(ts), c0 FROM { self . dbname } .meters PARTITION BY tbname INTERVAL(1s) SLIDING(1s); ' )
tdSql . waitedQuery ( f ' show streams ' , 2 , 10 )
sleep ( 5 )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574930000, 0, 1, NULL, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574931000, 1, 1, NULL, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574932000, 2, 2, NULL, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574933000, 3, 3, NULL, NULL) ' )
tdSql . waitedQuery ( f ' select * from { self . dbname } .last_col2 ' , 3 , 10 )
tdSql . waitedQuery ( f ' select * from { self . dbname } .last_col1 ' , 3 , 10 )
tdSql . query ( f ' select * from { self . dbname } .last_col1 ' )
tdSql . checkRows ( 3 )
tdSql . checkData ( 0 , 0 , 1734574930000 )
tdSql . checkData ( 0 , 1 , 1734574930000 )
tdSql . checkData ( 0 , 2 , 0 )
tdSql . checkData ( 1 , 0 , 1734574931000 )
tdSql . checkData ( 1 , 1 , 1734574931000 )
tdSql . checkData ( 1 , 2 , 1 )
tdSql . checkData ( 2 , 0 , 1734574932000 )
tdSql . checkData ( 2 , 1 , 1734574932000 )
tdSql . checkData ( 2 , 2 , 2 )
def stream_cols_test2 ( self ) :
db2 = " test2 "
tdSql . execute ( f ' create database { db2 } ' )
tdSql . execute ( f ' create table { db2 } .st (ts timestamp, c0 int) tags (t1 int) ' )
tdSql . execute ( f ' create table { db2 } .st_1 using { db2 } .st tags(1) ' )
tdSql . execute ( f ' create table { db2 } .st_2 using { db2 } .st tags(2) ' )
tdSql . execute ( f ' CREATE STREAM col1 INTO { db2 } .colt1 AS SELECT cols(min(c0), ts min_ts, c0 min_c0), cols(max(c0), ts max_ts, c0 max_c0) FROM { db2 } .st PARTITION BY tbname INTERVAL(1s) SLIDING(1s); ' )
tdSql . execute ( f ' CREATE STREAM col2 INTO { db2 } .colt2 AS SELECT min(c0), max(c0) FROM { db2 } .st PARTITION BY tbname INTERVAL(1s) SLIDING(1s); ' )
2025-02-13 11:08:58 +00:00
2025-04-02 03:31:08 +00:00
tdSql . waitedQuery ( f ' show streams ' , 4 , 10 )
time . sleep ( 5 )
tdSql . execute ( f ' insert into { db2 } .st_1 values(1734574930000, 0), (1734574930100, 1), (1734574930200, 2), (1734574930300, 3) ' )
tdSql . execute ( f ' insert into { db2 } .st_1 values(1734574931000, 1), (1734574931100, 2), (1734574931200, 3), (1734574931300, 4) ' )
tdSql . execute ( f ' insert into { db2 } .st_1 values(1734574932000, 2), (1734574932100, 3), (1734574932200, 4), (1734574932300, 5) ' )
tdSql . execute ( f ' insert into { db2 } .st_1 values(1734574933000, 3), (1734574933100, 4), (1734574933200, 5), (1734574933300, 6) ' )
tdSql . waitedQuery ( f ' select * from { db2 } .colt2 ' , 3 , 10 )
tdSql . query ( f ' select * from { db2 } .colt2 ' )
tdSql . checkRows ( 3 )
tdSql . checkData ( 0 , 1 , 0 )
tdSql . checkData ( 0 , 2 , 3 )
tdSql . checkData ( 1 , 1 , 1 )
tdSql . checkData ( 1 , 2 , 4 )
tdSql . checkData ( 2 , 1 , 2 )
tdSql . checkData ( 2 , 2 , 5 )
tdSql . query ( f " select * from { db2 } .colt1 " )
tdSql . checkRows ( 3 )
tdSql . checkData ( 0 , 1 , 1734574930000 )
tdSql . checkData ( 0 , 2 , 0 )
tdSql . checkData ( 0 , 3 , 1734574930300 )
tdSql . checkData ( 0 , 4 , 3 )
tdSql . checkData ( 1 , 1 , 1734574931000 )
tdSql . checkData ( 1 , 2 , 1 )
tdSql . checkData ( 1 , 3 , 1734574931300 )
tdSql . checkData ( 1 , 4 , 4 )
tdSql . checkData ( 2 , 1 , 1734574932000 )
tdSql . checkData ( 2 , 2 , 2 )
tdSql . checkData ( 2 , 3 , 1734574932300 )
tdSql . checkData ( 2 , 4 , 5 )
2025-02-13 11:08:58 +00:00
def include_null_test ( self ) :
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929010, 0, NULL, NULL, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929011, NULL, 1, NULL, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929012, NULL, NULL, 2, NULL) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929013, NULL, NULL, NULL, false) ' )
tdSql . execute ( f ' insert into { self . dbname } .d0 values(1734574929014, NULL, NULL, NULL, NULL) ' )
tdSql . query ( f ' select cols(last(c0), ts), cols(last(c1), ts), cols(last(c2), ts), cols(last(c3), ts) from { self . dbname } .d0 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , 1734574929010 )
tdSql . checkData ( 0 , 1 , 1734574929011 )
tdSql . checkData ( 0 , 2 , 1734574929012 )
tdSql . checkData ( 0 , 3 , 1734574929013 )
2025-02-18 05:06:13 +00:00
def long_column_name_test ( self ) :
tdSql . execute ( f ' use { self . dbname } ' )
tdSql . execute ( f ' create table { self . dbname } .long_col_test (ts timestamp, longcolumntestlongcolumntestlongcolumntestlongcolumntest88888888 int, c1 float, c2 nchar(30), c3 bool) tags (t1 nchar(30)) ' )
tdSql . execute ( f ' create table { self . dbname } .dl0 using { self . dbname } .long_col_test tags( " st1 " ) ' )
tdSql . execute ( f ' create table { self . dbname } .dl1 using { self . dbname } .long_col_test tags( " st2 " ) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl0 values(1734574929000, 1, 1, " c2 " , true) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl0 values(1734574929001, 2, 2, " bbbbbbbbb1 " , false) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl0 values(1734574929002, 2, 2, " bbbbbbbbb1 " , false) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl0 values(1734574929003, 3, 3, " a2 " , true) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl0 values(1734574929004, 4, 4, " bbbbbbbbb2 " , false) ' )
tdSql . execute ( f ' insert into { self . dbname } .dl1 values(1734574929000, 1, 1, " c2 " , true) ' )
tdSql . query ( f ' select cols(last(longcolumntestlongcolumntestlongcolumntestlongcolumntest88888888),ts lts, c1 lc1), cols(first(longcolumntestlongcolumntestlongcolumntestlongcolumntest88888888), ts fts, c1 as fc1), count(1) from test.long_col_test ' )
tdSql . checkResColNameList ( [ ' lts ' , ' lc1 ' , ' fts ' , ' fc1 ' , ' count(1) ' ] )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 5 )
tdSql . checkData ( 0 , 0 , 1734574929004 )
tdSql . checkData ( 0 , 1 , 4 )
tdSql . checkData ( 0 , 2 , 1734574929000 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , 6 )
2025-02-13 11:08:58 +00:00
2025-02-18 05:06:13 +00:00
tdLog . info ( " long_column_name_test subquery_test: orderby_test from meters " )
self . orderby_test ( " test.long_col_test " , " longcolumntestlongcolumntestlongcolumntestlongcolumntest88888888 " , False )
tdLog . info ( " long_column_name_test subquery_test: orderby_test from (select *, tbname from meters) " )
self . orderby_test ( " (select *, tbname from test.long_col_test) " , " longcolumntestlongcolumntestlongcolumntestlongcolumntest88888888 " , True )
tdLog . info ( " long_column_name_test subquery_test: one_cols_multi_output_with_group_test from meters " )
2025-02-11 09:33:34 +00:00
2025-02-20 08:29:23 +00:00
def test_in_interval ( self ) :
2025-02-18 12:14:05 +00:00
dbname = " db1 "
tdSql . execute ( f " drop database if exists { dbname } " )
tdSql . execute ( f " create database { dbname } vgroups 6 " )
tdSql . execute ( f " use { dbname } " )
tdSql . execute ( f " create stable { dbname } .sta (ts timestamp, f1 int, f2 binary(10), f3 bool) tags(t1 int, t2 bool, t3 binary(10)); " )
tdSql . execute ( f " create table { dbname } .tba1 using sta tags(0, false, ' 0 ' ); " )
tdSql . execute ( f " create table { dbname } .tba2 using sta tags(1, true, ' 1 ' ); " )
tdSql . execute ( f " create table { dbname } .tba3 using sta tags(null, null, ' ' ); " )
tdSql . execute ( f " create table { dbname } .tba4 using sta tags(1, false, null); " )
tdSql . execute ( f " create table { dbname } .tba5 using sta tags(3, true, ' aa ' ); " )
tdSql . execute ( f " insert into { dbname } .tba1 values ( ' 2022-09-26 15:15:01 ' , 0, ' a ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba1 values ( ' 2022-09-26 15:15:02 ' , 1, ' 0 ' , true); " )
tdSql . execute ( f " insert into { dbname } .tba1 values ( ' 2022-09-26 15:15:03 ' , 5, ' 5 ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba1 values ( ' 2022-09-26 15:15:04 ' , null, null, null); " )
tdSql . execute ( f " insert into { dbname } .tba2 values ( ' 2022-09-27 15:15:01 ' , 0, ' a ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba2 values ( ' 2022-09-27 15:15:02 ' , 1, ' 0 ' , true); " )
tdSql . execute ( f " insert into { dbname } .tba2 values ( ' 2022-09-27 15:15:03 ' , 5, ' 5 ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba2 values ( ' 2022-09-27 15:15:04 ' , null, null, null); " )
tdSql . execute ( f " insert into { dbname } .tba3 values ( ' 2022-09-28 15:15:01 ' , 0, ' a ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba3 values ( ' 2022-09-28 15:15:02 ' , 1, ' 0 ' , true); " )
tdSql . execute ( f " insert into { dbname } .tba3 values ( ' 2022-09-28 15:15:03 ' , 5, ' 5 ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba3 values ( ' 2022-09-28 15:15:04 ' , null, null, null); " )
tdSql . execute ( f " insert into { dbname } .tba4 values ( ' 2022-09-29 15:15:01 ' , 0, ' a ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba4 values ( ' 2022-09-29 15:15:02 ' , 1, ' 0 ' , true); " )
tdSql . execute ( f " insert into { dbname } .tba4 values ( ' 2022-09-29 15:15:03 ' , 5, ' 5 ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba4 values ( ' 2022-09-29 15:15:04 ' , null, null, null); " )
tdSql . execute ( f " insert into { dbname } .tba5 values ( ' 2022-09-30 15:15:01 ' , 0, ' a ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba5 values ( ' 2022-09-30 15:15:02 ' , 1, ' 0 ' , true); " )
tdSql . execute ( f " insert into { dbname } .tba5 values ( ' 2022-09-30 15:15:03 ' , 5, ' 5 ' , false); " )
tdSql . execute ( f " insert into { dbname } .tba5 values ( ' 2022-09-30 15:15:04 ' , null, null, null); " )
tdSql . query ( f ' select tbname, cols(last(ts), ts as ts1), cols(last(f1), ts as ts2) from tba5 interval(1s); ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 1 , " 2022-09-30 15:15:01 " )
tdSql . checkData ( 0 , 2 , " 2022-09-30 15:15:01 " )
tdSql . checkData ( 1 , 1 , " 2022-09-30 15:15:02 " )
tdSql . checkData ( 1 , 2 , " 2022-09-30 15:15:02 " )
tdSql . checkData ( 2 , 1 , " 2022-09-30 15:15:03 " )
tdSql . checkData ( 2 , 2 , " 2022-09-30 15:15:03 " )
tdSql . checkData ( 3 , 1 , " 2022-09-30 15:15:04 " )
2025-02-20 08:29:23 +00:00
tdSql . checkData ( 3 , 2 , None )
2025-02-18 12:14:05 +00:00
2025-02-20 08:29:23 +00:00
tdSql . query ( f ' select tbname, last(f1), ts from tba5 interval(1s) ' )
tdSql . checkRows ( 3 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 1 , 0 )
2025-02-18 12:14:05 +00:00
tdSql . checkData ( 0 , 2 , " 2022-09-30 15:15:01 " )
2025-02-20 08:29:23 +00:00
tdSql . checkData ( 1 , 1 , 1 )
2025-02-18 12:14:05 +00:00
tdSql . checkData ( 1 , 2 , " 2022-09-30 15:15:02 " )
2025-02-20 08:29:23 +00:00
tdSql . checkData ( 2 , 1 , 5 )
2025-02-18 12:14:05 +00:00
tdSql . checkData ( 2 , 2 , " 2022-09-30 15:15:03 " )
2025-02-20 08:29:23 +00:00
tdSql . query ( f ' select tbname, last(ts) from tba5 interval(1s) ' )
tdSql . checkData ( 0 , 1 , " 2022-09-30 15:15:01 " )
tdSql . checkData ( 1 , 1 , " 2022-09-30 15:15:02 " )
tdSql . checkData ( 2 , 1 , " 2022-09-30 15:15:03 " )
2025-02-18 12:14:05 +00:00
tdSql . checkData ( 3 , 1 , " 2022-09-30 15:15:04 " )
2025-02-18 17:32:02 +00:00
tdSql . query ( f ' select tbname, cols(last(ts), ts as ts1), cols(last(f1), ts as ts2) from { dbname } .sta group by tbname; ' )
tdSql . checkRows ( 5 )
tdSql . checkCols ( 3 )
tdSql . query ( f ' select tbname, cols(last(ts), ts as ts1), cols(last(f1), ts as ts2) from { dbname } .sta group by tbname order by ts1; ' )
tdSql . checkRows ( 5 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 1 , " 2022-09-26 15:15:04 " )
tdSql . checkData ( 0 , 2 , " 2022-09-26 15:15:03 " )
tdSql . checkData ( 1 , 1 , " 2022-09-27 15:15:04 " )
tdSql . checkData ( 1 , 2 , " 2022-09-27 15:15:03 " )
tdSql . checkData ( 2 , 1 , " 2022-09-28 15:15:04 " )
tdSql . checkData ( 2 , 2 , " 2022-09-28 15:15:03 " )
tdSql . checkData ( 3 , 1 , " 2022-09-29 15:15:04 " )
tdSql . checkData ( 3 , 2 , " 2022-09-29 15:15:03 " )
tdSql . checkData ( 4 , 1 , " 2022-09-30 15:15:04 " )
tdSql . checkData ( 4 , 2 , " 2022-09-30 15:15:03 " )
tdSql . query ( f ' select t1, cols(last(ts), ts as ts1), cols(last(f1), ts as ts2) from { dbname } .sta group by t1; ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 3 )
tdSql . query ( f ' select t1, cols(last(ts), ts as ts1), cols(last(f1), ts as ts2) from { dbname } .sta group by t1 order by ts1; ' )
tdSql . checkRows ( 4 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 1 , " 2022-09-26 15:15:04 " )
tdSql . checkData ( 0 , 2 , " 2022-09-26 15:15:03 " )
tdSql . checkData ( 1 , 1 , " 2022-09-28 15:15:04 " )
tdSql . checkData ( 1 , 2 , " 2022-09-28 15:15:03 " )
tdSql . checkData ( 2 , 1 , " 2022-09-29 15:15:04 " )
tdSql . checkData ( 2 , 2 , " 2022-09-29 15:15:03 " )
tdSql . checkData ( 3 , 1 , " 2022-09-30 15:15:04 " )
tdSql . checkData ( 3 , 2 , " 2022-09-30 15:15:03 " )
2025-02-19 05:15:25 +00:00
def having_test ( self , table_name , is_subquery ) :
tdLog . info ( " having_test " )
t1 = f " from { table_name } "
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) > 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929014 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) = 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d1 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) < 1734574929000 ' )
tdSql . checkRows ( 0 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) != 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929014 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) >= 1734574929000 ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d1 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . checkData ( 1 , 0 , ' d0 ' )
tdSql . checkData ( 1 , 1 , 1734574929014 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(ts), ts) <= 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d1 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . query ( f ' select tbname, cols(last(ts), ts) { t1 } group by tbname having cols(last(c0), ts) between 1734574929000 and 1734574929014 ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , ' d1 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . checkData ( 1 , 0 , ' d0 ' )
tdSql . checkData ( 1 , 1 , 1734574929014 )
2025-04-02 03:31:08 +00:00
def star_test ( self ) :
tdLog . info ( " star_test " )
tdSql . query ( f ' select tbname, cols(last(ts), *) from test.meters group by tbname having cols(last(ts), ts) > 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 7 )
tdSql . checkData ( 0 , 0 , ' d0 ' )
tdSql . checkData ( 0 , 1 , 1734574929014 )
tdSql . query ( f ' select tbname, cols(last(ts), *) from test.meters group by tbname having cols(last(ts), ts) = 1734574929000 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 7 )
tdSql . checkData ( 0 , 0 , ' d1 ' )
tdSql . checkData ( 0 , 1 , 1734574929000 )
tdSql . checkData ( 0 , 2 , 1 )
tdSql . checkData ( 0 , 3 , 1 )
tdSql . checkData ( 0 , 4 , ' c2 ' )
tdSql . checkData ( 0 , 5 , True )
tdSql . error ( f ' select tbname, cols(last(ts), *) from test.meters group by tbname having cols(last(ts), *) = 1734574929000 ' )
2025-02-19 05:15:25 +00:00
2025-02-20 08:29:23 +00:00
def test_null2 ( self ) :
dbname = " test_null2 "
tdSql . execute ( f " drop database if exists { dbname } " )
tdSql . execute ( f " create database test_null2 vgroups 5 " )
tdSql . execute ( f " use test_null2 " )
tdSql . execute ( f " create stable { dbname } .stb_null1 (ts timestamp, c0 int, c1 int, c2 nchar(30), c3 bool) tags (t1 nchar(30)) " )
tdSql . execute ( f " create table { dbname } .sub_null_1 using { dbname } .stb_null1 tags( ' st1 ' ) " )
tdSql . execute ( f " create table { dbname } .sub_null_2 using { dbname } .stb_null1 tags( ' st2 ' ) " )
tdSql . execute ( f " insert into { dbname } .sub_null_1 values(1734574929000, 1, null, null, null) " )
tdSql . execute ( f " insert into { dbname } .sub_null_1 values(1734574929001, 2, null, null, null) " )
tdSql . execute ( f " insert into { dbname } .sub_null_2 values(1734574929000, 21, null, null, null) " )
tdSql . execute ( f " insert into { dbname } .sub_null_2 values(1734574929001, 22, null, null, null) " )
tdSql . query ( f ' select cols(last(ts), ts), cols(last(c2), ts) from { dbname } .stb_null1 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 2 )
tdSql . checkData ( 0 , 0 , 1734574929001 )
tdSql . checkData ( 0 , 1 , None )
tdSql . query ( f ' select tbname, cols(last(ts), c0), cols(last(c2), c0) from { dbname } .stb_null1 group by tbname order by tbname ' )
tdSql . checkRows ( 2 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , ' sub_null_1 ' )
tdSql . checkData ( 0 , 1 , 2 )
tdSql . checkData ( 0 , 2 , None )
tdSql . checkData ( 1 , 0 , ' sub_null_2 ' )
tdSql . checkData ( 1 , 1 , 22 )
tdSql . checkData ( 1 , 2 , None )
tdSql . query ( f ' select tbname, t1, cols(last(ts), c0), cols(last(c2), c0) from { dbname } .sub_null_1 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , ' sub_null_1 ' )
tdSql . checkData ( 0 , 1 , " st1 " )
tdSql . checkData ( 0 , 2 , 2 )
tdSql . checkData ( 0 , 3 , None )
tdSql . query ( f ' select tbname, t1, cols(last(ts), c0), cols(last(c2), ts) from { dbname } .sub_null_2 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 4 )
tdSql . checkData ( 0 , 0 , ' sub_null_2 ' )
tdSql . checkData ( 0 , 1 , " st2 " )
tdSql . checkData ( 0 , 2 , 22 )
tdSql . checkData ( 0 , 3 , None )
tdSql . query ( f ' select tbname, cols(last(ts), c0), cols(last(c2), c0) from { dbname } .sub_null_1 ' )
tdSql . checkRows ( 1 )
tdSql . checkCols ( 3 )
tdSql . checkData ( 0 , 0 , ' sub_null_1 ' )
tdSql . checkData ( 0 , 1 , 2 )
tdSql . checkData ( 0 , 2 , None )
tdSql . error ( f ' select tbname, cols(last(ts), c0), cols(last(c2), c0) from { dbname } .stb_null1 ' )
tdSql . error ( f ' select t1, cols(last(ts), c0), cols(last(c2), c0) from { dbname } .stb_null1 ' )
2024-12-09 08:21:14 +00:00
def run ( self ) :
2024-12-19 02:48:40 +00:00
self . funcNestTest ( )
2024-12-26 03:13:51 +00:00
self . funcSupperTableTest ( )
2024-12-09 08:21:14 +00:00
self . create_test_data ( )
self . parse_test ( )
self . one_cols_1output_test ( )
self . multi_cols_output_test ( )
2025-01-01 11:17:12 +00:00
self . subquery_test ( )
2025-02-15 17:15:12 +00:00
self . window_test ( )
2025-02-06 01:39:39 +00:00
self . join_test ( )
2025-02-20 08:29:23 +00:00
self . test_in_interval ( )
2025-02-13 11:08:58 +00:00
self . include_null_test ( )
2025-02-18 05:06:13 +00:00
self . long_column_name_test ( )
2025-02-20 08:29:23 +00:00
2025-02-19 05:15:25 +00:00
self . having_test ( " test.meters " , False )
self . having_test ( " (select tbname, * from test.meters) " , True )
2025-04-02 03:31:08 +00:00
self . star_test ( )
2025-02-20 08:29:23 +00:00
self . test_null2 ( )
2025-02-21 08:32:39 +00:00
self . window_test2 ( )
2025-04-02 03:31:08 +00:00
self . stream_cols_test ( )
self . stream_cols_test2 ( )
2024-12-09 08:21:14 +00:00
2025-02-15 17:15:12 +00:00
2024-12-09 08:21:14 +00:00
def stop ( self ) :
tdSql . close ( )
tdLog . success ( " %s successfully executed " % __file__ )
tdCases . addWindows ( __file__ , TDTestCase ( ) )
tdCases . addLinux ( __file__ , TDTestCase ( ) )