pub trait SchemaMeta: Record {
// Required method
fn fields() -> Vec<Field>;
// Provided methods
fn metadata() -> HashMap<String, String> { ... }
fn schema() -> Arc<Schema> { ... }
}
Expand description
Arrow runtime schema metadata for a top-level Record.
Required Methods§
Provided Methods§
Sourcefn schema() -> Arc<Schema>
fn schema() -> Arc<Schema>
Construct an Arc<arrow_schema::Schema>
from fields()
.
Examples found in repository?
examples/08_record_batch.rs (line 45)
19fn main() {
20 let rows = vec![
21 PersonRB {
22 id: 1,
23 address: Some(AddressRB {
24 city: "NYC".into(),
25 zip: None,
26 }),
27 email: Some("a@example.com".into()),
28 },
29 PersonRB {
30 id: 2,
31 address: None,
32 email: None,
33 },
34 PersonRB {
35 id: 3,
36 address: Some(AddressRB {
37 city: "SF".into(),
38 zip: Some(94111),
39 }),
40 email: Some("c@example.com".into()),
41 },
42 ];
43
44 // Schema from type
45 let schema = <PersonRB as SchemaMeta>::schema();
46 println!("fields={}", schema.fields().len());
47
48 // Build arrays from rows and into RecordBatch
49 let mut b = <PersonRB as BuildRows>::new_builders(rows.len());
50 b.append_rows(rows);
51 let arrays = b.finish();
52 let batch: RecordBatch = arrays.into_record_batch();
53 println!(
54 "batch_rows={}, field0={}, field1={}, field2={}",
55 batch.num_rows(),
56 batch.schema().field(0).name(),
57 batch.schema().field(1).name(),
58 batch.schema().field(2).name()
59 );
60
61 // A quick peek at nested values
62 let city = as_string_array(arrow_array::cast::as_struct_array(batch.column(1)).column(0));
63 println!("first_city={}, third_city={}", city.value(0), city.value(2));
64}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.