Skip to content

Write the text of every expression from all of its parts, so unaliased column names are complete #2675

Open

Description

@mathiasrw

What happens today

Each expression node writes its own toString() by hand (src/expression/). That text is the name of an unaliased result column (src/select/columns.js). Parts that a toString() leaves out are missing from the name, so two different expressions can get the same name and the second overwrites the first in the result row.

alasql("SELECT a LIKE 'x!%' ESCAPE '!' FROM ?", [[{a: 'x%'}]]);
// [{"a LIKE 'x!%'": true}]

What to change

  1. Every node class prints every child slot it declares in static children (Op.children = ['left', 'right', 'right1', 'right2', 'escape'] and the others). Fix the gaps the round-trip test finds. Known ones are ESCAPE in LIKE and the elements of ARRAY[...].
  2. Print parentheses and spacing in one form, so that parsing the text again gives an equal node. Today NOT (a = 1 OR b = 2) prints NOT((a = 1 OR b = 2)) and a IS NOT NULL prints a IS NOT(NULL).
  3. The name of an unaliased expression column comes from this text through the one function that decides result columns (Decide the result columns of a SELECT in one function and let modify() read them from it #2651).

What stays the same

  • Results and aliased column names.
  • Unaliased column names change only where the old text left out a part or printed it in another form.

Done when

  • A new test file named after this issue has a round-trip test. For every SELECT the test suite parses, parse(toString(node)) equals node by structure (equals() on the base class).
  • It checks the column names of LIKE ... ESCAPE, ARRAY[...], NOT (...) and IS NOT NULL.
  • The tests of Keep ESCAPE in the text of a LIKE expression #2674 and Keep the elements of ARRAY[...] in its text #2691 are restored with the new names.
  • The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.

Depends on

#2651, #2647, #2660

Activity

  1. mathiasrw commented on Oct 20, 2026

    @mathiasrw
    MemberAuthor

    Another instance of the same pattern, found while reviewing #2195: each node lists its child expressions by hand in every walker, so a node with extra parts gets missed. Op.findAggregator did not walk right1 / right2 of BETWEEN until #2195 added it. One list of child expressions per node, used by toString(), findAggregator and the other walkers, would close this class with the toString() gaps.

  2. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    MemberAuthor

    2026-10-21: #2674 (ESCAPE in the text) and #2691 (ARRAY[...] elements in the text) changed the names of unaliased columns, which existing code may rely on, so they are reverted for 4.x in #2750 and come back in 5.0 with this issue. Their tests are in the reverted PRs.

  3. changed the title [-]Review #1197 for code improvements: toString() is used as the identity of an expression[/-] [+]Write the text of every expression from all of its parts, so unaliased column names are complete[/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions