Skip to content

Expressions: identity by text and column lookup while generating code #2723

Open
2 of 5 issues completed
Open

Description

@mathiasrw

Several bugs come from how expressions find what they refer to. Expression nodes compare and name themselves by their toString() text and list their children by hand in each function that walks them, and a column is matched to its table while the JavaScript is generated, partly by guessing. Each statement also looks up the database of db.table on its own.

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. Most of them go away as a result of the two changes, and the rest are fixed in the new structure.

  1. Node classes with declared children and one walker. Each expression class (Op, UniOp, Column, FuncValue, AggrValue and the others) lists its child slots once, for example static children = ['left', 'right', 'right1', 'right2', 'escape'] on Op. Walking the tree, comparing two expressions, hashing and printing are then written once on a shared base class, not by hand in each class and in each function that walks the tree, such as findAggregator. Two expressions are equal when their structure is equal, not when their text is.

  2. A bind step between parsing and code generation. bind(statement, db) runs once after parsing. It builds one scope per SELECT with its sources and a link to the outer SELECT, and records on each Column which source and which column it refers to. It also resolves each db.table once. Code generation then only reads what bind recorded, so Column.toJS writes p[source][column] without guessing, and statements no longer look up their database themselves.

Ground rules

Bugs traced to this

Sub-issues

Sub-issues

2 of 5 Issues completed
Loading 5 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