@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.
- package/LICENSE +4 -4
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +6 -6
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +16 -6
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +3 -2
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +3 -2
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
- package/dist/arrow/index.cjs.map +2 -2
- package/dist/arrow/internal.cjs.map +2 -2
- package/dist/dist.dev.js +1539 -211
- package/dist/dist.min.js +401 -105
- package/dist/gpu-core/gpu-graph-compiler.cjs +48 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts +1 -0
- package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.js +50 -0
- package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.cjs +7 -15
- package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.js +7 -18
- package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
- package/dist/gpu-core/gpu-reduction.cjs +6 -14
- package/dist/gpu-core/gpu-reduction.d.ts.map +1 -1
- package/dist/gpu-core/gpu-reduction.js +6 -15
- package/dist/gpu-core/gpu-reduction.js.map +1 -1
- package/dist/gpu-core/gpu-semantic-aggregation-operation.cjs +112 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts +71 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js +92 -0
- package/dist/gpu-core/gpu-semantic-aggregation-operation.js.map +1 -0
- package/dist/gpu-core/index.cjs +5 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +2 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +1 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +7 -2
- package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -1
- package/dist/gpu-data/cpu-gpu-vector-transfer.js +9 -6
- package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -1
- package/dist/gpu-data/gpu-data-buffer-props.cjs +41 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts +5 -0
- package/dist/gpu-data/gpu-data-buffer-props.d.ts.map +1 -0
- package/dist/gpu-data/gpu-data-buffer-props.js +19 -0
- package/dist/gpu-data/gpu-data-buffer-props.js.map +1 -0
- package/dist/gpu-data/index.cjs.map +3 -3
- package/dist/gpu-graph/index.cjs +5 -0
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph/index.d.ts +2 -0
- package/dist/gpu-graph/index.d.ts.map +1 -1
- package/dist/gpu-graph/index.js +1 -0
- package/dist/gpu-graph/index.js.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph-algorithms/index.cjs.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/graph.cjs.map +3 -3
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-sql/gpu-sql.cjs +112 -100
- package/dist/gpu-sql/gpu-sql.d.ts +1 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +120 -102
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +2 -2
- package/dist/gpu-tables/index.cjs.map +2 -2
- package/dist/gpu-tables/table/gpu-table.cjs +2 -2
- package/dist/gpu-tables/table/gpu-table.d.ts.map +1 -1
- package/dist/gpu-tables/table/gpu-table.js +2 -2
- package/dist/gpu-tables/table/gpu-table.js.map +1 -1
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +17 -6
- package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +3 -2
- package/src/gpu-core/gpu-graph-compiler.ts +61 -0
- package/src/gpu-core/gpu-group-aggregation.ts +38 -50
- package/src/gpu-core/gpu-reduction.ts +32 -42
- package/src/gpu-core/gpu-semantic-aggregation-operation.ts +150 -0
- package/src/gpu-core/index.ts +6 -0
- package/src/gpu-data/cpu-gpu-vector-transfer.ts +10 -7
- package/src/gpu-data/gpu-data-buffer-props.ts +25 -0
- package/src/gpu-graph/index.ts +9 -0
- package/src/gpu-sql/gpu-sql.ts +130 -103
- package/src/gpu-tables/table/gpu-table.ts +2 -1
- package/src/index.ts +9 -0
package/dist/gpu-sql/gpu-sql.cjs
CHANGED
|
@@ -21,12 +21,12 @@ __export(gpu_sql_exports, {
|
|
|
21
21
|
GPUSQLQuery: () => GPUSQLQuery
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(gpu_sql_exports);
|
|
24
|
+
var import_sql = require("@math.gl/core/sql");
|
|
24
25
|
var import_gpu_data_frame = require("../gpu-dataframe/gpu-data-frame.cjs");
|
|
25
26
|
var import_gpu_data_frame_query = require("../gpu-dataframe/gpu-data-frame-query.cjs");
|
|
26
27
|
var import_gpu_expression = require("../gpu-dataframe/gpu-expression.cjs");
|
|
27
28
|
const MAXIMUM_SQL_LENGTH = 65536;
|
|
28
29
|
const MAXIMUM_SQL_TOKENS = 4096;
|
|
29
|
-
const MAXIMUM_EXPRESSION_DEPTH = 64;
|
|
30
30
|
class GPUSQLContext {
|
|
31
31
|
tables;
|
|
32
32
|
constructor(tables) {
|
|
@@ -151,13 +151,14 @@ function buildGPUSQLPlan(tables, statement) {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
if (statement.orderBy) {
|
|
154
|
-
const
|
|
154
|
+
const { column: requested, direction, nulls } = statement.orderBy;
|
|
155
|
+
const orderColumn = selected.includes(requested) ? requested : resolve(requested);
|
|
155
156
|
if (!selected.includes(orderColumn)) {
|
|
156
157
|
throw new Error("GPUSQL ORDER BY requires the sort column in the SELECT projection");
|
|
157
158
|
}
|
|
158
159
|
const sort = query.select(selected).sortByGlobal(orderColumn, {
|
|
159
|
-
direction
|
|
160
|
-
...
|
|
160
|
+
direction,
|
|
161
|
+
...nulls ? { nulls } : {}
|
|
161
162
|
});
|
|
162
163
|
return statement.limit === void 0 ? sort : sort.topK(statement.limit);
|
|
163
164
|
}
|
|
@@ -184,10 +185,9 @@ function resolveGPUSQLColumn(name, qualifier, columns) {
|
|
|
184
185
|
throw new Error(`GPUSQL column "${name}" has an unknown table qualifier`);
|
|
185
186
|
}
|
|
186
187
|
const requested = parts[parts.length - 1];
|
|
187
|
-
|
|
188
|
-
if (matches.length !== 1)
|
|
188
|
+
if (!columns.includes(requested))
|
|
189
189
|
throw new Error(`GPUSQL column "${name}" does not exist`);
|
|
190
|
-
return
|
|
190
|
+
return requested;
|
|
191
191
|
}
|
|
192
192
|
function resolveGPUSQLExpression(expression, resolve) {
|
|
193
193
|
switch (expression.kind) {
|
|
@@ -223,7 +223,7 @@ class GPUSQLParser {
|
|
|
223
223
|
const table = this.parseIdentifier();
|
|
224
224
|
const alias = this.parseOptionalTableAlias();
|
|
225
225
|
const join = this.parseOptionalJoin();
|
|
226
|
-
const predicate = this.takeKeyword("WHERE") ? this.parseExpression(
|
|
226
|
+
const predicate = this.takeKeyword("WHERE") ? this.parseExpression() : void 0;
|
|
227
227
|
let groupBy;
|
|
228
228
|
if (this.takeKeyword("GROUP")) {
|
|
229
229
|
this.expectKeyword("BY");
|
|
@@ -292,7 +292,7 @@ class GPUSQLParser {
|
|
|
292
292
|
...this.takeKeyword("AS") ? { alias: this.parseIdentifier() } : {}
|
|
293
293
|
};
|
|
294
294
|
}
|
|
295
|
-
const expression = this.parseExpression(
|
|
295
|
+
const expression = this.parseExpression();
|
|
296
296
|
return {
|
|
297
297
|
...expression ? { expression } : {},
|
|
298
298
|
...this.takeKeyword("AS") ? { alias: this.parseIdentifier() } : {}
|
|
@@ -323,72 +323,47 @@ class GPUSQLParser {
|
|
|
323
323
|
const right = this.parseIdentifier();
|
|
324
324
|
return { type, table, ...alias ? { alias } : {}, left, right };
|
|
325
325
|
}
|
|
326
|
-
parseExpression(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
let
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
};
|
|
339
|
-
continue;
|
|
326
|
+
parseExpression() {
|
|
327
|
+
const tokens = [];
|
|
328
|
+
let depth = 0;
|
|
329
|
+
let expectsOperand = true;
|
|
330
|
+
for (let token = this.peek(); token; token = this.peek()) {
|
|
331
|
+
const value = token.value;
|
|
332
|
+
if (depth === 0) {
|
|
333
|
+
if (token.kind === "symbol" && (value === "," || value === ";"))
|
|
334
|
+
break;
|
|
335
|
+
if (token.kind === "identifier" && !expectsOperand && /^(AS|FROM|GROUP|ORDER|LIMIT)$/i.test(value)) {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
340
338
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return expression;
|
|
366
|
-
}
|
|
367
|
-
const token = this.take();
|
|
368
|
-
if (!token)
|
|
369
|
-
throw new Error("GPUSQL expected an expression");
|
|
370
|
-
if (token.kind === "number") {
|
|
371
|
-
const value = Number(token.value);
|
|
372
|
-
if (!Number.isFinite(value))
|
|
373
|
-
throw new Error("GPUSQL numeric literals must be finite");
|
|
374
|
-
return (0, import_gpu_expression.literal)(value).node;
|
|
375
|
-
}
|
|
376
|
-
if (token.kind === "parameter") {
|
|
377
|
-
if (!Object.hasOwn(this.parameters, token.value)) {
|
|
378
|
-
throw new Error(`GPUSQL parameter ":${token.value}" requires an explicit default`);
|
|
339
|
+
switch (token.kind) {
|
|
340
|
+
case "parameter":
|
|
341
|
+
tokens.push(`":${value}"`);
|
|
342
|
+
expectsOperand = false;
|
|
343
|
+
break;
|
|
344
|
+
case "identifier": {
|
|
345
|
+
const operator = /^NOT$/i.test(value) || !expectsOperand && /^(AND|OR|IS)$/i.test(value);
|
|
346
|
+
const keyword = operator || /^(NULL|TRUE|FALSE)$/i.test(value);
|
|
347
|
+
tokens.push(keyword ? value : `"${value}"`);
|
|
348
|
+
expectsOperand = operator;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case "symbol":
|
|
352
|
+
if (value === "(")
|
|
353
|
+
depth++;
|
|
354
|
+
if (value === ")")
|
|
355
|
+
depth--;
|
|
356
|
+
tokens.push(value);
|
|
357
|
+
expectsOperand = value !== ")";
|
|
358
|
+
break;
|
|
359
|
+
case "number":
|
|
360
|
+
tokens.push(value);
|
|
361
|
+
expectsOperand = false;
|
|
362
|
+
break;
|
|
379
363
|
}
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
if (token.kind === "identifier") {
|
|
383
|
-
if (/^NULL$/i.test(token.value))
|
|
384
|
-
return (0, import_gpu_expression.literal)(null).node;
|
|
385
|
-
if (/^TRUE$/i.test(token.value))
|
|
386
|
-
return (0, import_gpu_expression.literal)(true).node;
|
|
387
|
-
if (/^FALSE$/i.test(token.value))
|
|
388
|
-
return (0, import_gpu_expression.literal)(false).node;
|
|
389
|
-
return (0, import_gpu_expression.column)(token.value).node;
|
|
364
|
+
this.take();
|
|
390
365
|
}
|
|
391
|
-
|
|
366
|
+
return lowerSQLExpression((0, import_sql.parseSQLExpression)(tokens.join(" ")), this.parameters);
|
|
392
367
|
}
|
|
393
368
|
parseOptionalTableAlias() {
|
|
394
369
|
if (this.takeKeyword("AS"))
|
|
@@ -461,36 +436,73 @@ function tokenizeGPUSQL(source) {
|
|
|
461
436
|
}
|
|
462
437
|
return tokens;
|
|
463
438
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
case "
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
return
|
|
489
|
-
|
|
490
|
-
|
|
439
|
+
const SQL_BINARY_OPERATORS = {
|
|
440
|
+
"||": "or",
|
|
441
|
+
"&&": "and",
|
|
442
|
+
"==": "equal",
|
|
443
|
+
"!=": "not-equal",
|
|
444
|
+
">": "greater-than",
|
|
445
|
+
">=": "greater-than-or-equal",
|
|
446
|
+
"<": "less-than",
|
|
447
|
+
"<=": "less-than-or-equal",
|
|
448
|
+
"+": "add",
|
|
449
|
+
"-": "subtract",
|
|
450
|
+
"*": "multiply",
|
|
451
|
+
"/": "divide"
|
|
452
|
+
};
|
|
453
|
+
function lowerSQLExpression(node, parameters) {
|
|
454
|
+
const expression = node;
|
|
455
|
+
switch (expression.type) {
|
|
456
|
+
case "Identifier": {
|
|
457
|
+
if (!expression.name.startsWith(":"))
|
|
458
|
+
return (0, import_gpu_expression.column)(expression.name).node;
|
|
459
|
+
const name = expression.name.slice(1);
|
|
460
|
+
if (!Object.hasOwn(parameters, name)) {
|
|
461
|
+
throw new Error(`GPUSQL parameter ":${name}" requires an explicit default`);
|
|
462
|
+
}
|
|
463
|
+
return (0, import_gpu_expression.parameter)(name, parameters[name]).node;
|
|
464
|
+
}
|
|
465
|
+
case "Literal": {
|
|
466
|
+
const value = expression.value;
|
|
467
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) {
|
|
468
|
+
return (0, import_gpu_expression.literal)(value).node;
|
|
469
|
+
}
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
case "UnaryExpression":
|
|
473
|
+
if (expression.operator === "!" || expression.operator === "-") {
|
|
474
|
+
return {
|
|
475
|
+
kind: "unary",
|
|
476
|
+
operator: expression.operator === "!" ? "not" : "negate",
|
|
477
|
+
operand: lowerSQLExpression(expression.argument, parameters)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
break;
|
|
481
|
+
case "BinaryExpression": {
|
|
482
|
+
const operator = SQL_BINARY_OPERATORS[expression.operator];
|
|
483
|
+
if (operator) {
|
|
484
|
+
return {
|
|
485
|
+
kind: "binary",
|
|
486
|
+
operator,
|
|
487
|
+
left: lowerSQLExpression(expression.left, parameters),
|
|
488
|
+
right: lowerSQLExpression(expression.right, parameters)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
case "CallExpression":
|
|
494
|
+
if (expression.arguments.length === 1 && (expression.callee["name"] === "isNull" || expression.callee["name"] === "isNotNull")) {
|
|
495
|
+
return {
|
|
496
|
+
kind: "unary",
|
|
497
|
+
operator: expression.callee["name"] === "isNull" ? "is-null" : "is-valid",
|
|
498
|
+
operand: lowerSQLExpression(expression.arguments[0], parameters)
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
491
502
|
default:
|
|
492
|
-
|
|
503
|
+
break;
|
|
493
504
|
}
|
|
505
|
+
throw new Error(`GPUSQL does not support SQL expression "${expression.type}"`);
|
|
494
506
|
}
|
|
495
507
|
// Annotate the CommonJS export names for ESM import in node:
|
|
496
508
|
0 && (module.exports = {
|
|
@@ -11,7 +11,7 @@ type GPUSQLCompiledPlan = Readonly<{
|
|
|
11
11
|
compile: (graph: GPUCommandGraph<GPUDataFrameQueryParameters>) => CompiledGPUDataFrameQuery;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* SQL frontend over explicitly registered, already GPU-resident dataframes.
|
|
15
15
|
*
|
|
16
16
|
* Parsing and planning never upload data, submit work, or read GPU buffers. Arrow upload/output
|
|
17
17
|
* remain explicit `@luma.gl/graph/arrow` operations around the shared GPU table execution core.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpu-sql.d.ts","sourceRoot":"","sources":["../../src/gpu-sql/gpu-sql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gpu-sql.d.ts","sourceRoot":"","sources":["../../src/gpu-sql/gpu-sql.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAC,YAAY,EAAC,2CAAwC;AAU7D,OAAO,KAAK,EACV,yBAAyB,EACzB,2BAA2B,EAC5B,+CAA4C;AAK7C,2FAA2F;AAC3F,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAElE,iGAAiG;AACjG,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IAAC,UAAU,CAAC,EAAE,2BAA2B,CAAA;CAAC,CAAC,CAAC;AAkCtF,KAAK,kBAAkB,GAAG,QAAQ,CAAC;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,2BAA2B,CAAC,KAAK,yBAAyB,CAAC;CAC7F,CAAC,CAAC;AAiCH;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;gBAEpD,MAAM,EAAE,YAAY;IAchC,8FAA8F;IAC9F,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,WAAW;CAKrE;AAED,+FAA+F;AAC/F,qBAAa,WAAW;IACtB,2FAA2F;IAC3F,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAE1C,gBAAgB;gBACJ,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB;IAMjD,sFAAsF;IACtF,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,2BAA2B,CAAC,GAAG,yBAAyB;CAGxF"}
|
package/dist/gpu-sql/gpu-sql.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by relational SQL semantics.
|
|
5
|
+
import { parseSQLExpression } from '@math.gl/core/sql';
|
|
5
6
|
import { GPUDataFrame } from "../gpu-dataframe/gpu-data-frame.js";
|
|
6
7
|
import { GPUDataFrameQuery } from "../gpu-dataframe/gpu-data-frame-query.js";
|
|
7
8
|
import { GPUExpression, column, literal, parameter } from "../gpu-dataframe/gpu-expression.js";
|
|
8
9
|
const MAXIMUM_SQL_LENGTH = 65_536;
|
|
9
10
|
const MAXIMUM_SQL_TOKENS = 4_096;
|
|
10
|
-
const MAXIMUM_EXPRESSION_DEPTH = 64;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* SQL frontend over explicitly registered, already GPU-resident dataframes.
|
|
13
13
|
*
|
|
14
14
|
* Parsing and planning never upload data, submit work, or read GPU buffers. Arrow upload/output
|
|
15
15
|
* remain explicit `@luma.gl/graph/arrow` operations around the shared GPU table execution core.
|
|
@@ -143,14 +143,14 @@ function buildGPUSQLPlan(tables, statement) {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
if (statement.orderBy) {
|
|
146
|
-
const
|
|
147
|
-
|
|
146
|
+
const { column: requested, direction, nulls } = statement.orderBy;
|
|
147
|
+
const orderColumn = selected.includes(requested) ? requested : resolve(requested);
|
|
148
148
|
if (!selected.includes(orderColumn)) {
|
|
149
149
|
throw new Error('GPUSQL ORDER BY requires the sort column in the SELECT projection');
|
|
150
150
|
}
|
|
151
151
|
const sort = query.select(selected).sortByGlobal(orderColumn, {
|
|
152
|
-
direction
|
|
153
|
-
...(
|
|
152
|
+
direction,
|
|
153
|
+
...(nulls ? { nulls } : {})
|
|
154
154
|
});
|
|
155
155
|
return statement.limit === undefined ? sort : sort.topK(statement.limit);
|
|
156
156
|
}
|
|
@@ -177,10 +177,9 @@ function resolveGPUSQLColumn(name, qualifier, columns) {
|
|
|
177
177
|
throw new Error(`GPUSQL column "${name}" has an unknown table qualifier`);
|
|
178
178
|
}
|
|
179
179
|
const requested = parts[parts.length - 1];
|
|
180
|
-
|
|
181
|
-
if (matches.length !== 1)
|
|
180
|
+
if (!columns.includes(requested))
|
|
182
181
|
throw new Error(`GPUSQL column "${name}" does not exist`);
|
|
183
|
-
return
|
|
182
|
+
return requested;
|
|
184
183
|
}
|
|
185
184
|
function resolveGPUSQLExpression(expression, resolve) {
|
|
186
185
|
switch (expression.kind) {
|
|
@@ -216,7 +215,7 @@ class GPUSQLParser {
|
|
|
216
215
|
const table = this.parseIdentifier();
|
|
217
216
|
const alias = this.parseOptionalTableAlias();
|
|
218
217
|
const join = this.parseOptionalJoin();
|
|
219
|
-
const predicate = this.takeKeyword('WHERE') ? this.parseExpression(
|
|
218
|
+
const predicate = this.takeKeyword('WHERE') ? this.parseExpression() : undefined;
|
|
220
219
|
let groupBy;
|
|
221
220
|
if (this.takeKeyword('GROUP')) {
|
|
222
221
|
this.expectKeyword('BY');
|
|
@@ -288,7 +287,7 @@ class GPUSQLParser {
|
|
|
288
287
|
...(this.takeKeyword('AS') ? { alias: this.parseIdentifier() } : {})
|
|
289
288
|
};
|
|
290
289
|
}
|
|
291
|
-
const expression = this.parseExpression(
|
|
290
|
+
const expression = this.parseExpression();
|
|
292
291
|
return {
|
|
293
292
|
...(expression ? { expression } : {}),
|
|
294
293
|
...(this.takeKeyword('AS') ? { alias: this.parseIdentifier() } : {})
|
|
@@ -322,72 +321,50 @@ class GPUSQLParser {
|
|
|
322
321
|
const right = this.parseIdentifier();
|
|
323
322
|
return { type, table, ...(alias ? { alias } : {}), left, right };
|
|
324
323
|
}
|
|
325
|
-
parseExpression(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
let
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
324
|
+
parseExpression() {
|
|
325
|
+
const tokens = [];
|
|
326
|
+
let depth = 0;
|
|
327
|
+
let expectsOperand = true;
|
|
328
|
+
for (let token = this.peek(); token; token = this.peek()) {
|
|
329
|
+
const value = token.value;
|
|
330
|
+
if (depth === 0) {
|
|
331
|
+
if (token.kind === 'symbol' && (value === ',' || value === ';'))
|
|
332
|
+
break;
|
|
333
|
+
if (token.kind === 'identifier' &&
|
|
334
|
+
!expectsOperand &&
|
|
335
|
+
/^(AS|FROM|GROUP|ORDER|LIMIT)$/i.test(value)) {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
339
338
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
const token = this.take();
|
|
367
|
-
if (!token)
|
|
368
|
-
throw new Error('GPUSQL expected an expression');
|
|
369
|
-
if (token.kind === 'number') {
|
|
370
|
-
const value = Number(token.value);
|
|
371
|
-
if (!Number.isFinite(value))
|
|
372
|
-
throw new Error('GPUSQL numeric literals must be finite');
|
|
373
|
-
return literal(value).node;
|
|
374
|
-
}
|
|
375
|
-
if (token.kind === 'parameter') {
|
|
376
|
-
if (!Object.hasOwn(this.parameters, token.value)) {
|
|
377
|
-
throw new Error(`GPUSQL parameter ":${token.value}" requires an explicit default`);
|
|
339
|
+
switch (token.kind) {
|
|
340
|
+
case 'parameter':
|
|
341
|
+
// The shared AST leaves parameter binding to the GPU planner.
|
|
342
|
+
tokens.push(`":${value}"`);
|
|
343
|
+
expectsOperand = false;
|
|
344
|
+
break;
|
|
345
|
+
case 'identifier': {
|
|
346
|
+
const operator = /^NOT$/i.test(value) || (!expectsOperand && /^(AND|OR|IS)$/i.test(value));
|
|
347
|
+
const keyword = operator || /^(NULL|TRUE|FALSE)$/i.test(value);
|
|
348
|
+
tokens.push(keyword ? value : `"${value}"`);
|
|
349
|
+
expectsOperand = operator;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case 'symbol':
|
|
353
|
+
if (value === '(')
|
|
354
|
+
depth++;
|
|
355
|
+
if (value === ')')
|
|
356
|
+
depth--;
|
|
357
|
+
tokens.push(value);
|
|
358
|
+
expectsOperand = value !== ')';
|
|
359
|
+
break;
|
|
360
|
+
case 'number':
|
|
361
|
+
tokens.push(value);
|
|
362
|
+
expectsOperand = false;
|
|
363
|
+
break;
|
|
378
364
|
}
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
if (token.kind === 'identifier') {
|
|
382
|
-
if (/^NULL$/i.test(token.value))
|
|
383
|
-
return literal(null).node;
|
|
384
|
-
if (/^TRUE$/i.test(token.value))
|
|
385
|
-
return literal(true).node;
|
|
386
|
-
if (/^FALSE$/i.test(token.value))
|
|
387
|
-
return literal(false).node;
|
|
388
|
-
return column(token.value).node;
|
|
365
|
+
this.take();
|
|
389
366
|
}
|
|
390
|
-
|
|
367
|
+
return lowerSQLExpression(parseSQLExpression(tokens.join(' ')), this.parameters);
|
|
391
368
|
}
|
|
392
369
|
parseOptionalTableAlias() {
|
|
393
370
|
if (this.takeKeyword('AS'))
|
|
@@ -463,35 +440,76 @@ function tokenizeGPUSQL(source) {
|
|
|
463
440
|
}
|
|
464
441
|
return tokens;
|
|
465
442
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
443
|
+
const SQL_BINARY_OPERATORS = {
|
|
444
|
+
'||': 'or',
|
|
445
|
+
'&&': 'and',
|
|
446
|
+
'==': 'equal',
|
|
447
|
+
'!=': 'not-equal',
|
|
448
|
+
'>': 'greater-than',
|
|
449
|
+
'>=': 'greater-than-or-equal',
|
|
450
|
+
'<': 'less-than',
|
|
451
|
+
'<=': 'less-than-or-equal',
|
|
452
|
+
'+': 'add',
|
|
453
|
+
'-': 'subtract',
|
|
454
|
+
'*': 'multiply',
|
|
455
|
+
'/': 'divide'
|
|
456
|
+
};
|
|
457
|
+
function lowerSQLExpression(node, parameters) {
|
|
458
|
+
// math.gl types child nodes as generic expressions, though the SQL parser emits the AST union.
|
|
459
|
+
const expression = node;
|
|
460
|
+
switch (expression.type) {
|
|
461
|
+
case 'Identifier': {
|
|
462
|
+
if (!expression.name.startsWith(':'))
|
|
463
|
+
return column(expression.name).node;
|
|
464
|
+
const name = expression.name.slice(1);
|
|
465
|
+
if (!Object.hasOwn(parameters, name)) {
|
|
466
|
+
throw new Error(`GPUSQL parameter ":${name}" requires an explicit default`);
|
|
467
|
+
}
|
|
468
|
+
return parameter(name, parameters[name]).node;
|
|
469
|
+
}
|
|
470
|
+
case 'Literal': {
|
|
471
|
+
const value = expression.value;
|
|
472
|
+
if (value === null ||
|
|
473
|
+
typeof value === 'boolean' ||
|
|
474
|
+
(typeof value === 'number' && Number.isFinite(value))) {
|
|
475
|
+
return literal(value).node;
|
|
476
|
+
}
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
case 'UnaryExpression':
|
|
480
|
+
if (expression.operator === '!' || expression.operator === '-') {
|
|
481
|
+
return {
|
|
482
|
+
kind: 'unary',
|
|
483
|
+
operator: expression.operator === '!' ? 'not' : 'negate',
|
|
484
|
+
operand: lowerSQLExpression(expression.argument, parameters)
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
break;
|
|
488
|
+
case 'BinaryExpression': {
|
|
489
|
+
const operator = SQL_BINARY_OPERATORS[expression.operator];
|
|
490
|
+
if (operator) {
|
|
491
|
+
return {
|
|
492
|
+
kind: 'binary',
|
|
493
|
+
operator,
|
|
494
|
+
left: lowerSQLExpression(expression.left, parameters),
|
|
495
|
+
right: lowerSQLExpression(expression.right, parameters)
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
case 'CallExpression':
|
|
501
|
+
if (expression.arguments.length === 1 &&
|
|
502
|
+
(expression.callee['name'] === 'isNull' || expression.callee['name'] === 'isNotNull')) {
|
|
503
|
+
return {
|
|
504
|
+
kind: 'unary',
|
|
505
|
+
operator: expression.callee['name'] === 'isNull' ? 'is-null' : 'is-valid',
|
|
506
|
+
operand: lowerSQLExpression(expression.arguments[0], parameters)
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
break;
|
|
493
510
|
default:
|
|
494
|
-
|
|
511
|
+
break;
|
|
495
512
|
}
|
|
513
|
+
throw new Error(`GPUSQL does not support SQL expression "${expression.type}"`);
|
|
496
514
|
}
|
|
497
515
|
//# sourceMappingURL=gpu-sql.js.map
|