@loaders.gl/parquet 4.2.0-alpha.4 → 4.2.0-alpha.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.
Files changed (265) hide show
  1. package/dist/index.cjs +269 -616
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.d.ts +12 -12
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +6 -1
  6. package/dist/lib/arrow/convert-columns-to-row-group.js +1 -2
  7. package/dist/lib/arrow/convert-row-group-to-columns.js +8 -6
  8. package/dist/lib/arrow/convert-schema-from-parquet.d.ts +3 -3
  9. package/dist/lib/arrow/convert-schema-from-parquet.d.ts.map +1 -1
  10. package/dist/lib/arrow/convert-schema-from-parquet.js +71 -82
  11. package/dist/lib/arrow/convert-schema-to-parquet.d.ts +1 -1
  12. package/dist/lib/arrow/convert-schema-to-parquet.d.ts.map +1 -1
  13. package/dist/lib/arrow/convert-schema-to-parquet.js +65 -35
  14. package/dist/lib/constants.js +14 -1
  15. package/dist/lib/parsers/get-parquet-schema.d.ts +1 -1
  16. package/dist/lib/parsers/get-parquet-schema.d.ts.map +1 -1
  17. package/dist/lib/parsers/get-parquet-schema.js +9 -7
  18. package/dist/lib/parsers/parse-geoparquet.d.ts +1 -1
  19. package/dist/lib/parsers/parse-geoparquet.d.ts.map +1 -1
  20. package/dist/lib/parsers/parse-geoparquet.js +47 -45
  21. package/dist/lib/parsers/parse-parquet-to-columns.d.ts +1 -1
  22. package/dist/lib/parsers/parse-parquet-to-columns.d.ts.map +1 -1
  23. package/dist/lib/parsers/parse-parquet-to-columns.js +36 -25
  24. package/dist/lib/parsers/parse-parquet.d.ts +1 -1
  25. package/dist/lib/parsers/parse-parquet.d.ts.map +1 -1
  26. package/dist/lib/parsers/parse-parquet.js +62 -50
  27. package/dist/lib/wasm/encode-parquet-wasm.d.ts +1 -1
  28. package/dist/lib/wasm/encode-parquet-wasm.d.ts.map +1 -1
  29. package/dist/lib/wasm/encode-parquet-wasm.js +49 -12
  30. package/dist/lib/wasm/load-wasm.js +13 -10
  31. package/dist/lib/wasm/parse-parquet-wasm.d.ts +1 -1
  32. package/dist/lib/wasm/parse-parquet-wasm.d.ts.map +1 -1
  33. package/dist/lib/wasm/parse-parquet-wasm.js +19 -15
  34. package/dist/parquet-loader.d.ts +1 -1
  35. package/dist/parquet-loader.d.ts.map +1 -1
  36. package/dist/parquet-loader.js +77 -64
  37. package/dist/parquet-wasm-loader.js +25 -28
  38. package/dist/parquet-wasm-writer.js +19 -23
  39. package/dist/parquet-writer.js +16 -12
  40. package/dist/parquetjs/codecs/declare.d.ts +1 -1
  41. package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
  42. package/dist/parquetjs/codecs/declare.js +0 -1
  43. package/dist/parquetjs/codecs/dictionary.js +4 -8
  44. package/dist/parquetjs/codecs/index.d.ts +3 -3
  45. package/dist/parquetjs/codecs/index.d.ts.map +1 -1
  46. package/dist/parquetjs/codecs/index.js +20 -17
  47. package/dist/parquetjs/codecs/plain.d.ts +2 -2
  48. package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
  49. package/dist/parquetjs/codecs/plain.js +166 -162
  50. package/dist/parquetjs/codecs/rle.d.ts +2 -2
  51. package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
  52. package/dist/parquetjs/codecs/rle.js +124 -105
  53. package/dist/parquetjs/compression.d.ts +1 -1
  54. package/dist/parquetjs/compression.d.ts.map +1 -1
  55. package/dist/parquetjs/compression.js +157 -43
  56. package/dist/parquetjs/encoder/parquet-encoder.d.ts +3 -3
  57. package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
  58. package/dist/parquetjs/encoder/parquet-encoder.js +406 -275
  59. package/dist/parquetjs/parquet-thrift/BoundaryOrder.js +12 -7
  60. package/dist/parquetjs/parquet-thrift/BsonType.js +31 -27
  61. package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts +1 -1
  62. package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts.map +1 -1
  63. package/dist/parquetjs/parquet-thrift/ColumnChunk.js +175 -166
  64. package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts +1 -1
  65. package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts.map +1 -1
  66. package/dist/parquetjs/parquet-thrift/ColumnIndex.js +178 -166
  67. package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts +6 -6
  68. package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts.map +1 -1
  69. package/dist/parquetjs/parquet-thrift/ColumnMetaData.js +359 -333
  70. package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts +1 -1
  71. package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts.map +1 -1
  72. package/dist/parquetjs/parquet-thrift/ColumnOrder.js +73 -68
  73. package/dist/parquetjs/parquet-thrift/CompressionCodec.js +17 -12
  74. package/dist/parquetjs/parquet-thrift/ConvertedType.js +31 -26
  75. package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts +2 -2
  76. package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts.map +1 -1
  77. package/dist/parquetjs/parquet-thrift/DataPageHeader.js +136 -124
  78. package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts +2 -2
  79. package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts.map +1 -1
  80. package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js +198 -181
  81. package/dist/parquetjs/parquet-thrift/DateType.js +31 -27
  82. package/dist/parquetjs/parquet-thrift/DecimalType.js +76 -69
  83. package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts +1 -1
  84. package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts.map +1 -1
  85. package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js +93 -86
  86. package/dist/parquetjs/parquet-thrift/Encoding.js +17 -12
  87. package/dist/parquetjs/parquet-thrift/EnumType.js +31 -27
  88. package/dist/parquetjs/parquet-thrift/FieldRepetitionType.js +12 -7
  89. package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts +4 -4
  90. package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts.map +1 -1
  91. package/dist/parquetjs/parquet-thrift/FileMetaData.js +217 -205
  92. package/dist/parquetjs/parquet-thrift/IndexPageHeader.js +31 -27
  93. package/dist/parquetjs/parquet-thrift/IntType.js +76 -69
  94. package/dist/parquetjs/parquet-thrift/JsonType.js +31 -27
  95. package/dist/parquetjs/parquet-thrift/KeyValue.js +73 -67
  96. package/dist/parquetjs/parquet-thrift/ListType.js +31 -27
  97. package/dist/parquetjs/parquet-thrift/LogicalType.d.ts +13 -13
  98. package/dist/parquetjs/parquet-thrift/LogicalType.d.ts.map +1 -1
  99. package/dist/parquetjs/parquet-thrift/LogicalType.js +325 -344
  100. package/dist/parquetjs/parquet-thrift/MapType.js +31 -27
  101. package/dist/parquetjs/parquet-thrift/MicroSeconds.js +31 -27
  102. package/dist/parquetjs/parquet-thrift/MilliSeconds.js +31 -27
  103. package/dist/parquetjs/parquet-thrift/NullType.js +31 -27
  104. package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts +1 -1
  105. package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts.map +1 -1
  106. package/dist/parquetjs/parquet-thrift/OffsetIndex.js +66 -60
  107. package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts +2 -2
  108. package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts.map +1 -1
  109. package/dist/parquetjs/parquet-thrift/PageEncodingStats.js +98 -88
  110. package/dist/parquetjs/parquet-thrift/PageHeader.d.ts +5 -5
  111. package/dist/parquetjs/parquet-thrift/PageHeader.d.ts.map +1 -1
  112. package/dist/parquetjs/parquet-thrift/PageHeader.js +185 -175
  113. package/dist/parquetjs/parquet-thrift/PageLocation.js +108 -96
  114. package/dist/parquetjs/parquet-thrift/PageType.js +13 -8
  115. package/dist/parquetjs/parquet-thrift/RowGroup.d.ts +2 -2
  116. package/dist/parquetjs/parquet-thrift/RowGroup.d.ts.map +1 -1
  117. package/dist/parquetjs/parquet-thrift/RowGroup.js +145 -133
  118. package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts +4 -4
  119. package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts.map +1 -1
  120. package/dist/parquetjs/parquet-thrift/SchemaElement.js +211 -205
  121. package/dist/parquetjs/parquet-thrift/SortingColumn.js +98 -88
  122. package/dist/parquetjs/parquet-thrift/Statistics.js +143 -137
  123. package/dist/parquetjs/parquet-thrift/StringType.js +31 -27
  124. package/dist/parquetjs/parquet-thrift/TimeType.d.ts +1 -1
  125. package/dist/parquetjs/parquet-thrift/TimeType.d.ts.map +1 -1
  126. package/dist/parquetjs/parquet-thrift/TimeType.js +76 -69
  127. package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts +2 -2
  128. package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts.map +1 -1
  129. package/dist/parquetjs/parquet-thrift/TimeUnit.js +94 -91
  130. package/dist/parquetjs/parquet-thrift/TimestampType.d.ts +1 -1
  131. package/dist/parquetjs/parquet-thrift/TimestampType.d.ts.map +1 -1
  132. package/dist/parquetjs/parquet-thrift/TimestampType.js +76 -69
  133. package/dist/parquetjs/parquet-thrift/Type.js +17 -12
  134. package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js +31 -27
  135. package/dist/parquetjs/parquet-thrift/UUIDType.js +31 -27
  136. package/dist/parquetjs/parquet-thrift/index.d.ts +44 -44
  137. package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
  138. package/dist/parquetjs/parquet-thrift/index.js +6 -1
  139. package/dist/parquetjs/parser/decoders.d.ts +3 -3
  140. package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
  141. package/dist/parquetjs/parser/decoders.js +306 -242
  142. package/dist/parquetjs/parser/parquet-reader.d.ts +3 -3
  143. package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
  144. package/dist/parquetjs/parser/parquet-reader.js +179 -157
  145. package/dist/parquetjs/schema/declare.d.ts +1 -1
  146. package/dist/parquetjs/schema/declare.d.ts.map +1 -1
  147. package/dist/parquetjs/schema/declare.js +6 -9
  148. package/dist/parquetjs/schema/schema.d.ts +1 -1
  149. package/dist/parquetjs/schema/schema.d.ts.map +1 -1
  150. package/dist/parquetjs/schema/schema.js +139 -120
  151. package/dist/parquetjs/schema/shred.d.ts +2 -2
  152. package/dist/parquetjs/schema/shred.d.ts.map +1 -1
  153. package/dist/parquetjs/schema/shred.js +301 -204
  154. package/dist/parquetjs/schema/types.d.ts +1 -1
  155. package/dist/parquetjs/schema/types.d.ts.map +1 -1
  156. package/dist/parquetjs/schema/types.js +328 -314
  157. package/dist/parquetjs/utils/file-utils.js +24 -23
  158. package/dist/parquetjs/utils/read-utils.d.ts +1 -1
  159. package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
  160. package/dist/parquetjs/utils/read-utils.js +79 -69
  161. package/dist/polyfills/buffer/buffer-polyfill.browser.js +8 -3
  162. package/dist/polyfills/buffer/buffer-polyfill.node.js +13 -8
  163. package/dist/polyfills/buffer/buffer.js +1750 -1367
  164. package/dist/polyfills/buffer/index.d.ts +3 -3
  165. package/dist/polyfills/buffer/index.d.ts.map +1 -1
  166. package/dist/polyfills/buffer/index.js +5 -1
  167. package/dist/polyfills/buffer/install-buffer-polyfill.js +2 -1
  168. package/dist/polyfills/util.js +4 -1
  169. package/dist/workers/parquet-worker.js +3 -1
  170. package/package.json +15 -13
  171. package/src/index.ts +1 -1
  172. package/src/lib/parsers/parse-parquet-to-columns.ts +1 -1
  173. package/src/lib/parsers/parse-parquet.ts +1 -1
  174. package/src/parquetjs/encoder/parquet-encoder.ts +2 -2
  175. package/src/parquetjs/parser/decoders.ts +2 -2
  176. package/src/parquetjs/parser/parquet-reader.ts +1 -1
  177. package/src/parquetjs/schema/schema.ts +1 -1
  178. package/src/parquetjs/utils/read-utils.ts +2 -2
  179. package/dist/index.js.map +0 -1
  180. package/dist/lib/arrow/convert-columns-to-row-group.js.map +0 -1
  181. package/dist/lib/arrow/convert-row-group-to-columns.js.map +0 -1
  182. package/dist/lib/arrow/convert-schema-from-parquet.js.map +0 -1
  183. package/dist/lib/arrow/convert-schema-to-parquet.js.map +0 -1
  184. package/dist/lib/constants.js.map +0 -1
  185. package/dist/lib/parsers/get-parquet-schema.js.map +0 -1
  186. package/dist/lib/parsers/parse-geoparquet.js.map +0 -1
  187. package/dist/lib/parsers/parse-parquet-to-columns.js.map +0 -1
  188. package/dist/lib/parsers/parse-parquet.js.map +0 -1
  189. package/dist/lib/wasm/encode-parquet-wasm.js.map +0 -1
  190. package/dist/lib/wasm/load-wasm.js.map +0 -1
  191. package/dist/lib/wasm/parse-parquet-wasm.js.map +0 -1
  192. package/dist/lib/wip/convert-schema-deep.java.disabled +0 -910
  193. package/dist/lib/wip/convert-schema-deep.rs.disabled +0 -976
  194. package/dist/parquet-loader.js.map +0 -1
  195. package/dist/parquet-wasm-loader.js.map +0 -1
  196. package/dist/parquet-wasm-writer.js.map +0 -1
  197. package/dist/parquet-writer.js.map +0 -1
  198. package/dist/parquetjs/LICENSE +0 -20
  199. package/dist/parquetjs/codecs/declare.js.map +0 -1
  200. package/dist/parquetjs/codecs/dictionary.js.map +0 -1
  201. package/dist/parquetjs/codecs/index.js.map +0 -1
  202. package/dist/parquetjs/codecs/plain.js.map +0 -1
  203. package/dist/parquetjs/codecs/rle.js.map +0 -1
  204. package/dist/parquetjs/compression.js.map +0 -1
  205. package/dist/parquetjs/encoder/parquet-encoder.js.map +0 -1
  206. package/dist/parquetjs/modules.d.ts +0 -21
  207. package/dist/parquetjs/parquet-thrift/BoundaryOrder.js.map +0 -1
  208. package/dist/parquetjs/parquet-thrift/BsonType.js.map +0 -1
  209. package/dist/parquetjs/parquet-thrift/ColumnChunk.js.map +0 -1
  210. package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +0 -1
  211. package/dist/parquetjs/parquet-thrift/ColumnMetaData.js.map +0 -1
  212. package/dist/parquetjs/parquet-thrift/ColumnOrder.js.map +0 -1
  213. package/dist/parquetjs/parquet-thrift/CompressionCodec.js.map +0 -1
  214. package/dist/parquetjs/parquet-thrift/ConvertedType.js.map +0 -1
  215. package/dist/parquetjs/parquet-thrift/DataPageHeader.js.map +0 -1
  216. package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js.map +0 -1
  217. package/dist/parquetjs/parquet-thrift/DateType.js.map +0 -1
  218. package/dist/parquetjs/parquet-thrift/DecimalType.js.map +0 -1
  219. package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js.map +0 -1
  220. package/dist/parquetjs/parquet-thrift/Encoding.js.map +0 -1
  221. package/dist/parquetjs/parquet-thrift/EnumType.js.map +0 -1
  222. package/dist/parquetjs/parquet-thrift/FieldRepetitionType.js.map +0 -1
  223. package/dist/parquetjs/parquet-thrift/FileMetaData.js.map +0 -1
  224. package/dist/parquetjs/parquet-thrift/IndexPageHeader.js.map +0 -1
  225. package/dist/parquetjs/parquet-thrift/IntType.js.map +0 -1
  226. package/dist/parquetjs/parquet-thrift/JsonType.js.map +0 -1
  227. package/dist/parquetjs/parquet-thrift/KeyValue.js.map +0 -1
  228. package/dist/parquetjs/parquet-thrift/ListType.js.map +0 -1
  229. package/dist/parquetjs/parquet-thrift/LogicalType.js.map +0 -1
  230. package/dist/parquetjs/parquet-thrift/MapType.js.map +0 -1
  231. package/dist/parquetjs/parquet-thrift/MicroSeconds.js.map +0 -1
  232. package/dist/parquetjs/parquet-thrift/MilliSeconds.js.map +0 -1
  233. package/dist/parquetjs/parquet-thrift/NullType.js.map +0 -1
  234. package/dist/parquetjs/parquet-thrift/OffsetIndex.js.map +0 -1
  235. package/dist/parquetjs/parquet-thrift/PageEncodingStats.js.map +0 -1
  236. package/dist/parquetjs/parquet-thrift/PageHeader.js.map +0 -1
  237. package/dist/parquetjs/parquet-thrift/PageLocation.js.map +0 -1
  238. package/dist/parquetjs/parquet-thrift/PageType.js.map +0 -1
  239. package/dist/parquetjs/parquet-thrift/RowGroup.js.map +0 -1
  240. package/dist/parquetjs/parquet-thrift/SchemaElement.js.map +0 -1
  241. package/dist/parquetjs/parquet-thrift/SortingColumn.js.map +0 -1
  242. package/dist/parquetjs/parquet-thrift/Statistics.js.map +0 -1
  243. package/dist/parquetjs/parquet-thrift/StringType.js.map +0 -1
  244. package/dist/parquetjs/parquet-thrift/TimeType.js.map +0 -1
  245. package/dist/parquetjs/parquet-thrift/TimeUnit.js.map +0 -1
  246. package/dist/parquetjs/parquet-thrift/TimestampType.js.map +0 -1
  247. package/dist/parquetjs/parquet-thrift/Type.js.map +0 -1
  248. package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js.map +0 -1
  249. package/dist/parquetjs/parquet-thrift/UUIDType.js.map +0 -1
  250. package/dist/parquetjs/parquet-thrift/index.js.map +0 -1
  251. package/dist/parquetjs/parser/decoders.js.map +0 -1
  252. package/dist/parquetjs/parser/parquet-reader.js.map +0 -1
  253. package/dist/parquetjs/schema/declare.js.map +0 -1
  254. package/dist/parquetjs/schema/schema.js.map +0 -1
  255. package/dist/parquetjs/schema/shred.js.map +0 -1
  256. package/dist/parquetjs/schema/types.js.map +0 -1
  257. package/dist/parquetjs/utils/file-utils.js.map +0 -1
  258. package/dist/parquetjs/utils/read-utils.js.map +0 -1
  259. package/dist/polyfills/buffer/buffer-polyfill.browser.js.map +0 -1
  260. package/dist/polyfills/buffer/buffer-polyfill.node.js.map +0 -1
  261. package/dist/polyfills/buffer/buffer.js.map +0 -1
  262. package/dist/polyfills/buffer/index.js.map +0 -1
  263. package/dist/polyfills/buffer/install-buffer-polyfill.js.map +0 -1
  264. package/dist/polyfills/util.js.map +0 -1
  265. package/dist/workers/parquet-worker.js.map +0 -1
