|
1 | 1 | use std::os::raw::c_void;
|
2 | 2 |
|
3 |
| -use crate::scan::CStringMap; |
| 3 | +use crate::scan::{CStringMap, SharedSchema}; |
4 | 4 | use crate::{handle::Handle, kernel_string_slice, KernelStringSlice, SharedSnapshot};
|
5 | 5 | use delta_kernel::schema::{ArrayType, DataType, MapType, PrimitiveType, StructType};
|
6 | 6 |
|
@@ -201,11 +201,32 @@ pub struct EngineSchemaVisitor {
|
201 | 201 | ///
|
202 | 202 | /// Caller is responsible for passing a valid snapshot handle and schema visitor.
|
203 | 203 | #[no_mangle]
|
204 |
| -pub unsafe extern "C" fn visit_schema( |
| 204 | +pub unsafe extern "C" fn visit_snapshot_schema( |
205 | 205 | snapshot: Handle<SharedSnapshot>,
|
206 | 206 | visitor: &mut EngineSchemaVisitor,
|
207 | 207 | ) -> usize {
|
208 | 208 | 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 { |
209 | 230 | // Visit all the fields of a struct and return the list of children
|
210 | 231 | fn visit_struct_fields(visitor: &EngineSchemaVisitor, s: &StructType) -> usize {
|
211 | 232 | let child_list_id = (visitor.make_field_list)(visitor.data, s.fields.len());
|
@@ -316,5 +337,5 @@ pub unsafe extern "C" fn visit_schema(
|
316 | 337 | }
|
317 | 338 | }
|
318 | 339 |
|
319 |
| - visit_struct_fields(visitor, snapshot.schema()) |
| 340 | + visit_struct_fields(visitor, schema) |
320 | 341 | }
|
0 commit comments