galaaz 2.1.0 → 2.1.1

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.
data/lib/galaaz_jruby.rb CHANGED
@@ -3,14 +3,20 @@
3
3
  # JVM arguments required for every JRuby process that loads Galaaz (Apache Arrow memory
4
4
  # on Java 9+). Rake and Ruby launchers should use GalaazJRuby.shell_j_arg_string.
5
5
  #
6
+ # The opens flag must be on the *JVM at startup*. `jruby -J--add-opens=... -S bundle exec`
7
+ # does not pass it to the child rspec JVM — export JAVA_OPTS instead (see
8
+ # +apply_java_opts_env!+ and bin/galaaz_jruby_env.inc.sh).
9
+ #
6
10
  # Optional extra flags (e.g. -J-Xmx4g): set environment variable GALAAZ_JRUBY_OPTS
7
11
  # (space-separated; passed through to the shell unquoted).
8
12
  #
9
13
  # Bash entrypoints (bin/run_rspec, etc.) source bin/galaaz_jruby_env.inc.sh — keep the
10
14
  # -J list there identical to REQUIRED_JRUBY_J_ARGS below.
11
15
  module GalaazJRuby
12
- REQUIRED_JRUBY_J_ARGS = %w[
13
- -J--add-opens=java.base/java.nio=ALL-UNNAMED
16
+ JAVA_NIO_ADD_OPENS = '--add-opens=java.base/java.nio=ALL-UNNAMED'
17
+
18
+ REQUIRED_JRUBY_J_ARGS = %W[
19
+ -J#{JAVA_NIO_ADD_OPENS}
14
20
  ].freeze
15
21
 
16
22
  OPTIONAL_ENV = 'GALAAZ_JRUBY_OPTS'
@@ -19,4 +25,13 @@ module GalaazJRuby
19
25
  extra = ENV[OPTIONAL_ENV].to_s.strip
20
26
  [REQUIRED_JRUBY_J_ARGS.join(' '), extra].reject(&:empty?).join(' ')
21
27
  end
28
+
29
+ # For subprocess JVMs (and so launchers that exec JRuby after requiring this file
30
+ # pick up the flag). Does not change the already-running JVM.
31
+ def self.apply_java_opts_env!
32
+ opts = ENV['JAVA_OPTS'].to_s
33
+ return if opts.split.include?(JAVA_NIO_ADD_OPENS)
34
+
35
+ ENV['JAVA_OPTS'] = [JAVA_NIO_ADD_OPENS, opts].reject(&:empty?).join(' ')
36
+ end
22
37
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Async synchronization for Stage B1 Arrow IPC handoff.
4
+ # Run: bin/run_all_rspec new_bridge_specs/arrow_ipc_async_spec.rb
5
+
6
+ require 'thread'
7
+ require 'galaaz'
8
+
9
+ RSpec.describe 'Arrow IPC async handoff' do
10
+ before(:all) do
11
+ skip 'R not on PATH' unless system('command -v R >/dev/null 2>&1')
12
+ skip 'Galaaz::ArrowIpc writer backend not available' unless Galaaz::ArrowIpc.available?
13
+ ok = R::Support.eval("requireNamespace('arrow', quietly=TRUE) && requireNamespace('dplyr', quietly=TRUE)")
14
+ skip 'R packages arrow/dplyr are not available' unless ok == true
15
+ @paths = []
16
+ end
17
+
18
+ after(:each) do
19
+ Array(@paths).each { |p| Galaaz::ArrowIpc.release(p) }
20
+ @paths = []
21
+ end
22
+
23
+ def track(path)
24
+ @paths << path
25
+ path
26
+ end
27
+
28
+ it 'happens-before: write+fsync then async open returns correct nrow' do
29
+ values = [1.0, 2.0, 3.0, 4.0]
30
+ path = track(Galaaz::ArrowIpc.write(value: values))
31
+
32
+ done = Queue.new
33
+ # Path-only over the bridge; R reads the IPC file.
34
+ R.eval_r_async("nrow(arrow::read_ipc_file(#{path.inspect}))", timeout: 30) do |result|
35
+ done.push(result)
36
+ end
37
+ r = done.pop
38
+ expect(r).to be_ok
39
+ expect(r.value).to match(/4/)
40
+ end
41
+
42
+ it 'async open then sync R reduction on the proxy' do
43
+ path = track(Galaaz::ArrowIpc.write(value: [10.0, 20.0, 30.0]))
44
+
45
+ done = Queue.new
46
+ R::Async.arrow___read_ipc_file(path, as_data_frame: false, timeout: 30) do |result|
47
+ done.push(result)
48
+ end
49
+ r = done.pop
50
+ expect(r).to be_ok
51
+ expect(r.value).to be_a(R::Object)
52
+
53
+ tbl = r.value
54
+ mean = R.mean(R.dplyr___pull(tbl, :value))
55
+ mean_v = mean.respond_to?(:>>) ? (mean >> 0) : mean
56
+ expect(mean_v).to eq(20.0)
57
+ end
58
+
59
+ it 'two concurrent handoffs do not cross-talk' do
60
+ path_a = track(Galaaz::ArrowIpc.write(tag: ['A'], n: [1]))
61
+ path_b = track(Galaaz::ArrowIpc.write(tag: ['B', 'B'], n: [2, 2]))
62
+
63
+ done = Queue.new
64
+ R.eval_r_async("nrow(arrow::read_ipc_file(#{path_a.inspect}))", timeout: 30) do |result|
65
+ done.push([:a, result])
66
+ end
67
+ R.eval_r_async("nrow(arrow::read_ipc_file(#{path_b.inspect}))", timeout: 30) do |result|
68
+ done.push([:b, result])
69
+ end
70
+
71
+ results = {}
72
+ 2.times do
73
+ key, res = done.pop
74
+ expect(res).to be_ok
75
+ results[key] = res.value
76
+ end
77
+ expect(results[:a]).to match(/1/)
78
+ expect(results[:b]).to match(/2/)
79
+ end
80
+
81
+ it 'missing path fails without hanging' do
82
+ done = Queue.new
83
+ missing = File.join(Galaaz::ArrowIpc.scratch_dir, 'galaaz_missing_async.arrow')
84
+ R.eval_r_async("arrow::read_ipc_file(#{missing.inspect})", timeout: 10) do |result|
85
+ done.push(result)
86
+ end
87
+ r = done.pop
88
+ expect(r).not_to be_ok
89
+ end
90
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Async synchronization for Stage B2 R→Ruby Arrow IPC export.
4
+ # Run: bin/run_all_rspec new_bridge_specs/arrow_ipc_export_async_spec.rb
5
+
6
+ require 'thread'
7
+ require 'galaaz'
8
+
9
+ RSpec.describe 'Arrow IPC export async (Stage B2)' do
10
+ before(:all) do
11
+ skip 'R not on PATH' unless system('command -v R >/dev/null 2>&1')
12
+ skip 'Galaaz::ArrowIpc backend not available' unless Galaaz::ArrowIpc.available?
13
+ ok = R::Support.eval("requireNamespace('arrow', quietly=TRUE)")
14
+ skip 'R package arrow is not available' unless ok == true
15
+ @paths = []
16
+ end
17
+
18
+ after(:each) do
19
+ Array(@paths).each { |p| Galaaz::ArrowIpc.release(p) }
20
+ @paths = []
21
+ end
22
+
23
+ def track(path)
24
+ @paths << path
25
+ path
26
+ end
27
+
28
+ it 'happens-before: async R write_ipc_file then Ruby read matches' do
29
+ in_path = track(Galaaz::ArrowIpc.write(n: [1, 2, 3]))
30
+ out_path = track(Galaaz::ArrowIpc.allocate_path)
31
+
32
+ done = Queue.new
33
+ R.eval_r_async(
34
+ "({ arrow::write_ipc_file(arrow::read_ipc_file(#{in_path.inspect}, as_data_frame=FALSE), #{out_path.inspect}, compression='uncompressed'); 1L })",
35
+ timeout: 30
36
+ ) { |result| done.push(result) }
37
+ r = done.pop
38
+ expect(r).to be_ok
39
+
40
+ cols = Galaaz::ArrowIpc.read(out_path)
41
+ expect(cols['n'].map(&:to_i)).to eq([1, 2, 3])
42
+ end
43
+
44
+ it 'two concurrent R exports do not cross-talk' do
45
+ in_a = track(Galaaz::ArrowIpc.write(tag: ['A']))
46
+ in_b = track(Galaaz::ArrowIpc.write(tag: ['B']))
47
+ out_a = track(Galaaz::ArrowIpc.allocate_path)
48
+ out_b = track(Galaaz::ArrowIpc.allocate_path)
49
+
50
+ done = Queue.new
51
+ R.eval_r_async(
52
+ "({ arrow::write_ipc_file(arrow::read_ipc_file(#{in_a.inspect}, as_data_frame=FALSE), #{out_a.inspect}, compression='uncompressed'); 1L })",
53
+ timeout: 30
54
+ ) { |res| done.push([:a, res]) }
55
+ R.eval_r_async(
56
+ "({ arrow::write_ipc_file(arrow::read_ipc_file(#{in_b.inspect}, as_data_frame=FALSE), #{out_b.inspect}, compression='uncompressed'); 1L })",
57
+ timeout: 30
58
+ ) { |res| done.push([:b, res]) }
59
+
60
+ 2.times do
61
+ _key, res = done.pop
62
+ expect(res).to be_ok
63
+ end
64
+
65
+ expect(Galaaz::ArrowIpc.read(out_a)['tag']).to eq(['A'])
66
+ expect(Galaaz::ArrowIpc.read(out_b)['tag']).to eq(['B'])
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ # CRAN packages for `galaaz add arrow`.
2
+ dplyr
3
+ arrow
@@ -0,0 +1,4 @@
1
+ # Best-effort CRAN extras for `galaaz add knit` (warn if missing).
2
+ ggplot2
3
+ kableExtra
4
+ RColorBrewer
@@ -0,0 +1,4 @@
1
+ # Hard CRAN set for `galaaz add knit` (must succeed).
2
+ dplyr
3
+ knitr
4
+ rmarkdown
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'galaaz'
4
+
5
+ describe 'Arrow IPC export (Stage B2)' do
6
+ before(:all) do
7
+ skip 'Galaaz::ArrowIpc backend not available' unless Galaaz::ArrowIpc.available?
8
+ ok = R::Support.eval("requireNamespace('arrow', quietly=TRUE) && requireNamespace('dplyr', quietly=TRUE)")
9
+ skip 'R packages arrow/dplyr are not available' unless ok == true
10
+ @paths = []
11
+ end
12
+
13
+ after(:each) do
14
+ Array(@paths).each { |p| Galaaz::ArrowIpc.release(p) }
15
+ @paths = []
16
+ end
17
+
18
+ def track(path)
19
+ @paths << path
20
+ path
21
+ end
22
+
23
+ it 'reads columns R wrote via write_ipc (R→Ruby)' do
24
+ in_path = track(Galaaz::ArrowIpc.write(value: [1.5, 2.5], grp: %w[a b]))
25
+ tbl = R::Arrow.open_ipc(in_path)
26
+ out_path = track(R::Arrow.write_ipc(tbl))
27
+ expect(File.exist?(out_path)).to be true
28
+
29
+ cols = Galaaz::ArrowIpc.read(out_path)
30
+ expect(cols['value']).to eq([1.5, 2.5])
31
+ expect(cols['grp']).to eq(%w[a b])
32
+
33
+ rows = Galaaz::ArrowIpc.read_batches(out_path)
34
+ expect(rows).to eq([{ value: 1.5, grp: 'a' }, { value: 2.5, grp: 'b' }])
35
+ end
36
+
37
+ it 'proves DB-style loop: Ruby ingest → R summarise → Ruby reads result table' do
38
+ in_path = track(Galaaz::ArrowIpc.write_batches([
39
+ { id: 1, grp: 'a', value: 10.0 },
40
+ { id: 2, grp: 'b', value: 20.5 },
41
+ { id: 3, grp: 'a', value: 30.0 }
42
+ ]))
43
+ tbl = R::Arrow.open_ipc(in_path)
44
+ grouped = R.dplyr___group_by(tbl, :grp)
45
+ summed = R.dplyr___summarise(grouped, total: E.sum(:value))
46
+ out_path = track(R::Arrow.write_ipc(summed))
47
+
48
+ rows = Galaaz::ArrowIpc.read_batches(out_path)
49
+ by_grp = rows.each_with_object({}) { |r, h| h[r[:grp].to_s] = r[:total].to_f }
50
+ expect(by_grp['a']).to eq(40.0)
51
+ expect(by_grp['b']).to eq(20.5)
52
+
53
+ Galaaz::ArrowIpc.release(out_path)
54
+ expect(File.exist?(out_path)).to be false
55
+ end
56
+
57
+ it 'raises when reading a missing IPC file' do
58
+ expect {
59
+ Galaaz::ArrowIpc.read('/tmp/galaaz_missing_b2.arrow')
60
+ }.to raise_error(ArgumentError, /not found/)
61
+ end
62
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'galaaz'
4
+
5
+ describe 'Arrow IPC handoff (Stage B1)' do
6
+ before(:all) do
7
+ skip 'Galaaz::ArrowIpc writer backend not available' unless Galaaz::ArrowIpc.available?
8
+ ok = R::Support.eval("requireNamespace('arrow', quietly=TRUE) && requireNamespace('dplyr', quietly=TRUE)")
9
+ skip 'R packages arrow/dplyr are not available' unless ok == true
10
+ @paths = []
11
+ end
12
+
13
+ after(:each) do
14
+ Array(@paths).each { |p| Galaaz::ArrowIpc.release(p) }
15
+ @paths = []
16
+ end
17
+
18
+ def track(path)
19
+ @paths << path
20
+ path
21
+ end
22
+
23
+ it 'round-trips a float64 column through open_ipc' do
24
+ values = [1.5, 2.5, -3.0, 0.0]
25
+ path = track(Galaaz::ArrowIpc.write(value: values))
26
+ expect(File.exist?(path)).to be true
27
+
28
+ tbl = R::Arrow.open_ipc(path)
29
+ expect(tbl.rclass.split(' ')).to include('Table')
30
+ expect((R.nrow(tbl) >> 0)).to eq(values.length)
31
+
32
+ collected = R.dplyr___collect(tbl)
33
+ col = collected[['value']]
34
+ got = (1..(col.length >> 0)).map do |i|
35
+ v = col[i]
36
+ v.respond_to?(:>>) ? (v >> 0) : v
37
+ end
38
+ expect(got).to eq(values)
39
+
40
+ Galaaz::ArrowIpc.release(path)
41
+ expect(File.exist?(path)).to be false
42
+ end
43
+
44
+ it 'round-trips multi-column id/grp/value via write_batches' do
45
+ rows = [
46
+ { id: 1, grp: 'a', value: 10.0 },
47
+ { id: 2, grp: 'b', value: 20.5 },
48
+ { id: 3, grp: 'a', value: 30.0 }
49
+ ]
50
+ path = track(Galaaz::ArrowIpc.write_batches(rows))
51
+ tbl = R::Arrow.open_ipc(path)
52
+
53
+ expect((R.nrow(tbl) >> 0)).to eq(3)
54
+ summed = R.dplyr___summarise(tbl, total: E.sum(:value))
55
+ out = R.dplyr___collect(summed)
56
+ total = out[['total']]
57
+ tot = total[1]
58
+ tot = tot.respond_to?(:>>) ? (tot >> 0) : tot
59
+ expect(tot).to eq(60.5)
60
+ end
61
+
62
+ it 'raises on missing R arrow package path for open_ipc with bad path' do
63
+ expect {
64
+ R::Arrow.open_ipc('/tmp/galaaz_missing_ipc_file_does_not_exist.arrow')
65
+ }.to raise_error(StandardError)
66
+ end
67
+
68
+ it 'raises when write is called without a usable backend message path' do
69
+ # available? already gated the suite; still check empty columns
70
+ expect { Galaaz::ArrowIpc.write({}) }.to raise_error(ArgumentError)
71
+ end
72
+
73
+ it 'optional timing smoke vs from_ruby_batches for N≈50k' do
74
+ n = 50_000
75
+ cols = {
76
+ id: (0...n).to_a,
77
+ grp: (0...n).map { |i| "g#{i % 5}" },
78
+ value: (0...n).map { |i| (i % 10) + 1.0 }
79
+ }
80
+
81
+ t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
82
+ path = track(Galaaz::ArrowIpc.write(cols))
83
+ tbl = R::Arrow.open_ipc(path)
84
+ ipc_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000.0
85
+ expect((R.nrow(tbl) >> 0)).to eq(n)
86
+
87
+ rows = (0...n).map { |i| { id: i, grp: "g#{i % 5}", value: (i % 10) + 1.0 } }
88
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
89
+ tbl2 = R::Arrow.from_ruby_batches(rows)
90
+ batch_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1) * 1000.0
91
+ expect((R.nrow(tbl2) >> 0)).to eq(n)
92
+
93
+ # Not a flaky perf gate — only ensure both paths produce a table.
94
+ expect(ipc_ms).to be > 0
95
+ expect(batch_ms).to be > 0
96
+ end
97
+ end
data/version.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  $gem_name = "galaaz"
2
- $version="2.1.0"
2
+ $version="2.1.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: galaaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Botafogo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-03 00:00:00.000000000 Z
11
+ date: 2026-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -337,6 +337,10 @@ files:
337
337
  - lib/R_interface/runary_operators.rb
338
338
  - lib/R_interface/rvector.rb
339
339
  - lib/galaaz.rb
340
+ - lib/galaaz/arrow_ipc.rb
341
+ - lib/galaaz/arrow_ipc/java_arrow_backend.rb
342
+ - lib/galaaz/arrow_ipc/red_arrow_backend.rb
343
+ - lib/galaaz/cli.rb
340
344
  - lib/galaaz_jruby.rb
341
345
  - lib/galaaz_ruby.rb
342
346
  - lib/gknit.rb
@@ -357,6 +361,8 @@ files:
357
361
  - lib/new_bridge/tcp_framed.rb
358
362
  - lib/util/exec_ruby.rb
359
363
  - lib/util/inline_file.rb
364
+ - new_bridge_specs/arrow_ipc_async_spec.rb
365
+ - new_bridge_specs/arrow_ipc_export_async_spec.rb
360
366
  - new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb
361
367
  - new_bridge_specs/eval_r_async_spec.rb
362
368
  - new_bridge_specs/integration_phase5_1_concurrent_spec.rb
@@ -383,10 +389,15 @@ files:
383
389
  - new_bridge_specs/phase4_2_hardening_spec.rb
384
390
  - new_bridge_specs/phase4_3_r_instance_manager_spec.rb
385
391
  - new_bridge_specs/phase4_nested_callbacks_spec.rb
392
+ - r_requires/arrow.txt
386
393
  - r_requires/ggplot.rb
394
+ - r_requires/knit-extras.txt
395
+ - r_requires/knit.txt
387
396
  - r_requires/knitr.rb
388
397
  - specs/all.rb
389
398
  - specs/arrow_from_ruby_batches_spec.rb
399
+ - specs/arrow_ipc_export_spec.rb
400
+ - specs/arrow_ipc_handoff_spec.rb
390
401
  - specs/arrow_semantics_spec.rb
391
402
  - specs/bridge_concurrent_spec.rb
392
403
  - specs/bridge_nested_spec.rb