Class: ClickHouse::Definition::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/click_house/definition/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Column

Returns a new instance of Column.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
# File 'lib/click_house/definition/column.rb', line 15

def initialize(params = {})
  params.each { |k, v| public_send("#{k}=", v) }
  yield(self) if block_given?
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



11
12
13
# File 'lib/click_house/definition/column.rb', line 11

def default
  @default
end

#extensionsObject

Returns the value of attribute extensions.



10
11
12
# File 'lib/click_house/definition/column.rb', line 10

def extensions
  @extensions
end

#low_cardinalityObject

Returns the value of attribute low_cardinality.



9
10
11
# File 'lib/click_house/definition/column.rb', line 9

def low_cardinality
  @low_cardinality
end

#materializedObject

Returns the value of attribute materialized.



12
13
14
# File 'lib/click_house/definition/column.rb', line 12

def materialized
  @materialized
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/click_house/definition/column.rb', line 6

def name
  @name
end

#nullableObject

Returns the value of attribute nullable.



8
9
10
# File 'lib/click_house/definition/column.rb', line 8

def nullable
  @nullable
end

#ttlObject

Returns the value of attribute ttl.



13
14
15
# File 'lib/click_house/definition/column.rb', line 13

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/click_house/definition/column.rb', line 7

def type
  @type
end

Instance Method Details

#extension_typeObject



42
43
44
45
46
# File 'lib/click_house/definition/column.rb', line 42

def extension_type
  extensions.nil? ? type : format(type, *extensions)
rescue TypeError, ArgumentError
  raise StandardError, "please provide extensions for <#{type}>"
end

#optsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/click_house/definition/column.rb', line 28

def opts
  options = {
    DEFAULT: Util::Statement.ensure(default, default),
    MATERIALIZED: Util::Statement.ensure(materialized, materialized),
    TTL: Util::Statement.ensure(ttl, ttl)
  }.compact

  result = options.each_with_object([]) do |(key, value), object|
    object << "#{key} #{value}"
  end

  result.join(' ')
end

#to_sObject



20
21
22
23
24
25
26
# File 'lib/click_house/definition/column.rb', line 20

def to_s
  type = extension_type
  type = "Nullable(#{type})" if nullable
  type = "LowCardinality(#{type})" if low_cardinality

  "#{name} #{type} #{opts}"
end