@loaders.gl/parquet 3.1.0-alpha.5 → 3.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/dist.min.js +27 -13
- package/dist/dist.min.js.map +7 -1
- package/dist/es5/index.js +6 -26
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/parquet-loader.js +1 -1
- package/dist/es5/parquet-loader.js.map +1 -1
- package/dist/es5/parquet-writer.js +1 -1
- package/dist/es5/parquet-writer.js.map +1 -1
- package/dist/es5/parquetjs/codecs/rle.js +1 -1
- package/dist/es5/parquetjs/codecs/rle.js.map +1 -1
- package/dist/es5/parquetjs/compression.js +1 -12
- package/dist/es5/parquetjs/compression.js.map +1 -1
- package/dist/es5/parquetjs/parser/decoders.js +1 -1
- package/dist/es5/parquetjs/parser/decoders.js.map +1 -1
- package/dist/es5/parquetjs/parser/parquet-envelope-reader.js +0 -13
- package/dist/es5/parquetjs/parser/parquet-envelope-reader.js.map +1 -1
- package/dist/es5/parquetjs/parser/parquet-reader.js +0 -13
- package/dist/es5/parquetjs/parser/parquet-reader.js.map +1 -1
- package/dist/es5/parquetjs/utils/file-utils.js +0 -53
- package/dist/es5/parquetjs/utils/file-utils.js.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parquet-loader.js +1 -1
- package/dist/esm/parquet-loader.js.map +1 -1
- package/dist/esm/parquet-writer.js +1 -1
- package/dist/esm/parquet-writer.js.map +1 -1
- package/dist/esm/parquetjs/codecs/rle.js +1 -1
- package/dist/esm/parquetjs/codecs/rle.js.map +1 -1
- package/dist/esm/parquetjs/compression.js +1 -10
- package/dist/esm/parquetjs/compression.js.map +1 -1
- package/dist/esm/parquetjs/parser/decoders.js +1 -1
- package/dist/esm/parquetjs/parser/decoders.js.map +1 -1
- package/dist/esm/parquetjs/parser/parquet-envelope-reader.js +0 -9
- package/dist/esm/parquetjs/parser/parquet-envelope-reader.js.map +1 -1
- package/dist/esm/parquetjs/parser/parquet-reader.js +0 -13
- package/dist/esm/parquetjs/parser/parquet-reader.js.map +1 -1
- package/dist/esm/parquetjs/utils/file-utils.js +0 -45
- package/dist/esm/parquetjs/utils/file-utils.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/lib/convert-schema.d.ts +1 -0
- package/dist/lib/convert-schema.d.ts.map +1 -0
- package/dist/lib/convert-schema.js +70 -0
- package/dist/lib/parse-parquet.d.ts +1 -0
- package/dist/lib/parse-parquet.d.ts.map +1 -0
- package/dist/lib/parse-parquet.js +28 -0
- package/dist/lib/read-array-buffer.d.ts +1 -0
- package/dist/lib/read-array-buffer.d.ts.map +1 -0
- package/dist/lib/read-array-buffer.js +29 -0
- package/dist/parquet-loader.d.ts +1 -0
- package/dist/parquet-loader.d.ts.map +1 -0
- package/dist/parquet-loader.js +27 -0
- package/dist/parquet-worker.js +27 -13
- package/dist/parquet-worker.js.map +7 -1
- package/dist/parquet-writer.d.ts +1 -0
- package/dist/parquet-writer.d.ts.map +1 -0
- package/dist/parquet-writer.js +21 -0
- package/dist/parquetjs/codecs/declare.d.ts +1 -0
- package/dist/parquetjs/codecs/declare.d.ts.map +1 -0
- package/dist/parquetjs/codecs/declare.js +2 -0
- package/dist/parquetjs/codecs/dictionary.d.ts +1 -0
- package/dist/parquetjs/codecs/dictionary.d.ts.map +1 -0
- package/dist/parquetjs/codecs/dictionary.js +14 -0
- package/dist/parquetjs/codecs/index.d.ts +1 -0
- package/dist/parquetjs/codecs/index.d.ts.map +1 -0
- package/dist/parquetjs/codecs/index.js +51 -0
- package/dist/parquetjs/codecs/plain.d.ts +1 -0
- package/dist/parquetjs/codecs/plain.d.ts.map +1 -0
- package/dist/parquetjs/codecs/plain.js +211 -0
- package/dist/parquetjs/codecs/rle.d.ts +1 -0
- package/dist/parquetjs/codecs/rle.d.ts.map +1 -0
- package/dist/parquetjs/codecs/rle.js +145 -0
- package/dist/parquetjs/compression.d.ts +1 -0
- package/dist/parquetjs/compression.d.ts.map +1 -0
- package/dist/parquetjs/compression.js +168 -0
- package/dist/parquetjs/encoder/writer.d.ts +1 -0
- package/dist/parquetjs/encoder/writer.d.ts.map +1 -0
- package/dist/parquetjs/encoder/writer.js +478 -0
- package/dist/parquetjs/file.d.ts +1 -0
- package/dist/parquetjs/file.d.ts.map +1 -0
- package/dist/parquetjs/file.js +99 -0
- package/dist/parquetjs/parquet-thrift/BoundaryOrder.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/BoundaryOrder.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/BoundaryOrder.js +15 -0
- package/dist/parquetjs/parquet-thrift/BsonType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/BsonType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/BsonType.js +58 -0
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnChunk.js +207 -0
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js +213 -0
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.js +398 -0
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ColumnOrder.js +104 -0
- package/dist/parquetjs/parquet-thrift/CompressionCodec.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/CompressionCodec.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/CompressionCodec.js +20 -0
- package/dist/parquetjs/parquet-thrift/ConvertedType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ConvertedType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ConvertedType.js +34 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeader.js +166 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js +226 -0
- package/dist/parquetjs/parquet-thrift/DateType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/DateType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/DateType.js +58 -0
- package/dist/parquetjs/parquet-thrift/DecimalType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/DecimalType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/DecimalType.js +105 -0
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js +122 -0
- package/dist/parquetjs/parquet-thrift/Encoding.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/Encoding.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/Encoding.js +20 -0
- package/dist/parquetjs/parquet-thrift/EnumType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/EnumType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/EnumType.js +58 -0
- package/dist/parquetjs/parquet-thrift/FieldRepetitionType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/FieldRepetitionType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/FieldRepetitionType.js +15 -0
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/FileMetaData.js +256 -0
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.js +58 -0
- package/dist/parquetjs/parquet-thrift/IntType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/IntType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/IntType.js +105 -0
- package/dist/parquetjs/parquet-thrift/JsonType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/JsonType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/JsonType.js +58 -0
- package/dist/parquetjs/parquet-thrift/KeyValue.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/KeyValue.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/KeyValue.js +102 -0
- package/dist/parquetjs/parquet-thrift/ListType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/ListType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/ListType.js +58 -0
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/LogicalType.js +380 -0
- package/dist/parquetjs/parquet-thrift/MapType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/MapType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/MapType.js +58 -0
- package/dist/parquetjs/parquet-thrift/MicroSeconds.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/MicroSeconds.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/MicroSeconds.js +58 -0
- package/dist/parquetjs/parquet-thrift/MilliSeconds.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/MilliSeconds.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/MilliSeconds.js +58 -0
- package/dist/parquetjs/parquet-thrift/NullType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/NullType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/NullType.js +58 -0
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/OffsetIndex.js +97 -0
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.js +127 -0
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/PageHeader.js +216 -0
- package/dist/parquetjs/parquet-thrift/PageLocation.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/PageLocation.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/PageLocation.js +141 -0
- package/dist/parquetjs/parquet-thrift/PageType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/PageType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/PageType.js +16 -0
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/RowGroup.js +182 -0
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/SchemaElement.js +239 -0
- package/dist/parquetjs/parquet-thrift/SortingColumn.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/SortingColumn.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/SortingColumn.js +127 -0
- package/dist/parquetjs/parquet-thrift/Statistics.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/Statistics.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/Statistics.js +176 -0
- package/dist/parquetjs/parquet-thrift/StringType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/StringType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/StringType.js +58 -0
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/TimeType.js +106 -0
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/TimeUnit.js +127 -0
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/TimestampType.js +106 -0
- package/dist/parquetjs/parquet-thrift/Type.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/Type.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/Type.js +20 -0
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js +58 -0
- package/dist/parquetjs/parquet-thrift/UUIDType.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/UUIDType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/UUIDType.js +58 -0
- package/dist/parquetjs/parquet-thrift/index.d.ts +1 -0
- package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/index.js +61 -0
- package/dist/parquetjs/parser/decoders.d.ts +1 -0
- package/dist/parquetjs/parser/decoders.d.ts.map +1 -0
- package/dist/parquetjs/parser/decoders.js +318 -0
- package/dist/parquetjs/parser/parquet-cursor.d.ts +1 -0
- package/dist/parquetjs/parser/parquet-cursor.d.ts.map +1 -0
- package/dist/parquetjs/parser/parquet-cursor.js +74 -0
- package/dist/parquetjs/parser/parquet-envelope-reader.d.ts +1 -1
- package/dist/parquetjs/parser/parquet-envelope-reader.d.ts.map +1 -0
- package/dist/parquetjs/parser/parquet-envelope-reader.js +136 -0
- package/dist/parquetjs/parser/parquet-reader.d.ts +1 -5
- package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -0
- package/dist/parquetjs/parser/parquet-reader.js +134 -0
- package/dist/parquetjs/schema/declare.d.ts +1 -0
- package/dist/parquetjs/schema/declare.d.ts.map +1 -0
- package/dist/parquetjs/schema/declare.js +10 -0
- package/dist/parquetjs/schema/schema.d.ts +1 -0
- package/dist/parquetjs/schema/schema.d.ts.map +1 -0
- package/dist/parquetjs/schema/schema.js +162 -0
- package/dist/parquetjs/schema/shred.d.ts +1 -0
- package/dist/parquetjs/schema/shred.d.ts.map +1 -0
- package/dist/parquetjs/schema/shred.js +225 -0
- package/dist/parquetjs/schema/types.d.ts +1 -0
- package/dist/parquetjs/schema/types.d.ts.map +1 -0
- package/dist/parquetjs/schema/types.js +418 -0
- package/dist/parquetjs/utils/buffer-utils.d.ts +1 -0
- package/dist/parquetjs/utils/buffer-utils.d.ts.map +1 -0
- package/dist/parquetjs/utils/buffer-utils.js +22 -0
- package/dist/parquetjs/utils/file-utils.d.ts +1 -4
- package/dist/parquetjs/utils/file-utils.d.ts.map +1 -0
- package/dist/parquetjs/utils/file-utils.js +46 -0
- package/dist/parquetjs/utils/read-utils.d.ts +1 -0
- package/dist/parquetjs/utils/read-utils.d.ts.map +1 -0
- package/dist/parquetjs/utils/read-utils.js +109 -0
- package/dist/workers/parquet-worker.d.ts +1 -0
- package/dist/workers/parquet-worker.d.ts.map +1 -0
- package/dist/workers/parquet-worker.js +5 -0
- package/package.json +7 -8
- package/src/index.ts +3 -3
- package/src/parquetjs/codecs/rle.ts +1 -1
- package/src/parquetjs/compression.ts +10 -10
- package/src/parquetjs/parser/decoders.ts +1 -1
- package/src/parquetjs/parser/parquet-envelope-reader.ts +0 -11
- package/src/parquetjs/parser/parquet-reader.ts +0 -16
- package/src/parquetjs/utils/file-utils.ts +0 -49
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.materializeRecords = exports.shredRecord = exports.shredBuffer = exports.ParquetBuffer = void 0;
|
|
24
|
+
const declare_1 = require("./declare");
|
|
25
|
+
Object.defineProperty(exports, "ParquetBuffer", { enumerable: true, get: function () { return declare_1.ParquetBuffer; } });
|
|
26
|
+
const Types = __importStar(require("./types"));
|
|
27
|
+
function shredBuffer(schema) {
|
|
28
|
+
const columnData = {};
|
|
29
|
+
for (const field of schema.fieldList) {
|
|
30
|
+
columnData[field.key] = {
|
|
31
|
+
dlevels: [],
|
|
32
|
+
rlevels: [],
|
|
33
|
+
values: [],
|
|
34
|
+
pageHeaders: [],
|
|
35
|
+
count: 0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return { rowCount: 0, columnData };
|
|
39
|
+
}
|
|
40
|
+
exports.shredBuffer = shredBuffer;
|
|
41
|
+
/**
|
|
42
|
+
* 'Shred' a record into a list of <value, repetition_level, definition_level>
|
|
43
|
+
* tuples per column using the Google Dremel Algorithm..
|
|
44
|
+
*
|
|
45
|
+
* The buffer argument must point to an object into which the shredded record
|
|
46
|
+
* will be returned. You may re-use the buffer for repeated calls to this function
|
|
47
|
+
* to append to an existing buffer, as long as the schema is unchanged.
|
|
48
|
+
*
|
|
49
|
+
* The format in which the shredded records will be stored in the buffer is as
|
|
50
|
+
* follows:
|
|
51
|
+
*
|
|
52
|
+
* buffer = {
|
|
53
|
+
* columnData: [
|
|
54
|
+
* 'my_col': {
|
|
55
|
+
* dlevels: [d1, d2, .. dN],
|
|
56
|
+
* rlevels: [r1, r2, .. rN],
|
|
57
|
+
* values: [v1, v2, .. vN],
|
|
58
|
+
* }, ...
|
|
59
|
+
* ],
|
|
60
|
+
* rowCount: X,
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
function shredRecord(schema, record, buffer) {
|
|
64
|
+
/* shred the record, this may raise an exception */
|
|
65
|
+
const data = shredBuffer(schema).columnData;
|
|
66
|
+
shredRecordFields(schema.fields, record, data, 0, 0);
|
|
67
|
+
/* if no error during shredding, add the shredded record to the buffer */
|
|
68
|
+
if (buffer.rowCount === 0) {
|
|
69
|
+
buffer.rowCount = 1;
|
|
70
|
+
buffer.columnData = data;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
buffer.rowCount += 1;
|
|
74
|
+
for (const field of schema.fieldList) {
|
|
75
|
+
Array.prototype.push.apply(buffer.columnData[field.key].rlevels, data[field.key].rlevels);
|
|
76
|
+
Array.prototype.push.apply(buffer.columnData[field.key].dlevels, data[field.key].dlevels);
|
|
77
|
+
Array.prototype.push.apply(buffer.columnData[field.key].values, data[field.key].values);
|
|
78
|
+
buffer.columnData[field.key].count += data[field.key].count;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.shredRecord = shredRecord;
|
|
82
|
+
// eslint-disable-next-line max-statements, complexity
|
|
83
|
+
function shredRecordFields(fields, record, data, rLevel, dLevel) {
|
|
84
|
+
for (const name in fields) {
|
|
85
|
+
const field = fields[name];
|
|
86
|
+
// fetch values
|
|
87
|
+
let values = [];
|
|
88
|
+
if (record &&
|
|
89
|
+
field.name in record &&
|
|
90
|
+
record[field.name] !== undefined &&
|
|
91
|
+
record[field.name] !== null) {
|
|
92
|
+
if (record[field.name].constructor === Array) {
|
|
93
|
+
values = record[field.name];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
values.push(record[field.name]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// check values
|
|
100
|
+
if (values.length === 0 && Boolean(record) && field.repetitionType === 'REQUIRED') {
|
|
101
|
+
throw new Error(`missing required field: ${field.name}`);
|
|
102
|
+
}
|
|
103
|
+
if (values.length > 1 && field.repetitionType !== 'REPEATED') {
|
|
104
|
+
throw new Error(`too many values for field: ${field.name}`);
|
|
105
|
+
}
|
|
106
|
+
// push null
|
|
107
|
+
if (values.length === 0) {
|
|
108
|
+
if (field.isNested) {
|
|
109
|
+
shredRecordFields(field.fields, null, data, rLevel, dLevel);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
data[field.key].count += 1;
|
|
113
|
+
data[field.key].rlevels.push(rLevel);
|
|
114
|
+
data[field.key].dlevels.push(dLevel);
|
|
115
|
+
}
|
|
116
|
+
continue; // eslint-disable-line no-continue
|
|
117
|
+
}
|
|
118
|
+
// push values
|
|
119
|
+
for (let i = 0; i < values.length; i++) {
|
|
120
|
+
const rlvl = i === 0 ? rLevel : field.rLevelMax;
|
|
121
|
+
if (field.isNested) {
|
|
122
|
+
shredRecordFields(field.fields, values[i], data, rlvl, field.dLevelMax);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
data[field.key].count += 1;
|
|
126
|
+
data[field.key].rlevels.push(rlvl);
|
|
127
|
+
data[field.key].dlevels.push(field.dLevelMax);
|
|
128
|
+
data[field.key].values.push(Types.toPrimitive((field.originalType || field.primitiveType), values[i]));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 'Materialize' a list of <value, repetition_level, definition_level>
|
|
135
|
+
* tuples back to nested records (objects/arrays) using the Google Dremel
|
|
136
|
+
* Algorithm..
|
|
137
|
+
*
|
|
138
|
+
* The buffer argument must point to an object with the following structure (i.e.
|
|
139
|
+
* the same structure that is returned by shredRecords):
|
|
140
|
+
*
|
|
141
|
+
* buffer = {
|
|
142
|
+
* columnData: [
|
|
143
|
+
* 'my_col': {
|
|
144
|
+
* dlevels: [d1, d2, .. dN],
|
|
145
|
+
* rlevels: [r1, r2, .. rN],
|
|
146
|
+
* values: [v1, v2, .. vN],
|
|
147
|
+
* }, ...
|
|
148
|
+
* ],
|
|
149
|
+
* rowCount: X,
|
|
150
|
+
* }
|
|
151
|
+
*/
|
|
152
|
+
function materializeRecords(schema, buffer) {
|
|
153
|
+
const records = [];
|
|
154
|
+
for (let i = 0; i < buffer.rowCount; i++)
|
|
155
|
+
records.push({});
|
|
156
|
+
for (const key in buffer.columnData) {
|
|
157
|
+
materializeColumn(schema, buffer, key, records);
|
|
158
|
+
}
|
|
159
|
+
return records;
|
|
160
|
+
}
|
|
161
|
+
exports.materializeRecords = materializeRecords;
|
|
162
|
+
// eslint-disable-next-line max-statements, complexity
|
|
163
|
+
function materializeColumn(schema, buffer, key, records) {
|
|
164
|
+
const data = buffer.columnData[key];
|
|
165
|
+
if (!data.count)
|
|
166
|
+
return;
|
|
167
|
+
const field = schema.findField(key);
|
|
168
|
+
const branch = schema.findFieldBranch(key);
|
|
169
|
+
// tslint:disable-next-line:prefer-array-literal
|
|
170
|
+
const rLevels = new Array(field.rLevelMax + 1).fill(0);
|
|
171
|
+
let vIndex = 0;
|
|
172
|
+
for (let i = 0; i < data.count; i++) {
|
|
173
|
+
const dLevel = data.dlevels[i];
|
|
174
|
+
const rLevel = data.rlevels[i];
|
|
175
|
+
rLevels[rLevel]++;
|
|
176
|
+
rLevels.fill(0, rLevel + 1);
|
|
177
|
+
let rIndex = 0;
|
|
178
|
+
let record = records[rLevels[rIndex++] - 1];
|
|
179
|
+
// Internal nodes
|
|
180
|
+
for (const step of branch) {
|
|
181
|
+
if (step === field)
|
|
182
|
+
break;
|
|
183
|
+
if (dLevel < step.dLevelMax)
|
|
184
|
+
break;
|
|
185
|
+
if (step.repetitionType === 'REPEATED') {
|
|
186
|
+
if (!(step.name in record)) {
|
|
187
|
+
// eslint-disable max-depth
|
|
188
|
+
record[step.name] = [];
|
|
189
|
+
}
|
|
190
|
+
const ix = rLevels[rIndex++];
|
|
191
|
+
while (record[step.name].length <= ix) {
|
|
192
|
+
// eslint-disable max-depth
|
|
193
|
+
record[step.name].push({});
|
|
194
|
+
}
|
|
195
|
+
record = record[step.name][ix];
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
record[step.name] = record[step.name] || {};
|
|
199
|
+
record = record[step.name];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Leaf node
|
|
203
|
+
if (dLevel === field.dLevelMax) {
|
|
204
|
+
const value = Types.fromPrimitive(
|
|
205
|
+
// @ts-ignore
|
|
206
|
+
field.originalType || field.primitiveType, data.values[vIndex], field);
|
|
207
|
+
vIndex++;
|
|
208
|
+
if (field.repetitionType === 'REPEATED') {
|
|
209
|
+
if (!(field.name in record)) {
|
|
210
|
+
// eslint-disable max-depth
|
|
211
|
+
record[field.name] = [];
|
|
212
|
+
}
|
|
213
|
+
const ix = rLevels[rIndex];
|
|
214
|
+
while (record[field.name].length <= ix) {
|
|
215
|
+
// eslint-disable max-depth
|
|
216
|
+
record[field.name].push(null);
|
|
217
|
+
}
|
|
218
|
+
record[field.name][ix] = value;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
record[field.name] = value;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/parquetjs/schema/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAC,MAAM,WAAW,CAAC;AAEjF,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;IACtB,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAuJrE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,YAAY,OAM9E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,YAAY,OAUhF"}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fromPrimitive = exports.toPrimitive = exports.PARQUET_LOGICAL_TYPES = void 0;
|
|
7
|
+
// Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
|
|
8
|
+
/* eslint-disable camelcase */
|
|
9
|
+
const bson_1 = __importDefault(require("bson"));
|
|
10
|
+
exports.PARQUET_LOGICAL_TYPES = {
|
|
11
|
+
BOOLEAN: {
|
|
12
|
+
primitiveType: 'BOOLEAN',
|
|
13
|
+
toPrimitive: toPrimitive_BOOLEAN,
|
|
14
|
+
fromPrimitive: fromPrimitive_BOOLEAN
|
|
15
|
+
},
|
|
16
|
+
INT32: {
|
|
17
|
+
primitiveType: 'INT32',
|
|
18
|
+
toPrimitive: toPrimitive_INT32
|
|
19
|
+
},
|
|
20
|
+
INT64: {
|
|
21
|
+
primitiveType: 'INT64',
|
|
22
|
+
toPrimitive: toPrimitive_INT64
|
|
23
|
+
},
|
|
24
|
+
INT96: {
|
|
25
|
+
primitiveType: 'INT96',
|
|
26
|
+
toPrimitive: toPrimitive_INT96
|
|
27
|
+
},
|
|
28
|
+
FLOAT: {
|
|
29
|
+
primitiveType: 'FLOAT',
|
|
30
|
+
toPrimitive: toPrimitive_FLOAT
|
|
31
|
+
},
|
|
32
|
+
DOUBLE: {
|
|
33
|
+
primitiveType: 'DOUBLE',
|
|
34
|
+
toPrimitive: toPrimitive_DOUBLE
|
|
35
|
+
},
|
|
36
|
+
BYTE_ARRAY: {
|
|
37
|
+
primitiveType: 'BYTE_ARRAY',
|
|
38
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
39
|
+
},
|
|
40
|
+
FIXED_LEN_BYTE_ARRAY: {
|
|
41
|
+
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
42
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
43
|
+
},
|
|
44
|
+
UTF8: {
|
|
45
|
+
primitiveType: 'BYTE_ARRAY',
|
|
46
|
+
originalType: 'UTF8',
|
|
47
|
+
toPrimitive: toPrimitive_UTF8,
|
|
48
|
+
fromPrimitive: fromPrimitive_UTF8
|
|
49
|
+
},
|
|
50
|
+
TIME_MILLIS: {
|
|
51
|
+
primitiveType: 'INT32',
|
|
52
|
+
originalType: 'TIME_MILLIS',
|
|
53
|
+
toPrimitive: toPrimitive_TIME_MILLIS
|
|
54
|
+
},
|
|
55
|
+
TIME_MICROS: {
|
|
56
|
+
primitiveType: 'INT64',
|
|
57
|
+
originalType: 'TIME_MICROS',
|
|
58
|
+
toPrimitive: toPrimitive_TIME_MICROS
|
|
59
|
+
},
|
|
60
|
+
DATE: {
|
|
61
|
+
primitiveType: 'INT32',
|
|
62
|
+
originalType: 'DATE',
|
|
63
|
+
toPrimitive: toPrimitive_DATE,
|
|
64
|
+
fromPrimitive: fromPrimitive_DATE
|
|
65
|
+
},
|
|
66
|
+
TIMESTAMP_MILLIS: {
|
|
67
|
+
primitiveType: 'INT64',
|
|
68
|
+
originalType: 'TIMESTAMP_MILLIS',
|
|
69
|
+
toPrimitive: toPrimitive_TIMESTAMP_MILLIS,
|
|
70
|
+
fromPrimitive: fromPrimitive_TIMESTAMP_MILLIS
|
|
71
|
+
},
|
|
72
|
+
TIMESTAMP_MICROS: {
|
|
73
|
+
primitiveType: 'INT64',
|
|
74
|
+
originalType: 'TIMESTAMP_MICROS',
|
|
75
|
+
toPrimitive: toPrimitive_TIMESTAMP_MICROS,
|
|
76
|
+
fromPrimitive: fromPrimitive_TIMESTAMP_MICROS
|
|
77
|
+
},
|
|
78
|
+
UINT_8: {
|
|
79
|
+
primitiveType: 'INT32',
|
|
80
|
+
originalType: 'UINT_8',
|
|
81
|
+
toPrimitive: toPrimitive_UINT8
|
|
82
|
+
},
|
|
83
|
+
UINT_16: {
|
|
84
|
+
primitiveType: 'INT32',
|
|
85
|
+
originalType: 'UINT_16',
|
|
86
|
+
toPrimitive: toPrimitive_UINT16
|
|
87
|
+
},
|
|
88
|
+
UINT_32: {
|
|
89
|
+
primitiveType: 'INT32',
|
|
90
|
+
originalType: 'UINT_32',
|
|
91
|
+
toPrimitive: toPrimitive_UINT32
|
|
92
|
+
},
|
|
93
|
+
UINT_64: {
|
|
94
|
+
primitiveType: 'INT64',
|
|
95
|
+
originalType: 'UINT_64',
|
|
96
|
+
toPrimitive: toPrimitive_UINT64
|
|
97
|
+
},
|
|
98
|
+
INT_8: {
|
|
99
|
+
primitiveType: 'INT32',
|
|
100
|
+
originalType: 'INT_8',
|
|
101
|
+
toPrimitive: toPrimitive_INT8
|
|
102
|
+
},
|
|
103
|
+
INT_16: {
|
|
104
|
+
primitiveType: 'INT32',
|
|
105
|
+
originalType: 'INT_16',
|
|
106
|
+
toPrimitive: toPrimitive_INT16
|
|
107
|
+
},
|
|
108
|
+
INT_32: {
|
|
109
|
+
primitiveType: 'INT32',
|
|
110
|
+
originalType: 'INT_32',
|
|
111
|
+
toPrimitive: toPrimitive_INT32
|
|
112
|
+
},
|
|
113
|
+
INT_64: {
|
|
114
|
+
primitiveType: 'INT64',
|
|
115
|
+
originalType: 'INT_64',
|
|
116
|
+
toPrimitive: toPrimitive_INT64
|
|
117
|
+
},
|
|
118
|
+
JSON: {
|
|
119
|
+
primitiveType: 'BYTE_ARRAY',
|
|
120
|
+
originalType: 'JSON',
|
|
121
|
+
toPrimitive: toPrimitive_JSON,
|
|
122
|
+
fromPrimitive: fromPrimitive_JSON
|
|
123
|
+
},
|
|
124
|
+
BSON: {
|
|
125
|
+
primitiveType: 'BYTE_ARRAY',
|
|
126
|
+
originalType: 'BSON',
|
|
127
|
+
toPrimitive: toPrimitive_BSON,
|
|
128
|
+
fromPrimitive: fromPrimitive_BSON
|
|
129
|
+
},
|
|
130
|
+
INTERVAL: {
|
|
131
|
+
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
132
|
+
originalType: 'INTERVAL',
|
|
133
|
+
typeLength: 12,
|
|
134
|
+
toPrimitive: toPrimitive_INTERVAL,
|
|
135
|
+
fromPrimitive: fromPrimitive_INTERVAL
|
|
136
|
+
},
|
|
137
|
+
DECIMAL_INT32: {
|
|
138
|
+
primitiveType: 'INT32',
|
|
139
|
+
originalType: 'DECIMAL_INT32',
|
|
140
|
+
toPrimitive: decimalToPrimitive_INT32,
|
|
141
|
+
fromPrimitive: decimalFromPrimitive_INT
|
|
142
|
+
},
|
|
143
|
+
DECIMAL_INT64: {
|
|
144
|
+
primitiveType: 'INT64',
|
|
145
|
+
originalType: 'DECIMAL_INT64',
|
|
146
|
+
toPrimitive: decimalToPrimitive_INT64,
|
|
147
|
+
fromPrimitive: decimalFromPrimitive_INT
|
|
148
|
+
},
|
|
149
|
+
DECIMAL_BYTE_ARRAY: {
|
|
150
|
+
primitiveType: 'BYTE_ARRAY',
|
|
151
|
+
originalType: 'DECIMAL_BYTE_ARRAY',
|
|
152
|
+
toPrimitive: decimalToPrimitive_BYTE_ARRAY,
|
|
153
|
+
fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
|
|
154
|
+
},
|
|
155
|
+
DECIMAL_FIXED_LEN_BYTE_ARRAY: {
|
|
156
|
+
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
157
|
+
originalType: 'DECIMAL_FIXED_LEN_BYTE_ARRAY',
|
|
158
|
+
toPrimitive: decimalToPrimitive_BYTE_ARRAY,
|
|
159
|
+
fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Convert a value from it's native representation to the internal/underlying
|
|
164
|
+
* primitive type
|
|
165
|
+
*/
|
|
166
|
+
function toPrimitive(type, value, field) {
|
|
167
|
+
if (!(type in exports.PARQUET_LOGICAL_TYPES)) {
|
|
168
|
+
throw new Error(`invalid type: ${type}`);
|
|
169
|
+
}
|
|
170
|
+
return exports.PARQUET_LOGICAL_TYPES[type].toPrimitive(value, field);
|
|
171
|
+
}
|
|
172
|
+
exports.toPrimitive = toPrimitive;
|
|
173
|
+
/**
|
|
174
|
+
* Convert a value from it's internal/underlying primitive representation to
|
|
175
|
+
* the native representation
|
|
176
|
+
*/
|
|
177
|
+
function fromPrimitive(type, value, field) {
|
|
178
|
+
if (!(type in exports.PARQUET_LOGICAL_TYPES)) {
|
|
179
|
+
throw new Error(`invalid type: ${type}`);
|
|
180
|
+
}
|
|
181
|
+
if ('fromPrimitive' in exports.PARQUET_LOGICAL_TYPES[type]) {
|
|
182
|
+
return exports.PARQUET_LOGICAL_TYPES[type].fromPrimitive?.(value, field);
|
|
183
|
+
// tslint:disable-next-line:no-else-after-return
|
|
184
|
+
}
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
exports.fromPrimitive = fromPrimitive;
|
|
188
|
+
function toPrimitive_BOOLEAN(value) {
|
|
189
|
+
return Boolean(value);
|
|
190
|
+
}
|
|
191
|
+
function fromPrimitive_BOOLEAN(value) {
|
|
192
|
+
return Boolean(value);
|
|
193
|
+
}
|
|
194
|
+
function toPrimitive_FLOAT(value) {
|
|
195
|
+
const v = parseFloat(value);
|
|
196
|
+
if (isNaN(v)) {
|
|
197
|
+
throw new Error(`invalid value for FLOAT: ${value}`);
|
|
198
|
+
}
|
|
199
|
+
return v;
|
|
200
|
+
}
|
|
201
|
+
function toPrimitive_DOUBLE(value) {
|
|
202
|
+
const v = parseFloat(value);
|
|
203
|
+
if (isNaN(v)) {
|
|
204
|
+
throw new Error(`invalid value for DOUBLE: ${value}`);
|
|
205
|
+
}
|
|
206
|
+
return v;
|
|
207
|
+
}
|
|
208
|
+
function toPrimitive_INT8(value) {
|
|
209
|
+
const v = parseInt(value, 10);
|
|
210
|
+
if (v < -0x80 || v > 0x7f || isNaN(v)) {
|
|
211
|
+
throw new Error(`invalid value for INT8: ${value}`);
|
|
212
|
+
}
|
|
213
|
+
return v;
|
|
214
|
+
}
|
|
215
|
+
function toPrimitive_UINT8(value) {
|
|
216
|
+
const v = parseInt(value, 10);
|
|
217
|
+
if (v < 0 || v > 0xff || isNaN(v)) {
|
|
218
|
+
throw new Error(`invalid value for UINT8: ${value}`);
|
|
219
|
+
}
|
|
220
|
+
return v;
|
|
221
|
+
}
|
|
222
|
+
function toPrimitive_INT16(value) {
|
|
223
|
+
const v = parseInt(value, 10);
|
|
224
|
+
if (v < -0x8000 || v > 0x7fff || isNaN(v)) {
|
|
225
|
+
throw new Error(`invalid value for INT16: ${value}`);
|
|
226
|
+
}
|
|
227
|
+
return v;
|
|
228
|
+
}
|
|
229
|
+
function toPrimitive_UINT16(value) {
|
|
230
|
+
const v = parseInt(value, 10);
|
|
231
|
+
if (v < 0 || v > 0xffff || isNaN(v)) {
|
|
232
|
+
throw new Error(`invalid value for UINT16: ${value}`);
|
|
233
|
+
}
|
|
234
|
+
return v;
|
|
235
|
+
}
|
|
236
|
+
function toPrimitive_INT32(value) {
|
|
237
|
+
const v = parseInt(value, 10);
|
|
238
|
+
if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
|
|
239
|
+
throw new Error(`invalid value for INT32: ${value}`);
|
|
240
|
+
}
|
|
241
|
+
return v;
|
|
242
|
+
}
|
|
243
|
+
function decimalToPrimitive_INT32(value, field) {
|
|
244
|
+
const primitiveValue = value * 10 ** (field.scale || 0);
|
|
245
|
+
const v = Math.round(((primitiveValue * 10 ** -field.presision) % 1) * 10 ** field.presision);
|
|
246
|
+
if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
|
|
247
|
+
throw new Error(`invalid value for INT32: ${value}`);
|
|
248
|
+
}
|
|
249
|
+
return v;
|
|
250
|
+
}
|
|
251
|
+
function toPrimitive_UINT32(value) {
|
|
252
|
+
const v = parseInt(value, 10);
|
|
253
|
+
if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
|
|
254
|
+
throw new Error(`invalid value for UINT32: ${value}`);
|
|
255
|
+
}
|
|
256
|
+
return v;
|
|
257
|
+
}
|
|
258
|
+
function toPrimitive_INT64(value) {
|
|
259
|
+
const v = parseInt(value, 10);
|
|
260
|
+
if (isNaN(v)) {
|
|
261
|
+
throw new Error(`invalid value for INT64: ${value}`);
|
|
262
|
+
}
|
|
263
|
+
return v;
|
|
264
|
+
}
|
|
265
|
+
function decimalToPrimitive_INT64(value, field) {
|
|
266
|
+
const primitiveValue = value * 10 ** (field.scale || 0);
|
|
267
|
+
const v = Math.round(((primitiveValue * 10 ** -field.presision) % 1) * 10 ** field.presision);
|
|
268
|
+
if (isNaN(v)) {
|
|
269
|
+
throw new Error(`invalid value for INT64: ${value}`);
|
|
270
|
+
}
|
|
271
|
+
return v;
|
|
272
|
+
}
|
|
273
|
+
function toPrimitive_UINT64(value) {
|
|
274
|
+
const v = parseInt(value, 10);
|
|
275
|
+
if (v < 0 || isNaN(v)) {
|
|
276
|
+
throw new Error(`invalid value for UINT64: ${value}`);
|
|
277
|
+
}
|
|
278
|
+
return v;
|
|
279
|
+
}
|
|
280
|
+
function toPrimitive_INT96(value) {
|
|
281
|
+
const v = parseInt(value, 10);
|
|
282
|
+
if (isNaN(v)) {
|
|
283
|
+
throw new Error(`invalid value for INT96: ${value}`);
|
|
284
|
+
}
|
|
285
|
+
return v;
|
|
286
|
+
}
|
|
287
|
+
function toPrimitive_BYTE_ARRAY(value) {
|
|
288
|
+
return Buffer.from(value);
|
|
289
|
+
}
|
|
290
|
+
function decimalToPrimitive_BYTE_ARRAY(value) {
|
|
291
|
+
// TBD
|
|
292
|
+
return Buffer.from(value);
|
|
293
|
+
}
|
|
294
|
+
function toPrimitive_UTF8(value) {
|
|
295
|
+
return Buffer.from(value, 'utf8');
|
|
296
|
+
}
|
|
297
|
+
function fromPrimitive_UTF8(value) {
|
|
298
|
+
return value.toString();
|
|
299
|
+
}
|
|
300
|
+
function toPrimitive_JSON(value) {
|
|
301
|
+
return Buffer.from(JSON.stringify(value));
|
|
302
|
+
}
|
|
303
|
+
function fromPrimitive_JSON(value) {
|
|
304
|
+
return JSON.parse(value);
|
|
305
|
+
}
|
|
306
|
+
function toPrimitive_BSON(value) {
|
|
307
|
+
return Buffer.from(bson_1.default.serialize(value));
|
|
308
|
+
}
|
|
309
|
+
function fromPrimitive_BSON(value) {
|
|
310
|
+
return bson_1.default.deserialize(value);
|
|
311
|
+
}
|
|
312
|
+
function toPrimitive_TIME_MILLIS(value) {
|
|
313
|
+
const v = parseInt(value, 10);
|
|
314
|
+
if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) {
|
|
315
|
+
throw new Error(`invalid value for TIME_MILLIS: ${value}`);
|
|
316
|
+
}
|
|
317
|
+
return v;
|
|
318
|
+
}
|
|
319
|
+
function toPrimitive_TIME_MICROS(value) {
|
|
320
|
+
const v = parseInt(value, 10);
|
|
321
|
+
if (v < 0 || isNaN(v)) {
|
|
322
|
+
throw new Error(`invalid value for TIME_MICROS: ${value}`);
|
|
323
|
+
}
|
|
324
|
+
return v;
|
|
325
|
+
}
|
|
326
|
+
const kMillisPerDay = 86400000;
|
|
327
|
+
function toPrimitive_DATE(value) {
|
|
328
|
+
/* convert from date */
|
|
329
|
+
if (value instanceof Date) {
|
|
330
|
+
return value.getTime() / kMillisPerDay;
|
|
331
|
+
}
|
|
332
|
+
/* convert from integer */
|
|
333
|
+
{
|
|
334
|
+
const v = parseInt(value, 10);
|
|
335
|
+
if (v < 0 || isNaN(v)) {
|
|
336
|
+
throw new Error(`invalid value for DATE: ${value}`);
|
|
337
|
+
}
|
|
338
|
+
return v;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function fromPrimitive_DATE(value) {
|
|
342
|
+
return new Date(value * kMillisPerDay);
|
|
343
|
+
}
|
|
344
|
+
function toPrimitive_TIMESTAMP_MILLIS(value) {
|
|
345
|
+
/* convert from date */
|
|
346
|
+
if (value instanceof Date) {
|
|
347
|
+
return value.getTime();
|
|
348
|
+
}
|
|
349
|
+
/* convert from integer */
|
|
350
|
+
{
|
|
351
|
+
const v = parseInt(value, 10);
|
|
352
|
+
if (v < 0 || isNaN(v)) {
|
|
353
|
+
throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
|
|
354
|
+
}
|
|
355
|
+
return v;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function fromPrimitive_TIMESTAMP_MILLIS(value) {
|
|
359
|
+
return new Date(value);
|
|
360
|
+
}
|
|
361
|
+
function toPrimitive_TIMESTAMP_MICROS(value) {
|
|
362
|
+
/* convert from date */
|
|
363
|
+
if (value instanceof Date) {
|
|
364
|
+
return value.getTime() * 1000;
|
|
365
|
+
}
|
|
366
|
+
/* convert from integer */
|
|
367
|
+
{
|
|
368
|
+
const v = parseInt(value, 10);
|
|
369
|
+
if (v < 0 || isNaN(v)) {
|
|
370
|
+
throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
|
|
371
|
+
}
|
|
372
|
+
return v;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function fromPrimitive_TIMESTAMP_MICROS(value) {
|
|
376
|
+
return new Date(value / 1000);
|
|
377
|
+
}
|
|
378
|
+
function toPrimitive_INTERVAL(value) {
|
|
379
|
+
if (!value.months || !value.days || !value.milliseconds) {
|
|
380
|
+
throw new Error('value for INTERVAL must be object { months: ..., days: ..., milliseconds: ... }');
|
|
381
|
+
}
|
|
382
|
+
const buf = Buffer.alloc(12);
|
|
383
|
+
buf.writeUInt32LE(value.months, 0);
|
|
384
|
+
buf.writeUInt32LE(value.days, 4);
|
|
385
|
+
buf.writeUInt32LE(value.milliseconds, 8);
|
|
386
|
+
return buf;
|
|
387
|
+
}
|
|
388
|
+
function fromPrimitive_INTERVAL(value) {
|
|
389
|
+
const buf = Buffer.from(value);
|
|
390
|
+
const months = buf.readUInt32LE(0);
|
|
391
|
+
const days = buf.readUInt32LE(4);
|
|
392
|
+
const millis = buf.readUInt32LE(8);
|
|
393
|
+
return { months, days, milliseconds: millis };
|
|
394
|
+
}
|
|
395
|
+
function decimalFromPrimitive_INT(value, field) {
|
|
396
|
+
const presisionInt = Math.round(((value * 10 ** -field.presision) % 1) * 10 ** field.presision);
|
|
397
|
+
return presisionInt * 10 ** -(field.scale || 0);
|
|
398
|
+
}
|
|
399
|
+
function decimalFromPrimitive_BYTE_ARRAY(value, field) {
|
|
400
|
+
let number = 0;
|
|
401
|
+
if (value.length <= 4) {
|
|
402
|
+
// Bytewise operators faster. Use them if it is possible
|
|
403
|
+
for (let i = 0; i < value.length; i++) {
|
|
404
|
+
// `value.length - i - 1` bytes have reverse order (big-endian)
|
|
405
|
+
const component = value[i] << (8 * (value.length - i - 1));
|
|
406
|
+
number += component;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
for (let i = 0; i < value.length; i++) {
|
|
411
|
+
// `value.length - i - 1` bytes have reverse order (big-endian)
|
|
412
|
+
const component = value[i] * 2 ** (8 * (value.length - 1 - i));
|
|
413
|
+
number += component;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const presisionInt = Math.round(((number * 10 ** -field.presision) % 1) * 10 ** field.presision);
|
|
417
|
+
return presisionInt * 10 ** -(field.scale || 0);
|
|
418
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-utils.d.ts","sourceRoot":"","sources":["../../../src/parquetjs/utils/buffer-utils.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAOzD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBuffer = exports.toArrayBuffer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert Buffer to ArrayBuffer
|
|
6
|
+
*/
|
|
7
|
+
function toArrayBuffer(buffer) {
|
|
8
|
+
// TODO - per docs we should just be able to call buffer.buffer, but there are issues
|
|
9
|
+
if (Buffer.isBuffer(buffer)) {
|
|
10
|
+
const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
|
|
11
|
+
return typedArray.slice().buffer;
|
|
12
|
+
}
|
|
13
|
+
return buffer;
|
|
14
|
+
}
|
|
15
|
+
exports.toArrayBuffer = toArrayBuffer;
|
|
16
|
+
/**
|
|
17
|
+
* Convert (copy) ArrayBuffer to Buffer
|
|
18
|
+
*/
|
|
19
|
+
function toBuffer(arrayBuffer) {
|
|
20
|
+
return Buffer.from(arrayBuffer);
|
|
21
|
+
}
|
|
22
|
+
exports.toBuffer = toBuffer;
|
|
@@ -10,10 +10,7 @@ export interface WriteStreamOptions {
|
|
|
10
10
|
autoClose?: boolean;
|
|
11
11
|
start?: number;
|
|
12
12
|
}
|
|
13
|
-
export declare function fopen(filePath: string): Promise<number>;
|
|
14
|
-
export declare function fstat(filePath: string): Promise<fs.Stats>;
|
|
15
|
-
export declare function fread(fd: number, position: number, length: number): Promise<Buffer>;
|
|
16
|
-
export declare function fclose(fd: number): Promise<void>;
|
|
17
13
|
export declare function oswrite(os: Writable, buf: Buffer): Promise<void>;
|
|
18
14
|
export declare function osclose(os: Writable): Promise<void>;
|
|
19
15
|
export declare function osopen(path: string, opts?: WriteStreamOptions): Promise<fs.WriteStream>;
|
|
16
|
+
//# sourceMappingURL=file-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../../src/parquetjs/utils/file-utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAEhC,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAEtC;AACD,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,CAMvF"}
|