TDengine/tests/army/vtable/test_vtable_join.py
Jing Sima 410324746b
feat:[TS-4897] virtual table (#30098)
* feat: [TS-4897] Support create/drop/alter/show/describe vtable

* feat: [TS-4897] Support vtable's query

* feat: [TS-4897] Support create virtual supertable

* feat: [TS-4897] Support explain analyze / where / count(*) and only select ts of vtable.

* feat: [TS-4897] Add create test and fix bugs

* feat: [TS-4897] Add alter/drop test and fix bugs

* feat: [TS-4897] Add describe/show test and fix bugs

* feat: [TS-4897] Add auth test and fix bugs

* feat: [TS-4897] Fix meta/catalog/cache bugs

* feat: [TS-4897] Support select tag from virtual child table

* feat: [TS-4897] Add select test and fix plenty of bugs

* feat: [TS-4897] Add optimize rule for vtable scan / support create vtable cross database / remove enterprise constraint / fix bugs.

* feat: [TS-4897] Fix 'schema is old'

* feat: [TS-4897] Support virtual stable query

* feat: [TS-4897] Add tests and Fix bugs

* feat: [TS-4897] resolve conflict.
2025-03-15 14:10:46 +08:00

203 lines
10 KiB
Python

###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
from frame import etool
from frame.etool import *
from frame.log import *
from frame.cases import *
from frame.sql import *
from frame.caseBase import *
from frame.common import *
class TDTestCase(TBase):
def prepare_org_tables(self):
tdLog.info(f"prepare org tables.")
tdSql.execute("drop database if exists test_vtable_join;")
tdSql.execute("create database test_vtable_join;")
tdSql.execute("use test_vtable_join;")
tdLog.info(f"prepare org super table.")
tdSql.execute("select database();")
tdSql.execute(f"CREATE STABLE `vtb_org_stb` ("
"ts timestamp, "
"u_tinyint_col tinyint unsigned, "
"u_smallint_col smallint unsigned, "
"u_int_col int unsigned, "
"u_bigint_col bigint unsigned, "
"tinyint_col tinyint, "
"smallint_col smallint, "
"int_col int, "
"bigint_col bigint, "
"float_col float, "
"double_col double, "
"bool_col bool, "
"binary_16_col binary(16),"
"binary_32_col binary(32),"
"nchar_16_col nchar(16),"
"nchar_32_col nchar(32)"
") TAGS ("
"int_tag int,"
"bool_tag bool,"
"float_tag float,"
"double_tag double,"
"nchar_32_tag nchar(32),"
"binary_32_tag binary(32))")
tdLog.info(f"prepare org child table.")
for i in range(3):
tdSql.execute(f"CREATE TABLE `vtb_org_child_{i}` USING `vtb_org_stb` TAGS ({i}, false, {i}, {i}, 'child{i}', 'child{i}');")
tdLog.info(f"prepare org normal table.")
for i in range(3):
tdSql.execute(f"CREATE TABLE `vtb_org_normal_{i}` (ts timestamp, u_tinyint_col tinyint unsigned, u_smallint_col smallint unsigned, u_int_col int unsigned, u_bigint_col bigint unsigned, tinyint_col tinyint, smallint_col smallint, int_col int, bigint_col bigint, float_col float, double_col double, bool_col bool, binary_16_col binary(16), binary_32_col binary(32), nchar_16_col nchar(16), nchar_32_col nchar(32))")
tdLog.info(f"insert data into org tables.")
datafile = etool.curFile(__file__, "data/data1.csv")
tdSql.execute("insert into vtb_org_normal_0 file '%s';" % datafile)
tdSql.execute("insert into vtb_org_child_0 file '%s';" % datafile)
datafile = etool.curFile(__file__, "data/data2.csv")
tdSql.execute("insert into vtb_org_normal_1 file '%s';" % datafile)
tdSql.execute("insert into vtb_org_child_1 file '%s';" % datafile)
datafile = etool.curFile(__file__, "data/data3.csv")
tdSql.execute("insert into vtb_org_normal_2 file '%s';" % datafile)
tdSql.execute("insert into vtb_org_child_2 file '%s';" % datafile)
tdLog.info(f"prepare virtual normal table.")
tdSql.execute(f"CREATE VTABLE `vtb_virtual_ntb_1` ("
"ts timestamp, "
"u_tinyint_col tinyint unsigned from vtb_org_normal_0.u_tinyint_col, "
"u_smallint_col smallint unsigned from vtb_org_normal_1.u_smallint_col, "
"u_int_col int unsigned from vtb_org_normal_2.u_int_col, "
"u_bigint_col bigint unsigned from vtb_org_normal_0.u_bigint_col, "
"tinyint_col tinyint from vtb_org_normal_1.tinyint_col, "
"smallint_col smallint from vtb_org_normal_2.smallint_col, "
"int_col int from vtb_org_normal_0.int_col, "
"bigint_col bigint from vtb_org_normal_1.bigint_col, "
"float_col float from vtb_org_normal_2.float_col, "
"double_col double from vtb_org_normal_0.double_col, "
"bool_col bool from vtb_org_normal_1.bool_col, "
"binary_16_col binary(16) from vtb_org_normal_2.binary_16_col,"
"binary_32_col binary(32) from vtb_org_normal_0.binary_32_col,"
"nchar_16_col nchar(16) from vtb_org_normal_1.nchar_16_col,"
"nchar_32_col nchar(32) from vtb_org_normal_2.nchar_32_col)")
tdSql.execute(f"CREATE VTABLE `vtb_virtual_ntb_2` ("
"ts timestamp, "
"u_tinyint_col tinyint unsigned from vtb_org_normal_1.u_tinyint_col, "
"u_smallint_col smallint unsigned from vtb_org_normal_2.u_smallint_col, "
"u_int_col int unsigned from vtb_org_normal_0.u_int_col, "
"u_bigint_col bigint unsigned from vtb_org_normal_1.u_bigint_col, "
"tinyint_col tinyint from vtb_org_normal_2.tinyint_col, "
"smallint_col smallint from vtb_org_normal_0.smallint_col, "
"int_col int from vtb_org_normal_1.int_col, "
"bigint_col bigint from vtb_org_normal_2.bigint_col, "
"float_col float from vtb_org_normal_0.float_col, "
"double_col double from vtb_org_normal_1.double_col, "
"bool_col bool from vtb_org_normal_2.bool_col, "
"binary_16_col binary(16) from vtb_org_normal_0.binary_16_col,"
"binary_32_col binary(32) from vtb_org_normal_1.binary_32_col,"
"nchar_16_col nchar(16) from vtb_org_normal_2.nchar_16_col,"
"nchar_32_col nchar(32) from vtb_org_normal_0.nchar_32_col)")
tdSql.execute(f"CREATE STABLE `vtb_virtual_stb` ("
"ts timestamp, "
"u_tinyint_col tinyint unsigned, "
"u_smallint_col smallint unsigned, "
"u_int_col int unsigned, "
"u_bigint_col bigint unsigned, "
"tinyint_col tinyint, "
"smallint_col smallint, "
"int_col int, "
"bigint_col bigint, "
"float_col float, "
"double_col double, "
"bool_col bool, "
"binary_16_col binary(16),"
"binary_32_col binary(32),"
"nchar_16_col nchar(16),"
"nchar_32_col nchar(32)"
") TAGS ("
"int_tag int,"
"bool_tag bool,"
"float_tag float,"
"double_tag double,"
"nchar_32_tag nchar(32),"
"binary_32_tag binary(32))"
"VIRTUAL 1")
tdLog.info(f"prepare virtual child table.")
tdSql.execute(f"CREATE VTABLE `vtb_virtual_ctb_1` ("
"u_tinyint_col from vtb_org_normal_0.u_tinyint_col, "
"u_smallint_col from vtb_org_normal_1.u_smallint_col, "
"u_int_col from vtb_org_normal_2.u_int_col, "
"u_bigint_col from vtb_org_normal_0.u_bigint_col, "
"tinyint_col from vtb_org_normal_1.tinyint_col, "
"smallint_col from vtb_org_normal_2.smallint_col, "
"int_col from vtb_org_normal_0.int_col, "
"bigint_col from vtb_org_normal_1.bigint_col, "
"float_col from vtb_org_normal_2.float_col, "
"double_col from vtb_org_normal_0.double_col, "
"bool_col from vtb_org_normal_1.bool_col, "
"binary_16_col from vtb_org_normal_2.binary_16_col,"
"binary_32_col from vtb_org_normal_0.binary_32_col,"
"nchar_16_col from vtb_org_normal_1.nchar_16_col,"
"nchar_32_col from vtb_org_normal_2.nchar_32_col)"
"USING `vtb_virtual_stb` TAGS (0, false, 0, 0, 'child0', 'child0')")
tdSql.execute(f"CREATE VTABLE `vtb_virtual_ctb_2` ("
"u_tinyint_col from vtb_org_normal_1.u_tinyint_col, "
"u_smallint_col from vtb_org_normal_2.u_smallint_col, "
"u_int_col from vtb_org_normal_0.u_int_col, "
"u_bigint_col from vtb_org_normal_1.u_bigint_col, "
"tinyint_col from vtb_org_normal_2.tinyint_col, "
"smallint_col from vtb_org_normal_0.smallint_col, "
"int_col from vtb_org_normal_1.int_col, "
"bigint_col from vtb_org_normal_2.bigint_col, "
"float_col from vtb_org_normal_0.float_col, "
"double_col from vtb_org_normal_1.double_col, "
"bool_col from vtb_org_normal_2.bool_col, "
"binary_16_col from vtb_org_normal_0.binary_16_col,"
"binary_32_col from vtb_org_normal_1.binary_32_col,"
"nchar_16_col from vtb_org_normal_2.nchar_16_col,"
"nchar_32_col from vtb_org_normal_0.nchar_32_col)"
"USING `vtb_virtual_stb` TAGS (1, false, 1, 1, 'child1', 'child1')")
def test_normal_query(self, testCase):
# read sql from .sql file and execute
tdLog.info(f"test case : {testCase}.")
self.sqlFile = etool.curFile(__file__, f"in/{testCase}.in")
self.ansFile = etool.curFile(__file__, f"ans/{testCase}.ans")
tdCom.compare_testcase_result(self.sqlFile, self.ansFile, testCase)
def test_vtable_join(self):
self.test_normal_query("test_vtable_join")
def run(self):
tdLog.debug(f"start to excute {__file__}")
self.prepare_org_tables()
self.test_vtable_join()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())