taosdata / taos-connector-rust Goto Github PK
View Code? Open in Web Editor NEWTDengine connector for Rust
License: MIT License
TDengine connector for Rust
License: MIT License
It seems inserting with stmt
need to_json_value
method, which may cause:
thread 'core::training::tests::test_register_in_parallel' panicked at 'not yet implemented'
as BINARY
is such a common type in TDengine, which represents those fields with only ASCII characters.
We are using tdengine 2.2 with go, and we want to use rust to rewrite some cases. Does this work with tdengine 2.2?
use taos::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let tao = TaosBuilder::from_dsn("taos://localhost:6030")?.build().await?;
let result = tao.query("SELECT ts, current FROM meters LIMIT 2").await?;
for row in result.fields() {
println!("got row: {}", row.name())
}
}
system Linux cc 5.10.0-15-arm64 #1 SMP Debian 5.10.120-1 (2022-06-09) aarch64 GNU/Linux
cargo run
# ...
Compiling taos v0.9.0
Finished dev [unoptimized + debuginfo] target(s) in 1m 55s
Running `target/debug/rus`
read /etc/localtime error, reason:Invalid argumentfailed to create dir:/var/log/taos/ since Operation not permitted WARING: Create taoslog failed:Operation not permitted. configDir=/etc/taos/
Error: [0x2616] Internal error: `����`
Caused by:
Internal error: `����`
# run sudo
sudo ./target/debug/rus
Error: [0x2616] Internal error: `Q����`
Caused by:
Internal error: `Q����`
read /etc/localtime error, reason:Invalid argument
maybe caused by this issue taosdata/TDengine#18677
Server: Ubuntu and run tdengine in docker container.
tdengine version: 3.0.1.0
Client: Windows Server.
tdengine client version: 3.0.1.0
Problem:
unable to establish connection
.use taos::sync::*;
// #[tokio::main]
// fn demo_write() -> anyhow::Result<()> {
// let dsn = "taos://192.168.0.166:6030";
// let taos = TaosBuilder::from_dsn(dsn)?.build()?;
// taos.exec_many([
// "DROP DATABASE IF EXISTS power",
// "CREATE DATABASE power",
// "USE power",
// "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
// ])?;
// // ]).await?;
// let inserted = taos.exec("INSERT INTO
// power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
// VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)
// ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
// power.d1002 USING power.meters TAGS('California.SanFrancisco', 3)
// VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
// power.d1003 USING power.meters TAGS('California.LosAngeles', 2)
// VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
// power.d1004 USING power.meters TAGS('California.LosAngeles', 3)
// VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)")?;
// assert_eq!(inserted, 8);
// Ok(())
// }
fn demo() -> anyhow::Result<()> {
println!("hahahah --------- 1");
let taos = TaosBuilder::from_dsn("taos://192.168.0.191:6030")?.build()?;
// let taos = TaosBuilder::from_dsn("taos://192.168.0.191:6030/performance_schema")?.build()?;
println!("hahahah --------- 2");
let _ = taos.exec("Use algom;");
let mut result = taos.query("select * from perf_connectionsxxxxx limit 2;")?;
println!("hahahah --------- 3");
// print column names
let meta = result.fields();
println!("{}", meta.iter().map(|field| field.name()).join("\t"));
// print rows
let rows = result.rows();
for row in rows {
let row = row?;
for (_name, value) in row {
print!("{}\t", value);
}
println!();
}
Ok(())
}
fn main() {
let res = demo();
let _res_v = match res {
Ok(vv) => vv,
Err(error) => panic!("error is {:?}", error),
};
}
[dependencies]
# use default feature
taos = { version = "0.2.10"}
All operations in this issue are performed in
ws
mode as:
taos = { version = "*", default-features = false, features = ["ws"] }
In a special scenario we need to use the connector in blocking (synchronous) way. I've noticed that the blocking mode was implemented by futures::executor::block_on()
in source code, but I'm not sure what is the right runtime for this, so tokio was just introduced by the error message:
The tokio was labelled as dependency in my Cargo.toml
(with all features enabled):
tokio = { version = "1", features = ["full"] }
and with the default test runtime by tokio:
#[tokio::test()]
async fn test_task_running_in_parallel() -> Result<()> {
// ...
taos.exec_sync("...")?
}
this will cause hanging:
The Cargo.toml
was same to Try 1, but the code was changed to:
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_task_running_in_parallel() -> Result<()> {
// ...
taos.exec_sync("...")?
}
This time the test passed.
The Cargo.toml
was same to previous ones, but the code was changed to:
#[test]
fn test_task_running_in_parallel() -> Result<()> {
// ...
use tokio::runtime::Runtime;
Runtime::new().unwrap().block_on(
async {
taos.exec_sync("...").unwrap()
}
);
}
The test also passed.
It seems that with tokio, the futures::executor::block_on()
can work well in a new thread instead of the current one.
Please also refer to this: tokio-rs/tokio#2376 (comment)
So which one is the best way and if there's other elegant solutions? The 3rd way is better for me since I don't want a function with an asynchronous declaration in its signature, but it's inconvenience for initializing a blocking tokio runtime everywhere.
Or shall we use tokio::task::spawn_blocking()
instead of futures::executor::block_on()
for exec_sync
and query_sync
?
Hi,I’m trying to create a connection pool according to the documentation:
fn build_pool(&self) -> Pool<Manager<TaosBuilder>> {
let dsn = "taos://localhost:6030";
let opts = TaosBuilder::pool_builder.max_size(88);
TaosBuilder::from_dsn(dsn).unwrap().with_pool_config(opts).unwrap()
}
However, there're some problems:
let pool = TaosBuilder::from_dsn(dsn)?.with_pool_builder(opts)?;
, but there's no with_pool_builder()
method now. It seems be an outdated version.with_pool_config()
instead as shown in my snippet, the compiler will complain:the trait bound `taos::taos_query::Manager<taos::TaosBuilder>: r2d2::ManageConnection` is not satisfied
the trait `r2d2::ManageConnection` is not implemented for `taos::taos_query::Manager<taos::TaosBuilder>`
So does taos::TaosBuilder
need to implement the r2d2::ManageConnection
?
Our project zino
is using taos
. When upgrading the version to 0.6.0
, it fails to build. We would like to find the CHANGELOG for the new version. Thanks!
我的查询 代码
let conn = self.td_conns.get(machine_index as usize).unwrap();
let query_clone = query.clone();
let result = conn.query(query_clone).await;
let mut result = match result {
Ok(result) => result,
Err(err) => {
return Err(format!("查询taos 错误 ,sql语句 is {}, err is {}", query, err));
}
};
如果 出现错误 ,如 查询的表不存在 , 在命令行打印为
Jan 29 01:41:07.621 INFO axum_study::controller::jian_pan_controller: 查询失败 "查询taos 错误 ,sql语句 is select 1 as sort_order ,'dcs_rhte' as tablename,'undefined' as description ,'' as label ,'1' as borderType ,'undefined' as unit, l
ast(ts) as ts ,last(pvalue) as pvalue from dcs_rhte order by sort_order ;, err is [0x2662] Internal error: `����������������������������������������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������systS�x�`"
err 全都是乱码,无法显示
另外 这是我启动的代码
let start = Instant::now();
// 建立 taos 连接
let taos_futures: Vec<_> = config.cfg.iter().enumerate().map(|(index, cfg)| {
let dsn = format!("taos://{}:{}@{}:{}/{}", cfg.user, cfg.password, cfg.host, cfg.port, cfg.database);
info!("{}号机 taos 连接字符串为: {}", index + 1, dsn);
async move {
let builder = TaosBuilder::from_dsn(&dsn).map_err(|e| format!("创建 TaosBuilder 失败:{}", e))?;
builder.build().await.map_err(|e| format!("{}号机 taos 数据库连接失败:{}", index + 1, e))
}
}).collect();
// let taos = Vec::new();
let taos: Vec<_> = join_all(taos_futures)
.await
.into_iter()
.map(|db| db.unwrap_or_else(|e| panic!("taos 数据库连接失败:{}", e)))
.collect();
let duration = start.elapsed();
info!("建立taos 连接耗时为 :{:?}", duration);
启动完成后 发现 程序 占用内存 50多m ,注释掉这行代码 只用内存为 7m , 我尝试过不用futures ,然后 单个连接taos 数据库, 结果占用内存 48m , 连接同样的taos 数据库, c# 占用内存就少很多 ,只有 8m 多 ,不知道为什么
Bug Description
stmt.set_tbname_tags()
contains null tags resulting in error signal: 11, SIGSEGV: invalid memory reference
using native
connection, while using websocket
connection is ok
~/taos-connector-rust-test$ cargo test test_ok
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running unittests src/main.rs (target/debug/deps/taos_connector_rust_test-e94ad84d9c31444b)
running 1 test
test tests::test_ok ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 1.46s
~/taos-connector-rust-test$ cargo test test_ws_null
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running unittests src/main.rs (target/debug/deps/taos_connector_rust_test-e94ad84d9c31444b)
running 1 test
test tests::test_ws_null ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.60s
~/taos-connector-rust-test$ cargo test test_taos_null --bin taos-connector-rust-test
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running unittests src/main.rs (target/debug/deps/taos_connector_rust_test-e94ad84d9c31444b)
running 1 test
error: test failed, to rerun pass `--bin taos-connector-rust-test`
Caused by:
process didn't exit successfully: `/home/zky/taos-connector-rust-test/target/debug/deps/taos_connector_rust_test-e94ad84d9c31444b test_taos_null` (signal: 11, SIGSEGV: invalid memory reference)
To Reproduce
test_taos_null()
reults in error while test_ws_null()
and test_ok()
work fine.main.rs
use taos::*;
async fn test_null_tag(dsn: &str, tag_value: Value) -> anyhow::Result<()> {
let taos = TaosBuilder::from_dsn(dsn)?.build().await?;
taos.exec("DROP DATABASE IF EXISTS power").await?;
taos.create_database("power").await?;
taos.use_database("power").await?;
taos.exec("CREATE STABLE IF NOT EXISTS meters (ts TIMESTAMP, current FLOAT) TAGS (location BINARY(64), groupId INT)").await?;
let mut stmt = Stmt::init(&taos).await?;
stmt.prepare("INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?)")
.await?;
// bind table name and tags
stmt.set_tbname_tags(
"d1001",
&[Value::VarChar("California.SanFransico".into()), tag_value],
)
.await?;
// bind values.
let values = vec![
ColumnView::from_millis_timestamp(vec![1648432611249]),
ColumnView::from_floats(vec![10.3]),
];
stmt.bind(&values).await?;
stmt.add_batch().await?;
// execute.
let rows = stmt.execute().await?;
assert_eq!(rows, 1);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use anyhow::Result;
#[tokio::test]
async fn test_taos_null() -> Result<()> {
test_null_tag("taos://", Value::Null(Ty::Int)).await?;
Ok(())
}
#[tokio::test]
async fn test_ws_null() -> Result<()> {
test_null_tag("ws://", Value::Null(Ty::Int)).await?;
Ok(())
}
#[tokio::test]
async fn test_ok() -> Result<()> {
test_null_tag("ws://", Value::Int(8)).await?;
test_null_tag("taos://", Value::Int(8)).await?;
Ok(())
}
}
Cargo.toml
[package]
name = "taos-connector-rust-test"
version = "0.1.0"
edition = "2021"
[dependencies]
taos = "*"
anyhow = "1"
For example, we can get current timestamp in nano second like this:
let current_ts = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("Clock may have gone backwards")
.as_nanos() as i64;
Since I'v not found a method with nano second, I just used ColumnView::from_big_ints(vec![current_ts])
for binding value, and the record in database was correctly in nano second. So what's the difference between ColumnView::from_millis_timestamp
and ColumnView::from_xxx_ints
?
when execute cargo build --release, it cames out :
error: failed to run custom build command for `taos-sys v0.3.12 (/Users/zmlgirl/Documents/codes/github/taosdata/taos-connector-rust/taos-sys)`
Caused by:
process didn't exit successfully: `/Users/zmlgirl/Documents/codes/github/taosdata/taos-connector-rust/target/release/build/taos-sys-a09b52143fd67bfc/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=TAOS_LIBRARY_PATH
TAOS_LIBRARY_PATH unset
--- stderr
thread 'main' panicked at 'internal error: entered unreachable code: the current os is not supported', taos-sys/build.rs:60:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error[E0432]: unresolved import super::Offset
--> .cargo/registry/src/github.com-1ecc6299db9ec823/taos-0.8.8/src/lib.rs:11:43
|
11 | pub use super::{Consumer, MessageSet, Offset, TmqBuilder};
| ^^^^^^
| |
| no Offset
in the root
| help: a similar name exists in the module: IsOffset
|
= help: consider importing one of these items instead:
crate::tmq::Offset
taos_sys::tmq::Offset
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.