spring-projects / spring-projects/spring-batch

PagingQueryProvider improvements to query specific page

Open
#4,396 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: infrastructure status: waiting-for-reporter type: enhancement
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

In commit 220de61, the method generateJumpToItemQuery() was removed from PagingQueryProvider class, with the following message: "Remove un-used code for jump-to-item queries". Well, currently, Spring Cloud Data Flow invokes that method to generate the query for a specific page in the database, so they will be impacted when they upgrade to Spring Batch 5.

Anyway, what is now the expected usage to generate the query for remaining pages? I see no easy way to access to a random page (e.g. page 7). Should I call generateRemainingPagesQuery() repeteadly in streaming fashion? Note also that the Javadoc does not make that clear. In fact, the documentation for generateFirstPageQuery and generateRemainingPagesQuery is currently the same...

In Oracle, for example, the current implementation (OraclePagingQueryProvider) is based on legacy ROWNUM syntax, which is deprecated since Oracle 12c. More easily, OFFSET and FETCH clauses could be used (ANSI SQL 2016 compliant), and have a single method in PagingQueryProvider() to generate the query for the specific page. A similar solution could be applied in other databases too.

public class Oracle19PagingQueryProvider extends PagingQueryProvider {

	
	public String generatePageQuery(int itemIndex, int pageSize) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT ").append(this.getSelectClause());
		sql.append(" FROM ").append(this.getFromClause());
		sql.append(this.getWhereClause() == null ? "" : " WHERE " + this.getWhereClause());
		buildGroupByClause(sql);
		sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
		sql.append(" OFFSET ").append(itemIndex);
		sql.append(" ROWS FETCH NEXT ").append(pageSize).append(" ROWS ONLY");

		return sql.toString();
	}
	
	private void buildGroupByClause(StringBuilder sql) {
		if(StringUtils.hasText(getGroupClause())) {
			sql.append(" GROUP BY ");
			sql.append(getGroupClause());
		}
	}	
}

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 the PagingQueryProvider API, its generateFirstPageQuery and generateRemainingPagesQuery Javadocs, and the OraclePagingQueryProvider implementation. Compare the current paging behavior with Spring Cloud Data Flow's need to query a specific page, then define whether the API should support random-page queries and what the provider documentation must state.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, sql
Domain
backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.