Skip to content

Minor(proto): Implement TryFrom<&DFSchema> for protobuf::DfSchema#7505

Merged
alamb merged 1 commit intoapache:mainfrom
jonahgao:try_from_dfschema
Sep 8, 2023
Merged

Minor(proto): Implement TryFrom<&DFSchema> for protobuf::DfSchema#7505
alamb merged 1 commit intoapache:mainfrom
jonahgao:try_from_dfschema

Conversation

@jonahgao
Copy link
Member

@jonahgao jonahgao commented Sep 8, 2023

Which issue does this PR close?

N/A

Rationale for this change

Currently, we have only implemented TryFrom<&DFSchemaRef> for protobuf::DfSchema.
In the example below, when encoding a DFSchema, we have to create an Arc, which can be considered wasteful.

let dfschema = datafusion::common::DFSchema::empty();
let arc_dfschema = Arc::new(dfschema);
let proto_dfschema: datafusion_proto::DfSchema =(&arc_dfschema).try_into().unwrap();

Implementing TryFrom<&DFSchema> for protobuf::DfSchema helps to avoid this issue,
and then the code is simplified as follows.

let dfschema = datafusion::common::DFSchema::empty();
let proto_dfschema: datafusion_proto::DfSchema =(&dfschema).try_into().unwrap();

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

New API, without breaking changes

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jonahgao

@alamb alamb merged commit c7a93fc into apache:main Sep 8, 2023
@jonahgao jonahgao deleted the try_from_dfschema branch September 8, 2023 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants