Repository navigation
Refactor: Name the rules for an ambiguous and an unknown column beside the binding - #3112
Merged
Merged
Conversation
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.
Part of #2723, step 1 of letting the generated code read the binding. It does not close the issue, and no generated code reads anything new.
Why
bind.columnsays what a column reference refers to. In a few places 4.x reads something else, and queries rely on it. Before the generated code can read the binding, those readings have to be written down as rules, so that a later step keeps them and 5.0 can remove them one by one."The first table" turned out to mean three different things. With
t0(k, x),t1(k, v)andt2(k, v)joined in that order, the bare namevgives this today.SELECT v ...t1SELECT ABS(v) AS r ...undefined, a read oft0.vSELECT v, COUNT(*) AS n ... GROUP BY t0.kundefined, a read oft0.v... WHERE v > 0What changes
src/engine/bind.jsgets three 4.x rules andbind.read(ref, scope, place), which applies the rules of a place to a binding. Each rule has a comment that says what it keeps and which issue removes it.onlyTableundefinedfirstTablefirstWithColumnIn a plain expression an ambiguous name is an error in 4.x too, so there is no rule for it.
The names differ from my plan, which had a default-table, a per-row and a strict rule. The strict one is no 4.x rule, it is what the binding says, and the default-table rule was two rules with two different issues, so it is split.
The place is told by the code that compiles the reference, not guessed. The select list passes
'select'. The grouped select list (src/select/columns.js) and the arguments of a built-in function (src/functions/functions.js) set the place on the scope around their call and set it back. Everything else is'row'.Only in the test mode
As with the binding, nothing of this runs for a user. The two call sites read
Column.onBindonce and set the place only when it is set.Column.toJSand the select list callbind.readonly on the path that already requiredColumn.onBind. The scope carries nothing new. The place is a property that only the test mode writes.Column.onBindgets the 4.x reading as a ninth argument.The binding check
test/bind/now compares today's lookup with the binding after the rule of the place is applied. The list of known cases and the rules that read the SQL text with regular expressions are gone. The check fails on any difference, and on an error thrown bybind.columnor a rule.On this branch the suite compiles 5,669 column references inside a SELECT.
onlyTable(21 in a plain expression, 1 in a function, 1 in the select list)firstTable(12 in a function, 8 in a grouped select list)firstWithColumnTests
test/test2723-C.js, in the named databasetest2723C, pins today's results in the four places with the three tables above, and with two tables where the first one defines the name. It also pins the unknown column of the only table (WHERE nosuch IS NULL,ABS(nosuch)) and the HAVING alias (HAVING SUM(n) > 0). For each place it reads the binding and the 4.x reading throughColumn.onBind. The comment at the top says that these are today's results and not the ones 5.0 should give.Suite: 2751 pass, 213 skip, 0 fail. The run-state check gives an empty list and
yarn test-parserpasses.Compile time
With the test mode off. Microseconds for one
Select.compileof a parsed statement, the best of sixteen processes of 12 rounds of 300 compiles (twenty for the last two queries), with main and the PR taking turns. Node 24 and Bun 1.4.3.SELECT a, b, a + b AS c FROM ? WHERE a > ?The machine was under heavy load from other work (load average 35 to 98), so these numbers are weaker than the ones in #3108. The first two queries do not go through any changed line with the test mode off, and they move by as much as the last two, which do. In two runs of the last two queries the +6% was once on one and once on the other. I read the table as no measurable change. The code that a compile runs in addition is one read of
Column.onBindand atryandfinallyper built-in function call and per bare column of a grouped select list.Parity differences
From the parity job of this PR, against the base (f4a75e7) with the test files of this PR. 78,622 statements aligned in 589 files.
There is no difference to list.
Sizes:
alasql.fs.js954,074 to 957,663 bytes (+0.38%),alasql.min.js543,544 to 544,683 bytes (+0.21%), gzip +403 bytes on the minified file. About half of the added source is the comments of the rules.Supply chain
No change to
package.json, the lockfiles, the workflows, the grammar or the generated parser.The next step, not started
Step 2 of the plan: the grouped select list writes its code from
bind.read, with the lookup kept as the check in the other direction.