feat(core): accept the resolved reference paths when building a row mapper - #361
Merged
Conversation
…apper A statement that resolves references widens its select list, so the row mapper has to be built for that wider shape. The overload carrying the plan took the package-private FetchPlan, which no executor outside the package can name, so a third-party query executor could only build mappers for the declared shape and failed on the arity mismatch. Take the paths instead, in the form Sql.fetchPaths() already reports them, and keep FetchPlan internal.
There was a problem hiding this comment.
Pull request overview
This PR makes ObjectMapperFactory usable by out-of-tree query executors when a SELECT widens its row shape due to resolved reference paths (as reported by Sql.fetchPaths()), by exposing a public overload that accepts those paths directly.
Changes:
- Added a new public
ObjectMapperFactory.getObjectMapper(..., Collection<String> fetchPaths)overload that converts paths to aFetchPlan. - Demoted the
FetchPlanoverload to package-private (keeping in-package callers unchanged) and expanded Javadoc guidance for external callers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+95
to
+97
| @Nonnull Collection<String> fetchPaths) throws SqlTemplateException { | ||
| return getObjectMapper(columnCount, type, refFactory, FetchPlan.of(fetchPaths)); | ||
| } |
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.
Problem
select().fetch(...)widens the select list: a named reference is selected as the referenced table's columns rather than as its foreign key column. The row mapper has to be built for that wider shape, whichQueryImplandPreparedQueryImpldo by passing the plan derived fromSql.fetchPaths().The overload that carries the plan is public but takes
FetchPlan, which is package-private, so it is public in name only.st.orm.core.template.implis exported, so an out-of-tree query executor can reachObjectMapperFactory, but it cannot name that parameter type and is left with the three-argument overload, which resolves the mapper for the declared shape. Reading a fetching statement through such an executor then fails on the arity mismatch: the statement returns the wide row, the mapper is compiled for the narrow one, and no mapper matches the column count.Change
Publish an overload taking the paths themselves, in the form
Sql.fetchPaths()already reports them, and demote theFetchPlanoverload to package-private. Its callers,QueryImpl,PreparedQueryImplandObjectMapperFactoryTest, all sit in the package.The javadoc records the condition an external caller has to honour: the paths apply only when the rows are read back as the statement's own data type, since reading the same statement as anything else, a primary key for a ref stream in particular, consumes the columns by that type's own shape. That mirrors
QueryImpl.Environment.fetchPlanFor.Verification
ObjectMapperFactoryTest,FetchElementTest,FetchSizeTestandRefFetchIntegrationTestpass (50 tests). Behaviour of the in-tree executors is unchanged: they keep calling theFetchPlanoverload.