Skip to content

Commit

Permalink
apacheGH-37983: [JS] create nullable Fields in Table constructor (apa…
Browse files Browse the repository at this point in the history
…che#37982)

Previously, Tables constructed from vectors with null values would infer
Schemas that did not permit null values. This resulted in downstream
code making bad assumptions about the data. After this change, we always
assume data can be nullable, and construct a Schema with nullable
Fields.

### Are these changes tested?

I informally tested these changes for my use case, but have not tested
them more extensively

### Are there any user-facing changes?

Yes: the `Table` constructor will now produce schemas with nullable
`Fields` in situations in which it previously did not
* Closes: apache#37983
  • Loading branch information
zenazn authored Dec 16, 2023
1 parent 49fde23 commit a91a11d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Table<T extends TypeMap = any> {
} else if (typeof x === 'object') {
const keys = Object.keys(x) as (keyof T)[];
const vecs = keys.map((k) => new Vector([x[k]]));
const schema = new Schema(keys.map((k, i) => new Field(String(k), vecs[i].type)));
const schema = new Schema(keys.map((k, i) => new Field(String(k), vecs[i].type, true)));
const [, batches] = distributeVectorsIntoRecordBatches(schema, vecs);
return batches.length === 0 ? [new RecordBatch(x)] : batches;
}
Expand Down

0 comments on commit a91a11d

Please sign in to comment.