From 70740c6d0e8887860bc65c2ab935864333dbc71a Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 28 Nov 2024 22:17:27 +0100 Subject: [PATCH] fixup! Encapsulate create table/view construction rename fallible new() to try_new() --- datafusion/expr/src/logical_plan/ddl.rs | 12 ++++++------ datafusion/proto/src/logical_plan/mod.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/datafusion/expr/src/logical_plan/ddl.rs b/datafusion/expr/src/logical_plan/ddl.rs index a2fe7a2ef82f..c45bbd27817c 100644 --- a/datafusion/expr/src/logical_plan/ddl.rs +++ b/datafusion/expr/src/logical_plan/ddl.rs @@ -291,7 +291,7 @@ impl PartialOrd for CreateExternalTable { } impl CreateExternalTable { - pub fn new(fields: CreateExternalTableFields) -> Result { + pub fn try_new(fields: CreateExternalTableFields) -> Result { let CreateExternalTableFields { name, schema, @@ -497,7 +497,7 @@ impl CreateExternalTableBuilder { } pub fn build(self) -> Result { - CreateExternalTable::new(CreateExternalTableFields { + CreateExternalTable::try_new(CreateExternalTableFields { name: self.name.expect("name is required"), schema: self.schema.expect("schema is required"), location: self.location.expect("location is required"), @@ -536,7 +536,7 @@ pub struct CreateMemoryTable { } impl CreateMemoryTable { - pub fn new(fields: CreateMemoryTableFields) -> Result { + pub fn try_new(fields: CreateMemoryTableFields) -> Result { let CreateMemoryTableFields { name, constraints, @@ -664,7 +664,7 @@ impl CreateMemoryTableBuilder { } pub fn build(self) -> Result { - CreateMemoryTable::new(CreateMemoryTableFields { + CreateMemoryTable::try_new(CreateMemoryTableFields { name: self.name.expect("name is required"), constraints: self.constraints, input: self.input.expect("input is required"), @@ -693,7 +693,7 @@ pub struct CreateView { } impl CreateView { - pub fn new(fields: CreateViewFields) -> Result { + pub fn try_new(fields: CreateViewFields) -> Result { let CreateViewFields { name, input, @@ -795,7 +795,7 @@ impl CreateViewBuilder { } pub fn build(self) -> Result { - CreateView::new(CreateViewFields { + CreateView::try_new(CreateViewFields { name: self.name.expect("name is required"), input: self.input.expect("input is required"), or_replace: self.or_replace, diff --git a/datafusion/proto/src/logical_plan/mod.rs b/datafusion/proto/src/logical_plan/mod.rs index 49e20540fb3d..3c295905b6cf 100644 --- a/datafusion/proto/src/logical_plan/mod.rs +++ b/datafusion/proto/src/logical_plan/mod.rs @@ -568,7 +568,7 @@ impl AsLogicalPlan for LogicalPlanNode { } Ok(LogicalPlan::Ddl(DdlStatement::CreateExternalTable( - CreateExternalTable::new(CreateExternalTableFields { + CreateExternalTable::try_new(CreateExternalTableFields { schema: pb_schema.try_into()?, name: from_table_reference( create_extern_table.name.as_ref(), @@ -602,8 +602,8 @@ impl AsLogicalPlan for LogicalPlanNode { None }; - Ok(LogicalPlan::Ddl(DdlStatement::CreateView(CreateView::new( - CreateViewFields { + Ok(LogicalPlan::Ddl(DdlStatement::CreateView( + CreateView::try_new(CreateViewFields { name: from_table_reference( create_view.name.as_ref(), "CreateView", @@ -612,8 +612,8 @@ impl AsLogicalPlan for LogicalPlanNode { input: Arc::new(plan), or_replace: create_view.or_replace, definition, - }, - )?))) + })?, + ))) } LogicalPlanType::CreateCatalogSchema(create_catalog_schema) => { let pb_schema = (create_catalog_schema.schema.clone()).ok_or_else(|| {