Class: Blazer::Adapters::IgniteAdapter

Inherits:
BaseAdapter show all
Defined in:
lib/blazer/adapters/ignite_adapter.rb

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?

Constructor Details

This class inherits a constructor from Blazer::Adapters::BaseAdapter

Instance Method Details

#parameter_bindingObject



46
47
48
# File 'lib/blazer/adapters/ignite_adapter.rb', line 46

def parameter_binding
  :positional
end

#preview_statementObject



20
21
22
# File 'lib/blazer/adapters/ignite_adapter.rb', line 20

def preview_statement
  "SELECT * FROM {table} LIMIT 10"
end

#quotingObject

TODO figure out error Table ‘__T0` can be accessed only within Ignite query context. def schema

sql = "SELECT table_schema, table_name, column_name, data_type, ordinal_position FROM information_schema.columns WHERE table_schema NOT IN ('INFORMATION_SCHEMA', 'SYS')"
result = data_source.run_statement(sql)
result.rows.group_by { |r| [r[0], r[1]] }.map { |k, vs| {schema: k[0], table: k[1], columns: vs.sort_by { |v| v[2] }.map { |v| {name: v[2], data_type: v[3]} }} }.sort_by { |t| [t[:schema] == default_schema ? "" : t[:schema], t[:table]] }

end



40
41
42
# File 'lib/blazer/adapters/ignite_adapter.rb', line 40

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
# File 'lib/blazer/adapters/ignite_adapter.rb', line 4

def run_statement(statement, comment, bind_params)
  columns = []
  rows = []
  error = nil

  begin
    result = client.query("#{statement} /*#{comment}*/", bind_params, schema: default_schema, statement_type: :select, timeout: data_source.timeout)
    columns = result.any? ? result.first.keys : []
    rows = result.map(&:values)
  rescue => e
    error = e.message
  end

  [columns, rows, error]
end

#tablesObject



24
25
26
27
28
29
30
# File 'lib/blazer/adapters/ignite_adapter.rb', line 24

def tables
  sql = "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('INFORMATION_SCHEMA', 'SYS')"
  result = data_source.run_statement(sql)
  result.rows.reject { |row| row[1].start_with?("__") }.map do |row|
    (row[0] == default_schema ? row[1] : "#{row[0]}.#{row[1]}").downcase
  end
end