spring-projects / spring-projects/spring-batch

JdbcPagingItemReader - Not able to provide table alias in the column name in the sortKeys [BATCH-2854]

Open
#759 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: infrastructure status: waiting-for-triage type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.