Skip to content

Commit d935ebe

Browse files
committed
update base on comment
1 parent 23b4e65 commit d935ebe

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ impl fmt::Display for Statement {
32333233
}
32343234

32353235
if let Some(options) = options {
3236-
write!(f, "({}) ",display_comma_separated(options))?;
3236+
write!(f, "({}) ", display_comma_separated(options))?;
32373237
}
32383238

32393239
write!(f, "{statement}")

src/parser/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ impl<'a> Parser<'a> {
12741274
}
12751275
}
12761276

1277-
pub fn parse_utility_option_list(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
1277+
pub fn parse_utility_options(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
12781278
self.expect_token(&Token::LParen)?;
12791279
let options = self.parse_comma_separated(Self::parse_utility_option)?;
12801280
self.expect_token(&Token::RParen)?;
@@ -8471,10 +8471,10 @@ impl<'a> Parser<'a> {
84718471
// Note: DuckDB is compatible with PostgreSQL syntax for this statement,
84728472
// although not all features may be implemented.
84738473
if describe_alias == DescribeAlias::Explain
8474-
&& dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect)
8474+
&& self.dialect.supports_explain_with_utility_options()
84758475
&& self.peek_token().token == Token::LParen
84768476
{
8477-
options = Some(self.parse_utility_option_list()?)
8477+
options = Some(self.parse_utility_options()?)
84788478
} else {
84798479
analyze = self.parse_keyword(Keyword::ANALYZE);
84808480
verbose = self.parse_keyword(Keyword::VERBOSE);

src/test_utils.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ impl TestedDialects {
148148
self.one_statement_parses_to(sql, sql)
149149
}
150150

151-
/// Ensures that `sql` parses as a single [Statement] and that the re-serialization of the parsed
152-
/// result matches the given `canonical` SQL string.
153-
pub fn verified_stmt_with_canonical(&self, sql: &str, canonical: &str) -> Statement {
154-
self.one_statement_parses_to(sql, canonical)
155-
}
156-
157151
/// Ensures that `sql` parses as a single [Query], and that
158152
/// re-serializing the parse result produces the same `sql`
159153
/// string (is not modified after a serialization round-trip).

tests/sqlparser_common.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,31 +4256,14 @@ fn parse_scalar_function_in_projection() {
42564256
}
42574257

42584258
fn run_explain_analyze(
4259+
dialect: TestedDialects,
42594260
query: &str,
42604261
expected_verbose: bool,
42614262
expected_analyze: bool,
42624263
expected_format: Option<AnalyzeFormat>,
42634264
exepcted_options: Option<Vec<UtilityOption>>,
42644265
) {
4265-
run_explain_analyze_with_specific_dialect(
4266-
|_d| true,
4267-
query,
4268-
expected_verbose,
4269-
expected_analyze,
4270-
expected_format,
4271-
exepcted_options,
4272-
)
4273-
}
4274-
4275-
fn run_explain_analyze_with_specific_dialect<T: Fn(&dyn Dialect) -> bool>(
4276-
dialect_predicate: T,
4277-
query: &str,
4278-
expected_verbose: bool,
4279-
expected_analyze: bool,
4280-
expected_format: Option<AnalyzeFormat>,
4281-
exepcted_options: Option<Vec<UtilityOption>>,
4282-
) {
4283-
match all_dialects_where(dialect_predicate).verified_stmt(query) {
4266+
match dialect.verified_stmt(query) {
42844267
Statement::Explain {
42854268
describe_alias: _,
42864269
analyze,
@@ -4338,29 +4321,40 @@ fn explain_desc() {
43384321
fn parse_explain_analyze_with_simple_select() {
43394322
// Describe is an alias for EXPLAIN
43404323
run_explain_analyze(
4324+
all_dialects(),
43414325
"DESCRIBE SELECT sqrt(id) FROM foo",
43424326
false,
43434327
false,
43444328
None,
43454329
None,
43464330
);
43474331

4348-
run_explain_analyze("EXPLAIN SELECT sqrt(id) FROM foo", false, false, None, None);
43494332
run_explain_analyze(
4333+
all_dialects(),
4334+
"EXPLAIN SELECT sqrt(id) FROM foo",
4335+
false,
4336+
false,
4337+
None,
4338+
None,
4339+
);
4340+
run_explain_analyze(
4341+
all_dialects(),
43504342
"EXPLAIN VERBOSE SELECT sqrt(id) FROM foo",
43514343
true,
43524344
false,
43534345
None,
43544346
None,
43554347
);
43564348
run_explain_analyze(
4349+
all_dialects(),
43574350
"EXPLAIN ANALYZE SELECT sqrt(id) FROM foo",
43584351
false,
43594352
true,
43604353
None,
43614354
None,
43624355
);
43634356
run_explain_analyze(
4357+
all_dialects(),
43644358
"EXPLAIN ANALYZE VERBOSE SELECT sqrt(id) FROM foo",
43654359
true,
43664360
true,
@@ -4369,6 +4363,7 @@ fn parse_explain_analyze_with_simple_select() {
43694363
);
43704364

43714365
run_explain_analyze(
4366+
all_dialects(),
43724367
"EXPLAIN ANALYZE FORMAT GRAPHVIZ SELECT sqrt(id) FROM foo",
43734368
false,
43744369
true,
@@ -4377,6 +4372,7 @@ fn parse_explain_analyze_with_simple_select() {
43774372
);
43784373

43794374
run_explain_analyze(
4375+
all_dialects(),
43804376
"EXPLAIN ANALYZE VERBOSE FORMAT JSON SELECT sqrt(id) FROM foo",
43814377
true,
43824378
true,
@@ -4385,6 +4381,7 @@ fn parse_explain_analyze_with_simple_select() {
43854381
);
43864382

43874383
run_explain_analyze(
4384+
all_dialects(),
43884385
"EXPLAIN VERBOSE FORMAT TEXT SELECT sqrt(id) FROM foo",
43894386
true,
43904387
false,
@@ -10828,8 +10825,8 @@ fn test_extract_seconds_single_quote_err() {
1082810825

1082910826
#[test]
1083010827
fn parse_explain_with_option_list() {
10831-
run_explain_analyze_with_specific_dialect(
10832-
|d| d.supports_explain_with_utility_options(),
10828+
run_explain_analyze(
10829+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1083310830
"EXPLAIN (ANALYZE false, VERBOSE true) SELECT sqrt(id) FROM foo",
1083410831
false,
1083510832
false,
@@ -10846,8 +10843,8 @@ fn parse_explain_with_option_list() {
1084610843
]),
1084710844
);
1084810845

10849-
run_explain_analyze_with_specific_dialect(
10850-
|d| d.supports_explain_with_utility_options(),
10846+
run_explain_analyze(
10847+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1085110848
"EXPLAIN (ANALYZE ON, VERBOSE OFF) SELECT sqrt(id) FROM foo",
1085210849
false,
1085310850
false,
@@ -10864,8 +10861,8 @@ fn parse_explain_with_option_list() {
1086410861
]),
1086510862
);
1086610863

10867-
run_explain_analyze_with_specific_dialect(
10868-
|d| d.supports_explain_with_utility_options(),
10864+
run_explain_analyze(
10865+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1086910866
r#"EXPLAIN (FORMAT1 TEXT, FORMAT2 'JSON', FORMAT3 "XML", FORMAT4 YAML) SELECT sqrt(id) FROM foo"#,
1087010867
false,
1087110868
false,
@@ -10890,8 +10887,8 @@ fn parse_explain_with_option_list() {
1089010887
]),
1089110888
);
1089210889

10893-
run_explain_analyze_with_specific_dialect(
10894-
|d| d.supports_explain_with_utility_options(),
10890+
run_explain_analyze(
10891+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1089510892
r#"EXPLAIN (NUM1 10, NUM2 +10.1, NUM3 -10.2) SELECT sqrt(id) FROM foo"#,
1089610893
false,
1089710894
false,
@@ -10918,7 +10915,7 @@ fn parse_explain_with_option_list() {
1091810915
]),
1091910916
);
1092010917

10921-
let utility_option_list = vec![
10918+
let utility_options = vec![
1092210919
UtilityOption {
1092310920
name: Ident::new("ANALYZE"),
1092410921
arg: None,
@@ -10943,12 +10940,12 @@ fn parse_explain_with_option_list() {
1094310940
}),
1094410941
},
1094510942
];
10946-
run_explain_analyze_with_specific_dialect(
10947-
|d| d.supports_explain_with_utility_options(),
10943+
run_explain_analyze (
10944+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1094810945
"EXPLAIN (ANALYZE, VERBOSE true, WAL OFF, FORMAT YAML, USER_DEF_NUM -100.1) SELECT sqrt(id) FROM foo",
1094910946
false,
1095010947
false,
1095110948
None,
10952-
Some(utility_option_list),
10949+
Some(utility_options),
1095310950
);
1095410951
}

0 commit comments

Comments
 (0)