-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat/sql null comparisons #20
base: main
Are you sure you want to change the base?
feat/sql null comparisons #20
Conversation
Hi @MiguelMJ I like your proposal, thanks a lot! But I don't understand why you need the code in I mean, If you added the UnaryPredicate, I think you should use it to compare if a column is null with the For example the "where" test could be: @Test
internal fun `build with null comparison`() {
where.predicates.add(tBook.pagesCount.isNull()) instead of your actual code @Test
internal fun `build with null comparison`() {
where.predicates.add(tBook.pagesCount.eq(null)) So, I would remove all the code: is BinaryPredicate<*> -> {
// val isNullRight = predicate.right is ParameterExpression && predicate.right.value == null
//
// if (isNullRight && predicate.operator == BinaryOperator.EQ) {
// appendPredicate(sb, UnaryPredicate(predicate.left, UnaryOperator.IS_NULL), parameters)
// } else if (isNullRight && predicate.operator == BinaryOperator.NE) {
// appendPredicate(sb, UnaryPredicate(predicate.left, UnaryOperator.IS_NOT_NULL), parameters)
// } else {
appendPredicate(sb, predicate.left, parameters)
sb.append(predicate.operator.sql)
appendPredicate(sb, predicate.right, parameters)
// }
} What do you think? Why did you add these code in the |
Hello! My reasoning was that when you have a nullable type In other words, it acts as a shortcut for Thank you for the review! |
Hi @MiguelMJ In this case, please, I prefer If you remove that code in the Thanks! |
Done ;) |
Currently, a predicate checking a null value like
myColumn.eq(null)
translates to the following SQL:which is valid SQL, but doesn't actually check if
my_column
is null.IS [NOT] NULL
is defined as a unary operator (1) so I implemented the correspondingUnaryOperator
class for them.SqlWhereBuilder
to translateEQ/NE
comparisons with a null value to aIS_NULL/IS_NOT_NULL
.