Class: Arrow::StructDataType

Inherits:
Object
  • Object
show all
Includes:
FieldContainable
Defined in:
lib/arrow/struct-data-type.rb

Instance Method Summary collapse

Methods included from FieldContainable

#find_field

Constructor Details

#initialize(fields) ⇒ StructDataType #initialize(fields) ⇒ StructDataType #initialize(description) ⇒ StructDataType

Creates a new Arrow::StructDataType.

Overloads:

  • #initialize(fields) ⇒ StructDataType

    Examples:

    Create a struct data type with Fields

    visible_field = Arrow::Field.new("visible", :boolean)
    count_field = Arrow::Field.new("count", :int32)
    Arrow::StructDataType.new([visible_field, count_field])

    Create a struct data type with field descriptions

    field_descriptions = [
      {name: "visible", type: :boolean},
      {name: "count", type: :int32},
    ]
    Arrow::StructDataType.new(field_descriptions)

    Create a struct data type with Field and field description

    fields = [
      Arrow::Field.new("visible", :boolean),
      {name: "count", type: :int32},
    ]
    Arrow::StructDataType.new(fields)

    Parameters:

    • fields (::Array<Arrow::Field, Hash>)

      The fields of the struct data type. You can also specify field description as a field. You can mix Field and field description.

      See Field.new how to specify field description.

  • #initialize(fields) ⇒ StructDataType

    Examples:

    Create a struct data type with DataTypes

    fields = {
      "visible" => Arrow::BooleanDataType.new,
      "count" => Arrow::Int32DataType.new,
    }
    Arrow::StructDataType.new(fields)

    Create a struct data type with data type descriptions

    fields = {
      "visible" => :boolean,
      "count" => {type: :int32},
    }
    Arrow::StructDataType.new(fields)

    Create a struct data type with DataType and data type description

    fields = {
      "visible" => Arrow::BooleanDataType.new,
      "count" => {type: :int32},
    }
    Arrow::StructDataType.new(fields)

    Parameters:

    • fields (Hash{String, Symbol => Arrow::DataType, Hash})

      The pairs of field name and field data type of the struct data type. You can also specify data type description by ‘Hash`. You can mix DataType and data type description.

      See DataType.resolve how to specify data type description.

  • #initialize(description) ⇒ StructDataType

    Examples:

    Create a struct data type with Field and field description

    fields = [
      Arrow::Field.new("visible", :boolean),
      {name: "count", type: :int32},
    ]
    Arrow::StructDataType.new(fields: fields)

    Create a struct data type with DataType and data type description

    fields = {
      "visible" => Arrow::BooleanDataType.new,
      "count" => {type: :int32},
    }
    Arrow::StructDataType.new(fields: fields)

    Parameters:

    • description (Hash)

      The description of the struct data type. It must have ‘:fields` value.

    Options Hash (description):

    • :fields (::Array<Arrow::Field, Hash>, Hash{String, Symbol => Arrow::DataType, Hash, String, Symbol})

      The fields of the struct data type.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/arrow/struct-data-type.rb', line 108

def initialize(fields)
  if fields.is_a?(Hash) and fields.key?(:fields)
    description = fields
    fields = description[:fields]
  end
  if fields.is_a?(Hash)
    fields = fields.collect do |name, data_type|
      Field.new(name, data_type)
    end
  else
    fields = fields.collect do |field|
      field = Field.new(field) unless field.is_a?(Field)
      field
    end
  end
  initialize_raw(fields)
end