From d2ba90109bc53ea705626ab21e5125363a19a5c4 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 2 Apr 2024 18:17:47 -0400 Subject: [PATCH] Minor: Use impl Into> to construct TableReference (#9916) --- datafusion/common/src/table_reference.rs | 13 ++++++++++--- datafusion/proto/src/logical_plan/from_proto.rs | 6 +++--- datafusion/sql/src/planner.rs | 8 ++++---- datafusion/sql/src/statement.rs | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/datafusion/common/src/table_reference.rs b/datafusion/common/src/table_reference.rs index 1ffcbb8f34aa..63dbb9517724 100644 --- a/datafusion/common/src/table_reference.rs +++ b/datafusion/common/src/table_reference.rs @@ -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>) -> TableReference { TableReference::Bare { table: table.into(), } @@ -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>, + table: impl Into>, + ) -> TableReference { TableReference::Partial { schema: schema.into(), table: table.into(), @@ -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>, + schema: impl Into>, + table: impl Into>, + ) -> TableReference { TableReference::Full { catalog: catalog.into(), schema: schema.into(), diff --git a/datafusion/proto/src/logical_plan/from_proto.rs b/datafusion/proto/src/logical_plan/from_proto.rs index 02f73b296a7a..3694418412b1 100644 --- a/datafusion/proto/src/logical_plan/from_proto.rs +++ b/datafusion/proto/src/logical_plan/from_proto.rs @@ -223,17 +223,17 @@ impl TryFrom 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)), } } } diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index 0ee7860573dd..d2182962b98e 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -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() } @@ -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), } diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs index 84dab9067848..69d1b71e4fe8 100644 --- a/datafusion/sql/src/statement.rs +++ b/datafusion/sql/src/statement.rs @@ -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(