[JS] Creating element with JS arrays returns "0" instead of "undefined" for missing elements.
- Dominant language
- TypeScript
- Stars
- 112
- Forks
- 23
- Avg merge
- 21h 18m
- Merged PRs (30d)
- 8
Description
### Describe the bug, including details regarding any error messages, version, and platform.
When creating a table using regular JavaScript Array syntax, the resulting `Vector` gives unexpected results:
```js
import { tableFromArrays } from 'https://cdn.skypack.dev/apache-arrow@15.0.2';
const table = tableFromArrays({
a: new Float64Array([100, 200, 300]),
b: [100, 200, 300],
});
console.log('Table rows:', table.numRows);
const vectorA = table.getChild('a');
const vectorB = table.getChild('b');
console.log('Length of "a":', vectorA.length);
console.log('Length of "b":', vectorB.length);
console.log('Element "a" at index 3:', vectorA.get(3));
console.log('Element "b" at index 3:', vectorB.get(3));
console.log('Element "a" at index 100:', vectorA.get(100));
console.log('Element "b" at index 100:', vectorB.get(100));
console.log('Vector "a" internal data length:', vectorA.data[0].values.length);
console.log('Vector "b" internal data length:', vectorB.data[0].values.length);
```
The output is:
```
Table rows: 3
Length of "a": 3
Length of "b": 3
Vector "a" at index 3: undefined
Vector "b" at index 3: 0
Vector "a" at index 100: undefined
Vector "b" at index 100: undefined
Vector "a" internal data length: 3
Vector "b" internal data length: 8
```
I would expect "b" to also return `undefined` for elements outside of its length. Instead it returns zero.
I noticed that the internal length of the `Float64Array` is 8 instead of 3, I suspect this has something to do with it?
Here's an online playground that shows the issue:
https://stackblitz.com/edit/vitejs-vite-9k7gaz?file=main.js
### Component(s)
JavaScript
Contributor guide
Research direction
Start with the tableFromArrays example in the issue and reproduce it from the linked StackBlitz main.js entry point. Trace how the regular JavaScript array becomes the Vector and how Vector.get handles indexes beyond its length, comparing it with the Float64Array case. Done means the array-backed vector returns undefined for the same out-of-range access while preserving the reported table and vector lengths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100