Skip to content

Commit 10a63ea

Browse files
authored
Revert "Enhance object name path segments (apache#1539)"
This reverts commit 3ec49b2.
1 parent 2de82ca commit 10a63ea

20 files changed

+466
-584
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ println!("AST: {:?}", ast);
5353
This outputs
5454

5555
```rust
56-
AST: [Query(Query { ctes: [], body: Select(Select { distinct: false, projection: [UnnamedExpr(Identifier("a")), UnnamedExpr(Identifier("b")), UnnamedExpr(Value(Long(123))), UnnamedExpr(Function(Function { name:ObjectName([Identifier(Ident { value: "myfunc", quote_style: None })]), args: [Identifier("b")], filter: None, over: None, distinct: false }))], from: [TableWithJoins { relation: Table { name: ObjectName([Identifier(Ident { value: "table_1", quote_style: None })]), alias: None, args: [], with_hints: [] }, joins: [] }], selection: Some(BinaryOp { left: BinaryOp { left: Identifier("a"), op: Gt, right: Identifier("b") }, op: And, right: BinaryOp { left: Identifier("b"), op: Lt, right: Value(Long(100)) } }), group_by: [], having: None }), order_by: [OrderByExpr { expr: Identifier("a"), asc: Some(false) }, OrderByExpr { expr: Identifier("b"), asc: None }], limit: None, offset: None, fetch: None })]
56+
AST: [Query(Query { ctes: [], body: Select(Select { distinct: false, projection: [UnnamedExpr(Identifier("a")), UnnamedExpr(Identifier("b")), UnnamedExpr(Value(Long(123))), UnnamedExpr(Function(Function { name: ObjectName(["myfunc"]), args: [Identifier("b")], filter: None, over: None, distinct: false }))], from: [TableWithJoins { relation: Table { name: ObjectName(["table_1"]), alias: None, args: [], with_hints: [] }, joins: [] }], selection: Some(BinaryOp { left: BinaryOp { left: Identifier("a"), op: Gt, right: Identifier("b") }, op: And, right: BinaryOp { left: Identifier("b"), op: Lt, right: Value(Long(100)) } }), group_by: [], having: None }), order_by: [OrderByExpr { expr: Identifier("a"), asc: Some(false) }, OrderByExpr { expr: Identifier("b"), asc: None }], limit: None, offset: None, fetch: None })]
5757
```
5858

5959

src/ast/helpers/stmt_create_table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::parser::ParserError;
4242
/// ```rust
4343
/// use sqlparser::ast::helpers::stmt_create_table::CreateTableBuilder;
4444
/// use sqlparser::ast::{ColumnDef, DataType, Ident, ObjectName};
45-
/// let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]))
45+
/// let builder = CreateTableBuilder::new(ObjectName(vec![Ident::new("table_name")]))
4646
/// .if_not_exists(true)
4747
/// .columns(vec![ColumnDef {
4848
/// name: Ident::new("c1"),
@@ -602,7 +602,7 @@ mod tests {
602602

603603
#[test]
604604
pub fn test_from_valid_statement() {
605-
let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]));
605+
let builder = CreateTableBuilder::new(ObjectName(vec![Ident::new("table_name")]));
606606

607607
let stmt = builder.clone().build();
608608

src/ast/mod.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -267,44 +267,14 @@ impl fmt::Display for Ident {
267267
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
268268
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
269269
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
270-
pub struct ObjectName(pub Vec<ObjectNamePart>);
271-
272-
impl From<Vec<Ident>> for ObjectName {
273-
fn from(idents: Vec<Ident>) -> Self {
274-
ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
275-
}
276-
}
270+
pub struct ObjectName(pub Vec<Ident>);
277271

278272
impl fmt::Display for ObjectName {
279273
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
280274
write!(f, "{}", display_separated(&self.0, "."))
281275
}
282276
}
283277

