@loaders.gl/core 5.0.0 → 5.0.2
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/dist/api.cjs +4129 -0
- package/dist/api.cjs.map +6 -0
- package/dist/api.d.ts +34 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +50 -0
- package/dist/api.js.map +1 -0
- package/dist/arrow-geometry/index.cjs +5 -2
- package/dist/arrow-geometry/index.cjs.map +2 -2
- package/dist/arrow-geometry/index.d.ts +1 -0
- package/dist/arrow-geometry/index.d.ts.map +1 -1
- package/dist/arrow-geometry/index.js +1 -0
- package/dist/arrow-geometry/index.js.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs +100 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs.map +7 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts +15 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts.map +1 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js +87 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js.map +1 -0
- package/dist/dist.dev.js +458 -539
- package/dist/dist.min.js +3 -3
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +1 -1
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts.map +1 -1
- package/dist/geoarrow/index.cjs +1 -1
- package/dist/geoarrow/index.cjs.map +1 -1
- package/dist/geoarrow/index.d.ts +2 -2
- package/dist/geoarrow/index.d.ts.map +1 -1
- package/dist/geoarrow/index.js +1 -1
- package/dist/geoarrow/index.js.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
- package/dist/index.cjs +67 -4114
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -46
- package/dist/index.js.map +1 -1
- package/dist/lib/api/encode-table.d.ts +4 -4
- package/dist/lib/api/encode-table.d.ts.map +1 -1
- package/dist/lib/api/encode-table.js +21 -3
- package/dist/lib/api/encode-table.js.map +1 -1
- package/dist/lib/api/encode.d.ts +6 -6
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +46 -7
- package/dist/lib/api/encode.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +94 -24
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/index.d.ts +3 -2
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +2 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader-metadata.cjs +85 -0
- package/dist/loader-utils/json-loader-metadata.cjs.map +6 -0
- package/dist/loader-utils/json-loader-metadata.d.ts +51 -0
- package/dist/loader-utils/json-loader-metadata.d.ts.map +1 -0
- package/dist/loader-utils/json-loader-metadata.js +31 -0
- package/dist/loader-utils/json-loader-metadata.js.map +1 -0
- package/dist/loader-utils/json-loader.cjs +80 -0
- package/dist/loader-utils/json-loader.cjs.map +6 -0
- package/dist/loader-utils/json-loader.d.ts +4 -4
- package/dist/loader-utils/json-loader.d.ts.map +1 -1
- package/dist/loader-utils/json-loader.js +3 -17
- package/dist/loader-utils/json-loader.js.map +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.d.ts +2 -0
- package/dist/loader-utils/lib/request-utils/authentication.d.ts.map +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.js +12 -0
- package/dist/loader-utils/lib/request-utils/authentication.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/raster-source.d.ts +21 -1
- package/dist/loader-utils/lib/sources/raster-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/raster-source.js.map +1 -1
- package/dist/loader-utils/lib/sources/raster-tile.d.ts +7 -0
- package/dist/loader-utils/lib/sources/raster-tile.d.ts.map +1 -0
- package/dist/loader-utils/lib/sources/raster-tile.js +34 -0
- package/dist/loader-utils/lib/sources/raster-tile.js.map +1 -0
- package/dist/loader-utils/lib/sources/utils/utils.d.ts +1 -1
- package/dist/loader-utils/lib/sources/utils/utils.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.d.ts +2 -1
- package/dist/loader-utils/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.js +1 -1
- package/dist/loader-utils/tile-grid.js.map +1 -1
- package/dist/loader-utils/writer-types.d.ts +2 -0
- package/dist/loader-utils/writer-types.d.ts.map +1 -1
- package/dist/null-loader-metadata.cjs +89 -0
- package/dist/null-loader-metadata.cjs.map +6 -0
- package/dist/null-loader-metadata.d.ts +48 -0
- package/dist/null-loader-metadata.d.ts.map +1 -0
- package/dist/null-loader-metadata.js +30 -0
- package/dist/null-loader-metadata.js.map +1 -0
- package/dist/null-loader.cjs +84 -0
- package/dist/null-loader.cjs.map +6 -0
- package/dist/null-loader.d.ts +6 -6
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +2 -15
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +58 -28
- package/dist/null-worker.js +58 -28
- package/dist/scan/arrow-execution/expressions.d.ts +1 -1
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
- package/dist/scan/arrow-query.cjs +2 -0
- package/dist/scan/arrow-query.cjs.map +2 -2
- package/dist/scan/arrow-query.d.ts +1 -1
- package/dist/scan/arrow-query.d.ts.map +1 -1
- package/dist/scan/arrow-query.js +1 -1
- package/dist/scan/arrow-query.js.map +1 -1
- package/dist/scan/index.cjs +16 -22
- package/dist/scan/index.cjs.map +2 -2
- package/dist/scan/index.d.ts +7 -7
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +4 -6
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/plan-arrow-table-query.d.ts +1 -1
- package/dist/scan/plan-arrow-table-query.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.cjs +7 -19
- package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
- package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.js +7 -22
- package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
- package/dist/scan/query-executor.cjs +202 -0
- package/dist/scan/query-executor.cjs.map +7 -0
- package/dist/scan/query-executor.d.ts +27 -0
- package/dist/scan/query-executor.d.ts.map +1 -0
- package/dist/scan/query-executor.js +203 -0
- package/dist/scan/query-executor.js.map +1 -0
- package/dist/scan/query.cjs +92 -205
- package/dist/scan/query.cjs.map +3 -3
- package/dist/scan/query.d.ts +5 -4
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +94 -238
- package/dist/scan/query.js.map +1 -1
- package/dist/schema-utils/index.cjs +182 -0
- package/dist/schema-utils/index.cjs.map +3 -3
- package/dist/schema-utils/index.d.ts +3 -0
- package/dist/schema-utils/index.d.ts.map +1 -1
- package/dist/schema-utils/index.js +3 -0
- package/dist/schema-utils/index.js.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts +24 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js +43 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts +29 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js +89 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts +17 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js +24 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts +4 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js +51 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js.map +1 -0
- package/dist/worker-utils/index.cjs +2 -2
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/package.json +49 -23
- package/src/api.ts +99 -0
- package/src/arrow-geometry/index.ts +5 -0
- package/src/arrow-geometry/triangulate-wkb-geometry-column.ts +122 -0
- package/src/geoarrow/index.ts +2 -2
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +1 -1
- package/src/index.ts +2 -94
- package/src/lib/api/encode-table.ts +31 -6
- package/src/lib/api/encode.ts +61 -11
- package/src/loader-utils/index.ts +3 -0
- package/src/loader-utils/json-loader-metadata.ts +35 -0
- package/src/loader-utils/json-loader.ts +3 -18
- package/src/loader-utils/lib/request-utils/authentication.ts +17 -0
- package/src/loader-utils/lib/sources/raster-source.ts +22 -1
- package/src/loader-utils/lib/sources/raster-tile.ts +46 -0
- package/src/loader-utils/tile-grid.ts +16 -1
- package/src/loader-utils/writer-types.ts +2 -0
- package/src/null-loader-metadata.ts +32 -0
- package/src/null-loader.ts +2 -17
- package/src/scan/arrow-query.ts +1 -1
- package/src/scan/index.ts +24 -13
- package/src/scan/query-arrow-table-in-batches.ts +7 -24
- package/src/scan/query-executor.ts +286 -0
- package/src/scan/query.ts +112 -299
- package/src/schema-utils/index.ts +14 -0
- package/src/schema-utils/lib/arrow/arrow-converter.ts +74 -0
- package/src/schema-utils/lib/arrow/convert-arrow-variable-width.ts +121 -0
- package/src/schema-utils/lib/arrow/convert-arrow.ts +52 -0
- package/src/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.ts +83 -0
- package/dist/cluster-source.cjs +0 -6360
- package/dist/cluster-source.cjs.map +0 -6
- package/dist/cluster-source.d.ts +0 -2
- package/dist/cluster-source.d.ts.map +0 -1
- package/dist/cluster-source.js +0 -2
- package/dist/cluster-source.js.map +0 -1
- package/dist/federated-table-scan-source.cjs +0 -1905
- package/dist/federated-table-scan-source.cjs.map +0 -6
- package/dist/federated-table-scan-source.d.ts +0 -2
- package/dist/federated-table-scan-source.d.ts.map +0 -1
- package/dist/federated-table-scan-source.js +0 -2
- package/dist/federated-table-scan-source.js.map +0 -1
- package/dist/geoarrow/geoarrow-builder.cjs +0 -31
- package/dist/geoarrow/geoarrow-builder.cjs.map +0 -7
- package/dist/geoarrow/geoarrow-builder.d.ts +0 -3
- package/dist/geoarrow/geoarrow-builder.d.ts.map +0 -1
- package/dist/geoarrow/geoarrow-builder.js +0 -5
- package/dist/geoarrow/geoarrow-builder.js.map +0 -1
- package/dist/vector-table-scan-source.cjs +0 -1200
- package/dist/vector-table-scan-source.cjs.map +0 -6
- package/dist/vector-table-scan-source.d.ts +0 -2
- package/dist/vector-table-scan-source.d.ts.map +0 -1
- package/dist/vector-table-scan-source.js +0 -2
- package/dist/vector-table-scan-source.js.map +0 -1
- package/src/cluster-source.ts +0 -1
- package/src/federated-table-scan-source.ts +0 -1
- package/src/geoarrow/geoarrow-builder.ts +0 -21
- package/src/vector-table-scan-source.ts +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {GetRasterTileParameters, NumericRasterData, RasterSource} from './raster-source';
|
|
6
|
+
import {resolveTileGridTile} from './tile-grid';
|
|
7
|
+
import {waitForPromiseWithSignal} from '../request-utils/abort-utils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reads one native tile without resampling (experimental).
|
|
11
|
+
* Uses the advertised matrix IDs for default bands and lets the source validate explicit bands.
|
|
12
|
+
*/
|
|
13
|
+
export async function readRasterTile(
|
|
14
|
+
source: RasterSource<NumericRasterData>,
|
|
15
|
+
parameters: GetRasterTileParameters
|
|
16
|
+
): Promise<NumericRasterData | null> {
|
|
17
|
+
const {tileMatrix, bands, signal} = parameters;
|
|
18
|
+
signal?.throwIfAborted();
|
|
19
|
+
const {tileGrid, nativeTileMatrixIds} = await waitForPromiseWithSignal(
|
|
20
|
+
source.getMetadata({signal}),
|
|
21
|
+
signal
|
|
22
|
+
);
|
|
23
|
+
signal?.throwIfAborted();
|
|
24
|
+
const matrixSet = tileGrid?.tileMatrixSet;
|
|
25
|
+
if (!matrixSet?.crs || !matrixSet.matrices.length)
|
|
26
|
+
throw new Error('readRasterTile requires a complete native tile matrix set');
|
|
27
|
+
|
|
28
|
+
const resolved = resolveTileGridTile(tileGrid, {...parameters, z: 0});
|
|
29
|
+
const matrix = matrixSet.matrices.find(candidate => candidate.id === tileMatrix)!;
|
|
30
|
+
if (bands === undefined && nativeTileMatrixIds && !nativeTileMatrixIds.includes(tileMatrix))
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Tile matrix "${tileMatrix}" does not support native tile reads. Readable matrix IDs: ${JSON.stringify(nativeTileMatrixIds)}`
|
|
33
|
+
);
|
|
34
|
+
if (!resolved) return null;
|
|
35
|
+
if (!source.getRasterTile) throw new Error('Raster source does not support native tile reads');
|
|
36
|
+
|
|
37
|
+
const raster = await waitForPromiseWithSignal(
|
|
38
|
+
source.getRasterTile({...parameters, x: resolved.x}),
|
|
39
|
+
signal
|
|
40
|
+
);
|
|
41
|
+
signal?.throwIfAborted();
|
|
42
|
+
if (!raster) return null;
|
|
43
|
+
if (raster.width !== matrix.tileSize[0] || raster.height !== matrix.tileSize[1])
|
|
44
|
+
throw new Error(`Raster tile dimensions do not match matrix "${tileMatrix}"`);
|
|
45
|
+
return raster;
|
|
46
|
+
}
|
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/** Focused, renderer-independent grid normalization, validation and addressing utilities. */
|
|
6
|
-
export
|
|
6
|
+
export {
|
|
7
|
+
createTileGrid,
|
|
8
|
+
createTileGridMatrix,
|
|
9
|
+
getRequestedTileMatrix,
|
|
10
|
+
getTileGridMatrixId,
|
|
11
|
+
getTileGridValidation,
|
|
12
|
+
resolveTileGridTile,
|
|
13
|
+
validateTileGrid,
|
|
14
|
+
validateTileGridLimits
|
|
15
|
+
} from './lib/sources/tile-grid';
|
|
16
|
+
export type {
|
|
17
|
+
TileGridValidation,
|
|
18
|
+
TileGridValidationInput,
|
|
19
|
+
TileGridValidationIssue,
|
|
20
|
+
TileMatrixFields
|
|
21
|
+
} from './lib/sources/tile-grid';
|
|
7
22
|
export {getXYZTileGridOptions} from './lib/sources/xyz-grid-options';
|
|
8
23
|
export type {XYZTileGridAssessment, XYZTileGridOptions} from './lib/sources/xyz-grid-options';
|
|
@@ -39,6 +39,8 @@ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOpt
|
|
|
39
39
|
dataType?: DataT;
|
|
40
40
|
/** The batched result type of this loader */
|
|
41
41
|
batchType?: BatchT;
|
|
42
|
+
/** Loads the encoder implementation on demand. */
|
|
43
|
+
preload?(): Promise<WriterWithEncoder<DataT, BatchT, WriterOptionsT>>;
|
|
42
44
|
/** Version should be injected by build tools */
|
|
43
45
|
version: string;
|
|
44
46
|
/** A boolean, or a URL */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
8
|
+
|
|
9
|
+
/** Shared metadata for NullLoader. */
|
|
10
|
+
export const NullLoaderMetadata = {
|
|
11
|
+
dataType: null,
|
|
12
|
+
batchType: null,
|
|
13
|
+
name: 'Null loader',
|
|
14
|
+
id: 'null',
|
|
15
|
+
module: 'core',
|
|
16
|
+
version: VERSION,
|
|
17
|
+
mimeTypes: ['application/x.empty'] as string[],
|
|
18
|
+
extensions: ['null'] as string[],
|
|
19
|
+
tests: [() => false] as (() => boolean)[],
|
|
20
|
+
options: {
|
|
21
|
+
null: {}
|
|
22
|
+
}
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
/** Defers the NullLoader parser until first use. */
|
|
26
|
+
export const NullLoader = {
|
|
27
|
+
...NullLoaderMetadata,
|
|
28
|
+
async preload() {
|
|
29
|
+
const implementation = await import('./null-loader.js');
|
|
30
|
+
return implementation.NullLoader;
|
|
31
|
+
}
|
|
32
|
+
} as const;
|
package/src/null-loader.ts
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {NullLoaderMetadata} from './null-loader-metadata';
|
|
5
6
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/core/loader-utils';
|
|
6
7
|
import {LoaderContext} from '@loaders.gl/core/loader-utils';
|
|
7
8
|
|
|
8
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
-
|
|
12
9
|
export type NullLoaderOptions = LoaderOptions & {
|
|
13
10
|
null?: {};
|
|
14
11
|
};
|
|
@@ -17,15 +14,7 @@ export type NullLoaderOptions = LoaderOptions & {
|
|
|
17
14
|
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
18
15
|
*/
|
|
19
16
|
export const NullLoader = {
|
|
20
|
-
|
|
21
|
-
batchType: null,
|
|
22
|
-
|
|
23
|
-
name: 'Null loader',
|
|
24
|
-
id: 'null',
|
|
25
|
-
module: 'core',
|
|
26
|
-
version: VERSION,
|
|
27
|
-
mimeTypes: ['application/x.empty'],
|
|
28
|
-
extensions: ['null'],
|
|
17
|
+
...NullLoaderMetadata,
|
|
29
18
|
parse: async (
|
|
30
19
|
arrayBuffer: ArrayBufferLike | ArrayBufferView,
|
|
31
20
|
options?: NullLoaderOptions,
|
|
@@ -36,10 +25,6 @@ export const NullLoader = {
|
|
|
36
25
|
for await (const batch of asyncIterator) {
|
|
37
26
|
yield parseSync(batch, options, context);
|
|
38
27
|
}
|
|
39
|
-
},
|
|
40
|
-
tests: [() => false],
|
|
41
|
-
options: {
|
|
42
|
-
null: {}
|
|
43
28
|
}
|
|
44
29
|
} as const satisfies LoaderWithParser<null, null, NullLoaderOptions>;
|
|
45
30
|
|
package/src/scan/arrow-query.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
export {ARROW_TABLE_QUERY_CAPABILITIES} from './plan-arrow-table-query';
|
|
5
|
+
export {ARROW_TABLE_QUERY_CAPABILITIES, explainArrowTableQuery} from './plan-arrow-table-query';
|
|
6
6
|
export {queryArrowTable} from './query-arrow-table';
|
|
7
7
|
export {queryArrowTableInBatches} from './query-arrow-table-in-batches';
|
|
8
8
|
export {getSQLPredicateColumnNames, planTableQuery} from './table-query';
|
package/src/scan/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type {
|
|
|
24
24
|
// Re-export the query vocabulary from one optional entry point for applications. Format adapters
|
|
25
25
|
// should continue importing the lightweight contracts from @loaders.gl/core/loader-utils.
|
|
26
26
|
export {parseSQLPredicate} from './parse-sql-predicate';
|
|
27
|
+
export type {ArrowFilterOptions} from './arrow-execution';
|
|
27
28
|
export type {ArrowQueryOptions} from './query-arrow-table';
|
|
28
29
|
export type {SQLPredicate} from './sql-predicate-types';
|
|
29
30
|
export type {
|
|
@@ -102,9 +103,27 @@ export type {
|
|
|
102
103
|
VectorTileTableScanSourceOptions
|
|
103
104
|
} from './vector-table-scan-source';
|
|
104
105
|
|
|
105
|
-
export {
|
|
106
|
-
export {
|
|
107
|
-
|
|
106
|
+
export {bindSQLPredicate} from './bind-sql-predicate';
|
|
107
|
+
export {
|
|
108
|
+
isSQLPredicate,
|
|
109
|
+
SQL_PREDICATE_JSON_SCHEMA,
|
|
110
|
+
validateSQLPredicate
|
|
111
|
+
} from './sql-predicate-schema';
|
|
112
|
+
export {isSQLPredicateParameter} from './sql-predicate-types';
|
|
113
|
+
export type {
|
|
114
|
+
BoundSQLPredicate,
|
|
115
|
+
SQLComparisonPredicate,
|
|
116
|
+
SQLInPredicate,
|
|
117
|
+
SQLLogicalPredicate,
|
|
118
|
+
SQLNotPredicate,
|
|
119
|
+
SQLNullPredicate,
|
|
120
|
+
SQLPredicateParameter,
|
|
121
|
+
SQLPredicateParameterValues,
|
|
122
|
+
SQLPredicateParserOptions,
|
|
123
|
+
SQLPredicateProperty,
|
|
124
|
+
SQLPredicateScalar,
|
|
125
|
+
SQLPredicateValue
|
|
126
|
+
} from './sql-predicate-types';
|
|
108
127
|
export {explainTableQuery, getSQLPredicateColumnNames, planTableQuery} from './table-query';
|
|
109
128
|
export type {
|
|
110
129
|
TableQueryPlan,
|
|
@@ -126,11 +145,8 @@ export type {
|
|
|
126
145
|
LogicalTableQueryPlan
|
|
127
146
|
} from '../loader-utils/lib/scan-utils/logical-table-query';
|
|
128
147
|
|
|
129
|
-
export {projectArrowTable, filterArrowTable} from './arrow-execution';
|
|
130
|
-
export type {ArrowFilterOptions} from './arrow-execution';
|
|
131
|
-
|
|
132
148
|
export {queryGroupedSQL} from './query-grouped-sql';
|
|
133
|
-
export {query, queryInBatches, queryProgressive} from './query';
|
|
149
|
+
export {preloadQuery, query, queryInBatches, queryProgressive} from './query';
|
|
134
150
|
export type {
|
|
135
151
|
ProgressiveAggregate,
|
|
136
152
|
ProgressiveAggregateQuery,
|
|
@@ -160,9 +176,4 @@ export type {
|
|
|
160
176
|
QueryPushdownCapabilityHints
|
|
161
177
|
} from '@loaders.gl/core/loader-utils';
|
|
162
178
|
|
|
163
|
-
export {
|
|
164
|
-
createArrowQueryWorker,
|
|
165
|
-
queryArrowTableInWorker,
|
|
166
|
-
type ArrowQueryWorkerOptions,
|
|
167
|
-
type ArrowQueryWorkerSession
|
|
168
|
-
} from './arrow-query-worker';
|
|
179
|
+
export type {ArrowQueryWorkerOptions, ArrowQueryWorkerSession} from './arrow-query-worker';
|
|
@@ -31,28 +31,11 @@ export async function* queryArrowTableInBatches(
|
|
|
31
31
|
validateTableQueryLimit(options.limit);
|
|
32
32
|
options.signal?.throwIfAborted();
|
|
33
33
|
if (options.limit === 0) return;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let next: IteratorResult<arrow.RecordBatch> = first;
|
|
42
|
-
!next.done;
|
|
43
|
-
next = await iterator.next()
|
|
44
|
-
) {
|
|
45
|
-
yield next.value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
yield* executeArrowQueryInBatches(readBatches(), first.value.schema, {
|
|
49
|
-
select: options.select ?? options.columns,
|
|
50
|
-
where: options.predicate,
|
|
51
|
-
limit: options.limit,
|
|
52
|
-
signal: options.signal,
|
|
53
|
-
emitEmptyBatches: true
|
|
54
|
-
});
|
|
55
|
-
} finally {
|
|
56
|
-
await iterator.return?.();
|
|
57
|
-
}
|
|
34
|
+
yield* executeArrowQueryInBatches(batches, {
|
|
35
|
+
select: options.select ?? options.columns,
|
|
36
|
+
where: options.predicate,
|
|
37
|
+
limit: options.limit,
|
|
38
|
+
signal: options.signal,
|
|
39
|
+
emitEmptyBatches: true
|
|
40
|
+
});
|
|
58
41
|
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import * as arrow from 'apache-arrow';
|
|
6
|
+
import type {TableBatch, Schema} from '@loaders.gl/core/schema';
|
|
7
|
+
import {
|
|
8
|
+
normalizeTableQuery,
|
|
9
|
+
getColumnarPredicateColumns,
|
|
10
|
+
executeTableScanBatches,
|
|
11
|
+
planTableQuery,
|
|
12
|
+
type TableQuery,
|
|
13
|
+
type TableScanReadOptions,
|
|
14
|
+
type TableScanSource,
|
|
15
|
+
type TableQueryExecutionSummary
|
|
16
|
+
} from '@loaders.gl/core/loader-utils';
|
|
17
|
+
import {
|
|
18
|
+
convertArrowToSchema,
|
|
19
|
+
convertSchemaToArrow,
|
|
20
|
+
convertTableToArrow,
|
|
21
|
+
makeArrowMetadataBatch,
|
|
22
|
+
makeArrowTableFromBatches
|
|
23
|
+
} from '@loaders.gl/core/schema-utils';
|
|
24
|
+
import {projectArrowTable, filterArrowTable} from './arrow-execution';
|
|
25
|
+
import {filterArrowRows} from './arrow-execution/filter-arrow-table';
|
|
26
|
+
import type {QueryOptions} from './query';
|
|
27
|
+
import {planQueryPushdown} from './query-pushdown';
|
|
28
|
+
import type {SQLQuery} from '@math.gl/sql/parser';
|
|
29
|
+
import type {SQLCatalogQuery} from './sql-catalog';
|
|
30
|
+
|
|
31
|
+
/** Source and query information available before the first physical read. */
|
|
32
|
+
type PreparedQuery = {
|
|
33
|
+
/** Validated logical query. */
|
|
34
|
+
logicalQuery: TableQuery | Exclude<SQLQuery, SQLCatalogQuery>;
|
|
35
|
+
/** Resolved table or scan source. */
|
|
36
|
+
source: object;
|
|
37
|
+
/** Native Arrow input when supplied by the caller. */
|
|
38
|
+
inMemory: arrow.Table | null;
|
|
39
|
+
/** Discovery result for a scan source. */
|
|
40
|
+
metadata: Awaited<ReturnType<TableScanSource['getQueryMetadata']>> | undefined;
|
|
41
|
+
/** Whether WHERE requires expression evaluation. */
|
|
42
|
+
castPredicate: boolean;
|
|
43
|
+
/** Whether this request targets catalog metadata. */
|
|
44
|
+
catalogQuery: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Executes a prepared query and updates its public completion counters. */
|
|
48
|
+
export async function* executePreparedQuery(
|
|
49
|
+
{logicalQuery, source, inMemory, metadata, castPredicate, catalogQuery}: PreparedQuery,
|
|
50
|
+
options: QueryOptions,
|
|
51
|
+
metrics: Pick<
|
|
52
|
+
{-readonly [Key in keyof TableQueryExecutionSummary]: TableQueryExecutionSummary[Key]},
|
|
53
|
+
'sourcesRead' | 'rowsRead' | 'rowsReturned' | 'batchesRead' | 'earlyTerminationReason'
|
|
54
|
+
>
|
|
55
|
+
): AsyncGenerator<arrow.RecordBatch> {
|
|
56
|
+
const sourceSchema = inMemory ? inMemory.schema : convertSchemaToArrow(metadata!.schema);
|
|
57
|
+
const names = sourceSchema.fields.map(field => field.name);
|
|
58
|
+
const {select: requestedSelect, where, ...controls} = logicalQuery;
|
|
59
|
+
const computedProjection =
|
|
60
|
+
Array.isArray(requestedSelect) &&
|
|
61
|
+
requestedSelect.some(
|
|
62
|
+
selection =>
|
|
63
|
+
selection &&
|
|
64
|
+
typeof selection === 'object' &&
|
|
65
|
+
('expression' in selection || 'array' in selection)
|
|
66
|
+
);
|
|
67
|
+
// Resolve the public scan aliases before planning either native or residual projection.
|
|
68
|
+
const select = computedProjection
|
|
69
|
+
? requestedSelect.map((item, index) =>
|
|
70
|
+
item && typeof item === 'object' && ('expression' in item || 'array' in item)
|
|
71
|
+
? {...item, as: item.as ?? `column${index + 1}`}
|
|
72
|
+
: item
|
|
73
|
+
)
|
|
74
|
+
: requestedSelect;
|
|
75
|
+
const expressionFilter =
|
|
76
|
+
where && typeof where === 'object' && 'expression' in where ? where : undefined;
|
|
77
|
+
const portablePredicate = expressionFilter ? undefined : (where as TableQuery['where']);
|
|
78
|
+
const normalized = normalizeTableQuery(names, {
|
|
79
|
+
...controls,
|
|
80
|
+
select: computedProjection ? undefined : (select as TableQuery['select']),
|
|
81
|
+
where: castPredicate ? undefined : portablePredicate
|
|
82
|
+
});
|
|
83
|
+
const expressionTools =
|
|
84
|
+
computedProjection || expressionFilter || castPredicate
|
|
85
|
+
? await import('./arrow-execution/expressions')
|
|
86
|
+
: undefined;
|
|
87
|
+
const outputColumns = computedProjection
|
|
88
|
+
? expressionTools!.getProjectionColumns(select!)
|
|
89
|
+
: normalized.select.map(selection => selection.column);
|
|
90
|
+
const expressionColumns = expressionFilter
|
|
91
|
+
? expressionTools!.getExpressionColumns(expressionFilter.expression)
|
|
92
|
+
: castPredicate && portablePredicate
|
|
93
|
+
? getColumnarPredicateColumns(portablePredicate)
|
|
94
|
+
: [];
|
|
95
|
+
const required = [...new Set([...outputColumns, ...expressionColumns])];
|
|
96
|
+
const plan = planTableQuery(names, {
|
|
97
|
+
// A literal-only projection still needs a physical column to retain row counts.
|
|
98
|
+
columns: required.length ? required : names.slice(0, 1),
|
|
99
|
+
predicate: normalized.where
|
|
100
|
+
});
|
|
101
|
+
const requiredColumns = plan[0].kind === 'scan' ? plan[0].columns : names;
|
|
102
|
+
const capabilities = (metadata?.queryCapabilities ?? metadata?.capabilities)?.table;
|
|
103
|
+
// read() must perform exact filtering when it advertises pushdown+residual, not only pruning.
|
|
104
|
+
const delegatePredicate = Boolean(
|
|
105
|
+
normalized.where &&
|
|
106
|
+
capabilities &&
|
|
107
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.predicate)
|
|
108
|
+
);
|
|
109
|
+
const residual = delegatePredicate ? undefined : normalized.where;
|
|
110
|
+
const canDelegateWindow = !residual && !expressionFilter && !castPredicate;
|
|
111
|
+
const delegateOffset = Boolean(
|
|
112
|
+
canDelegateWindow &&
|
|
113
|
+
normalized.offset !== undefined &&
|
|
114
|
+
capabilities &&
|
|
115
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.offset ?? 'unsupported')
|
|
116
|
+
);
|
|
117
|
+
const requestedRows =
|
|
118
|
+
normalized.limit === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: (delegateOffset ? 0 : (normalized.offset ?? 0)) + normalized.limit;
|
|
121
|
+
const readOptions: TableScanReadOptions = {
|
|
122
|
+
signal: options.signal,
|
|
123
|
+
...(capabilities && capabilities.projection !== 'unsupported'
|
|
124
|
+
? {columns: requiredColumns}
|
|
125
|
+
: {}),
|
|
126
|
+
...(delegatePredicate ? {predicate: normalized.where} : {}),
|
|
127
|
+
...(delegateOffset ? {offset: normalized.offset} : {}),
|
|
128
|
+
...(canDelegateWindow &&
|
|
129
|
+
requestedRows !== undefined &&
|
|
130
|
+
Number.isSafeInteger(requestedRows) &&
|
|
131
|
+
capabilities &&
|
|
132
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.limit)
|
|
133
|
+
? {limit: requestedRows}
|
|
134
|
+
: {})
|
|
135
|
+
};
|
|
136
|
+
const inputSchema = readOptions.columns
|
|
137
|
+
? sourceSchema.select([...readOptions.columns])
|
|
138
|
+
: sourceSchema;
|
|
139
|
+
const readSchema = convertArrowToSchema(inputSchema);
|
|
140
|
+
const comparisonInputSchema = expressionTools ? convertSchemaToArrow(readSchema) : undefined;
|
|
141
|
+
const compiledFilter = expressionFilter
|
|
142
|
+
? expressionTools!.compileArrowExpression(expressionFilter.expression, {
|
|
143
|
+
inputSchema,
|
|
144
|
+
functions: options.functions
|
|
145
|
+
})
|
|
146
|
+
: castPredicate && portablePredicate
|
|
147
|
+
? expressionTools!.compileArrowPredicate(portablePredicate, {inputSchema})
|
|
148
|
+
: undefined;
|
|
149
|
+
if (compiledFilter && !arrow.DataType.isBool(compiledFilter.outputField.type))
|
|
150
|
+
throw new Error('SQL WHERE expression must return Boolean.');
|
|
151
|
+
const project = computedProjection
|
|
152
|
+
? expressionTools!.prepareArrowProjection(inputSchema, select!, {
|
|
153
|
+
signal: options.signal,
|
|
154
|
+
functions: options.functions
|
|
155
|
+
}).projectTable
|
|
156
|
+
: (data: arrow.Table) => projectArrowTable(data, normalized.select);
|
|
157
|
+
const empty = project(new arrow.Table(inputSchema));
|
|
158
|
+
const comparisonSchema = convertSchemaToArrow(convertArrowToSchema(empty.schema));
|
|
159
|
+
const pushedPlan =
|
|
160
|
+
!inMemory &&
|
|
161
|
+
!options.functions?.length &&
|
|
162
|
+
!catalogQuery &&
|
|
163
|
+
(source as TableScanSource).planQueryPushdown
|
|
164
|
+
? await planQueryPushdown(
|
|
165
|
+
source as TableScanSource,
|
|
166
|
+
{...logicalQuery, select},
|
|
167
|
+
capabilities,
|
|
168
|
+
comparisonSchema,
|
|
169
|
+
Boolean(computedProjection || expressionFilter),
|
|
170
|
+
inputSchema,
|
|
171
|
+
options.signal
|
|
172
|
+
)
|
|
173
|
+
: null;
|
|
174
|
+
options.signal?.throwIfAborted();
|
|
175
|
+
let emitted = false;
|
|
176
|
+
/** Adapts physical batches without pulling ahead of the query consumer. */
|
|
177
|
+
async function* inputs(): AsyncIterable<arrow.Table> {
|
|
178
|
+
metrics.sourcesRead = 1;
|
|
179
|
+
const batches: AsyncIterable<unknown> = pushedPlan
|
|
180
|
+
? pushedPlan.read({signal: options.signal})
|
|
181
|
+
: inMemory
|
|
182
|
+
? memoryBatches(inMemory)
|
|
183
|
+
: (source as TableScanSource).read(readOptions);
|
|
184
|
+
for await (const value of batches) {
|
|
185
|
+
options.signal?.throwIfAborted();
|
|
186
|
+
let batch = normalizeBatch(value, pushedPlan?.schema ?? readSchema);
|
|
187
|
+
if (
|
|
188
|
+
!pushedPlan &&
|
|
189
|
+
comparisonInputSchema &&
|
|
190
|
+
!arrow.util.compareSchemas(
|
|
191
|
+
comparisonInputSchema,
|
|
192
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
193
|
+
)
|
|
194
|
+
) {
|
|
195
|
+
// A source may return a wider or differently ordered projection than requested.
|
|
196
|
+
batch = batch.select(inputSchema.names);
|
|
197
|
+
if (
|
|
198
|
+
!arrow.util.compareSchemas(
|
|
199
|
+
comparisonInputSchema,
|
|
200
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
throw new Error('Query input schema does not match source metadata.');
|
|
204
|
+
}
|
|
205
|
+
metrics.batchesRead++;
|
|
206
|
+
metrics.rowsRead += batch.numRows;
|
|
207
|
+
yield batch;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for await (const value of executeTableScanBatches<arrow.Table>(
|
|
211
|
+
() => inputs(),
|
|
212
|
+
{
|
|
213
|
+
predicate: pushedPlan ? undefined : residual,
|
|
214
|
+
offset: pushedPlan || delegateOffset ? undefined : normalized.offset,
|
|
215
|
+
limit: normalized.limit,
|
|
216
|
+
skipEmptyBatches: true,
|
|
217
|
+
signal: options.signal
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
filter: (batch, predicate, signal) => {
|
|
221
|
+
if (pushedPlan) return batch;
|
|
222
|
+
if (compiledFilter) {
|
|
223
|
+
return filterArrowRows(
|
|
224
|
+
batch,
|
|
225
|
+
recordBatch => {
|
|
226
|
+
const matches = compiledFilter.evaluate(recordBatch, {signal});
|
|
227
|
+
return index => matches.get(index) === true;
|
|
228
|
+
},
|
|
229
|
+
{signal}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
return predicate ? filterArrowTable(batch, predicate, {signal}) : batch;
|
|
233
|
+
},
|
|
234
|
+
project: batch => (pushedPlan || computedProjection ? batch : project(batch))
|
|
235
|
+
}
|
|
236
|
+
)) {
|
|
237
|
+
const finishProjection = pushedPlan
|
|
238
|
+
? pushedPlan.project
|
|
239
|
+
: computedProjection
|
|
240
|
+
? project
|
|
241
|
+
: undefined;
|
|
242
|
+
const batch = finishProjection ? finishProjection(value) : value;
|
|
243
|
+
if (
|
|
244
|
+
!arrow.util.compareSchemas(
|
|
245
|
+
comparisonSchema,
|
|
246
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
throw new Error('Query output schema does not match source metadata.');
|
|
250
|
+
emitted = true;
|
|
251
|
+
metrics.rowsReturned += batch.numRows;
|
|
252
|
+
if (batch.batches.length) yield* batch.batches;
|
|
253
|
+
else yield makeArrowMetadataBatch(batch.schema);
|
|
254
|
+
}
|
|
255
|
+
// An empty schema-bearing batch makes collected and streaming empty results identical.
|
|
256
|
+
if (!emitted) {
|
|
257
|
+
if (empty.batches.length) yield* empty.batches;
|
|
258
|
+
else yield makeArrowMetadataBatch(empty.schema);
|
|
259
|
+
}
|
|
260
|
+
if (normalized.limit !== undefined && metrics.rowsReturned >= normalized.limit)
|
|
261
|
+
metrics.earlyTerminationReason = 'limit';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export {makeArrowTableFromBatches};
|
|
265
|
+
|
|
266
|
+
/** Emits original Arrow RecordBatches without copying their buffers. */
|
|
267
|
+
async function* memoryBatches(data: arrow.Table): AsyncIterable<arrow.Table> {
|
|
268
|
+
for (const batch of data.batches) yield new arrow.Table(data.schema, [batch]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Converts supported native table batches to Arrow while preserving their declared schema. */
|
|
272
|
+
function normalizeBatch(value: unknown, fallbackSchema: Schema): arrow.Table {
|
|
273
|
+
if (!value || typeof value !== 'object') throw new Error('Unsupported query batch.');
|
|
274
|
+
if ('numRows' in value) {
|
|
275
|
+
const batch = value as arrow.RecordBatch;
|
|
276
|
+
return new arrow.Table(batch.schema, [batch]);
|
|
277
|
+
}
|
|
278
|
+
if (!('shape' in value)) throw new Error('Unsupported query batch.');
|
|
279
|
+
const input = value as TableBatch;
|
|
280
|
+
const batch = {...input, schema: input.schema ?? fallbackSchema} as TableBatch;
|
|
281
|
+
if (!['object-row-table', 'array-row-table', 'columnar-table'].includes(batch.shape))
|
|
282
|
+
throw new Error(`Unsupported query batch shape: ${batch.shape}`);
|
|
283
|
+
return batch.length === 0 && batch.schema
|
|
284
|
+
? new arrow.Table(convertSchemaToArrow(batch.schema))
|
|
285
|
+
: convertTableToArrow(batch);
|
|
286
|
+
}
|