Skip to content

Decide the result columns of a SELECT in one function to close #2651 - #3211

Open
mathiasrw wants to merge 2 commits into
mainfrom
fix/2651
Open

mathiasrw wants to merge 2 commits into
mainfrom
fix/2651

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Closes #2651

modify() in src/select/select.js no longer works out the columns of a result itself. It calls the new resultColumns(run, rows) once, and every modifier reads that list. The three branches are now three lines, and the loop over the first columnlookup rows is written once in namesInRows(). It keeps reading the rows from the last to the first, as that decides the order of the names. The function is exported as internal.resultColumns.

Branch 1 returns a new list instead of pushing into run.columns. The order is the same, and nothing reads run.columns after modify(), since INTO gets its columns earlier in queryfn.

The new test/test2651.js pins the column lists of RECORDSET, ALASQL_DETAILS, MATRIX and COLUMN for each case the issue names (A to G), and for PIVOT over ? (I). All of them pass on main before the change. Test H pins the one difference and fails on main.

Differences

The parity check shows only the two results of test H.

With * and a named column over ?, a key named like a built-in method, such as constructor, valueOf, toString or hasOwnProperty, was left out of the columns. RECORDSET, ALASQL_DETAILS and MATRIX change. The merge now uses a Set of the names as strings. Turning them into strings keeps one thing from the old code, as PIVOT gives numbers as column names and the rows have them as strings. Test I pins that PIVOT over ? names each column once.

alasql('SELECT RECORDSET *, 1 AS c FROM ?', [[{constructor: 5, a: 1}]]).columns;
// before   c, a
// after    c, constructor, a
alasql('SELECT MATRIX *, 1 AS c FROM ?', [[{constructor: 5, a: 1}]]);
// before   [[1, 1]]
// after    [[1, 5, 1]]

Checks

  • Full suite passes with 3076 pass, 211 skip and 0 fail.
  • The parity check against de6b53f shows only the two results of test H. The size of alasql.min.js goes down by 111 bytes.
  • The run-state check, the binding check and the dialect test pass with all cases as expected.

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.

Decide the result columns of a SELECT in one function and let modify() read them from it

1 participant