pinot 0.1.3 → 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: 6443fe94263c767cc5039c400a7684fae467ab856e2d04253959ef6e0042e1d1
4
- data.tar.gz: 4cb05bc8fe5c6f9b83cffa623e359f3c90fdc768575033e13968a78c5f7d43ff
3
+ metadata.gz: aef65c895b1ae235ffe6f25f80a9a18cc78d2fabf65f01bc75b10a1478bd02d3
4
+ data.tar.gz: bbd2cdc1d049f5a847ef14c93601fcdba235cf9d0eccdcefdbc6d9f5575d3f47
5
5
  SHA512:
6
- metadata.gz: f217a53c1c2712e8d098aa94e5f3a4a93995e0839cad0f1a640f78c6e5269f7847afe9ef6d8344c2eb1d1df85ea087a5fb0db853ce3eb8c2d65d029ddbc6d554
7
- data.tar.gz: 70694ca05dd5de01ef4e1d8af6e8bc61b899840e73ccb2b9680150d5d9dd48553fba2002607e6b22a9e3e1939d08d625e8c1d672adc6f4001345ad0ea5da9c5a
6
+ metadata.gz: 38f78b8f0bb9bb60e3f88d5fdcce033bdb16d8f0544bdd9d02867c55d58f5ee60e9fe666579020bfd0b597c05ec5720720ac13ee0f987ce0eb4b57afc7759ea3
7
+ data.tar.gz: 92391075e082157fdf2c6b662640578ca5633374e38525b031b56011ee481aaf5c56e1f3abf7180d2b315756d5c0020773f22c520ca517de8cb380d928255cfc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## [0.1.3] - 2024-07-02
4
8
 
5
9
  - feature: add tables command
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
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.3"
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.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Celso Fernandes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-02 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