def run(self): buildPath = self.getBuildPath() if (buildPath == ""): tdLog.exit("taosd not found!") else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" walFilePath = "/var/lib/taos/mnode_bak/wal/" # new taos client conn1 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config) print(conn1) cur1 = conn1.cursor() tdSql.init(cur1, True) # create backgroud db and tb tdSql.execute("drop database if exists db1") os.system("%staosdemo -f compress/insertDataDb1.json -y " % binPath) # create foreground db and tb tdSql.execute("drop database if exists foredb") tdSql.execute("create database foredb") tdSql.execute("use foredb") print("123test") tdSql.execute( "create stable if not exists stb (ts timestamp, dataInt int, dataDouble double,dataStr nchar(200)) tags(loc nchar(50),t1 int)" ) tdSql.execute("create table tb1 using stb tags('beijing1', 10)") tdSql.execute( "insert into tb1 values(1614218412000,8635,98.861,'qazwsxedcrfvtgbyhnujmikolp1')(1614218422000,8636,98.862,'qazwsxedcrfvtgbyhnujmikolp2')" ) tdSql.execute("create table tb2 using stb tags('beijing2', 11)") tdSql.execute( "insert into tb2 values(1614218432000,8647,98.863,'qazwsxedcrfvtgbyhnujmikolp3')" ) tdSql.execute( "insert into tb2 values(1614218442000,8648,98.864,'qazwsxedcrfvtgbyhnujmikolp4')" ) # check data correct tdSql.execute("use db1") tdSql.query("select count(tbname) from stb0") tdSql.checkData(0, 0, 50000) tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 5000000) tdSql.execute("use foredb") tdSql.query("select count (tbname) from stb") tdSql.checkData(0, 0, 2) tdSql.query("select count (*) from stb") tdSql.checkData(0, 0, 4) tdSql.query("select * from tb1 order by ts") tdSql.checkData(0, 3, "qazwsxedcrfvtgbyhnujmikolp1") tdSql.query("select * from tb2 order by ts") tdSql.checkData(1, 3, "qazwsxedcrfvtgbyhnujmikolp4") # delete useless file testcaseFilename = os.path.split(__file__)[-1] os.system("rm -rf ./insert_res.txt")
def initConnection(self): self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taos" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def query_thread_nr(self, threadID): #使用原生python接口进行重放 host = self.host user = self.user password = self.password conn = taos.connect( host, user, password, ) cl = conn.cursor() cl.execute("use %s;" % self.dbname) replay_sql = [] with open('bak_sql_n_%d' % threadID, 'r') as f: replay_sql = f.readlines() print("Replay Thread %d: starting" % threadID) for sql in replay_sql: try: print("sql is ", sql) start = time.time() cl.execute(sql) cl.fetchall() end = time.time() print("time cost :", end - start) except Exception as e: print('-' * 40) print("Failure thread%d, sql: %s \nexception: %s" % (threadID, str(sql), str(e))) err_uec = 'Unable to establish connection' if err_uec in str(e) and loop > 0: exit(-1) cl.close() conn.close() print("Replay Thread %d: finishing" % threadID)
def init(self): tdLog.debug("start to execute %s" % __file__) tdLog.info("prepare cluster") tdDnodes.stopAll() tdDnodes.deploy(1) tdDnodes.start(1) self.conn = taos.connect(config=tdDnodes.getSimCfgPath()) tdSql.init(self.conn.cursor()) tdSql.execute('reset query cache') tdSql.execute('create dnode 192.168.0.2') tdDnodes.deploy(2) tdDnodes.start(2) tdSql.execute('create dnode 192.168.0.3') tdDnodes.deploy(3) tdDnodes.start(3) time.sleep(3) self.db = "db" self.stb = "stb" self.tbPrefix = "tb" self.tbNum = 100000 self.count = 0 # self.conn = taos.connect(config=tdDnodes.getSimCfgPath()) self.threadNum = 1 # threadLock = threading.Lock() # global counter for number of tables created by all threads self.global_counter = 0 tdSql.init(self.conn.cursor())
def connectDB(self): self.conn = taos.connect( self.host, self.user, self.password, self.config) return self.conn.cursor()
def deleteTableAndRecreate(self): self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = tdDnodes.getSimCfgPath() self.conn = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config) self.cursor = self.conn.cursor() self.cursor.execute("use test") print("drop table stb") self.cursor.execute("drop table stb") print("create table stb") self.cursor.execute( "create table if not exists stb (ts timestamp, col1 int) tags(areaid int, city nchar(20))" ) print("insert data") for i in range(self.tables): city = "beijing" if i % 2 == 0 else "shanghai" self.cursor.execute("create table tb%d using stb tags(%d, '%s')" % (i, i, city)) for j in range(self.rows): self.cursor.execute("insert into tb%d values(%d, %d)" % (i, self.ts + j, j * 100000))
def getdbconnection(cnfdict): _conn = taos.connect(host=cnfdict["dbhost"], user=cnfdict["user"], password=cnfdict["password"], database=cnfdict["database"]) print(_conn._host) return _conn
def gen_data(self): stableNum = self.stableNum subtableNum = self.subtableNum insertRows = self.insertRows t0 = self.ts host = self.host user = self.user password = self.password conn = taos.connect( host, user, password, ) cl = conn.cursor() cl.execute("drop database if exists %s;" % self.dbname) cl.execute("create database if not exists %s;" % self.dbname) cl.execute("use %s" % self.dbname) for k in range(stableNum): sql = "create table %s (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool,c8 binary(20),c9 nchar(20)) \ tags(t1 int, t2 float, t3 bigint, t4 smallint, t5 tinyint, t6 double, t7 bool,t8 binary(20),t9 nchar(20))" % ( self.stb_prefix + str(k)) cl.execute(sql) for j in range(subtableNum): sql = "create table %s using %s tags(%d,%d,%d,%d,%d,%d,%d,'%s','%s')" % \ (self.subtb_prefix+str(k)+'_'+str(j),self.stb_prefix+str(k),j,j/2.0,j%41,j%51,j%53,j*1.0,j%2,'taos'+str(j),'涛思'+str(j)) print(sql) cl.execute(sql) for i in range(insertRows): ret = cl.execute( "insert into %s values (%d , %d,%d,%d,%d,%d,%d,%d,'%s','%s')" % (self.subtb_prefix + str(k) + '_' + str(j), t0 + i, i % 100, i / 2.0, i % 41, i % 51, i % 53, i * 1.0, i % 2, 'taos' + str(i), '涛思' + str(i))) cl.close() conn.close()
def query_thread_n(self,threadID): #使用原生python接口查询 host = "127.0.0.1" user = "******" password = "******" conn = taos.connect( host, user, password, ) cl = conn.cursor() cl.execute("use test;") print("Thread %d: starting" % threadID) while True: try: sql=self.gen_query_sql() print("sql is ",sql) start = time.time() cl.execute(sql) cl.fetchall() end = time.time() print("time cost :",end-start) except Exception as e: print( "Failure thread%d, sql: %s,exception: %s" % (threadID, str(sql),str(e))) #exit(-1) print("Thread %d: finishing" % threadID)
def connect_tdengine(): # conn = taos.connect(host="127.0.0.1", user="******", password="******", config="C:\TDengine\cfg") conn = taos.connect(host="106.55.27.102", user="******", password="******", config="/etc/taos") # conn = taos.connect(host="127.0.0.1", user="******", password="******", config="/etc/taos") td = conn.cursor() data = [] # 创建数据库 try: if td.execute("show databases;") is not None: datalist = td.fetchall() for i in datalist: data.append(i[0]) if 'air' in data: if td.execute("use air;") != 0: return 0, 0 else: if td.execute("create database air;") != 0: return 0, 0 else: if td.execute("use air;") != 0: return 0, 0 if create_stable(conn, td) == 1: return conn, td else: return 0, 0 except Exception as err: conn.close() raise err
def connect_server(host, user, password): """ Connect to server. Parameters ---------- host: str Host name as the address of the TDEngine Server. user: str User name of the TDEngine Server. password: str Password for the TDEngine Server. Returns ------- conn: taos.connection.TDengineConnection TDEnginine connection name. cursor: taos.cursor.TDengineCursor TDEnginine cursor name. """ # Connect to TDengine server. # # parameters: # @host : TDengine server IP address # @user : Username used to connect to TDengine server # @password : Password # @database : Database to use when connecting to TDengine server # @config : Configuration directory conn = taos.connect(host, user, password, config="/etc/taos") cursor = conn.cursor() return conn, cursor
def query_thread(self,threadID): host = "10.211.55.14" user = "******" password = "******" conn = taos.connect( host, user, password, ) cl = conn.cursor() cl.execute("use test;") print("Thread %d: starting" % threadID) while True: ran_query_sql=query_sql random.shuffle(ran_query_sql) for i in ran_query_sql: print("Thread %d : %s"% (threadID,i)) try: start = time.time() cl.execute(i) cl.fetchall end = time.time() print("time cost :",end-start) except Exception as e: print( "Failure thread%d, sql: %s,exception: %s" % (threadID, str(i),str(e))) exit(-1) print("Thread %d: finishing" % threadID)
def __init__(self, ip, user, password, database): self.conn = taos.connect(host=ip, user=user, password=password, database=database) self.cursor = self.conn.cursor() self.database = database
def __init__(self, hostAddr, cfgPath): # Make the DB connection self._conn = taos.connect(host=hostAddr, config=cfgPath) self._cursor = self._conn.cursor() self.queryRows = 0 self.queryCols = 0 self.affectedRows = 0
def srun(self): try: self.conn = taos.connect(host=self.host,user=self.user,password=self.password) #self.conn = taos.connect(self.host,self.user,self.password) except Exception as e: print("connection failed: %s"%self.host) exit(1) print("[ OK ] Connection established.") self.cl = self.conn.cursor()
def open_spider(self, spider): # 连接TDengine self.TDengine_conn = taos.connect(host=self.TDengine_host, user="******" % self.TDengine_user, password="******" % self.TDengine_password, database=self.TDengine_database) # 获取操作游标 self.TDengine_cursor = self.TDengine_conn.cursor()
def __init__(self, commitID, dbName): self.commitID = commitID self.dbName = dbName self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/perf" self.conn = taos.connect(self.host, self.user, self.password, self.config) self.insertDB = "insertDB"
def initConnection(self): self.records = 10000000 self.numOfTherads = 50 self.ts = 1537146000000 self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/home/xp/git/TDengine/sim/dnode1/cfg" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def connect(self): conn = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config) cursor = conn.cursor() self.conn = conn self.cursor = cursor print('connect ...') return self.cursor
def initConnection(self): self.tables = 100 self.records = 10 self.numOfTherads = 5 self.ts = 1537146000000 self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taos" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def __init__(self, clearCache, dbName, keep): self.clearCache = clearCache self.dbname = dbName self.drop = "yes" self.keep = keep self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taosperf" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def taos_init(table, connect_host, pk): conn = taos.connect(host=connect_host, user="******", password="******", config="/etc/taos", database='test') cursor = conn.cursor() sql = f"CREATE TABLE {table}_{pk} USING {table} TAGS ({pk})" cursor.execute(sql) cursor.close() conn.close()
def init(self): tdLog.debug("start to execute %s" % __file__) tdLog.info("prepare cluster") tdDnodes.stopAll() tdDnodes.deploy(1) tdDnodes.start(1) self.conn = taos.connect(config=tdDnodes.getSimCfgPath()) tdSql.init(self.conn.cursor()) tdSql.execute('reset query cache') tdSql.execute('create dnode 192.168.0.2') tdDnodes.deploy(2) tdDnodes.start(2) self.conn = taos.connect(config=tdDnodes.getSimCfgPath()) tdSql.init(self.conn.cursor()) tdSql.execute('reset query cache') tdSql.execute('create dnode 192.168.0.3') tdDnodes.deploy(3) tdDnodes.start(3)
def __init__(self, clearCache, commitID, dbName, stbName, tbPerfix): self.clearCache = clearCache self.commitID = commitID self.dbName = dbName self.stbName = stbName self.tbPerfix = tbPerfix self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taosperf" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def __init__(self, commitID, dbName, stbName, branchName): self.commitID = commitID self.dbName = dbName self.stbName = stbName self.branchName = branchName self.ts = 1500074556514 self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taosperf" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def connect_server(host, user, password): # Connect to TDengine server. # # parameters: # @host : TDengine server IP address # @user : Username used to connect to TDengine server # @password : Password # @database : Database to use when connecting to TDengine server # @config : Configuration directory conn = taos.connect(host, user, password, config="/etc/taos") cursor = conn.cursor() return conn, cursor
def __init__(self, commitID, dbName, createTableTime, insertRecordsTime, recordsPerSecond): self.commitID = commitID self.dbName = dbName self.createTableTime = createTableTime self.insertRecordsTime = insertRecordsTime self.recordsPerSecond = recordsPerSecond self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/taosperf" self.conn = taos.connect(self.host, self.user, self.password, self.config)
def __init__(self, commitID, dbName, tbName, branchName, buildType): self.commitID = commitID self.dbName = dbName self.tbName = tbName self.branchName = branchName self.type = buildType self.ts = 1500000000000 self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = "/etc/perf" self.conn = taos.connect( self.host, self.user, self.password, self.config) self.host2 = "192.168.1.179" self.conn2 = taos.connect( host = self.host2, user = self.user, password = self.password, config = self.config)
def updateMetadata(self): self.host = "127.0.0.1" self.user = "******" self.password = "******" self.config = tdDnodes.getSimCfgPath() self.conn = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config) self.cursor = self.conn.cursor() self.cursor.execute("alter table db.tb add column col2 int") print("alter table done")
def init(self): self.queryRows = 0 tdLog.debug("start to execute %s" % __file__) tdLog.info("prepare cluster") tdDnodes.init("") tdDnodes.setTestCluster(False) tdDnodes.setValgrind(False) tdDnodes.stopAll() tdDnodes.deploy(1) tdDnodes.start(1) print(tdDnodes.getDnodesRootDir()) self.conn = taos.connect(config=tdDnodes.getSimCfgPath()) tdSql.init(self.conn.cursor()) tdSql.execute('reset query cache')