Skip to content

Give expression nodes one base class with walk() and equals() to close #2721 - #3088

Merged
mathiasrw merged 4 commits into
mainfrom
fix/2723
Nov 19, 2026
Merged

mathiasrw merged 4 commits into
mainfrom
fix/2723

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Closes #2721. Part of #2723. This is the first step named in that issue. It stops before bind.

What changes

Every expression node class now extends one base class, Node (src/expression/node.js), and says once what it is made of.

Op.children = ['left', 'right', 'right1', 'right2', 'escape']; // the slots that hold nodes
Op.fields = ['op', 'allsome']; // the values that say which node it is

walk(fn) and equals(other) are written once on Node and read those lists. They are used in three places.

  • findAggregator is one method on Node that walks the tree. The seven copies written by hand (Expression, Op, UniOp, AggrValue, FuncValue, CaseValue, Convert) are removed. A node tells the walk what to do at it with collectAggregate(). An aggregate registers itself there. A subquery, an OVER clause and the list of IN, ALL, ANY and SOME keep what is inside them, as before.
  • Two aggregates share one accumulator when equals() says they are the same expression. Before, they shared when their toString() text was the same.
  • A SELECT item is matched to a GROUP BY expression with equals() in compileSelectGroup2. Before, the two texts were compared. This is the fix for SELECT (a+1) ... GROUP BY a+1 drops the column #2721.

equals() compares the class, the fields and the children of two nodes, all the way down. Parentheses do not count. The name of a built-in function is compared in any case, as its text is today. A flag set to false is the same as a flag that is left out. An alias and what a compile step adds to a node (nick, queriesidx) are not part of it.

The key of a grouped expression is made by expressionKey in every branch of decartes (src/select/rollup.js). The branch for a function directly inside CUBE or GROUPING SETS made its own key, and it is removed.

FuncValue, CaseValue, Convert and Json were constructor functions and are classes now. Select, Join, Apply, Over and ExistsValue extend Node too, so that a walk can pass through them or stop at them.

Results that change

Measured on main (a06c64c) and on this branch (5716f61). The data is a = 1, 1, 2 unless the row says otherwise. Rows 12 to 15 also have b = x, y, x.

# Query main this PR
1 SELECT (a+1) AS x, COUNT(*) AS n FROM ? GROUP BY a+1 {n: 2}, {n: 1} {x: 2, n: 2}, {x: 3, n: 1}
2 SELECT a+1 AS x, COUNT(*) AS n FROM ? GROUP BY (a+1) {n: 2}, {n: 1} {x: 2, n: 2}, {x: 3, n: 1}
3 SELECT a+1 AS x, a+1 AS y, COUNT(*) AS n FROM ? GROUP BY a+1 {x: 2, n: 2}, {x: 3, n: 1} {x: 2, y: 2, n: 2}, {x: 3, y: 3, n: 1}
4 SELECT SUM(CASE WHEN s LIKE '%!%%' THEN 1 ELSE 0 END) AS x, SUM(CASE WHEN s LIKE '%!%%' ESCAPE '!' THEN 1 ELSE 0 END) AS y FROM ? with s = a%b, a!b, a!b {x: 2, y: 2} {x: 2, y: 1}
5 SELECT FIRST(ARRAY[1, 2]) AS x, FIRST(ARRAY[3, 4]) AS y FROM ? {x: [1, 2], y: [1, 2]} {x: [1, 2], y: [3, 4]}
6 SELECT SUM(CASE WHEN a = 1 THEN 1 ELSE 0 END) AS x, SUM(CASE WHEN a = 1 THEN 1 ELSE 10 END) AS y FROM ? {x: 2, y: 2} {x: 2, y: 12}
7 SELECT GROUP_CONCAT(a SEPARATOR '-') AS x, GROUP_CONCAT(a SEPARATOR '+') AS y FROM ? {x: '1-1-2', y: '1-1-2'} {x: '1-1-2', y: '1+1+2'}
8 SELECT GROUP_CONCAT(a ORDER BY a DESC) AS z, GROUP_CONCAT(a ORDER BY a ASC) AS w FROM ? {z: '2,1,1', w: '2,1,1'} {z: '2,1,1', w: '1,1,2'}
9 SELECT ARRAY[SUM(a), MAX(a)] AS x FROM ? error g is not defined {x: [4, 2]}
10 SELECT a, ARRAY[SUM(a)] AS x FROM ? GROUP BY a {a: 1, x: [null]}, {a: 2, x: [null]} {a: 1, x: [2]}, {a: 2, x: [2]}
11 SELECT 'x' LIKE 'x' ESCAPE MAX(s) AS x FROM ? error g is not defined {}
12 SELECT ARRAY[3,4] AS z, COUNT(*) AS n FROM ? GROUP BY ARRAY[1,2] {z: [1, 2], n: 3} {z: [3, 4], n: 3}
13 SELECT CASE WHEN a=1 THEN 1 ELSE 2 END AS c, COUNT(*) AS n FROM ? GROUP BY CASE WHEN a=1 THEN 1 ELSE 3 END {c: 1, n: 2}, {c: 3, n: 1} {c: 2, n: 2}, {c: 2, n: 1}
14 SELECT CONCAT(b,'z') AS k, COUNT(*) AS n FROM ? GROUP BY CUBE(CONCAT(b,'z')) error {k: null, n: 3}, {k: 'xz', n: 2}, {k: 'yz', n: 1}
15 SELECT CONCAT(b,'z') AS k, COUNT(*) AS n FROM ? GROUP BY GROUPING SETS(CONCAT(b,'z')) error {k: 'xz', n: 2}, {k: 'yz', n: 1}

Rows 1 and 2 are #2721. Row 3 is the same fault, as the second copy of an expression got a numbered name that matched no GROUP BY text. Rows 4 to 8 are aggregates that shared one result because their text leaves a part out. The text is not changed here, see the next section. Rows 9 to 11 are aggregates in a part of a node that no hand-written walker visited. The last row still has no value for x. That is what main answers when the same aggregate also stands in the SELECT list, so the error is gone and the answer is not yet right.

Rows 12 and 13 have an expression in SELECT that is not the one in GROUP BY. The two have the same text, so main gave the SELECT item the value of the GROUP BY expression. Here the SELECT item is no longer matched and is worked out on its own, as any other expression that is not grouped. Neither answer is one to rely on. Rows 14 and 15 are CUBE and GROUPING SETS over a function that has a string literal. They follow from using expressionKey in every branch, and they now answer as ROLLUP and a plain GROUP BY over the same function already do on main.

What stays the same

Parity check

Reference is main at a06c64c (4.23.2). Both builds were recorded with the same test files and two suite runs each. The two new test files were left out of that recording, so that every statement lines up.

bun test/parity/run.js record ref-main --ref a06c64c4
bun test/parity/run.js record tip
bun test/parity/run.js compare ref-main tip

files compared: 583; statements aligned: 78419; volatile (code only): 53; unstable in one build (code only): 3; code reordered: 0
differences: result 16, error 0, params 0, code 24, only in a 0, only in b 0, diverged 0
api: 1672 paths; only in a: 0; only in b: 0; changed: 0; allowed differences: 272

The check was run again at 5716f61, after the two commits from the review, and the numbers are the same as at 43f72d2. No statement of the suite or the corpus has the form of rows 12 to 15, so they do not show here.

All differences are in 24 statements of the dialect corpus, and all 24 are the #2721 case, (k % 2) in SELECT with GROUP BY k % 2 or the other way round. In each of them the generated select function gets one more assignment and nothing else changes. 16 of them return another result. The other 8 read no rows, so only their code differs.

