Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of asterisk projection (table.*) for aliased tables #1662

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1651-asterisk-aliased-table-SNAPSHOT</version>
</parent>

<properties>
Expand Down
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 @@ -635,6 +635,17 @@ void rendersAliasedExpression() {
.isEqualTo("SELECT table.name AS alias FROM table");
}

@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
Loading