class Blazer::Adapters::SnowflakeAdapter
Public Class Methods
name()
click to toggle source
# File lib/blazer/adapters/snowflake_adapter.rb, line 57 def self.name "Blazer::Connection::SnowflakeAdapter#{object_id}" end
new(data_source)
click to toggle source
# File lib/blazer/adapters/snowflake_adapter.rb, line 4 def initialize(data_source) @data_source = data_source @@registered ||= begin require "active_record/connection_adapters/odbc_adapter" require "odbc_adapter/adapters/postgresql_odbc_adapter" ODBCAdapter.register(/snowflake/, ODBCAdapter::Adapters::PostgreSQLODBCAdapter) do # Explicitly turning off prepared statements as they are not yet working with # snowflake + the ODBC ActiveRecord adapter def prepared_statements false end # Quoting needs to be changed for snowflake def quote_column_name(name) name.to_s end private # Override dbms_type_cast to get the values encoded in UTF-8 def dbms_type_cast(columns, values) int_column = {} columns.each_with_index do |c, i| int_column[i] = c.type == 3 && c.scale == 0 end float_column = {} columns.each_with_index do |c, i| float_column[i] = c.type == 3 && c.scale != 0 end values.each do |row| row.each_index do |idx| val = row[idx] if val if int_column[idx] row[idx] = val.to_i elsif float_column[idx] row[idx] = val.to_f elsif val.is_a?(String) row[idx] = val.force_encoding('UTF-8') end end end end end end end @connection_model = Class.new(Blazer::Connection) do def self.name "Blazer::Connection::SnowflakeAdapter#{object_id}" end if data_source.settings["conn_str"] establish_connection(adapter: "odbc", conn_str: data_source.settings["conn_str"]) elsif data_source.settings["dsn"] establish_connection(adapter: "odbc", dsn: data_source.settings["dsn"]) end end end
Public Instance Methods
cancel(run_id)
click to toggle source
# File lib/blazer/adapters/snowflake_adapter.rb, line 68 def cancel(run_id) # todo end
dbms_type_cast(columns, values)
click to toggle source
Override dbms_type_cast
to get the values encoded in UTF-8
# File lib/blazer/adapters/snowflake_adapter.rb, line 26 def dbms_type_cast(columns, values) int_column = {} columns.each_with_index do |c, i| int_column[i] = c.type == 3 && c.scale == 0 end float_column = {} columns.each_with_index do |c, i| float_column[i] = c.type == 3 && c.scale != 0 end values.each do |row| row.each_index do |idx| val = row[idx] if val if int_column[idx] row[idx] = val.to_i elsif float_column[idx] row[idx] = val.to_f elsif val.is_a?(String) row[idx] = val.force_encoding('UTF-8') end end end end end
prepared_statements()
click to toggle source
Explicitly turning off prepared statements as they are not yet working with snowflake + the ODBC ActiveRecord adapter
# File lib/blazer/adapters/snowflake_adapter.rb, line 14 def prepared_statements false end
quote_column_name(name)
click to toggle source
Quoting needs to be changed for snowflake
# File lib/blazer/adapters/snowflake_adapter.rb, line 19 def quote_column_name(name) name.to_s end