From dc982dc04cc745e1dda4e206453937e73a4de541 Mon Sep 17 00:00:00 2001 From: Connor Tsui Date: Mon, 23 Nov 2026 21:48:28 +0000 Subject: [PATCH] Require Arrow plugin exports to keep storage values An Arrow plugin can round-trip values while changing the order an Arrow reader sees. Require exports to preserve nulls and comparable extension values, and check both rules in the Arrow test harness. Two exporters can preserve order within their own outputs and still encode equal storage values differently. Keep plugin-exported fields selected through extension storage in DataFusion. Check that literals with extension metadata or nested importers round-trip so lossy imports cannot change a comparison. Claude-Session: https://claude.ai/code/session_01J3PQt9ZhAgF2rD6wiqPQ1e Signed-off-by: Connor Tsui --- Cargo.lock | 1 + Cargo.toml | 1 + vortex-arrow/Cargo.toml | 7 +- vortex-arrow/src/extension/mod.rs | 3 + vortex-arrow/src/session.rs | 77 +++++++--- vortex-arrow/src/test_harness/round_trip.rs | 115 ++++++++++++++- vortex-datafusion/src/convert/exprs/mod.rs | 53 ++++--- vortex-datafusion/src/convert/exprs/tests.rs | 145 ++++++++++++++++++- 8 files changed, 349 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f3939e4f95c..be931110723 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11145,6 +11145,7 @@ dependencies = [ "arrow-buffer 59.3.3", "arrow-cast 59.3.3", "arrow-data 59.3.3", + "arrow-ord 59.3.3", "arrow-schema 59.3.3", "arrow-select 59.3.3", "base64 0.23.1", diff --git a/Cargo.toml b/Cargo.toml index a0b4b2c87fc..dea49788a9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,6 +111,7 @@ arrow-buffer = "59.2" arrow-cast = "59.2" arrow-data = "59.2" arrow-ipc = "59.2" +arrow-ord = "59.2" arrow-row = "59.2" arrow-schema = "59.2" arrow-select = "59.2" diff --git a/vortex-arrow/Cargo.toml b/vortex-arrow/Cargo.toml index cbb3e8d6f39..248cb92e160 100644 --- a/vortex-arrow/Cargo.toml +++ b/vortex-arrow/Cargo.toml @@ -19,7 +19,11 @@ all-features = true workspace = true [features] -_test-harness = ["vortex-array/_test-harness", "dep:arrow-select"] +_test-harness = [ + "vortex-array/_test-harness", + "dep:arrow-ord", + "dep:arrow-select", +] _test-harness-hegel = ["_test-harness", "dep:hegeltest", "dep:half"] [dependencies] @@ -27,6 +31,7 @@ arrow-array = { workspace = true, features = ["ffi"] } arrow-buffer = { workspace = true } arrow-cast = { workspace = true } arrow-data = { workspace = true } +arrow-ord = { workspace = true, optional = true } arrow-schema = { workspace = true, features = ["canonical_extension_types"] } arrow-select = { workspace = true, optional = true } base64 = { workspace = true } diff --git a/vortex-arrow/src/extension/mod.rs b/vortex-arrow/src/extension/mod.rs index 386745ff3ae..75f4a10a240 100644 --- a/vortex-arrow/src/extension/mod.rs +++ b/vortex-arrow/src/extension/mod.rs @@ -102,6 +102,9 @@ pub trait ArrowExtVTable: ExtVTable { /// The adapter checks the source extension type before calling this method. Return /// [`ArrowExport::Unsupported`] when the target is unsupported. Child exports **must** receive /// the same `options` through [`crate::ExecuteArrowExt::execute_arrow_with_options`]. + /// + /// The export **must** follow the + /// [null and comparison rules](crate::ArrowExportVTable::execute_arrow). fn execute_arrow( &self, array: ArrayRef, diff --git a/vortex-arrow/src/session.rs b/vortex-arrow/src/session.rs index ca45f4e76ce..d820cab0956 100644 --- a/vortex-arrow/src/session.rs +++ b/vortex-arrow/src/session.rs @@ -190,6 +190,24 @@ pub trait ArrowExportVTable: 'static + Send + Sync + Debug { /// those exports, through [`ExecuteArrowExt::execute_arrow_with_options`]. The [`ArrowSession`] /// of `ctx` is the session of the export, so a plugin that needs one must use it. /// + /// # Exported values + /// + /// Every export **must** preserve the nulls of `array`. + /// + /// If `array` has an extension dtype and the output type supports the Arrow comparison kernels, + /// the export **must** preserve equality and order. Two non-null exported values compare the + /// same way in Arrow as their storage values compare in Vortex. Nested Arrow types only have + /// the null requirement. + /// + /// The comparison rule holds across batches in one Arrow representation. To push a comparison + /// down to Vortex storage, an engine also needs to know that both operands use compatible + /// representations. Two exporters can each preserve order and still encode equal storage + /// values differently. A round trip alone does not even ensure that one exporter preserves + /// order. An exporter can reverse the bytes of each value and undo that change on import. + /// + /// A plugin that breaks these rules gives incorrect query results instead of an error. It does + /// not cause memory unsafety. `test_harness::check_arrow` checks both rules for one array. + /// /// [`ExecuteArrowExt::execute_arrow_with_options`]: crate::ExecuteArrowExt::execute_arrow_with_options fn execute_arrow( &self, @@ -279,6 +297,9 @@ type ArrowImporterRegistry = ArcSwapMap>; /// preserve its dtype and logical values. The owning dtype and Arrow plugins must be registered in /// the importing session. /// +/// An Arrow reader observes exported values before any Vortex importer runs. +/// [`ArrowExportVTable::execute_arrow`] defines the null and comparison rules for those values. +/// /// The session checks inferred fields and successful plugin imports, including raw plugins. /// Explicit export targets may request a different dtype. Unknown Vortex IDs import as storage. /// @@ -567,8 +588,8 @@ impl ArrowSession { /// produce any data for the same field, so a name with an exporter gives `false`. /// /// The answer covers only the top level of `field`. Each storage child exports to its own - /// field, which can name another exporter, and [`Self::exports_without_plugins`] checks every - /// depth. + /// field, which can name another exporter. [`Self::exports_without_plugins`] checks for + /// exporters at every depth. #[expect(clippy::disallowed_methods, reason = "interning a dynamic id")] pub fn exports_extension_storage(&self, ext_dtype: &ExtDTypeRef, field: &Field) -> bool { // A dictionary or run-end encoded field holds the storage values behind an encoding, so @@ -608,21 +629,20 @@ impl ArrowSession { .is_ok_and(|dtype| &dtype == ext_dtype.storage_dtype()) } - /// Returns whether an export to `field` calls no registered exporter at any depth. + /// Returns whether exporting to `field` uses only the built-in conversions at every depth. /// - /// Such an export uses only the conversions of this crate, so a caller planning reads without - /// the array knows which Arrow data it produces. A field that names an extension type without - /// an exporter still qualifies, because it exports through its Vortex ID or as plain storage. - #[expect(clippy::disallowed_methods, reason = "interning a dynamic id")] + /// A registered exporter can choose the Arrow representation even if the field also supports + /// a built-in conversion. The answer is conservative because the plugin can defer at runtime. pub fn exports_without_plugins(&self, field: &Field) -> bool { - let names_exporter = field - .extension_type_name() - .is_some_and(|name| !self.exporters(&Id::new(name)).is_empty()); + !field_uses_plugin(field, &|id| !self.exporters(id).is_empty()) + } - !names_exporter - && nested_fields(field.data_type()) - .into_iter() - .all(|child| self.exports_without_plugins(child)) + /// Returns whether importing from `field` uses only the built-in conversions at every depth. + /// + /// A registered importer can transform values before Vortex sees them, even if the outer field + /// has no extension name. + pub fn imports_without_plugins(&self, field: &Field) -> bool { + !field_uses_plugin(field, &|id| !self.importers(id).is_empty()) } /// Fails unless `field`, which names the Vortex ID of `ext_dtype`, describes `ext_dtype`. @@ -1206,23 +1226,32 @@ pub(crate) fn ensure_ext_metadata( Ok(()) } -/// Returns the fields nested directly in `data_type`. -/// -/// A dictionary has no field for its values, so it returns the fields nested in the value type. -fn nested_fields(data_type: &DataType) -> Vec<&Field> { +#[expect(clippy::disallowed_methods, reason = "interning a dynamic id")] +fn field_uses_plugin(field: &Field, is_registered: &impl Fn(&Id) -> bool) -> bool { + field + .extension_type_name() + .is_some_and(|name| is_registered(&Id::new(name))) + || child_uses_plugin(field.data_type(), is_registered) +} + +fn child_uses_plugin(data_type: &DataType, is_registered: &impl Fn(&Id) -> bool) -> bool { match data_type { - DataType::Struct(fields) => fields.iter().map(Arc::as_ref).collect(), - DataType::Union(fields, _) => fields.iter().map(|(_, field)| field.as_ref()).collect(), + DataType::Struct(fields) => fields + .iter() + .any(|field| field_uses_plugin(field, is_registered)), + DataType::Union(fields, _) => fields + .iter() + .any(|(_, field)| field_uses_plugin(field, is_registered)), DataType::List(field) | DataType::LargeList(field) | DataType::ListView(field) | DataType::LargeListView(field) | DataType::FixedSizeList(field, _) | DataType::Map(field, _) - | DataType::RunEndEncoded(_, field) => vec![field.as_ref()], - DataType::Dictionary(_, values) => nested_fields(values), - // Other Arrow types have no nested fields. - _ => Vec::new(), + | DataType::RunEndEncoded(_, field) => field_uses_plugin(field, is_registered), + // A dictionary carries its value field's metadata on the outer field, checked above. + DataType::Dictionary(_, values) => child_uses_plugin(values, is_registered), + _ => false, } } diff --git a/vortex-arrow/src/test_harness/round_trip.rs b/vortex-arrow/src/test_harness/round_trip.rs index 77576217f12..b978d8f4c19 100644 --- a/vortex-arrow/src/test_harness/round_trip.rs +++ b/vortex-arrow/src/test_harness/round_trip.rs @@ -9,12 +9,15 @@ use std::sync::Arc; use arrow_array::Array; +use arrow_ord::cmp; use arrow_schema::DataType; use arrow_schema::Field; use vortex_array::ArrayRef; use vortex_array::ExecutionCtx; use vortex_array::IntoArray; +use vortex_array::arrays::BoolArray; use vortex_array::arrays::DictArray; +use vortex_array::arrays::ExtensionArray; use vortex_array::arrays::FixedSizeListArray; use vortex_array::arrays::ListArray; use vortex_array::arrays::ListViewArray; @@ -22,11 +25,14 @@ use vortex_array::arrays::MapArray; use vortex_array::arrays::PrimitiveArray; use vortex_array::arrays::RunEnd; use vortex_array::arrays::StructArray; +use vortex_array::arrays::extension::ExtensionArrayExt; use vortex_array::assert_arrays_eq; +use vortex_array::builtins::ArrayBuiltins; use vortex_array::dtype::DType; use vortex_array::dtype::FieldNames; use vortex_array::dtype::Nullability; use vortex_array::dtype::PType; +use vortex_array::scalar_fn::builtin::operators::Operator; use vortex_array::validity::Validity; use vortex_error::VortexExpect; use vortex_error::VortexResult; @@ -39,6 +45,9 @@ use crate::ExecuteArrowExt; /// The caller supplies both representations from source values. The expected field must not come /// from the Vortex exporter. The Vortex array must have an extension dtype. Arrow data equality /// ignores values masked by nulls. +/// +/// Also check the export against the Vortex storage for nulls, equality, and order where the Arrow +/// comparison kernels support the output type. #[track_caller] pub fn check_arrow( array: ArrayRef, @@ -46,7 +55,8 @@ pub fn check_arrow( expected: arrow_array::ArrayRef, ctx: &mut ExecutionCtx, ) -> VortexResult<()> { - check_arrow_values(array.clone(), field, Arc::clone(&expected), ctx)?; + let exported = check_arrow_values(array.clone(), field, Arc::clone(&expected), ctx)?; + check_exported_values(array.clone(), exported.as_ref(), ctx)?; check_nested_arrow(array.clone(), field, Arc::clone(&expected), ctx)?; let len = array.len(); let indices: Vec<_> = (0..u32::try_from(len)?) @@ -78,9 +88,7 @@ pub fn check_arrow( ]; for (operation, selected, expected) in selected { assert_eq!(selected.dtype(), array.dtype(), "{operation} dtype"); - let selected = selected - .execute::(ctx)? - .into_array(); + let selected = selected.execute::(ctx)?.into_array(); let exported = selected.execute_arrow(Some(field), ctx)?; assert_eq!(exported.to_data(), expected.to_data(), "{operation} values"); } @@ -94,7 +102,7 @@ fn check_arrow_values( field: &Field, expected: arrow_array::ArrayRef, ctx: &mut ExecutionCtx, -) -> VortexResult<()> { +) -> VortexResult { let session = ctx.session().clone(); let arrow = session.arrow(); assert_eq!(expected.data_type(), field.data_type()); @@ -106,6 +114,71 @@ fn check_arrow_values( exported.to_data().validate_full()?; assert_eq!(exported.to_data(), expected.to_data()); + Ok(exported) +} + +/// Checks the nulls and comparable storage values against the exported array. +/// +/// [`ArrowExportVTable::execute_arrow`] states the two rules. Check nulls across all rows, then +/// compare consecutive non-null rows. If the array contains distinct values, at least one pair +/// compares them. Nested exports only support the null check. +/// +/// [`ArrowExportVTable::execute_arrow`]: crate::ArrowExportVTable::execute_arrow +#[track_caller] +fn check_exported_values( + array: ArrayRef, + exported: &dyn Array, + ctx: &mut ExecutionCtx, +) -> VortexResult<()> { + let len = array.len(); + let nulls = exported.logical_nulls(); + let exported_is_null = match &nulls { + Some(nulls) => BoolArray::from_iter(nulls.iter().map(|valid| !valid)), + None => BoolArray::from_iter(std::iter::repeat_n(false, len)), + }; + assert_arrays_eq!(exported_is_null.into_array(), array.is_null()?, ctx); + + if exported.data_type().is_nested() { + return Ok(()); + } + + let indices = match nulls { + Some(nulls) => nulls + .valid_indices() + .map(u32::try_from) + .collect::, _>>()?, + None => (0..u32::try_from(len)?).collect(), + }; + if indices.len() < 2 { + return Ok(()); + } + + let left_indices = &indices[..indices.len() - 1]; + let right_indices = &indices[1..]; + + let session = ctx.session().clone(); + let extension = array.execute::(ctx)?; + let storage = extension.storage_array(); + let arrow_left = reference_take(exported, left_indices)?; + let arrow_right = reference_take(exported, right_indices)?; + let storage_left = + storage.take(PrimitiveArray::from_iter(left_indices.iter().copied()).into_array())?; + let storage_right = + storage.take(PrimitiveArray::from_iter(right_indices.iter().copied()).into_array())?; + + let comparisons = [ + (Operator::Eq, cmp::eq(&arrow_left, &arrow_right)?), + (Operator::Lt, cmp::lt(&arrow_left, &arrow_right)?), + ]; + + for (operator, in_arrow) in comparisons { + let in_vortex = storage_left.binary(storage_right.clone(), operator)?; + let in_arrow = session + .arrow() + .from_arrow_array(Arc::new(in_arrow), in_vortex.dtype().is_nullable())?; + assert_arrays_eq!(in_arrow, in_vortex, ctx); + } + Ok(()) } @@ -292,7 +365,9 @@ fn check_nested_arrow( .data_type(run_field.data_type().clone()) .build()?, ); - check_arrow_values(runs, &run_field, expected_runs, ctx) + check_arrow_values(runs, &run_field, expected_runs, ctx)?; + + Ok(()) } /// Selects source rows while retaining the row count of zero-width lists. @@ -484,3 +559,31 @@ pub fn check_containers(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult check_field_round_trip(run_end, &field, Some(&field), ctx) } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use arrow_array::Date32Array; + use vortex_array::VortexSessionExecute as _; + use vortex_error::VortexExpect; + use vortex_session::VortexSession; + + use super::check_exported_values; + use crate::ArrowSessionExt; + + #[test] + #[should_panic(expected = "assertion failed: arrays do not match")] + fn test_export_order_check_pairs_non_null_rows() { + let session = VortexSession::empty(); + let storage_order = Date32Array::from(vec![Some(1), Some(2), None, None]); + let reversed_order = Date32Array::from(vec![Some(2), Some(1), None, None]); + let array = session + .arrow() + .from_arrow_array(Arc::new(storage_order), true) + .vortex_expect("Date32 imports as a Vortex date array"); + + check_exported_values(array, &reversed_order, &mut session.create_execution_ctx()) + .vortex_expect("Date32 comparisons are supported"); + } +} diff --git a/vortex-datafusion/src/convert/exprs/mod.rs b/vortex-datafusion/src/convert/exprs/mod.rs index 4bc8bb51380..d00c2ead58b 100644 --- a/vortex-datafusion/src/convert/exprs/mod.rs +++ b/vortex-datafusion/src/convert/exprs/mod.rs @@ -79,6 +79,7 @@ use vortex::scalar_fn::builtin::get_item::GetItem; use vortex::scalar_fn::builtin::operators::Operator; use vortex::session::VortexSession; use vortex_arrow::ArrowSessionExt; +use vortex_arrow::ExecuteArrowExt; use crate::row_index::RowIndex; @@ -267,8 +268,8 @@ type Conversion = Result; /// Nested struct field access also uses Vortex semantics: a null parent produces a null child, /// whereas DataFusion extracts the child without applying parent validity. These differences /// are accepted for both filters and projections. -/// Field access through an extension can run natively when Arrow exposes its Vortex storage and no -/// plugin exports the selected field. +/// Field access through an extension can run natively when Arrow exposes its Vortex storage and +/// the selected field exports without plugins. /// Searched `CASE WHEN` expressions preserve short-circuit evaluation: conditions and /// branch values only execute on the rows that reach them, including fallible branches. /// Other expressions require compatible SQL semantics or remain in DataFusion. @@ -583,6 +584,10 @@ impl DefaultExpressionConverter { /// /// A literal that the plugins reject stays in DataFusion, including when a plugin accepts the /// field but rejects the value. + /// + /// Check that literals with extension metadata or a nested importer export back to the same + /// Arrow value. An importer can map several Arrow values to one Vortex value, such as every + /// non-zero `arrow.bool8` to true. DataFusion still distinguishes the original values. fn import_literal(&self, literal: &df_expr::Literal, field: &Field) -> Conversion { let array = literal.value().to_array()?; if array.len() != 1 { @@ -595,16 +600,31 @@ impl DefaultExpressionConverter { self.arrow_dtype(field)?; - self.session + let mut ctx = self.session.create_execution_ctx(); + let imported = self + .session .arrow() - .from_arrow_array(array, field) - .map_err(|_| Unconverted::Unsupported)? - .execute_scalar(0, &mut self.session.create_execution_ctx()) - .map_err(|error| { - Unconverted::Failed(DataFusionError::External(Box::new( - error.with_context(format!("Failed to convert literal {literal}")), - ))) - }) + .from_arrow_array(Arc::clone(&array), field) + .map_err(|_| Unconverted::Unsupported)?; + + if field.extension_type_name().is_some() + || !self.session.arrow().imports_without_plugins(field) + { + let exported = imported + .clone() + .execute_arrow(Some(field), &mut ctx) + .map_err(|_| Unconverted::Unsupported)?; + + if exported.to_data() != array.to_data() { + return Err(Unconverted::Unsupported); + } + } + + imported.execute_scalar(0, &mut ctx).map_err(|error| { + Unconverted::Failed(DataFusionError::External(Box::new( + error.with_context(format!("Failed to convert literal {literal}")), + ))) + }) } /// Converts a string argument of a string function. @@ -805,6 +825,11 @@ impl DefaultExpressionConverter { /// sides read the same values only when Vortex exports the parent as exactly its storage, which /// [`exports_extension_storage`] checks. /// + /// A plugin can choose how to export the selected field. Keep that read in DataFusion when + /// traversing extension storage. Two exporters can preserve order within their own outputs + /// and still encode equal values differently. Raw exporters of plain values can also change + /// their order. + /// /// [`exports_extension_storage`]: vortex_arrow::ArrowSession::exports_extension_storage fn convert_get_field( &self, @@ -861,12 +886,6 @@ impl DefaultExpressionConverter { read = get_item(name, read); } - // A plugin exporter decides which Arrow data DataFusion sees for the selected field, so - // Vortex and DataFusion agree on that field only if the export keeps values. Columns and - // plain struct fields already assume this, and the check skips them so that their pushdown - // stays the same. - // TODO(connor): Drop this check once the Arrow plugin contract requires exports to keep - // values. if reads_extension_storage && !self.session.arrow().exports_without_plugins(field) { return Err(Unconverted::Unsupported); } diff --git a/vortex-datafusion/src/convert/exprs/tests.rs b/vortex-datafusion/src/convert/exprs/tests.rs index be1e1882b1f..aa606ea8db1 100644 --- a/vortex-datafusion/src/convert/exprs/tests.rs +++ b/vortex-datafusion/src/convert/exprs/tests.rs @@ -934,6 +934,93 @@ fn test_literal_rejected_by_importer_is_unsupported() -> anyhow::Result<()> { Ok(()) } +const ABSOLUTE_EXTENSION_NAME: &str = "test.absolute"; +static ABSOLUTE_ID: CachedId = CachedId::new(ABSOLUTE_EXTENSION_NAME); + +/// An Arrow importer that imports every `Int32` as its absolute value, so two Arrow values can +/// import as one Vortex value. +#[derive(Debug)] +struct AbsoluteValueImporter; + +impl ArrowImportVTable for AbsoluteValueImporter { + fn arrow_ext_id(&self) -> Id { + *ABSOLUTE_ID + } + + fn from_arrow_field( + &self, + field: &Field, + session: &ArrowSession, + ) -> VortexResult> { + session + .from_arrow_datatype(field.data_type(), field.is_nullable().into()) + .map(Some) + } + + fn from_arrow_array( + &self, + array: ArrowArrayRef, + field: &Field, + _dtype: &DType, + session: &ArrowSession, + ) -> VortexResult { + let Some(values) = array.as_any().downcast_ref::() else { + vortex_bail!( + "{ABSOLUTE_EXTENSION_NAME} imports Int32, got {}", + array.data_type() + ); + }; + let absolute: Int32Array = values.unary(i32::wrapping_abs); + + session + .from_arrow_array(Arc::new(absolute), field.is_nullable()) + .map(ArrowImport::Imported) + } +} + +/// A literal with an importer converts only if it exports back to its own Arrow value. +/// +/// DataFusion distinguishes `1` from `-1`, but both import as `1`, including in a struct child. +#[rstest] +#[case::keeps_value(1, true)] +#[case::changes_value(-1, false)] +fn test_literal_importer_must_round_trip( + #[case] value: i32, + #[case] expect_native: bool, + #[values(false, true)] nested: bool, +) -> anyhow::Result<()> { + let session = VortexSession::default(); + session + .arrow() + .register_importer(Arc::new(AbsoluteValueImporter)); + let field = Field::new("v", DataType::Int32, false).with_metadata( + [( + EXTENSION_TYPE_NAME_KEY.to_string(), + ABSOLUTE_EXTENSION_NAME.to_string(), + )] + .into(), + ); + let literal = if nested { + let structure = StructArray::try_new( + vec![field].into(), + vec![Arc::new(Int32Array::from(vec![value]))], + None, + )?; + df_expr::Literal::new(ScalarValue::Struct(Arc::new(structure))) + } else { + df_expr::Literal::new_with_metadata( + ScalarValue::Int32(Some(value)), + Some(FieldMetadata::new_from_field(&field)), + ) + }; + let literal: Arc = Arc::new(literal); + + let converted = + DefaultExpressionConverter::new(session).try_convert(&literal, &Schema::empty())?; + assert_eq!(converted.is_some(), expect_native); + Ok(()) +} + #[rstest] #[case::comparison(false)] #[case::membership(true)] @@ -2705,15 +2792,15 @@ fn test_get_field_reads_extension_storage( /// /// The converter cannot know that before the export runs, so it treats the plugin as opaque. #[derive(Debug)] -struct DecliningPointExporter; +struct DecliningExporter(Id); -impl ArrowExportVTable for DecliningPointExporter { +impl ArrowExportVTable for DecliningExporter { fn arrow_ext_id(&self) -> Id { - *ANY_STORAGE_ID + self.0 } fn vortex_id(&self) -> Id { - *ANY_STORAGE_ID + self.0 } fn to_arrow_field( @@ -2748,7 +2835,7 @@ fn test_get_field_on_plugin_export_stays_in_datafusion( let batch = point_batch(&session)?; session .arrow() - .register_exporter(Arc::new(DecliningPointExporter)); + .register_exporter(Arc::new(DecliningExporter(*ANY_STORAGE_ID))); // The plugin leaves the inferred field as it is, so the field alone does not show the plugin. let schema = batch.schema(); @@ -2765,6 +2852,54 @@ fn test_get_field_on_plugin_export_stays_in_datafusion( Ok(()) } +static RAW_CHILD_EXPORTER_ID: CachedId = CachedId::new("test.raw_child_exporter"); + +#[rstest] +#[case::extension_child(true)] +#[case::plain_child(false)] +fn test_get_field_leaves_plugin_exported_child_in_datafusion( + #[case] extension_child: bool, +) -> anyhow::Result<()> { + let session = VortexSession::default(); + session.dtypes().register(AnyStorage); + + let child = if extension_child { + let mut child = Field::new("child", DataType::FixedSizeBinary(16), false); + child.try_with_extension_type(ArrowUuid)?; + child + } else { + session + .arrow() + .register_exporter(Arc::new(DecliningExporter(*RAW_CHILD_EXPORTER_ID))); + Field::new("child", DataType::Int32, false).with_metadata( + [( + EXTENSION_TYPE_NAME_KEY.to_string(), + RAW_CHILD_EXPORTER_ID.to_string(), + )] + .into(), + ) + }; + let child_dtype = session.arrow().from_arrow_field(&child)?; + let storage = DType::struct_([("child", child_dtype)], Nullability::NonNullable); + let holder = DType::Extension(AnyStorage::dtype(storage)?); + let holder_field = session + .arrow() + .to_arrow_field("holder", &holder)? + .with_data_type(DataType::Struct(vec![child].into())); + assert!( + session + .arrow() + .exports_extension_storage(holder.as_extension(), &holder_field) + ); + let schema = Schema::new(vec![holder_field]); + + let source = Arc::new(df_expr::Column::new("holder", 0)); + let expr = get_field_expr(source, &["child"], &schema)?; + let converter = DefaultExpressionConverter::new(session); + assert!(converter.try_convert(&expr, &schema)?.is_none()); + Ok(()) +} + #[rstest] fn test_nested_functions_reject_unknown_children( #[values(false, true)] list: bool,