Class: Pinot::Client
- Inherits:
-
Object
- Object
- Pinot::Client
- Defined in:
- lib/pinot/client.rb
Instance Attribute Summary collapse
-
#controller_host ⇒ Object
readonly
Returns the value of attribute controller_host.
-
#controller_port ⇒ Object
readonly
Returns the value of attribute controller_port.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Instance Method Summary collapse
- #controller_uri ⇒ Object
- #create_schema(schema, override: true, force: false) ⇒ Object
- #create_table(schema) ⇒ Object
- #delete_segments(name, type: :offline) ⇒ Object
- #delete_table(name, type: :offline) ⇒ Object
- #execute(sql) ⇒ Object
- #http(content_type: "application/json") ⇒ Object
- #ingest_json(file, table:) ⇒ Object
-
#initialize(host:, port:, controller_port:, controller_host: nil, protocol: :http) ⇒ Client
constructor
A new instance of Client.
- #query_sql_uri ⇒ Object
- #schema(name) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(host:, port:, controller_port:, controller_host: nil, protocol: :http) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 |
# File 'lib/pinot/client.rb', line 5 def initialize(host:, port:, controller_port:, controller_host: nil, protocol: :http) @host = host @port = port @controller_port = controller_port @controller_host = controller_host || host @protocol = protocol end |
Instance Attribute Details
#controller_host ⇒ Object (readonly)
Returns the value of attribute controller_host.
3 4 5 |
# File 'lib/pinot/client.rb', line 3 def controller_host @controller_host end |
#controller_port ⇒ Object (readonly)
Returns the value of attribute controller_port.
3 4 5 |
# File 'lib/pinot/client.rb', line 3 def controller_port @controller_port end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/pinot/client.rb', line 3 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/pinot/client.rb', line 3 def port @port end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
3 4 5 |
# File 'lib/pinot/client.rb', line 3 def protocol @protocol end |
Instance Method Details
#controller_uri ⇒ Object
73 74 75 |
# File 'lib/pinot/client.rb', line 73 def controller_uri "#{protocol}://#{controller_host}:#{controller_port}" end |
#create_schema(schema, override: true, force: false) ⇒ Object
59 60 61 62 63 |
# File 'lib/pinot/client.rb', line 59 def create_schema(schema, override: true, force: false) url = "#{controller_uri}/schemas?override=#{override}&force=#{force}" response = http.post(url, body: schema) JSON.parse(response) end |
#create_table(schema) ⇒ Object
30 31 32 33 34 |
# File 'lib/pinot/client.rb', line 30 def create_table(schema) url = "#{controller_uri}/tables" response = http.post(url, body: schema) JSON.parse(response) end |
#delete_segments(name, type: :offline) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/pinot/client.rb', line 23 def delete_segments(name, type: :offline) type = type.to_s.upcase url = "#{controller_uri}/segments/#{name}?type=#{type}" response = http.delete(url) JSON.parse(response) end |
#delete_table(name, type: :offline) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/pinot/client.rb', line 36 def delete_table(name, type: :offline) type = type.to_s.downcase url = "#{controller_uri}/tables/#{name}?type=#{type}" response = http.delete(url) JSON.parse(response) end |
#execute(sql) ⇒ Object
13 14 15 |
# File 'lib/pinot/client.rb', line 13 def execute(sql) Response.new(JSON.parse(http.post(query_sql_uri, json: {sql: sql}))) end |
#http(content_type: "application/json") ⇒ Object
65 66 67 |
# File 'lib/pinot/client.rb', line 65 def http(content_type: "application/json") HTTPX.with(headers: {"Content-Type" => content_type}) end |
#ingest_json(file, table:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pinot/client.rb', line 43 def ingest_json(file, table:) url = "#{controller_uri}/ingestFromFile?tableNameWithType=#{table}&batchConfigMapStr=%7B%22inputFormat%22%3A%22json%22%7D" content_type = "multipart/form-data" response = HTTPX.post( url, form: { file: { filename: File.basename(file.path), content_type: content_type, body: file.read } } ) JSON.parse(response) end |
#query_sql_uri ⇒ Object
77 78 79 |
# File 'lib/pinot/client.rb', line 77 def query_sql_uri "#{uri}/query/sql" end |
#schema(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/pinot/client.rb', line 17 def schema(name) url = "#{controller_uri}/schemas/#{name}" response = http.get(url) JSON.parse(response) end |
#uri ⇒ Object
69 70 71 |
# File 'lib/pinot/client.rb', line 69 def uri "#{protocol}://#{host}:#{port}" end |