spring-projects / spring-projects/spring-batch
JdbcPagingItemReader - Not able to provide table alias in the column name in the sortKeys [BATCH-2854]
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
Shakti Tripathy opened BATCH-2854 and commented
If a table alias is given along with the column name for a sort key e.g.
JdbcPagingItemReader reader = new JdbcPagingItemReader();
PostgresPagingQueryProvider provider = new PostgresPagingQueryProvider();
....
Map<String, Order> sortKeys = new HashMap<>();
sortKeys.put("mu.student_id", Order.ASCENDING);
provider.setSortKeys(sortKeys);
The code fails in JdbcPagingItemReader.PagingRowMapper
private class PagingRowMapper implements RowMapper<T> {
@Override
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
startAfterValues = new LinkedHashMap<>();
for (Map.Entry<String, Order> sortKey : queryProvider.getSortKeys().entrySet()) {
startAfterValues.put(sortKey.getKey(), rs.getObject(sortKey.getKey()));
}
return rowMapper.mapRow(rs, rowNum);
}
}
While its trying to get the column from resultset as mu.student_id, it fails. Can we remove any preceding aliases before the DOT(.) before pulling the column from the resultset.
The aliases are needed when using a join query.
Affects: 4.2.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with JdbcPagingItemReader.PagingRowMapper and the sort-key handling used by PostgresPagingQueryProvider. Trace how each sort-key name is passed to ResultSet, then verify that a qualified key such as mu.student_id still supports joined queries while retrieving the unqualified result-set column.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100