Skip to content

Commit

Permalink
Minor: Use impl Into<Arc<str>> to construct TableReference (#9916)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Apr 2, 2024
1 parent a6ff1fe commit d2ba901
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
13 changes: 10 additions & 3 deletions datafusion/common/src/table_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl TableReference {
/// As described on [`TableReference`] this does *NO* parsing at
/// all, so "Foo.Bar" stays as a reference to the table named
/// "Foo.Bar" (rather than "foo"."bar")
pub fn bare(table: &str) -> TableReference {
pub fn bare(table: impl Into<Arc<str>>) -> TableReference {
TableReference::Bare {
table: table.into(),
}
Expand All @@ -140,7 +140,10 @@ impl TableReference {
/// Convenience method for creating a [`TableReference::Partial`].
///
/// As described on [`TableReference`] this does *NO* parsing at all.
pub fn partial(schema: &str, table: &str) -> TableReference {
pub fn partial(
schema: impl Into<Arc<str>>,
table: impl Into<Arc<str>>,
) -> TableReference {
TableReference::Partial {
schema: schema.into(),
table: table.into(),
Expand All @@ -150,7 +153,11 @@ impl TableReference {
/// Convenience method for creating a [`TableReference::Full`]
///
/// As described on [`TableReference`] this does *NO* parsing at all.
pub fn full(catalog: &str, schema: &str, table: &str) -> TableReference {
pub fn full(
catalog: impl Into<Arc<str>>,
schema: impl Into<Arc<str>>,
table: impl Into<Arc<str>>,
) -> TableReference {
TableReference::Full {
catalog: catalog.into(),
schema: schema.into(),
Expand Down
6 changes: 3 additions & 3 deletions datafusion/proto/src/logical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ impl TryFrom<protobuf::OwnedTableReference> for OwnedTableReference {

match table_reference_enum {
TableReferenceEnum::Bare(protobuf::BareTableReference { table }) => {
Ok(OwnedTableReference::bare(&table))
Ok(OwnedTableReference::bare(table))
}
TableReferenceEnum::Partial(protobuf::PartialTableReference {
schema,
table,
}) => Ok(OwnedTableReference::partial(&schema, &table)),
}) => Ok(OwnedTableReference::partial(schema, table)),
TableReferenceEnum::Full(protobuf::FullTableReference {
catalog,
schema,
table,
}) => Ok(OwnedTableReference::full(&catalog, &schema, &table)),
}) => Ok(OwnedTableReference::full(catalog, schema, table)),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let plan = self.apply_expr_alias(plan, alias.columns)?;

LogicalPlanBuilder::from(plan)
.alias(TableReference::bare(&self.normalizer.normalize(alias.name)))?
.alias(TableReference::bare(self.normalizer.normalize(alias.name)))?
.build()
}

Expand Down Expand Up @@ -530,18 +530,18 @@ pub(crate) fn idents_to_table_reference(
match taker.0.len() {
1 => {
let table = taker.take(enable_normalization);
Ok(OwnedTableReference::bare(&table))
Ok(OwnedTableReference::bare(table))
}
2 => {
let table = taker.take(enable_normalization);
let schema = taker.take(enable_normalization);
Ok(OwnedTableReference::partial(&schema, &table))
Ok(OwnedTableReference::partial(schema, table))
}
3 => {
let table = taker.take(enable_normalization);
let schema = taker.take(enable_normalization);
let catalog = taker.take(enable_normalization);
Ok(OwnedTableReference::full(&catalog, &schema, &table))
Ok(OwnedTableReference::full(catalog, schema, table))
}
_ => plan_err!("Unsupported compound identifier '{:?}'", taker.0),
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
self.build_order_by(order_exprs, &df_schema, &mut planner_context)?;

// External tables do not support schemas at the moment, so the name is just a table name
let name = OwnedTableReference::bare(&name);
let name = OwnedTableReference::bare(name);
let constraints =
Constraints::new_from_table_constraints(&all_constraints, &df_schema)?;
Ok(LogicalPlan::Ddl(DdlStatement::CreateExternalTable(
Expand Down

0 comments on commit d2ba901

Please sign in to comment.