Class: Parquet::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/parquet/schema.rb

Overview

Schema definition for Parquet files

Defined Under Namespace

Classes: SchemaBuilder

Class Method Summary collapse

Class Method Details

.define(&block) ⇒ Hash

Define a new schema using the DSL

Examples:

Define a schema with nullable and non-nullable fields

Parquet::Schema.define do
  field :id, :int64, nullable: false  # ID cannot be null
  field :name, :string  # Default nullable: true

  # Decimal field with precision and scale
  field :price, :decimal, precision: 10, scale: 2

  # List with non-nullable items
  field :scores, :list, item: :float, item_nullable: false

  # Map with nullable values
  field :metadata, :map,
        key: :string,
        value: :string,
        value_nullable: true

  # Nested struct with non-nullable fields
  field :address, :struct, nullable: true do
    field :street, :string, nullable: false
    field :city, :string, nullable: false
    field :zip, :string, nullable: false
  end
end

Returns:

  • (Hash)

    schema definition hash



33
34
35
36
37
38
39
# File 'lib/parquet/schema.rb', line 33

def self.define(&block)
  builder = SchemaBuilder.new
  builder.instance_eval(&block)

  # Return a structured hash representing the schema
  { type: :struct, fields: builder.fields }
end