ironSource / parquetjs

fully asynchronous, pure JavaScript implementation of the Parquet file format
MIT License
350 stars 174 forks source link

size RangeError with RLE encoding on INT32 field #100

Open nicwaller opened 4 years ago

nicwaller commented 4 years ago

I'm trying to use RLE encoding with this library, but I always get this error regardless of how I tweak the configuration parameters.

The value "NaN" is invalid for option "size" at Function.alloc (buffer.js:371:3)

(node:74887) UnhandledPromiseRejectionWarning: RangeError [ERR_INVALID_OPT_VALUE]: The value "NaN" is invalid for option "size"
    at Function.alloc (buffer.js:371:3)
    at encodeRunBitpacked (/myproject/node_modules/parquetjs/lib/codec/rle.js:8:20)
    at Object.exports.encodeValues (/myproject/node_modules/parquetjs/lib/codec/rle.js:81:31)
    at encodeValues (/myproject/node_modules/parquetjs/lib/writer.js:287:34)
    at encodeDataPageV2 (/myproject/node_modules/parquetjs/lib/writer.js:346:19)
    at encodeColumnChunk (/myproject/node_modules/parquetjs/lib/writer.js:420:18)
    at encodeRowGroup (/myproject/node_modules/parquetjs/lib/writer.js:483:22)
    at ParquetEnvelopeWriter.writeRowGroup (/myproject/node_modules/parquetjs/lib/writer.js:201:18)
    at ParquetWriter.close (/myproject/node_modules/parquetjs/lib/writer.js:116:33)
    at test (/myproject/src/parquetify.js:112:18)

Here is my simple test case. Am I doing something wrong, or is this a real bug?

var person_schema = new parquet.ParquetSchema({
    name: { type: 'UTF8' },
    age: { type: 'INT32', encoding: 'RLE', bitWidth: 7 },
});
var writer = await parquet.ParquetWriter.openFile(person_schema, 'person.parquet');
await writer.appendRow({
    name: 'John Smith',
    age: 0,
});
await writer.close();

I'm using parquetjs 0.11.2 from https://registry.npmjs.org/parquetjs/-/parquetjs-0.11.2.tgz

samsullivan commented 4 years ago

The docs are wrong; you want to use typeLength instead of bitWidth.

See: https://github.com/ironSource/parquetjs/blob/455ff9ffce89ac055fd667cf8d0555aec93f7c9f/lib/writer.js#L310-L316

MollsReis commented 3 years ago

Blast from the past, thanks for this @samsullivan I was having the same issue