Repository navigation
Description
Several bugs come from how a query's result is shaped for output. The list of result columns is decided in more than one place, result rows carry internal keys that have to be removed before they are returned, and some output formats (INTO OBJECT(), SELECT INTO) change how the query itself is compiled.
What this issue is about
This issue asks for a change in structure, not for a fix of each bug listed below. The bugs show where the current structure fails, and they serve as test cases. Two changes.
-
One internal result shape. Every query produces its column list and its rows as tuples, with no internal keys in the rows. Helper values such as sort keys (
$$$0) and running aggregates (_SUM_x) are kept beside the rows, not inside them.{columns: [{name, type}], rows: [[v1, v2], ...]}
-
Output as functions of that shape. Modifiers (
VALUE,ROW,COLUMN,MATRIX,INDEX,RECORDSET,TEXTSTRING) andINTOformats only read the result. They no longer set flags in the compiler or in the query runner.modifiers.COLUMN = r => r.rows.map(t => t[0]); alasql.into.OBJECT = r => r.rows.map(t => nest(r.columns, t));
The column list is decided once, where the query is planned. Set operations (#2718) and ORDER BY (#2720) build on the tuples.
Before you start
This issue does not need the other areas, but it goes more smoothly after #2723, as the column list then comes from bound expressions.
Ground rules
- Results stay as in 4.x, including column names, column order and the shape of every modifier. Only the bugs a pull request names may change results.
- Small steps. A good first pull request makes
modify()insrc/select/select.jsread the columns from one function that decides them, with no change in behaviour. - Each pull request passes the full test suite and the parity check in
test/parity/against the build before it. - The code this touches moves to ES6 as part of the work, with tuples in place of rows with internal keys.
Bugs traced to this
- Columns decided in several places: Decide the result columns of a SELECT in one function and let modify() read them from it #2651
- Internal keys taking part in comparisons: INTERSECT, EXCEPT and UNION compare rows wrongly when both SELECTs have their own ORDER BY #2610, Remove order keys before comparing rows in a set operation to close #2610 #2611
- Output formats that reach into the compiler: Convert values for a typed column in one function, used by every write into a table #2659, Let modifiers and INTO formats only read the finished result #2699
Activity