arrow-datafusion 0.0.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.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +49 -0
- data/arrow-datafusion.gemspec +22 -0
- data/ext/datafusion_ruby/Cargo.lock +1706 -0
- data/ext/datafusion_ruby/Cargo.toml +12 -0
- data/ext/datafusion_ruby/Rakefile +159 -0
- data/ext/datafusion_ruby/src/context.rs +14 -0
- data/ext/datafusion_ruby/src/lib.rs +11 -0
- data/lib/datafusion/version.rb +3 -0
- data/lib/datafusion.rb +1 -0
- metadata +68 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shellwords"
|
4
|
+
|
5
|
+
class RakeCargoHelper
|
6
|
+
attr_reader :gem_name, :crate_name
|
7
|
+
|
8
|
+
def initialize(gem_name:, crate_name:)
|
9
|
+
@gem_name = gem_name
|
10
|
+
@crate_name = crate_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.command?(name)
|
14
|
+
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
|
15
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
|
16
|
+
exts.any? do |ext|
|
17
|
+
exe = File.join(path, "#{name}#{ext}")
|
18
|
+
File.executable?(exe) && !File.directory?(exe)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.rust_toolchain
|
24
|
+
str = `rustc --version --verbose`
|
25
|
+
info = str.lines.map { |l| l.chomp.split(/:\s+/, 2) }.drop(1).to_h
|
26
|
+
info["host"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cargo_target_dir
|
30
|
+
return @cargo_target_dir if defined? @cargo_target_dir
|
31
|
+
|
32
|
+
str = `cargo metadata --format-version 1 --offline --no-deps --quiet`
|
33
|
+
begin
|
34
|
+
require "json"
|
35
|
+
dir = JSON.parse(str)["target_directory"]
|
36
|
+
rescue LoadError # json is usually part of the stdlib, but just in case
|
37
|
+
/"target_directory"\s*:\s*"(?<dir>[^"]*)"/ =~ str
|
38
|
+
end
|
39
|
+
@cargo_target_dir = dir || "target"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.flags
|
43
|
+
cc_flags = Shellwords.split(RbConfig.expand(RbConfig::MAKEFILE_CONFIG["CC"].dup))
|
44
|
+
|
45
|
+
["-C", "linker=#{cc_flags.shift}",
|
46
|
+
*cc_flags.flat_map { |a| ["-C", "link-arg=#{a}"] },
|
47
|
+
"-L", "native=#{RbConfig::CONFIG["libdir"]}",
|
48
|
+
*dld_flags,
|
49
|
+
*platform_flags]
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.dld_flags
|
53
|
+
Shellwords.split(RbConfig::CONFIG["DLDFLAGS"]).flat_map do |arg|
|
54
|
+
arg = arg.gsub(/\$\((\w+)\)/) do
|
55
|
+
$1 == "DEFFILE" ? nil : RbConfig::CONFIG[name]
|
56
|
+
end.strip
|
57
|
+
next [] if arg.empty?
|
58
|
+
|
59
|
+
transform_flag(arg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.platform_flags
|
64
|
+
return unless RbConfig::CONFIG["target_os"] =~ /mingw/i
|
65
|
+
|
66
|
+
[*Shellwords.split(RbConfig::CONFIG["LIBRUBYARG"]).flat_map { |arg| transform_flag(arg) },
|
67
|
+
"-C", "link-arg=-Wl,--dynamicbase",
|
68
|
+
"-C", "link-arg=-Wl,--disable-auto-image-base",
|
69
|
+
"-C", "link-arg=-static-libgcc"]
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.transform_flag(arg)
|
73
|
+
k, v = arg.split(/(?<=..)/, 2)
|
74
|
+
case k
|
75
|
+
when "-L"
|
76
|
+
[k, "native=#{v}"]
|
77
|
+
when "-l"
|
78
|
+
[k, v]
|
79
|
+
when "-F"
|
80
|
+
["-l", "framework=#{v}"]
|
81
|
+
else
|
82
|
+
["-C", "link_arg=#{k}#{v}"]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def install_dir
|
87
|
+
File.expand_path(File.join("..", "..", "lib", gem_name), __dir__)
|
88
|
+
end
|
89
|
+
|
90
|
+
def rust_name
|
91
|
+
prefix = "lib" unless Gem.win_platform?
|
92
|
+
suffix = if RbConfig::CONFIG["target_os"] =~ /darwin/i
|
93
|
+
".dylib"
|
94
|
+
elsif Gem.win_platform?
|
95
|
+
".dll"
|
96
|
+
else
|
97
|
+
".so"
|
98
|
+
end
|
99
|
+
"#{prefix}#{crate_name}#{suffix}"
|
100
|
+
end
|
101
|
+
|
102
|
+
def ruby_name
|
103
|
+
"#{crate_name}.#{RbConfig::CONFIG["DLEXT"]}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
task default: [:install, :clean]
|
108
|
+
|
109
|
+
desc "set dev mode for subsequent task, run like `rake dev install`"
|
110
|
+
task :dev do
|
111
|
+
@dev = true
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "build gem native extension and copy to lib"
|
115
|
+
task install: [:cd, :build] do
|
116
|
+
helper = RakeCargoHelper.new(gem_name: "datafusion", crate_name: "datafusion_ruby")
|
117
|
+
profile_dir = @dev ? "debug" : "release"
|
118
|
+
source = File.join(RakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
|
119
|
+
dest = File.join(helper.install_dir, helper.ruby_name)
|
120
|
+
mkdir_p(helper.install_dir)
|
121
|
+
rm(dest) if File.exist?(dest)
|
122
|
+
cp(source, dest)
|
123
|
+
end
|
124
|
+
|
125
|
+
desc "build gem native extension"
|
126
|
+
task build: [:cargo, :cd] do
|
127
|
+
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.flags
|
128
|
+
end
|
129
|
+
|
130
|
+
desc "clean up release build artifacts"
|
131
|
+
task clean: [:cargo, :cd] do
|
132
|
+
sh "cargo clean --release"
|
133
|
+
end
|
134
|
+
|
135
|
+
desc "clean up build artifacts"
|
136
|
+
task clobber: [:cargo, :cd] do
|
137
|
+
sh "cargo clean"
|
138
|
+
end
|
139
|
+
|
140
|
+
desc "check for cargo"
|
141
|
+
task :cargo do
|
142
|
+
raise <<-MSG unless RakeCargoHelper.command?("cargo")
|
143
|
+
|
144
|
+
This gem requires a Rust compiler and the `cargo' build tool to build the
|
145
|
+
gem's native extension. See https://www.rust-lang.org/tools/install for
|
146
|
+
how to install Rust. `cargo' is usually part of the Rust installation.
|
147
|
+
MSG
|
148
|
+
|
149
|
+
raise <<-MSG if Gem.win_platform? && RakeCargoHelper.rust_toolchain !~ /gnu/
|
150
|
+
|
151
|
+
Found Rust toolchain `#{RakeCargoHelper.rust_toolchain}' but the gem native
|
152
|
+
extension requires the gnu toolchain on Windows.
|
153
|
+
MSG
|
154
|
+
end
|
155
|
+
|
156
|
+
# ensure task is running in the right dir
|
157
|
+
task :cd do
|
158
|
+
cd(__dir__) unless __dir__ == pwd
|
159
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
use datafusion::execution::context::SessionContext;
|
2
|
+
|
3
|
+
#[magnus::wrap(class = "Datafusion::SessionContext")]
|
4
|
+
pub(crate) struct RbSessionContext {
|
5
|
+
ctx: SessionContext,
|
6
|
+
}
|
7
|
+
|
8
|
+
impl RbSessionContext {
|
9
|
+
pub(crate) fn new() -> Self {
|
10
|
+
Self {
|
11
|
+
ctx: SessionContext::new(),
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
use magnus::{define_module, function, prelude::*, Error};
|
2
|
+
|
3
|
+
mod context;
|
4
|
+
|
5
|
+
#[magnus::init]
|
6
|
+
fn init() -> Result<(), Error> {
|
7
|
+
let module = define_module("Datafusion")?;
|
8
|
+
let class = module.define_class("SessionContext", Default::default())?;
|
9
|
+
class.define_singleton_method("new", function!(context::RbSessionContext::new, 0))?;
|
10
|
+
Ok(())
|
11
|
+
}
|
data/lib/datafusion.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "datafusion/datafusion_ruby"
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arrow-datafusion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Datafusion Contrib Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: DataFusion is an extensible query execution framework, written in Rust,
|
28
|
+
that uses Apache Arrow as its in-memory format.
|
29
|
+
email:
|
30
|
+
executables: []
|
31
|
+
extensions:
|
32
|
+
- ext/datafusion_ruby/Rakefile
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- arrow-datafusion.gemspec
|
38
|
+
- ext/datafusion_ruby/Cargo.lock
|
39
|
+
- ext/datafusion_ruby/Cargo.toml
|
40
|
+
- ext/datafusion_ruby/Rakefile
|
41
|
+
- ext/datafusion_ruby/src/context.rs
|
42
|
+
- ext/datafusion_ruby/src/lib.rs
|
43
|
+
- lib/datafusion.rb
|
44
|
+
- lib/datafusion/version.rb
|
45
|
+
homepage: https://github.com/datafusion-contrib/datafusion-ruby
|
46
|
+
licenses:
|
47
|
+
- Apache-2.0
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.1.6
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Ruby bindings of Apache Arrow Datafusion
|
68
|
+
test_files: []
|