Class: Blazer::Adapters::ElasticsearchAdapter
Instance Attribute Summary
Attributes inherited from BaseAdapter
#data_source
Instance Method Summary
collapse
Methods inherited from BaseAdapter
#cachable?, #cancel, #cohort_analysis_statement, #cost, #explain, #initialize, #reconnect, #schema, #supports_cohort_analysis?
Instance Method Details
#parameter_binding ⇒ Object
46
47
48
|
# File 'lib/blazer/adapters/elasticsearch_adapter.rb', line 46
def parameter_binding
:positional
end
|
#preview_statement ⇒ Object
36
37
38
|
# File 'lib/blazer/adapters/elasticsearch_adapter.rb', line 36
def preview_statement
"SELECT * FROM \"{table}\" LIMIT 10"
end
|
#quoting ⇒ Object
41
42
43
|
# File 'lib/blazer/adapters/elasticsearch_adapter.rb', line 41
def quoting
:single_quote_escape
end
|
#run_statement(statement, comment, bind_params) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/blazer/adapters/elasticsearch_adapter.rb', line 4
def run_statement(statement, , bind_params)
columns = []
rows = []
error = nil
begin
response = client.transport.perform_request("POST", endpoint, {}, {query: "#{statement} /*#{}*/", params: bind_params}).body
columns = response["columns"].map { |v| v["name"] }
date_indexes = response["columns"].each_index.select { |i| ["date", "datetime"].include?(response["columns"][i]["type"]) }
if columns.any?
rows = response["rows"]
date_indexes.each do |i|
rows.each do |row|
row[i] &&= Time.parse(row[i])
end
end
end
rescue => e
error = e.message
error = Blazer::VARIABLE_MESSAGE if error.include?("mismatched input '?'")
end
[columns, rows, error]
end
|
#tables ⇒ Object
30
31
32
33
34
|
# File 'lib/blazer/adapters/elasticsearch_adapter.rb', line 30
def tables
indices = client.cat.indices(format: "json").map { |v| v["index"] }
aliases = client.cat.aliases(format: "json").map { |v| v["alias"] }
(indices + aliases).uniq.sort
end
|