Coder Social home page Coder Social logo

taos-connector-rust's People

Contributors

adameecs avatar bioinformatist avatar dingbo8128 avatar dinglezhang avatar matthiasbeyer avatar sangshuduo avatar sheyanjie-qq avatar sheyanjie-taos avatar sunpe avatar tjuzyp avatar zhaoyanggh avatar zitsen avatar zmlgirl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taos-connector-rust's Issues

Will Value::VarBinary be fully supported?

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.

Error: [0x2616] Internal error: `����`

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

'error is [0x000B] Unable to establish connection',

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:

  1. TDengine Client can connect to server.
  2. Rust Demo Code always says unable to establish connection.

image

image

image

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"}

What is the proper executor for `exec_sync` (`query_sync`)?

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:

image

Try 1: Use the default test runtime by tokio:x:

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:

image

Try 2: Use the multi-threaded runtime with only one worker thread by tokio:heavy_check_mark:

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.

Try 3: Create a blocking tokio runtime by initializing an instance when necessary:heavy_check_mark:

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?

Problem with connection pool

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:

  1. The example in document is 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.
  2. If it is changed to 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?

win10 下 查询 报错 乱码,另外 占用内存40多m ,有点多

我的查询 代码

        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 多 ,不知道为什么

关于tao-ws 库中异步运行时的问题

在0.5.12 版本中,会进行异步运行时的判断,当存在运行时会加入,不存在才会新建。这个行为是符合实际应用的。但在0.10.20 这个版本中,把判断取消了,直接新建了运行时,这在一些场景下无法正常使用。希望能改回0.5.12的这种模式。

0.5.12 代码
image

0.10.20 代码
image

请问这个变更是基于什么考虑,能否改回原来的模式。谢谢!

`stmt.set_tbname_tags()` contains null tags resulting in error `Signal: 11, SIGSEGV: invalid memory reference`

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"

When using stmt insertion, what's the difference between ColumnView::from_millis_timestamp and ColumnView::from_xxx_ints?

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?

macos 12 & 13.2.1 compile error: the current os is not supported

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...

unresolved import `super::Offset`

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.