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

[Go] *array.Binary.ValueOffset doesn't work correctly #41

Closed
Korzhenevskyi opened this issue Nov 10, 2023 · 3 comments · Fixed by #165
Closed

[Go] *array.Binary.ValueOffset doesn't work correctly #41

Korzhenevskyi opened this issue Nov 10, 2023 · 3 comments · Fixed by #165
Labels
Type: bug Something isn't working

Comments

@Korzhenevskyi
Copy link

Describe the bug, including details regarding any error messages, version, and platform.

https://github.com/apache/arrow/blob/main/go/arrow/array/binary.go#L76 -- this place is incorrect. For example, valueOffsets contain 6 offsets for the array with 5 elements, but calling array.ValueOffset(5) will cause the panic although the element exists.

It must be

func (a *Binary) ValueOffset(i int) int {
	if i < 0 || i > a.array.data.length {
		panic("arrow/array: index out of range")
	}
	return int(a.valueOffsets[a.array.data.offset+i])
}

similar to strings https://github.com/apache/arrow/blob/main/go/arrow/array/string.go#L66.

Component(s)

Go

@Korzhenevskyi Korzhenevskyi added the Type: bug Something isn't working label Nov 10, 2023
@zeroshade
Copy link
Member

ValueOffset returns the starting offset for the value at index i. ValueOffset(5) is correct to panic for an array of 5 elements, there's no element at index 5 (index 4 is the last element in the array).

@Korzhenevskyi
Copy link
Author

@zeroshade I am talking about inconsistency between binary and string.

I had a loop over binary and string arrays of the same length, and it raised panic for binary. However, when I debugged, I could see the element at the requested index, so the if-statement was not wrong. I think the logic for strings is correct, because as I said the element existed in the array but could not be accessed due to panic.

@zeroshade
Copy link
Member

Semantically, the logic in for the Binary array is correct, not the String one.

You should never be calling ValueOffset for an index larger than the size of the array itself. The method returns the offset for the start of the value for the index requested. There is no value at the index of array length + 1.

If you need that value you could iterate through the slice provided by calling ValueOffsets() or by doing len(ValueBytes()).

@assignUser assignUser transferred this issue from apache/arrow Aug 30, 2024
zeroshade added a commit to zeroshade/arrow-go that referenced this issue Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants