Skip to content
New issue

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

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

Already on GitHub? # to your account

Issue with Column Alias mapping to projection in R2dbcRepository Query #1757

Open
jaykakkad69 opened this issue Mar 27, 2024 · 0 comments
Open
Assignees
Labels
in: r2dbc Spring Data R2DBC status: waiting-for-triage An issue we've not yet triaged

Comments

@jaykakkad69
Copy link

Hi Team,

I have created this query in repository with appropriate java class for projection. When query is executed, i am getting null in walmartYearWeek.

@Query("""
           SELECT DISTINCT ON (com_yr_wk) com_yr_wk as walmart_year_week, com_start_date as walmart_week_start_date
           FROM calendar_meta
           WHERE calendar_date BETWEEN :startDate AND :endDate
           ORDER BY com_yr_wk
            """)
    Flux<WalmartCalendarWeek> findWalmartYearWeekDistinctByDateBetween(LocalDate startDate, LocalDate endDate);
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalmartCalendarWeek {

        Integer walmartYearWeek;
        LocalDate walmartWeekStartDate;
}

Then, i tried following query and class and now the value is coming as expected in walmarYearWeek.

@Query("""
           SELECT DISTINCT ON (com_yr_wk) com_yr_wk as walmar_year_week, com_start_date as walmart_week_start_date
           FROM calendar_meta
           WHERE calendar_date BETWEEN :startDate AND :endDate
           ORDER BY com_yr_wk
            """)
    Flux<WalmarCalendarWeek> findWalmarYearWeekDistinctByDateBetween(LocalDate startDate, LocalDate endDate);
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalmarCalendarWeek {

        Integer walmarYearWeek;
        LocalDate walmartWeekStartDate;
}

To conclude, walmart_year_week alias is not working but walmar_year_week or any other alias works

NOTE: Above issue is not there with org.springframework.boot:spring-boot-starter-parent:3.2.0.

I have created sample repo to reproduce this behaviour
https://github.com/jaykakkad69/r2dbc-demo

  • Added a data.sql file to create database and populate test data
  • There are two end points to test each query
  • Please change the credentials accordingly in PostgresConfiguration

Thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 27, 2024
@mp911de mp911de self-assigned this Apr 15, 2024
@schauder schauder added the in: r2dbc Spring Data R2DBC label Sep 25, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: r2dbc Spring Data R2DBC status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants