Skip to content

Commit

Permalink
make ffi work, add default tight_bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed May 27, 2024
1 parent 86f9f25 commit 20355e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ffi/cffi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
void visit_callback(void* engine_context,
KernelStringSlice path,
int64_t size,
const Stats* stats,
const DvInfo* dv_info,
const CStringMap* partition_values) {
printf("file: %.*s\n", (int)path.len, path.ptr);
printf("file: %.*s (size: %" PRId64 ", num_records:", (int)path.len, path.ptr, size);
if (stats) {
printf("%" PRId64 ")\n", stats->num_records);
} else {
printf(" [no stats])\n");
}
}

void visit_data(void* engine_context,
Expand Down
13 changes: 13 additions & 0 deletions ffi/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,17 @@ pub unsafe extern "C" fn kernel_scan_data_free(data: Handle<SharedScanDataIterat
data.drop_handle();
}

#[repr(C)]
pub struct Stats {
num_records: u64,
tight_bounds: bool,
}

type CScanCallback = extern "C" fn(
engine_context: NullableCvoid,
path: KernelStringSlice,
size: i64,
stats: Option<&Stats>,
dv_info: &DvInfo,
partition_map: &CStringMap,
);
Expand Down Expand Up @@ -336,16 +343,22 @@ fn rust_callback(
context: &mut ContextWrapper,
path: &str,
size: i64,
kernel_stats: Option<delta_kernel::scan::state::Stats>,
dv_info: DvInfo,
partition_values: HashMap<String, String>,
) {
let partition_map = CStringMap {
values: partition_values,
};
let stats = kernel_stats.map(|ks| Stats {
num_records: ks.num_records,
tight_bounds: ks.tight_bounds,
});
(context.callback)(
context.engine_context,
path.into(),
size,
stats.as_ref(),
&dv_info,
&partition_map,
);
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/scan/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ pub struct DvInfo {
deletion_vector: Option<DeletionVectorDescriptor>,
}

fn default_false() -> bool {
false
}

/// Give engines an easy way to consume stats
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Stats {
pub num_records: u64,
#[serde(default = "default_false")]
pub tight_bounds: bool,
}

Expand Down

0 comments on commit 20355e6

Please sign in to comment.