Skip to content

Commit

Permalink
Fix rendering of asterisk projection (table.*) for aliased tables.
Browse files Browse the repository at this point in the history
Closes #1651
Original pull request: #1662
  • Loading branch information
schauder authored and mp911de committed Nov 14, 2023
1 parent bb20c66 commit 9223e06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ Delegation enterMatched(Expression segment) {
} else {
value = segment.toString();
}
} else if (segment instanceof AsteriskFromTable) {
value = NameRenderer.render(context, ((AsteriskFromTable) segment).getTable()) + ".*";
} else if (segment instanceof AsteriskFromTable asteriskFromTable) {

TableLike table = asteriskFromTable.getTable();
CharSequence renderedTable;
if (table instanceof Aliased aliasedTable) {
renderedTable = NameRenderer.render(context, aliasedTable);
} else {
renderedTable = NameRenderer.render(context, table);
}
value = renderedTable + ".*";
} else if (segment instanceof Cast) {

CastVisitor visitor = new CastVisitor(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ void notOfNested() {
assertThat(sql).isEqualTo("SELECT atable.* FROM atable WHERE NOT (atable.id = 1 AND atable.id = 2)");
}

@Test // GH-1651
void asteriskOfAliasedTableUsesAlias() {

Table employee = SQL.table("employee").as("e");
Select select = Select.builder().select(employee.asterisk()).select(employee.column("id")).from(employee).build();

String rendered = SqlRenderer.toString(select);

assertThat(rendered).isEqualTo("SELECT e.*, e.id FROM employee e");
}

/**
* Tests the rendering of analytic functions.
*/
Expand Down

0 comments on commit 9223e06

Please sign in to comment.