This is an automated email from the ASF dual-hosted git repository.
mgrund pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-go.git
The following commit(s) were added to refs/heads/master by this push:
new a24841f #86 Fix ordering of `Row.FieldNames()`
a24841f is described below
commit a24841fc8b3aed82492de44d7f5270849eca6907
Author: Martin Grund <[email protected]>
AuthorDate: Fri Jan 3 07:39:30 2025 +0100
#86 Fix ordering of `Row.FieldNames()`
### What changes were proposed in this pull request?
Previously, the map order was used to return the list of field names which
is not guaranteed to be stable. This patch implements a stable list based on
the offset inside the row schema.
### Why are the changes needed?
Correctness
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing UT
Closes #104 from grundprinzip/86.
Authored-by: Martin Grund <[email protected]>
Signed-off-by: Martin Grund <[email protected]>
---
spark/sql/types/row.go | 11 ++++++++---
spark/sql/types/row_test.go | 4 ++--
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/spark/sql/types/row.go b/spark/sql/types/row.go
index 34337ec..cace488 100644
--- a/spark/sql/types/row.go
+++ b/spark/sql/types/row.go
@@ -16,6 +16,10 @@
package types
+import (
+ "maps"
+)
+
type Row interface {
// At returns field's value at the given index within a [Row].
// It returns nil for invalid indices.
@@ -59,9 +63,10 @@ func (r *rowImpl) Len() int {
}
func (r *rowImpl) FieldNames() []string {
- names := make([]string, 0, len(r.offsets))
- for name := range r.offsets {
- names = append(names, name)
+ names := make([]string, len(r.offsets))
+ // Sort the field names to make the output deterministic.
+ for k, v := range maps.All(r.offsets) {
+ names[v] = k
}
return names
}
diff --git a/spark/sql/types/row_test.go b/spark/sql/types/row_test.go
index 791a56a..1cafcf6 100644
--- a/spark/sql/types/row_test.go
+++ b/spark/sql/types/row_test.go
@@ -26,11 +26,11 @@ import (
var rowImplSample rowImpl = rowImpl{
values: []any{1, 2, 3, 4, 5},
offsets: map[string]int{
+ "five": 4,
"one": 0,
"two": 1,
- "three": 2,
"four": 3,
- "five": 4,
+ "three": 2,
},
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]