activerecord-pinot-adapter 0.1.1 → 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: c09ea0dd800fdfd76f57fae011fbe90ef3e42498ea51b58d86cfcd0b22611a89
4
- data.tar.gz: e336a92e3d15be236bfbfea8cb775be28f9d8b459e8ff04a92fd92071d9915a5
3
+ metadata.gz: 28c4f9381e73ca7e68d549d47f4a7dff6b7740b33bd965833e0397f07e27c3da
4
+ data.tar.gz: 05220a45210bd4e03329891870bb428c4f613ea60a4d4367c7d9bccf1b1d66f2
5
5
  SHA512:
6
- metadata.gz: 33d9d6d982ec4b36813addc7a4e9463cc1279befb2e1692d7a66aa634e306bb5d7ad7a330c71af8ca3cbb542caf689a02ad4a581b6905f3d4da8a8d36caf7cd5
7
- data.tar.gz: 63a9ab22309ef70b77a9ef72d319a1311f288c1adb62f72821e2f258bf5465695e228d6e8589bcfcca51479914c415f43c73d451e5f31ccc4510c10591acb115
6
+ metadata.gz: a4d61494dcafd454bfac76959c8e77bab174cc9472187dd19bd0715cf8ba8786b610afb86852b19c55694709ca2e2b6ab40076ebd25be28f3ea4a4bb127281aa
7
+ data.tar.gz: 2b723803e42dd71eab40751e15c34246fd9eca74593fc87fc4318565c0a46eccf60f291bc7efcac1bd8a5cf36c79c39fc1f09dafd27e6e82a6945e0af79d013b
data/README.md CHANGED
@@ -1,24 +1,63 @@
1
- # Activerecord::Pinot::Adapter
1
+ # Pinot Adapter
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Ruby on Rails Active Record database adapter for Apache Pinot, a client library for Pinot-compatible database servers.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activerecord/pinot/adapter`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Disclaimer: This is alpha stage software, please use with caution.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Install the gem and add to the application's Gemfile by executing:
12
10
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
11
+ $ bundle add activerecord-pinot-adapter
14
12
 
15
13
  If bundler is not being used to manage dependencies, install the gem by executing:
16
14
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15
+ $ gem install activerecord-pinot-adapter
16
+
17
+ This adapter uses the [pinot](https://rubygems.org/gems/pinot) gem, that is the Apache Pinot client, you can install an specific version of the client, but it's highly recommended to let this gem manage its own dependency.
18
18
 
19
19
  ## Usage
20
20
 
21
21
  TODO: Write usage instructions here
22
+ First step is to configure the `config/database.yml`
23
+
24
+ ```yaml
25
+ pinot:
26
+ adapter: pinot
27
+ host: host.to.your.broker.com
28
+ port: 443
29
+ controller_host: host.to.your.controller.com
30
+ controller_port: 443
31
+ protocol: https
32
+ ```
33
+
34
+ Adapter also supports:
35
+
36
+ - `socks5_uri` in case you are using are using a jump host as your socks proxy. Please provide the full uri with protocol and port (eg. `socks5://127.0.0.1:8080`)
37
+ - `bearer_token` in case your broker/host need a bearer token to authenticate the requests
38
+ - `query_options` in case needs to specify pinot [query options](https://docs.pinot.apache.org/users/user-guide-query/query-options), it's a hash, and keys are on the _underscore_ format.
39
+
40
+ By design we avoided trying to guess the port and protocol based on any provided information, so port is always required, and protocol by default is `http` to make easier to test local, and then must be specified as `https` for production.
41
+
42
+ ### Models
43
+
44
+ To start using on your application, it's recommended to create an abstract class, so it's only needed to specify the connection database in one place.
45
+
46
+ ```ruby
47
+ class PinotRecord < ApplicationRecord
48
+ self.abstract_class = true
49
+ connects_to database: {writing: :pinot, reading: :pinot}
50
+ end
51
+ ```
52
+
53
+ After abstract class, just use it on any class you want to use.
54
+
55
+ ```ruby
56
+ class MyModel < PinotRecord
57
+ end
58
+ ```
59
+
60
+ If you are incrementally migrating from one database to Pinot, or want to use both in parallel, prefix your models on a namespace, and use `self.table_name=` to specify the correct table name for the model.
22
61
 
23
62
  ## Development
24
63
 
@@ -11,6 +11,7 @@ module ActiveRecord
11
11
  "pinot_type" => "dimension"
12
12
  }
