Class: Blazer::Adapters::SnowflakeAdapter

Inherits:
SqlAdapter show all
Defined in:
lib/blazer/adapters/snowflake_adapter.rb

Instance Attribute Summary

Attributes inherited from SqlAdapter

#connection_model

Attributes inherited from BaseAdapter

#data_source

Instance Method Summary collapse

Methods inherited from SqlAdapter

#cachable?, #cost, #explain, #preview_statement, #reconnect, #run_statement, #schema, #tables

Methods inherited from BaseAdapter

#cachable?, #cost, #explain, #preview_statement, #reconnect, #run_statement, #schema, #tables

Constructor Details

#initialize(data_source) ⇒ SnowflakeAdapter

Returns a new instance of SnowflakeAdapter.



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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

Instance Method Details

#cancel(run_id) ⇒ Object



68
69
70
# File 'lib/blazer/adapters/snowflake_adapter.rb', line 68

def cancel(run_id)
  # todo
end