Merge pull request #28073 from taosdata/test/ci-sh-3.0
add nodejs python ci examples
This commit is contained in:
commit
d3c42765b0
|
@ -4,7 +4,6 @@
|
|||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tdengine/client": "^3.0.1",
|
||||
"@tdengine/rest": "^3.0.0"
|
||||
"@tdengine/websocket": "^3.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ async function json_tag_example() {
|
|||
|
||||
} catch (err) {
|
||||
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
|
@ -78,9 +79,10 @@ async function all_type_example() {
|
|||
let row = wsRows.getData();
|
||||
console.log(row);
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
|
@ -91,7 +93,7 @@ async function all_type_example() {
|
|||
|
||||
async function test() {
|
||||
await json_tag_example()
|
||||
await all_type_example()
|
||||
await all_type_example()
|
||||
taos.destroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ async function json_tag_example() {
|
|||
|
||||
} catch (err) {
|
||||
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err
|
||||
} finally {
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
|
@ -125,6 +126,7 @@ async function all_type_example() {
|
|||
|
||||
} catch (err) {
|
||||
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (stmt) {
|
||||
await stmt.close();
|
||||
|
@ -136,10 +138,7 @@ async function all_type_example() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function test() {
|
||||
taos.setLevel("debug")
|
||||
async function test() {
|
||||
await json_tag_example()
|
||||
await all_type_example()
|
||||
taos.destroy();
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
const taos = require("@tdengine/websocket");
|
||||
|
||||
var host = null;
|
||||
for(var i = 2; i < global.process.argv.length; i++){
|
||||
var key = global.process.argv[i].split("=")[0];
|
||||
var value = global.process.argv[i].split("=")[1];
|
||||
if("host" == key){
|
||||
host = value;
|
||||
}
|
||||
}
|
||||
|
||||
if(host == null){
|
||||
console.log("Usage: node nodejsChecker.js host=<hostname> port=<port>");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let dbData = ["{\"metric\": \"meter_current\",\"timestamp\": 1626846402,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1001\"}}",
|
||||
"{\"metric\": \"meter_current\",\"timestamp\": 1626846403,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1002\"}}",
|
||||
"{\"metric\": \"meter_current\",\"timestamp\": 1626846404,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1003\"}}"]
|
||||
|
||||
async function createConnect() {
|
||||
let dsn = 'ws://' + host + ':6041'
|
||||
let conf = new taos.WSConfig(dsn);
|
||||
conf.setUser('root');
|
||||
conf.setPwd('taosdata');
|
||||
conf.setDb('power');
|
||||
return await taos.sqlConnect(conf);
|
||||
}
|
||||
|
||||
async function test() {
|
||||
let wsSql = null;
|
||||
let wsRows = null;
|
||||
let reqId = 0;
|
||||
try {
|
||||
wsSql = await createConnect()
|
||||
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;', reqId++);
|
||||
await wsSql.schemalessInsert([dbData], taos.SchemalessProto.OpenTSDBJsonFormatProtocol, taos.Precision.SECONDS, 0);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err.code, err.message);
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
await wsRows.close();
|
||||
}
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
}
|
||||
taos.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test()
|
|
@ -15,8 +15,8 @@ async function createConnect() {
|
|||
return wsSql;
|
||||
}
|
||||
|
||||
|
||||
async function test() {
|
||||
let dsn = 'ws://localhost:6041'
|
||||
let wsSql = null;
|
||||
let wsRows = null;
|
||||
let ttl = 0;
|
||||
|
@ -29,6 +29,7 @@ async function test() {
|
|||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to insert data with schemaless, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
|
@ -40,4 +41,5 @@ async function test() {
|
|||
taos.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
test()
|
||||
|
|
|
@ -10,11 +10,9 @@ for(var i = 2; i < global.process.argv.length; i++){
|
|||
}
|
||||
|
||||
if(host == null){
|
||||
console.log("Usage: node nodejsChecker.js host=<hostname> port=<port>");
|
||||
process.exit(0);
|
||||
host = 'localhost';
|
||||
}
|
||||
|
||||
|
||||
async function createConnect() {
|
||||
let dsn = 'ws://' + host + ':6041'
|
||||
console.log(dsn)
|
||||
|
@ -41,7 +39,7 @@ async function test() {
|
|||
taosResult = await wsSql.exec('USE power', reqId++);
|
||||
console.log(taosResult);
|
||||
|
||||
taosResult = await wsSql.exec('CREATE STABLE IF NOT EXISTS meters (_ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);', reqId++);
|
||||
taosResult = await wsSql.exec('CREATE STABLE IF NOT EXISTS meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);', reqId++);
|
||||
console.log(taosResult);
|
||||
|
||||
taosResult = await wsSql.exec('DESCRIBE meters', reqId++);
|
||||
|
@ -62,6 +60,7 @@ async function test() {
|
|||
}
|
||||
catch (err) {
|
||||
console.error(err.code, err.message);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
|
|
|
@ -41,6 +41,7 @@ async function createDbAndTable() {
|
|||
console.log("Create stable power.meters successfully");
|
||||
} catch (err) {
|
||||
console.error(`Failed to create database power or stable meters, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
|
@ -53,21 +54,23 @@ async function createDbAndTable() {
|
|||
// ANCHOR: insertData
|
||||
async function insertData() {
|
||||
let wsSql = null
|
||||
let insertQuery = "INSERT INTO " +
|
||||
"power.d1001 USING power.meters (location, groupId) TAGS('California.SanFrancisco', 2) " +
|
||||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 219, 0.31000) " +
|
||||
"(NOW + 2a, 12.60000, 218, 0.33000) " +
|
||||
"(NOW + 3a, 12.30000, 221, 0.31000) " +
|
||||
"power.d1002 USING power.meters (location, groupId) TAGS('California.SanFrancisco', 3) " +
|
||||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 218, 0.25000) ";
|
||||
|
||||
try {
|
||||
wsSql = await createConnect();
|
||||
let insertQuery = "INSERT INTO " +
|
||||
"power.d1001 USING power.meters (location, groupId) TAGS('California.SanFrancisco', 2) " +
|
||||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 219, 0.31000) " +
|
||||
"(NOW + 2a, 12.60000, 218, 0.33000) " +
|
||||
"(NOW + 3a, 12.30000, 221, 0.31000) " +
|
||||
"power.d1002 USING power.meters TAGS('California.SanFrancisco', 3) " +
|
||||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 218, 0.25000) ";
|
||||
taosResult = await wsSql.exec(insertQuery);
|
||||
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to power.meters.");
|
||||
} catch (err) {
|
||||
console.error(`Failed to insert data to power.meters, sql: ${insertQuery}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
|
@ -91,6 +94,7 @@ async function queryData() {
|
|||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to query data from power.meters, sql: ${sql}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
|
@ -118,6 +122,7 @@ async function sqlWithReqid() {
|
|||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to query data from power.meters, reqId: ${reqId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
|
@ -135,7 +140,7 @@ async function test() {
|
|||
await insertData();
|
||||
await queryData();
|
||||
await sqlWithReqid();
|
||||
taos.destroy();
|
||||
taos.destroy();
|
||||
}
|
||||
|
||||
test()
|
||||
|
|
|
@ -23,7 +23,7 @@ async function prepare() {
|
|||
return wsSql
|
||||
}
|
||||
|
||||
(async () => {
|
||||
async function test() {
|
||||
let stmt = null;
|
||||
let connector = null;
|
||||
try {
|
||||
|
@ -60,6 +60,7 @@ async function prepare() {
|
|||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to insert to table meters using stmt, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (stmt) {
|
||||
|
@ -70,4 +71,6 @@ async function prepare() {
|
|||
}
|
||||
taos.destroy();
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
test()
|
|
@ -1,58 +0,0 @@
|
|||
const taos = require("@tdengine/websocket");
|
||||
|
||||
var host = null;
|
||||
for(var i = 2; i < global.process.argv.length; i++){
|
||||
var key = global.process.argv[i].split("=")[0];
|
||||
var value = global.process.argv[i].split("=")[1];
|
||||
if("host" == key){
|
||||
host = value;
|
||||
}
|
||||
}
|
||||
|
||||
if(host == null){
|
||||
console.log("Usage: node nodejsChecker.js host=<hostname> port=<port>");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let dbData = ["meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",];
|
||||
|
||||
async function createConnect() {
|
||||
let dsn = 'ws://' + host + ':6041'
|
||||
let conf = new taos.WSConfig(dsn);
|
||||
conf.setUser('root');
|
||||
conf.setPwd('taosdata');
|
||||
|
||||
return await taos.sqlConnect(conf);
|
||||
}
|
||||
|
||||
async function test() {
|
||||
let wsSql = null;
|
||||
let wsRows = null;
|
||||
let reqId = 0;
|
||||
try {
|
||||
wsSql = await createConnect()
|
||||
await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;', reqId++);
|
||||
await wsSql.exec('use power', reqId++);
|
||||
await wsSql.schemalessInsert(dbData, taos.SchemalessProto.OpenTSDBTelnetLineProtocol, taos.Precision.MILLI_SECONDS, 0);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err.code, err.message);
|
||||
}
|
||||
finally {
|
||||
if (wsRows) {
|
||||
await wsRows.close();
|
||||
}
|
||||
if (wsSql) {
|
||||
await wsSql.close();
|
||||
}
|
||||
taos.destroy();
|
||||
}
|
||||
}
|
||||
test()
|
|
@ -1,3 +1,4 @@
|
|||
const { sleep } = require("@tdengine/websocket");
|
||||
const taos = require("@tdengine/websocket");
|
||||
|
||||
// ANCHOR: create_consumer
|
||||
|
@ -49,12 +50,20 @@ async function prepare() {
|
|||
|
||||
let createTopic = `CREATE TOPIC IF NOT EXISTS ${topics[0]} AS SELECT * FROM ${db}.${stable}`;
|
||||
await wsSql.exec(createTopic);
|
||||
await wsSql.close();
|
||||
}
|
||||
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
async function insert() {
|
||||
let conf = new taos.WSConfig('ws://localhost:6041');
|
||||
conf.setUser('root');
|
||||
conf.setPwd('taosdata');
|
||||
conf.setDb('power');
|
||||
let wsSql = await taos.sqlConnect(conf);
|
||||
for (let i = 0; i < 50; i++) {
|
||||
await wsSql.exec(`INSERT INTO d1001 USING ${stable} (location, groupId) TAGS ("California.SanFrancisco", 3) VALUES (NOW, ${10 + i}, ${200 + i}, ${0.32 + i})`);
|
||||
await sleep(100);
|
||||
}
|
||||
wsSql.close();
|
||||
await wsSql.close();
|
||||
}
|
||||
|
||||
async function subscribe(consumer) {
|
||||
|
@ -82,13 +91,17 @@ async function test() {
|
|||
let consumer = null;
|
||||
try {
|
||||
await prepare();
|
||||
consumer = await createConsumer()
|
||||
await subscribe(consumer)
|
||||
consumer = await createConsumer();
|
||||
const allPromises = [];
|
||||
allPromises.push(subscribe(consumer));
|
||||
allPromises.push(insert());
|
||||
await Promise.all(allPromises);
|
||||
await consumer.unsubscribe();
|
||||
console.log("Consumer unsubscribed successfully.");
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to unsubscribe consumer, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (consumer) {
|
||||
|
|
|
@ -1,41 +1,45 @@
|
|||
const { sleep } = require("@tdengine/websocket");
|
||||
const taos = require("@tdengine/websocket");
|
||||
|
||||
const db = 'power';
|
||||
const stable = 'meters';
|
||||
const url = 'ws://localhost:6041';
|
||||
const topic = 'topic_meters'
|
||||
const topics = [topic];
|
||||
const groupId = "group1";
|
||||
const clientId = "client1";
|
||||
|
||||
|
||||
// ANCHOR: create_consumer
|
||||
async function createConsumer() {
|
||||
|
||||
let groupId = "group1";
|
||||
let clientId = "client1";
|
||||
let configMap = new Map([
|
||||
[taos.TMQConstants.GROUP_ID, "group1"],
|
||||
[taos.TMQConstants.CLIENT_ID, 'client1'],
|
||||
[taos.TMQConstants.GROUP_ID, groupId],
|
||||
[taos.TMQConstants.CLIENT_ID, clientId],
|
||||
[taos.TMQConstants.CONNECT_USER, "root"],
|
||||
[taos.TMQConstants.CONNECT_PASS, "taosdata"],
|
||||
[taos.TMQConstants.AUTO_OFFSET_RESET, "latest"],
|
||||
[taos.TMQConstants.WS_URL, 'ws://localhost:6041'],
|
||||
[taos.TMQConstants.WS_URL, url],
|
||||
[taos.TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
|
||||
[taos.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000']
|
||||
]);
|
||||
try {
|
||||
return await taos.tmqConnect(configMap);
|
||||
conn = await taos.tmqConnect(configMap);
|
||||
console.log(`Create consumer successfully, host: ${url}, groupId: ${groupId}, clientId: ${clientId}`)
|
||||
return conn;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(`Failed to create websocket consumer, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
}
|
||||
// ANCHOR_END: create_consumer
|
||||
|
||||
async function prepare() {
|
||||
let conf = new taos.WSConfig('ws://localhost:6041');
|
||||
let conf = new taos.WSConfig('ws://192.168.1.98:6041');
|
||||
conf.setUser('root');
|
||||
conf.setPwd('taosdata');
|
||||
conf.setDb('power');
|
||||
const createDB = `CREATE DATABASE IF NOT EXISTS ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`;
|
||||
const createDB = `CREATE DATABASE IF NOT EXISTS ${db}`;
|
||||
const createStable = `CREATE STABLE IF NOT EXISTS ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`;
|
||||
|
||||
let wsSql = await taos.sqlConnect(conf);
|
||||
|
@ -44,58 +48,63 @@ async function prepare() {
|
|||
|
||||
let createTopic = `CREATE TOPIC IF NOT EXISTS ${topics[0]} AS SELECT * FROM ${db}.${stable}`;
|
||||
await wsSql.exec(createTopic);
|
||||
await wsSql.close();
|
||||
}
|
||||
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
async function insert() {
|
||||
let conf = new taos.WSConfig('ws://localhost:6041');
|
||||
conf.setUser('root');
|
||||
conf.setPwd('taosdata');
|
||||
conf.setDb('power');
|
||||
let wsSql = await taos.sqlConnect(conf);
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await wsSql.exec(`INSERT INTO d1001 USING ${stable} (location, groupId) TAGS ("California.SanFrancisco", 3) VALUES (NOW, ${10 + i}, ${200 + i}, ${0.32 + i})`);
|
||||
}
|
||||
await wsSql.close();
|
||||
}
|
||||
|
||||
// ANCHOR: subscribe
|
||||
// ANCHOR: offset
|
||||
async function subscribe(consumer) {
|
||||
try {
|
||||
await consumer.subscribe(['topic_meters']);
|
||||
for (let i = 0; i < 50; i++) {
|
||||
let res = await consumer.poll(100);
|
||||
for (let [key, value] of res) {
|
||||
// Add your data processing logic here
|
||||
console.log(`data: ${key} ${value}`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Failed to poll data, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
}
|
||||
// ANCHOR_END: subscribe
|
||||
|
||||
// ANCHOR: offset
|
||||
async function test() {
|
||||
let consumer = null;
|
||||
try {
|
||||
await prepare();
|
||||
let consumer = await createConsumer()
|
||||
await consumer.subscribe(['topic_meters']);
|
||||
let res = new Map();
|
||||
while (res.size == 0) {
|
||||
res = await consumer.poll(100);
|
||||
await consumer.commit();
|
||||
}
|
||||
|
||||
let assignment = await consumer.assignment();
|
||||
await consumer.seekToBeginning(assignment);
|
||||
console.log("Assignment seek to beginning successfully");
|
||||
} catch (err) {
|
||||
console.error(`Failed to seek offset, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: offset
|
||||
|
||||
async function test() {
|
||||
let consumer = null;
|
||||
try {
|
||||
await prepare();
|
||||
consumer = await createConsumer();
|
||||
const allPromises = [];
|
||||
allPromises.push(subscribe(consumer));
|
||||
allPromises.push(insert());
|
||||
await Promise.all(allPromises);
|
||||
await consumer.unsubscribe();
|
||||
console.log("Consumer unsubscribed successfully.");
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to seek offset, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
console.error(`Failed to consumer, topic: ${topic}, groupId: ${groupId}, clientId: ${clientId}, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
if (consumer) {
|
||||
await consumer.close();
|
||||
console.log("Consumer closed successfully.");
|
||||
}
|
||||
taos.destroy();
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: offset
|
||||
|
||||
test()
|
||||
|
|
|
@ -15,6 +15,7 @@ def create_connection():
|
|||
print(f"Connected to {host}:{port} successfully.");
|
||||
except Exception as err:
|
||||
print(f"Failed to connect to {host}:{port} , ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -15,7 +15,7 @@ def create_connection():
|
|||
print(f"Connected to {host}:{port} successfully.");
|
||||
except Exception as err:
|
||||
print(f"Failed to connect to {host}:{port} , ErrMessage:{err}")
|
||||
|
||||
raise err
|
||||
return conn
|
||||
# ANCHOR_END: connect
|
||||
|
||||
|
@ -28,6 +28,7 @@ def create_db_table(conn):
|
|||
conn.execute("CREATE TABLE IF NOT EXISTS `d0` USING `meters` (groupId, location) TAGS(0, 'Los Angles')")
|
||||
except Exception as err:
|
||||
print(f'Exception {err}')
|
||||
raise err
|
||||
# ANCHOR_END: create_db
|
||||
|
||||
def insert(conn):
|
||||
|
@ -42,9 +43,10 @@ def insert(conn):
|
|||
"""
|
||||
try:
|
||||
inserted = conn.execute(sql)
|
||||
assert inserted == 8
|
||||
assert inserted == 4
|
||||
except Exception as err:
|
||||
print(f'Exception111 {err}')
|
||||
raise err
|
||||
# ANCHOR_END: insert
|
||||
|
||||
def query(conn):
|
||||
|
@ -58,6 +60,7 @@ def query(conn):
|
|||
print(row)
|
||||
except Exception as err:
|
||||
print(f'Exception {err}')
|
||||
raise err
|
||||
# ANCHOR_END: query
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -21,6 +21,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to create database power or stable meters, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -20,6 +20,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to create database power or stable meters, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -21,6 +21,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to create database power or stable meters, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -22,6 +22,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to insert data to power.meters, sql: {sql}, ErrMessage: {err}.")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -21,6 +21,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to insert data to power.meters, sql:{sql}, ErrMessage:{err}.")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -22,6 +22,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to insert data to power.meters, sql: {sql}, ErrMessage: {err}.")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -16,6 +16,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to query data from power.meters, sql: {sql}, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -15,3 +15,4 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to query data from power.meters, sql: {sql}, ErrMessage:{err}")
|
||||
raise err
|
||||
|
|
|
@ -15,6 +15,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to query data from power.meters, sql: {sql}, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -18,7 +18,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to execute sql with reqId:{reqId}, ErrMessage:{err}")
|
||||
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -16,3 +16,4 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to execute sql with reqId:{reqId}, ErrMessage:{err}")
|
||||
raise err
|
||||
|
|
|
@ -19,6 +19,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to execute sql with reqId:{reqId}, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -35,6 +35,7 @@ try:
|
|||
print("Inserted data with schemaless successfully.");
|
||||
except Exception as err:
|
||||
print(f"Failed to insert data with schemaless, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
|
|
@ -75,8 +75,6 @@ def schemaless_insert():
|
|||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
prepare()
|
||||
schemaless_insert()
|
||||
except Exception as err:
|
||||
print(f"Failed to insert data with schemaless, err:{err}")
|
||||
prepare()
|
||||
schemaless_insert()
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to insert to table meters using stmt, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if stmt:
|
||||
stmt.close()
|
||||
|
|
|
@ -62,6 +62,7 @@ try:
|
|||
|
||||
except Exception as err:
|
||||
print(f"Failed to insert to table meters using stmt, ErrMessage:{err}")
|
||||
raise err
|
||||
finally:
|
||||
if stmt:
|
||||
stmt.close()
|
||||
|
|
|
@ -152,6 +152,7 @@ def unsubscribe(consumer):
|
|||
print("Consumer unsubscribed successfully.");
|
||||
except Exception as err:
|
||||
print(f"Failed to unsubscribe consumer. topic: {topic}, groupId: {groupId}, clientId: {clientId}, ErrMessage:{err}.")
|
||||
raise err
|
||||
finally:
|
||||
if consumer:
|
||||
consumer.close()
|
||||
|
@ -166,7 +167,6 @@ if __name__ == "__main__":
|
|||
subscribe(consumer)
|
||||
seek_offset(consumer)
|
||||
commit_offset(consumer)
|
||||
except Exception as err:
|
||||
print(f"Failed to execute consumer example, topic: {topic}, groupId: {groupId}, clientId: {clientId}, ErrMessage:{err}.")
|
||||
finally:
|
||||
unsubscribe(consumer);
|
||||
if consumer:
|
||||
unsubscribe(consumer);
|
||||
|
|
|
@ -31,7 +31,7 @@ def prepareMeta():
|
|||
|
||||
# create super table
|
||||
rowsAffected = conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
|
||||
"CREATE TABLE IF NOT EXISTS `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(64))"
|
||||
)
|
||||
assert rowsAffected == 0
|
||||
|
||||
|
@ -155,6 +155,7 @@ def unsubscribe(consumer):
|
|||
print("Consumer unsubscribed successfully.");
|
||||
except Exception as err:
|
||||
print(f"Failed to unsubscribe consumer. topic: {topic}, groupId: {groupId}, clientId: {clientId}, ErrMessage:{err}.")
|
||||
raise err
|
||||
finally:
|
||||
if consumer:
|
||||
consumer.close()
|
||||
|
@ -170,7 +171,6 @@ if __name__ == "__main__":
|
|||
subscribe(consumer)
|
||||
seek_offset(consumer)
|
||||
commit_offset(consumer)
|
||||
except Exception as err:
|
||||
print(f"Failed to execute consumer example, topic: {topic}, groupId: {groupId}, clientId: {clientId}, ErrMessage:{err}.")
|
||||
finally:
|
||||
unsubscribe(consumer)
|
||||
if consumer:
|
||||
unsubscribe(consumer)
|
||||
|
|
|
@ -85,8 +85,6 @@ Node.js 连接器目前仅支持 Websocket 连接器, 其通过 taosAdapter
|
|||
| [sql_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/sql_example.js) | 基本的使用如如建立连接,执行 SQL 等操作。 |
|
||||
| [stmt_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/stmt_example.js) | 绑定参数插入的示例。 | |
|
||||
| [line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/line_example.js) | 行协议写入示例。 |
|
||||
| [telnet_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/telnet_line_example.js) | OpenTSDB Telnet 行协议写入示例。 |
|
||||
| [json_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/json_line_example.js) | OpenTSDB JSON 行协议写入示例。 |
|
||||
| [tmq_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/tmq_example.js) | 订阅的使用示例。 |
|
||||
| [all_type_query](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/all_type_query.js) | 支持全部类型示例。 |
|
||||
| [all_type_stmt](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/all_type_stmt.js) | 参数绑定支持全部类型示例。 |
|
||||
|
|
|
@ -2,41 +2,63 @@
|
|||
|
||||
set -e
|
||||
|
||||
check_transactions() {
|
||||
for i in {1..30}
|
||||
do
|
||||
output=$(taos -s "show transactions;")
|
||||
if [[ $output == *"Query OK, 0 row(s)"* ]]; then
|
||||
echo "Success: No transactions are in progress."
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Error: Transactions are still in progress after 30 attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
reset_cache() {
|
||||
response=$(curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' --data 'reset query cache')
|
||||
|
||||
if [[ $response == \{\"code\":0* ]]; then
|
||||
echo "Success: Query cache reset successfully."
|
||||
else
|
||||
echo "Error: Failed to reset query cache. Response: $response"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
pgrep taosd || taosd >> /dev/null 2>&1 &
|
||||
pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
|
||||
|
||||
sleep 10
|
||||
|
||||
cd ../../docs/examples/node
|
||||
|
||||
npm install
|
||||
cd restexample;
|
||||
|
||||
node connect.js
|
||||
cd websocketexample
|
||||
|
||||
cd ../nativeexample
|
||||
node all_type_query.js
|
||||
|
||||
node connect.js
|
||||
node all_type_stmt.js
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
node insert_example.js
|
||||
|
||||
node query_example.js
|
||||
|
||||
node async_query_example.js
|
||||
|
||||
# node subscribe_demo.js
|
||||
|
||||
taos -s "drop topic if exists topic_name_example"
|
||||
taos -s "drop database if exists power"
|
||||
node param_bind_example.js
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
node line_example.js
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
node multi_bind_example.js
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
node nodejsChecker.js
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
node influxdb_line_example.js
|
||||
node sql_example.js
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
node opentsdb_telnet_example.js
|
||||
node stmt_example.js
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
node opentsdb_json_example.js
|
||||
|
||||
node tmq_example.js
|
||||
|
||||
node tmq_seek_example.js
|
|
@ -2,6 +2,34 @@
|
|||
|
||||
set -e
|
||||
|
||||
check_transactions() {
|
||||
for i in {1..30}
|
||||
do
|
||||
output=$(taos -s "show transactions;")
|
||||
if [[ $output == *"Query OK, 0 row(s)"* ]]; then
|
||||
echo "Success: No transactions are in progress."
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Error: Transactions are still in progress after 30 attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
reset_cache() {
|
||||
response=$(curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' --data 'reset query cache')
|
||||
|
||||
if [[ $response == \{\"code\":0* ]]; then
|
||||
echo "Success: Query cache reset successfully."
|
||||
else
|
||||
echo "Error: Failed to reset query cache. Response: $response"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
taosd >>/dev/null 2>&1 &
|
||||
taosadapter >>/dev/null 2>&1 &
|
||||
|
||||
|
@ -11,18 +39,26 @@ cd ../../docs/examples/python
|
|||
|
||||
# 1
|
||||
taos -s "create database if not exists log"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 connect_example.py
|
||||
|
||||
# 2
|
||||
taos -s "drop database if exists power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 native_insert_example.py
|
||||
|
||||
# 3
|
||||
taos -s "drop database power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 bind_param_example.py
|
||||
|
||||
# 4
|
||||
taos -s "drop database power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 multi_bind_example.py
|
||||
|
||||
# 5
|
||||
|
@ -33,20 +69,28 @@ python3 async_query_example.py
|
|||
|
||||
# 7
|
||||
taos -s "drop database if exists test"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 line_protocol_example.py
|
||||
|
||||
# 8
|
||||
taos -s "drop database test"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 telnet_line_protocol_example.py
|
||||
|
||||
# 9
|
||||
taos -s "drop database test"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 json_protocol_example.py
|
||||
|
||||
# 10
|
||||
pip install SQLAlchemy
|
||||
pip install pandas
|
||||
taosBenchmark -y -d power -t 10 -n 10
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 conn_native_pandas.py
|
||||
python3 conn_rest_pandas.py
|
||||
taos -s "drop database if exists power"
|
||||
|
@ -86,8 +130,69 @@ pip3 install kafka-python
|
|||
python3 kafka_example_consumer.py
|
||||
|
||||
# 21
|
||||
pip3 install taos-ws-py==0.3.1
|
||||
pip3 install taos-ws-py==0.3.3
|
||||
python3 conn_websocket_pandas.py
|
||||
|
||||
# 22
|
||||
python3 connect_websocket_examples.py
|
||||
|
||||
# 23
|
||||
python3 create_db_ws.py
|
||||
|
||||
# 24
|
||||
python3 create_db_native.py
|
||||
|
||||
# 25
|
||||
python3 create_db_rest.py
|
||||
|
||||
python3 insert_native.py
|
||||
|
||||
python3 insert_rest.py
|
||||
|
||||
python3 insert_ws.py
|
||||
|
||||
python3 query_native.py
|
||||
|
||||
python3 query_rest.py
|
||||
|
||||
python3 query_ws.py
|
||||
|
||||
python3 reqid_native.py
|
||||
|
||||
python3 reqid_rest.py
|
||||
|
||||
python3 reqid_ws.py
|
||||
|
||||
taos -s "drop database power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 schemaless_native.py
|
||||
|
||||
taos -s "drop database power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 schemaless_ws.py
|
||||
|
||||
taos -s "drop database power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 stmt_native.py
|
||||
|
||||
python3 stmt_ws.py
|
||||
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
taos -s "drop database if exists power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 tmq_native.py
|
||||
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
taos -s "drop database if exists power"
|
||||
check_transactions || exit 1
|
||||
reset_cache || exit 1
|
||||
python3 tmq_websocket_example.py
|
||||
|
||||
|
|
|
@ -1555,9 +1555,10 @@
|
|||
|
||||
#docs-examples test
|
||||
,,n,docs-examples-test,bash python.sh
|
||||
#,,n,docs-examples-test,bash node.sh
|
||||
,,n,docs-examples-test,bash node.sh
|
||||
,,n,docs-examples-test,bash csharp.sh
|
||||
,,n,docs-examples-test,bash jdbc.sh
|
||||
,,n,docs-examples-test,bash rust.sh
|
||||
,,n,docs-examples-test,bash go.sh
|
||||
,,n,docs-examples-test,bash test_R.sh
|
||||
|
||||
|
|
Loading…
Reference in New Issue