Class: ClickHouse::Response::ResultSet
- Inherits:
-
Object
- Object
- ClickHouse::Response::ResultSet
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/click_house/response/result_set.rb
Constant Summary collapse
- TYPE_ARGV_DELIM =
','
- NULLABLE =
'Nullable'
- NULLABLE_TYPE_RE =
/#{NULLABLE}\((.+)\)/i.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
Class Method Summary collapse
-
.extract_type_info(type) ⇒ Array<String, Array>
-
first element is name of “ClickHouse.types.keys” * second element is extra arguments that should to be passed to <cast> function.
-
Instance Method Summary collapse
-
#initialize(meta:, data:, statistics: nil) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #to_a ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(meta:, data:, statistics: nil) ⇒ ResultSet
Returns a new instance of ResultSet.
51 52 53 54 55 |
# File 'lib/click_house/response/result_set.rb', line 51 def initialize(meta:, data:, statistics: nil) @meta = @data = data @statistics = Hash(statistics) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/click_house/response/result_set.rb', line 17 def data @data end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
17 18 19 |
# File 'lib/click_house/response/result_set.rb', line 17 def @meta end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
17 18 19 |
# File 'lib/click_house/response/result_set.rb', line 17 def statistics @statistics end |
Class Method Details
.extract_type_info(type) ⇒ Array<String, Array>
-
first element is name of “ClickHouse.types.keys”
-
second element is extra arguments that should to be passed to <cast> function
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/click_house/response/result_set.rb', line 32 def extract_type_info(type) type = type.gsub(NULLABLE_TYPE_RE, '\1') nullable = Regexp.last_match(1) argv = [] type = type.gsub(/\((.+)\)/, '') if (match = Regexp.last_match(1)) counter = Array.new(match.count(TYPE_ARGV_DELIM).next) { '%s' } type = "#{type}(#{counter.join("#{TYPE_ARGV_DELIM} ")})" argv = match.split("#{TYPE_ARGV_DELIM} ") end [nullable ? "#{NULLABLE}(#{type})" : type, argv] end |
Instance Method Details
#to_a ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/click_house/response/result_set.rb', line 57 def to_a @to_a ||= data.each do |row| row.each do |name, value| casting = types.fetch(name) row[name] = casting.fetch(:caster).cast(value, *casting.fetch(:arguments)) end end end |
#types ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/click_house/response/result_set.rb', line 66 def types @types ||= .each_with_object({}) do |row, object| type_name, argv = self.class.extract_type_info(row.fetch('type')) object[row.fetch('name')] = { caster: ClickHouse.types[type_name], arguments: argv } end end |