Skip to content

Commit 72b585d

Browse files
feat!(ffi): new visit_schema FFI and rename old visit_schema to visit_snapshot_schema (#683)
## What changes are proposed in this pull request? When given a schema (e.g. in `global_scan_state`) the engine needs a way to visit this schema. This introduces a new API `visit_schema` to allow engines to visit any schema over FFI. An API called `visit_schema` previously existed but visited the schema of a given _snapshot_; this has now been renamed to `visit_snapshot_schema`. ### This PR affects the following public APIs Renamed `visit_schema` to `visit_snapshot_schema` and now `visit_schema` takes `SharedSchema` as an argument instead of a snapshot. ## How was this change tested? updated read_table test
1 parent 2e4f555 commit 72b585d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

ffi/examples/read-table/schema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void print_schema(SharedSnapshot* snapshot)
273273
.visit_timestamp = visit_timestamp,
274274
.visit_timestamp_ntz = visit_timestamp_ntz,
275275
};
276-
uintptr_t schema_list_id = visit_schema(snapshot, &visitor);
276+
uintptr_t schema_list_id = visit_snapshot_schema(snapshot, &visitor);
277277
#ifdef VERBOSE
278278
printf("Schema returned in list %" PRIxPTR "\n", schema_list_id);
279279
#endif

ffi/src/schema.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::os::raw::c_void;
22

3-
use crate::scan::CStringMap;
3+
use crate::scan::{CStringMap, SharedSchema};
44
use crate::{handle::Handle, kernel_string_slice, KernelStringSlice, SharedSnapshot};
55
use delta_kernel::schema::{ArrayType, DataType, MapType, PrimitiveType, StructType};
66

@@ -201,11 +201,32 @@ pub struct EngineSchemaVisitor {
201201
///
202202
/// Caller is responsible for passing a valid snapshot handle and schema visitor.
203203
#[no_mangle]
204-
pub unsafe extern "C" fn visit_schema(
204+
pub unsafe extern "C" fn visit_snapshot_schema(
205205
snapshot: Handle<SharedSnapshot>,
206206
visitor: &mut EngineSchemaVisitor,
207207
) -> usize {
208208
let snapshot = unsafe { snapshot.as_ref() };
209+
visit_schema_impl(snapshot.schema(), visitor)
210+
}
211+
212+
/// Visit the given `schema` using the provided `visitor`. See the documentation of
213+
/// [`EngineSchemaVisitor`] for a description of how this visitor works.
214+
///
215+
/// This method returns the id of the list allocated to hold the top level schema columns.
216+
///
217+
/// # Safety
218+
///
219+
/// Caller is responsible for passing a valid schema handle and schema visitor.
220+
#[no_mangle]
221+
pub unsafe extern "C" fn visit_schema(
222+
schema: Handle<SharedSchema>,
223+
visitor: &mut EngineSchemaVisitor,
224+
) -> usize {
225+
let schema = unsafe { schema.as_ref() };
226+
visit_schema_impl(schema, visitor)
227+
}
228+
229+
fn visit_schema_impl(schema: &StructType, visitor: &mut EngineSchemaVisitor) -> usize {
209230
// Visit all the fields of a struct and return the list of children
210231
fn visit_struct_fields(visitor: &EngineSchemaVisitor, s: &StructType) -> usize {
211232
let child_list_id = (visitor.make_field_list)(visitor.data, s.fields.len());
@@ -316,5 +337,5 @@ pub unsafe extern "C" fn visit_schema(
316337
}
317338
}
318339

319-
visit_struct_fields(visitor, snapshot.schema())
340+
visit_struct_fields(visitor, schema)
320341
}

0 commit comments

Comments
 (0)