use arrow::array::{Float64Array, Int64Array, RecordBatch};
use arrow::datatypes::{DataType, Field, Schema};
use fv_compute::Runtime;
use fv_compute_container::ContainerBackend;
use std::path::Path;
use std::sync::Arc;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let transforms = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../examples/transforms");
let runtime = Runtime::builder()
.root(transforms)
.backend(ContainerBackend::new())
.build()?;
let schema = Arc::new(Schema::new(vec![
Field::new("id", DataType::Int64, true),
Field::new("score", DataType::Float64, true),
]));
let input = RecordBatch::try_new(
schema,
vec![
Arc::new(Int64Array::from(vec![1, 2, 3])),
Arc::new(Float64Array::from(vec![0.1, 0.5, 0.9])),
],
)?;
let output = runtime.run("riskBand@1.0.0", &[input])?;
print_batch(&output)?;
Ok(())
}
fn print_batch(batch: &RecordBatch) -> Result<(), Box<dyn std::error::Error>> {
use arrow::util::display::{ArrayFormatter, FormatOptions};
let options = FormatOptions::default();
let formatters: Vec<ArrayFormatter> = batch
.columns()
.iter()
.map(|c| ArrayFormatter::try_new(c.as_ref(), &options))
.collect::<Result<_, _>>()?;
let names: Vec<String> = batch.schema().fields().iter().map(|f| f.name().clone()).collect();
println!("{}", names.join("\t"));
for row in 0..batch.num_rows() {
let cells: Vec<String> = formatters.iter().map(|f| f.value(row).to_string()).collect();
println!("{}", cells.join("\t"));
}
Ok(())
}