@luma.gl/graph 10.0.0-alpha.12 → 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 (92) 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 +1539 -211
  14. package/dist/dist.min.js +401 -105
  15. package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
  16. package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
  17. package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
  18. package/dist/gpu-core/gpu-graph-compiler.js +50 -0
  19. package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
  20. package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
  21. package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
  22. package/dist/gpu-core/gpu-group-aggregation.js +7 -18
  23. package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
  24. package/dist/gpu-core/gpu-reduction.cjs +6 -14
  25. package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
  26. package/dist/gpu-core/gpu-reduction.js +6 -15
  27. package/dist/gpu-core/gpu-reduction.js.map +1 -1
  28. package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
  29. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
  30. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
  31. package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
  32. package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
  33. package/dist/gpu-core/index.cjs +5 -0
  34. package/dist/gpu-core/index.cjs.map +3 -3
  35. package/dist/gpu-core/index.d.ts +2 -0
  36. package/dist/gpu-core/index.d.ts.map +1 -1
  37. package/dist/gpu-core/index.js +1 -0
  38. package/dist/gpu-core/index.js.map +1 -1
  39. package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
  40. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
  41. package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
  42. package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
  43. package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
  44. package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
  45. package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
  46. package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
  47. package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
  48. package/dist/gpu-data/index.cjs.map +3 -3
  49. package/dist/gpu-graph/index.cjs +5 -0
  50. package/dist/gpu-graph/index.cjs.map +3 -3
  51. package/dist/gpu-graph/index.d.ts +2 -0
  52. package/dist/gpu-graph/index.d.ts.map +1 -1
  53. package/dist/gpu-graph/index.js +1 -0
  54. package/dist/gpu-graph/index.js.map +1 -1
  55. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  56. package/dist/gpu-graph-algorithms/index.cjs.map +1 -1
  57. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  58. package/dist/gpu-project/crs.cjs.map +2 -2
  59. package/dist/gpu-project/graph.cjs.map +3 -3
  60. package/dist/gpu-project/index.cjs.map +2 -2
  61. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  62. package/dist/gpu-sql/gpu-sql.cjs +112 -100
  63. package/dist/gpu-sql/gpu-sql.d.ts +1 -1
  64. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  65. package/dist/gpu-sql/gpu-sql.js +120 -102
  66. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  67. package/dist/gpu-sql/index.cjs.map +2 -2
  68. package/dist/gpu-tables/index.cjs.map +2 -2
  69. package/dist/gpu-tables/table/gpu-table.cjs +2 -2
  70. package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
  71. package/dist/gpu-tables/table/gpu-table.js +2 -2
  72. package/dist/gpu-tables/table/gpu-table.js.map +1 -1
  73. package/dist/index.cjs +5 -0
  74. package/dist/index.cjs.map +3 -3
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +1 -0
  78. package/dist/index.js.map +1 -1
  79. package/package.json +10 -8
  80. package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +17 -6
  81. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +3 -2
  82. package/src/gpu-core/gpu-graph-compiler.ts +61 -0
  83. package/src/gpu-core/gpu-group-aggregation.ts +38 -50
  84. package/src/gpu-core/gpu-reduction.ts +32 -42
  85. package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
  86. package/src/gpu-core/index.ts +6 -0
  87. package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
  88. package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
  89. package/src/gpu-graph/index.ts +9 -0
  90. package/src/gpu-sql/gpu-sql.ts +130 -103
  91. package/src/gpu-tables/table/gpu-table.ts +2 -1
  92. package/src/index.ts +9 -0
@@ -0,0 +1,25 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, type BufferProps, type Device} from '@luma.gl/core';
6
+
7
+ export const PORTABLE_GPU_DATA_USAGE =
8
+ Buffer.STORAGE | Buffer.VERTEX | Buffer.COPY_SRC | Buffer.COPY_DST;
9
+
10
+ /** Usage defaults for general-purpose GPUData backing storage. */
11
+ export function getGPUDataBufferProps(
12
+ device: Device,
13
+ indexType: BufferProps['indexType'] = 'uint32'
14
+ ): Pick<BufferProps, 'usage' | 'indexType'> {
15
+ const usage = PORTABLE_GPU_DATA_USAGE;
16
+ if (device.type !== 'webgpu') {
17
+ // WebGL fixes the buffer target on first bind, so INDEX would prevent vertex use.
18
+ return {usage};
19
+ }
20
+ return {
21
+ usage: usage | Buffer.INDEX | Buffer.UNIFORM | Buffer.INDIRECT | Buffer.QUERY_RESOLVE,
22
+ // Explicit index metadata prevents Device from widening raw Uint8Array uploads.
23
+ indexType
24
+ };
25
+ }
@@ -82,3 +82,12 @@ export type {
82
82
  GPUCPUVector,
83
83
  GPUCPUResult
84
84
  } from '../gpu-core/gpu-cpu-operation';
85
+
86
+ export {
87
+ GPUGraphGroupAggregation,
88
+ GPUGraphReduction
89
+ } from '../gpu-core/gpu-semantic-aggregation-operation';
90
+ export type {
91
+ GPUGraphGroupAggregationProps,
92
+ GPUGraphReductionProps
93
+ } from '../gpu-core/gpu-semantic-aggregation-operation';
@@ -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
@@ -216,3 +216,12 @@ export type {
216
216
  GPUCPUVector,
217
217
  GPUCPUResult
218
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';