@luma.gl/graph 10.0.0-alpha.12 → 10.0.0-alpha.14

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 (145) hide show
  1. package/LICENSE +4 -4
  2. package/THIRD-PARTY-NOTICES.md +19 -0
  3. package/dist/arrow/arrow-colors.cjs +99 -18
  4. package/dist/arrow/arrow-colors.d.ts +27 -10
  5. package/dist/arrow/arrow-colors.d.ts.map +1 -1
  6. package/dist/arrow/arrow-colors.js +107 -24
  7. package/dist/arrow/arrow-colors.js.map +1 -1
  8. package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +8 -6
  9. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts +1 -0
  10. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
  11. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +17 -7
  12. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
  13. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +35 -5
  14. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +6 -1
  15. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  16. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +40 -5
  17. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  18. package/dist/arrow/index.cjs.map +3 -3
  19. package/dist/arrow/internal.cjs.map +2 -2
  20. package/dist/dist.dev.js +1506 -163
  21. package/dist/dist.min.js +401 -105
  22. package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
  23. package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
  24. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  25. package/dist/gpu-core/gpu-expression-operation.js +1 -1
  26. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  27. package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
  28. package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
  29. package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
  30. package/dist/gpu-core/gpu-graph-compiler.js +50 -0
  31. package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
  32. package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
  33. package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
  34. package/dist/gpu-core/gpu-group-aggregation.js +7 -18
  35. package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
  36. package/dist/gpu-core/gpu-reduction.cjs +6 -14
  37. package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
  38. package/dist/gpu-core/gpu-reduction.js +6 -15
  39. package/dist/gpu-core/gpu-reduction.js.map +1 -1
  40. package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
  41. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
  42. package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
  43. package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
  44. package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
  45. package/dist/gpu-core/index.cjs +5 -0
  46. package/dist/gpu-core/index.cjs.map +3 -3
  47. package/dist/gpu-core/index.d.ts +2 -0
  48. package/dist/gpu-core/index.d.ts.map +1 -1
  49. package/dist/gpu-core/index.js +1 -0
  50. package/dist/gpu-core/index.js.map +1 -1
  51. package/dist/gpu-data/color-conversion.cjs +105 -0
  52. package/dist/gpu-data/color-conversion.d.ts +30 -0
  53. package/dist/gpu-data/color-conversion.d.ts.map +1 -0
  54. package/dist/gpu-data/color-conversion.js +109 -0
  55. package/dist/gpu-data/color-conversion.js.map +1 -0
  56. package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
  57. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
  58. package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
  59. package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
  60. package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
  61. package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
  62. package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
  63. package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
  64. package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
  65. package/dist/gpu-data/index.cjs +7 -2
  66. package/dist/gpu-data/index.cjs.map +3 -3
  67. package/dist/gpu-data/index.d.ts +2 -0
  68. package/dist/gpu-data/index.d.ts.map +1 -1
  69. package/dist/gpu-data/index.js +1 -0
  70. package/dist/gpu-data/index.js.map +1 -1
  71. package/dist/gpu-graph/index.cjs +5 -0
  72. package/dist/gpu-graph/index.cjs.map +3 -3
  73. package/dist/gpu-graph/index.d.ts +2 -0
  74. package/dist/gpu-graph/index.d.ts.map +1 -1
  75. package/dist/gpu-graph/index.js +1 -0
  76. package/dist/gpu-graph/index.js.map +1 -1
  77. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  78. package/dist/gpu-graph-algorithms/index.cjs.map +1 -1
  79. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  80. package/dist/gpu-project/crs.cjs.map +2 -2
  81. package/dist/gpu-project/graph.cjs.map +3 -3
  82. package/dist/gpu-project/index.cjs.map +2 -2
  83. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  84. package/dist/gpu-simple-graph/index.d.ts +1 -1
  85. package/dist/gpu-simple-graph/index.d.ts.map +1 -1
  86. package/dist/gpu-simple-graph/index.js.map +1 -1
  87. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +2 -0
  88. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +3 -0
  89. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
  90. package/dist/gpu-simple-graph/operations/convert-colors.cjs +6 -6
  91. package/dist/gpu-simple-graph/operations/convert-colors.d.ts +5 -1
  92. package/dist/gpu-simple-graph/operations/convert-colors.d.ts.map +1 -1
  93. package/dist/gpu-simple-graph/operations/convert-colors.js +12 -7
  94. package/dist/gpu-simple-graph/operations/convert-colors.js.map +1 -1
  95. package/dist/gpu-simple-graph/operations/cpu/convert-colors.cjs +16 -33
  96. package/dist/gpu-simple-graph/operations/cpu/convert-colors.d.ts.map +1 -1
  97. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js +22 -35
  98. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js.map +1 -1
  99. package/dist/gpu-simple-graph/operations/cpu/index.cjs.map +3 -3
  100. package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +3 -3
  101. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.cjs +31 -13
  102. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.d.ts.map +1 -1
  103. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js +42 -13
  104. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js.map +1 -1
  105. package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
  106. package/dist/gpu-sql/gpu-sql.cjs +112 -100
  107. package/dist/gpu-sql/gpu-sql.d.ts +1 -1
  108. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  109. package/dist/gpu-sql/gpu-sql.js +120 -102
  110. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  111. package/dist/gpu-sql/index.cjs.map +2 -2
  112. package/dist/gpu-tables/index.cjs.map +2 -2
  113. package/dist/gpu-tables/table/gpu-table.cjs +2 -2
  114. package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
  115. package/dist/gpu-tables/table/gpu-table.js +2 -2
  116. package/dist/gpu-tables/table/gpu-table.js.map +1 -1
  117. package/dist/index.cjs +5 -0
  118. package/dist/index.cjs.map +3 -3
  119. package/dist/index.d.ts +2 -0
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +1 -0
  122. package/dist/index.js.map +1 -1
  123. package/package.json +11 -8
  124. package/src/arrow/arrow-colors.ts +194 -33
  125. package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +20 -7
  126. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +49 -6
  127. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  128. package/src/gpu-core/gpu-graph-compiler.ts +61 -0
  129. package/src/gpu-core/gpu-group-aggregation.ts +38 -50
  130. package/src/gpu-core/gpu-reduction.ts +32 -42
  131. package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
  132. package/src/gpu-core/index.ts +6 -0
  133. package/src/gpu-data/color-conversion.ts +158 -0
  134. package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
  135. package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
  136. package/src/gpu-data/index.ts +3 -0
  137. package/src/gpu-graph/index.ts +9 -0
  138. package/src/gpu-simple-graph/index.ts +1 -0
  139. package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +2 -0
  140. package/src/gpu-simple-graph/operations/convert-colors.ts +22 -7
  141. package/src/gpu-simple-graph/operations/cpu/convert-colors.ts +31 -48
  142. package/src/gpu-simple-graph/operations/webgpu/convert-colors.ts +47 -13
  143. package/src/gpu-sql/gpu-sql.ts +130 -103
  144. package/src/gpu-tables/table/gpu-table.ts +2 -1
  145. package/src/index.ts +9 -0
