Parquet
Parquet support is provided by a package extension. It activates automatically once Parquet2 is loaded:
import Pkg; Pkg.add("Parquet2")
import Parquet2 # activates SerdeParquetExtParsing
Serde.SerdeParquet.parse_parquet — Function
parse_parquetDecode Parquet bytes, an IO stream, or an on-disk file into a row-oriented Vector of dictionaries without mapping to a target type.
Each element corresponds to one row; keys are the Parquet column names (as Strings) and values are the column's decoded Julia values (including missing for nulls).
Arguments
x: aVector{UInt8}holding raw Parquet bytes, orio: anIOstream positioned at the start of a Parquet file, orpath: a filesystem path to a.parquetfile.
Keyword arguments
dict_type::Type{<:AbstractDict}: concrete dict type used for each row (defaultDict{String,Any}).- Additional keyword arguments are forwarded to
Parquet2.Dataset.
Returns
A Vector of dict_type - one entry per data row.
Throws
ParseError: if the input is not a valid Parquet file.
Examples
julia> struct Row; name::String; age::Int; end
julia> bytes = to_parquet([Row("Alice", 30), Row("Bob", 25)]);
julia> parse_parquet(bytes)
2-element Vector{Dict{String, Any}}:
Dict("name" => "Alice", "age" => 30)
Dict("name" => "Bob", "age" => 25)See also: from_parquet, try_from_parquet.
Deserialization
Serde.SerdeParquet.from_parquet — Function
from_parquetParse Parquet input and deserialize each row into type T, returning a Vector{T}.
Because Parquet is an inherently tabular (columnar) format, the target type must be a Vector{T}. Passing a non-vector type raises ArgumentError. x may be a Vector{UInt8}, an IO, or a filesystem path, exactly as accepted by parse_parquet.
Arguments
::Type{Vector{T}}: the target row-vector type.Vector{Any}and the bareVectorshortcut both return the raw dictionary rows produced byparse_parquet.x: Parquet bytes,IO, or path.strategy: optional context object.
Keyword arguments
dict_type::Type{<:AbstractDict}: dict type used for intermediate rows (defaultDict{String,Any}).- Other keyword arguments are forwarded to
Parquet2.Dataset.
Returns
Vector{T} - one element per data row.
Throws
ArgumentError: if the target type is not aVector{T}.ParseError: ifxis not valid Parquet.MissingFieldError: if a required struct field is absent.TypeMismatchError: if a column value cannot be coerced to the field type.
Examples
julia> struct Row; name::String; age::Int; end
julia> bytes = to_parquet([Row("Alice", 30), Row("Bob", 25)]);
julia> from_parquet(Vector{Row}, bytes)
2-element Vector{Row}:
Row("Alice", 30)
Row("Bob", 25)See also: try_from_parquet, to_parquet, parse_parquet.
Serde.SerdeParquet.try_from_parquet — Function
try_from_parquetLike from_parquet but returns a SerdeError instead of throwing on failure.
Returns
Vector{T}on success.- A
ParseErrororDeserErrorsubtype on failure.
See also: from_parquet, SerdeError.
Serialization
Serde.SerdeParquet.to_parquet — Function
to_parquetSerialize a vector of structs into Parquet bytes (or write them to io).
data is interpreted row-wise: every element becomes one row, and the struct's field names — passed through Serde.ser_name — become column names. Field values are converted via Serde.ser_value / Serde.ser_type; fields skipped by Serde.ser_skip are omitted from the schema. Each column is automatically narrowed to the tightest element type (with missing added when any value is nothing or missing).
Arguments
data::AbstractVector: rows to serialize. Must be non-empty — Parquet has no zero-row encoding.io::IO: optional sink to write the bytes to.strategy: optional context object.
Keyword arguments
- Forwarded to
Parquet2.writefile(e.g.compression_codec).
Returns
- The 1-arg / 2-arg forms return
Vector{UInt8}containing the Parquet file. - The
IO-sink forms write toioand returnnothing.
Throws
ArgumentError: ifdatais empty, if its row type has no fields, or if every field is excluded bySerde.ser_skip.
Examples
julia> struct Row; name::String; age::Int; end
julia> bytes = to_parquet([Row("Alice", 30), Row("Bob", 25)]);
julia> from_parquet(Vector{Row}, bytes)
2-element Vector{Row}:
Row("Alice", 30)
Row("Bob", 25)See also: from_parquet.