@luma.gl/graph 10.0.0-alpha.14 → 10.0.0-alpha.15
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/arrow/gpu/arrow-column-gpu-vector.cjs +27 -8
- package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts +11 -1
- package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-column-gpu-vector.js +33 -8
- package/dist/arrow/gpu/arrow-column-gpu-vector.js.map +1 -1
- package/dist/arrow/index.cjs +2 -0
- package/dist/arrow/index.cjs.map +1 -1
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/dist.dev.js +79 -39
- package/dist/dist.min.js +61 -61
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/simulation/index.cjs.map +1 -1
- package/dist/geospatial/gpu-point-spatial-query.cjs +2 -15
- package/dist/geospatial/gpu-point-spatial-query.d.ts.map +1 -1
- package/dist/geospatial/gpu-point-spatial-query.js +2 -15
- package/dist/geospatial/gpu-point-spatial-query.js.map +1 -1
- package/dist/geospatial/index.cjs.map +2 -2
- package/dist/gpu-a5/index.cjs.map +1 -1
- package/dist/gpu-core/gpu-command-graph-compiler.cjs +11 -2
- package/dist/gpu-core/gpu-command-graph-compiler.d.ts +2 -1
- package/dist/gpu-core/gpu-command-graph-compiler.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph-compiler.js +13 -2
- package/dist/gpu-core/gpu-command-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph-types.d.ts +16 -1
- package/dist/gpu-core/gpu-command-graph-types.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph-types.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph.cjs +6 -4
- package/dist/gpu-core/gpu-command-graph.d.ts +4 -4
- package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph.js +6 -4
- package/dist/gpu-core/gpu-command-graph.js.map +1 -1
- package/dist/gpu-core/gpu-dispatch-utils.cjs +7 -3
- package/dist/gpu-core/gpu-dispatch-utils.d.ts +2 -0
- package/dist/gpu-core/gpu-dispatch-utils.d.ts.map +1 -1
- package/dist/gpu-core/gpu-dispatch-utils.js +4 -1
- package/dist/gpu-core/gpu-dispatch-utils.js.map +1 -1
- package/dist/gpu-core/gpu-grid-aggregation.cjs +2 -5
- package/dist/gpu-core/gpu-grid-aggregation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-grid-aggregation.js +2 -5
- package/dist/gpu-core/gpu-grid-aggregation.js.map +1 -1
- package/dist/gpu-core/gpu-grid-binning.cjs +2 -5
- package/dist/gpu-core/gpu-grid-binning.d.ts.map +1 -1
- package/dist/gpu-core/gpu-grid-binning.js +2 -5
- package/dist/gpu-core/gpu-grid-binning.js.map +1 -1
- package/dist/gpu-core/gpu-grid-coordinate.cjs +41 -0
- package/dist/gpu-core/gpu-grid-coordinate.d.ts +7 -0
- package/dist/gpu-core/gpu-grid-coordinate.d.ts.map +1 -0
- package/dist/gpu-core/gpu-grid-coordinate.js +24 -0
- package/dist/gpu-core/gpu-grid-coordinate.js.map +1 -0
- package/dist/gpu-core/gpu-grid-index-internals.cjs +2 -15
- package/dist/gpu-core/gpu-grid-index-internals.d.ts.map +1 -1
- package/dist/gpu-core/gpu-grid-index-internals.js +2 -15
- package/dist/gpu-core/gpu-grid-index-internals.js.map +1 -1
- package/dist/gpu-core/gpu-grid-index-query.cjs +2 -16
- package/dist/gpu-core/gpu-grid-index-query.d.ts.map +1 -1
- package/dist/gpu-core/gpu-grid-index-query.js +2 -16
- package/dist/gpu-core/gpu-grid-index-query.js.map +1 -1
- package/dist/gpu-core/gpu-scan.cjs +46 -32
- package/dist/gpu-core/gpu-scan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-scan.js +56 -44
- package/dist/gpu-core/gpu-scan.js.map +1 -1
- package/dist/gpu-core/gpu-segmented-reduction.cjs +12 -9
- package/dist/gpu-core/gpu-segmented-reduction.d.ts +1 -1
- package/dist/gpu-core/gpu-segmented-reduction.d.ts.map +1 -1
- package/dist/gpu-core/gpu-segmented-reduction.js +12 -9
- package/dist/gpu-core/gpu-segmented-reduction.js.map +1 -1
- package/dist/gpu-core/gpu-segmented-scan.cjs +73 -16
- package/dist/gpu-core/gpu-segmented-scan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-segmented-scan.js +73 -16
- package/dist/gpu-core/gpu-segmented-scan.js.map +1 -1
- package/dist/gpu-core/index.cjs +18 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +13 -1
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +6 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-data/gpu-vector-wgsl-layout.cjs +50 -0
- package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts +41 -0
- package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts.map +1 -0
- package/dist/gpu-data/gpu-vector-wgsl-layout.js +45 -0
- package/dist/gpu-data/gpu-vector-wgsl-layout.js.map +1 -0
- package/dist/gpu-data/index.cjs +3 -0
- package/dist/gpu-data/index.cjs.map +2 -2
- package/dist/gpu-data/index.d.ts +1 -0
- package/dist/gpu-data/index.d.ts.map +1 -1
- package/dist/gpu-data/index.js +1 -0
- package/dist/gpu-data/index.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +1 -16
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +1 -23
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +91 -2
- package/dist/gpu-dataframe/gpu-expression.d.ts +37 -0
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +106 -0
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +12 -2
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-dataframe/index.d.ts +4 -0
- package/dist/gpu-dataframe/index.d.ts.map +1 -1
- package/dist/gpu-dataframe/index.js +2 -0
- package/dist/gpu-dataframe/index.js.map +1 -1
- package/dist/gpu-dataframe/portable-expression.cjs +103 -0
- package/dist/gpu-dataframe/portable-expression.d.ts +19 -0
- package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -0
- package/dist/gpu-dataframe/portable-expression.js +98 -0
- package/dist/gpu-dataframe/portable-expression.js.map +1 -0
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-dggs/index.cjs.map +1 -1
- package/dist/gpu-geometry/index.cjs.map +1 -1
- package/dist/gpu-graph/index.cjs.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
- package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.cjs +2 -15
- package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.d.ts.map +1 -1
- package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js +2 -15
- package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js.map +1 -1
- package/dist/gpu-graph-algorithms/index.cjs.map +2 -2
- package/dist/gpu-h3/index.cjs.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +3 -1
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +4 -0
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +3 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +1 -1
- package/dist/gpu-physics/rigid-body-parallel-shaders.cjs +24 -9
- package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-parallel-shaders.js +28 -9
- package/dist/gpu-physics/rigid-body-parallel-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +2 -2
- package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +2 -2
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-pointcloud/index.cjs.map +1 -1
- package/dist/gpu-project/graph.cjs.map +1 -1
- package/dist/gpu-simple-graph/index.cjs.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +97 -4
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +100 -5
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +2 -2
- package/dist/gpu-timeseries/index.cjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/arrow/gpu/arrow-column-gpu-vector.ts +67 -14
- package/src/arrow/index.ts +2 -0
- package/src/geospatial/gpu-point-spatial-query.ts +2 -15
- package/src/gpu-core/gpu-command-graph-compiler.ts +25 -2
- package/src/gpu-core/gpu-command-graph-types.ts +20 -0
- package/src/gpu-core/gpu-command-graph.ts +11 -4
- package/src/gpu-core/gpu-dispatch-utils.ts +13 -1
- package/src/gpu-core/gpu-grid-aggregation.ts +2 -5
- package/src/gpu-core/gpu-grid-binning.ts +2 -5
- package/src/gpu-core/gpu-grid-coordinate.ts +24 -0
- package/src/gpu-core/gpu-grid-index-internals.ts +2 -15
- package/src/gpu-core/gpu-grid-index-query.ts +2 -16
- package/src/gpu-core/gpu-scan.ts +59 -45
- package/src/gpu-core/gpu-segmented-reduction.ts +20 -10
- package/src/gpu-core/gpu-segmented-scan.ts +82 -17
- package/src/gpu-core/index.ts +21 -0
- package/src/gpu-data/gpu-vector-wgsl-layout.ts +79 -0
- package/src/gpu-data/index.ts +7 -0
- package/src/gpu-dataframe/gpu-data-frame-query.ts +6 -26
- package/src/gpu-dataframe/gpu-expression.ts +135 -0
- package/src/gpu-dataframe/index.ts +11 -0
- package/src/gpu-dataframe/portable-expression.ts +117 -0
- package/src/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.ts +2 -15
- package/src/gpu-physics/gpu-rigid-body-world.ts +8 -1
- package/src/gpu-physics/rigid-body-parallel-shaders.ts +32 -9
- package/src/gpu-physics/rigid-body-shaders.ts +3 -2
- package/src/gpu-sql/gpu-sql.ts +105 -5
- package/src/index.ts +2 -0
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
getGPUVectorWGSLLayout,
|
|
8
|
+
type GPUVectorWGSLFormat as GPUExpressionNumericFormat
|
|
9
|
+
} from '@luma.gl/graph/gpu-data';
|
|
10
|
+
|
|
11
|
+
/** Numeric values, including fixed-width vectors. */
|
|
12
|
+
export type GPUExpressionNumericValue = number | readonly number[] | null;
|
|
13
|
+
|
|
6
14
|
/** Portable scalar values accepted by GPU-resident dataframe expressions. */
|
|
7
15
|
export type GPUExpressionValue = number | boolean | null;
|
|
8
16
|
|
|
@@ -26,6 +34,12 @@ export type GPUExpressionBinaryOperator =
|
|
|
26
34
|
|
|
27
35
|
/** Immutable, renderer-independent dataframe expression syntax. */
|
|
28
36
|
export type GPUExpressionNode =
|
|
37
|
+
| Readonly<{
|
|
38
|
+
kind: 'vector';
|
|
39
|
+
format: GPUExpressionNumericFormat;
|
|
40
|
+
components: readonly GPUExpressionNode[];
|
|
41
|
+
}>
|
|
42
|
+
| Readonly<{kind: 'cast'; format: GPUExpressionNumericFormat; operand: GPUExpressionNode}>
|
|
29
43
|
| Readonly<{kind: 'column'; name: string}>
|
|
30
44
|
| Readonly<{kind: 'literal'; value: GPUExpressionValue}>
|
|
31
45
|
| Readonly<{kind: 'parameter'; name: string; value: GPUExpressionValue}>
|
|
@@ -236,6 +250,18 @@ export function getGPUExpressionColumnNames(expression: GPUExpression<any, strin
|
|
|
236
250
|
/** Clones every closed node so caller-owned child objects cannot alter an immutable query plan. */
|
|
237
251
|
function cloneFrozenGPUExpressionNode(node: GPUExpressionNode): GPUExpressionNode {
|
|
238
252
|
switch (node.kind) {
|
|
253
|
+
case 'vector':
|
|
254
|
+
return Object.freeze({
|
|
255
|
+
kind: 'vector',
|
|
256
|
+
format: node.format,
|
|
257
|
+
components: Object.freeze(node.components.map(cloneFrozenGPUExpressionNode))
|
|
258
|
+
});
|
|
259
|
+
case 'cast':
|
|
260
|
+
return Object.freeze({
|
|
261
|
+
kind: 'cast',
|
|
262
|
+
format: node.format,
|
|
263
|
+
operand: cloneFrozenGPUExpressionNode(node.operand)
|
|
264
|
+
});
|
|
239
265
|
case 'column':
|
|
240
266
|
return Object.freeze({kind: 'column', name: node.name});
|
|
241
267
|
case 'literal':
|
|
@@ -262,6 +288,13 @@ function cloneFrozenGPUExpressionNode(node: GPUExpressionNode): GPUExpressionNod
|
|
|
262
288
|
|
|
263
289
|
function collectGPUExpressionColumnNames(node: GPUExpressionNode, columnNames: Set<string>): void {
|
|
264
290
|
switch (node.kind) {
|
|
291
|
+
case 'vector':
|
|
292
|
+
for (const component of node.components)
|
|
293
|
+
collectGPUExpressionColumnNames(component, columnNames);
|
|
294
|
+
break;
|
|
295
|
+
case 'cast':
|
|
296
|
+
collectGPUExpressionColumnNames(node.operand, columnNames);
|
|
297
|
+
break;
|
|
265
298
|
case 'column':
|
|
266
299
|
columnNames.add(node.name);
|
|
267
300
|
break;
|
|
@@ -307,3 +340,105 @@ function assertValidExpressionValue(
|
|
|
307
340
|
throw new Error(`GPUDataFrame ${kind} values must be finite numbers, booleans, or null`);
|
|
308
341
|
}
|
|
309
342
|
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Constructs a fixed-width numeric vector. A null component makes the whole row null.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* const position = vector('float32x3', [column('x'), column('y'), column('z')]);
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
export function vector<Columns extends string>(
|
|
353
|
+
format: GPUExpressionNumericFormat,
|
|
354
|
+
components: readonly GPUExpression<number | null, Columns>[]
|
|
355
|
+
): GPUExpression<readonly number[] | null, Columns> {
|
|
356
|
+
const width = getGPUVectorWGSLLayout(format).components;
|
|
357
|
+
if (![2, 3, 4].includes(width) || components.length !== width)
|
|
358
|
+
throw new Error('Vector width must match its format');
|
|
359
|
+
return new GPUExpression({
|
|
360
|
+
kind: 'vector',
|
|
361
|
+
format,
|
|
362
|
+
components: components.map(component => component.node)
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Converts a numeric expression to the requested format while preserving its width.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* const position = vector('sint32x2', [column('x'), column('y')]);
|
|
372
|
+
* const floatPosition = cast(position, 'float32x2');
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
export function cast<Value extends GPUExpressionNumericValue, Columns extends string>(
|
|
376
|
+
expression: GPUExpression<Value, Columns>,
|
|
377
|
+
format: GPUExpressionNumericFormat
|
|
378
|
+
): GPUExpression<Value, Columns> {
|
|
379
|
+
return new GPUExpression(makeGPUCastNode(expression.node, format));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function makeGPUCastNode<Format extends GPUExpressionNumericFormat>(
|
|
383
|
+
operand: GPUExpressionNode,
|
|
384
|
+
format: Format
|
|
385
|
+
): {kind: 'cast'; format: Format; operand: GPUExpressionNode} {
|
|
386
|
+
const width = getGPUVectorWGSLLayout(format).components;
|
|
387
|
+
const operandWidth = getKnownExpressionWidth(operand);
|
|
388
|
+
if (operandWidth !== undefined && operandWidth !== width) {
|
|
389
|
+
throw new Error('Numeric casts must preserve width');
|
|
390
|
+
}
|
|
391
|
+
return {kind: 'cast', format, operand};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function getKnownExpressionWidth(node: GPUExpressionNode): number | undefined {
|
|
395
|
+
switch (node.kind) {
|
|
396
|
+
case 'vector':
|
|
397
|
+
case 'cast':
|
|
398
|
+
return getGPUVectorWGSLLayout(node.format).components;
|
|
399
|
+
case 'literal':
|
|
400
|
+
case 'parameter':
|
|
401
|
+
return node.value === null ? undefined : 1;
|
|
402
|
+
case 'unary':
|
|
403
|
+
return node.operator === 'negate' ? getKnownExpressionWidth(node.operand) : 1;
|
|
404
|
+
case 'binary': {
|
|
405
|
+
if (isBooleanExpressionNode(node)) {
|
|
406
|
+
return 1;
|
|
407
|
+
}
|
|
408
|
+
const leftWidth = getKnownExpressionWidth(node.left);
|
|
409
|
+
const rightWidth = getKnownExpressionWidth(node.right);
|
|
410
|
+
if (leftWidth !== undefined && rightWidth !== undefined && leftWidth !== rightWidth) {
|
|
411
|
+
throw new Error('Numeric arithmetic requires matching widths');
|
|
412
|
+
}
|
|
413
|
+
return leftWidth ?? rightWidth;
|
|
414
|
+
}
|
|
415
|
+
case 'column':
|
|
416
|
+
return undefined;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Checks whether the expression produces a boolean result. */
|
|
421
|
+
export function isBooleanExpressionNode(node: GPUExpressionNode): boolean {
|
|
422
|
+
switch (node.kind) {
|
|
423
|
+
case 'column':
|
|
424
|
+
return false;
|
|
425
|
+
case 'literal':
|
|
426
|
+
case 'parameter':
|
|
427
|
+
return typeof node.value === 'boolean';
|
|
428
|
+
case 'unary':
|
|
429
|
+
return node.operator === 'not' || node.operator === 'is-valid' || node.operator === 'is-null';
|
|
430
|
+
case 'binary':
|
|
431
|
+
return (
|
|
432
|
+
node.operator === 'equal' ||
|
|
433
|
+
node.operator === 'not-equal' ||
|
|
434
|
+
node.operator === 'greater-than' ||
|
|
435
|
+
node.operator === 'greater-than-or-equal' ||
|
|
436
|
+
node.operator === 'less-than' ||
|
|
437
|
+
node.operator === 'less-than-or-equal' ||
|
|
438
|
+
node.operator === 'and' ||
|
|
439
|
+
node.operator === 'or'
|
|
440
|
+
);
|
|
441
|
+
default:
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
@@ -63,3 +63,14 @@ export {CompiledGPUDataFrameHistogram} from './gpu-histogram-compiler';
|
|
|
63
63
|
export {CompiledGPUDataFrameSort} from './gpu-sort-compiler';
|
|
64
64
|
export {CompiledGPUDataFrameGlobalSort} from './gpu-global-sort-compiler';
|
|
65
65
|
export {CompiledGPUDataFrameJoin, CompiledGPUDataFrameLookup} from './gpu-join-compiler';
|
|
66
|
+
|
|
67
|
+
export {vector, cast} from './gpu-expression';
|
|
68
|
+
export type {GPUExpressionNumericValue} from './gpu-expression';
|
|
69
|
+
export type {
|
|
70
|
+
GPUVectorWGSLFormat as GPUExpressionNumericFormat,
|
|
71
|
+
GPUVectorWGSLScalarFormat as GPUExpressionScalarFormat
|
|
72
|
+
} from '@luma.gl/graph/gpu-data';
|
|
73
|
+
export {
|
|
74
|
+
makeGPUExpressionFromPortableAST,
|
|
75
|
+
makeGPUPredicateFromPortableAST
|
|
76
|
+
} from './portable-expression';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
|
|
5
|
+
|
|
6
|
+
import {validateExpressionAST, type Expression} from '@math.gl/expressions';
|
|
7
|
+
import {
|
|
8
|
+
GPUExpression,
|
|
9
|
+
isBooleanExpressionNode,
|
|
10
|
+
makeGPUCastNode,
|
|
11
|
+
type GPUExpressionNode,
|
|
12
|
+
type GPUExpressionBinaryOperator,
|
|
13
|
+
type GPUExpressionNumericValue
|
|
14
|
+
} from './gpu-expression';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Converts the supported subset of math.gl's portable AST into a DataFrame expression.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import {parseSQLExpression} from '@math.gl/expressions/sql';
|
|
22
|
+
*
|
|
23
|
+
* const position = makeGPUExpressionFromPortableAST(
|
|
24
|
+
* parseSQLExpression('ARRAY[x,y,z]::REAL[3]')
|
|
25
|
+
* );
|
|
26
|
+
* const query = frame.withColumn('position', position, {format: 'float32x3'});
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function makeGPUExpressionFromPortableAST(
|
|
30
|
+
expression: Expression
|
|
31
|
+
): GPUExpression<GPUExpressionNumericValue | boolean> {
|
|
32
|
+
return new GPUExpression(convertPortableExpression(expression));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Converts a portable AST and requires a boolean result for use as a DataFrame predicate. */
|
|
36
|
+
export function makeGPUPredicateFromPortableAST(expression: Expression): GPUExpression<boolean> {
|
|
37
|
+
const node = convertPortableExpression(expression);
|
|
38
|
+
if (!isBooleanExpressionNode(node)) {
|
|
39
|
+
throw new Error('Expected a boolean portable GPU dataframe expression');
|
|
40
|
+
}
|
|
41
|
+
return new GPUExpression(node);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function convertPortableExpression(expression: Expression): GPUExpressionNode {
|
|
45
|
+
validateExpressionAST(expression);
|
|
46
|
+
return convert(expression);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const binaryOperators: Readonly<Record<string, GPUExpressionBinaryOperator>> = {
|
|
50
|
+
'+': 'add',
|
|
51
|
+
'-': 'subtract',
|
|
52
|
+
'*': 'multiply',
|
|
53
|
+
'/': 'divide',
|
|
54
|
+
'==': 'equal',
|
|
55
|
+
'===': 'equal',
|
|
56
|
+
'!=': 'not-equal',
|
|
57
|
+
'!==': 'not-equal',
|
|
58
|
+
'>': 'greater-than',
|
|
59
|
+
'>=': 'greater-than-or-equal',
|
|
60
|
+
'<': 'less-than',
|
|
61
|
+
'<=': 'less-than-or-equal',
|
|
62
|
+
'&&': 'and',
|
|
63
|
+
'||': 'or'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Lowers one validated portable node and rejects unsupported operations. */
|
|
67
|
+
function convert(expression: Expression): GPUExpressionNode {
|
|
68
|
+
// math.gl's public parser type includes nonportable nodes; validation above narrows at runtime.
|
|
69
|
+
const node = expression as any;
|
|
70
|
+
switch (node.type) {
|
|
71
|
+
case 'Identifier':
|
|
72
|
+
return {kind: 'column', name: node.name};
|
|
73
|
+
case 'Literal':
|
|
74
|
+
if (
|
|
75
|
+
node.value === null ||
|
|
76
|
+
typeof node.value === 'boolean' ||
|
|
77
|
+
(typeof node.value === 'number' && Number.isFinite(node.value))
|
|
78
|
+
)
|
|
79
|
+
return {kind: 'literal', value: node.value};
|
|
80
|
+
break;
|
|
81
|
+
case 'UnaryExpression':
|
|
82
|
+
if (node.operator === '-' || node.operator === '!')
|
|
83
|
+
return {
|
|
84
|
+
kind: 'unary',
|
|
85
|
+
operator: node.operator === '-' ? 'negate' : 'not',
|
|
86
|
+
operand: convert(node.argument)
|
|
87
|
+
};
|
|
88
|
+
break;
|
|
89
|
+
case 'BinaryExpression':
|
|
90
|
+
case 'LogicalExpression': {
|
|
91
|
+
const operator = binaryOperators[node.operator];
|
|
92
|
+
if (operator)
|
|
93
|
+
return {kind: 'binary', operator, left: convert(node.left), right: convert(node.right)};
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'CallExpression': {
|
|
97
|
+
const name = node.callee.name;
|
|
98
|
+
if (name === 'array_float32' && [2, 3, 4].includes(node.arguments.length)) {
|
|
99
|
+
return {
|
|
100
|
+
kind: 'vector',
|
|
101
|
+
format: `float32x${node.arguments.length}` as 'float32x2' | 'float32x3' | 'float32x4',
|
|
102
|
+
components: node.arguments.map(convert)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (name === 'cast' && node.arguments.length === 2 && node.arguments[1].type === 'Literal') {
|
|
106
|
+
const target = node.arguments[1].value;
|
|
107
|
+
if (target === 'float32' || target === 'int32')
|
|
108
|
+
return makeGPUCastNode(
|
|
109
|
+
convert(node.arguments[0]),
|
|
110
|
+
target === 'int32' ? 'sint32' : 'float32'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new Error('Unsupported portable GPU dataframe expression');
|
|
117
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuGraph.
|
|
5
5
|
|
|
6
|
+
import {GPU_GRID_COORDINATE_WGSL} from '../gpu-core/gpu-grid-coordinate';
|
|
6
7
|
import {addGPUCommandNodes} from '@luma.gl/graph/gpu-core';
|
|
7
8
|
import {type Binding} from '@luma.gl/core';
|
|
8
9
|
import {Kernel} from '../execution/compute/kernel';
|
|
@@ -423,21 +424,7 @@ const CELL_CENTERS_OFFSET: u32 = ${getViewElementOffset(state.cellCenters)}u;
|
|
|
423
424
|
const VALIDITY_OFFSET: u32 = ${getViewElementOffset(state.validity)}u;
|
|
424
425
|
${getBindingDeclarations(bindings)}
|
|
425
426
|
|
|
426
|
-
|
|
427
|
-
if (maximum == minimum || value == minimum) { return 0u; }
|
|
428
|
-
if (value == maximum) { return size - 1u; }
|
|
429
|
-
if (minimum < 0.0 && maximum > 0.0) {
|
|
430
|
-
let scale = max(abs(minimum), abs(maximum));
|
|
431
|
-
let scaledValue = value / scale;
|
|
432
|
-
let scaledMinimum = minimum / scale;
|
|
433
|
-
let scaledMaximum = maximum / scale;
|
|
434
|
-
return min(
|
|
435
|
-
u32((scaledValue - scaledMinimum) / (scaledMaximum - scaledMinimum) * f32(size)),
|
|
436
|
-
size - 1u
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
return min(u32((value - minimum) / (maximum - minimum) * f32(size)), size - 1u);
|
|
440
|
-
}
|
|
427
|
+
${GPU_GRID_COORDINATE_WGSL}
|
|
441
428
|
|
|
442
429
|
fn readPosition(vertex: u32) -> vec2<f32> {
|
|
443
430
|
let positionOffset = POSITIONS_OFFSET + vertex * 2u;
|
|
@@ -139,6 +139,10 @@ export type GPURigidBodyWorldProps = {
|
|
|
139
139
|
maximumRecoverySpeed?: number;
|
|
140
140
|
/** Additional under-relaxation for the parallel solver, in (0, 1]. Default 1. */
|
|
141
141
|
parallelRelaxation?: number;
|
|
142
|
+
/** Contact scheduling within a parallel manifold. Block uses two local sweeps before gathering.
|
|
143
|
+
* Default scalar preserves the original per-contact relaxation path.
|
|
144
|
+
*/
|
|
145
|
+
parallelContactSolver?: 'scalar' | 'block';
|
|
142
146
|
/** Small worlds retain the all-pairs numerical oracle; larger worlds use sparse discovery. */
|
|
143
147
|
/** Independent equal collider blocks; currently excludes joints, CCD and authored triggers. */
|
|
144
148
|
collisionPartitionSize?: number;
|
|
@@ -271,6 +275,8 @@ export class GPURigidBodyWorld {
|
|
|
271
275
|
this.solver = props.solver ?? 'ordered';
|
|
272
276
|
if (!['ordered', 'parallel'].includes(this.solver))
|
|
273
277
|
throw new Error('Invalid rigid-body solver');
|
|
278
|
+
if (!['scalar', 'block'].includes(props.parallelContactSolver ?? 'scalar'))
|
|
279
|
+
throw new Error('Invalid parallel contact solver');
|
|
274
280
|
validateRigidBodyJoints(props.joints ?? [], props.bodies, this.solver);
|
|
275
281
|
const colliderCount = props.bodies.reduce(
|
|
276
282
|
(sum, body) => sum + (body.colliders?.length ?? 1),
|
|
@@ -1043,7 +1049,8 @@ export class GPURigidBodyWorld {
|
|
|
1043
1049
|
this.props.joints?.length ?? 0,
|
|
1044
1050
|
this.props.compactContacts ?? true,
|
|
1045
1051
|
this.props.collisionPartitionSize,
|
|
1046
|
-
this.props.ensembleBodiesPerInstance
|
|
1052
|
+
this.props.ensembleBodiesPerInstance,
|
|
1053
|
+
this.props.parallelContactSolver === 'block'
|
|
1047
1054
|
);
|
|
1048
1055
|
const parallelBindings: Record<string, readonly string[]> = {
|
|
1049
1056
|
parallelReset: ['parallelState'],
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/** Sparse contact adjacency and block-Jacobi impulses; each dispatch has exclusive output owners. */
|
|
6
|
-
export function getRigidBodyParallelShader(ensemble: boolean): string {
|
|
6
|
+
export function getRigidBodyParallelShader(ensemble: boolean, blockContacts = false): string {
|
|
7
7
|
return /* wgsl */ `
|
|
8
8
|
struct ParallelState {
|
|
9
9
|
diagnostics:array<atomic<u32>,4>,
|
|
@@ -173,32 +173,55 @@ fn writePairDeltas(pair:u32,first:u32,second:u32,impulse:vec3f,firstTorque:vec3f
|
|
|
173
173
|
let relaxation=settings.stability.w/f32(max(1u,max(atomicLoad(¶llelState.degrees[first]),atomicLoad(¶llelState.degrees[second]))));
|
|
174
174
|
var firstLinear=velocities[first].xyz;var secondLinear=velocities[second].xyz;
|
|
175
175
|
var firstAngular=angularVelocities[first].xyz;var secondAngular=angularVelocities[second].xyz;
|
|
176
|
+
${
|
|
177
|
+
blockContacts
|
|
178
|
+
? `
|
|
179
|
+
// Solve the contact patch locally, then relax the whole block once. No extra dispatches.
|
|
180
|
+
var contacts:array<Contact,4>;
|
|
181
|
+
for(var slot=0u;slot<manifolds[pair].count;slot++){contacts[slot]=manifolds[pair].contacts[slot];}
|
|
182
|
+
for(var sweep=0u;sweep<2u;sweep++){
|
|
183
|
+
`
|
|
184
|
+
: ''
|
|
185
|
+
}
|
|
176
186
|
for(var slot=0u;slot<manifolds[pair].count;slot++){
|
|
177
|
-
var contact
|
|
187
|
+
var contact=${blockContacts ? 'contacts[slot]' : 'manifolds[pair].contacts[slot]'};let point=contact.point.xyz;let normal=contact.normal.xyz;
|
|
178
188
|
let firstLever=point-positions[first].xyz;let secondLever=point-positions[second].xyz;
|
|
179
189
|
let relative=secondLinear+cross(secondAngular,secondLever)-firstLinear-cross(firstAngular,firstLever);
|
|
180
190
|
let normalMass=effectiveMass(first,second,point,normal);if(normalMass<=0.0){continue;}
|
|
181
191
|
let bias=min(settings.stability.z,settings.stability.y*max(0.0,contact.point.w-settings.solver.x)/settings.gravity.w);
|
|
182
192
|
let desiredImpulse=max(0.0,contact.impulse.x+(max(bias,contact.normal.w)-dot(relative,normal))/normalMass);
|
|
183
|
-
let change=(desiredImpulse-contact.impulse.x)
|
|
193
|
+
let change=(desiredImpulse-contact.impulse.x)*${blockContacts ? '1.0' : 'relaxation'};contact.impulse.x+=change;
|
|
184
194
|
var impulse=normal*change;
|
|
185
195
|
if(dynamic(first)){firstLinear-=impulse*velocities[first].w;firstAngular-=inverseInertia(first,cross(firstLever,impulse));}
|
|
186
196
|
if(dynamic(second)){secondLinear+=impulse*velocities[second].w;secondAngular+=inverseInertia(second,cross(secondLever,impulse));}
|
|
187
197
|
let after=secondLinear+cross(secondAngular,secondLever)-firstLinear-cross(firstAngular,firstLever);
|
|
188
198
|
let tangent=solveFriction(firstCollider,secondCollider,contact,after);
|
|
189
|
-
var relaxedTangent=contact.tangent.xyz+(tangent-contact.tangent.xyz)
|
|
199
|
+
var relaxedTangent=contact.tangent.xyz+(tangent-contact.tangent.xyz)*${blockContacts ? '1.0' : 'relaxation'};
|
|
190
200
|
// A falling normal impulse must shrink the cone even when under-relaxing.
|
|
191
201
|
let staticLimit=frictionCoefficient(firstCollider,secondCollider,false)*contact.impulse.x;
|
|
192
202
|
if(length(relaxedTangent)>staticLimit){relaxedTangent*=staticLimit/max(1e-30,length(relaxedTangent));}
|
|
193
203
|
impulse=relaxedTangent-contact.tangent.xyz;contact.tangent=vec4f(relaxedTangent,0);
|
|
194
204
|
if(dynamic(first)){firstLinear-=impulse*velocities[first].w;firstAngular-=inverseInertia(first,cross(firstLever,impulse));}
|
|
195
205
|
if(dynamic(second)){secondLinear+=impulse*velocities[second].w;secondAngular+=inverseInertia(second,cross(secondLever,impulse));}
|
|
196
|
-
manifolds[pair].contacts[slot]=contact;
|
|
206
|
+
${blockContacts ? 'contacts[slot]' : 'manifolds[pair].contacts[slot]'}=contact;
|
|
207
|
+
}
|
|
208
|
+
${
|
|
209
|
+
blockContacts
|
|
210
|
+
? `
|
|
211
|
+
}
|
|
212
|
+
// Interpolation of feasible impulses preserves the friction cone, including unloading.
|
|
213
|
+
for(var slot=0u;slot<manifolds[pair].count;slot++){
|
|
214
|
+
let previous=manifolds[pair].contacts[slot];
|
|
215
|
+
manifolds[pair].contacts[slot].impulse.x=mix(previous.impulse.x,contacts[slot].impulse.x,relaxation);
|
|
216
|
+
manifolds[pair].contacts[slot].tangent=mix(previous.tangent,contacts[slot].tangent,relaxation);
|
|
217
|
+
}
|
|
218
|
+
`
|
|
219
|
+
: ''
|
|
197
220
|
}
|
|
198
|
-
parallelState.deltas[pair*4u]=vec4f(firstLinear-velocities[first].xyz,0);
|
|
199
|
-
parallelState.deltas[pair*4u+1u]=vec4f(firstAngular-angularVelocities[first].xyz,0);
|
|
200
|
-
parallelState.deltas[pair*4u+2u]=vec4f(secondLinear-velocities[second].xyz,0);
|
|
201
|
-
parallelState.deltas[pair*4u+3u]=vec4f(secondAngular-angularVelocities[second].xyz,0);
|
|
221
|
+
parallelState.deltas[pair*4u]=vec4f((firstLinear-velocities[first].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
|
|
222
|
+
parallelState.deltas[pair*4u+1u]=vec4f((firstAngular-angularVelocities[first].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
|
|
223
|
+
parallelState.deltas[pair*4u+2u]=vec4f((secondLinear-velocities[second].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
|
|
224
|
+
parallelState.deltas[pair*4u+3u]=vec4f((secondAngular-angularVelocities[second].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
|
|
202
225
|
}
|
|
203
226
|
@compute @workgroup_size(64) fn parallelGather(@builtin(global_invocation_id) invocation:vec3u){
|
|
204
227
|
var body=invocation.x;
|
|
@@ -29,7 +29,8 @@ export function getRigidBodyShader(
|
|
|
29
29
|
jointCount = 0,
|
|
30
30
|
compactContacts = true,
|
|
31
31
|
collisionPartitionSize?: number,
|
|
32
|
-
ensembleBodiesPerInstance?: number
|
|
32
|
+
ensembleBodiesPerInstance?: number,
|
|
33
|
+
blockContacts = false
|
|
33
34
|
): string {
|
|
34
35
|
return /* wgsl */ `
|
|
35
36
|
const COMPACT_CONTACTS:bool=${compactContacts};
|
|
@@ -390,7 +391,7 @@ ${
|
|
|
390
391
|
}
|
|
391
392
|
manifolds[pair].count=contactCount;
|
|
392
393
|
}
|
|
393
|
-
${parallel ? getRigidBodyParallelShader(Boolean(ensembleBodiesPerInstance)) : ''}
|
|
394
|
+
${parallel ? getRigidBodyParallelShader(Boolean(ensembleBodiesPerInstance), blockContacts) : ''}
|
|
394
395
|
${(parallel || hasJoints) && extended ? '@compute @workgroup_size(1) fn meshCollect(){collectMeshContacts();}' : ''}
|
|
395
396
|
${jointShader}
|
|
396
397
|
${parallel && hasJoints ? '@compute @workgroup_size(1) fn parallelJointWarm(){solveJoints(true);} @compute @workgroup_size(1) fn parallelJointSolve(){solveJoints(false);}' : ''}
|
package/src/gpu-sql/gpu-sql.ts
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
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 {
|
|
6
|
+
import {
|
|
7
|
+
parseSQLExpression,
|
|
8
|
+
parseSQLSelectStatement,
|
|
9
|
+
SQLParseError,
|
|
10
|
+
type SQLSelectStatement
|
|
11
|
+
} from '@math.gl/expressions/sql';
|
|
7
12
|
import type {Expression} from '@math.gl/expressions';
|
|
8
13
|
import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
|
|
9
14
|
import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
|
|
@@ -122,8 +127,7 @@ export class GPUSQLContext {
|
|
|
122
127
|
|
|
123
128
|
/** Parses and validates one immutable SELECT plan without touching registered GPU sources. */
|
|
124
129
|
query(source: string, options: GPUSQLQueryOptions = {}): GPUSQLQuery {
|
|
125
|
-
const
|
|
126
|
-
const statement = parser.parse();
|
|
130
|
+
const statement = parseGPUSQLStatement(source, options.parameters ?? {});
|
|
127
131
|
return new GPUSQLQuery(source, buildGPUSQLPlan(this.tables, statement));
|
|
128
132
|
}
|
|
129
133
|
}
|
|
@@ -309,13 +313,107 @@ function resolveGPUSQLExpression(
|
|
|
309
313
|
}
|
|
310
314
|
}
|
|
311
315
|
|
|
316
|
+
function parseGPUSQLStatement(
|
|
317
|
+
source: string,
|
|
318
|
+
parameters: GPUDataFrameQueryParameters
|
|
319
|
+
): GPUSQLStatement {
|
|
320
|
+
// Preserve GPUSQL's lexical limits and accepted input tokens.
|
|
321
|
+
const tokens = tokenizeGPUSQL(source);
|
|
322
|
+
let statement: SQLSelectStatement;
|
|
323
|
+
try {
|
|
324
|
+
statement = parseSQLSelectStatement(source, {
|
|
325
|
+
parseParameter: name => ({type: 'Identifier', name: `:${name}`})
|
|
326
|
+
});
|
|
327
|
+
} catch (error) {
|
|
328
|
+
// Older GPUSQL queries permit unquoted keyword-named columns, such as "limit".
|
|
329
|
+
if (!(error instanceof SQLParseError)) throw error;
|
|
330
|
+
return new GPUSQLParser(tokens, parameters).parse();
|
|
331
|
+
}
|
|
332
|
+
if (statement.offset !== undefined) throw new Error('GPUSQL does not support OFFSET');
|
|
333
|
+
if (statement.joins.length > 1) throw new Error('GPUSQL currently supports one JOIN');
|
|
334
|
+
if ((statement.groupBy?.length ?? 0) > 1) {
|
|
335
|
+
throw new Error('GPUSQL currently supports one GROUP BY column');
|
|
336
|
+
}
|
|
337
|
+
if ((statement.orderBy?.length ?? 0) > 1) {
|
|
338
|
+
throw new Error('GPUSQL currently supports one ORDER BY column');
|
|
339
|
+
}
|
|
340
|
+
if (statement.limit !== undefined && statement.limit > 0xffffffff) {
|
|
341
|
+
throw new Error('GPUSQL LIMIT must fit an unsigned 32-bit row count');
|
|
342
|
+
}
|
|
343
|
+
const items: GPUSQLSelectItem[] = statement.select?.map(({expression, alias}) => {
|
|
344
|
+
if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier') {
|
|
345
|
+
const name = String(expression.callee['name']).toLowerCase();
|
|
346
|
+
const aggregate = name === 'avg' ? 'mean' : name;
|
|
347
|
+
switch (aggregate) {
|
|
348
|
+
case 'count':
|
|
349
|
+
case 'sum':
|
|
350
|
+
case 'min':
|
|
351
|
+
case 'max':
|
|
352
|
+
case 'mean': {
|
|
353
|
+
if (expression.arguments.length !== 1) {
|
|
354
|
+
throw new Error('GPUSQL aggregates require one argument');
|
|
355
|
+
}
|
|
356
|
+
const argument = readGPUSQLColumn(expression.arguments[0]);
|
|
357
|
+
if ((aggregate === 'count') !== (argument === '*')) {
|
|
358
|
+
throw new Error('GPUSQL only permits COUNT(*) as a wildcard aggregation');
|
|
359
|
+
}
|
|
360
|
+
return {aggregate, ...(argument !== '*' ? {aggregateColumn: argument} : {}), alias};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return {expression: lowerSQLExpression(expression, parameters), alias};
|
|
365
|
+
}) ?? [{star: true}];
|
|
366
|
+
const join = statement.joins[0];
|
|
367
|
+
let loweredJoin: GPUSQLStatement['join'];
|
|
368
|
+
if (join) {
|
|
369
|
+
if (join.on.type !== 'BinaryExpression' || join.on.operator !== '==') {
|
|
370
|
+
throw new Error('GPUSQL JOIN requires equality between two columns');
|
|
371
|
+
}
|
|
372
|
+
loweredJoin = {
|
|
373
|
+
type: join.type,
|
|
374
|
+
table: join.table.name,
|
|
375
|
+
alias: join.table.alias,
|
|
376
|
+
left: readGPUSQLColumn(join.on.left),
|
|
377
|
+
right: readGPUSQLColumn(join.on.right)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
const sort = statement.orderBy?.[0];
|
|
381
|
+
return {
|
|
382
|
+
items,
|
|
383
|
+
table: statement.from.name,
|
|
384
|
+
alias: statement.from.alias,
|
|
385
|
+
join: loweredJoin,
|
|
386
|
+
predicate: statement.where && lowerSQLExpression(statement.where, parameters),
|
|
387
|
+
groupBy: statement.groupBy?.[0] && readGPUSQLColumn(statement.groupBy[0]),
|
|
388
|
+
orderBy: sort && {
|
|
389
|
+
column: readGPUSQLColumn(sort.expression),
|
|
390
|
+
direction: sort.direction === 'desc' ? 'descending' : 'ascending',
|
|
391
|
+
nulls: sort.nulls
|
|
392
|
+
},
|
|
393
|
+
limit: statement.limit
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function readGPUSQLColumn(node: Extract<Expression, {type: 'BinaryExpression'}>['left']): string {
|
|
398
|
+
const expression = node as Expression;
|
|
399
|
+
if (expression.type === 'Identifier' && !expression.name.startsWith(':')) return expression.name;
|
|
400
|
+
if (expression.type === 'MemberExpression' && !expression.computed) {
|
|
401
|
+
const object = expression.object as Expression;
|
|
402
|
+
const property = expression.property as Expression;
|
|
403
|
+
if (object.type === 'Identifier' && property.type === 'Identifier') {
|
|
404
|
+
return `${object.name}.${property.name}`;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
throw new Error('GPUSQL expected a table or column identifier');
|
|
408
|
+
}
|
|
409
|
+
|
|
312
410
|
class GPUSQLParser {
|
|
313
411
|
private readonly tokens: readonly GPUSQLToken[];
|
|
314
412
|
private readonly parameters: GPUDataFrameQueryParameters;
|
|
315
413
|
private position = 0;
|
|
316
414
|
|
|
317
|
-
constructor(
|
|
318
|
-
this.tokens =
|
|
415
|
+
constructor(tokens: readonly GPUSQLToken[], parameters: GPUDataFrameQueryParameters) {
|
|
416
|
+
this.tokens = tokens;
|
|
319
417
|
this.parameters = parameters;
|
|
320
418
|
}
|
|
321
419
|
|
|
@@ -584,6 +682,8 @@ function lowerSQLExpression(
|
|
|
584
682
|
}
|
|
585
683
|
return parameter(name, parameters[name]).node;
|
|
586
684
|
}
|
|
685
|
+
case 'MemberExpression':
|
|
686
|
+
return column(readGPUSQLColumn(expression)).node;
|
|
587
687
|
case 'Literal': {
|
|
588
688
|
const value = expression.value;
|
|
589
689
|
if (
|
package/src/index.ts
CHANGED
|
@@ -53,6 +53,8 @@ export {
|
|
|
53
53
|
type GPUCommandGraphNodeConditionPreflight,
|
|
54
54
|
type GPUCommandGraphNodeEncodingStats,
|
|
55
55
|
type GPUCommandGraphNodePreflight,
|
|
56
|
+
type GPUCommandGraphCompileOptions,
|
|
57
|
+
type GPUCommandGraphKernelMetadata,
|
|
56
58
|
type GPUCommandGraphResourceSummary,
|
|
57
59
|
type GPUCommandGraphNodePublication,
|
|
58
60
|
type GPUCommandGraphNodeTiming,
|