Skip to content

Commit

Permalink
feat: add ColumnSchema creation shortcuts (#14)
Browse files Browse the repository at this point in the history
* docs: update readme and removes features that no longer valid

* feat: add schema creation shortcuts

* chore: make license eye happy
  • Loading branch information
sunng87 authored Feb 2, 2024
1 parent 4cb19ec commit 35c09ba
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 50 deletions.
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
31 changes: 6 additions & 25 deletions examples/ingest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -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
2 changes: 1 addition & 1 deletion examples/stream_ingest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/api/v1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/channel_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -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 2024 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()
}
}
2 changes: 1 addition & 1 deletion src/helpers/values.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/load_balance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/stream_insert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 35c09ba

Please sign in to comment.