Class: SparkConnect::Types::DataType

Inherits:
Object
  • Object
show all
Defined in:
lib/spark_connect/types.rb

Overview

Abstract base class for all Spark data types.

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



50
51
52
# File 'lib/spark_connect/types.rb', line 50

def ==(other)
  other.is_a?(self.class) && other.class == self.class
end

#hashObject



55
56
57
# File 'lib/spark_connect/types.rb', line 55

def hash
  self.class.hash
end

#inspectObject



63
64
65
# File 'lib/spark_connect/types.rb', line 63

def inspect
  "#<#{self.class.name} #{simple_string}>"
end

#jsonString

Returns the JSON schema string for this type.

Returns:

  • (String)

    the JSON schema string for this type.



41
42
43
# File 'lib/spark_connect/types.rb', line 41

def json
  JSON.generate(json_value)
end

#json_valueString, Hash

Returns the Spark JSON schema fragment for this type.

Returns:

  • (String, Hash)

    the Spark JSON schema fragment for this type.



36
37
38
# File 'lib/spark_connect/types.rb', line 36

def json_value
  type_name
end

#simple_stringString

Returns the Spark simpleString representation, e.g. "int", "array<string>", "struct<a:int>".

Returns:

  • (String)

    the Spark simpleString representation, e.g. "int", "array<string>", "struct<a:int>".



24
25
26
# File 'lib/spark_connect/types.rb', line 24

def simple_string
  type_name
end

#to_protoSpark::Connect::DataType

Returns the protobuf representation.

Returns:

  • (Spark::Connect::DataType)

    the protobuf representation.

Raises:



46
47
48
# File 'lib/spark_connect/types.rb', line 46

def to_proto
  raise NotImplementedError, "#{self.class}#to_proto is not implemented"
end

#to_sObject



59
60
61
# File 'lib/spark_connect/types.rb', line 59

def to_s
  simple_string
end

#type_nameString

Returns the short type name used by Spark's JSON schema, e.g. "integer", "long", "string".

Returns:

  • (String)

    the short type name used by Spark's JSON schema, e.g. "integer", "long", "string".



30
31
32
33
# File 'lib/spark_connect/types.rb', line 30

def type_name
  n = self.class.name.split("::").last.sub(/Type$/, "")
  n.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
end