Class: UmbrellioUtils::ClickHouse::TableMetadata

Inherits:
Struct
  • Object
show all
Defined in:
lib/umbrellio_utils/click_house/table_metadata.rb,
lib/umbrellio_utils/click_house/table_metadata.rb

Overview

Reopened rather than declared with a block: constants defined inside a Struct.new do ... end block leak to the enclosing lexical scope.

Defined Under Namespace

Classes: UnknownTable

Constant Summary collapse

REPLICATED_ARGS_COUNT =

zookeeper path + replica name

2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#engineObject

Returns the value of attribute engine

Returns:

  • (Object)

    the current value of engine



12
13
14
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12

def engine
  @engine
end

#is_deletedObject

Returns the value of attribute is_deleted

Returns:

  • (Object)

    the current value of is_deleted



12
13
14
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12

def is_deleted
  @is_deleted
end

#sorting_keyObject

Returns the value of attribute sorting_key

Returns:

  • (Object)

    the current value of sorting_key



12
13
14
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12

def sorting_key
  @sorting_key
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



12
13
14
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12

def version
  @version
end

Class Method Details

.distributed_target(engine_full) ⇒ Object

Distributed('cluster', 'database', 'table'[, sharding_key])



41
42
43
44
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 41

def distributed_target(engine_full)
  _cluster, database, table = engine_args(engine_full)
  [unquote(database), unquote(table)]
end

.engine_args(engine_full) ⇒ Object

Arguments of the leading engine call, or [] when the engine takes none. Only a parenthesis directly after the engine name counts — later clauses such as PARTITION BY toYYYYMM(created_at) must not be read.



49
50
51
52
53
54
55
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 49

def engine_args(engine_full)
  open_index = engine_full.index("(")
  return [] unless open_index
  return [] unless engine_full[0...open_index].match?(/\A\w+\z/)

  split_args(engine_full[(open_index + 1)...close_index(engine_full, open_index)])
end

.parse(engine:, engine_full:, sorting_key:) ⇒ Object

Built first so it can answer #replacing? for itself — the engine test lives in one place only.



29
30
31
32
33
34
35
36
37
38
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 29

def parse(engine:, engine_full:, sorting_key:)
  meta = new(engine, split_args(sorting_key), nil, nil)
  return meta unless meta.replacing?

  args = engine_args(engine_full)
  args = args.drop(REPLICATED_ARGS_COUNT) if engine.start_with?("Replicated")
  meta.version, meta.is_deleted = args[0]&.to_sym, args[1]&.to_sym

  meta
end

.split_args(source) ⇒ Object

Split on top-level commas only: sorting keys hold function calls and engine arguments hold quoted paths, both of which may contain commas.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 59

def split_args(source)
  args = []
  current = +""

  scan(source) do |char, depth, in_string|
    if char == "," && depth.zero? && !in_string
      args << current.strip
      current = +""
    else
      current << char
    end
  end

  args << current.strip
  args.reject(&:empty?)
end

Instance Method Details

#replacing?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 22

def replacing?
  engine.include?("Replacing")
end