@loaders.gl/core 5.0.0-beta.11 → 5.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SCHEMA-UTILS-README.md +1 -1
- package/dist/arrow-geometry/binary-features.cjs +4 -1
- package/dist/arrow-geometry/binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/binary-features.d.ts.map +1 -1
- package/dist/arrow-geometry/binary-features.js +1 -1
- package/dist/arrow-geometry/binary-features.js.map +1 -1
- package/dist/arrow-geometry/binary-geometry-to-wkb.cjs +2 -2
- package/dist/arrow-geometry/binary-geometry-to-wkb.cjs.map +2 -2
- package/dist/arrow-geometry/binary-geometry-to-wkb.js +1 -1
- package/dist/arrow-geometry/binary-geometry-to-wkb.js.map +1 -1
- package/dist/arrow-geometry/geojson-table.cjs +3 -3
- package/dist/arrow-geometry/geojson-table.cjs.map +3 -3
- package/dist/arrow-geometry/geojson-table.d.ts +1 -1
- package/dist/arrow-geometry/geojson-table.d.ts.map +1 -1
- package/dist/arrow-geometry/geojson-table.js +2 -2
- package/dist/arrow-geometry/geojson-table.js.map +1 -1
- package/dist/arrow-geometry/geometry-codecs.cjs +6 -6
- package/dist/arrow-geometry/geometry-codecs.cjs.map +2 -2
- package/dist/arrow-geometry/geometry-codecs.js +1 -1
- package/dist/arrow-geometry/geometry-codecs.js.map +1 -1
- package/dist/arrow-geometry/geometry-to-wkt.cjs +2 -2
- package/dist/arrow-geometry/geometry-to-wkt.cjs.map +2 -2
- package/dist/arrow-geometry/geometry-to-wkt.js +1 -1
- package/dist/arrow-geometry/geometry-to-wkt.js.map +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs +3 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js +3 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js.map +1 -1
- package/dist/arrow-geometry/wkb-builder.cjs +3 -3
- package/dist/arrow-geometry/wkb-builder.cjs.map +2 -2
- package/dist/arrow-geometry/wkb-builder.d.ts +1 -1
- package/dist/arrow-geometry/wkb-builder.d.ts.map +1 -1
- package/dist/arrow-geometry/wkb-builder.js +1 -1
- package/dist/arrow-geometry/wkb-builder.js.map +1 -1
- package/dist/arrow-geometry/wkb-statistics.cjs +2 -2
- package/dist/arrow-geometry/wkb-statistics.cjs.map +2 -2
- package/dist/arrow-geometry/wkb-statistics.js +1 -1
- package/dist/arrow-geometry/wkb-statistics.js.map +1 -1
- package/dist/arrow-worker-transport.cjs +1 -1
- package/dist/arrow-worker-transport.d.ts +1 -1
- package/dist/arrow-worker-transport.d.ts.map +1 -1
- package/dist/arrow-worker-transport.js +1 -1
- package/dist/arrow-worker-transport.js.map +1 -1
- package/dist/cluster-source.cjs +36 -34
- package/dist/cluster-source.cjs.map +2 -2
- package/dist/dist.min.js +2 -2
- package/dist/federated-table-scan-source.cjs +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.cjs +2 -2
- package/dist/geoarrow/binary-polygon-to-geoarrow.cjs.map +2 -2
- package/dist/geoarrow/binary-polygon-to-geoarrow.d.ts +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.d.ts.map +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.js +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.js.map +1 -1
- package/dist/geoarrow/geoarrow-bounds.cjs +7 -7
- package/dist/geoarrow/geoarrow-bounds.cjs.map +3 -3
- package/dist/geoarrow/geoarrow-bounds.js +3 -3
- package/dist/geoarrow/geoarrow-bounds.js.map +1 -1
- package/dist/geoarrow/geoarrow-capabilities.cjs +2 -2
- package/dist/geoarrow/geoarrow-capabilities.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-capabilities.js +1 -1
- package/dist/geoarrow/geoarrow-capabilities.js.map +1 -1
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs +8 -8
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs.map +3 -3
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.d.ts.map +1 -1
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js +2 -2
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js.map +1 -1
- package/dist/geoarrow/geoarrow-inspection.cjs +2 -2
- package/dist/geoarrow/geoarrow-inspection.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-inspection.js +1 -1
- package/dist/geoarrow/geoarrow-inspection.js.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs.map +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.js +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.js.map +1 -1
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +5 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.cjs +4 -4
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs +3 -3
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -1
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.cjs +3 -3
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.cjs.map +2 -2
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.js +1 -1
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.js.map +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.cjs.map +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js +1 -1
- package/dist/geoarrow/mesharrow/arrow-fixed-size-list-utils.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +23 -11
- package/dist/loader-utils/index.cjs.map +1 -1
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.d.ts +6 -1
- package/dist/loader-utils/lib/sources/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.js +32 -14
- package/dist/loader-utils/lib/sources/tile-grid.js.map +1 -1
- package/dist/loader-utils/tile-grid.cjs +21 -9
- package/dist/loader-utils/tile-grid.cjs.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.cjs +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.js +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -1
- package/dist/scan/arrow-query-worker-entry.cjs +1 -1
- package/dist/scan/arrow-query-worker-entry.cjs.map +1 -1
- package/dist/scan/arrow-query-worker.cjs +1 -1
- package/dist/scan/arrow-query-worker.cjs.map +1 -1
- package/dist/scan/query-scales.cjs +75 -20
- package/dist/scan/query-scales.cjs.map +3 -3
- package/dist/scan/query-scales.d.ts +12 -0
- package/dist/scan/query-scales.d.ts.map +1 -1
- package/dist/scan/query-scales.js +100 -19
- package/dist/scan/query-scales.js.map +1 -1
- package/dist/schema/geometry/geoarrow.d.ts +2 -2
- package/dist/schema/geometry/geoarrow.d.ts.map +1 -1
- package/dist/schema-utils/index.cjs +1 -1
- package/dist/schema-utils/index.cjs.map +1 -1
- package/dist/schema-utils/index.d.ts.map +1 -1
- package/dist/schema-utils/index.js.map +1 -1
- package/dist/schema-utils/lib/table/tables/convert-arrow-table.js +2 -1
- package/dist/schema-utils/lib/table/tables/convert-arrow-table.js.map +1 -1
- package/dist/vector-table-scan-source.cjs +1 -1
- package/dist/wkt/index.cjs.map +1 -1
- package/dist/wkt/index.d.ts.map +1 -1
- package/dist/wkt/index.js.map +1 -1
- package/dist/worker-utils/index.cjs +2 -2
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/npm-tag.d.ts.map +1 -1
- package/dist/worker-utils/lib/npm-tag.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js.map +1 -1
- package/dist/worker-utils/null-worker.js.map +1 -1
- package/package.json +7 -8
- package/src/arrow-geometry/binary-features.ts +4 -1
- package/src/arrow-geometry/binary-geometry-to-wkb.ts +1 -1
- package/src/arrow-geometry/geojson-table.ts +2 -2
- package/src/arrow-geometry/geometry-codecs.ts +2 -2
- package/src/arrow-geometry/geometry-to-wkt.ts +2 -2
- package/src/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.ts +3 -1
- package/src/arrow-geometry/wkb-builder.ts +2 -2
- package/src/arrow-geometry/wkb-statistics.ts +2 -2
- package/src/arrow-worker-transport.ts +1 -1
- package/src/geoarrow/binary-polygon-to-geoarrow.ts +2 -2
- package/src/geoarrow/geoarrow-bounds.ts +3 -3
- package/src/geoarrow/geoarrow-capabilities.ts +1 -1
- package/src/geoarrow/geoarrow-converter/convert-geoarrow-geometry.ts +3 -7
- package/src/geoarrow/geoarrow-inspection.ts +2 -2
- package/src/geoarrow/get-geoarrow-vertex-count.ts +1 -1
- package/src/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +5 -2
- package/src/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.ts +1 -1
- package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +2 -2
- package/src/geoarrow/lib/kernels/encode-geoarrow-box.ts +1 -1
- package/src/geoarrow/mesharrow/arrow-fixed-size-list-utils.ts +1 -1
- package/src/loader-utils/lib/sources/tile-grid.ts +34 -18
- package/src/scan/arrow-execution/filter-arrow-table.ts +1 -1
- package/src/scan/query-scales.ts +129 -29
- package/src/schema/geometry/geoarrow.ts +2 -2
- package/src/schema-utils/index.ts +1 -1
- package/src/schema-utils/lib/table/tables/convert-arrow-table.ts +2 -1
- package/src/wkt/index.ts +1 -1
- package/src/worker-utils/lib/npm-tag.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type * as arrow from 'apache-arrow';
|
|
6
|
-
import {isArrowTable} from '@math.gl/arrow';
|
|
6
|
+
import {isArrowTable} from '@math.gl/core/arrow';
|
|
7
7
|
import type {
|
|
8
8
|
BinaryFeatureCollection,
|
|
9
9
|
BinaryPointFeature,
|
|
@@ -1468,7 +1468,10 @@ function triangulatePolygons(polygons: BinaryPolygonFeature): Uint32Array | null
|
|
|
1468
1468
|
const polygonTriangles = earcut(
|
|
1469
1469
|
polygonPositions,
|
|
1470
1470
|
holeIndices.length > 0 ? holeIndices : undefined,
|
|
1471
|
-
polygons.positions.size
|
|
1471
|
+
polygons.positions.size,
|
|
1472
|
+
undefined,
|
|
1473
|
+
'xy',
|
|
1474
|
+
{triangulation: 'balanced'}
|
|
1472
1475
|
);
|
|
1473
1476
|
if (polygonTriangles.length === 0) {
|
|
1474
1477
|
throw new Error('earcut failed e.g. invalid polygon');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {BinaryGeometry} from '@loaders.gl/core/schema';
|
|
6
|
-
import {getWellKnownDimensionSize, scanWKB, visitWKB} from '@math.gl/arrow
|
|
6
|
+
import {getWellKnownDimensionSize, scanWKB, visitWKB} from '@math.gl/core/arrow';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Materializes legacy vertex-indexed binary geometry using math.gl's WKB traversal.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {inspectWKBHeader} from '@math.gl/arrow
|
|
6
|
-
import type {WellKnownDimension, WKBGeometryType as MathWKBGeometryType} from '@math.gl/arrow
|
|
5
|
+
import {inspectWKBHeader} from '@math.gl/core/arrow';
|
|
6
|
+
import type {WellKnownDimension, WKBGeometryType as MathWKBGeometryType} from '@math.gl/core/arrow';
|
|
7
7
|
import type {WKBGeometryType, WKBHeader} from './wkb-types';
|
|
8
8
|
import {MAX_SRID, WKT_MAGIC_STRINGS, WKT_MAGIC_BYTES} from './wkb-types';
|
|
9
9
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import * as arrow from 'apache-arrow';
|
|
6
6
|
import {convertWKTToGeometry} from '@loaders.gl/core/arrow-geometry/geometry-codecs';
|
|
7
|
-
import {scanWKB} from '@math.gl/arrow
|
|
7
|
+
import {scanWKB} from '@math.gl/core/arrow';
|
|
8
8
|
import type {GeoArrowDimension, GeoArrowEncoding} from '@loaders.gl/core/schema';
|
|
9
9
|
|
|
10
10
|
type BoxDimension = 2 | 3 | 4;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {TypedArray} from '@math.gl/core';
|
|
6
|
-
import {isFixedSizeListArrowType} from '@math.gl/arrow';
|
|
6
|
+
import {isFixedSizeListArrowType} from '@math.gl/core/arrow';
|
|
7
7
|
import * as arrow from 'apache-arrow';
|
|
8
8
|
import {getDataTypeFromArray, deserializeArrowType} from '@loaders.gl/core/schema-utils';
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {GetTileParameters, TileGrid, TileGridMatrix, TileGridLimits} from './tile-source';
|
|
6
|
-
import {
|
|
6
|
+
import {resolveTileIndex, validateTileMatrix, validateTileMatrixSet} from '@math.gl/geospatial';
|
|
7
7
|
import type {TileMatrix, TileMatrixSet, VariableMatrixWidth} from '@math.gl/geospatial';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -300,6 +300,17 @@ export function getTileGridValidation(grid: TileGridValidationInput): TileGridVa
|
|
|
300
300
|
message: error instanceof Error ? error.message : 'Invalid tile grid limits.'
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
+
// math.gl owns the complete-set contract; it must agree before geometry is called complete.
|
|
304
|
+
if (matrixSet && !issues.length) {
|
|
305
|
+
try {
|
|
306
|
+
validateTileMatrixSet(matrixSet, grid.limits);
|
|
307
|
+
} catch (error) {
|
|
308
|
+
issues.push({
|
|
309
|
+
code: 'invalid-matrix',
|
|
310
|
+
message: error instanceof Error ? error.message : 'Invalid tile matrix set.'
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
303
314
|
const invalid = issues.some(
|
|
304
315
|
issue => issue.code !== 'missing-crs' && issue.code !== 'missing-geometry'
|
|
305
316
|
);
|
|
@@ -320,28 +331,39 @@ export function validateTileGrid(grid: TileGridValidationInput): void {
|
|
|
320
331
|
throw new RangeError('Complete tile matrix geometry requires a CRS.');
|
|
321
332
|
}
|
|
322
333
|
|
|
323
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* Validates inclusive base-grid coverage even when resolution or CRS is unknown. Each malformed
|
|
336
|
+
* rectangle throws a `RangeError` that names the reason: a missing or repeated matrix ID, an
|
|
337
|
+
* unknown matrix, an index that is not a nonnegative safe integer, reversed bounds, or bounds
|
|
338
|
+
* beyond the advertised matrix dimensions.
|
|
339
|
+
*/
|
|
324
340
|
export function validateTileGridLimits(grid: TileGridValidationInput): void {
|
|
325
341
|
if (grid.limits === undefined) return;
|
|
326
342
|
if (!Array.isArray(grid.limits)) throw new RangeError('Tile matrix limits require an array.');
|
|
327
343
|
const identifiers = new Set<string>();
|
|
328
344
|
const matrices = grid.tileMatrixSet?.matrices ?? grid.matrices;
|
|
345
|
+
const matrixById = Array.isArray(matrices)
|
|
346
|
+
? new Map(matrices.map(matrix => [matrix?.id, matrix]))
|
|
347
|
+
: undefined;
|
|
329
348
|
for (const limit of grid.limits) {
|
|
330
349
|
if (
|
|
331
350
|
!limit ||
|
|
332
351
|
typeof limit.tileMatrix !== 'string' ||
|
|
333
352
|
!limit.tileMatrix ||
|
|
334
|
-
identifiers.has(limit.tileMatrix)
|
|
353
|
+
identifiers.has(limit.tileMatrix)
|
|
354
|
+
)
|
|
355
|
+
throw new RangeError('Tile matrix limits require unique nonempty matrix identifiers.');
|
|
356
|
+
identifiers.add(limit.tileMatrix);
|
|
357
|
+
if (
|
|
335
358
|
![limit.minTileColumn, limit.maxTileColumn, limit.minTileRow, limit.maxTileRow].every(
|
|
336
359
|
value => Number.isSafeInteger(value) && value >= 0
|
|
337
|
-
)
|
|
338
|
-
limit.minTileColumn > limit.maxTileColumn ||
|
|
339
|
-
limit.minTileRow > limit.maxTileRow
|
|
360
|
+
)
|
|
340
361
|
)
|
|
341
|
-
throw new RangeError('
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
362
|
+
throw new RangeError('Tile matrix limits require nonnegative safe integers.');
|
|
363
|
+
if (limit.minTileColumn > limit.maxTileColumn || limit.minTileRow > limit.maxTileRow)
|
|
364
|
+
throw new RangeError('Tile matrix limits have reversed bounds.');
|
|
365
|
+
const matrix = matrixById?.get(limit.tileMatrix);
|
|
366
|
+
if (matrixById && !matrix)
|
|
345
367
|
throw new RangeError('Tile matrix limits reference an unknown matrix.');
|
|
346
368
|
if (
|
|
347
369
|
matrix?.matrixSize &&
|
|
@@ -391,14 +413,8 @@ export function resolveTileGridTile<
|
|
|
391
413
|
)
|
|
392
414
|
return null;
|
|
393
415
|
if (matrix && grid.tileMatrixSet) {
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
geometry,
|
|
397
|
-
getTileBounds(geometry, parameters.x, parameters.y),
|
|
398
|
-
limits
|
|
399
|
-
);
|
|
400
|
-
if (!ranges.length) return null;
|
|
401
|
-
return {...parameters, x: ranges[0].minTileColumn, tileMatrix};
|
|
416
|
+
const index = resolveTileIndex(matrix as TileMatrix, parameters.x, parameters.y, limits);
|
|
417
|
+
return index ? {...parameters, x: index[0], tileMatrix} : null;
|
|
402
418
|
}
|
|
403
419
|
if (matrix?.variableMatrixWidths?.length)
|
|
404
420
|
throw new RangeError('Coalesced tile requests require complete geometry.');
|
package/src/scan/query-scales.ts
CHANGED
|
@@ -4,17 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import {Table, type RecordBatch, type Vector} from 'apache-arrow';
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
bindArrowScale,
|
|
8
8
|
compileArrowScales,
|
|
9
|
+
compileArrowScaleExpression,
|
|
9
10
|
createStreamingDomainAccumulator,
|
|
10
|
-
type CompiledArrowScale
|
|
11
|
-
} from '@math.gl/sql/arrow-scales';
|
|
12
|
-
import {
|
|
11
|
+
type CompiledArrowScale,
|
|
13
12
|
parseSQLScaleExpression,
|
|
14
13
|
type ParsedSQLScale,
|
|
15
14
|
type ResolvedScale
|
|
16
15
|
} from '@math.gl/sql/scales';
|
|
17
16
|
import {makeArrowTableFromBatches} from '@loaders.gl/core/schema-utils';
|
|
17
|
+
import {compileArrowExpression, type CompiledArrowExpression} from '@math.gl/sql/arrow';
|
|
18
|
+
import type {Expression} from '@math.gl/sql/expressions';
|
|
18
19
|
import {query, queryInBatches, type Query, type QueryOptions} from './query';
|
|
19
20
|
|
|
20
21
|
/** Named row-preserving scale expressions applied to an input query result. */
|
|
@@ -39,7 +40,9 @@ export async function queryScales<Name extends string>(
|
|
|
39
40
|
options: QueryOptions
|
|
40
41
|
): Promise<ScaleQueryResult<Name>> {
|
|
41
42
|
options.signal?.throwIfAborted();
|
|
43
|
+
/** Scale calls validated before reading the source. */
|
|
42
44
|
const parsed = parseScaleProjections(projections);
|
|
45
|
+
/** Selected rows that define all data-derived domains. */
|
|
43
46
|
const table = await query(input, options);
|
|
44
47
|
options.signal?.throwIfAborted();
|
|
45
48
|
return evaluateScaleProjections(table, compileArrowScales(table, parsed), options.signal);
|
|
@@ -82,6 +85,7 @@ export async function* queryScalesInBatches<Name extends string>(
|
|
|
82
85
|
options: QueryOptions
|
|
83
86
|
): AsyncIterable<ScaleQueryResult<Name>> {
|
|
84
87
|
options.signal?.throwIfAborted();
|
|
88
|
+
/** Scale calls validated before reading the source. */
|
|
85
89
|
const parsed = parseScaleProjections(projections);
|
|
86
90
|
if (Object.values<ParsedSQLScale>(parsed).some(({scale}) => scale.domain.type !== 'fixed')) {
|
|
87
91
|
throw new Error('Append-only scale projections require fixed domains.');
|
|
@@ -129,46 +133,69 @@ export async function* queryScalesProgressive<Name extends string>(
|
|
|
129
133
|
) {
|
|
130
134
|
throw new Error('Scale snapshot interval and row limit must be positive integers.');
|
|
131
135
|
}
|
|
136
|
+
/** Scale calls validated before reading the source. */
|
|
132
137
|
const parsed = parseScaleProjections(projections);
|
|
138
|
+
/** Projection order shared by domain results and output descriptors. */
|
|
133
139
|
const entries = Object.entries<ParsedSQLScale>(parsed) as [Name, ParsedSQLScale][];
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
/** Expressions evaluated once per incoming batch for computed domain statistics. */
|
|
141
|
+
const domainExpressions = new Map<string, CompiledArrowExpression>();
|
|
142
|
+
/** Domain dependencies use private column names for computed values. */
|
|
143
|
+
const domains = entries.map(([, {scale}], index) =>
|
|
144
|
+
scale.domain.type === 'expression-extent'
|
|
145
|
+
? {type: 'extent' as const, column: `expression:${index}`}
|
|
146
|
+
: {
|
|
147
|
+
...scale.domain,
|
|
148
|
+
...(scale.domain.type === 'fixed' ? {} : {column: `column:${scale.domain.column}`})
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
/** Columns whose sketches supply classification breaks. */
|
|
152
|
+
const quantileColumns = entries.flatMap(([, {scale}], index) =>
|
|
153
|
+
scale.type === 'quantile' && scale.domain.type !== 'fixed'
|
|
154
|
+
? [
|
|
155
|
+
scale.domain.type === 'expression-extent'
|
|
156
|
+
? `expression:${index}`
|
|
157
|
+
: `column:${scale.domain.column}`
|
|
158
|
+
]
|
|
159
|
+
: []
|
|
140
160
|
);
|
|
161
|
+
/** Shared domain accumulator over projected scalar values. */
|
|
162
|
+
const accumulator = createStreamingDomainAccumulator(domains, {
|
|
163
|
+
quantileCapacity,
|
|
164
|
+
quantileColumns
|
|
165
|
+
});
|
|
141
166
|
const batches: RecordBatch[] = [];
|
|
142
167
|
let retainedRows = 0;
|
|
143
168
|
let batchesSinceEmission = 0;
|
|
144
169
|
let last: ScaleQueryResult<Name> | undefined;
|
|
145
170
|
|
|
146
171
|
/** Binds the current statistics and evaluates the selected snapshot. */
|
|
147
|
-
async function snapshot(
|
|
172
|
+
async function snapshot(): Promise<ScaleQueryResult<Name> | undefined> {
|
|
173
|
+
/** Current domain values in projection order. */
|
|
148
174
|
const domains = accumulator.result();
|
|
149
175
|
if (domains.some(domain => domain.length === 0)) return undefined;
|
|
150
|
-
// math.gl beta.11 cannot bind repeated quantize breaks. Defer publication
|
|
151
|
-
// until the extent grows, while still surfacing final domain errors.
|
|
152
|
-
if (
|
|
153
|
-
!final &&
|
|
154
|
-
entries.some(
|
|
155
|
-
([, {scale}], index) =>
|
|
156
|
-
scale.type === 'quantize' &&
|
|
157
|
-
scale.range.type === 'palette' &&
|
|
158
|
-
(scale.range.count ?? 0) > 2 &&
|
|
159
|
-
domains[index][0] === domains[index][1]
|
|
160
|
-
)
|
|
161
|
-
)
|
|
162
|
-
return undefined;
|
|
163
|
-
|
|
164
176
|
const table = await makeArrowTableFromBatches(batches);
|
|
165
177
|
signal?.throwIfAborted();
|
|
166
178
|
if (!table) return undefined;
|
|
167
|
-
const schemaOnly = new Table(table.schema);
|
|
168
179
|
const compiled = Object.fromEntries(
|
|
169
180
|
entries.map(([name, expression], index) => [
|
|
170
181
|
name,
|
|
171
|
-
|
|
182
|
+
bindArrowScale(table.schema, expression, {
|
|
183
|
+
domain: domains[index],
|
|
184
|
+
...(expression.scale.type === 'quantile'
|
|
185
|
+
? {
|
|
186
|
+
quantileBreaks: accumulator.quantileBreaks(
|
|
187
|
+
expression.scale.domain.type === 'expression-extent'
|
|
188
|
+
? `expression:${index}`
|
|
189
|
+
: expression.scale.domain.type !== 'fixed'
|
|
190
|
+
? `column:${expression.scale.domain.column}`
|
|
191
|
+
: String(index),
|
|
192
|
+
expression.scale.range.type === 'palette'
|
|
193
|
+
? expression.scale.range.count!
|
|
194
|
+
: expression.scale.range.values.length
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
: {})
|
|
198
|
+
})
|
|
172
199
|
])
|
|
173
200
|
) as Record<Name, CompiledArrowScale>;
|
|
174
201
|
return evaluateScaleProjections(table, compiled, signal);
|
|
@@ -184,7 +211,35 @@ export async function* queryScalesProgressive<Name extends string>(
|
|
|
184
211
|
}
|
|
185
212
|
batches.push(batch);
|
|
186
213
|
if (batch.numRows === 0) continue;
|
|
187
|
-
accumulator.
|
|
214
|
+
/** Scalar columns visited by the shared accumulator. */
|
|
215
|
+
const domainColumns: Record<string, Vector> = {};
|
|
216
|
+
entries.forEach(([, {scale}], index) => {
|
|
217
|
+
if (scale.domain.type === 'fixed') return;
|
|
218
|
+
/** Namespaced accumulator column, independent of source column spelling. */
|
|
219
|
+
const name =
|
|
220
|
+
scale.domain.type === 'expression-extent'
|
|
221
|
+
? `expression:${index}`
|
|
222
|
+
: `column:${scale.domain.column}`;
|
|
223
|
+
if (scale.domain.type === 'expression-extent') {
|
|
224
|
+
/** Reusable evaluator for the domain value expression. */
|
|
225
|
+
let compiled = domainExpressions.get(name);
|
|
226
|
+
if (!compiled) {
|
|
227
|
+
compiled = compileArrowExpression(scale.domain.expression as Expression, {
|
|
228
|
+
inputSchema: batch.schema
|
|
229
|
+
});
|
|
230
|
+
domainExpressions.set(name, compiled);
|
|
231
|
+
}
|
|
232
|
+
domainColumns[name] = compiled.evaluate(batch, {signal});
|
|
233
|
+
} else {
|
|
234
|
+
/** Source vector reused without copying. */
|
|
235
|
+
const column = batch.getChild(scale.domain.column);
|
|
236
|
+
if (!column) throw new Error(`Missing scale column: ${scale.domain.column}`);
|
|
237
|
+
domainColumns[name] = column;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
if (Object.keys(domainColumns).length) {
|
|
241
|
+
for (const domainBatch of new Table(domainColumns).batches) accumulator.update(domainBatch);
|
|
242
|
+
}
|
|
188
243
|
if (++batchesSinceEmission < emitEveryBatches) continue;
|
|
189
244
|
last = await snapshot();
|
|
190
245
|
if (last) {
|
|
@@ -193,7 +248,52 @@ export async function* queryScalesProgressive<Name extends string>(
|
|
|
193
248
|
}
|
|
194
249
|
}
|
|
195
250
|
signal?.throwIfAborted();
|
|
196
|
-
const final = last && batchesSinceEmission === 0 ? last : await snapshot(
|
|
251
|
+
const final = last && batchesSinceEmission === 0 ? last : await snapshot();
|
|
197
252
|
if (!final) throw new Error('Progressive scale query could not resolve its domain.');
|
|
198
253
|
yield {...final, final: true};
|
|
199
254
|
}
|
|
255
|
+
|
|
256
|
+
/** Row-preserving expression output and the resolved scales used by each expression. */
|
|
257
|
+
export type ScaleExpressionQueryResult<Name extends string = string> = Readonly<{
|
|
258
|
+
/** Rows selected by the input table query. */
|
|
259
|
+
table: Table;
|
|
260
|
+
/** Computed Arrow vectors in the selected row order. */
|
|
261
|
+
columns: Readonly<Record<Name, Vector>>;
|
|
262
|
+
/** Resolved samplers in expression traversal order, including conditional branches. */
|
|
263
|
+
scales: Readonly<Record<Name, readonly ResolvedScale[]>>;
|
|
264
|
+
}>;
|
|
265
|
+
|
|
266
|
+
/** Evaluates scale calls inside CASE, COALESCE, and nested expressions over selected rows. */
|
|
267
|
+
export async function queryScaleExpressions<Name extends string>(
|
|
268
|
+
input: Query | string,
|
|
269
|
+
expressions: Readonly<Record<Name, string | Expression>>,
|
|
270
|
+
options: QueryOptions
|
|
271
|
+
): Promise<ScaleExpressionQueryResult<Name>> {
|
|
272
|
+
options.signal?.throwIfAborted();
|
|
273
|
+
/** Selected rows that define all data-derived domains. */
|
|
274
|
+
const table = await query(input, options);
|
|
275
|
+
/** Named expression outputs and their matching resolved scales. */
|
|
276
|
+
const results = (Object.entries(expressions) as [Name, string | Expression][]).map(
|
|
277
|
+
([name, expression]) => {
|
|
278
|
+
options.signal?.throwIfAborted();
|
|
279
|
+
/** Upstream expression evaluator with resolved scale samplers. */
|
|
280
|
+
const compiled = compileArrowScaleExpression(table, expression);
|
|
281
|
+
return {
|
|
282
|
+
name,
|
|
283
|
+
column: compiled.evaluateTable(table, {signal: options.signal}),
|
|
284
|
+
scales: compiled.scales
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
return {
|
|
289
|
+
table,
|
|
290
|
+
columns: Object.fromEntries(results.map(result => [result.name, result.column])) as Record<
|
|
291
|
+
Name,
|
|
292
|
+
Vector
|
|
293
|
+
>,
|
|
294
|
+
scales: Object.fromEntries(results.map(result => [result.name, result.scales])) as Record<
|
|
295
|
+
Name,
|
|
296
|
+
readonly ResolvedScale[]
|
|
297
|
+
>
|
|
298
|
+
};
|
|
299
|
+
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {GeoArrowEncoding} from '@math.gl/arrow
|
|
5
|
+
import type {GeoArrowEncoding} from '@math.gl/core/arrow';
|
|
6
6
|
|
|
7
7
|
/** Canonical geometry encodings are shared with math.gl. */
|
|
8
8
|
export type {
|
|
9
9
|
GeoArrowEncoding,
|
|
10
10
|
GeoArrowDimension,
|
|
11
11
|
GeoArrowCoordinateLayout
|
|
12
|
-
} from '@math.gl/arrow
|
|
12
|
+
} from '@math.gl/core/arrow';
|
|
13
13
|
|
|
14
14
|
/** Preferred output policy for loader-facing GeoArrow conversions. */
|
|
15
15
|
export type GeoArrowEncodingPreference = 'geoarrow.wkb' | 'geoarrow.geometry' | 'optimized';
|
|
@@ -141,7 +141,7 @@ export {
|
|
|
141
141
|
// IntervalYearMonth,
|
|
142
142
|
// FixedSizeList,
|
|
143
143
|
// Struct
|
|
144
|
-
} from './lib/table/arrow-api
|
|
144
|
+
} from './lib/table/arrow-api';
|
|
145
145
|
|
|
146
146
|
// EXPERIMENTAL APIs
|
|
147
147
|
export {ArrowTableBuilder} from './lib/table/batch-builder/arrow-table-builder';
|
|
@@ -93,7 +93,8 @@ function convertArrowToColumnarTable(arrowTable: arrow.Table): ColumnarTable {
|
|
|
93
93
|
for (const field of arrowTable.schema.fields) {
|
|
94
94
|
// This (is intended to) coalesce all record batches into a single typed array
|
|
95
95
|
const arrowColumn = arrowTable.getChild(field.name);
|
|
96
|
-
|
|
96
|
+
// Typed value buffers omit the validity bitmap; materialize nullable columns through Arrow.
|
|
97
|
+
const values = arrowColumn?.nullCount ? Array.from(arrowColumn) : arrowColumn?.toArray();
|
|
97
98
|
columns[field.name] = values;
|
|
98
99
|
}
|
|
99
100
|
|
package/src/wkt/index.ts
CHANGED