Class: SparkConnect::Types::StructType
- Inherits:
-
DataType
- Object
- DataType
- SparkConnect::Types::StructType
show all
- Includes:
- Enumerable
- Defined in:
- lib/spark_connect/types.rb
Overview
A struct (row) type: an ordered collection of StructFields. This is the
type of every DataFrame's schema.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from DataType
#hash, #inspect, #json, #to_s
Constructor Details
#initialize(fields = []) ⇒ StructType
Returns a new instance of StructType.
362
363
364
365
|
# File 'lib/spark_connect/types.rb', line 362
def initialize(fields = [])
super()
@fields = fields
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
360
361
362
|
# File 'lib/spark_connect/types.rb', line 360
def fields
@fields
end
|
Instance Method Details
#==(other) ⇒ Object
406
|
# File 'lib/spark_connect/types.rb', line 406
def ==(other) = other.is_a?(StructType) && other.fields == fields
|
#[](key) ⇒ Object
381
|
# File 'lib/spark_connect/types.rb', line 381
def [](key) = key.is_a?(Integer) ? fields[key] : fields.find { |f| f.name == key.to_s }
|
#add(name, data_type = nil, nullable: true, metadata: nil) ⇒ StructType
Append a field and return self (chainable builder).
371
372
373
374
375
376
377
378
|
# File 'lib/spark_connect/types.rb', line 371
def add(name, data_type = nil, nullable: true, metadata: nil)
@fields << if name.is_a?(StructField)
name
else
StructField.new(name, data_type, nullable: nullable, metadata: metadata)
end
self
end
|
#each ⇒ Object
380
|
# File 'lib/spark_connect/types.rb', line 380
def each(&) = fields.each(&)
|
#json_value ⇒ Object
389
390
391
|
# File 'lib/spark_connect/types.rb', line 389
def json_value
{ "type" => "struct", "fields" => fields.map(&:json_value) }
end
|
#length ⇒ Object
Also known as:
size
383
|
# File 'lib/spark_connect/types.rb', line 383
def length = fields.length
|
#names ⇒ Object
382
|
# File 'lib/spark_connect/types.rb', line 382
def names = fields.map(&:name)
|
#simple_string ⇒ Object
386
|
# File 'lib/spark_connect/types.rb', line 386
def simple_string = "struct<#{fields.map(&:simple_string).join(',')}>"
|
#to_proto ⇒ Object
393
394
395
|
# File 'lib/spark_connect/types.rb', line 393
def to_proto
Types.wrap(struct: Proto::DataType::Struct.new(fields: fields.map(&:to_proto)))
end
|
#tree_string ⇒ String
400
401
402
403
404
|
# File 'lib/spark_connect/types.rb', line 400
def tree_string
lines = ["root"]
fields.each { |f| append_tree(lines, f, " |") }
"#{lines.join("\n")}\n"
end
|
#type_name ⇒ Object
387
|
# File 'lib/spark_connect/types.rb', line 387
def type_name = "struct"
|