forked from segmentio/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress.go
96 lines (79 loc) · 2.39 KB
/
compress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package parquet
import (
"fmt"
"github.com/segmentio/parquet-go/compress"
"github.com/segmentio/parquet-go/compress/brotli"
"github.com/segmentio/parquet-go/compress/gzip"
"github.com/segmentio/parquet-go/compress/lz4"
"github.com/segmentio/parquet-go/compress/snappy"
"github.com/segmentio/parquet-go/compress/uncompressed"
"github.com/segmentio/parquet-go/compress/zstd"
"github.com/segmentio/parquet-go/format"
)
var (
// Uncompressed is a parquet compression codec representing uncompressed
// pages.
Uncompressed uncompressed.Codec
// Snappy is the SNAPPY parquet compression codec.
Snappy snappy.Codec
// Gzip is the GZIP parquet compression codec.
Gzip = gzip.Codec{
Level: gzip.DefaultCompression,
}
// Brotli is the BROTLI parquet compression codec.
Brotli = brotli.Codec{
Quality: brotli.DefaultQuality,
LGWin: brotli.DefaultLGWin,
}
// Zstd is the ZSTD parquet compression codec.
Zstd = zstd.Codec{
Level: zstd.DefaultLevel,
}
// Lz4Raw is the LZ4_RAW parquet compression codec.
Lz4Raw = lz4.Codec{
Level: lz4.DefaultLevel,
}
// Table of compression codecs indexed by their code in the parquet format.
compressionCodecs = [...]compress.Codec{
format.Uncompressed: &Uncompressed,
format.Snappy: &Snappy,
format.Gzip: &Gzip,
format.Brotli: &Brotli,
format.Zstd: &Zstd,
format.Lz4Raw: &Lz4Raw,
}
)
// LookupCompressionCodec returns the compression codec associated with the
// given code.
//
// The function never returns nil. If the encoding is not supported,
// an "unsupported" codec is returned.
func LookupCompressionCodec(codec format.CompressionCodec) compress.Codec {
if codec >= 0 && int(codec) < len(compressionCodecs) {
if c := compressionCodecs[codec]; c != nil {
return c
}
}
return &unsupported{codec}
}
type unsupported struct {
codec format.CompressionCodec
}
func (u *unsupported) String() string {
return "UNSUPPORTED"
}
func (u *unsupported) CompressionCodec() format.CompressionCodec {
return u.codec
}
func (u *unsupported) Encode(dst, src []byte) ([]byte, error) {
return dst[:0], u.error()
}
func (u *unsupported) Decode(dst, src []byte) ([]byte, error) {
return dst[:0], u.error()
}
func (u *unsupported) error() error {
return fmt.Errorf("unsupported compression codec: %s", u.codec)
}
func isCompressed(c compress.Codec) bool {
return c != nil && c.CompressionCodec() != format.Uncompressed
}