Class: ClickHouse::Response::Summary

Inherits:
Object
  • Object
show all
Defined in:
lib/click_house/response/summary.rb

Constant Summary collapse

SUMMARY_HEADER =
'x-clickhouse-summary'
KEY_TOTALS =
'totals'
KEY_STATISTICS =
'statistics'
KEY_ROWS_BEFORE_LIMIT_AT_LEAST =
'rows_before_limit_at_least'
KEY_STAT_ELAPSED =
'elapsed'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, headers: Faraday::Utils::Headers.new, body: {}) ⇒ Summary

TOTALS [Array|Hash|NilClass] Support for ‘GROUP BY WITH TOTALS’ modifier

https://clickhouse.tech/docs/en/sql-reference/statements/select/group-by/#with-totals-modifier
Hash in JSON format and Array in JSONCompact

Parameters:

  • config (Config)
  • headers (Faraday::Utils::Headers) (defaults to: Faraday::Utils::Headers.new)
  • body (Hash) (defaults to: {})


26
27
28
29
30
31
32
33
# File 'lib/click_house/response/summary.rb', line 26

def initialize(config, headers: Faraday::Utils::Headers.new, body: {})
  @headers = headers
  @config = config
  @statistics = body.fetch(config.key(KEY_STATISTICS), {})
  @totals = body[config.key(KEY_TOTALS)]
  @rows_before_limit_at_least = body[config.key(KEY_ROWS_BEFORE_LIMIT_AT_LEAST)]
  @summary = parse_summary(headers[SUMMARY_HEADER])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def config
  @config
end

#headersObject (readonly)

Returns the value of attribute headers.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def headers
  @headers
end

#rows_before_limit_at_leastObject (readonly)

Returns the value of attribute rows_before_limit_at_least.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def rows_before_limit_at_least
  @rows_before_limit_at_least
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def statistics
  @statistics
end

#summaryObject (readonly)

Returns the value of attribute summary.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def summary
  @summary
end

#totalsObject (readonly)

Returns the value of attribute totals.



12
13
14
# File 'lib/click_house/response/summary.rb', line 12

def totals
  @totals
end

Instance Method Details

#elapsedFloat

Returns:

  • (Float)


81
82
83
# File 'lib/click_house/response/summary.rb', line 81

def elapsed
  statistics[config.key(KEY_STAT_ELAPSED)].to_f
end

#elapsed_prettyString

Returns:

  • (String)


86
87
88
# File 'lib/click_house/response/summary.rb', line 86

def elapsed_pretty
  Util::Pretty.measure(elapsed * 1000)
end

#read_bytesInteger

Returns:

  • (Integer)


41
42
43
# File 'lib/click_house/response/summary.rb', line 41

def read_bytes
  summary[config.key('read_bytes')].to_i
end

#read_bytes_prettyString

Returns:

  • (String)


46
47
48
# File 'lib/click_house/response/summary.rb', line 46

def read_bytes_pretty
  Util::Pretty.size(read_bytes)
end

#read_rowsInteger

Returns:

  • (Integer)


36
37
38
# File 'lib/click_house/response/summary.rb', line 36

def read_rows
  summary[config.key('read_rows')].to_i
end

#result_bytesInteger

Returns:

  • (Integer)


76
77
78
# File 'lib/click_house/response/summary.rb', line 76

def result_bytes
  summary[config.key('result_bytes')].to_i
end

#result_rowsInteger

Returns:

  • (Integer)


71
72
73
# File 'lib/click_house/response/summary.rb', line 71

def result_rows
  summary[config.key('result_rows')].to_i
end

#total_rows_to_readInteger

Returns:

  • (Integer)


66
67
68
# File 'lib/click_house/response/summary.rb', line 66

def total_rows_to_read
  summary[config.key('total_rows_to_read')].to_i
end

#written_bytesInteger

Returns:

  • (Integer)


56
57
58
# File 'lib/click_house/response/summary.rb', line 56

def written_bytes
  summary[config.key('written_bytes')].to_i
end

#written_bytes_prettyString

Returns:

  • (String)


61
62
63
# File 'lib/click_house/response/summary.rb', line 61

def written_bytes_pretty
  Util::Pretty.size(written_bytes)
end

#written_rowsInteger

Returns:

  • (Integer)


51
52
53
# File 'lib/click_house/response/summary.rb', line 51

def written_rows
  summary[config.key('written_rows')].to_i
end