Class: UmbrellioUtils::ClickHouse::TableMetadata
- Inherits:
-
Struct
- Object
- Struct
- UmbrellioUtils::ClickHouse::TableMetadata
- 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
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#is_deleted ⇒ Object
Returns the value of attribute is_deleted.
-
#sorting_key ⇒ Object
Returns the value of attribute sorting_key.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.distributed_target(engine_full) ⇒ Object
Distributed('cluster', 'database', 'table'[, sharding_key]).
-
.engine_args(engine_full) ⇒ Object
Arguments of the leading engine call, or [] when the engine takes none.
-
.parse(engine:, engine_full:, sorting_key:) ⇒ Object
Built first so it can answer #replacing? for itself — the engine test lives in one place only.
-
.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.
Instance Method Summary collapse
Instance Attribute Details
#engine ⇒ Object
Returns the value of attribute engine
12 13 14 |
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12 def engine @engine end |
#is_deleted ⇒ Object
Returns the value of attribute is_deleted
12 13 14 |
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12 def is_deleted @is_deleted end |
#sorting_key ⇒ Object
Returns the value of attribute sorting_key
12 13 14 |
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 12 def sorting_key @sorting_key end |
#version ⇒ Object
Returns the value of attribute 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:) = new(engine, split_args(sorting_key), nil, nil) return unless .replacing? args = engine_args(engine_full) args = args.drop(REPLICATED_ARGS_COUNT) if engine.start_with?("Replicated") .version, .is_deleted = args[0]&.to_sym, args[1]&.to_sym 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
22 23 24 |
# File 'lib/umbrellio_utils/click_house/table_metadata.rb', line 22 def replacing? engine.include?("Replacing") end |