Repository navigation
Conversation
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.walk(fn)andequals(other)are written once onNodeand read those lists. They are used in three places.findAggregatoris one method onNodethat 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 withcollectAggregate(). An aggregate registers itself there. A subquery, anOVERclause and the list ofIN,ALL,ANYandSOMEkeep what is inside them, as before.equals()says they are the same expression. Before, they shared when theirtoString()text was the same.equals()incompileSelectGroup2. 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
expressionKeyin every branch ofdecartes(src/select/rollup.js). The branch for a function directly insideCUBEorGROUPING SETSmade its own key, and it is removed.FuncValue,CaseValue,ConvertandJsonwere constructor functions and are classes now.Select,Join,Apply,OverandExistsValueextendNodetoo, 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 haveb= x, y, x.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}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}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}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 ?withs= a%b, a!b, a!b{x: 2, y: 2}{x: 2, y: 1}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]}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}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'}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'}SELECT ARRAY[SUM(a), MAX(a)] AS x FROM ?g is not defined{x: [4, 2]}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]}SELECT 'x' LIKE 'x' ESCAPE MAX(s) AS x FROM ?g is not defined{}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}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}SELECT CONCAT(b,'z') AS k, COUNT(*) AS n FROM ? GROUP BY CUBE(CONCAT(b,'z')){k: null, n: 3}, {k: 'xz', n: 2}, {k: 'yz', n: 1}SELECT CONCAT(b,'z') AS k, COUNT(*) AS n FROM ? GROUP BY GROUPING SETS(CONCAT(b,'z')){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
CUBEandGROUPING SETSover a function that has a string literal. They follow from usingexpressionKeyin every branch, and they now answer asROLLUPand a plain GROUP BY over the same function already do on main.What stays the same
toString()is not touched, so the 4.20.1 names that Restore 4.20.1 behaviour for multi-character ESCAPE and the names of LIKE ... ESCAPE and ARRAY[...] columns #2750 restored stay.SELECT s LIKE 'a!%%' ESCAPE '!' FROM ?still names its columns LIKE 'a!%%',SELECT ARRAY[1, 2] FROM ?stillARRAY[], and(a + 1)anda + 1keep their own names. Test L oftest/test2723.jsholds this.IN (...)is not registered, as before. Registering it changedSELECT a IN (SUM(a), 1) AS x FROM ?from three rows to one row without a value, which is not a fix. It can follow IN and NOT IN ignore list items that are not plain literals: a IN (-1, 5) misses -1 #2874.(a+1)*2withGROUP BY a+1), and the same in HAVING and ORDER BY, are not matched. That is GROUP BY: group keys as slots matched by structure, one aggregate interface and one partitioning step #2722.db.table. Those are thebindsteps of Expressions: identity by text and column lookup while generating code #2723.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.
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 withGROUP BY k % 2or 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)
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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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}]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
SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2r['(k % 2)']=g['k % 2'];SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 HAVING SUM(gb.num) > 0r['(k % 2)']=g['k % 2'];SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 HAVING COUNT(*) > 1r['(k % 2)']=g['k % 2'];SELECT (k % 2), COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY k % 2 ORDER BY k % 2r['(k % 2)']=g['k % 2'];SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2)r['k % 2']=g['(k % 2)'];SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) HAVING SUM(gb.num) > 0r['k % 2']=g['(k % 2)'];SELECT k % 2, COUNT(*), SUM(gb.num) FROM gb WHERE gb.id < 0 GROUP BY (k % 2) HAVING COUNT(*) > 1r['k % 2']=g['(k % 2)'];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'];orr['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.jsreads 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 give46316.50089123843where the reference has46316.500890856485.test/parity/README.mddescribes this for a build with another number of tests.API snapshot. 272 paths differ, all on purpose, and
test/parity/api-allowed.txtlists them with the reason.findAggregatormethods of the node classes, whichNodenow holds, and the paths below three of them.alasql.yy.Nodewith its methods, thechildrenandfieldslists of the node classes with every item of each list, and the methodscollectAggregate,sameFields,sameChildrenandbareon the classes that have their own.Node, soX.lengthis 0 where it was 1 (new yy.X(params)works as before), and the prototypes ofCaseValue,Convert,FuncValueandJsonare class prototypes.All 272 paths
Sizes.
alasql.fs.js940,842 to 945,451 bytes (0.49%),alasql.min.js536,987 to 539,309 bytes (0.43%), gzip 119,349 to 120,489.Dialect test
test/dialect/expected-differencesloses 14 entries that now give SQLite's answer, and 2 entries get the new alasql answer (... GROUP BY k % 2 ORDER BY k % 2with parentheses on one side, which now answers as the form without parentheses does).bun test/dialect/run.jsreports 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 themCUBEandGROUPING SETSover a function that has a string literal. The other two hold what already worked.test/test2723.js, 13 tests forequals(),walk(), shared aggregates and the kept names. 10 fail on main and pass here.yarn testgives 2716 pass, 213 skip, 0 fail. Main gives 2691 pass, 213 skip, 0 fail.Notes for the review
Op.children = [...]), not with thestatic 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 reachdistas written, where the newest syntax today is?.. It is a one-line change per class if you prefer the syntax.FuncValue,CaseValue,ConvertandJsonkeep 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.txtgrows by 209 lines, because the snapshot lists every item of a list and a listed path covers only its prototype and constructor.bind, at first only to resolvedb.table(Review #2201 for code improvements: each statement resolves db.table on its own #2705), as its own pull request.