Sha256: ec3ee520bf22a50208f5d8c915ce86fef3a4ce74c946497dfc79d92bcc90bfb4

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

module Blazer
  module Adapters
    class HiveAdapter < BaseAdapter
      def run_statement(statement, comment)
        columns = []
        rows = []
        error = nil

        begin
          result = client.execute("#{statement} /*#{comment}*/")
          columns = result.any? ? result.first.keys : []
          rows = result.map(&:values)
        rescue => e
          error = e.message
        end

        [columns, rows, error]
      end

      def tables
        client.execute("SHOW TABLES").map { |r| r["tab_name"] }
      end

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

      # https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-StringsstringStrings
      def quoting
        :backslash_escape
      end

      # has variable substitution, but sets for session
      # https://cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution
      def parameter_binding
      end

      protected

      def client
        @client ||= begin
          uri = URI.parse(settings["url"])
          Hexspace::Client.new(
            host: uri.host,
            port: uri.port,
            username: uri.user,
            password: uri.password,
            database: uri.path.sub(/\A\//, ""),
            mode: uri.scheme.to_sym
          )
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
blazer_xlsx-3.0.7 lib/blazer/adapters/hive_adapter.rb
blazer_xlsx-3.0.6 lib/blazer/adapters/hive_adapter.rb
blazer_xlsx-3.0.5 lib/blazer/adapters/hive_adapter.rb
blazer-3.0.3 lib/blazer/adapters/hive_adapter.rb
blazer-3.0.2 lib/blazer/adapters/hive_adapter.rb
finery-3.0.3 lib/blazer/adapters/hive_adapter.rb
finery-3.0.2 lib/blazer/adapters/hive_adapter.rb
blazer-3.0.1 lib/blazer/adapters/hive_adapter.rb
finery-3.0.1 lib/blazer/adapters/hive_adapter.rb
finery-3.0.0 lib/blazer/adapters/hive_adapter.rb
blazer-3.0.0 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.5 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.4 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.3 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.2 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.1 lib/blazer/adapters/hive_adapter.rb
blazer-2.6.0 lib/blazer/adapters/hive_adapter.rb