@dsnp/parquetjs
Advanced tools
Comparing version 0.0.0-44d9f3 to 0.0.0-6fb5fc
@@ -19,3 +19,3 @@ "use strict"; | ||
class XxHasher { | ||
static h64 = xxhash_wasm_1.default().then(x => x.h64); | ||
static h64 = (0, xxhash_wasm_1.default)().then(x => x.h64); | ||
async hashit(value) { | ||
@@ -22,0 +22,0 @@ return (await XxHasher.h64)(value); |
@@ -41,3 +41,6 @@ "use strict"; | ||
catch (e) { | ||
throw new Error(e); | ||
if (typeof e === 'string') | ||
throw new Error(e); | ||
else | ||
throw e; | ||
} | ||
@@ -60,3 +63,6 @@ const bloomFilterHeader = new parquet_types_1.default.BloomFilterHeader(); | ||
catch (e) { | ||
throw new Error(e); | ||
if (typeof e === 'string') | ||
throw new Error(e); | ||
else | ||
throw e; | ||
} | ||
@@ -68,3 +74,3 @@ }; | ||
const siftAllByteOffsets = (columnChunkDataCollection) => { | ||
return exports.parseBloomFilterOffsets(filterColumnChunksWithBloomFilters(columnChunkDataCollection)); | ||
return (0, exports.parseBloomFilterOffsets)(filterColumnChunksWithBloomFilters(columnChunkDataCollection)); | ||
}; | ||
@@ -74,3 +80,3 @@ exports.siftAllByteOffsets = siftAllByteOffsets; | ||
const columnChunkDataCollection = envelopeReader.getAllColumnChunkDataFor(columnNames); | ||
const bloomFilterOffsetData = exports.siftAllByteOffsets(columnChunkDataCollection); | ||
const bloomFilterOffsetData = (0, exports.siftAllByteOffsets)(columnChunkDataCollection); | ||
const offsetByteValues = bloomFilterOffsetData.map(({ offsetBytes }) => offsetBytes); | ||
@@ -77,0 +83,0 @@ const filterBlocksBuffers = await readFilterDataFrom(offsetByteValues, envelopeReader); |
@@ -41,3 +41,3 @@ "use strict"; | ||
const serializedFilterBlocks = serializeFilterBlocks(params.filterBlocks); | ||
const serializedFilterHeaders = exports.serializeFilterHeaders(params.filterByteSize); | ||
const serializedFilterHeaders = (0, exports.serializeFilterHeaders)(params.filterByteSize); | ||
return Buffer.concat([serializedFilterHeaders, serializedFilterBlocks]); | ||
@@ -53,5 +53,5 @@ }; | ||
const filterByteSize = splitBlockBloomFilter.getNumFilterBytes(); | ||
return exports.serializeFilterData({ filterBlocks, filterByteSize }); | ||
return (0, exports.serializeFilterData)({ filterBlocks, filterByteSize }); | ||
}; | ||
exports.getSerializedBloomFilterData = getSerializedBloomFilterData; | ||
//# sourceMappingURL=bloomFilterWriter.js.map |
"use strict"; | ||
module.exports = class BufferReader { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class BufferReader { | ||
maxSpan; | ||
maxLength; | ||
queueWait; | ||
scheduled; | ||
queue; | ||
envelopeReader; | ||
constructor(envelopeReader, options) { | ||
@@ -58,5 +65,7 @@ options = options || {}; | ||
}); | ||
readSubqueue(subqueue); | ||
readSubqueue(); | ||
} | ||
}; | ||
} | ||
exports.default = BufferReader; | ||
; | ||
//# sourceMappingURL=bufferReader.js.map |
"use strict"; | ||
module.exports.PLAIN = require('./plain'); | ||
module.exports.RLE = require('./rle'); | ||
module.exports.PLAIN_DICTIONARY = require('./plain_dictionary'); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PLAIN_DICTIONARY = exports.RLE = exports.PLAIN = void 0; | ||
exports.PLAIN = __importStar(require("./plain")); | ||
exports.RLE = __importStar(require("./rle")); | ||
exports.PLAIN_DICTIONARY = __importStar(require("./plain_dictionary")); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
const rle = require('./rle'); | ||
exports.decodeValues = function (type, cursor, count, opts) { | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeValues = void 0; | ||
const rle = __importStar(require("./rle")); | ||
const decodeValues = function (type, cursor, count, opts) { | ||
opts.bitWidth = cursor.buffer.slice(cursor.offset, cursor.offset + 1).readInt8(0); | ||
@@ -8,2 +29,3 @@ cursor.offset += 1; | ||
}; | ||
exports.decodeValues = decodeValues; | ||
//# sourceMappingURL=plain_dictionary.js.map |
@@ -1,3 +0,8 @@ | ||
'use strict'; | ||
const INT53 = require('int53'); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeValues = exports.encodeValues = void 0; | ||
const int53_1 = __importDefault(require("int53")); | ||
function encodeValues_BOOLEAN(values) { | ||
@@ -8,3 +13,3 @@ let buf = Buffer.alloc(Math.ceil(values.length / 8)); | ||
if (values[i]) { | ||
buf[Math.floor(i / 8)] |= (1 << (i % 8)); | ||
buf[Math.floor(i / 8)] |= 1 << i % 8; | ||
} | ||
@@ -18,3 +23,3 @@ } | ||
let b = cursor.buffer[cursor.offset + Math.floor(i / 8)]; | ||
values.push((b & (1 << (i % 8))) > 0); | ||
values.push((b & (1 << i % 8)) > 0); | ||
} | ||
@@ -58,7 +63,7 @@ cursor.offset += Math.ceil(count / 8); | ||
if (values[i] >= 0) { | ||
INT53.writeInt64LE(values[i], buf, i * 12); | ||
int53_1.default.writeInt64LE(values[i], buf, i * 12); | ||
buf.writeUInt32LE(0, i * 12 + 8); // truncate to 64 actual precision | ||
} | ||
else { | ||
INT53.writeInt64LE((~-values[i]) + 1, buf, i * 12); | ||
int53_1.default.writeInt64LE(~-values[i] + 1, buf, i * 12); | ||
buf.writeUInt32LE(0xffffffff, i * 12 + 8); // truncate to 64 actual precision | ||
@@ -72,6 +77,6 @@ } | ||
for (let i = 0; i < count; ++i) { | ||
const low = INT53.readInt64LE(cursor.buffer, cursor.offset); | ||
const low = int53_1.default.readInt64LE(cursor.buffer, cursor.offset); | ||
const high = cursor.buffer.readUInt32LE(cursor.offset + 8); | ||
if (high === 0xffffffff) { | ||
values.push((~-low) + 1); // truncate to 64 actual precision | ||
values.push(~-low + 1); // truncate to 64 actual precision | ||
} | ||
@@ -115,14 +120,16 @@ else { | ||
} | ||
// Waylands reminder to check again | ||
function encodeValues_BYTE_ARRAY(values) { | ||
let buf_len = 0; | ||
const returnedValues = []; | ||
for (let i = 0; i < values.length; i++) { | ||
values[i] = Buffer.from(values[i]); | ||
buf_len += 4 + values[i].length; | ||
returnedValues[i] = Buffer.from(values[i]); | ||
buf_len += 4 + returnedValues[i].length; | ||
} | ||
let buf = Buffer.alloc(buf_len); | ||
let buf_pos = 0; | ||
for (let i = 0; i < values.length; i++) { | ||
buf.writeUInt32LE(values[i].length, buf_pos); | ||
values[i].copy(buf, buf_pos + 4); | ||
buf_pos += 4 + values[i].length; | ||
for (let i = 0; i < returnedValues.length; i++) { | ||
buf.writeUInt32LE(returnedValues[i].length, buf_pos); | ||
returnedValues[i].copy(buf, buf_pos + 4); | ||
buf_pos += 4 + returnedValues[i].length; | ||
} | ||
@@ -145,10 +152,10 @@ return buf; | ||
} | ||
let buf_len = 0; | ||
const returnedValues = []; | ||
for (let i = 0; i < values.length; i++) { | ||
values[i] = Buffer.from(values[i]); | ||
if (values[i].length !== opts.typeLength) { | ||
throw "invalid value for FIXED_LEN_BYTE_ARRAY: " + values[i]; | ||
returnedValues[i] = Buffer.from(values[i]); | ||
if (returnedValues[i].length !== opts.typeLength) { | ||
throw "invalid value for FIXED_LEN_BYTE_ARRAY: " + returnedValues[i]; | ||
} | ||
} | ||
return Buffer.concat(values); | ||
return Buffer.concat(returnedValues); | ||
} | ||
@@ -166,46 +173,48 @@ function decodeValues_FIXED_LEN_BYTE_ARRAY(cursor, count, opts) { | ||
} | ||
exports.encodeValues = function (type, values, opts) { | ||
const encodeValues = function (type, values, opts) { | ||
switch (type) { | ||
case 'BOOLEAN': | ||
case "BOOLEAN": | ||
return encodeValues_BOOLEAN(values); | ||
case 'INT32': | ||
case "INT32": | ||
return encodeValues_INT32(values); | ||
case 'INT64': | ||
case "INT64": | ||
return encodeValues_INT64(values); | ||
case 'INT96': | ||
case "INT96": | ||
return encodeValues_INT96(values); | ||
case 'FLOAT': | ||
case "FLOAT": | ||
return encodeValues_FLOAT(values); | ||
case 'DOUBLE': | ||
case "DOUBLE": | ||
return encodeValues_DOUBLE(values); | ||
case 'BYTE_ARRAY': | ||
case "BYTE_ARRAY": | ||
return encodeValues_BYTE_ARRAY(values); | ||
case 'FIXED_LEN_BYTE_ARRAY': | ||
case "FIXED_LEN_BYTE_ARRAY": | ||
return encodeValues_FIXED_LEN_BYTE_ARRAY(values, opts); | ||
default: | ||
throw 'unsupported type: ' + type; | ||
throw "unsupported type: " + type; | ||
} | ||
}; | ||
exports.decodeValues = function (type, cursor, count, opts) { | ||
exports.encodeValues = encodeValues; | ||
const decodeValues = function (type, cursor, count, opts) { | ||
switch (type) { | ||
case 'BOOLEAN': | ||
case "BOOLEAN": | ||
return decodeValues_BOOLEAN(cursor, count); | ||
case 'INT32': | ||
case "INT32": | ||
return decodeValues_INT32(cursor, count); | ||
case 'INT64': | ||
case "INT64": | ||
return decodeValues_INT64(cursor, count); | ||
case 'INT96': | ||
case "INT96": | ||
return decodeValues_INT96(cursor, count); | ||
case 'FLOAT': | ||
case "FLOAT": | ||
return decodeValues_FLOAT(cursor, count); | ||
case 'DOUBLE': | ||
case "DOUBLE": | ||
return decodeValues_DOUBLE(cursor, count); | ||
case 'BYTE_ARRAY': | ||
case "BYTE_ARRAY": | ||
return decodeValues_BYTE_ARRAY(cursor, count); | ||
case 'FIXED_LEN_BYTE_ARRAY': | ||
case "FIXED_LEN_BYTE_ARRAY": | ||
return decodeValues_FIXED_LEN_BYTE_ARRAY(cursor, count, opts); | ||
default: | ||
throw 'unsupported type: ' + type; | ||
throw "unsupported type: " + type; | ||
} | ||
}; | ||
exports.decodeValues = decodeValues; | ||
//# sourceMappingURL=plain.js.map |
"use strict"; | ||
const varint = require('varint'); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeValues = exports.encodeValues = void 0; | ||
const varint_1 = __importDefault(require("varint")); | ||
function encodeRunBitpacked(values, opts) { | ||
@@ -14,3 +19,3 @@ for (let i = 0; i < values.length % 8; i++) { | ||
return Buffer.concat([ | ||
Buffer.from(varint.encode(((values.length / 8) << 1) | 1)), | ||
Buffer.from(varint_1.default.encode(((values.length / 8) << 1) | 1)), | ||
buf | ||
@@ -26,7 +31,15 @@ ]); | ||
return Buffer.concat([ | ||
Buffer.from(varint.encode(count << 1)), | ||
Buffer.from(varint_1.default.encode(count << 1)), | ||
buf | ||
]); | ||
} | ||
exports.encodeValues = function (type, values, opts) { | ||
function unknownToParsedInt(value) { | ||
if (typeof value === 'string') { | ||
return parseInt(value, 10); | ||
} | ||
else { | ||
return value; | ||
} | ||
} | ||
const encodeValues = function (type, values, opts) { | ||
if (!('bitWidth' in opts)) { | ||
@@ -39,3 +52,3 @@ throw 'bitWidth is required'; | ||
case 'INT64': | ||
values = values.map((x) => parseInt(x, 10)); | ||
values = values.map((x) => unknownToParsedInt(x)); | ||
break; | ||
@@ -85,2 +98,3 @@ default: | ||
}; | ||
exports.encodeValues = encodeValues; | ||
function decodeRunBitpacked(cursor, count, opts) { | ||
@@ -108,3 +122,3 @@ if (count % 8 !== 0) { | ||
} | ||
exports.decodeValues = function (type, cursor, count, opts) { | ||
const decodeValues = function (_, cursor, count, opts) { | ||
if (!('bitWidth' in opts)) { | ||
@@ -119,4 +133,4 @@ throw 'bitWidth is required'; | ||
while (values.length < count) { | ||
const header = varint.decode(cursor.buffer, cursor.offset); | ||
cursor.offset += varint.encodingLength(header); | ||
const header = varint_1.default.decode(cursor.buffer, cursor.offset); | ||
cursor.offset += varint_1.default.encodingLength(header); | ||
if (header & 1) { | ||
@@ -138,2 +152,3 @@ res = decodeRunBitpacked(cursor, (header >> 1) * 8, opts); | ||
}; | ||
exports.decodeValues = decodeValues; | ||
//# sourceMappingURL=rle.js.map |
@@ -1,8 +0,12 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const zlib = require('zlib'); | ||
const snappy = require('snappyjs'); | ||
exports.inflate = exports.deflate = exports.PARQUET_COMPRESSION_METHODS = void 0; | ||
const zlib_1 = __importDefault(require("zlib")); | ||
const snappyjs_1 = __importDefault(require("snappyjs")); | ||
const wasm_brotli_1 = require("wasm-brotli"); | ||
// LZO compression is disabled. See: https://github.com/LibertyDSNP/parquetjs/issues/18 | ||
const PARQUET_COMPRESSION_METHODS = { | ||
exports.PARQUET_COMPRESSION_METHODS = { | ||
'UNCOMPRESSED': { | ||
@@ -29,7 +33,8 @@ deflate: deflate_identity, | ||
async function deflate(method, value) { | ||
if (!(method in PARQUET_COMPRESSION_METHODS)) { | ||
if (!(method in exports.PARQUET_COMPRESSION_METHODS)) { | ||
throw 'invalid compression method: ' + method; | ||
} | ||
return PARQUET_COMPRESSION_METHODS[method].deflate(value); | ||
return exports.PARQUET_COMPRESSION_METHODS[method].deflate(value); | ||
} | ||
exports.deflate = deflate; | ||
function deflate_identity(value) { | ||
@@ -39,13 +44,14 @@ return value; | ||
function deflate_gzip(value) { | ||
return zlib.gzipSync(value); | ||
return zlib_1.default.gzipSync(value); | ||
} | ||
function deflate_snappy(value) { | ||
return snappy.compress(value); | ||
return snappyjs_1.default.compress(value); | ||
} | ||
async function deflate_brotli(value) { | ||
const compressedContent = await wasm_brotli_1.compress(value, { | ||
mode: 0, | ||
quality: 8, | ||
lgwin: 22 | ||
}); | ||
const compressedContent = await (0, wasm_brotli_1.compress)(value /*, { | ||
mode: 0, | ||
quality: 8, | ||
lgwin: 22 | ||
} | ||
*/); | ||
return Buffer.from(compressedContent); | ||
@@ -57,7 +63,8 @@ } | ||
async function inflate(method, value) { | ||
if (!(method in PARQUET_COMPRESSION_METHODS)) { | ||
if (!(method in exports.PARQUET_COMPRESSION_METHODS)) { | ||
throw 'invalid compression method: ' + method; | ||
} | ||
return await PARQUET_COMPRESSION_METHODS[method].inflate(value); | ||
return await exports.PARQUET_COMPRESSION_METHODS[method].inflate(value); | ||
} | ||
exports.inflate = inflate; | ||
function inflate_identity(value) { | ||
@@ -67,12 +74,11 @@ return value; | ||
function inflate_gzip(value) { | ||
return zlib.gunzipSync(value); | ||
return zlib_1.default.gunzipSync(value); | ||
} | ||
function inflate_snappy(value) { | ||
return snappy.uncompress(value); | ||
return snappyjs_1.default.uncompress(value); | ||
} | ||
async function inflate_brotli(value) { | ||
const uncompressedContent = await wasm_brotli_1.decompress(value); | ||
const uncompressedContent = await (0, wasm_brotli_1.decompress)(value); | ||
return Buffer.from(uncompressedContent); | ||
} | ||
module.exports = { PARQUET_COMPRESSION_METHODS, deflate, inflate }; | ||
//# sourceMappingURL=compression.js.map |
@@ -1,6 +0,26 @@ | ||
'use strict'; | ||
const parquet_codec = require('./codec'); | ||
const parquet_compression = require('./compression'); | ||
const parquet_types = require('./types'); | ||
const parquet_util = require('./util'); | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParquetSchema = void 0; | ||
const parquet_codec = __importStar(require("./codec")); | ||
const parquet_compression = __importStar(require("./compression")); | ||
const parquet_types = __importStar(require("./types")); | ||
const PARQUET_COLUMN_KEY_SEPARATOR = '.'; | ||
@@ -11,2 +31,5 @@ /** | ||
class ParquetSchema { | ||
schema; | ||
fields; | ||
fieldList; | ||
/** | ||
@@ -24,3 +47,3 @@ * Create a new schema from a JSON schema definition | ||
findField(path) { | ||
if (path.constructor !== Array) { | ||
if (typeof path === 'string') { | ||
path = path.split(","); | ||
@@ -33,3 +56,6 @@ } | ||
for (; path.length > 1; path.shift()) { | ||
n = n[path[0]].fields; | ||
let fields = n[path[0]]?.fields; | ||
if (isDefined(fields)) { | ||
n = fields; | ||
} | ||
} | ||
@@ -42,3 +68,3 @@ return n[path[0]]; | ||
findFieldBranch(path) { | ||
if (path.constructor !== Array) { | ||
if (typeof path === 'string') { | ||
path = path.split(","); | ||
@@ -50,4 +76,5 @@ } | ||
branch.push(n[path[0]]); | ||
if (path.length > 1) { | ||
n = n[path[0]].fields; | ||
let fields = n[path[0]].fields; | ||
if (path.length > 1 && isDefined(fields)) { | ||
n = fields; | ||
} | ||
@@ -58,2 +85,3 @@ } | ||
} | ||
exports.ParquetSchema = ParquetSchema; | ||
; | ||
@@ -94,3 +122,3 @@ function buildFields(schema, rLevelParentMax, dLevelParentMax, path) { | ||
name: name, | ||
path: path.concat([name]), | ||
path: path.concat(name), | ||
repetitionType: repetitionType, | ||
@@ -102,3 +130,3 @@ rLevelMax: rLevelMax, | ||
fieldCount: Object.keys(opts.fields).length, | ||
fields: buildFields(opts.fields, rLevelMax, dLevelMax, path.concat([name])) | ||
fields: buildFields(opts.fields, rLevelMax, dLevelMax, path.concat(name)) | ||
}; | ||
@@ -109,6 +137,5 @@ if (opts.type == 'LIST' || opts.type == 'MAP') | ||
} | ||
/* field type */ | ||
const typeDef = parquet_types.PARQUET_LOGICAL_TYPES[opts.type]; | ||
const typeDef = opts.type ? parquet_types.PARQUET_LOGICAL_TYPES[opts.type] : undefined; | ||
if (!typeDef) { | ||
throw 'invalid parquet type: ' + opts.type; | ||
throw 'invalid parquet type: ' + (opts.type || "missing type"); | ||
} | ||
@@ -120,3 +147,3 @@ /* field encoding */ | ||
if (!(opts.encoding in parquet_codec)) { | ||
throw 'unsupported parquet encoding: ' + opts.encodig; | ||
throw 'unsupported parquet encoding: ' + opts.encoding; | ||
} | ||
@@ -150,4 +177,5 @@ if (!opts.compression) { | ||
list.push(fields[k]); | ||
if (fields[k].isNested) { | ||
list = list.concat(listFields(fields[k].fields)); | ||
const nestedFields = fields[k].fields; | ||
if (fields[k].isNested && isDefined(nestedFields)) { | ||
list = list.concat(listFields(nestedFields)); | ||
} | ||
@@ -157,3 +185,5 @@ } | ||
} | ||
module.exports = { ParquetSchema }; | ||
function isDefined(val) { | ||
return val !== undefined; | ||
} | ||
//# sourceMappingURL=schema.js.map |
'use strict'; | ||
const BSON = require('bson'); | ||
const PARQUET_LOGICAL_TYPES = { | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromPrimitive = exports.toPrimitive = exports.PARQUET_LOGICAL_TYPES = void 0; | ||
const BSON = __importStar(require("bson")); | ||
exports.PARQUET_LOGICAL_TYPES = { | ||
'BOOLEAN': { | ||
@@ -142,7 +163,8 @@ primitiveType: 'BOOLEAN', | ||
function toPrimitive(type, value) { | ||
if (!(type in PARQUET_LOGICAL_TYPES)) { | ||
if (!(type in exports.PARQUET_LOGICAL_TYPES)) { | ||
throw 'invalid type: ' + type; | ||
} | ||
return PARQUET_LOGICAL_TYPES[type].toPrimitive(value); | ||
return exports.PARQUET_LOGICAL_TYPES[type].toPrimitive(value); | ||
} | ||
exports.toPrimitive = toPrimitive; | ||
/** | ||
@@ -153,7 +175,8 @@ * Convert a value from it's internal/underlying primitive representation to | ||
function fromPrimitive(type, value) { | ||
if (!(type in PARQUET_LOGICAL_TYPES)) { | ||
if (!(type in exports.PARQUET_LOGICAL_TYPES)) { | ||
throw 'invalid type: ' + type; | ||
} | ||
if ("fromPrimitive" in PARQUET_LOGICAL_TYPES[type]) { | ||
return PARQUET_LOGICAL_TYPES[type].fromPrimitive(value); | ||
const typeFromPrimitive = exports.PARQUET_LOGICAL_TYPES[type].fromPrimitive; | ||
if (typeFromPrimitive !== undefined) { | ||
return typeFromPrimitive(value); | ||
} | ||
@@ -164,2 +187,3 @@ else { | ||
} | ||
exports.fromPrimitive = fromPrimitive; | ||
function toPrimitive_BOOLEAN(value) { | ||
@@ -172,23 +196,27 @@ return !!value; | ||
function toPrimitive_FLOAT(value) { | ||
const v = parseFloat(value); | ||
if (isNaN(v)) { | ||
throw 'invalid value for FLOAT: ' + value; | ||
if (typeof value === 'string') { | ||
const v = parseFloat(value); | ||
return v; | ||
} | ||
return v; | ||
else if (typeof value === 'number') { | ||
return value; | ||
} | ||
throw 'invalid value for FLOAT: ' + value; | ||
} | ||
function toPrimitive_DOUBLE(value) { | ||
const v = parseFloat(value); | ||
if (isNaN(v)) { | ||
throw 'invalid value for DOUBLE: ' + value; | ||
if (typeof value === 'string') { | ||
const v = parseFloat(value); | ||
return v; | ||
} | ||
return v; | ||
else if (typeof value === 'number') { | ||
return value; | ||
} | ||
throw 'invalid value for DOUBLE: ' + value; | ||
} | ||
function toPrimitive_INT8(value) { | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(-0x80, 0x7f, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(-0x80, 0x7f, v); | ||
return v; | ||
@@ -202,8 +230,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(0, 0xff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(0, 0xff, v); | ||
return v; | ||
@@ -217,8 +243,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(-0x8000, 0x7fff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(-0x8000, 0x7fff, v); | ||
return v; | ||
@@ -232,8 +256,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(0, 0xffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(0, 0xffff, v); | ||
return v; | ||
@@ -247,8 +269,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(-0x80000000, 0x7fffffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(-0x80000000, 0x7fffffff, v); | ||
return v; | ||
@@ -262,8 +282,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(0, 0xffffffffffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(0, 0xffffffffffff, v); | ||
return v; | ||
@@ -277,8 +295,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(-0x8000000000000000, 0x7fffffffffffffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(-0x8000000000000000, 0x7fffffffffffffff, v); | ||
return v; | ||
@@ -292,8 +308,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(0, 0xffffffffffffffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(0, 0xffffffffffffffff, v); | ||
return v; | ||
@@ -307,8 +321,6 @@ } | ||
try { | ||
const v = parseInt(value, 10); | ||
const bigV = BigInt(value); | ||
checkValidValue(-0x800000000000000000000000, 0x7fffffffffffffffffffffff, v, bigV); | ||
if (typeof value === 'bigint' || typeof value === 'string') { | ||
return bigV; | ||
} | ||
let v = value; | ||
if (typeof v === 'string') | ||
v = BigInt(value); | ||
checkValidValue(-0x800000000000000000000000, 0x7fffffffffffffffffffffff, v); | ||
return v; | ||
@@ -342,4 +354,7 @@ } | ||
function toPrimitive_TIME_MILLIS(value) { | ||
const v = parseInt(value, 10); | ||
if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) { | ||
let v = value; | ||
if (typeof value === `string`) { | ||
v = parseInt(value, 10); | ||
} | ||
if (v < 0 || v > 0xffffffffffffffff || typeof v !== 'number') { | ||
throw 'invalid value for TIME_MILLIS: ' + value; | ||
@@ -351,3 +366,3 @@ } | ||
const v = BigInt(value); | ||
if (v < 0n || isNaN(v)) { | ||
if (v < 0n) { | ||
throw 'invalid value for TIME_MICROS: ' + value; | ||
@@ -364,9 +379,10 @@ } | ||
/* convert from integer */ | ||
{ | ||
const v = parseInt(value, 10); | ||
if (v < 0 || isNaN(v)) { | ||
throw 'invalid value for DATE: ' + value; | ||
} | ||
return v; | ||
let v = value; | ||
if (typeof value === 'string') { | ||
v = parseInt(value, 10); | ||
} | ||
if (v < 0 || typeof v !== 'number') { | ||
throw 'invalid value for DATE: ' + value; | ||
} | ||
return v; | ||
} | ||
@@ -382,9 +398,10 @@ function fromPrimitive_DATE(value) { | ||
/* convert from integer */ | ||
{ | ||
const v = parseInt(value, 10); | ||
if (v < 0 || isNaN(v)) { | ||
throw 'invalid value for TIMESTAMP_MILLIS: ' + value; | ||
} | ||
return v; | ||
let v = value; | ||
if (typeof value === 'string') { | ||
v = parseInt(value, 10); | ||
} | ||
if (v < 0 || typeof v !== 'number') { | ||
throw 'invalid value for TIMESTAMP_MILLIS: ' + value; | ||
} | ||
return v; | ||
} | ||
@@ -409,3 +426,3 @@ function fromPrimitive_TIMESTAMP_MILLIS(value) { | ||
function fromPrimitive_TIMESTAMP_MICROS(value) { | ||
return new Date(parseInt(value / 1000n)); | ||
return typeof value === 'bigint' ? new Date(Number(value / 1000n)) : new Date(value / 1000); | ||
} | ||
@@ -429,8 +446,7 @@ function toPrimitive_INTERVAL(value) { | ||
} | ||
function checkValidValue(lowerRange, upperRange, v, bigV) { | ||
if (bigV < lowerRange || bigV > upperRange || isNaN(v)) { | ||
function checkValidValue(lowerRange, upperRange, v) { | ||
if (v < lowerRange || v > upperRange) { | ||
throw "invalid value"; | ||
} | ||
} | ||
module.exports = { PARQUET_LOGICAL_TYPES, toPrimitive, fromPrimitive }; | ||
//# sourceMappingURL=types.js.map |
@@ -132,2 +132,10 @@ "use strict"; | ||
fromPrimitive: fromPrimitive_INTERVAL | ||
}, | ||
MAP: { | ||
originalType: 'MAP', | ||
toPrimitive: toPrimitive_MAP, | ||
}, | ||
LIST: { | ||
originalType: 'LIST', | ||
toPrimitive: toPrimitive_LIST, | ||
} | ||
@@ -246,2 +254,8 @@ }; | ||
} | ||
function toPrimitive_MAP(value) { | ||
return value; | ||
} | ||
function toPrimitive_LIST(value) { | ||
return value; | ||
} | ||
function toPrimitive_BYTE_ARRAY(value) { | ||
@@ -248,0 +262,0 @@ return Buffer.from(value); |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/parquet.js", | ||
"version": "0.0.0-44d9f3", | ||
"version": "0.0.0-6fb5fc", | ||
"homepage": "https://github.com/LibertyDSNP/parquetjs", | ||
@@ -18,2 +18,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/varint": "^6.0.0", | ||
"browserify-zlib": "^0.2.0", | ||
@@ -48,3 +49,3 @@ "bson": "4.4.0", | ||
"core-js": "^3.15.1", | ||
"esbuild": "^0.12.20", | ||
"esbuild": "^0.14.1", | ||
"mocha": "8.3.2", | ||
@@ -60,3 +61,3 @@ "msw": "^0.29.0", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.3.4" | ||
"typescript": "^4.5.2" | ||
}, | ||
@@ -63,0 +64,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51
17732
2987292
11
+ Added@types/varint@^6.0.0
+ Added@types/node@22.9.1(transitive)
+ Added@types/varint@6.0.3(transitive)
+ Addedundici-types@6.19.8(transitive)