Skip to content

feat: support explain options #1426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 19, 2024
Merged

Conversation

kysshsy
Copy link
Contributor

@kysshsy kysshsy commented Sep 13, 2024

support EXPLAIN [ ( option [, ...] ) ] statement

close #1425

@kysshsy
Copy link
Contributor Author

kysshsy commented Sep 15, 2024

Update my code. Please review again @iffyio Thank you.

@kysshsy kysshsy requested a review from iffyio September 15, 2024 06:00
@kysshsy kysshsy requested a review from iffyio September 16, 2024 10:25
@@ -1274,6 +1274,29 @@ impl<'a> Parser<'a> {
}
}

pub fn parse_utility_option_list(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn parse_utility_option_list(&mut self) -> Result<Vec<UtilityOption>, ParserError> {
pub fn parse_utility_options(&mut self) -> Result<Vec<UtilityOption>, ParserError> {

// Note: DuckDB is compatible with PostgreSQL syntax for this statement,
// although not all features may be implemented.
if describe_alias == DescribeAlias::Explain
&& dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect)
&& self.dialect.supports_explain_with_utility_options()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. thank you

Comment on lines 4265 to 4282
run_explain_analyze_with_specific_dialect(
|_d| true,
query,
expected_verbose,
expected_analyze,
expected_format,
exepcted_options,
)
}

fn run_explain_analyze_with_specific_dialect<T: Fn(&dyn Dialect) -> bool>(
dialect_predicate: T,
query: &str,
expected_verbose: bool,
expected_analyze: bool,
expected_format: Option<AnalyzeFormat>,
exepcted_options: Option<Vec<UtilityOption>>,
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of having two functions, we can reuse the existing run_explain_analyze and have that one take in a dialect: TestedDialects as the argument (instead of a lambda), then the existing tests can pass in all_dialects() while the new tests pass in all_dialects_where(|d| d.supports_option_list())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 151 to 155
/// Ensures that `sql` parses as a single [Statement] and that the re-serialization of the parsed
/// result matches the given `canonical` SQL string.
pub fn verified_stmt_with_canonical(&self, sql: &str, canonical: &str) -> Statement {
self.one_statement_parses_to(sql, canonical)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Ensures that `sql` parses as a single [Statement] and that the re-serialization of the parsed
/// result matches the given `canonical` SQL string.
pub fn verified_stmt_with_canonical(&self, sql: &str, canonical: &str) -> Statement {
self.one_statement_parses_to(sql, canonical)
}

this looks unused and we can remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@kysshsy kysshsy requested a review from iffyio September 18, 2024 12:55
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! cc @alamb

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nicely done @kysshsy and @iffyio -- thank you

@@ -7116,6 +7123,47 @@ where
}
}

/// Represents a single PostgreSQL utility option.
///
/// A utility option is a key-value pair where the key is an identifier (IDENT) and the value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@alamb
Copy link
Contributor

alamb commented Sep 19, 2024

Looks like there are some small CI issues to address

@coveralls
Copy link

coveralls commented Sep 19, 2024

Pull Request Test Coverage Report for Build 10942458377

Details

  • 143 of 159 (89.94%) changed or added relevant lines in 7 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.002%) to 89.338%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dialect/duckdb.rs 1 2 50.0%
src/dialect/generic.rs 1 2 50.0%
src/dialect/mod.rs 1 2 50.0%
src/dialect/postgresql.rs 1 2 50.0%
tests/sqlparser_common.rs 104 116 89.66%
Files with Coverage Reduction New Missed Lines %
src/ast/mod.rs 1 82.43%
Totals Coverage Status
Change from base Build 10939574081: 0.002%
Covered Lines: 29602
Relevant Lines: 33135

💛 - Coveralls

@kysshsy kysshsy force-pushed the support_explain_options branch from d935ebe to b5bb4f2 Compare September 19, 2024 13:30
@kysshsy
Copy link
Contributor Author

kysshsy commented Sep 19, 2024

Looks like there are some small CI issues to address

Fixes the CI issues @alamb .

@kysshsy kysshsy requested a review from alamb September 19, 2024 14:09
@alamb
Copy link
Contributor

alamb commented Sep 19, 2024

🚀 -- thanks @kysshsy and @iffyio

@alamb alamb merged commit 04a53e5 into apache:main Sep 19, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Postgres Explain options
4 participants