Skip to content

Commit d629020

Browse files
committed
get columns from record batch
1 parent 7a38709 commit d629020

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

examples/flights.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ console.log(table.schema);
1313
const batch = table.recordBatch(0);
1414

1515
console.log(batch.numRows);
16+
console.log(batch.columns[3]);
1617
console.log(batch.numColumns);
1718
console.log(batch.schema.toJSON());
1819
console.log(batch.schema.fields);

examples/schema.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const arrow_wasm = require("../pkg/arrow_wasm");
2+
3+
const schema = arrow_wasm.Schema.from({
4+
fields: [
5+
{
6+
name: "number",
7+
nullable: false,
8+
type: {
9+
name: "int",
10+
isSigned: true,
11+
bitWidth: 32,
12+
},
13+
},
14+
],
15+
});
16+
17+
console.log(schema.toJSON());

src/record_batch.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{schema, vector};
2+
use js_sys::Array;
23
use wasm_bindgen::prelude::*;
34

45
#[wasm_bindgen]
@@ -27,6 +28,20 @@ impl RecordBatch {
2728
vector::Vector::new(self.0.column(index).clone())
2829
}
2930

31+
/// Get all columns in the record batch.
32+
// TODO: specify that the output type is Array<Vector>, not Array<any>
33+
#[wasm_bindgen(getter)]
34+
pub fn columns(&self) -> Array {
35+
let vectors: Vec<vector::Vector> = self
36+
.0
37+
.columns()
38+
.into_iter()
39+
.map(|column| vector::Vector::new(column.clone()))
40+
.collect();
41+
42+
vectors.into_iter().map(JsValue::from).collect()
43+
}
44+
3045
/// Get a column's vector by name.
3146
#[wasm_bindgen(js_name = columnWithName)]
3247
pub fn column_with_name(&self, name: &str) -> Result<crate::vector::Vector, JsValue> {

0 commit comments

Comments
 (0)