Compress: add MarshalText and UnmarshalText#357
Merged
zeroshade merged 2 commits intoapache:mainfrom Apr 18, 2025
Merged
Conversation
zeroshade
reviewed
Apr 17, 2025
Comment on lines
+142
to
+154
| func TestMarshalText(t *testing.T) { | ||
| compression := compress.Codecs.Zstd | ||
| data, err := compression.MarshalText() | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, "ZSTD", string(data)) | ||
| } | ||
|
|
||
| func TestUnmarshalText(t *testing.T) { | ||
| var compression compress.Compression | ||
| err := compression.UnmarshalText([]byte("ZSTD")) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, compress.Codecs.Zstd, compression) | ||
| } |
Member
There was a problem hiding this comment.
I figured we should probably use a table test and test all the codecs. i.e.
func TestMarshalText(t *testing.T) {
tests := []struct{
codec ....
text string
}{
{compress.Codecs.Zstd, "ZSTD"},
{compress.Codecs.Snappy, "SNAPPY"},
...
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
data, err := tt.codec.MarshalText()
assert.NoError(t, err)
assert.Equal(t, tt.text, string(data))
...
})
}
}and so on
zeroshade
approved these changes
Apr 18, 2025
Member
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for this! This is helpful and I'll probably end up updating iceberg-go to utilize it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Right now, there is no public API to convert a string like
"ZSTD"to a compression codec. There is only https://pkg.go.dev/github.com/apache/arrow-go/v18@v18.2.0/parquet/internal/gen-go/parquet#CompressionCodecFromString but that can't be used since it's in aninternalpackage.Adding
UnmarshalTextcan be used for applications taking such a string as configuration option. AddingMarshalTextisn't strictly needed since it overlaps withString()but makes sense for symmetry.What changes are included in this PR?
Add
UnmarshalTextandMarshalTextas thin wrappers around the same methods from the internal https://pkg.go.dev/github.com/apache/arrow-go/v18@v18.2.0/parquet/internal/gen-go/parquet#CompressionCodec type.Are these changes tested?
Yes
Are there any user-facing changes?
Minor new API for
Compressiontype