@@ -1,397 +1,411 @@
1
+ // Forked from https://github.com/kbajalc/parquets under MIT license (Copyright (c) 2017 ironSource Ltd.)
2
+ /* eslint-disable camelcase */
1
3
  import { BSONLoader, BSONWriter } from '@loaders.gl/bson';
2
4
  export const PARQUET_LOGICAL_TYPES = {
3
- BOOLEAN: {
4
- primitiveType: 'BOOLEAN',
5
- toPrimitive: toPrimitive_BOOLEAN,
6
- fromPrimitive: fromPrimitive_BOOLEAN
7
- },
8
- INT32: {
9
- primitiveType: 'INT32',
10
- toPrimitive: toPrimitive_INT32
11
- },
12
- INT64: {
13
- primitiveType: 'INT64',
14
- toPrimitive: toPrimitive_INT64
15
- },
16
- INT96: {
17
- primitiveType: 'INT96',
18
- toPrimitive: toPrimitive_INT96
19
- },
20
- FLOAT: {
21
- primitiveType: 'FLOAT',
22
- toPrimitive: toPrimitive_FLOAT
23
- },
24
- DOUBLE: {
25
- primitiveType: 'DOUBLE',
26
- toPrimitive: toPrimitive_DOUBLE
27
- },
28
- BYTE_ARRAY: {
29
- primitiveType: 'BYTE_ARRAY',
30
- toPrimitive: toPrimitive_BYTE_ARRAY
31
- },
32
- FIXED_LEN_BYTE_ARRAY: {
33
- primitiveType: 'FIXED_LEN_BYTE_ARRAY',
34
- toPrimitive: toPrimitive_BYTE_ARRAY
35
- },
36
- UTF8: {
37
- primitiveType: 'BYTE_ARRAY',
38
- originalType: 'UTF8',
39
- toPrimitive: toPrimitive_UTF8,
40
- fromPrimitive: fromPrimitive_UTF8
41
- },
42
- TIME_MILLIS: {
43
- primitiveType: 'INT32',
44
- originalType: 'TIME_MILLIS',
45
- toPrimitive: toPrimitive_TIME_MILLIS
46
- },
47
- TIME_MICROS: {
48
- primitiveType: 'INT64',
49
- originalType: 'TIME_MICROS',
50
- toPrimitive: toPrimitive_TIME_MICROS
51
- },
52
- DATE: {
53
- primitiveType: 'INT32',
54
- originalType: 'DATE',
55
- toPrimitive: toPrimitive_DATE,
56
- fromPrimitive: fromPrimitive_DATE
57
- },
58
- TIMESTAMP_MILLIS: {
59
- primitiveType: 'INT64',
60
- originalType: 'TIMESTAMP_MILLIS',
61
- toPrimitive: toPrimitive_TIMESTAMP_MILLIS,
62
- fromPrimitive: fromPrimitive_TIMESTAMP_MILLIS
63
- },
64
- TIMESTAMP_MICROS: {
65
- primitiveType: 'INT64',
66
- originalType: 'TIMESTAMP_MICROS',
67
- toPrimitive: toPrimitive_TIMESTAMP_MICROS,
68
- fromPrimitive: fromPrimitive_TIMESTAMP_MICROS
69
- },
70
- UINT_8: {
71
- primitiveType: 'INT32',
72
- originalType: 'UINT_8',
73
- toPrimitive: toPrimitive_UINT8
74
- },
75
- UINT_16: {
76
- primitiveType: 'INT32',
77
- originalType: 'UINT_16',
78
- toPrimitive: toPrimitive_UINT16
79
- },
80
- UINT_32: {
81
- primitiveType: 'INT32',
82
- originalType: 'UINT_32',
83
- toPrimitive: toPrimitive_UINT32
84
- },
85
- UINT_64: {
86
- primitiveType: 'INT64',
87
- originalType: 'UINT_64',
88
- toPrimitive: toPrimitive_UINT64
89
- },
90
- INT_8: {
91
- primitiveType: 'INT32',
92
- originalType: 'INT_8',
93
- toPrimitive: toPrimitive_INT8
94
- },
95
- INT_16: {
96
- primitiveType: 'INT32',
97
- originalType: 'INT_16',
98
- toPrimitive: toPrimitive_INT16
99
- },
100
- INT_32: {
101
- primitiveType: 'INT32',
102
- originalType: 'INT_32',
103
- toPrimitive: toPrimitive_INT32
104
- },
105
- INT_64: {
106
- primitiveType: 'INT64',
107
- originalType: 'INT_64',
108
- toPrimitive: toPrimitive_INT64
109
- },
110
- JSON: {
111
- primitiveType: 'BYTE_ARRAY',
112
- originalType: 'JSON',
113
- toPrimitive: toPrimitive_JSON,
114
- fromPrimitive: fromPrimitive_JSON
115
- },
116
- BSON: {
117
- primitiveType: 'BYTE_ARRAY',
118
- originalType: 'BSON',
119
- toPrimitive: toPrimitive_BSON,
120
- fromPrimitive: fromPrimitive_BSON
121
- },
122
- INTERVAL: {
123
- primitiveType: 'FIXED_LEN_BYTE_ARRAY',
124
- originalType: 'INTERVAL',
125
- typeLength: 12,
126
- toPrimitive: toPrimitive_INTERVAL,
127
- fromPrimitive: fromPrimitive_INTERVAL
128
- },
129
- DECIMAL_INT32: {
130
- primitiveType: 'INT32',
131
- originalType: 'DECIMAL_INT32',
132
- toPrimitive: decimalToPrimitive_INT32,
133
- fromPrimitive: decimalFromPrimitive_INT
134
- },
135
- DECIMAL_INT64: {
136
- primitiveType: 'INT64',
137
- originalType: 'DECIMAL_INT64',
138
- toPrimitive: decimalToPrimitive_INT64,
139
- fromPrimitive: decimalFromPrimitive_INT
140
- },
141
- DECIMAL_BYTE_ARRAY: {
142
- primitiveType: 'BYTE_ARRAY',
143
- originalType: 'DECIMAL_BYTE_ARRAY',
144
- toPrimitive: decimalToPrimitive_BYTE_ARRAY,
145
- fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
146
- },
147
- DECIMAL_FIXED_LEN_BYTE_ARRAY: {
148
- primitiveType: 'FIXED_LEN_BYTE_ARRAY',
149
- originalType: 'DECIMAL_FIXED_LEN_BYTE_ARRAY',
150
- toPrimitive: decimalToPrimitive_BYTE_ARRAY,
151
- fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
152
- }
5
+ BOOLEAN: {
6
+ primitiveType: 'BOOLEAN',
7
+ toPrimitive: toPrimitive_BOOLEAN,
8
+ fromPrimitive: fromPrimitive_BOOLEAN
9
+ },
10
+ INT32: {
11
+ primitiveType: 'INT32',
12
+ toPrimitive: toPrimitive_INT32
13
+ },
14
+ INT64: {
15
+ primitiveType: 'INT64',
16
+ toPrimitive: toPrimitive_INT64
17
+ },
18
+ INT96: {
19
+ primitiveType: 'INT96',
20
+ toPrimitive: toPrimitive_INT96
21
+ },
22
+ FLOAT: {
23
+ primitiveType: 'FLOAT',
24
+ toPrimitive: toPrimitive_FLOAT
25
+ },
26
+ DOUBLE: {
27
+ primitiveType: 'DOUBLE',
28
+ toPrimitive: toPrimitive_DOUBLE
29
+ },
30
+ BYTE_ARRAY: {
31
+ primitiveType: 'BYTE_ARRAY',
32
+ toPrimitive: toPrimitive_BYTE_ARRAY
33
+ },
34
+ FIXED_LEN_BYTE_ARRAY: {
35
+ primitiveType: 'FIXED_LEN_BYTE_ARRAY',
36
+ toPrimitive: toPrimitive_BYTE_ARRAY
37
+ },
38
+ UTF8: {
39
+ primitiveType: 'BYTE_ARRAY',
40
+ originalType: 'UTF8',
41
+ toPrimitive: toPrimitive_UTF8,
42
+ fromPrimitive: fromPrimitive_UTF8
43
+ },
44
+ TIME_MILLIS: {
45
+ primitiveType: 'INT32',
46
+ originalType: 'TIME_MILLIS',
47
+ toPrimitive: toPrimitive_TIME_MILLIS
48
+ },
49
+ TIME_MICROS: {
50
+ primitiveType: 'INT64',
51
+ originalType: 'TIME_MICROS',
52
+ toPrimitive: toPrimitive_TIME_MICROS
53
+ },
54
+ DATE: {
55
+ primitiveType: 'INT32',
56
+ originalType: 'DATE',
57
+ toPrimitive: toPrimitive_DATE,
58
+ fromPrimitive: fromPrimitive_DATE
59
+ },
60
+ TIMESTAMP_MILLIS: {
61
+ primitiveType: 'INT64',
62
+ originalType: 'TIMESTAMP_MILLIS',
63
+ toPrimitive: toPrimitive_TIMESTAMP_MILLIS,
64
+ fromPrimitive: fromPrimitive_TIMESTAMP_MILLIS
65
+ },
66
+ TIMESTAMP_MICROS: {
67
+ primitiveType: 'INT64',
68
+ originalType: 'TIMESTAMP_MICROS',
69
+ toPrimitive: toPrimitive_TIMESTAMP_MICROS,
70
+ fromPrimitive: fromPrimitive_TIMESTAMP_MICROS
71
+ },
72
+ UINT_8: {
73
+ primitiveType: 'INT32',
74
+ originalType: 'UINT_8',
75
+ toPrimitive: toPrimitive_UINT8
76
+ },
77
+ UINT_16: {
78
+ primitiveType: 'INT32',
79
+ originalType: 'UINT_16',
80
+ toPrimitive: toPrimitive_UINT16
81
+ },
82
+ UINT_32: {
83
+ primitiveType: 'INT32',
84
+ originalType: 'UINT_32',
85
+ toPrimitive: toPrimitive_UINT32
86
+ },
87
+ UINT_64: {
88
+ primitiveType: 'INT64',
89
+ originalType: 'UINT_64',
90
+ toPrimitive: toPrimitive_UINT64
91
+ },
92
+ INT_8: {
93
+ primitiveType: 'INT32',
94
+ originalType: 'INT_8',
95
+ toPrimitive: toPrimitive_INT8
96
+ },
97
+ INT_16: {
98
+ primitiveType: 'INT32',
99
+ originalType: 'INT_16',
100
+ toPrimitive: toPrimitive_INT16
101
+ },
102
+ INT_32: {
103
+ primitiveType: 'INT32',
104
+ originalType: 'INT_32',
105
+ toPrimitive: toPrimitive_INT32
106
+ },
107
+ INT_64: {
108
+ primitiveType: 'INT64',
109
+ originalType: 'INT_64',
110
+ toPrimitive: toPrimitive_INT64
111
+ },
112
+ JSON: {
113
+ primitiveType: 'BYTE_ARRAY',
114
+ originalType: 'JSON',
115
+ toPrimitive: toPrimitive_JSON,
116
+ fromPrimitive: fromPrimitive_JSON
117
+ },
118
+ BSON: {
119
+ primitiveType: 'BYTE_ARRAY',
120
+ originalType: 'BSON',
121
+ toPrimitive: toPrimitive_BSON,
122
+ fromPrimitive: fromPrimitive_BSON
123
+ },
124
+ INTERVAL: {
125
+ primitiveType: 'FIXED_LEN_BYTE_ARRAY',
126
+ originalType: 'INTERVAL',
127
+ typeLength: 12,
128
+ toPrimitive: toPrimitive_INTERVAL,
129
+ fromPrimitive: fromPrimitive_INTERVAL
130
+ },
131
+ DECIMAL_INT32: {
132
+ primitiveType: 'INT32',
133
+ originalType: 'DECIMAL_INT32',
134
+ toPrimitive: decimalToPrimitive_INT32,
135
+ fromPrimitive: decimalFromPrimitive_INT
136
+ },
137
+ DECIMAL_INT64: {
138
+ primitiveType: 'INT64',
139
+ originalType: 'DECIMAL_INT64',
140
+ toPrimitive: decimalToPrimitive_INT64,
141
+ fromPrimitive: decimalFromPrimitive_INT
142
+ },
143
+ DECIMAL_BYTE_ARRAY: {
144
+ primitiveType: 'BYTE_ARRAY',
145
+ originalType: 'DECIMAL_BYTE_ARRAY',
146
+ toPrimitive: decimalToPrimitive_BYTE_ARRAY,
147
+ fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
148
+ },
149
+ DECIMAL_FIXED_LEN_BYTE_ARRAY: {
150
+ primitiveType: 'FIXED_LEN_BYTE_ARRAY',
151
+ originalType: 'DECIMAL_FIXED_LEN_BYTE_ARRAY',
152
+ toPrimitive: decimalToPrimitive_BYTE_ARRAY,
153
+ fromPrimitive: decimalFromPrimitive_BYTE_ARRAY
154
+ }
153
155
  };
156
+ /**
157
+ * Convert a value from it's native representation to the internal/underlying
158
+ * primitive type
159
+ */
154
160
  export function toPrimitive(type, value, field) {
155
- if (!(type in PARQUET_LOGICAL_TYPES)) {
156
- throw new Error(`invalid type: ${type}`);
157
- }
158
- return PARQUET_LOGICAL_TYPES[type].toPrimitive(value, field);
161
+ if (!(type in PARQUET_LOGICAL_TYPES)) {
162
+ throw new Error(`invalid type: ${type}`);
163
+ }
164
+ return PARQUET_LOGICAL_TYPES[type].toPrimitive(value, field);
159
165
  }
166
+ /**
167
+ * Convert a value from it's internal/underlying primitive representation to
168
+ * the native representation
169
+ */
160
170
  export function fromPrimitive(type, value, field) {
161
- if (!(type in PARQUET_LOGICAL_TYPES)) {
162
- throw new Error(`invalid type: ${type}`);
163
- }
164
- if ('fromPrimitive' in PARQUET_LOGICAL_TYPES[type]) {
165
- var _PARQUET_LOGICAL_TYPE, _PARQUET_LOGICAL_TYPE2;
166
- return (_PARQUET_LOGICAL_TYPE = (_PARQUET_LOGICAL_TYPE2 = PARQUET_LOGICAL_TYPES[type]).fromPrimitive) === null || _PARQUET_LOGICAL_TYPE === void 0 ? void 0 : _PARQUET_LOGICAL_TYPE.call(_PARQUET_LOGICAL_TYPE2, value, field);
167
- }
168
- return value;
171
+ if (!(type in PARQUET_LOGICAL_TYPES)) {
172
+ throw new Error(`invalid type: ${type}`);
173
+ }
174
+ if ('fromPrimitive' in PARQUET_LOGICAL_TYPES[type]) {
175
+ return PARQUET_LOGICAL_TYPES[type].fromPrimitive?.(value, field);
176
+ // tslint:disable-next-line:no-else-after-return
177
+ }
178
+ return value;
169
179
  }
170
180
  function toPrimitive_BOOLEAN(value) {
171
- return Boolean(value);
181
+ return Boolean(value);
172
182
  }
173
183
  function fromPrimitive_BOOLEAN(value) {
174
- return Boolean(value);
184
+ return Boolean(value);
175
185
  }
176
186
  function toPrimitive_FLOAT(value) {
177
- const v = parseFloat(value);
178
- if (isNaN(v)) {
179
- throw new Error(`invalid value for FLOAT: ${value}`);
180
- }
181
- return v;
187
+ const v = parseFloat(value);
188
+ if (isNaN(v)) {
189
+ throw new Error(`invalid value for FLOAT: ${value}`);
190
+ }
191
+ return v;
182
192
  }
183
193
  function toPrimitive_DOUBLE(value) {
184
- const v = parseFloat(value);
185
- if (isNaN(v)) {
186
- throw new Error(`invalid value for DOUBLE: ${value}`);
187
- }
188
- return v;
194
+ const v = parseFloat(value);
195
+ if (isNaN(v)) {
196
+ throw new Error(`invalid value for DOUBLE: ${value}`);
197
+ }
198
+ return v;
189
199
  }
190
200
  function toPrimitive_INT8(value) {
191
- const v = parseInt(value, 10);
192
- if (v < -0x80 || v > 0x7f || isNaN(v)) {
193
- throw new Error(`invalid value for INT8: ${value}`);
194
- }
195
- return v;
201
+ const v = parseInt(value, 10);
202
+ if (v < -0x80 || v > 0x7f || isNaN(v)) {
203
+ throw new Error(`invalid value for INT8: ${value}`);
204
+ }
205
+ return v;
196
206
  }
197
207
  function toPrimitive_UINT8(value) {
198
- const v = parseInt(value, 10);
199
- if (v < 0 || v > 0xff || isNaN(v)) {
200
- throw new Error(`invalid value for UINT8: ${value}`);
201
- }
202
- return v;
208
+ const v = parseInt(value, 10);
209
+ if (v < 0 || v > 0xff || isNaN(v)) {
210
+ throw new Error(`invalid value for UINT8: ${value}`);
211
+ }
212
+ return v;
203
213
  }
204
214
  function toPrimitive_INT16(value) {
205
- const v = parseInt(value, 10);
206
- if (v < -0x8000 || v > 0x7fff || isNaN(v)) {
207
- throw new Error(`invalid value for INT16: ${value}`);
208
- }
209
- return v;
215
+ const v = parseInt(value, 10);
216
+ if (v < -0x8000 || v > 0x7fff || isNaN(v)) {
217
+ throw new Error(`invalid value for INT16: ${value}`);
218
+ }
219
+ return v;
210
220
  }
211
221
  function toPrimitive_UINT16(value) {
212
- const v = parseInt(value, 10);
213
- if (v < 0 || v > 0xffff || isNaN(v)) {
214
- throw new Error(`invalid value for UINT16: ${value}`);
215
- }
216
- return v;
222
+ const v = parseInt(value, 10);
223
+ if (v < 0 || v > 0xffff || isNaN(v)) {
224
+ throw new Error(`invalid value for UINT16: ${value}`);
225
+ }
226
+ return v;
217
227
  }
