Skip to content

Commit cc8dec0

Browse files
authored
Minor: Split DmlStatement into its own module (#6120)
* Minor: Split `DmlStatement` into its own module * fix: doc link
1 parent 451e81e commit cc8dec0

File tree

4 files changed

+66
-44
lines changed

4 files changed

+66
-44
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::{
19+
fmt::{self, Display},
20+
sync::Arc,
21+
};
22+
23+
use datafusion_common::{DFSchemaRef, OwnedTableReference};
24+
25+
use crate::LogicalPlan;
26+
27+
/// The operator that modifies the content of a database (adapted from
28+
/// substrait WriteRel)
29+
#[derive(Clone, PartialEq, Eq, Hash)]
30+
pub struct DmlStatement {
31+
/// The table name
32+
pub table_name: OwnedTableReference,
33+
/// The schema of the table (must align with Rel input)
34+
pub table_schema: DFSchemaRef,
35+
/// The type of operation to perform
36+
pub op: WriteOp,
37+
/// The relation that determines the tuples to add/remove/modify the schema must match with table_schema
38+
pub input: Arc<LogicalPlan>,
39+
}
40+
41+
#[derive(Clone, PartialEq, Eq, Hash)]
42+
pub enum WriteOp {
43+
Insert,
44+
Delete,
45+
Update,
46+
Ctas,
47+
}
48+
49+
impl Display for WriteOp {
50+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51+
match self {
52+
WriteOp::Insert => write!(f, "Insert"),
53+
WriteOp::Delete => write!(f, "Delete"),
54+
WriteOp::Update => write!(f, "Update"),
55+
WriteOp::Ctas => write!(f, "Ctas"),
56+
}
57+
}
58+
}

datafusion/expr/src/logical_plan/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
pub mod builder;
1919
pub mod display;
20+
mod dml;
2021
mod extension;
2122
mod plan;
2223
mod statement;
2324

2425
pub use builder::{table_scan, LogicalPlanBuilder};
26+
pub use dml::{DmlStatement, WriteOp};
2527
pub use plan::{
2628
Aggregate, Analyze, CreateCatalog, CreateCatalogSchema, CreateExternalTable,
2729
CreateMemoryTable, CreateView, CrossJoin, DescribeTable, Distinct, DropTable,
@@ -31,8 +33,8 @@ pub use plan::{
3133
Unnest, Values, Window,
3234
};
3335
pub use statement::{
34-
DmlStatement, SetVariable, Statement, TransactionAccessMode, TransactionConclusion,
35-
TransactionEnd, TransactionIsolationLevel, TransactionStart, WriteOp,
36+
SetVariable, Statement, TransactionAccessMode, TransactionConclusion, TransactionEnd,
37+
TransactionIsolationLevel, TransactionStart,
3638
};
3739

3840
pub use display::display_schema;

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
///! Logical plan types
1919
use crate::logical_plan::display::{GraphvizVisitor, IndentVisitor};
2020
use crate::logical_plan::extension::UserDefinedLogicalNode;
21-
use crate::logical_plan::statement::{DmlStatement, Statement};
21+
use crate::logical_plan::{DmlStatement, Statement};
2222

2323
use crate::logical_plan::plan;
2424
use crate::utils::{

datafusion/expr/src/logical_plan/statement.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::{
19-
fmt::{self, Display},
20-
sync::Arc,
21-
};
18+
use std::fmt::{self, Display};
2219

23-
use datafusion_common::{DFSchemaRef, OwnedTableReference};
24-
25-
use crate::LogicalPlan;
20+
use datafusion_common::DFSchemaRef;
2621

2722
/// Various types of Statements.
2823
///
@@ -65,7 +60,7 @@ impl Statement {
6560
/// description of this LogicalPlan node per node, not including
6661
/// children.
6762
///
68-
/// See [LogicalPlan::display] for an example
63+
/// See [crate::LogicalPlan::display] for an example
6964
pub fn display(&self) -> impl fmt::Display + '_ {
7065
struct Wrapper<'a>(&'a Statement);
7166
impl<'a> Display for Wrapper<'a> {
@@ -97,39 +92,6 @@ impl Statement {
9792
}
9893
}
9994

100-
/// The operator that modifies the content of a database (adapted from
101-
/// substrait WriteRel)
102-
#[derive(Clone, PartialEq, Eq, Hash)]
103-
pub struct DmlStatement {
104-
/// The table name
105-
pub table_name: OwnedTableReference,
106-
/// The schema of the table (must align with Rel input)
107-
pub table_schema: DFSchemaRef,
108-
/// The type of operation to perform
109-
pub op: WriteOp,
110-
/// The relation that determines the tuples to add/remove/modify the schema must match with table_schema
111-
pub input: Arc<LogicalPlan>,
112-
}
113-
114-
#[derive(Clone, PartialEq, Eq, Hash)]
115-
pub enum WriteOp {
116-
Insert,
117-
Delete,
118-
Update,
119-
Ctas,
120-
}
121-
122-
impl Display for WriteOp {
123-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124-
match self {
125-
WriteOp::Insert => write!(f, "Insert"),
126-
WriteOp::Delete => write!(f, "Delete"),
127-
WriteOp::Update => write!(f, "Update"),
128-
WriteOp::Ctas => write!(f, "Ctas"),
129-
}
130-
}
131-
}
132-
13395
/// Indicates if a transaction was committed or aborted
13496
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
13597
pub enum TransactionConclusion {

0 commit comments

Comments
 (0)