Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ColumnSchema creation shortcuts #14

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# GreptimeDB Rust Client
# GreptimeDB Rust Ingester

A Rust client for GreptimeDB gRPC protocol.

## Status

- [x] gRPC inserts
- [x] gRPC stream inserts
- [x] gRPC deletes
- [ ] Arrow Flight API
- [ ] DDL
- [ ] SQL query
- [ ] PromQL query
- [ ] Prometheus gateway API
A Rust client for ingesting data into GreptimeDB, using GreptimeDB's gRPC
protocol.

See
[examples](https://github.com/GreptimeTeam/greptimedb-ingester-rust/blob/master/examples/ingest.rs)
for latest usage demo.

## License

Expand Down
29 changes: 5 additions & 24 deletions examples/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use derive_new::new;

use greptimedb_client::api::v1::*;
use greptimedb_client::helpers::schema::*;
use greptimedb_client::helpers::values::*;
use greptimedb_client::{Client, Database, DEFAULT_SCHEMA_NAME};

Expand Down Expand Up @@ -61,30 +62,10 @@ fn weather_records() -> Vec<WeatherRecord> {

fn weather_schema() -> Vec<ColumnSchema> {
vec![
ColumnSchema {
column_name: "ts".to_owned(),
semantic_type: SemanticType::Timestamp as i32,
datatype: ColumnDataType::TimestampMillisecond as i32,
..Default::default()
},
ColumnSchema {
column_name: "collector".to_owned(),
semantic_type: SemanticType::Tag as i32,
datatype: ColumnDataType::String as i32,
..Default::default()
},
ColumnSchema {
column_name: "temperature".to_owned(),
semantic_type: SemanticType::Field as i32,
datatype: ColumnDataType::Float32 as i32,
..Default::default()
},
ColumnSchema {
column_name: "humidity".to_owned(),
semantic_type: SemanticType::Field as i32,
datatype: ColumnDataType::Int32 as i32,
..Default::default()
},
timestamp("ts", ColumnDataType::TimestampMillisecond),
tag("collector", ColumnDataType::String),
field("temperature", ColumnDataType::Float32),
field("humidity", ColumnDataType::Int32),
]
}

Expand Down
1 change: 1 addition & 0 deletions src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod schema;
pub mod values;
42 changes: 42 additions & 0 deletions src/helpers/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::api::v1::*;

pub fn tag(name: &str, datatype: ColumnDataType) -> ColumnSchema {
ColumnSchema {
column_name: name.to_string(),
semantic_type: SemanticType::Tag as i32,
datatype: datatype as i32,
..Default::default()
}
}

pub fn timestamp(name: &str, datatype: ColumnDataType) -> ColumnSchema {
ColumnSchema {
column_name: name.to_string(),
semantic_type: SemanticType::Timestamp as i32,
datatype: datatype as i32,
..Default::default()
}
}

pub fn field(name: &str, datatype: ColumnDataType) -> ColumnSchema {
ColumnSchema {
column_name: name.to_string(),
semantic_type: SemanticType::Field as i32,
datatype: datatype as i32,
..Default::default()
}
}
Loading