use typed_arrow::prelude::*;
trait PrimaryKey {
type Key;
const FIELD_INDEX: usize;
const FIELD_NAME: &'static str;
}
macro_rules! per_field {
(owner = $owner:ty, index = $idx:tt, field = $fname:ident, ty = $ty:ty, nullable = $nul:expr, ext = (key $($rest:tt)*)) => {
impl PrimaryKey for $owner {
type Key = $ty;
const FIELD_INDEX: usize = $idx;
const FIELD_NAME: &'static str = stringify!($fname);
}
};
(owner = $owner:ty, index = $idx:tt, field = $fname:ident, ty = $ty:ty, nullable = $nul:expr, ext = ($($rest:tt)*)) => {};
}
macro_rules! per_record {
(owner = $owner:ty, len = $len:expr, ext = ($($rest:tt)*)) => {
impl $owner {
const __NUM_COLS: usize = $len;
}
};
}
struct DebugVisitor;
impl ColumnVisitor for DebugVisitor {
fn visit<const I: usize, R>(_m: FieldMeta<R>) {
let _ = I;
}
}
#[derive(Record)]
#[record(field_macro = "per_field", record_macro = "per_record")]
struct Person {
#[record(ext(key))]
id: i64,
name: Option<String>,
score: f32,
}
fn main() {
<Person as ForEachCol>::for_each_col::<DebugVisitor>();
let mut b = <Person as BuildRows>::new_builders(2);
b.append_row(Person {
id: 1,
name: Some("a".into()),
score: 3.5,
});
b.append_row(Person {
id: 2,
name: None,
score: 4.0,
});
let arrays = b.finish();
let _batch = arrays.into_record_batch();
println!("columns: {}", Person::__NUM_COLS);
println!(
"pk field: {}@{}",
<Person as PrimaryKey>::FIELD_NAME,
<Person as PrimaryKey>::FIELD_INDEX
);
}