Reputation: 804
I'm trying to build a new empty Table based on schema only using the javascript API. I have tried different approaches unsuccessfully. I can't find in the documentation either
import {Schema, Field, Table} from '../node_modules/apache-arrow/Arrow.dom'
import {Type} from '../node_modules/apache-arrow/fb/Schema'
const field1 = Field.new('field1',Type.FloatingPoint);
const field2 = Field.new('field2',Type.Int);
const schema = new Schema([field1, field2]);
const table = Table.empty(schema)
console.log(table)
From the browser (firefox) I get the following error:
Uncaught Error: Unrecognized typeId undefined new webpack://wstat/./node_modules/apache-arrow/data.js?:152 _InternalEmptyPlaceholderRecordBatch webpack://wstat/./node_modules/apache-arrow/recordbatch.js?:94 _InternalEmptyPlaceholderRecordBatch webpack://wstat/./node_modules/apache-arrow/recordbatch.js?:94 Table webpack://wstat/./node_modules/apache-arrow/table.js?:42 empty webpack://wstat/./node_modules/apache-arrow/table.js?:48
Upvotes: 2
Views: 811
Reputation: 804
I found the solution below:
const field1 = Field.new({name:'field1',type:new Float(Precision.DOUBLE)})
const field2 = Field.new({name:'field2',type:new Int(true,64)})
const tab2 = Table.empty(new Schema([field1,field2]))
The difference is the field constructor type argument. Should be a class Type and not the enum Type.
Upvotes: 1