Class: Pinot::SchemaClient

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(controller_address, headers: {}, http_client: nil) ⇒ SchemaClient

Returns a new instance of SchemaClient.

Parameters:

  • controller_address (String)

    base URL e.g. “controller:9000” or “controller:9000” or “controller:9000

  • headers (Hash) (defaults to: {})

    extra HTTP headers for every request

  • http_client (HttpClient, nil) (defaults to: nil)

    optional pre-configured client



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", ... }

Parameters:

  • table (String)

Returns:

  • (Hash{String => 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.

Parameters:

  • table (String)

    table name (without _OFFLINE / _REALTIME suffix)

Returns:

  • (Hash)

    raw schema JSON

Raises:



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.

Parameters:

  • table (String)

    table name (without _OFFLINE / _REALTIME suffix)

Returns:

  • (Hash)

    raw tableConfig JSON

Raises:



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_tablesArray<String>

Returns an array of all table names known to the controller.

Returns:

  • (Array<String>)


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.

Parameters:

  • table (String)

Returns:

  • (Boolean)


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