-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Adding Support for json_populate_record
and jsonb_populate_record
#4325
Conversation
just for context the PR is for the issue #4216 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry to take that long to review this PR and I'm also sorry to bring up an issue, but it seems like the nullable bounds are not correct yet. I've added a more detailed comment in the specific location on how this can be fixed.
fn jsonb_populate_record< | ||
B: RecordOrNullableRecord + SingleValue, | ||
J: JsonbOrNullableJsonb + CombinedNullableValue<Jsonb, B> | ||
>(base: B, from_json: J) -> J::Out; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've played a bit around on the postgresql command line and it seems like the output type of this function is only null if both inputs are null. The CombineNullableValue
helper trait expresses a constraint that says "if one of the inputs is null the output is null", so that's slightly different. We need to have a similar trait, but with slightly different bounds. Essentially we need a new trait with the same structure, but that replace the usage of OneIsNullable
in the bounds with AllIsNullable
. The trait implementation of CombineNullableValue
is here:
diesel/diesel/src/pg/expression/expression_methods.rs
Lines 3698 to 3707 in a5f7548
impl<T, O, Out> CombinedNullableValue<O, Out> for T | |
where | |
T: SingleValue, | |
O: SingleValue, | |
T::IsNull: OneIsNullable<O::IsNull>, | |
<T::IsNull as OneIsNullable<O::IsNull>>::Out: MaybeNullableType<Out>, | |
<<T::IsNull as OneIsNullable<O::IsNull>>::Out as MaybeNullableType<Out>>::Out: SingleValue, | |
{ | |
type Out = <<T::IsNull as OneIsNullable<O::IsNull>>::Out as MaybeNullableType<Out>>::Out; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @weiznich ! This is great to know and really informative, I totally understand what needs to be done, I'll implement the required change are add the changes. and thanks for telling a good way to test the nullability, will definitely keep that in mind next time.
ed5c870
to
f10ddd3
Compare
I'm not sure if the naming convention is the best for the new Nullable Trait implementation. I think this will take care of Nullablility, but let me know if there is anything I might have missed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. This looks good beside the name of the new trait.
@@ -3726,4 +3726,19 @@ pub(in crate::pg) mod private { | |||
|
|||
impl<T> RecordOrNullableRecord for Record<T> {} | |||
impl<T> RecordOrNullableRecord for Nullable<Record<T>> {} | |||
|
|||
pub trait CombinedOneNullableValue<O, Out>: SingleValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this CombinedAllNullableValue
or something like that instead to transport that this only evaluates to Nullable
if all inputs are Nullable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @weiznich , sure I will change the name accordingly. And yes they allarenullable only returns nullable value when both values are null, completing the logic we need for this trait.
f10ddd3
to
bbf1ae2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update
Using the traits already defined and have written the test_cases with my understanding of the functions, but open to suggestions and learnings!