pinot 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc12c931af8cd247929cbab2185c0ccd69a7d241e750211ba95287af996e3914
4
- data.tar.gz: 3682d27b5db1c615f1084af77ef1d64496859a6db92a21a4bdf4d45761f8b741
3
+ metadata.gz: aef65c895b1ae235ffe6f25f80a9a18cc78d2fabf65f01bc75b10a1478bd02d3
4
+ data.tar.gz: bbd2cdc1d049f5a847ef14c93601fcdba235cf9d0eccdcefdbc6d9f5575d3f47
5
5
  SHA512:
6
- metadata.gz: f9a4464727f662abe8c7cace2952076e45ea08802d1380a09568b9c60f4d2b58b6f8bd501f29216e59525a2d54f131bd66d19de12dbb7a5880780dc1bab06831
7
- data.tar.gz: 890d0696eb36c2059873a9d8330f584fdd3b6ff13870567f5eee7d69a7fd286f895b9143f6ecc387a150fce460f27e3c7db4b063fb1500d9d849a7403d3c3468
6
+ metadata.gz: 38f78b8f0bb9bb60e3f88d5fdcce033bdb16d8f0544bdd9d02867c55d58f5ee60e9fe666579020bfd0b597c05ec5720720ac13ee0f987ce0eb4b57afc7759ea3
7
+ data.tar.gz: 92391075e082157fdf2c6b662640578ca5633374e38525b031b56011ee481aaf5c56e1f3abf7180d2b315756d5c0020773f22c520ca517de8cb380d928255cfc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-07-12
4
+
5
+ - feature: Add support for Apache Pinot [Query Options](https://docs.pinot.apache.org/users/user-guide-query/query-options)
6
+
7
+ ## [0.1.3] - 2024-07-02
8
+
9
+ - feature: add tables command
10
+
3
11
  ## [0.1.2] - 2024-05-29
4
12
 
5
13
  - feature: support socks5
data/README.md CHANGED
@@ -51,6 +51,16 @@ resp.columns
51
51
 
52
52
  It's not on the public API, but the instance variable `@payload` contains all information returned from the Pinot cluster in case can help with troubleshooting
53
53
 
54
+ ### Query Options
55
+
56
+ In case there's the need to pass any Pinot [query options](https://docs.pinot.apache.org/users/user-guide-query/query-options), it's can be done when initializing the client.
57
+
58
+ ```ruby
59
+ client = Pinot::Client.new(query_options: {use_multistage_engine: true}, **options)
60
+ ```
61
+
62
+ Any of the query options on the documentation is supported, remember to use its name with underscore formatting.
63
+
54
64
  ### Authentication
55
65
 
56
66
  In case your pinot cluster is using authentication bearer token, you can specify it on the client constructor
@@ -0,0 +1,51 @@
1
+ module Pinot
2
+ class Client
3
+ class QueryOptions
4
+ class InvalidOption < StandardError; end
5
+
6
+ OPTIONS = [:timeout_ms, :enable_null_handling, :explain_plan_verbose, :use_multistage_engine, :max_execution_threads, :num_replica_groups_to_query, :min_segment_group_trim_size, :min_server_group_trim_size, :skip_indexes, :skip_upsert, :use_star_tree, :and_scan_reordering, :max_rows_in_join, :in_predicate_pre_sorted, :in_predicate_lookup_algorithm, :max_server_response_size_bytes, :max_query_response_size_bytes]
7
+
8
+ OPTIONS.each do |opt|
9
+ attr_reader opt
10
+ end
11
+
12
+ def initialize(options = {})
13
+ process_options_hash(options)
14
+ end
15
+
16
+ def available_options
17
+ OPTIONS
18
+ end
19
+
20
+ def to_query_options
21
+ query_options = []
22
+ available_options.each do |opt|
23
+ if (value = send(opt))
24
+ query_options << "#{camelize_option(opt)}=#{value}"
25
+ end
26
+ end
27
+
28
+ return nil if query_options.empty?
29
+
30
+ query_options.join(";")
31
+ end
32
+
33
+ private
34
+
35
+ # avoid monkeypatch String#camelize
36
+ def camelize_option(option)
37
+ string = option.to_s
38
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
39
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
40
+ end
41
+
42
+ def process_options_hash(options)
43
+ options.each_pair do |k, v|
44
+ raise InvalidOption.new("`#{k}' is not a valid option for Pinot Client") unless available_options.include?(k.to_sym)
45
+
46
+ instance_variable_set(:"@#{k}", v)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/pinot/client.rb CHANGED
@@ -1,8 +1,10 @@
1
+ require_relative "client/query_options"
2
+
1
3
  module Pinot
2
4
  class Client
3
- attr_reader :host, :port, :controller_host, :controller_port, :protocol, :socks5_uri, :bearer_token
5
+ attr_reader :host, :port, :controller_host, :controller_port, :protocol, :socks5_uri, :bearer_token, :query_options
4
6
 
5
- def initialize(host:, port:, controller_port:, controller_host: nil, protocol: :http, socks5_uri: nil, bearer_token: nil)
7
+ def initialize(host:, port:, controller_port:, controller_host: nil, protocol: :http, socks5_uri: nil, bearer_token: nil, query_options: {})
6
8
  @host = host
7
9
  @port = port
8
10
  @controller_port = controller_port
@@ -10,10 +12,16 @@ module Pinot
10
12
  @protocol = protocol
11
13
  @socks5_uri = socks5_uri
12
14
  @bearer_token = bearer_token
15
+ @query_options = QueryOptions.new(query_options)
13
16
  end
14
17
 
15
18
  def execute(sql)
16
- response = http.post(query_sql_uri, json: {sql: sql})
19
+ query_params = {sql: sql}
20
+ if (value = query_options.to_query_options)
21
+ query_params["queryOptions"] = value
22
+ end
23
+
24
+ response = http.post(query_sql_uri, json: query_params)
17
25
  return response if response.is_a?(HTTPX::ErrorResponse)
18
26
  Response.new(JSON.parse(response))
19
27
  end
@@ -66,11 +74,17 @@ module Pinot
66
74
  JSON.parse(response)
67
75
  end
68
76
 
77
+ def tables
78
+ url = "#{controller_uri}/tables"
79
+ response = http.get(url)
80
+ JSON.parse(response)
81
+ end
82
+
69
83
  def http(content_type: "application/json")
70
84
  return @http if !@http.nil?
71
85
  default_headers = {"Content-Type" => content_type}
72
86
  default_headers["Authorization"] = "Bearer #{bearer_token}" if bearer_token
73
- @http = HTTPX.with(headers: default_headers, timeout: { connect_timeout: 5 })
87
+ @http = HTTPX.with(headers: default_headers, timeout: {connect_timeout: 5})
74
88
  if socks5_uri
75
89
  @http = @http.plugin(:proxy).with_proxy(uri: socks5_uri) if socks5_uri
76
90
  end
data/lib/pinot/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pinot
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Celso Fernandes
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-29 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpx
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - lib/pinot.rb
83
83
  - lib/pinot/client.rb
84
+ - lib/pinot/client/query_options.rb
84
85
  - lib/pinot/response.rb
85
86
  - lib/pinot/version.rb
86
87
  - sig/pinot.rbs
@@ -90,7 +91,7 @@ metadata:
90
91
  homepage_uri: https://github.com/fernandes/pinot-ruby
91
92
  source_code_uri: https://github.com/fernandes/pinot
92
93
  changelog_uri: https://github.com/fernandes/pinot/blob/main/CHANGELOG.md
93
- post_install_message:
94
+ post_install_message:
94
95
  rdoc_options: []
95
96
  require_paths:
96
97
  - lib
@@ -105,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []
108
- rubygems_version: 3.5.3
109
- signing_key:
109
+ rubygems_version: 3.5.14
110
+ signing_key:
110
111
  specification_version: 4
111
112
  summary: Client for Apache Pinot
112
113
  test_files: []