Now that rledger
can parse a basic journal, we need a way to query the transactions and postings.
My instinct is to use SQL. I considered using SQLite but wanted to explore the data frame libraries in Rust.
I tried using pola.rs. This crate has a very flexible API that seemed ideal for my querying needs.
In addition, polars would provide excellent performance.
However, after experimenting with calculations needed for producing the balance sheet, I decided to remove polars due to unbearably long compile times.
I will revisit using the crate in the future in case there are ways to improve dev-cycle compile times.
Perhaps once features are more stable, longer compile times will become more tolerable?
Next, I tried datafusion. I immediately ran into build/linking failures.
Instead of debugging those, I discounted using datafusion as it needs an async runtime (tokio), which I don't plan to use just yet (perhaps a web UI in the future will need this though).
I then tried using duckdb. This provides a nice SQL interface and is fast at runtime. However, it also increases compile times.
So I finally settled on writing my own query engine.
I started by using built-in data structures such as HashMap
and BTreeMap
.
This worked well and was fast, but I hadn't found a nice abstraction.
The implementation was also low-level.
The current solution uses the itertools crate, which provides high level iterator methods like group_by
.
This solution is both ergonomic, fast and seems to have a negligible impact on compile times 🚀.