[WIP] Fix if (liftQuery(set).isEmpty) #1559
Open
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 #1557
Progress
Problem
This is a PR aiming to fix
liftQueryScalar
which is currently broken.So the core issue we have is that is on expansion of reified liftings. Reifying a traversable liftings is done as so
More specifically
val liftings = values.map(v => ScalarLiftToken(ScalarValueLift(lift.name, v, lift.encoder)))
is the part that creates aList
ofScalarLiftToken
. Here is the current code expanding this reificationThe problem here occurs when you have a custom encoder for something traversable. The
ClassCastException
happens atencoder(idx, lift.value, row)
. We happen to be applying theencoder
to the collection rather than every element inside the collection.Solution
Unfortunately the solution isn't going to be nice. Either its going to be hacky but will work without any major changes, but in order to create a clean solution some major changes need to be done.
To clarify, the issue is we have no way to distinguish whether an
Encoder
should be used on the collection or an every element inside the collection when doing expansion. When doing the expansion we just have some genericEncoder
. If ourEncoder
happens to be a custom encoder than we typically do want to apply it on every element (linked issue describes this in more detail) however if its for already supported types (i.e. lets say aList
of ints) then we apply the encoder to the entire list. To compound the problem further, expansion is shared amongst all modules so it needs to be completely generic (so currently distinguishing between jdbc/postgres-async/cassandra etc is impossible at this point)From what I can see, the only way to solve without major changes is to catch a
ClassCastException
on the assumption we are hitting this case (custom encoder that needs to be applied on every element in the collection) and then if there is a problem here then we have to rethrow this sameClassCastException
Checklist
README.md
if applicable[WIP]
to the pull request title if it's work in progresssbt scalariformFormat test:scalariformFormat
to make sure that the source files are formatted@getquill/maintainers