284-
/// A single part of an ObjectName
285-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
286-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
287-
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
288-
pub enum ObjectNamePart {
289-
Identifier(Ident),
290-
}
291-
292-
impl ObjectNamePart {
293-
pub fn as_ident(&self) -> Option<&Ident> {
294-
match self {
295-
ObjectNamePart::Identifier(ident) => Some(ident),
296-
}
297-
}
298-
}
299-
300-
impl fmt::Display for ObjectNamePart {
301-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
302-
match self {
303-
ObjectNamePart::Identifier(ident) => write!(f, "{}", ident),
304-
}
305-
}
306-
}
307-
308278
/// Represents an Array Expression, either
309279
/// `ARRAY[..]`, or `[..]`
310280
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]

src/ast/spans.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ use super::{
2727
FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments,
2828
GroupByExpr, HavingBound, IlikeSelectItem, Insert, Interpolate, InterpolateExpr, Join,
2929
JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView, MatchRecognizePattern,
30-
Measure, NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict,
31-
OnConflictAction, OnInsert, OrderBy, OrderByExpr, Partition, PivotValueSource,
32-
ProjectionSelect, Query, ReferentialAction, RenameSelectItem, ReplaceSelectElement,
33-
ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript,
34-
SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject,
35-
TableOptionsClustered, TableWithJoins, UpdateTableFromKind, Use, Value, Values, ViewColumnDef,
36-
WildcardAdditionalOptions, With, WithFill,
30+
Measure, NamedWindowDefinition, ObjectName, Offset, OnConflict, OnConflictAction, OnInsert,
31+
OrderBy, OrderByExpr, Partition, PivotValueSource, ProjectionSelect, Query, ReferentialAction,
32+
RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem,
33+
SetExpr, SqlOption, Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef,
34+
TableConstraint, TableFactor, TableObject, TableOptionsClustered, TableWithJoins,
35+
UpdateTableFromKind, Use, Value, Values, ViewColumnDef, WildcardAdditionalOptions, With,
36+
WithFill,
3737
};
3838

