This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 5104d0e0fa Zero-copy conversion from SchemaRef to DfSchema (#10298)
5104d0e0fa is described below
commit 5104d0e0fa4516fb99d000337502138561f6374e
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Mon Apr 29 16:14:47 2024 +0100
Zero-copy conversion from SchemaRef to DfSchema (#10298)
---
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 64e40ea99e..b2a3de7235 100644
--- a/datafusion/common/src/dfschema.rs
+++ b/datafusion/common/src/dfschema.rs
@@ -810,9 +810,16 @@ impl From<&DFSchema> for Schema {
impl TryFrom<Schema> for DFSchema {
type Error = DataFusionError;
fn try_from(schema: Schema) -> Result<Self, Self::Error> {
+ Self::try_from(Arc::new(schema))
+ }
+}
+
+impl TryFrom<SchemaRef> for DFSchema {
+ type Error = DataFusionError;
+ fn try_from(schema: SchemaRef) -> Result<Self, Self::Error> {
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<DFSchema> {
- // 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)
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]