Skip to content
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

Add support for DROP EXTENSION #1610

Merged
merged 2 commits into from
Dec 27, 2024
Merged

Add support for DROP EXTENSION #1610

merged 2 commits into from
Dec 27, 2024

Conversation

ramnivas
Copy link
Contributor

DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

https://www.postgresql.org/docs/current/sql-dropextension.html

```
DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
```

https://www.postgresql.org/docs/current/sql-dropextension.html
ramnivas added a commit to exograph/exograph that referenced this pull request Dec 19, 2024
Our migration tests have used strings in Rust files (for exo and expected SQL), which required string escaping, prefix stripping, and other modifications. This made it difficult to read and extend the test code (for example, consider `MigrationScope`s). Also, we relied on exact string matches, which required paying too much attention to the precise format.

This refactoring:
1. Move .exo and .sql files outside of rust code
2. Use `sqlparser` to match without considering the format

Note that in some cases, `sqlparser` doesn't parse valid syntax, so we rely on exact string comparison as a fallback/optimization. We have already contributed a couple of changes (apache/datafusion-sqlparser-rs#1608, apache/datafusion-sqlparser-rs#1610) and will continue to do so to remove this reliance.
@@ -2759,6 +2759,15 @@ pub enum Statement {
version: Option<Ident>,
},
/// ```sql
/// DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also include the link in the description here? would help folks find the syntax quicker in the future if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -5861,6 +5863,22 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_drop_extension(&mut self) -> Result<Statement, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the function is being made a public function, could we include a description for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

cascade_or_restrict: cascade_or_restrict.map(|k| match k {
Keyword::CASCADE => ReferentialAction::Cascade,
Keyword::RESTRICT => ReferentialAction::Restrict,
_ => unreachable!(),
Copy link
Contributor

Choose a reason for hiding this comment

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

in place of panicking here in case we missed something/bug, we can return an explicit error return self.expected(..)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -662,6 +662,22 @@ fn parse_create_extension() {
.verified_stmt("CREATE EXTENSION extension_name WITH SCHEMA schema_name VERSION version");
}

#[test]
fn parse_drop_extension() {
pg_and_generic().verified_stmt("DROP EXTENSION extension_name");
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the feature introduces a new node to the ast can we add one scenario that asserts the ast in this style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but in a slightly different style (more succinct), and did so for all scenarios.

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! Thanks @ramnivas!
cc @alamb

@iffyio iffyio changed the title Adds support for pg DROP EXTENSION Add support for DROP EXTENSION Dec 27, 2024
@iffyio iffyio merged commit 7dbf31b into apache:main Dec 27, 2024
8 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.

2 participants