Skip to content
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

fix: Make all array kinds nillable #2534

Merged
merged 5 commits into from
Apr 20, 2024

Conversation

nasdf
Copy link
Member

@nasdf nasdf commented Apr 19, 2024

Relevant issue(s)

Resolves #2533

Description

This PR fixes a bug where ScalarArrayKind.IsNillable() returned an incorrect value for arrays of non-nillable values.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

make test

Specify the platform(s) on which this was tested:

  • MacOS

@nasdf nasdf added the bug Something isn't working label Apr 19, 2024
@nasdf nasdf added this to the DefraDB v0.11 milestone Apr 19, 2024
@nasdf nasdf self-assigned this Apr 19, 2024
@nasdf nasdf requested a review from a team April 19, 2024 19:04
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this :) Got a couple of todos for you though

@@ -154,7 +154,11 @@ func (k ScalarArrayKind) Underlying() string {
}

func (k ScalarArrayKind) IsNillable() bool {
return k == FieldKind_NILLABLE_BOOL_ARRAY ||
return k == FieldKind_BOOL_ARRAY ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: This could be simplified to return true.

@@ -154,7 +154,11 @@ func (k ScalarArrayKind) Underlying() string {
}

func (k ScalarArrayKind) IsNillable() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: Please add some integration tests that fail before the production code is fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure how the tests did not fail before. I'm still investigating, but I believe its because of encoding / decoding of []int{} vs nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a unit test, but I don't think an integration test can actually catch this problem due to the encoding I mentioned above.

Copy link
Contributor

@AndrewSisley AndrewSisley Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe its because of encoding / decoding of []int{} vs nil.

I think that might be another bug, client.validateFieldSchema does not appear to reject nil values for non-nillable fields. I'll create a new ticket, is kind of out of scope here if that is what was hiding this PR's bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nasdf nasdf requested a review from AndrewSisley April 19, 2024 20:17
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Keenan :)

// This test documents a bug where array values
// were not returning the correct value for IsNillable
// and were also not convertible to a normal nil kind.
func TestArrayValue_IsNillable(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I'm not sure that this is correct. Please wait before merging.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good here. I got mixed up because of us not updating the field kinds.

@@ -34,13 +34,13 @@ func NewNormalNil(kind FieldKind) (NormalValue, error) {
return NewNormalNillableString(immutable.None[string]()), nil
case FieldKind_NILLABLE_BLOB:
return NewNormalNillableBytes(immutable.None[[]byte]()), nil
case FieldKind_NILLABLE_BOOL_ARRAY:
case FieldKind_BOOL_ARRAY, FieldKind_NILLABLE_BOOL_ARRAY:
Copy link
Collaborator

@fredcarle fredcarle Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: This should be changed to

case FieldKind_BOOL_ARRAY:
    return NewNormalIntNillableArray(immutable.None[[]bool]()), nil
case FieldKind_NILLABLE_BOOL_ARRAY:
    return NewNormalNillableBoolNillableArray(immutable.None[[]immutable.Option[bool]]()), nil

and similarly for the other array types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spot :)

FieldKind_NILLABLE_BOOL_ARRAY,
FieldKind_NILLABLE_INT_ARRAY,
FieldKind_NILLABLE_FLOAT_ARRAY,
FieldKind_NILLABLE_STRING_ARRAY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: sorry, but I'm trying to figure out what this PR actually tries to achieve.
Looking at this test I'm a bit confused.
We have the following array types:

  1. FieldKind__ARRAY - NOT nillable array with NOT nillable elements
  2. FieldKind_NILLABLE__ARRAY - NOT nillable array with nillable elements
  3. FieldKind__NILLABLE_ARRAY - nillable array with NOT nillable elements
  4. FieldKind_NILLABLE__NILLABLE_ARRAY - nillable array with nillable elements
    At least this is how these different array kinds are supposed to be distinguished.

At the moment IsNillable on ScalarArrayKind return true IIRC only elements are nillable, but it's no ideal. I also planned to put some effort on this.

So please clarify which of those 4 types you are changing and how.

Copy link
Contributor

@AndrewSisley AndrewSisley Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a discord conversation around this, all the scalar arrays are nillable atm, the enum values are just stuck with the old names. e.g. FieldKind_INT_ARRAY is nillable, with non-nillable elements.

Copy link
Collaborator

@fredcarle fredcarle Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, FieldKind__ARRAY is a Nillable array with NOT nillable elements. That is where we all get confused. This needs to be fix. This PR ensures that things work as they should given the current naming.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FieldKind__NILLABLE_ARRAY and FieldKind_NILLABLE__NILLABLE_ARRAY don't exist at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like I missed this discord conversation. All right then

@nasdf nasdf merged commit 39286f1 into sourcenetwork:develop Apr 20, 2024
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array field kinds return incorrect value for IsNillable
4 participants