Repository navigation
Conversation
The sort key is a SQL column reference, not a result set column label: for a delimited identifier such as "A" or t."A", ResultSet.findColumn never matches because the quote characters are part of the lookup string. PostgreSQL does not lower case quoted identifiers, so lower casing the sort key would neither fix the lookup nor be safe for drivers that compare identifiers case sensitively. Resolve the configured sort key to a column label instead (unquoting the last identifier and preserving dots and spaces inside quotes) while keeping the configured key for restart checkpoints. A quoted key matches the exact label only, because a delimited identifier is case sensitive. An unquoted key with a qualifier matches a label ignoring case, and only when that match is unique. A plain unquoted key keeps the behavior of failing as soon as findColumn does, without a metadata scan. The lookup is a single pass, so a result set holding both id and "id" rejects the unquoted p.id key instead of silently binding it to the quoted column and dropping the rows read so far. Also fix the named parameter placeholder for such keys, which previously produced :_"A" and failed to parse. Scope is limited to identifiers delimited with ANSI double quotes. Backtick and bracket quoting are out of scope, because those databases may still compare quoted identifiers case insensitively. Resolves spring-projects#4641 Signed-off-by: Jinhui Kim <46351067+BDARJH@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4641
Summary
JdbcPagingItemReader.PagingRowMapper(getSortKeyLabel), dropping ANSI double-quote delimiters while preserving the case of the identifier and spaces inside it.startAfterValuesstays keyed by the original sort key for restart compatibility.rs.findColumn(key)to a label lookup overResultSetMetaData, rethrowing the originalSQLExceptionwhen the label is missing or duplicated. A single lookup decides the match: a quoted key matches the exact label only, because a delimited identifier is case sensitive, while an unquoted qualified key matches a label ignoring case and only when that match is unique. A plain unquoted key with no qualifier keeps themainbehavior of throwing as soon asfindColumnfails, without a metadata scan.idand"id"rejects an unquotedp.idsort key as ambiguous instead of silently binding it to the quoted column and dropping rows 3~5.:{...}) inAbstractSqlPagingQueryProvider.getSortKeyPlaceHolderwhen a sort key contains", preventingNamedParameterUtilsfrom splitting at the quote character on page 2+.Tests
JdbcPagingItemReaderSortKeyTests(H2) with the quoted sort key cases: reading with positional and named parameters, restarting with a qualified quoted key (p."A"), composite quoted keys with and without named parameters, a delimited identifier containing spaces (" A "), and a rejection ofselect p.id, p."id"with an unquotedp.idsort key.JdbcPagingItemReaderSortKeyLabelTestsunit tests for the label resolution, including outer whitespace,t."A"and a plain key.JdbcPagingItemReaderPostgresQuotedSortKeyIntegrationTests(Testcontainerspostgres:17.5) for a read with named parameters and a restart.AbstractSqlPagingQueryProviderSortKeyPlaceHolderTests, which covers the sort key placeholder once with a mockDataSource, so the dialect subclasses no longer start an embedded H2 database for it.Scope
") only. Identifiers delimited with backticks (MySQL) or brackets (SQL Server) are left out of scope and can be addressed in a follow-up, because those databases may still compare quoted identifiers case-insensitively, which this lookup assumes they do not.:{...}placeholder cannot contain},{or:, so sort keys with such characters are not supported there; they keep working with positional (?) parameters.Backport
main.findSortKeyColumnwas introduced onmain, so a6.0.xbackport needs a separate patch.Checklist
mainbranch and squashed commitsgit commit -s)