Skip to content

Commit b4f9042

Browse files
committed
Some minor optimizations
1 parent 0a4985c commit b4f9042

File tree

4 files changed

+66
-75
lines changed

4 files changed

+66
-75
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ readme = "README.md"
2323
description = "Rust client library for Apache IoTDB"
2424
keywords = ["iotdb", "iotdb-client-rust", "apache-iotdb"]
2525
repository = "https://github.com/manlge/iotdb-client-rs.git"
26+
license-file = "LICENSE"
27+
categories = ["database"]
28+
documentation = "https://docs.rs/iotdb-client-rs"
2629

2730
[dependencies]
2831
thrift="0.15.0"

README.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -244,45 +244,38 @@ fn run() -> Result<()> {
244244

245245
//execute_query_statement
246246
let dataset = session.execute_query_statement("select * from root.sg_rs.device2", None)?;
247-
// Get columns, column types and values from the data set
247+
// Get columns, column types and values from the dataset
248248
// For example:
249-
// dataset
250-
// .get_column_names()
251-
// .iter()
252-
// .for_each(|c| print!("{}\t", c));
253-
// print!("\n");
254-
// dataset
255-
// .get_data_types()
256-
// .iter()
257-
// .for_each(|c| print!("{:?}\t", c));
258-
// print!("\n");
259-
// dataset.for_each(|r| {
260-
// r.values.iter().for_each(|v| match v {
261-
// Value::Bool(v) => print!("{}\t", v),
262-
// Value::Int32(v) => print!("{}\t", v),
263-
// Value::Int64(v) => print!("{}\t", v),
264-
// Value::Float(v) => print!("{}\t", v),
265-
// Value::Double(v) => print!("{}\t", v),
266-
// Value::Text(v) => print!("{}\t", v),
267-
// Value::Null => print!("null\t"),
268-
// });
269-
// print!("\n");
270-
// });
271-
272-
let mut table = Table::new();
273-
table.set_titles(Row::new(
274-
dataset
275-
.get_column_names()
276-
.iter()
277-
.map(|c| cell!(c))
278-
.collect(),
279-
));
280-
dataset.for_each(|r: RowRecord| {
281-
table.add_row(Row::new(
282-
r.values.iter().map(|v: &Value| cell!(v)).collect(),
283-
));
249+
let width = 18;
250+
let column_count = dataset.get_column_names().len();
251+
let print_line_sep = || println!("{:=<width$}", '=', width = (width + 1) * column_count + 1);
252+
253+
print_line_sep();
254+
dataset
255+
.get_column_names()
256+
.iter()
257+
.for_each(|c| print!("|{:>width$}", c.split('.').last().unwrap(), width = width));
258+
print!("|\n");
259+
print_line_sep();
260+
dataset.get_data_types().iter().for_each(|t| {
261+
let type_name = format!("{:?}", t);
262+
print!("|{:>width$}", type_name, width = width)
284263
});
285-
table.printstd();
264+
print!("|\n");
265+
print_line_sep();
266+
dataset.for_each(|r| {
267+
r.values.iter().for_each(|v| match v {
268+
Value::Bool(v) => print!("|{:>width$}", v, width = width),
269+
Value::Int32(v) => print!("|{:>width$}", v, width = width),
270+
Value::Int64(v) => print!("|{:>width$}", v, width = width),
271+
Value::Float(v) => print!("|{:>width$}", v, width = width),
272+
Value::Double(v) => print!("|{:>width$}", v, width = width),
273+
Value::Text(v) => print!("|{:>width$}", v, width = width),
274+
Value::Null => print!("|{:>width$}", "null", width = width),
275+
});
276+
print!("|\n");
277+
});
278+
print_line_sep();
286279

287280
//execute_statement
288281
let dataset = session.execute_statement("show timeseries", None)?;

examples/session_example.rs

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -193,45 +193,38 @@ fn run() -> Result<()> {
193193

194194
//execute_query_statement
195195
let dataset = session.execute_query_statement("select * from root.sg_rs.device2", None)?;
196-
// Get columns, column types and values from the data set
196+
// Get columns, column types and values from the dataset
197197
// For example:
198-
// dataset
199-
// .get_column_names()
200-
// .iter()
201-
// .for_each(|c| print!("{}\t", c));
202-
// print!("\n");
203-
// dataset
204-
// .get_data_types()
205-
// .iter()
206-
// .for_each(|c| print!("{:?}\t", c));
207-
// print!("\n");
208-
// dataset.for_each(|r| {
209-
// r.values.iter().for_each(|v| match v {
210-
// Value::Bool(v) => print!("{}\t", v),
211-
// Value::Int32(v) => print!("{}\t", v),
212-
// Value::Int64(v) => print!("{}\t", v),
213-
// Value::Float(v) => print!("{}\t", v),
214-
// Value::Double(v) => print!("{}\t", v),
215-
// Value::Text(v) => print!("{}\t", v),
216-
// Value::Null => print!("null\t"),
217-
// });
218-
// print!("\n");
219-
// });
198+
let width = 18;
199+
let column_count = dataset.get_column_names().len();
200+
let print_line_sep = || println!("{:=<width$}", '=', width = (width + 1) * column_count + 1);
220201

221-
let mut table = Table::new();
222-
table.set_titles(Row::new(
223-
dataset
224-
.get_column_names()
225-
.iter()
226-
.map(|c| cell!(c))
227-
.collect(),
228-
));
229-
dataset.for_each(|r: RowRecord| {
230-
table.add_row(Row::new(
231-
r.values.iter().map(|v: &Value| cell!(v)).collect(),
232-
));
202+
print_line_sep();
203+
dataset
204+
.get_column_names()
205+
.iter()
206+
.for_each(|c| print!("|{:>width$}", c.split('.').last().unwrap(), width = width));
207+
print!("|\n");
208+
print_line_sep();
209+
dataset.get_data_types().iter().for_each(|t| {
210+
let type_name = format!("{:?}", t);
211+
print!("|{:>width$}", type_name, width = width)
233212
});
234-
table.printstd();
213+
print!("|\n");
214+
print_line_sep();
215+
dataset.for_each(|r| {
216+
r.values.iter().for_each(|v| match v {
217+
Value::Bool(v) => print!("|{:>width$}", v, width = width),
218+
Value::Int32(v) => print!("|{:>width$}", v, width = width),
219+
Value::Int64(v) => print!("|{:>width$}", v, width = width),
220+
Value::Float(v) => print!("|{:>width$}", v, width = width),
221+
Value::Double(v) => print!("|{:>width$}", v, width = width),
222+
Value::Text(v) => print!("|{:>width$}", v, width = width),
223+
Value::Null => print!("|{:>width$}", "null", width = width),
224+
});
225+
print!("|\n");
226+
});
227+
print_line_sep();
235228

236229
//execute_statement
237230
let dataset = session.execute_statement("show timeseries", None)?;

src/client/remote.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ use super::{
4646
};
4747
use super::{DataSet, Dictionary, Result, Session, Value};
4848

49+
static DEFAULT_TIME_ZONE: &str = "Asia/Shanghai";
50+
4951
#[derive(Debug, Clone)]
5052

5153
pub struct Config {
@@ -70,7 +72,7 @@ impl Default for Config {
7072
password: String::from("root"),
7173
timeout_ms: Some(30000),
7274
fetch_size: 1000,
73-
timezone: Some(String::from("Asia/Shanghai")),
75+
timezone: Some(String::from(DEFAULT_TIME_ZONE)),
7476
enable_compression: false,
7577
protocol_version: TSProtocolVersion::IOTDB_SERVICE_PROTOCOL_V3,
7678
is_align: true,
@@ -385,7 +387,7 @@ impl<'a> Session<'a> for RpcSession {
385387
self.config
386388
.timezone
387389
.clone()
388-
.unwrap_or(Config::default().timezone.unwrap()),
390+
.unwrap_or(DEFAULT_TIME_ZONE.to_string()),
389391
self.config.username.clone(),
390392
self.config.password.clone(),
391393
None,

0 commit comments

Comments
 (0)