Skip to content

Commit 406ce84

Browse files
committed
update base on comment
1 parent 5c75a9e commit 406ce84

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
@@ -3238,7 +3238,7 @@ impl fmt::Display for Statement {
32383238
}
32393239

32403240
if let Some(options) = options {
3241-
write!(f, "({}) ",display_comma_separated(options))?;
3241+
write!(f, "({}) ", display_comma_separated(options))?;
32423242
}
32433243

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

src/parser/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ impl<'a> Parser<'a> {
12771277
}
12781278
}
12791279

1280-
pub fn parse_utility_option_list(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
1280+
pub fn parse_utility_options(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
12811281
self.expect_token(&Token::LParen)?;
12821282
let options = self.parse_comma_separated(Self::parse_utility_option)?;
12831283
self.expect_token(&Token::RParen)?;
@@ -8495,10 +8495,10 @@ impl<'a> Parser<'a> {
84958495
// Note: DuckDB is compatible with PostgreSQL syntax for this statement,
84968496
// although not all features may be implemented.
84978497
if describe_alias == DescribeAlias::Explain
8498-
&& dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect)
8498+
&& self.dialect.supports_explain_with_utility_options()
84998499
&& self.peek_token().token == Token::LParen
85008500
{
8501-
options = Some(self.parse_utility_option_list()?)
8501+
options = Some(self.parse_utility_options()?)
85028502
} else {
85038503
analyze = self.parse_keyword(Keyword::ANALYZE);
85048504
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
@@ -4268,31 +4268,14 @@ fn parse_scalar_function_in_projection() {
42684268
}
42694269

42704270
fn run_explain_analyze(
4271+
dialect: TestedDialects,
42714272
query: &str,
42724273
expected_verbose: bool,
42734274
expected_analyze: bool,
42744275
expected_format: Option<AnalyzeFormat>,
42754276
exepcted_options: Option<Vec<UtilityOption>>,
42764277
) {
4277-
run_explain_analyze_with_specific_dialect(
4278-
|_d| true,
4279-
query,
4280-
expected_verbose,
4281-
expected_analyze,
4282-
expected_format,
4283-
exepcted_options,
4284-
)
4285-
}
4286-
4287-
fn run_explain_analyze_with_specific_dialect<T: Fn(&dyn Dialect) -> bool>(
4288-
dialect_predicate: T,
4289-
query: &str,
4290-
expected_verbose: bool,
4291-
expected_analyze: bool,
4292-
expected_format: Option<AnalyzeFormat>,
4293-
exepcted_options: Option<Vec<UtilityOption>>,
4294-
) {
4295-
match all_dialects_where(dialect_predicate).verified_stmt(query) {
4278+
match dialect.verified_stmt(query) {
42964279
Statement::Explain {
42974280
describe_alias: _,
42984281
analyze,
@@ -4350,29 +4333,40 @@ fn explain_desc() {
43504333
fn parse_explain_analyze_with_simple_select() {
43514334
// Describe is an alias for EXPLAIN
43524335
run_explain_analyze(
4336+
all_dialects(),
43534337
"DESCRIBE SELECT sqrt(id) FROM foo",
43544338
false,
43554339
false,
43564340
None,
43574341
None,
43584342
);
43594343

4360-
run_explain_analyze("EXPLAIN SELECT sqrt(id) FROM foo", false, false, None, None);
43614344
run_explain_analyze(
4345+
all_dialects(),
4346+
"EXPLAIN SELECT sqrt(id) FROM foo",
4347+
false,
4348+
false,
4349+
None,
4350+
None,
4351+
);
4352+
run_explain_analyze(
4353+
all_dialects(),
43624354
"EXPLAIN VERBOSE SELECT sqrt(id) FROM foo",
43634355
true,
43644356
false,
43654357
None,
43664358
None,
43674359
);
43684360
run_explain_analyze(
4361+
all_dialects(),
43694362
"EXPLAIN ANALYZE SELECT sqrt(id) FROM foo",
43704363
false,
43714364
true,
43724365
None,
43734366
None,
43744367
);
43754368
run_explain_analyze(
4369+
all_dialects(),
43764370
"EXPLAIN ANALYZE VERBOSE SELECT sqrt(id) FROM foo",
43774371
true,
43784372
true,
@@ -4381,6 +4375,7 @@ fn parse_explain_analyze_with_simple_select() {
43814375
);
43824376

43834377
run_explain_analyze(
4378+
all_dialects(),
43844379
"EXPLAIN ANALYZE FORMAT GRAPHVIZ SELECT sqrt(id) FROM foo",
43854380
false,
43864381
true,
@@ -4389,6 +4384,7 @@ fn parse_explain_analyze_with_simple_select() {
43894384
);
43904385

43914386
run_explain_analyze(
4387+
all_dialects(),
43924388
"EXPLAIN ANALYZE VERBOSE FORMAT JSON SELECT sqrt(id) FROM foo",
43934389
true,
43944390
true,
@@ -4397,6 +4393,7 @@ fn parse_explain_analyze_with_simple_select() {
43974393
);
43984394

43994395
run_explain_analyze(
4396+
all_dialects(),
44004397
"EXPLAIN VERBOSE FORMAT TEXT SELECT sqrt(id) FROM foo",
44014398
true,
44024399
false,
@@ -10861,8 +10858,8 @@ fn test_truncate_table_with_on_cluster() {
1086110858

1086210859
#[test]
1086310860
fn parse_explain_with_option_list() {
10864-
run_explain_analyze_with_specific_dialect(
10865-
|d| d.supports_explain_with_utility_options(),
10861+
run_explain_analyze(
10862+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1086610863
"EXPLAIN (ANALYZE false, VERBOSE true) SELECT sqrt(id) FROM foo",
1086710864
false,
1086810865
false,
@@ -10879,8 +10876,8 @@ fn parse_explain_with_option_list() {
1087910876
]),
1088010877
);
1088110878

10882-
run_explain_analyze_with_specific_dialect(
10883-
|d| d.supports_explain_with_utility_options(),
10879+
run_explain_analyze(
10880+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1088410881
"EXPLAIN (ANALYZE ON, VERBOSE OFF) SELECT sqrt(id) FROM foo",
1088510882
false,
1088610883
false,
@@ -10897,8 +10894,8 @@ fn parse_explain_with_option_list() {
1089710894
]),
1089810895
);
1089910896

10900-
run_explain_analyze_with_specific_dialect(
10901-
|d| d.supports_explain_with_utility_options(),
10897+
run_explain_analyze(
10898+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1090210899
r#"EXPLAIN (FORMAT1 TEXT, FORMAT2 'JSON', FORMAT3 "XML", FORMAT4 YAML) SELECT sqrt(id) FROM foo"#,
1090310900
false,
1090410901
false,
@@ -10923,8 +10920,8 @@ fn parse_explain_with_option_list() {
1092310920
]),
1092410921
);
1092510922

10926-
run_explain_analyze_with_specific_dialect(
10927-
|d| d.supports_explain_with_utility_options(),
10923+
run_explain_analyze(
10924+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1092810925
r#"EXPLAIN (NUM1 10, NUM2 +10.1, NUM3 -10.2) SELECT sqrt(id) FROM foo"#,
1092910926
false,
1093010927
false,
@@ -10951,7 +10948,7 @@ fn parse_explain_with_option_list() {
1095110948
]),
1095210949
);
1095310950

10954-
let utility_option_list = vec![
10951+
let utility_options = vec![
1095510952
UtilityOption {
1095610953
name: Ident::new("ANALYZE"),
1095710954
arg: None,
@@ -10976,12 +10973,12 @@ fn parse_explain_with_option_list() {
1097610973
}),
1097710974
},
1097810975
];
10979-
run_explain_analyze_with_specific_dialect(
10980-
|d| d.supports_explain_with_utility_options(),
10976+
run_explain_analyze (
10977+
all_dialects_where(|d| d.supports_explain_with_utility_options()),
1098110978
"EXPLAIN (ANALYZE, VERBOSE true, WAL OFF, FORMAT YAML, USER_DEF_NUM -100.1) SELECT sqrt(id) FROM foo",
1098210979
false,
1098310980
false,
1098410981
None,
10985-
Some(utility_option_list),
10982+
Some(utility_options),
1098610983
);
1098710984
}

0 commit comments

Comments
 (0)