The 16 statements with another result (each also has the one added assignment)
# Statement main this PR
1 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY k % 2 [{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":2,"SUM(gb.num)":2}]
2 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY k % 2 HAVING SUM(gb.num) > 0 [{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":2,"SUM(gb.num)":2}]
3 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY k % 2 HAVING COUNT(*) > 1 [{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":2,"SUM(gb.num)":2}]
4 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY k % 2 ORDER BY k % 2 [{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":2,"SUM(gb.num)":2}]
5 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb GROUP BY k % 2 [{"(k % 2)":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2},{"(k % 2)":undefined,"COUNT(*)":1,"SUM(gb.num)":0}] [{"(k % 2)":1,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":0,"COUNT(*)":2,"SUM(gb.num)":2},{"(k % 2)":undefined,"COUNT(*)":1,"SUM(gb.num)":0}]
6 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb GROUP BY k % 2 HAVING SUM(gb.num) > 0 [{"(k % 2)":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":0,"COUNT(*)":2,"SUM(gb.num)":2}]
7 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb GROUP BY k % 2 HAVING COUNT(*) > 1 [{"(k % 2)":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"(k % 2)":1,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":0,"COUNT(*)":2,"SUM(gb.num)":2}]
8 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb GROUP BY k % 2 ORDER BY k % 2 [{"(k % 2)":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":undefined,"COUNT(*)":2,"SUM(gb.num)":2},{"(k % 2)":undefined,"COUNT(*)":1,"SUM(gb.num)":0}] [{"(k % 2)":1,"COUNT(*)":4,"SUM(gb.num)":6},{"(k % 2)":0,"COUNT(*)":2,"SUM(gb.num)":2},{"(k % 2)":undefined,"COUNT(*)":1,"SUM(gb.num)":0}]
9 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY (k % 2) [{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":2,"SUM(gb.num)":2}]
10 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY (k % 2) HAVING SUM(gb.num) > 0 [{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":2,"SUM(gb.num)":2}]
11 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY (k % 2) HAVING COUNT(*) > 1 [{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":2,"SUM(gb.num)":2}]
12 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.k = 1 GROUP BY (k % 2) ORDER BY (k % 2) [{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":2,"SUM(gb.num)":2}]
13 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb GROUP BY (k % 2) [{"k % 2":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2},{"k % 2":undefined,"COUNT(*)":1,"SUM(gb.num)":0}] [{"k % 2":1,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":0,"COUNT(*)":2,"SUM(gb.num)":2},{"k % 2":undefined,"COUNT(*)":1,"SUM(gb.num)":0}]
14 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb GROUP BY (k % 2) HAVING SUM(gb.num) > 0 [{"k % 2":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":0,"COUNT(*)":2,"SUM(gb.num)":2}]
15 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb GROUP BY (k % 2) HAVING COUNT(*) > 1 [{"k % 2":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2}] [{"k % 2":1,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":0,"COUNT(*)":2,"SUM(gb.num)":2}]
16 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb GROUP BY (k % 2) ORDER BY (k % 2) [{"k % 2":undefined,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":undefined,"COUNT(*)":2,"SUM(gb.num)":2},{"k % 2":undefined,"COUNT(*)":1,"SUM(gb.num)":0}] [{"k % 2":1,"COUNT(*)":4,"SUM(gb.num)":6},{"k % 2":0,"COUNT(*)":2,"SUM(gb.num)":2},{"k % 2":undefined,"COUNT(*)":1,"SUM(gb.num)":0}]
The 8 statements where only the generated code differs
# Statement Added to the select function
17 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 r['(k % 2)']=g['k % 2'];
18 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 HAVING SUM(gb.num) > 0 r['(k % 2)']=g['k % 2'];
19 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 HAVING COUNT(*) > 1 r['(k % 2)']=g['k % 2'];
20 SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 ORDER BY k % 2 r['(k % 2)']=g['k % 2'];
21 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) r['k % 2']=g['(k % 2)'];
22 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) HAVING SUM(gb.num) > 0 r['k % 2']=g['(k % 2)'];
23 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) HAVING COUNT(*) > 1 r['k % 2']=g['(k % 2)'];
24 SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) ORDER BY (k % 2) r['k % 2']=g['(k % 2)'];

For statements 1 to 16 the added assignment is the same one, r['(k % 2)']=g['k % 2']; or r['k % 2']=g['(k % 2)'];.

With the two new test files in the recording there is one more difference, and it is not from the engine. test815.js reads an xlsx date cell that holds the time of the run, and the recorder's clock moves one step per statement, so more statements before it give 46316.50089123843 where the reference has 46316.500890856485. test/parity/README.md describes this for a build with another number of tests.

API snapshot. 272 paths differ, all on purpose, and test/parity/api-allowed.txt lists them with the reason.

  • 13 paths are gone. They are the seven findAggregator methods of the node classes, which Node now holds, and the paths below three of them.
  • 199 paths are new. They are alasql.yy.Node with its methods, the children and fields lists of the node classes with every item of each list, and the methods collectAggregate, sameFields, sameChildren and bare on the classes that have their own.
  • 60 paths changed. 28 classes take their constructor from Node, so X.length is 0 where it was 1 (new yy.X(params) works as before), and the prototypes of CaseValue, Convert, FuncValue and Json are class prototypes.
All 272 paths
only in a: alasql.yy.AggrValue.prototype.findAggregator
only in a: alasql.yy.CaseValue.prototype.findAggregator
only in a: alasql.yy.Convert.prototype.findAggregator
only in a: alasql.yy.Expression.prototype.findAggregator
only in a: alasql.yy.FuncValue.prototype.findAggregator
only in a: alasql.yy.Op.prototype.findAggregator
only in a: alasql.yy.UniOp.prototype.findAggregator
only in a: alasql.yy.CaseValue.prototype.findAggregator.prototype
only in a: alasql.yy.Convert.prototype.findAggregator.prototype
only in a: alasql.yy.FuncValue.prototype.findAggregator.prototype
only in a: alasql.yy.CaseValue.prototype.findAggregator.prototype.constructor
only in a: alasql.yy.Convert.prototype.findAggregator.prototype.constructor
only in a: alasql.yy.FuncValue.prototype.findAggregator.prototype.constructor
only in b: alasql.yy.Node
only in b: alasql.yy.AggrValue.children
only in b: alasql.yy.AggrValue.fields
only in b: alasql.yy.Apply.children
only in b: alasql.yy.Apply.fields
only in b: alasql.yy.ArrayValue.children
only in b: alasql.yy.CaseValue.children
only in b: alasql.yy.Column.fields
only in b: alasql.yy.Convert.children
only in b: alasql.yy.Convert.fields
only in b: alasql.yy.ExistsValue.children
only in b: alasql.yy.Expression.children
only in b: alasql.yy.Expression.fields
only in b: alasql.yy.ExpressionStatement.children
only in b: alasql.yy.FuncValue.children
only in b: alasql.yy.FuncValue.fields
only in b: alasql.yy.GroupExpression.children
only in b: alasql.yy.GroupExpression.fields
only in b: alasql.yy.JavaScript.fields
only in b: alasql.yy.Join.children
only in b: alasql.yy.Join.fields
only in b: alasql.yy.Json.children
only in b: alasql.yy.Literal.fields
only in b: alasql.yy.LogicValue.fields
only in b: alasql.yy.Node.children
only in b: alasql.yy.Node.fields
only in b: alasql.yy.Node.prototype
only in b: alasql.yy.NumValue.fields
only in b: alasql.yy.Op.children
only in b: alasql.yy.Op.fields
only in b: alasql.yy.OrderExpression.children
only in b: alasql.yy.OrderExpression.fields
only in b: alasql.yy.Over.children
only in b: alasql.yy.ParamValue.fields
only in b: alasql.yy.Select.children
only in b: alasql.yy.Select.fields
only in b: alasql.yy.StringValue.fields
only in b: alasql.yy.Table.fields
only in b: alasql.yy.UniOp.children
only in b: alasql.yy.UniOp.fields
only in b: alasql.yy.VarValue.fields
only in b: alasql.yy.View.fields
only in b: alasql.yy.AggrValue.children.0
only in b: alasql.yy.AggrValue.children.1
only in b: alasql.yy.AggrValue.children.2
only in b: alasql.yy.AggrValue.children.3
only in b: alasql.yy.AggrValue.children.length
only in b: alasql.yy.AggrValue.fields.0
only in b: alasql.yy.AggrValue.fields.1
only in b: alasql.yy.AggrValue.fields.2
only in b: alasql.yy.AggrValue.fields.length
only in b: alasql.yy.AggrValue.prototype.collectAggregate
only in b: alasql.yy.AggrValue.prototype.sameFields
only in b: alasql.yy.Apply.children.0
only in b: alasql.yy.Apply.children.length
only in b: alasql.yy.Apply.fields.0
only in b: alasql.yy.Apply.fields.1
only in b: alasql.yy.Apply.fields.length
only in b: alasql.yy.ArrayValue.children.0
only in b: alasql.yy.ArrayValue.children.length
only in b: alasql.yy.CaseValue.children.0
only in b: alasql.yy.CaseValue.children.1
only in b: alasql.yy.CaseValue.children.2
only in b: alasql.yy.CaseValue.children.length
only in b: alasql.yy.Column.fields.0
only in b: alasql.yy.Column.fields.1
only in b: alasql.yy.Column.fields.2
only in b: alasql.yy.Column.fields.3
only in b: alasql.yy.Column.fields.length
only in b: alasql.yy.Convert.children.0
only in b: alasql.yy.Convert.children.length
only in b: alasql.yy.Convert.fields.0
only in b: alasql.yy.Convert.fields.1
only in b: alasql.yy.Convert.fields.2
only in b: alasql.yy.Convert.fields.3
only in b: alasql.yy.Convert.fields.length
only in b: alasql.yy.ExistsValue.children.0
only in b: alasql.yy.ExistsValue.children.length
only in b: alasql.yy.Expression.children.0
only in b: alasql.yy.Expression.children.1
only in b: alasql.yy.Expression.children.length
only in b: alasql.yy.Expression.fields.0
only in b: alasql.yy.Expression.fields.1
only in b: alasql.yy.Expression.fields.2
only in b: alasql.yy.Expression.fields.length
only in b: alasql.yy.ExpressionStatement.children.0
only in b: alasql.yy.ExpressionStatement.children.length
only in b: alasql.yy.FuncValue.children.0
only in b: alasql.yy.FuncValue.children.1
only in b: alasql.yy.FuncValue.children.length
only in b: alasql.yy.FuncValue.fields.0
only in b: alasql.yy.FuncValue.fields.length
only in b: alasql.yy.FuncValue.prototype.sameFields
only in b: alasql.yy.GroupExpression.children.0
only in b: alasql.yy.GroupExpression.children.length
only in b: alasql.yy.GroupExpression.fields.0
only in b: alasql.yy.GroupExpression.fields.length
only in b: alasql.yy.JavaScript.fields.0
only in b: alasql.yy.JavaScript.fields.length
only in b: alasql.yy.Join.children.0
only in b: alasql.yy.Join.children.1
only in b: alasql.yy.Join.children.2
only in b: alasql.yy.Join.children.3
only in b: alasql.yy.Join.children.4
only in b: alasql.yy.Join.children.5
only in b: alasql.yy.Join.children.length
only in b: alasql.yy.Join.fields.0
only in b: alasql.yy.Join.fields.1
only in b: alasql.yy.Join.fields.2
only in b: alasql.yy.Join.fields.3
only in b: alasql.yy.Join.fields.4
only in b: alasql.yy.Join.fields.length
only in b: alasql.yy.Json.children.0
only in b: alasql.yy.Json.children.length
only in b: alasql.yy.Literal.fields.0
only in b: alasql.yy.Literal.fields.1
only in b: alasql.yy.Literal.fields.length
only in b: alasql.yy.LogicValue.fields.0
only in b: alasql.yy.LogicValue.fields.length
only in b: alasql.yy.Node.children.length
only in b: alasql.yy.Node.fields.length
only in b: alasql.yy.Node.prototype.bare
only in b: alasql.yy.Node.prototype.collectAggregate
only in b: alasql.yy.Node.prototype.constructor
only in b: alasql.yy.Node.prototype.eachChild
only in b: alasql.yy.Node.prototype.equals
only in b: alasql.yy.Node.prototype.findAggregator
only in b: alasql.yy.Node.prototype.sameChildren
only in b: alasql.yy.Node.prototype.sameFields
only in b: alasql.yy.Node.prototype.walk
only in b: alasql.yy.NumValue.fields.0
only in b: alasql.yy.NumValue.fields.length
only in b: alasql.yy.Op.children.0
only in b: alasql.yy.Op.children.1
only in b: alasql.yy.Op.children.2
only in b: alasql.yy.Op.children.3
only in b: alasql.yy.Op.children.4
only in b: alasql.yy.Op.children.length
only in b: alasql.yy.Op.fields.0
only in b: alasql.yy.Op.fields.1
only in b: alasql.yy.Op.fields.length
only in b: alasql.yy.Op.prototype.collectAggregate
only in b: alasql.yy.OrderExpression.children.0
only in b: alasql.yy.OrderExpression.children.length
only in b: alasql.yy.OrderExpression.fields.0
only in b: alasql.yy.OrderExpression.fields.1
only in b: alasql.yy.OrderExpression.fields.2
only in b: alasql.yy.OrderExpression.fields.length
only in b: alasql.yy.Over.children.0
only in b: alasql.yy.Over.children.1
only in b: alasql.yy.Over.children.length
only in b: alasql.yy.Over.prototype.collectAggregate
only in b: alasql.yy.ParamValue.fields.0
only in b: alasql.yy.ParamValue.fields.length
only in b: alasql.yy.ParamValue.prototype.sameFields
only in b: alasql.yy.Select.children.0
only in b: alasql.yy.Select.children.1
only in b: alasql.yy.Select.children.10
only in b: alasql.yy.Select.children.11
only in b: alasql.yy.Select.children.12
only in b: alasql.yy.Select.children.13
only in b: alasql.yy.Select.children.14
only in b: alasql.yy.Select.children.15
only in b: alasql.yy.Select.children.16
only in b: alasql.yy.Select.children.17
only in b: alasql.yy.Select.children.18
only in b: alasql.yy.Select.children.2
only in b: alasql.yy.Select.children.3
only in b: alasql.yy.Select.children.4
only in b: alasql.yy.Select.children.5
only in b: alasql.yy.Select.children.6
only in b: alasql.yy.Select.children.7
only in b: alasql.yy.Select.children.8
only in b: alasql.yy.Select.children.9
only in b: alasql.yy.Select.children.length
only in b: alasql.yy.Select.fields.0
only in b: alasql.yy.Select.fields.1
only in b: alasql.yy.Select.fields.2
only in b: alasql.yy.Select.fields.3
only in b: alasql.yy.Select.fields.4
only in b: alasql.yy.Select.fields.5
only in b: alasql.yy.Select.fields.length
only in b: alasql.yy.Select.prototype.collectAggregate
only in b: alasql.yy.Select.prototype.sameChildren
only in b: alasql.yy.StringValue.fields.0
only in b: alasql.yy.StringValue.fields.length
only in b: alasql.yy.Table.fields.0
only in b: alasql.yy.Table.fields.1
only in b: alasql.yy.Table.fields.length
only in b: alasql.yy.UniOp.children.0
only in b: alasql.yy.UniOp.children.length
only in b: alasql.yy.UniOp.fields.0
only in b: alasql.yy.UniOp.fields.length
only in b: alasql.yy.UniOp.prototype.bare
only in b: alasql.yy.VarValue.fields.0
only in b: alasql.yy.VarValue.fields.length
only in b: alasql.yy.View.fields.0
only in b: alasql.yy.View.fields.1
only in b: alasql.yy.View.fields.length
changed: alasql.yy.AggrValue: function/1 -> function/0
changed: alasql.yy.Apply: function/1 -> function/0
changed: alasql.yy.ArrayValue: function/1 -> function/0
changed: alasql.yy.CaseValue: function/1 -> function/0
changed: alasql.yy.Column: function/1 -> function/0
changed: alasql.yy.Convert: function/1 -> function/0
changed: alasql.yy.DomainValueValue: function/1 -> function/0
changed: alasql.yy.ExistsValue: function/1 -> function/0
changed: alasql.yy.Expression: function/1 -> function/0
changed: alasql.yy.ExpressionStatement: function/1 -> function/0
changed: alasql.yy.FuncValue: function/1 -> function/0
changed: alasql.yy.GroupExpression: function/1 -> function/0
changed: alasql.yy.JavaScript: function/1 -> function/0
changed: alasql.yy.Join: function/1 -> function/0
changed: alasql.yy.Json: function/1 -> function/0
changed: alasql.yy.Literal: function/1 -> function/0
changed: alasql.yy.LogicValue: function/1 -> function/0
changed: alasql.yy.NullValue: function/1 -> function/0
changed: alasql.yy.NumValue: function/1 -> function/0
changed: alasql.yy.OrderExpression: function/1 -> function/0
changed: alasql.yy.Over: function/1 -> function/0
changed: alasql.yy.ParamValue: function/1 -> function/0
changed: alasql.yy.Select: function/1 -> function/0
changed: alasql.yy.StringValue: function/1 -> function/0
changed: alasql.yy.Table: function/1 -> function/0
changed: alasql.yy.UniOp: function/1 -> function/0
changed: alasql.yy.VarValue: function/1 -> function/0
changed: alasql.yy.View: function/1 -> function/0
changed: alasql.yy.CaseValue.prototype: object -> CaseValue
changed: alasql.yy.Convert.prototype: object -> Convert
changed: alasql.yy.FuncValue.prototype: object -> FuncValue
changed: alasql.yy.Json.prototype: object -> Json
changed: alasql.yy.AggrValue.prototype.constructor: function/1 = alasql.yy.AggrValue -> function/0 = alasql.yy.AggrValue
changed: alasql.yy.Apply.prototype.constructor: function/1 = alasql.yy.Apply -> function/0 = alasql.yy.Apply
changed: alasql.yy.ArrayValue.prototype.constructor: function/1 = alasql.yy.ArrayValue -> function/0 = alasql.yy.ArrayValue
changed: alasql.yy.CaseValue.prototype.constructor: function/1 = alasql.yy.CaseValue -> function/0 = alasql.yy.CaseValue
changed: alasql.yy.Column.prototype.constructor: function/1 = alasql.yy.Column -> function/0 = alasql.yy.Column
changed: alasql.yy.Convert.prototype.constructor: function/1 = alasql.yy.Convert -> function/0 = alasql.yy.Convert
changed: alasql.yy.DomainValueValue.prototype.constructor: function/1 = alasql.yy.DomainValueValue -> function/0 = alasql.yy.DomainValueValue
changed: alasql.yy.ExistsValue.prototype.constructor: function/1 = alasql.yy.ExistsValue -> function/0 = alasql.yy.ExistsValue
changed: alasql.yy.Expression.prototype.constructor: function/1 = alasql.yy.Expression -> function/0 = alasql.yy.Expression
changed: alasql.yy.ExpressionStatement.prototype.constructor: function/1 = alasql.yy.ExpressionStatement -> function/0 = alasql.yy.ExpressionStatement
changed: alasql.yy.FuncValue.prototype.constructor: function/1 = alasql.yy.FuncValue -> function/0 = alasql.yy.FuncValue
changed: alasql.yy.GroupExpression.prototype.constructor: function/1 = alasql.yy.GroupExpression -> function/0 = alasql.yy.GroupExpression
changed: alasql.yy.JavaScript.prototype.constructor: function/1 = alasql.yy.JavaScript -> function/0 = alasql.yy.JavaScript
changed: alasql.yy.Join.prototype.constructor: function/1 = alasql.yy.Join -> function/0 = alasql.yy.Join
changed: alasql.yy.Json.prototype.constructor: function/1 = alasql.yy.Json -> function/0 = alasql.yy.Json
changed: alasql.yy.Literal.prototype.constructor: function/1 = alasql.yy.Literal -> function/0 = alasql.yy.Literal
changed: alasql.yy.LogicValue.prototype.constructor: function/1 = alasql.yy.LogicValue -> function/0 = alasql.yy.LogicValue
changed: alasql.yy.NullValue.prototype.constructor: function/1 = alasql.yy.NullValue -> function/0 = alasql.yy.NullValue
changed: alasql.yy.NumValue.prototype.constructor: function/1 = alasql.yy.NumValue -> function/0 = alasql.yy.NumValue
changed: alasql.yy.OrderExpression.prototype.constructor: function/1 = alasql.yy.OrderExpression -> function/0 = alasql.yy.OrderExpression
changed: alasql.yy.Over.prototype.constructor: function/1 = alasql.yy.Over -> function/0 = alasql.yy.Over
changed: alasql.yy.ParamValue.prototype.constructor: function/1 = alasql.yy.ParamValue -> function/0 = alasql.yy.ParamValue
changed: alasql.yy.Select.prototype.constructor: function/1 = alasql.yy.Select -> function/0 = alasql.yy.Select
changed: alasql.yy.StringValue.prototype.constructor: function/1 = alasql.yy.StringValue -> function/0 = alasql.yy.StringValue
changed: alasql.yy.Table.prototype.constructor: function/1 = alasql.yy.Table -> function/0 = alasql.yy.Table
changed: alasql.yy.UniOp.prototype.constructor: function/1 = alasql.yy.UniOp -> function/0 = alasql.yy.UniOp
changed: alasql.yy.VarValue.prototype.constructor: function/1 = alasql.yy.VarValue -> function/0 = alasql.yy.VarValue
changed: alasql.yy.View.prototype.constructor: function/1 = alasql.yy.View -> function/0 = alasql.yy.View

Sizes. alasql.fs.js 940,842 to 945,451 bytes (0.49%), alasql.min.js 536,987 to 539,309 bytes (0.43%), gzip 119,349 to 120,489.

Dialect test

test/dialect/expected-differences loses 14 entries that now give SQLite's answer, and 2 entries get the new alasql answer (... GROUP BY k % 2 ORDER BY k % 2 with parentheses on one side, which now answers as the form without parentheses does). bun test/dialect/run.js reports 46 failing entries on main and the same 46 on this branch. They are stale entries about subqueries in JOIN and HAVING and are left alone here.

Tests

  • test/test2721.js, 12 tests. 10 fail on main and pass here, among them CUBE and GROUPING SETS over a function that has a string literal. The other two hold what already worked.
  • test/test2723.js, 13 tests for equals(), walk(), shared aggregates and the kept names. 10 fail on main and pass here.
  • yarn test gives 2716 pass, 213 skip, 0 fail. Main gives 2691 pass, 213 skip, 0 fail.

Notes for the review

  • The lists are set after the class (Op.children = [...]), not with the static children = [...] syntax of the issue. The result is the same property. The class field syntax is ES2022 and the build has no target, so it would reach dist as written, where the newest syntax today is ?.. It is a one-line change per class if you prefer the syntax.
  • FuncValue, CaseValue, Convert and Json keep their methods as assignments to the prototype, to keep this diff small. They can move into the class body in a later step.
  • api-allowed.txt grows by 209 lines, because the snapshot lists every item of a list and a listed path covers only its prototype and constructor.
  • Speed was not benchmarked. The change is in compiling only. A rough check, not a benchmark, on a machine that was not quiet. 3,000 different grouped statements compiled and run once each on node 24, five runs per build. The median is 3,205 ms on main and 3,261 ms here, with one run of each above 4,000 ms.
  • Next is bind, at first only to resolve db.table (Review #2201 for code improvements: each statement resolves db.table on its own #2705), as its own pull request.

@mathiasrw mathiasrw added this to the v4.x Focus milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SELECT (a+1) ... GROUP BY a+1 drops the column

1 participant