Problem
How to read a dataframe in polars from mysql.
Docs are silent on the issue. Currently probably there is only support for parquet, json, ipc, etc, and no direct support for sql
as mentioned here.
Regardless what would be an appropriate method to read in data using libraries like: sqlx
or mysql
Current Approach
Currently I am following this approach as provided in this answer:
- Read in a
Vec<Struct>
usingsqlx
- Convert it into a tuple of vecs
(Vec<T>, Vec<T>)
using the code below - Convert
(Vec<T>, Vec<T>)
into(Series, Series)
- Create a dataframe using:
DataFrame::new(vec![s0, s1])
; wheres0
ands1
areSeries
struct A(u8, i8);
fn main() {
let v = vec![A(1, 4), A(2, 6), A(3, 5)];
let result = v.into_iter()
.fold((vec![], vec![]), |(mut u, mut i), item| {
u.push(item.0);
i.push(item.1);
(u, i)
});
dbg!(result);
// `result` is just a tuple of vectors
// let (unsigneds, signeds): (Vec<u8>, Vec<i8>) = result;
}
See Question&Answers more detail:os