@loaders.gl/parquet 4.4.2 → 5.0.0-alpha.1

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 (267) hide show
  1. package/dist/bundled.d.ts +6 -0
  2. package/dist/bundled.d.ts.map +1 -0
  3. package/dist/bundled.js +7 -0
  4. package/dist/bundled.js.map +1 -0
  5. package/dist/geoparquet-loader-with-parser.d.ts +34 -0
  6. package/dist/geoparquet-loader-with-parser.d.ts.map +1 -0
  7. package/dist/geoparquet-loader-with-parser.js +52 -0
  8. package/dist/geoparquet-loader-with-parser.js.map +1 -0
  9. package/dist/geoparquet-loader.d.ts +61 -0
  10. package/dist/geoparquet-loader.d.ts.map +1 -0
  11. package/dist/geoparquet-loader.js +30 -0
  12. package/dist/geoparquet-loader.js.map +1 -0
  13. package/dist/index.cjs +5879 -5643
  14. package/dist/index.cjs.map +4 -4
  15. package/dist/index.d.ts +7 -7
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5 -11
  18. package/dist/index.js.map +1 -1
  19. package/dist/lib/constants.d.ts +1 -1
  20. package/dist/lib/constants.js +2 -2
  21. package/dist/lib/constants.js.map +1 -1
  22. package/dist/lib/encoders/encode-arrow-to-parquet.d.ts +2 -2
  23. package/dist/lib/encoders/encode-arrow-to-parquet.d.ts.map +1 -1
  24. package/dist/lib/encoders/encode-arrow-to-parquet.js +3 -10
  25. package/dist/lib/encoders/encode-arrow-to-parquet.js.map +1 -1
  26. package/dist/lib/encoders/encode-table-to-parquet-js.d.ts +5 -0
  27. package/dist/lib/encoders/encode-table-to-parquet-js.d.ts.map +1 -0
  28. package/dist/lib/encoders/encode-table-to-parquet-js.js +149 -0
  29. package/dist/lib/encoders/encode-table-to-parquet-js.js.map +1 -0
  30. package/dist/lib/geo/geospatial-metadata.d.ts +67 -0
  31. package/dist/lib/geo/geospatial-metadata.d.ts.map +1 -0
  32. package/dist/lib/geo/geospatial-metadata.js +357 -0
  33. package/dist/lib/geo/geospatial-metadata.js.map +1 -0
  34. package/dist/lib/parsers/get-parquet-schema.d.ts.map +1 -1
  35. package/dist/lib/parsers/get-parquet-schema.js +3 -1
  36. package/dist/lib/parsers/get-parquet-schema.js.map +1 -1
  37. package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts +4 -4
  38. package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts.map +1 -1
  39. package/dist/lib/parsers/parse-geoparquet-to-geojson.js +19 -6
  40. package/dist/lib/parsers/parse-geoparquet-to-geojson.js.map +1 -1
  41. package/dist/lib/parsers/parse-parquet-tables.d.ts +50 -0
  42. package/dist/lib/parsers/parse-parquet-tables.d.ts.map +1 -0
  43. package/dist/lib/parsers/parse-parquet-tables.js +101 -0
  44. package/dist/lib/parsers/parse-parquet-tables.js.map +1 -0
  45. package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts +6 -0
  46. package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts.map +1 -0
  47. package/dist/lib/parsers/parse-parquet-to-arrow-js.js +23 -0
  48. package/dist/lib/parsers/parse-parquet-to-arrow-js.js.map +1 -0
  49. package/dist/lib/parsers/parse-parquet-to-arrow.d.ts +7 -7
  50. package/dist/lib/parsers/parse-parquet-to-arrow.d.ts.map +1 -1
  51. package/dist/lib/parsers/parse-parquet-to-arrow.js +45 -32
  52. package/dist/lib/parsers/parse-parquet-to-arrow.js.map +1 -1
  53. package/dist/lib/parsers/parse-parquet-to-columns.d.ts +3 -3
  54. package/dist/lib/parsers/parse-parquet-to-columns.d.ts.map +1 -1
  55. package/dist/lib/parsers/parse-parquet-to-columns.js +1 -4
  56. package/dist/lib/parsers/parse-parquet-to-columns.js.map +1 -1
  57. package/dist/lib/parsers/parse-parquet-to-json.d.ts +3 -3
  58. package/dist/lib/parsers/parse-parquet-to-json.d.ts.map +1 -1
  59. package/dist/lib/parsers/parse-parquet-to-json.js +77 -26
  60. package/dist/lib/parsers/parse-parquet-to-json.js.map +1 -1
  61. package/dist/lib/utils/load-wasm.d.ts +2 -2
  62. package/dist/lib/utils/load-wasm.d.ts.map +1 -1
  63. package/dist/lib/utils/load-wasm.js +7 -7
  64. package/dist/lib/utils/load-wasm.js.map +1 -1
  65. package/dist/lib/utils/make-stream-iterator.js +1 -1
  66. package/dist/lib/utils/make-stream-iterator.js.map +1 -1
  67. package/dist/lib/utils/normalize-parquet-options.d.ts +5 -0
  68. package/dist/lib/utils/normalize-parquet-options.d.ts.map +1 -0
  69. package/dist/lib/utils/normalize-parquet-options.js +11 -0
  70. package/dist/lib/utils/normalize-parquet-options.js.map +1 -0
  71. package/dist/parquet-format.d.ts +2 -0
  72. package/dist/parquet-format.d.ts.map +1 -1
  73. package/dist/parquet-format.js +2 -0
  74. package/dist/parquet-format.js.map +1 -1
  75. package/dist/parquet-js-loader.d.ts +57 -0
  76. package/dist/parquet-js-loader.d.ts.map +1 -0
  77. package/dist/parquet-js-loader.js +33 -0
  78. package/dist/parquet-js-loader.js.map +1 -0
  79. package/dist/parquet-js-writer.d.ts +34 -0
  80. package/dist/parquet-js-writer.d.ts.map +1 -0
  81. package/dist/parquet-js-writer.js +28 -0
  82. package/dist/parquet-js-writer.js.map +1 -0
  83. package/dist/parquet-loader-options.d.ts +56 -0
  84. package/dist/parquet-loader-options.d.ts.map +1 -0
  85. package/dist/parquet-loader-options.js +11 -0
  86. package/dist/parquet-loader-options.js.map +1 -0
  87. package/dist/parquet-loader-with-parser.d.ts +33 -0
  88. package/dist/parquet-loader-with-parser.d.ts.map +1 -0
  89. package/dist/parquet-loader-with-parser.js +40 -0
  90. package/dist/parquet-loader-with-parser.js.map +1 -0
  91. package/dist/parquet-loader.d.ts +62 -0
  92. package/dist/parquet-loader.d.ts.map +1 -0
  93. package/dist/parquet-loader.js +53 -0
  94. package/dist/parquet-loader.js.map +1 -0
  95. package/dist/parquet-wasm-loader-with-parser.d.ts +40 -0
  96. package/dist/parquet-wasm-loader-with-parser.d.ts.map +1 -0
  97. package/dist/parquet-wasm-loader-with-parser.js +68 -0
  98. package/dist/parquet-wasm-loader-with-parser.js.map +1 -0
  99. package/dist/parquet-writer.d.ts +10 -0
  100. package/dist/parquet-writer.d.ts.map +1 -0
  101. package/dist/parquet-writer.js +29 -0
  102. package/dist/parquet-writer.js.map +1 -0
  103. package/dist/parquet_wasm_bg.wasm +0 -0
  104. package/dist/parquetjs/codecs/declare.d.ts +2 -2
  105. package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
  106. package/dist/parquetjs/codecs/dictionary.js +1 -1
  107. package/dist/parquetjs/codecs/dictionary.js.map +1 -1
  108. package/dist/parquetjs/codecs/plain.d.ts +1 -1
  109. package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
  110. package/dist/parquetjs/codecs/plain.js +36 -41
  111. package/dist/parquetjs/codecs/plain.js.map +1 -1
  112. package/dist/parquetjs/codecs/rle.d.ts +1 -1
  113. package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
  114. package/dist/parquetjs/codecs/rle.js +16 -21
  115. package/dist/parquetjs/codecs/rle.js.map +1 -1
  116. package/dist/parquetjs/compression.d.ts +2 -3
  117. package/dist/parquetjs/compression.d.ts.map +1 -1
  118. package/dist/parquetjs/compression.js +4 -105
  119. package/dist/parquetjs/compression.js.map +1 -1
  120. package/dist/parquetjs/encoder/parquet-encoder.d.ts +4 -4
  121. package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
  122. package/dist/parquetjs/encoder/parquet-encoder.js +38 -33
  123. package/dist/parquetjs/encoder/parquet-encoder.js.map +1 -1
  124. package/dist/parquetjs/parquet-thrift/ColumnIndex.js +1 -1
  125. package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +1 -1
  126. package/dist/parquetjs/parquet-thrift/index.d.ts +0 -1
  127. package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
  128. package/dist/parquetjs/parquet-thrift/index.js +0 -1
  129. package/dist/parquetjs/parquet-thrift/index.js.map +1 -1
  130. package/dist/parquetjs/parser/decoders.d.ts +1 -1
  131. package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
  132. package/dist/parquetjs/parser/decoders.js +4 -22
  133. package/dist/parquetjs/parser/decoders.js.map +1 -1
  134. package/dist/parquetjs/parser/parquet-reader.d.ts +1 -1
  135. package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
  136. package/dist/parquetjs/parser/parquet-reader.js +9 -9
  137. package/dist/parquetjs/parser/parquet-reader.js.map +1 -1
  138. package/dist/parquetjs/schema/declare.d.ts +1 -1
  139. package/dist/parquetjs/schema/declare.d.ts.map +1 -1
  140. package/dist/parquetjs/schema/types.d.ts.map +1 -1
  141. package/dist/parquetjs/schema/types.js +36 -35
  142. package/dist/parquetjs/schema/types.js.map +1 -1
  143. package/dist/parquetjs/utils/binary-utils.d.ts +39 -0
  144. package/dist/parquetjs/utils/binary-utils.d.ts.map +1 -0
  145. package/dist/parquetjs/utils/binary-utils.js +102 -0
  146. package/dist/parquetjs/utils/binary-utils.js.map +1 -0
  147. package/dist/parquetjs/utils/file-utils.d.ts +1 -1
  148. package/dist/parquetjs/utils/file-utils.d.ts.map +1 -1
  149. package/dist/parquetjs/utils/file-utils.js +3 -3
  150. package/dist/parquetjs/utils/file-utils.js.map +1 -1
  151. package/dist/parquetjs/utils/read-utils.d.ts +4 -4
  152. package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
  153. package/dist/parquetjs/utils/read-utils.js +12 -17
  154. package/dist/parquetjs/utils/read-utils.js.map +1 -1
  155. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts +78 -0
  156. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts.map +1 -0
  157. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js +213 -0
  158. package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js.map +1 -0
  159. package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts +78 -0
  160. package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts.map +1 -0
  161. package/dist/parquetjs/utils/uint8-array-compact-protocol.js +276 -0
  162. package/dist/parquetjs/utils/uint8-array-compact-protocol.js.map +1 -0
  163. package/dist/parquetjs/utils/uint8-array-transport.d.ts +25 -0
  164. package/dist/parquetjs/utils/uint8-array-transport.d.ts.map +1 -0
  165. package/dist/parquetjs/utils/uint8-array-transport.js +62 -0
  166. package/dist/parquetjs/utils/uint8-array-transport.js.map +1 -0
  167. package/dist/unbundled.d.ts +6 -0
  168. package/dist/unbundled.d.ts.map +1 -0
  169. package/dist/unbundled.js +7 -0
  170. package/dist/unbundled.js.map +1 -0
  171. package/package.json +21 -25
  172. package/src/bundled.ts +9 -0
  173. package/src/geoparquet-loader-with-parser.ts +95 -0
  174. package/src/geoparquet-loader.ts +54 -0
  175. package/src/index.ts +7 -25
  176. package/src/lib/constants.ts +1 -1
  177. package/src/lib/encoders/encode-arrow-to-parquet.ts +9 -15
  178. package/src/lib/encoders/encode-table-to-parquet-js.ts +199 -0
  179. package/src/lib/geo/geospatial-metadata.ts +507 -0
  180. package/src/lib/parsers/get-parquet-schema.ts +3 -1
  181. package/src/lib/parsers/parse-geoparquet-to-geojson.ts +27 -14
  182. package/src/lib/parsers/parse-parquet-tables.ts +137 -0
  183. package/src/lib/parsers/parse-parquet-to-arrow-js.ts +36 -0
  184. package/src/lib/parsers/parse-parquet-to-arrow.ts +63 -36
  185. package/src/lib/parsers/parse-parquet-to-columns.ts +6 -7
  186. package/src/lib/parsers/parse-parquet-to-json.ts +101 -33
  187. package/src/lib/utils/load-wasm.ts +16 -9
  188. package/src/lib/utils/make-stream-iterator.ts +1 -1
  189. package/src/lib/utils/normalize-parquet-options.ts +14 -0
  190. package/src/parquet-format.ts +2 -0
  191. package/src/parquet-js-loader.ts +43 -0
  192. package/src/parquet-js-writer.ts +52 -0
  193. package/src/parquet-loader-options.ts +63 -0
  194. package/src/parquet-loader-with-parser.ts +68 -0
  195. package/src/parquet-loader.ts +79 -0
  196. package/src/parquet-wasm-loader-with-parser.ts +115 -0
  197. package/src/parquet-writer.ts +44 -0
  198. package/src/parquetjs/codecs/declare.ts +2 -2
  199. package/src/parquetjs/codecs/dictionary.ts +1 -1
  200. package/src/parquetjs/codecs/plain.ts +67 -53
  201. package/src/parquetjs/codecs/rle.ts +20 -26
  202. package/src/parquetjs/compression.ts +7 -114
  203. package/src/parquetjs/encoder/parquet-encoder.ts +49 -43
  204. package/src/parquetjs/parquet-thrift/ColumnIndex.ts +1 -1
  205. package/src/parquetjs/parquet-thrift/index.ts +0 -2
  206. package/src/parquetjs/parser/decoders.ts +5 -23
  207. package/src/parquetjs/parser/parquet-reader.ts +10 -12
  208. package/src/parquetjs/schema/declare.ts +1 -1
  209. package/src/parquetjs/schema/types.ts +48 -40
  210. package/src/parquetjs/utils/binary-utils.ts +127 -0
  211. package/src/parquetjs/utils/file-utils.ts +4 -4
  212. package/src/parquetjs/utils/read-utils.ts +19 -34
  213. package/src/parquetjs/utils/uint8-array-compact-protocol-writer.ts +254 -0
  214. package/src/parquetjs/utils/uint8-array-compact-protocol.ts +322 -0
  215. package/src/parquetjs/utils/uint8-array-transport.ts +79 -0
  216. package/src/unbundled.ts +9 -0
  217. package/dist/parquet-arrow-loader.d.ts +0 -43
  218. package/dist/parquet-arrow-loader.d.ts.map +0 -1
  219. package/dist/parquet-arrow-loader.js +0 -49
  220. package/dist/parquet-arrow-loader.js.map +0 -1
  221. package/dist/parquet-arrow-writer.d.ts +0 -9
  222. package/dist/parquet-arrow-writer.d.ts.map +0 -1
  223. package/dist/parquet-arrow-writer.js +0 -23
  224. package/dist/parquet-arrow-writer.js.map +0 -1
  225. package/dist/parquet-json-loader.d.ts +0 -148
  226. package/dist/parquet-json-loader.d.ts.map +0 -1
  227. package/dist/parquet-json-loader.js +0 -106
  228. package/dist/parquet-json-loader.js.map +0 -1
  229. package/dist/parquet-json-writer.d.ts +0 -19
  230. package/dist/parquet-json-writer.d.ts.map +0 -1
  231. package/dist/parquet-json-writer.js +0 -20
  232. package/dist/parquet-json-writer.js.map +0 -1
  233. package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts +0 -3
  234. package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts.map +0 -1
  235. package/dist/polyfills/buffer/buffer-polyfill.browser.js +0 -12
  236. package/dist/polyfills/buffer/buffer-polyfill.browser.js.map +0 -1
  237. package/dist/polyfills/buffer/buffer-polyfill.node.d.ts +0 -3
  238. package/dist/polyfills/buffer/buffer-polyfill.node.d.ts.map +0 -1
  239. package/dist/polyfills/buffer/buffer-polyfill.node.js +0 -17
  240. package/dist/polyfills/buffer/buffer-polyfill.node.js.map +0 -1
  241. package/dist/polyfills/buffer/buffer.d.ts +0 -222
  242. package/dist/polyfills/buffer/buffer.d.ts.map +0 -1
  243. package/dist/polyfills/buffer/buffer.js +0 -1868
  244. package/dist/polyfills/buffer/buffer.js.map +0 -1
  245. package/dist/polyfills/buffer/index.d.ts +0 -4
  246. package/dist/polyfills/buffer/index.d.ts.map +0 -1
  247. package/dist/polyfills/buffer/index.js +0 -9
  248. package/dist/polyfills/buffer/index.js.map +0 -1
  249. package/dist/polyfills/buffer/install-buffer-polyfill.d.ts +0 -2
  250. package/dist/polyfills/buffer/install-buffer-polyfill.d.ts.map +0 -1
  251. package/dist/polyfills/buffer/install-buffer-polyfill.js +0 -10
  252. package/dist/polyfills/buffer/install-buffer-polyfill.js.map +0 -1
  253. package/dist/workers/parquet-json-worker.d.ts +0 -2
  254. package/dist/workers/parquet-json-worker.d.ts.map +0 -1
  255. package/dist/workers/parquet-json-worker.js +0 -7
  256. package/dist/workers/parquet-json-worker.js.map +0 -1
  257. package/src/parquet-arrow-loader.ts +0 -74
  258. package/src/parquet-arrow-writer.ts +0 -33
  259. package/src/parquet-json-loader.ts +0 -160
  260. package/src/parquet-json-writer.ts +0 -27
  261. package/src/parquetjs/modules.d.ts +0 -25
  262. package/src/polyfills/buffer/buffer-polyfill.browser.ts +0 -14
  263. package/src/polyfills/buffer/buffer-polyfill.node.ts +0 -19
  264. package/src/polyfills/buffer/buffer.ts +0 -2205
  265. package/src/polyfills/buffer/index.ts +0 -11
  266. package/src/polyfills/buffer/install-buffer-polyfill.ts +0 -12
  267. package/src/workers/parquet-json-worker.ts +0 -8
