@loaders.gl/parquet 3.3.0-alpha.8 → 3.3.0

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.
Files changed (131) hide show
  1. package/dist/dist.min.js +17 -26
  2. package/dist/dist.min.js.map +3 -3
  3. package/dist/es5/index.js +3 -3
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/lib/convert-schema-deep.ts.disabled +910 -0
  6. package/dist/es5/lib/parse-parquet.js +49 -25
  7. package/dist/es5/lib/parse-parquet.js.map +1 -1
  8. package/dist/es5/parquet-loader.js +3 -2
  9. package/dist/es5/parquet-loader.js.map +1 -1
  10. package/dist/es5/parquet-wasm-loader.js +1 -1
  11. package/dist/es5/parquet-wasm-loader.js.map +1 -1
  12. package/dist/es5/parquet-wasm-writer.js +1 -1
  13. package/dist/es5/parquet-wasm-writer.js.map +1 -1
  14. package/dist/es5/parquet-writer.js +1 -1
  15. package/dist/es5/parquet-writer.js.map +1 -1
  16. package/dist/es5/parquetjs/compression.js +15 -5
  17. package/dist/es5/parquetjs/compression.js.map +1 -1
  18. package/dist/es5/parquetjs/encoder/{writer.js → parquet-encoder.js} +70 -158
  19. package/dist/es5/parquetjs/encoder/parquet-encoder.js.map +1 -0
  20. package/dist/es5/parquetjs/parser/parquet-reader.js +553 -222
  21. package/dist/es5/parquetjs/parser/parquet-reader.js.map +1 -1
  22. package/dist/es5/parquetjs/schema/declare.js +3 -1
  23. package/dist/es5/parquetjs/schema/declare.js.map +1 -1
  24. package/dist/es5/parquetjs/schema/shred.js +39 -33
  25. package/dist/es5/parquetjs/schema/shred.js.map +1 -1
  26. package/dist/es5/parquetjs/schema/types.js.map +1 -1
  27. package/dist/es5/parquetjs/utils/file-utils.js +2 -3
  28. package/dist/es5/parquetjs/utils/file-utils.js.map +1 -1
  29. package/dist/esm/index.js +1 -1
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/lib/convert-schema-deep.ts.disabled +910 -0
  32. package/dist/esm/lib/parse-parquet.js +6 -12
  33. package/dist/esm/lib/parse-parquet.js.map +1 -1
  34. package/dist/esm/parquet-loader.js +3 -2
  35. package/dist/esm/parquet-loader.js.map +1 -1
  36. package/dist/esm/parquet-wasm-loader.js +1 -1
  37. package/dist/esm/parquet-wasm-loader.js.map +1 -1
  38. package/dist/esm/parquet-wasm-writer.js +1 -1
  39. package/dist/esm/parquet-wasm-writer.js.map +1 -1
  40. package/dist/esm/parquet-writer.js +1 -1
  41. package/dist/esm/parquet-writer.js.map +1 -1
  42. package/dist/esm/parquetjs/compression.js +10 -1
  43. package/dist/esm/parquetjs/compression.js.map +1 -1
  44. package/dist/esm/parquetjs/encoder/{writer.js → parquet-encoder.js} +7 -37
  45. package/dist/esm/parquetjs/encoder/parquet-encoder.js.map +1 -0
  46. package/dist/esm/parquetjs/parser/parquet-reader.js +158 -72
  47. package/dist/esm/parquetjs/parser/parquet-reader.js.map +1 -1
  48. package/dist/esm/parquetjs/schema/declare.js +1 -0
  49. package/dist/esm/parquetjs/schema/declare.js.map +1 -1
  50. package/dist/esm/parquetjs/schema/shred.js +42 -34
  51. package/dist/esm/parquetjs/schema/shred.js.map +1 -1
  52. package/dist/esm/parquetjs/schema/types.js.map +1 -1
  53. package/dist/esm/parquetjs/utils/file-utils.js +1 -1
  54. package/dist/esm/parquetjs/utils/file-utils.js.map +1 -1
  55. package/dist/index.d.ts +1 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +3 -4
  58. package/dist/lib/parse-parquet.d.ts +2 -2
  59. package/dist/lib/parse-parquet.d.ts.map +1 -1
  60. package/dist/lib/parse-parquet.js +24 -12
  61. package/dist/parquet-loader.d.ts +1 -0
  62. package/dist/parquet-loader.d.ts.map +1 -1
  63. package/dist/parquet-loader.js +2 -1
  64. package/dist/parquet-worker.js +15 -24
  65. package/dist/parquet-worker.js.map +3 -3
  66. package/dist/parquetjs/compression.d.ts.map +1 -1
  67. package/dist/parquetjs/compression.js +16 -5
  68. package/dist/parquetjs/encoder/{writer.d.ts → parquet-encoder.d.ts} +10 -19
  69. package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -0
  70. package/dist/parquetjs/encoder/{writer.js → parquet-encoder.js} +39 -37
  71. package/dist/parquetjs/parser/parquet-reader.d.ts +47 -57
  72. package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
  73. package/dist/parquetjs/parser/parquet-reader.js +168 -102
  74. package/dist/parquetjs/schema/declare.d.ts +14 -7
  75. package/dist/parquetjs/schema/declare.d.ts.map +1 -1
  76. package/dist/parquetjs/schema/declare.js +2 -0
  77. package/dist/parquetjs/schema/shred.d.ts +115 -0
  78. package/dist/parquetjs/schema/shred.d.ts.map +1 -1
  79. package/dist/parquetjs/schema/shred.js +161 -43
  80. package/dist/parquetjs/schema/types.d.ts +2 -2
  81. package/dist/parquetjs/schema/types.d.ts.map +1 -1
  82. package/dist/parquetjs/utils/file-utils.d.ts +3 -4
  83. package/dist/parquetjs/utils/file-utils.d.ts.map +1 -1
  84. package/dist/parquetjs/utils/file-utils.js +2 -5
  85. package/package.json +7 -5
  86. package/src/index.ts +2 -2
  87. package/src/lib/convert-schema-deep.ts.disabled +910 -0
  88. package/src/lib/parse-parquet.ts +25 -12
  89. package/src/parquet-loader.ts +3 -1
  90. package/src/parquetjs/compression.ts +14 -1
  91. package/src/parquetjs/encoder/{writer.ts → parquet-encoder.ts} +22 -28
  92. package/src/parquetjs/parser/parquet-reader.ts +239 -122
  93. package/src/parquetjs/schema/declare.ts +17 -9
  94. package/src/parquetjs/schema/shred.ts +157 -28
  95. package/src/parquetjs/schema/types.ts +21 -27
  96. package/src/parquetjs/utils/file-utils.ts +3 -4
  97. package/dist/es5/parquetjs/encoder/writer.js.map +0 -1
  98. package/dist/es5/parquetjs/file.js +0 -94
  99. package/dist/es5/parquetjs/file.js.map +0 -1
  100. package/dist/es5/parquetjs/parser/parquet-cursor.js +0 -183
  101. package/dist/es5/parquetjs/parser/parquet-cursor.js.map +0 -1
  102. package/dist/es5/parquetjs/parser/parquet-envelope-reader.js +0 -327
  103. package/dist/es5/parquetjs/parser/parquet-envelope-reader.js.map +0 -1
  104. package/dist/es5/parquetjs/utils/buffer-utils.js +0 -19
  105. package/dist/es5/parquetjs/utils/buffer-utils.js.map +0 -1
  106. package/dist/esm/parquetjs/encoder/writer.js.map +0 -1
  107. package/dist/esm/parquetjs/file.js +0 -81
  108. package/dist/esm/parquetjs/file.js.map +0 -1
  109. package/dist/esm/parquetjs/parser/parquet-cursor.js +0 -78
  110. package/dist/esm/parquetjs/parser/parquet-cursor.js.map +0 -1
  111. package/dist/esm/parquetjs/parser/parquet-envelope-reader.js +0 -129
  112. package/dist/esm/parquetjs/parser/parquet-envelope-reader.js.map +0 -1
  113. package/dist/esm/parquetjs/utils/buffer-utils.js +0 -13
  114. package/dist/esm/parquetjs/utils/buffer-utils.js.map +0 -1
  115. package/dist/parquetjs/encoder/writer.d.ts.map +0 -1
  116. package/dist/parquetjs/file.d.ts +0 -10
  117. package/dist/parquetjs/file.d.ts.map +0 -1
  118. package/dist/parquetjs/file.js +0 -99
  119. package/dist/parquetjs/parser/parquet-cursor.d.ts +0 -36
  120. package/dist/parquetjs/parser/parquet-cursor.d.ts.map +0 -1
  121. package/dist/parquetjs/parser/parquet-cursor.js +0 -74
  122. package/dist/parquetjs/parser/parquet-envelope-reader.d.ts +0 -40
  123. package/dist/parquetjs/parser/parquet-envelope-reader.d.ts.map +0 -1
  124. package/dist/parquetjs/parser/parquet-envelope-reader.js +0 -136
  125. package/dist/parquetjs/utils/buffer-utils.d.ts +0 -10
  126. package/dist/parquetjs/utils/buffer-utils.d.ts.map +0 -1
  127. package/dist/parquetjs/utils/buffer-utils.js +0 -22
  128. package/src/parquetjs/file.ts +0 -90
  129. package/src/parquetjs/parser/parquet-cursor.ts +0 -94
  130. package/src/parquetjs/parser/parquet-envelope-reader.ts +0 -199
  131. package/src/parquetjs/utils/buffer-utils.ts +0 -18
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParquetCursor = void 0;
4
- const shred_1 = require("../schema/shred");
5
- /**
6
- * A parquet cursor is used to retrieve rows from a parquet file in order
7
- */
8
- class ParquetCursor {
9
- /**
10
- * Create a new parquet reader from the file metadata and an envelope reader.
11
- * It is usually not recommended to call this constructor directly except for
12
- * advanced and internal use cases. Consider using getCursor() on the
13
- * ParquetReader instead
14
- */
15
- constructor(metadata, envelopeReader, schema, columnList) {
16
- this.rowGroup = [];
17
- this.metadata = metadata;
18
- this.envelopeReader = envelopeReader;
19
- this.schema = schema;
20
- this.columnList = columnList;
21
- this.rowGroupIndex = 0;
22
- }
23
- /**
24
- * Retrieve the next row from the cursor. Returns a row or NULL if the end
25
- * of the file was reached
26
- */
27
- async next() {
28
- if (this.rowGroup.length === 0) {
29
- if (this.rowGroupIndex >= this.metadata.row_groups.length) {
30
- // @ts-ignore
31
- return null;
32
- }
33
- const rowBuffer = await this.envelopeReader.readRowGroup(this.schema, this.metadata.row_groups[this.rowGroupIndex], this.columnList);
34
- this.rowGroup = (0, shred_1.materializeRecords)(this.schema, rowBuffer);
35
- this.rowGroupIndex++;
36
- }
37
- return this.rowGroup.shift();
38
- }
39
- /**
40
- * Rewind the cursor the the beginning of the file
41
- */
42
- rewind() {
43
- this.rowGroup = [];
44
- this.rowGroupIndex = 0;
45
- }
46
- /**
47
- * Implement AsyncIterable
48
- */
49
- // tslint:disable-next-line:function-name
50
- [Symbol.asyncIterator]() {
51
- let done = false;
52
- return {
53
- next: async () => {
54
- if (done) {
55
- return { done, value: null };
56
- }
57
- const value = await this.next();
58
- if (value === null) {
59
- return { done: true, value };
60
- }
61
- return { done: false, value };
62
- },
63
- return: async () => {
64
- done = true;
65
- return { done, value: null };
66
- },
67
- throw: async () => {
68
- done = true;
69
- return { done: true, value: null };
70
- }
71
- };
72
- }
73
- }
74
- exports.ParquetCursor = ParquetCursor;
@@ -1,40 +0,0 @@
1
- /// <reference types="node" />
2
- import { ParquetSchema } from '../schema/schema';
3
- import { ColumnChunk, FileMetaData, RowGroup } from '../parquet-thrift';
4
- import { ParquetBuffer, ParquetData, ParquetOptions } from '../schema/declare';
5
- /**
6
- * The parquet envelope reader allows direct, unbuffered access to the individual
7
- * sections of the parquet file, namely the header, footer and the row groups.
8
- * This class is intended for advanced/internal users; if you just want to retrieve
9
- * rows from a parquet file use the ParquetReader instead
10
- */
11
- export declare class ParquetEnvelopeReader {
12
- read: (position: number, length: number) => Promise<Buffer>;
13
- /**
14
- * Close this parquet reader. You MUST call this method once you're finished
15
- * reading rows
16
- */
17
- close: () => Promise<void>;
18
- fileSize: number;
19
- defaultDictionarySize: number;
20
- static openBuffer(buffer: Buffer): Promise<ParquetEnvelopeReader>;
21
- constructor(read: (position: number, length: number) => Promise<Buffer>, close: () => Promise<void>, fileSize: number, options?: any);
22
- readHeader(): Promise<void>;
23
- readRowGroup(schema: ParquetSchema, rowGroup: RowGroup, columnList: string[][]): Promise<ParquetBuffer>;
24
- /**
25
- * Do reading of parquet file's column chunk
26
- * @param schema
27
- * @param colChunk
28
- */
29
- readColumnChunk(schema: ParquetSchema, colChunk: ColumnChunk): Promise<ParquetData>;
30
- /**
31
- * Getting dictionary for allows to flatten values by indices.
32
- * @param dictionaryPageOffset
33
- * @param options
34
- * @param pagesOffset
35
- * @returns
36
- */
37
- getDictionary(dictionaryPageOffset: number, options: ParquetOptions, pagesOffset: number): Promise<string[]>;
38
- readFooter(): Promise<FileMetaData>;
39
- }
40
- //# sourceMappingURL=parquet-envelope-reader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parquet-envelope-reader.d.ts","sourceRoot":"","sources":["../../../src/parquetjs/parser/parquet-envelope-reader.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAC,WAAW,EAAoB,YAAY,EAAE,QAAQ,EAAO,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACL,aAAa,EAEb,WAAW,EAEX,cAAc,EACf,MAAM,mBAAmB,CAAC;AAM3B;;;;;GAKG;AACH,qBAAa,qBAAqB;IACzB,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE;;;OAGG;IACI,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;WAExB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;gBAQrE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC3D,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,GAAG;IAQT,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B,YAAY,CAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,EAAE,EAAE,GACrB,OAAO,CAAC,aAAa,CAAC;IAgBzB;;;;OAIG;IACG,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAoDzF;;;;;;OAMG;IACG,aAAa,CACjB,oBAAoB,EAAE,MAAM,EAC5B,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,EAAE,CAAC;IAwBd,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;CAqB1C"}
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParquetEnvelopeReader = void 0;
4
- const constants_1 = require("../../constants");
5
- const parquet_thrift_1 = require("../parquet-thrift");
6
- const read_utils_1 = require("../utils/read-utils");
7
- const decoders_1 = require("./decoders");
8
- const DEFAULT_DICTIONARY_SIZE = 1e6;
9
- /**
10
- * The parquet envelope reader allows direct, unbuffered access to the individual
11
- * sections of the parquet file, namely the header, footer and the row groups.
12
- * This class is intended for advanced/internal users; if you just want to retrieve
13
- * rows from a parquet file use the ParquetReader instead
14
- */
15
- class ParquetEnvelopeReader {
16
- static async openBuffer(buffer) {
17
- const readFn = (position, length) => Promise.resolve(buffer.slice(position, position + length));
18
- const closeFn = () => Promise.resolve();
19
- return new ParquetEnvelopeReader(readFn, closeFn, buffer.length);
20
- }
21
- constructor(read, close, fileSize, options) {
22
- this.read = read;
23
- this.close = close;
24
- this.fileSize = fileSize;
25
- this.defaultDictionarySize = options?.defaultDictionarySize || DEFAULT_DICTIONARY_SIZE;
26
- }
27
- async readHeader() {
28
- const buffer = await this.read(0, constants_1.PARQUET_MAGIC.length);
29
- const magic = buffer.toString();
30
- switch (magic) {
31
- case constants_1.PARQUET_MAGIC:
32
- break;
33
- case constants_1.PARQUET_MAGIC_ENCRYPTED:
34
- throw new Error('Encrypted parquet file not supported');
35
- default:
36
- throw new Error(`Invalid parquet file (magic=${magic})`);
37
- }
38
- }
39
- async readRowGroup(schema, rowGroup, columnList) {
40
- const buffer = {
41
- rowCount: Number(rowGroup.num_rows),
42
- columnData: {}
43
- };
44
- for (const colChunk of rowGroup.columns) {
45
- const colMetadata = colChunk.meta_data;
46
- const colKey = colMetadata?.path_in_schema;
47
- if (columnList.length > 0 && (0, read_utils_1.fieldIndexOf)(columnList, colKey) < 0) {
48
- continue; // eslint-disable-line no-continue
49
- }
50
- buffer.columnData[colKey.join()] = await this.readColumnChunk(schema, colChunk);
51
- }
52
- return buffer;
53
- }
54
- /**
55
- * Do reading of parquet file's column chunk
56
- * @param schema
57
- * @param colChunk
58
- */
59
- async readColumnChunk(schema, colChunk) {
60
- if (colChunk.file_path !== undefined && colChunk.file_path !== null) {
61
- throw new Error('external references are not supported');
62
- }
63
- const field = schema.findField(colChunk.meta_data?.path_in_schema);
64
- const type = (0, read_utils_1.getThriftEnum)(parquet_thrift_1.Type, colChunk.meta_data?.type);
65
- if (type !== field.primitiveType) {
66
- throw new Error(`chunk type not matching schema: ${type}`);
67
- }
68
- const compression = (0, read_utils_1.getThriftEnum)(parquet_thrift_1.CompressionCodec, colChunk.meta_data?.codec);
69
- const pagesOffset = Number(colChunk.meta_data?.data_page_offset);
70
- let pagesSize = Number(colChunk.meta_data?.total_compressed_size);
71
- if (!colChunk.file_path) {
72
- pagesSize = Math.min(this.fileSize - pagesOffset, Number(colChunk.meta_data?.total_compressed_size));
73
- }
74
- const options = {
75
- type,
76
- rLevelMax: field.rLevelMax,
77
- dLevelMax: field.dLevelMax,
78
- compression,
79
- column: field,
80
- numValues: colChunk.meta_data?.num_values,
81
- dictionary: []
82
- };
83
- let dictionary;
84
- const dictionaryPageOffset = colChunk?.meta_data?.dictionary_page_offset;
85
- if (dictionaryPageOffset) {
86
- const dictionaryOffset = Number(dictionaryPageOffset);
87
- // Getting dictionary from column chunk to iterate all over indexes to get dataPage values.
88
- dictionary = await this.getDictionary(dictionaryOffset, options, pagesOffset);
89
- }
90
- dictionary = options.dictionary?.length ? options.dictionary : dictionary;
91
- const pagesBuf = await this.read(pagesOffset, pagesSize);
92
- return await (0, decoders_1.decodeDataPages)(pagesBuf, { ...options, dictionary });
93
- }
94
- /**
95
- * Getting dictionary for allows to flatten values by indices.
96
- * @param dictionaryPageOffset
97
- * @param options
98
- * @param pagesOffset
99
- * @returns
100
- */
101
- async getDictionary(dictionaryPageOffset, options, pagesOffset) {
102
- if (dictionaryPageOffset === 0) {
103
- // dictionarySize = Math.min(this.fileSize - pagesOffset, this.defaultDictionarySize);
104
- // pagesBuf = await this.read(pagesOffset, dictionarySize);
105
- // In this case we are working with parquet-mr files format. Problem is described below:
106
- // https://stackoverflow.com/questions/55225108/why-is-dictionary-page-offset-0-for-plain-dictionary-encoding
107
- // We need to get dictionary page from column chunk if it exists.
108
- // Now if we use code commented above we don't get DICTIONARY_PAGE we get DATA_PAGE instead.
109
- return [];
110
- }
111
- const dictionarySize = Math.min(this.fileSize - dictionaryPageOffset, this.defaultDictionarySize);
112
- const pagesBuf = await this.read(dictionaryPageOffset, dictionarySize);
113
- const cursor = { buffer: pagesBuf, offset: 0, size: pagesBuf.length };
114
- const decodedPage = await (0, decoders_1.decodePage)(cursor, options);
115
- return decodedPage.dictionary;
116
- }
117
- async readFooter() {
118
- const trailerLen = constants_1.PARQUET_MAGIC.length + 4;
119
- const trailerBuf = await this.read(this.fileSize - trailerLen, trailerLen);
120
- const magic = trailerBuf.slice(4).toString();
121
- if (magic !== constants_1.PARQUET_MAGIC) {
122
- throw new Error(`Not a valid parquet file (magic="${magic})`);
123
- }
124
- const metadataSize = trailerBuf.readUInt32LE(0);
125
- const metadataOffset = this.fileSize - metadataSize - trailerLen;
126
- if (metadataOffset < constants_1.PARQUET_MAGIC.length) {
127
- throw new Error(`Invalid metadata size ${metadataOffset}`);
128
- }
129
- const metadataBuf = await this.read(metadataOffset, metadataSize);
130
- // let metadata = new parquet_thrift.FileMetaData();
131
- // parquet_util.decodeThrift(metadata, metadataBuf);
132
- const { metadata } = (0, read_utils_1.decodeFileMetadata)(metadataBuf);
133
- return metadata;
134
- }
135
- }
136
- exports.ParquetEnvelopeReader = ParquetEnvelopeReader;
@@ -1,10 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Convert Buffer to ArrayBuffer
4
- */
5
- export declare function toArrayBuffer(buffer: Buffer): ArrayBuffer;
6
- /**
7
- * Convert (copy) ArrayBuffer to Buffer
8
- */
9
- export declare function toBuffer(arrayBuffer: ArrayBuffer): Buffer;
10
- //# sourceMappingURL=buffer-utils.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,22 +0,0 @@
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;
@@ -1,90 +0,0 @@
1
- // Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
2
- import fs from 'fs';
3
-
4
- export function fopen(filePath) {
5
- return new Promise((resolve, reject) => {
6
- fs.open(filePath, 'r', (err, fd) => {
7
- if (err) {
8
- reject(err);
9
- } else {
10
- resolve(fd);
11
- }
12
- });
13
- });
14
- }
15
-
16
- export function fstat(filePath) {
17
- return new Promise<fs.Stats>((resolve, reject) => {
18
- fs.stat(filePath, (err, stat) => {
19
- if (err) {
20
- reject(err);
21
- } else {
22
- resolve(stat);
23
- }
24
- });
25
- });
26
- }
27
-
28
- export function fread(fd, position, length) {
29
- const buffer = Buffer.alloc(length);
30
-
31
- return new Promise((resolve, reject) => {
32
- fs.read(fd, buffer, 0, length, position, (err, bytesRead, buf) => {
33
- if (err || bytesRead !== length) {
34
- reject(err || Error('read failed'));
35
- } else {
36
- resolve(buf);
37
- }
38
- });
39
- });
40
- }
41
-
42
- export function fclose(fd) {
43
- return new Promise((resolve, reject) => {
44
- fs.close(fd, (err) => {
45
- if (err) {
46
- reject(err);
47
- } else {
48
- resolve(err);
49
- }
50
- });
51
- });
52
- }
53
-
54
- export function oswrite(os, buf): Promise<void> {
55
- return new Promise((resolve, reject) => {
56
- os.write(buf, (err) => {
57
- if (err) {
58
- reject(err);
59
- } else {
60
- resolve();
61
- }
62
- });
63
- });
64
- }
65
-
66
- export function osclose(os): Promise<void> {
67
- return new Promise((resolve, reject) => {
68
- os.close((err) => {
69
- if (err) {
70
- reject(err);
71
- } else {
72
- resolve();
73
- }
74
- });
75
- });
76
- }
77
-
78
- export function osopen(path, opts) {
79
- return new Promise((resolve, reject) => {
80
- const outputStream = fs.createWriteStream(path, opts);
81
-
82
- outputStream.on('open', function (fd) {
83
- resolve(outputStream);
84
- });
85
-
86
- outputStream.on('error', function (err) {
87
- reject(err);
88
- });
89
- });
90
- }
@@ -1,94 +0,0 @@
1
- // Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
2
- import {FileMetaData} from '../parquet-thrift';
3
- import {ParquetEnvelopeReader} from './parquet-envelope-reader';
4
- import {ParquetSchema} from '../schema/schema';
5
- import {ParquetRecord} from '../schema/declare';
6
- import {materializeRecords} from '../schema/shred';
7
-
8
- /**
9
- * A parquet cursor is used to retrieve rows from a parquet file in order
10
- */
11
- export class ParquetCursor<T> implements AsyncIterable<T> {
12
- public metadata: FileMetaData;
13
- public envelopeReader: ParquetEnvelopeReader;
14
- public schema: ParquetSchema;
15
- public columnList: string[][];
16
- public rowGroup: ParquetRecord[] = [];
17
- public rowGroupIndex: number;
18
-
19
- /**
20
- * Create a new parquet reader from the file metadata and an envelope reader.
21
- * It is usually not recommended to call this constructor directly except for
22
- * advanced and internal use cases. Consider using getCursor() on the
23
- * ParquetReader instead
24
- */
25
- constructor(
26
- metadata: FileMetaData,
27
- envelopeReader: ParquetEnvelopeReader,
28
- schema: ParquetSchema,
29
- columnList: string[][]
30
- ) {
31
- this.metadata = metadata;
32
- this.envelopeReader = envelopeReader;
33
- this.schema = schema;
34
- this.columnList = columnList;
35
- this.rowGroupIndex = 0;
36
- }
37
-
38
- /**
39
- * Retrieve the next row from the cursor. Returns a row or NULL if the end
40
- * of the file was reached
41
- */
42
- async next<T = any>(): Promise<T> {
43
- if (this.rowGroup.length === 0) {
44
- if (this.rowGroupIndex >= this.metadata.row_groups.length) {
45
- // @ts-ignore
46
- return null;
47
- }
48
- const rowBuffer = await this.envelopeReader.readRowGroup(
49
- this.schema,
50
- this.metadata.row_groups[this.rowGroupIndex],
51
- this.columnList
52
- );
53
- this.rowGroup = materializeRecords(this.schema, rowBuffer);
54
- this.rowGroupIndex++;
55
- }
56
- return this.rowGroup.shift() as any;
57
- }
58
-
59
- /**
60
- * Rewind the cursor the the beginning of the file
61
- */
62
- rewind(): void {
63
- this.rowGroup = [];
64
- this.rowGroupIndex = 0;
65
- }
66
-
67
- /**
68
- * Implement AsyncIterable
69
- */
70
- // tslint:disable-next-line:function-name
71
- [Symbol.asyncIterator](): AsyncIterator<T> {
72
- let done = false;
73
- return {
74
- next: async () => {
75
- if (done) {
76
- return {done, value: null};
77
- }
78
- const value = await this.next();
79
- if (value === null) {
80
- return {done: true, value};
81
- }
82
- return {done: false, value};
83
- },
84
- return: async () => {
85
- done = true;
86
- return {done, value: null};
87
- },
88
- throw: async () => {
89
- done = true;
90
- return {done: true, value: null};
91
- }
92
- };
93
- }
94
- }
@@ -1,199 +0,0 @@
1
- // Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
2
- import {ParquetSchema} from '../schema/schema';
3
- import {PARQUET_MAGIC, PARQUET_MAGIC_ENCRYPTED} from '../../constants';
4
- import {ColumnChunk, CompressionCodec, FileMetaData, RowGroup, Type} from '../parquet-thrift';
5
- import {
6
- ParquetBuffer,
7
- ParquetCompression,
8
- ParquetData,
9
- PrimitiveType,
10
- ParquetOptions
11
- } from '../schema/declare';
12
- import {decodeFileMetadata, getThriftEnum, fieldIndexOf} from '../utils/read-utils';
13
- import {decodeDataPages, decodePage} from './decoders';
14
-
15
- const DEFAULT_DICTIONARY_SIZE = 1e6;
16
-
17
- /**
18
- * The parquet envelope reader allows direct, unbuffered access to the individual
19
- * sections of the parquet file, namely the header, footer and the row groups.
20
- * This class is intended for advanced/internal users; if you just want to retrieve
21
- * rows from a parquet file use the ParquetReader instead
22
- */
23
- export class ParquetEnvelopeReader {
24
- public read: (position: number, length: number) => Promise<Buffer>;
25
- /**
26
- * Close this parquet reader. You MUST call this method once you're finished
27
- * reading rows
28
- */
29
- public close: () => Promise<void>;
30
- public fileSize: number;
31
- public defaultDictionarySize: number;
32
-
33
- static async openBuffer(buffer: Buffer): Promise<ParquetEnvelopeReader> {
34
- const readFn = (position: number, length: number) =>
35
- Promise.resolve(buffer.slice(position, position + length));
36
- const closeFn = () => Promise.resolve();
37
- return new ParquetEnvelopeReader(readFn, closeFn, buffer.length);
38
- }
39
-
40
- constructor(
41
- read: (position: number, length: number) => Promise<Buffer>,
42
- close: () => Promise<void>,
43
- fileSize: number,
44
- options?: any
45
- ) {
46
- this.read = read;
47
- this.close = close;
48
- this.fileSize = fileSize;
49
- this.defaultDictionarySize = options?.defaultDictionarySize || DEFAULT_DICTIONARY_SIZE;
50
- }
51
-
52
- async readHeader(): Promise<void> {
53
- const buffer = await this.read(0, PARQUET_MAGIC.length);
54
-
55
- const magic = buffer.toString();
56
- switch (magic) {
57
- case PARQUET_MAGIC:
58
- break;
59
- case PARQUET_MAGIC_ENCRYPTED:
60
- throw new Error('Encrypted parquet file not supported');
61
- default:
62
- throw new Error(`Invalid parquet file (magic=${magic})`);
63
- }
64
- }
65
-
66
- async readRowGroup(
67
- schema: ParquetSchema,
68
- rowGroup: RowGroup,
69
- columnList: string[][]
70
- ): Promise<ParquetBuffer> {
71
- const buffer: ParquetBuffer = {
72
- rowCount: Number(rowGroup.num_rows),
73
- columnData: {}
74
- };
75
- for (const colChunk of rowGroup.columns) {
76
- const colMetadata = colChunk.meta_data;
77
- const colKey = colMetadata?.path_in_schema;
78
- if (columnList.length > 0 && fieldIndexOf(columnList, colKey!) < 0) {
79
- continue; // eslint-disable-line no-continue
80
- }
81
- buffer.columnData[colKey!.join()] = await this.readColumnChunk(schema, colChunk);
82
- }
83
- return buffer;
84
- }
85
-
86
- /**
87
- * Do reading of parquet file's column chunk
88
- * @param schema
89
- * @param colChunk
90
- */
91
- async readColumnChunk(schema: ParquetSchema, colChunk: ColumnChunk): Promise<ParquetData> {
92
- if (colChunk.file_path !== undefined && colChunk.file_path !== null) {
93
- throw new Error('external references are not supported');
94
- }
95
-
96
- const field = schema.findField(colChunk.meta_data?.path_in_schema!);
97
- const type: PrimitiveType = getThriftEnum(Type, colChunk.meta_data?.type!) as any;
98
-
99
- if (type !== field.primitiveType) {
100
- throw new Error(`chunk type not matching schema: ${type}`);
101
- }
102
-
103
- const compression: ParquetCompression = getThriftEnum(
104
- CompressionCodec,
105
- colChunk.meta_data?.codec!
106
- ) as any;
107
-
108
- const pagesOffset = Number(colChunk.meta_data?.data_page_offset!);
109
- let pagesSize = Number(colChunk.meta_data?.total_compressed_size!);
110
-
111
- if (!colChunk.file_path) {
112
- pagesSize = Math.min(
113
- this.fileSize - pagesOffset,
114
- Number(colChunk.meta_data?.total_compressed_size)
115
- );
116
- }
117
-
118
- const options: ParquetOptions = {
119
- type,
120
- rLevelMax: field.rLevelMax,
121
- dLevelMax: field.dLevelMax,
122
- compression,
123
- column: field,
124
- numValues: colChunk.meta_data?.num_values,
125
- dictionary: []
126
- };
127
-
128
- let dictionary;
129
-
130
- const dictionaryPageOffset = colChunk?.meta_data?.dictionary_page_offset;
131
-
132
- if (dictionaryPageOffset) {
133
- const dictionaryOffset = Number(dictionaryPageOffset);
134
- // Getting dictionary from column chunk to iterate all over indexes to get dataPage values.
135
- dictionary = await this.getDictionary(dictionaryOffset, options, pagesOffset);
136
- }
137
-
138
- dictionary = options.dictionary?.length ? options.dictionary : dictionary;
139
- const pagesBuf = await this.read(pagesOffset, pagesSize);
140
- return await decodeDataPages(pagesBuf, {...options, dictionary});
141
- }
142
-
143
- /**
144
- * Getting dictionary for allows to flatten values by indices.
145
- * @param dictionaryPageOffset
146
- * @param options
147
- * @param pagesOffset
148
- * @returns
149
- */
150
- async getDictionary(
151
- dictionaryPageOffset: number,
152
- options: ParquetOptions,
153
- pagesOffset: number
154
- ): Promise<string[]> {
155
- if (dictionaryPageOffset === 0) {
156
- // dictionarySize = Math.min(this.fileSize - pagesOffset, this.defaultDictionarySize);
157
- // pagesBuf = await this.read(pagesOffset, dictionarySize);
158
-
159
- // In this case we are working with parquet-mr files format. Problem is described below:
160
- // https://stackoverflow.com/questions/55225108/why-is-dictionary-page-offset-0-for-plain-dictionary-encoding
161
- // We need to get dictionary page from column chunk if it exists.
162
- // Now if we use code commented above we don't get DICTIONARY_PAGE we get DATA_PAGE instead.
163
- return [];
164
- }
165
-
166
- const dictionarySize = Math.min(
167
- this.fileSize - dictionaryPageOffset,
168
- this.defaultDictionarySize
169
- );
170
- const pagesBuf = await this.read(dictionaryPageOffset, dictionarySize);
171
-
172
- const cursor = {buffer: pagesBuf, offset: 0, size: pagesBuf.length};
173
- const decodedPage = await decodePage(cursor, options);
174
-
175
- return decodedPage.dictionary!;
176
- }
177
-
178
- async readFooter(): Promise<FileMetaData> {
179
- const trailerLen = PARQUET_MAGIC.length + 4;
180
- const trailerBuf = await this.read(this.fileSize - trailerLen, trailerLen);
181
-
182
- const magic = trailerBuf.slice(4).toString();
183
- if (magic !== PARQUET_MAGIC) {
184
- throw new Error(`Not a valid parquet file (magic="${magic})`);
185
- }
186
-
187
- const metadataSize = trailerBuf.readUInt32LE(0);
188
- const metadataOffset = this.fileSize - metadataSize - trailerLen;
189
- if (metadataOffset < PARQUET_MAGIC.length) {
190
- throw new Error(`Invalid metadata size ${metadataOffset}`);
191
- }
192
-
193
- const metadataBuf = await this.read(metadataOffset, metadataSize);
194
- // let metadata = new parquet_thrift.FileMetaData();
195
- // parquet_util.decodeThrift(metadata, metadataBuf);
196
- const {metadata} = decodeFileMetadata(metadataBuf);
197
- return metadata;
198
- }
199
- }