swallez commented on code in PR #44247:
URL: https://github.com/apache/arrow/pull/44247#discussion_r1779657198
##########
js/src/table.ts:
##########
@@ -238,17 +238,30 @@ export class Table<T extends TypeMap = any> {
*
* @returns An Array of Table rows.
*/
- public toArray() {
+ public toArray(): Array<Struct<T>['TValue']> {
return [...this];
}
+ /**
+ * Return a JavaScript Array view of the Table rows.
+ *
+ * It is a lightweight read-only proxy that delegates to the table.
Accessing elements has some
+ * overhead compared to the regular array returned by `toArray()` because
of this indirection,
+ * but it avoids potentially large memory allocation.
+ *
+ * @returns An Array proxy to the Table rows.
+ */
+ public toArrayView(): Array<Struct<T>['TValue']> {
+ return new Proxy([] as Array<Struct<T>['TValue']>, new
TableArrayProxyHandler(this));
+ }
+
/**
* Returns a string representation of the Table rows.
*
* @returns A string representation of the Table rows.
*/
public toString() {
- return `[\n ${this.toArray().join(',\n ')}\n]`;
+ return `[\n ${this.toArrayView().join(',\n ')}\n]`;
Review Comment:
We need an array (or array-like) to use `join()`. This _was_ creating an
array, and with `toArrayView()` this now just creates a proxy. Or did I
misunderstand your comment?
--
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]