add test scripts for TS-4243
This commit is contained in:
parent
62ab1b1c41
commit
b61bf20ebf
|
@ -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/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 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/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_database.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_replica.py -N 3
|
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_replica.py -N 3
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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())
|
|
@ -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())
|
|
@ -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())
|
Loading…
Reference in New Issue