Apache IoTDB

Apache IoTDB (Database for Internet of Things) is an IoT native database with high performance for
data management and analysis, deployable on the edge and the cloud. Due to its light-weight
architecture, high performance and rich feature set together with its deep integration with
Apache Hadoop, Spark and Flink, Apache IoTDB can meet the requirements of massive data storage,
high-speed data ingestion and complex data analysis in the IoT industrial fields.
Apache IoTDB Client for Rust
About version support
Supports the latest version 1.3.1 of IoTDB and is also compatible with operations below version 1.0
Overview
This is the Rust client of Apache IoTDB.
Apache IoTDB website: https://iotdb.apache.org
Apache IoTDB Github: https://github.com/apache/iotdb
Prerequisites
apache-iotdb 0.12.0 and newer.
rust 1.56.0 and newer.
How to Use the Client (Quick Start)
Usage
Put this in your Cargo.toml
:
[dependencies]
iotdb-client="0.1.0"
Example
Put this in your example's Cargo.toml
:
[dependencies]
iotdb-client="0.1.0"
chrono="0.4.19"
prettytable-rs="0.8.0"
structopt = "0.3.25"
use std::{collections::BTreeMap, vec};
use chrono::Local;
use iotdb_client::client::remote::{Config, RpcSession};
use iotdb_client::client::{MeasurementSchema, Result, RowRecord, Session, Tablet, Value};
use iotdb_client::protocal::{TSCompressionType, TSDataType, TSEncoding};
use prettytable::{cell, Row, Table};
use structopt::StructOpt;
fn main() {
demo().expect("failed to run example.");
}
fn demo() -> Result<()> {
let config = Config::builder()
.host("127.0.0.1")
.port(6667)
.username("root")
.password("root")
.build();
let mut session = RpcSession::new(config)?;
session.open()?;
let tz = session.get_time_zone()?;
if tz != "Asia/Shanghai" {
session.set_time_zone("Asia/Shanghai")?;
}
{
let dataset = session.execute_query_statement(" select * from root.sg_rs.*;", None)?;
let width = 18;
let column_count = dataset.get_column_names().len();
let print_line_sep =
|| println!("{:=<width$}", '=', width = (width + 1) * column_count + 1);
print_line_sep();
dataset
.get_column_names()
.iter()
.for_each(|c| print!("|{:>width$}", c.split('.').last().unwrap(), width = width));
println!("|");
print_line_sep();
dataset.get_data_types().iter().for_each(|t| {
let type_name = format!("{:?}", t);
print!("|{:>width$}", type_name, width = width)
});
println!("|");
print_line_sep();
dataset.for_each(|r| {
r.values.iter().for_each(|v| match v {
Value::Bool(v) => print!("|{:>width$}", v, width = width),
Value::Int32(v) => print!("|{:>width$}", v, width = width),
Value::Int64(v) => print!("|{:>width$}", v, width = width),
Value::Float(v) => print!("|{:>width$}", v, width = width),
Value::Double(v) => print!("|{:>width$}", v, width = width),
Value::Text(v) => print!("|{:>width$}", v, width = width),
Value::Null => print!("|{:>width$}", "null", width = width),
});
println!("|");
});
print_line_sep();
}
session.close()?;
Ok(())
}