From e8c363e5477fa853124713dbf59aa95ea3c3c68a Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Mon, 29 Apr 2024 15:19:31 +0100 Subject: [PATCH] Zero-copy conversion from SchemaRef to DfSchema --- datafusion/common/src/dfschema.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rs index 64e40ea99e67..b2a3de72356c 100644 --- a/datafusion/common/src/dfschema.rs +++ b/datafusion/common/src/dfschema.rs @@ -810,9 +810,16 @@ impl From<&DFSchema> for Schema { impl TryFrom for DFSchema { type Error = DataFusionError; fn try_from(schema: Schema) -> Result { + Self::try_from(Arc::new(schema)) + } +} + +impl TryFrom for DFSchema { + type Error = DataFusionError; + fn try_from(schema: SchemaRef) -> Result { let field_count = schema.fields.len(); let dfschema = Self { - inner: schema.into(), + inner: schema, field_qualifiers: vec![None; field_count], functional_dependencies: FunctionalDependencies::empty(), }; @@ -856,12 +863,7 @@ impl ToDFSchema for Schema { impl ToDFSchema for SchemaRef { fn to_dfschema(self) -> Result { - // Attempt to use the Schema directly if there are no other - // references, otherwise clone - match Self::try_unwrap(self) { - Ok(schema) => DFSchema::try_from(schema), - Err(schemaref) => DFSchema::try_from(schemaref.as_ref().clone()), - } + DFSchema::try_from(self) } }