@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.
Files changed (131) hide show
  1. package/LICENSE +4 -4
  2. package/THIRD-PARTY-NOTICES.md +19 -0
  3. package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +6 -6
  4. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
  5. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +16 -6
  6. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
  7. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +3 -2
  8. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  9. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +3 -2
  10. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  11. package/dist/arrow/index.cjs.map +2 -2
  12. package/dist/arrow/internal.cjs.map +2 -2
  13. package/dist/dist.dev.js +2148 -454
  14. package/dist/dist.min.js +437 -123
  15. package/dist/experimental/index.cjs.map +1 -1
  16. package/dist/experimental/simulation/index.cjs.map +1 -1
  17. package/dist/gpu-core/compiled-gpu-graph.cjs +15 -0
  18. package/dist/gpu-core/compiled-gpu-graph.d.ts +1 -0
  19. package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
  20. package/dist/gpu-core/compiled-gpu-graph.js +15 -0
  21. package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
  22. package/dist/gpu-core/gpu-command-graph.cjs +9 -0
  23. package/dist/gpu-core/gpu-command-graph.d.ts +2 -0
  24. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  25. package/dist/gpu-core/gpu-command-graph.js +9 -0
  26. package/dist/gpu-core/gpu-command-graph.js.map +1 -1
  27. package/dist/gpu-core/gpu-expression-plan.cjs +4 -0
  28. package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
  29. package/dist/gpu-core/gpu-expression-plan.js +5 -0
  30. package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
  31. package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
  32. package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
  33. package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
  34. package/dist/gpu-core/gpu-graph-compiler.js +50 -0
  35. package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
  36. package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
  37. package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
  38. package/dist/gpu-core/gpu-group-aggregation.js +7 -18
  39. package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
  40. package/dist/gpu-core/gpu-reduction.cjs +6 -14
  41. package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
  42. package/dist/gpu-core/gpu-reduction.js +6 -15
  43. package/dist/gpu-core/gpu-reduction.js.map +1 -1
  44. package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
  45. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
  46. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
  47. package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
  48. package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
  49. package/dist/gpu-core/gpu-shader-pass-kernel.cjs +267 -0
  50. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts +29 -0
  51. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts.map +1 -0
  52. package/dist/gpu-core/gpu-shader-pass-kernel.js +260 -0
  53. package/dist/gpu-core/gpu-shader-pass-kernel.js.map +1 -0
  54. package/dist/gpu-core/gpu-shader-pass-operation.cjs +85 -0
  55. package/dist/gpu-core/gpu-shader-pass-operation.d.ts +32 -0
  56. package/dist/gpu-core/gpu-shader-pass-operation.d.ts.map +1 -0
  57. package/dist/gpu-core/gpu-shader-pass-operation.js +74 -0
  58. package/dist/gpu-core/gpu-shader-pass-operation.js.map +1 -0
  59. package/dist/gpu-core/index.cjs +8 -0
  60. package/dist/gpu-core/index.cjs.map +3 -3
  61. package/dist/gpu-core/index.d.ts +4 -0
  62. package/dist/gpu-core/index.d.ts.map +1 -1
  63. package/dist/gpu-core/index.js +2 -0
  64. package/dist/gpu-core/index.js.map +1 -1
  65. package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
  66. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
  67. package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
  68. package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
  69. package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
  70. package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
  71. package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
  72. package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
  73. package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
  74. package/dist/gpu-data/index.cjs.map +3 -3
  75. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  76. package/dist/gpu-graph/index.cjs +5 -0
  77. package/dist/gpu-graph/index.cjs.map +3 -3
  78. package/dist/gpu-graph/index.d.ts +2 -0
  79. package/dist/gpu-graph/index.d.ts.map +1 -1
  80. package/dist/gpu-graph/index.js +1 -0
  81. package/dist/gpu-graph/index.js.map +1 -1
  82. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  83. package/dist/gpu-graph-algorithms/index.cjs.map +1 -1
  84. package/dist/gpu-physics/index.cjs.map +1 -1
  85. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  86. package/dist/gpu-project/crs.cjs.map +2 -2
  87. package/dist/gpu-project/graph.cjs.map +3 -3
  88. package/dist/gpu-project/index.cjs.map +2 -2
  89. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +53 -5
  90. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +3 -1
  91. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
  92. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +58 -5
  93. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
  94. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  95. package/dist/gpu-sql/gpu-sql.cjs +112 -100
  96. package/dist/gpu-sql/gpu-sql.d.ts +1 -1
  97. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  98. package/dist/gpu-sql/gpu-sql.js +120 -102
  99. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  100. package/dist/gpu-sql/index.cjs.map +2 -2
  101. package/dist/gpu-tables/index.cjs.map +2 -2
  102. package/dist/gpu-tables/table/gpu-table.cjs +2 -2
  103. package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
  104. package/dist/gpu-tables/table/gpu-table.js +2 -2
  105. package/dist/gpu-tables/table/gpu-table.js.map +1 -1
  106. package/dist/index.cjs +8 -0
  107. package/dist/index.cjs.map +3 -3
  108. package/dist/index.d.ts +4 -0
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +2 -0
  111. package/dist/index.js.map +1 -1
  112. package/package.json +10 -8
  113. package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +17 -6
  114. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +3 -2
  115. package/src/gpu-core/compiled-gpu-graph.ts +18 -0
  116. package/src/gpu-core/gpu-command-graph.ts +10 -0
  117. package/src/gpu-core/gpu-expression-plan.ts +6 -0
  118. package/src/gpu-core/gpu-graph-compiler.ts +61 -0
  119. package/src/gpu-core/gpu-group-aggregation.ts +38 -50
  120. package/src/gpu-core/gpu-reduction.ts +32 -42
  121. package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
  122. package/src/gpu-core/gpu-shader-pass-kernel.ts +307 -0
  123. package/src/gpu-core/gpu-shader-pass-operation.ts +103 -0
  124. package/src/gpu-core/index.ts +8 -0
  125. package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
  126. package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
  127. package/src/gpu-graph/index.ts +9 -0
  128. package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +59 -5
  129. package/src/gpu-sql/gpu-sql.ts +130 -103
  130. package/src/gpu-tables/table/gpu-table.ts +2 -1
  131. 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 copy operations only'
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 a straight-line texture-copy program without submitting work. */
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 GPUCopyOperation) ||
103
- !this.program.textures.some(texture => texture.id === operation.input)
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('SimpleGraph prepare currently supports texture-copy programs only');
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. */
@@ -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
- * Dependency-free SQL frontend over explicitly registered, already GPU-resident dataframes.
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 orderColumn =
249
- selected.find(name => name.toLowerCase() === statement.orderBy!.column.toLowerCase()) ??
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: statement.orderBy.direction,
256
- ...(statement.orderBy.nulls ? {nulls: statement.orderBy.nulls} : {})
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
- const matches = columns.filter(candidate => candidate.toLowerCase() === requested.toLowerCase());
289
- if (matches.length !== 1) throw new Error(`GPUSQL column "${name}" does not exist`);
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(0) : undefined;
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(0);
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(depth: number, minimumPrecedence = 0): GPUExpressionNode {
438
- if (depth > MAXIMUM_EXPRESSION_DEPTH)
439
- throw new Error('GPUSQL expression nesting exceeds its safe limit');
440
- let expression = this.parseUnary(depth + 1);
441
- while (true) {
442
- if (minimumPrecedence <= 3 && this.takeKeyword('IS')) {
443
- const negated = this.takeKeyword('NOT');
444
- this.expectKeyword('NULL');
445
- expression = {
446
- kind: 'unary',
447
- operator: negated ? 'is-valid' : 'is-null',
448
- operand: expression
449
- };
450
- continue;
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
- const token = this.peek();
453
- const operation = token ? getGPUSQLBinaryOperator(token.value) : undefined;
454
- if (!operation || operation.precedence < minimumPrecedence) break;
455
- this.take();
456
- expression = {
457
- kind: 'binary',
458
- operator: operation.operator,
459
- left: expression,
460
- right: this.parseExpression(depth + 1, operation.precedence + 1)
461
- };
462
- }
463
- return expression;
464
- }
465
-
466
- private parseUnary(depth: number): GPUExpressionNode {
467
- if (this.takeKeyword('NOT')) {
468
- return {kind: 'unary', operator: 'not', operand: this.parseExpression(depth, 3)};
469
- }
470
- if (this.takeSymbol('-')) {
471
- return {kind: 'unary', operator: 'negate', operand: this.parseUnary(depth + 1)};
472
- }
473
- if (this.takeSymbol('(')) {
474
- const expression = this.parseExpression(depth + 1);
475
- this.expectSymbol(')');
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
- return parameter(token.value, this.parameters[token.value]).node;
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
- throw new Error(`GPUSQL does not support expression token "${token.value}"`);
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
- function getGPUSQLBinaryOperator(value: string):
574
- | Readonly<{
575
- operator: Extract<GPUExpressionNode, {kind: 'binary'}>['operator'];
576
- precedence: number;
577
- }>
578
- | undefined {
579
- switch (value.toUpperCase()) {
580
- case 'OR':
581
- return {operator: 'or', precedence: 1};
582
- case 'AND':
583
- return {operator: 'and', precedence: 2};
584
- case '=':
585
- return {operator: 'equal', precedence: 3};
586
- case '!=':
587
- case '<>':
588
- return {operator: 'not-equal', precedence: 3};
589
- case '>':
590
- return {operator: 'greater-than', precedence: 3};
591
- case '>=':
592
- return {operator: 'greater-than-or-equal', precedence: 3};
593
- case '<':
594
- return {operator: 'less-than', precedence: 3};
595
- case '<=':
596
- return {operator: 'less-than-or-equal', precedence: 3};
597
- case '+':
598
- return {operator: 'add', precedence: 4};
599
- case '-':
600
- return {operator: 'subtract', precedence: 4};
601
- case '*':
602
- return {operator: 'multiply', precedence: 5};
603
- case '/':
604
- return {operator: 'divide', precedence: 5};
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
- return undefined;
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
- usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC,
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';