-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Ruby bindings from helix to rutie
- Loading branch information
1 parent
5b6e98f
commit 0d8b23f
Showing
9 changed files
with
162 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,15 @@ jobs: | |
- name: Cache Rust build | ||
uses: actions/[email protected] | ||
with: | ||
path: target/debug/build | ||
key: ruby-${{ runner.OS }}-target-build-${{ hashFiles('**/Cargo.lock') }} | ||
path: target/release/build | ||
key: ruby-${{ runner.OS }}-target-release-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
ruby-${{ runner.OS }}-target-build- | ||
- name: Cache Rust incremental build | ||
uses: actions/[email protected] | ||
with: | ||
path: target/debug/incremental | ||
key: ruby-${{ runner.OS }}-target-incremental-${{ hashFiles('**/Cargo.lock') }} | ||
path: target/release/incremental | ||
key: ruby-${{ runner.OS }}-target-release-incremental-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
ruby-${{ runner.OS }}-target-incremental- | ||
- name: Install minimal stable with clippy and rustfmt | ||
|
@@ -34,6 +34,8 @@ jobs: | |
profile: default | ||
toolchain: stable | ||
override: true | ||
- name: Build Release for Ruby | ||
run: cargo build --release | ||
- name: 'Set up Ruby' | ||
uses: actions/setup-ruby@v1 | ||
- name: 'Install Ruby Dependencies' | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ version = "0.1.0" | |
authors = ["R Tyler Croy <[email protected]>"] | ||
|
||
[lib] | ||
|
||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
helix = "*" | ||
lazy_static = "1" | ||
rutie = "0.8.2" | ||
tokio = { version = "1", features = ["rt-multi-thread"] } | ||
|
||
[dependencies.deltalake] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'helix_runtime/build_task' | ||
require 'rspec/core/rake_task' | ||
|
||
# For Windows | ||
$stdout.sync = true | ||
|
||
HelixRuntime::BuildTask.new do |t| | ||
t.build_root = File.expand_path("../", __dir__) | ||
end | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |t| | ||
t.verbose = false | ||
end | ||
|
||
task :spec => :build | ||
task :default => :spec | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Deltalake | ||
VERSION = '0.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,91 @@ | ||
#![recursion_limit = "1024"] | ||
|
||
#[macro_use] | ||
extern crate helix; | ||
extern crate deltalake; | ||
|
||
#[macro_use] | ||
extern crate lazy_static; | ||
|
||
#[macro_use] | ||
extern crate rutie; | ||
|
||
use deltalake::DeltaTable; | ||
use rutie::{AnyObject, Array, Class, Integer, Object, RString}; | ||
use std::sync::Arc; | ||
|
||
ruby! { | ||
class Table { | ||
struct { | ||
table_path: String, | ||
actual: Arc<DeltaTable>, | ||
} | ||
pub struct TableData { | ||
table_path: String, | ||
actual: Arc<DeltaTable>, | ||
} | ||
|
||
def initialize(helix, table_path: String) { | ||
println!("initializing with {}", table_path); | ||
impl TableData { | ||
fn new(table_path: String) -> Self { | ||
println!("initializing with {}", table_path); | ||
|
||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
let table = rt.block_on(deltalake::open_table(&table_path)).unwrap(); | ||
let actual = Arc::new(table); | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
let table = rt.block_on(deltalake::open_table(&table_path)).unwrap(); | ||
let actual = Arc::new(table); | ||
|
||
Table { | ||
helix, | ||
table_path, | ||
actual, | ||
} | ||
} | ||
Self { table_path, actual } | ||
} | ||
|
||
def table_path(&self) -> String { | ||
self.table_path.clone() | ||
} | ||
fn table_path(&self) -> &str { | ||
&self.table_path | ||
} | ||
|
||
def version(&self) -> i64 { | ||
self.actual.version | ||
} | ||
fn version(&self) -> i64 { | ||
self.actual.version | ||
} | ||
|
||
def files(&self) -> Vec<String> { | ||
self.actual.get_files().to_vec() | ||
fn files(&self) -> &[String] { | ||
self.actual.get_files().as_slice() | ||
} | ||
} | ||
|
||
wrappable_struct!(TableData, TableDataWrapper, TABLE_DATA_WRAPPER); | ||
|
||
class!(Table); | ||
|
||
methods!( | ||
Table, | ||
rtself, | ||
fn ruby_table_new(table_path: RString) -> AnyObject { | ||
let table_data = TableData::new(table_path.unwrap().to_string()); | ||
|
||
Class::from_existing("Table").wrap_data(table_data, &*TABLE_DATA_WRAPPER) | ||
}, | ||
fn ruby_table_path() -> RString { | ||
let table_path = rtself.get_data(&*TABLE_DATA_WRAPPER).table_path(); | ||
|
||
RString::new_utf8(table_path) | ||
}, | ||
fn ruby_version() -> Integer { | ||
let version = rtself.get_data(&*TABLE_DATA_WRAPPER).version(); | ||
|
||
Integer::new(version) | ||
}, | ||
fn ruby_files() -> Array { | ||
let files = rtself.get_data(&*TABLE_DATA_WRAPPER).files(); | ||
|
||
let mut array = Array::with_capacity(files.len()); | ||
|
||
for file in files { | ||
array.push(RString::new_utf8(file)); | ||
} | ||
|
||
array | ||
} | ||
); | ||
|
||
#[allow(non_snake_case)] | ||
#[no_mangle] | ||
pub extern "C" fn Init_table() { | ||
let data_class = Class::from_existing("Object"); | ||
|
||
Class::new("Table", Some(&data_class)).define(|klass| { | ||
klass.def_self("new", ruby_table_new); | ||
|
||
klass.def("table_path", ruby_table_path); | ||
klass.def("version", ruby_version); | ||
klass.def("files", ruby_files); | ||
}); | ||
} |