Skip to content

Commit 4acb3d1

Browse files
authored
fix(parquet/variant): fix basic stringify (#624)
### Rationale for this change fixes #623 ### What changes are included in this PR? checking for the `isLarge` bit upon calling `Value()` for a BasicArray was incorrect, forgetting to shift appropriately. ### Are these changes tested? Yes, a unit test is added to check for this ### Are there any user-facing changes? only fixing the assert.
1 parent 2d0962e commit 4acb3d1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

parquet/variant/variant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func (v Value) Value() any {
685685
case BasicArray:
686686
valueHdr := (v.value[0] >> basicTypeBits)
687687
fieldOffsetSz := (valueHdr & 0b11) + 1
688-
isLarge := (valueHdr & 0b1) == 1
688+
isLarge := ((valueHdr >> 2) & 0b1) == 1
689689

690690
var (
691691
sz int

parquet/variant/variant_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,28 @@ func TestValueCloneConsistency(t *testing.T) {
783783
assert.Equal(t, variant.String, cloned.Type())
784784
assert.Equal(t, "test", cloned.Value())
785785
}
786+
787+
// test fix from github.com/apache/arrow-go/issues/623
788+
func TestVariantJSONRoundTrip(t *testing.T) {
789+
jsonBytes := []byte(`{
790+
"object_array": [
791+
{
792+
"a_field_name_1": "some value AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
793+
"a_field_name_2": "some value AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
794+
"a_field_name_3": "some value",
795+
"a_field_name_4": "some value",
796+
"a_field_name_5": "some value",
797+
"a_field_name_6": "some value",
798+
"a_field_name_7": "some value",
799+
"a_field_name_8": "some value",
800+
"a_field_name_9": "some value",
801+
"a_field_name_10": "some value"
802+
}
803+
]
804+
}`)
805+
variantFromJSON, err := variant.ParseJSONBytes(jsonBytes, false)
806+
if err != nil {
807+
panic(err)
808+
}
809+
assert.JSONEq(t, string(jsonBytes), variantFromJSON.String())
810+
}

0 commit comments

Comments
 (0)