iffyio commented on code in PR #2162:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2162#discussion_r2726915136
##########
src/parser/mod.rs:
##########
@@ -14005,6 +14015,59 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses an optional optimizer hint at the current token position
+ ///
+ ///
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html#optimizer-hints-overview)
+ ///
[Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
+ fn parse_optional_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
+ let supports_multiline = dialect_of!(self is MySqlDialect |
OracleDialect | GenericDialect);
+ let supports_singleline = dialect_of!(self is OracleDialect |
GenericDialect);
+ if !supports_multiline && !supports_singleline {
+ return Ok(None);
+ }
+ loop {
+ let t = self.peek_nth_token_no_skip_ref(0);
+ match &t.token {
+ // ~ only the very first comment
+ Token::Whitespace(ws) => {
+ match ws {
+ Whitespace::SingleLineComment { comment, prefix } => {
+ return Ok(if supports_singleline &&
comment.starts_with("+") {
+ let text = comment.split_at(1).1.into();
+ let prefix = prefix.clone();
+ self.next_token_no_skip(); // ~ consume the
token
+ Some(OptimizerHint {
+ text,
+ style: OptimizerHintStyle::SingleLine {
prefix },
+ })
+ } else {
+ None
+ });
+ }
+ Whitespace::MultiLineComment(comment) => {
+ return Ok(if supports_multiline &&
comment.starts_with("+") {
+ let text = comment.split_at(1).1.into();
+ self.next_token_no_skip(); // ~ consume the
token
+ Some(OptimizerHint {
+ text,
+ style: OptimizerHintStyle::MultiLine,
+ })
+ } else {
+ None
+ });
+ }
+ // ~ but skip (pure) whitespace
+ Whitespace::Space | Whitespace::Tab |
Whitespace::Newline => {
+ // ~ consume the token and try with the next
whitespace (if any)
Review Comment:
```suggestion
// but skip (pure) whitespace
Whitespace::Space | Whitespace::Tab |
Whitespace::Newline => {
// consume the token and try with the next
whitespace (if any)
```
let's avoid the `~` before the comments, since that's not a convention used
in the codebase
##########
src/parser/mod.rs:
##########
@@ -14005,6 +14015,59 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses an optional optimizer hint at the current token position
+ ///
+ ///
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html#optimizer-hints-overview)
+ ///
[Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
+ fn parse_optional_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
+ let supports_multiline = dialect_of!(self is MySqlDialect |
OracleDialect | GenericDialect);
+ let supports_singleline = dialect_of!(self is OracleDialect |
GenericDialect);
+ if !supports_multiline && !supports_singleline {
+ return Ok(None);
+ }
+ loop {
+ let t = self.peek_nth_token_no_skip_ref(0);
+ match &t.token {
+ // ~ only the very first comment
Review Comment:
hmm not sure I followed, what does this comment mean by 'very first comment'?
##########
src/parser/mod.rs:
##########
@@ -14005,6 +14015,59 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses an optional optimizer hint at the current token position
+ ///
+ ///
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html#optimizer-hints-overview)
+ ///
[Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
+ fn parse_optional_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
Review Comment:
```suggestion
fn maybe_parse_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
```
##########
src/parser/mod.rs:
##########
@@ -14005,6 +14015,59 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses an optional optimizer hint at the current token position
+ ///
+ ///
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html#optimizer-hints-overview)
+ ///
[Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
+ fn parse_optional_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
+ let supports_multiline = dialect_of!(self is MySqlDialect |
OracleDialect | GenericDialect);
+ let supports_singleline = dialect_of!(self is OracleDialect |
GenericDialect);
+ if !supports_multiline && !supports_singleline {
+ return Ok(None);
+ }
+ loop {
+ let t = self.peek_nth_token_no_skip_ref(0);
+ match &t.token {
+ // ~ only the very first comment
+ Token::Whitespace(ws) => {
+ match ws {
+ Whitespace::SingleLineComment { comment, prefix } => {
+ return Ok(if supports_singleline &&
comment.starts_with("+") {
+ let text = comment.split_at(1).1.into();
+ let prefix = prefix.clone();
+ self.next_token_no_skip(); // ~ consume the
token
Review Comment:
```suggestion
self.next_token_no_skip(); // Consume the
comment token
```
##########
src/parser/mod.rs:
##########
@@ -14005,6 +14015,59 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses an optional optimizer hint at the current token position
+ ///
+ ///
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html#optimizer-hints-overview)
+ ///
[Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
+ fn parse_optional_optimizer_hint(&mut self) ->
Result<Option<OptimizerHint>, ParserError> {
+ let supports_multiline = dialect_of!(self is MySqlDialect |
OracleDialect | GenericDialect);
+ let supports_singleline = dialect_of!(self is OracleDialect |
GenericDialect);
Review Comment:
can we change this to use dialect methods? e.g. `if
self.supports_comment_optimizer_hint()`
Also I think we can use the same flag and let the parser always accept
either the single or multiline cases if they show up
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]