trxcllnt commented on issue #31458:
URL: https://github.com/apache/arrow/issues/31458#issuecomment-1494961959
@feefladder we have a few rudimentary column-wise `select()` and `assign()`
routines on Table (and RecordBatch and Schema). This is written by hand so
apologies if it doesn't compile, but here's how I'd implement something like
that:
```typescript
import {DataType, Vector, makeTable} from "apache-arrow"
function* filter<T extends DataType>(vec: Vector<T>, pred: (x: T['TValue'])
=> boolean) {
for (const val of vec) { yield pred(val); }
}
const src = makeTable({ name: ["Alice", "Bob"], otherColumn: [1, 2] });
const dst = src.assign(makeTable({
name: filter(src.getChild("name"), (x) => x === "bob")
}));
```
We explicitly wanted to enable using iterators like this, as there's lots of
existing JS Iterator/AsyncIterator algorithm libraries (and even a [language
proposal](https://github.com/tc39/proposal-iterator-helpers)!). So if instead
you can use an iterator library like [IxJS](https://github.com/reactiveX/ixjs):
```typescript
import {makeTable} from "apache-arrow";
import {filter} from "ix/iterable/operators/filter";
const src = makeTable({ name: ["Alice", "Bob"], otherColumn: [1, 2] });
const dst = src.assign(makeTable({
name: filter((x) => x === "bob")(src.getChild("name"))
}));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]