Skip to content

Query results: columns decided in several places and internal keys in result rows #2726

Open
0 of 3 issues completed

Description

@mathiasrw

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.

  1. 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], ...]}
  2. Output as functions of that shape. Modifiers (VALUE, ROW, COLUMN, MATRIX, INDEX, RECORDSET, TEXTSTRING) and INTO formats 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() in src/select/select.js read 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

Sub-issues

Sub-issues

0 of 3 Issues completed
Loading 3 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions