Skip to content

Commit

Permalink
refactor: move show views into own statement for databricks override
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Dec 18, 2024
1 parent 6efd23d commit 0037844
Showing 1 changed file with 142 additions and 106 deletions.
248 changes: 142 additions & 106 deletions crates/lib-dialects/src/sparksql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ pub fn dialect() -> Dialect {
.into(),
),
]);

sparksql_dialect.add([
(
"FileLiteralSegment".into(),
Expand Down Expand Up @@ -2569,6 +2570,29 @@ pub fn dialect() -> Dialect {
.to_matchable()
.into(),
),
(
"ShowViewsStatement".into(),
Sequence::new(vec_of_erased![
Ref::keyword("SHOW"),
Ref::keyword("VIEWS"),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![Ref::keyword("FROM"), Ref::keyword("IN")]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
])
.to_matchable()
.into(),
),
(
"SetStatementSegment".into(),
NodeMatcher::new(
Expand All @@ -2593,133 +2617,145 @@ pub fn dialect() -> Dialect {
"ShowStatement".into(),
NodeMatcher::new(
SyntaxKind::ShowStatement,
Sequence::new(vec_of_erased![
Ref::keyword("SHOW"),
one_of(vec_of_erased![
Sequence::new(vec_of_erased![
Ref::keyword("CREATE"),
Ref::keyword("TABLE"),
Ref::new("TableExpressionSegment"),
Sequence::new(vec_of_erased![
Ref::keyword("AS"),
Ref::keyword("SERDE")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
Ref::keyword("COLUMNS"),
Ref::keyword("IN"),
Ref::new("TableExpressionSegment"),
one_of(vec_of_erased![
Ref::new("ShowViewsStatement"),
Sequence::new(vec_of_erased![
Ref::keyword("SHOW"),
one_of(vec_of_erased![
Sequence::new(vec_of_erased![
Ref::keyword("IN"),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("DATABASES"),
Ref::keyword("SCHEMAS")
Ref::keyword("CREATE"),
Ref::keyword("TABLE"),
Ref::new("TableExpressionSegment"),
Sequence::new(vec_of_erased![
Ref::keyword("AS"),
Ref::keyword("SERDE")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("USER"),
Ref::keyword("SYSTEM"),
Ref::keyword("ALL")
])
.config(|config| {
config.optional();
}),
Ref::keyword("FUNCTIONS"),
one_of(vec_of_erased![
Ref::keyword("COLUMNS"),
Ref::keyword("IN"),
Ref::new("TableExpressionSegment"),
Sequence::new(vec_of_erased![
Ref::new("DatabaseReferenceSegment"),
Ref::new("DotSegment"),
Ref::new("FunctionNameSegment")
Ref::keyword("IN"),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.disallow_gaps();
config.optional();
}),
Ref::new("FunctionNameSegment").optional(),
})
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("DATABASES"),
Ref::keyword("SCHEMAS")
]),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
])
]),
Sequence::new(vec_of_erased![
Ref::keyword("PARTITIONS"),
Ref::new("TableReferenceSegment"),
Ref::new("PartitionSpecGrammar").optional()
]),
Sequence::new(vec_of_erased![
Ref::keyword("TABLE"),
Ref::keyword("EXTENDED"),
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![Ref::keyword("IN"), Ref::keyword("FROM")]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment"),
Ref::new("PartitionSpecGrammar").optional()
]),
Sequence::new(vec_of_erased![
Ref::keyword("TABLES"),
one_of(vec_of_erased![
Ref::keyword("USER"),
Ref::keyword("SYSTEM"),
Ref::keyword("ALL")
])
.config(|config| {
config.optional();
}),
Ref::keyword("FUNCTIONS"),
one_of(vec_of_erased![
Sequence::new(vec_of_erased![
Ref::new("DatabaseReferenceSegment"),
Ref::new("DotSegment"),
Ref::new("FunctionNameSegment")
])
.config(|config| {
config.disallow_gaps();
config.optional();
}),
Ref::new("FunctionNameSegment").optional(),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
])
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![Ref::keyword("FROM"), Ref::keyword("IN")]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Ref::keyword("PARTITIONS"),
Ref::new("TableReferenceSegment"),
Ref::new("PartitionSpecGrammar").optional()
]),
Sequence::new(vec_of_erased![
Ref::keyword("TABLE"),
Ref::keyword("EXTENDED"),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("IN"),
Ref::keyword("FROM")
]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
Ref::keyword("TBLPROPERTIES"),
Ref::new("TableReferenceSegment"),
Ref::new("BracketedPropertyNameListGrammar").optional()
]),
Sequence::new(vec_of_erased![
Ref::keyword("VIEWS"),
Ref::new("QuotedLiteralSegment"),
Ref::new("PartitionSpecGrammar").optional()
]),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![Ref::keyword("FROM"), Ref::keyword("IN")]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Ref::keyword("TABLES"),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("FROM"),
Ref::keyword("IN")
]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
]),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
Ref::keyword("TBLPROPERTIES"),
Ref::new("TableReferenceSegment"),
Ref::new("BracketedPropertyNameListGrammar").optional()
]),
Sequence::new(vec_of_erased![
Ref::keyword("VIEWS"),
Sequence::new(vec_of_erased![
one_of(vec_of_erased![
Ref::keyword("FROM"),
Ref::keyword("IN")
]),
Ref::new("DatabaseReferenceSegment")
])
.config(|config| {
config.optional();
}),
Sequence::new(vec_of_erased![
Ref::keyword("LIKE"),
Ref::new("QuotedLiteralSegment")
])
.config(|config| {
config.optional();
})
])
.config(|config| {
config.optional();
})
])
])
])
Expand Down

0 comments on commit 0037844

Please sign in to comment.