chalk_ruby 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 394c3d1735d1ee6d9ecc4df5d6ba9627a7323bc42a0c89df4879aadfc7a9b923
4
- data.tar.gz: 62bca659a3b33122657df4c6bfccc2a420de7d815d8a4da09e7f3b01b13ef683
3
+ metadata.gz: 4165478b519e054426f89a0e2a5baa7a8f1ef2e4eb3d23a4489bb478e96adca2
4
+ data.tar.gz: c51633a4a2a3ee79dfb2f1a22d9bf80d9a6c8719f587f71d894b7be877f1fa91
5
5
  SHA512:
6
- metadata.gz: 5027aaea4f0bc4c65b3f51d8552992c4831137f4a118f82f308332c9277381b2c4d86c71d4858aaf6f53a9518f6654918fec701188abb030dd48891b01f0b917
7
- data.tar.gz: 90555aee1fde8a17db6624ea7d9ed8049e5ffee4f4ce4b2bdb1171edf91aae422cae8366958223ffe343bc9c2c69bdbacdb796079aca318519ba0503c56661a4
6
+ metadata.gz: 3a52b774af1729f1ba7194c97aa9ba8b323b3bbb47efe06dd9e8cfd5124e3fe963eb5fab5ecf698614cc9a3f4ae6aa09a65c6ff1f770f0d0ae6e257be80a1036
7
+ data.tar.gz: a4f91f89f52e8b3b036e3d19c1dde26845e430fa69e766cf88e0e7122f5a12f2750c8d689bfa7cdfc5d6094b307b608a8d79aeec9c5df0c462cf7a19450e38aa
data/chalk_ruby.gemspec CHANGED
@@ -42,11 +42,11 @@ Gem::Specification.new do |spec|
42
42
 
43
43
  spec.add_dependency 'multi_json', '~> 1.0'
44
44
  spec.add_dependency 'net-http-persistent'
45
- spec.add_dependency 'red-arrow', '~> 18.0.0'
46
45
 
47
46
  spec.add_development_dependency 'httpclient'
48
47
  spec.add_development_dependency 'm'
49
48
  spec.add_development_dependency 'minitest'
50
49
  spec.add_development_dependency 'minitest-hooks'
51
50
  spec.add_development_dependency 'minitest-proveit'
51
+ spec.add_development_dependency 'red-arrow', '~> 18.0.0'
52
52
  end
@@ -228,7 +228,7 @@ module ChalkRuby
228
228
  end
229
229
 
230
230
  # Warm up connections to the API and query servers by establishing
231
- # connections without making actual requests
231
+ # TCP connections with lightweight HEAD requests
232
232
  def warm_connections
233
233
  # Get the query server host
234
234
  query_host = query_server_host
@@ -242,13 +242,23 @@ module ChalkRuby
242
242
 
243
243
  private
244
244
 
245
- # Establish a connection to a host without making a request
245
+ # Establish a connection to a host by making a lightweight request
246
246
  def warm_connection(host)
247
247
  # Access the underlying HTTP requester
248
248
  requester = @transporter.instance_variable_get(:@http_requester)
249
249
 
250
- # This will create and cache the Faraday connection
251
- requester.connection(host)
250
+ # Create the Faraday connection object
251
+ connection = requester.connection(host)
252
+
253
+ # Make a HEAD request to "/" to actually establish the TCP connection
254
+ # HEAD is used as it's lightweight and most servers support it
255
+ begin
256
+ connection.head('/')
257
+ rescue => e
258
+ # Ignore errors - we're just warming the connection
259
+ # The server might not support HEAD on /, but the TCP connection
260
+ # will still be established
261
+ end
252
262
  end
253
263
 
254
264
  def api_server_request(method:, path:, body:, headers:)
@@ -168,6 +168,9 @@ module ChalkRuby
168
168
  correlation_id: nil,
169
169
  planner_options: nil
170
170
  )
171
+ unless red_arrow_available?
172
+ raise NotImplementedError, "query_bulk requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
173
+ end
171
174
  # Convert input to feather format
172
175
  inputs_feather = to_feather(input)
173
176
 
@@ -412,10 +415,22 @@ module ChalkRuby
412
415
 
413
416
  private
414
417
 
418
+ def red_arrow_available?
419
+ @red_arrow_available ||= begin
420
+ require 'arrow'
421
+ true
422
+ rescue LoadError
423
+ false
424
+ end
425
+ end
426
+
415
427
  # Converts Arrow binary data to an array of hashes
416
428
  # @param arrow_data [String] Binary Arrow data (IPC stream format)
417
429
  # @return [Array<Hash>] Array of hashes with column name as keys and Ruby values
418
430
  def arrow_table_to_array(arrow_data)
431
+ unless red_arrow_available?
432
+ raise NotImplementedError, "arrow_table_to_array requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
433
+ end
419
434
  require 'arrow'
420
435
 
421
436
  buffer = Arrow::Buffer.new(arrow_data)
@@ -454,23 +469,55 @@ module ChalkRuby
454
469
  end
455
470
 
456
471
  def to_feather(input_hash)
472
+ raise NotImplementedError,
473
+ "Add `gem 'red-arrow', '~> 18.0'` to your Gemfile" unless red_arrow_available?
474
+
457
475
  require 'arrow'
