added examples
This commit is contained in:
parent
9e808b2b47
commit
386218eecb
9 changed files with 55 additions and 44 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -8,16 +8,9 @@ version = "1.0.95"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byteorder",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,5 +4,4 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.5"
|
||||
anyhow = "1.0"
|
||||
|
|
|
|||
3
examples/join/data/left.csv
Normal file
3
examples/join/data/left.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name value
|
||||
a 3
|
||||
b 4
|
||||
|
3
examples/join/data/right.csv
Normal file
3
examples/join/data/right.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name cowdung
|
||||
a 2
|
||||
c 42
|
||||
|
18
examples/join/main.rs
Normal file
18
examples/join/main.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use csv::Table;
|
||||
|
||||
fn main() {
|
||||
let left = Table::from_csv(include_str!("data/left.csv"), "\t");
|
||||
let right = Table::from_csv(include_str!("data/right.csv"), "\t");
|
||||
println!("left:");
|
||||
left.select("*");
|
||||
println!("\nright:");
|
||||
right.select("*");
|
||||
println!("\njoin on name:");
|
||||
left.left_join(&right, "name", "name", false)
|
||||
.select("name, cowdung, value");
|
||||
println!("\nleft join on name:");
|
||||
left.left_join(&right, "name", "name", true).select("*");
|
||||
println!("\nright join on name:");
|
||||
left.right_join(&right, "name", "name", true)
|
||||
.select("name,cowdung,value");
|
||||
}
|
||||
4
examples/orderby/data/table.csv
Normal file
4
examples/orderby/data/table.csv
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
name value
|
||||
a 3
|
||||
q 11
|
||||
b 4
|
||||
|
12
examples/orderby/main.rs
Normal file
12
examples/orderby/main.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use csv::Table;
|
||||
|
||||
fn main() {
|
||||
let table = Table::from_csv(include_str!("data/table.csv"), "\t");
|
||||
println!("not ordered:");
|
||||
table.select("*");
|
||||
|
||||
println!("order by name ascending:");
|
||||
table.order_by("name").select("*");
|
||||
|
||||
println!("\nTODO descending");
|
||||
}
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
use crate::Table;
|
||||
// use crate::Table;
|
||||
|
||||
impl Table {
|
||||
pub fn group_by(&self, select_expression: &str, group_by_expression: &str) -> Table {
|
||||
let table = Table::new("");
|
||||
|
||||
table
|
||||
}
|
||||
}
|
||||
|
||||
// fn parse_select(select: &str){
|
||||
// impl Table {
|
||||
// pub fn group_by(&self, select_expression: &str, group_by_expression: &str) -> Table {
|
||||
// let table = Table::new("");
|
||||
|
||||
// table
|
||||
// }
|
||||
// }
|
||||
|
||||
// enum Aggregation {
|
||||
// Sum(String),
|
||||
// Max(String),
|
||||
// Min(String),
|
||||
// }
|
||||
// // fn parse_select(select: &str){
|
||||
|
||||
// // }
|
||||
|
||||
// // enum Aggregation {
|
||||
// // Sum(String),
|
||||
// // Max(String),
|
||||
// // Min(String),
|
||||
// // }
|
||||
|
|
|
|||
21
src/main.rs
21
src/main.rs
|
|
@ -1,21 +0,0 @@
|
|||
use csv::Table;
|
||||
|
||||
fn main() {
|
||||
let companies = Table::from_csv(include_str!("data/companies.csv"), "\t");
|
||||
let remove = Table::from_csv(include_str!("data/remove.csv"), "\t");
|
||||
|
||||
// companies.pretty_print("*");
|
||||
// remove.pretty_print("*");
|
||||
let left = Table::from_csv(include_str!("data/left.csv"), "\t");
|
||||
let right = Table::from_csv(include_str!("data/right.csv"), "\t");
|
||||
// left.pretty_print("*");
|
||||
// right.pretty_print("*");
|
||||
let join1 = left.left_join(&right, "name", "name", true);
|
||||
let join2 = left.right_join(&right, "name", "name", true);
|
||||
//
|
||||
companies
|
||||
.left_join(&remove, "aisAccountID", "aisaccountid", false)
|
||||
.order_by("aisAccountID")
|
||||
.select("aisAccountID");
|
||||
// join2.pretty_print("*");
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue