@kepler.gl/utils 3.3.0-alpha.2 → 3.3.0-alpha.21

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 (264) hide show
  1. package/dist/application-config.d.ts +180 -1
  2. package/dist/arrow-data-container.d.ts +55 -2
  3. package/dist/camera-tour.d.ts +11 -0
  4. package/dist/camera-utils.d.ts +7 -0
  5. package/dist/cjs/aggregation.js +84 -0
  6. package/dist/cjs/aggregation.js.map +1 -0
  7. package/dist/cjs/application-config-types.js +6 -0
  8. package/dist/cjs/application-config-types.js.map +1 -0
  9. package/dist/cjs/application-config.js +178 -0
  10. package/dist/cjs/application-config.js.map +1 -0
  11. package/dist/cjs/arrow-data-container.js +1152 -0
  12. package/dist/cjs/arrow-data-container.js.map +1 -0
  13. package/dist/cjs/browser-utils.js +17 -0
  14. package/dist/cjs/browser-utils.js.map +1 -0
  15. package/dist/cjs/camera-tour.js +99 -0
  16. package/dist/cjs/camera-tour.js.map +1 -0
  17. package/dist/cjs/camera-utils.js +81 -0
  18. package/dist/cjs/camera-utils.js.map +1 -0
  19. package/dist/cjs/color-utils.js +462 -0
  20. package/dist/cjs/color-utils.js.map +1 -0
  21. package/dist/cjs/column-statistics.js +115 -0
  22. package/dist/cjs/column-statistics.js.map +1 -0
  23. package/dist/cjs/data-container-interface.js +6 -0
  24. package/dist/cjs/data-container-interface.js.map +1 -0
  25. package/dist/cjs/data-container-utils.js +76 -0
  26. package/dist/cjs/data-container-utils.js.map +1 -0
  27. package/dist/cjs/data-row.js +110 -0
  28. package/dist/cjs/data-row.js.map +1 -0
  29. package/dist/cjs/data-scale-utils.js +634 -0
  30. package/dist/cjs/data-scale-utils.js.map +1 -0
  31. package/dist/cjs/data-utils.js +538 -0
  32. package/dist/cjs/data-utils.js.map +1 -0
  33. package/dist/cjs/dataset-utils.js +361 -0
  34. package/dist/cjs/dataset-utils.js.map +1 -0
  35. package/dist/cjs/dom-to-image.js +433 -0
  36. package/dist/cjs/dom-to-image.js.map +1 -0
  37. package/dist/cjs/dom-utils.js +349 -0
  38. package/dist/cjs/dom-utils.js.map +1 -0
  39. package/dist/cjs/editor-feature-utils.js +177 -0
  40. package/dist/cjs/editor-feature-utils.js.map +1 -0
  41. package/dist/cjs/effect-utils.js +340 -0
  42. package/dist/cjs/effect-utils.js.map +1 -0
  43. package/dist/cjs/export-map-html.js +112 -0
  44. package/dist/cjs/export-map-html.js.map +1 -0
  45. package/dist/cjs/export-utils.js +318 -0
  46. package/dist/cjs/export-utils.js.map +1 -0
  47. package/dist/cjs/extract-dataset-utils.js +218 -0
  48. package/dist/cjs/extract-dataset-utils.js.map +1 -0
  49. package/dist/cjs/filter-utils.js +1762 -0
  50. package/dist/cjs/filter-utils.js.map +1 -0
  51. package/dist/cjs/format.js +38 -0
  52. package/dist/cjs/format.js.map +1 -0
  53. package/dist/cjs/gl-utils.js +118 -0
  54. package/dist/cjs/gl-utils.js.map +1 -0
  55. package/dist/{index.js → cjs/index.js} +391 -10
  56. package/dist/cjs/index.js.map +1 -0
  57. package/dist/cjs/indexed-data-container.js +214 -0
  58. package/dist/cjs/indexed-data-container.js.map +1 -0
  59. package/dist/cjs/jenks.js +156 -0
  60. package/dist/cjs/jenks.js.map +1 -0
  61. package/dist/cjs/locale-utils.js +39 -0
  62. package/dist/cjs/locale-utils.js.map +1 -0
  63. package/dist/cjs/map-info-utils.js +41 -0
  64. package/dist/cjs/map-info-utils.js.map +1 -0
  65. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
  66. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  67. package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
  68. package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
  69. package/dist/cjs/map-utils.js +76 -0
  70. package/dist/cjs/map-utils.js.map +1 -0
  71. package/dist/cjs/mapbox-utils.js +19 -0
  72. package/dist/cjs/mapbox-utils.js.map +1 -0
  73. package/dist/cjs/notifications-utils.js +69 -0
  74. package/dist/cjs/notifications-utils.js.map +1 -0
  75. package/dist/cjs/observe-dimensions.js +136 -0
  76. package/dist/cjs/observe-dimensions.js.map +1 -0
  77. package/dist/cjs/plot.js +1502 -0
  78. package/dist/cjs/plot.js.map +1 -0
  79. package/dist/cjs/position-utils.js +29 -0
  80. package/dist/cjs/position-utils.js.map +1 -0
  81. package/dist/cjs/projection-utils.js +141 -0
  82. package/dist/cjs/projection-utils.js.map +1 -0
  83. package/dist/cjs/quick-insertion-sort.js +132 -0
  84. package/dist/cjs/quick-insertion-sort.js.map +1 -0
  85. package/dist/cjs/row-data-container.js +291 -0
  86. package/dist/cjs/row-data-container.js.map +1 -0
  87. package/dist/cjs/slider-scale-utils.js +138 -0
  88. package/dist/cjs/slider-scale-utils.js.map +1 -0
  89. package/dist/cjs/split-map-utils.js +117 -0
  90. package/dist/cjs/split-map-utils.js.map +1 -0
  91. package/dist/cjs/strings.js +16 -0
  92. package/dist/cjs/strings.js.map +1 -0
  93. package/dist/cjs/theme-utils.js +46 -0
  94. package/dist/cjs/theme-utils.js.map +1 -0
  95. package/dist/cjs/time.js +321 -0
  96. package/dist/cjs/time.js.map +1 -0
  97. package/dist/cjs/types.js +6 -0
  98. package/dist/cjs/types.js.map +1 -0
  99. package/dist/cjs/utils.js +224 -0
  100. package/dist/cjs/utils.js.map +1 -0
  101. package/dist/column-statistics.d.ts +54 -0
  102. package/dist/data-container-interface.d.ts +16 -1
  103. package/dist/data-container-utils.d.ts +2 -1
  104. package/dist/data-scale-utils.d.ts +5 -0
  105. package/dist/data-utils.d.ts +3 -3
  106. package/dist/dataset-utils.d.ts +11 -28
  107. package/dist/editor-feature-utils.d.ts +30 -0
  108. package/dist/esm/aggregation.js +75 -0
  109. package/dist/esm/aggregation.js.map +1 -0
  110. package/dist/esm/application-config-types.js +3 -0
  111. package/dist/esm/application-config-types.js.map +1 -0
  112. package/dist/esm/application-config.js +167 -0
  113. package/dist/esm/application-config.js.map +1 -0
  114. package/dist/esm/arrow-data-container.js +1136 -0
  115. package/dist/esm/arrow-data-container.js.map +1 -0
  116. package/dist/esm/browser-utils.js +11 -0
  117. package/dist/esm/browser-utils.js.map +1 -0
  118. package/dist/esm/camera-tour.js +92 -0
  119. package/dist/esm/camera-tour.js.map +1 -0
  120. package/dist/esm/camera-utils.js +74 -0
  121. package/dist/esm/camera-utils.js.map +1 -0
  122. package/dist/esm/color-utils.js +435 -0
  123. package/dist/esm/color-utils.js.map +1 -0
  124. package/dist/esm/column-statistics.js +105 -0
  125. package/dist/esm/column-statistics.js.map +1 -0
  126. package/dist/esm/data-container-interface.js +3 -0
  127. package/dist/esm/data-container-interface.js.map +1 -0
  128. package/dist/esm/data-container-utils.js +68 -0
  129. package/dist/esm/data-container-utils.js.map +1 -0
  130. package/dist/esm/data-row.js +106 -0
  131. package/dist/esm/data-row.js.map +1 -0
  132. package/dist/esm/data-scale-utils.js +602 -0
  133. package/dist/esm/data-scale-utils.js.map +1 -0
  134. package/dist/esm/data-utils.js +504 -0
  135. package/dist/esm/data-utils.js.map +1 -0
  136. package/dist/esm/dataset-utils.js +352 -0
  137. package/dist/esm/dataset-utils.js.map +1 -0
  138. package/dist/esm/dom-to-image.js +426 -0
  139. package/dist/esm/dom-to-image.js.map +1 -0
  140. package/dist/esm/dom-utils.js +323 -0
  141. package/dist/esm/dom-utils.js.map +1 -0
  142. package/dist/esm/editor-feature-utils.js +164 -0
  143. package/dist/esm/editor-feature-utils.js.map +1 -0
  144. package/dist/esm/effect-utils.js +333 -0
  145. package/dist/esm/effect-utils.js.map +1 -0
  146. package/dist/esm/export-map-html.js +107 -0
  147. package/dist/esm/export-map-html.js.map +1 -0
  148. package/dist/esm/export-utils.js +297 -0
  149. package/dist/esm/export-utils.js.map +1 -0
  150. package/dist/esm/extract-dataset-utils.js +206 -0
  151. package/dist/esm/extract-dataset-utils.js.map +1 -0
  152. package/dist/esm/filter-utils.js +1701 -0
  153. package/dist/esm/filter-utils.js.map +1 -0
  154. package/dist/esm/format.js +31 -0
  155. package/dist/esm/format.js.map +1 -0
  156. package/dist/esm/gl-utils.js +113 -0
  157. package/dist/esm/gl-utils.js.map +1 -0
  158. package/dist/esm/index.js +55 -0
  159. package/dist/esm/index.js.map +1 -0
  160. package/dist/esm/indexed-data-container.js +210 -0
  161. package/dist/esm/indexed-data-container.js.map +1 -0
  162. package/dist/esm/jenks.js +149 -0
  163. package/dist/esm/jenks.js.map +1 -0
  164. package/dist/esm/locale-utils.js +36 -0
  165. package/dist/esm/locale-utils.js.map +1 -0
  166. package/dist/esm/map-info-utils.js +35 -0
  167. package/dist/esm/map-info-utils.js.map +1 -0
  168. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
  169. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  170. package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
  171. package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
  172. package/dist/esm/map-utils.js +72 -0
  173. package/dist/esm/map-utils.js.map +1 -0
  174. package/dist/esm/mapbox-utils.js +13 -0
  175. package/dist/esm/mapbox-utils.js.map +1 -0
  176. package/dist/esm/notifications-utils.js +63 -0
  177. package/dist/esm/notifications-utils.js.map +1 -0
  178. package/dist/esm/observe-dimensions.js +128 -0
  179. package/dist/esm/observe-dimensions.js.map +1 -0
  180. package/dist/esm/plot.js +1460 -0
  181. package/dist/esm/plot.js.map +1 -0
  182. package/dist/esm/position-utils.js +22 -0
  183. package/dist/esm/position-utils.js.map +1 -0
  184. package/dist/esm/projection-utils.js +131 -0
  185. package/dist/esm/projection-utils.js.map +1 -0
  186. package/dist/esm/quick-insertion-sort.js +125 -0
  187. package/dist/esm/quick-insertion-sort.js.map +1 -0
  188. package/dist/esm/row-data-container.js +286 -0
  189. package/dist/esm/row-data-container.js.map +1 -0
  190. package/dist/esm/slider-scale-utils.js +129 -0
  191. package/dist/esm/slider-scale-utils.js.map +1 -0
  192. package/dist/esm/split-map-utils.js +109 -0
  193. package/dist/esm/split-map-utils.js.map +1 -0
  194. package/dist/esm/strings.js +10 -0
  195. package/dist/esm/strings.js.map +1 -0
  196. package/dist/esm/theme-utils.js +38 -0
  197. package/dist/esm/theme-utils.js.map +1 -0
  198. package/dist/esm/time.js +308 -0
  199. package/dist/esm/time.js.map +1 -0
  200. package/dist/esm/types.js +3 -0
  201. package/dist/esm/types.js.map +1 -0
  202. package/dist/esm/utils.js +203 -0
  203. package/dist/esm/utils.js.map +1 -0
  204. package/dist/export-map-html.d.ts +5 -0
  205. package/dist/export-utils.d.ts +31 -3
  206. package/dist/extract-dataset-utils.d.ts +79 -0
  207. package/dist/filter-utils.d.ts +56 -7
  208. package/dist/index.d.ts +20 -9
  209. package/dist/jenks.d.ts +5 -0
  210. package/dist/map-info-utils.d.ts +11 -1
  211. package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
  212. package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
  213. package/dist/plot.d.ts +187 -21
  214. package/dist/projection-utils.d.ts +6 -4
  215. package/dist/row-data-container.d.ts +19 -0
  216. package/dist/split-map-utils.d.ts +7 -0
  217. package/dist/theme-utils.d.ts +8 -0
  218. package/dist/time.d.ts +3 -3
  219. package/dist/types.d.ts +2 -0
  220. package/package.json +33 -26
  221. package/dist/aggregation.js +0 -84
  222. package/dist/application-config-types.js +0 -6
  223. package/dist/application-config.js +0 -113
  224. package/dist/arrow-data-container.js +0 -398
  225. package/dist/browser-utils.js +0 -17
  226. package/dist/color-utils.js +0 -462
  227. package/dist/data-container-interface.js +0 -6
  228. package/dist/data-container-utils.js +0 -75
  229. package/dist/data-row.js +0 -110
  230. package/dist/data-scale-utils.js +0 -620
  231. package/dist/data-utils.js +0 -532
  232. package/dist/dataset-utils.js +0 -330
  233. package/dist/dom-to-image.js +0 -433
  234. package/dist/dom-utils.js +0 -349
  235. package/dist/effect-utils.js +0 -318
  236. package/dist/export-map-html.js +0 -38
  237. package/dist/export-utils.js +0 -203
  238. package/dist/filter-utils.js +0 -1274
  239. package/dist/format.js +0 -38
  240. package/dist/gl-utils.js +0 -118
  241. package/dist/indexed-data-container.js +0 -214
  242. package/dist/locale-utils.js +0 -39
  243. package/dist/map-info-utils.js +0 -14
  244. package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
  245. package/dist/map-style-utils/mapbox-utils.js +0 -107
  246. package/dist/map-utils.js +0 -72
  247. package/dist/mapbox-utils.js +0 -19
  248. package/dist/noop.d.ts +0 -1
  249. package/dist/noop.js +0 -13
  250. package/dist/notifications-utils.js +0 -69
  251. package/dist/observe-dimensions.js +0 -136
  252. package/dist/plot.js +0 -637
  253. package/dist/position-utils.js +0 -26
  254. package/dist/projection-utils.js +0 -91
  255. package/dist/quick-insertion-sort.js +0 -132
  256. package/dist/row-data-container.js +0 -206
  257. package/dist/searcher-utils.d.ts +0 -1
  258. package/dist/searcher-utils.js +0 -25
  259. package/dist/slider-scale-utils.js +0 -138
  260. package/dist/split-map-utils.js +0 -99
  261. package/dist/strings.js +0 -16
  262. package/dist/time.js +0 -325
  263. package/dist/types.js +0 -6
  264. package/dist/utils.js +0 -224
@@ -0,0 +1,1136 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
7
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
13
+ var _marked = /*#__PURE__*/_regeneratorRuntime.mark(rowsIterator),
14
+ _marked2 = /*#__PURE__*/_regeneratorRuntime.mark(columnIterator);
15
+ // SPDX-License-Identifier: MIT
16
+ // Copyright contributors to the kepler.gl project
17
+
18
+ import { ALL_FIELD_TYPES, GEOARROW_METADATA_KEY } from '@kepler.gl/constants';
19
+ import * as arrow from 'apache-arrow';
20
+ import { console as globalConsole } from 'global/window';
21
+ import { DATA_TYPES as AnalyzerDATA_TYPES } from 'type-analyzer';
22
+ import { getApplicationConfig } from './application-config';
23
+ import { DataRow } from './data-row';
24
+ /**
25
+ * Check if table is an ArrowTable object.
26
+ *
27
+ * We use duck-typing instead of `instanceof arrow.Table` because DuckDB loads its own
28
+ * bundled version of Apache Arrow. When DuckDB creates Arrow tables, they are instances
29
+ * of DuckDB's Arrow.Table class, not the Arrow.Table class from our application's
30
+ * apache-arrow package. This causes `instanceof` checks to fail even though the objects
31
+ * are functionally equivalent Arrow tables.
32
+ *
33
+ * @param data - object to check
34
+ * @returns true if data is an ArrowTable object (type guarded)
35
+ */
36
+ export function isArrowTable(data) {
37
+ return _typeof(data) === 'object' && data !== null && 'schema' in data && 'getChildAt' in data && typeof data.getChildAt === 'function' && 'batches' in data && Array.isArray(data.batches);
38
+ }
39
+
40
+ /**
41
+ * Check if data is an ArrowVector object.
42
+ * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version.
43
+ *
44
+ * @param data - object to check
45
+ * @returns true if data is an ArrowVector object (type guarded)
46
+ */
47
+ export function isArrowVector(data) {
48
+ return _typeof(data) === 'object' && data !== null && 'type' in data && 'length' in data && typeof data.length === 'number' && 'get' in data && typeof data.get === 'function' && 'data' in data && Array.isArray(data.data);
49
+ }
50
+
51
+ /**
52
+ * Normalize native point coordinates for deck.gl and loaders.gl. Interleaved
53
+ * coordinates are already usable and retain their buffers without copying.
54
+ */
55
+ export function convertStructToFixedSizeList(coords) {
56
+ if (arrow.DataType.isFixedSizeList(coords.type)) {
57
+ var pointData = coords;
58
+ var child = pointData.children[0];
59
+ var length = coords.length * coords.type.listSize;
60
+ // IPC/compaction can pad the final buffer. Expose only logical coordinates
61
+ // to loaders.gl, which derives feature counts and bounds from buffer length.
62
+ return child.values.length === length ? pointData : pointData.clone(undefined, undefined, undefined, undefined, undefined, [child.slice(0, length)]);
63
+ }
64
+ if (!arrow.DataType.isStruct(coords.type)) {
65
+ throw new Error('Expected GeoArrow point coordinates');
66
+ }
67
+ var dimensions = coords.children.length;
68
+ var values = new Float64Array(coords.length * dimensions);
69
+ var _loop = function _loop(i) {
70
+ // Arrow slices already slice child values. Parent/child validity bitmaps
71
+ // retain their own offsets, which getValid accounts for.
72
+ var valid = coords.getValid(i) && coords.children.every(function (child) {
73
+ return child.getValid(i) && Number.isFinite(child.values[i]);
74
+ });
75
+ for (var axis = 0; axis < dimensions; axis++) {
76
+ // Preserve row alignment while keeping missing/empty points out of bounds
77
+ // and rendering. Float64 also preserves Float32 input values exactly.
78
+ values[i * dimensions + axis] = valid ? coords.children[axis].values[i] : NaN;
79
+ }
80
+ };
81
+ for (var i = 0; i < coords.length; i++) {
82
+ _loop(i);
83
+ }
84
+ var floatType = new arrow.Float64();
85
+ return arrow.makeData({
86
+ type: new arrow.FixedSizeList(dimensions, new arrow.Field('coords', floatType)),
87
+ offset: coords.offset,
88
+ length: coords.length,
89
+ nullCount: coords.nullCount,
90
+ nullBitmap: coords.nullBitmap,
91
+ child: arrow.makeData({
92
+ type: floatType,
93
+ length: values.length,
94
+ data: values
95
+ })
96
+ });
97
+ }
98
+
99
+ /** Build an Arrow vector while letting Arrow infer the physical type from converted values. */
100
+ export function createArrowVector(values) {
101
+ return arrow.vectorFromArray(values);
102
+ }
103
+
104
+ /**
105
+ * Check if data is an Arrow FixedSizeList DataType.
106
+ * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version.
107
+ *
108
+ * @param data - object to check
109
+ * @returns true if data is an Arrow FixedSizeList DataType (type guarded)
110
+ */
111
+ export function isArrowFixedSizeList(data) {
112
+ return _typeof(data) === 'object' && data !== null && 'typeId' in data && 'listSize' in data && typeof data.listSize === 'number' && 'children' in data && Array.isArray(data.children);
113
+ }
114
+
115
+ /**
116
+ * Check if data is an Arrow Struct DataType.
117
+ * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version.
118
+ *
119
+ * @param data - object to check
120
+ * @returns true if data is an Arrow Struct DataType (type guarded)
121
+ */
122
+ export function isArrowStruct(data) {
123
+ return _typeof(data) === 'object' && data !== null && 'typeId' in data && 'children' in data && Array.isArray(data.children) && !('listSize' in data);
124
+ }
125
+
126
+ /**
127
+ * @param dataContainer
128
+ * @param sharedRow
129
+ */
130
+ function rowsIterator(dataContainer, sharedRow) {
131
+ var numRows, rowIndex;
132
+ return _regeneratorRuntime.wrap(function rowsIterator$(_context) {
133
+ while (1) switch (_context.prev = _context.next) {
134
+ case 0:
135
+ numRows = dataContainer.numRows();
136
+ rowIndex = 0;
137
+ case 2:
138
+ if (!(rowIndex < numRows)) {
139
+ _context.next = 8;
140
+ break;
141
+ }
142
+ _context.next = 5;
143
+ return dataContainer.row(rowIndex, sharedRow);
144
+ case 5:
145
+ ++rowIndex;
146
+ _context.next = 2;
147
+ break;
148
+ case 8:
149
+ case "end":
150
+ return _context.stop();
151
+ }
152
+ }, _marked);
153
+ }
154
+
155
+ /**
156
+ * @param dataContainer
157
+ * @param columnIndex
158
+ */
159
+ function columnIterator(dataContainer, columnIndex) {
160
+ var numRows, rowIndex;
161
+ return _regeneratorRuntime.wrap(function columnIterator$(_context2) {
162
+ while (1) switch (_context2.prev = _context2.next) {
163
+ case 0:
164
+ numRows = dataContainer.numRows();
165
+ rowIndex = 0;
166
+ case 2:
167
+ if (!(rowIndex < numRows)) {
168
+ _context2.next = 8;
169
+ break;
170
+ }
171
+ _context2.next = 5;
172
+ return dataContainer.valueAt(rowIndex, columnIndex);
173
+ case 5:
174
+ ++rowIndex;
175
+ _context2.next = 2;
176
+ break;
177
+ case 8:
178
+ case "end":
179
+ return _context2.stop();
180
+ }
181
+ }, _marked2);
182
+ }
183
+ var DEFAULT_MAX_ARROW_BATCHES = 1;
184
+
185
+ /**
186
+ * Collapse Arrow record batches into as few chunks as possible.
187
+ *
188
+ * Deck.gl picking encodes at most 255 pickable leaf layers. Kepler creates one
189
+ * Deck layer per Arrow record batch (and GeoJsonLayer adds fill/stroke/point
190
+ * sublayers), so parquet/DuckDB tables with hundreds of batches make hover and
191
+ * click miss most of the data. Combining chunks keeps picking under that cap
192
+ * without changing row values.
193
+ *
194
+ * apache-arrow JS does not expose Vector.combineChunks in the version Kepler
195
+ * uses, so we rebuild each column through a Builder (one chunk per column).
196
+ *
197
+ * Compaction only runs when `table.batches.length` is greater than
198
+ * `maxArrowBatches` from {@link getApplicationConfig} (default `1`) or the
199
+ * optional override. Progressive Arrow loading does not compact on each
200
+ * incoming batch; {@link ArrowDataContainer.update} assigns new chunks as-is
201
+ * and the completed file is compacted once.
202
+ */
203
+ export function compactArrowTable(table, maxArrowBatches) {
204
+ var _ref;
205
+ var batchLimit = (_ref = maxArrowBatches !== null && maxArrowBatches !== void 0 ? maxArrowBatches : getApplicationConfig().maxArrowBatches) !== null && _ref !== void 0 ? _ref : DEFAULT_MAX_ARROW_BATCHES;
206
+ if (!table || !Array.isArray(table.batches) || table.batches.length <= 1) {
207
+ return table;
208
+ }
209
+ if (table.batches.length <= batchLimit) {
210
+ return table;
211
+ }
212
+ try {
213
+ var _compacted$batches;
214
+ var columns = {};
215
+ var columnNames = [];
216
+ var seenNames = new Map();
217
+ for (var i = 0; i < table.numCols; i++) {
218
+ var _seenNames$get;
219
+ var field = table.schema.fields[i];
220
+ var column = table.getChildAt(i);
221
+ if (!column) {
222
+ continue;
223
+ }
224
+ // Arrow schemas may repeat field names; object keys would drop earlier columns.
225
+ var seen = (_seenNames$get = seenNames.get(field.name)) !== null && _seenNames$get !== void 0 ? _seenNames$get : 0;
226
+ seenNames.set(field.name, seen + 1);
227
+ var key = seen === 0 ? field.name : "".concat(field.name, "_").concat(seen);
228
+ columns[key] = compactArrowVector(column, column.type || field.type);
229
+ columnNames.push(key);
230
+ }
231
+
232
+ // Always build a kepler apache-arrow Table. Using `table.constructor` can
233
+ // mix DuckDB's bundled Arrow Table with rebuilt vectors and drop schema
234
+ // metadata (`geo`, ARROW:extension:name) that Kepler needs to create layers.
235
+ var compacted = tableFromCompactedColumns(table, columns, columnNames);
236
+ if (compacted !== null && compacted !== void 0 && (_compacted$batches = compacted.batches) !== null && _compacted$batches !== void 0 && _compacted$batches.length && compacted.batches.length < table.batches.length) {
237
+ return compacted;
238
+ }
239
+ } catch (_unused) {
240
+ // Keep the original table if this Arrow build cannot combine chunks.
241
+ }
242
+ return table;
243
+ }
244
+ function copyArrowSchemaMetadata(from, to) {
245
+ if (!from || !to) {
246
+ return;
247
+ }
248
+ var fromMeta = from.metadata;
249
+ var toMeta = to.metadata;
250
+ if (fromMeta && toMeta && typeof fromMeta.forEach === 'function' && typeof toMeta.set === 'function') {
251
+ fromMeta.forEach(function (value, key) {
252
+ toMeta.set(key, value);
253
+ });
254
+ }
255
+ var fromByName = new Map((from.fields || []).map(function (field) {
256
+ return [field.name, field];
257
+ }));
258
+ (to.fields || []).forEach(function (toField, index) {
259
+ var _from$fields;
260
+ var fromField = ((_from$fields = from.fields) === null || _from$fields === void 0 ? void 0 : _from$fields[index]) || fromByName.get(toField.name);
261
+ var src = fromField === null || fromField === void 0 ? void 0 : fromField.metadata;
262
+ var dst = toField === null || toField === void 0 ? void 0 : toField.metadata;
263
+ if (!src || !dst || typeof src.forEach !== 'function' || typeof dst.set !== 'function') {
264
+ return;
265
+ }
266
+ src.forEach(function (value, key) {
267
+ dst.set(key, value);
268
+ });
269
+ });
270
+ }
271
+ function tableFromCompactedColumns(source, columns, columnNames) {
272
+ var ordered = new arrow.Table(columns).select(columnNames);
273
+ var compacted;
274
+ try {
275
+ compacted = new arrow.Table(source.schema, ordered.batches.map(function (batch) {
276
+ return new arrow.RecordBatch(source.schema, batch.data);
277
+ }));
278
+ } catch (_unused2) {
279
+ compacted = ordered;
280
+ }
281
+ copyArrowSchemaMetadata(source.schema, compacted.schema);
282
+ return compacted;
283
+ }
284
+
285
+ /**
286
+ * Convert an Arrow cell from Vector.get() into a value makeBuilder.append accepts.
287
+ * Nested GeoArrow (FixedSizeList / List) cells are Vectors, not arrays.
288
+ */
289
+ function arrowCellToBuilderValue(value) {
290
+ var logicalChildren = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
291
+ if (value == null) {
292
+ return null;
293
+ }
294
+ if (ArrayBuffer.isView(value)) {
295
+ return Array.from(value);
296
+ }
297
+ if (logicalChildren && (value instanceof arrow.StructRow || value instanceof arrow.MapRow)) {
298
+ return new Map(Array.from(value, function (_ref2) {
299
+ var _ref3 = _slicedToArray(_ref2, 2),
300
+ key = _ref3[0],
301
+ child = _ref3[1];
302
+ return [key, arrowCellToBuilderValue(child, true)];
303
+ }));
304
+ }
305
+ var nested = value;
306
+
307
+ // Keep ordinary import compaction unchanged. Edited snapshots reinterpret
308
+ // timestamp storage first, so their children can safely use logical getters.
309
+ if (!logicalChildren && typeof nested.toArray === 'function' && nested.numChildren === 0) {
310
+ return Array.from(nested.toArray());
311
+ }
312
+ if (typeof nested.get === 'function' && typeof nested.length === 'number') {
313
+ var out = [];
314
+ for (var i = 0; i < nested.length; i++) {
315
+ var valid = typeof nested.isValid === 'function' ? nested.isValid(i) : true;
316
+ out.push(valid ? arrowCellToBuilderValue(nested.get(i), logicalChildren) : null);
317
+ }
318
+ return out;
319
+ }
320
+ return value;
321
+ }
322
+ function compactArrowVector(column) {
323
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : column.type;
324
+ var logicalChildren = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
325
+ var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
326
+ if (!column || !column.data || !force && column.data.length <= 1) {
327
+ return column;
328
+ }
329
+ var maybeCombine = column.combineChunks;
330
+ if (typeof maybeCombine === 'function') {
331
+ try {
332
+ var _combined$data;
333
+ var combined = maybeCombine.call(column);
334
+ if ((combined === null || combined === void 0 || (_combined$data = combined.data) === null || _combined$data === void 0 ? void 0 : _combined$data.length) <= 1) {
335
+ return combined;
336
+ }
337
+ } catch (_unused3) {
338
+ // fall through to Builder
339
+ }
340
+ }
341
+ var builder = arrow.makeBuilder(_objectSpread({
342
+ type: type,
343
+ nullValues: [null]
344
+ }, logicalChildren && arrow.DataType.isDictionary(type) ? {
345
+ // Struct/Map cells become Maps for builders; their default string key
346
+ // is always "[object Map]". Hash their typed contents instead.
347
+ dictionaryHashFunction: function dictionaryHashFunction(value) {
348
+ return JSON.stringify(value, function (_, child) {
349
+ return child instanceof Map ? Array.from(child) : typeof child === 'bigint' || typeof child === 'number' && !Number.isFinite(child) ? String(child) : child;
350
+ });
351
+ }
352
+ } : {}));
353
+ var length = column.length;
354
+ for (var i = 0; i < length; i++) {
355
+ var isValid = typeof column.isValid === 'function' ? column.isValid(i) : true;
356
+ // FixedSizeList/List .get() returns nested Vectors. Appending those
357
+ // silently writes NaN (points) or throws (lines/polygons). Plain JS
358
+ // arrays are what makeBuilder expects.
359
+ builder.append(isValid ? arrowCellToBuilderValue(column.get(i), logicalChildren) : null);
360
+ }
361
+ var finished = builder.finish();
362
+ if (finished instanceof arrow.Vector) {
363
+ return finished;
364
+ }
365
+ if (typeof finished.toVector === 'function') {
366
+ return finished.toVector();
367
+ }
368
+ return column;
369
+ }
370
+
371
+ /**
372
+ * Primitive (and dictionary-of-primitive) columns can be rebuilt from JS row
373
+ * arrays via vectorFromArray. Nested, binary, and geoarrow columns cannot.
374
+ */
375
+ function isSupportedArrowRowEditType(type) {
376
+ if (arrow.DataType.isUtf8(type) || arrow.DataType.isNull(type) || arrow.DataType.isInt(type) || arrow.DataType.isFloat(type) || arrow.DataType.isBool(type) || arrow.DataType.isDate(type) || arrow.DataType.isTimestamp(type) || arrow.DataType.isTime(type)) {
377
+ return true;
378
+ }
379
+ if (arrow.DataType.isDictionary(type)) {
380
+ var dictionary = type.dictionary;
381
+ return Boolean(dictionary && isSupportedArrowRowEditType(dictionary));
382
+ }
383
+ return false;
384
+ }
385
+
386
+ /** Reinterpret timestamp storage for builders without rounding through JS milliseconds. */
387
+ function rowEditStorageType(type) {
388
+ var _type$children;
389
+ if (arrow.DataType.isTimestamp(type)) return new arrow.Int64();
390
+ if (arrow.DataType.isDictionary(type)) return type.indices;
391
+ if ((_type$children = type.children) !== null && _type$children !== void 0 && _type$children.length) {
392
+ // Retain the Arrow type's prototype and layout (list size, union mode, etc.).
393
+ // Field.clone preserves names, nullability and extension metadata.
394
+ return Object.assign(Object.create(Object.getPrototypeOf(type)), type, {
395
+ children: type.children.map(function (field) {
396
+ return field.clone({
397
+ type: rowEditStorageType(field.type)
398
+ });
399
+ })
400
+ });
401
+ }
402
+ return type;
403
+ }
404
+ function rowEditStorageVector(column, type) {
405
+ var remapped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Map();
406
+ var dictionaries = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Map();
407
+ var _convert = function convert(original, nextType) {
408
+ var data = remapped.get(original) || original;
409
+ var copy = data.clone(nextType, data.offset, data.length, data.nullCount, data.buffers, data.children.map(function (child, i) {
410
+ return _convert(child, nextType.children[i].type);
411
+ }));
412
+ if (arrow.DataType.isDictionary(nextType)) {
413
+ var canonical = dictionaries.get(nextType.id);
414
+ if (canonical) {
415
+ // Equivalent field types from different batches need the same object,
416
+ // even when their DataType instances differ.
417
+ copy.dictionary = canonical;
418
+ } else {
419
+ if (!data.dictionary) throw new Error('Missing Arrow dictionary');
420
+ copy.dictionary = rowEditStorageVector(data.dictionary, nextType.dictionary, remapped, dictionaries);
421
+ }
422
+ }
423
+ return copy;
424
+ };
425
+ return new arrow.Vector(column.data.map(function (data) {
426
+ return _convert(data, type);
427
+ }));
428
+ }
429
+ function rowEditDictionaryCapacity(type) {
430
+ return Math.pow(2, type.indices.bitWidth - (type.indices.isSigned ? 1 : 0));
431
+ }
432
+ function collectRowEditDictionaries(data, groups) {
433
+ data.children.forEach(function (child) {
434
+ return collectRowEditDictionaries(child, groups);
435
+ });
436
+ if (!arrow.DataType.isDictionary(data.type) || !data.dictionary) return;
437
+ // Inner dictionaries must be reconciled before their enclosing dictionary.
438
+ data.dictionary.data.forEach(function (child) {
439
+ return collectRowEditDictionaries(child, groups);
440
+ });
441
+ var group = groups.get(data.type.id) || new Set();
442
+ group.add(data);
443
+ groups.set(data.type.id, group);
444
+ }
445
+ function checkRowEditDictionaryCapacity(column) {
446
+ if (!arrow.DataType.isDictionary(column.type)) return;
447
+ var capacity = rowEditDictionaryCapacity(column.type);
448
+ if (column.data.some(function (data) {
449
+ var _data$dictionary;
450
+ return (((_data$dictionary = data.dictionary) === null || _data$dictionary === void 0 ? void 0 : _data$dictionary.length) || 0) > capacity;
451
+ })) {
452
+ throw new Error('Row edit exceeds the Arrow dictionary index capacity');
453
+ }
454
+ }
455
+
456
+ /** Compact only edited snapshots; progressive loading and other rebuilds keep their behavior. */
457
+ function compactRowEditColumns(columns) {
458
+ columns = columns.map(function (column) {
459
+ return new arrow.Vector(column.data.map(function (data) {
460
+ if (!data.children.length) return data;
461
+ // List/Map slices retain their entire child buffer. Normalize each
462
+ // retained chunk before merging dictionaries so deleted/null child
463
+ // entries cannot cause a false index-capacity overflow.
464
+ var sourceGroups = new Map();
465
+ collectRowEditDictionaries(data, sourceGroups);
466
+ var sourceDictionaries = new Map();
467
+ sourceGroups.forEach(function (entries, id) {
468
+ var _entries$values$next$;
469
+ var dictionary = (_entries$values$next$ = entries.values().next().value) === null || _entries$values$next$ === void 0 ? void 0 : _entries$values$next$.dictionary;
470
+ if (dictionary) sourceDictionaries.set(id, dictionary);
471
+ });
472
+ var type = rowEditStorageType(data.type);
473
+ var compacted = compactArrowVector(rowEditStorageVector(new arrow.Vector([data]), type), type, true, true);
474
+ return rowEditStorageVector(compacted, data.type, new Map(), sourceDictionaries).data[0];
475
+ }));
476
+ });
477
+ var groups = new Map();
478
+ columns.forEach(function (column) {
479
+ return column.data.forEach(function (data) {
480
+ return collectRowEditDictionaries(data, groups);
481
+ });
482
+ });
483
+ var dictionaries = new Map();
484
+ var remapped = new Map();
485
+ var _iterator = _createForOfIteratorHelper(groups.values()),
486
+ _step;
487
+ try {
488
+ var _loop2 = function _loop2() {
489
+ var entries = _step.value;
490
+ // Narrow indexes get the first dictionary entries before wider columns add values.
491
+ var group = _toConsumableArray(entries).sort(function (a, b) {
492
+ return rowEditDictionaryCapacity(a.type) - rowEditDictionaryCapacity(b.type);
493
+ });
494
+ var type = group[group.length - 1].type;
495
+ if (group.some(function (data) {
496
+ return String(data.type.dictionary) !== String(type.dictionary);
497
+ })) {
498
+ throw new Error('Shared Arrow dictionary value types must match');
499
+ }
500
+ var original = group[0].dictionary;
501
+ if (!original) throw new Error('Missing Arrow dictionary');
502
+ if (group.every(function (data) {
503
+ return data.dictionary === original;
504
+ })) {
505
+ // Deletion usually keeps one original mapping. Preserve its exact payload,
506
+ // including nested timestamps, and only compact the retained indices.
507
+ dictionaries.set(type.id, rowEditStorageVector(original, original.type, remapped, dictionaries));
508
+ return 1; // continue
509
+ }
510
+ var storageType = new arrow.Dictionary(rowEditStorageType(type.dictionary), type.indices, type.id, type.isOrdered);
511
+ var combined = new arrow.Vector(group.flatMap(function (data) {
512
+ return rowEditStorageVector(new arrow.Vector([data]), storageType, remapped, dictionaries).data;
513
+ }));
514
+ var compacted = compactArrowVector(combined, storageType, true);
515
+ checkRowEditDictionaryCapacity(compacted);
516
+ var compactedDictionary = compacted.data[0].dictionary;
517
+ if (!compactedDictionary) throw new Error('Missing compacted Arrow dictionary');
518
+ var dictionary = rowEditStorageVector(compactedDictionary, type.dictionary, new Map(), dictionaries);
519
+ dictionaries.set(type.id, dictionary);
520
+ var offset = 0;
521
+ var _iterator2 = _createForOfIteratorHelper(group),
522
+ _step2;
523
+ try {
524
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
525
+ var originalData = _step2.value;
526
+ var columnType = originalData.type;
527
+ var chunk = compacted.slice(offset, offset + originalData.length).data[0];
528
+ var capacity = rowEditDictionaryCapacity(columnType);
529
+ for (var index = 0; index < chunk.length; index++) {
530
+ if (chunk.getValid(index) && Number(chunk.values[index]) >= capacity) {
531
+ throw new Error('Row edit exceeds the Arrow dictionary index capacity');
532
+ }
533
+ }
534
+ var buffers = chunk.buffers;
535
+ buffers[arrow.BufferType.DATA] = new columnType.indices.ArrayType(chunk.values);
536
+ var data = chunk.clone(columnType, chunk.offset, chunk.length, chunk.nullCount, buffers);
537
+ data.dictionary = dictionary;
538
+ remapped.set(originalData, data);
539
+ offset += originalData.length;
540
+ }
541
+ } catch (err) {
542
+ _iterator2.e(err);
543
+ } finally {
544
+ _iterator2.f();
545
+ }
546
+ };
547
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
548
+ if (_loop2()) continue;
549
+ }
550
+ } catch (err) {
551
+ _iterator.e(err);
552
+ } finally {
553
+ _iterator.f();
554
+ }
555
+ return columns.map(function (column) {
556
+ // Builders see raw timestamp units and canonical dictionary indices, even
557
+ // inside lists/structs. Restore the original types after one-batch compaction.
558
+ var type = rowEditStorageType(column.type);
559
+ return rowEditStorageVector(compactArrowVector(rowEditStorageVector(column, type, remapped, dictionaries), type, true), column.type, new Map(), dictionaries);
560
+ });
561
+ }
562
+
563
+ /**
564
+ * A data container where all data is stored in raw Arrow table
565
+ */
566
+ export var ArrowDataContainer = /*#__PURE__*/function () {
567
+ function ArrowDataContainer(data) {
568
+ var _this$_cols$0$length, _this$_cols$, _this$_cols$0$data$le, _this$_cols$2;
569
+ _classCallCheck(this, ArrowDataContainer);
570
+ _defineProperty(this, "_cols", void 0);
571
+ _defineProperty(this, "_numColumns", void 0);
572
+ _defineProperty(this, "_numRows", void 0);
573
+ _defineProperty(this, "_fields", void 0);
574
+ _defineProperty(this, "_numChunks", void 0);
575
+ _defineProperty(this, "_geoArrowBinaryData", void 0);
576
+ // cache column data to make valueAt() faster
577
+ // _colData: any[][];
578
+ /** An arrow table recreated from vectors */
579
+ _defineProperty(this, "_arrowTable", void 0);
580
+ if (!data.cols) {
581
+ throw Error('ArrowDataContainer: no columns provided');
582
+ }
583
+ if (!Array.isArray(data.cols)) {
584
+ throw Error("ArrowDataContainer: columns object isn't an array");
585
+ }
586
+ this._fields = data.fields || [];
587
+ this._cols = data.cols;
588
+ this._numColumns = this._cols.length;
589
+ this._numRows = (_this$_cols$0$length = (_this$_cols$ = this._cols[0]) === null || _this$_cols$ === void 0 ? void 0 : _this$_cols$.length) !== null && _this$_cols$0$length !== void 0 ? _this$_cols$0$length : 0;
590
+ this._numChunks = (_this$_cols$0$data$le = (_this$_cols$2 = this._cols[0]) === null || _this$_cols$2 === void 0 || (_this$_cols$2 = _this$_cols$2.data) === null || _this$_cols$2 === void 0 ? void 0 : _this$_cols$2.length) !== null && _this$_cols$0$data$le !== void 0 ? _this$_cols$0$data$le : 0;
591
+ this._geoArrowBinaryData = data.geoArrowBinaryData || {};
592
+ var table = compactArrowTable(data.arrowTable || this._createTable());
593
+ this._arrowTable = table;
594
+ if (table.numCols > 0) {
595
+ this._assignTable(table);
596
+ }
597
+ }
598
+
599
+ /**
600
+ * Restores internal Arrow table from vectors.
601
+ * TODO: consider using original arrow table, as it could contain extra metadata, not passed to the fields.
602
+ */
603
+ return _createClass(ArrowDataContainer, [{
604
+ key: "_createTable",
605
+ value: function _createTable() {
606
+ var _this = this;
607
+ var creaOpts = {};
608
+ this._fields.map(function (field, index) {
609
+ creaOpts[field.name] = _this._cols[index];
610
+ });
611
+ return new arrow.Table(creaOpts).select(this._fields.map(function (field) {
612
+ return field.name;
613
+ }));
614
+ }
615
+ }, {
616
+ key: "getTable",
617
+ value: function getTable() {
618
+ return this._arrowTable;
619
+ }
620
+ }, {
621
+ key: "_assignTable",
622
+ value: function _assignTable(table) {
623
+ var _this$_cols$0$length2, _this$_cols$3, _this$_cols$0$data$le2, _this$_cols$4;
624
+ this._arrowTable = table;
625
+ this._cols = Array.from({
626
+ length: table.numCols
627
+ }, function (_, i) {
628
+ return table.getChildAt(i);
629
+ }).filter(function (col) {
630
+ return col;
631
+ });
632
+ this._numColumns = this._cols.length;
633
+ this._numRows = (_this$_cols$0$length2 = (_this$_cols$3 = this._cols[0]) === null || _this$_cols$3 === void 0 ? void 0 : _this$_cols$3.length) !== null && _this$_cols$0$length2 !== void 0 ? _this$_cols$0$length2 : 0;
634
+ this._numChunks = (_this$_cols$0$data$le2 = (_this$_cols$4 = this._cols[0]) === null || _this$_cols$4 === void 0 || (_this$_cols$4 = _this$_cols$4.data) === null || _this$_cols$4 === void 0 ? void 0 : _this$_cols$4.length) !== null && _this$_cols$0$data$le2 !== void 0 ? _this$_cols$0$data$le2 : 0;
635
+ }
636
+ }, {
637
+ key: "update",
638
+ value: function update(updateData) {
639
+ var _this2 = this;
640
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
641
+ // Incremental Arrow loads append batches here. Compacting on every update
642
+ // would copy the growing table (Builder over every cell). Skip collapse;
643
+ // processArrowBatches compact once when the file is fully loaded.
644
+ var previousNumChunks = this._numChunks;
645
+ var isArrow = isArrowTable(updateData);
646
+ if (isArrow) {
647
+ this._assignTable(updateData);
648
+ } else {
649
+ this._cols = updateData;
650
+ var table = this._createTable();
651
+ if (table.numCols > 0) {
652
+ this._assignTable(table);
653
+ } else {
654
+ var _this$_cols$0$length3, _this$_cols$5, _this$_cols$0$data$le3, _this$_cols$6;
655
+ this._numColumns = this._cols.length;
656
+ this._numRows = (_this$_cols$0$length3 = (_this$_cols$5 = this._cols[0]) === null || _this$_cols$5 === void 0 ? void 0 : _this$_cols$5.length) !== null && _this$_cols$0$length3 !== void 0 ? _this$_cols$0$length3 : 0;
657
+ this._numChunks = (_this$_cols$0$data$le3 = (_this$_cols$6 = this._cols[0]) === null || _this$_cols$6 === void 0 || (_this$_cols$6 = _this$_cols$6.data) === null || _this$_cols$6 === void 0 ? void 0 : _this$_cols$6.length) !== null && _this$_cols$0$data$le3 !== void 0 ? _this$_cols$0$data$le3 : 0;
658
+ this._arrowTable = table;
659
+ }
660
+ }
661
+
662
+ // Progressive snapshots add one record batch at a time, so keep already
663
+ // parsed chunks and merge the new worker result. A compaction/replacement
664
+ // resets chunk numbering and must replace the cache instead.
665
+ if (this._numChunks > previousNumChunks) {
666
+ Object.entries(options.geoArrowBinaryData || {}).forEach(function (_ref4) {
667
+ var _ref5 = _slicedToArray(_ref4, 2),
668
+ columnIndex = _ref5[0],
669
+ chunks = _ref5[1];
670
+ _this2._geoArrowBinaryData[Number(columnIndex)] = _objectSpread(_objectSpread({}, _this2._geoArrowBinaryData[Number(columnIndex)]), chunks);
671
+ });
672
+ } else {
673
+ this._geoArrowBinaryData = options.geoArrowBinaryData || {};
674
+ }
675
+
676
+ // cache column data to make valueAt() faster
677
+ // this._colData = this._cols.map(c => c.toArray());
678
+ }
679
+
680
+ /** Append typed rows atomically while retaining the container and prior snapshots. */
681
+ }, {
682
+ key: "append",
683
+ value: function append(rows) {
684
+ if (!Array.isArray(rows)) return false;
685
+ return this.replaceRows(new Map(), rows);
686
+ }
687
+ }, {
688
+ key: "replace",
689
+ value: function replace(index, row) {
690
+ return this.replaceRows(new Map([[index, row]]), []);
691
+ }
692
+
693
+ /** @internal Match upsert keys in the same representation returned by valueAt. */
694
+ }, {
695
+ key: "getRowEditKeys",
696
+ value: function getRowEditKeys(rows, keyIndex) {
697
+ var _this$_arrowTable$sch;
698
+ var type = (_this$_arrowTable$sch = this._arrowTable.schema.fields[keyIndex]) === null || _this$_arrowTable$sch === void 0 ? void 0 : _this$_arrowTable$sch.type;
699
+ if (!type) return null;
700
+ var valueType = type;
701
+ while (arrow.DataType.isDictionary(valueType)) valueType = valueType.dictionary;
702
+ try {
703
+ if (arrow.DataType.isInt(valueType)) {
704
+ var bits = valueType.bitWidth;
705
+ var limit = 1n << BigInt(bits - (valueType.isSigned ? 1 : 0));
706
+ var min = valueType.isSigned ? -limit : 0n;
707
+ var max = limit - 1n;
708
+ var _iterator3 = _createForOfIteratorHelper(rows),
709
+ _step3;
710
+ try {
711
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
712
+ var row = _step3.value;
713
+ var value = row[keyIndex];
714
+ if (value === null) continue;
715
+ // Arrow's typed array assignment wraps out-of-range integers. A key
716
+ // must not silently turn into a different existing row's identity.
717
+ if (typeof value === 'string' && !value.trim()) return null;
718
+ var integer = BigInt(bits === 64 ? value : Number(value));
719
+ if (integer < min || integer > max) return null;
720
+ }
721
+ } catch (err) {
722
+ _iterator3.e(err);
723
+ } finally {
724
+ _iterator3.f();
725
+ }
726
+ }
727
+ var keys = arrow.vectorFromArray(rows.map(function (row) {
728
+ return row[keyIndex];
729
+ }), type);
730
+ checkRowEditDictionaryCapacity(keys);
731
+ return Array.from(keys);
732
+ } catch (_unused4) {
733
+ return null;
734
+ }
735
+ }
736
+
737
+ /** @internal Encode a complete edit batch before replacing any live columns. */
738
+ }, {
739
+ key: "replaceRows",
740
+ value: function replaceRows(replacements, appended) {
741
+ var _iterator4 = _createForOfIteratorHelper(replacements.keys()),
742
+ _step4;
743
+ try {
744
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
745
+ var index = _step4.value;
746
+ if (!Number.isInteger(index) || index < 0 || index >= this._numRows) return false;
747
+ }
748
+ } catch (err) {
749
+ _iterator4.e(err);
750
+ } finally {
751
+ _iterator4.f();
752
+ }
753
+ var incoming = this._columnsFromRows([].concat(_toConsumableArray(replacements.values()), _toConsumableArray(appended)));
754
+ if (!incoming) return false;
755
+ var ordered = _toConsumableArray(replacements.keys()).map(function (index, incomingIndex) {
756
+ return {
757
+ index: index,
758
+ incomingIndex: incomingIndex
759
+ };
760
+ }).sort(function (a, b) {
761
+ return a.index - b.index;
762
+ });
763
+ try {
764
+ var columns = this._cols.map(function (column, i) {
765
+ var chunks = [];
766
+ var start = 0;
767
+ var _iterator5 = _createForOfIteratorHelper(ordered),
768
+ _step5;
769
+ try {
770
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
771
+ var _step5$value = _step5.value,
772
+ index = _step5$value.index,
773
+ incomingIndex = _step5$value.incomingIndex;
774
+ chunks.push.apply(chunks, _toConsumableArray(column.slice(start, index).data).concat(_toConsumableArray(incoming[i].slice(incomingIndex, incomingIndex + 1).data)));
775
+ start = index + 1;
776
+ }
777
+ } catch (err) {
778
+ _iterator5.e(err);
779
+ } finally {
780
+ _iterator5.f();
781
+ }
782
+ chunks.push.apply(chunks, _toConsumableArray(column.slice(start).data).concat(_toConsumableArray(incoming[i].slice(replacements.size).data)));
783
+ return new arrow.Vector(chunks);
784
+ });
785
+ this._commitColumns(columns);
786
+ return true;
787
+ } catch (_unused5) {
788
+ return false;
789
+ }
790
+ }
791
+
792
+ /** Delete unique valid indexes without decoding retained values. */
793
+ }, {
794
+ key: "remove",
795
+ value: function remove(indexes) {
796
+ var _this3 = this;
797
+ if (!Array.isArray(indexes) || !indexes.length) return false;
798
+ if (indexes.some(function (index) {
799
+ return !Number.isInteger(index) || index < 0 || index >= _this3._numRows;
800
+ })) return false;
801
+ var sorted = _toConsumableArray(new Set(indexes)).sort(function (a, b) {
802
+ return a - b;
803
+ });
804
+ try {
805
+ var columns = this._cols.map(function (column) {
806
+ var chunks = [];
807
+ var start = 0;
808
+ var _iterator6 = _createForOfIteratorHelper(sorted),
809
+ _step6;
810
+ try {
811
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
812
+ var index = _step6.value;
813
+ if (start < index) chunks.push.apply(chunks, _toConsumableArray(column.slice(start, index).data));
814
+ start = index + 1;
815
+ }
816
+ } catch (err) {
817
+ _iterator6.e(err);
818
+ } finally {
819
+ _iterator6.f();
820
+ }
821
+ if (start < _this3._numRows) chunks.push.apply(chunks, _toConsumableArray(column.slice(start).data));
822
+ return chunks.length ? new arrow.Vector(chunks) : column.slice(0, 0);
823
+ });
824
+ this._commitColumns(columns);
825
+ return true;
826
+ } catch (_unused6) {
827
+ return false;
828
+ }
829
+ }
830
+ }, {
831
+ key: "_commitColumns",
832
+ value: function _commitColumns(columns) {
833
+ var schema = this._arrowTable.schema;
834
+ var compacted = compactRowEditColumns(columns);
835
+ // Ordinal keys let Arrow align chunks without interpreting real column names.
836
+ var ordered = new arrow.Table(Object.fromEntries(compacted.map(function (column, i) {
837
+ return [i, column];
838
+ })));
839
+ var batches = ordered.batches.map(function (batch) {
840
+ var result = new arrow.RecordBatch(schema, batch.data);
841
+ // Arrow reconciles fields by name, even for positional input. Retain the
842
+ // source fields when an external schema contains duplicate names.
843
+ schema.fields.forEach(function (field, i) {
844
+ result.schema.fields[i] = field;
845
+ });
846
+ // Validate shared dictionary identities before publishing the snapshot.
847
+ result.dictionaries;
848
+ return result;
849
+ });
850
+ this._assignTable(new arrow.Table(schema, batches));
851
+ this._geoArrowBinaryData = {};
852
+ }
853
+ }, {
854
+ key: "_columnsFromRows",
855
+ value: function _columnsFromRows(rows) {
856
+ var fields = this._arrowTable.schema.fields;
857
+ if (!rows.length || !fields.length || rows.some(function (row) {
858
+ return !Array.isArray(row) || row.length !== fields.length;
859
+ })) return null;
860
+ var _iterator7 = _createForOfIteratorHelper(fields),
861
+ _step7;
862
+ try {
863
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
864
+ var _field$metadata$get;
865
+ var field = _step7.value;
866
+ if ((_field$metadata$get = field.metadata.get(GEOARROW_METADATA_KEY)) !== null && _field$metadata$get !== void 0 && _field$metadata$get.startsWith('geoarrow') || !isSupportedArrowRowEditType(field.type)) {
867
+ globalConsole.warn("ArrowDataContainer: row edits do not support column \"".concat(field.name, "\" (").concat(field.type, ")"));
868
+ return null;
869
+ }
870
+ }
871
+ } catch (err) {
872
+ _iterator7.e(err);
873
+ } finally {
874
+ _iterator7.f();
875
+ }
876
+ try {
877
+ return fields.map(function (field, i) {
878
+ var column = arrow.vectorFromArray(rows.map(function (row) {
879
+ return row[i];
880
+ }), field.type);
881
+ checkRowEditDictionaryCapacity(column);
882
+ return column;
883
+ });
884
+ } catch (_unused7) {
885
+ globalConsole.warn('ArrowDataContainer: could not encode row edits using the existing column types');
886
+ return null;
887
+ }
888
+ }
889
+ }, {
890
+ key: "numChunks",
891
+ value: function numChunks() {
892
+ return this._numChunks;
893
+ }
894
+ }, {
895
+ key: "getGeoArrowBinaryData",
896
+ value: function getGeoArrowBinaryData(columnIndex, chunkIndex) {
897
+ var columnData = this._geoArrowBinaryData[columnIndex];
898
+ if (!columnData) {
899
+ return undefined;
900
+ }
901
+ if (chunkIndex !== undefined) {
902
+ return columnData[chunkIndex];
903
+ }
904
+ var chunks = Object.entries(columnData).map(function (_ref6) {
905
+ var _ref7 = _slicedToArray(_ref6, 2),
906
+ index = _ref7[0],
907
+ data = _ref7[1];
908
+ return {
909
+ index: Number(index),
910
+ data: data
911
+ };
912
+ }).sort(function (a, b) {
913
+ return a.index - b.index;
914
+ });
915
+ if (chunks.length !== this._numChunks) {
916
+ return undefined;
917
+ }
918
+ var featureTypes = {
919
+ point: false,
920
+ line: false,
921
+ polygon: false
922
+ };
923
+ var bounds = [Infinity, Infinity, -Infinity, -Infinity];
924
+ var binaryGeometries = [];
925
+ var meanCenters = [];
926
+ var hasMeanCenters = true;
927
+ chunks.forEach(function (_ref8) {
928
+ var data = _ref8.data;
929
+ data.binaryGeometries.forEach(function (geometry) {
930
+ return binaryGeometries.push(geometry);
931
+ });
932
+ featureTypes.point || (featureTypes.point = data.featureTypes.point);
933
+ featureTypes.line || (featureTypes.line = data.featureTypes.line);
934
+ featureTypes.polygon || (featureTypes.polygon = data.featureTypes.polygon);
935
+ bounds[0] = Math.min(bounds[0], data.bounds[0]);
936
+ bounds[1] = Math.min(bounds[1], data.bounds[1]);
937
+ bounds[2] = Math.max(bounds[2], data.bounds[2]);
938
+ bounds[3] = Math.max(bounds[3], data.bounds[3]);
939
+ if (data.meanCenters) {
940
+ data.meanCenters.forEach(function (center) {
941
+ return meanCenters.push(center);
942
+ });
943
+ } else {
944
+ hasMeanCenters = false;
945
+ }
946
+ });
947
+ return _objectSpread({
948
+ binaryGeometries: binaryGeometries,
949
+ featureTypes: featureTypes,
950
+ bounds: bounds
951
+ }, hasMeanCenters ? {
952
+ meanCenters: meanCenters
953
+ } : {});
954
+ }
955
+ }, {
956
+ key: "numRows",
957
+ value: function numRows() {
958
+ return this._numRows;
959
+ }
960
+ }, {
961
+ key: "numColumns",
962
+ value: function numColumns() {
963
+ return this._numColumns;
964
+ }
965
+ }, {
966
+ key: "valueAt",
967
+ value: function valueAt(rowIndex, columnIndex) {
968
+ // return this._colData[columnIndex][rowIndex];
969
+ return this._cols[columnIndex].get(rowIndex);
970
+ }
971
+ }, {
972
+ key: "row",
973
+ value: function row(rowIndex, sharedRow) {
974
+ var tSharedRow = DataRow.createSharedRow(sharedRow);
975
+ if (tSharedRow) {
976
+ tSharedRow.setSource(this, rowIndex);
977
+ return tSharedRow;
978
+ }
979
+ return new DataRow(this, rowIndex);
980
+ }
981
+ }, {
982
+ key: "rowAsArray",
983
+ value: function rowAsArray(rowIndex) {
984
+ // return this._colData.map(col => col[rowIndex]);
985
+ return this._cols.map(function (col) {
986
+ return col.get(rowIndex);
987
+ });
988
+ }
989
+ }, {
990
+ key: "rows",
991
+ value: function rows(sharedRow) {
992
+ var tSharedRow = DataRow.createSharedRow(sharedRow);
993
+ return rowsIterator(this, tSharedRow);
994
+ }
995
+ }, {
996
+ key: "column",
997
+ value: function column(columnIndex) {
998
+ return columnIterator(this, columnIndex);
999
+ }
1000
+ }, {
1001
+ key: "getColumn",
1002
+ value: function getColumn(columnIndex) {
1003
+ return this._cols[columnIndex];
1004
+ }
1005
+ }, {
1006
+ key: "getField",
1007
+ value: function getField(columnIndex) {
1008
+ return this._fields[columnIndex];
1009
+ }
1010
+ }, {
1011
+ key: "flattenData",
1012
+ value: function flattenData() {
1013
+ var data = [];
1014
+ for (var i = 0; i < this._numRows; ++i) {
1015
+ data.push(this.rowAsArray(i));
1016
+ }
1017
+ return data;
1018
+ }
1019
+ }, {
1020
+ key: "getPlainIndex",
1021
+ value: function getPlainIndex() {
1022
+ return _toConsumableArray(Array(this._numRows).keys());
1023
+ }
1024
+ }, {
1025
+ key: "map",
1026
+ value: function map(func, sharedRow) {
1027
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1028
+ var tSharedRow = DataRow.createSharedRow(sharedRow);
1029
+ var _options$start = options.start,
1030
+ start = _options$start === void 0 ? 0 : _options$start,
1031
+ _options$end = options.end,
1032
+ end = _options$end === void 0 ? this.numRows() : _options$end;
1033
+ var endRow = Math.min(this.numRows(), end);
1034
+ var out = [];
1035
+ for (var rowIndex = start; rowIndex < endRow; ++rowIndex) {
1036
+ var row = this.row(rowIndex, tSharedRow);
1037
+ out.push(func(row, rowIndex));
1038
+ }
1039
+ return out;
1040
+ }
1041
+ }, {
1042
+ key: "mapIndex",
1043
+ value: function mapIndex(func) {
1044
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1045
+ var _options$start2 = options.start,
1046
+ start = _options$start2 === void 0 ? 0 : _options$start2,
1047
+ _options$end2 = options.end,
1048
+ end = _options$end2 === void 0 ? this.numRows() : _options$end2;
1049
+ var endRow = Math.min(this.numRows(), end);
1050
+ var out = [];
1051
+ for (var rowIndex = start; rowIndex < endRow; ++rowIndex) {
1052
+ out.push(func({
1053
+ index: rowIndex
1054
+ }, this));
1055
+ }
1056
+ return out;
1057
+ }
1058
+ }, {
1059
+ key: "find",
1060
+ value: function find(func, sharedRow) {
1061
+ var tSharedRow = DataRow.createSharedRow(sharedRow);
1062
+ for (var rowIndex = 0; rowIndex < this._numRows; ++rowIndex) {
1063
+ var row = this.row(rowIndex, tSharedRow);
1064
+ if (func(row, rowIndex)) {
1065
+ return row;
1066
+ }
1067
+ }
1068
+ return undefined;
1069
+ }
1070
+ }, {
1071
+ key: "reduce",
1072
+ value: function reduce(func, initialValue, sharedRow) {
1073
+ var tSharedRow = DataRow.createSharedRow(sharedRow);
1074
+ for (var rowIndex = 0; rowIndex < this._numRows; ++rowIndex) {
1075
+ var row = this.row(rowIndex, tSharedRow);
1076
+ initialValue = func(initialValue, row, rowIndex);
1077
+ }
1078
+ return initialValue;
1079
+ }
1080
+ }]);
1081
+ }();
1082
+
1083
+ /**
1084
+ * Convert arrow data type to kepler.gl field types
1085
+ *
1086
+ * @param arrowType the arrow data type
1087
+ * @returns corresponding type in `ALL_FIELD_TYPES`
1088
+ */
1089
+ export function arrowDataTypeToFieldType(arrowType) {
1090
+ // Note: this function doesn't return ALL_FIELD_TYPES.geojson or ALL_FIELD_TYPES.array, which
1091
+ // should be further detected by caller
1092
+ if (arrow.DataType.isDate(arrowType)) {
1093
+ return ALL_FIELD_TYPES.date;
1094
+ } else if (arrow.DataType.isTimestamp(arrowType) || arrow.DataType.isTime(arrowType)) {
1095
+ return ALL_FIELD_TYPES.timestamp;
1096
+ } else if (arrow.DataType.isFloat(arrowType)) {
1097
+ return ALL_FIELD_TYPES.real;
1098
+ } else if (arrow.DataType.isInt(arrowType)) {
1099
+ return ALL_FIELD_TYPES.integer;
1100
+ } else if (arrow.DataType.isBool(arrowType)) {
1101
+ return ALL_FIELD_TYPES["boolean"];
1102
+ } else if (arrow.DataType.isUtf8(arrowType) || arrow.DataType.isNull(arrowType)) {
1103
+ return ALL_FIELD_TYPES.string;
1104
+ } else if (arrow.DataType.isBinary(arrowType) || arrow.DataType.isDictionary(arrowType) || arrow.DataType.isFixedSizeBinary(arrowType) || arrow.DataType.isFixedSizeList(arrowType) || arrow.DataType.isList(arrowType) || arrow.DataType.isMap(arrowType) || arrow.DataType.isStruct(arrowType)) {
1105
+ return ALL_FIELD_TYPES.object;
1106
+ }
1107
+ globalConsole.warn("Unsupported arrow type: ".concat(arrowType));
1108
+ return ALL_FIELD_TYPES.string;
1109
+ }
1110
+
1111
+ /**
1112
+ * Convert arrow data type to analyzer type
1113
+ *
1114
+ * @param arrowType the arrow data type
1115
+ * @returns corresponding type in `AnalyzerDATA_TYPES`
1116
+ */
1117
+ export function arrowDataTypeToAnalyzerDataType(arrowType) {
1118
+ if (arrow.DataType.isDate(arrowType)) {
1119
+ return AnalyzerDATA_TYPES.DATE;
1120
+ } else if (arrow.DataType.isTimestamp(arrowType) || arrow.DataType.isTime(arrowType)) {
1121
+ return AnalyzerDATA_TYPES.DATETIME;
1122
+ } else if (arrow.DataType.isFloat(arrowType)) {
1123
+ return AnalyzerDATA_TYPES.FLOAT;
1124
+ } else if (arrow.DataType.isInt(arrowType)) {
1125
+ return AnalyzerDATA_TYPES.INT;
1126
+ } else if (arrow.DataType.isBool(arrowType)) {
1127
+ return AnalyzerDATA_TYPES.BOOLEAN;
1128
+ } else if (arrow.DataType.isUtf8(arrowType) || arrow.DataType.isNull(arrowType)) {
1129
+ return AnalyzerDATA_TYPES.STRING;
1130
+ } else if (arrow.DataType.isBinary(arrowType) || arrow.DataType.isDictionary(arrowType) || arrow.DataType.isFixedSizeBinary(arrowType) || arrow.DataType.isFixedSizeList(arrowType) || arrow.DataType.isList(arrowType) || arrow.DataType.isMap(arrowType) || arrow.DataType.isStruct(arrowType)) {
1131
+ return AnalyzerDATA_TYPES.OBJECT;
1132
+ }
1133
+ globalConsole.warn("Unsupported arrow type: ".concat(arrowType));
1134
+ return AnalyzerDATA_TYPES.STRING;
1135
+ }
1136
+ //# sourceMappingURL=arrow-data-container.js.map