-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NativeParameterUtils doesn't support collection with nullable values #845
Comments
Have you seen |
Thanks @mp911de This is the abstract class that all other batching repositories inherit from:
And here is the code where we are binding parameters. This class is extended via our CoroutineCrudRepository.
In the sample code I found that this code is sending a batch of statements vs the more performant sending a list of tuples with a single statement. After posting it looks like I should be able to bind the collection of parameters into the single statement. Thoughts? On a follow up question: When looking at the bindStatement method I am trying to understand how to bind a List<Object[]> parameters. |
To what gets |
If I understand your question. The timeseries insert works perfectly fine unless there would be a null value parameter. For instance maybe there would be a timestep missing and we wanted to record the value as null ( not a valid scenario but for example purposes). The bind statement will delegate to the I was looking and it may be possible to create a BindMarkerFactory to handle this more gracefully than modifying the NamedParameterUtils class. |
I should have started with a simple example test.
In the first test everything works fine but in the second "testSaveNull" I get this exception. This seems to be an issue where bindNull should be invoked rather than bind.
|
Thanks for the detail. Have you tried wrapping your nullable values in listOf(
arrayOf(OffsetDateTime.now(), Parameters.in(R2dbcType.VARCHAR, "value1")),
arrayOf(OffsetDateTime.now(), Parameters.in(R2dbcType.VARCHAR, null))
) |
Ah yes, that works and is a much cleaner solution. Thanks Mark! |
We have a case where we are upserting large numbers of daily values into multiple tables. I am going to use a simple example of our timeseries history where we use the collection of tuples to upsert values into the history table.
I have benchmarked this using large collections and it is around 75% faster than our original batch insert multiple statements, however this only works with non null values.
If you need nulls like
suspend fun upsertReturningCount(tuples: List<Array<Any?>>)
the NamedParameterUtils class fails to check for null before calling bind. I created a hacky work around but would like advice.My solution was to override the NamedParamterUtils in my project and add the following bind function.
The issue I ran into was that I could not find a way to get the parameter's type so I created a hack class called NullableParameter.
My question: is there any way to check a nullable parameter type? I am assuming that this is not possible but if there was a formal way to pass a nullable parameter to the statement of tuples that would be pretty nice.
Been away from Java for a few years so please don't throw shade on my use of Optionals :)
The text was updated successfully, but these errors were encountered: