From 8a71b16ac6c423d71e7e475a4383dc0146083df6 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 19 Apr 2024 11:51:10 -0700 Subject: [PATCH 1/4] make all array kinds nillable --- client/normal_nil.go | 8 ++++---- client/schema_field_description.go | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/normal_nil.go b/client/normal_nil.go index 7513fa9979..658095eba1 100644 --- a/client/normal_nil.go +++ b/client/normal_nil.go @@ -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: return NewNormalBoolNillableArray(immutable.None[[]bool]()), nil - case FieldKind_NILLABLE_INT_ARRAY: + case FieldKind_INT_ARRAY, FieldKind_NILLABLE_INT_ARRAY: return NewNormalIntNillableArray(immutable.None[[]int64]()), nil - case FieldKind_NILLABLE_FLOAT_ARRAY: + case FieldKind_FLOAT_ARRAY, FieldKind_NILLABLE_FLOAT_ARRAY: return NewNormalFloatNillableArray(immutable.None[[]float64]()), nil - case FieldKind_NILLABLE_STRING_ARRAY: + case FieldKind_STRING_ARRAY, FieldKind_NILLABLE_STRING_ARRAY: return NewNormalStringNillableArray(immutable.None[[]string]()), nil default: return nil, NewCanNotMakeNormalNilFromFieldKind(kind) diff --git a/client/schema_field_description.go b/client/schema_field_description.go index 7f945e3ab8..d1f6c95778 100644 --- a/client/schema_field_description.go +++ b/client/schema_field_description.go @@ -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 || + k == FieldKind_INT_ARRAY || + k == FieldKind_FLOAT_ARRAY || + k == FieldKind_STRING_ARRAY || + k == FieldKind_NILLABLE_BOOL_ARRAY || k == FieldKind_NILLABLE_INT_ARRAY || k == FieldKind_NILLABLE_FLOAT_ARRAY || k == FieldKind_NILLABLE_STRING_ARRAY From 26905680b67684da3e675bc1f30fad3599f2dc59 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 19 Apr 2024 12:10:38 -0700 Subject: [PATCH 2/4] simplify ScalarArrayKind IsNillable --- client/schema_field_description.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/client/schema_field_description.go b/client/schema_field_description.go index d1f6c95778..cacfd5ddb2 100644 --- a/client/schema_field_description.go +++ b/client/schema_field_description.go @@ -154,14 +154,7 @@ func (k ScalarArrayKind) Underlying() string { } func (k ScalarArrayKind) IsNillable() bool { - return k == FieldKind_BOOL_ARRAY || - k == FieldKind_INT_ARRAY || - k == FieldKind_FLOAT_ARRAY || - k == FieldKind_STRING_ARRAY || - k == FieldKind_NILLABLE_BOOL_ARRAY || - k == FieldKind_NILLABLE_INT_ARRAY || - k == FieldKind_NILLABLE_FLOAT_ARRAY || - k == FieldKind_NILLABLE_STRING_ARRAY + return true } func (k ScalarArrayKind) IsObject() bool { From d1737e065578dbfede460d11f2fc220c8f25e530 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 19 Apr 2024 13:12:27 -0700 Subject: [PATCH 3/4] add TestArrayValue_IsNillable --- client/normal_value_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client/normal_value_test.go b/client/normal_value_test.go index 75e858b056..33cd20c46e 100644 --- a/client/normal_value_test.go +++ b/client/normal_value_test.go @@ -1622,3 +1622,28 @@ func TestNormalValue_ToArrayOfNormalValues(t *testing.T) { }) } } + +// 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) { + fieldKinds := []FieldKind{ + FieldKind_BOOL_ARRAY, + FieldKind_INT_ARRAY, + FieldKind_FLOAT_ARRAY, + FieldKind_STRING_ARRAY, + FieldKind_NILLABLE_BOOL_ARRAY, + FieldKind_NILLABLE_INT_ARRAY, + FieldKind_NILLABLE_FLOAT_ARRAY, + FieldKind_NILLABLE_STRING_ARRAY, + } + + for _, kind := range fieldKinds { + assert.True(t, kind.IsNillable()) + + v, err := NewNormalNil(kind) + require.NoError(t, err) + + assert.True(t, v.IsNil()) + } +} From 8a83889aeb131b067934d3c6560996ec8f115e3e Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 19 Apr 2024 14:58:35 -0700 Subject: [PATCH 4/4] use correct normal values for normal nil arrays --- client/normal_nil.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/normal_nil.go b/client/normal_nil.go index 658095eba1..7cd2df3f16 100644 --- a/client/normal_nil.go +++ b/client/normal_nil.go @@ -34,14 +34,22 @@ func NewNormalNil(kind FieldKind) (NormalValue, error) { return NewNormalNillableString(immutable.None[string]()), nil case FieldKind_NILLABLE_BLOB: return NewNormalNillableBytes(immutable.None[[]byte]()), nil - case FieldKind_BOOL_ARRAY, FieldKind_NILLABLE_BOOL_ARRAY: + case FieldKind_BOOL_ARRAY: return NewNormalBoolNillableArray(immutable.None[[]bool]()), nil - case FieldKind_INT_ARRAY, FieldKind_NILLABLE_INT_ARRAY: + case FieldKind_INT_ARRAY: return NewNormalIntNillableArray(immutable.None[[]int64]()), nil - case FieldKind_FLOAT_ARRAY, FieldKind_NILLABLE_FLOAT_ARRAY: + case FieldKind_FLOAT_ARRAY: return NewNormalFloatNillableArray(immutable.None[[]float64]()), nil - case FieldKind_STRING_ARRAY, FieldKind_NILLABLE_STRING_ARRAY: + case FieldKind_STRING_ARRAY: return NewNormalStringNillableArray(immutable.None[[]string]()), nil + case FieldKind_NILLABLE_BOOL_ARRAY: + return NewNormalNillableBoolNillableArray(immutable.None[[]immutable.Option[bool]]()), nil + case FieldKind_NILLABLE_INT_ARRAY: + return NewNormalNillableIntNillableArray(immutable.None[[]immutable.Option[int]]()), nil + case FieldKind_NILLABLE_FLOAT_ARRAY: + return NewNormalNillableFloatNillableArray(immutable.None[[]immutable.Option[float64]]()), nil + case FieldKind_NILLABLE_STRING_ARRAY: + return NewNormalNillableStringNillableArray(immutable.None[[]immutable.Option[string]]()), nil default: return nil, NewCanNotMakeNormalNilFromFieldKind(kind) }