added examples

This commit is contained in:
Sander Hautvast 2025-02-13 22:19:26 +01:00
parent 9e808b2b47
commit 386218eecb
9 changed files with 55 additions and 44 deletions

7
Cargo.lock generated
View file

@ -8,16 +8,9 @@ version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "csv" name = "csv"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"byteorder",
] ]

View file

@ -4,5 +4,4 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
byteorder = "1.5"
anyhow = "1.0" anyhow = "1.0"

View file

@ -0,0 +1,3 @@
name value
a 3
b 4
1 name value
2 a 3
3 b 4

View file

@ -0,0 +1,3 @@
name cowdung
a 2
c 42
1 name cowdung
2 a 2
3 c 42

18
examples/join/main.rs Normal file
View 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");
}

View file

@ -0,0 +1,4 @@
name value
a 3
q 11
b 4
1 name value
2 a 3
3 q 11
4 b 4

12
examples/orderby/main.rs Normal file
View 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");
}

View file

@ -1,19 +1,19 @@
use crate::Table; // use crate::Table;
impl Table { // impl Table {
pub fn group_by(&self, select_expression: &str, group_by_expression: &str) -> Table { // pub fn group_by(&self, select_expression: &str, group_by_expression: &str) -> Table {
let table = Table::new(""); // let table = Table::new("");
table
}
}
// fn parse_select(select: &str){
// table
// }
// } // }
// enum Aggregation { // // fn parse_select(select: &str){
// Sum(String),
// Max(String), // // }
// Min(String),
// } // // enum Aggregation {
// // Sum(String),
// // Max(String),
// // Min(String),
// // }

View file

@ -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("*");
}