Skip to content

Read qualified columns from their own table in grouped expressions to close #2637 - #3016

Open
mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2637-group-qualified-column
Open

mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2637-group-qualified-column

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Closes #2637

What was wrong

GROUP BY a.id, b.id stores both keys under g['id']. Column.toJS in the group context read g['id'] for a column without a nick. So a.id inside an expression got the value of b.id.

What changed

In the group context, a table-qualified column without a nick now reads its own table from the group's source row (this.groupSources), which every group already keeps. When g holds null for the key, as in ROLLUP and CUBE subtotal rows, it still returns that null. Unqualified columns are unchanged.

Tests

test/test2637.js covers the issue query, the case with only one column in an expression, the same column in HAVING, and a ROLLUP subtotal. The first three fail without the fix. test/test536-B.js still passes.

yarn test-only gives 2555 pass. The only failures are the 5 Test 418 cases that load files from the internet.

Not in this PR

SELECT a.id AS x FROM a JOIN b ON a.k = b.k GROUP BY a.id, b.id (a plain column, alone in the SELECT) still returns b.id. It goes through another code path. I can open a separate issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GROUP BY a.id, b.id: a.id inside an expression reads b.id

2 participants