From b61bf20ebf86ca965e76be6a01c85234037999ac Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Wed, 3 Apr 2024 18:05:21 +0800 Subject: [PATCH 01/10] add test scripts for TS-4243 --- tests/parallel_test/cases.task | 3 + tests/pytest/util/csv.py | 62 ++ .../1-insert/composite_primary_key_create.py | 222 +++++ .../1-insert/composite_primary_key_delete.py | 244 ++++++ .../1-insert/composite_primary_key_insert.py | 776 ++++++++++++++++++ 5 files changed, 1307 insertions(+) create mode 100644 tests/pytest/util/csv.py create mode 100644 tests/system-test/1-insert/composite_primary_key_create.py create mode 100644 tests/system-test/1-insert/composite_primary_key_delete.py create mode 100644 tests/system-test/1-insert/composite_primary_key_insert.py diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 0cdac26a3a..101201a85e 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -308,6 +308,9 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py +,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/composite_primary_key_create.py +,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/composite_primary_key_insert.py +,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/composite_primary_key_delete.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/insert_double.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_database.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_replica.py -N 3 diff --git a/tests/pytest/util/csv.py b/tests/pytest/util/csv.py new file mode 100644 index 0000000000..6e1ee1732c --- /dev/null +++ b/tests/pytest/util/csv.py @@ -0,0 +1,62 @@ +import csv +import os + +class TDCsv: + def __init__(self): + self.__file_name = '' + self.__file_path = '' + + @property + def file_name(self): + return self.__file_name + + @file_name.setter + def file_name(self, value): + self.__file_name = value + + @property + def file_path(self): + return self.__file_path + + @file_path.setter + def file_path(self, value): + self.__file_path = value + + @property + def file(self): + if self.file_name and self.file_path: + return os.path.join(self.file_path, self.file_name) + return None + + + def read(self): + try: + with open(self.file, newline='') as csvfile: + reader = csv.reader(csvfile) + for row in reader: + print(row) + except Exception as errMsg: + raise Exception(errMsg) + + def __write_with_quotes(self, csv_writer, data): + for row in data: + row_with_quotes = [f'"{field}"' if isinstance(field, str) else field for field in row] + csv_writer.writerow(row_with_quotes) + + def write(self, data: dict): + try: + with open(self.file, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + writer.writerows(data) + # self.__write_with_quotes(writer, data) + except Exception as errMsg: + raise Exception(errMsg) + + def delete(self): + try: + if os.path.exists(self.file): + os.remove(self.file) + except Exception as errMsg: + raise Exception(errMsg) + + diff --git a/tests/system-test/1-insert/composite_primary_key_create.py b/tests/system-test/1-insert/composite_primary_key_create.py new file mode 100644 index 0000000000..503aa6df7d --- /dev/null +++ b/tests/system-test/1-insert/composite_primary_key_create.py @@ -0,0 +1,222 @@ +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * + + +class IllegalDataType(Enum): + NULL = 'null' + BOOL = 'bool' + TINYINT = 'tinyint' + SMALLINT = 'smallint' + FLOAT = 'float' + DOUBLE = 'double' + TIMESTAMP = 'timestamp' + NCHAR = 'nchar(100)' + UTINYINT = 'tinyint unsigned' + USMALLINT = 'smallint unsigned' + JSON = 'json' + VARBINARY = 'varbinary(100)' + DECIMAL = 'decimal' + BLOB = 'blob' + MEDIUMBLOB = 'mediumblob' + GEOMETRY = 'geometry(512)' + EMPTY = '\'\'' + SPACE = '\' \'' + + +class LegalDataType(Enum): + INT = 'INT' + UINT = 'INT UNSIGNED' + BIGINT = 'BIGINT' + UBIGINT = 'BIGINT UNSIGNED' + VARCHAR = 'VARCHAR(100)' + BINARY = 'BINARY(100)' + +class LegalSpell(Enum): + CASE1 = 'primary key' + CASE2 = 'PRIMARY KEY' + CASE3 = 'Primary Key' + CASE4 = 'PriMary keY' + +class IllegalSpell(Enum): + CASE1 = 'primary' + CASE2 = 'key' + CASE3 = 'primay key' + CASE4 = 'primary ky' + CASE5 = 'primarykey' + CASE6 = 'key primary' + CASE6 = 'primay key primay key' + + +class TableType(Enum): + SUPERTABLE = 0 + CHILDTABLE = 1 + NORNALTABLE = 2 + +SHOW_LOG = True + +class TDTestCase: + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + self.database = "db_create_composite_primary_key" + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + + def prepare_db(self): + tdSql.execute(f"drop database if exists {self.database}") + tdSql.execute(f"create database {self.database}") + tdSql.execute(f"use {self.database}") + + def check_pk_definition(self, table_name: str, d_type: LegalDataType, t_type: TableType): + tdSql.query(f"describe {table_name}", show=SHOW_LOG) + tdSql.checkData(1, 3, "PRIMARY KEY") + + if d_type == LegalDataType.BINARY: + d_type = LegalDataType.VARCHAR + + if t_type == TableType.SUPERTABLE: + expected_value = f'CREATE STABLE `{table_name}` (`ts` TIMESTAMP, `pk` {d_type.value} PRIMARY KEY, `c2` INT) TAGS (`engine` INT)' + elif t_type == TableType.NORNALTABLE: + expected_value = f'CREATE TABLE `{table_name}` (`ts` TIMESTAMP, `pk` {d_type.value} PRIMARY KEY, `c2` INT)' + + tdSql.query(f"show create table {table_name}", show=SHOW_LOG) + tdSql.checkData(0, 1, expected_value) + + def test_pk_datatype_legal(self, stable_name: str, ctable_name: str, ntable_name: str, dtype: LegalDataType): + # create super table and child table + tdSql.execute(f"drop table if exists {stable_name}", show=SHOW_LOG) + tdSql.execute(f"drop table if exists {ntable_name}", show=SHOW_LOG) + + tdSql.execute(f"create table {stable_name} (ts timestamp, pk {dtype.value} primary key, c2 int) tags (engine int)", show=SHOW_LOG) + self.check_pk_definition(stable_name, dtype, TableType.SUPERTABLE) + + tdSql.execute(f"create table {ctable_name} using {stable_name} tags (0)", show=SHOW_LOG) + tdSql.execute(f"create table {ctable_name}_1 using {stable_name} tags (1) {ctable_name}_2 using {stable_name} tags (2) {ctable_name}_3 using {stable_name} tags (3)", show=SHOW_LOG) + + # create normal table + tdSql.execute(f"create table {ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 int)", show=SHOW_LOG) + self.check_pk_definition(ntable_name, dtype, TableType.NORNALTABLE) + + def test_pk_datatype_illegal(self, stable_name: str, ntable_name: str, dtype: LegalDataType): + # create super table and child table + tdSql.execute(f"drop table if exists {stable_name}", show=SHOW_LOG) + tdSql.execute(f"drop table if exists {ntable_name}", show=SHOW_LOG) + + tdSql.error(f"create table {stable_name} (ts timestamp, pk {dtype.value} primary key, c2 int) tags (engine int)", show=SHOW_LOG) + + # create normal table + tdSql.error(f"create table {ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 int)", show=SHOW_LOG) + + def test_pk_spell_legal(self, stable_name: str, ntable_name: str, pk_spell: LegalSpell): + # create super table and child table + tdSql.execute(f"drop table if exists {stable_name}", show=SHOW_LOG) + tdSql.execute(f"drop table if exists {ntable_name}", show=SHOW_LOG) + + tdSql.execute(f"create table {stable_name} (ts timestamp, pk int {pk_spell.value}, c2 int) tags (engine int)", show=SHOW_LOG) + + # create normal table + tdSql.execute(f"create table {ntable_name} (ts timestamp, pk int {pk_spell.value}, c2 int)", show=SHOW_LOG) + + def test_pk_spell_illegal(self, stable_name: str, ntable_name: str, pk_spell: LegalSpell): + # create super table and child table + tdSql.execute(f"drop table if exists {stable_name}", show=SHOW_LOG) + tdSql.execute(f"drop table if exists {ntable_name}", show=SHOW_LOG) + + tdSql.error(f"create table {stable_name} (ts timestamp, pk int {pk_spell.value}, c2 int) tags (engine int)", show=SHOW_LOG) + + # create normal table + tdSql.error(f"create table {ntable_name} (ts timestamp, pk int {pk_spell.value}, c2 int)", show=SHOW_LOG) + + def test_update_pk(self, table_name: str, t_type: TableType): + # create super table and child table + tdSql.execute(f"drop table if exists {table_name}", show=SHOW_LOG) + + if t_type == TableType.SUPERTABLE: + tdSql.execute(f"create table {table_name} (ts timestamp, c2 int) tags (engine int)", show=SHOW_LOG) + elif t_type == TableType.NORNALTABLE: + # create normal table + tdSql.execute(f"create table {table_name} (ts timestamp, c2 int)", show=SHOW_LOG) + + tdSql.error(f"alter table {table_name} add column pk varchar(100) primary key", show=SHOW_LOG) + + tdSql.execute(f"drop table if exists {table_name}", show=SHOW_LOG) + if t_type == TableType.SUPERTABLE: + tdSql.execute(f"create table {table_name} (ts timestamp, pk varchar(200) primary key, c2 int) tags (engine int)", show=SHOW_LOG) + elif t_type == TableType.NORNALTABLE: + # create normal table + tdSql.execute(f"create table {table_name} (ts timestamp, pk varchar(200) primary key, c2 int)", show=SHOW_LOG) + + tdSql.error(f"alter table {table_name} add column new_pk varchar(20) primary key", show=SHOW_LOG) + for date_type in IllegalDataType.__members__.items(): + tdSql.error(f"alter table {table_name} modify column pk {date_type[1].value}", show=SHOW_LOG) + for date_type in LegalDataType.__members__.items(): + tdSql.error(f"alter table {table_name} modify column pk {date_type[1].value}", show=SHOW_LOG) + + tdSql.error(f"alter table {table_name} modify column pk varchar(300)", show=SHOW_LOG) + tdSql.error(f"alter table {table_name} rename column pk new_pk", show=SHOW_LOG) + tdSql.error(f"alter table {table_name} drop column pk", show=SHOW_LOG) + + def run(self): + tdSql.prepare(replica = self.replicaVar) + self.prepare_db() + + # 1.check legal data type + for date_type in LegalDataType.__members__.items(): + self.test_pk_datatype_legal('s_table', 'c_table', 'n_table', date_type[1]) + + # 2.check illegal data type + for date_type in IllegalDataType.__members__.items(): + self.test_pk_datatype_illegal('s_table', 'n_table', date_type[1]) + + # 3.check legal spell + for date_type in LegalSpell.__members__.items(): + self.test_pk_spell_legal('s_table', 'n_table', date_type[1]) + + # 4.check illegal spell + for date_type in IllegalSpell.__members__.items(): + self.test_pk_spell_illegal('s_table', 'n_table', date_type[1]) + + # 5.only define ts and pk columns + # create super table and child table + tdSql.execute(f"drop table if exists s_table", show=SHOW_LOG) + tdSql.execute(f"drop table if exists n_table", show=SHOW_LOG) + + tdSql.execute(f"create table s_table (ts timestamp, pk int primary key) tags (engine int)", show=SHOW_LOG) + tdSql.execute(f"create table c_table using s_table tags (1)", show=SHOW_LOG) + tdSql.execute(f"insert into c_table values(now, 1)", show=SHOW_LOG) + tdSql.query(f"select * from s_table", show=SHOW_LOG) + tdSql.checkRows(1) + + # create normal table + tdSql.execute(f"create table n_table (ts timestamp, pk int primary key)", show=SHOW_LOG) + tdSql.execute(f"insert into n_table values(now, 1)", show=SHOW_LOG) + tdSql.query(f"select * from n_table", show=SHOW_LOG) + tdSql.checkRows(1) + + # 6.mutiple pk & pk not defined as sencod column + tdSql.execute(f"drop table if exists s_table", show=SHOW_LOG) + tdSql.execute(f"drop table if exists n_table", show=SHOW_LOG) + + # create super table + tdSql.error(f"create table s_table (ts timestamp, c1 int, pk1 int primary key) tags (engine int)", show=SHOW_LOG) + tdSql.error(f"create table s_table (ts timestamp, pk1 int primary key, pk2 int primary key) tags (engine int)", show=SHOW_LOG) + tdSql.error(f"create table s_table (ts timestamp, pk1 int primary key, c2 int, pk2 int primary key) tags (engine int)", show=SHOW_LOG) + # create normal table + tdSql.error(f"create table n_table (ts timestamp, c1 int, pk1 int primary key)", show=SHOW_LOG) + tdSql.error(f"create table n_table (ts timestamp, pk1 int primary key, pk2 int primary key)", show=SHOW_LOG) + tdSql.error(f"create table n_table (ts timestamp, pk1 int primary key, c2 int, pk2 int primary key)", show=SHOW_LOG) + + # 7.add\update\delete pk column is not support + self.test_update_pk('s_table', TableType.SUPERTABLE) + self.test_update_pk('n_table', TableType.NORNALTABLE) + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/1-insert/composite_primary_key_delete.py b/tests/system-test/1-insert/composite_primary_key_delete.py new file mode 100644 index 0000000000..31c7d7428e --- /dev/null +++ b/tests/system-test/1-insert/composite_primary_key_delete.py @@ -0,0 +1,244 @@ +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.csv import * +import os +import taos +import json +from taos import SmlProtocol, SmlPrecision +from taos.error import SchemalessError + + +class LegalDataType(Enum): + INT = 'INT' + UINT = 'INT UNSIGNED' + BIGINT = 'BIGINT' + UBIGINT = 'BIGINT UNSIGNED' + VARCHAR = 'VARCHAR(100)' + BINARY = 'BINARY(100)' + + +class TableType(Enum): + SUPERTABLE = 0 + CHILDTABLE = 1 + NORNALTABLE = 2 + +SHOW_LOG = True +STAET_TS = '2023-10-01 00:00:00.000' + +class TDTestCase: + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + self.database = "db_insert_composite_primary_key" + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + + self.testcasePath = os.path.split(__file__)[0] + self.testcasePath = self.testcasePath.replace('\\', '//') + self.testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.stable_name = 's_table' + self.ctable_name = 'c_table' + self.ntable_name = 'n_table' + self.ts_list = {} + + + def prepare_db(self): + tdSql.execute(f"drop database if exists {self.database}") + tdSql.execute(f"create database {self.database} CACHEMODEL 'none'") + tdSql.execute(f"use {self.database}") + + def get_latest_ts(self, table_name: str): + tdSql.query(f'select last(ts) from {table_name}') + now_time = tdSql.queryResult[0][0].strftime("%Y-%m-%d %H:%M:%S.%f") + return f"'{now_time}'" + + def prepare_data(self, dtype: LegalDataType): + # drop super table and child table + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}") + + # create super table & child table + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c1 smallint, c2 varchar(10)) tags (engine int)", show=SHOW_LOG) + + table_name1 = f'{self.ctable_name}_1' + tdSql.execute(f"insert into {table_name1} using {self.stable_name} tags(1) values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_1 = self.get_latest_ts(table_name1) + tdSql.execute(f"insert into {table_name1} values({child_ts_1}, 2, '8', '6') ({child_ts_1}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name1} (ts, pk, c2) values({child_ts_1}, 4, '8') ({child_ts_1}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name1} values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_2 = self.get_latest_ts(table_name1) + tdSql.execute(f"insert into {table_name1} values({child_ts_2}, 2, '8', '6') ({child_ts_2}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name1} (ts, pk, c2) values({child_ts_2}, 4, '8') ({child_ts_2}, 5, '9')", show=SHOW_LOG) + + table_name2 = f'{self.ctable_name}_2' + tdSql.execute(f"insert into {table_name2} using {self.stable_name} tags(2) values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_3 = self.get_latest_ts(table_name2) + tdSql.execute(f"insert into {table_name2} values({child_ts_3}, 2, '8', '6') ({child_ts_3}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name2} (ts, pk, c2) values({child_ts_3}, 4, '8') ({child_ts_3}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name2} values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_4 = self.get_latest_ts(table_name2) + tdSql.execute(f"insert into {table_name2} values({child_ts_4}, 2, '8', '6') ({child_ts_4}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name2} (ts, pk, c2) values({child_ts_4}, 4, '8') ({child_ts_4}, 5, '9')", show=SHOW_LOG) + + table_name3 = f'{self.ctable_name}_3' + tdSql.execute(f"insert into {table_name3} using {self.stable_name} tags(3) values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_5 = self.get_latest_ts(table_name3) + tdSql.execute(f"insert into {table_name3} values({child_ts_5}, 2, '8', '6') ({child_ts_5}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name3} (ts, pk, c2) values({child_ts_5}, 4, '8') ({child_ts_5}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name3} values(now, 1, '7', '6')", show=SHOW_LOG) + child_ts_6 = self.get_latest_ts(table_name3) + tdSql.execute(f"insert into {table_name3} values({child_ts_6}, 2, '8', '6') ({child_ts_6}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name3} (ts, pk, c2) values({child_ts_6}, 4, '8') ({child_ts_6}, 5, '9')", show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(30) + + # create normal table + tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c1 smallint, c2 varchar(10))", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_1 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_1}, 2, '8', '6') ({normal_ts_1}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_1}, 4, '8') ({normal_ts_1}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_2 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_2}, 2, '8', '6') ({normal_ts_2}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_2}, 4, '8') ({normal_ts_2}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_3 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_3}, 2, '8', '6') ({normal_ts_3}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_3}, 4, '8') ({normal_ts_3}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_4 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_4}, 2, '8', '6') ({normal_ts_4}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_4}, 4, '8') ({normal_ts_4}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_5 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_5}, 2, '8', '6') ({normal_ts_5}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_5}, 4, '8') ({normal_ts_5}, 5, '9')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.ntable_name} values(now, 1, '7', '6')", show=SHOW_LOG) + normal_ts_6 = self.get_latest_ts(self.ntable_name) + tdSql.execute(f"insert into {self.ntable_name} values({normal_ts_6}, 2, '8', '6') ({normal_ts_6}, 3, '9', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.ntable_name} (ts, pk, c2) values({normal_ts_6}, 4, '8') ({normal_ts_6}, 5, '9')", show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(30) + + self.ts_list['child_ts_1'] = child_ts_1 + self.ts_list['child_ts_2'] = child_ts_2 + self.ts_list['child_ts_3'] = child_ts_3 + self.ts_list['child_ts_4'] = child_ts_4 + self.ts_list['child_ts_5'] = child_ts_5 + self.ts_list['child_ts_6'] = child_ts_6 + self.ts_list['normal_ts_1'] = normal_ts_1 + self.ts_list['normal_ts_2'] = normal_ts_2 + self.ts_list['normal_ts_3'] = normal_ts_3 + self.ts_list['normal_ts_4'] = normal_ts_4 + self.ts_list['normal_ts_5'] = normal_ts_5 + self.ts_list['normal_ts_6'] = normal_ts_6 + + + + def test_delete_data(self): + # delete with ts + tdSql.execute(f"delete from {self.stable_name} where ts={self.ts_list['child_ts_1']} ", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(25) + tdSql.execute(f"delete from {self.ctable_name}_1 where ts={self.ts_list['child_ts_2']} ", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(20) + tdSql.execute(f"delete from {self.ntable_name} where ts={self.ts_list['normal_ts_1']} ", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(25) + + # delete with ts range + tdSql.execute(f"delete from {self.stable_name} where ts>{self.ts_list['child_ts_2']} and ts<{self.ts_list['child_ts_4']}", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(15) + tdSql.execute(f"delete from {self.ctable_name}_2 where ts>{self.ts_list['child_ts_2']} and ts<{self.ts_list['child_ts_5']}", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(10) + tdSql.execute(f"delete from {self.ntable_name} where ts>{self.ts_list['normal_ts_2']} and ts<{self.ts_list['normal_ts_5']}", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(15) + + tdSql.execute(f"delete from {self.stable_name}", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + table_name4 = f'{self.ctable_name}_4' + tdSql.execute(f"insert into {table_name4} using {self.stable_name} tags(3) values(now, 1, '7', '6')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name4} values(now+1s, 2, '8', '6') (now+2s, 3, '9', '6')", show=SHOW_LOG) + + tdSql.execute(f"delete from {table_name4}", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + tdSql.execute(f"delete from {self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(0) + + tdSql.execute(f"delete from {self.stable_name}", show=SHOW_LOG) + tdSql.execute(f"delete from {table_name4}", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + tdSql.execute(f"delete from {self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(0) + + def test_delete_data_illegal(self, dtype: LegalDataType): + if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + pk_condition_value = '\'1\'' + else: + pk_condition_value = '1' + # delete with ts & pk + tdSql.error(f"delete from {self.stable_name} where ts={self.ts_list['child_ts_1']} and pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ctable_name}_2 where ts={self.ts_list['child_ts_1']} and pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ntable_name} where ts={self.ts_list['normal_ts_1']} and pk={pk_condition_value}", show=SHOW_LOG) + + # delete with ts range & pk + tdSql.error(f"delete from {self.stable_name} where ts>{self.ts_list['child_ts_1']} and ts<{self.ts_list['child_ts_2']} and pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ctable_name}_2 where ts>{self.ts_list['child_ts_1']} and ts<{self.ts_list['child_ts_2']} and pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ntable_name} where ts>{self.ts_list['normal_ts_1']} and ts<{self.ts_list['normal_ts_2']} and pk={pk_condition_value}", show=SHOW_LOG) + + # delete with pk + tdSql.error(f"delete from {self.stable_name} where pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ctable_name}_2 where pk={pk_condition_value}", show=SHOW_LOG) + tdSql.error(f"delete from {self.ntable_name} where pk={pk_condition_value}", show=SHOW_LOG) + + def _compare_table_data(self, result1, result2, row = 0, col = 0): + for i in range(row): + for j in range(col): + if result1[i][j] != result2[i][j]: + tdSql.checkEqual(False, True) + + def run(self): + tdSql.prepare(replica = self.replicaVar) + self.prepare_db() + + for date_type in LegalDataType.__members__.items(): + self.prepare_data(date_type[1]) + self.test_delete_data_illegal(date_type[1]) + self.test_delete_data() + + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py new file mode 100644 index 0000000000..a867ac2a4a --- /dev/null +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -0,0 +1,776 @@ +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.csv import * +import os +import taos +import json +from taos import SmlProtocol, SmlPrecision +from taos.error import SchemalessError + + +class IllegalData(Enum): + NULL = 'null' + # EMPTY = '\'\'' + NONE = 'none' + # TRUE = 'true' + # FALSE = 'false' + +# class IllegalDataVar(Enum): +# NULL = 'null' +# EMPTY = '\'\'' +# NONE = 'none' +# TRUE = 'true' +# FALSE = 'false' + + +class LegalDataType(Enum): + INT = 'INT' + UINT = 'INT UNSIGNED' + BIGINT = 'BIGINT' + UBIGINT = 'BIGINT UNSIGNED' + VARCHAR = 'VARCHAR(100)' + BINARY = 'BINARY(100)' + + +class TableType(Enum): + SUPERTABLE = 0 + CHILDTABLE = 1 + NORNALTABLE = 2 + +class HasPK(Enum): + NO = 0 + YES = 1 + +SHOW_LOG = True +STAET_TS = '2023-10-01 00:00:00.000' + +class TDTestCase: + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + self.database = "db_insert_composite_primary_key" + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + + self.testcasePath = os.path.split(__file__)[0] + self.testcasePath = self.testcasePath.replace('\\', '//') + self.testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + # tdSql.execute(f"insert into db4096.ctb00 file '{self.testcasePath}//tableColumn4096csvLength64k.csv'") + + self.tdCsv = TDCsv() + self.tdCsv.file_path = self.testcasePath + self.tdCsv.file_name = 'file1.csv' + + self.stable_name = 's_table' + self.ctable_name = 'c_table' + self.ntable_name = 'n_table' + + + def prepare_db(self): + tdSql.execute(f"drop database if exists {self.database}") + tdSql.execute(f"create database {self.database} CACHEMODEL 'none'") + tdSql.execute(f"use {self.database}") + + def get_latest_ts(self, table_name: str): + tdSql.query(f'select last(ts) from {table_name}') + now_time = tdSql.queryResult[0][0].strftime("%Y-%m-%d %H:%M:%S.%f") + return f"'{now_time}'" + + def test_insert_data(self, dtype: LegalDataType, hasPk: HasPK): + # drop super table and child table + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}_1") + tdSql.execute(f"drop table if exists {self.ntable_name}_2") + if hasPk: + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value}) tags (engine int)", show=SHOW_LOG) + else: + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value}, c2 {dtype.value}, c3 {dtype.value}) tags (engine int)", show=SHOW_LOG) + + # 1.insert into value through supper table + table_name = f'{self.ctable_name}_1' + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, now, 1, '1')", show=SHOW_LOG) + current_ts1 = self.get_latest_ts(self.stable_name) + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, {current_ts1}, 2, '2')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, {current_ts1}, 3, '3')", show=SHOW_LOG) + + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, now + 1s, 1, '4')", show=SHOW_LOG) + current_ts2 = self.get_latest_ts(self.stable_name) + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, {current_ts2}, 2, '5')", show=SHOW_LOG) + tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk) values('{table_name}', 1, now + 2s, 2)", show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts1}", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts2}", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts2} and pk = 2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 2.insert into value through child table + table_name = f'{self.ctable_name}_2' + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) values(now, 1, '7', '6')", show=SHOW_LOG) + current_ts3 = self.get_latest_ts(table_name) + tdSql.execute(f"insert into {table_name} values({current_ts3}, 2, '8', '6') ({current_ts3}, 3, '9', '6')", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) values(now + 2s, 1, '10', '6')", show=SHOW_LOG) + current_ts4 = self.get_latest_ts(table_name) + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) (ts, pk, c2)values({current_ts4}, 2, '11')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) (ts, pk) values(now + 4s, 2)", show=SHOW_LOG) + + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {table_name} where engine = 2 and ts ={current_ts3}", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {table_name} where engine = 2 and ts ={current_ts4}", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {table_name} where engine = 2 and ts ={current_ts4} and pk = 2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 3.insert value into child table from csv file + data = [ + ['ts','pk','c2'], + ['\'2024-03-29 16:55:42.572\'','1','1','100'], + ['\'2024-03-29 16:55:42.572\'','2','2','100'], + ['\'2024-03-29 16:55:42.572\'','3','3','100'], + ['\'2024-03-29 16:55:43.586\'','1','4','100'], + ['\'2024-03-29 16:55:43.586\'','2','5','100'], + ['\'2024-03-29 16:55:44.595\'','2','6','100'] + ] + + self.tdCsv.delete() + self.tdCsv.write(data) + + table_name = f'{self.ctable_name}_3' + tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:42.572'", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:43.586'", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:43.586' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 4.insert value into child table from csv file, create table automatically + data = [ + ['ts','pk','c2'], + ['\'2024-03-28 16:55:42.572\'','1','1','100'], + ['\'2024-03-28 16:55:42.572\'','2','2','100'], + ['\'2024-03-28 16:55:42.572\'','3','3','100'], + ['\'2024-03-28 16:55:43.586\'','1','4','100'], + ['\'2024-03-28 16:55:43.586\'','2','5','100'], + ['\'2024-03-28 16:55:44.595\'','2','6','100'] + ] + + self.tdCsv.delete() + self.tdCsv.write(data) + + table_name = f'{self.ctable_name}_4' + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(4) file '{self.tdCsv.file}'", show=SHOW_LOG) + + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {self.stable_name} where engine=4 and ts='2024-03-28 16:55:42.572'", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {self.stable_name} where engine=4 and ts='2024-03-28 16:55:43.586'", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {self.stable_name} where engine=4 and ts='2024-03-28 16:55:43.586' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 5.insert value into normal table from csv file + table_name = f'{self.ntable_name}_1' + if hasPk: + tdSql.execute(f"create table {table_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + else: + tdSql.execute(f"create table {table_name} (ts timestamp, pk {dtype.value}, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {table_name} where ts='2024-03-28 16:55:42.572'", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {table_name} where ts='2024-03-28 16:55:43.586'", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {table_name} where ts='2024-03-28 16:55:43.586' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 6.insert value into normal table + table_name = f'{self.ntable_name}_2' + if hasPk: + tdSql.execute(f"create table {table_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + else: + tdSql.execute(f"create table {table_name} (ts timestamp, pk {dtype.value}, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name} values(now, 1, '1', '234')", show=SHOW_LOG) + current_ts1 = self.get_latest_ts(table_name) + tdSql.execute(f"insert into {table_name} values({current_ts1}, 2, '2', '234') ({current_ts1}, 3, '3', '234')", show=SHOW_LOG) + + tdSql.execute(f"insert into {table_name} values(now + 1s, 1, '4', '234')", show=SHOW_LOG) + current_ts2 = self.get_latest_ts(table_name) + tdSql.execute(f"insert into {table_name} (ts, pk, c2) values({current_ts2}, 2, '5')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name} (ts, pk) values(now + 2s, 2)", show=SHOW_LOG) + + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(6) + tdSql.query(f"select * from {table_name} where ts ={current_ts1}", show=SHOW_LOG) + tdSql.checkRows(3) + tdSql.query(f"select * from {table_name} where ts ={current_ts2}", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {table_name} where ts ={current_ts2} and pk = 2", show=SHOW_LOG) + tdSql.checkRows(1) + + def test_insert_data_illegal(self, dtype: LegalDataType, illegal_data: IllegalData): + # drop tables + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}_1") + tdSql.execute(f"drop table if exists {self.ntable_name}_2") + + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + + # 1.insert into value through supper table + table_name = f'{self.ctable_name}_1' + tdSql.error(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, now, {illegal_data.value}, '1')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # 2.insert into value through child table + table_name = f'{self.ctable_name}_2' + tdSql.error(f"insert into {table_name} using {self.stable_name} tags(2) values(now, {illegal_data.value}, '7')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # 4.insert value into child table from csv file + data = [ + ['ts','pk','c2'], + ['\'2024-03-29 16:55:42.572\'','1','1'], + ['\'2024-03-29 16:55:42.572\'',f'{illegal_data.value}','2'], + ['\'2024-03-29 16:55:42.572\'','3','3'], + ['\'2024-03-29 16:55:43.586\'','1','4'], + ['\'2024-03-29 16:55:43.586\'','2','5'], + ['\'2024-03-29 16:55:44.595\'','2','6'] + ] + + self.tdCsv.delete() + self.tdCsv.write(data) + + table_name = f'{self.ctable_name}_3' + tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) + tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(0) + + # 5.insert value into child table from csv file, create table automatically + table_name = f'{self.ctable_name}_4' + tdSql.error(f"insert into {table_name} using {self.stable_name} tags(4) file '{self.tdCsv.file}'", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # 6.insert value into normal table from csv file + table_name = f'{self.ntable_name}_1' + tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) + tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(0) + + # 7.insert value into normal table + table_name = f'{self.ntable_name}_2' + tdSql.execute(f"create table {table_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + tdSql.error(f"insert into {table_name} values(now, {illegal_data.value}, '1')", show=SHOW_LOG) + tdSql.query(f'select * from {table_name}') + tdSql.checkRows(0) + + def test_insert_select(self, dtype: LegalDataType): + # # 1.pk table to non-pk table, throw error + tdSql.execute(f"drop table if exists source_{self.stable_name}") + tdSql.execute(f"drop table if exists source_{self.ctable_name}") + tdSql.execute(f"drop table if exists source_{self.ntable_name}") + tdSql.execute(f"drop table if exists dest_{self.ntable_name}") + + tdSql.execute(f"create table source_{self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + tdSql.execute(f"create table source_{self.ctable_name} using source_{self.stable_name} tags(3)", show=SHOW_LOG) + tdSql.execute(f"create table source_{self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"create table dest_{self.ntable_name} (ts timestamp, pk {dtype.value}, c2 {dtype.value})", show=SHOW_LOG) + + tdSql.error(f"insert into dest_{self.ntable_name} select * from source_{self.stable_name})", show=SHOW_LOG) + tdSql.error(f"insert into dest_{self.ntable_name} select * from source_{self.ctable_name})", show=SHOW_LOG) + tdSql.error(f"insert into dest_{self.ntable_name} select * from source_{self.ntable_name})", show=SHOW_LOG) + + # 2.non-pk table to pk table + tdSql.execute(f"drop table if exists source_{self.stable_name}") + tdSql.execute(f"drop table if exists source_{self.ctable_name}") + tdSql.execute(f"drop table if exists source_{self.ntable_name}") + tdSql.execute(f"drop table if exists dest_{self.ntable_name}") + + # create dest super & child table + tdSql.execute(f"create table dest_{self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + tdSql.execute(f"create table dest_{self.ctable_name} using dest_{self.stable_name} tags(3)", show=SHOW_LOG) + # tdSql.execute(f"insert into source_{self.ctable_name} values(now, 1, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) + + # create normal dest table + tdSql.execute(f"create table dest_{self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + + # create source table & insert data + tdSql.execute(f"create table source_{self.ntable_name} (ts timestamp, pk {dtype.value}, c2 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"insert into source_{self.ntable_name} values(now, 1, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) + tdSql.query(f'select * from source_{self.ntable_name}') + source_data = tdSql.queryResult + + tdSql.execute(f"insert into dest_{self.ctable_name} select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from dest_{self.ctable_name}') + dest_data = tdSql.queryResult + self._compare_table_data(source_data, dest_data, 3, 3) + tdSql.execute(f"delete from dest_{self.ctable_name}", show=SHOW_LOG) + + tdSql.execute(f"insert into dest_{self.ntable_name} select * from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from dest_{self.ntable_name}') + dest_data = tdSql.queryResult + self._compare_table_data(source_data, dest_data, 3, 3) + tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) + + # TD-29363 + tdSql.execute(f"create table source_null (ts timestamp, pk {dtype.value}, c2 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"insert into source_null values(now, null, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) + tdSql.error(f"insert into dest_{self.ntable_name} values(now, null, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) + tdSql.error(f"insert into dest_{self.ctable_name} select ts, pk, c2 from source_null", show=SHOW_LOG) + tdSql.error(f"insert into dest_{self.ntable_name} select * from source_null", show=SHOW_LOG) + + # 3.pk table to pk table + tdSql.execute(f"drop table if exists source_{self.stable_name}") + tdSql.execute(f"drop table if exists source_{self.ctable_name}") + tdSql.execute(f"drop table if exists source_{self.ntable_name}") + tdSql.execute(f"drop table if exists dest_{self.stable_name}") + tdSql.execute(f"drop table if exists dest_{self.ntable_name}") + + # create dest super & child table + tdSql.execute(f"create table dest_{self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value}) tags (engine int)", show=SHOW_LOG) + tdSql.execute(f"create table dest_{self.ctable_name} using dest_{self.stable_name} tags(3)", show=SHOW_LOG) + tdSql.execute(f"insert into dest_{self.ctable_name} values('2024-04-01 17:38:08.764', 1, 1, 100) ('2024-04-01 17:38:08.764', 2, 2, 200) ('2024-04-01 17:38:08.764', 3, 3, 300)", show=SHOW_LOG) + tdSql.execute(f"insert into dest_{self.ctable_name} values('2024-04-02 17:38:08.764', 1, 4, 400) ('2024-04-02 17:38:08.764', 2, 1, 500) ('2024-04-02 17:38:08.764', 3, 1, 600)", show=SHOW_LOG) + + # create normal dest table + tdSql.execute(f"create table dest_{self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"insert into dest_{self.ntable_name} values('2024-04-01 17:38:08.764', 1, 1, 100) ('2024-04-01 17:38:08.764', 2, 2, 200) ('2024-04-01 17:38:08.764', 3, 3, 300)", show=SHOW_LOG) + tdSql.execute(f"insert into dest_{self.ntable_name} values('2024-04-02 17:38:08.764', 1, 4, 400) ('2024-04-02 17:38:08.764', 2, 1, 500) ('2024-04-02 17:38:08.764', 3, 1, 600)", show=SHOW_LOG) + + # create source table & insert data + tdSql.execute(f"create table source_{self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"insert into source_{self.ntable_name} values('2024-04-02 17:38:08.764', 1, 4, 800) ('2024-04-02 17:38:08.764', 2, 5, 400) ('2024-04-02 17:38:08.764', 3, 6, 600)", show=SHOW_LOG) + tdSql.execute(f"insert into source_{self.ntable_name} values('2024-04-04 17:38:08.764', 1, 7, 365)", show=SHOW_LOG) + + # insert into select + tdSql.execute(f"insert into dest_{self.ctable_name} (ts, pk, c2) select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from dest_{self.ctable_name}') + tdSql.checkRows(7) + if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + tdSql.query(f"select * from dest_{self.ctable_name} where c2='5' and c2='6'", show=SHOW_LOG) + else: + tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 and c2=6', show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.execute(f"delete from dest_{self.ctable_name}", show=SHOW_LOG) + + tdSql.execute(f"insert into dest_{self.ntable_name} (ts, pk, c2) select * from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.query(f'select * from dest_{self.ntable_name}') + tdSql.checkRows(7) + if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + tdSql.query(f"select * from dest_{self.ctable_name} where c2='5' and c2='6'") + else: + tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 and c2=6') + tdSql.checkRows(2) + tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) + + def test_schemaless_error(self): + # 5.1.insert into values via influxDB + lines = ["meters,location=California.LosAngeles,groupid=2 current=11i32,voltage=221,phase=0.28 1648432611249000", + "meters,location=California.LosAngeles,groupid=2 current=13i32,voltage=223,phase=0.29 1648432611249000", + "meters,location=California.LosAngeles,groupid=3 current=10i32,voltage=223,phase=0.29 1648432611249300", + "meters,location=California.LosAngeles,groupid=3 current=11i32,voltage=221,phase=0.35 1648432611249300", + ] + try: + conn = taos.connect() + conn.execute("drop database if exists influxDB") + conn.execute("CREATE DATABASE influxDB precision 'us'") + conn.execute("USE influxDB") + conn.execute("CREATE STABLE `meters` (`_ts` TIMESTAMP, `current` int primary key, `voltage` DOUBLE, `phase` DOUBLE) TAGS (`location` NCHAR(32), `groupid` NCHAR(2))") + conn.execute("create table t_be97833a0e1f523fcdaeb6291d6fdf27 using meters tags('California.LosAngeles', 2)") + conn.execute("create table t_10b65f71ff8970369c8c18de0d6be028 using meters tags('California.LosAngeles', 3)") + conn.schemaless_insert(lines, SmlProtocol.LINE_PROTOCOL, SmlPrecision.MICRO_SECONDS) + except SchemalessError: + tdSql.checkEqual(False, True) + + # 5.2.insert into values via OpenTSDB + lines = ["meters.current 1648432611249 10i32 location=California.SanFrancisco groupid=2", + "meters.current 1648432611250 12i32 location=California.SanFrancisco groupid=2", + "meters.current 1648432611249 10i32 location=California.LosAngeles groupid=3", + "meters.current 1648432611250 11i32 location=California.LosAngeles groupid=3", + "meters.voltage 1648432611249 219i32 location=California.SanFrancisco groupid=2", + "meters.voltage 1648432611250 218i32 location=California.SanFrancisco groupid=2", + "meters.voltage 1648432611249 221i32 location=California.LosAngeles groupid=3", + "meters.voltage 1648432611250 217i32 location=California.LosAngeles groupid=3", + ] + try: + conn = taos.connect() + conn.execute("drop database if exists OpenTSDB") + conn.execute("CREATE DATABASE OpenTSDB precision 'us'") + conn.execute("USE OpenTSDB") + conn.execute("CREATE STABLE `meters_current` (`_ts` TIMESTAMP, `_value` INT primary key) TAGS (`location` NCHAR(32), `groupid` NCHAR(2))") + conn.execute("CREATE TABLE `t_c66ea0b2497be26ca9d328b59c39dd61` USING `meters_current` (`location`, `groupid`) TAGS ('California.LosAngeles', '3')") + conn.execute("CREATE TABLE `t_e71c6cf63cfcabb0e261886adea02274` USING `meters_current` (`location`, `groupid`) TAGS ('California.SanFrancisco', '2')") + conn.schemaless_insert(lines, SmlProtocol.TELNET_PROTOCOL, SmlPrecision.NOT_CONFIGURED) + except SchemalessError: + tdSql.checkEqual(False, True) + + # 5.3.insert into values via OpenTSDB Json + lines = [{"metric": "meters.current", "timestamp": 1648432611249, "value": "a32", "tags": {"location": "California.SanFrancisco", "groupid": 2}}] + try: + conn = taos.connect() + conn.execute("drop database if exists OpenTSDBJson") + conn.execute("CREATE DATABASE OpenTSDBJson") + conn.execute("USE OpenTSDBJson") + conn.execute("CREATE STABLE `meters_current` (`_ts` TIMESTAMP, `_value` varchar(10) primary key) TAGS (`location` VARCHAR(32), `groupid` DOUBLE)") + conn.execute("CREATE TABLE `t_71d176bfc4c952b64d30d719004807a0` USING `meters_current` (`location`, `groupid`) TAGS ('California.SanFrancisco', 2.000000e+00)") + # global lines + lines = json.dumps(lines) + # note: the first parameter must be a list with only one element. + conn.schemaless_insert([lines], SmlProtocol.JSON_PROTOCOL, SmlPrecision.NOT_CONFIGURED) + except SchemalessError as errMsg: + tdSql.checkEqual(False, True) + + def test_insert_values_special(self, dtype: LegalDataType): + # 4.insert into values without ts column + # drop tables + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}") + + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 binary(10)) tags (engine int)", show=SHOW_LOG) + + # # 4.1.insert into value through supper table + tdSql.error(f"insert into {self.stable_name} (tbname, engine, pk, c2) values('{self.ctable_name}', 1, '1', '1')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # # 4.2.insert into value through child table + tdSql.error(f"insert into {self.ctable_name} using {self.stable_name} tags(2) (pk, c2) values('1', '7')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # # 4.3.insert value into normal table + tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) + tdSql.error(f"insert into {self.ntable_name} (pk, c2) values('1', '1')", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(0) + + # 5.insert into values without pk column + # drop tables + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}") + + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 binary(10)) tags (engine int)", show=SHOW_LOG) + + # # 5.1.insert into value through supper table + tdSql.error(f"insert into {self.stable_name} (tbname, engine, ts, c2) values('{self.ctable_name}', 1, now, '1')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # # 5.2.insert into value through child table + tdSql.error(f"insert into {self.ctable_name} using {self.stable_name} tags(2) (ts, c2) values(now, '7')", show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + # # 5.3.insert value into normal table + tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) + tdSql.error(f"insert into {self.ntable_name} (ts, c2) values(now, '1')", show=SHOW_LOG) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(0) + + def test_insert_into_mutiple_tables(self, dtype: LegalDataType): + # drop super table and child table + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + + # 1.insert into value by supper table syntax + error_sql = f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) " \ + f"values('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 1, 100) " \ + f"('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 2, 200) " \ + f"('{self.ctable_name}_2', 2, '2021-07-14 14:06:34.630', 1, 300) " \ + f"('{self.ctable_name}_2', 2, '2021-07-14 14:06:34.630', 2, 400) " \ + f"('{self.ctable_name}_3', 3, '2021-07-15 14:06:34.630', null, 500)" + + tdSql.error(error_sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + sql = f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) " \ + f"values('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 1, 100) " \ + f"('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 2, 200) " \ + f"('{self.ctable_name}_2', 2, '2021-07-14 14:06:34.630', 1, 300) " \ + f"('{self.ctable_name}_2', 2, '2021-07-14 14:06:34.630', 2, 400) " \ + f"('{self.ctable_name}_3', 3, '2021-07-15 14:06:34.630', 1, 500)" + + tdSql.execute(sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(5) + tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630'", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 2.insert into value and create table automatically + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + + error_sql = f"insert into {self.ctable_name}_1 using {self.stable_name} tags(1) values('2021-07-13 14:06:34.630', 1, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ + f"{self.ctable_name}_2 using {self.stable_name} (engine) tags(2) values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " \ + f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) values('2021-07-15 14:06:34.630', null, 500)" + + tdSql.error(error_sql, show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + sql = f"insert into {self.ctable_name}_1 using {self.stable_name} tags(1) values('2021-07-13 14:06:34.630', 1, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ + f"{self.ctable_name}_2 using {self.stable_name} (engine) tags(2) values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " \ + f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) values('2021-07-15 14:06:34.630', 1, 500)" + + tdSql.execute(sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(5) + tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630'", show=SHOW_LOG) + tdSql.checkRows(2) + tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 3.insert value into child table from csv file, create table automatically + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + + error_data = [ + ['ts','pk','c2'], + ['\'2024-03-29 16:55:42.572\'','1','1'], + ['\'2024-03-29 16:55:42.572\'','2','2'], + ['\'2024-03-29 16:55:42.572\'','null','3'], + ['\'2024-03-29 16:55:43.586\'','1','4'], + ['\'2024-03-29 16:55:43.586\'','2','5'], + ['\'2024-03-29 16:55:44.595\'','2','6'] + ] + + self.tdCsv.delete() + self.tdCsv.write(error_data) + + sql = f"insert into {self.ctable_name}_1 using {self.stable_name} tags(1) FILE '{self.tdCsv.file}' " \ + f"{self.ctable_name}_2 using {self.stable_name} (engine) tags(2) FILE '{self.tdCsv.file}' " \ + f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) FILE '{self.tdCsv.file}'" + + tdSql.error(sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + + data = [ + ['ts','pk','c2'], + ['\'2024-03-29 16:55:42.572\'','1','1'], + ['\'2024-03-29 16:55:42.572\'','2','2'], + ['\'2024-03-29 16:55:42.572\'','2','3'], + ['\'2024-03-29 16:55:43.586\'','1','4'], + ['\'2024-03-29 16:55:43.586\'','2','5'], + ['\'2024-03-29 16:55:44.595\'','2','6'] + ] + + self.tdCsv.delete() + self.tdCsv.write(data) + + sql = f"insert into {self.ctable_name}_1 using {self.stable_name} tags(1) FILE '{self.tdCsv.file}'" \ + f"{self.ctable_name}_2 using {self.stable_name} (engine) tags(2) FILE '{self.tdCsv.file}'" \ + f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) FILE '{self.tdCsv.file}'" + + tdSql.execute(sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(15) + tdSql.query(f"select * from {self.stable_name} where ts='2024-03-29 16:55:42.572'", show=SHOW_LOG) + tdSql.checkRows(6) + tdSql.query(f"select * from {self.stable_name} where ts='2024-03-29 16:55:42.572' and pk=2", show=SHOW_LOG) + tdSql.checkRows(3) + + # 6.insert value into normal table + tdSql.execute(f"drop table if exists {self.ntable_name}_1") + tdSql.execute(f"drop table if exists {self.ntable_name}_2") + tdSql.execute(f"create table {self.ntable_name}_1 (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + tdSql.execute(f"create table {self.ntable_name}_2 (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + + sql = f"insert into {self.ntable_name}_1 values('2021-07-13 14:06:34.630', 1, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ + f"{self.ntable_name}_2 values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " + + tdSql.execute(sql, show=SHOW_LOG) + + tdSql.query(f'select * from {self.ntable_name}_1') + tdSql.checkRows(2) + tdSql.query(f"select * from {self.ntable_name}_2 where ts='2021-07-14 14:06:34.630' and pk=2", show=SHOW_LOG) + tdSql.checkRows(1) + + # 7. insert value into child and normal table + tdSql.execute(f"drop table if exists {self.stable_name}") + tdSql.execute(f"drop table if exists {self.ctable_name}") + tdSql.execute(f"drop table if exists {self.ntable_name}") + + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) + tdSql.execute(f"create table {self.ctable_name} using {self.stable_name} tags (1)", show=SHOW_LOG) + tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + + error_sql = f"insert into {self.ctable_name} values('2021-07-13 14:06:34.630', null, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ + f"{self.ntable_name} values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " + + sql = f"insert into {self.ctable_name} values('2021-07-13 14:06:34.630', 1, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ + f"{self.ntable_name} values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " + + tdSql.error(error_sql, show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(0) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(0) + + tdSql.execute(sql, show=SHOW_LOG) + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(2) + tdSql.query(f'select * from {self.ntable_name}') + tdSql.checkRows(2) + + def test_stmt(self, dtype: LegalDataType): + tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 float) tags (engine int)", show=SHOW_LOG) + + sql = f"INSERT INTO ? USING {self.stable_name} TAGS(?) VALUES (?,?,?,?)" + + conn = taos.connect() + conn.select_db(self.database) + stmt = conn.statement(sql) + + tbname = f"d1001" + + tags = taos.new_bind_params(1) + tags[0].int([2]) + + stmt.set_tbname_tags(tbname, tags) + + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589, 1626861392589, 1626861392592)) + if dtype == LegalDataType.INT : + params[1].int((10, 12, 12)) + params[2].int([194, 200, 201]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((10, 12, 12)) + params[2].int_unsigned([194, 200, 201]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((10, 12, 12)) + params[2].bigint([194, 200, 201]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((10, 12, 12)) + params[2].bigint_unsigned([194, 200, 201]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: + params[1].binary(("s10", "s12", "s12")) + params[2].binary(["s194", "s200", "s201"]) + params[3].float([0.31, 0.33, 0.31]) + + stmt.bind_param_batch(params) + + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589)) + if dtype == LegalDataType.INT : + params[1].int((11)) + params[2].int([100]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((10)) + params[2].int_unsigned([100]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((10)) + params[2].bigint([100]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((10)) + params[2].bigint_unsigned([100]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: + params[1].binary(("s10")) + params[2].binary(["s100"]) + params[3].float([0.31]) + + stmt.bind_param(params) + + stmt.execute() + + stmt.close() + + def test_implicit_conversion(self, dtype: LegalDataType): + + tdSql.execute(f"drop table if exists dest_table", show=SHOW_LOG) + tdSql.execute(f"create table dest_table (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value})", show=SHOW_LOG) + for type in LegalDataType: + if type == dtype: + continue + tdSql.execute(f"drop table if exists source_table", show=SHOW_LOG) + tdSql.execute(f"create table source_table (ts timestamp, pk {dtype.value} primary key, c2 int)", show=SHOW_LOG) + tdSql.execute(f"insert into source_table values(now, 100, 1000)", show=SHOW_LOG) + tdSql.execute(f"insert into dest_table select * from source_table", show=SHOW_LOG) + + tdSql.query(f'select * from dest_table where c2=1000') + tdSql.checkRows(1) + tdSql.execute(f"delete from dest_table", show=SHOW_LOG) + + def _compare_table_data(self, result1, result2, row = 0, col = 0): + for i in range(row): + for j in range(col): + if result1[i][j] != result2[i][j]: + tdSql.checkEqual(False, True) + + def run(self): + tdSql.prepare(replica = self.replicaVar) + self.prepare_db() + + # for date_type in LegalDataType.__members__.items(): + # # 1.insert into value with pk - pass + # self.test_insert_data(date_type[1], HasPK.YES) + + # # 2.insert into value without pk - pass + # self.test_insert_data(date_type[1], HasPK.NO) + + # # 3.insert into illegal data - pass + # for illegal_data in IllegalData.__members__.items(): + # self.test_insert_data_illegal(date_type[1], illegal_data[1]) + + # # 4. insert into select bug!!! + # self.test_insert_select(date_type[1]) + + # # 5. insert into values special cases - pass + # self.test_insert_values_special(date_type[1]) + + # 6. insert into value to mutiple tables - pass + # self.test_implicit_conversion(date_type[1]) + + # # 7. insert into value to mutiple tables - pass + # self.test_insert_into_mutiple_tables(date_type[1]) + + # 8. stmt wait for test!!!! + # self.test_stmt(date_type[1]) + + # 9. insert data by schemaless model is not allowed - bug!!! + self.test_schemaless_error() + + + + + + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From ea81f194c0b721d6747e337c77d7324e8895c1af Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Wed, 10 Apr 2024 16:21:30 +0800 Subject: [PATCH 02/10] update composite_primary_key_insert.py --- .../1-insert/composite_primary_key_insert.py | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index a867ac2a4a..d818c5ac7e 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -119,7 +119,7 @@ class TDTestCase: tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) values(now + 2s, 1, '10', '6')", show=SHOW_LOG) current_ts4 = self.get_latest_ts(table_name) - tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) (ts, pk, c2)values({current_ts4}, 2, '11')", show=SHOW_LOG) + tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) (ts, pk, c2) values({current_ts4}, 2, '11')", show=SHOW_LOG) tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(2) (ts, pk) values(now + 4s, 2)", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') @@ -292,6 +292,7 @@ class TDTestCase: tdSql.execute(f"drop table if exists source_{self.stable_name}") tdSql.execute(f"drop table if exists source_{self.ctable_name}") tdSql.execute(f"drop table if exists source_{self.ntable_name}") + tdSql.execute(f"drop table if exists dest_{self.stable_name}") tdSql.execute(f"drop table if exists dest_{self.ntable_name}") tdSql.execute(f"create table source_{self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}) tags (engine int)", show=SHOW_LOG) @@ -307,6 +308,7 @@ class TDTestCase: tdSql.execute(f"drop table if exists source_{self.stable_name}") tdSql.execute(f"drop table if exists source_{self.ctable_name}") tdSql.execute(f"drop table if exists source_{self.ntable_name}") + tdSql.execute(f"drop table if exists dest_{self.stable_name}") tdSql.execute(f"drop table if exists dest_{self.ntable_name}") # create dest super & child table @@ -336,6 +338,8 @@ class TDTestCase: tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) # TD-29363 + tdSql.execute(f"drop table if exists source_null") + tdSql.execute(f"create table source_null (ts timestamp, pk {dtype.value}, c2 {dtype.value})", show=SHOW_LOG) tdSql.execute(f"insert into source_null values(now, null, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) tdSql.error(f"insert into dest_{self.ntable_name} values(now, null, 1) (now+1s, 2, 2) (now+2s, 3, 3)", show=SHOW_LOG) @@ -370,19 +374,19 @@ class TDTestCase: tdSql.query(f'select * from dest_{self.ctable_name}') tdSql.checkRows(7) if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: - tdSql.query(f"select * from dest_{self.ctable_name} where c2='5' and c2='6'", show=SHOW_LOG) + tdSql.query(f"select * from dest_{self.ctable_name} where c2='5' or c2='6'", show=SHOW_LOG) else: - tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 and c2=6', show=SHOW_LOG) + tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 or c2=6', show=SHOW_LOG) tdSql.checkRows(2) tdSql.execute(f"delete from dest_{self.ctable_name}", show=SHOW_LOG) - tdSql.execute(f"insert into dest_{self.ntable_name} (ts, pk, c2) select * from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.execute(f"insert into dest_{self.ntable_name} (ts, pk, c2) select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) tdSql.query(f'select * from dest_{self.ntable_name}') tdSql.checkRows(7) if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: - tdSql.query(f"select * from dest_{self.ctable_name} where c2='5' and c2='6'") + tdSql.query(f"select * from dest_{self.ntable_name} where c2='5' or c2='6'") else: - tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 and c2=6') + tdSql.query(f'select * from dest_{self.ntable_name} where c2=5 or c2=6') tdSql.checkRows(2) tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) @@ -402,8 +406,9 @@ class TDTestCase: conn.execute("create table t_be97833a0e1f523fcdaeb6291d6fdf27 using meters tags('California.LosAngeles', 2)") conn.execute("create table t_10b65f71ff8970369c8c18de0d6be028 using meters tags('California.LosAngeles', 3)") conn.schemaless_insert(lines, SmlProtocol.LINE_PROTOCOL, SmlPrecision.MICRO_SECONDS) - except SchemalessError: tdSql.checkEqual(False, True) + except SchemalessError as errMsg: + tdSql.checkEqual(errMsg.msg == 'Can not insert data into table with primary key', True) # 5.2.insert into values via OpenTSDB lines = ["meters.current 1648432611249 10i32 location=California.SanFrancisco groupid=2", @@ -424,8 +429,9 @@ class TDTestCase: conn.execute("CREATE TABLE `t_c66ea0b2497be26ca9d328b59c39dd61` USING `meters_current` (`location`, `groupid`) TAGS ('California.LosAngeles', '3')") conn.execute("CREATE TABLE `t_e71c6cf63cfcabb0e261886adea02274` USING `meters_current` (`location`, `groupid`) TAGS ('California.SanFrancisco', '2')") conn.schemaless_insert(lines, SmlProtocol.TELNET_PROTOCOL, SmlPrecision.NOT_CONFIGURED) - except SchemalessError: tdSql.checkEqual(False, True) + except SchemalessError as errMsg: + tdSql.checkEqual(errMsg.msg == 'Can not insert data into table with primary key', True) # 5.3.insert into values via OpenTSDB Json lines = [{"metric": "meters.current", "timestamp": 1648432611249, "value": "a32", "tags": {"location": "California.SanFrancisco", "groupid": 2}}] @@ -440,8 +446,9 @@ class TDTestCase: lines = json.dumps(lines) # note: the first parameter must be a list with only one element. conn.schemaless_insert([lines], SmlProtocol.JSON_PROTOCOL, SmlPrecision.NOT_CONFIGURED) - except SchemalessError as errMsg: tdSql.checkEqual(False, True) + except SchemalessError as errMsg: + tdSql.checkEqual(errMsg.msg == 'Can not insert data into table with primary key', True) def test_insert_values_special(self, dtype: LegalDataType): # 4.insert into values without ts column @@ -732,40 +739,34 @@ class TDTestCase: tdSql.prepare(replica = self.replicaVar) self.prepare_db() - # for date_type in LegalDataType.__members__.items(): - # # 1.insert into value with pk - pass - # self.test_insert_data(date_type[1], HasPK.YES) + for date_type in LegalDataType.__members__.items(): + # 1.insert into value with pk - pass + self.test_insert_data(date_type[1], HasPK.YES) - # # 2.insert into value without pk - pass - # self.test_insert_data(date_type[1], HasPK.NO) + # 2.insert into value without pk - pass + self.test_insert_data(date_type[1], HasPK.NO) - # # 3.insert into illegal data - pass - # for illegal_data in IllegalData.__members__.items(): - # self.test_insert_data_illegal(date_type[1], illegal_data[1]) + # 3.insert into illegal data - pass + for illegal_data in IllegalData.__members__.items(): + self.test_insert_data_illegal(date_type[1], illegal_data[1]) - # # 4. insert into select bug!!! - # self.test_insert_select(date_type[1]) + # 4. insert into select bug!!! + self.test_insert_select(date_type[1]) - # # 5. insert into values special cases - pass - # self.test_insert_values_special(date_type[1]) + # 5. insert into values special cases - pass + self.test_insert_values_special(date_type[1]) # 6. insert into value to mutiple tables - pass - # self.test_implicit_conversion(date_type[1]) + self.test_implicit_conversion(date_type[1]) - # # 7. insert into value to mutiple tables - pass - # self.test_insert_into_mutiple_tables(date_type[1]) + # 7. insert into value to mutiple tables - pass + self.test_insert_into_mutiple_tables(date_type[1]) # 8. stmt wait for test!!!! - # self.test_stmt(date_type[1]) + self.test_stmt(date_type[1]) - # 9. insert data by schemaless model is not allowed - bug!!! + # 9. insert data by schemaless model is not allowed - pass self.test_schemaless_error() - - - - - - def stop(self): tdSql.close() From e0b60125b564dd63183d1590799f0213c4d225dd Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Wed, 10 Apr 2024 17:05:16 +0800 Subject: [PATCH 03/10] chore: add test case for composite primary key --- .../1-insert/composite_primary_key_insert.py | 104 +++++++++--------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index d818c5ac7e..a0cecd2b17 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -667,44 +667,46 @@ class TDTestCase: stmt.set_tbname_tags(tbname, tags) - params = taos.new_bind_params(4) - params[0].timestamp((1626861392589, 1626861392589, 1626861392592)) - if dtype == LegalDataType.INT : - params[1].int((10, 12, 12)) - params[2].int([194, 200, 201]) - elif dtype == LegalDataType.UINT: - params[1].int_unsigned((10, 12, 12)) - params[2].int_unsigned([194, 200, 201]) - elif dtype == LegalDataType.BIGINT: - params[1].bigint((10, 12, 12)) - params[2].bigint([194, 200, 201]) - elif dtype == LegalDataType.UBIGINT: - params[1].bigint_unsigned((10, 12, 12)) - params[2].bigint_unsigned([194, 200, 201]) - elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: - params[1].binary(("s10", "s12", "s12")) - params[2].binary(["s194", "s200", "s201"]) - params[3].float([0.31, 0.33, 0.31]) + # params = taos.new_bind_params(4) + # params[0].timestamp((1626861392589, 1626861392589, 1626861392592)) + # if dtype == LegalDataType.INT : + # params[1].int((10, 12, 12)) + # params[2].int([194, 200, 201]) + # elif dtype == LegalDataType.UINT: + # params[1].int_unsigned((10, 12, 12)) + # params[2].int_unsigned([194, 200, 201]) + # elif dtype == LegalDataType.BIGINT: + # params[1].bigint((10, 12, 12)) + # params[2].bigint([194, 200, 201]) + # elif dtype == LegalDataType.UBIGINT: + # params[1].bigint_unsigned((10, 12, 12)) + # params[2].bigint_unsigned([194, 200, 201]) + # elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: + # params[1].binary(("s10", "s12", "s12")) + # params[2].binary(["s194", "s200", "s201"]) + # params[3].float([0.31, 0.33, 0.31]) - stmt.bind_param_batch(params) + # stmt.bind_param_batch(params) params = taos.new_bind_params(4) params[0].timestamp((1626861392589)) - if dtype == LegalDataType.INT : - params[1].int((11)) - params[2].int([100]) - elif dtype == LegalDataType.UINT: - params[1].int_unsigned((10)) - params[2].int_unsigned([100]) - elif dtype == LegalDataType.BIGINT: - params[1].bigint((10)) - params[2].bigint([100]) - elif dtype == LegalDataType.UBIGINT: - params[1].bigint_unsigned((10)) - params[2].bigint_unsigned([100]) - elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: - params[1].binary(("s10")) - params[2].binary(["s100"]) + params[1].int((11)) + params[2].int([100]) + # if dtype == LegalDataType.INT : + # params[1].int((11)) + # params[2].int([100]) + # elif dtype == LegalDataType.UINT: + # params[1].int_unsigned((10)) + # params[2].int_unsigned([100]) + # elif dtype == LegalDataType.BIGINT: + # params[1].bigint((10)) + # params[2].bigint([100]) + # elif dtype == LegalDataType.UBIGINT: + # params[1].bigint_unsigned((10)) + # params[2].bigint_unsigned([100]) + # elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: + # params[1].binary(("s10")) + # params[2].binary(["s100"]) params[3].float([0.31]) stmt.bind_param(params) @@ -740,33 +742,33 @@ class TDTestCase: self.prepare_db() for date_type in LegalDataType.__members__.items(): - # 1.insert into value with pk - pass - self.test_insert_data(date_type[1], HasPK.YES) + # # 1.insert into value with pk - pass + # self.test_insert_data(date_type[1], HasPK.YES) - # 2.insert into value without pk - pass - self.test_insert_data(date_type[1], HasPK.NO) + # # 2.insert into value without pk - pass + # self.test_insert_data(date_type[1], HasPK.NO) - # 3.insert into illegal data - pass - for illegal_data in IllegalData.__members__.items(): - self.test_insert_data_illegal(date_type[1], illegal_data[1]) + # # 3.insert into illegal data - pass + # for illegal_data in IllegalData.__members__.items(): + # self.test_insert_data_illegal(date_type[1], illegal_data[1]) - # 4. insert into select bug!!! - self.test_insert_select(date_type[1]) + # # 4. insert into select bug!!! + # self.test_insert_select(date_type[1]) - # 5. insert into values special cases - pass - self.test_insert_values_special(date_type[1]) + # # 5. insert into values special cases - pass + # self.test_insert_values_special(date_type[1]) - # 6. insert into value to mutiple tables - pass - self.test_implicit_conversion(date_type[1]) + # # 6. insert into value to mutiple tables - pass + # self.test_implicit_conversion(date_type[1]) - # 7. insert into value to mutiple tables - pass - self.test_insert_into_mutiple_tables(date_type[1]) + # # 7. insert into value to mutiple tables - pass + # self.test_insert_into_mutiple_tables(date_type[1]) # 8. stmt wait for test!!!! self.test_stmt(date_type[1]) - # 9. insert data by schemaless model is not allowed - pass - self.test_schemaless_error() + # # 9. insert data by schemaless model is not allowed - pass + # self.test_schemaless_error() def stop(self): tdSql.close() From 42bf46139af4a0cd3cc1f858129a7d6f37b2bef9 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Thu, 11 Apr 2024 11:17:00 +0800 Subject: [PATCH 04/10] update stmt test cases --- .../1-insert/composite_primary_key_insert.py | 171 ++++++++++++++---- 1 file changed, 134 insertions(+), 37 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index a0cecd2b17..b9a92194e7 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -652,6 +652,7 @@ class TDTestCase: tdSql.checkRows(2) def test_stmt(self, dtype: LegalDataType): + tdSql.execute(f"drop table if exists {self.stable_name}", show=SHOW_LOG) tdSql.execute(f"create table {self.stable_name} (ts timestamp, pk {dtype.value} primary key, c2 {dtype.value}, c3 float) tags (engine int)", show=SHOW_LOG) sql = f"INSERT INTO ? USING {self.stable_name} TAGS(?) VALUES (?,?,?,?)" @@ -667,52 +668,146 @@ class TDTestCase: stmt.set_tbname_tags(tbname, tags) - # params = taos.new_bind_params(4) - # params[0].timestamp((1626861392589, 1626861392589, 1626861392592)) - # if dtype == LegalDataType.INT : - # params[1].int((10, 12, 12)) - # params[2].int([194, 200, 201]) - # elif dtype == LegalDataType.UINT: - # params[1].int_unsigned((10, 12, 12)) - # params[2].int_unsigned([194, 200, 201]) - # elif dtype == LegalDataType.BIGINT: - # params[1].bigint((10, 12, 12)) - # params[2].bigint([194, 200, 201]) - # elif dtype == LegalDataType.UBIGINT: - # params[1].bigint_unsigned((10, 12, 12)) - # params[2].bigint_unsigned([194, 200, 201]) - # elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: - # params[1].binary(("s10", "s12", "s12")) - # params[2].binary(["s194", "s200", "s201"]) - # params[3].float([0.31, 0.33, 0.31]) + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589, 1626861392589, 1626861392592)) + if dtype == LegalDataType.INT : + params[1].int((10, 12, 12)) + params[2].int([194, 200, 201]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((10, 12, 12)) + params[2].int_unsigned([194, 200, 201]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((10, 12, 12)) + params[2].bigint([194, 200, 201]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((10, 12, 12)) + params[2].bigint_unsigned([194, 200, 201]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + params[1].binary(("s10", "s12", "s12")) + params[2].binary(["s194", "s200", "s201"]) + params[3].float([0.31, 0.33, 0.31]) - # stmt.bind_param_batch(params) + stmt.bind_param_batch(params) + + stmt.execute() + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(3) params = taos.new_bind_params(4) params[0].timestamp((1626861392589)) - params[1].int((11)) - params[2].int([100]) - # if dtype == LegalDataType.INT : - # params[1].int((11)) - # params[2].int([100]) - # elif dtype == LegalDataType.UINT: - # params[1].int_unsigned((10)) - # params[2].int_unsigned([100]) - # elif dtype == LegalDataType.BIGINT: - # params[1].bigint((10)) - # params[2].bigint([100]) - # elif dtype == LegalDataType.UBIGINT: - # params[1].bigint_unsigned((10)) - # params[2].bigint_unsigned([100]) - # elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BIGINT: - # params[1].binary(("s10")) - # params[2].binary(["s100"]) + if dtype == LegalDataType.INT : + params[1].int((11)) + params[2].int([199]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((11)) + params[2].int_unsigned([199]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((11)) + params[2].bigint([199]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((11)) + params[2].bigint_unsigned([199]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + params[1].binary(("s11")) + params[2].binary(["s199"]) params[3].float([0.31]) stmt.bind_param(params) stmt.execute() + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(4) + + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589)) + if dtype == LegalDataType.INT : + params[1].int((11)) + params[2].int([1000]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((11)) + params[2].int_unsigned([1000]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((11)) + params[2].bigint([1000]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((11)) + params[2].bigint_unsigned([1000]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + params[1].binary(("s11")) + params[2].binary(["1000"]) + params[3].float([0.31]) + + stmt.bind_param(params) + + stmt.execute() + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(4) + + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589)) + if dtype == LegalDataType.INT : + params[1].int(None) + params[2].int([199]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned(None) + params[2].int_unsigned([199]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint(None) + params[2].bigint([199]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned(None) + params[2].bigint_unsigned([199]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + params[1].binary(None) + params[2].binary(["s199"]) + params[3].float([0.31]) + + try: + stmt.bind_param(params) + tdSql.checkEqual(False, True) + except Exception as errMsg: + pass + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(4) + + params = taos.new_bind_params(4) + params[0].timestamp((1626861392589, 1626861392589, )) + if dtype == LegalDataType.INT : + params[1].int((None, 18,)) + params[2].int([194, 200]) + elif dtype == LegalDataType.UINT: + params[1].int_unsigned((None, 18)) + params[2].int_unsigned([194, 200]) + elif dtype == LegalDataType.BIGINT: + params[1].bigint((None, 18)) + params[2].bigint([194, 200]) + elif dtype == LegalDataType.UBIGINT: + params[1].bigint_unsigned((None, 18)) + params[2].bigint_unsigned([194, 200]) + elif dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + params[1].binary((None, "s18")) + params[2].binary(["s194", "s200"]) + params[3].float([0.31, 0.33, 0.31]) + + try: + stmt.bind_param(params) + tdSql.checkEqual(False, True) + except Exception as errMsg: + pass + + tdSql.query(f'select * from {self.stable_name}') + tdSql.checkRows(4) + + if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: + tdSql.query(f'select * from {self.stable_name} where pk="s11"') + tdSql.checkEqual(tdSql.queryResult[0][2] == '1000', True) + else: + tdSql.query(f'select * from {self.stable_name} where pk=11') + tdSql.checkEqual(tdSql.queryResult[0][2] == 1000, True) stmt.close() def test_implicit_conversion(self, dtype: LegalDataType): @@ -752,7 +847,7 @@ class TDTestCase: # for illegal_data in IllegalData.__members__.items(): # self.test_insert_data_illegal(date_type[1], illegal_data[1]) - # # 4. insert into select bug!!! + # # 4. insert into select - pass # self.test_insert_select(date_type[1]) # # 5. insert into values special cases - pass @@ -769,6 +864,8 @@ class TDTestCase: # # 9. insert data by schemaless model is not allowed - pass # self.test_schemaless_error() + # while(True): + # self.test_stmt(LegalDataType.VARCHAR) def stop(self): tdSql.close() From 49639714f3854b72dbd0371fccfd48a23a77425e Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Fri, 12 Apr 2024 09:47:41 +0800 Subject: [PATCH 05/10] update test cases for composite_primary_key_insert --- .../1-insert/composite_primary_key_insert.py | 97 ++++++++++++++++--- 1 file changed, 81 insertions(+), 16 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index b9a92194e7..7261a75717 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -110,6 +110,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts2} and pk = 2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(self.stable_name) # 2.insert into value through child table table_name = f'{self.ctable_name}_2' @@ -130,6 +131,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {table_name} where engine = 2 and ts ={current_ts4} and pk = 2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(table_name) # 3.insert value into child table from csv file data = [ @@ -157,6 +159,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:43.586' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(table_name) # 4.insert value into child table from csv file, create table automatically data = [ @@ -173,6 +176,7 @@ class TDTestCase: self.tdCsv.write(data) table_name = f'{self.ctable_name}_4' + self._check_select(self.stable_name) tdSql.execute(f"insert into {table_name} using {self.stable_name} tags(4) file '{self.tdCsv.file}'", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') @@ -183,6 +187,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {self.stable_name} where engine=4 and ts='2024-03-28 16:55:43.586' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(self.stable_name) # 5.insert value into normal table from csv file table_name = f'{self.ntable_name}_1' @@ -201,6 +206,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {table_name} where ts='2024-03-28 16:55:43.586' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(table_name) # 6.insert value into normal table table_name = f'{self.ntable_name}_2' @@ -226,6 +232,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {table_name} where ts ={current_ts2} and pk = 2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(table_name) def test_insert_data_illegal(self, dtype: LegalDataType, illegal_data: IllegalData): # drop tables @@ -240,12 +247,14 @@ class TDTestCase: tdSql.error(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, now, {illegal_data.value}, '1')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # 2.insert into value through child table table_name = f'{self.ctable_name}_2' tdSql.error(f"insert into {table_name} using {self.stable_name} tags(2) values(now, {illegal_data.value}, '7')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # 4.insert value into child table from csv file data = [ @@ -266,12 +275,14 @@ class TDTestCase: tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(0) + self._check_select(table_name) # 5.insert value into child table from csv file, create table automatically table_name = f'{self.ctable_name}_4' tdSql.error(f"insert into {table_name} using {self.stable_name} tags(4) file '{self.tdCsv.file}'", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(table_name) # 6.insert value into normal table from csv file table_name = f'{self.ntable_name}_1' @@ -279,6 +290,7 @@ class TDTestCase: tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(0) + self._check_select(table_name) # 7.insert value into normal table table_name = f'{self.ntable_name}_2' @@ -286,6 +298,7 @@ class TDTestCase: tdSql.error(f"insert into {table_name} values(now, {illegal_data.value}, '1')", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(0) + self._check_select(table_name) def test_insert_select(self, dtype: LegalDataType): # # 1.pk table to non-pk table, throw error @@ -329,13 +342,17 @@ class TDTestCase: tdSql.query(f'select * from dest_{self.ctable_name}') dest_data = tdSql.queryResult self._compare_table_data(source_data, dest_data, 3, 3) + self._check_select(f'dest_{self.ctable_name}') tdSql.execute(f"delete from dest_{self.ctable_name}", show=SHOW_LOG) + self._check_select(f'dest_{self.ctable_name}') tdSql.execute(f"insert into dest_{self.ntable_name} select * from source_{self.ntable_name}", show=SHOW_LOG) tdSql.query(f'select * from dest_{self.ntable_name}') dest_data = tdSql.queryResult self._compare_table_data(source_data, dest_data, 3, 3) + self._check_select(f'dest_{self.ntable_name}') tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) + self._check_select(f'dest_{self.ntable_name}') # TD-29363 tdSql.execute(f"drop table if exists source_null") @@ -378,7 +395,9 @@ class TDTestCase: else: tdSql.query(f'select * from dest_{self.ctable_name} where c2=5 or c2=6', show=SHOW_LOG) tdSql.checkRows(2) + self._check_select(f'dest_{self.ctable_name}') tdSql.execute(f"delete from dest_{self.ctable_name}", show=SHOW_LOG) + self._check_select(f'dest_{self.ctable_name}') tdSql.execute(f"insert into dest_{self.ntable_name} (ts, pk, c2) select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) tdSql.query(f'select * from dest_{self.ntable_name}') @@ -388,7 +407,9 @@ class TDTestCase: else: tdSql.query(f'select * from dest_{self.ntable_name} where c2=5 or c2=6') tdSql.checkRows(2) + self._check_select(f'dest_{self.ntable_name}') tdSql.execute(f"delete from dest_{self.ntable_name}", show=SHOW_LOG) + self._check_select(f'dest_{self.ntable_name}') def test_schemaless_error(self): # 5.1.insert into values via influxDB @@ -462,17 +483,20 @@ class TDTestCase: tdSql.error(f"insert into {self.stable_name} (tbname, engine, pk, c2) values('{self.ctable_name}', 1, '1', '1')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # # 4.2.insert into value through child table tdSql.error(f"insert into {self.ctable_name} using {self.stable_name} tags(2) (pk, c2) values('1', '7')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # # 4.3.insert value into normal table tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) tdSql.error(f"insert into {self.ntable_name} (pk, c2) values('1', '1')", show=SHOW_LOG) tdSql.query(f'select * from {self.ntable_name}') tdSql.checkRows(0) + self._check_select(self.ntable_name) # 5.insert into values without pk column # drop tables @@ -485,17 +509,20 @@ class TDTestCase: tdSql.error(f"insert into {self.stable_name} (tbname, engine, ts, c2) values('{self.ctable_name}', 1, now, '1')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # # 5.2.insert into value through child table tdSql.error(f"insert into {self.ctable_name} using {self.stable_name} tags(2) (ts, c2) values(now, '7')", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) # # 5.3.insert value into normal table tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) tdSql.error(f"insert into {self.ntable_name} (ts, c2) values(now, '1')", show=SHOW_LOG) tdSql.query(f'select * from {self.ntable_name}') tdSql.checkRows(0) + self._check_select(self.ntable_name) def test_insert_into_mutiple_tables(self, dtype: LegalDataType): # drop super table and child table @@ -514,7 +541,8 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) - + self._check_select(self.stable_name) + sql = f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) " \ f"values('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 1, 100) " \ f"('{self.ctable_name}_1', 1, '2021-07-13 14:06:34.630', 2, 200) " \ @@ -530,6 +558,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(self.stable_name) # 2.insert into value and create table automatically tdSql.execute(f"drop table if exists {self.stable_name}") @@ -542,6 +571,7 @@ class TDTestCase: tdSql.error(error_sql, show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) sql = f"insert into {self.ctable_name}_1 using {self.stable_name} tags(1) values('2021-07-13 14:06:34.630', 1, 100) ('2021-07-13 14:06:34.630', 2, 200) " \ f"{self.ctable_name}_2 using {self.stable_name} (engine) tags(2) values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " \ @@ -555,6 +585,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {self.stable_name} where ts='2021-07-13 14:06:34.630' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(self.stable_name) # 3.insert value into child table from csv file, create table automatically tdSql.execute(f"drop table if exists {self.stable_name}") @@ -581,6 +612,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) + self._check_select(self.stable_name) data = [ ['ts','pk','c2'], @@ -607,6 +639,7 @@ class TDTestCase: tdSql.checkRows(6) tdSql.query(f"select * from {self.stable_name} where ts='2024-03-29 16:55:42.572' and pk=2", show=SHOW_LOG) tdSql.checkRows(3) + self._check_select(self.stable_name) # 6.insert value into normal table tdSql.execute(f"drop table if exists {self.ntable_name}_1") @@ -623,6 +656,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f"select * from {self.ntable_name}_2 where ts='2021-07-14 14:06:34.630' and pk=2", show=SHOW_LOG) tdSql.checkRows(1) + self._check_select(self.ntable_name) # 7. insert value into child and normal table tdSql.execute(f"drop table if exists {self.stable_name}") @@ -650,6 +684,8 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(f'select * from {self.ntable_name}') tdSql.checkRows(2) + self._check_select(self.stable_name) + self._check_select(self.ntable_name) def test_stmt(self, dtype: LegalDataType): tdSql.execute(f"drop table if exists {self.stable_name}", show=SHOW_LOG) @@ -693,6 +729,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(3) + self._check_select(self.stable_name) params = taos.new_bind_params(4) params[0].timestamp((1626861392589)) @@ -719,6 +756,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(4) + self._check_select(self.stable_name) params = taos.new_bind_params(4) params[0].timestamp((1626861392589)) @@ -745,6 +783,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(4) + self._check_select(self.stable_name) params = taos.new_bind_params(4) params[0].timestamp((1626861392589)) @@ -773,6 +812,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(4) + self._check_select(self.stable_name) params = taos.new_bind_params(4) params[0].timestamp((1626861392589, 1626861392589, )) @@ -801,6 +841,7 @@ class TDTestCase: tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(4) + self._check_select(self.stable_name) if dtype == LegalDataType.VARCHAR or dtype == LegalDataType.BINARY: tdSql.query(f'select * from {self.stable_name} where pk="s11"') @@ -825,6 +866,7 @@ class TDTestCase: tdSql.query(f'select * from dest_table where c2=1000') tdSql.checkRows(1) tdSql.execute(f"delete from dest_table", show=SHOW_LOG) + self._check_select('dest_table') def _compare_table_data(self, result1, result2, row = 0, col = 0): for i in range(row): @@ -832,38 +874,61 @@ class TDTestCase: if result1[i][j] != result2[i][j]: tdSql.checkEqual(False, True) + def _check_select(self, table_nam: str): + tdSql.query(f'select count(*) from {table_nam} ') + tdSql.query(f'select * from {table_nam}') + tdSql.query(f'select last_row(*) from {table_nam}') + tdSql.query(f'select first(*) from {table_nam}') + tdSql.query(f'select last(*) from {table_nam}') + tdSql.query(f'select * from {table_nam} order by ts asc') + tdSql.query(f'select * from {table_nam} order by ts desc') + tdSql.query(f'select * from {table_nam} order by pk asc') + tdSql.query(f'select * from {table_nam} order by pk desc') + tdSql.query(f'select * from {table_nam} order by ts asc, pk desc') + tdSql.query(f'select * from {table_nam} order by ts desc, pk asc') + def run(self): tdSql.prepare(replica = self.replicaVar) self.prepare_db() for date_type in LegalDataType.__members__.items(): - # # 1.insert into value with pk - pass - # self.test_insert_data(date_type[1], HasPK.YES) + tdLog.info(f'') + # 1.insert into value with pk - pass + tdLog.info('[1.insert into value with pk]') + self.test_insert_data(date_type[1], HasPK.YES) - # # 2.insert into value without pk - pass - # self.test_insert_data(date_type[1], HasPK.NO) + # 2.insert into value without pk - pass + tdLog.info('[2.insert into value without pk]') + self.test_insert_data(date_type[1], HasPK.NO) - # # 3.insert into illegal data - pass + # 3.insert into illegal data - pass + tdLog.info('[3.insert into illegal data]') # for illegal_data in IllegalData.__members__.items(): # self.test_insert_data_illegal(date_type[1], illegal_data[1]) - # # 4. insert into select - pass - # self.test_insert_select(date_type[1]) + # 4. insert into select - pass + tdLog.info('[4. insert into select]') + self.test_insert_select(date_type[1]) - # # 5. insert into values special cases - pass - # self.test_insert_values_special(date_type[1]) + # 5. insert into values special cases - pass + tdLog.info('[5. insert into values special cases]') + self.test_insert_values_special(date_type[1]) - # # 6. insert into value to mutiple tables - pass - # self.test_implicit_conversion(date_type[1]) + # 6. test implicit conversion - pass + tdLog.info('[6. test implicit conversion]') + self.test_implicit_conversion(date_type[1]) - # # 7. insert into value to mutiple tables - pass - # self.test_insert_into_mutiple_tables(date_type[1]) + # 7. insert into value to mutiple tables - pass + tdLog.info('[7. insert into value to mutiple tables]') + self.test_insert_into_mutiple_tables(date_type[1]) # 8. stmt wait for test!!!! + tdLog.info('[8. stmt wait for test]') self.test_stmt(date_type[1]) - # # 9. insert data by schemaless model is not allowed - pass - # self.test_schemaless_error() + # 9. insert data by schemaless model is not allowed - pass + tdLog.info('[9. insert data by schemaless model is not allowed]') + self.test_schemaless_error() # while(True): # self.test_stmt(LegalDataType.VARCHAR) From 0241be8b083e9e148e0939fa41deab956403d6f6 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Fri, 12 Apr 2024 10:57:46 +0800 Subject: [PATCH 06/10] add flush test to composite primary key insert --- .../1-insert/composite_primary_key_insert.py | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index 7261a75717..84fa24247a 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -102,6 +102,7 @@ class TDTestCase: tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, {current_ts2}, 2, '5')", show=SHOW_LOG) tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk) values('{table_name}', 1, now + 2s, 2)", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(6) tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts1}", show=SHOW_LOG) @@ -151,6 +152,7 @@ class TDTestCase: tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) tdSql.execute(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(6) tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:42.572'", show=SHOW_LOG) @@ -224,6 +226,7 @@ class TDTestCase: tdSql.execute(f"insert into {table_name} (ts, pk, c2) values({current_ts2}, 2, '5')", show=SHOW_LOG) tdSql.execute(f"insert into {table_name} (ts, pk) values(now + 2s, 2)", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(6) tdSql.query(f"select * from {table_name} where ts ={current_ts1}", show=SHOW_LOG) @@ -288,6 +291,7 @@ class TDTestCase: table_name = f'{self.ntable_name}_1' tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(0) self._check_select(table_name) @@ -339,6 +343,7 @@ class TDTestCase: source_data = tdSql.queryResult tdSql.execute(f"insert into dest_{self.ctable_name} select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from dest_{self.ctable_name}') dest_data = tdSql.queryResult self._compare_table_data(source_data, dest_data, 3, 3) @@ -471,6 +476,8 @@ class TDTestCase: except SchemalessError as errMsg: tdSql.checkEqual(errMsg.msg == 'Can not insert data into table with primary key', True) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + def test_insert_values_special(self, dtype: LegalDataType): # 4.insert into values without ts column # drop tables @@ -520,6 +527,7 @@ class TDTestCase: # # 5.3.insert value into normal table tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) tdSql.error(f"insert into {self.ntable_name} (ts, c2) values(now, '1')", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {self.ntable_name}') tdSql.checkRows(0) self._check_select(self.ntable_name) @@ -569,6 +577,7 @@ class TDTestCase: f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) values('2021-07-15 14:06:34.630', null, 500)" tdSql.error(error_sql, show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) self._check_select(self.stable_name) @@ -674,6 +683,7 @@ class TDTestCase: f"{self.ntable_name} values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " tdSql.error(error_sql, show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) tdSql.query(f'select * from {self.ntable_name}') @@ -727,6 +737,7 @@ class TDTestCase: stmt.execute() + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(3) self._check_select(self.stable_name) @@ -863,6 +874,7 @@ class TDTestCase: tdSql.execute(f"insert into source_table values(now, 100, 1000)", show=SHOW_LOG) tdSql.execute(f"insert into dest_table select * from source_table", show=SHOW_LOG) + tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) tdSql.query(f'select * from dest_table where c2=1000') tdSql.checkRows(1) tdSql.execute(f"delete from dest_table", show=SHOW_LOG) @@ -892,19 +904,19 @@ class TDTestCase: self.prepare_db() for date_type in LegalDataType.__members__.items(): - tdLog.info(f'') - # 1.insert into value with pk - pass - tdLog.info('[1.insert into value with pk]') - self.test_insert_data(date_type[1], HasPK.YES) + # tdLog.info(f'') + # # 1.insert into value with pk - pass + # tdLog.info('[1.insert into value with pk]') + # self.test_insert_data(date_type[1], HasPK.YES) - # 2.insert into value without pk - pass - tdLog.info('[2.insert into value without pk]') - self.test_insert_data(date_type[1], HasPK.NO) + # # 2.insert into value without pk - pass + # tdLog.info('[2.insert into value without pk]') + # self.test_insert_data(date_type[1], HasPK.NO) # 3.insert into illegal data - pass tdLog.info('[3.insert into illegal data]') - # for illegal_data in IllegalData.__members__.items(): - # self.test_insert_data_illegal(date_type[1], illegal_data[1]) + for illegal_data in IllegalData.__members__.items(): + self.test_insert_data_illegal(date_type[1], illegal_data[1]) # 4. insert into select - pass tdLog.info('[4. insert into select]') From a7fb34991688909b1e0297319bbafdcfba463a80 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Fri, 12 Apr 2024 16:42:48 +0800 Subject: [PATCH 07/10] add flush before select --- .../1-insert/composite_primary_key_insert.py | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index 84fa24247a..7f73000b05 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -72,7 +72,7 @@ class TDTestCase: def prepare_db(self): tdSql.execute(f"drop database if exists {self.database}") - tdSql.execute(f"create database {self.database} CACHEMODEL 'none'") + tdSql.execute(f"create database {self.database}") tdSql.execute(f"use {self.database}") def get_latest_ts(self, table_name: str): @@ -102,7 +102,7 @@ class TDTestCase: tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk, c2) values('{table_name}', 1, {current_ts2}, 2, '5')", show=SHOW_LOG) tdSql.execute(f"insert into {self.stable_name} (tbname, engine, ts, pk) values('{table_name}', 1, now + 2s, 2)", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(6) tdSql.query(f"select * from {self.stable_name} where engine = 1 and ts ={current_ts1}", show=SHOW_LOG) @@ -152,7 +152,7 @@ class TDTestCase: tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) tdSql.execute(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(6) tdSql.query(f"select * from {table_name} where engine=3 and ts='2024-03-29 16:55:42.572'", show=SHOW_LOG) @@ -226,7 +226,7 @@ class TDTestCase: tdSql.execute(f"insert into {table_name} (ts, pk, c2) values({current_ts2}, 2, '5')", show=SHOW_LOG) tdSql.execute(f"insert into {table_name} (ts, pk) values(now + 2s, 2)", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(6) tdSql.query(f"select * from {table_name} where ts ={current_ts1}", show=SHOW_LOG) @@ -291,7 +291,7 @@ class TDTestCase: table_name = f'{self.ntable_name}_1' tdSql.execute(f"create table {table_name} using {self.stable_name} tags(3)", show=SHOW_LOG) tdSql.error(f"insert into {table_name} file '{self.tdCsv.file}'", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {table_name}') tdSql.checkRows(0) self._check_select(table_name) @@ -343,7 +343,7 @@ class TDTestCase: source_data = tdSql.queryResult tdSql.execute(f"insert into dest_{self.ctable_name} select ts, pk, c2 from source_{self.ntable_name}", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from dest_{self.ctable_name}') dest_data = tdSql.queryResult self._compare_table_data(source_data, dest_data, 3, 3) @@ -476,7 +476,7 @@ class TDTestCase: except SchemalessError as errMsg: tdSql.checkEqual(errMsg.msg == 'Can not insert data into table with primary key', True) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) def test_insert_values_special(self, dtype: LegalDataType): # 4.insert into values without ts column @@ -527,7 +527,7 @@ class TDTestCase: # # 5.3.insert value into normal table tdSql.execute(f"create table {self.ntable_name} (ts timestamp, pk {dtype.value} primary key, c2 varchar(20))", show=SHOW_LOG) tdSql.error(f"insert into {self.ntable_name} (ts, c2) values(now, '1')", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {self.ntable_name}') tdSql.checkRows(0) self._check_select(self.ntable_name) @@ -577,7 +577,7 @@ class TDTestCase: f"{self.ctable_name}_3 using {self.stable_name} (engine) tags(3) values('2021-07-15 14:06:34.630', null, 500)" tdSql.error(error_sql, show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) self._check_select(self.stable_name) @@ -683,7 +683,7 @@ class TDTestCase: f"{self.ntable_name} values('2021-07-14 14:06:34.630', 1, 300) ('2021-07-14 14:06:34.630', 2, 400) " tdSql.error(error_sql, show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) tdSql.query(f'select * from {self.ntable_name}') @@ -737,7 +737,7 @@ class TDTestCase: stmt.execute() - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(3) self._check_select(self.stable_name) @@ -874,7 +874,7 @@ class TDTestCase: tdSql.execute(f"insert into source_table values(now, 100, 1000)", show=SHOW_LOG) tdSql.execute(f"insert into dest_table select * from source_table", show=SHOW_LOG) - tdSql.execute(f"flush database {table_name}", show=SHOW_LOG) + tdSql.execute(f"flush database {self.database}", show=SHOW_LOG) tdSql.query(f'select * from dest_table where c2=1000') tdSql.checkRows(1) tdSql.execute(f"delete from dest_table", show=SHOW_LOG) @@ -890,8 +890,13 @@ class TDTestCase: tdSql.query(f'select count(*) from {table_nam} ') tdSql.query(f'select * from {table_nam}') tdSql.query(f'select last_row(*) from {table_nam}') + tdSql.query(f'select last_row(*) from {table_nam} group by tbname') tdSql.query(f'select first(*) from {table_nam}') + tdSql.query(f'select first(*) from {table_nam} group by tbname') tdSql.query(f'select last(*) from {table_nam}') + tdSql.query(f'select last(*) from {table_nam} group by tbname') + tdSql.query(f'select ts, last(pk) from {table_nam} order by ts') + tdSql.query(f'select * from {table_nam} order by ts asc') tdSql.query(f'select * from {table_nam} order by ts desc') tdSql.query(f'select * from {table_nam} order by pk asc') @@ -904,14 +909,14 @@ class TDTestCase: self.prepare_db() for date_type in LegalDataType.__members__.items(): - # tdLog.info(f'') - # # 1.insert into value with pk - pass - # tdLog.info('[1.insert into value with pk]') - # self.test_insert_data(date_type[1], HasPK.YES) + tdLog.info(f'') + # 1.insert into value with pk - pass + tdLog.info('[1.insert into value with pk]') + self.test_insert_data(date_type[1], HasPK.YES) - # # 2.insert into value without pk - pass - # tdLog.info('[2.insert into value without pk]') - # self.test_insert_data(date_type[1], HasPK.NO) + # 2.insert into value without pk - pass + tdLog.info('[2.insert into value without pk]') + self.test_insert_data(date_type[1], HasPK.NO) # 3.insert into illegal data - pass tdLog.info('[3.insert into illegal data]') From 88d227a97d5edc878363fa9e1ff131eae55e5e83 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Sun, 14 Apr 2024 12:19:04 +0800 Subject: [PATCH 08/10] update composite primary ke case --- tests/system-test/1-insert/composite_primary_key_insert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index 7f73000b05..1a22eb781c 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -285,7 +285,7 @@ class TDTestCase: tdSql.error(f"insert into {table_name} using {self.stable_name} tags(4) file '{self.tdCsv.file}'", show=SHOW_LOG) tdSql.query(f'select * from {self.stable_name}') tdSql.checkRows(0) - self._check_select(table_name) + self._check_select(self.stable_name) # 6.insert value into normal table from csv file table_name = f'{self.ntable_name}_1' From 35453772eb8aeb8bac94064b97fbb786d610b1e6 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Fri, 19 Apr 2024 13:33:38 +0800 Subject: [PATCH 09/10] update composite_primary_key_create --- tests/system-test/1-insert/composite_primary_key_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/composite_primary_key_create.py b/tests/system-test/1-insert/composite_primary_key_create.py index 503aa6df7d..cafedc16ac 100644 --- a/tests/system-test/1-insert/composite_primary_key_create.py +++ b/tests/system-test/1-insert/composite_primary_key_create.py @@ -47,7 +47,7 @@ class IllegalSpell(Enum): CASE4 = 'primary ky' CASE5 = 'primarykey' CASE6 = 'key primary' - CASE6 = 'primay key primay key' + CASE7 = 'primay key primay key' class TableType(Enum): From 5da1fffa996fbf73d8ca4b53989330d8078a45f8 Mon Sep 17 00:00:00 2001 From: Chris Zhai Date: Fri, 19 Apr 2024 16:41:53 +0800 Subject: [PATCH 10/10] update cases --- .../system-test/1-insert/composite_primary_key_create.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/system-test/1-insert/composite_primary_key_create.py b/tests/system-test/1-insert/composite_primary_key_create.py index cafedc16ac..cde960739c 100644 --- a/tests/system-test/1-insert/composite_primary_key_create.py +++ b/tests/system-test/1-insert/composite_primary_key_create.py @@ -78,12 +78,14 @@ class TDTestCase: d_type = LegalDataType.VARCHAR if t_type == TableType.SUPERTABLE: - expected_value = f'CREATE STABLE `{table_name}` (`ts` TIMESTAMP, `pk` {d_type.value} PRIMARY KEY, `c2` INT) TAGS (`engine` INT)' + expected_value = f"CREATE STABLE `{table_name}` (`ts` TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `pk` {d_type.value} ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium' PRIMARY KEY, `c2` INT ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium') TAGS (`engine` INT)" elif t_type == TableType.NORNALTABLE: - expected_value = f'CREATE TABLE `{table_name}` (`ts` TIMESTAMP, `pk` {d_type.value} PRIMARY KEY, `c2` INT)' + expected_value = f"CREATE TABLE `{table_name}` (`ts` TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `pk` {d_type.value} ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium' PRIMARY KEY, `c2` INT ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium')" tdSql.query(f"show create table {table_name}", show=SHOW_LOG) - tdSql.checkData(0, 1, expected_value) + result = tdSql.queryResult + + tdSql.checkEqual("PRIMARY KEY" in result[0][1], True) def test_pk_datatype_legal(self, stable_name: str, ctable_name: str, ntable_name: str, dtype: LegalDataType): # create super table and child table