Elbehery commented on PR #75:
URL: https://github.com/apache/spark-connect-go/pull/75#issuecomment-2400750264
I wrote a test case to validate
```
// rowImplTest is a read-only sample [Row] to be used in all tests.
var rowImplSample rowImpl = rowImpl{
values: []any{1, 2, 3, 4, 5},
offsets: map[string]int{
"one": 0,
"two": 1,
"three": 2,
"four": 3,
"five": 4,
},
}
```
```
func TestRowImpl_FieldNames(t *testing.T) {
exp := []string{"one", "two", "three", "four", "five"}
act := rowImplSample.FieldNames()
require.Equal(t, exp, act)
}
```
test fails
```
Expected :[]string{"one", "two", "three", "four", "five"}
Actual :[]string{"", "", "", "", "", "four", "five", "one", "two", "three"}
```
So the issue is that
```
names := make([]string, len(r.offsets))
```
will create a slice with the given length and initialize it with default
values
It is idiomatic in `Go` to declare a slice like below
```
var names []string
```
then the slice is not `nil`, it is both (i.e. initialized && empty ), and
can be appended to without surprising bugs
I created tests for the `Row` type and pushing it now 👍🏽
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]