Documentation
¶
Overview ¶
Package parquet is a pure-Go (CGO=0), MRI-faithful implementation of the Ruby red-parquet gem's core surface — reading and writing Apache Parquet files as Apache Arrow tables.
Relationship to upstream ¶
The real red-parquet gem is a thin Ruby binding over the C++ library libparquet (via GObject introspection over Apache Arrow), so it cannot be shipped in a CGO-free static binary. This package mirrors red-parquet's observable Ruby surface — Parquet::ArrowFileReader, Parquet::ArrowFileWriter, the Parquet::Writer convenience, Table#save / Table.load format dispatch and the Parquet::*Error tree — on top of the Parquet reader/writer of github.com/apache/arrow-go/v18/parquet and its Arrow bridge github.com/apache/arrow-go/v18/parquet/pqarrow, the official pure-Go Apache Parquet implementation. It does not reimplement the Parquet format; it re-presents arrow-go's Parquet stack through Ruby's naming and semantics so it can back an embedded Ruby (go-embedded-ruby / rbgo) with no cgo.
Interoperability with go-ruby-arrow ¶
The Arrow tables this package reads and writes are github.com/go-ruby-arrow/arrow Tables — the same type red-arrow is mapped to — so the two libraries compose at the Ruby level: build a Table with go-ruby-arrow, persist it here, load it back, and hand it to any go-ruby-arrow consumer unchanged.
Ruby-to-Go mapping ¶
Parquet::ArrowFileReader -> *ArrowFileReader (ReadTable/ReadRowGroup/NumRows/…) Parquet::ArrowFileWriter -> *ArrowFileWriter (Write/Close) Parquet::Writer.write -> WriteTable / WriteTableTo / Save Arrow::Table.load -> Load / ReadTable Arrow::Table#save -> Save Parquet::Error (tree) -> *Error (Kind + RubyClass mapping)
Compression and encoding ¶
The writer honours red-parquet's per-file compression symbols (:uncompressed / :snappy / :gzip / :zstd) via WithCompression, the row-group size via WithRowGroupSize, and dictionary encoding via WithDictionary. Every codec round-trips.
Wire compatibility ¶
A Parquet file written here is read back by arrow-go's canonical pqarrow.FileReader, and a file written by arrow-go's canonical writer is read here — both directions are verified by the differential tests, not asserted. Parquet is a little-endian on-disk format; arrow-go handles the byte swap on big-endian targets (s390x), so the same files round-trip identically across all six supported 64-bit arches.
Index ¶
- Constants
- Variables
- func Load(path string) (*gruby.Table, error)
- func ReadTableBytes(data []byte) (*gruby.Table, error)
- func Save(t *gruby.Table, path string, opts ...WriteOption) error
- func WriteTable(t *gruby.Table, path string, opts ...WriteOption) error
- func WriteTableTo(w io.Writer, t *gruby.Table, opts ...WriteOption) error
- type ArrowFileReader
- func (r *ArrowFileReader) Close() error
- func (r *ArrowFileReader) NumRowGroups() int
- func (r *ArrowFileReader) NumRows() int64
- func (r *ArrowFileReader) ReadRowGroup(idx int) (*gruby.Table, error)
- func (r *ArrowFileReader) ReadTable() (*gruby.Table, error)
- func (r *ArrowFileReader) Schema() (*gruby.Schema, error)
- type ArrowFileWriter
- type Compression
- type Error
- type ErrorKind
- type WriteOption
Constants ¶
const DefaultRowGroupSize int64 = 1024 * 1024
DefaultRowGroupSize is the number of rows per row group used when no WithRowGroupSize option is given, matching arrow-go's default row-group length.
Variables ¶
var ( // ErrType matches KindType errors, ErrIndex matches KindIndex, etc. ErrType = &Error{Kind: KindType} ErrIndex = &Error{Kind: KindIndex} ErrArgument = &Error{Kind: KindArgument} ErrIO = &Error{Kind: KindIO} ErrNotImplemented = &Error{Kind: KindNotImplemented} )
Sentinel values for errors.Is matching by kind.
Functions ¶
func Load ¶
Load reads a Parquet file at path into a go-ruby-arrow table, mirroring red-arrow's Arrow::Table.load format dispatch for the ".parquet" extension.
func ReadTableBytes ¶
ReadTableBytes reads a whole Parquet file held in memory into a go-ruby-arrow table, a convenience over NewArrowFileReader + ArrowFileReader.ReadTable.
func Save ¶
func Save(t *gruby.Table, path string, opts ...WriteOption) error
Save writes a go-ruby-arrow table to a Parquet file at path, mirroring red-arrow's Arrow::Table#save format dispatch for the ".parquet" extension.
func WriteTable ¶
func WriteTable(t *gruby.Table, path string, opts ...WriteOption) error
WriteTable writes a go-ruby-arrow table to a Parquet file at path (Parquet::Writer.write(table, path)).
func WriteTableTo ¶
WriteTableTo writes a single go-ruby-arrow table to w as a complete Parquet file (open, write, close), mirroring Parquet::Writer.write to an IO.
Types ¶
type ArrowFileReader ¶
type ArrowFileReader struct {
// contains filtered or unexported fields
}
ArrowFileReader is the pure-Go counterpart of Parquet::ArrowFileReader — a random-access Parquet reader that yields go-ruby-arrow tables. Construct one from an in-memory reader with NewArrowFileReader or from a path with OpenArrowFileReader, read with ArrowFileReader.ReadTable / ArrowFileReader.ReadRowGroup, and ArrowFileReader.Close it when done.
func NewArrowFileReader ¶
func NewArrowFileReader(r parquet.ReaderAtSeeker) (*ArrowFileReader, error)
NewArrowFileReader opens a Parquet reader over an in-memory random-access source (Parquet::ArrowFileReader.new with an IO). A *bytes.Reader or *os.File satisfies parquet.ReaderAtSeeker.
func OpenArrowFileReader ¶
func OpenArrowFileReader(path string) (*ArrowFileReader, error)
OpenArrowFileReader opens the Parquet file at path (Parquet::ArrowFileReader.new with a path). The whole file is buffered into memory and the OS file handle is released before returning, so no handle outlives the call — on Windows the file can then always be deleted, even while the reader is still in use.
func (*ArrowFileReader) Close ¶
func (r *ArrowFileReader) Close() error
Close releases the reader (Parquet::ArrowFileReader#close). The source is always in memory, so there is no OS file handle to release. It is idempotent.
func (*ArrowFileReader) NumRowGroups ¶
func (r *ArrowFileReader) NumRowGroups() int
NumRowGroups returns the number of row groups (Parquet::ArrowFileReader#n_row_groups).
func (*ArrowFileReader) NumRows ¶
func (r *ArrowFileReader) NumRows() int64
NumRows returns the total number of rows across all row groups (Parquet::ArrowFileReader#n_rows).
func (*ArrowFileReader) ReadRowGroup ¶
func (r *ArrowFileReader) ReadRowGroup(idx int) (*gruby.Table, error)
ReadRowGroup reads a single row group by index into a go-ruby-arrow table (Parquet::ArrowFileReader#read_row_group). An out-of-range index yields an *Error of KindIndex.
type ArrowFileWriter ¶
type ArrowFileWriter struct {
// contains filtered or unexported fields
}
ArrowFileWriter is the pure-Go counterpart of Parquet::ArrowFileWriter — a streaming Parquet writer bound to an io.Writer and an Arrow schema. Write one or more go-ruby-arrow tables, then ArrowFileWriter.Close to flush the footer.
func NewArrowFileWriter ¶
func NewArrowFileWriter(w io.Writer, schema *gruby.Schema, opts ...WriteOption) (*ArrowFileWriter, error)
NewArrowFileWriter opens a Parquet writer over w for tables matching schema (Parquet::ArrowFileWriter.new). The write options select compression, row-group size and dictionary encoding.
func (*ArrowFileWriter) Close ¶
func (w *ArrowFileWriter) Close() error
Close flushes the Parquet footer and releases the writer (Parquet::ArrowFileWriter#close). It is idempotent.
type Compression ¶
type Compression int
Compression selects the Parquet column-chunk compression codec, mirroring red-parquet's per-file compression symbols (:uncompressed, :snappy, :gzip, :zstd) passed to Parquet::WriterProperties#set_compression.
const ( // Uncompressed stores column chunks with no compression. Uncompressed Compression = iota // Snappy is red-parquet's default codec — fast, moderate ratio. Snappy // Gzip (DEFLATE) trades speed for a better ratio. Gzip // Zstd offers a strong ratio at competitive speed. Zstd )
func ParseCompression ¶
func ParseCompression(name string) (Compression, error)
ParseCompression resolves a red-parquet compression symbol/string (case- and leading-colon-insensitive, e.g. "snappy", ":gzip", "ZSTD") to a Compression. An unrecognized name yields an *Error of KindArgument.
func (Compression) String ¶
func (c Compression) String() string
String returns the Ruby symbol name of the codec (without the leading colon), e.g. "snappy", matching red-parquet's compression names.
type Error ¶
Error is the pure-Go counterpart of red-parquet's Parquet::Error exception tree. It carries the ErrorKind (so the exact Ruby class can be reconstructed) and an optional wrapped cause, and it participates in errors.Is/As via Error.Is and Error.Unwrap.
func (*Error) Is ¶
Is reports whether target is an *Error of the same ErrorKind, letting callers write errors.Is(err, parquet.ErrIO) against the sentinel values.
type ErrorKind ¶
type ErrorKind int
ErrorKind identifies which node of red-parquet's exception tree an Error corresponds to. red-parquet raises Ruby exception classes (largely inherited from Arrow's); the kind records which one so a host (rbgo) can re-raise the faithful class.
const ( // KindError is the base Parquet::Error (a StandardError in Ruby). KindError ErrorKind = iota // KindType maps to Ruby's TypeError — a value did not fit the column type. KindType // KindIndex maps to Ruby's IndexError — an out-of-range row group / column. KindIndex // KindArgument maps to Ruby's ArgumentError — a malformed call or option. KindArgument // KindIO maps to Parquet::Error::Io — a Parquet read/write failure. KindIO // KindNotImplemented maps to Ruby's NotImplementedError. KindNotImplemented )
type WriteOption ¶
type WriteOption func(*writeConfig)
WriteOption configures the Parquet writer, mirroring the knobs red-parquet exposes through Parquet::WriterProperties (compression, row-group size and dictionary encoding).
func WithCompression ¶
func WithCompression(c Compression) WriteOption
WithCompression sets the column-chunk compression codec (Parquet::WriterProperties#set_compression).
func WithDictionary ¶
func WithDictionary(enabled bool) WriteOption
WithDictionary enables or disables dictionary encoding (Parquet::WriterProperties#set_enable_dictionary).
func WithRowGroupSize ¶
func WithRowGroupSize(n int64) WriteOption
WithRowGroupSize sets the maximum number of rows per row group (Parquet::ArrowFileWriter#write_table chunk_size). A non-positive size falls back to DefaultRowGroupSize.
