Skip to content

Commit dce1011

Browse files
committed
sql-parser: select from clause (join clauses)
1 parent 3cbf7e7 commit dce1011

File tree

2 files changed

+437
-61
lines changed

2 files changed

+437
-61
lines changed

src/ast/select.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::{Expression, Identifier, OrderingTerm, WindowDefinition};
2+
use std::fmt::Display;
23

34
/// An enum representing the possible types of SELECT statements
45
#[derive(Debug, PartialEq, Clone)]
@@ -130,7 +131,7 @@ pub struct JoinClause {
130131
pub struct JoinTable {
131132
pub join_type: JoinType,
132133
pub table: Box<SelectFrom>,
133-
pub constraints: JoinConstraint,
134+
pub constraints: Option<JoinConstraint>,
134135
}
135136

136137
/// A type alias for the `NATURAL` keyword in a JOIN clause
@@ -151,13 +152,33 @@ pub enum JoinType {
151152
Cross,
152153
}
153154

155+
impl Display for JoinType {
156+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
157+
match self {
158+
JoinType::Left(is_natural) => {
159+
write!(f, "{} LEFT", if *is_natural { "NATURAL" } else { "" })
160+
}
161+
JoinType::Right(is_natural) => {
162+
write!(f, "{} RIGHT", if *is_natural { "NATURAL" } else { "" })
163+
}
164+
JoinType::Full(is_natural) => {
165+
write!(f, "{} FULL", if *is_natural { "NATURAL" } else { "" })
166+
}
167+
JoinType::Inner(is_natural) => {
168+
write!(f, "{} INNER", if *is_natural { "NATURAL" } else { "" })
169+
}
170+
JoinType::Cross => write!(f, "CROSS"),
171+
}
172+
}
173+
}
174+
154175
/// A constraint for a JOIN clause
155176
#[derive(Debug, PartialEq, Clone)]
156177
pub enum JoinConstraint {
157178
/// ON clause
158179
On(Expression),
159180
/// USING clause
160-
Using(Vec<String>),
181+
Using(Vec<Identifier>),
161182
}
162183

163184
/// A clause for a LIMIT statement

0 commit comments

Comments
 (0)