@luma.gl/graph 10.0.0-alpha.11 → 10.0.0-alpha.13
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/LICENSE +4 -4
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +6 -6
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +16 -6
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +3 -2
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +3 -2
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
- package/dist/arrow/index.cjs.map +2 -2
- package/dist/arrow/internal.cjs.map +2 -2
- package/dist/dist.dev.js +2148 -454
- package/dist/dist.min.js +437 -123
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/simulation/index.cjs.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.cjs +15 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts +1 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.js +15 -0
- package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph.cjs +9 -0
- package/dist/gpu-core/gpu-command-graph.d.ts +2 -0
- package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph.js +9 -0
- package/dist/gpu-core/gpu-command-graph.js.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.cjs +4 -0
- package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.js +5 -0
- package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.js +50 -0
- package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
- package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.js +7 -18
- package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
- package/dist/gpu-core/gpu-reduction.cjs +6 -14
- package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
- package/dist/gpu-core/gpu-reduction.js +6 -15
- package/dist/gpu-core/gpu-reduction.js.map +1 -1
- package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.cjs +267 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.d.ts +29 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.d.ts.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.js +260 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.js.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-operation.cjs +85 -0
- package/dist/gpu-core/gpu-shader-pass-operation.d.ts +32 -0
- package/dist/gpu-core/gpu-shader-pass-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-operation.js +74 -0
- package/dist/gpu-core/gpu-shader-pass-operation.js.map +1 -0
- package/dist/gpu-core/index.cjs +8 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +4 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +2 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
- package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
- package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
- package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
- package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
- package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
- package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
- package/dist/gpu-data/index.cjs.map +3 -3
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph/index.cjs +5 -0
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph/index.d.ts +2 -0
- package/dist/gpu-graph/index.d.ts.map +1 -1
- package/dist/gpu-graph/index.js +1 -0
- package/dist/gpu-graph/index.js.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph-algorithms/index.cjs.map +1 -1
- package/dist/gpu-physics/index.cjs.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/graph.cjs.map +3 -3
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +53 -5
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +3 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +58 -5
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-sql/gpu-sql.cjs +112 -100
- package/dist/gpu-sql/gpu-sql.d.ts +1 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +120 -102
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +2 -2
- package/dist/gpu-tables/index.cjs.map +2 -2
- package/dist/gpu-tables/table/gpu-table.cjs +2 -2
- package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
- package/dist/gpu-tables/table/gpu-table.js +2 -2
- package/dist/gpu-tables/table/gpu-table.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +17 -6
- package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +3 -2
- package/src/gpu-core/compiled-gpu-graph.ts +18 -0
- package/src/gpu-core/gpu-command-graph.ts +10 -0
- package/src/gpu-core/gpu-expression-plan.ts +6 -0
- package/src/gpu-core/gpu-graph-compiler.ts +61 -0
- package/src/gpu-core/gpu-group-aggregation.ts +38 -50
- package/src/gpu-core/gpu-reduction.ts +32 -42
- package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
- package/src/gpu-core/gpu-shader-pass-kernel.ts +307 -0
- package/src/gpu-core/gpu-shader-pass-operation.ts +103 -0
- package/src/gpu-core/index.ts +8 -0
- package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
- package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
- package/src/gpu-graph/index.ts +9 -0
- package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +59 -5
- package/src/gpu-sql/gpu-sql.ts +130 -103
- package/src/gpu-tables/table/gpu-table.ts +2 -1
- package/src/index.ts +11 -0
|
@@ -38,6 +38,8 @@ import type {GPUGraphOutputs} from '../gpu-core/gpu-texture-plan';
|
|
|
38
38
|
|
|
39
39
|
import {GPUExpressionCastOperation} from './gpu-expression-cast-operation';
|
|
40
40
|
import {GPUExpressionRowOperation} from './gpu-expression-row-operation';
|
|
41
|
+
import {GPUShaderPassOperation} from '../gpu-core/gpu-shader-pass-operation';
|
|
42
|
+
import {GPUShaderPassKernel} from '../gpu-core/gpu-shader-pass-kernel';
|
|
41
43
|
|
|
42
44
|
import {GPUCPUOperation} from '../gpu-core/gpu-cpu-operation';
|
|
43
45
|
import {GPUCPUExecution} from '../gpu-core/gpu-cpu-execution';
|
|
@@ -47,6 +49,7 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
47
49
|
Outputs extends GPUGraphOutputs = Record<string, GPUVector>
|
|
48
50
|
> {
|
|
49
51
|
private readonly program: GPUExpressionProgram;
|
|
52
|
+
private readonly shaderPasses = new Map<GPUShaderPassOperation, GPUShaderPassKernel>();
|
|
50
53
|
private cpuExecution?: GPUCPUExecution;
|
|
51
54
|
private readonly outputLocations: Readonly<Record<string, 'cpu' | 'gpu'>>;
|
|
52
55
|
private running = false;
|
|
@@ -71,12 +74,13 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
71
74
|
operation instanceof GPUCPUOperation ||
|
|
72
75
|
operation instanceof GPUExpressionOperation ||
|
|
73
76
|
operation instanceof GPUUploadOperation ||
|
|
77
|
+
operation instanceof GPUShaderPassOperation ||
|
|
74
78
|
operation instanceof GPUCopyOperation
|
|
75
79
|
)
|
|
76
80
|
)
|
|
77
81
|
)
|
|
78
82
|
throw new Error(
|
|
79
|
-
'SimpleGraph declarative execution supports expression, CPU, upload and
|
|
83
|
+
'SimpleGraph declarative execution supports expression, CPU, upload, copy and shader-pass operations only'
|
|
80
84
|
);
|
|
81
85
|
if (
|
|
82
86
|
this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
|
|
@@ -87,9 +91,20 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
87
91
|
this.program,
|
|
88
92
|
(source, outputs) => new CompiledGPUSimpleExpressionGraph(device, source, {outputs})
|
|
89
93
|
);
|
|
94
|
+
try {
|
|
95
|
+
for (const operation of this.program.operations)
|
|
96
|
+
if (operation instanceof GPUShaderPassOperation)
|
|
97
|
+
this.shaderPasses.set(
|
|
98
|
+
operation,
|
|
99
|
+
new GPUShaderPassKernel(device, operation, this.program)
|
|
100
|
+
);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.destroy();
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
90
105
|
}
|
|
91
106
|
|
|
92
|
-
/** Prepare
|
|
107
|
+
/** Prepare straight-line texture copies and shader passes without submitting work. */
|
|
93
108
|
prepare(
|
|
94
109
|
supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
|
|
95
110
|
options: GPUGraphRunOptions = {}
|
|
@@ -99,13 +114,23 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
99
114
|
!this.program.textures.length ||
|
|
100
115
|
this.program.operations.some(
|
|
101
116
|
operation =>
|
|
102
|
-
!(operation instanceof
|
|
103
|
-
!
|
|
117
|
+
!(operation instanceof GPUShaderPassOperation) &&
|
|
118
|
+
(!(operation instanceof GPUCopyOperation) ||
|
|
119
|
+
!this.program.textures.some(texture => texture.id === operation.input))
|
|
104
120
|
)
|
|
105
121
|
)
|
|
106
|
-
throw new Error(
|
|
122
|
+
throw new Error(
|
|
123
|
+
'SimpleGraph prepare currently supports texture-copy and shader-pass programs only'
|
|
124
|
+
);
|
|
107
125
|
const resolved = this.program.resolveBindings(supplied, options);
|
|
108
126
|
const invocation = this.program.prepare(this.device, resolved.bindings, resolved.options);
|
|
127
|
+
let shaderPasses;
|
|
128
|
+
try {
|
|
129
|
+
shaderPasses = this.prepareShaderPasses(invocation);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
invocation.destroy();
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
109
134
|
let encoded = false;
|
|
110
135
|
let destroyed = false;
|
|
111
136
|
return {
|
|
@@ -114,6 +139,10 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
114
139
|
assert(!this.destroyed && !destroyed && !encoded && encoder.device === this.device);
|
|
115
140
|
encoded = true;
|
|
116
141
|
for (const operation of this.program.operations) {
|
|
142
|
+
if (operation instanceof GPUShaderPassOperation) {
|
|
143
|
+
shaderPasses.get(operation)!.encode(encoder);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
117
146
|
assert(operation instanceof GPUCopyOperation);
|
|
118
147
|
encodeTextureCopy(
|
|
119
148
|
encoder,
|
|
@@ -125,6 +154,7 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
125
154
|
destroy: (): void => {
|
|
126
155
|
if (destroyed) return;
|
|
127
156
|
destroyed = true;
|
|
157
|
+
for (const pass of shaderPasses.values()) pass.destroy();
|
|
128
158
|
invocation.finish();
|
|
129
159
|
}
|
|
130
160
|
};
|
|
@@ -164,14 +194,23 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
164
194
|
const scalarBuffers = new Set<Buffer>();
|
|
165
195
|
let scope: GPUEvaluationScope | undefined;
|
|
166
196
|
let invocation: ReturnType<GPUExpressionProgram['prepare']> | undefined;
|
|
197
|
+
let shaderPasses:
|
|
198
|
+
| ReturnType<CompiledGPUSimpleExpressionGraph['prepareShaderPasses']>
|
|
199
|
+
| undefined;
|
|
167
200
|
try {
|
|
168
201
|
invocation = this.program.prepare(this.device, bindings, options);
|
|
202
|
+
shaderPasses = this.prepareShaderPasses(invocation);
|
|
169
203
|
if (this.device.type === 'webgpu') scope = new GPUEvaluationScope(this.device);
|
|
170
204
|
const retain = (evaluator: GPUDataEvaluator): GPUDataEvaluator => {
|
|
171
205
|
evaluators.add(evaluator);
|
|
172
206
|
return evaluator;
|
|
173
207
|
};
|
|
174
208
|
for (const operation of this.program.operations) {
|
|
209
|
+
if (operation instanceof GPUShaderPassOperation) {
|
|
210
|
+
assert(scope);
|
|
211
|
+
shaderPasses.get(operation)!.encode(scope.commandEncoder);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
175
214
|
if (operation instanceof GPUUploadOperation || operation instanceof GPUCopyOperation) {
|
|
176
215
|
if (
|
|
177
216
|
operation instanceof GPUCopyOperation &&
|
|
@@ -400,6 +439,7 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
400
439
|
invocation?.destroy();
|
|
401
440
|
throw error;
|
|
402
441
|
} finally {
|
|
442
|
+
for (const pass of shaderPasses?.values() ?? []) pass.destroy();
|
|
403
443
|
for (const evaluator of evaluators) evaluator.destroy();
|
|
404
444
|
for (const buffer of scalarBuffers) buffer.destroy();
|
|
405
445
|
this.running = false;
|
|
@@ -410,8 +450,22 @@ export class CompiledGPUSimpleExpressionGraph<
|
|
|
410
450
|
// A running program owns evaluator resources until execution finishes.
|
|
411
451
|
assert(!this.running);
|
|
412
452
|
this.cpuExecution?.destroy();
|
|
453
|
+
for (const kernel of this.shaderPasses.values()) kernel.destroy();
|
|
454
|
+
this.shaderPasses.clear();
|
|
413
455
|
this.destroyed = true;
|
|
414
456
|
}
|
|
457
|
+
|
|
458
|
+
private prepareShaderPasses(invocation: ReturnType<GPUExpressionProgram['prepare']>) {
|
|
459
|
+
const passes = new Map<GPUShaderPassOperation, ReturnType<GPUShaderPassKernel['prepare']>>();
|
|
460
|
+
try {
|
|
461
|
+
for (const [operation, kernel] of this.shaderPasses)
|
|
462
|
+
passes.set(operation, kernel.prepare(invocation.textures!.values, invocation.values));
|
|
463
|
+
return passes;
|
|
464
|
+
} catch (error) {
|
|
465
|
+
for (const pass of passes.values()) pass.destroy();
|
|
466
|
+
throw error;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
415
469
|
}
|
|
416
470
|
|
|
417
471
|
/** Keep graph scalar arithmetic on the GPU with the same float32 boundaries as vectors. */
|
package/src/gpu-sql/gpu-sql.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by relational SQL semantics.
|
|
5
5
|
|
|
6
|
+
import type {Expression} from '@math.gl/core/expressions';
|
|
7
|
+
import {parseSQLExpression} from '@math.gl/core/sql';
|
|
6
8
|
import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
|
|
7
9
|
import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
|
|
8
10
|
import {GPUDataFrameQuery} from '../gpu-dataframe/gpu-data-frame-query';
|
|
@@ -21,7 +23,6 @@ import type {
|
|
|
21
23
|
|
|
22
24
|
const MAXIMUM_SQL_LENGTH = 65_536;
|
|
23
25
|
const MAXIMUM_SQL_TOKENS = 4_096;
|
|
24
|
-
const MAXIMUM_EXPRESSION_DEPTH = 64;
|
|
25
26
|
|
|
26
27
|
/** Explicit GPU dataframe registrations; Arrow remains exclusively an adapter boundary. */
|
|
27
28
|
export type GPUSQLTables = Readonly<Record<string, GPUDataFrame>>;
|
|
@@ -97,7 +98,7 @@ type GPUSQLDynamicQuery = GPUSQLCompiledPlan & {
|
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
|
-
*
|
|
101
|
+
* SQL frontend over explicitly registered, already GPU-resident dataframes.
|
|
101
102
|
*
|
|
102
103
|
* Parsing and planning never upload data, submit work, or read GPU buffers. Arrow upload/output
|
|
103
104
|
* remain explicit `@luma.gl/graph/arrow` operations around the shared GPU table execution core.
|
|
@@ -245,15 +246,14 @@ function buildGPUSQLPlan(
|
|
|
245
246
|
}
|
|
246
247
|
|
|
247
248
|
if (statement.orderBy) {
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
resolve(statement.orderBy.column);
|
|
249
|
+
const {column: requested, direction, nulls} = statement.orderBy;
|
|
250
|
+
const orderColumn = selected.includes(requested) ? requested : resolve(requested);
|
|
251
251
|
if (!selected.includes(orderColumn)) {
|
|
252
252
|
throw new Error('GPUSQL ORDER BY requires the sort column in the SELECT projection');
|
|
253
253
|
}
|
|
254
254
|
const sort = query.select(selected).sortByGlobal(orderColumn, {
|
|
255
|
-
direction
|
|
256
|
-
...(
|
|
255
|
+
direction,
|
|
256
|
+
...(nulls ? {nulls} : {})
|
|
257
257
|
});
|
|
258
258
|
return statement.limit === undefined ? sort : sort.topK(statement.limit);
|
|
259
259
|
}
|
|
@@ -285,9 +285,8 @@ function resolveGPUSQLColumn(name: string, qualifier: string, columns: readonly
|
|
|
285
285
|
throw new Error(`GPUSQL column "${name}" has an unknown table qualifier`);
|
|
286
286
|
}
|
|
287
287
|
const requested = parts[parts.length - 1];
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return matches[0];
|
|
288
|
+
if (!columns.includes(requested)) throw new Error(`GPUSQL column "${name}" does not exist`);
|
|
289
|
+
return requested;
|
|
291
290
|
}
|
|
292
291
|
|
|
293
292
|
function resolveGPUSQLExpression(
|
|
@@ -330,7 +329,7 @@ class GPUSQLParser {
|
|
|
330
329
|
const table = this.parseIdentifier();
|
|
331
330
|
const alias = this.parseOptionalTableAlias();
|
|
332
331
|
const join = this.parseOptionalJoin();
|
|
333
|
-
const predicate = this.takeKeyword('WHERE') ? this.parseExpression(
|
|
332
|
+
const predicate = this.takeKeyword('WHERE') ? this.parseExpression() : undefined;
|
|
334
333
|
let groupBy: string | undefined;
|
|
335
334
|
if (this.takeKeyword('GROUP')) {
|
|
336
335
|
this.expectKeyword('BY');
|
|
@@ -402,7 +401,7 @@ class GPUSQLParser {
|
|
|
402
401
|
...(this.takeKeyword('AS') ? {alias: this.parseIdentifier()} : {})
|
|
403
402
|
};
|
|
404
403
|
}
|
|
405
|
-
const expression = this.parseExpression(
|
|
404
|
+
const expression = this.parseExpression();
|
|
406
405
|
return {
|
|
407
406
|
...(expression ? {expression} : {}),
|
|
408
407
|
...(this.takeKeyword('AS') ? {alias: this.parseIdentifier()} : {})
|
|
@@ -434,67 +433,50 @@ class GPUSQLParser {
|
|
|
434
433
|
return {type, table, ...(alias ? {alias} : {}), left, right};
|
|
435
434
|
}
|
|
436
435
|
|
|
437
|
-
private parseExpression(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
let
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
kind
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
436
|
+
private parseExpression(): GPUExpressionNode {
|
|
437
|
+
const tokens: string[] = [];
|
|
438
|
+
let depth = 0;
|
|
439
|
+
let expectsOperand: boolean = true;
|
|
440
|
+
for (let token = this.peek(); token; token = this.peek()) {
|
|
441
|
+
const value = token.value;
|
|
442
|
+
if (depth === 0) {
|
|
443
|
+
if (token.kind === 'symbol' && (value === ',' || value === ';')) break;
|
|
444
|
+
if (
|
|
445
|
+
token.kind === 'identifier' &&
|
|
446
|
+
!expectsOperand &&
|
|
447
|
+
/^(AS|FROM|GROUP|ORDER|LIMIT)$/i.test(value)
|
|
448
|
+
) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
451
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return expression;
|
|
477
|
-
}
|
|
478
|
-
const token = this.take();
|
|
479
|
-
if (!token) throw new Error('GPUSQL expected an expression');
|
|
480
|
-
if (token.kind === 'number') {
|
|
481
|
-
const value = Number(token.value);
|
|
482
|
-
if (!Number.isFinite(value)) throw new Error('GPUSQL numeric literals must be finite');
|
|
483
|
-
return literal(value).node;
|
|
484
|
-
}
|
|
485
|
-
if (token.kind === 'parameter') {
|
|
486
|
-
if (!Object.hasOwn(this.parameters, token.value)) {
|
|
487
|
-
throw new Error(`GPUSQL parameter ":${token.value}" requires an explicit default`);
|
|
452
|
+
switch (token.kind) {
|
|
453
|
+
case 'parameter':
|
|
454
|
+
// The shared AST leaves parameter binding to the GPU planner.
|
|
455
|
+
tokens.push(`":${value}"`);
|
|
456
|
+
expectsOperand = false;
|
|
457
|
+
break;
|
|
458
|
+
case 'identifier': {
|
|
459
|
+
const operator: boolean =
|
|
460
|
+
/^NOT$/i.test(value) || (!expectsOperand && /^(AND|OR|IS)$/i.test(value));
|
|
461
|
+
const keyword = operator || /^(NULL|TRUE|FALSE)$/i.test(value);
|
|
462
|
+
tokens.push(keyword ? value : `"${value}"`);
|
|
463
|
+
expectsOperand = operator;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
case 'symbol':
|
|
467
|
+
if (value === '(') depth++;
|
|
468
|
+
if (value === ')') depth--;
|
|
469
|
+
tokens.push(value);
|
|
470
|
+
expectsOperand = value !== ')';
|
|
471
|
+
break;
|
|
472
|
+
case 'number':
|
|
473
|
+
tokens.push(value);
|
|
474
|
+
expectsOperand = false;
|
|
475
|
+
break;
|
|
488
476
|
}
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
if (token.kind === 'identifier') {
|
|
492
|
-
if (/^NULL$/i.test(token.value)) return literal(null).node;
|
|
493
|
-
if (/^TRUE$/i.test(token.value)) return literal(true).node;
|
|
494
|
-
if (/^FALSE$/i.test(token.value)) return literal(false).node;
|
|
495
|
-
return column(token.value).node;
|
|
477
|
+
this.take();
|
|
496
478
|
}
|
|
497
|
-
|
|
479
|
+
return lowerSQLExpression(parseSQLExpression(tokens.join(' ')), this.parameters);
|
|
498
480
|
}
|
|
499
481
|
|
|
500
482
|
private parseOptionalTableAlias(): string | undefined {
|
|
@@ -570,39 +552,84 @@ function tokenizeGPUSQL(source: string): GPUSQLToken[] {
|
|
|
570
552
|
return tokens;
|
|
571
553
|
}
|
|
572
554
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
case '
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
555
|
+
const SQL_BINARY_OPERATORS: Readonly<
|
|
556
|
+
Partial<Record<string, Extract<GPUExpressionNode, {kind: 'binary'}>['operator']>>
|
|
557
|
+
> = {
|
|
558
|
+
'||': 'or',
|
|
559
|
+
'&&': 'and',
|
|
560
|
+
'==': 'equal',
|
|
561
|
+
'!=': 'not-equal',
|
|
562
|
+
'>': 'greater-than',
|
|
563
|
+
'>=': 'greater-than-or-equal',
|
|
564
|
+
'<': 'less-than',
|
|
565
|
+
'<=': 'less-than-or-equal',
|
|
566
|
+
'+': 'add',
|
|
567
|
+
'-': 'subtract',
|
|
568
|
+
'*': 'multiply',
|
|
569
|
+
'/': 'divide'
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
function lowerSQLExpression(
|
|
573
|
+
node: Extract<Expression, {type: 'BinaryExpression'}>['left'],
|
|
574
|
+
parameters: GPUDataFrameQueryParameters
|
|
575
|
+
): GPUExpressionNode {
|
|
576
|
+
// math.gl types child nodes as generic expressions, though the SQL parser emits the AST union.
|
|
577
|
+
const expression = node as Expression;
|
|
578
|
+
switch (expression.type) {
|
|
579
|
+
case 'Identifier': {
|
|
580
|
+
if (!expression.name.startsWith(':')) return column(expression.name).node;
|
|
581
|
+
const name = expression.name.slice(1);
|
|
582
|
+
if (!Object.hasOwn(parameters, name)) {
|
|
583
|
+
throw new Error(`GPUSQL parameter ":${name}" requires an explicit default`);
|
|
584
|
+
}
|
|
585
|
+
return parameter(name, parameters[name]).node;
|
|
586
|
+
}
|
|
587
|
+
case 'Literal': {
|
|
588
|
+
const value = expression.value;
|
|
589
|
+
if (
|
|
590
|
+
value === null ||
|
|
591
|
+
typeof value === 'boolean' ||
|
|
592
|
+
(typeof value === 'number' && Number.isFinite(value))
|
|
593
|
+
) {
|
|
594
|
+
return literal(value).node;
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
case 'UnaryExpression':
|
|
599
|
+
if (expression.operator === '!' || expression.operator === '-') {
|
|
600
|
+
return {
|
|
601
|
+
kind: 'unary',
|
|
602
|
+
operator: expression.operator === '!' ? 'not' : 'negate',
|
|
603
|
+
operand: lowerSQLExpression(expression.argument, parameters)
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
break;
|
|
607
|
+
case 'BinaryExpression': {
|
|
608
|
+
const operator = SQL_BINARY_OPERATORS[expression.operator];
|
|
609
|
+
if (operator) {
|
|
610
|
+
return {
|
|
611
|
+
kind: 'binary',
|
|
612
|
+
operator,
|
|
613
|
+
left: lowerSQLExpression(expression.left, parameters),
|
|
614
|
+
right: lowerSQLExpression(expression.right, parameters)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
case 'CallExpression':
|
|
620
|
+
if (
|
|
621
|
+
expression.arguments.length === 1 &&
|
|
622
|
+
(expression.callee['name'] === 'isNull' || expression.callee['name'] === 'isNotNull')
|
|
623
|
+
) {
|
|
624
|
+
return {
|
|
625
|
+
kind: 'unary',
|
|
626
|
+
operator: expression.callee['name'] === 'isNull' ? 'is-null' : 'is-valid',
|
|
627
|
+
operand: lowerSQLExpression(expression.arguments[0], parameters)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
break;
|
|
605
631
|
default:
|
|
606
|
-
|
|
632
|
+
break;
|
|
607
633
|
}
|
|
634
|
+
throw new Error(`GPUSQL does not support SQL expression "${expression.type}"`);
|
|
608
635
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {getGPUDataBufferProps} from '../../gpu-data/gpu-data-buffer-props';
|
|
5
6
|
import {Buffer, type BufferLayout, type VertexFormat} from '@luma.gl/core';
|
|
6
7
|
import {DynamicBuffer} from '@luma.gl/core/dynamic';
|
|
7
8
|
import type {GPUField, GPUSchema, GPUTypeMap} from './gpu-schema';
|
|
@@ -545,7 +546,7 @@ function createPackedGPURecordBatch(
|
|
|
545
546
|
0
|
|
546
547
|
);
|
|
547
548
|
const buffer = device.createBuffer({
|
|
548
|
-
|
|
549
|
+
...getGPUDataBufferProps(device, firstData.format === 'uint16' ? 'uint16' : 'uint32'),
|
|
549
550
|
byteLength
|
|
550
551
|
});
|
|
551
552
|
let destinationOffset = 0;
|
package/src/index.ts
CHANGED
|
@@ -193,6 +193,8 @@ export type {
|
|
|
193
193
|
} from './gpu-core/gpu-operation-contract';
|
|
194
194
|
|
|
195
195
|
export {GPUUploadOperation, GPUCopyOperation} from './gpu-core/gpu-transfer-operation';
|
|
196
|
+
export {GPUShaderPassOperation} from './gpu-core/gpu-shader-pass-operation';
|
|
197
|
+
export type {GPUShaderPassOperationProps} from './gpu-core/gpu-shader-pass-operation';
|
|
196
198
|
export type {
|
|
197
199
|
GPUUploadOperationProps,
|
|
198
200
|
GPUCopyOperationProps
|
|
@@ -214,3 +216,12 @@ export type {
|
|
|
214
216
|
GPUCPUVector,
|
|
215
217
|
GPUCPUResult
|
|
216
218
|
} from './gpu-core/gpu-cpu-operation';
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
GPUGraphGroupAggregation,
|
|
222
|
+
GPUGraphReduction
|
|
223
|
+
} from './gpu-core/gpu-semantic-aggregation-operation';
|
|
224
|
+
export type {
|
|
225
|
+
GPUGraphGroupAggregationProps,
|
|
226
|
+
GPUGraphReductionProps
|
|
227
|
+
} from './gpu-core/gpu-semantic-aggregation-operation';
|