@@ -0,0 +1,254 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import * as thrift from 'thrift';
6
+ import {concatUint8Arrays, encodeUtf8, toUint8Array, writeDoubleLE} from './binary-utils';
7
+
8
+ const COMPACT_TYPE_STOP = 0x00;
9
+ const COMPACT_TYPE_BOOLEAN_TRUE = 0x01;
10
+ const COMPACT_TYPE_BOOLEAN_FALSE = 0x02;
11
+ const COMPACT_TYPE_BYTE = 0x03;
12
+ const COMPACT_TYPE_I16 = 0x04;
13
+ const COMPACT_TYPE_I32 = 0x05;
14
+ const COMPACT_TYPE_I64 = 0x06;
15
+ const COMPACT_TYPE_DOUBLE = 0x07;
16
+ const COMPACT_TYPE_BINARY = 0x08;
17
+ const COMPACT_TYPE_LIST = 0x09;
18
+ const COMPACT_TYPE_SET = 0x0a;
19
+ const COMPACT_TYPE_MAP = 0x0b;
20
+ const COMPACT_TYPE_STRUCT = 0x0c;
21
+
22
+ type Int64Like = number | bigint | {toString(radix?: number): string; valueOf?: () => number};
23
+
24
+ /** Write-only Thrift compact protocol that assembles exact Uint8Array output. */
25
+ export class Uint8ArrayCompactProtocolWriter {
26
+ /** Serialized byte chunks accumulated by thrift write calls. */
27
+ private readonly chunks: Uint8Array[] = [];
28
+
29
+ /** Field id at the current nesting depth, used to emit compact field-id deltas. */
30
+ private lastFieldId = 0;
31
+
32
+ /** Parent struct field ids restored when nested structs end. */
33
+ private readonly lastFieldIds: number[] = [];
34
+
35
+ /** Boolean field header waiting for the following boolean payload. */
36
+ private pendingBooleanField: {fid: number} | null = null;
37
+
38
+ /** Enter a struct and reset the delta-encoded field id state. */
39
+ writeStructBegin(_name: string): void {
40
+ this.lastFieldIds.push(this.lastFieldId);
41
+ this.lastFieldId = 0;
42
+ }
43
+
44
+ /** Exit a struct and restore the parent field id state. */
45
+ writeStructEnd(): void {
46
+ this.lastFieldId = this.lastFieldIds.pop() || 0;
47
+ }
48
+
49
+ /** Write a field header, deferring boolean fields until their value is known. */
50
+ writeFieldBegin(_name: string, fieldType: thrift.Thrift.Type, fid: number): void {
51
+ if (fieldType === thrift.Thrift.Type.BOOL) {
52
+ this.pendingBooleanField = {fid};
53
+ return;
54
+ }
55
+
56
+ this.writeFieldHeader(this.getCompactType(fieldType), fid);
57
+ }
58
+
59
+ /** Complete the current field; compact protocol has no field-end bytes. */
60
+ writeFieldEnd(): void {}
61
+
62
+ /** Write the stop marker that terminates a thrift struct. */
63
+ writeFieldStop(): void {
64
+ this.writeByteDirect(COMPACT_TYPE_STOP);
65
+ }
66
+
67
+ /** Write a map header with compact key/value element types. */
68
+ writeMapBegin(keyType: thrift.Thrift.Type, valueType: thrift.Thrift.Type, size: number): void {
69
+ if (size === 0) {
70
+ this.writeByteDirect(0);
71
+ return;
72
+ }
73
+
74
+ this.writeVarint32(size);
75
+ this.writeByteDirect((this.getCompactType(keyType) << 4) | this.getCompactType(valueType));
76
+ }
77
+
78
+ /** Complete the current map; compact protocol has no map-end bytes. */
79
+ writeMapEnd(): void {}
80
+
81
+ /** Write a list header with compact element type and element count. */
82
+ writeListBegin(elementType: thrift.Thrift.Type, size: number): void {
83
+ this.writeCollectionBegin(elementType, size);
84
+ }
85
+
86
+ /** Complete the current list; compact protocol has no list-end bytes. */
87
+ writeListEnd(): void {}
88
+
89
+ /** Write a set header with compact element type and element count. */
90
+ writeSetBegin(elementType: thrift.Thrift.Type, size: number): void {
91
+ this.writeCollectionBegin(elementType, size);
92
+ }
93
+
94
+ /** Complete the current set; compact protocol has no set-end bytes. */
95
+ writeSetEnd(): void {}
96
+
97
+ /** Write a boolean, either inline in its field header or as a value byte. */
98
+ writeBool(value: boolean): void {
99
+ const compactType = value ? COMPACT_TYPE_BOOLEAN_TRUE : COMPACT_TYPE_BOOLEAN_FALSE;
100
+ if (this.pendingBooleanField) {
101
+ this.writeFieldHeader(compactType, this.pendingBooleanField.fid);
102
+ this.pendingBooleanField = null;
103
+ return;
104
+ }
105
+
106
+ this.writeByteDirect(compactType);
107
+ }
108
+
109
+ /** Write a signed byte. */
110
+ writeByte(value: number): void {
111
+ this.writeByteDirect(value);
112
+ }
113
+
114
+ /** Write a signed 16-bit integer as zig-zag varint. */
115
+ writeI16(value: number): void {
116
+ this.writeI32(value);
117
+ }
118
+
119
+ /** Write a signed 32-bit integer as zig-zag varint. */
120
+ writeI32(value: number): void {
121
+ this.writeVarint32(this.encodeZigZag32(value));
122
+ }
123
+
124
+ /** Write a signed 64-bit-like value as zig-zag varint. */
125
+ writeI64(value: Int64Like): void {
126
+ this.writeVarint64(this.encodeZigZag64(this.toBigInt(value)));
127
+ }
128
+
129
+ /** Write a little-endian 64-bit float. */
130
+ writeDouble(value: number): void {
131
+ const bytes = new Uint8Array(8);
132
+ writeDoubleLE(bytes, value, 0);
133
+ this.writeBytes(bytes);
134
+ }
135
+
136
+ /** Write a length-prefixed UTF-8 string. */
137
+ writeString(value: string): void {
138
+ this.writeBinary(encodeUtf8(value));
139
+ }
140
+
141
+ /** Write a length-prefixed binary payload from any typed-array view. */
142
+ writeBinary(value: ArrayBuffer | ArrayBufferView): void {
143
+ const bytes = toUint8Array(value);
144
+ this.writeVarint32(bytes.length);
145
+ this.writeBytes(bytes);
146
+ }
147
+
148
+ /** Return all serialized chunks as one contiguous byte array. */
149
+ getBytes(): Uint8Array {
150
+ return concatUint8Arrays(this.chunks);
151
+ }
152
+
153
+ /** Write a compact collection header for list or set values. */
154
+ private writeCollectionBegin(elementType: thrift.Thrift.Type, size: number): void {
155
+ const compactType = this.getCompactType(elementType);
156
+ if (size <= 14) {
157
+ this.writeByteDirect((size << 4) | compactType);
158
+ return;
159
+ }
160
+
161
+ this.writeByteDirect(0xf0 | compactType);
162
+ this.writeVarint32(size);
163
+ }
164
+
165
+ /** Write a compact field header using a field-id delta when possible. */
166
+ private writeFieldHeader(compactType: number, fid: number): void {
167
+ const fieldIdDelta = fid - this.lastFieldId;
168
+ if (fieldIdDelta > 0 && fieldIdDelta <= 15) {
169
+ this.writeByteDirect((fieldIdDelta << 4) | compactType);
170
+ } else {
171
+ this.writeByteDirect(compactType);
172
+ this.writeI16(fid);
173
+ }
174
+ this.lastFieldId = fid;
175
+ }
176
+
177
+ /** Append an already serialized byte range without copying. */
178
+ private writeBytes(bytes: Uint8Array): void {
179
+ this.chunks.push(bytes);
180
+ }
181
+
182
+ /** Append one byte to the serialized output. */
183
+ private writeByteDirect(value: number): void {
184
+ this.chunks.push(new Uint8Array([value & 0xff]));
185
+ }
186
+
187
+ /** Write an unsigned 32-bit value as a compact varint. */
188
+ private writeVarint32(value: number): void {
189
+ this.writeVarint64(BigInt(value >>> 0));
190
+ }
191
+
192
+ /** Write an unsigned 64-bit value as a compact varint. */
193
+ private writeVarint64(value: bigint): void {
194
+ let nextValue = value;
195
+ while (true) {
196
+ if ((nextValue & ~0x7fn) === 0n) {
197
+ this.writeByteDirect(Number(nextValue));
198
+ return;
199
+ }
200
+
201
+ this.writeByteDirect(Number((nextValue & 0x7fn) | 0x80n));
202
+ nextValue >>= 7n;
203
+ }
204
+ }
205
+
206
+ /** Encode a signed 32-bit integer as an unsigned zig-zag value. */
207
+ private encodeZigZag32(value: number): number {
208
+ return ((value << 1) ^ (value >> 31)) >>> 0;
209
+ }
210
+
211
+ /** Encode a signed 64-bit integer as an unsigned zig-zag value. */
212
+ private encodeZigZag64(value: bigint): bigint {
213
+ return (value << 1n) ^ (value >> 63n);
214
+ }
215
+
216
+ /** Normalize thrift int64-like values to bigint before zig-zag encoding. */
217
+ private toBigInt(value: Int64Like): bigint {
218
+ return typeof value === 'bigint' || typeof value === 'number'
219
+ ? BigInt(value)
220
+ : BigInt(value.toString());
221
+ }
222
+
223
+ /** Convert a generated-thrift type to a compact protocol wire type. */
224
+ private getCompactType(thriftType: thrift.Thrift.Type): number {
225
+ switch (thriftType) {
226
+ case thrift.Thrift.Type.STOP:
227
+ return COMPACT_TYPE_STOP;
228
+ case thrift.Thrift.Type.BOOL:
229
+ return COMPACT_TYPE_BOOLEAN_TRUE;
230
+ case thrift.Thrift.Type.BYTE:
231
+ return COMPACT_TYPE_BYTE;
232
+ case thrift.Thrift.Type.I16:
233
+ return COMPACT_TYPE_I16;
234
+ case thrift.Thrift.Type.I32:
235
+ return COMPACT_TYPE_I32;
236
+ case thrift.Thrift.Type.I64:
237
+ return COMPACT_TYPE_I64;
238
+ case thrift.Thrift.Type.DOUBLE:
239
+ return COMPACT_TYPE_DOUBLE;
240
+ case thrift.Thrift.Type.STRING:
241
+ return COMPACT_TYPE_BINARY;
242
+ case thrift.Thrift.Type.LIST:
243
+ return COMPACT_TYPE_LIST;
244
+ case thrift.Thrift.Type.SET:
245
+ return COMPACT_TYPE_SET;
246
+ case thrift.Thrift.Type.MAP:
247
+ return COMPACT_TYPE_MAP;
248
+ case thrift.Thrift.Type.STRUCT:
249
+ return COMPACT_TYPE_STRUCT;
250
+ default:
251
+ throw new Error(`Unsupported thrift type: ${thriftType}`);
252
+ }
253
+ }
254
+ }
@@ -0,0 +1,322 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import * as thrift from 'thrift';
6
+ import {readDoubleLE} from './binary-utils';
7
+ import {Uint8ArrayTransport} from './uint8-array-transport';
8
+
9
+ const COMPACT_TYPE_STOP = 0x00;
10
+ const COMPACT_TYPE_BOOLEAN_TRUE = 0x01;
11
+ const COMPACT_TYPE_BOOLEAN_FALSE = 0x02;
12
+ const COMPACT_TYPE_BYTE = 0x03;
13
+ const COMPACT_TYPE_I16 = 0x04;
14
+ const COMPACT_TYPE_I32 = 0x05;
15
+ const COMPACT_TYPE_I64 = 0x06;
16
+ const COMPACT_TYPE_DOUBLE = 0x07;
17
+ const COMPACT_TYPE_BINARY = 0x08;
18
+ const COMPACT_TYPE_LIST = 0x09;
19
+ const COMPACT_TYPE_SET = 0x0a;
20
+ const COMPACT_TYPE_MAP = 0x0b;
21
+ const COMPACT_TYPE_STRUCT = 0x0c;
22
+
23
+ /** Number-like replacement for node-int64 used by the compact protocol. */
24
+ export class CompactInt64 {
25
+ /** Signed integer payload represented without precision loss. */
26
+ private readonly value: bigint;
27
+
28
+ /** Create a compact-protocol int64 wrapper from a bigint. */
29
+ constructor(value: bigint) {
30
+ this.value = value;
31
+ }
32
+
33
+ /** Return the payload as a JavaScript number. */
34
+ toNumber(): number {
35
+ return Number(this.value);
36
+ }
37
+
38
+ /** Return the payload as a JavaScript number for generated thrift arithmetic. */
39
+ valueOf(): number {
40
+ return this.toNumber();
41
+ }
42
+
43
+ /** Format the payload as a string. */
44
+ toString(radix?: number): string {
45
+ return this.value.toString(radix);
46
+ }
47
+ }
48
+
49
+ /** Read-only Thrift compact protocol backed by Uint8Array. */
50
+ export class Uint8ArrayCompactProtocol {
51
+ /** Byte transport that provides thrift-compatible read, borrow, and consume methods. */
52
+ private readonly transport: Uint8ArrayTransport;
53
+
54
+ /** Field id at the current nesting depth, used for compact field-id deltas. */
55
+ private lastFieldId = 0;
56
+
57
+ /** Parent struct field ids restored when nested structs end. */
58
+ private readonly lastFieldIds: number[] = [];
59
+
60
+ /** Boolean payload encoded in a compact field header. */
61
+ private boolValue: boolean | null = null;
62
+
63
+ /** Create a compact protocol reader over a Uint8Array-backed transport. */
64
+ constructor(transport: Uint8ArrayTransport) {
65
+ this.transport = transport;
66
+ }
67
+
68
+ /** Enter a struct and reset the delta-encoded field id state. */
69
+ readStructBegin(): thrift.TStruct {
70
+ this.lastFieldIds.push(this.lastFieldId);
71
+ this.lastFieldId = 0;
72
+ return {fname: ''};
73
+ }
74
+
75
+ readStructEnd(): void {
76
+ this.lastFieldId = this.lastFieldIds.pop() || 0;
77
+ }
78
+
79
+ /** Read a compact field header and expand it to a thrift field descriptor. */
80
+ readFieldBegin(): thrift.TField {
81
+ const fieldHeader = this.transport.readByte();
82
+ const compactType = fieldHeader & 0x0f;
83
+
84
+ if (compactType === COMPACT_TYPE_STOP) {
85
+ return {fname: null!, ftype: thrift.Thrift.Type.STOP, fid: 0};
86
+ }
87
+
88
+ const fieldIdDelta = (fieldHeader & 0xf0) >>> 4;
89
+ const fieldId = fieldIdDelta === 0 ? this.readI16() : this.lastFieldId + fieldIdDelta;
90
+ const fieldType = this.getThriftType(compactType);
91
+
92
+ if (compactType === COMPACT_TYPE_BOOLEAN_TRUE || compactType === COMPACT_TYPE_BOOLEAN_FALSE) {
93
+ this.boolValue = compactType === COMPACT_TYPE_BOOLEAN_TRUE;
94
+ }
95
+
96
+ this.lastFieldId = fieldId;
97
+ return {fname: null!, ftype: fieldType, fid: fieldId};
98
+ }
99
+
100
+ readFieldEnd(): void {}
101
+
102
+ /** Read a map header, including element compact types when the map is non-empty. */
103
+ readMapBegin(): thrift.TMap {
104
+ const size = this.readVarint32();
105
+ const keyAndValueType = size === 0 ? 0 : this.transport.readByte();
106
+ return {
107
+ ktype: this.getThriftType((keyAndValueType & 0xf0) >>> 4),
108
+ vtype: this.getThriftType(keyAndValueType & 0x0f),
109
+ size
110
+ };
111
+ }
112
+
113
+ readMapEnd(): void {}
114
+
115
+ /** Read a list header and expand the inline or varint element count. */
116
+ readListBegin(): thrift.TList {
117
+ const sizeAndType = this.transport.readByte();
118
+ let size = (sizeAndType >>> 4) & 0x0f;
119
+ if (size === 15) {
120
+ size = this.readVarint32();
121
+ }
122
+
123
+ return {
124
+ etype: this.getThriftType(sizeAndType & 0x0f),
125
+ size
126
+ };
127
+ }
128
+
129
+ readListEnd(): void {}
130
+
131
+ /** Read a set header; compact protocol encodes sets and lists the same way. */
132
+ readSetBegin(): thrift.TSet {
133
+ return this.readListBegin();
134
+ }
135
+
136
+ readSetEnd(): void {}
137
+
138
+ /** Read a boolean from the field header or from the next compact boolean byte. */
139
+ readBool(): boolean {
140
+ if (this.boolValue !== null) {
141
+ const value = this.boolValue;
142
+ this.boolValue = null;
143
+ return value;
144
+ }
145
+
146
+ return this.transport.readByte() === COMPACT_TYPE_BOOLEAN_TRUE;
147
+ }
148
+
149
+ /** Read a signed byte from the transport. */
150
+ readByte(): number {
151
+ return this.transport.readByte();
152
+ }
153
+
154
+ /** Read a signed 16-bit integer encoded as zig-zag varint. */
155
+ readI16(): number {
156
+ return this.readI32();
157
+ }
158
+
159
+ /** Read a signed 32-bit integer encoded as zig-zag varint. */
160
+ readI32(): number {
161
+ return this.decodeZigZag32(this.readVarint32());
162
+ }
163
+
164
+ /** Read a signed 64-bit integer encoded as zig-zag varint. */
165
+ readI64(): CompactInt64 {
166
+ return new CompactInt64(this.decodeZigZag64(this.readVarint64()));
167
+ }
168
+
169
+ /** Read a little-endian 64-bit float. */
170
+ readDouble(): number {
171
+ return readDoubleLE(this.transport.read(8), 0);
172
+ }
173
+
174
+ /** Read a length-prefixed binary payload as an exact Uint8Array. */
175
+ readBinary(): Uint8Array {
176
+ const size = this.readVarint32();
177
+ return size === 0 ? new Uint8Array(0) : this.transport.read(size);
178
+ }
179
+
180
+ /** Read a length-prefixed UTF-8 string. */
181
+ readString(): string {
182
+ const size = this.readVarint32();
183
+ return size === 0 ? '' : this.transport.readString(size);
184
+ }
185
+
186
+ /** Consume and discard a value with the supplied thrift type. */
187
+ skip(type: thrift.Thrift.Type): void {
188
+ switch (type) {
189
+ case thrift.Thrift.Type.STOP:
190
+ return;
191
+ case thrift.Thrift.Type.BOOL:
192
+ this.readBool();
193
+ return;
194
+ case thrift.Thrift.Type.BYTE:
195
+ this.readByte();
196
+ return;
197
+ case thrift.Thrift.Type.I16:
198
+ this.readI16();
199
+ return;
200
+ case thrift.Thrift.Type.I32:
201
+ this.readI32();
202
+ return;
203
+ case thrift.Thrift.Type.I64:
204
+ this.readI64();
205
+ return;
206
+ case thrift.Thrift.Type.DOUBLE:
207
+ this.readDouble();
208
+ return;
209
+ case thrift.Thrift.Type.STRING:
210
+ this.readBinary();
211
+ return;
212
+ case thrift.Thrift.Type.STRUCT:
213
+ this.skipStruct();
214
+ return;
215
+ case thrift.Thrift.Type.MAP:
216
+ this.skipMap();
217
+ return;
218
+ case thrift.Thrift.Type.SET:
219
+ case thrift.Thrift.Type.LIST:
220
+ this.skipList();
221
+ return;
222
+ default:
223
+ throw new Error(`Unsupported thrift type: ${type}`);
224
+ }
225
+ }
226
+
227
+ /** Read an unsigned 32-bit compact varint. */
228
+ private readVarint32(): number {
229
+ return Number(this.readVarint64());
230
+ }
231
+
232
+ /** Read an unsigned 64-bit compact varint. */
233
+ private readVarint64(): bigint {
234
+ let value = 0n;
235
+ let shift = 0n;
236
+
237
+ while (true) {
238
+ const byte = BigInt(this.transport.readByte() & 0xff);
239
+ value |= (byte & 0x7fn) << shift;
240
+ if ((byte & 0x80n) === 0n) {
241
+ return value;
242
+ }
243
+ shift += 7n;
244
+ }
245
+ }
246
+
247
+ /** Decode a zig-zag 32-bit integer to a signed integer. */
248
+ private decodeZigZag32(value: number): number {
249
+ return (value >>> 1) ^ -(value & 1);
250
+ }
251
+
252
+ /** Decode a zig-zag 64-bit integer to a signed integer. */
253
+ private decodeZigZag64(value: bigint): bigint {
254
+ return (value >> 1n) ^ -(value & 1n);
255
+ }
256
+
257
+ /** Convert a compact wire type to a generated-thrift type. */
258
+ private getThriftType(compactType: number): thrift.Thrift.Type {
259
+ switch (compactType) {
260
+ case COMPACT_TYPE_STOP:
261
+ return thrift.Thrift.Type.STOP;
262
+ case COMPACT_TYPE_BOOLEAN_TRUE:
263
+ case COMPACT_TYPE_BOOLEAN_FALSE:
264
+ return thrift.Thrift.Type.BOOL;
265
+ case COMPACT_TYPE_BYTE:
266
+ return thrift.Thrift.Type.BYTE;
267
+ case COMPACT_TYPE_I16:
268
+ return thrift.Thrift.Type.I16;
269
+ case COMPACT_TYPE_I32:
270
+ return thrift.Thrift.Type.I32;
271
+ case COMPACT_TYPE_I64:
272
+ return thrift.Thrift.Type.I64;
273
+ case COMPACT_TYPE_DOUBLE:
274
+ return thrift.Thrift.Type.DOUBLE;
275
+ case COMPACT_TYPE_BINARY:
276
+ return thrift.Thrift.Type.STRING;
277
+ case COMPACT_TYPE_LIST:
278
+ return thrift.Thrift.Type.LIST;
279
+ case COMPACT_TYPE_SET:
280
+ return thrift.Thrift.Type.SET;
281
+ case COMPACT_TYPE_MAP:
282
+ return thrift.Thrift.Type.MAP;
283
+ case COMPACT_TYPE_STRUCT:
284
+ return thrift.Thrift.Type.STRUCT;
285
+ default:
286
+ throw new Error(`Unknown compact thrift type: ${compactType}`);
287
+ }
288
+ }
289
+
290
+ /** Skip every field in the current struct. */
291
+ private skipStruct(): void {
292
+ this.readStructBegin();
293
+ while (true) {
294
+ const field = this.readFieldBegin();
295
+ if (field.ftype === thrift.Thrift.Type.STOP) {
296
+ break;
297
+ }
298
+ this.skip(field.ftype);
299
+ this.readFieldEnd();
300
+ }
301
+ this.readStructEnd();
302
+ }
303
+
304
+ /** Skip every key and value in the current map. */
305
+ private skipMap(): void {
306
+ const map = this.readMapBegin();
307
+ for (let index = 0; index < map.size; index++) {
308
+ this.skip(map.ktype);
309
+ this.skip(map.vtype);
310
+ }
311
+ this.readMapEnd();
312
+ }
313
+
314
+ /** Skip every element in the current list or set. */
315
+ private skipList(): void {
316
+ const list = this.readListBegin();
317
+ for (let index = 0; index < list.size; index++) {
318
+ this.skip(list.etype);
319
+ }
320
+ this.readListEnd();
321
+ }
322
+ }
@@ -0,0 +1,79 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {decodeString, toUint8Array} from './binary-utils';
6
+
7
+ /** Thrift compact-protocol read transport backed by Uint8Array. */
8
+ export class Uint8ArrayTransport {
9
+ public readPos = 0;
10
+
11
+ private readonly buffer: Uint8Array;
12
+
13
+ constructor(buffer: Uint8Array) {
14
+ this.buffer = toUint8Array(buffer);
15
+ }
16
+
17
+ commitPosition(): void {}
18
+
19
+ rollbackPosition(): void {}
20
+
21
+ isOpen(): boolean {
22
+ return true;
23
+ }
24
+
25
+ open(): boolean {
26
+ return true;
27
+ }
28
+
29
+ close(): boolean {
30
+ return true;
31
+ }
32
+
33
+ setCurrSeqId(_sequenceId: number): void {}
34
+
35
+ ensureAvailable(byteLength: number): void {
36
+ if (this.readPos + byteLength > this.buffer.length) {
37
+ throw new Error('Input buffer underrun');
38
+ }
39
+ }
40
+
41
+ read(byteLength: number): Uint8Array {
42
+ this.ensureAvailable(byteLength);
43
+ const end = this.readPos + byteLength;
44
+ const value = this.buffer.subarray(this.readPos, end);
45
+ this.readPos = end;
46
+ return value;
47
+ }
48
+
49
+ readByte(): number {
50
+ this.ensureAvailable(1);
51
+ const value = this.buffer[this.readPos++];
52
+ return value > 127 ? value - 256 : value;
53
+ }
54
+
55
+ readString(byteLength: number): string {
56
+ this.ensureAvailable(byteLength);
57
+ const value = decodeString(this.buffer, this.readPos, this.readPos + byteLength);
58
+ this.readPos += byteLength;
59
+ return value;
60
+ }
61
+
62
+ borrow(): {buf: Uint8Array; readIndex: number; writeIndex: number} {
63
+ return {
64
+ buf: this.buffer,
65
+ readIndex: this.readPos,
66
+ writeIndex: this.buffer.length
67
+ };
68
+ }
69
+
70
+ consume(bytesConsumed: number): void {
71
+ this.readPos += bytesConsumed;
72
+ }
73
+
74
+ write(): never {
75
+ throw new Error('Uint8ArrayTransport is read-only');
76
+ }
77
+
78
+ flush(): void {}
79
+ }
@@ -0,0 +1,9 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export type {ParquetLoaderOptions} from './parquet-loader';
6
+ export type {GeoParquetLoaderOptions} from './geoparquet-loader';
7
+ export {ParquetLoader} from './parquet-loader';
8
+ export {GeoParquetLoader} from './geoparquet-loader';
9
+ export {ParquetJSLoader} from './parquet-js-loader';
@@ -1,43 +0,0 @@
1
- import type { ArrowTable, ArrowTableBatch } from '@loaders.gl/schema';
2
- import type { LoaderOptions } from '@loaders.gl/loader-utils';
3
- /** Parquet WASM loader options */
4
- export type ParquetArrowLoaderOptions = LoaderOptions & {
5
- parquet?: {
6
- limit?: number;
7
- offset?: number;
8
- batchSize?: number;
9
- columns?: string[];
10
- rowGroups?: number[];
11
- concurrency?: number;
12
- wasmUrl?: string;
13
- };
14
- };
15
- /** Parquet WASM table loader */
16
- export declare const ParquetArrowWorkerLoader: {
17
- readonly dataType: ArrowTable;
18
- readonly batchType: ArrowTableBatch;
19
- readonly name: "Apache Parquet";
20
- readonly id: "parquet-wasm";
21
- readonly module: "parquet";
22
- readonly version: any;
23
- readonly worker: false;
24
- readonly category: "table";
25
- readonly extensions: ["parquet"];
26
- readonly mimeTypes: ["application/octet-stream"];
27
- readonly binary: true;
28
- readonly tests: ["PAR1", "PARE"];
29
- readonly options: {
30
- readonly parquet: {
31
- readonly limit: undefined;
32
- readonly offset: 0;
33
- readonly batchSize: undefined;
34
- readonly columns: undefined;
35
- readonly rowGroups: undefined;
36
- readonly concurrency: undefined;
37
- readonly wasmUrl: "https://unpkg.com/parquet-wasm@0.6.1/esm/parquet_wasm_bg.wasm";
38
- };
39
- };
40
- };
41
- /** Parquet WASM table loader */
42
- export declare const ParquetArrowLoader: any;
43
- //# sourceMappingURL=parquet-arrow-loader.d.ts.map