458
476
 
459
- # Ensure all values in the input hash are arrays
460
- array_input_hash = input_hash.transform_values { |v| v.is_a?(Array) ? v : [v] }
477
+ # Normalise column data
478
+ array_input_hash = input_hash.transform_keys(&:to_s)
479
+ .transform_values { |v| v.is_a?(Array) ? v : [v] }
461
480
 
462
- # Create a table from the transformed input hash
463
- table = Arrow::Table.new(array_input_hash)
481
+ lengths = array_input_hash.values.map(&:length).uniq
482
+ raise ArgumentError, "Columns must be the same length (got #{lengths})" unless lengths.one?
464
483
 
465
- # Write to feather format in memory
466
- buffer = Arrow::ResizableBuffer.new(0)
484
+ table = Arrow::Table.new(array_input_hash)
467
485
 
486
+ buffer = Arrow::ResizableBuffer.new(0)
468
487
  output = Arrow::BufferOutputStream.new(buffer)
469
488
 
489
+ # ──────────────────────────────────────────────────────────
470
490
  table.write_as_feather(output)
491
+ output.close # ← **critical**: flush footer
492
+ # ──────────────────────────────────────────────────────────
471
493
 
472
- # Remove trailing null bytes from the resizable buffer; the buffer is 512 aligned
473
- buffer.data.to_s.b.gsub(/ARROW1(.*)ARROW1.*/m) {"ARROW1#{$1}ARROW1"}
494
+ # The stream writes exactly `output.tell` bytes; slice to that.
495
+ bytes_written = output.tell
496
+ buffer.data.to_s.b.byteslice(0, bytes_written)
474
497
  end
475
498
  end
499
+
500
+ # def to_feather(input_hash)
501
+ # unless red_arrow_available?
502
+ # raise NotImplementedError, "to_feather requires the 'red-arrow' gem. Please add it to your Gemfile: gem 'red-arrow', '~> 18.0.0'"
503
+ # end
504
+ # require 'arrow'
505
+ #
506
+ # # Ensure all values in the input hash are arrays
507
+ # array_input_hash = input_hash.transform_values { |v| v.is_a?(Array) ? v : [v] }
508
+ #
509
+ # # Create a table from the transformed input hash
510
+ # table = Arrow::Table.new(array_input_hash)
511
+ #
512
+ # # Write to feather format in memory
513
+ # buffer = Arrow::ResizableBuffer.new(0)
514
+ #
515
+ # output = Arrow::BufferOutputStream.new(buffer)
516
+ #
517
+ # table.write_as_feather(output)
518
+ #
519
+ # # Remove trailing null bytes from the resizable buffer; the buffer is 512 aligned
520
+ # buffer.data.to_s.b.gsub(/ARROW1(.*)ARROW1.*/m) {"ARROW1#{$1}ARROW1"}
521
+ # end
522
+ # end
476
523
  end
@@ -1,3 +1,3 @@
1
1
  module ChalkRuby
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
@@ -3,8 +3,8 @@ require 'rspec/autorun'
3
3
  require 'chalk_ruby/client'
4
4
  require 'chalk_ruby/error'
5
5
 
6
- CLIENT_ID = ''
7
- CLIENT_SECRET = ''
6
+ CLIENT_ID = 'client-9314816c664be6cb04678e5e3d0e50e2'
7
+ CLIENT_SECRET = 'secret-51f3ce3d4f701f23afdd622015732edf1eb62d0d678b3511b615f9b1f00b4a7d'
8
8
 
9
9
  RSpec.describe 'Online query' do
10
10
  it 'should accept valid queries' do
@@ -14,6 +14,8 @@ require 'chalk_ruby/protos/chalk/engine/v1/query_server_services_pb'
14
14
  require 'arrow'
15
15
 
16
16
 
17
+ CLIENT_ID = 'client-9314816c664be6cb04678e5e3d0e50e2'
18
+ CLIENT_SECRET = 'secret-51f3ce3d4f701f23afdd622015732edf1eb62d0d678b3511b615f9b1f00b4a7d'
17
19
 
18
20
 
19
21
  RSpec.describe ChalkRuby::GrpcClient do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chalk_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chalk AI, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-07 00:00:00.000000000 Z
11
+ date: 2025-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,20 +140,6 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
- - !ruby/object:Gem::Dependency
144
- name: red-arrow
145
- requirement: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - "~>"
148
- - !ruby/object:Gem::Version
149
- version: 18.0.0
150
- type: :runtime
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - "~>"
155
- - !ruby/object:Gem::Version
156
- version: 18.0.0
157
143
  - !ruby/object:Gem::Dependency
158
144
  name: httpclient
159
145
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +210,20 @@ dependencies:
224
210
  - - ">="
225
211
  - !ruby/object:Gem::Version
226
212
  version: '0'
213
+ - !ruby/object:Gem::Dependency
214
+ name: red-arrow
215
+ requirement: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - "~>"
218
+ - !ruby/object:Gem::Version
219
+ version: 18.0.0
220
+ type: :development
221
+ prerelease: false
222
+ version_requirements: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - "~>"
225
+ - !ruby/object:Gem::Version
226
+ version: 18.0.0
227
227
  description: A simple Ruby client for Chalk
228
228
  email:
229
229
  - help@chalk.ai