Class: Pinot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pinot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_hostObject (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_portObject (readonly)

Returns the value of attribute controller_port.



3
4
5
# File 'lib/pinot/client.rb', line 3

def controller_port
  @controller_port
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/pinot/client.rb', line 3

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/pinot/client.rb', line 3

def port
  @port
end

#protocolObject (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_uriObject



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_uriObject



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

#uriObject



69
70
71
# File 'lib/pinot/client.rb', line 69

def uri
  "#{protocol}://#{host}:#{port}"
end