- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.5k
Remove alias of sort key when PagingQueryProvider has sort key with alias and group by clause. #4743
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
base: main
Are you sure you want to change the base?
Conversation
        
          
                spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProcessor.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | Can you please edit your initial comment and explain the problem this PR addresses. I know you linked the previous PR in which the problem is explained, but since we might include this PR in the change log it would be better to have the problem explained here. Moreover, is this specific to MySQL only? | 
| @fmbenhassine Thank you for the comment. Using a table alias from a subquery in an outer query is not compliant with the ANSI SQL standard. Given this, it is likely that all DBMSs providing an implementation of  Since I'm not familiar with other DBMSs, I only created a test for MysqlPagingQueryProvider. | 
Signed-off-by: KyeongHoon Lee <[email protected]>
Signed-off-by: KyeongHoon Lee <[email protected]>
Remove table aliases of the sort keys when the PagingQueryProvider uses sort keys with table aliases and a GROUP BY clause. Signed-off-by: KyeongHoon Lee <[email protected]>
This reverts commit a851d71. Signed-off-by: KyeongHoon Lee <[email protected]>
| @fmbenhassine Hello!! I add some tests for MariaDB, PostgreSQL and SQLite. I executed query on those DBMSs running in Docker. I found implementations of PagingQueryProvider that call the method I modified: Db2PagingQueryProvider, DerbyPagingQueryProvider, HanaPagingQueryProvider, MariaDBPagingQueryProvider, MySqlPagingQueryProvider, PostgresPagingQueryProvider, and SqlitePagingQueryProvider. Among these, I have directly created tables and executed queries in all except Db2, Derby, and Hana | 
Signed-off-by: KyeongHoon Lee <[email protected]>
Hello.
Motivation
I tried to build a batch application.
Environment
Problem
I use MySqlPagingQueryProvider like below, and Query built by this provider only works for first page query.
(Because of sort key's alias)
provider.setSelectClause( """ SELECT t1.member_id AS member_id , t2.kyc_id AS kyc_id , SUM(t1.balance) AS total_balance """.trimIndent() ) provider.setFromClause( """ FROM cash_history t1 LEFT JOIN kyc t2 ON t1.member_id = t2.member_id """.trimIndent() ) provider.setWhereClause( """ WHERE t1.balance_year_month = '202412' AND kyc_id is NOT NULL """.trimIndent() ) provider.setGroupClause("GROUP BY t1.member_id") provider.setSortKeys(mapOf("t1.member_id" to Order.ASCENDING))Generated Remaining Query
This generated remaining query has order by clause with t1.memeber, and valid scope of t1 alias is in MAIN_QRY.
Solution