Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit 1a3df39

Browse files
committed
release: 0.0.7
1 parent 0b3efb5 commit 1a3df39

File tree

6 files changed

+790
-323
lines changed

6 files changed

+790
-323
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iotdb"
3-
version = "0.0.6"
3+
version = "0.0.7"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "README.md"

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,42 @@ Add `iotdb` to your `Cargo.toml`
3131

3232
```toml
3333
[dependencies]
34-
iotdb = "0.0.6"
34+
iotdb = "0.0.7"
35+
simplelog = "0.11.0"
3536
```
3637

3738
## Example
3839

3940
```rust
4041
use chrono::Local;
41-
use thrift::Error;
4242

43-
use iotdb::common::{Compressor, DataType, Encoding};
44-
use iotdb::{ConfigBuilder, Session};
43+
use iotdb::*;
4544

46-
fn main() -> Result<(), Error> {
47-
let config = ConfigBuilder::new()
48-
.endpoint("127.0.0.1", "6667")
45+
fn main() -> Result<(), anyhow::Error> {
46+
debug(false);
47+
48+
let config = iotdb::ConfigBuilder::new()
49+
.endpoint("localhost:6667")
4950
.user("root")
5051
.password("root")
5152
.time_zone("UTC+8")
52-
// .debug(true)
5353
.build();
5454

5555
// open session
56-
let mut session = Session::new(config).open()?;
56+
let mut session = Session::connect(config)?;
5757
println!("time_zone: {}", session.time_zone()?);
5858
session.delete_storage_group("root.ln")?;
5959
session.set_storage_group("root.ln")?;
6060
session.create_time_series(
6161
"root.ln.wf01.wt01.temperature",
62-
DataType::INT64,
62+
DataType::FLOAT,
6363
Encoding::default(),
6464
Compressor::default(),
6565
)?;
6666

6767
session.create_time_series(
68-
"root.ln.wf01.wt01.humidity",
69-
DataType::INT64,
68+
"root.ln.wf01.wt01.status",
69+
DataType::BOOLEAN,
7070
Encoding::default(),
7171
Compressor::default(),
7272
)?;
@@ -102,10 +102,28 @@ fn main() -> Result<(), Error> {
102102
)?;
103103
session.sql("select * from root.ln")?.show();
104104

105+
// DF (TODO)
106+
let df = session.sql("select * from root.ln")?.to_df()?;
107+
println!("IoTDB DF is empty: {}", df.is_empty());
108+
105109
session.close()?;
106110

107111
Ok(())
108112
}
113+
114+
fn debug(enable: bool) {
115+
use simplelog::*;
116+
let mut log_level = LevelFilter::Info;
117+
if enable {
118+
log_level = LevelFilter::Debug;
119+
}
120+
let _ = CombinedLogger::init(vec![TermLogger::new(
121+
log_level,
122+
Default::default(),
123+
TerminalMode::Mixed,
124+
ColorChoice::Auto,
125+
)]);
126+
}
109127
```
110128

111129
## Run example
@@ -133,7 +151,7 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
133151
```shell
134152
git clone https://github.com/francis-du/iotdb-rs.git
135153

136-
cargo run --example main
154+
cargo run --example iotdb
137155
```
138156

139157
## LICENSE

examples/polars.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/ds.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,12 @@ impl RecordBatch {
8585
}
8686
}
8787

88-
#[derive(Clone, Debug)]
88+
#[derive(Clone, Debug, Default)]
8989
pub struct DataSet {
9090
record_batch: RecordBatch,
9191
ignore_time_stamp: Option<bool>,
9292
}
9393

94-
impl Default for DataSet {
95-
fn default() -> Self {
96-
Self {
97-
record_batch: RecordBatch::default(),
98-
ignore_time_stamp: None,
99-
}
100-
}
101-
}
102-
10394
impl DataSet {
10495
pub(crate) fn new(resp: TSExecuteStatementResp) -> DataSet {
10596
debug!("{:#?}", resp);

src/lib.rs

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,47 @@
2222
//!
2323
//! ```toml
2424
//! [dependencies]
25-
//! iotdb = "0.0.6"
25+
//! iotdb = "0.0.7"
26+
//! simplelog = "0.11.0"
2627
//! ```
2728
//!
2829
//! # Example
2930
//!
3031
//! ```rust
3132
//! use chrono::Local;
32-
//! use thrift::Error;
3333
//!
34-
//! use iotdb::common::{Compressor, DataType, Encoding};
35-
//! use iotdb::{ConfigBuilder, Session};
34+
//! use iotdb::*;
3635
//!
37-
//! fn main() -> Result<(), Error> {
38-
//! let config = ConfigBuilder::new()
39-
//! .endpoint("127.0.0.1", "6667")
36+
//! fn main() -> Result<(), anyhow::Error> {
37+
//! debug(false);
38+
//!
39+
//! let config = iotdb::ConfigBuilder::new()
40+
//! .endpoint("localhost:6667")
4041
//! .user("root")
4142
//! .password("root")
42-
//! .zone_id("UTC+8")
43-
//! .debug(true)
43+
//! .time_zone("UTC+8")
4444
//! .build();
4545
//!
46-
//! // open session
47-
//! let mut session = Session::new(config).open()?;
46+
//! // open session
47+
//! let mut session = Session::connect(config)?;
4848
//! println!("time_zone: {}", session.time_zone()?);
4949
//! session.delete_storage_group("root.ln")?;
5050
//! session.set_storage_group("root.ln")?;
5151
//! session.create_time_series(
5252
//! "root.ln.wf01.wt01.temperature",
53-
//! DataType::INT64,
53+
//! DataType::FLOAT,
5454
//! Encoding::default(),
5555
//! Compressor::default(),
5656
//! )?;
5757
//!
5858
//! session.create_time_series(
59-
//! "root.ln.wf01.wt01.humidity",
60-
//! DataType::INT64,
59+
//! "root.ln.wf01.wt01.status",
60+
//! DataType::BOOLEAN,
6161
//! Encoding::default(),
6262
//! Compressor::default(),
6363
//! )?;
6464
//!
65-
//! let now = Local::now().timestamp();
65+
//! let now = Local::now().timestamp_millis();
6666
//! session.sql(
6767
//! format!(
6868
//! "INSERT INTO root.ln.wf01.wt01(timestamp,status) values({},true)",
@@ -91,41 +91,50 @@
9191
//! )
9292
//! .as_str(),
9393
//! )?;
94-
//! session.sql("select * from root.ln")?.show();
95-
//! session.close()?;
94+
//! session.sql("select * from root.ln")?.show();
95+
//!
96+
//! // DF (TODO)
97+
//! let df = session.sql("select * from root.ln")?.to_df()?;
98+
//! println!("IoTDB DF is empty: {}", df.is_empty());
99+
//!
100+
//! session.close()?;
101+
//!
102+
//! Ok(())
103+
//! }
96104
//!
97-
//! Ok(())
105+
//! fn debug(enable: bool) {
106+
//! use simplelog::*;
107+
//! let mut log_level = LevelFilter::Info;
108+
//! if enable {
109+
//! log_level = LevelFilter::Debug;
110+
//! }
111+
//! let _ = CombinedLogger::init(vec![TermLogger::new(
112+
//! log_level,
113+
//! Default::default(),
114+
//! TerminalMode::Mixed,
115+
//! ColorChoice::Auto,
116+
//! )]);
98117
//! }
99118
//! ```
100119
#[macro_use]
101120
extern crate prettytable;
102121

103-
pub use chrono;
104-
pub use polars;
105122
use std::collections::BTreeMap;
106123
use std::net::TcpStream;
107124
use std::str::FromStr;
108-
pub use thrift;
109125

110126
use anyhow::bail;
127+
pub use chrono;
111128
use chrono::{Local, Utc};
112129
use log::{debug, error, info};
113130
use mimalloc::MiMalloc;
114-
use thrift::protocol::{
115-
TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol, TCompactOutputProtocol,
116-
TInputProtocol, TOutputProtocol,
117-
};
118-
use thrift::transport::{TFramedReadTransport, TFramedWriteTransport, TIoChannel, TTcpChannel};
131+
pub use polars;
132+
pub use thrift;
133+
use thrift::protocol::*;
134+
use thrift::transport::*;
119135

120136
use crate::ds::DataSet;
121-
pub use crate::ds::*;
122-
use crate::rpc::{
123-
TSCancelOperationReq, TSCloseSessionReq, TSCreateMultiTimeseriesReq, TSCreateTimeseriesReq,
124-
TSDeleteDataReq, TSExecuteBatchStatementReq, TSExecuteStatementReq, TSExecuteStatementResp,
125-
TSIServiceSyncClient, TSInsertRecordReq, TSInsertRecordsReq, TSInsertStringRecordsReq,
126-
TSInsertTabletReq, TSInsertTabletsReq, TSOpenSessionReq, TSOpenSessionResp, TSProtocolVersion,
127-
TSRawDataQueryReq, TSSetTimeZoneReq, TSStatus, TTSIServiceSyncClient,
128-
};
137+
use crate::rpc::*;
129138

130139
mod ds;
131140
mod errors;
@@ -345,6 +354,7 @@ impl Into<i32> for Compressor {
345354
}
346355
}
347356

357+
/// Session Endpoint
348358
#[derive(Clone, Debug)]
349359
pub struct Endpoint {
350360
pub host: String,
@@ -421,6 +431,7 @@ impl Default for Config {
421431
}
422432
}
423433

434+
/// IotDB Config Builder
424435
pub struct ConfigBuilder(Config);
425436

426437
impl Default for ConfigBuilder {
@@ -499,6 +510,7 @@ impl ConfigBuilder {
499510
}
500511
}
501512

513+
/// IotDB Session
502514
pub struct Session {
503515
client: ClientType,
504516
config: Config,
@@ -574,7 +586,7 @@ impl Session {
574586
})
575587
}
576588
} else {
577-
let msg = format!("{}", status.message.unwrap_or_else(|| "None".to_string()));
589+
let msg = status.message.unwrap_or_else(|| "None".to_string());
578590
error!("{}", msg);
579591
bail!(msg)
580592
}
@@ -635,7 +647,7 @@ impl Session {
635647
/// Delete a storage group.
636648
pub fn delete_storage_group(&mut self, storage_group: &str) -> anyhow::Result<()> {
637649
debug!("Delete storage group {:?}", storage_group);
638-
Ok(self.delete_storage_groups(vec![storage_group.to_string()])?)
650+
self.delete_storage_groups(vec![storage_group.to_string()])
639651
}
640652

641653
/// Delete storage groups.
@@ -775,14 +787,12 @@ impl Session {
775787
false,
776788
);
777789

778-
match self.client.execute_query_statement(req)? {
779-
TSExecuteStatementResp { query_data_set, .. } => {
780-
if query_data_set.is_none() {
781-
Ok(false)
782-
} else {
783-
Ok(query_data_set.unwrap().value_list.is_empty())
784-
}
785-
}
790+
let TSExecuteStatementResp { query_data_set, .. } =
791+
self.client.execute_query_statement(req)?;
792+
if let Some(..) = query_data_set {
793+
Ok(false)
794+
} else {
795+
Ok(query_data_set.unwrap().value_list.is_empty())
786796
}
787797
}
788798

@@ -1109,14 +1119,10 @@ impl Session {
11091119
let status = resp.clone().status;
11101120
let msg = status.clone().message.unwrap_or_else(|| "None".to_string());
11111121
if self.is_success(&status) {
1112-
debug!(
1113-
"Execute statement {:?}, message: {:?}",
1114-
statement,
1115-
msg.clone()
1116-
);
1122+
debug!("Execute statement {:?}, message: {:?}", statement, msg);
11171123
Ok(DataSet::new(resp))
11181124
} else {
1119-
error!("{}", msg.clone());
1125+
error!("{}", msg);
11201126
bail!(msg)
11211127
}
11221128
}

0 commit comments

Comments
 (0)