Skip to content

Commit

Permalink
show progress
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Dec 19, 2024
1 parent cab7246 commit 0f09194
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 186 deletions.
41 changes: 35 additions & 6 deletions crates/lib-dialects/src/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use sqruff_lib_core::{
},
vec_of_erased,
};
use crate::sparksql;

pub fn dialect() -> Dialect {
let raw_sparksql = crate::sparksql::dialect();
let raw_sparksql = sparksql::dialect();

let mut databricks = crate::sparksql::dialect();
let mut databricks = sparksql::dialect();
databricks.name = DialectKind::Databricks;

// databricks
Expand Down Expand Up @@ -238,6 +239,16 @@ pub fn dialect() -> Dialect {
.to_matchable()
.into(),
),
(
"ShowVolumesStatement".into(),
Sequence::new(vec_of_erased![
Ref::keyword("SHOW"),
Ref::keyword("VOLUMES"),
Ref::new("DatabaseReferenceSegment"),
])
.to_matchable()
.into(),
),
// // NotebookStart=TypedParser("notebook_start", CommentSegment, type="notebook_start"),
// // MagicLineGrammar=TypedParser("magic_line", CodeSegment, type="magic_line"),
// // MagicStartGrammar=TypedParser("magic_start", CodeSegment, type="magic_start"),
Expand All @@ -261,11 +272,12 @@ pub fn dialect() -> Dialect {
databricks.replace_grammar(
"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"),
])])
Sequence::new(vec_of_erased![
one_of(vec_of_erased![Ref::keyword("FROM"), Ref::keyword("IN"),]),
Ref::new("DatabaseReferenceSegment"),
])
.config(|config| {
config.optional();
}),
Expand All @@ -279,6 +291,23 @@ pub fn dialect() -> Dialect {
.into(),
);

let mut show_statements = sparksql::show_statements();
show_statements.push(
Ref::new("ShowVolumesStatement")
.to_matchable()
.into()
);
databricks.replace_grammar(
"ShowStatement".into(),
one_of(show_statements)
.to_matchable()
.into(),
);





// // TODO Missing Show Object Grammar
// databricks.replace_grammar(
// "NotNullGrammar".into(),
Expand Down
283 changes: 138 additions & 145 deletions crates/lib-dialects/src/sparksql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sqruff_lib_core::parser::grammar::conditional::Conditional;
use sqruff_lib_core::parser::grammar::delimited::Delimited;
use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence};
use sqruff_lib_core::parser::lexer::Matcher;
use sqruff_lib_core::parser::matchable::MatchableTrait;
use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait};
use sqruff_lib_core::parser::node_matcher::NodeMatcher;
use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser};
use sqruff_lib_core::parser::segments::bracketed::BracketedSegmentMatcher;
Expand Down Expand Up @@ -2593,7 +2593,9 @@ pub fn dialect() -> Dialect {
})
])
.to_matchable(),
).to_matchable().into(),
)
.to_matchable()
.into(),
),
(
"SetStatementSegment".into(),
Expand All @@ -2619,149 +2621,7 @@ pub fn dialect() -> Dialect {
"ShowStatement".into(),
NodeMatcher::new(
SyntaxKind::ShowStatement,
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("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"),
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")
]),
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![
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![
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"),
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("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();
})
])
])
])
])
.to_matchable(),
one_of(show_statements()).to_matchable(),
)
.to_matchable()
.into(),
Expand Down Expand Up @@ -3547,3 +3407,136 @@ pub fn dialect() -> Dialect {
sparksql_dialect.expand();
sparksql_dialect
}

pub fn show_statements() -> Vec<Matchable> {
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("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"),
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")
]),
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![
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![
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"),
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("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();
})
])
])
])
]
}
Loading

0 comments on commit 0f09194

Please sign in to comment.