3939
/// Given an iterator of spans, return the [Span::union] of all spans.
@@ -1385,7 +1385,7 @@ impl Spanned for Expr {
13851385
.union_opt(&overlay_for.as_ref().map(|i| i.span())),
13861386
Expr::Collate { expr, collation } => expr
13871387
.span()
1388-
.union(&union_spans(collation.0.iter().map(|i| i.span()))),
1388+
.union(&union_spans(collation.0.iter().map(|i| i.span))),
13891389
Expr::Nested(expr) => expr.span(),
13901390
Expr::Value(value) => value.span(),
13911391
Expr::TypedString { .. } => Span::empty(),
@@ -1489,7 +1489,7 @@ impl Spanned for Expr {
14891489
object_name
14901490
.0
14911491
.iter()
1492-
.map(|i| i.span())
1492+
.map(|i| i.span)
14931493
.chain(iter::once(token.0.span)),
14941494
),
14951495
Expr::OuterJoin(expr) => expr.span(),
@@ -1534,15 +1534,7 @@ impl Spanned for ObjectName {
15341534
fn span(&self) -> Span {
15351535
let ObjectName(segments) = self;
15361536

1537-
union_spans(segments.iter().map(|i| i.span()))
1538-
}
1539-
}
1540-
1541-
impl Spanned for ObjectNamePart {
1542-
fn span(&self) -> Span {
1543-
match self {
1544-
ObjectNamePart::Identifier(ident) => ident.span,
1545-
}
1537+
union_spans(segments.iter().map(|i| i.span))
15461538
}
15471539
}
15481540

@@ -1573,7 +1565,7 @@ impl Spanned for Function {
15731565
union_spans(
15741566
name.0
15751567
.iter()
1576-
.map(|i| i.span())
1568+
.map(|i| i.span)
15771569
.chain(iter::once(args.span()))
15781570
.chain(iter::once(parameters.span()))
15791571
.chain(filter.iter().map(|i| i.span()))
@@ -1659,7 +1651,7 @@ impl Spanned for SelectItem {
16591651
object_name
16601652
.0
16611653
.iter()
1662-
.map(|i| i.span())
1654+
.map(|i| i.span)
16631655
.chain(iter::once(wildcard_additional_options.span())),
16641656
),
16651657
SelectItem::Wildcard(wildcard_additional_options) => wildcard_additional_options.span(),
@@ -1769,7 +1761,7 @@ impl Spanned for TableFactor {
17691761
} => union_spans(
17701762
name.0
17711763
.iter()
1772-
.map(|i| i.span())
1764+
.map(|i| i.span)
17731765
.chain(alias.as_ref().map(|alias| {
17741766
union_spans(
17751767
iter::once(alias.name.span)
@@ -1814,7 +1806,7 @@ impl Spanned for TableFactor {
18141806
} => union_spans(
18151807
name.0
18161808
.iter()
1817-
.map(|i| i.span())
1809+
.map(|i| i.span)
18181810
.chain(args.iter().map(|i| i.span()))
18191811
.chain(alias.as_ref().map(|alias| alias.span())),
18201812
),
@@ -1965,7 +1957,7 @@ impl Spanned for FunctionArgExpr {
19651957
match self {
19661958
FunctionArgExpr::Expr(expr) => expr.span(),
19671959
FunctionArgExpr::QualifiedWildcard(object_name) => {
1968-
union_spans(object_name.0.iter().map(|i| i.span()))
1960+
union_spans(object_name.0.iter().map(|i| i.span))
19691961
}
19701962
FunctionArgExpr::Wildcard => Span::empty(),
19711963
}
@@ -2176,7 +2168,7 @@ impl Spanned for TableObject {
21762168
fn span(&self) -> Span {
21772169
match self {
21782170
TableObject::TableName(ObjectName(segments)) => {
2179-
union_spans(segments.iter().map(|i| i.span()))
2171+
union_spans(segments.iter().map(|i| i.span))
21802172
}
21812173
TableObject::TableFunction(func) => func.span(),
21822174
}

src/ast/visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ where
403403
/// ```
404404
/// # use sqlparser::parser::Parser;
405405
/// # use sqlparser::dialect::GenericDialect;
406-
/// # use sqlparser::ast::{ObjectName, ObjectNamePart, Ident, visit_relations_mut};
406+
/// # use sqlparser::ast::{ObjectName, visit_relations_mut};
407407
/// # use core::ops::ControlFlow;
408408
/// let sql = "SELECT a FROM foo";
409409
/// let mut statements = Parser::parse_sql(&GenericDialect{}, sql)
410410
/// .unwrap();
411411
///
412412
/// // visit statements, renaming table foo to bar
413413
/// visit_relations_mut(&mut statements, |table| {
414-
/// table.0[0] = ObjectNamePart::Identifier(Ident::new("bar"));
414+
/// table.0[0].value = table.0[0].value.replace("foo", "bar");
415415
/// ControlFlow::<()>::Continue(())
416416
/// });
417417
///
@@ -529,7 +529,7 @@ where
529529
/// if matches!(expr, Expr::Identifier(col_name) if col_name.value == "x") {
530530
/// let old_expr = std::mem::replace(expr, Expr::Value(Value::Null));
531531
/// *expr = Expr::Function(Function {
532-
/// name: ObjectName::from(vec![Ident::new("f")]),
532+
/// name: ObjectName(vec![Ident::new("f")]),
533533
/// uses_odbc_syntax: false,
534534
/// args: FunctionArguments::List(FunctionArgumentList {
535535
/// duplicate_treatment: None,

src/dialect/snowflake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub fn parse_snowflake_stage_name(parser: &mut Parser) -> Result<ObjectName, Par
651651
break;
652652
}
653653
}
654-
Ok(ObjectName::from(idents))
654+
Ok(ObjectName(idents))
655655
}
656656
_ => {
657657
parser.prev_token();

0 commit comments

Comments
 (0)