Skip to content

Commit 50e1827

Browse files
committed
Add comment
Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>
1 parent ab5f6d0 commit 50e1827

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/utils/src/arrow-data-container.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ type ArrowDataContainerInput = {
1717
};
1818

1919
/**
20-
* Checks if the provided object is an Arrow Table.
21-
* @param data - The object to check.
22-
* @returns {boolean} - Returns true if the object is an Arrow Table; acts as a type guard for arrow.Table.
20+
* Check if table is an ArrowTable object.
21+
*
22+
* We use duck-typing instead of `instanceof arrow.Table` because DuckDB loads its own
23+
* bundled version of Apache Arrow. When DuckDB creates Arrow tables, they are instances
24+
* of DuckDB's Arrow.Table class, not the Arrow.Table class from our application's
25+
* apache-arrow package. This causes `instanceof` checks to fail even though the objects
26+
* are functionally equivalent Arrow tables.
27+
*
28+
* @param data - object to check
29+
* @returns true if data is an ArrowTable object (type guarded)
2330
*/
2431
export function isArrowTable(data: any): data is arrow.Table {
2532
return (
@@ -115,14 +122,10 @@ export class ArrowDataContainer implements DataContainerInterface {
115122
} else {
116123
this._cols = updateData;
117124
}
118-
this._numColumns = this._cols.length;
119-
this._numRows = this._cols[0].length;
120-
this._numChunks = this._cols[0].data.length;
121-
if (isArrow) {
122-
this._arrowTable = updateData;
123-
} else {
124-
this._arrowTable = this._createTable();
125-
}
125+
this._numColumns = this._cols?.length ?? 0;
126+
this._numRows = this._cols?.[0]?.length ?? 0;
127+
this._numChunks = this._cols?.[0]?.data?.length ?? 0;
128+
this._arrowTable = isArrow ? updateData : this._createTable();
126129

127130
// cache column data to make valueAt() faster
128131
// this._colData = this._cols.map(c => c.toArray());

0 commit comments

Comments
 (0)