Skip to content

Commit 5104d0e

Browse files
authored
Zero-copy conversion from SchemaRef to DfSchema (#10298)
1 parent c963d21 commit 5104d0e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

datafusion/common/src/dfschema.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,16 @@ impl From<&DFSchema> for Schema {
810810
impl TryFrom<Schema> for DFSchema {
811811
type Error = DataFusionError;
812812
fn try_from(schema: Schema) -> Result<Self, Self::Error> {
813+
Self::try_from(Arc::new(schema))
814+
}
815+
}
816+
817+
impl TryFrom<SchemaRef> for DFSchema {
818+
type Error = DataFusionError;
819+
fn try_from(schema: SchemaRef) -> Result<Self, Self::Error> {
813820
let field_count = schema.fields.len();
814821
let dfschema = Self {
815-
inner: schema.into(),
822+
inner: schema,
816823
field_qualifiers: vec![None; field_count],
817824
functional_dependencies: FunctionalDependencies::empty(),
818825
};
@@ -856,12 +863,7 @@ impl ToDFSchema for Schema {
856863

857864
impl ToDFSchema for SchemaRef {
858865
fn to_dfschema(self) -> Result<DFSchema> {
859-
// Attempt to use the Schema directly if there are no other
860-
// references, otherwise clone
861-
match Self::try_unwrap(self) {
862-
Ok(schema) => DFSchema::try_from(schema),
863-
Err(schemaref) => DFSchema::try_from(schemaref.as_ref().clone()),
864-
}
866+
DFSchema::try_from(self)
865867
}
866868
}
867869

0 commit comments

Comments
 (0)