Skip to content
Open
3 changes: 3 additions & 0 deletions rust/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ pub enum ErrorCode {
Exec = 52,
DatasetMerge = 53,
NamespaceQueryTable = 54,
NamespaceListNamespaces = 55,
NamespaceCreateNamespace = 56,
NamespaceDropNamespace = 57,
}

struct LastError {
Expand Down
19 changes: 6 additions & 13 deletions rust/ffi/dir_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::runtime;
use super::session::record_dataset_open;
use super::types::DatasetHandle;
use super::util::{
cstr_to_str, optional_session_handle, slice_from_ptr, to_c_string, FfiError, FfiResult,
cstr_to_str, export_string_list, optional_session_handle, slice_from_ptr, to_c_string,
FfiError, FfiResult, LanceStringList,
};

fn parse_storage_options(
Expand Down Expand Up @@ -102,18 +103,10 @@ pub unsafe extern "C" fn lance_dir_namespace_list_tables(
option_keys: *const *const c_char,
option_values: *const *const c_char,
options_len: usize,
) -> *const c_char {
match dir_namespace_list_tables_inner(root, option_keys, option_values, options_len) {
Ok(tables) => {
clear_last_error();
let joined = tables.join("\n");
to_c_string(joined).into_raw() as *const c_char
}
Err(err) => {
set_last_error(err.code, err.message);
ptr::null()
}
}
out: *mut LanceStringList,
) -> i32 {
let result = dir_namespace_list_tables_inner(root, option_keys, option_values, options_len);
unsafe { export_string_list(result, out) }
}

fn open_dataset_in_dir_namespace_inner(
Expand Down
50 changes: 8 additions & 42 deletions rust/ffi/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::runtime;

use super::types::{SchemaHandle, StreamHandle};
use super::util::{
canonicalize_lance_field_path, cstr_to_str, dataset_handle, to_c_string, FfiError, FfiResult,
canonicalize_lance_field_path, cstr_to_str, dataset_handle, export_string_list, to_c_string,
FfiError, FfiResult, LanceStringList,
};

#[derive(Debug, Default, Deserialize)]
Expand Down Expand Up @@ -156,50 +157,15 @@ fn create_index_list_stream_inner(dataset: *mut c_void) -> FfiResult<StreamHandl
Ok(StreamHandle::Batches(vec![batch].into_iter()))
}

/// Returns an array of column names that have scalar indices.
/// The caller must free the returned array with `lance_free_scalar_indexed_columns`.
/// Returns column names that have scalar indices.
/// The caller must free the result with `lance_free_string_list`.
#[no_mangle]
pub unsafe extern "C" fn lance_dataset_list_scalar_indexed_columns(
dataset: *mut c_void,
out_len: *mut usize,
) -> *mut *mut c_char {
match list_scalar_indexed_columns_inner(dataset) {
Ok(cols) => {
clear_last_error();
unsafe { *out_len = cols.len() };
if cols.is_empty() {
return std::ptr::null_mut();
}
let ptrs: Vec<*mut c_char> = cols
.into_iter()
.map(|s| to_c_string(s).into_raw())
.collect();
let mut boxed = ptrs.into_boxed_slice();
let ptr = boxed.as_mut_ptr();
std::mem::forget(boxed);
ptr
}
Err(err) => {
set_last_error(err.code, err.message);
unsafe { *out_len = 0 };
std::ptr::null_mut()
}
}
}

#[no_mangle]
pub unsafe extern "C" fn lance_free_scalar_indexed_columns(ptr: *mut *mut c_char, len: usize) {
if ptr.is_null() {
return;
}
unsafe {
let slice = Box::from_raw(std::ptr::slice_from_raw_parts_mut(ptr, len));
for &p in slice.iter() {
if !p.is_null() {
drop(std::ffi::CString::from_raw(p));
}
}
}
out: *mut LanceStringList,
) -> i32 {
let result = list_scalar_indexed_columns_inner(dataset);
unsafe { export_string_list(result, out) }
}

fn list_scalar_indexed_columns_inner(dataset: *mut c_void) -> FfiResult<Vec<String>> {
Expand Down
Loading
Loading