Class: Blazer::Adapters::ClickhouseAdapter
Constant Summary
collapse
- DATE_TIME_TYPES =
["DateTime", "DateTime(%s)", "DateTime64(%d, %s)"].freeze
Instance Attribute Summary
Attributes inherited from BaseAdapter
#data_source
Instance Method Summary
collapse
Methods inherited from BaseAdapter
#cachable?, #cancel, #cohort_analysis_statement, #cost, #initialize, #parameter_binding, #quoting, #reconnect, #supports_cohort_analysis?
Instance Method Details
#explain(statement) ⇒ Object
53
54
55
|
# File 'lib/blazer/adapters/clickhouse_adapter.rb', line 53
def explain(statement)
connection.explain(statement)
end
|
#preview_statement ⇒ Object
49
50
51
|
# File 'lib/blazer/adapters/clickhouse_adapter.rb', line 49
def preview_statement
"SELECT * FROM {table} LIMIT 10"
end
|
#run_statement(statement, _comment) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/blazer/adapters/clickhouse_adapter.rb', line 6
def run_statement(statement, )
columns = []
rows = []
error = nil
begin
result = connection.select_all(statement)
unless result.data.blank?
date_time_columns = result.meta
.select { |column| column["type"].in?(DATE_TIME_TYPES) }
.map { |column| column["name"] }
columns = result.first.keys
rows = result.map { |row| convert_time_columns(row, date_time_columns).values }
end
rescue => e
error = e.message
end
[columns, rows, error]
end
|
#schema ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/blazer/adapters/clickhouse_adapter.rb', line 31
def schema
statement = " SELECT table, name, type\n FROM system.columns\n WHERE database = currentDatabase()\n ORDER BY table, position\n SQL\n\n response = connection.post(query: { query: statement, default_format: \"CSV\" })\n\n return [] if response.body.nil?\n\n response.body\n .group_by { |row| row[0] }\n .transform_values { |columns| columns.map { |c| { name: c[1], data_type: c[2] } } }\n .map { |table, columns| { schema: \"public\", table: table, columns: columns } }\nend\n"
|
#tables ⇒ Object
27
28
29
|
# File 'lib/blazer/adapters/clickhouse_adapter.rb', line 27
def tables
connection.tables
end
|