Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(ffi): new visit_schema FFI and rename old visit_schema to visit_snapshot_schema #683

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions ffi/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::os::raw::c_void;

use crate::scan::CStringMap;
use crate::scan::{CStringMap, SharedSchema};
use crate::{handle::Handle, kernel_string_slice, KernelStringSlice, SharedSnapshot};
use delta_kernel::schema::{ArrayType, DataType, MapType, PrimitiveType, StructType};

Expand Down Expand Up @@ -201,11 +201,32 @@ pub struct EngineSchemaVisitor {
///
/// Caller is responsible for passing a valid snapshot handle and schema visitor.
#[no_mangle]
pub unsafe extern "C" fn visit_schema(
pub unsafe extern "C" fn visit_snapshot_schema(
snapshot: Handle<SharedSnapshot>,
visitor: &mut EngineSchemaVisitor,
) -> usize {
let snapshot = unsafe { snapshot.as_ref() };
visit_schema_impl(snapshot.schema(), visitor)
}

/// Visit the given `schema` using the provided `visitor`. See the documentation of
/// [`EngineSchemaVisitor`] for a description of how this visitor works.
///
/// This method returns the id of the list allocated to hold the top level schema columns.
///
/// # Safety
///
/// Caller is responsible for passing a valid schema handle and schema visitor.
#[no_mangle]
pub unsafe extern "C" fn visit_schema(
schema: Handle<SharedSchema>,
visitor: &mut EngineSchemaVisitor,
) -> usize {
let schema = unsafe { schema.as_ref() };
visit_schema_impl(schema, visitor)
}

fn visit_schema_impl(schema: &StructType, visitor: &mut EngineSchemaVisitor) -> usize {
// Visit all the fields of a struct and return the list of children
fn visit_struct_fields(visitor: &EngineSchemaVisitor, s: &StructType) -> usize {
let child_list_id = (visitor.make_field_list)(visitor.data, s.fields.len());
Expand Down Expand Up @@ -316,5 +337,5 @@ pub unsafe extern "C" fn visit_schema(
}
}

visit_struct_fields(visitor, snapshot.schema())
visit_struct_fields(visitor, schema)
}
Loading