218
228
  function toPrimitive_INT32(value) {
219
- const v = parseInt(value, 10);
220
- if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
221
- throw new Error(`invalid value for INT32: ${value}`);
222
- }
223
- return v;
229
+ const v = parseInt(value, 10);
230
+ if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
231
+ throw new Error(`invalid value for INT32: ${value}`);
232
+ }
233
+ return v;
224
234
  }
225
235
  function decimalToPrimitive_INT32(value, field) {
226
- const primitiveValue = value * 10 ** (field.scale || 0);
227
- const v = Math.round(primitiveValue * 10 ** -field.presision % 1 * 10 ** field.presision);
228
- if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
229
- throw new Error(`invalid value for INT32: ${value}`);
230
- }
231
- return v;
236
+ const primitiveValue = value * 10 ** (field.scale || 0);
237
+ const v = Math.round(((primitiveValue * 10 ** -field.presision) % 1) * 10 ** field.presision);
238
+ if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
239
+ throw new Error(`invalid value for INT32: ${value}`);
240
+ }
241
+ return v;
232
242
  }
233
243
  function toPrimitive_UINT32(value) {
234
- const v = parseInt(value, 10);
235
- if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
236
- throw new Error(`invalid value for UINT32: ${value}`);
237
- }
238
- return v;
244
+ const v = parseInt(value, 10);
245
+ if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
246
+ throw new Error(`invalid value for UINT32: ${value}`);
247
+ }
248
+ return v;
239
249
  }