@@ -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';
@@ -63,6 +63,7 @@ export {extent} from './operations/extent';
63
63
  export {convertColorData} from './operations/convert-colors';
64
64
  export type {
65
65
  ColorInputFormat,
66
+ ColorOutputFormat,
66
67
  ConvertColorsInputs,
67
68
  ConvertColorsProps
68
69
  } from './operations/convert-colors';
@@ -929,6 +929,8 @@ function getVertexFormat(
929
929
  if (size < 1 || size > 4) {
930
930
  throw new Error(`Cannot synthesize a GPUVector vertex format with ${size} components`);
931
931
  }
932
+ // Binary16 RGB has no vertex format; retain byte-identical packed storage for compute readers.
933
+ if (type === 'float16' && size === 3 && !normalized) return 'uint16x3-webgl';
932
934
  let baseFormat: string = type;
933
935
  if (normalized) {
934
936
  switch (type) {
@@ -8,6 +8,7 @@ import {
8
8
  type GPUDataEvaluatorInput
9
9
  } from '../operation/gpu-data-evaluator';
10
10
  import {Operation} from '../operation/operation';
11
+ import type {ColorOutputFormat} from '../../gpu-data/color-conversion';
11
12
 
12
13
  export type ColorInputFormat =
13
14
  | 'uint8x3'
@@ -17,13 +18,17 @@ export type ColorInputFormat =
17
18
  | 'float32x3'
18
19
  | 'float32x4';
19
20
 
21
+ export type {ColorOutputFormat} from '../../gpu-data/color-conversion';
22
+
20
23
  export type ConvertColorsProps = {
24
+ format?: ColorOutputFormat;
21
25
  inputFormat?: ColorInputFormat;
22
26
  };
23
27
 
24
28
  export type ConvertColorsInputs = {
25
29
  source: GPUDataEvaluator;
26
30
  inputFormat: ColorInputFormat;
31
+ outputFormat: ColorOutputFormat;
27
32
  };
28
33
 
29
34
  class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
@@ -31,15 +36,24 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
31
36
 
32
37
  output: GPUDataEvaluator;
33
38
 
34
- constructor(source: GPUDataEvaluator, inputFormat: ColorInputFormat) {
35
- super({source, inputFormat});
39
+ constructor(
40
+ source: GPUDataEvaluator,
41
+ inputFormat: ColorInputFormat,
42
+ outputFormat: ColorOutputFormat
43
+ ) {
44
+ super({source, inputFormat, outputFormat});
36
45
 
37
46
  this.output = new GPUDataEvaluator({
38
47
  id: `convertColors(${source})`,
39
- type: 'uint8',
48
+ type:
49
+ outputFormat === 'unorm8x4'
50
+ ? 'uint8'
51
+ : outputFormat === 'float16x4'
52
+ ? 'float16'
53
+ : 'float32',
40
54
  size: 4,
41
- normalized: true,
42
- format: 'unorm8x4',
55
+ normalized: outputFormat === 'unorm8x4',
56
+ format: outputFormat,
43
57
  length: source.length,
44
58
  source: this
45
59
  });
@@ -50,14 +64,15 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
50
64
  }
51
65
  }
52
66
 
53
- /** Converts one fixed-width GPU data range to normalized Uint8 RGBA values. */
67
+ /** Converts one fixed-width color range to RGBA8, binary16 or binary32 RGBA storage. */
54
68
  export function convertColorData(
55
69
  source: GPUDataEvaluatorInput,
56
70
  props: ConvertColorsProps = {}
57
71
  ): GPUDataEvaluator {
58
72
  const sourceEvaluator = getGPUDataEvaluator(source);
59
73
  const inputFormat = props.inputFormat ?? getColorInputFormat(sourceEvaluator);
60
- return new ConvertColorsOperation(sourceEvaluator, inputFormat).output;
74
+ return new ConvertColorsOperation(sourceEvaluator, inputFormat, props.format ?? 'unorm8x4')
75
+ .output;
61
76
  }
62
77
 
63
78
  function getColorInputFormat(source: GPUDataEvaluator): ColorInputFormat {
@@ -2,55 +2,38 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import {fromHalfFloat} from '@luma.gl/shaders';
6
- import type {TypedArray} from '@math.gl/core';
5
+ import {CPUData} from '../../../gpu-data/cpu-data';
6
+ import {convertCPUColorData} from '../../../gpu-data/color-conversion';
7
7
  import type {OperationHandler} from '../../operation/operation';
8
8
  import type {ConvertColorsInputs} from '../convert-colors';
9
9
 
10
- export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
11
- inputs,
12
- output,
13
- target
14
- }) => {
15
- const {source, inputFormat} = inputs;
16
- const sourceValue = await source.ensureCPUValue();
17
- const result = new output.ValueType(output.length * output.size);
18
- const inputSize = inputFormat.endsWith('x3') ? 3 : 4;
19
-
20
- for (let rowIndex = 0; rowIndex < output.length; rowIndex++) {
21
- const inputOffset =
22
- source.offset / source.ValueType.BYTES_PER_ELEMENT +
23
- rowIndex * (source.stride / source.ValueType.BYTES_PER_ELEMENT);
24
- const outputOffset = rowIndex * 4;
25
-
26
- result[outputOffset] = convertColorChannel(sourceValue, inputOffset, inputFormat);
27
- result[outputOffset + 1] = convertColorChannel(sourceValue, inputOffset + 1, inputFormat);
28
- result[outputOffset + 2] = convertColorChannel(sourceValue, inputOffset + 2, inputFormat);
29
- result[outputOffset + 3] =
30
- inputSize === 4 ? convertColorChannel(sourceValue, inputOffset + 3, inputFormat) : 255;
31
- }
32
-
33
- target.write(result);
34
- return {success: true, value: result};
10
+ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({inputs, target}) => {
11
+ const {source, inputFormat, outputFormat} = inputs;
12
+ const values = await source.ensureCPUValue();
13
+ const format =
14
+ source.format ??
15
+ (inputFormat === 'uint8x3'
16
+ ? 'uint8x3-webgl'
17
+ : inputFormat === 'float16x3'
18
+ ? 'uint16x3-webgl'
19
+ : inputFormat);
20
+ const converted = convertCPUColorData(
21
+ new CPUData({
22
+ buffer: values,
23
+ format,
24
+ length: source.length,
25
+ byteOffset: source.offset,
26
+ byteStride: source.stride
27
+ }),
28
+ outputFormat,
29
+ inputFormat
30
+ );
31
+ const bytes = new Uint8Array(
32
+ converted.buffer,
33
+ converted.byteOffset,
34
+ converted.length * converted.byteStride
35
+ );
36
+ target.write(bytes);
37
+ // Let the evaluator decode the target in its own Float16Array/Uint16Array representation.
38
+ return {success: true};
35
39
  };
36
-
37
- function convertColorChannel(values: TypedArray, index: number, inputFormat: string): number {
38
- if (inputFormat.startsWith('uint8')) {
39
- return values[index];
40
- }
41
-
42
- const value = inputFormat.startsWith('float16') ? getFloat16Value(values, index) : values[index];
43
- return Math.round(Math.min(Math.max(value, 0), 1) * 255);
44
- }
45
-
46
- function getFloat16Value(values: TypedArray, index: number): number {
47
- const Float16ArrayConstructor = getNativeFloat16ArrayConstructor();
48
- if (Float16ArrayConstructor && values.constructor === Float16ArrayConstructor) {
49
- return values[index];
50
- }
51
- return fromHalfFloat(values[index]);
52
- }
53
-
54
- function getNativeFloat16ArrayConstructor(): unknown {
55
- return (globalThis as typeof globalThis & {Float16Array?: unknown}).Float16Array;
56
- }
@@ -13,11 +13,19 @@ const COMPUTATION_RUNS = 'Computation Runs';
13
13
  export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
14
14
  inputs,
15
15
  output,
16
- target
16
+ target,
17
+ scope
17
18
  }) => {
18
19
  const {source, inputFormat} = inputs;
20
+ if (output.length === 0) return {success: true};
19
21
  const kernel = new Kernel(target.device, {
20
- source: getConvertColorsWGSL(inputFormat, source.offset, source.stride, output.length),
22
+ source: getConvertColorsWGSL(
23
+ inputFormat,
24
+ source.offset,
25
+ source.stride,
26
+ output.length,
27
+ inputs.outputFormat
28
+ ),
21
29
  shaderLayout: {
22
30
  bindings: [
23
31
  {name: 'source', type: 'storage' as const, group: 0, location: 0},
@@ -31,23 +39,38 @@ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
31
39
  result: target
32
40
  };
33
41
 
34
- const computePass = target.device.beginComputePass({});
35
- target.device.statsManager.getStats(GPGPU_OPERATION_STATS).get(COMPUTATION_RUNS).incrementCount();
36
- kernel.dispatch(computePass, {
37
- bindings: kernelBindings,
38
- x: Math.ceil(output.length / WORKGROUP_SIZE)
39
- });
40
- computePass.end();
41
- target.device.submit();
42
- kernel.destroy();
42
+ if (scope) scope.retain(() => kernel.destroy());
43
+ try {
44
+ const computePass = scope
45
+ ? scope.commandEncoder.beginComputePass({})
46
+ : target.device.beginComputePass({});
47
+ try {
48
+ target.device.statsManager
49
+ .getStats(GPGPU_OPERATION_STATS)
50
+ .get(COMPUTATION_RUNS)
51
+ .incrementCount();
52
+ kernel.dispatch(computePass, {
53
+ bindings: kernelBindings,
54
+ x: Math.ceil(output.length / WORKGROUP_SIZE)
55
+ });
56
+ } finally {
57
+ computePass.end();
58
+ }
59
+ if (!scope) target.device.submit();
60
+ } finally {
61
+ if (!scope) kernel.destroy();
62
+ }
63
+
43
64
  return {success: true};
44
65
  };
66
+ convertColors.supportsEvaluationScope = true;
45
67
 
46
68
  function getConvertColorsWGSL(
47
69
  inputFormat: ConvertColorsInputs['inputFormat'],
48
70
  byteOffset: number,
49
71
  byteStride: number,
50
- length: number
72
+ length: number,
73
+ outputFormat: ConvertColorsInputs['outputFormat']
51
74
  ): string {
52
75
  return /* wgsl */ `\
53
76
  @group(0) @binding(0) var<storage, read> source: array<u32>;
@@ -90,7 +113,18 @@ ${getReadColorWGSL(inputFormat)}
90
113
  return;
91
114
  }
92
115
 
93
- result[rowIndex] = pack4x8unorm(readColor(rowIndex));
116
+ let color = readColor(rowIndex);
117
+ ${
118
+ outputFormat === 'unorm8x4'
119
+ ? ' result[rowIndex] = pack4x8unorm(color);'
120
+ : outputFormat === 'float16x4'
121
+ ? ` result[rowIndex * 2u] = pack2x16float(color.xy);
122
+ result[rowIndex * 2u + 1u] = pack2x16float(color.zw);`
123
+ : ` result[rowIndex * 4u] = bitcast<u32>(color.x);
124
+ result[rowIndex * 4u + 1u] = bitcast<u32>(color.y);
125
+ result[rowIndex * 4u + 2u] = bitcast<u32>(color.z);
126
+ result[rowIndex * 4u + 3u] = bitcast<u32>(color.w);`
127
+ }
94
128
  }
95
129
  `;
96
130
  }
@@ -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 {parseSQLExpression} from '@math.gl/expressions/sql';
7
+ import type {Expression} from '@math.gl/expressions';
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';