Sha256: 382e440971608c64e85eb1a8f8127257d17c8b57dcde81d25718601125fadb2c

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

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

        begin
          columns, rows = client.run("#{statement} /*#{comment}*/")
          columns = columns.map(&:name)
        rescue => e
          error = e.message
        end

        [columns, rows, error]
      end

      def tables
        _, rows = client.run("SHOW TABLES")
        rows.map(&:first)
      end

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

      def quoting
        :single_quote_escape
      end

      # TODO support prepared statements - https://prestodb.io/docs/current/sql/prepare.html
      # feature request for variables - https://github.com/prestodb/presto/issues/5918
      def parameter_binding
      end

      protected

      def client
        @client ||= begin
          uri = URI.parse(settings["url"])
          query = uri.query ? CGI.parse(uri.query) : {}
          Presto::Client.new(
            server: "#{uri.host}:#{uri.port}",
            catalog: uri.path.to_s.delete_prefix("/"),
            schema: query["schema"] || "public",
            user: uri.user,
            http_debug: false
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
blazer-3.1.0 lib/blazer/adapters/presto_adapter.rb
blazer-3.0.4 lib/blazer/adapters/presto_adapter.rb
blazer_xlsx-3.0.8 lib/blazer/adapters/presto_adapter.rb