13
13
  end
14
+ schema["metricFieldSpecs"] ||= []
14
15
  schema["metricFieldSpecs"].each do |f|
15
16
  fields << {
16
17
  "name" => f["name"],
@@ -17,15 +17,31 @@ module ActiveRecord
17
17
  "INT" => Type::Integer.new,
18
18
  "TIMESTAMP" => Type::DateTime.new,
19
19
  "FLOAT" => Type::Decimal.new,
20
- "LONG" => Type::Decimal.new
20
+ "LONG" => Type::Decimal.new,
21
+ "STRING" => Type::String.new,
22
+ "JSON" => ActiveRecord::Type::Json.new
21
23
  }
22
24
  def initialize(config = {})
23
25
  @pinot_host = config.fetch(:host)
24
26
  @pinot_port = config.fetch(:port)
25
27
  @pinot_controller_port = config.fetch(:controller_port)
26
28
  @pinot_controller_host = config.fetch(:controller_host) || @pinot_host
29
+ @pinot_socks5_uri = config.fetch(:socks5_uri, nil)
30
+ @pinot_bearer_token = config.fetch(:bearer_token, nil)
31
+ @pinot_protocol = config.fetch(:protocol, "http")
32
+ @pinot_query_options = config.fetch(:query_options, {})
27
33
  # TODO: does it need connection pooling?
28
- @pinot_client = ::Pinot::Client.new(host: @pinot_host, port: @pinot_port, controller_host: @pinot_controller_host, controller_port: @pinot_controller_port)
34
+
35
+ @pinot_client = ::Pinot::Client.new(
36
+ host: @pinot_host,
37
+ port: @pinot_port,
38
+ controller_host: @pinot_controller_host,
39
+ controller_port: @pinot_controller_port,
40
+ protocol: @pinot_protocol,
41
+ socks5_uri: @pinot_socks5_uri,
42
+ bearer_token: @pinot_bearer_token,
43
+ query_options: @pinot_query_options
44
+ )
29
45
 
30
46
  super(config)
31
47
  end
@@ -34,13 +50,21 @@ module ActiveRecord
34
50
  false
35
51
  end
36
52
 
53
+ def prepared_statements
54
+ false
55
+ end
56
+
37
57
  def table_structure(table_name)
38
58
  schema = @pinot_client.schema(table_name)
39
59
  @table_structure = TableStructure.from_schema(schema)
40
60
  @table_structure.sort_by! { |x| x[:name] }
41
61
  end
42
62
 
43
- def new_column_from_field(table_name, field, definitions)
63
+ def data_sources
64
+ @pinot_data_sources ||= @pinot_client.tables["tables"]
65
+ end
66
+
67
+ def new_column_from_field(table_name, field, definitions = nil)
44
68
  default = nil
45
69
 
46
70
  type_metadata = fetch_type_metadata(field["type"])
@@ -116,11 +140,13 @@ module ActiveRecord
116
140
  )
117
141
  end
118
142
 
119
- def data_source_sql(name = nil, type: nil)
143
+ def exec_query(sql, name = "SQL", binds = [], prepare: false)
144
+ internal_exec_query(sql, name, binds, prepare: prepare, async: false)
120
145
  end
121
146
 
122
147
  def primary_keys(table_name)
123
- []
148
+ # TODO: implement
149
+ [:id]
124
150
  end
125
151
  end
126
152
 
@@ -3,7 +3,7 @@
3
3
  module Activerecord
4
4
  module Pinot
5
5
  module Adapter
6
- VERSION = "0.1.1"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-pinot-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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-16 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: activerecord
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: 0.2.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 0.2.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +126,7 @@ metadata:
126
126
  homepage_uri: https://github.com/fernandes/activerecord-pinot-adapter
127
127
  source_code_uri: https://github.com/fernandes/activerecord-pinot-adapter
128
128
  changelog_uri: https://github.com/fernandes/activerecord-pinot-adapter/blob/main/CHANGELOG.md
129
- post_install_message:
129
+ post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
132
132
  - lib
@@ -141,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.5.3
145
- signing_key:
144
+ rubygems_version: 3.5.14
145
+ signing_key:
146
146
  specification_version: 4
147
147
  summary: ActiveRecord Apache Pinot Adapter
148
148
  test_files: []