Class: Pinot::SchemaClient
- Inherits:
-
Object
- Object
- Pinot::SchemaClient
- Defined in:
- lib/pinot/schema_client.rb
Overview
Thin client for the Pinot Controller REST API — table listing and schema introspection. Useful for tooling, migrations, and debugging column types.
Usage
client = Pinot::SchemaClient.new("http://controller:9000")
client.list_tables # => ["baseballStats", "orders", ...]
client.get_schema("baseballStats") # => Hash (raw schema JSON)
client.get_table_config("baseballStats")# => Hash (raw tableConfig JSON)
client.table_exists?("orders") # => true / false
Authentication / extra headers
client = Pinot::SchemaClient.new(
"https://controller:9000",
headers: { "Authorization" => "Bearer <token>" }
)
The client is intentionally stateless and lightweight — it uses a shared HttpClient (connection pool) but does not perform background polling.
Constant Summary collapse
- TABLES_PATH =
"/tables".freeze
- SCHEMA_PATH =
"/schemas/%<table>s".freeze
- TABLE_CONFIG_PATH =
"/tables/%<table>s".freeze
Instance Method Summary collapse
-
#column_types(table) ⇒ Hash{String => String}
Returns the column names and their data types for a table.
-
#get_schema(table) ⇒ Hash
Returns the schema for a table as a Hash.
-
#get_table_config(table) ⇒ Hash
Returns the full table config (including segmentsConfig, tableIndexConfig, tenants, etc.) for a table as a Hash.
-
#initialize(controller_address, headers: {}, http_client: nil) ⇒ SchemaClient
constructor
A new instance of SchemaClient.
-
#list_tables ⇒ Array<String>
Returns an array of all table names known to the controller.
-
#table_exists?(table) ⇒ Boolean
Returns true when the controller knows about the given table.
Constructor Details
#initialize(controller_address, headers: {}, http_client: nil) ⇒ SchemaClient
Returns a new instance of SchemaClient.
36 37 38 39 40 |
# File 'lib/pinot/schema_client.rb', line 36 def initialize(controller_address, headers: {}, http_client: nil) @base = normalize_address(controller_address) @headers = { "Accept" => "application/json" }.merge(headers) @http = http_client || HttpClient.new end |
Instance Method Details
#column_types(table) ⇒ Hash{String => String}
Returns the column names and their data types for a table.
Convenience wrapper around get_schema that returns a flat Hash:
{ "playerId" => "INT", "playerName" => "STRING", ... }
89 90 91 92 93 94 95 96 97 |
# File 'lib/pinot/schema_client.rb', line 89 def column_types(table) schema = get_schema(table) dims = schema["dimensionFieldSpecs"] || [] metrics = schema["metricFieldSpecs"] || [] date_time = schema["dateTimeFieldSpecs"] || [] (dims + metrics + date_time).to_h do |spec| [spec["name"], spec["dataType"]] end end |
#get_schema(table) ⇒ Hash
Returns the schema for a table as a Hash.
56 57 58 |
# File 'lib/pinot/schema_client.rb', line 56 def get_schema(table) get_json(format(SCHEMA_PATH, table: table)) end |
#get_table_config(table) ⇒ Hash
Returns the full table config (including segmentsConfig, tableIndexConfig, tenants, etc.) for a table as a Hash.
67 68 69 |
# File 'lib/pinot/schema_client.rb', line 67 def get_table_config(table) get_json(format(TABLE_CONFIG_PATH, table: table)) end |
#list_tables ⇒ Array<String>
Returns an array of all table names known to the controller.
45 46 47 48 |
# File 'lib/pinot/schema_client.rb', line 45 def list_tables body = get_json(TABLES_PATH) body["tables"] || [] end |
#table_exists?(table) ⇒ Boolean
Returns true when the controller knows about the given table.
75 76 77 78 79 80 |
# File 'lib/pinot/schema_client.rb', line 75 def table_exists?(table) get_table_config(table) true rescue TableNotFoundError false end |