240
250
  function toPrimitive_INT64(value) {
241
- const v = parseInt(value, 10);
242
- if (isNaN(v)) {
243
- throw new Error(`invalid value for INT64: ${value}`);
244
- }
245
- return v;
251
+ const v = parseInt(value, 10);
252
+ if (isNaN(v)) {
253
+ throw new Error(`invalid value for INT64: ${value}`);
254
+ }
255
+ return v;
246
256
  }
247
257
  function decimalToPrimitive_INT64(value, field) {
248
- const primitiveValue = value * 10 ** (field.scale || 0);
249
- const v = Math.round(primitiveValue * 10 ** -field.presision % 1 * 10 ** field.presision);
250
- if (isNaN(v)) {
251
- throw new Error(`invalid value for INT64: ${value}`);
252
- }
253
- return v;
258
+ const primitiveValue = value * 10 ** (field.scale || 0);
259
+ const v = Math.round(((primitiveValue * 10 ** -field.presision) % 1) * 10 ** field.presision);
260
+ if (isNaN(v)) {
261
+ throw new Error(`invalid value for INT64: ${value}`);
262
+ }
263
+ return v;
254
264
  }
255
265
  function toPrimitive_UINT64(value) {
256
- const v = parseInt(value, 10);
257
- if (v < 0 || isNaN(v)) {
258
- throw new Error(`invalid value for UINT64: ${value}`);
259
- }
260
- return v;
266
+ const v = parseInt(value, 10);
267
+ if (v < 0 || isNaN(v)) {
268
+ throw new Error(`invalid value for UINT64: ${value}`);
269
+ }
270
+ return v;
261
271
  }
262
272
  function toPrimitive_INT96(value) {
263
- const v = parseInt(value, 10);
264
- if (isNaN(v)) {
265
- throw new Error(`invalid value for INT96: ${value}`);
266
- }
267
- return v;
273
+ const v = parseInt(value, 10);
274
+ if (isNaN(v)) {
275
+ throw new Error(`invalid value for INT96: ${value}`);
276
+ }
277
+ return v;
268
278
  }
269
279
  function toPrimitive_BYTE_ARRAY(value) {
270
- return Buffer.from(value);
280
+ return Buffer.from(value);
271
281
  }
272
282
  function decimalToPrimitive_BYTE_ARRAY(value) {
273
- return Buffer.from(value);
283
+ // TBD
284
+ return Buffer.from(value);
274
285
  }
275
286
  function toPrimitive_UTF8(value) {
276
- return Buffer.from(value, 'utf8');
287
+ return Buffer.from(value, 'utf8');
277
288
  }
278
289
  function fromPrimitive_UTF8(value) {
279
- return value.toString();
290
+ return value.toString();
280
291
  }
281
292
  function toPrimitive_JSON(value) {
282
- return Buffer.from(JSON.stringify(value));
293
+ return Buffer.from(JSON.stringify(value));
283
294
  }
284
295
  function fromPrimitive_JSON(value) {
285
- return JSON.parse(value);
296
+ return JSON.parse(value);
286
297
  }
287
298
  function toPrimitive_BSON(value) {
288
- var _BSONWriter$encodeSyn;
289
- const arrayBuffer = (_BSONWriter$encodeSyn = BSONWriter.encodeSync) === null || _BSONWriter$encodeSyn === void 0 ? void 0 : _BSONWriter$encodeSyn.call(BSONWriter, value);
290
- return Buffer.from(arrayBuffer);
299
+ const arrayBuffer = BSONWriter.encodeSync?.(value);
300
+ return Buffer.from(arrayBuffer);
291
301
  }
292
302
  function fromPrimitive_BSON(value) {
293
- var _BSONLoader$parseSync;
294
- return (_BSONLoader$parseSync = BSONLoader.parseSync) === null || _BSONLoader$parseSync === void 0 ? void 0 : _BSONLoader$parseSync.call(BSONLoader, value);
303
+ return BSONLoader.parseSync?.(value);
295
304
  }
296
305
  function toPrimitive_TIME_MILLIS(value) {
297
- const v = parseInt(value, 10);
298
- if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) {
299
- throw new Error(`invalid value for TIME_MILLIS: ${value}`);
300
- }
301
- return v;
306
+ const v = parseInt(value, 10);
307
+ if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) {
308
+ throw new Error(`invalid value for TIME_MILLIS: ${value}`);
309
+ }
310
+ return v;
302
311
  }
