-
Notifications
You must be signed in to change notification settings - Fork 691
Add SETOF support for PostgreSQL function return types #2217
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
Open
fmguerreiro
wants to merge
3
commits into
apache:main
Choose a base branch
from
fmguerreiro:setof-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−55
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -597,6 +597,31 @@ impl Spanned for CreateTable { | |
| } | ||
| } | ||
|
|
||
| impl Spanned for PartitionBoundValue { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| PartitionBoundValue::Expr(expr) => expr.span(), | ||
| PartitionBoundValue::MinValue => Span::empty(), | ||
| PartitionBoundValue::MaxValue => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ForValues { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| ForValues::In(exprs) => union_spans(exprs.iter().map(|e| e.span())), | ||
| ForValues::From { from, to } => union_spans( | ||
| from.iter() | ||
| .map(|v| v.span()) | ||
| .chain(to.iter().map(|v| v.span())), | ||
| ), | ||
| ForValues::With { .. } => Span::empty(), | ||
| ForValues::Default => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ColumnDef { | ||
| fn span(&self) -> Span { | ||
| let ColumnDef { | ||
|
|
@@ -632,33 +657,6 @@ impl Spanned for TableConstraint { | |
| } | ||
| } | ||
|
|
||
| impl Spanned for PartitionBoundValue { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any changes in this diff (if not can we revert it)? |
||
| fn span(&self) -> Span { | ||
| match self { | ||
| PartitionBoundValue::Expr(expr) => expr.span(), | ||
| // MINVALUE and MAXVALUE are keywords without tracked spans | ||
| PartitionBoundValue::MinValue => Span::empty(), | ||
| PartitionBoundValue::MaxValue => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for ForValues { | ||
| fn span(&self) -> Span { | ||
| match self { | ||
| ForValues::In(exprs) => union_spans(exprs.iter().map(|e| e.span())), | ||
| ForValues::From { from, to } => union_spans( | ||
| from.iter() | ||
| .map(|v| v.span()) | ||
| .chain(to.iter().map(|v| v.span())), | ||
| ), | ||
| // WITH (MODULUS n, REMAINDER r) - u64 values have no spans | ||
| ForValues::With { .. } => Span::empty(), | ||
| ForValues::Default => Span::empty(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Spanned for CreateIndex { | ||
| fn span(&self) -> Span { | ||
| let CreateIndex { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -933,6 +933,7 @@ define_keywords!( | |
| SESSION_USER, | ||
| SET, | ||
| SETERROR, | ||
| SETOF, | ||
| SETS, | ||
| SETTINGS, | ||
| SHARE, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5545,7 +5545,7 @@ impl<'a> Parser<'a> { | |||||
| self.expect_token(&Token::RParen)?; | ||||||
|
|
||||||
| let return_type = if self.parse_keyword(Keyword::RETURNS) { | ||||||
| Some(self.parse_data_type()?) | ||||||
| Some(self.parse_function_return_type()?) | ||||||
| } else { | ||||||
| None | ||||||
| }; | ||||||
|
|
@@ -5724,7 +5724,7 @@ impl<'a> Parser<'a> { | |||||
| let (name, args) = self.parse_create_function_name_and_params()?; | ||||||
|
|
||||||
| let return_type = if self.parse_keyword(Keyword::RETURNS) { | ||||||
| Some(self.parse_data_type()?) | ||||||
| Some(self.parse_function_return_type()?) | ||||||
| } else { | ||||||
| None | ||||||
| }; | ||||||
|
|
@@ -5827,11 +5827,11 @@ impl<'a> Parser<'a> { | |||||
| }) | ||||||
| })?; | ||||||
|
|
||||||
| let return_type = if return_table.is_some() { | ||||||
| return_table | ||||||
| } else { | ||||||
| Some(self.parse_data_type()?) | ||||||
| let data_type = match return_table { | ||||||
| Some(table_type) => table_type, | ||||||
| None => self.parse_data_type()?, | ||||||
| }; | ||||||
| let return_type = Some(FunctionReturnType::DataType(data_type)); | ||||||
|
|
||||||
| let _ = self.parse_keyword(Keyword::AS); | ||||||
|
|
||||||
|
|
@@ -5883,6 +5883,17 @@ impl<'a> Parser<'a> { | |||||
| }) | ||||||
| } | ||||||
|
|
||||||
| /// Parse a [`FunctionReturnType`] after the `RETURNS` keyword. | ||||||
| /// | ||||||
| /// Handles `RETURNS SETOF <type>` and plain `RETURNS <type>`. | ||||||
|
Comment on lines
+5887
to
+5888
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| fn parse_function_return_type(&mut self) -> Result<FunctionReturnType, ParserError> { | ||||||
| if self.parse_keyword(Keyword::SETOF) { | ||||||
| Ok(FunctionReturnType::SetOf(self.parse_data_type()?)) | ||||||
| } else { | ||||||
| Ok(FunctionReturnType::DataType(self.parse_data_type()?)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn parse_create_function_name_and_params( | ||||||
| &mut self, | ||||||
| ) -> Result<(ObjectName, Vec<OperateFunctionArg>), ParserError> { | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead move the link to the postgres docs here? since the enum itself applies to all dialects, whereas only this variant is pg specific