Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ is a simple example that shows how to instantiate a `ParquetSchema` object:
var schema = new parquet.ParquetSchema({
name: { type: 'UTF8' },
quantity: { type: 'INT64' },
bigint: { type: 'BIGINT' }, // To utilize BigInt instead of node-int64
price: { type: 'DOUBLE' },
date: { type: 'TIMESTAMP_MILLIS' },
in_stock: { type: 'BOOLEAN' }
Expand Down
7 changes: 4 additions & 3 deletions gen-nodejs/parquet_types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion lib/codec/plain.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ function decodeValues_INT32(cursor, count) {
function encodeValues_INT64(values) {
let buf = Buffer.alloc(8 * values.length);
for (let i = 0; i < values.length; i++) {
//console.log(typeof values[i]);
buf.writeBigInt64LE(BigInt(values[i]), i * 8);
}

return buf;
}

function encodeValues_BIGINT(values) {
let buf = Buffer.alloc(8 * values.length);
for (let i = 0; i < values.length; i++) {
buf.writeBigInt64LE(BigInt(values[i]), i * 8);
}

Expand All @@ -67,6 +75,17 @@ function decodeValues_INT64(cursor, count) {
return values;
}

function decodeValues_BIGINT(cursor, count) {
let values = [];

for (let i = 0; i < count; ++i) {
values.push(cursor.buffer.readBigInt64LE(cursor.offset));
cursor.offset += 8;
}

return values;
}

function encodeValues_INT96(values) {
let buf = Buffer.alloc(12 * values.length);

Expand Down Expand Up @@ -235,6 +254,9 @@ exports.encodeValues = function(type, values, opts) {
case 'FIXED_LEN_BYTE_ARRAY':
return encodeValues_FIXED_LEN_BYTE_ARRAY(values, opts);

case 'BIGINT':
return encodeValues_BIGINT(values);

default:
throw 'unsupported type: ' + type;

Expand Down Expand Up @@ -268,6 +290,9 @@ exports.decodeValues = function(type, cursor, count, opts) {
case 'FIXED_LEN_BYTE_ARRAY':
return decodeValues_FIXED_LEN_BYTE_ARRAY(cursor, count, opts);

case 'BIGINT':
return decodeValues_BIGINT(cursor, count);

default:
throw 'unsupported type: ' + type;

Expand Down
3 changes: 3 additions & 0 deletions lib/codec/rle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ exports.encodeValues = function(type, values, opts) {
case 'INT64':
values = values.map((x) => parseInt(x, 10));
break;
case 'BIGINT':
values = values.map((x) => BigInt(x));
break;

default:
throw 'unsupported type: ' + type;
Expand Down
8 changes: 6 additions & 2 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const parquet_compression = require('./compression')
const parquet_types = require('./types');
const BufferReader = require('./bufferReader');

const parquet_thrift_Type = Object.assign({
BIGINT: 2
}, parquet_thrift.Type);

/**
* Parquet File Magic String
*/
Expand Down Expand Up @@ -640,7 +644,7 @@ class ParquetEnvelopeReader {

let field = schema.findField(colChunk.meta_data.path_in_schema);
let type = parquet_util.getThriftEnum(
parquet_thrift.Type,
parquet_thrift_Type,
colChunk.meta_data.type);

let compression = parquet_util.getThriftEnum(
Expand Down Expand Up @@ -1058,7 +1062,7 @@ function decodeSchema(schemaElements) {
schema = schema[schemaElement.name].fields;
} else {
let logicalType = parquet_util.getThriftEnum(
parquet_thrift.Type,
parquet_thrift_Type,
schemaElement.type);

if (schemaElement.converted_type != null) {
Expand Down
15 changes: 15 additions & 0 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const PARQUET_LOGICAL_TYPES = {
primitiveType: 'INT64',
toPrimitive: toPrimitive_INT64
},
'BIGINT': {
primitiveType: 'BIGINT',
toPrimitive: toPrimitive_BIGINT,
fromPrimitive: fromPrimitive_BIGINT
},
'INT96': {
primitiveType: 'INT96',
toPrimitive: toPrimitive_INT96
Expand Down Expand Up @@ -253,6 +258,16 @@ function toPrimitive_INT64(value) {
return v;
}

function toPrimitive_BIGINT(value) {
const v = BigInt(value)

return v;
}

function fromPrimitive_BIGINT(value) {
return value.toString();
}

function toPrimitive_UINT64(value) {
const v = parseInt(value, 10);
if (v < 0 || isNaN(v)) {
Expand Down
16 changes: 9 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ exports.getBitWidth = function (val) {
}
}

/**
* FIXME not ideal that this is linear
*/
const reverseEnums = new Map();
exports.getThriftEnum = function (klass, value) {
for (let k in klass) {
if (klass[k] === value) {
return k;
let reverse = reverseEnums.get(klass)
if (!reverse) {
reverse = {};
for (let k in klass) {
reverse[klass[k]] = k;
}
reverseEnums.set(klass, reverse);
}

const ret = reverse[value]
if (ret) return ret;
throw 'Invalid ENUM value';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class ParquetTransformer extends stream.Transform {
}

_flush(callback) {
this.writer.close(callback)
this.writer.close()
.then(d => callback(null, d), callback);
}

Expand Down
Loading