class TrinoClient
Runs arbitrary SQL against the ephemeral Trino and returns rows keyed by column name. Used by the catalog sync (SELECT of table lists); the maintenance path keeps using TrinoRestClient.
Constants
- MAX_POLL_SECONDS
- POLL_INTERVAL
Public Class Methods
# File app/services/trino_client.rb, line 17 def initialize(endpoint: ENV.fetch("TRINO_URL"), catalog_name: nil, transport: HttpTransport.new, query_timeout: nil) @endpoint = endpoint @catalog_name = catalog_name @transport = transport @query_timeout = query_timeout end
Creates the client with an endpoint and optional default catalog.
@param endpoint [String] the Trino coordinator URL @param catalog_name [String, nil] the default catalog header value @param transport [HttpTransport] injectable transport (tests) @param query_timeout [Integer, nil] per-query timeout in seconds (nil = MAX_POLL_SECONDS)
Public Instance Methods
Source
# File app/services/trino_client.rb, line 48 def query_column(sql, column) poll(sql, limit: nil).filter_map { |row| row[column] } end
Runs SQL and returns the values of a column across all rows. For small result sets (DISTINCT + LIMIT) this drains all pages; for a single value prefer query_scalar.
@param sql [String] the query @param column [String] the column to read @return [Array] the column values
Source
# File app/services/trino_client.rb, line 36 def query_scalar(sql, column) rows = poll(sql, limit: 1) rows.first&.fetch(column, nil) end
Runs SQL and returns the value of a single column in the first row. Stops paginating after the first row β no need to drain every page.
@param sql [String] the query @param column [String] the column to read @return [Object, nil] the first rowβs value
Source
# File app/services/trino_client.rb, line 26 def run_with_names(sql) poll(sql, limit: nil) end
Runs arbitrary SQL and returns the rows as hashes keyed by column name.