303
312
  function toPrimitive_TIME_MICROS(value) {
304
- const v = parseInt(value, 10);
305
- if (v < 0 || isNaN(v)) {
306
- throw new Error(`invalid value for TIME_MICROS: ${value}`);
307
- }
308
- return v;
309
- }
310
- const kMillisPerDay = 86400000;
311
- function toPrimitive_DATE(value) {
312
- if (value instanceof Date) {
313
- return value.getTime() / kMillisPerDay;
314
- }
315
- {
316
313
  const v = parseInt(value, 10);
317
314
  if (v < 0 || isNaN(v)) {
318
- throw new Error(`invalid value for DATE: ${value}`);
315
+ throw new Error(`invalid value for TIME_MICROS: ${value}`);
319
316
  }
320
317
  return v;
321
- }
318
+ }
319
+ const kMillisPerDay = 86400000;
320
+ function toPrimitive_DATE(value) {
321
+ /* convert from date */
322
+ if (value instanceof Date) {
323
+ return value.getTime() / kMillisPerDay;
324
+ }
325
+ /* convert from integer */
326
+ {
327
+ const v = parseInt(value, 10);
328
+ if (v < 0 || isNaN(v)) {
329
+ throw new Error(`invalid value for DATE: ${value}`);
330
+ }
331
+ return v;
332
+ }
322
333
  }
323
334
  function fromPrimitive_DATE(value) {
324
- return new Date(value * kMillisPerDay);
335
+ return new Date(value * kMillisPerDay);
325
336
  }
326
337
  function toPrimitive_TIMESTAMP_MILLIS(value) {
327
- if (value instanceof Date) {
328
- return value.getTime();
329
- }
330
- {
331
- const v = parseInt(value, 10);
332
- if (v < 0 || isNaN(v)) {
333
- throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
338
+ /* convert from date */
339
+ if (value instanceof Date) {
340
+ return value.getTime();
341
+ }
342
+ /* convert from integer */
343
+ {
344
+ const v = parseInt(value, 10);
345
+ if (v < 0 || isNaN(v)) {
346
+ throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
347
+ }
348
+ return v;
334
349
  }
335
- return v;
336
- }
337
350
  }
338
351
  function fromPrimitive_TIMESTAMP_MILLIS(value) {
339
- return new Date(value);
352
+ return new Date(value);
340
353
  }
341
354
  function toPrimitive_TIMESTAMP_MICROS(value) {
342
- if (value instanceof Date) {
343
- return value.getTime() * 1000;
344
- }
345
- {
346
- const v = parseInt(value, 10);
347
- if (v < 0 || isNaN(v)) {
348
- throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
355
+ /* convert from date */
356
+ if (value instanceof Date) {
357
+ return value.getTime() * 1000;
358
+ }
359
+ /* convert from integer */
360
+ {
361
+ const v = parseInt(value, 10);
362
+ if (v < 0 || isNaN(v)) {
363
+ throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
364
+ }
365
+ return v;
349
366
  }
350
- return v;
351
- }
352
367
  }
353
368
  function fromPrimitive_TIMESTAMP_MICROS(value) {
354
- return new Date(value / 1000);
369
+ return new Date(value / 1000);
355
370
  }
356
371
  function toPrimitive_INTERVAL(value) {
357
- if (!value.months || !value.days || !value.milliseconds) {
358
- throw new Error('value for INTERVAL must be object { months: ..., days: ..., milliseconds: ... }');
359
- }
360
- const buf = Buffer.alloc(12);
361
- buf.writeUInt32LE(value.months, 0);
362
- buf.writeUInt32LE(value.days, 4);
363
- buf.writeUInt32LE(value.milliseconds, 8);
364
- return buf;
372
+ if (!value.months || !value.days || !value.milliseconds) {
373
+ throw new Error('value for INTERVAL must be object { months: ..., days: ..., milliseconds: ... }');
374
+ }
375
+ const buf = Buffer.alloc(12);
376
+ buf.writeUInt32LE(value.months, 0);
377
+ buf.writeUInt32LE(value.days, 4);
378
+ buf.writeUInt32LE(value.milliseconds, 8);
379
+ return buf;
365
380
  }
366
381
  function fromPrimitive_INTERVAL(value) {
367
- const buf = Buffer.from(value);
368
- const months = buf.readUInt32LE(0);
369
- const days = buf.readUInt32LE(4);
370
- const millis = buf.readUInt32LE(8);
371
- return {
372
- months,
373
- days,
374
- milliseconds: millis
375
- };
382
+ const buf = Buffer.from(value);
383
+ const months = buf.readUInt32LE(0);
384
+ const days = buf.readUInt32LE(4);
385
+ const millis = buf.readUInt32LE(8);
386
+ return { months, days, milliseconds: millis };
376
387
  }
377
388
  function decimalFromPrimitive_INT(value, field) {
378
- const presisionInt = Math.round(value * 10 ** -field.presision % 1 * 10 ** field.presision);
379
- return presisionInt * 10 ** -(field.scale || 0);
389
+ const presisionInt = Math.round(((value * 10 ** -field.presision) % 1) * 10 ** field.presision);
390
+ return presisionInt * 10 ** -(field.scale || 0);
380
391
  }
381
392
  function decimalFromPrimitive_BYTE_ARRAY(value, field) {
382
- let number = 0;
383
- if (value.length <= 4) {
384
- for (let i = 0; i < value.length; i++) {
385
- const component = value[i] << 8 * (value.length - i - 1);
386
- number += component;
393
+ let number = 0;
394
+ if (value.length <= 4) {
395
+ // Bytewise operators faster. Use them if it is possible
396
+ for (let i = 0; i < value.length; i++) {
397
+ // `value.length - i - 1` bytes have reverse order (big-endian)
398
+ const component = value[i] << (8 * (value.length - i - 1));
399
+ number += component;
400
+ }
387
401
  }
388
- } else {
389
- for (let i = 0; i < value.length; i++) {
390
- const component = value[i] * 2 ** (8 * (value.length - 1 - i));
391
- number += component;
402
+ else {
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] * 2 ** (8 * (value.length - 1 - i));
406
+ number += component;
407
+ }
392
408
  }
393
- }
394
- const presisionInt = Math.round(number * 10 ** -field.presision % 1 * 10 ** field.presision);
395
- return presisionInt * 10 ** -(field.scale || 0);
409
+ const presisionInt = Math.round(((number * 10 ** -field.presision) % 1) * 10 ** field.presision);
410
+ return presisionInt * 10 ** -(field.scale || 0);
396
411
  }
397
- //# sourceMappingURL=types.js.map