tscottcoombes1 commented on code in PR #43555:
URL: https://github.com/apache/arrow/pull/43555#discussion_r1709985045


##########
go/arrow/util/protobuf_reflect_test.go:
##########
@@ -169,123 +369,140 @@ func TestGetSchema(t *testing.T) {
     - Double: type=float64, nullable
     - Enum: type=dictionary<values=utf8, indices=int32, ordered=false>, 
nullable
     - Oneofstring: type=utf8, nullable`
-
-       require.Equal(t, want, got, "got: %s\nwant: %s", got, want)
+       CheckSchema(t, pmr, want)
 
        onlyEnum := func(pfr *ProtobufFieldReflection) bool {
                return !pfr.isEnum()
        }
-       got = NewProtobufMessageReflection(
-               &msg,
+       pmr = NewProtobufMessageReflection(
+               f.msg,
                WithExclusionPolicy(onlyEnum),
                WithEnumHandler(EnumNumber),
-       ).Schema().String()
+       )
        want = `schema:
   fields: 1
     - enum: type=int32, nullable`
+       CheckSchema(t, pmr, want)
 
-       require.Equal(t, want, got, "got: %s\nwant: %s", got, want)
-
-       got = NewProtobufMessageReflection(
-               &msg,
+       pmr = NewProtobufMessageReflection(
+               f.msg,
                WithExclusionPolicy(onlyEnum),
                WithEnumHandler(EnumValue),
-       ).Schema().String()
+       )
        want = `schema:
   fields: 1
     - enum: type=utf8, nullable`
-
-       require.Equal(t, want, got, "got: %s\nwant: %s", got, want)
+       CheckSchema(t, pmr, want)
 }
 
 func TestRecordFromProtobuf(t *testing.T) {
-       msg := SetupTest()
+       f := AllTheTypesFixture()
 
-       pmr := NewProtobufMessageReflection(&msg, 
WithOneOfHandler(OneOfDenseUnion))
-       schema := pmr.Schema()
-       got := pmr.Record(nil)
-       jsonStr := `[
-               {
-                       "str":"Hello",
-                       "int32":10,
-                       "int64":100,
-                       "sint32":-10,
-                       "sin64":-100,
-                       "uint32":10,
-                       "uint64":100,
-                       "fixed32":10,
-                       "fixed64":1000,
-                       "sfixed32":10,
-                       "bool":false,
-                       "bytes":"SGVsbG8sIHdvcmxkIQ==",
-                       "double":1.1,
-                       "enum":"OPTION_1",
-                       "message":{"field1":"Example"},
-                       "oneof": [0, "World"],
-                       "any":{"field1":"Example"},
-                       "simple_map":[{"key":99,"value":"Hello"}],
-                       
"complex_map":[{"key":"complex","value":{"field1":"Example"}}],
-                       "simple_list":["Hello","World"],
-                       "complex_list":[{"field1":"Example"}]
-               }
-       ]`
-       want, _, err := array.RecordFromJSON(memory.NewGoAllocator(), schema, 
strings.NewReader(jsonStr))
-
-       require.NoError(t, err)
-       require.EqualExportedValues(t, got, want, "got: %s\nwant: %s", got, 
want)
+       pmr := NewProtobufMessageReflection(f.msg, 
WithOneOfHandler(OneOfDenseUnion))
+       CheckRecord(t, pmr, fmt.Sprintf(`[%s]`, f.jsonStr))
 
        onlyEnum := func(pfr *ProtobufFieldReflection) bool { return 
!pfr.isEnum() }
-       pmr = NewProtobufMessageReflection(&msg, WithExclusionPolicy(onlyEnum), 
WithEnumHandler(EnumValue))
-       got = pmr.Record(nil)
-       jsonStr = `[ { "enum":"OPTION_1" } ]`
-       want, _, err = array.RecordFromJSON(memory.NewGoAllocator(), 
pmr.Schema(), strings.NewReader(jsonStr))
-       require.NoError(t, err)
-       require.True(t, array.RecordEqual(got, want), "got: %s\nwant: %s", got, 
want)
+       pmr = NewProtobufMessageReflection(f.msg, 
WithExclusionPolicy(onlyEnum), WithEnumHandler(EnumValue))
+       jsonStr := `[ { "enum":"OPTION_1" } ]`
+       CheckRecord(t, pmr, jsonStr)
 
-       pmr = NewProtobufMessageReflection(&msg, WithExclusionPolicy(onlyEnum), 
WithEnumHandler(EnumNumber))
-       got = pmr.Record(nil)
+       pmr = NewProtobufMessageReflection(f.msg, 
WithExclusionPolicy(onlyEnum), WithEnumHandler(EnumNumber))
        jsonStr = `[ { "enum":"1" } ]`
-       want, _, err = array.RecordFromJSON(memory.NewGoAllocator(), 
pmr.Schema(), strings.NewReader(jsonStr))
-       require.NoError(t, err)
-       require.True(t, array.RecordEqual(got, want), "got: %s\nwant: %s", got, 
want)
+       CheckRecord(t, pmr, jsonStr)
 }
 
 func TestNullRecordFromProtobuf(t *testing.T) {
        pmr := NewProtobufMessageReflection(&util_message.AllTheTypes{})
-       schema := pmr.Schema()
-       got := pmr.Record(nil)
-       _, _ = got.MarshalJSON()
-       jsonStr := `[
-               {
-                       "str":"",
-                       "int32":0,
-                       "int64":0,
-                       "sint32":0,
-                       "sin64":0,
-                       "uint32":0,
-                       "uint64":0,
-                       "fixed32":0,
-                       "fixed64":0,
-                       "sfixed32":0,
-                       "bool":false,
-                       "bytes":"",
-                       "double":0,
-                       "enum":"OPTION_0",
-                       "message":null,
-                       "oneofmessage":{"field1":""},
-                       "oneofstring":"",
-                       "any":null,
-                       "simple_map":[],
-                       "complex_map":[],
-                       "simple_list":[],
-                       "complex_list":[]
-               }
-       ]`
+       f := AllTheTypesFixture()
+       CheckRecord(t, pmr, fmt.Sprintf(`[%s]`, f.nullJsonStr))
+}
 
-       want, _, err := array.RecordFromJSON(memory.NewGoAllocator(), schema, 
strings.NewReader(jsonStr))
+func TestExcludedNested(t *testing.T) {
+       msg := util_message.ExampleMessage{
+               Field1: "Example",
+       }
+       schema := `schema:
+  fields: 2
+    - simple_a: type=list<item: struct<field1: utf8>, nullable>, nullable
+    - simple_b: type=list<item: struct<field1: utf8>, nullable>, nullable`
 
-       require.NoError(t, err)
-       require.EqualExportedValues(t, got, want, "got: %s\nwant: %s", got, 
want)
+       simpleNested := util_message.SimpleNested{
+               SimpleA: []*util_message.ExampleMessage{&msg},
+               SimpleB: []*util_message.ExampleMessage{&msg},
+       }
+       pmr := NewProtobufMessageReflection(&simpleNested)
+       jsonStr := `[{ "simple_a":[{"field1":"Example"}], 
"simple_b":[{"field1":"Example"}] }]`
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       //exclude one value
+       simpleNested = util_message.SimpleNested{
+               SimpleA: []*util_message.ExampleMessage{&msg},
+       }
+       jsonStr = `[{ "simple_a":[{"field1":"Example"}] }]`
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       //exclude both values
+       simpleNested = util_message.SimpleNested{}
+       jsonStr = `[{ "simple_a":[{}] }]`
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       f := AllTheTypesNoAnyFixture()
+       schema = `schema:
+  fields: 2
+    - all_the_types_no_any_a: type=list<item: struct<str: utf8, int32: int32, 
int64: int64, sint32: int32, sin64: int64, uint32: uint32, uint64: uint64, 
fixed32: uint32, fixed64: uint64, sfixed32: int32, bool: bool, bytes: binary, 
double: float64, enum: dictionary<values=utf8, indices=int32, ordered=false>, 
message: struct<field1: utf8>, oneofstring: utf8, oneofmessage: struct<field1: 
utf8>, simple_map: map<int32, utf8, items_nullable>, complex_map: map<utf8, 
struct<field1: utf8>, items_nullable>, simple_list: list<item: utf8, nullable>, 
complex_list: list<item: struct<field1: utf8>, nullable>>, nullable>, nullable
+    - all_the_types_no_any_b: type=list<item: struct<str: utf8, int32: int32, 
int64: int64, sint32: int32, sin64: int64, uint32: uint32, uint64: uint64, 
fixed32: uint32, fixed64: uint64, sfixed32: int32, bool: bool, bytes: binary, 
double: float64, enum: dictionary<values=utf8, indices=int32, ordered=false>, 
message: struct<field1: utf8>, oneofstring: utf8, oneofmessage: struct<field1: 
utf8>, simple_map: map<int32, utf8, items_nullable>, complex_map: map<utf8, 
struct<field1: utf8>, items_nullable>, simple_list: list<item: utf8, nullable>, 
complex_list: list<item: struct<field1: utf8>, nullable>>, nullable>, nullable`
+
+       complexNested := util_message.ComplexNested{
+               AllTheTypesNoAnyA: 
[]*util_message.AllTheTypesNoAny{f.msg.(*util_message.AllTheTypesNoAny)},
+               AllTheTypesNoAnyB: 
[]*util_message.AllTheTypesNoAny{f.msg.(*util_message.AllTheTypesNoAny)},
+       }
+       jsonStr = fmt.Sprintf(`[{ "all_the_types_a": [%s], "all_the_types_b": 
[%s] }]`, f.jsonStr, f.jsonStr)
+       pmr = NewProtobufMessageReflection(&complexNested)
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       // exclude one value
+       complexNested = util_message.ComplexNested{
+               AllTheTypesNoAnyB: 
[]*util_message.AllTheTypesNoAny{f.msg.(*util_message.AllTheTypesNoAny)},
+       }
+       jsonStr = fmt.Sprintf(`[{ "all_the_types_a": [%s], "all_the_types_b": 
[%s] }]`, f.nullJsonStr, f.jsonStr)
+       pmr = NewProtobufMessageReflection(&complexNested)
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       // exclude both values
+       complexNested = util_message.ComplexNested{}
+       jsonStr = fmt.Sprintf(`[{ "all_the_types_a": [%s], "all_the_types_b": 
[%s] }]`, f.nullJsonStr, f.nullJsonStr)
+       pmr = NewProtobufMessageReflection(&complexNested)
+       CheckSchema(t, pmr, schema)
+       CheckRecord(t, pmr, jsonStr)
+
+       schema = `schema:
+  fields: 2
+    - complex_nested: type=struct<all_the_types_no_any_a: list<item: 
struct<str: utf8, int32: int32, int64: int64, sint32: int32, sin64: int64, 
uint32: uint32, uint64: uint64, fixed32: uint32, fixed64: uint64, sfixed32: 
int32, bool: bool, bytes: binary, double: float64, enum: 
dictionary<values=utf8, indices=int32, ordered=false>, message: struct<field1: 
utf8>, oneofstring: utf8, oneofmessage: struct<field1: utf8>, simple_map: 
map<int32, utf8, items_nullable>, complex_map: map<utf8, struct<field1: utf8>, 
items_nullable>, simple_list: list<item: utf8, nullable>, complex_list: 
list<item: struct<field1: utf8>, nullable>>, nullable>, all_the_types_no_any_b: 
list<item: struct<str: utf8, int32: int32, int64: int64, sint32: int32, sin64: 
int64, uint32: uint32, uint64: uint64, fixed32: uint32, fixed64: uint64, 
sfixed32: int32, bool: bool, bytes: binary, double: float64, enum: 
dictionary<values=utf8, indices=int32, ordered=false>, message: struct<field1: 
utf8>, oneofstring: utf8, oneofmessage
 : struct<field1: utf8>, simple_map: map<int32, utf8, items_nullable>, 
complex_map: map<utf8, struct<field1: utf8>, items_nullable>, simple_list: 
list<item: utf8, nullable>, complex_list: list<item: struct<field1: utf8>, 
nullable>>, nullable>>, nullable
+    - simple_nested: type=struct<simple_a: list<item: struct<field1: utf8>, 
nullable>, simple_b: list<item: struct<field1: utf8>, nullable>>, nullable`
+
+       deepNested := util_message.DeepNested{
+               ComplexNested: &complexNested,
+               SimpleNested:  &simpleNested,
+       }
+       pmr = NewProtobufMessageReflection(&deepNested)
+       CheckSchema(t, pmr, schema)

Review Comment:
   nope, I have added them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to