Skip to content

Add From<&SchemaRef> impls to avoid explicit schema clones#61

Merged
adriangb merged 1 commit into
pydantic:table-schema-builderfrom
alamb:table-schema-from-ref-impls
May 26, 2026
Merged

Add From<&SchemaRef> impls to avoid explicit schema clones#61
adriangb merged 1 commit into
pydantic:table-schema-builderfrom
alamb:table-schema-from-ref-impls

Conversation

@alamb

@alamb alamb commented May 26, 2026

Copy link
Copy Markdown

Proposed addition to

This builds on the new TableSchemaBuilder by adding From impls that take a borrowed SchemaRef, so call sites no longer need an explicit Arc::clone(..) / .clone():

Add `From<&SchemaRef>` for `TableSchema`, and `From<SchemaRef>` /
`From<&SchemaRef>` for `TableSchemaBuilder`, so callers can construct a
schema/builder from a borrowed `SchemaRef` without writing an explicit
`Arc::clone(..)` / `.clone()` at every call site.

Port the existing call sites that explicitly cloned the file schema to
the new `From` impls:
  - `TableSchema::builder(Arc::clone(&x))` -> `TableSchemaBuilder::from(&x)`
  - `TableSchema::from(Arc::clone(&x))`    -> `TableSchema::from(&x)`

The `Arc::clone` still happens inside the `From` impl; this just removes
the boilerplate at the call sites. Owned-value call sites are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
/// Creates a file source for this table
fn create_file_source(&self) -> Arc<dyn FileSource> {
let table_schema = TableSchema::builder(Arc::clone(&self.file_schema))
let table_schema = TableSchemaBuilder::from(&self.file_schema)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the point of this PR is to simplity the code and avoid a bunch of explicit clones

@alamb alamb marked this pull request as ready for review May 26, 2026 20:16
@alamb

alamb commented May 26, 2026

Copy link
Copy Markdown
Author

FYI @adriangb

@adriangb adriangb merged commit f07c7c1 into pydantic:table-schema-builder May 26, 2026
33 checks passed
@adriangb

Copy link
Copy Markdown
Member

thanks Andrew!

@alamb alamb deleted the table-schema-from-ref-impls branch May 26, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants